Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

quizplay.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: quizplay.php 9344 2002-03-06 08:56:33Z jhe $
5 //
6 // Created on: <28-May-2001 11:24:41 pkej>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // First check if this game is open
28 // Check if there are other open games
29
30 // include_once( "classes/ezlocale.php" );
31 // include_once( "classes/ezdate.php" );
32 // include_once( "classes/eztemplate.php" );
33 // include_once( "classes/ezhttptool.php" );
34 // include_once( "ezquiz/classes/ezquizquestion.php" );
35 // include_once( "ezquiz/classes/ezquizgame.php" );
36 // include_once( "ezquiz/classes/ezquizanswer.php" );
37 // include_once( "ezquiz/classes/ezquizscore.php" );
38 // include_once( "classes/INIFile.php" );
39
40 $ini =& eZINI::instance( 'site.ini' );
41 $Language = $ini->variable( "eZQuizMain", "Language" );
42 $t = new eZTemplate( "kernel/ezquiz/user/" . $ini->variable( "eZQuizMain", "TemplateDir" ),
43 "kernel/ezquiz/user/intl/", $Language, "quiz.php" );
44
45 $intl = new eZINI( "kernel/ezquiz/user/intl/". $Language . "/quiz.php.ini" );
46
47 if ( isset( $SaveButton ) )
48 {
49 // Do we have the same user uploading the data?
50 // Me? Paranoid?
51 if ( $UserID == $user->id() )
52 {
53 $question = new eZQuizQuestion( $QuestionID );
54 $game = $question->game();
55 $score = new eZQuizScore();
56 $score->getUserGame( $user, $game );
57 if ( $score->id() == 0 )
58 {
59 $score->setUser( $user );
60 $score->setGame( $game );
61 }
62 $score->setNextQuestion( $Placement );
63 $score->store();
64
65 eZHTTPTool::header( "Location: /quiz/my/open/" );
66 }
67 }
68
69
70
71 if ( isset( $NextButton ) )
72 {
73 // Do we have the same user uploading the data?
74 // Me? Paranoid?
75 if ( $UserID == $user->id() )
76 {
77 $question = new eZQuizQuestion( $QuestionID );
78 $alternative = new eZQuizAlternative( $AlternativeID );
79 if ( $question->isAlternative( $alternative ) )
80 {
81 if ( $alternative->isCorrect() )
82 {
83 $scoreValue = $question->score();
84 if ( empty( $scoreValue ) )
85 {
86 $scoreValue = 1;
87 }
88 }
89 $answer = new eZQuizAnswer();
90
91 $answer->setUser( $user );
92 $answer->setAlternative( $alternative );
93 $game = $question->game();
94 $score = new eZQuizScore();
95
96 $score->getUserGame( $user, $game );
97 if ( $answer->hasAnswered() )
98 {
99 $QuestionNum = $score->nextQuestion();
100 }
101 else
102 {
103 $totalScore = $score->totalScore() + $scoreValue;
104 $score->setTotalScore( $totalScore );
105 $score->setGame( $game );
106 $score->setUser( $user );
107
108 $score->setNextQuestion( $QuestionNum );
109
110 if ( $QuestionNum > $game->numberOfQuestions() )
111 {
112 $score->setFinishedGame( true );
113 // include_once( "ezquiz/classes/ezquiztool.php" );
114 }
115 else
116 {
117 $score->setFinishedGame( false );
118 }
119 $answer->store();
120 $score->store();
121 }
122 }
123 else
124 {
125 $t->set_var( "error_message", $intl->variable( "strings", "error_no_such_alternative" ) );
126 $t->parse( "error_item", "error_item_tpl" );
127 }
128 }
129 else
130 {
131 $t->set_var( "error_message", $intl->variable( "strings", "error_differing_user_ids" ) );
132 $t->parse( "error_item", "error_item_tpl" );
133 }
134 }
135
136 $t->setAllStrings();
137
138 $t->set_file( "question_page_tpl", "question.tpl" );
139
140 $t->set_block( "question_page_tpl", "question_item_tpl", "question_item" );
141 $t->set_block( "question_page_tpl", "high_score_item_tpl", "high_score_item" );
142 $t->set_block( "question_page_tpl", "your_score_item_tpl", "your_score_item" );
143 $t->set_block( "question_page_tpl", "start_item_tpl", "start_item" );
144 $t->set_block( "question_page_tpl", "error_item_tpl", "error_item" );
145 $t->set_block( "question_item_tpl", "alternative_item_tpl", "alternative_item" );
146
147 $t->set_var( "start_item", "" );
148 $t->set_var( "question_item", "" );
149 $t->set_var( "high_score_item", "" );
150 $t->set_var( "your_score_item", "" );
151 $t->set_var( "error_item", "" );
152
153 $game = new eZQuizGame( $GameID );
154 $t->set_var( "game_id", $GameID );
155 $t->set_var( "user_id", $user->id() );
156 $t->set_var( "game_name", $game->name() );
157 $t->set_var( "questions", $game->numberOfQuestions() );
158 $t->set_var( "players", $game->numberOfPlayers() );
159
160 $score = new eZQuizScore();
161 $highScorer = $score->highScore( $game );
162
163 if ( $highScorer->id() > 0 )
164 {
165 $t->set_var( "high_score", $highScorer->totalScore() );
166 $highPlayer = $highScorer->user();
167 $t->set_var( "scorer", $highPlayer->login() );
168 $t->set_var( "scorer_id", $highPlayer->id() );
169 $t->parse( "high_score_item", "high_score_item_tpl" );
170 }
171
172 $score->getUserGame( $user, $game );
173
174 if ( $score->isFinishedGame() )
175 {
176 $t->set_var( "your_score", $score->totalScore() );
177 $t->set_var( "your_name", $user->login() );
178 $t->set_var( "your_id", $user->id() );
179 $t->parse( "your_score_item", "your_score_item_tpl" );
180 }
181
182 // Find out which question this user should start on (has he saved earlier info).
183
184 if ( $score->nextQuestion() > 1 )
185 {
186 $QuestionNum = $score->nextQuestion();
187 }
188
189 if ( $QuestionNum == 0 )
190 {
191 $t->parse( "start_item", "start_item_tpl" );
192 }
193 elseif ( empty( $error ) )
194 {
195 if ( $QuestionNum >= 1 )
196 {
197 $QuestionNum = $score->nextQuestion();
198 }
199
200 $questionCount = $game->numberOfQuestions();
201 $currentQuestion = $game->question( $QuestionNum );
202
203 if ( $questionCount <= 0 )
204 {
205 $t->set_var( "error_message", $intl->variable( "strings", "error_no_questions" ) );
206 $t->parse( "error_item", "error_item_tpl" );
207 }
208 else if ( $QuestionNum <= $questionCount )
209 {
210 $t->set_var( "question_id", $currentQuestion->id() );
211
212 $t->set_var( "placement", $QuestionNum );
213 $QuestionNum++;
214
215 $t->set_var( "next_question_num", $QuestionNum );
216 $t->set_var( "question_name", $currentQuestion->name() );
217
218 $alternatives = $currentQuestion->alternatives();
219
220 $i = 0;
221 $count = count( $alternatives );
222
223 if ( $count == 0 )
224 {
225 $t->set_var( "error_message", $intl->variable( "strings", "error_no_alternatives" ) );
226 $t->parse( "error_item", "error_item_tpl" );
227 }
228 else
229 {
230 foreach ( $alternatives as $alternative )
231 {
232 if ( ( $i % 2 ) == 0 )
233 {
234 $t->set_var( "td_class", "bglight" );
235 }
236 else
237 {
238 $t->set_var( "td_class", "bgdark" );
239 }
240 $t->set_var( "alternative_id", $alternative->id() );
241 $t->set_var( "alternative_name", $alternative->name() );
242 $t->parse( "alternative_item", "alternative_item_tpl", true );
243 $i++;
244 }
245 $t->parse( "question_item", "question_item_tpl" );
246 }
247 }
248 else
249 {
250 // finished game.
251 }
252 }
253
254 if ( $error )
255 {
256 switch ( $error )
257 {
258 case "unopened":
259 {
260 $t->set_var( "error_message", $intl->variable( "strings", "error_unopened" ) );
261 $t->parse( "error_item", "error_item_tpl" );
262 }
263 break;
264
265 case "closed":
266 {
267 $t->set_var( "error_message", $intl->variable( "strings", "error_closed" ) );
268 $t->parse( "error_item", "error_item_tpl" );
269 }
270 break;
271
272 default:
273 {
274 $t->set_var( "error_message", $intl->variable( "strings", "error_undefined" ) );
275 $t->parse( "error_item", "error_item_tpl" );
276 }
277 break;
278 }
279 }
280
281 $t->pparse( "output", "question_page_tpl" );
282
283 ?>
$i
$i
Definition: admin/adlist.php:91
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZINI
Reads and writes .ini style configuration files.
eZQuizAlternative
Definition: ezquizalternative.php:42
eZQuizAnswer
Definition: ezquizanswer.php:43
eZQuizGame
Definition: ezquizgame.php:43
eZQuizQuestion
Definition: ezquizquestion.php:44
eZQuizScore
Definition: ezquizscore.php:43
eZTemplate
Definition: eztemplate.php:107
$QuestionID
$QuestionID
Definition: default.php:30
$question
$question
Definition: default.php:43
$error
$error
Definition: ezarticle/admin/categoryedit.php:51
$count
$count
Definition: onlinetypelist.php:108
$t
$t
Definition: quizplay.php:42
$intl
$intl
Definition: quizplay.php:45
$game
$game
Definition: quizplay.php:153
$Language
$Language
Definition: quizplay.php:41
$ini
$ini
Definition: quizplay.php:40
$score
$score
Definition: quizplay.php:160
$highScorer
$highScorer
Definition: quizplay.php:161
$UserID
$UserID
Definition: todoedit.php:122
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.