Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

questionedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: questionedit.php 8687 2001-12-06 10:19:29Z jhe $
5 //
6 // Created on: <22-May-2001 16:17:22 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
31 // include_once( "ezquiz/classes/ezquizquestion.php" );
32
33 $errorMessages = array();
34 if ( isset( $NewAlternative ) )
35 {
36 $question = new eZQuizQuestion( $QuestionID );
37 $alternative = new eZQuizAlternative();
38 $alternative->setQuestion( $question );
39 $alternative->store();
40 $Action = "Update";
41 }
42 else
43 {
44 $question = new eZQuizQuestion( $QuestionID );
45 }
46
47
48 if ( isset( $OK ) )
49 {
50 $question = new eZQuizQuestion( $QuestionID );
51
52 if ( $question->countAlternatives() == false )
53 {
54 $errorMessages[] = "error_add_alternative";
55 }
56
57 if ( count( $errorMessages ) > 0 )
58 {
59 unset( $OK );
60 }
61 $Action = "Update";
62 }
63
64 if ( isset( $Cancel ) )
65 {
66 $question = new eZQuizQuestion( $QuestionID);
67 $game =& $question->game();
68 $gameID = $game->id();
69 eZHTTPTool::header( "Location: /quiz/game/edit/$gameID/" );
70 exit();
71 }
72
73 if ( isset( $Delete ) )
74 {
75 if ( count( $AlternativeDeleteArray ) > 0 )
76 {
77 foreach ( $AlternativeDeleteArray as $AltID )
78 {
79 eZQuizAlternative::delete( $AltID );
80 }
81 }
82 $Action = "";
83 }
84
85 $ini =& eZINI::instance( 'site.ini' );
86 $Language = $ini->variable( "eZQuizMain", "Language" );
87
88 $t = new eZTemplate( "kernel/ezquiz/admin/" . $ini->variable( "eZQuizMain", "AdminTemplateDir" ),
89 "kernel/ezquiz/admin/" . "/intl", $Language, "questionedit.php" );
90 $t->setAllStrings();
91
92 $t->set_file( array(
93 "question_edit_page" => "questionedit.tpl"
94 ) );
95
96 $t->set_block( "question_edit_page", "alternative_list_tpl", "alternative_list" );
97 $t->set_block( "alternative_list_tpl", "alternative_item_tpl", "alternative_item" );
98 $t->set_block( "question_edit_page", "error_list_tpl", "error_list" );
99 $t->set_block( "error_list_tpl", "error_item_tpl", "error_item" );
100
101 $t->set_var( "question_name", isset( $Name ) ? $Name : false );
102 $t->set_var( "question_description", isset( $Description ) ? $Description : false );
103
104 if ( isset( $Action ) && $Action == "Update" )
105 {
106 if ( is_numeric( $QuestionID ) )
107 $question = new eZQuizQuestion( $QuestionID );
108 else
109 $question = new eZQuizQuestion();
110
111 if ( empty( $Name ) )
112 {
113 $errorMessages[] = "error_missing_question_name";
114 unset( $OK );
115 }
116 else
117 {
118 $question->setName( $Name );
119 }
120 $question->store();
121 $alternativeNameError = false;
122 if ( isset( $AlternativeArrayID ) && count( $AlternativeArrayID ) > 0 )
123 {
124 for ( $i = 0; $i < count( $AlternativeArrayID ); $i++ )
125 {
126 $alternative = new eZQuizAlternative( $AlternativeArrayID[$i] );
127 if ( empty( $AlternativeArrayName[$i] ) )
128 {
129 if ( $alternativeNameError == false )
130 {
131 $errorMessages[] = "error_missing_answer_name";
132 unset( $OK );
133 $alternativeNameError = true;
134 }
135 }
136 else
137 {
138 $alternative->setName( $AlternativeArrayName[$i] );
139 }
140
141 if ( isset( $IsCorrect ) && $IsCorrect == $AlternativeArrayID[$i] )
142 $alternative->setIsCorrect( true );
143 else
144 $alternative->setIsCorrect( false );
145 $alternative->store();
146 }
147 unset( $alternative );
148 }
149
150 if ( $question->countCorrectAlternatives() == false && !isset( $NewAlternative ) )
151 {
152 $errorMessages[] = "error_no_correct_alternative";
153 unset( $OK );
154 }
155
156
157 if ( isset( $OK ) )
158 {
159 $game =& $question->game();
160 $gameID = $game->id();
161 eZHTTPTool::header( "Location: /quiz/game/edit/$gameID" );
162 exit();
163 }
164 }
165
166 if ( isset( $Action ) && $Action == "Delete" )
167 {
168 if ( count( $AlternativeArrayID ) > 0 )
169 {
170 foreach ( $AlternativeArrayID as $AlternativeID )
171 {
172 $alternative = new eZQuizAlternative( $AlternativeID );
173 $alternative->delete();
174 }
175 }
176 eZHTTPTool::header( "Location: /quiz/game/question/edit/$GameID" );
177 exit();
178 }
179
180 if ( is_numeric( $QuestionID ) )
181 {
182 if ( !is_a( $question, "eZQuizQuestion" ) )
183 $question = new eZQuizQuestion( $QuestionID );
184 $t->set_var( "question_id", $question->id() );
185 $t->set_var( "question_name", $question->name() );
186
187 $alternativeList =& $question->alternatives();
188 }
189
190 if ( count( $alternativeList ) > 0 )
191 {
192 foreach ( $alternativeList as $alternative )
193 {
194 $t->set_var( "alternative_id", $alternative->id() );
195 $t->set_var( "alternative_name", $alternative->name() );
196
197 if ( $alternative->isCorrect() == $alternative->id() )
198 $t->set_var( "is_selected", "checked" );
199 else
200 $t->set_var( "is_selected", "" );
201
202 $t->parse( "alternative_item", "alternative_item_tpl", true );
203 }
204 $t->parse( "alternative_list", "alternative_list_tpl", true );
205 }
206 else
207 {
208 $t->set_var( "alternative_list", "" );
209 }
210
211 if ( count( $errorMessages ) > 0 )
212 {
213 foreach ( $errorMessages as $errorMessage )
214 {
215 $errorMessage =& $t->Ini->variable( "strings", $errorMessage );
216 $t->set_var( "error_message", $errorMessage );
217 $t->parse( "error_item", "error_item_tpl", true );
218 }
219
220 $t->set_var( "question_name", $Name );
221 $t->set_var( "question_id", $QuestionID );
222
223 $t->parse( "error_list", "error_list_tpl" );
224 }
225 else
226 {
227 $t->set_var( "error_list", "" );
228 }
229
230 $t->pparse( "output", "question_edit_page" );
231
232 ?>
$i
$i
Definition: admin/adlist.php:91
$Description
$Description
Definition: articlelistrss.php:38
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZQuizAlternative
Definition: ezquizalternative.php:42
eZQuizAlternative\delete
delete( $catID=-1)
Definition: ezquizalternative.php:105
eZQuizQuestion
Definition: ezquizquestion.php:44
eZTemplate
Definition: eztemplate.php:107
$Action
$Action
Definition: companysearch.php:80
$QuestionID
$QuestionID
Definition: default.php:30
$question
$question
Definition: default.php:43
exit
exit
Definition: folder.php:81
$Name
$Name
Definition: polledit.php:250
$t
$t
Definition: questionedit.php:88
$ini
if(isset( $OK)) if(isset( $Cancel)) if(isset( $Delete)) $ini
Definition: questionedit.php:85
$Language
$Language
Definition: questionedit.php:86
$errorMessages
$errorMessages
Definition: questionedit.php:33
$game
$game
Definition: quizlist.php:60
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.