YAP  2.5
 All Data Structures Namespaces Files Functions Variables
CYap_Control.php
Go to the documentation of this file.
1 <?PHP
12 /*
13  * +-------------------------------------------------------------------------+
14  * | Yap, Version 2.5.0 |
15  * +-------------------------------------------------------------------------+
16  * | Copyright (c) 2003-2013 Andrioli Darvin |
17  * | Email darvin@andrioli.com |
18  * | Web http://www.andrioli.com/en/yap.html |
19  * | Download http://www.phpclasses.org/browse.html/package/1391.html |
20  * | |
21  * +-------------------------------------------------------------------------+
22  * | This library is free software; you can redistribute it and/or modify |
23  * | it under the terms of the GNU Lesser General Public License as |
24  * | published by the Free Software Foundation; either version 2 of the |
25  * | License, or (at your option) any later version. |
26  * | |
27  * | This library is distributed in the hope that it will be useful, but |
28  * | WITHOUT ANY WARRANTY; without even the implied warranty of |
29  * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
30  * | Lesser General Public License for more details. |
31  * | |
32  * | You should have received a copy of the GNU Lesser General Public |
33  * | License along with this library; if not, write to the Free Software |
34  * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
35  * +-------------------------------------------------------------------------+
36  */
41 {
46 var $Name;
70 var $ValidIndex=array('autoincrement','values','table','type','apice','size','decimal','name');
97 var $Label;
98 
105 function CYap_control($TableFieldDef=array())
106 {
107 $this->IHaveValue=false;
108 if(count($TableFieldDef)>0)
109  $this->BindField($TableFieldDef);
110 $this->CallBackCheck='';
111 }
112 
118 function BindField($FieldDef)
119 {
120 $this->DbFieldInfo=$FieldDef;
121 if(array_key_exists('name',$this->DbFieldInfo))
122  $this->SetControlName($this->DbFieldInfo['name']);
123 }
124 
130 function SetValue($value)
131 {
132 $this->FieldValue=$value;
133 $this->IHaveValue=true;
134 }
135 
141 function SetControlName($name)
142 {
143 $this->Name=$name;
144 }
150 function SetControlLabel($name)
151 {
152 $this->Label=$name;
153 }
159 function SetCalBackFunc($name)
160 {
161 $this->CallBackCheck=$name;
162 }
170 function SetProperty($Property,$value)
171 {
172 // TODO use reflection to check whether the property exists
173 eval('$this->'.$Property.'=$value;');
174 }
175 
181 function ParseResponse()
182 {
183 if(array_key_exists($this->Name,$_SERVER))
184  {
185  $this->SetValue($_SERVER[$this->Name]);
186  }
187 $this->_InternalCheck();
188 }
189 
196 function _InternalCheck()
197 {
198 $this->IsValidInput=true;
199 }
200 
201 
207 function IsValid()
208 {
209 return($this->IsValidInput);
210 }
216 function GetSqlData()
217 {
218 if(!$this->HasValue())
219  trigger_error('Field '.$this->Name.' unset',E_USER_ERROR);
220 return($this->DbFieldInfo['apici'].$this->FieldValue.$this->DbFieldInfo['apici']);
221 }
222 
228 function GetSqlFieldName()
229 {
230 return($this->DbFieldInfo['name']);
231 }
232 
239 function GetInfo($InfoName)
240 {
241 if(!in_array($InfoName,$this->ValidIndex))
242  trigger_error('Unexpected index '.$InfoName.' requested',E_USER_ERROR);
243 if(array_key_exists($InfoName,$this->DbFieldInfo))
244  return($this->DbFieldInfo[$InfoName]);
245 else
246  trigger_error('Iindex '.$InfoName.' doesn\'t set',E_USER_ERROR);
247 }
248 
249 // Abstract function
250 function GetHeaderCode()
251 {
252 return('');
253 }
254 
259 function HasValue()
260 {
261 return($this->IHaveValue);
262 }
263 
264 function GetValue()
265 {
266 return($this->FieldValue);
267 }
272 function GetJsCode()
273 {
274 return('');
275 }
276 
282 {
283 return('');
284 }
285 
293 function Draw($Show=true)
294 {
295 }
303 function DrawLabel($Show=true)
304 {
305 return($this->Label);
306 }
313 function IsHidden()
314 {
315 return(false);
316 }
317 
318 } // class Yap_Controll
319 
320 /********************************************************
321  * T E X T B O X
322  ********************************************************/
323 
329 {
330 
331 function CYap_TextBox($TableFieldDef=array())
332 {
333 parent::CYap_Control($TableFieldDef);
334 }
335 
336 
343 function Draw($Show=true)
344 {
345 if($this->Name=='')
346  trigger_error('Control without name!',E_USER_ERROR);
347 $width=$this->DbFieldInfo['size'];
348 $Text='<input type=text name='.$this->Name.' size='.$width.' ';
349 if($this->FieldValue!='')
350  $Text.='value=\''.htmlentities($this->FieldValue,ENT_QUOTES).'\'';
351 $Text.='>';
352 if($Show)
353  echo $Text;
354 return($Text);
355 }
356 } // CYap_TextBox
357 
361 class CYAP_ViewTextBox extends CYAP_Control
362 {
363 var $Size;
364 
365 function CYAP_ViewTextBox($TableFieldDef=array())
366 {
367 parent::CYap_Control($TableFieldDef);
368 }
369 
370 
371 //
372 function Draw($Show=true)
373 {
374 if($this->Name=='')
375  trigger_error('Control without name!',E_USER_ERROR);
376 $Text='<input type=text name='.$this->Name.' size='.$this->Size.' ';
377 if($this->FieldValue!='')
378  $Text.='Value=\''.htmlentities($this->FieldValue,ENT_QUOTES).'\'';
379 $Text.='>';
380 return($Text);
381 }
382 function DrawLabel($Show=true)
383 {
384 return($this->Label);
385 }
386 
387 // The view control create only the HTML code, it doesn't manage the
388 // logic behind it.
389 
391 {
392 return('');
393 }
394 }
399 {
402 
403 function CYAP_ViewTextRange($TableFieldDef=array())
404 {
405 parent::CYAP_ViewTextBox($TableFieldDef);
406 }
412 function SetValueTo($value)
413 {
414 $this->FieldValueTo=$value;
415 }
421 function SetControlNameTo($name)
422 {
423 $this->NameTo=$name;
424 }
425 //
426 function Draw($Show=true)
427 {
428 if($this->Name=='')
429  trigger_error('Control without name!',E_USER_ERROR);
430 $Text='<input type=text name='.$this->Name.' size='.$this->Size.' ';
431 if($this->FieldValue!='')
432  $Text.='Value=\''.htmlentities($this->FieldValue,ENT_QUOTES).'\'';
433 $Text.='>';
434 $Text.=' to ';
435 $Text.='<input type=text name='.$this->NameTo.' size='.$this->Size.' ';
436 if($this->FieldValueTo!='')
437  $Text.='Value=\''.htmlentities($this->FieldValueTo,ENT_QUOTES).'\'';
438 $Text.='>';
439 return($Text);
440 }
441 function DrawLabel($Show=true)
442 {
443 return($this->Label);
444 }
445 
446 // The view control create only the HTML code, it doesn't manage the
447 // logic behind it.
448 
450 {
451 return('');
452 }
453 }
454 
455 /********************************************************
456  * S E L E C T B O X
457  ********************************************************/
462 {
468 function CYap_SelectBox($TableFieldDef=array())
469 {
470 parent::CYap_Control($TableFieldDef);
471 $this->Choices=array();
472 }
473 
479 function SetChoices($tblChoices=array())
480 {
481 $this->Choices=$tblChoices;
482 }
483 
490 function Draw($Show=true)
491 {
492 // $width=$this->DbFieldInfo['size'];
493 if($this->Name=='')
494  trigger_error('Control without name!',E_USER_ERROR);
495 $HtmlCode='';
496 $HtmlCode.='<SELECT name='.$this->Name.' >'.chr(13);
497 foreach($this->Choices as $key => $Value)
498  {
499  $HtmlCode.="<option ";
500  if ($this->FieldValue==(string)$key) {
501  $HtmlCode.="SELECTED";
502  }
503  $HtmlCode.=" value='".$key."'";
504  $HtmlCode.=" >".$this->Choices[$key]."</option>".chr(13);
505  }
506 $HtmlCode.="</SELECT>".chr(13);
507 if($Show)
508  echo $HtmlCode;
509 return($HtmlCode);
510 }
511 
512 }
513 
522 {
523 
524 function CYap_Preset($TableFieldDef=array())
525 {
526 parent::CYap_Control($TableFieldDef);
527 }
528 
535 function ParseResponse()
536 {
537 $this->IsValidInput=true;
538 }
539 
546 function Draw($Show=true)
547 {
548 if($this->Name=='')
549  trigger_error('Control without name!',E_USER_ERROR);
550 $Text='<input type=hidden name='.$this->Name.' ';
551 if($this->FieldValue!='')
552  $Text.='value=\''.htmlentities($this->FieldValue,ENT_QUOTES).'\'';
553 $Text.='>';
554 if($Show)
555  echo $Text;
556 return($Text);
557 }
558 
565 function IsHidden()
566 {
567 return(true);
568 }
569 
570 } // CYap_Preset
571 
572 
573 /********************************************************
574  * S U B M I T B U T T O N
575  ********************************************************/
579 class CYAP_ViewSubmitButton extends CYAP_Control
580 {
581 var $Size;
582 
583 function CYAP_ViewSubmitButton($TableFieldDef=array())
584 {
585 parent::CYap_Control($TableFieldDef);
586 }
587 
588 
589 //
590 function Draw($Show=true)
591 {
592 $Text="<input type=submit value='".$this->Label."'>";
593 return($Text);
594 }
595 
596 function DrawLabel($Show=true)
597 {
598 return('');
599 }
600 
601 // The view control create only the HTML code, it doesn't manage the
602 // logic behind it.
603 
605 {
606 return('');
607 }
608 }
613 {
621 
622 function CYap_ViewDate($TableFieldDef=array())
623 {
627 parent::CYap_Control($TableFieldDef);
628 }
636 function SetProperty($Property,$value)
637 {
638 parent::SetProperty($Property,$value);
639 /*
640  * Format validation.
641  * Supported format:
642  * d.m.Y
643  * m.d.Y
644  * Y.m.d
645  */
646 if(strtolower($Property)=='showformat')
647  {
648  if(preg_match('/^d.m.Y$/',$value))
649  {
650  $cond='/^d(.*)m(.*)Y$/';
651  $replace='dd${1}mm${2}yyyy';
652  $this->JsFormat=preg_replace($cond,$replace,$value);
653  }
654  elseif(preg_match('/^Y.m.d$/',$value))
655  {
656  $cond='/^Y(.*)m(.*)d$/';
657  $replace='yyyy${1}mm${2}dd';
658  $this->JsFormat=preg_replace($cond,$replace,$value);
659  }
660  elseif(preg_match('/^m.d.Y$/',$value))
661  {
662  $cond='/^m(.*)d(.*)Y$/';
663  $replace='mm${1}dd${2}yyyy';
664  $this->JsFormat=preg_replace($cond,$replace,$value);
665  }
666  else
667  {
668  $this->JsFormat='dd/mm/yyyy';
669  }
670  }
671 }
682 function Draw($Show=true)
683 {
684 if($this->Name=='')
685  trigger_error('Control without name!',E_USER_ERROR);
686 $Text='<input type=text name='.$this->Name.' id=viewdate_'.$this->Name.' ';
687 if($this->FieldValue!='')
688  $Text.='value=\''.htmlentities(date($this->ShowFormat,$this->FieldValue),ENT_QUOTES).'\'';
689 $Text.='>';
690 $Text.='<input type="button" value="Cal" onclick="displayCalendar(\'viewdate_'.$this->Name.'\',\''.$this->JsFormat.'\',this)">';
691 if($Show)
692  echo $Text;
693 return($Text);
694 }
695 function GetJsCode()
696 {
697 $txt='
698 <SCRIPT type="text/javascript" src="dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
699 <script type="text/javascript">
700  var pathToImages = \'dhtmlgoodies_calendar/images/\'; // Relative to your HTML file
701  </script>
702 ';
703 return($txt);
704 }
705 }
709 class CYap_ViewOptRegex extends CYap_Control
710 {
717 var $UseRegex;
718 function CYap_ViewOptRegex($TableFieldDef=array())
719 {
720 parent::CYap_Control($TableFieldDef);
721 }
722 
723 function Draw($Show=true)
724 {
725 if($this->Name=='')
726  trigger_error('Control without name!',E_USER_ERROR);
727 $Text='<input type=text name='.$this->Name.' ';
728 if($this->FieldValue!='')
729  $Text.='value=\''.htmlentities($this->FieldValue,ENT_QUOTES).'\'';
730 $Text.='>';
731 $Text.='&nbsp;&nbsp; <input type="checkbox" name='.$this->Name.'_compWord ';
732 if($this->UseRegex=='0')
733  $Text.=' CHECKED ';
734 $Text.='> Exact match';
735 if($Show)
736  echo $Text;
737 return($Text);
738 }
739 
740 }
741 ?>