tiki-quiz_edit.php 7.3 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3
// (c) Copyright 2002-2009 by authors of the Tiki Wiki/CMS/Groupware Project
// 
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: /cvsroot/tikiwiki/tiki/tiki-quiz_edit.php,v 1.21.2.1 2007-11-04 21:49:20 nyloth Exp $
ggeller's avatar
ggeller committed
7 8
/*

changi67's avatar
changi67 committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
(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
24
*/
changi67's avatar
changi67 committed
25 26
require_once ('tiki-setup.php');
include_once ('lib/quizzes/quizlib.php');
27
if ($prefs['feature_quizzes'] != 'y') {
changi67's avatar
changi67 committed
28
	$smarty->assign('msg', tra("This feature is disabled") . ": feature_quizzes");
29 30 31
	$smarty->display("error.tpl");
	die;
}
changi67's avatar
changi67 committed
32
// quizId of 0 is used as a place holder; There should NEVER be a row in the
33
//   tiki_quizzes table with an id of zero.
changi67's avatar
changi67 committed
34
if (!isset($_REQUEST["quizId"])) {
35
	$_REQUEST["quizId"] = 0;
36 37 38 39 40 41
}
$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');
changi67's avatar
changi67 committed
42
		foreach($perms["data"] as $perm) {
43 44 45 46 47 48 49 50 51 52 53
			$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
54
if ($tiki_p_admin_quizzes != 'y') {
55
	$smarty->assign('errortype', 401);
56
	$smarty->assign('msg', tra("You don't have permission to edit quizzes."));
ggeller's avatar
ggeller committed
57 58
	$smarty->display("error.tpl");
	die;
59
}
ggeller's avatar
ggeller committed
60 61 62
$cat_type = 'quiz';
$cat_objid = $_REQUEST["quizId"];
include_once ("categorize_list.php");
changi67's avatar
changi67 committed
63 64
if (isset($_REQUEST["preview"]) || isset($_REQUEST["xmlview"]) || isset($_REQUEST["textview"])) {
	echo "line: " . __LINE__ . "<br>";
65
	echo "Sorry, preview, xmlview and textview are not supported in this version.<br>";
changi67's avatar
changi67 committed
66 67 68
	// 	foreach ($_REQUEST as $key => $request){
	// 		echo $key." = ".$request."<br>";
	// 	}
ggeller's avatar
ggeller committed
69 70
	die;
}
71
$quiz = $quizlib->quiz_fetch($_REQUEST["quizId"]);
changi67's avatar
changi67 committed
72 73
function fetchYNOption(&$quiz, $_REQUEST, $option) {
	if (isset($_REQUEST[$option]) && $_REQUEST[$option] == 'on') {
ggeller's avatar
ggeller committed
74 75 76 77 78
		$quiz[$option] = 'y';
	} else {
		$quiz[$option] = 'n';
	}
}
changi67's avatar
changi67 committed
79 80
// Load the data from the
function quiz_data_load() {
81 82
	global $_REQUEST;
	$quiz_data = array();
changi67's avatar
changi67 committed
83 84 85
	foreach($_REQUEST as $key => $val) {
		if (preg_match("/^quiz_/", $key)) {
			$k = preg_replace("/^quiz_([.]*)/", "\$1", $key);
86
			$quiz_data[$k] = $val;
ggeller's avatar
ggeller committed
87 88
		}
	}
changi67's avatar
changi67 committed
89
	if ($quiz_data["online"] == "online") {
90
		$quiz_data["online"] = "y";
changi67's avatar
changi67 committed
91
	} else if ($quiz_data["online"] == "offline") {
92
		$quiz_data["online"] = "n";
ggeller's avatar
ggeller committed
93
	}
changi67's avatar
changi67 committed
94 95 96 97
	$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"]);
	$fields = array('nQuestion', 'shuffleAnswers', 'shuffleQuestions', 'multiSession', 'additionalQuestions', 'limitDisplay', 'timeLimited', 'canRepeat', 'additionalQuestions', 'forum');
	foreach($fields as $field) {
98
		fetchYNOption($quiz_data, $quiz_data, $field);
99
		// echo '$quiz_data["'.$field.'"] = '.$quiz_data[$field]."<br>";
changi67's avatar
changi67 committed
100 101 102
		
	}
	return $quiz_data;
103 104 105
}
if (isset($_REQUEST["save"])) {
	check_ticket('edit-quiz-question');
changi67's avatar
changi67 committed
106 107 108 109 110 111 112
	// 	echo __FILE__." line ".__LINE__."<br />";
	// 	foreach($_REQUEST as $key => $val){
	// 		if (preg_match("/^quiz_/",$key)){
	// 			echo $key." = ".$val."<br />";
	// 		}
	// 	}
	// 	die;
113
	$quiz_data = quiz_data_load();
changi67's avatar
changi67 committed
114 115 116 117
	// 	foreach($quiz_data as $key => $val){
	// 		echo $key." = ".$val."<br />";
	// 	}
	// 	die;
118 119 120 121 122
	$quizNew = new Quiz;
	$quizNew->data_load($quiz_data);
	// echo __FILE__." line: ".__LINE__."<br />";
	// 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
123
	if ($quiz->id == 0 || ($quizNew != $quiz)) {
124 125
		$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
changi67's avatar
changi67 committed
126 127
		
	} else {
128
		// tell user no changes were stored, return to list of admin quizzes
changi67's avatar
changi67 committed
129
		
130 131
	}
	// This way for including questions is was too complicated.  Need to think of a simpler way.
changi67's avatar
changi67 committed
132 133
	die;
	echo "line: " . __LINE__ . "<br>";
134 135
	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
136
	if ($cat_objid != 0) {
137 138 139 140 141
		$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
142
	die;
143
}
ggeller's avatar
ggeller committed
144
// Scaffolding
145 146
// 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
147 148 149 150 151 152
// $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).";
ggeller's avatar
ggeller committed
153 154
$smarty->assign('quiz', $quiz);
// echo __LINE__."<br>";
155
// echo '$quiz->id = '.$quiz->id."<br>";
ggeller's avatar
ggeller committed
156
// die;
changi67's avatar
changi67 committed
157
function setup_options(&$tpl) {
ggeller's avatar
ggeller committed
158
	//	global $smarty;
159 160
	global $tikilib;
	global $user;
changi67's avatar
changi67 committed
161
	$tpl['online_choices'] = array('online' => 'Online', 'offline' => 'Offline');
162 163 164 165
	$optionsGrading = array();
	$optionsGrading[] = "machine";
	$optionsGrading[] = "peer review";
	$optionsGrading[] = "teacher";
ggeller's avatar
ggeller committed
166
	$tpl['optionsGrading'] = $optionsGrading;
167 168 169 170
	$optionsShowScore = array();
	$optionsShowScore[] = "immediately";
	$optionsShowScore[] = "after expire date";
	$optionsShowScore[] = "never";
ggeller's avatar
ggeller committed
171
	$tpl['optionsShowScore'] = $optionsShowScore;
172 173
	// FIXME - This needs to be limited to the session timeout in php.ini
	$mins = array();
changi67's avatar
changi67 committed
174
	for ($i = 1; $i <= 20; $i++) {
175 176
		$mins[] = $i;
	}
177
	$tpl['mins'] = $mins;
178 179
	$repetitions = array();
	$qpp = array();
changi67's avatar
changi67 committed
180
	for ($i = 1; $i <= 10; $i++) {
181 182 183 184
		$qpp[] = $i;
		$repetitions[] = $i;
	}
	$repetitions[] = "unlimited";
185 186
	$qpp[] = "unlimited";
	$tpl['repetitions'] = $repetitions;
ggeller's avatar
ggeller committed
187
	$tpl['qpp'] = $qpp;
188
	$tpl['siteTimeZone'] = $prefs['display_timezone'];
189
}
ggeller's avatar
ggeller committed
190
$tpl = array();
191
setup_options($tpl);
ggeller's avatar
ggeller committed
192
$smarty->assign('tpl', $tpl);
193
ask_ticket('edit-quiz-question');
194 195
// Display the template
$smarty->assign('mid', 'tiki-quiz_edit.tpl');
196
$smarty->display("tiki.tpl");