Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezformrenderer.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezformrenderer.php 9785 2003-02-28 08:31:05Z br $
5 //
6 // eZFormRenderer class
7 //
8 // Created on: <11-Jun-2001 12:07:57 pkej>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
38 // include_once( "classes/INIFile.php" );
39 // include_once( "classes/eztemplate.php" );
40 // include_once( "classes/ezhttptool.php" );
41
42 // include_once( "ezform/classes/ezform.php" );
43 // include_once( "ezform/classes/ezformelement.php" );
44 // include_once( "ezform/classes/ezformelementtype.php" );
45 // include_once( "ezmail/classes/ezmail.php" );
46 // include_once( "ezuser/classes/ezuser.php" );
47
48
49 class eZFormRenderer
50 {
51
55 function __construct( $form = "" )
56 {
57 $ini =& eZINI::instance( 'site.ini' );
58 if ( is_a( $form, "eZForm" ) )
59 {
60 $this->Form = $form;
61 }
62 $Language = $ini->variable( "eZFormMain", "Language" );
63
64 $this->Template = new eZTemplate( "kernel/ezform/admin/" . $ini->variable( "eZFormMain", "AdminTemplateDir" ),
65 "kernel/ezform/admin/intl/", $Language, "form.php" );
66
67 $this->Template->setAllStrings();
68
69 $this->Template->set_file( "form_renderer_page_tpl", "formrenderer.tpl" );
70
71 $this->Template->set_block( "form_renderer_page_tpl", "text_field_item_tpl", "text_field_item" );
72 $this->Template->set_block( "form_renderer_page_tpl", "text_area_item_tpl", "text_area_item" );
73 $this->Template->set_block( "form_renderer_page_tpl", "multiple_select_item_tpl", "multiple_select_item" );
74 $this->Template->set_block( "multiple_select_item_tpl", "multiple_select_item_sub_item_tpl", "multiple_select_item_sub_item" );
75 $this->Template->set_block( "form_renderer_page_tpl", "dropdown_item_tpl", "dropdown_item" );
76 $this->Template->set_block( "dropdown_item_tpl", "dropdown_item_sub_item_tpl", "dropdown_item_sub_item" );
77
78 $this->Template->set_block( "form_renderer_page_tpl", "radiobox_item_tpl", "radiobox_item" );
79 $this->Template->set_block( "radiobox_item_tpl", "radiobox_item_sub_item_tpl", "radiobox_item_sub_item" );
80
81 $this->Template->set_block( "form_renderer_page_tpl", "checkbox_item_tpl", "checkbox_item" );
82 $this->Template->set_block( "checkbox_item_tpl", "checkbox_item_sub_item_tpl", "checkbox_item_sub_item" );
83
84 $this->Template->set_block( "form_renderer_page_tpl", "form_list_tpl", "form_list" );
85 $this->Template->set_block( "form_list_tpl", "form_item_tpl", "form_item" );
86 $this->Template->set_block( "form_item_tpl", "break_tpl", "break" );
87 $this->Template->set_block( "form_list_tpl", "form_start_tag_tpl", "form_start_tag" );
88 $this->Template->set_block( "form_list_tpl", "form_end_tag_tpl", "form_end_tag" );
89 $this->Template->set_block( "form_list_tpl", "form_buttons_tpl", "form_buttons" );
90 $this->Template->set_block( "form_list_tpl", "form_sender_tpl", "form_sender" );
91 $this->Template->set_block( "form_list_tpl", "form_instructions_tpl", "form_instructions" );
92 $this->Template->set_block( "form_renderer_page_tpl", "error_list_tpl", "error_list" );
93 $this->Template->set_block( "error_list_tpl", "error_item_tpl", "error_item" );
94
95 $this->Template->set_var( "error_list", "" );
96 $this->Template->set_var( "error_item", "" );
97 $this->Template->set_var( "form_start_tag", "" );
98 $this->Template->set_var( "form_sender", "" );
99 $this->Template->set_var( "form_end_tag", "" );
100 $this->Template->set_var( "form_buttons", "" );
101 $this->Template->set_var( "form_list", "" );
102 $this->Template->set_var( "form_item", "" );
103 $this->Template->set_var( "text_field_item", "" );
104 $this->Template->set_var( "text_area_item", "" );
105 $this->Template->set_var( "form_instructions", "" );
106 $this->Template->set_var( "form_sender_value", "" );
107
108
109 global $GlobalSectionID, $SectionIDOverride;
110
111 if ( isset( $SectionIDOverride ) )
112 {
113 $this->Template->set_var( "section_id", $SectionIDOverride );
114 }
115 else
116 {
117 $this->Template->set_var( "section_id", $GlobalSectionID );
118 }
119
120 }
121
125 function &renderElement( $element )
126 {
127 $output = "";
128 $target = '';
129 if ( is_a( $element, "eZFormElement" ) )
130 {
131 $subItems =& $element->fixedValues();
132 $this->Template->set_var( "sub_item", "" );
133
134 $type =& $element->elementType();
135
136 if( !is_null( $type ) )
137 $name = $type->name();
138 else
139 $name = false;
140
141 $elementType = $element->elementType();
142 if( !is_null( $elementType ) )
143 {
144 $type = $elementType->name();
145 $type = str_replace( " ", "_", $type );
146 }
147 else
148 {
149 $type = '';
150 }
151
152 $elementName = "eZFormElement_" . $element->id();
153
154 $elementValue = '';
155 global $$elementName;
156 if ( isset( $$elementName ) )
157 $elementValue = $$elementName;
158
159 $this->Template->set_var( "field_name", $elementName );
160 $this->Template->set_var( "field_value", $elementValue );
161
162 if ( $element->size() == 0 )
163 {
164 $this->Template->set_var( "element_size", 40 );
165 }
166 else
167 {
168 $this->Template->set_var( "element_size", $element->size() );
169 }
170
171 if ( $element->isBreaking() )
172 {
173 $this->Template->set_var( "break", "<br>" );
174 }
175 else
176 {
177 $this->Template->set_var( "break", "" );
178 }
179
180 $this->Template->set_var( $name . "_sub_item", "" );
181
182 foreach ( $subItems as $subItem )
183 {
184 $this->Template->set_var( "sub_value", $subItem->value() );
185 $this->Template->parse( $name . "_sub_item", $name . "_sub_item_tpl", true );
186 }
187
188 if( !is_null( $$elementName ) )
189 {
190 $elementValue = str_replace( "eZFormElement_", "", $$elementName );
191 }
192 else
193 {
194 $elementValue = $elementName;
195 }
196
197 if ( trim( $type ) != "" )
198 $output =& $this->Template->parse( $target, $type . "_tpl" );
199 }
200
201 return $output;
202 }
203
207 function &renderForm( $form = "", $addFormTags = true, $addButtons = true )
208 {
209 $output = "";
210 $render = false;
211 $target = '';
212
213 if ( is_a( $form, "eZForm" ) )
214 {
215 $this->Form =& $form;
216 $render = true;
217 }
218 else
219 {
220 if ( is_a( $this->Form, "eZForm" ) )
221 {
222 $render = true;
223 }
224 }
225
226 if ( $render == true )
227 {
228 $elements =& $this->Form->formElements();
229
230 $elementCounter = 0;
231
232 $this->Template->set_var( "form_id", $this->Form->id() );
233 $this->Template->set_var( "form_name", $this->Form->name() );
234 $this->Template->set_var( "form_completed_page", $this->Form->completedPage() );
235 if ( $this->Form->instructionPage() != "" )
236 {
237 $this->Template->set_var( "form_instruction_page", $this->Form->instructionPage() );
238 $this->Template->parse( "form_instructions", "form_instructions_tpl" );
239 }
240
241 $maxBreakCount = 1;
242 $breakCount = 1;
243 $lastBreaked = true;
244 // count the max number of unbreaked elements
245 foreach ( $elements as $element )
246 {
247 $eType = $element->elementType();
248
249 if ( $element->isBreaking() or ( !is_null( $eType ) && $eType->name() != "text_field_item" ) )
250 {
251 $lastBreaked = true;
252 $breakCount = 1;
253 }
254 else
255 {
256 $lastBreaked = false;
257 }
258
259 if ( $lastBreaked == false )
260 {
261 $breakCount++;
262 $maxBreakCount = max( $maxBreakCount, $breakCount );
263 }
264 }
265
266 foreach ( $elements as $element )
267 {
268 $elementCounter++;
269
270 $eType = $element->elementType();
271
272 $output = $this->renderElement( $element );
273
274 $this->Template->set_var( "element", $output );
275 $this->Template->set_var( "element_name", $element->name() );
276
277
278 if ( !is_null( $eType ) && $eType->name() != "text_field_item" )
279 $this->Template->set_var( "colspan", " colspan=\"$maxBreakCount\"" );
280 else
281 $this->Template->set_var( "colspan", " colspan=\"1\"" );
282
283
284 if ( ( !is_null( $eType ) && $eType->name() != "text_field_item" ) or $element->isBreaking() )
285 {
286 $this->Template->parse( "break", "break_tpl" );
287 }
288 else
289 {
290 $this->Template->set_var( "break", "" );
291 }
292 $this->Template->parse( "form_item", "form_item_tpl", true );
293 }
294
295
296 if ( $form->isSendAsUser() )
297 {
298 global $formSender;
299 if ( $formSender )
300 {
301 $this->Template->set_var( "form_sender_value", $formSender );
302 }
303 else
304 {
305 if ( $user =& eZUser::currentUser() )
306 {
307 $this->Template->set_var( "form_sender", $user->eMail() );
308 }
309 else
310 {
311 $this->Template->set_var( "form_sender", "" );
312 }
313 }
314 $this->Template->parse( "form_sender", "form_sender_tpl" );
315 }
316
317 if ( $elementCounter != 0 )
318 {
319 if ( $addFormTags == true )
320 {
321 $this->Template->parse( "form_start_tag", "form_start_tag_tpl" );
322 $this->Template->parse( "form_end_tag", "form_end_tag_tpl" );
323 }
324
325 if ( $addButtons == true )
326 {
327 $this->Template->parse( "form_buttons", "form_buttons_tpl" );
328 }
329 $output = $this->Template->parse( $target, "form_list_tpl" );
330 }
331 }
332
333 return $output;
334 }
335
339 function verifyForm()
340 {
341 global $FormID;
342 global $formName;
343 global $formSender;
344 global $redirectTo;
345
346 $output = "";
347 $target = false;
348 $errorMessages = array();
349 $errorMessagesAdditionalInfo = array();
350 $ini =& eZINI::instance( 'site.ini' );
351
352 $this->Form = new eZForm( $FormID );
353
354 $elements = $this->Form->formElements();
355
356 if ( $this->Form->isSendAsUser() )
357 {
358 if ( isset( $formSender ) )
359 {
360 if ( eZMail::validate( $formSender ) == false )
361 {
362 $errorMessages[] = "form_sender_not_valid";
363 $errorMessagesAdditionalInfo[] = "";
364 }
365 }
366 else
367 {
368 $errorMessages[] = "form_sender_missing";
369 $errorMessagesAdditionalInfo[] = "";
370 }
371 }
372
373 foreach ( $elements as $element )
374 {
375 $elementName = "eZFormElement_" . $element->id();
376
377 global $$elementName;
378
379 $value = $$elementName;
380
381 if ( $element->isRequired() == true )
382 {
383 if ( empty( $value ) )
384 {
385 $errorMessages[] = "required_field";
386 $errorMessagesAdditionalInfo[] = "\"" . $element->name() . "\"" ;
387 }
388 }
389 }
390
391 if ( count( $errorMessages ) > 0 )
392 {
393 $i = 0;
394 foreach ( $errorMessages as $errorMessage )
395 {
396 $errorMessage = $this->Template->Ini->variable( "strings", $errorMessage );
397 $this->Template->set_var( "error_message", $errorMessage );
398 $this->Template->set_var( "error_value", $errorMessagesAdditionalInfo[$i] );
399 $this->Template->parse( "error_item", "error_item_tpl", true );
400 $i++;
401 }
402
403 $output = $this->Template->parse( $target, "error_list_tpl" );
404 }
405
406 return $output;
407 }
408
412 function sendForm()
413 {
414 global $FormID;
415 global $formName;
416 global $formSender;
417 global $redirectTo;
418
419 $formSent = false;
420
421 $form = new eZForm( $FormID );
422
423 $ini =& eZINI::instance( 'site.ini' );
424 $Language = $ini->variable( "eZFormMain", "Language" );
425
426 $emailDefaults = false;
427
428 if ( $ini->variable( "eZFormMain", "CreateEmailDefaults" ) == "enabled" )
429 {
430 $emailDefaults = true;
431 }
432
433 $elements = $form->formElements();
434
435 $mail = new eZMail();
436
437 $content = "";
438
439 foreach ( $elements as $element )
440 {
441 $elementName = "eZFormElement_" . $element->id();
442
443 global $$elementName;
444 $value = $$elementName;
445
446
447 // convert array to multiple textlines.
448 $tmpValue = "";
449 if ( is_array( $value ) )
450 {
451 foreach ( $value as $v )
452 {
453 $tmpValue .= $v . "\n";
454 }
455 $value = $tmpValue;
456 }
457
458 if ( $emailDefaults == true )
459 {
460 if ( $element->name() == $this->Template->Ini->variable( "strings", "subject_label" ) )
461 {
462 $mail->setSubject( $value );
463 }
464 else
465 {
466 $content .= $element->name() . ":\n " . $value . "\n\n";
467 }
468 }
469 else
470 {
471 $content .= $element->name() . ":\n " . $value . "\n\n";
472 }
473 }
474
475 if ( $emailDefaults == false )
476 {
477 $mail->setSubject( $form->name() );
478 }
479
480 $t = new eZTemplate( "kernel/ezform/user/" . $ini->variable( "eZFormMain", "TemplateDir" ),
481 "kernel/ezform/user/intl/", $Language, "form.php" );
482
483 $t->set_file( array(
484 "form_mail_tpl" => "emailtemplate.tpl"
485 ) );
486
487
488 $t->set_var( "content", $content );
489
490 $t->setAllStrings();
491
492 $formatedContent = $t->parse( "output", "form_mail_tpl" );
493
494 $mail->setBody( stripslashes($formatedContent) );
495
496 if ( $form->isSendAsUser() )
497 {
498 $mail->setFrom( $formSender );
499 $mail->setCC( $form->CC() . ", " . $formSender );
500 }
501 else
502 {
503 $mail->setFrom( $form->sender() );
504 $mail->setCC( $form->CC() . ", " . $form->sender() );
505 }
506
507 $mail->setTo( $form->receiver() );
508
509 $mail->send();
510 $formSent = true;
511
512 if ( $formSent )
513 {
514 if ( $form->completedPage() == "" )
515 {
516 eZHTTPTool::header( "Location: /" );
517 }
518 else
519 {
520 $redirectTo = $form->completedPage();
521 eZHTTPTool::header( "Location: $redirectTo" );
522 }
523 exit();
524 }
525 }
526
527 var $Template;
528 var $Form;
529 }
530
531 ?>
$i
$i
Definition: admin/adlist.php:91
Template
Definition: template.inc.php:13
Template\set_var
set_var($varname, $value="")
Definition: template.inc.php:129
Template\set_block
set_block($parent, $handle, $name="")
Definition: template.inc.php:106
Template\set_file
set_file($handle, $filename="")
Definition: template.inc.php:81
Template\parse
parse( $target, $handle, $append=false)
Definition: template.inc.php:178
eZFormRenderer
Definition: ezformrenderer.php:50
eZFormRenderer\renderElement
& renderElement( $element)
Definition: ezformrenderer.php:125
eZFormRenderer\__construct
__construct( $form="")
Definition: ezformrenderer.php:55
eZFormRenderer\verifyForm
verifyForm()
Definition: ezformrenderer.php:339
eZFormRenderer\$Template
$Template
Definition: ezformrenderer.php:527
eZFormRenderer\sendForm
sendForm()
Definition: ezformrenderer.php:412
eZFormRenderer\renderForm
& renderForm( $form="", $addFormTags=true, $addButtons=true)
Definition: ezformrenderer.php:207
eZFormRenderer\$Form
$Form
Definition: ezformrenderer.php:528
eZForm
Definition: ezform.php:42
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZMail
Definition: ezmail.php:57
eZMail\validate
static validate( $address)
Definition: ezmail.php:599
eZTemplate
Definition: eztemplate.php:107
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$t
foreach( $Modules as $module) if(isset( $ItemInsert)) $t
Definition: classes/admin/linklist.php:168
$Language
$Language
Definition: classes/admin/linklist.php:65
$ini
$ini
Definition: classes/admin/linklist.php:64
$type
$type
Definition: classes/admin/linkselect.php:220
$name
$name
Definition: companytypelist.php:194
$GlobalSectionID
$GlobalSectionID
Definition: ezad/user/datasupplier.php:28
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
$content
$content
Definition: ezimagecatalogue/admin/filedownload.php:53
exit
exit
Definition: folder.php:81
$element
if(! $parent) $element
Definition: folder.php:64
$form
$form
Definition: formedit.php:46
$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
$output
$output
Definition: formpreview.php:81
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.