Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

surveyedit.php
Go to the documentation of this file.
1 <?php
4 // include_once( "classes/INIFile.php" );
5 // include_once( "classes/eztemplate.php" );
6 // include_once( "ezsurvey/classes/ezsurvey.php" );
7 // include_once( "ezsurvey/classes/ezquestion.php" );
8 // include_once( "ezsitemanager/classes/ezsection.php" );
9
10 $ini =& eZINI::instance( 'site.ini' );
11 $Language = $ini->variable( "eZSurveyMain", "Language" );
12
13 $t = new eZTemplate( "kernel/ezsurvey/admin/" . $ini->variable( "eZSurveyMain", "AdminTemplateDir" ),
14 "kernel/ezsurvey/admin/intl", $Language, "surveyedit.php" );
15
16 $t->set_file( "surveyedit_tpl", "surveyedit.tpl" );
17 $t->setAllStrings();
18
19 $t->set_block( "surveyedit_tpl", "status_item_tpl", "status_item" );
20 $t->set_block( "surveyedit_tpl", "section_item_tpl", "section_item" );
21
22 $t->set_block( "surveyedit_tpl", "element_list_tpl", "element_list" );
23 $t->set_block( "element_list_tpl", "element_item_tpl", "element_item" );
24 $t->set_block( "element_item_tpl", "name_tpl", "name" );
25 $t->set_block( "element_item_tpl", "no_name_tpl", "no_name" );
26 $t->set_block( "element_item_tpl", "typelist_item_tpl", "typelist_item" );
27 $t->set_block( "element_item_tpl", "fixed_values_tpl", "fixed_values" );
28 $t->set_block( "element_item_tpl", "default_tpl", "default" );
29 $t->set_block( "element_item_tpl", "size_tpl", "size" );
30 $t->set_block( "element_item_tpl", "no_size_tpl", "no_size" );
31 $t->set_block( "element_item_tpl", "required_tpl", "required" );
32
33 $t->set_block( "surveyedit_tpl", "error_list_tpl", "error_list" );
34 $t->set_block( "error_list_tpl", "error_item_tpl", "error_item" );
35
36 $t->set_block( "surveyedit_tpl", "stats_btn_tpl", "stats_btn" );
37
38 $t->set_var( "survey_count", "0" );
39 $t->set_var( "total_survey_count", "0" );
40 $t->set_var( "error_list", "" );
41 $t->set_var( "element_list", "" );
42
43 $errorMessages = array();
44
45 $SurveyID = $url_array[4];
46
47 if ( is_numeric($SurveyID) )
48 {
49 $survey = new eZSurvey($SurveyID);
50 }
51 else
52 {
53 $survey = new eZSurvey();
54 $currentUser = eZUser::currentUser();
55 if ( $currentUser != FALSE )
56 {
57 $survey->setUserID( $currentUser->id() );
58 }
59 }
60
61 // copia o survey e edita-o
62 if ( $Action == "copy" )
63 {
64 $survey =& $survey->copySurvey( "C�pia de " . $survey->title() );
65 $currentUser = eZUser::currentUser();
66 if ( $currentUser != FALSE )
67 {
68 $survey->setUserID( $currentUser->id() );
69 }
70 $Action = "edit";
71 }
72
73 // altera posi��es
74 if ( $Action == "down" )
75 {
76 $question = new eZQuestion( $QuestionID );
77 $question->moveDown();
78 $Action = "edit";
79 }
80
81 if ( $Action == "up" )
82 {
83 $question = new eZQuestion( $QuestionID );
84 $question->moveUp();
85 $Action = "edit";
86 }
87
88 if ( $Action == "edit" )
89 {
90 // altera��es
91 if ( isset( $OK ) || isset( $NewElement ) || isset( $Update ) || isset( $DeleteSelected ) || isset( $Preview ) )
92 {
93 $save = true;
94
95 // grava��o do survey
96 if ( $save )
97 {
98 $survey->setTitle( $Title );
99 $survey->setSubTitle( $SubTitle );
100 $survey->setInfo( $Info );
101 $survey->setEMail( $EMail );
102 $survey->setThankHead( $ThankHead );
103 $survey->setThankBody( $ThankBody );
104 $survey->setStatus( $Status );
105 $survey->setSectionID( $Section );
106
107 if ( isset( $Public ) && $Public == "N" )
108 {
109 $Public = "N";
110 }
111 else
112 {
113 $Public = "Y";
114 }
115
116 $survey->setPublic( $Public );
117
118 $survey->store();
119 }
120
121 $t->set_var( "title_value", $Title );
122 $t->set_var( "subtitle_value", $SubTitle );
123 $t->set_var( "info_value", $Info );
124 $t->set_var( "email_value", $EMail );
125 $t->set_var( "thankhead_value", $ThankHead );
126 $t->set_var( "thankbody_value", $ThankBody );
127
128 foreach ( $survey->statusOptions() as $statusItem )
129 {
130 $t->set_var( "status_value", $statusItem );
131 $t->parse( "status_item", "status_item_tpl", true );
132 }
133
134 $section_array =& eZSection::getAll();
135
136 foreach ( $section_array as $sectionItem )
137 {
138 $t->set_var( "section_value", $sectionItem->id() );
139 $t->set_var( "section_name", $sectionItem->name() );
140
141 if ( $sectionItem->id() == $Section )
142 {
143 $t->set_var( "selected", "selected" );
144 }
145 else
146 {
147 $t->set_var( "selected", "" );
148 }
149
150 $t->parse( "section_item", "section_item_tpl", true );
151 }
152 }
153 else
154 {
155 // edi��o de um survey (quando se entra na p�gina pela primeira vez)
156 $t->set_var( "title_value", $survey->title() );
157 $t->set_var( "subtitle_value", $survey->subTitle() );
158 $t->set_var( "info_value", $survey->info() );
159 $t->set_var( "email_value", $survey->email() );
160 $t->set_var( "thankhead_value", $survey->thankHead() );
161 $t->set_var( "thankbody_value", $survey->thankBody() );
162
163 foreach ( $survey->statusOptions() as $statusItem )
164 {
165 $t->set_var( "status_value", $statusItem );
166 $t->parse( "status_item", "status_item_tpl", true );
167 }
168
169 $section_array =& eZSection::getAll();
170
171 foreach ( $section_array as $sectionItem )
172 {
173 $t->set_var( "section_value", $sectionItem->id() );
174 $t->set_var( "section_name", $sectionItem->name() );
175
176 if ( $sectionItem->id() == $survey->sectionID() )
177 {
178 $t->set_var( "selected", "selected" );
179 }
180 else
181 {
182 $t->set_var( "selected", "" );
183 }
184
185 $t->parse( "section_item", "section_item_tpl", true );
186 }
187 }
188
189 // inser��o de uma nova pergunta.
190 if ( isset( $NewElement ) && $survey->id() != "" )
191 {
192 $question = new eZQuestion();
193
194 $count = $survey->numberOfQuestions();
195
196 $question->setSurveyID( $survey->id() );
197 $question->setContent( "New Question " . ($count+1) );
198 $question->setPosition();
199
200 $question->store();
201 }
202
203 // altera��o das perguntas
204 $i = -1;
205 if ( isset($elementID) )
206 {
207 foreach ($elementID as $elementItem )
208 {
209 $i++;
210 $question = new eZQuestion( $elementItem );
211
212 if ( $question->questionTypeID() != $elementTypeID[$i] && $survey->status() == "ACTIVE" )
213 {
214 $errorMessages[] = "You can't change question types while in ACTIVE mode";
215 continue;
216 }
217
218 // trata da elimina��o caso tenha sido pedida
219 if ( isset($elementDelete) && in_array($elementItem, $elementDelete) )
220 {
221 $question->delete();
222 }
223 else
224 {
225 $question->setContent( $elementName[$i] );
226 $question->setQuestionTypeID( $elementTypeID[$i] );
227 $question->setLength( $Size[$i] );
228
229 // Is required?
230 if ( isset($elementRequired) && in_array($elementItem, $elementRequired) )
231 $question->setRequired( "Y" );
232 else
233 $question->setRequired( "N" );
234
235 if ( isset( $Public ) && $Public == "N" )
236 {
237 $Public = "N";
238 }
239 else
240 {
241 $Public = "Y";
242 }
243
244 $question->setPublic( $Public );
245 $question->store();
246 }
247 }
248 }
249
250 if( isset( $OK ) )
251 {
252 eZHTTPTool::header( "Location: /survey/surveylist/list" );
253 exit();
254 }
255
256
257 if( isset( $Preview ) )
258 {
259 eZHTTPTool::header( "Location: /survey/preview/$SurveyID" );
260 exit();
261 }
262
263 if( isset( $Stats ) )
264 {
265 eZHTTPTool::header( "Location: /survey/stats/$SurveyID" );
266 exit();
267 }
268
269 // lista perguntas
270 $types =& eZQuestion::questionTypes();
271 $question_array = $survey->surveyQuestions();
272
273 $i = 0;
274 foreach ($question_array as $questionItem )
275 {
276 if ($i++ % 2)
277 $t->set_var( "td_class", "bgdark" );
278 else
279 $t->set_var( "td_class", "bglight" );
280
281 $clear = false;
282
283 // id
284 $t->set_var( "element_id", $questionItem->id() );
285
286 // Name
287 if ( $questionItem->hasName() )
288 {
289 $t->set_var( "element_name", $questionItem->content() );
290 $t->set_var( "no_name", "" );
291 $t->parse( "name", "name_tpl" );
292 }
293 else
294 {
295 $t->set_var( "name", "" );
296 $t->parse( "no_name", "no_name_tpl" );
297 }
298
299 // Type
300 foreach ( $types as $typeItem )
301 {
302 $t->set_var( "element_type_id", $typeItem[0] );
303 $t->set_var( "element_type_name", $typeItem[1] );
304
305 if ($questionItem->questionTypeID() == $typeItem[0])
306 $t->set_var( "selected", "selected" );
307 else
308 $t->set_var( "selected", "" );
309
310 $t->parse( "typelist_item", "typelist_item_tpl", $clear );
311 $clear = true;
312 }
313
314 // Fixed values
315 if ( $questionItem->hasChoices() )
316 $t->parse( "fixed_values", "fixed_values_tpl" );
317 else
318 $t->set_var( "fixed_values", "" );
319
320 // Default
321 if ( $questionItem->hasDefault() )
322 $t->parse( "default", "default_tpl" );
323 else
324 $t->set_var( "default", "" );
325
326 // Size
327 if ( $questionItem->hasSize() )
328 {
329 $t->set_var( "element_size", $questionItem->length() );
330 $t->set_var( "no_size", "" );
331 $t->parse( "size", "size_tpl" );
332 }
333 else
334 {
335 $t->set_var( "element_size", '0' );
336 $t->set_var( "size", "" );
337 $t->parse( "no_size", "no_size_tpl" );
338 }
339
340 // Required
341 if ( $questionItem->hasRequired() )
342 {
343 if ( $questionItem->isRequired() )
344 $t->set_var( "element_required", "checked" );
345 else
346 $t->set_var( "element_required", "" );
347
348 $t->parse( "required", "required_tpl" );
349 }
350 else
351 {
352 $t->set_var( "required", "" );
353 }
354
355 $t->parse( "element_item", "element_item_tpl", true );
356 }
357 if ( count( $question_array ) > 0 )
358 {
359 $t->parse( "element_list", "element_list_tpl" );
360 }
361 }
362
363 if ( $Action == "new" )
364 {
365 $survey = new eZSurvey();
366 $count = eZSurvey::numberOfSurveys() + 1;
367
368 $t->set_var( "title_value", "Survey Title $count" );
369 $t->set_var( "subtitle_value", "" );
370 $t->set_var( "info_value", "" );
371 $t->set_var( "email_value", "" );
372 $t->set_var( "thankhead_value", "" );
373 $t->set_var( "thankbody_value", "" );
374 $t->set_var( "element_list", "" );
375
376 foreach ( $survey->statusOptions() as $statusItem )
377 {
378 $t->set_var( "status_value", $statusItem );
379 $t->parse( "status_item", "status_item_tpl", true );
380 }
381
382 $section_array =& eZSection::getAll();
383
384 foreach ( $section_array as $sectionItem )
385 {
386 $t->set_var( "section_value", $sectionItem->id() );
387 $t->set_var( "section_name", $sectionItem->name() );
388
389 $t->parse( "section_item", "section_item_tpl", true );
390 }
391 }
392
393 // tratamento de erros
394 foreach ($errorMessages as $errorItem )
395 {
396 $t->set_var( "error_message", $errorItem );
397 $t->parse( "error_item", "error_item_tpl", true );
398 }
399 if ( count($errorMessages) > 0 )
400 $t->parse( "error_list", "error_list_tpl" );
401 else
402 $t->set_var( "error_list", "" );
403
404 if ( $survey->status() == "ACTIVE" )
405 {
406 $t->parse( "stats_btn", "stats_btn_tpl" );
407 }
408 else
409 {
410 $t->set_var( "stats_btn", "" );
411 }
412
413 $t->set_var( "survey_id", $survey->id() );
414
415 $t->pparse( "output", "surveyedit_tpl" );
416
417 ?>
$i
$i
Definition: admin/adlist.php:91
$Title
$Title
Definition: articlelistrss.php:36
$types
$types
Definition: articlepreview.php:108
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZQuestion
Definition: ezquestion.php:11
eZQuestion\questionTypes
static questionTypes()
Definition: ezquestion.php:242
eZSection\getAll
static getAll( $offset=0, $limit=40)
Definition: ezsection.php:177
eZSurvey
Definition: ezsurvey.php:8
eZSurvey\numberOfSurveys
static numberOfSurveys()
Definition: ezsurvey.php:276
eZTemplate
Definition: eztemplate.php:107
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$Action
$Action
Definition: companysearch.php:80
$QuestionID
$QuestionID
Definition: default.php:30
$question
$question
Definition: default.php:43
$url_array
$url_array
Definition: ezaddress/admin/datasupplier.php:34
$Preview
$Preview
Definition: ezmessage/user/messageedit.php:121
$EMail
$EMail
Definition: ezuser/admin/userlist.php:77
exit
exit
Definition: folder.php:81
$count
$count
Definition: onlinetypelist.php:108
$question_array
$question_array
Definition: preview.php:88
$survey
if( $Page=="") if(isset( $OK)) if(isset( $NextPage)) if(isset( $PreviousPage)) $survey
Definition: preview.php:72
$t
$t
Definition: surveyedit.php:13
$currentUser
$currentUser
Definition: surveyedit.php:54
$Language
$Language
Definition: surveyedit.php:11
$ini
$ini
Definition: surveyedit.php:10
$errorMessages
$errorMessages
Definition: surveyedit.php:43
$SurveyID
$SurveyID
Definition: surveyedit.php:45
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.