MkFramework
 All Data Structures Functions
plugin_form.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
24 
25  protected $oObject;
26  protected $tMessage;
27  protected $isPost;
28 
34  public function __construct($oObject=null){
35 
36  $this->oObject=$oObject;
37 
38  $this->isPost=false;
39  if(_root::getRequest()->isPost()){
40  $this->isPost=true;
41  }
42  }
43 
49  public function setMessage($tMessage){
50  $this->tMessage=$tMessage;
51  }
58  public function getInputHidden($sName,$tOption=null){
59  $sHtml=null;
60  $sHtml.='<input type="hidden" name="'.$sName.'" value="'.$this->getValue($sName).'" '.$this->getOption($tOption).'/>';
61  return $sHtml;
62  }
70  public function getToken($sName,$sValue,$tOption=null){
71  $sHtml=null;
72  $sHtml.='<input type="hidden" type="text" name="'.$sName.'" value="'.$sValue.'" '.$this->getOption($tOption).'/>';
73  $sHtml.=$this->getMessage($sName);
74  return $sHtml;
75  }
82  public function getInputText($sName,$tOption=null){
83  $sHtml=null;
84  $sHtml.='<input type="text" name="'.$sName.'" value="'.$this->getValue($sName).'" '.$this->getOption($tOption).'/>';
85  $sHtml.=$this->getMessage($sName);
86  return $sHtml;
87  }
94  public function getInputTextarea($sName,$tOption=null){
95  $sHtml=null;
96  $sHtml.='<textarea type="text" name="'.$sName.'" '.$this->getOption($tOption).'>';
97  $sHtml.=$this->getValue($sName).'</textarea>';
98  $sHtml.=$this->getMessage($sName);
99  return $sHtml;
100  }
107  public function getInputUpload($sName,$tOption=null){
108  $sHtml=null;
109  $sHtml.='<input type="file" name="'.$sName.'" '.$this->getOption($tOption).'/>';
110  $sHtml.=$this->getMessage($sName);
111  return $sHtml;
112  }
120  public function getSelect($sName,$tValue,$tOption=null){
121 
122  $sCurrentValue=$this->getValue($sName);
123 
124  $sHtml=null;
125  $sHtml.='<select name="'.$sName.'" '.$this->getOption($tOption).'>';
126  foreach($tValue as $sValue => $sLabel){
127  $sHtml.='<option ';
128  if($sValue==$sCurrentValue){
129  $sHtml.=' selected="selected"';
130  }
131  $sHtml.=' value="'.$sValue.'">'.$sLabel.'</option>';
132  }
133  $sHtml.='</select>';
134  $sHtml.=$this->getMessage($sName);
135  return $sHtml;
136 
137  }
145  public function getListRadio($sName,$tValue,$tOption=null){
146  $sCurrentValue=$this->getValue($sName);
147 
148  $sHtml=null;
149 
150  foreach($tValue as $sValue => $sLabel){
151  $sHtml.='<input type="radio" name="'.$sName.'" ';
152  if($sValue==$sCurrentValue){
153  $sHtml.=' checked="checked"';
154  }
155  $sHtml.=' value="'.$sValue.'" '.$this->getOption($tOption).'/>'.$sLabel.' ';
156  }
157  $sHtml.=$this->getMessage($sName);
158  return $sHtml;
159  }
167  public function getInputCheckbox($sName,$sValue,$tOption=null){
168  $sCurrentValue=$this->getValue($sName);
169 
170  $sHtml='<input type="checkbox" ';
171  if($sCurrentValue==$sValue){
172  $sHtml.='checked="checked" ';
173  }
174  $sHtml.=' name="'.$sName.'" value="'.$sValue.'" '.$this->getOption($tOption).'/>';
175  $sHtml.=$this->getMessage($sName);
176  return $sHtml;
177  }
178 
179  private function getValue($sName){
180  if($this->isPost){
181  return _root::getParam($sName);
182  }else if($this->oObject){
183  if($this->oObject->$sName){
184  return $this->oObject->$sName;
185  }
186  }
187  }
188 
189  private function getMessage($sName){
190  if(isset($this->tMessage[$sName])){
191  if(is_array($this->tMessage[$sName])){
192  return '<p class="error">'.implode(',',$this->tMessage[$sName]).'</p>';
193  }else{
194  return '<p class="error">'.$this->tMessage[$sName].'</p>';
195  }
196  }
197  return null;
198  }
199 
200  private function getOption($tOption=null){
201 
202  if(!$tOption){
203  return null;
204  }
205 
206  $sHtml=null;
207  foreach($tOption as $sKey => $sValue){
208  $sHtml.=$sKey.'="'.$sValue.'" ';
209 
210  }
211  return $sHtml;
212 
213  }
214 }
getSelect($sName, $tValue, $tOption=null)
getInputText($sName, $tOption=null)
Definition: plugin_form.php:82
getToken($sName, $sValue, $tOption=null)
Definition: plugin_form.php:70
setMessage($tMessage)
Definition: plugin_form.php:49
getInputHidden($sName, $tOption=null)
Definition: plugin_form.php:58
getInputTextarea($sName, $tOption=null)
Definition: plugin_form.php:94
getInputUpload($sName, $tOption=null)
static getParam($sVar, $uElse=null)
Definition: class_root.php:465
static getRequest()
Definition: class_root.php:541
__construct($oObject=null)
Definition: plugin_form.php:34
getListRadio($sName, $tValue, $tOption=null)
getInputCheckbox($sName, $sValue, $tOption=null)