tiki-quiz_edit.php 7.52 KB
Newer Older
1 2
<?php

3
// $Id: /cvsroot/tikiwiki/tiki/tiki-quiz_edit.php,v 1.21.2.1 2007-11-04 21:49:20 nyloth Exp $
4

5
// Copyright (c) 2002-2007, Luis Argerich, Garland Foster, Eduardo Polidor, 
6 7 8 9
//                          George G. Geller et. al.
// 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.

ggeller's avatar
ggeller committed
10 11 12 13 14 15 16 17
/*

	(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.)
18
	(Quiz results for students are always stored; quiz results for teachers 
ggeller's avatar
ggeller committed
19 20 21 22 23 24 25 26
    (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 28
*/

29 30 31 32 33
// Initialization
require_once('tiki-setup.php');

include_once('lib/quizzes/quizlib.php');

34
if ($prefs['feature_quizzes'] != 'y') {
35 36 37 38 39 40
	$smarty->assign('msg', tra("This feature is disabled").": feature_quizzes");

	$smarty->display("error.tpl");
	die;
}

41 42
// quizId of 0 is used as a place holder; There should NEVER be a row in the 
//   tiki_quizzes table with an id of zero.
43 44
if(!isset($_REQUEST["quizId"])){
	$_REQUEST["quizId"] = 0;
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
}

$smarty->assign('individual', 'n');
if ($userlib->object_has_one_permission($_REQUEST["quizId"], 'quiz')) {
	$smarty->assign('individual', 'y');

	if ($tiki_p_admin != 'y') {
		$perms = $userlib->get_permissions(0, -1, 'permName_desc', '', 'quizzes');

		foreach ($perms["data"] as $perm) {
			$permName = $perm["permName"];

			if ($userlib->object_has_permission($user, $_REQUEST["quizId"], 'quiz', $permName)) {
				$$permName = 'y';

				$smarty->assign("$permName", 'y');
			} else {
				$$permName = 'n';

				$smarty->assign("$permName", 'n');
			}
		}
	}
}

ggeller's avatar
ggeller committed
70
if ($tiki_p_admin_quizzes != 'y') {
71
	$smarty->assign('errortype', 401);
72
	$smarty->assign('msg', tra("You don't have permission to edit quizzes."));
73

ggeller's avatar
ggeller committed
74 75
	$smarty->display("error.tpl");
	die;
76 77
}

ggeller's avatar
ggeller committed
78 79 80
$cat_type = 'quiz';
$cat_objid = $_REQUEST["quizId"];
include_once ("categorize_list.php");
81

ggeller's avatar
ggeller committed
82 83
if (isset($_REQUEST["preview"]) || isset($_REQUEST["xmlview"])|| isset($_REQUEST["textview"])) {
	echo "line: ".__LINE__."<br>";
84
	echo "Sorry, preview, xmlview and textview are not supported in this version.<br>";
ggeller's avatar
ggeller committed
85

86 87 88
// 	foreach ($_REQUEST as $key => $request){
// 		echo $key." = ".$request."<br>";
// 	}
ggeller's avatar
ggeller committed
89 90 91
	die;
}

92 93
$quiz = $quizlib->quiz_fetch($_REQUEST["quizId"]);

94
function fetchYNOption(&$quiz, $_REQUEST, $option){
ggeller's avatar
ggeller committed
95 96 97 98 99 100 101
	if (isset($_REQUEST[$option]) && $_REQUEST[$option] == 'on'){
		$quiz[$option] = 'y';
	} else {
		$quiz[$option] = 'n';
	}
}

102 103 104 105
// Load the data from the 
function quiz_data_load(){
	global $_REQUEST;
	$quiz_data = array();
ggeller's avatar
ggeller committed
106 107
	foreach($_REQUEST as $key => $val){
		if (preg_match("/^quiz_/",$key)){
108 109
			$k = preg_replace("/^quiz_([.]*)/","\$1",$key);
			$quiz_data[$k] = $val;
ggeller's avatar
ggeller committed
110 111
		}
	}
112 113
	if ($quiz_data["online"] == "online"){
		$quiz_data["online"] = "y";
ggeller's avatar
ggeller committed
114
	}
115 116
	else if ($quiz_data["online"] == "offline"){
		$quiz_data["online"] = "n";
ggeller's avatar
ggeller committed
117 118
	}

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  $quiz_data["datePub"] = TikiLib::make_time(
	$quiz_data["publish_Hour"],
	$quiz_data["publish_Minute"],
	0,
	$quiz_data["publish_Month"],
	$quiz_data["publish_Day"],
	$quiz_data["publish_Year"]
  );

  $quiz_data["dateExp"] = TikiLib::make_time(
	$quiz_data["expire_Hour"],
	$quiz_data["expire_Minute"],
	0,
	$quiz_data["expire_Month"],
	$quiz_data["expire_Day"],
	$quiz_data["expire_Year"]
  );
ggeller's avatar
ggeller committed
136
 
ggeller's avatar
ggeller committed
137 138
	$fields = array('nQuestion',
									'shuffleAnswers',
ggeller's avatar
ggeller committed
139 140 141 142 143 144 145 146 147
									'shuffleQuestions',
									'multiSession',
									'additionalQuestions',
									'limitDisplay',
									'timeLimited',
									'canRepeat',
									'additionalQuestions',
									'forum');
	foreach ($fields as $field){
148
		fetchYNOption($quiz_data, $quiz_data, $field);
149
		// echo '$quiz_data["'.$field.'"] = '.$quiz_data[$field]."<br>";
ggeller's avatar
ggeller committed
150 151
 	}

152 153
 	return $quiz_data;
}
ggeller's avatar
ggeller committed
154

155 156
if (isset($_REQUEST["save"])) {
	check_ticket('edit-quiz-question');
ggeller's avatar
ggeller committed
157

158 159 160 161 162 163
// 	echo __FILE__." line ".__LINE__."<br />";
// 	foreach($_REQUEST as $key => $val){
// 		if (preg_match("/^quiz_/",$key)){
// 			echo $key." = ".$val."<br />";
// 		}
// 	}
ggeller's avatar
ggeller committed
164
// 	die;
ggeller's avatar
ggeller committed
165

166
	$quiz_data = quiz_data_load();
ggeller's avatar
ggeller committed
167

168 169 170
// 	foreach($quiz_data as $key => $val){
// 		echo $key." = ".$val."<br />";
// 	}
ggeller's avatar
ggeller committed
171
// 	die;
ggeller's avatar
ggeller committed
172

173 174
	$quizNew = new Quiz;
	$quizNew->data_load($quiz_data);
ggeller's avatar
ggeller committed
175

176
	// echo __FILE__." line: ".__LINE__."<br />";
ggeller's avatar
ggeller committed
177

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
	// if the id is 0, use just save the new data
	// otherwise we compare the data to what was there before.
	if ($quiz->id == 0 || ($quizNew != $quiz)){
		$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
	}
	else {
		// tell user no changes were stored, return to list of admin quizzes
	}

	// This way for including questions is was too complicated.  Need to think of a simpler way.
 	die;

	echo "line: ".__LINE__."<br>";
	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!
	if ($cat_objid != 0){
		$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
202

203

ggeller's avatar
ggeller committed
204
	die;
205 206
}

ggeller's avatar
ggeller committed
207
// Scaffolding
208 209
// The taken and history stuff has to come from version and studentAttempts fields in
//  the tiki_quiz table in the database.
ggeller's avatar
ggeller committed
210 211 212 213 214 215
// $quiz->taken = 'y';
// $quiz->history = array();
// $quiz->history[] = "and so on...";
// $quiz->history[] = "Version 3 (date stamp) was attempted by students 3 time(s).";
// $quiz->history[] = "Version 2 (date stamp) was attempted by students 2 time(s).";
// $quiz->history[] = "Version 1 (date stamp) was attempted by students 1 time(s).";
216

ggeller's avatar
ggeller committed
217
$smarty->assign('quiz', $quiz);
218

ggeller's avatar
ggeller committed
219
// echo __LINE__."<br>";
220
// echo '$quiz->id = '.$quiz->id."<br>";
ggeller's avatar
ggeller committed
221
// die;
222

ggeller's avatar
ggeller committed
223
function setup_options(&$tpl){
ggeller's avatar
ggeller committed
224
	//	global $smarty;
225 226
	global $tikilib;
	global $user;
227

ggeller's avatar
ggeller committed
228
	$tpl['online_choices'] = array('online'  => 'Online',	'offline' => 'Offline');
229 230 231 232 233
	
	$optionsGrading = array();
	$optionsGrading[] = "machine";
	$optionsGrading[] = "peer review";
	$optionsGrading[] = "teacher";
ggeller's avatar
ggeller committed
234
	$tpl['optionsGrading'] = $optionsGrading;
235 236 237 238 239

	$optionsShowScore = array();
	$optionsShowScore[] = "immediately";
	$optionsShowScore[] = "after expire date";
	$optionsShowScore[] = "never";
ggeller's avatar
ggeller committed
240
	$tpl['optionsShowScore'] = $optionsShowScore;
241 242 243 244 245 246
	
	// FIXME - This needs to be limited to the session timeout in php.ini
	$mins = array();
	for ($i = 1; $i <= 20; $i++){
		$mins[] = $i;
	}
247
	$tpl['mins'] = $mins;
248 249 250 251 252 253 254 255 256
	
	$repetitions = array();
	$qpp = array();
	
	for ($i = 1; $i <= 10; $i++){
		$qpp[] = $i;
		$repetitions[] = $i;
	}
	$repetitions[] = "unlimited";
257 258
	$qpp[] = "unlimited";
	$tpl['repetitions'] = $repetitions;
ggeller's avatar
ggeller committed
259

ggeller's avatar
ggeller committed
260
	$tpl['qpp'] = $qpp;
261
	
262
	$tpl['siteTimeZone'] = $prefs['display_timezone'];
263 264
}

ggeller's avatar
ggeller committed
265
$tpl = array();
266
setup_options($tpl);
ggeller's avatar
ggeller committed
267
$smarty->assign('tpl', $tpl);
268

269
ask_ticket('edit-quiz-question');
ggeller's avatar
ggeller committed
270

271 272
// Display the template
$smarty->assign('mid', 'tiki-quiz_edit.tpl');
273

274
$smarty->display("tiki.tpl");