MkFramework
 All Data Structures Functions
plugin_html.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 
35  public function getImg($sSrc,$sAlt=null,$tOption=null){
36  if($sAlt==null){ $sAlt=$sSrc; }
37  $sOptions=$this->getOptionFromTab($tOption);
38  return '<img src="'._root::getConfigVar('path.img').$sSrc.'" title="'.$sAlt.'" '.$sOptions.'/>';
39  }
48  public function getDiv($sContenu,$tOption=null){
49  return '<div'.$this->getOptionFromTab($tOption).'>'.$sContenu.'</div>';
50  }
60  public function getInput($sName,$sValue=null,$tOption=null){
61  if(!isset($tOption['class'])){ $tOption['class']='input'; }
62  return '<input type="input" name="'.$sName.'" value="'.$sValue.'"'.$this->getOptionFromTab($tOption).'/>';
63  }
74  public function getInputRadio($sName,$sValue=null,$bChecked=false,$tOption=null){
75  if(!isset($tOption['class'])){ $tOption['class']='input'; }
76  $sOptions='';
77  if($bChecked){ $sOptions.='checked="checked" ';}
78  $sOptions.=$this->getOptionFromTab($tOption);
79  return '<input type="radio" name="'.$sName.'" value="'.$sValue.'" '.$sOptions.'/>';
80  }
91  public function getInputCheckbox($sName,$sValue=null,$bChecked=false,$tOption=null){
92  if(!isset($tOption['class'])){ $tOption['class']='input'; }
93  $sOptions='';
94  if($bChecked){ $sOptions.='checked="checked" ';}
95  $sOptions.=$this->getOptionFromTab($tOption);
96  return '<input type="checkbox" name="'.$sName.'" value="'.$sValue.'" '.$sOptions.'/>';
97  }
108  public function getSelect($sName,$tSelect,$sValue=null,$tOption=null){
109  if(!isset($tOption['class'])){ $tOption['class']='select'; }
110  $sHtml='<select name="'.$sName.'"'.$this->getOptionFromTab($tOption).'>';
111  if($tSelect){
112  foreach($tSelect as $sKey => $sVal){
113  $sHtml.='<option ';
114  if($sKey==$sValue){
115  $sHtml.='selected="selected"';
116  }
117  $sHtml.=' value="'.$sKey.'">'.$sVal.'</option>';
118  }
119  }
120  $sHtml.='</select>';
121  return $sHtml;
122  }
133  public function getSelectMultiple($sName,$tSelect,$tValue=null,$tOption=null){
134  if(!isset($tOption['class'])){ $tOption['class']='select'; }
135  $sHtml='<select multiple="multiple" name="'.$sName.'[]"'.$this->getOptionFromTab($tOption).'>';
136  if($tSelect){
137  foreach($tSelect as $sKey => $sVal){
138  $sHtml.='<option ';
139  if(is_array($tValue) and in_array($sKey,$tValue)){
140  $sHtml.='selected="selected"';
141  }
142  $sHtml.=' value="'.$sKey.'">'.$sVal.'</option>';
143  }
144  }
145  $sHtml.='</select>';
146  return $sHtml;
147  }
157  public function getTextarea($sName,$sValue=null,$tOption=null){
158  if(!isset($tOption['class'])){ $tOption['class']='textarea'; }
159  return '<textarea name="'.$sName.'"'.$this->getOptionFromTab($tOption).'>'.$sValue.'</textarea>';
160  }
170  public function getInputDate($sName,$sValue=null,$tOption=null){
171  $sValueAnnee=$sValueMois=$sValueJour='';
172  if($sValue!=null and preg_match('/-/',$sValue)){
173  list($sValueAnnee,$sValueMois,$sValueJour)=preg_split('/-/',$sValue);
174  $sValueAnnee=sprintf('%04d',$sValueAnnee);
175  $sValueMois=sprintf('%02d',$sValueMois);
176  $sValueJour=sprintf('%02d',$sValueJour);
177  }
178  $sHtml='';
179  $tOption2['class']='inputDateJour';
180  $sOptions=$this->getOptionFromTab($tOption2);
181  $sHtml.= '<input type="input" name="'.$sName.'_jour" value="'.$sValueJour.'"'.$sOptions.'/>';
182  $sHtml.= ' / ';
183  $tOption2['class']='inputDateMois';
184  $sOptions=$this->getOptionFromTab($tOption2);
185  $sHtml.= '<input type="input" name="'.$sName.'_mois" value="'.$sValueMois.'"'.$sOptions.'/>';
186  $sHtml.= ' / ';
187  $tOption2['class']='inputDateAnnee';
188  $sOptions=$this->getOptionFromTab($tOption2);
189  $sHtml.= '<input type="input" name="'.$sName.'_annee" value="'.$sValueAnnee.'"'.$sOptions.'/>';
190  if(!isset($tOption['class'])){ $tOption['class']='inputDate'; }
191  return $this->getDiv($sHtml,$tOption);
192  }
200  public function getDateFromInput($tPost,$sName){
201  if(!isset($tPost[$sName.'_annee']) or !isset($tPost[$sName.'_mois']) or !isset($tPost[$sName.'_jour'])
202  or $tPost[$sName.'_annee']=='' or $tPost[$sName.'_mois']=='' or $tPost[$sName.'_jour']==''
203  ){
204  return null;
205  }
206  return (int)$tPost[$sName.'_annee'].'-'.(int)$tPost[$sName.'_mois'].'-'.(int)$tPost[$sName.'_jour'];
207  }
208 
209  private function getOptionFromTab($tOption){
210  if($tOption==null){ return null;}
211  $sOption='';
212  foreach($tOption as $sVar => $sVal){
213  $sOption.=' '.$sVar.'="'.preg_replace("/'/",'\'',$sVal).'"';
214  }
215  return $sOption;
216  }
217 
218 }
getInputRadio($sName, $sValue=null, $bChecked=false, $tOption=null)
Definition: plugin_html.php:74
getImg($sSrc, $sAlt=null, $tOption=null)
Definition: plugin_html.php:35
getInputCheckbox($sName, $sValue=null, $bChecked=false, $tOption=null)
Definition: plugin_html.php:91
getSelectMultiple($sName, $tSelect, $tValue=null, $tOption=null)
getInput($sName, $sValue=null, $tOption=null)
Definition: plugin_html.php:60
getDateFromInput($tPost, $sName)
getDiv($sContenu, $tOption=null)
Definition: plugin_html.php:48
getInputDate($sName, $sValue=null, $tOption=null)
getSelect($sName, $tSelect, $sValue=null, $tOption=null)
getTextarea($sName, $sValue=null, $tOption=null)