tiki-edit_quiz.php 8.36 KB
Newer Older
1
<?php
2
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
3
//
4 5
// 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.
changi67's avatar
changi67 committed
6
// $Id$
7

rjsmelo's avatar
rjsmelo committed
8
require_once('tiki-setup.php');
9

10
$access->check_feature('feature_quizzes');
11

12 13
$quizlib = TikiLib::lib('quiz');

rjsmelo's avatar
rjsmelo committed
14
if (! isset($_REQUEST["quizId"])) {
15
	$_REQUEST["quizId"] = 0;
16 17
}

18 19 20 21
$smarty->assign('quizId', $_REQUEST["quizId"]);

$smarty->assign('individual', 'n');

22
$tikilib->get_perm_object($_REQUEST["quizId"], 'quiz');
23

24
$access->check_permission('tiki_p_admin_quizzes');
25

rjsmelo's avatar
rjsmelo committed
26
$auto_query_args = [
27 28 29 30
			'quizId',
			'offset',
			'sort_mode',
			'find',
rjsmelo's avatar
rjsmelo committed
31
];
32

33
$_REQUEST["questionsPerPage"] = 999;
34
//Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences
35
$userprefslib = TikiLib::lib('userprefs');
36 37
$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));

38

rjsmelo's avatar
rjsmelo committed
39
$info = [];
40 41
$info["name"] = '';
$info["description"] = '';
mose's avatar
mose committed
42
$info["publishDate"] = $tikilib->now;
changi67's avatar
changi67 committed
43
$cur_time = explode(',', $tikilib->date_format('%Y,%m,%d,%H,%M,%S', $info["publishDate"]));
rjsmelo's avatar
rjsmelo committed
44
$info["expireDate"] = $tikilib->make_time($cur_time[3], $cur_time[4], $cur_time[5], $cur_time[1], $cur_time[2], $cur_time[0] + 1);
45 46
$info["canRepeat"] = 'n';
$info["storeResults"] = 'n';
47
/*$info["immediateFeedback"] = 'n';
48 49
$info["showAnswers"] = 'n';
$info["shuffleQuestions"] = 'n';
50
$info["shuffleAnswers"] = 'n';*/
51 52
$info["questionsPerPage"] = 10;
$info["timeLimited"] = 'n';
53
$info["passingperct"] = '';
54
$info["timeLimit"] = 60 * 60;
55

56
if (isset($_REQUEST["save"])) {
57
	check_ticket('edit-quiz');
58

59
	//Convert 12-hour clock hours to 24-hour scale to compute time
rjsmelo's avatar
rjsmelo committed
60
	if (! empty($_REQUEST['publish_Meridian'])) {
61 62
		$_REQUEST['publish_Hour'] = date('H', strtotime($_REQUEST['publish_Hour'] . ':00 ' . $_REQUEST['publish_Meridian']));
	}
rjsmelo's avatar
rjsmelo committed
63
	if (! empty($_REQUEST['expire_Meridian'])) {
64 65 66
		$_REQUEST['expire_Hour'] = date('H', strtotime($_REQUEST['expire_Hour'] . ':00 ' . $_REQUEST['expire_Meridian']));
	}
	# convert from the displayed 'site' time to 'server' time
rjsmelo's avatar
rjsmelo committed
67 68
	 $publishDate = $tikilib->make_time($_REQUEST["publish_Hour"], $_REQUEST["publish_Minute"], 0, $_REQUEST["publish_Month"], $_REQUEST["publish_Day"], $_REQUEST["publish_Year"]);
	 $expireDate = $tikilib->make_time($_REQUEST["expire_Hour"], $_REQUEST["expire_Minute"], 0, $_REQUEST["expire_Month"], $_REQUEST["expire_Day"], $_REQUEST["expire_Year"]);
69

70 71 72 73 74 75 76 77 78 79 80 81
	if (isset($_REQUEST["canRepeat"]) && $_REQUEST["canRepeat"] == 'on') {
		$_REQUEST["canRepeat"] = 'y';
	} else {
		$_REQUEST["canRepeat"] = 'n';
	}

	if (isset($_REQUEST["storeResults"]) && $_REQUEST["storeResults"] == 'on') {
		$_REQUEST["storeResults"] = 'y';
	} else {
		$_REQUEST["storeResults"] = 'n';
	}

82
/*	if (isset($_REQUEST["immediateFeedback"]) && $_REQUEST["immediateFeedback"] == 'on') {
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
		$_REQUEST["immediateFeedback"] = 'y';
	} else {
		$_REQUEST["immediateFeedback"] = 'n';
	}

	if (isset($_REQUEST["showAnswers"]) && $_REQUEST["showAnswers"] == 'on') {
		$_REQUEST["showAnswers"] = 'y';
	} else {
		$_REQUEST["showAnswers"] = 'n';
	}

	if (isset($_REQUEST["shuffleQuestions"]) && $_REQUEST["shuffleQuestions"] == 'on') {
		$_REQUEST["shuffleQuestions"] = 'y';
	} else {
		$_REQUEST["shuffleQuestions"] = 'n';
	}

	if (isset($_REQUEST["shuffleAnswers"]) && $_REQUEST["shuffleAnswers"] == 'on') {
		$_REQUEST["shuffleAnswers"] = 'y';
	} else {
		$_REQUEST["shuffleAnswers"] = 'n';
104
	}*/
105

106 107 108 109 110 111
	if (isset($_REQUEST["timeLimited"]) && $_REQUEST["timeLimited"] == 'on') {
		$_REQUEST["timeLimited"] = 'y';
	} else {
		$_REQUEST["timeLimited"] = 'n';
	}

112
	// Pass dummy "n" for immediateFeedback, showAnswers, shuffleQuestions and shuffleAnswers, which are not implemented.
113
	$qid = $quizlib->replace_quiz(
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
		$_REQUEST["quizId"],
		$_REQUEST["name"],
		$_REQUEST["description"],
		$_REQUEST["canRepeat"],
		$_REQUEST["storeResults"],
		'n',
		'n',
		'n',
		'n',
		$_REQUEST["questionsPerPage"],
		$_REQUEST["timeLimited"],
		$_REQUEST["timeLimit"],
		$publishDate,
		$expireDate,
		$_REQUEST["passingperct"]
129
	);
130 131 132 133 134
	$cat_type = 'quiz';
	$cat_objid = $qid;
	$cat_desc = substr($_REQUEST["description"], 0, 200);
	$cat_name = $_REQUEST["name"];
	$cat_href = "tiki-take_quiz.php?quizId=" . $cat_objid;
rjsmelo's avatar
rjsmelo committed
135
	include_once("categorize.php");
136
	$_REQUEST["quizId"] = 0;
137 138
	$smarty->assign('quizId', $_REQUEST["quizId"]);
	$quizId = 0;
139 140
} elseif ($_REQUEST["quizId"]) {
	$info = $quizlib->get_quiz($_REQUEST["quizId"]);
141

rjsmelo's avatar
rjsmelo committed
142
	if (! isset($info["publishDate"])) {
mose's avatar
mose committed
143
		$info["publishDate"] = $tikilib->now;
144
	}
rjsmelo's avatar
rjsmelo committed
145
	if (! isset($info["expireDate"])) {
146
		$cur_time = explode(',', $tikilib->date_format('%Y,%m,%d,%H,%M,%S', $tikilib->now));
rjsmelo's avatar
rjsmelo committed
147
		$info["expireDate"] = $tikilib->make_time($cur_time[3], $cur_time[4], $cur_time[5], $cur_time[1], $cur_time[2], $cur_time[0] + 1);
148
	}
149 150 151 152 153 154
}

$smarty->assign('name', $info["name"]);
$smarty->assign('description', $info["description"]);
$smarty->assign('canRepeat', $info["canRepeat"]);
$smarty->assign('storeResults', $info["storeResults"]);
155 156 157 158
$smarty->assign('immediateFeedback', $info["immediateFeedback"]);
$smarty->assign('showAnswers', $info["showAnswers"]);
$smarty->assign('shuffleQuestions', $info["shuffleQuestions"]);
$smarty->assign('shuffleAnswers', $info["shuffleAnswers"]);
159 160 161
$smarty->assign('questionsPerPage', $info["questionsPerPage"]);
$smarty->assign('timeLimited', $info["timeLimited"]);
$smarty->assign('timeLimit', $info["timeLimit"]);
162
$smarty->assign('passingperct', $info["passingperct"]);
163 164

if (isset($_REQUEST["remove"])) {
165 166
	$access->check_authenticity();
	$quizlib->remove_quiz($_REQUEST["remove"]);
167 168
}

rjsmelo's avatar
rjsmelo committed
169
if (! isset($_REQUEST["sort_mode"])) {
170
	$sort_mode = 'created_desc';
171
} else {
172 173
	$sort_mode = $_REQUEST["sort_mode"];
}
174

rjsmelo's avatar
rjsmelo committed
175
if (! isset($_REQUEST["offset"])) {
176
	$offset = 0;
177
} else {
178
	$offset = $_REQUEST["offset"];
179 180
}

181 182 183 184
$smarty->assign_by_ref('offset', $offset);

if (isset($_REQUEST["find"])) {
	$find = $_REQUEST["find"];
185
} else {
186
	$find = '';
187 188
}

189 190 191 192 193
$smarty->assign('find', $find);

$smarty->assign_by_ref('sort_mode', $sort_mode);
$channels = $quizlib->list_quizzes($offset, $maxRecords, $sort_mode, $find);

194 195
$temp_max = count($channels["data"]);
for ($i = 0; $i < $temp_max; $i++) {
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
	if ($userlib->object_has_one_permission($channels["data"][$i]["quizId"], 'quiz')) {
		$channels["data"][$i]["individual"] = 'y';

		if ($userlib->object_has_permission($user, $channels["data"][$i]["quizId"], 'quiz', 'tiki_p_take_quiz')) {
			$channels["data"][$i]["individual_tiki_p_take_quiz"] = 'y';
		} else {
			$channels["data"][$i]["individual_tiki_p_take_quiz"] = 'n';
		}

		if ($userlib->object_has_permission($user, $channels["data"][$i]["quizId"], 'quiz', 'tiki_p_view_quiz_stats')) {
			$channels["data"][$i]["individual_tiki_p_view_quiz_stats"] = 'y';
		} else {
			$channels["data"][$i]["individual_tiki_p_view_quiz_stats"] = 'n';
		}

		if ($userlib->object_has_permission($user, $channels["data"][$i]["quizId"], 'quiz', 'tiki_p_view_user_stats')) {
			$channels["data"][$i]["individual_tiki_p_view_user_stats"] = 'y';
		} else {
			$channels["data"][$i]["individual_tiki_p_view_user_stats"] = 'n';
		}

		if ($tiki_p_admin
			== 'y' || $userlib->object_has_permission($user, $channels["data"][$i]["quizId"], 'quiz', 'tiki_p_admin_quizzes')) {
			$channels["data"][$i]["individual_tiki_p_take_quiz"] = 'y';

			$channels["data"][$i]["individual_tiki_p_view_quiz_stats"] = 'y';
			$channels["data"][$i]["individual_tiki_p_admin_quizzes"] = 'y';
			$channels["data"][$i]["individual_tiki_p_view_user_stats"] = 'y';
		}
	} else {
		$channels["data"][$i]["individual"] = 'n';
	}
}
229

230
$smarty->assign_by_ref('cant_pages', $channels["cant"]);
231

232
$smarty->assign_by_ref('channels', $channels["data"]);
233 234

// Fill array with possible number of questions per page
rjsmelo's avatar
rjsmelo committed
235
$qpp = [ 1, 2, 3, 4 ];
236

rjsmelo's avatar
rjsmelo committed
237
for ($i = 5; $i < 50; $i += 5) {
238
	$qpp[] = $i;
rjsmelo's avatar
rjsmelo committed
239
}
240

rjsmelo's avatar
rjsmelo committed
241
$hrs = [];
242

rjsmelo's avatar
rjsmelo committed
243
for ($i = 0; $i < 10; $i++) {
244
	$hrs[] = $i;
rjsmelo's avatar
rjsmelo committed
245
}
246

rjsmelo's avatar
rjsmelo committed
247
$mins = [];
248

rjsmelo's avatar
rjsmelo committed
249
for ($i = 1; $i < 120; $i++) {
250
	$mins[] = $i;
rjsmelo's avatar
rjsmelo committed
251
}
252 253 254 255 256 257 258

$smarty->assign('qpp', $qpp);
$smarty->assign('hrs', $hrs);
$smarty->assign('mins', $mins);

$cat_type = 'quiz';
$cat_objid = $_REQUEST["quizId"];
rjsmelo's avatar
rjsmelo committed
259
include_once("categorize_list.php");
260
ask_ticket('edit-quiz');
261

262
$smarty->assign('publishDate', $info['publishDate']);
mose's avatar
mose committed
263
$smarty->assign('publishDateSite', $info['publishDate']);
264
$smarty->assign('expireDate', $info['expireDate']);
mose's avatar
mose committed
265
$smarty->assign('expireDateSite', $info['expireDate']);
266

267 268 269
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

270
// Display the template
271
$smarty->assign('mid', 'tiki-edit_quiz.tpl');
272
$smarty->display("tiki.tpl");