Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezform.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezform.php 8203 2001-11-01 18:02:12Z jhe $
5 //
6 // ezform 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
39 // include_once( "ezform/classes/ezformelement.php" );
40
41 class eZForm
42 {
43
50 function __construct( $id = -1 )
51 {
52 $this->Counter = 0;
53
54 if ( is_array( $id ) )
55 {
56 $this->fill( $id );
57 }
58 else if ( $id != -1 )
59 {
60 $this->ID = $id;
61 $this->get( $this->ID );
62 }
63 }
64
68 function store()
69 {
70 $db =& eZDB::globalDatabase();
71 $db->begin();
72
73 $name =& $db->escapeString( $this->Name );
74 $receiver =& $db->escapeString( $this->Receiver );
75 $cc =& $db->escapeString( $this->CC );
76 $completedPage =& $db->escapeString( $this->CompletedPage );
77 $instructionPage =& $db->escapeString( $this->InstructionPage );
78 $sender =& $db->escapeString( $this->Sender );
79 $sendAsUser =& $this->SendAsUser;
80 $counter =& $this->Counter;
81
82 if ( empty( $this->ID ) )
83 {
84 $db->lock( "eZForm_Form" );
85 $nextID = $db->nextID( "eZForm_Form", "ID" );
86 $res[] = $db->query( "INSERT INTO eZForm_Form
87 ( ID,
88 Name,
89 Receiver,
90 CompletedPage,
91 CC,
92 InstructionPage,
93 Counter,
94 SendAsUser,
95 Sender )
96 VALUES
97 ( '$nextID',
98 '$name',
99 '$receiver',
100 '$completedPage',
101 '$cc',
102 '$instructionPage',
103 '$counter',
104 '$sendAsUser',
105 '$sender' )" );
106
107 $this->ID = $nextID;
108 }
109 elseif ( is_numeric( $this->ID ) )
110 {
111 $res[] = $db->query( "UPDATE eZForm_Form SET
112 Name='$name',
113 Receiver='$receiver',
114 CompletedPage='$completedPage',
115 CC='$cc',
116 InstructionPage='$instructionPage',
117 Counter='$counter',
118 SendAsUser='$sendAsUser',
119 Sender='$sender'
120 WHERE ID='$this->ID'" );
121 }
122
123 eZDB::finish( $res, $db );
124
125 return true;
126 }
127
131 function delete( $formID=-1 )
132 {
133 if ( $formID == -1 )
134 $formID = $this->ID;
135
136 $db =& eZDB::globalDatabase();
137 $db->begin();
138
139 $formElements =& $this->formElements();
140 if ( is_array ( $formElements ) )
141 {
142 foreach ( $formElements as $element )
143 {
144 $element->delete();
145 }
146 }
147 $res = array();
148
149 $res[] = $db->query( "DELETE FROM eZForm_Form WHERE ID=$formID" );
150 $res[] = $db->query( "DELETE FROM eZArticle_ArticleFormDict WHERE FormID=$formID" );
151
152 if ( in_array( false, $res ) )
153 $db->rollback( );
154 else
155 $db->commit();
156
157 // eZDB::finish( $res, $db );
158 }
159
165 function get( $id=-1 )
166 {
167 $db =& eZDB::globalDatabase();
168
169 $ret = false;
170 if ( $id != "" )
171 {
172 $db->array_query( $formArray, "SELECT * FROM eZForm_Form WHERE ID='$id'",
173 0, 1 );
174 if ( count( $formArray ) == 1 )
175 {
176 $this->fill( $formArray[0] );
177 $ret = true;
178 }
179 elseif ( count( $formArray ) != 1 )
180 {
181 $this->ID = 0;
182 }
183 }
184 return $ret;
185 }
186
190 function fill( &$formArray )
191 {
192 $db =& eZDB::globalDatabase();
193 $this->ID = $formArray[$db->fieldName( "ID" )];
194 $this->Name = $formArray[$db->fieldName( "Name" )];
195 $this->CC = $formArray[$db->fieldName( "CC" )];
196 $this->Receiver = $formArray[$db->fieldName( "Receiver" )];
197 $this->CompletedPage = $formArray[$db->fieldName( "CompletedPage" )];
198 $this->InstructionPage = $formArray[$db->fieldName( "InstructionPage" )];
199 $this->Counter = $formArray[$db->fieldName( "Counter" )];
200 $this->SendAsUser = $formArray[$db->fieldName( "SendAsUser" )];
201 $this->Sender = $formArray[$db->fieldName( "Sender" )];
202 }
203
209 static public function &getAll( $offset=0, $limit=20 )
210 {
211 $db =& eZDB::globalDatabase();
212
213 $returnArray = array();
214 $formArray = array();
215
216 if ( $limit == false )
217 {
218 $db->array_query( $formArray, "SELECT ID
219 FROM eZForm_Form
220 ORDER BY Name DESC
221 " );
222
223 }
224 else
225 {
226 $db->array_query( $formArray, "SELECT ID
227 FROM eZForm_Form
228 ORDER BY Name DESC",
229 array( "Limit" => $limit, "Offset" => $offset ) );
230 }
231
232 for ( $i = 0; $i < count( $formArray ); $i++ )
233 {
234 $returnArray[$i] = new eZForm( $formArray[$i][$db->fieldName( "ID" )] );
235 }
236
237 return $returnArray;
238 }
239
243 static public function count()
244 {
245 $db =& eZDB::globalDatabase();
246 $ret = false;
247
248 $db->query_single( $result, "SELECT COUNT(ID) as Count
249 FROM eZForm_Form" );
250 $ret = $result[$db->fieldName( "Count" )];
251 return $ret;
252 }
253
257 function id()
258 {
259 return $this->ID;
260 }
261
265 function &name()
266 {
267 if( !is_null( $this->Name ) && $this->Name != "" )
268 {
269 return htmlspecialchars( $this->Name );
270 }
271 else
272 {
273 return $this->Name;
274 }
275 }
276
280 function &receiver()
281 {
282 if( !is_null( $this->Receiver ) && $this->Receiver != "" )
283 {
284 return htmlspecialchars( $this->Receiver );
285 }
286 else
287 {
288 return $this->Receiver;
289 }
290 }
291
295 function &cc()
296 {
297 if( !is_null( $this->CC ) && $this->CC != "" )
298 {
299 return htmlspecialchars( $this->CC );
300 }
301 else
302 {
303 return $this->CC;
304 }
305 }
306
310 function &completedPage()
311 {
312 return $this->CompletedPage;
313 }
314
318 function &instructionPage()
319 {
320 return $this->InstructionPage;
321 }
322
326 function &counter()
327 {
328 return $this->Counter;
329 }
330
334 function &sender()
335 {
336 return $this->Sender;
337 }
338
342 function &isSendAsUser()
343 {
344 $ret = true;
345
346 if( $this->SendAsUser == 0 )
347 {
348 $ret = false;
349 }
350
351 return $ret;
352 }
353
357 function setName( &$value )
358 {
359 $this->Name = $value;
360 }
361
365 function setSender( &$value )
366 {
367 $this->Sender = $value;
368 }
369
373 function setSendAsUser( $value = true )
374 {
375 if ( $value == false )
376 {
377 $this->SendAsUser = 0;
378 }
379 else
380 {
381 $this->SendAsUser = 1;
382 }
383 }
384
388 function setReceiver( &$value )
389 {
390 $this->Receiver = $value;
391 }
392
396 function setCC( &$value )
397 {
398 $this->CC = $value;
399 }
400
404 function setCompletedPage( &$value )
405 {
406 $this->CompletedPage = $value;
407 }
408
412 function setInstructionPage( &$value )
413 {
414 $this->InstructionPage = $value;
415 }
416
420 function counterAdd()
421 {
422 $this->Counter++;
423 }
424
429 function &formElements()
430 {
431 $returnArray = array();
432 $formArray = array();
433
434 $db =& eZDB::globalDatabase();
435 $db->array_query( $formArray, "SELECT ElementID FROM eZForm_FormElementDict WHERE
436 FormID='$this->ID' ORDER BY Placement" );
437
438 for ( $i = 0; $i < count( $formArray ); $i++ )
439 {
440 $returnArray[$i] = new eZFormElement( $formArray[$i][$db->fieldName( "ElementID" )], true );
441 }
442 return $returnArray;
443 }
444
449 function &formElement( $placement )
450 {
451 $db =& eZDB::globalDatabase();
452 $db->query_single( $element, "SELECT ElementID FROM eZForm_FormElementDict WHERE
453 FormID='$this->ID' AND Placement='$placement'" );
454
455 $return = new eZFormElement( $element[$db->fieldName( "ElementID" )], true );
456
457 return $return;
458 }
459
460
461
465 function &numberOfElements()
466 {
467 $db =& eZDB::globalDatabase();
468 $ret = false;
469
470 $db->query_single( $result, "SELECT COUNT(ElementID) as Count
471 FROM eZForm_FormElementDict WHERE FormID='$this->ID'" );
472 $ret = $result[$db->fieldName( "Count" )];
473 return $ret;
474 }
475
479 function &numberOfTypes()
480 {
481 $db =& eZDB::globalDatabase();
482 $ret = false;
483
484 $db->query_single( $result, "SELECT COUNT(ID) as Count
485 FROM eZForm_FormElementType" );
486 $ret = $result[$db->fieldName( "Count" )];
487
488 return $ret;
489 }
490
494 function addElement( &$object )
495 {
496 if ( is_a( $object, "eZFormElement" ) )
497 {
498 $elementID = $object->id();
499 $elementName = $object->name();
500 $formID = $this->ID;
501
502 $db =& eZDB::globalDatabase();
503 $db->begin();
504 $db->query_single( $result, "SELECT MAX(Placement) as Placement
505 FROM eZForm_FormElementDict WHERE FormID='$formID'" );
506
507 $placement = $result[$db->fieldName( "Placement" )];
508 $placement++;
509 $db->lock( "eZForm_FormElementDict" );
510 $nextID = $db->nextID( "eZForm_FormElementDict", "ID" );
511 $res[] = $db->query( "INSERT INTO eZForm_FormElementDict
512 ( ID, Placement, ElementID, FormID, Name )
513 VALUES
514 ( '$nextID', '$placement', '$elementID', '$formID', '$elementName' )" );
515 eZDB::finish( $res, $db );
516 return true;
517 }
518 }
519
523 function moveUp( $object )
524 {
525 if ( is_a( $object, "eZFormElement" ) )
526 {
527 $db =& eZDB::globalDatabase();
528
529 $formID = $this->id();
530 $elementID = $object->id();
531
532 $db->query_single( $qry, "SELECT Placement FROM eZForm_FormElementDict
533 WHERE ElementID = '$elementID' AND FormID = '$formID' ORDER BY Placement DESC",
534 array( "Limit" => 1, "Offset" => 0) );
535
536 $elementPlacement = $qry[$db->fieldName( "Placement" )];
537
538 $db->query_single( $qry, "SELECT min($db->fieldName( \"Placement\" )) as Placement
539 FROM eZForm_FormElementDict WHERE FormID='$formID'" );
540 $min =& $qry[$db->fieldName( "Placement" )];
541
542 if ( $min == $elementPlacement )
543 {
544 $db->query_single( $qry, "SELECT max($db->fieldName( \"Placement\" ) ) as Placement
545 FROM eZForm_FormElementDict WHERE FormID='$formID'" );
546
547 $newOrder =& $qry[$db->fieldName( "Placement" )];
548
549 $db->query_single( $qry, "SELECT ElementID FROM eZForm_FormElementDict
550 WHERE FormID='$formID' AND Placement='$newOrder'" );
551
552 $oldElementID =& $qry[$db->fieldName( "ElementID" )];
553 }
554 else
555 {
556 $db->query_single( $qry, "SELECT FormID, ElementID, Placement FROM eZForm_FormElementDict
557 WHERE Placement < '$elementPlacement' AND FormID='$formID'
558 ORDER BY Placement DESC",
559 array( "Limit" => 1, "Offset" => 0 ) );
560
561 $newOrder = $qry[$db->fieldName( "Placement" )];
562 $oldElementID = $qry[$db->fieldName( "ElementID" )];
563 }
564
565 $res[] = $db->query( "UPDATE eZForm_FormElementDict SET Placement='$newOrder'
566 WHERE ElementID='$elementID' AND FormID='$formID'" );
567
568 $res[] = $db->query( "UPDATE eZForm_FormElementDict SET Placement='$elementPlacement'
569 WHERE ElementID='$oldElementID' AND FormID='$formID'" );
570 eZDB::finish( $res, $db );
571 }
572 }
573
577 function moveDown( $object )
578 {
579 if ( is_a( $object, "eZFormElement" ) )
580 {
581 $db =& eZDB::globalDatabase();
582 $db->begin();
583
584 $formID = $this->id();
585 $elementID = $object->id();
586
587 $db->query_single( $qry, "SELECT Placement FROM eZForm_FormElementDict
588 WHERE ElementID = '$elementID' AND FormID = '$formID' ORDER BY Placement DESC",
589 array( "Limit" => 1, "Offset" => 0 ) );
590
591 $elementPlacement = $qry[$db->fieldName( "Placement" )];
592
593 $db->query_single( $qry, "SELECT max($db->fieldName( \"Placement\" )) as Placement
594 FROM eZForm_FormElementDict WHERE FormID='$formID'" );
595
596 $max =& $qry[$db->fieldName( "Placement" )];
597
598 if ( $max == $elementPlacement )
599 {
600 $db->query_single( $qry, "SELECT min($db->fieldName( \"Placement\" ) ) as Placement
601 FROM eZForm_FormElementDict WHERE FormID='$formID'" );
602
603 $newOrder =& $qry[$db->fieldName( "Placement" )];
604
605 $db->query_single( $qry, "SELECT ElementID FROM eZForm_FormElementDict
606 WHERE FormID='$formID' AND Placement='$newOrder'" );
607
608 $oldElementID =& $qry[$db->fieldName( "ElementID" )];
609 }
610 else
611 {
612 $db->query_single( $qry, "SELECT FormID, ElementID, Placement FROM eZForm_FormElementDict
613 WHERE Placement > '$elementPlacement' AND FormID='$formID' ORDER BY Placement",
614 array( "Limit" => 1, "Offset" => 0) );
615
616 $newOrder = $qry[$db->fieldName( "Placement" )];
617 $oldElementID = $qry[$db->fieldName( "ElementID" )];
618 }
619
620 $res[] = $db->query( "UPDATE eZForm_FormElementDict SET Placement='$newOrder'
621 WHERE ElementID='$elementID' AND FormID='$formID'" );
622
623 $res[] = $db->query( "UPDATE eZForm_FormElementDict SET Placement='$elementPlacement'
624 WHERE ElementID='$oldElementID' AND FormID='$formID'" );
625
626 eZDB::finish( $res, $db );
627 }
628 }
629
630
631 var $ID;
632 var $Name;
633 var $Receiver;
634 var $CC;
635 var $CompletedPage;
636 var $InstructionPage;
637 var $Counter;
638 var $SendAsUser;
639 var $Sender;
640 }
641
642 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZFormElement
Definition: ezformelement.php:44
eZForm
Definition: ezform.php:42
eZForm\fill
fill(&$formArray)
Definition: ezform.php:190
eZForm\$CC
$CC
Definition: ezform.php:634
eZForm\count
static count()
Definition: ezform.php:243
eZForm\sender
& sender()
Definition: ezform.php:334
eZForm\$ID
$ID
Definition: ezform.php:631
eZForm\__construct
__construct( $id=-1)
Definition: ezform.php:50
eZForm\receiver
& receiver()
Definition: ezform.php:280
eZForm\addElement
addElement(&$object)
Definition: ezform.php:494
eZForm\$Receiver
$Receiver
Definition: ezform.php:633
eZForm\getAll
static & getAll( $offset=0, $limit=20)
Definition: ezform.php:209
eZForm\counter
& counter()
Definition: ezform.php:326
eZForm\instructionPage
& instructionPage()
Definition: ezform.php:318
eZForm\numberOfElements
& numberOfElements()
Definition: ezform.php:465
eZForm\cc
& cc()
Definition: ezform.php:295
eZForm\setCompletedPage
setCompletedPage(&$value)
Definition: ezform.php:404
eZForm\id
id()
Definition: ezform.php:257
eZForm\setCC
setCC(&$value)
Definition: ezform.php:396
eZForm\$Name
$Name
Definition: ezform.php:632
eZForm\completedPage
& completedPage()
Definition: ezform.php:310
eZForm\setName
setName(&$value)
Definition: ezform.php:357
eZForm\$Counter
$Counter
Definition: ezform.php:637
eZForm\formElements
& formElements()
Definition: ezform.php:429
eZForm\$InstructionPage
$InstructionPage
Definition: ezform.php:636
eZForm\setReceiver
setReceiver(&$value)
Definition: ezform.php:388
eZForm\counterAdd
counterAdd()
Definition: ezform.php:420
eZForm\moveDown
moveDown( $object)
Definition: ezform.php:577
eZForm\setSendAsUser
setSendAsUser( $value=true)
Definition: ezform.php:373
eZForm\$CompletedPage
$CompletedPage
Definition: ezform.php:635
eZForm\setSender
setSender(&$value)
Definition: ezform.php:365
eZForm\numberOfTypes
& numberOfTypes()
Definition: ezform.php:479
eZForm\formElement
& formElement( $placement)
Definition: ezform.php:449
eZForm\store
store()
Definition: ezform.php:68
eZForm\isSendAsUser
& isSendAsUser()
Definition: ezform.php:342
eZForm\$SendAsUser
$SendAsUser
Definition: ezform.php:638
eZForm\moveUp
moveUp( $object)
Definition: ezform.php:523
eZForm\$Sender
$Sender
Definition: ezform.php:639
eZForm\name
& name()
Definition: ezform.php:265
eZForm\setInstructionPage
setInstructionPage(&$value)
Definition: ezform.php:412
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$element
if(! $parent) $element
Definition: folder.php:64
$counter
$counter
Definition: frontpage.php:249
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.