MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
inputcontrols.class
Ir para a documentação deste ficheiro.
1<?php
2
4{
5 public $size; // =0 => hidden
6 public $type; //text, multiline, password, file
7 public $validator;
8 public $rows;
9 public $cols;
10
11 public function __construct( $name='',$value='',$label='', $size=10, $hint='', $validator=NULL, $isReadOnly=false, $type='text' )
12 {
13 parent::__construct( $name, $value, $label, '', $hint );
14
15 $this->setReadOnly( $isReadOnly );
16 $this->size = $size;
17 $this->type = ( ($size > 0) ) ? $type : 'hidden';
18 $this->setValidator( $validator );
19 $this->rows = 1;
20 $this->cols = $this->size;
21 $this->formMode = MControl::FORM_MODE_SHOW_SIDE;
22 $this->formName = $this->page->getName();
23
24 }
25
26 function setClass($cssClass, $add = true)
27 {
28 parent::setClass($cssClass, $add);
29 $this->cssClass .= " form-control";
30 }
31
32 public function getValidator()
33 {
34 if($this->validator && $this->validator->name)
35 {
36 return $this->validator;
37 }
38 if ( method_exists($this->form, 'getFieldValidator') )
39 {
40 return $this->validator = $this->form->getFieldValidator($this->name);
41 }
42 }
43
44
45 public function setValidator( $value )
46 {
47 $this->validator = is_string($value) ? new MaskValidator( $name, $label, $value ) : $value;
48 }
49
50 public function generateInner()
51 {
52 if ( ( $this->label ) && ( $this->type == 'hidden' ) )
53 {
54 $span = new Span( $this->name, $this->value, MControl::CLASS_CAPTION ) ;
55 $html = $this->painter->span( $span );
56 }
57
58 if ( $this->autoPostBack )
59 {
60 $this->AddAttribute( 'onblur', "showLoading();" .
61 "$('#m-loading-message-bg, #m-loading-message').unbind('click');" .
62 "$('#m-loading-message-bg, #m-loading-message').prop('onclick', null);stopShowLoading();" .
63 "return _doPostBack('{$this->event}','');".
64 "document.{$this->page->name}.submit();"
65 );
66 }
67
68 if ( $this->getClass() == '' )
69 {
70 $this->setClass( 'm-text-field form-control' );
71 }
72
73 if ( $this->readonly )
74 {
75 $this->SetClass('m-readonly');
76 $this->AddAttribute('readonly');
77 }
78
79 $mask = $this->getValidator()->mask ?? null;
80 if ( $mask )
81 {
82 $this->addAttribute('onkeypress', 'return MIOLO_Validate_Mask('.$this->getValidator()->name.', event)');
83 $this->addAttribute('onkeyup', 'MIOLO_Apply_Mask('.$this->getValidator()->name.', event)');
84 }
85
86 if ( ( $this->type=='text' ) ||
87 ( $this->type=='password' ) ||
88 ( $this->type=='file' ) ||
89 ( $this->type=='number' )
90 )
91 {
92 $size = '';
93
94 if ( $this->type=='text' && $this->size )
95 {
97 }
98
99 $text = $this->getRender('inputtext');
100 $this->inner = $this->generateLabel() . $text;
101 }
102 else if ( ($this->type=='multiline') )
103 {
104 $text = $this->getRender('inputtextarea');
105 $this->inner = $this->generateLabel() . $text;
106 }
107 }
108}
109
110
112{
113 public function __construct( $name='', $value='', $label='', $size=20, $hint='', $validator=null )
114 {
115 parent::__construct( $name, $value, $label, $size, $hint, $validator );
116
117 $this->type = 'password';
118 }
119}
120
121
123{
124 public function generate()
125 {
126 return $this->getRender('inputhidden');
127 }
128}
129
130
132{
133 public function __construct( $name='', $value='', $label='', $size=20, $rows=1, $cols=20, $hint='', $validator=null )
134 {
135 parent::__construct( $name, $value, $label, $size, $hint, $validator );
136
137 $this->type = 'multiline';
138 $this->rows = $rows;
139 $this->cols = $cols;
140 $this->setClass('m-multiline-field form-control');
141 }
142}
143
144
146{
147 const EXT_ZIP = 'zip';
148 const EXT_TAR_GZ = 'tar.gz';
149 const EXT_GZ = 'gz';
150 const EXT_TXT = 'txt';
151 const EXT_CSV = 'csv';
152 const EXT_PFX = 'pfx';
153 const EXT_CER = 'cer';
154
158 private $allowedExtensions = array();
159
165 public $geraOnChange = true;
166
167 public function __construct( $name='', $value='', $label='', $size=40, $hint='', $showMaxUpload = true )
168 {
169 parent::__construct( $name, $value, $label, $size, $hint );
170
171 // Caso esteja num passo a passo já pode ter sido adicionado um arquivo
172 $hint .= '';
173 if ( strlen(MIOLO::_REQUEST('randomid')) > 0 )
174 {
175 $files = $this->manager->GetSession()->getValue('uploadedFiles_' . MIOLO::_REQUEST('randomid'));
176
177 foreach ( $files as $uploadedFiles )
178 {
179 list ($userFile, $fieldFileId, $fileName) = explode('|_|', $uploadedFiles['name']);
180
181 if ( $this->manager->GetLogin()->id == $userFile &&
182 $fieldFileId == $name )
183 {
184 // Mostra no hint que o arquivo foi adicionado
185 $hint .= "Arquivo adicionado: <strong>{$fileName}</strong>.";
186 }
187 }
188 }
189 $this->hint = $hint;
190 if ( $showMaxUpload )
191 $this->hint .= 'Máx: '.$this->obterTamanhoMaximoUpload().'MB';
192 $this->type = 'file';
193 }
194
195 public function copyFile( $path )
196 {
197 if( $f=$_FILES[$this->name]['tmp_name'])
198 {
199 copy( $f, $path );
200 return true;
201 }
202 else
203 {
204 return false;
205 }
206 }
207
208 public function getFileName( )
209 {
210 return $_FILES[$this->name]['name'];
211 }
212
213 public function getFileType( )
214 {
215 return $_FILES[$this->name]['type'];
216 }
217
222 public function getAllowedExtensions()
223 {
224 return $this->allowedExtensions;
225 }
226
227 public function setAllowedExtensions($allowedExtensions = array())
228 {
229 foreach ( $allowedExtensions as $ext )
230 {
231 $this->addAllowedExtension($ext);
232 }
233 }
234
235 public function addAllowedExtension($extension)
236 {
237 $this->allowedExtensions[] = '.' . $extension;
238 }
239
240 public function generateInner()
241 {
242 if ( $this->geraOnChange )
243 {
244 $this->addAttribute('onchange', $this->obtemOnChange());
245 }
246
247 return parent::generateInner();
248 }
249
250 public function obterTamanhoMaximoUpload()
251 {
252 $maxFileSize = substr(ini_get('upload_max_filesize'), 0, -1);
253 $maxPostSize = substr(ini_get('post_max_size'), 0, -1);
254
255 if ($maxFileSize > $maxPostSize)
256 {
257 return $maxPostSize;
258 }
259 return $maxFileSize;
260 }
261
267 public function obtemOnChange()
268 {
269 //validator config php upload_max_filesize
270 $maxFileSize = $this->obterTamanhoMaximoUpload();
271
272 if ( substr(ini_get('upload_max_filesize'), -1) == 'K' || substr(ini_get('upload_max_filesize'), -1) == 'k')
273 {
274 $maxFileSizeBytes = $maxFileSize * 1024;
275
276 $jsCode = "
277 var fileValida = document.getElementById('{$this->name}');
278 if(fileValida.files && fileValida.files.length == 1)
279 {
280 if ( fileValida.files[0].size > $maxFileSizeBytes)
281 {
282 alert('O Tamanho do arquivo não pode ser mais de ' + ($maxFileSizeBytes/1024) + 'KB');
283 fileValida.value = ''; //Limpa o conteudo selecionado
284 }
285 }
286 ";
287 }
288 else if ( substr(ini_get('upload_max_filesize'), -1) == 'G' || substr(ini_get('upload_max_filesize'), -1) == 'g')
289 {
290 $maxFileSizeBytes = $maxFileSize * 2111832064;
291
292 $jsCode = "
293 var fileValida = document.getElementById('{$this->name}');
294 if(fileValida.files && fileValida.files.length == 1)
295 {
296 if ( fileValida.files[0].size > $maxFileSizeBytes)
297 {
298 alert('O Tamanho do arquivo não pode ser mais de ' + ($maxFileSizeBytes/2111832064) + 'GB');
299 fileValida.value = ''; //Limpa o conteudo selecionado
300 }
301 }
302 ";
303 }
304 else
305 {
306 $maxFileSizeBytes = $maxFileSize * 1048576;
307
308 $jsCode = "
309 var fileValida = document.getElementById('{$this->name}');
310 if(fileValida.files && fileValida.files.length == 1)
311 {
312 if ( fileValida.files[0].size > $maxFileSizeBytes)
313 {
314 alert('O Tamanho do arquivo não pode ser mais de ' + ($maxFileSizeBytes/1024/1024) + 'MB');
315 fileValida.value = ''; //Limpa o conteudo selecionado
316 }
317 }
318 ";
319 }
320
321 // Add JS extension validator
322 $alExt = $this->getAllowedExtensions();
323 if ( count($alExt) > 0 )
324 {
325 $sql = new MSQL();
326 $showNumbers = implode(', ', $alExt);
327
328 $jsCode .= "
329 var validou = false;
330 var fileElement = document.getElementById('{$this->name}');";
331
332 foreach ( $alExt as $ext )
333 {
334 $jsCode .= "
335 if ( fileElement.value.indexOf('{$ext}') != -1 )
336 {
337 validou = true;
338 }";
339 }
340
341 $jsCode .= "
342 if ( !validou )
343 {
344 alert('As extensões permitidas são: {$showNumbers}');
345 fileElement.value = '';
346 }";
347 }
348
349 return $jsCode;
350 }
351
358 public static function uploadFiles($path = null)
359 {
361 $idUser = $MIOLO->GetLogin()->id;
362
363 // Caminho padrão
364 if ( is_null($path) )
365 {
366 $path = '/tmp/uploadedFilesSolisGe';
367 }
368
369 // Se o caminho não existir, cria
370 if ( !is_dir($path) )
371 {
372 mkdir($path, 0777, true);
373 }
374
375 $uploadedFiles = array();
376
377 // Já pode ter sido adicionado um arquivo
378 if ( strlen(MIOLO::_REQUEST('randomid')) > 0 )
379 {
380 $files = $MIOLO->GetSession()->getValue('uploadedFiles_' . MIOLO::_REQUEST('randomid'));
381
382 foreach ( $files as $jaEstaoBaixadas )
383 {
384 list ($userFile, $fieldFileId, $fileName) = explode('|_|', $jaEstaoBaixadas['name']);
385
386 if ( $MIOLO->GetLogin()->id == $userFile )
387 {
388 $uploadedFiles[$fieldFileId] = $jaEstaoBaixadas;
389 }
390 }
391 }
392
393 // Para todos as arquivos no $_FILES
394 foreach ( $_FILES as $keyFileInfo => $fileInfo )
395 {
396 // Concatena o nome do campo com o id do usuário e o nome do arquivo e sua extensão
397 $fileName = $idUser . '|_|' . $keyFileInfo . '|_|' . $fileInfo['name'];
398
399 // Deleta o arquivo no destino, por via das dúvidas
400 unlink("$path/{$fileName}");
401
402 // Copia o arquivo da pasta temporária do $_FILES para a pasta especificada
403 if ( copy($fileInfo['tmp_name'], "$path/{$fileName}") )
404 {
405 unlink($fileInfo['tmp_name']);
406 $uploadedFiles[$keyFileInfo] = array(
407 'name' => $fileName,
408 'path' => "$path/$fileName"
409 );
410 }
411 }
412
413 return $uploadedFiles;
414 }
415}
416
417
419{
420 public function __construct( $name='', $value='', $label='', $size=20, $hint='', $type='calendar-win2k-1' )
421 {
422 // este campo vai usar o calendário javascript
423 parent::__construct( $name, $value, $label, $size, $hint);
424
426
427 $this->setValidator( new DATEDMYValidator( $name, $label ) );
428
429 $this->setClass('m-text-field m-calendar-field form-control');
430 }
431
432 public static function loadDeps($type='calendar-win2k-1')
433 {
435 $MIOLO->page->addScript('m_validate.js');
436 $MIOLO->page->addScript('datepicker/calendar.js');
437 $MIOLO->page->addScript('datepicker/lang/calendar-pt-br.js');
438 $MIOLO->page->addScript('datepicker/calendar-setup.js');
439
440 $styleURL = $MIOLO->getAbsoluteURL('scripts/datepicker/css/' . $type . '.css');
441 $MIOLO->page->addStyleURL($styleURL);
442 }
443
444 public function generateInner()
445 {
446 parent::generateInner();
447
448 if ( ! $this->readonly )
449 {
450 $location = $this->manager->getUI()->getImage('', 'cal.gif' );
451 $imgName = 'btn'.$this->name;
452
453 $image = new MImage( $imgName, _M('Click to open the calendar'), $location );
454
455 $js = "Calendar.setup({inputField:\"{$this->name}\", ifFormat:\"%d/%m/%Y\", button:\"$imgName\"});";
456
457 if ( $this->page->request('cpaint_function') != "" )
458 {
459 $this->page->addAJAXJScode($js);
460 }
461 else
462 {
463 $this->page->onload($js);
464 }
465
466 $image->generateInner();
467 $divInput = new MDiv('input_' . $this->name, $this->inner, 'm-input-calendar');
468 $divImg = new MDiv('img_' . $this->name, $image->getInner(), 'm-img-calendar');
469 $hContainer = new MHContainer('hct_' . $this->name, array($divInput, $divImg));
470 $this->inner = $hContainer->generate();
471 }
472 }
473
474 public function setFieldForm(MForm $form)
475 {
476 // Adiciona validador de calendario automaticamente
477 $exists = false;
478
479 foreach ( $form->getFieldValidators($this->name) as $validator )
480 {
481 if ( $validator instanceof MDateDMYValidator )
482 {
483 $exists = true;
484 }
485 }
486
487 if ( !$exists )
488 {
489 $this->setValidator(null);
490 $form->AddValidator( new MDATEDMYValidator($this->name, $this->label, $this->getRequiredType()) );
491 }
492
493 parent::setFieldForm($form);
494 }
495}
496
497
499{
500 private $ISOCode = 'REAL';
501
502 public function __construct( $name='', $value='', $label='', $size=10, $hint='' )
503 {
504 // este campo vai usar validacao/formatacao javascript
505 parent::__construct( $name, $value, $label, $size, $hint );
506
508
509 $page->addScript( 'm_utils.js' );
510 $page->addScript( 'm_currency.js' );
511 }
512
513
514 public function getValue()
515 {
516 // internal ($this->value): float - 12345.67
517 // external (return): formated string - R$ 12.345,67
518 $format = new MCurrencyFormatter();
519
520 $value = $format->formatWithSymbol( $this->value, $this->ISOCode );
521
522 return $value;
523 }
524
525
526 public function setValue( $value )
527 {
528 // internal ($this->value): float - 12345.67
529 // external ($value): formated string - 12.345,67
530 $format = new MCurrencyFormatter();
531
532 $value = $format->toDecimal($value, $this->ISOCode);
533 $this->value = (float)$value;
534 }
535
536
537 public function generateInner()
538 {
539 $this->addAttribute( 'onBlur', "MIOLO_Currency(document.{$this->formName}.{$this->name})" );
540
541 parent::generateInner();
542 }
543}
544
545?>
__construct( $name='', $value='', $label='', $size=20, $hint='', $type='calendar-win2k-1')
static loadDeps($type='calendar-win2k-1')
setFieldForm(MForm $form)
setReadOnly($status)
Definição mcontrol.class:343
const CLASS_CAPTION
Definição mcontrol.class:46
addAttribute( $name, $value='')
Definição mcontrol.class:443
getRender( $method)
Definição mcontrol.class:833
const FORM_MODE_SHOW_SIDE
Definição mcontrol.class:42
__construct( $name='', $value='', $label='', $size=10, $hint='')
static uploadFiles($path=null)
addAllowedExtension($extension)
__construct( $name='', $value='', $label='', $size=40, $hint='', $showMaxUpload=true)
copyFile( $path)
setAllowedExtensions($allowedExtensions=array())
Definição mform.class:9
AddValidator($validator)
Definição mform.class:284
static _REQUEST( $vars, $from='ALL')
Definição miolo.class:1109
static getInstance()
Definição miolo.class:134
__construct( $name='', $value='', $label='', $size=20, $rows=1, $cols=20, $hint='', $validator=null)
__construct( $name='', $value='', $label='', $size=20, $hint='', $validator=null)
Definição msql.class:8
__construct( $name='', $value='', $label='', $size=10, $hint='', $validator=NULL, $isReadOnly=false, $type='text')
setClass($cssClass, $add=true)
setValidator( $value)