tiki-quiz_edit.php 6.06 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
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.
changi67's avatar
changi67 committed
9
// $Id$
ggeller's avatar
ggeller committed
10

11
/*
changi67's avatar
changi67 committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
(The expire date must be rigid.  That is, papers will not be accepted after the expire
date, even if the quiz was started before the expire date.  Otherwise, in cases where
we have "show answers after expire date", a student who has completed the quiz could
give the answers to another student during the grace period.  So when the student
takes the quiz, the system must issue a warning to the student about the expire date
if the date is less the the session timeout time away.)
(Quiz results for students are always stored; quiz results for teachers
(defined here as anyone with tiki_p_admin_quizzes) are never stored.)

The data field is supposed to be xml representing things like the prolog, questions and
epilog for this quiz.  At present if you put
<?questions nQuestions=10 ?>
It is supposed to use 10 questions for this quiz from the tiki_quiz_questions table.
If you leave the data field blank, the default is to use all the questions from the table.
You can also set the same option under the Generl Options section.
ggeller's avatar
ggeller committed
27
*/
changi67's avatar
changi67 committed
28
require_once ('tiki-setup.php');
29 30

$access->check_feature('feature_quizzes');
31
//Use 12- or 24-hour clock for $publishDate time selector based on admin and user preferences
32 33
$quizlib = TikiLib::lib('quiz');
$userprefslib = TikiLib::lib('userprefs');
34
$smarty->assign('use_24hr_clock', $userprefslib->get_user_clock_pref($user));
35

36
// quizId of 0 is used as a placeholder; There should NEVER be a row in the
37
//   tiki_quizzes table with an id of zero.
changi67's avatar
changi67 committed
38
if (!isset($_REQUEST["quizId"])) {
39
	$_REQUEST["quizId"] = 0;
40
}
41 42

$tikilib->get_perm_object($_REQUEST["quizId"], 'quiz');
43 44 45

$access->check_permission('tiki_p_admin_quizzes');

ggeller's avatar
ggeller committed
46 47 48
$cat_type = 'quiz';
$cat_objid = $_REQUEST["quizId"];
include_once ("categorize_list.php");
changi67's avatar
changi67 committed
49 50
if (isset($_REQUEST["preview"]) || isset($_REQUEST["xmlview"]) || isset($_REQUEST["textview"])) {
	echo "line: " . __LINE__ . "<br>";
51
	echo "Sorry, preview, xmlview and textview are not supported in this version.<br>";
ggeller's avatar
ggeller committed
52 53
	die;
}
54
$quiz = $quizlib->quiz_fetch($_REQUEST["quizId"]);
55

56 57 58 59 60
/**
 * @param $quiz
 * @param $_REQUEST
 * @param $option
 */
61
function fetchYNOption(&$quiz, $request, $option)
62
{
63
	if (isset($request[$option]) && $request[$option] == 'on') {
ggeller's avatar
ggeller committed
64 65 66 67 68
		$quiz[$option] = 'y';
	} else {
		$quiz[$option] = 'n';
	}
}
69

changi67's avatar
changi67 committed
70
// Load the data from the
71 72 73
/**
 * @return array
 */
74 75
function quiz_data_load()
{
76 77
	global $_REQUEST;
	$quiz_data = array();
78
	foreach ($_REQUEST as $key => $val) {
changi67's avatar
changi67 committed
79 80
		if (preg_match("/^quiz_/", $key)) {
			$k = preg_replace("/^quiz_([.]*)/", "\$1", $key);
81
			$quiz_data[$k] = $val;
ggeller's avatar
ggeller committed
82 83
		}
	}
changi67's avatar
changi67 committed
84
	if ($quiz_data["online"] == "online") {
85
		$quiz_data["online"] = "y";
changi67's avatar
changi67 committed
86
	} else if ($quiz_data["online"] == "offline") {
87
		$quiz_data["online"] = "n";
ggeller's avatar
ggeller committed
88
	}
89 90 91 92 93 94 95
	//Convert 12-hour clock hours to 24-hour scale to compute time
	if (!empty($_REQUEST['publish_Meridian'])) {
		$_REQUEST['publish_Hour'] = date('H', strtotime($_REQUEST['publish_Hour'] . ':00 ' . $_REQUEST['publish_Meridian']));
	}
	if (!empty($_REQUEST['expire_Meridian'])) {
		$_REQUEST['expire_Hour'] = date('H', strtotime($_REQUEST['expire_Hour'] . ':00 ' . $_REQUEST['expire_Meridian']));
	}
96

97
	$quiz_data["datePub"] = TikiLib::make_time(
98 99 100 101 102 103
		$quiz_data["publish_Hour"],
		$quiz_data["publish_Minute"],
		0,
		$quiz_data["publish_Month"],
		$quiz_data["publish_Day"],
		$quiz_data["publish_Year"]
104 105
	);
	$quiz_data["dateExp"] = TikiLib::make_time(
106 107 108 109 110 111
		$quiz_data["expire_Hour"],
		$quiz_data["expire_Minute"],
		0,
		$quiz_data["expire_Month"],
		$quiz_data["expire_Day"],
		$quiz_data["expire_Year"]
112
	);
113 114 115 116 117 118 119 120 121 122 123
	$fields = array('nQuestion'
								, 'shuffleAnswers'
								, 'shuffleQuestions'
								, 'multiSession'
								, 'additionalQuestions'
								, 'limitDisplay'
								, 'timeLimited'
								, 'canRepeat'
								, 'additionalQuestions'
								, 'forum'
								);
124
	foreach ($fields as $field) {
125
		fetchYNOption($quiz_data, $quiz_data, $field);
126

changi67's avatar
changi67 committed
127 128
	}
	return $quiz_data;
129
}
130

131 132 133 134 135 136 137
if (isset($_REQUEST["save"])) {
	check_ticket('edit-quiz-question');
	$quiz_data = quiz_data_load();
	$quizNew = new Quiz;
	$quizNew->data_load($quiz_data);
	// if the id is 0, use just save the new data
	// otherwise we compare the data to what was there before.
changi67's avatar
changi67 committed
138
	if ($quiz->id == 0 || ($quizNew != $quiz)) {
139 140
		$quizlib->quiz_store($quizNew);
		// tell user changes were stored (new quiz stored with id of x or quiz x modified), return to list of admin quizzes
141 142

	}
changi67's avatar
changi67 committed
143 144
	die;
	echo "line: " . __LINE__ . "<br>";
145 146
	echo "Sorry, this is only a prototype at present.<br>";
	// Fixme, this doesn't work for a brand-new quiz because the quizId is zero!
changi67's avatar
changi67 committed
147
	if ($cat_objid != 0) {
148 149 150 151 152
		$cat_href = "tiki-quiz.php?quizId=" . $cat_objid;
		$cat_name = $_REQUEST["name"];
		$cat_desc = substr($_REQUEST["description"], 0, 200);
		include_once ("categorize.php");
	}
ggeller's avatar
ggeller committed
153
	die;
154
}
155

ggeller's avatar
ggeller committed
156
$smarty->assign('quiz', $quiz);
157

158 159 160
/**
 * @param $tpl
 */
161 162
function setup_options(&$tpl)
{
Jonny Bradley's avatar
Jonny Bradley committed
163
	global $prefs;
changi67's avatar
changi67 committed
164
	$tpl['online_choices'] = array('online' => 'Online', 'offline' => 'Offline');
165 166 167 168
	$optionsGrading = array();
	$optionsGrading[] = "machine";
	$optionsGrading[] = "peer review";
	$optionsGrading[] = "teacher";
ggeller's avatar
ggeller committed
169
	$tpl['optionsGrading'] = $optionsGrading;
170 171 172 173
	$optionsShowScore = array();
	$optionsShowScore[] = "immediately";
	$optionsShowScore[] = "after expire date";
	$optionsShowScore[] = "never";
ggeller's avatar
ggeller committed
174
	$tpl['optionsShowScore'] = $optionsShowScore;
175
	// FIXME - This needs to be limited to the session timeout in php.ini
176
	$mins = array();
177
	for ($i = 1; $i <= 20; $i++) {
178 179
		$mins[] = $i;
	}
180
	$tpl['mins'] = $mins;
181 182
	$repetitions = array();
	$qpp = array();
changi67's avatar
changi67 committed
183
	for ($i = 1; $i <= 10; $i++) {
184 185 186 187
		$qpp[] = $i;
		$repetitions[] = $i;
	}
	$repetitions[] = "unlimited";
188 189
	$qpp[] = "unlimited";
	$tpl['repetitions'] = $repetitions;
ggeller's avatar
ggeller committed
190
	$tpl['qpp'] = $qpp;
191
	$tpl['siteTimeZone'] = $prefs['display_timezone'];
192
}
193

ggeller's avatar
ggeller committed
194
$tpl = array();
195
setup_options($tpl);
ggeller's avatar
ggeller committed
196
$smarty->assign('tpl', $tpl);
197
ask_ticket('edit-quiz-question');
198

199
$smarty->assign('mid', 'tiki-quiz_edit.tpl');
200
$smarty->display("tiki.tpl");