Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezformelement.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezformelement.php 8485 2001-11-16 12:53:06Z jhe $
5 //
6 // ezformelement 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/ezform.php" );
40 // include_once( "ezform/classes/ezformelementtype.php" );
41 // include_once( "ezform/classes/ezformelementfixedvalue.php" );
42
43 class eZFormElement
44 {
45
52 function __construct( $id=-1 )
53 {
54 $this->Required = 0;
55 $this->Size = 0;
56 $this->Break = 0;
57
58 if ( is_array( $id ) )
59 {
60 $this->fill( $id );
61 }
62 else if ( $id != -1 )
63 {
64 $this->ID = $id;
65 $this->get( $this->ID );
66 }
67 }
68
72 function store()
73 {
74 $db =& eZDB::globalDatabase();
75 $db->begin();
76
77 $name =& $db->escapeString( $this->Name );
78 $size =& $db->escapeString( $this->Size );
79 $required =& $this->Required;
80
81 if ( is_a( $this->ElementType, "eZFormElementType" ) )
82 {
83 $elementTypeID = $this->ElementType->id();
84 }
85 else
86 {
87 $elementTypeID = 0;
88 }
89
90 if ( empty( $this->ID ) )
91 {
92 $db->lock( "eZForm_FormElement" );
93 $nextID = $db->nextID( "eZForm_FormElement", "ID" );
94 $query = "INSERT INTO eZForm_FormElement
95 ( ID, Name, Required, Size, Break, ElementTypeID )
96 VALUES
97 ( '$nextID', '$name', '$required', '$size', '$this->Break', '$elementTypeID' )";
98
99
100 $res[] = $db->query( $query );
101 $this->ID = $nextID;
102 }
103 elseif ( is_numeric( $this->ID ) )
104 {
105 $query = "UPDATE eZForm_FormElement SET
106 Name='$name',
107 Required='$required',
108 Size='$size',
109 Break='$this->Break',
110 ElementTypeID='$elementTypeID'
111 WHERE ID='$this->ID'";
112
113 $res[] = $db->query( $query );
114 }
115
116
117 eZDB::finish( $res, $db );
118 return true;
119 }
120
124 function delete( $elementID = -1 )
125 {
126 if ( $elementID == -1 )
127 $elementID = $this->ID;
128
129 $fixedValues =& $this->fixedValues();
130 if ( $fixedValues )
131 {
132 foreach ( $fixedValues as $value )
133 {
134 $value->delete();
135 }
136 }
137
138 $db =& eZDB::globalDatabase();
139 $db->begin();
140
141 $deleteFormElementQuery = "DELETE FROM eZForm_FormElement WHERE ID='$elementID'";
142 $deleteFormElementDictQuery = "DELETE FROM eZForm_FormElementDict WHERE ElementID='$elementID'";
143
144 $res[] = $db->query( $deleteFormElementDictQuery );
145 $res[] = $db->query( $deleteFormElementQuery );
146
147 eZDB::finish( $res, $db );
148 }
149
155 function get( $id=-1 )
156 {
157 $db =& eZDB::globalDatabase();
158
159 $ret = false;
160 if ( $id != "" )
161 {
162 $db->array_query( $formArray, "SELECT * FROM eZForm_FormElement WHERE ID='$id'",
163 0, 1 );
164 if ( count( $formArray ) == 1 )
165 {
166 $this->fill( formArray: $formArray[0] );
167 $ret = true;
168 }
169 elseif( count( $formArray ) != 1 )
170 {
171 $this->ID = 0;
172 }
173 }
174 return $ret;
175 }
176
180 function fill( &$formArray )
181 {
182 $db =& eZDB::globalDatabase();
183
184 $this->ID = $formArray[$db->fieldName( "ID" )];
185 $this->Name = $formArray[$db->fieldName( "Name" )];
186 $this->Required = $formArray[$db->fieldName( "Required" )];
187 $this->Size = $formArray[$db->fieldName( "Size" )];
188 $this->Break = $formArray[$db->fieldName( "Break" )];
189 $this->ElementType = new eZFormElementType( $formArray[$db->fieldName( "ElementTypeID" )] );
190 }
191
197 function &getAll( $offset=0, $limit=20 )
198 {
199 $db =& eZDB::globalDatabase();
200
201 $returnArray = array();
202 $formArray = array();
203
204 if ( $limit == false )
205 {
206 $db->array_query( $formArray, "SELECT ID
207 FROM eZForm_FormElement
208 ORDER BY Name DESC
209 " );
210
211 }
212 else
213 {
214 $db->array_query( $formArray, "SELECT ID
215 FROM eZForm_FormElement
216 ORDER BY Name DESC",
217 array( "Limit" => $limit, "Offset" => $offset ) );
218 }
219
220 for ( $i = 0; $i < count( $formArray ); $i++ )
221 {
222 $returnArray[$i] = new eZFormElement( $formArray[$i][$db->fieldName( "ID" )] );
223 }
224
225 return $returnArray;
226 }
227
231 function count()
232 {
233 $db =& eZDB::globalDatabase();
234 $ret = false;
235
236 $db->query_single( $result, "SELECT COUNT(ID) as Count
237 FROM eZForm_FormElement" );
238 $ret = $result[$db->fieldName( "Count" )];
239 return $ret;
240 }
241
245 function id()
246 {
247 return $this->ID;
248 }
249
253 function &name()
254 {
255 if( !is_null( $this->Name ) )
256 return htmlspecialchars( $this->Name );
257 else
258 return $this->Name;
259 }
260
264 function size()
265 {
266 return htmlspecialchars( $this->Size );
267 }
268
272 function isRequired()
273 {
274 if ( $this->Required == 0 )
275 {
276 $ret = false;
277 }
278 else
279 {
280 $ret = true;
281 }
282
283 return $ret;
284 }
285
289 function isBreaking()
290 {
291 if ( $this->Break == 0 )
292 {
293 $ret = false;
294 }
295 else
296 {
297 $ret = true;
298 }
299
300 return $ret;
301 }
302
306 function &elementType()
307 {
308 return $this->ElementType;
309 }
310
314 function setName( &$value )
315 {
316 $this->Name = $value;
317 }
318
322 function setSize( $value )
323 {
324 $this->Size = $value;
325 }
326
330 function setRequired( $value = true )
331 {
332 if ( $value == true )
333 {
334 $value = 1;
335 }
336 else
337 {
338 $value = 0;
339 }
340 $this->Required = $value;
341 }
342
346 function setBreak( $value = true )
347 {
348 if ( $value == true )
349 {
350 $value = 1;
351 }
352 else
353 {
354 $value = 0;
355 }
356 $this->Break = $value;
357 }
358
362 function setElementType( &$object )
363 {
364 if ( is_a( $object, "eZFormElementType" ) )
365 {
366 $this->ElementType = $object;
367 }
368 }
369
374 function &forms()
375 {
376 $returnArray = array();
377 $formArray = array();
378
379 $db =& eZDB::globalDatabase();
380 $db->array_query( $formArray, "SELECT FormID FROM eZForm_FormElementDict WHERE ElementID='$this->ID'" );
381
382 for ( $i = 0; $i < count( $formArray ); $i++ )
383 {
384 $returnArray[$i] = new eZFormElement( $formArray[$i][$db->fieldName( "FormID" )], true );
385 }
386 return $returnArray;
387 }
388
389
393 function &numberOfForms()
394 {
395 $db =& eZDB::globalDatabase();
396 $ret = false;
397
398 $db->query_single( $result, "SELECT COUNT(ElementID) as Count
399 FROM eZForm_FormElementDict WHERE ElementID='$this->ID'" );
400 $ret = $result[$db->fieldName( "Count" )];
401
402 return $ret;
403 }
404
408 function &numberOfTypes()
409 {
410 $db =& eZDB::globalDatabase();
411 $ret = false;
412
413 $db->query_single( $result, "SELECT COUNT(ID) as Count
414 FROM eZForm_FormElementType" );
415 $ret = $result[$db->fieldName( "Count" )];
416
417 return $ret;
418 }
419
423 function addValue( &$value )
424 {
425 $db =& eZDB::globalDatabase();
426 $db->begin();
427
428 if ( is_object( $value ) )
429 $value = $value->id();
430
431 $db->lock( "eZForm_FormElementFixedValueLink" );
432 $nextID = $db->nextID( "eZForm_FormElementFixedValueLink", "ID" );
433 $res[] = $db->query( "INSERT INTO eZForm_FormElementFixedValueLink
434 ( ID, ElementID, FixedValueID )
435 VALUES
436 ( '$nextID', '$this->ID', '$value' )" );
437
438 eZDB::finish( $res, $db );
439 return true;
440 }
441
445 function &fixedValues()
446 {
447 $returnArray = array();
448 $formArray = array();
449
450 $db =& eZDB::globalDatabase();
451 $db->array_query( $formArray, "SELECT FixedValueID FROM eZForm_FormElementFixedValueLink WHERE ElementID='$this->ID'" );
452
453 for ( $i = 0; $i < count( $formArray ); $i++ )
454 {
455 $returnArray[$i] = new eZFormElementFixedValue( $formArray[$i][$db->fieldName( "FixedValueID" )], true );
456 }
457 return $returnArray;
458 }
459
460
461 var $ID;
462 var $Name;
463 var $Required;
464 var $ElementType;
465 var $Break;
466 var $Size;
467 }
$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
eZFormElementFixedValue
Definition: ezformelementfixedvalue.php:42
eZFormElementType
Definition: ezformelementtype.php:42
eZFormElement
Definition: ezformelement.php:44
eZFormElement\fixedValues
& fixedValues()
Definition: ezformelement.php:445
eZFormElement\isRequired
isRequired()
Definition: ezformelement.php:272
eZFormElement\$Break
$Break
Definition: ezformelement.php:465
eZFormElement\numberOfForms
& numberOfForms()
Definition: ezformelement.php:393
eZFormElement\forms
& forms()
Definition: ezformelement.php:374
eZFormElement\setName
setName(&$value)
Definition: ezformelement.php:314
eZFormElement\setElementType
setElementType(&$object)
Definition: ezformelement.php:362
eZFormElement\size
size()
Definition: ezformelement.php:264
eZFormElement\setBreak
setBreak( $value=true)
Definition: ezformelement.php:346
eZFormElement\name
& name()
Definition: ezformelement.php:253
eZFormElement\count
count()
Definition: ezformelement.php:231
eZFormElement\$Size
$Size
Definition: ezformelement.php:466
eZFormElement\$ID
$ID
Definition: ezformelement.php:461
eZFormElement\store
store()
Definition: ezformelement.php:72
eZFormElement\__construct
__construct( $id=-1)
Definition: ezformelement.php:52
eZFormElement\id
id()
Definition: ezformelement.php:245
eZFormElement\$ElementType
$ElementType
Definition: ezformelement.php:464
eZFormElement\isBreaking
isBreaking()
Definition: ezformelement.php:289
eZFormElement\numberOfTypes
& numberOfTypes()
Definition: ezformelement.php:408
eZFormElement\getAll
& getAll( $offset=0, $limit=20)
Definition: ezformelement.php:197
eZFormElement\$Name
$Name
Definition: ezformelement.php:462
eZFormElement\fill
fill(&$formArray)
Definition: ezformelement.php:180
eZFormElement\addValue
addValue(&$value)
Definition: ezformelement.php:423
eZFormElement\$Required
$Required
Definition: ezformelement.php:463
eZFormElement\elementType
& elementType()
Definition: ezformelement.php:306
eZFormElement\setRequired
setRequired( $value=true)
Definition: ezformelement.php:330
eZFormElement\setSize
setSize( $value)
Definition: ezformelement.php:322
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$size
if($file_debug) $size
Definition: ezfilemanager/user/filedownload.php:165
$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
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+.