00001 <?
00006 class MValidator extends MFormControl
00007 {
00008
00012 var $field;
00013
00017 var $min;
00018
00022 var $max;
00023
00027 var $type = 'required';
00028
00032 var $chars;
00033
00037 var $mask;
00038
00042 var $checker;
00043
00047 var $msgerr;
00048
00049
00057 function __construct()
00058 {
00059 parent::__construct('');
00060 $this->page->AddScript('m_validate.js');
00061 }
00062
00070 function Generate()
00071 {
00072 $name = $this->name;
00073 $html =
00074 <<< HERE
00075
00076 var $name = new MIOLO_Validator();
00077 $name.id = '{$this->id}';
00078 $name.form = '{$this->form}';
00079 $name.field = '{$this->field}';
00080 $name.label = '{$this->label}';
00081 $name.min = '{$this->min}';
00082 $name.max = '{$this->max}';
00083 $name.type = '{$this->type}';
00084 $name.chars = '{$this->chars}';
00085 $name.mask = '{$this->mask}';
00086 $name.msgerr= '{$this->msgerr}';
00087
00088 HERE;
00089 if ( $this->checker )
00090 {
00091 $html .= "$name.checker = 'MIOLO_Validate_Check_{$this->checker}';";
00092 }
00093 return $html;
00094 }
00095 }
00096
00101 class MRequiredValidator extends MValidator
00102 {
00115 function __construct($field,$label='',$max=0, $msgerr='')
00116 {
00117 parent::__construct();
00118 $this->id = 'required';
00119 $this->field = $field;
00120 $this->label = $label;
00121 $this->mask = '';
00122 $this->type = 'required';
00123 $this->min = 0;
00124 $this->max = $max;
00125 $this->chars = 'ALL';
00126 $this->msgerr = $msgerr;
00127 }
00128 }
00129
00134 class MMASKValidator extends MValidator
00135 {
00151 function __construct($field,$label='',$mask,$type = 'ignore',$msgerr='')
00152 {
00153 parent::__construct();
00154 $this->id = 'mask';
00155 $this->field = $field;
00156 $this->label = $label;
00157 $this->mask = $mask;
00158 $this->type = $type;
00159 $this->min = 0;
00160 $this->max = strlen($mask);
00161 $this->msgerr = $msgerr;
00162 $this->chars = 'ALL';
00163 }
00164 }
00165
00170 class MEmailValidator extends MValidator
00171 {
00186 function __construct($field,$label='',$type = 'optional',$msgerr='')
00187 {
00188 parent::__construct();
00189 $this->id = 'email';
00190 $this->field = $field;
00191 $this->label = $label;
00192 $this->type = $type;
00193 $this->min = 0;
00194 $this->max = 99;
00195 $this->chars = 'ALL';
00196 $this->mask = '';
00197 $this->checker = 'EMAIL';
00198 $this->msgerr = $msgerr;
00199 }
00200 }
00201
00206 class MPasswordValidator extends MValidator
00207 {
00222 function __construct($field,$label='',$type = 'required',$msgerr='')
00223 {
00224 parent::__construct();
00225 $this->id = 'password';
00226 $this->field = $field;
00227 $this->label = $label;
00228 $this->type = $type;
00229 $this->min = 0;
00230 $this->max = 99;
00231 $this->chars = 'ALL';
00232 $this->mask = '';
00233 $this->checker = 'PASSWORD';
00234 $this->msgerr = $msgerr;
00235 }
00236 }
00237
00242 class MCEPValidator extends MValidator
00243 {
00258 function __construct($field,$label='',$type = 'optional',$msgerr='')
00259 {
00260 parent::__construct();
00261 $this->id = 'cep';
00262 $this->field = $field;
00263 $this->label = $label;
00264 $this->type = $type;
00265 $this->min = 9;
00266 $this->max = 9;
00267 $this->chars = '0123456789-';
00268 $this->mask = '99999-999';
00269 $this->msgerr = $msgerr;
00270 }
00271 }
00272
00277 class MPHONEValidator extends MValidator
00278 {
00293 function __construct($field,$label='',$type = 'optional',$msgerr='')
00294 {
00295 parent::__construct();
00296 $this->id = 'phone';
00297 $this->field = $field;
00298 $this->label = $label;
00299 $this->type = $type;
00300 $this->min = 8;
00301 $this->max = 13;
00302 $this->chars = '() 01234-56789';
00303
00304 $this->msgerr = $msgerr;
00305 }
00306 }
00307
00312 class MTIMEValidator extends MValidator
00313 {
00328 function __construct($field,$label='',$type = 'optional',$msgerr='')
00329 {
00330 parent::__construct();
00331 $this->id = 'time';
00332 $this->field = $field;
00333 $this->label = $label;
00334 $this->type = $type;
00335 $this->min = 5;
00336 $this->max = 5;
00337 $this->chars = ':0123456789';
00338 $this->mask = '99:99';
00339 $this->checker = 'TIME';
00340 $this->msgerr = $msgerr;
00341 }
00342 }
00343
00348 class MCPFValidator extends MValidator
00349 {
00364 function __construct($field,$label='',$type = 'optional',$msgerr='')
00365 {
00366 parent::__construct();
00367 $this->id = 'cpf';
00368 $this->field = $field;
00369 $this->label = $label;
00370 $this->type = $type;
00371 $this->min = 14;
00372 $this->max = 14;
00373 $this->chars = '.-0123456789';
00374 $this->mask = '999.999.999-99';
00375 $this->checker = 'CPF';
00376 $this->msgerr = $msgerr;
00377 }
00378 }
00379
00384 class MCNPJValidator extends MValidator
00385 {
00400 function __construct($field,$label='',$type = 'optional',$msgerr='')
00401 {
00402 parent::__construct();
00403 $this->id = 'cnpj';
00404 $this->field = $field;
00405 $this->label = $label;
00406 $this->type = $type;
00407 $this->min = 18;
00408 $this->max = 18;
00409 $this->chars = '/.-0123456789';
00410 $this->mask = '99.999.999/9999-99';
00411 $this->checker = 'CNPJ';
00412 $this->msgerr = $msgerr;
00413 }
00414 }
00415
00420 class MDATEDMYValidator extends MValidator
00421 {
00436 function __construct($field,$label='',$type = 'optional',$msgerr='')
00437 {
00438 parent::__construct();
00439 $this->id = 'datedmy';
00440 $this->field = $field;
00441 $this->label = $label;
00442 $this->type = $type;
00443 $this->min = 10;
00444 $this->max = 10;
00445 $this->chars = '/0123456789';
00446 $this->mask = '99/99/9999';
00447 $this->checker = 'DATEDMY';
00448 $this->msgerr = $msgerr;
00449 }
00450 }
00451
00456 class MDATEYMDValidator extends MValidator
00457 {
00472 function __construct($field,$label='',$type = 'optional',$msgerr='')
00473 {
00474 parent::__construct();
00475 $this->id = 'dateymd';
00476 $this->field = $field;
00477 $this->label = $label;
00478 $this->type = $type;
00479 $this->min = 10;
00480 $this->max = 10;
00481 $this->chars = '/0123456789';
00482 $this->mask = '9999/99/99';
00483 $this->checker = 'DATEYMD';
00484 $this->msgerr = $msgerr;
00485 }
00486 }
00487
00492 class MCompareValidator extends MValidator
00493 {
00497 var $operator;
00498
00502 var $value;
00503
00507 var $datatype;
00508
00509
00527 function __construct($field,$label='', $operator, $value, $datatype='s', $type = 'optional',$msgerr='')
00528 {
00529 parent::__construct();
00530 $this->id = 'compare';
00531 $this->field = $field;
00532 $this->label = $label;
00533 $this->type = $type;
00534 $this->min = 0;
00535 $this->max = 255;
00536 $this->chars = 'ALL';
00537 $this->mask = '';
00538 $this->checker = 'COMPARE';
00539 $this->operator = $operator;
00540 $this->value = $value;
00541 $this->datatype = strtolower($datatype);
00542 $this->msgerr = $msgerr;
00543 }
00544
00552 function Generate()
00553 {
00554 $name = $this->name;
00555 $html = parent::Generate();
00556 $html .= "$name.operator = '{$this->operator}';\n";
00557 $html .= "$name.value = '{$this->value}';\n";
00558 $html .= "$name.datatype = '{$this->datatype}';\n";
00559 return $html;
00560 }
00561 }
00562
00567 class MRangeValidator extends MValidator
00568 {
00572 var $minvalue;
00573
00577 var $maxvalue;
00578
00582 var $datatype;
00583
00584
00602 function __construct($field,$label='', $min, $max, $datatype='s', $type = 'optional',$msgerr='', $separator='.')
00603 {
00604 parent::__construct();
00605 $this->id = 'range';
00606 $this->field = $field;
00607 $this->label = $label;
00608 $this->type = $type;
00609 $this->min = 0;
00610 $this->max = 255;
00611 $this->mask = '';
00612 $this->checker = 'RANGE';
00613 $this->minvalue = $min;
00614 $this->maxvalue = $max;
00615 $this->datatype = strtolower($datatype);
00616 $this->chars = $this->datatype == 'i' || $this->datatype == 'f' ? '+-0123456789' : 'ALL';
00617
00618 if ( $this->datatype == 'f' )
00619 {
00620 $this->chars .= $separator;
00621 }
00622
00623 $this->msgerr = $msgerr;
00624 }
00625
00633 function Generate()
00634 {
00635 $name = $this->name;
00636 $html = parent::Generate();
00637 $html .= "$name.minvalue = '{$this->minvalue}';\n";
00638 $html .= "$name.maxvalue = '{$this->maxvalue}';\n";
00639 $html .= "$name.datatype = '{$this->datatype}';\n";
00640 return $html;
00641 }
00642 }
00643
00648 class MRegExpValidator extends MValidator
00649 {
00653 var $regexp;
00654
00655
00671 function __construct($field,$label='', $regexp='', $type = 'optional',$msgerr='')
00672 {
00673 parent::__construct();
00674 $this->id = 'regexp';
00675 $this->field = $field;
00676 $this->label = $label;
00677 $this->type = $type;
00678 $this->min = 0;
00679 $this->max = 255;
00680 $this->chars = 'ALL';
00681 $this->mask = '';
00682 $this->checker = 'REGEXP';
00683 $this->regexp = $regexp;
00684 $this->msgerr = $msgerr;
00685 }
00686
00694 function Generate()
00695 {
00696 $name = $this->name;
00697 $html = parent::Generate();
00698 $html .= "$name.regexp = '{$this->regexp}';\n";
00699 return $html;
00700 }
00701 }
00702
00707 class MIntegerValidator extends MRegExpValidator
00708 {
00723 function __construct($field,$label='', $type = 'optional',$msgerr='')
00724 {
00725 parent::__construct($field,$label, '^[+-]?[0-9][0-9]*$', $type,$msgerr);
00726 }
00727 }
00728
00733 class mFloatValidator extends MRegExpValidator
00734 {
00749 function __construct($field,$label='', $separator='.', $precision=2, $type = 'optional',$msgerr='')
00750 {
00751 parent::__construct($field,$label, '^[+-]?[0-9]{1,}(\\'.$separator.'[0-9]{1,'.$precision.'})?$', $type,$msgerr);
00752 $this->chars = '0123456789+-'.$separator;
00753 }
00754 }
00755
00756
00761 class MDATETimeDMYValidator extends MValidator
00762 {
00777 function __construct($field,$label='',$type = 'optional',$msgerr='')
00778 {
00779 parent::__construct();
00780 $this->id = 'datetimedmy';
00781 $this->field = $field;
00782 $this->label = $label;
00783 $this->type = $type;
00784 $this->min = 10;
00785 $this->max = 16;
00786 $this->chars = ':/0123456789 ';
00787 $this->mask = '99/99/9999 99:99';
00788 $this->checker = 'DATETimeDMY';
00789 $this->msgerr = $msgerr;
00790 }
00791
00792 }
00793
00794
00795 ?>