Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

gameedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: gameedit.php 9344 2002-03-06 08:56:33Z jhe $
5 //
6 // Created on: <22-May-2001 13:44:13 ce>
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 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezhttptool.php" );
30 // include_once( "classes/ezdate.php" );
31
32 // include_once( "ezquiz/classes/ezquizgame.php" );
33 // include_once( "ezquiz/classes/ezquiztool.php" );
34
35 if ( isset( $OK ) )
36 {
37 $Action = "Insert";
38 }
39
40 if ( isset( $Delete ) )
41 {
42 $Action = "Delete";
43 }
44
45 if ( isset( $NewQuestion ) )
46 {
47 $Action = "Insert";
48 }
49
50 if ( isset( $Cancel ) )
51 {
52 eZHTTPTool::header( "Location: /quiz/game/list/" );
53 exit();
54 }
55
56 if ( isset( $DeleteQuestions ) )
57 {
58 if ( count( $DeleteQuestionArray ) > 0 )
59 {
60 foreach ( $DeleteQuestionArray as $Quest )
61 {
62 $quest = new eZQuizQuestion( $Quest );
63 $quest->delete();
64 }
65 }
66 }
67
68 if ( isset( $Action ) && $Action == "New" )
69 {
70 $Name = false;
71 $Description = false;
72 $StartMonth = false;
73 $StartDay = false;
74 $StartYear = false;
75 $StopDay = false;
76 $StopYear = false;
77 $StopMonth = false;
78 }
79 elseif ( isset( $Action ) && $Action != "Insert" )
80 {
81 $Name = false;
82 $Description = false;
83 $StartMonth = false;
84 $StartDay = false;
85 $StartYear = false;
86 $StopDay = false;
87 $StopYear = false;
88 $StopMonth = false;
89 $game = false;
90 }
91 elseif ( isset( $Action ) && $Action != "Insert" )
92 {
93 $Name = false;
94 $Description = false;
95 $StartMonth = false;
96 $StartDay = false;
97 $StartYear = false;
98 $StopDay = false;
99 $StopYear = false;
100 $StopMonth = false;
101 $game = false;
102 }
103
104 $ini =& eZINI::instance( 'site.ini' );
105 $Language = $ini->variable( "eZQuizMain", "Language" );
106
107 $t = new eZTemplate( "kernel/ezquiz/admin/" . $ini->variable( "eZQuizMain", "AdminTemplateDir" ),
108 "kernel/ezquiz/admin/intl", $Language, "gameedit.php" );
109 $t->setAllStrings();
110
111 $t->set_file( "game_edit_page", "gameedit.tpl" );
112
113 $t->set_block( "game_edit_page", "question_list_tpl", "question_list" );
114 $t->set_block( "question_list_tpl", "question_item_tpl", "question_item" );
115 $t->set_block( "game_edit_page", "error_no_date_tpl", "error_no_date" );
116 $t->set_block( "game_edit_page", "error_name_tpl", "error_name" );
117 $t->set_block( "game_edit_page", "error_date_tpl", "error_date" );
118 $t->set_block( "game_edit_page", "error_start_date_tpl", "error_start_date" );
119 $t->set_block( "game_edit_page", "error_stop_date_tpl", "error_stop_date" );
120 $t->set_block( "game_edit_page", "error_embracing_period_tpl", "error_embracing_period" );
121 $t->set_block( "game_edit_page", "error_question_tpl", "error_question" );
122
123 $t->set_var( "game_name", $Name );
124 $t->set_var( "game_description", $Description );
125
126 $t->set_var( "start_month", $StartMonth );
127 $t->set_var( "start_day", $StartDay );
128 $t->set_var( "start_year", $StartYear );
129
130 $t->set_var( "stop_month", $StopMonth );
131 $t->set_var( "stop_day", $StopDay );
132 $t->set_var( "stop_year", $StopYear );
133
134 $t->set_var( "game_id", $GameID );
135 $t->set_var( "error_date", "" );
136 $t->set_var( "error_start_date", "" );
137 $t->set_var( "error_stop_date", "" );
138 $t->set_var( "error_embracing_period", "" );
139 $t->set_var( "error_name", "" );
140 $t->set_var( "error_no_date", "" );
141 $t->set_var( "error_question", "" );
142
143 $error = false;
144 $checkDate = true;
145 if ( isset( $Action ) && $Action == "Insert" )
146 {
147 if ( $GameID > 0 && !isset( $NewQuestion ) )
148 {
149 $game = new eZQuizGame( $GameID );
150
151 if ( $game->numberOfQuestions() == 0 )
152 {
153 $t->parse( "error_question", "error_question_tpl" );
154 $error = true;
155 }
156 unset( $game );
157 }
158 elseif ( isset( $OK ) )
159 {
160 $t->parse( "error_question", "error_question_tpl" );
161 $error = true;
162 }
163
164 if ( empty( $Name ) )
165 {
166 $t->parse( "error_name", "error_name_tpl" );
167 $error = true;
168 }
169
170 if ( $StartMonth == 0 ||
171 $StartDay == 0 ||
172 $StartYear == 0 ||
173 $StopMonth == 0 ||
174 $StopDay == 0 ||
175 $StopYear == 0 )
176 {
177 $t->parse( "error_no_date", "error_no_date_tpl" );
178 $error = true;
179 }
180
181 $startDate = new eZDate();
182 $startDate->setMonth( $StartMonth );
183 $startDate->setDay( $StartDay );
184 $startDate->setYear( $StartYear );
185
186 $stopDate = new eZDate();
187 $stopDate->setMonth( $StopMonth );
188 $stopDate->setDay( $StopDay );
189 $stopDate->setYear( $StopYear );
190
191 if ( $checkDate )
192 {
193 $stillOpen =& eZQuizGame::endedInPeriod( $startDate, $stopDate );
194 $numberOfStillOpen = count( $stillOpen );
195
196 $willOpen =& eZQuizGame::startedInPeriod( $startDate, $stopDate );
197 $numberOfwillOpen = count( $willOpen );
198
199 $embracing =& eZQuizGame::embracingPeriod( $startDate, $stopDate );
200 $numberOfEmbracing = count( $embracing );
201 if ( $numberOfEmbracing > 0 )
202 {
203 foreach ( $embracing as $checkItem )
204 {
205 if ( $GameID != $checkItem->id() )
206 {
207 $stopDateCheck =& $checkItem->stopDate();
208 $startDateCheck =& $checkItem->startDate();
209
210 $t->set_var( "error_game_start_day", $startDateCheck->day() );
211 $t->set_var( "error_game_start_month", $startDateCheck->month() );
212 $t->set_var( "error_game_start_year", $startDateCheck->year() );
213 $t->set_var( "error_game_stop_day", $stopDateCheck->day() );
214 $t->set_var( "error_game_stop_month", $stopDateCheck->month() );
215 $t->set_var( "error_game_stop_year", $stopDateCheck->year() );
216
217 $t->set_var( "error_game_name", $checkItem->name() );
218 $t->set_var( "error_game_id", $checkItem->id() );
219 $t->parse( "error_embracing_period", "error_embracing_period_tpl" );
220 $error = true;
221 }
222 }
223 }
224
225 if ( $numberOfStillOpen > 0 )
226 {
227 foreach ( $stillOpen as $checkItem )
228 {
229 if ( $GameID != $checkItem->id() )
230 {
231 $stopDateCheck =& $checkItem->stopDate();
232 if ( $startDate->isGreater( $stopDateCheck, true ) )
233 {
234 $startDateCheck =& $checkItem->startDate();
235
236 $t->set_var( "error_game_start_day", $startDateCheck->day() );
237 $t->set_var( "error_game_start_month", $startDateCheck->month() );
238 $t->set_var( "error_game_start_year", $startDateCheck->year() );
239 $t->set_var( "error_game_stop_day", $stopDateCheck->day() );
240 $t->set_var( "error_game_stop_month", $stopDateCheck->month() );
241 $t->set_var( "error_game_stop_year", $stopDateCheck->year() );
242
243 $t->set_var( "error_game_name", $checkItem->name() );
244 $t->set_var( "error_game_id", $checkItem->id() );
245 $t->parse( "error_stop_date", "error_stop_date_tpl" );
246 $error = true;
247 }
248 }
249 }
250 }
251
252 if ( $numberOfwillOpen > 0 )
253 {
254 foreach ( $willOpen as $checkItem )
255 {
256 if ( $GameID != $checkItem->id() )
257 {
258 $startDateCheck =& $checkItem->startDate();
259 if ( $startDate->isGreater( $startDateCheck, true ) )
260 {
261 $stopDateCheck =& $checkItem->stopDate();
262
263 $t->set_var( "error_game_start_day", $startDateCheck->day() );
264 $t->set_var( "error_game_start_month", $startDateCheck->month() );
265 $t->set_var( "error_game_start_year", $startDateCheck->year() );
266 $t->set_var( "error_game_stop_day", $stopDateCheck->day() );
267 $t->set_var( "error_game_stop_month", $stopDateCheck->month() );
268 $t->set_var( "error_game_stop_year", $stopDateCheck->year() );
269
270 $t->set_var( "error_game_name", $checkItem->name() );
271 $t->set_var( "error_game_id", $checkItem->id() );
272 $t->parse( "error_start_date", "error_start_date_tpl" );
273 $error = true;
274 }
275 }
276 }
277 }
278 }
279 }
280
281
282 if ( ( isset( $Action ) && $Action == "Insert" ) && ( $error == false ) )
283 {
284 if ( is_numeric( $GameID ) )
285 $game = new eZQuizGame( $GameID );
286 else
287 $game = new eZQuizGame();
288
289 $game->setName( $Name );
290 $game->setDescription( $Description );
291
292 $game->setStartDate( $startDate );
293 $game->setStopDate( $stopDate );
294
295 $game->store();
296
297 if ( isset( $QuestionArrayID ) && count( $QuestionArrayID ) > 0 )
298 {
299 for ( $i = 0; $i < count( $QuestionArrayID ); $i++ )
300 {
301 $question = new eZQuizQuestion( $QuestionArrayID[$i] );
302 $question->setName( $QuestionArrayName[$i] );
303 $question->store();
304 }
305 unset( $question );
306 }
307
308 if ( isset( $NewQuestion ) )
309 {
310 $question = new eZQuizQuestion();
311 $question->setGame( $game );
312 $question->store();
313 $questionID = $question->id();
314 eZHTTPTool::header( "Location: /quiz/game/questionedit/$questionID" );
315 exit();
316 }
317
318 if ( isset( $OK ) )
319 {
320 eZHTTPTool::header( "Location: /quiz/game/list/" );
321 exit();
322 }
323 }
324
325 if ( isset( $Action ) && $Action == "Delete" )
326 {
327 if ( count( $GameArrayID ) > 0 )
328 {
329 foreach ( $GameArrayID as $GameID )
330 {
331 $game = new eZQuizGame( $GameID );
332 $game->delete();
333 }
334 }
335 eZHTTPTool::header( "Location: /quiz/game/list/" );
336 exit();
337 }
338
339 if ( is_numeric( $GameID ) && !isset( $OK ) && !isset( $NewQuestion ) )
340 {
341 if ( !is_a( $game, "eZQuizGame" ) )
342 $game = new eZQuizGame( $GameID );
343 $t->set_var( "game_id", $game->id() );
344 $t->set_var( "game_name", $game->name() );
345 $t->set_var( "game_description", $game->description() );
346
347 $startDate =& $game->startDate();
348 $stopDate =& $game->stopDate();
349
350 $t->set_var( "start_day", $startDate->day() );
351 $t->set_var( "start_month", $startDate->month() );
352 $t->set_var( "start_year", $startDate->year() );
353
354 $t->set_var( "stop_day", $stopDate->day() );
355 $t->set_var( "stop_month", $stopDate->month() );
356 $t->set_var( "stop_year", $stopDate->year() );
357
358 $questionList =& $game->questions();
359 }
360
361 if ( isset( $questionList ) && count( $questionList ) > 0 )
362 {
363 $i = 0;
364 foreach ( $questionList as $question )
365 {
366 if ( ( $i % 2 ) == 0 )
367 $t->set_var( "td_class", "bglight" );
368 else
369 $t->set_var( "td_class", "bgdark" );
370
371 $t->set_var( "question_id", $question->id() );
372 $t->set_var( "question_name", $question->name() );
373 $t->set_var( "question_score", $question->score() );
374
375 $i++;
376 $t->parse( "question_item", "question_item_tpl", true );
377 }
378 $t->parse( "question_list", "question_list_tpl", true );
379 }
380 else
381 {
382 $t->set_var( "question_list", "" );
383 }
384
385 $t->set_var( "site_style", $SiteDesign );
386
387 $t->pparse( "output", "game_edit_page" );
388
389 ?>
$i
$i
Definition: admin/adlist.php:91
$Description
$Description
Definition: articlelistrss.php:38
eZDate
Definition: ezdate.php:46
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZQuizGame
Definition: ezquizgame.php:43
eZQuizGame\embracingPeriod
static & embracingPeriod(&$inStartDate, &$inStopDate)
Definition: ezquizgame.php:561
eZQuizGame\startedInPeriod
static & startedInPeriod(&$inStartDate, &$inStopDate)
Definition: ezquizgame.php:508
eZQuizGame\endedInPeriod
static & endedInPeriod(&$inStartDate, &$inStopDate)
Definition: ezquizgame.php:535
eZQuizQuestion
Definition: ezquizquestion.php:44
eZTemplate
Definition: eztemplate.php:107
$Action
$Action
Definition: companysearch.php:80
$question
$question
Definition: default.php:43
$SiteDesign
$SiteDesign
Definition: ezbulkmail/user/datasupplier.php:31
exit
exit
Definition: folder.php:81
$ini
if(isset( $OK)) if(isset( $Delete)) if(isset( $NewQuestion)) if(isset( $Cancel)) if(isset( $DeleteQuestions)) if(isset( $Action) && $Action=="New") elseif(isset( $Action) && $Action !="Insert") elseif(isset( $Action) && $Action !="Insert") $ini
Definition: gameedit.php:104
$t
$t
Definition: gameedit.php:107
$Language
$Language
Definition: gameedit.php:105
$checkDate
$checkDate
Definition: gameedit.php:144
$error
$error
Definition: gameedit.php:143
$Name
$Name
Definition: polledit.php:250
$game
$game
Definition: quizlist.php:60
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.