tiki-edit_quiz_questions.php 4.19 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$
10

11
require_once('tiki-setup.php');
12
$quizlib = TikiLib::lib('quiz');
13

14
$auto_query_args = array('quizId', 'questionId', 'sort_mode', 'offset', 'find');
15
$access->check_feature('feature_quizzes');
16

17 18
if (!isset($_REQUEST['quizId'])) {
	$smarty->assign('msg', tra('No quiz indicated'));
ggeller's avatar
ggeller committed
19

20
	$smarty->display('error.tpl');
ggeller's avatar
ggeller committed
21 22 23
	die;
}

24
$tikilib->get_perm_object($_REQUEST['quizId'], 'quiz');
25

26
$access->check_permission('tiki_p_admin_quizzes');
27

28
$smarty->assign('quizId', $_REQUEST['quizId']);
29 30 31

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

32
$quiz_info = $quizlib->get_quiz($_REQUEST['quizId']);
33
$smarty->assign('quiz_info', $quiz_info);
34

35 36
if (!isset($_REQUEST['questionId'])) {
	$_REQUEST['questionId'] = 0;
37 38
}

39
$smarty->assign('questionId', $_REQUEST['questionId']);
40

41 42
if ($_REQUEST['questionId']) {
	$info = $quizlib->get_quiz_question($_REQUEST['questionId']);
43
} else {
44 45
	$info = array();

46 47 48
	$info['question'] = '';
	$info['type'] = '';
	$info['position'] = '';
49 50
}

51 52 53
$smarty->assign('question', $info['question']);
$smarty->assign('type', $info['type']);
$smarty->assign('position', $info['position']);
54

55
if (isset($_REQUEST['remove'])) {
56
	$access->check_authenticity();
57
	$quizlib->remove_quiz_question($_REQUEST['remove']);
58 59
}

60
if (isset($_REQUEST['save'])) {
61
	check_ticket('edit-quiz-question');
62

63
	$quizlib->replace_quiz_question(
64 65 66 67 68
		$_REQUEST['questionId'],
		$_REQUEST['question'],
		$_REQUEST['questionType'],
		$_REQUEST['quizId'],
		$_REQUEST['position']
69
	);
70 71

	$smarty->assign('question', '');
ggeller's avatar
ggeller committed
72 73 74
	$smarty->assign('questionId', 0);
}

75
if (isset($_REQUEST['import'])) {
ggeller's avatar
ggeller committed
76
	check_ticket('edit-quiz-question');
77

78
	$questions = TextToQuestions($_REQUEST['input_data']);
ggeller's avatar
ggeller committed
79

80
	foreach ($questions as $question) {
ggeller's avatar
ggeller committed
81
		$question_text = $question->getQuestion();
82
		$id = $quizlib->replace_quiz_question(0, $question_text, 'o', $_REQUEST['quizId'], 0);
83
		$temp_max = $question->getChoiceCount();
84
		for ($i = 0; $i < $temp_max; $i++) {
ggeller's avatar
ggeller committed
85 86 87 88 89 90 91
			$a = $question->GetChoice($i);
			$b = $question->GetCorrect($i);
			$quizlib->replace_question_option(0, $a, $b, $id);
		}
	}

	$smarty->assign('question', '');
92
	$smarty->assign('questionId', 0);
93 94
}

95
if (isset($_REQUEST['useQuestion'])) {
96
	check_ticket('edit-quiz-question');
97
	$info = $quizlib->get_quiz_question($_REQUEST['usequestionid']);
98

99 100
	$qid = $quizlib->replace_quiz_question(0, $info['question'], $info['type'], $_REQUEST['quizId'], $_REQUEST['position']);
	$options = $quizlib->list_quiz_question_options($info['questionId'], 0, -1, 'points_desc', '');
101

102 103
	foreach ($options['data'] as $opt) {
		$quizlib->replace_question_option(0, $opt['optionText'], $opt['points'], $qid);
104
	}
105 106
}

107
if (!isset($_REQUEST['sort_mode'])) {
108
	$sort_mode = 'position_asc';
109
} else {
110
	$sort_mode = $_REQUEST['sort_mode'];
111
}
112

113
if (!isset($_REQUEST['offset'])) {
114
	$offset = 0;
115
} else {
116
	$offset = $_REQUEST['offset'];
117 118
}

119 120
$smarty->assign_by_ref('offset', $offset);

121 122
if (isset($_REQUEST['find'])) {
	$find = $_REQUEST['find'];
123
} else {
124
	$find = '';
125 126
}

127 128 129
$smarty->assign('find', $find);

$smarty->assign_by_ref('sort_mode', $sort_mode);
130
$channels = $quizlib->list_quiz_questions($_REQUEST['quizId'], $offset, $maxRecords, $sort_mode, $find);
131 132 133
// GGG turned this off as we now have too many questions in the db for this to work.
// $questions = $quizlib->list_all_questions(0, -1, 'position_desc', '');
// $smarty->assign('questions', $questions["data"]);
134

135
$smarty->assign_by_ref('cant_pages', $channels['cant']);
136

137
$smarty->assign_by_ref('channels', $channels['data']);
138 139

// Fill array with possible number of questions per page
140
$positions = array();
141

142 143
for ($i = 1; $i < 100; $i++)
	$positions[] = $i;
144

145
$smarty->assign('positions', $positions);
146 147

$questionTypes = array();
148 149
$questionTypes['o'] = 'Optional';
$questionTypes['f'] = 'Optional + File';
150 151

$smarty->assign('questionTypes', $questionTypes);
152

153
ask_ticket('edit-quiz-question');
154

155 156 157
// disallow robots to index page:
$smarty->assign('metatag_robots', 'NOINDEX, NOFOLLOW');

158
// Display the template
159
$smarty->assign('mid', 'tiki-edit_quiz_questions.tpl');
160
$smarty->display('tiki.tpl');