[5307] | 1 | <? |
---|
| 2 | /** |
---|
| 3 | * FormularioInput |
---|
| 4 | * |
---|
| 5 | * Implementação de Formulários Padrões do Sistema. |
---|
| 6 | * @author Jair Pereira <pereira.jair@gmail.com> |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | class FormularioInput { |
---|
| 10 | |
---|
| 11 | protected $html; |
---|
| 12 | protected $tipo; |
---|
| 13 | protected $name; |
---|
| 14 | protected $value; |
---|
| 15 | protected $valueAux; |
---|
| 16 | protected $title; |
---|
| 17 | protected $form; |
---|
| 18 | protected $valuesSelect; |
---|
| 19 | protected $selectEscolha; |
---|
| 20 | protected $selectEscolhaValue; |
---|
| 21 | protected $valuesChecks; |
---|
| 22 | protected $valuesRadio; |
---|
| 23 | protected $width; |
---|
| 24 | protected $height; |
---|
| 25 | protected $multiple; |
---|
| 26 | protected $inforight; |
---|
| 27 | protected $obrigatorio; |
---|
| 28 | protected $selectCor; |
---|
| 29 | protected $selectValuesCor = array(); |
---|
| 30 | public $arreventos = array(); |
---|
| 31 | |
---|
| 32 | //$this->value |
---|
| 33 | function input(){ |
---|
| 34 | $this->html = ''; |
---|
| 35 | $addeventos = $this->getHtmlEventos(); |
---|
| 36 | switch($this->tipo){ |
---|
| 37 | case 'periodo' : |
---|
| 38 | $this->adicionarEvento("onkeyup","formatar(this,'@@/@@/@@@@'); validarPeriodo(document." . $this->form . "." . $this->name . "_inicio,document." .$this->form . "." . $this->name . "_fim);"); |
---|
| 39 | $this->adicionarEvento("onblur","revalidar(this,'@@/@@/@@@@','data'); validarPeriodo(document." . $this->form . "." . $this->name . "_inicio,document." .$this->form . "." . $this->name . "_fim);"); |
---|
| 40 | $addeventos = $this->getHtmlEventos(); |
---|
| 41 | echo '<input type="text" id="'.$this->obrigatorio.'id_'. $this->name.'_inicio" name="' . $this->name . '_inicio" value="' . $this->value . '" size="10" maxlength="10" ' . $addeventos .' title="' . $this->title . '">'; |
---|
| 42 | echo '<img id="id_imgcal_' . $this->name . '_inicio" src="./images/calendar_cal.gif" align="absmiddle" border="0" alt="Calendário..." onClick="displayCalendar(document.' . $this->form . '.' . $this->name . '_inicio,\'dd/mm/yyyy\',this)">'; |
---|
| 43 | echo ' a ' ; |
---|
| 44 | echo '<input type="text" id="'.$this->obrigatorio.'id_'. $this->name.'_fim" name="' . $this->name . '_fim" value="' . $this->valueAux . '" size="10" maxlength="10" ' . $addeventos .' title="' . $this->title . '">' ; |
---|
| 45 | echo '<img id="id_imgcal_' . $this->name . '_fim" src="./images/calendar_cal.gif" align="absmiddle" border="0" alt="Calendário..." onclick="displayCalendar(document.' . $this->form . '.' . $this->name . '_fim,\'dd/mm/yyyy\',this)"><span id="imgAjax_' . $this->name . '" style="display: none;"><img src="images/progress4.gif"></span>'; |
---|
| 46 | break; |
---|
| 47 | case 'data' : |
---|
| 48 | $this->adicionarEvento("onkeyup","formatar(this,'@@/@@/@@@@'); validarPeriodo(document." . $this->form . "." . $this->name . "_inicio,document." .$this->form . "." . $this->name . "_fim);"); |
---|
| 49 | $this->adicionarEvento("onblur","revalidar(this,'@@/@@/@@@@','data'); validarPeriodo(document." . $this->form . "." . $this->name . "_inicio,document." .$this->form . "." . $this->name . "_fim);"); |
---|
| 50 | $addeventos = $this->getHtmlEventos(); |
---|
| 51 | echo '<input type="text" id="'.$this->obrigatorio.'id_'. $this->name.'" name="' . $this->name . '_inicio" value="' . $this->value . '" size="10" maxlength="10" ' . $addeventos . ' title="' . $this->title . '">'; |
---|
| 52 | echo '<img id="id_imgcal_' . $this->name . '_inicio" src="./images/calendar_cal.gif" align="absmiddle" border="0" alt="Calendário..." onClick="displayCalendar(document.' . $this->form . '.' . $this->name . '_inicio,\'dd/mm/yyyy\',this)"><span id="imgAjax_' . $this->name . '" style="display: none;"><img src="images/progress4.gif"></span>'; |
---|
| 53 | break; |
---|
| 54 | |
---|
| 55 | case 'moeda' : |
---|
| 56 | $this->adicionarEvento("onkeyup","milhar(this);"); |
---|
| 57 | $this->adicionarEvento("onblur","revalidarMilhar(this);"); |
---|
| 58 | $addeventos = $this->getHtmlEventos(); |
---|
| 59 | echo '<input type="text" name="' . $this->name . '" id="'.$this->obrigatorio.'id_' . $this->name . '" value="' . $this->value . '" size="20" maxlength="20" ' . $addeventos . ' title="' . $this->title . '"><span id="imgAjax_' . $this->name . '" style="display: none;"><img src="images/progress4.gif"></span>'; break; |
---|
| 60 | case 'cpf' : |
---|
| 61 | $this->adicionarEvento("onkeyup","formatar(this,'@@@.@@@.@@@-@@');"); |
---|
| 62 | $this->adicionarEvento("onblur","revalidar(this,'@@@.@@@.@@@-@@','cpf');"); |
---|
| 63 | $addeventos = $this->getHtmlEventos(); |
---|
| 64 | echo '<input type="text" name="' . $this->name . '" id="'.$this->obrigatorio.'id_' . $this->name . '" value="' . $this->value . '" size="20" maxlength="20" ' . $addeventos . ' title="' . $this->title . '"><span id="imgAjax_' . $this->name . '" style="display: none;"><img src="images/progress4.gif"></span>'; break; |
---|
| 65 | case 'cnpj' : |
---|
| 66 | $this->adicionarEvento("onkeyup","formatar(this,'@@.@@@.@@@/@@@@-@@');"); |
---|
| 67 | $this->adicionarEvento("onblur","revalidar(this,'@@.@@@.@@@/@@@@-@@','cnpj');"); |
---|
| 68 | $addeventos = $this->getHtmlEventos(); |
---|
| 69 | echo '<input type="text" name="' . $this->name . '" id="'.$this->obrigatorio.'id_' . $this->name . '" value="' . $this->value . '" size="20" maxlength="20" ' . $addeventos . ' title="' . $this->title . '"><span id="imgAjax_' . $this->name . '" style="display: none;"><img src="images/progress4.gif"></span>'; break; |
---|
| 70 | |
---|
| 71 | case 'hidden':echo '<input type="hidden" name="' . $this->name . '" id="id_' . $this->name . '" value="' . $this->value . '">'; break; |
---|
| 72 | |
---|
| 73 | case 'int' : |
---|
| 74 | $this->adicionarEvento("onkeyup","formatar(this,'@@@@@@@@@@@@@@@@@@');"); |
---|
| 75 | $this->adicionarEvento("onblur","revalidar(this,'@@@@@@@@@@@@@@@@@@');"); |
---|
| 76 | $addeventos = $this->getHtmlEventos(); |
---|
| 77 | echo '<input type="text" name="' . $this->name . '" id="'.$this->obrigatorio.'id_' . $this->name . '" value="' . $this->value . '" title="' . $this->title . '" size="' . $this->width . '" maxlength="' . $this->height . '" ' . $addeventos . ' ><span id="id_info_' . $this->name . '" class=inforight style="color: rgb(100, 62, 65);"> ' . $this->inforight .'</span><span id="imgAjax_' . $this->name . '" style="display: none;"><img src="images/progress4.gif"></span>'; break; |
---|
| 78 | |
---|
| 79 | default : |
---|
| 80 | |
---|
| 81 | echo '<input type="text" name="' . $this->name . '" id="'.$this->obrigatorio.'id_' . $this->name . '" value="' . $this->value . '" title="' . $this->title . '" size="' . $this->width . '" maxlength="' . $this->height . '" ' . $addeventos . ' ><span id="id_info_' . $this->name . '" class=inforight style="color: rgb(100, 62, 65);"> ' . $this->inforight .'</span><span id="imgAjax_' . $this->name . '" style="display: none;"><img src="images/progress4.gif"></span>'; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | function subtitulo() { |
---|
| 87 | echo "<tr><td>" . $this->value . "</td></tr>"; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | function button() { |
---|
| 91 | $addeventos = $this->getHtmlEventos(); |
---|
| 92 | echo "<input type='button' name='" . $this->name . "' id='" . $this->form. "_btn_". $this->name . "' value='" . $this->value . "' style='width: 90px;' class='botao' " . $addeventos ." >"; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | function select(){ |
---|
| 96 | $selected = ""; |
---|
| 97 | $addeventos = $this->getHtmlEventos(); |
---|
| 98 | echo "\n\t\t\t"; |
---|
| 99 | if ($this->multiplo) { $addmultiplo = " MULTIPLE"; } |
---|
| 100 | echo '<table><tr><td><select id="'.$this->obrigatorio.'id_'. $this->name.'" name="' . $this->name . '" title="' . $this->title . '" style="width: ' . $this->width . 'px;" size="' . $this->height . '" ' . $addeventos . ' ' . $addmultiplo . '>'; |
---|
| 101 | echo "\n"; |
---|
| 102 | if($this->selectEscolha == true){ |
---|
| 103 | echo "\t\t\t<option value=''>" . $this->selectEscolhaValue . "</option>"; |
---|
| 104 | } |
---|
| 105 | if(count($this->valuesSelect) > 0 ){ |
---|
| 106 | foreach($this->valuesSelect as $chave => $valor){ |
---|
| 107 | $selected = ("$chave" == "$this->value") ? ' selected="selected" ' : ''; |
---|
| 108 | echo "\t\t\t\t"; |
---|
| 109 | if (in_array($chave,$this->selectValuesCor)) { |
---|
| 110 | $addstyle = ' style="color: '.$this->selectCor . ';"'; |
---|
| 111 | } else { |
---|
| 112 | $addstyle = ''; |
---|
| 113 | } |
---|
| 114 | echo '<option value="' . $chave . '"' . $selected . $addstyle . '>' . $valor . '</option>'; |
---|
| 115 | echo "\n"; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | echo "\t\t\t</select></td><td><span id='imgAjax_" . $this->name . "' style='display: none;'><img src='images/progress4.gif'></span></td></tr></table>\n"; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | function checkbox(){ |
---|
| 123 | $selected = ""; |
---|
| 124 | $addeventos = $this->getHtmlEventos(); |
---|
| 125 | echo ''; |
---|
| 126 | if(count($this->valuesChecks) > 0 ){ |
---|
| 127 | |
---|
| 128 | echo "\n\t\t<table border='0'>"; |
---|
| 129 | echo "\n\t\t<tr>\n\t\t\t<td>"; |
---|
| 130 | $i = 0; |
---|
| 131 | echo "\n\t\t\t<div id='".$this->obrigatorio .'div_ckbox_' .$this->name . "'>"; |
---|
| 132 | foreach($this->valuesChecks as $valores){ |
---|
| 133 | //$class = ($class == 'tdc') ? 'tde' : 'tdc'; |
---|
| 134 | $selected = ($valores[2] == true) ? ' checked ' : ''; |
---|
| 135 | if (isset($_POST[$this->name])) { |
---|
| 136 | if (in_array($valores[0],$_POST[$this->name])) { |
---|
| 137 | $selected = "checked"; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | $i = $i + 1; |
---|
| 141 | echo "\n\t\t\t\t"; |
---|
| 142 | echo '<input type="checkbox" class="checkbox" id="' . $this->name . '[' . $i . ']" name="' . $this->name . '[' . $i . ']" value="' . $valores[0] . '" ' . $addeventos . ' ' . $selected . ' >' . $valores[1] ; |
---|
| 143 | echo "<br>"; |
---|
| 144 | |
---|
| 145 | } |
---|
| 146 | echo "\n\t\t\t</div>"; |
---|
| 147 | echo "\n\t\t</td><td valign='top' id='imgAjax_" . $this->name . "' style='display: none;'><img src='images/progress4.gif'></td></tr>"; |
---|
| 148 | echo "\n\t\t</table>\n"; |
---|
| 149 | |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | function radio(){ |
---|
| 154 | $selected = ""; |
---|
| 155 | $this->html = ''; |
---|
| 156 | $addeventos = $this->getHtmlEventos(); |
---|
| 157 | if(count($this->valuesRadio) > 0 ){ |
---|
| 158 | echo "\n\t\t\t<div id='".$this->obrigatorio . $this->form. '_div_radio_' .$this->name . "'>"; |
---|
| 159 | echo "\n\t\t<table border='0'>"; |
---|
| 160 | echo "\n\t\t<tr>\n\t\t\t<td>"; |
---|
| 161 | |
---|
| 162 | foreach($this->valuesRadio as $valores){ |
---|
| 163 | $selected = ($valores[2] == true) ? ' checked ' : ''; |
---|
| 164 | echo "\n\t\t\t\t"; |
---|
| 165 | echo '<input type="radio" id="'. $this->name .'" class="radio" name="' . $this->name . '" value="' . $valores[0] . '" ' . $addeventos . " " . $selected . " >" . $valores[1] ; |
---|
| 166 | echo "<br>\n"; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | echo "\n\t\t</td><td valign='top' id='imgAjax_" . $this->name . "' style='display: none;'><img src='images/progress4.gif'></td></tr>"; |
---|
| 170 | echo "\n\t\t</table>\n"; |
---|
| 171 | echo "\n\t\t\t</div>"; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | function arquivo() { |
---|
| 177 | $this->html = ''; |
---|
| 178 | $this->html = '<input type="file" id="'. $this->name .'" name="'. $this->name .'">'; |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | function textArea(){ |
---|
| 182 | $this->html = ''; |
---|
| 183 | $addeventos = " " . $this->getHtmlEventos(); |
---|
| 184 | echo "<textarea name=\"" . $this->name . "\" id=\"" . $this->obrigatorio . "id_". $this->name . "\" cols=\"" . $this->width . "\" rows=\"" . $this->height . "\"$addeventos>" . $this->value . "</textarea>"; |
---|
| 185 | |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | |
---|
| 190 | function desenhaForm(){ |
---|
| 191 | return $this->html; |
---|
| 192 | } |
---|
| 193 | function setTipo($tipo){ |
---|
| 194 | $this->tipo = $tipo; |
---|
| 195 | } |
---|
| 196 | function setName($name){ |
---|
| 197 | $this->name = $name; |
---|
| 198 | } |
---|
| 199 | function setValue($value){ |
---|
| 200 | $this->value = "$value"; |
---|
| 201 | //echo $this->name . ": " . $this->value . "<br>"; |
---|
| 202 | } |
---|
| 203 | function setValueAux($valueAux){ |
---|
| 204 | $this->valueAux = $valueAux; |
---|
| 205 | } |
---|
| 206 | function setTitle($title){ |
---|
| 207 | $this->title = $title; |
---|
| 208 | } |
---|
| 209 | function setInfoRight($info) { |
---|
| 210 | $this->inforight = $info; |
---|
| 211 | } |
---|
| 212 | function setObrigatorio($obrigatorio){ |
---|
| 213 | |
---|
| 214 | if(strlen($obrigatorio)>1){ |
---|
| 215 | $this->obrigatorio = $obrigatorio; |
---|
| 216 | return true; |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | switch($obrigatorio){ |
---|
| 220 | case true : |
---|
| 221 | $this->obrigatorio = ""; |
---|
| 222 | break; |
---|
| 223 | case false : |
---|
| 224 | $this->obrigatorio = "not_"; |
---|
| 225 | break; |
---|
| 226 | default : |
---|
| 227 | $this->obrigatorio = ""; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | function setValuesSelect($arrayValores){ |
---|
| 233 | $this->valuesSelect = $arrayValores; |
---|
| 234 | } |
---|
| 235 | function getName() { |
---|
| 236 | return $this->name; |
---|
| 237 | } |
---|
| 238 | function getValue() { |
---|
| 239 | return $this->value; |
---|
| 240 | } |
---|
| 241 | function getWidth() { |
---|
| 242 | return $this->width; |
---|
| 243 | } |
---|
| 244 | function getTipo() { |
---|
| 245 | return $this->tipo; |
---|
| 246 | } |
---|
| 247 | function getObrigatorio() { |
---|
| 248 | return $this->obrigatorio; |
---|
| 249 | /*if ($this->obrigatorio == "not_") { |
---|
| 250 | $ret = false; |
---|
| 251 | } else { |
---|
| 252 | $ret = true; |
---|
| 253 | } |
---|
| 254 | return $ret; */ |
---|
| 255 | } |
---|
| 256 | function getHeight() { |
---|
| 257 | return $this->height; |
---|
| 258 | } |
---|
| 259 | function getMultiplo() { |
---|
| 260 | return $this->multiplo; |
---|
| 261 | } |
---|
| 262 | function getLabel() { |
---|
| 263 | return $this->label; |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | function setValuesSelectCor($cor,$values) { |
---|
| 267 | $this->selectValuesCor = $values; |
---|
| 268 | $this->selectCor = $cor; |
---|
| 269 | } |
---|
| 270 | |
---|
| 271 | function getTitle() { |
---|
| 272 | return $this->title; |
---|
| 273 | } |
---|
| 274 | function setForm($form){ |
---|
| 275 | $this->form = $form; |
---|
| 276 | } |
---|
| 277 | function getHtml() { |
---|
| 278 | return $this->html; |
---|
| 279 | } |
---|
| 280 | function setSelectEscolha($escolha, $valor){ |
---|
| 281 | $this->selectEscolha = $escolha; |
---|
| 282 | $this->selectEscolhaValue = $valor; |
---|
| 283 | } |
---|
| 284 | function getSelectEscolha() { |
---|
| 285 | return $this->selectEscolha; |
---|
| 286 | } |
---|
| 287 | function getSelectEscolhaValue() { |
---|
| 288 | return $this->selectEscolhaValue; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | function setValuesChecks($arrValores){ |
---|
| 292 | $this->valuesChecks = $arrValores; |
---|
| 293 | } |
---|
| 294 | function setValuesRadio($arrValores){ |
---|
| 295 | $this->valuesRadio = $arrValores; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | function setSize($tamanho1,$tamanho2 = "") { |
---|
| 299 | $this->width = $tamanho1; |
---|
| 300 | $this->height = $tamanho2; |
---|
| 301 | } |
---|
| 302 | function setMultiplo($multiplo) { |
---|
| 303 | $this->multiplo = $multiplo; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | function adicionarEvento($action,$javascript) { |
---|
| 307 | $arrevt = array("action" => $action, "evento" =>$javascript); |
---|
| 308 | array_push($this->arreventos,$arrevt); |
---|
| 309 | } |
---|
| 310 | function getHtmlEventos() { |
---|
| 311 | $streventos = ""; |
---|
| 312 | foreach($this->arreventos as $evento) { |
---|
| 313 | if ($evento["action"] == "onclick") { |
---|
| 314 | $addonclick .= $evento["evento"]; |
---|
| 315 | } |
---|
| 316 | if ($evento["action"] == "onchange") { |
---|
| 317 | $addonchange .= $evento["evento"]; |
---|
| 318 | } |
---|
| 319 | if ($evento["action"] == "onblur") { |
---|
| 320 | $addonblur .= $evento["evento"]; |
---|
| 321 | } |
---|
| 322 | if ($evento["action"] == "onmouseout") { |
---|
| 323 | $addonmouseout .= $evento["evento"]; |
---|
| 324 | } |
---|
| 325 | if ($evento["action"] == "onmousemove") { |
---|
| 326 | $addonmousemove .= $evento["evento"]; |
---|
| 327 | } |
---|
| 328 | if ($evento["action"] == "onkeydown") { |
---|
| 329 | $addonkeydown .= $evento["evento"]; |
---|
| 330 | } |
---|
| 331 | if ($evento["action"] == "onkeypress") { |
---|
| 332 | $addonkeypress .= $evento["evento"]; |
---|
| 333 | } |
---|
| 334 | if ($evento["action"] == "onkeyup") { |
---|
| 335 | $addonkeyup .= $evento["evento"]; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | if ($addonclick != "") { |
---|
| 339 | $streventos .= " OnClick=\" $addonclick \" "; |
---|
| 340 | } |
---|
| 341 | if ($addonchange != "") { |
---|
| 342 | $streventos .= " OnChange=\" $addonchange \" "; |
---|
| 343 | } |
---|
| 344 | if ($addonmouseout != "") { |
---|
| 345 | $streventos .= " OnMouseOut=\" $addonmouseout \" "; |
---|
| 346 | } |
---|
| 347 | if ($addonmousemove != "") { |
---|
| 348 | $streventos .= " OnMouseMove=\" $addonmousemove \" "; |
---|
| 349 | } |
---|
| 350 | if ($addonkeypress != "") { |
---|
| 351 | $streventos .= " OnKeyPress=\" $addonkeypress \" "; |
---|
| 352 | } |
---|
| 353 | if ($addonkeyup != "") { |
---|
| 354 | $streventos .= " OnKeyUp=\" $addonkeyup \" "; |
---|
| 355 | } |
---|
| 356 | if ($addonkeydown != "") { |
---|
| 357 | $streventos .= " OnKeyDown=\" $addonkeydown \" "; |
---|
| 358 | } |
---|
| 359 | if ($addonblur != "") { |
---|
| 360 | $streventos .= " OnBlur=\" $addonblur \" "; |
---|
| 361 | } |
---|
| 362 | return $streventos; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | } |
---|
| 366 | ?> |
---|