Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

formedit.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: formedit.php 8176 2001-11-01 17:01:50Z bf $
5 //
6 // Created on: <12-Jun-2001 13:07:24 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 // include_once( "classes/INIFile.php" );
28 // include_once( "classes/eztemplate.php" );
29 // include_once( "classes/ezhttptool.php" );
30
31 // include_once( "ezform/classes/ezform.php" );
32 // include_once( "ezform/classes/ezformelement.php" );
33 // include_once( "ezform/classes/ezformelementtype.php" );
34 // include_once( "ezmail/classes/ezmail.php" );
35
36 $ini =& eZINI::instance( 'site.ini' );
37
38 if ( isset( $Cancel ) )
39 {
40 eZHTTPTool::header( "Location: /form/form/list/" );
41 exit();
42 }
43
44 $ActionValue="edit";
45
46 $form = new eZForm( $FormID );
47
48 if ( isset( $Action ) && $Action == "up" )
49 {
50 $element = new eZFormElement( $ElementID );
51 $form->moveUp( $element );
52 eZHTTPTool::header( "Location: /form/form/edit/$FormID/" );
53 exit();
54 }
55
56 if ( isset( $Action ) && $Action == "down" )
57 {
58 $element = new eZFormElement( $ElementID );
59 $form->moveDown( $element );
60 eZHTTPTool::header( "Location: /form/form/edit/$FormID/" );
61 exit();
62 }
63
64
65 if ( isset( $DeleteSelected ) )
66 {
67 foreach ( $elementDelete as $deleteMe )
68 {
69 $element = new eZFormElement( $deleteMe );
70 $element->delete();
71 }
72 }
73
74 $errorMessages = array();
75
76 if ( isset( $OK ) || isset( $Update ) || isset( $Preview ) || isset( $NewElement ) )
77 {
78 if ( empty( $formSender ) )
79 {
80 if ( isset( $formSendAsUser ) == false )
81 {
82 $errorMessages[] = "form_must_have_sender";
83 }
84 }
85 else
86 {
87 if ( isset( $formSendAsUser ) )
88 {
89 $errorMessages[] = "form_cant_have_both";
90 }
91 else
92 {
93 if ( eZMail::validate( $formReceiver ) == false )
94 {
95 $errorMessages[] = "form_sender_not_valid";
96 }
97 }
98 }
99
100 if ( empty( $formName ) )
101 {
102 $errorMessages[] = "form_name_not_set";
103 }
104
105 if ( empty( $formReceiver ) )
106 {
107 $errorMessages[] = "form_receiver_not_set";
108 }
109 else
110 {
111 if ( eZMail::validate( $formReceiver ) == false )
112 {
113 $errorMessages[] = "form_receiver_not_valid";
114 }
115 }
116
117 if ( empty( $formCompletedPage ) )
118 {
119 $errorMessages[] = "form_completed_page_not_set";
120 }
121
122 if ( empty( $formCC ) == false )
123 {
124 if ( eZMail::validate( $formCC ) == false )
125 {
126 $errorMessages[] = "form_cc_not_valid";
127 }
128 }
129
130 if ( count( $errorMessages ) == 0 || isset( $NewElement ) || isset( $Update ) )
131 {
132 $form->setName( $formName );
133 $form->setReceiver( $formReceiver );
134 $form->setCC( $formCC );
135 $form->setCompletedPage( $formCompletedPage );
136 $form->setInstructionPage( $formInstructionPage );
137 $form->setSender( $formSender );
138
139 if ( isset( $formSendAsUser ) )
140 {
141 $form->setSendAsUser( true );
142 }
143 else
144 {
145 $form->setSendAsUser( false );
146 }
147
148 $form->store();
149 $FormID = $form->id();
150
151 $existingElementCount = $form->numberOfElements();
152 $existingElementCount++;
153
154 if ( isset( $NewElement ) )
155 {
156 $newElementName =& $ini->variable( "eZFormMain", "DefaultElementName" );
157 $newElementName = $newElementName . " " . $existingElementCount;
158 $element = new eZFormElement();
159 $element->setName( $newElementName );
160 $element->store();
161 }
162
163 if ( isset( $element ) )
164 {
165 $form->addElement( $element );
166 }
167
168 if( isset( $elementID ) )
169 $elementCount = count( $elementID );
170 else
171 $elementCount = false;
172
173 $elementTypeError = false;
174
175 for ( $i = 0; $i < $elementCount; $i++ )
176 {
177 $element = new eZFormElement( $elementID[$i] );
178 $elementType = new eZFormElementType( $elementTypeID[$i] );
179 $element->setElementType( $elementType );
180
181 if ( $elementType->id() == 0 && $elementTypeError == false )
182 {
183 $errorMessages[] = "all_elements_must_have_type";
184 $elementTypeError = true;
185 }
186
187 $element->setName( $elementName[$i] );
188
189 if( isset( $Size[ $i ] ) )
190 $element->setSize( $Size[$i] );
191 else
192 $element->setSize( 0 );
193
194
195 $required = false;
196 $break = false;
197 if ( isset( $elementRequired ) && count( $elementRequired ) > 0 )
198 {
199 foreach ( $elementRequired as $requiredID )
200 {
201 if ( $elementID[$i] == $requiredID )
202 {
203 $element->setRequired( true );
204 $required = true;
205 }
206 }
207 }
208 if ( isset( $ElementBreak ) && count( $ElementBreak ) > 0 )
209 {
210 foreach ( $ElementBreak as $breakID )
211 {
212 if ( $elementID[$i] == $breakID )
213 {
214 $element->setBreak( true );
215 $break = true;
216 }
217 }
218 }
219
220 $element->setBreak( $break );
221 $element->setRequired( $required );
222
223 $element->store();
224 }
225
226 $form->store();
227
228 if ( isset( $OK ) && count( $errorMessages ) == 0 )
229 {
230 eZHTTPTool::header( "Location: /form/form/list/" );
231 exit();
232 }
233
234 if ( isset( $Preview ) && count( $errorMessages ) == 0 )
235 {
236 eZHTTPTool::header( "Location: /form/form/preview/$FormID/" );
237 exit();
238 }
239 }
240 }
241
242 $Language = $ini->variable( "eZFormMain", "Language" );
243
244 $t = new eZTemplate( "kernel/ezform/admin/" . $ini->variable( "eZFormMain", "AdminTemplateDir" ),
245 "kernel/ezform/admin/intl/", $Language, "form.php" );
246
247 $t->set_file( "form_edit_page_tpl", "formedit.tpl" );
248
249 $t->set_block( "form_edit_page_tpl", "form_item_tpl", "form_item" );
250 $t->set_block( "form_edit_page_tpl", "error_list_tpl", "error_list" );
251 $t->set_block( "error_list_tpl", "error_item_tpl", "error_item" );
252 $t->set_block( "form_edit_page_tpl", "no_types_item_tpl", "no_types_item" );
253 $t->set_block( "form_edit_page_tpl", "no_elements_item_tpl", "no_elements_item" );
254 $t->set_block( "form_edit_page_tpl", "element_list_tpl", "element_list" );
255 $t->set_block( "element_list_tpl", "element_item_tpl", "element_item" );
256 $t->set_block( "element_item_tpl", "typelist_item_tpl", "typelist_item" );
257 $t->set_block( "element_item_tpl", "fixed_values_tpl", "fixed_values" );
258 $t->set_block( "element_item_tpl", "size_tpl", "size" );
259 $t->set_block( "element_item_tpl", "break_tpl", "break" );
260
261 $move_item = true;
262 $t->set_block( "element_item_tpl", "item_move_up_tpl", "item_move_up" );
263 $t->set_block( "element_item_tpl", "item_separator_tpl", "item_separator" );
264 $t->set_block( "element_item_tpl", "item_move_down_tpl", "item_move_down" );
265 $t->set_block( "element_item_tpl", "no_item_move_up_tpl", "no_item_move_up" );
266 $t->set_block( "element_item_tpl", "no_item_separator_tpl", "no_item_separator" );
267 $t->set_block( "element_item_tpl", "no_item_move_down_tpl", "no_item_move_down" );
268
269 $t->set_var( "no_types_item", "" );
270 $t->set_var( "no_elements_item", "" );
271 $t->set_var( "element_list", "" );
272 $t->set_var( "element_item", "" );
273 $t->set_var( "typelist_item", "" );
274 $t->set_var( "error_list", "" );
275 $t->set_var( "checked", "" );
276
277 $t->set_var( "form_completed_page", "" );
278 $t->set_var( "form_instruction_page", "" );
279
280 if ( $form->completedPage() )
281 {
282 $t->set_var( "form_completed_page", $form->completedPage() );
283 }
284 else
285 {
286 if ( $ini->variable( "eZFormMain", "UseDefaultRedirectPage" ) == "enabled" )
287 {
288 $t->set_var( "form_completed_page", $ini->variable( "eZFormMain", "DefaultRedirectPage" ) );
289 }
290 }
291
292 if ( $form->instructionPage() )
293 {
294 $t->set_var( "form_instruction_page", $form->instructionPage() );
295 }
296 else
297 {
298 if ( $ini->variable( "eZFormMain", "UseDefaultInstructionPage" ) == "enabled" )
299 {
300 $t->set_var( "form_instruction_page", $ini->variable( "eZFormMain", "DefaultInstructionPage" ) );
301 }
302 }
303
304 if ( isset( $Action ) && $Action != "new" && $form->numberOfTypes() == 0 && !isset( $NewElement ) && !isset( $DeleteSelected ) )
305 {
306 $t->parse( "no_types_item", "no_types_item_tpl" );
307 }
308
309 if ( $form->numberOfElements() == 0 )
310 {
311 if ( $ini->variable( "eZFormMain", "CreateEmailDefaults" ) == "enabled" )
312 {
313 $form->store();
314 $FormID = $form->id();
315 $elementTypeA = new eZFormElementType( 1 );
316 $elementTypeB = new eZFormElementType( 2 );
317 $elementA = new eZFormElement();
318 $elementB = new eZFormElement();
319 $name = $t->Ini->variable( "strings", "subject_label" );
320 $name = $t->Ini->variable( "strings", "content_label" );
321 $elementA->setName( $name );
322 $elementB->setName( $name );
323 $elementA->setElementType( $elementTypeA );
324 $elementB->setElementType( $elementTypeB );
325 $elementA->setRequired( true );
326 $elementB->setRequired( true );
327 $elementA->store();
328 $elementB->store();
329 $form->addElement( $elementA );
330 $form->addElement( $elementB );
331 }
332 else
333 {
334 if ( isset( $Action ) && $Action != "new" && !isset( $NewElement ) && !isset( $DeleteSelected ) )
335 $t->parse( "no_elements_item", "no_elements_item_tpl" );
336 }
337 }
338
339 $t->set_var( "form_id", $FormID );
340 $t->set_var( "form_name", $form->name() );
341 $t->set_var( "form_receiver", $form->receiver() );
342 $t->set_var( "form_cc", $form->cc() );
343 $t->set_var( "form_sender", $form->sender() );
344
345 if ( $form->isSendAsUser() )
346 {
347 $t->set_var( "form_send_as_user", "1" );
348 $t->set_var( "checked", "checked" );
349 }
350 else
351 {
352 $t->set_var( "form_send_as_user", "0" );
353 }
354
355 $elements = $form->formElements();
356 $count = $form->numberOfElements();
357
358 if ( $count > 0 )
359 {
360 $i = 0;
361 foreach ( $elements as $element )
362 {
363 if ( ( $i % 2 ) == 0 )
364 {
365 $t->set_var( "td_class", "bglight" );
366 }
367 else
368 {
369 $t->set_var( "td_class", "bgdark" );
370 }
371 $t->set_var( "element_name", $element->name() );
372 $t->set_var( "element_id", $element->id() );
373
374 $t->set_var( "element_size", $element->size() );
375
376 if ( $element->isRequired() )
377 {
378 $t->set_var( "element_required", "checked" );
379 }
380 else
381 {
382 $t->set_var( "element_required", "" );
383 }
384
385 if ( $element->isBreaking() )
386 {
387 $t->set_var( "element_is_breaking", "checked" );
388 }
389 else
390 {
391 $t->set_var( "element_is_breaking", "" );
392 }
393
394 $currentType = $element->elementType();
395
396 if( !is_null( $currentType ) )
397 $types = $currentType->getAll();
398 else
399 $types = eZFormElementType::getAll();
400
401 $t->set_var( "fixed_values", "" );
402 $t->set_var( "size", "" );
403 $t->set_var( "typelist_item", "" );
404 $t->set_var( "break", "" );
405
406 foreach ( $types as $type )
407 {
408 $t->set_var( "selected", "" );
409
410 if ( !is_null( $currentType ) && $type->id() == $currentType->id() )
411 {
412 $name = $currentType->name();
413 if ( $name == "multiple_select_item" ||
414 $name == "dropdown_item" ||
415 $name == "radiobox_item" ||
416 $name == "checkbox_item" )
417 {
418 $t->parse( "fixed_values", "fixed_values_tpl" );
419 }
420 else
421 $t->set_var( "fixed_values", "" );
422
423 $t->set_var( "selected", "selected" );
424
425 $t->set_var( "element_nr", $i );
426 if ( $name == "text_field_item" )
427 {
428 $t->parse( "size", "size_tpl" );
429 $t->parse( "break", "break_tpl" );
430 }
431 else
432 $t->set_var( "break", "" );
433 }
434
435 $t->set_var( "element_type_id", $type->id() );
436 $t->set_var( "element_type_name", $type->name() );
437 $t->parse( "typelist_item", "typelist_item_tpl", true );
438 }
439
440 $t->set_var( "item_move_up", "" );
441 $t->set_var( "no_item_move_up", "" );
442 $t->set_var( "item_move_down", "" );
443 $t->set_var( "no_item_move_down", "" );
444 $t->set_var( "item_separator", "" );
445 $t->set_var( "no_item_separator", "" );
446
447 if ( isset( $move_item ) )
448 {
449 $t->parse( "item_move_up", "item_move_up_tpl" );
450 }
451
452 if ( isset( $move_item ) )
453 {
454 $t->parse( "item_separator", "item_separator_tpl" );
455 }
456
457 if ( isset( $move_item ) )
458 {
459 $t->parse( "item_move_down", "item_move_down_tpl" );
460 }
461
462 $t->parse( "element_item", "element_item_tpl", true );
463 $i++;
464 }
465
466 $t->parse( "element_list", "element_list_tpl" );
467 }
468
469 if ( count( $errorMessages ) > 0 && !isset( $NewElement ) && !isset( $DeleteSelected ) )
470 {
471 foreach ( $errorMessages as $errorMessage )
472 {
473 $errorMessage =& $t->Ini->variable( "strings", $errorMessage );
474 $t->set_var( "error_message", $errorMessage );
475 $t->parse( "error_item", "error_item_tpl", true );
476 }
477
478 $t->set_var( "form_name", $formName );
479 $t->set_var( "form_receiver", $formReceiver );
480 $t->set_var( "form_cc", $formCC );
481 $t->set_var( "form_completed_page", $formCompletedPage );
482 $t->set_var( "form_sender", $formSender );
483
484 if ( isset( $formSendAsUser ) )
485 {
486 $t->set_var( "checked", "checked" );
487 }
488 $t->set_var( "form_instruction_page", $formInstructionPage );
489
490 $t->parse( "error_list", "error_list_tpl" );
491 }
492
493 $t->parse( "form_item", "form_item_tpl" );
494
495 $t->set_var( "action_value", $ActionValue );
496 $t->set_var( "site_style", $SiteDesign );
497 $t->setAllStrings();
498 $t->pparse( "output", "form_edit_page_tpl" );
499
500 ?>
$i
$i
Definition: admin/adlist.php:91
$types
$types
Definition: articlepreview.php:108
eZFormElementType
Definition: ezformelementtype.php:42
eZFormElementType\getAll
& getAll( $offset=0, $limit=20)
Definition: ezformelementtype.php:162
eZFormElement
Definition: ezformelement.php:44
eZForm
Definition: ezform.php:42
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZMail\validate
static validate( $address)
Definition: ezmail.php:599
eZTemplate
Definition: eztemplate.php:107
$type
$type
Definition: classes/admin/linkselect.php:220
$Action
$Action
Definition: companysearch.php:80
$name
$name
Definition: companytypelist.php:194
$SiteDesign
$SiteDesign
Definition: ezbulkmail/user/datasupplier.php:31
$Preview
$Preview
Definition: ezmessage/user/messageedit.php:121
exit
exit
Definition: folder.php:81
$element
if(! $parent) $element
Definition: folder.php:64
$form
$form
Definition: formedit.php:46
$t
$t
Definition: formedit.php:244
$Language
if(isset( $OK)||isset( $Update)||isset( $Preview)||isset( $NewElement)) $Language
Definition: formedit.php:242
$ini
$ini
Definition: formedit.php:36
$errorMessages
if(isset( $Action) && $Action=="up") if(isset( $Action) && $Action=="down") if(isset( $DeleteSelected)) $errorMessages
Definition: formedit.php:74
$elements
$elements
Definition: formedit.php:355
$ActionValue
if(isset( $Cancel)) $ActionValue
Definition: formedit.php:44
$move_item
$move_item
Definition: formedit.php:261
$count
$count
Definition: formedit.php:356
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.