tiki-admin_surveys.php 3.98 KB
Newer Older
lrargerich's avatar
lrargerich committed
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
rjsmelo's avatar
rjsmelo committed
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9
// $Id$
changi67's avatar
changi67 committed
10

nyloth's avatar
nyloth committed
11
$section = 'surveys';
rjsmelo's avatar
rjsmelo committed
12 13
require_once('tiki-setup.php');
include_once('lib/surveys/surveylib.php');
14
$access->check_feature('feature_surveys');
15

rjsmelo's avatar
rjsmelo committed
16
$auto_query_args = [
17 18 19 20
	'surveyId',
	'offset',
	'sort_mode',
	'find'
rjsmelo's avatar
rjsmelo committed
21
];
22

rjsmelo's avatar
rjsmelo committed
23
if (! isset($_REQUEST["surveyId"])) {
24
	$_REQUEST["surveyId"] = 0;
lrargerich's avatar
lrargerich committed
25
}
26
$smarty->assign('surveyId', $_REQUEST["surveyId"]);
27
$tikilib->get_perm_object($_REQUEST['surveyId'], 'survey');
28
$access->check_permission('tiki_p_admin_surveys');
29
if (isset($_REQUEST["save"])) {
30 31 32 33 34 35 36
	check_ticket('admin-surveys');
	$sid = $srvlib->replace_survey($_REQUEST["surveyId"], $_REQUEST["name"], $_REQUEST["description"], $_REQUEST["status"]);
	$cat_type = 'survey';
	$cat_objid = $sid;
	$cat_desc = substr($_REQUEST["description"], 0, 200);
	$cat_name = $_REQUEST["name"];
	$cat_href = "tiki-take_survey.php?surveyId=" . $cat_objid;
rjsmelo's avatar
rjsmelo committed
37
	include_once("categorize.php");
38
	$cookietab = 1;
39
	$_REQUEST["surveyId"] = 0;
40
}
rjsmelo's avatar
rjsmelo committed
41
if (! empty($_REQUEST["surveyId"])) {
42
	$info = $srvlib->get_survey($_REQUEST["surveyId"]);
43
	$cookietab = 2;
lrargerich's avatar
lrargerich committed
44
} else {
rjsmelo's avatar
rjsmelo committed
45
	$info = [];
46 47 48
	$info["name"] = '';
	$info["description"] = '';
	$info["status"] = 'o'; //check to see if survey is open
49
	$cookietab = 1;
lrargerich's avatar
lrargerich committed
50
}
51 52
$smarty->assign('info', $info);
if (isset($_REQUEST["remove"])) {
53 54
	$access->check_authenticity();
	$srvlib->remove_survey($_REQUEST["remove"]);
lrargerich's avatar
lrargerich committed
55
}
rjsmelo's avatar
rjsmelo committed
56
if (! isset($_REQUEST["sort_mode"])) {
57
	$sort_mode = 'created_desc';
lrargerich's avatar
lrargerich committed
58
} else {
59
	$sort_mode = $_REQUEST["sort_mode"];
60
}
rjsmelo's avatar
rjsmelo committed
61
if (! isset($_REQUEST["offset"])) {
62
	$offset = 0;
lrargerich's avatar
lrargerich committed
63
} else {
64
	$offset = $_REQUEST["offset"];
lrargerich's avatar
lrargerich committed
65
}
66 67
$smarty->assign_by_ref('offset', $offset);
if (isset($_REQUEST["find"])) {
68
	$find = $_REQUEST["find"];
lrargerich's avatar
lrargerich committed
69
} else {
70
	$find = '';
lrargerich's avatar
lrargerich committed
71
}
72 73 74
$smarty->assign('find', $find);
$smarty->assign_by_ref('sort_mode', $sort_mode);
$channels = $srvlib->list_surveys($offset, $maxRecords, $sort_mode, $find);
75
$temp_max = count($channels["data"]);
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
for ($i = 0; $i < $temp_max; $i++) {
	if ($userlib->object_has_one_permission($channels["data"][$i]["surveyId"], 'survey')) {
		$channels["data"][$i]["individual"] = 'y';
		if ($userlib->object_has_permission($user, $channels["data"][$i]["surveyId"], 'survey', 'tiki_p_take_survey')) {
			$channels["data"][$i]["individual_tiki_p_take_survey"] = 'y';
		} else {
			$channels["data"][$i]["individual_tiki_p_take_survey"] = 'n';
		}
		if ($userlib->object_has_permission($user, $channels["data"][$i]["surveyId"], 'survey', 'tiki_p_view_survey_stats')) {
			$channels["data"][$i]["individual_tiki_p_view_survey_stats"] = 'y';
		} else {
			$channels["data"][$i]["individual_tiki_p_view_survey_stats"] = 'n';
		}
		if ($tiki_p_admin == 'y' || $userlib->object_has_permission($user, $channels["data"][$i]["surveyId"], 'survey', 'tiki_p_admin_surveys')) {
			$channels["data"][$i]["individual_tiki_p_take_survey"] = 'y';
			$channels["data"][$i]["individual_tiki_p_view_survey_stats"] = 'y';
			$channels["data"][$i]["individual_tiki_p_admin_surveys"] = 'y';
		}
	} else {
		$channels["data"][$i]["individual"] = 'n';
	}
97
}
98
$smarty->assign_by_ref('cant_pages', $channels["cant"]);
99
$smarty->assign_by_ref('channels', $channels["data"]);
100
// Fill array with possible number of questions per page (qpp)
rjsmelo's avatar
rjsmelo committed
101
$qpp = [
102 103 104 105
	1,
	2,
	3,
	4
rjsmelo's avatar
rjsmelo committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
];
for ($i = 5; $i < 50;
$i += 5) {
	$qpp[] = $i;
}
$hrs = [];
for ($i = 0; $i < 10;
$i++) {
	$hrs[] = $i;
}
$mins = [];
for ($i = 1; $i < 120;
$i++) {
	$mins[] = $i;
}
121 122 123 124 125
$smarty->assign('qpp', $qpp);
$smarty->assign('hrs', $hrs);
$smarty->assign('mins', $mins);
$cat_type = 'survey';
$cat_objid = $_REQUEST["surveyId"];
rjsmelo's avatar
rjsmelo committed
126
include_once("categorize_list.php");
changi67's avatar
changi67 committed
127
$section = 'surveys';
rjsmelo's avatar
rjsmelo committed
128
include_once('tiki-section_options.php');
129
ask_ticket('admin-surveys');
130 131
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');
lrargerich's avatar
lrargerich committed
132
// Display the template
133
$smarty->assign('mid', 'tiki-admin_surveys.tpl');
134
$smarty->display("tiki.tpl");