YAP  2.5
 All Data Structures Namespaces Files Functions Variables
CYap_Form.php
Go to the documentation of this file.
1 <?PHP
9 /*
10  * +-------------------------------------------------------------------------+
11  * | Yap, Version 2.5.0 |
12  * +-------------------------------------------------------------------------+
13  * | Copyright (c) 2003-2013 Andrioli Darvin |
14  * | Email <darvin (inside) andrioli (dot) com> |
15  * | Web http://www.andrioli.com/en/yap.html |
16  * | Download http://www.phpclasses.org/browse.html/package/1391.html |
17  * | |
18  * +-------------------------------------------------------------------------+
19  * | This library is free software; you can redistribute it and/or modify |
20  * | it under the terms of the GNU Lesser General Public License as |
21  * | published by the Free Software Foundation; either version 2 of the |
22  * | License, or (at your option) any later version. |
23  * | |
24  * | This library is distributed in the hope that it will be useful, but |
25  * | WITHOUT ANY WARRANTY; without even the implied warranty of |
26  * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27  * | Lesser General Public License for more details. |
28  * | |
29  * | You should have received a copy of the GNU Lesser General Public |
30  * | License along with this library; if not, write to the Free Software |
31  * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
32  * +-------------------------------------------------------------------------+
33  */
34 
38 class CYap_form {
39 
50 var $Lang;
51 function CYap_form($Controls,$modify_info,$LangName)
52 {
53 $this->Controls=$Controls;
54 $this->Lang=parse_ini_file($LangName);
55 $this->modify_info=$modify_info;
56 }
57 
64 function MakeForm($Add,$KeyValue,$WrongFields,$cmdAbort)
65 {
66 // show the box
67 if($Add)
68  $msg='<h2 align=center>'.$this->Lang['NewRow'].'</h2>';
69 else
70  $msg='<h2 align=center>'.$this->Lang['ModifyRow'].'</h2>';
71 $msg.='
72  <table border=1 cellpadding=0 cellspacing=0 align=center>
73  <tr><td>';
74 
75 $msg.='</td></tr>
76  <tr><td>
77  <form action='.$_SERVER['PHP_SELF'].' method=post >';
78 if($Add)
79  $msg.='<input type=hidden name=ev value=YAP_DOSAVEROW>';
80 else
81  $msg.='<input type=hidden name=ev value=YAP_DOMODIFY>';
82 if(!$Add)
83  $msg.='<input type=hidden name=id value=\''.htmlentities($KeyValue,ENT_QUOTES).'\'>';
84 
85 $js=''; // javascript code
86 foreach($this->Controls as $Key => $obj)
87  {
88  $js.=$obj->GetJsCode();
89  // I don't ask the autoincrement field, and the key field if i'm updating the row
90  // and the preset field (hidden field)
91  if((($Key!=$this->modify_info['keyfield']&&!$Add)||$Add)
92  && !$obj->GetInfo('autoincrement')
93  && !$obj->IsHidden())
94  {
95  //var_dump($Key);
96  $msg.='<tr><td>'.$Key.'</td><td>';
97  $msg.=$obj->Draw(false);
98  // Show some text if the current field has a wrong value (i.e from a previous input form)
99  if(array_key_exists($Key,$WrongFields))
100  $msg.=$WrongFields[$Key];
101  $msg.='</td><td>'.$obj->GetInfo('type').'</td></tr>';
102  }
103  // Draw the hidden field (it writes <input type hidden....)
104  if($obj->IsHidden())
105  $msg.=$obj->Draw(false);
106  }
107 
108 $msg.='<tr><td>&nbsp;</td><td>';
109 $msg.=$this->_SubmitButton();
110 $msg.=$this->_AbortButton($cmdAbort);
111 $msg.='</form>
112  </td></tr>
113  </table>';
114 $msg.='<script>'.$js.'</script>';
115 $msgbox=new CYapBox($msg);
116 $msgbox->Show();
117 }
118 
119 
120 function _SubmitButton()
121 {
122  return('<input type=submit value=\''.$this->Lang['Run'].'\'>');
123 }
124 
125 function _AbortButton($cmdAbort)
126 {
127  return('<input type=button value=\''.$this->Lang['Abort'].'\' onclick="'.$cmdAbort.'">');
128 }
129 }
130 ?>