Source for file form.class.php

Documentation is available at form.class.php

  1. <?php
  2. /**
  3.  * TPLN Form Plugin
  4.  * @package Template Engine
  5.  */
  6. class Form extends Mail
  7. {
  8.     protected  $new_objects_name = array()// Array of names objects
  9.     protected  $msg_err = array()// Array of error messages
  10.     protected  $last_obj = ''// the last object on parameter
  11.     protected  $objError = array()// array of error object  / allows to indicate them in javascript
  12.     protected  $objErrorMsg = array()// array of errors for a possible customisation
  13.     protected  $custom_msg = ''// Personalize the errors messages
  14.     protected  $formErrorLang = TPLN_LANG// recover the language per defect
  15.     protected  $formName = ''// name of formulaire per defect
  16.     protected  $init = 0// initialize data of the formulaire ?
  17.     protected  $row_val = array()// contains the array of values
  18.     protected  $error_display_mode = 'I'// T: top ou bien I: Inline
  19.     protected  $captcha = 0// captcha activated
  20.  
  21.     /**
  22.      * @var string Form error color
  23.      */
  24.     public $formErrorColor = "#FF4444"// error color
  25.  
  26.     /**
  27.      * Return formatted message
  28.      *
  29.      * @param int $index 
  30.      * @param array $parameters 
  31.      * @return string 
  32.      */
  33.     public function getMessage($index$parameters=array())
  34.     {
  35.         global $tpln_form_lng;
  36.  
  37.         $msg $tpln_form_lng[$this->formErrorLang][$index];
  38.         //die($msg);
  39.         if(count($parameters0)
  40.         {
  41.             //print_r($parameters);
  42.             $msg vsprintf($msg$parameters);
  43.         }
  44.  
  45.         if(TPLN_OUTPUT_CHARSET != 'utf-8')
  46.             $msg utf8_decode($msg);
  47.  
  48.         return $msg;
  49.     }
  50.  
  51.     /**
  52.      * rewrite a new name object
  53.      *
  54.      * @param array $objects_name 
  55.      */
  56.     public function formSetObjectNames($objects_namearray())
  57.     {
  58.         $this->new_objects_name = $objects_name;
  59.     }
  60.  
  61.     /**
  62.      * get the new name of the object
  63.      *
  64.      * @return string 
  65.      */
  66.     protected function formGetUserObjectName()
  67.     {
  68.         if(isset($this->new_objects_name[$this->last_obj]))
  69.             return $this->new_objects_name[$this->last_obj];
  70.         return $this->last_obj;
  71.     }
  72.  
  73.     /**
  74.      * This method allows you to chose the place of form error messages T:
  75.      *
  76.      *  display messages on top (bloc form_error obliged) I (by default): display messages below html widget
  77.      *
  78.      * @param string $mode 
  79.      * @author H2LSOFT */
  80.     public function formSetDisplayMode($mode)
  81.     {
  82.         $this->error_display_mode = $mode;
  83.     }
  84.  
  85.     /**
  86.      * This method allows you to modify form name.
  87.      *
  88.      * @param string $formName 
  89.      * @author H2LSOFT */
  90.     public function formSetName($formName)
  91.     {
  92.         $this->formName = $formName;
  93.     }
  94.  
  95.     /**
  96.      * this method tests if there is personalized message error
  97.      * customize error message
  98.      *
  99.      * @return boolean 
  100.      * @author H2LSOFT */
  101.     protected function errorCustom()
  102.     {
  103.         // recover the objects of error for the signals in javascript
  104.         if(!in_array($this->last_obj$this->objError))
  105.         {
  106.             $this->objError[$this->last_obj;
  107.         }
  108.  
  109.         if(!empty($this->custom_msg))
  110.         {
  111.             $this->msg_err[$this->custom_msg;
  112.             $this->objErrorMsg[$this->last_obj][$this->custom_msg;
  113.  
  114.             $this->custom_msg = '';
  115.             return true;
  116.         }
  117.         else
  118.         {
  119.             $this->custom_msg = '';
  120.             return false;
  121.         }
  122.     }
  123.  
  124.     /**
  125.      * Verify if treatment protection has be done
  126.      * @var bool 
  127.      */
  128.     private $formXEntitiesPostDone = false;
  129.  
  130.  
  131.     /**
  132.      * this method
  133.      * @param string $obj 
  134.      *
  135.      * @return boolean 
  136.      * @author H2LSOFT */
  137.     public function rules($obj)
  138.     {
  139.         if($_POST)
  140.         {
  141.             // apply htmlentites to protect data
  142.             if(!$this->formXEntitiesPostDone && $this->dbProtectionMode)
  143.             {                
  144.                 $_POST $this->formXEntities($_POST);
  145.                 $this->formXEntitiesPostDone = true;
  146.             }
  147.  
  148.             // pull out the [] which is array
  149.             $array false;
  150.             $obj2 $obj;
  151.             if(substr($obj2-22== '[]')
  152.             {
  153.                 $obj2 substr($obj20strlen($obj2)-2);
  154.                 $array true;
  155.             }
  156.  
  157.             if(!isset($_POST[$obj2]))
  158.             {
  159.                 if($array)
  160.                     $_POST[$obj2array()#avoid the bugs IE, FIREFOX
  161.                 else
  162.                     $_POST[$obj2''#avoid the bugs IE, FIREFOX
  163.             }
  164.  
  165.             if(empty($obj))$obj $this->last_obj;
  166.             if(empty($obj))
  167.             {
  168. //            if($this->formErrorLang == 'fr')
  169. //                die("TPLN Form: `$obj` Aucun objet trouvé");
  170. //            else
  171. //                die("TPLN Form: `$obj` No object found");
  172.  
  173.                 $obj_name $this->formGetUserObjectName();
  174.                 //die($this->getMessage(0, array($obj_name)));
  175.                 trigger_error($this->getMessage(0array($obj_name))E_USER_ERROR);
  176.             }
  177.  
  178.             $this->last_obj = $obj;
  179.             return true;
  180.         }
  181.  
  182.         return false# obligatory
  183.     }
  184.  
  185.     /**
  186.      * This method initializes data of HTML form by convertion of php parameter.
  187.      *
  188.      * It is usefull for editing a record of a table.
  189.      *
  190.      * @param array $arr 
  191.      * @author H2LSOFT */
  192.     public function formInit($arr)
  193.     {
  194.         $this->init = 1;
  195.         $this->row_val = $arr;
  196.     }
  197.  
  198.     /**
  199.      * this method allows you to record an error message
  200.      *
  201.      * which will be posted with the next error.
  202.      *
  203.      * @param string $msg 
  204.      * @author H2LSOFT */
  205.     public function setMessage($msg// personalize an error message
  206.  
  207.     {
  208.         if(TPLN_OUTPUT_CHARSET == 'utf-8')
  209.             $this->custom_msg = $msg;
  210.         else
  211.             $this->custom_msg = utf8_decode($msg);
  212.     }
  213.  
  214.     /**
  215.      * this method allows you to ckeck if the object isn't empty.
  216.      *
  217.      *  If that's the case then alarm error is started.
  218.      *
  219.      * @param string $obj 
  220.      * @param string $msg 
  221.      *
  222.      * @author H2LSOFT */
  223.     public function notEmpty($obj ''$msg''// check if the object isn't empty
  224.  
  225.     {
  226.         if(is_array($obj))
  227.         {
  228.             foreach($obj as $cur_obj)
  229.                 $this->notEmpty($cur_obj);
  230.             return;
  231.         }
  232.  
  233.         if(!$this->rules($obj))return;
  234.  
  235.         $this->setMessage($msg);
  236.  
  237.  
  238.         // if notEmpty is used on file objet then fileControl will be called instead
  239.         if(isset($_FILES[$this->last_obj]))
  240.         {
  241.             $this->fileControl($this->last_obj1);
  242.             return;
  243.         }
  244.  
  245.         // Tow diffrents treantments for arrays and the others types
  246.         $obj2 str_replace('[]'''$this->last_obj);
  247.         $err false;
  248.  
  249.         if(!is_array($_POST[$obj2]))
  250.         {
  251.             if(strlen(trim($_POST[$obj2])) == 0)
  252.                 $err true;
  253.         }
  254.         elseif(count($_POST[$obj2]== 0)
  255.         {
  256.             $err true;
  257.         }
  258.  
  259.         if($err)
  260.         {
  261.             if(!$this->errorCustom())
  262.             {
  263.                 //$msg = "Field '$this->last_obj' can not be empty";
  264.                 //if($this->formErrorLang == 'fr')
  265.                 //$msg = "Le champ '$this->last_obj' ne peut être vide";
  266.  
  267.                 $obj_name $this->formGetUserObjectName();
  268.                 $msg $this->getMessage(1array($obj_name));
  269.  
  270.                 $this->msg_err[$msg;
  271.                 $this->objErrorMsg[$this->last_obj][$msg;
  272.             }
  273.             // $this->objErrorMsg[$this->last_obj][] = $msg;
  274.         }
  275.  
  276.         $this->custom_msg = ''# remove custom error message
  277.     }
  278.  
  279.     /**
  280.      * this method allows to ckeck that the value is a number,
  281.      *
  282.      *  if parameter floatnumber is true, Digit will accept a float number.
  283.      *
  284.      * @param string $obj 
  285.      * @param boolean $float_accepted 
  286.      *
  287.      * @author H2LSOFT */
  288.     public function onlyDigit($obj ''$float_accepted 0)
  289.     {
  290.         if(!$this->rules($obj))return;
  291.  
  292.         if($float_accepted)
  293.         {
  294.             // $res = ereg('^[+-]?[0-9]*\.?[0-9]+$', $_POST[$this->last_obj]);
  295.             $res preg_match('/^[+-]?[0-9]*\.?[0-9]+$/'$_POST[$this->last_obj]);
  296.         }
  297.         else
  298.         {
  299.             $res ctype_digit($_POST[$this->last_obj]);
  300.         }
  301.  
  302.         if(!empty($_POST[$this->last_obj]&& !$res)
  303.         {
  304.             if(!$this->errorCustom())
  305.             {
  306.                 //if($this->formErrorLang == 'fr')
  307.                 //    $msg = "Le champ '$this->last_obj' ne peut contenir que des chiffres";
  308.                 //else
  309.                 //    $msg = "Field '$this->last_obj' can only countain digit";
  310.  
  311.                 $obj_name $this->formGetUserObjectName();
  312.                 $msg $this->getMessage(2array($obj_name));
  313.  
  314.                 $this->msg_err[$msg;
  315.                 $this->objErrorMsg[$this->last_obj][$msg;
  316.             }
  317.         }
  318.         $this->custom_msg = ''# remove custom error message
  319.  
  320.  
  321.     }
  322.  
  323.     /**
  324.      * This method allows you to verify $_POST value is equal
  325.      *
  326.      * @param string $obj 
  327.      * @param string $value 
  328.      * @author H2LSOFT */
  329.     public function equal($obj ''$value)
  330.     {
  331.         $this->isEqual($obj ''$value);
  332.  
  333.     }
  334.  
  335.     /**
  336.      * This method allows you to verify $_POST value is equal
  337.      *
  338.      * @param string $obj 
  339.      * @param string $value 
  340.      *
  341.      * @deprecated
  342.      *
  343.      * @author H2LSOFT */
  344.     public function isEqual($obj ''$value)
  345.     {
  346.         if(!$this->rules($obj))return;
  347.         if(!empty($_POST[$this->last_obj]&& $_POST[$this->last_obj!= $value)
  348.         {
  349.             if(!$this->errorCustom())
  350.             {
  351.                 //if($this->formErrorLang == 'fr')
  352.                 //    $msg = "Le champ '$this->last_obj' doit être égale à '$value'";
  353.                 //else
  354.                 //    $msg = "Field '$this->last_obj' must be equal at '$value'";
  355.  
  356.                 $obj_name $this->formGetUserObjectName();
  357.                 $msg $this->getMessage(3array($obj_name$value));
  358.  
  359.                 $this->msg_err[$msg;
  360.                 $this->objErrorMsg[$this->last_obj][$msg;
  361.             }
  362.         }
  363.  
  364.         $this->custom_msg = '';
  365.     }
  366.  
  367.     /**
  368.      * This method allows to verify $_POST value is in the list
  369.      *
  370.      * @param string $obj 
  371.      * @param array $value 
  372.      * @author H2LSOFT */
  373.     public function inList($obj ''$value)
  374.     {
  375.         $this->inList($obj ''$value);
  376.     }
  377.  
  378.     /**
  379.      * This method allows to verify $_POST value is in the list
  380.      *
  381.      * @param string $obj 
  382.      * @param array $arr_value 
  383.      * @param boolean $case_sensitive 
  384.      *
  385.      * @deprecated
  386.      *
  387.      * @author H2LSOFT */
  388.     public function isInList($obj ''$arr_value$case_sensitive false)
  389.     {
  390.         if(!$this->rules($obj))return;
  391.  
  392.         $obj str_replace('[]'''$obj);
  393.         $val $_POST[$obj];
  394.  
  395.  
  396.         $arr_value_o $arr_value;
  397.         if(!$case_sensitive)
  398.         {
  399.             if(!is_array($val))
  400.                 $val strtolower($val);
  401.             else
  402.                 $val array_map('strtolower'$val);
  403.  
  404.             $arr_value array_map('strtolower'$arr_value);
  405.         }
  406.  
  407.         $err false;
  408.         if(is_array($val))
  409.         {
  410.             foreach($val as $v)
  411.             {
  412.                 if(!in_array($v$arr_valuetrue))
  413.                 {
  414.                     $err true;
  415.                     break;
  416.                 }
  417.             }
  418.         }
  419.         else
  420.         {
  421.             if(!in_array($val$arr_valuetrue))
  422.             {
  423.                 $err true;
  424.             }
  425.         }
  426.  
  427.  
  428.         if($err)
  429.         {
  430.             if(!$this->errorCustom())
  431.             {
  432.                 $values join(', '$arr_value_o);
  433.  
  434.                 //if($this->formErrorLang == 'fr')
  435.                 //    $msg = "Le champ '$this->last_obj' doit être dans la liste à '$values'";
  436.                 //else
  437.                 //    $msg = "Field '$this->last_obj' must be in the list '$values'";
  438.  
  439.                 $obj_name $this->formGetUserObjectName();
  440.                 $msg $this->getMessage(4array($obj_name$values));
  441.  
  442.                 $this->msg_err[$msg;
  443.                 $this->objErrorMsg[$this->last_obj][$msg;
  444.             }
  445.         }
  446.         $this->custom_msg = '';
  447.     }
  448.  
  449.     /**
  450.      * this method allows to check if the value contained is only letters characters.
  451.      *
  452.      * @param string $obj 
  453.      * @author H2LSOFT */
  454.     public function onlyLetter($obj '')
  455.     {
  456.         if(!$this->rules($obj))return;
  457.         if(!ctype_alpha($_POST[$this->last_obj]))
  458.         {
  459.             if(!$this->errorCustom())
  460.             {
  461.                 //if($this->formErrorLang == 'fr')
  462.                 //    $msg = "Le champ '$this->last_obj' ne peut contenir que des lettres";
  463.                 //else
  464.                 //    $msg = "Field '$this->last_obj' can only countain letters";
  465.  
  466.                 $obj_name $this->formGetUserObjectName();
  467.                 $msg $this->getMessage(5array($obj_name));
  468.  
  469.                 $this->msg_err[$msg;
  470.                 $this->objErrorMsg[$this->last_obj][$msg;
  471.             }
  472.         }
  473.  
  474.         $this->custom_msg = '';
  475.     }
  476.  
  477.     /**
  478.      * this method allows to check if the value given to the object is an email.
  479.      *
  480.      * @param string $obj 
  481.      * @author H2LSOFT */
  482.     public function email($obj '')
  483.     {
  484.         if(!$this->rules($obj))return;
  485.  
  486.         //if(!eregi("^[_\.0-9a-z-]+@([0-9a-z-]+\.)+[a-z]{2,4}$", $_POST[$this->last_obj]) && (!empty($_POST[$this->last_obj])))
  487.         if(!preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/i"$_POST[$this->last_obj]&& (!empty($_POST[$this->last_obj])))
  488.         {
  489.             if(!$this->errorCustom())
  490.             {
  491.                 //if($this->formErrorLang == 'fr')
  492.                 //    $msg = "Le champ '$this->last_obj' n'est pas une adresse mail valide";
  493.                 //else
  494.                 //    $msg = "Field '$this->last_obj' is not a valid mail address";
  495.  
  496.                 $obj_name $this->formGetUserObjectName();
  497.                 $msg $this->getMessage(6array($obj_name));
  498.  
  499.                 $this->msg_err[$msg;
  500.                 $this->objErrorMsg[$this->last_obj][$msg;
  501.             }
  502.         }
  503.         $this->custom_msg = '';
  504.     }
  505.  
  506.     /**
  507.      * this method allows to check that the value is N length.
  508.      *
  509.      * @param string $obj 
  510.      * @param int $length 
  511.      * @author H2LSOFT */
  512.     public function charLength($obj ''$length)
  513.     {
  514.         if(!$this->rules($obj))return;
  515.         if(strlen($_POST[$this->last_obj]!= $length)
  516.         {
  517.             if(!$this->errorCustom())
  518.             {
  519.                 //if($this->formErrorLang == 'fr')
  520.                 //    $msg = "Le champ '$this->last_obj' doit contenir '$length' caractères";
  521.                 //else
  522.                 //    $msg = "Field '$this->last_obj' must contain '$length' characters";
  523.  
  524.                 $obj_name $this->formGetUserObjectName();
  525.                 $msg $this->getMessage(7array($obj_name,$length));
  526.  
  527.                 $this->msg_err[$msg;
  528.                 $this->objErrorMsg[$this->last_obj][$msg;
  529.             }
  530.         }
  531.         $this->custom_msg = '';
  532.     }
  533.  
  534.     /**
  535.      * method allows you to put lenght minimum for a chain of character.
  536.      *
  537.      * @param string $obj 
  538.      * @param int $length 
  539.      * @author H2LSOFT */
  540.     public function minLength($obj ''$length)
  541.     {
  542.         if(!$this->rules($obj))return;
  543.         if(!empty($_POST[$this->last_obj]&& strlen($_POST[$this->last_obj]$length)
  544.         {
  545.             if(!$this->errorCustom())
  546.             {
  547.                 //if($this->formErrorLang == 'fr')
  548.                 //    $msg = "Le champ '$this->last_obj' doit contenir au moins '$length' caractères";
  549.                 //else
  550.                 //    $msg = "Field '$this->last_obj' must contain at least '$length' characters";
  551.  
  552.                 $obj_name $this->formGetUserObjectName();
  553.                 $msg $this->getMessage(8array($obj_name,$length));
  554.  
  555.                 $this->msg_err[$msg;
  556.                 $this->objErrorMsg[$this->last_obj][$msg;
  557.             }
  558.         }
  559.         $this->custom_msg = '';
  560.     }
  561.  
  562.     /**
  563.      * this method allows you to check that the object does not exceed the N lenght.
  564.      *
  565.      * @param string $obj 
  566.      * @param int $length 
  567.      * @author H2LSOFT */
  568.     public function maxLength($obj ''$length)
  569.     {
  570.         if(!$this->rules($obj))return;
  571.         if(strlen($_POST[$this->last_obj]$length)
  572.         {
  573.             if(!$this->errorCustom())
  574.             {
  575.                 //if($this->formErrorLang == 'fr')
  576.                 //    $msg = "Le champ '$this->last_obj' doit contenir au maximum '$length' caractères";
  577.                 //else
  578.                 //    $msg = "Field '$this->last_obj' must contain '$length' characters maximum";
  579.  
  580.                 $obj_name $this->formGetUserObjectName();
  581.                 $msg $this->getMessage(9array($obj_name$length));
  582.  
  583.                 $this->msg_err[$msg;
  584.                 $this->objErrorMsg[$this->last_obj][$msg;
  585.             }
  586.         }
  587.         $this->custom_msg = '';
  588.     }
  589.  
  590.     /**
  591.      * method allows to check if the object datas converted as parameters correspond to the pattern converted as parameter.
  592.      *
  593.      * The last argument(facultative) corresponds to the message in the event of error.
  594.      *
  595.      * @param string $pattern 
  596.      * @param string $obj 
  597.      * @param string $mess 
  598.      * @author H2LSOFT */
  599.     public function regexControl($pattern$obj ''$mess)
  600.     {
  601.         if(!$this->rules($obj))return;
  602.  
  603.         // if(is_array($_POST[$this->last_obj]) || (!empty($_POST[$this->last_obj]) && !eregi($pattern, $_POST[$this->last_obj])))
  604.         if(is_array($_POST[$this->last_obj]|| (!empty($_POST[$this->last_obj]&& !preg_match('/'.$pattern.'/i'$_POST[$this->last_obj])))
  605.         {
  606.             $this->setMessage($mess);
  607.             $this->errorCustom();
  608.         }
  609.         $this->custom_msg = '';
  610.     }
  611.  
  612.     /**
  613.      * This method allows to control if object countains only alphabetic caracters
  614.      *
  615.      * @param string $obj 
  616.      * @param string $except 
  617.      * @author H2LSOFT */
  618.     public function alpha($obj$except '')
  619.     {
  620.         // verify if the obj is on parameter, per defect or is missed
  621.         if(!$this->rules($obj)) return;
  622.  
  623.         //if($this->formErrorLang == 'fr')
  624.         //    $mess = "Le champ '$this->last_obj' contient des caractères non alphabétique";
  625.         //else
  626.         //    $mess = "Field '$this->last_obj' countains non alphabetic characters";
  627.  
  628.         $obj_name $this->formGetUserObjectName();
  629.         $mess $this->getMessage(10,array($obj_name));
  630.  
  631.         $pattern '[[:alpha:]]';
  632.         if(!empty($except))
  633.         {
  634.             $tmp_pattern preg_quote($except);
  635.             $pattern '('.$pattern.'|'.$tmp_pattern.')';
  636.         }
  637.         if(!empty($this->custom_msg))
  638.             $mess $this->custom_msg;
  639.  
  640.         $this->regexControl('^'.$pattern.'*$'$obj$mess);
  641.         $this->custom_msg = '';
  642.     }
  643.  
  644.     /**
  645.      * This method allows to control if object countains only alphanumeric characters
  646.      *
  647.      * @param string $obj 
  648.      * @param string $except 
  649.      * @author H2LSOFT */
  650.     public function alphaNumeric($obj$except '')
  651.     {
  652.         // verify if the obj is on parameter, per defect or is missed
  653.         if(!$this->rules($obj)) return;
  654.  
  655.         //if($this->formErrorLang == 'fr')
  656.         //    $mess = "Le champ '$this->last_obj' contient des caractères non alphanumérique";
  657.         //else
  658.         //    $mess = "Field '$this->last_obj' countains non alphanumeric characters";
  659.  
  660.         $obj_name $this->formGetUserObjectName();
  661.         $mess $this->getMessage(10array($obj_name));
  662.  
  663.         $pattern '[[:alnum:]]';
  664.         if(!empty($except))
  665.         {
  666.             $tmp_pattern preg_quote($except);
  667.             $pattern '('.$pattern.'|'.$tmp_pattern.')';
  668.         }
  669.  
  670.         if(!empty($this->custom_msg))
  671.             $mess $this->custom_msg;
  672.  
  673.         $this->regexControl('^'.$pattern.'*$'$obj$mess);
  674.         $this->custom_msg = '';
  675.     }
  676.  
  677.     /**
  678.      * this method allows to verify a html form object is well filled. Format parameter must be a string composed by :
  679.      *
  680.      * d -> day m -> month y -> year 2 digits Y -> year 4 digits H -> hour i -> minutes s -> seconds
  681.      *
  682.      * @param string $obj 
  683.      * @param string $format 
  684.      * @author H2LSOFT */
  685.     public function date($obj$format)
  686.     {
  687.         $this->isDate($obj$format);
  688.     }
  689.  
  690.     /**
  691.      * This method allows to verify a html form object is well filled. Format parameter must be a string composed by :
  692.      *
  693.      * d -> day m -> month y -> year 2 digits Y -> year 4 digits H -> hour i -> minutes
  694.      *
  695.      * @param string $obj 
  696.      * @param string $format 
  697.      *
  698.      * @return boolean 
  699.      * @see date
  700.      * @deprecated
  701.      * @author H2LSOFT */
  702.     public function isDate($obj$format)
  703.     {
  704.         // verify if the obj is on parameter, per defect or is missed
  705.         if(!$this->rules($obj)) return;
  706.  
  707.         $pattern $format;
  708.         $pattern str_replace('d''[0-9]{2}'$pattern);
  709.         $pattern str_replace('m''[0-9]{2}'$pattern);
  710.         $pattern str_replace('y''[0-9]{2}'$pattern);
  711.         $pattern str_replace('Y''[0-9]{4}'$pattern);
  712.  
  713.         $pattern str_replace('H''[0-9]{2}'$pattern);
  714.         $pattern str_replace('i''[0-9]{2}'$pattern);
  715.         $pattern str_replace('s''[0-9]{2}'$pattern);
  716.  
  717.         $pattern "^$pattern$";
  718.  
  719.         //if($this->formErrorLang == 'fr')
  720.         //    $mess = "Le champ '$this->last_obj' n'est pas une date valide , format autorisé $format";
  721.         //else
  722.         //    $mess = "Field '$this->last_obj' is not a valid date, format allowed $format";
  723.  
  724.         $obj_name $this->formGetUserObjectName();
  725.         $mess $this->getMessage(11,array($obj_name,$format));
  726.         if(!empty($this->custom_msg))
  727.             $mess $this->custom_msg;
  728.         $this->regexControl($pattern$obj$mess);
  729.         $this->custom_msg = '';
  730.     }
  731.  
  732.     /**
  733.      * This method allows to control the value of your form is a correct url.
  734.      *
  735.      * @param string $obj 
  736.      * @param string $format 
  737.      * @author H2LSOFT */
  738.     public function url($obj$format 'http://|https://|ftp://')
  739.     {
  740.         // verify if the obj is on parameter, per defect or is missed
  741.         if(!$this->rules($obj)) return;
  742.         $format2 str_replace('/''\/'$format);
  743.         $pattern "^($format2){0,1}[A-Za-z0-9][A-Za-z0-9\-\.]+[A-Za-z0-9]\.[A-Za-z]{2,}[\43-\176]*$";
  744.  
  745.         //if($this->formErrorLang == 'fr')
  746.         //    $mess = "Le champ '$this->last_obj' n'est pas une url valide";
  747.         //else
  748.         //    $mess = "Field '$this->last_obj' is not a valid url";
  749.  
  750.         $obj_name $this->formGetUserObjectName();
  751.         $mess $this->getMessage(12,array($obj_name));
  752.         if(!empty($this->custom_msg))
  753.             $mess $this->custom_msg;
  754.  
  755.         $this->regexControl($pattern$obj$mess);
  756.         $this->custom_msg = '';
  757.     }
  758.  
  759.     /**
  760.      * method allows you to control the presence, the size and/or the extention of a file when it will be upload.
  761.      *
  762.      * Now, you can specify the size by adding Ko or Mo
  763.      *
  764.      * @param string $obj 
  765.      * @param boolean $required 
  766.      * @param string $size 
  767.      * @param string $mimes 
  768.      * @param string $ext 
  769.      * @author H2LSOFT */
  770.     public function fileControl($obj$required ''$size ''$mimes ''$ext '')
  771.     {
  772.         // check if the obj is on parameter, per defect or is missed
  773.         if(!$this->rules($obj)) return;
  774.         // check if the type of controled obj is upload type
  775.         if($_FILES)
  776.         {
  777.             if(empty($_FILES[$this->last_obj]))
  778.             {
  779.                 // error arguments are missing
  780.                 //if($this->formErrorLang == 'fr')
  781.                 //    die("<b>Erreur</b> : La restriction <b>fileControl</b> ne peut pas contrôler l'objet <b>$obj</b> <br> ou alors l'objet <b>$obj</b> n'existe pas");
  782.                 //else
  783.                 //    die("<b>Error</b> :  The restriction <b>fileControl</b> cannot control the object <b>$obj</b> or then the <b>$obj</b> object does not exist");
  784.  
  785.                 $obj_name $this->formGetUserObjectName();
  786.                 //die($this->getMessage(13, array($obj_name)));
  787.                 trigger_error($this->getMessage(13array($obj_name))E_USER_ERROR);
  788.             }
  789.             // Control of presence
  790.             if(!is_uploaded_file($_FILES[$this->last_obj]['tmp_name']))
  791.             {
  792.                 if($required)
  793.                 {
  794.                     if(!$this->errorCustom())
  795.                     {
  796.                         //if($this->formErrorLang == 'fr')
  797.                         //    $msg = "Le champ '$this->last_obj' doit être rempli";
  798.                         //else
  799.                         //    $msg = "Field '$this->last_obj' cannot be empty";
  800.  
  801.                         $obj_name $this->formGetUserObjectName();
  802.                         $msg $this->getMessage(1array($obj_name));
  803.  
  804.                         $this->msg_err[$msg;
  805.                         $this->objErrorMsg[$this->last_obj][$msg;
  806.                     }
  807.                 }
  808.                 $this->custom_msg = '';
  809.  
  810.                 return;
  811.             }
  812.  
  813.             // Control of the maximum file length
  814.             if(!empty($size&& !is_int($size))
  815.             {
  816.                 $taille_origin $size;
  817.  
  818.                 // replace Ko and Mo
  819.                 $size strtolower($size);
  820.                 $size str_replace(' '''$size);
  821.                 $size str_replace('ko''*1024'$size);
  822.                 $size str_replace('mo''*1024*1024'$size);
  823.                 eval("\$size = $size;");
  824.             }
  825.  
  826.             if(!empty($size&& ($_FILES[$this->last_obj]['size'$size))
  827.             {
  828.                 if(!$this->errorCustom())
  829.                 {
  830.                     //if($this->formErrorLang == 'fr')
  831.                     //    $msg = "$this->last_obj: La taille du fichier {$_FILES[$this->last_obj]['name']} dépasse la taille maximum autorisée qui est de $taille_origin";
  832.                     //else
  833.                     //    $msg = "$this->last_obj: he {$_FILES[$this->last_obj]['name']} 's file size is over than the allowed's maximum size which is $taille_origin";
  834.  
  835.                     $obj_name $this->formGetUserObjectName();
  836.                     $msg $this->getMessage(26array($obj_name$taille_origin));
  837.  
  838.                     $this->msg_err[$msg;
  839.                     $this->objErrorMsg[$this->last_obj][$msg;
  840.                 }
  841.                 $this->custom_msg = '';
  842.             }
  843.  
  844.             // check the extension
  845.             $ext_arr explode(','$ext);
  846.             $ext_arr array_map('trim'$ext_arr);
  847.             $ext_arr array_map('strtolower'$ext_arr);
  848.  
  849.             // take the extension of the file
  850.             //@ereg("\.([^\.]*$)", $_FILES[$this->last_obj]['name'], $elts);
  851.             preg_match("/\.([^\.]*$)/i"$_FILES[$this->last_obj]['name']$elts);
  852.  
  853.             if(!empty($ext&& (count($elts== || !in_array(strtolower($elts[1])$ext_arr)))
  854.             {
  855.                 if(!$this->errorCustom())
  856.                 {
  857.                     //if($this->formErrorLang == 'fr')
  858.                     //    $msg = "$this->last_obj: L'extension du fichier {$_FILES[$this->last_obj]['name']} n'est pas autorisée, seulement '$ext'";
  859.                     //else
  860.                     //    $msg = "$this->last_obj: The extension of file {$_FILES[$this->last_obj]['name']} is not allowed, only '$ext'";
  861.  
  862.                     $obj_name $this->formGetUserObjectName();
  863.                     $msg $this->getMessage(14array($obj_name$ext));
  864.  
  865.                     $this->msg_err[$msg;
  866.                     $this->objErrorMsg[$this->last_obj][$msg;
  867.                 }
  868.                 $this->custom_msg = '';
  869.             }
  870.  
  871.             // Control MIME of file type
  872.             $mimes_arr explode(','$mimes);
  873.             $mimes_arr array_map('trim'$mimes_arr);
  874.             $mimes_arr array_map('strtolower'$mimes_arr);
  875.  
  876.             if(!empty($mimes&& !in_array(strtolower($_FILES[$this->last_obj]['type'])$mimes_arr))
  877.             {
  878.                 if(!$this->errorCustom())
  879.                 {
  880.                     //if($this->formErrorLang == 'fr')
  881.                     //    $msg = "$this->last_obj: Le type MIME `{$_FILES[$this->last_obj]['type']}` de votre fichier {$_FILES[$this->last_obj]['name']} n'est pas autorisé, seulement '$mimes'";
  882.                     //else
  883.                     //    $msg = "$this->last_obj: The MIME type `{$_FILES[$this->last_obj]['type']}` of {$_FILES[$this->last_obj]['name']} is not allowed, only '$mimes'";
  884.  
  885.                     $obj_name $this->formGetUserObjectName();
  886.                     $msg $this->getMessage(15,array($obj_name,$_FILES[$this->last_obj]['type']$mimes));
  887.  
  888.                     $this->msg_err[$msg;
  889.                     $this->objErrorMsg[$this->last_obj][$msg;
  890.                 }
  891.                 $this->custom_msg = '';
  892.             }
  893.         }
  894.         $this->custom_msg = '';
  895.     }
  896.  
  897.     /**
  898.      * this method allows to modify the language in which the error messages will be posted.
  899.      *
  900.      * @param string $lang 
  901.      * @author H2LSOFT */
  902.     public function formSetLang($lang)
  903.     {
  904.         $this->formErrorLang = $lang;
  905.     }
  906.  
  907.     /**
  908.      * method allows you to turn an object as error.
  909.      *
  910.      * @param string $obj 
  911.      * @param string $message 
  912.      * @author H2LSOFT */
  913.     public function addError($obj ''$message '')
  914.     {
  915.         if(!$this->rules($obj))return;
  916.  
  917.         if(!empty($message))
  918.         {
  919.             if(!$this->errorCustom())
  920.             {
  921.                 if(TPLN_OUTPUT_CHARSET == 'utf-8')
  922.                     $msg $message;
  923.                 else
  924.                     $msg utf8_decode($message);
  925.                 $this->msg_err[$message;
  926.             }
  927.         }
  928.         else
  929.         {
  930.             if(!$this->errorCustom())
  931.             {
  932.                 if($this->formErrorLang == 'fr')
  933.                     $msg "";
  934.                 else
  935.                     $msg "";
  936.             }
  937.         }
  938.  
  939.         $this->msg_err[$msg;
  940.         $this->objErrorMsg[$this->last_obj][$msg;
  941.         $this->custom_msg = '';
  942.     }
  943.  
  944.     /**
  945.      * method allows you to control the picture width and height uploaded.
  946.      *
  947.      * The object name can be forgotten if it has been used in a other method previously.
  948.      *
  949.      * @param string $obj 
  950.      * @param int $w 
  951.      * @param int $h 
  952.      * @author H2LSOFT */
  953.     public function imgStrictDimension($obj ''$w ''$h '')
  954.     {
  955.         // check if the obj is on parameter, per defect or is missed
  956.         if(!$this->rules($obj)) return;
  957.         // check if there is exists one restriction at least
  958.         if((empty($w)) && (empty($h)))
  959.         {
  960.             // error the arguments are missing
  961.             //if($this->formErrorLang == 'fr')
  962.             //    die("Argument manquant sur la methode imgStrictDimension contrôlant l'objet $this->last_obj ");
  963.             //else
  964.             //    die("Argument missing on the method imgStrictDimension controlling the $this->last_obj object");
  965.  
  966.             $obj_name $this->formGetUserObjectName();
  967.             //die($this->getMessage(16, array($obj_name)));
  968.             trigger_error($this->getMessage(16array($obj_name))E_USER_ERROR);
  969.         }
  970.         else // at least onr argument exists
  971.  
  972.         {
  973.             // check if the type of controled obj is upload type
  974.             if($_FILES)
  975.             {
  976.                 if(!isset($_FILES[$this->last_obj]))
  977.                 {
  978.                     // Erreur the obj is not correct
  979.                     //if($this->formErrorLang == 'fr')
  980.                     //    die("Erreur : La restriction imgStrictDimension peut pas contrôler l'objet $this->last_obj ou alors l'objet $this->last_obj n'existe pas");
  981.                     //else
  982.                     //    die("Error :  The restriction imgStrictDimension cannot control the object $this->last_obj or then the $this->last_obj object does not exist");
  983.  
  984.                     $obj_name $this->formGetUserObjectName();
  985.                     //die($this->getMessage(17,array($obj_name,$obj_name)));
  986.                     trigger_error($this->getMessage(17,array($obj_name,$obj_name))E_USER_ERROR);
  987.                 }
  988.             }
  989.  
  990.             // if we upload the picture and if the picture exixts
  991.             if(($_FILES&&
  992.                 (
  993.                 // eregi('^image/', $_FILES[$this->last_obj]['type'])
  994.                 stripos($_FILES[$this->last_obj]['type']'image/'!== false &&
  995.                 stripos($_FILES[$this->last_obj]['type']'image/'== 0
  996.  
  997.                 && # ,the type is picture
  998.                 ($dimension getimagesize($_FILES[$this->last_obj]['tmp_name'])) # and the picture exixts
  999.             )
  1000.             {
  1001.                 // test of the width
  1002.                 if(!empty($w&& ($w != $dimension[0]))
  1003.                 {
  1004.                     if(!$this->errorCustom()) # if the error has already referenced
  1005.  
  1006.                     {
  1007.                         if($this->formErrorLang == 'fr'# we select the language
  1008.  
  1009.                         {
  1010.                             if(($dimension[0$w0# calculate the diff�rences
  1011.                                 $relation 'grande';
  1012.                             else
  1013.                                 $relation 'petite';
  1014.  
  1015.                             //$msg = "La largeur de l'image {$_FILES[$this->last_obj]['name']} est trop $relation de " . abs($dimension[0] - $w) . " pixels (autorisé $w px)";
  1016.  
  1017.                             $obj_name $this->formGetUserObjectName();
  1018.                             $msg $this->getMessage(27,array($obj_name$relationabs($dimension[0$w)$w));
  1019.                             $this->custom_msg = '';
  1020.                         }
  1021.  
  1022.                         else
  1023.                         {
  1024.                             if(($dimension[0$w0)
  1025.                                 $relation 'big';
  1026.                             else
  1027.                                 $relation 'small';
  1028.  
  1029.                             //$msg = "The width of the image {$_FILES[$this->last_obj]['name']}  is too $relation by " . abs($dimension[0] - $w) . " pixels (allowed $w px)";
  1030.  
  1031.                             $obj_name $this->formGetUserObjectName();
  1032.                             $msg $this->getMessage(27,array($obj_name$relationabs($dimension[0$w)$w));
  1033.                             $this->custom_msg = '';
  1034.                         }
  1035.  
  1036.                         $this->msg_err[$msg;
  1037.                         $this->objErrorMsg[$this->last_obj][$msg;
  1038.                     }
  1039.                 }
  1040.  
  1041.                 // test of width
  1042.                 if(!empty($h&& ($h != $dimension[1]))
  1043.                 {
  1044.                     if(!$this->errorCustom())
  1045.                     {
  1046.                         if($this->formErrorLang == 'fr')
  1047.                         {
  1048.                             if(($dimension[1$h0)
  1049.                                 $relation 'grande';
  1050.                             else
  1051.                                 $relation 'petite';
  1052.  
  1053.                             //$msg = "La hauteur de l'image {$_FILES[$this->last_obj]['name']} est trop $relation de " . abs($dimension[1] - $h) . " pixels (autorisé $h px)";
  1054.  
  1055.                             $obj_name $this->formGetUserObjectName();
  1056.                             $msg $this->getMessage(28,array($obj_name$relationabs($dimension[1$h),$h));
  1057.                             $this->custom_msg = '';
  1058.                         }
  1059.                         else
  1060.                         {
  1061.                             if(($dimension[1$h0)
  1062.                                 $relation 'big';
  1063.                             else
  1064.                                 $relation 'small';
  1065.  
  1066.                             //$msg = "The height of the image {$_FILES[$this->last_obj]['name']}  is too $relation by " . abs($dimension[1] - $h) . " pixels (allowed $h px)";
  1067.  
  1068.                             $obj_name $this->formGetUserObjectName();
  1069.                             $msg $this->getMessage(28,array($obj_name$relationabs($dimension[1$h),$h));
  1070.                             $this->custom_msg = '';
  1071.                         }
  1072.  
  1073.                         $this->msg_err[$msg;
  1074.                         $this->objErrorMsg[$this->last_obj][$msg;
  1075.                     }
  1076.                 }
  1077.             }
  1078.         }
  1079.         $this->custom_msg = '';
  1080.     }
  1081.  
  1082.     /**
  1083.      * This method allows to control the width of uploaded image.
  1084.      *
  1085.      * The list of supported operator is : - '<' - '<=' - '=' - '>' - '>='
  1086.      *
  1087.      * @param string $obj 
  1088.      * @param string $operator 
  1089.      * @param int $width 
  1090.      * @author H2LSOFT */
  1091.     public function imgControlWidth($obj ''$operator$width)
  1092.     {
  1093.         // check if the obj is on parameter, per defect or is missed
  1094.         if(!$this->rules($obj)) return;
  1095.  
  1096.         // check if there is exists one restriction at least
  1097.         if(!in_array($operatorarray('<''<=''=''>''>=')))
  1098.         {
  1099.             // error the arguments are missing
  1100.             //if($this->formErrorLang == 'fr')
  1101.             //    die("Operateur non valide sur la methode imgControlWidth controlant l'objet $this->last_obj ");
  1102.             //else
  1103.             //    die("Operator not valid on method imgControlWidth controling the $this->last_obj object");
  1104.  
  1105.             $obj_name $this->formGetUserObjectName();
  1106.             //die($this->getMessage(18,array($obj_name)));
  1107.             trigger_error($this->getMessage(18,array($obj_name))E_USER_ERROR);
  1108.  
  1109.         }
  1110.  
  1111.         if(!is_int($width))
  1112.         {
  1113.             //if($this->formErrorLang == 'fr')
  1114.             //    die("Largeur non valide sur la methode imgControlWidth contrôlant l'objet $this->last_obj ");
  1115.             //else
  1116.             //    die("Width not valid on method imgControlWidth controling the $this->last_obj object");
  1117.  
  1118.             $obj_name $this->formGetUserObjectName();
  1119.             //die($this->getMessage(19,array($obj_name)));
  1120.             trigger_error($this->getMessage(19,array($obj_name))E_USER_ERROR);
  1121.  
  1122.         }
  1123.  
  1124.         // check if the type of controled obj is upload type
  1125.         if($_FILES)
  1126.         {
  1127.             if(!isset($_FILES[$this->last_obj]))
  1128.             {
  1129.                 // error the ojbect is not correct
  1130.                 //if($this->formErrorLang == 'fr')
  1131.                 //    die("Erreur : La restriction imgControlWidth peut pas contrôler l'objet $this->last_obj ou alors l'objet $this->last_obj n'existe pas");
  1132.                 //else
  1133.                 //    die("Error :  The restriction imgControlWidth can not control the object $this->last_obj or then the $this->last_obj object does not exist");
  1134.  
  1135.                 $obj_name $this->formGetUserObjectName();
  1136.                 //die($this->getMessage(20,array($obj_name, $obj_name)));
  1137.                 trigger_error($this->getMessage(20,array($obj_name$obj_name))E_USER_ERROR);
  1138.             }
  1139.         }
  1140.  
  1141.         // if we upload a picture and if the picture exixts
  1142.         if(($_FILES&& # if we upload
  1143.             (
  1144.             // eregi('^image/', $_FILES[$this->last_obj]['type'])
  1145.             stripos($_FILES[$this->last_obj]['type']'image/'!== false &&
  1146.             stripos($_FILES[$this->last_obj]['type']'image/'== 0
  1147.             && # the type is picture
  1148.             ($dimension getimagesize($_FILES[$this->last_obj]['tmp_name'])) # and the picture exists
  1149.         )
  1150.         {
  1151.             // test of width
  1152.             $res false;
  1153.  
  1154.             if($operator == '<' && $dimension[0$width)$res true;
  1155.             elseif($operator == '<=' && $dimension[0<= $width)$res true;
  1156.             elseif($operator == '=' && $dimension[0$width)$res true;
  1157.             elseif($operator == '>' && $dimension[0$width)$res true;
  1158.             elseif($operator == '>=' && $dimension[0>= $width)$res true;
  1159.  
  1160.             if(!$res)
  1161.             {
  1162.                 if(!$this->errorCustom()) # if the error has already referenced
  1163.  
  1164.                 {
  1165.                     //if($this->formErrorLang == 'fr') # we select the language
  1166.                     //    $msg = "La largeur de l'image {$_FILES[$this->last_obj]['name']} doit être $operator à $width pixels";
  1167.                     //else
  1168.                     //    $msg = "The width of the image {$_FILES[$this->last_obj]['name']} must be $operator at $width pixels";
  1169.  
  1170.                     $obj_name $this->formGetUserObjectName();
  1171.                     $msg $this->getMessage(21array($obj_name$operator$width));
  1172.  
  1173.                     $this->msg_err[$msg;
  1174.                     $this->objErrorMsg[$this->last_obj][$msg;
  1175.                     $this->custom_msg = '';
  1176.                 }
  1177.             }
  1178.         }
  1179.         $this->custom_msg = '';
  1180.     }
  1181.  
  1182.     /**
  1183.      * This method allows you to control the height of uploaded image.
  1184.      *
  1185.      * The list of supported operator is : - '<' - '<=' - '=' - '>' - '>='
  1186.      *
  1187.      * @param string $obj 
  1188.      * @param string $operator 
  1189.      * @param int $width 
  1190.      * @author H2LSOFT */
  1191.     public function imgControlHeight($obj ''$operator$width)
  1192.     {
  1193.         // check if the obj is on parameter, per defect or is missed
  1194.         if(!$this->rules($obj)) return;
  1195.         // check if there is exists one restriction at least
  1196.         if(!in_array($operatorarray('<''<=''=''>''>=')))
  1197.         {
  1198.             // error the arguments are missing
  1199.             //if($this->formErrorLang == 'fr')
  1200.             //    die("Operateur non valide sur la methode imgControlHeight contrôlant l'objet $this->last_obj ");
  1201.             //else
  1202.             //    die("Operator not valid on method imgControlHeight controling the $this->last_obj object");
  1203.  
  1204.             $obj_name $this->formGetUserObjectName();
  1205.             //die($this->getMessage(18, array($obj_name)));
  1206.             trigger_error($this->getMessage(18array($obj_name))E_USER_ERROR);
  1207.         }
  1208.  
  1209.         if(!is_int($width))
  1210.         {
  1211.             //if($this->formErrorLang == 'fr')
  1212.             //    die("Hauteur non valide sur la methode imgControlHeight contrôlant l'objet $this->last_obj ");
  1213.             //else
  1214.             //    die("Height not valid on method imgControlHeight controling the $this->last_obj object");
  1215.  
  1216.             $obj_name $this->formGetUserObjectName();
  1217.             //die($this->getMessage(22, array($obj_name)));
  1218.             trigger_error($this->getMessage(22array($obj_name))E_USER_ERROR);
  1219.         }
  1220.         // check if the type of controled obj is upload type
  1221.         if($_FILES)
  1222.         {
  1223.             if(!isset($_FILES[$this->last_obj]))
  1224.             {
  1225.                 // error the ojbect is not correct
  1226.                 //if($this->formErrorLang == 'fr')
  1227.                 //    die("Erreur : La restriction imgControlHeight ne peut pas contrôler l'objet $this->last_obj ou alors l'objet $this->last_obj n'existe pas");
  1228.                 //else
  1229.                 //    die("Error :  The restriction imgControlHeight can not control the object $this->last_obj or then the $this->last_obj object does not exist");
  1230.  
  1231.                 $obj_name $this->formGetUserObjectName();
  1232.                 //die($this->getMessage(20, array($obj_name, $this->last_obj)));
  1233.                 trigger_error($this->getMessage(20array($obj_name$this->last_obj))E_USER_ERROR);
  1234.  
  1235.             }
  1236.         }
  1237.         // if we upload a picture and if the picture exixts
  1238.         if(($_FILES&& # if we upload
  1239.             (
  1240.             // eregi('^image/', $_FILES[$this->last_obj]['type'])
  1241.             stripos($_FILES[$this->last_obj]['type']'image/'!== false &&
  1242.             stripos($_FILES[$this->last_obj]['type']'image/'== 0
  1243.             && # ,the type is picture
  1244.             ($dimension getimagesize($_FILES[$this->last_obj]['tmp_name'])) # and the picture exists
  1245.         )
  1246.         {
  1247.             // test of width
  1248.             $res false;
  1249.  
  1250.             if($operator == '<' && $dimension[1$width)$res true;
  1251.             elseif($operator == '<=' && $dimension[1<= $width)$res true;
  1252.             elseif($operator == '=' && $dimension[1$width)$res true;
  1253.             elseif($operator == '>' && $dimension[1$width)$res true;
  1254.             elseif($operator == '>=' && $dimension[1>= $width)$res true;
  1255.  
  1256.             if(!$res)
  1257.             {
  1258.                 if(!$this->errorCustom()) # if the error has already referenced
  1259.  
  1260.                 {
  1261.                     //if($this->formErrorLang == 'fr') # we select the language
  1262.                     //    $msg = "La Hauteur de l'image {$_FILES[$this->last_obj]['name']} doit être $operator à $width pixels";
  1263.                     //else
  1264.                     //    $msg = "The Height of the image {$_FILES[$this->last_obj]['name']} must be $operator at $width pixels";
  1265.  
  1266.                     $obj_name $this->formGetUserObjectName();
  1267.                     $msg $this->getMessage(23array($obj_name$operator$width));
  1268.  
  1269.                     $this->msg_err[$msg;
  1270.                     $this->objErrorMsg[$this->last_obj][$msg;
  1271.                     $this->custom_msg = '';
  1272.                 }
  1273.             }
  1274.         }
  1275.         $this->custom_msg = '';
  1276.     }
  1277.  
  1278.     /**
  1279.      * treatment of the formulaire directly in PHP
  1280.      *
  1281.      * @param string $elements 
  1282.      * @param string $source 
  1283.      * @author H2LSOFT */
  1284.     public function formParse($elements$source)
  1285.     {
  1286.         //$errs = array_keys($this->objErrorMsg);
  1287.         $errs =  $this->objError;
  1288.  
  1289.         // capture the relevant formulaire
  1290.         if(empty($this->formName))
  1291.             $motif "<form [^>]* [^>]*>(.*)<\/form>";
  1292.         else
  1293.             $motif "<form [^>]* name=\"$this->formName\"[^>]*>(.*)<\/form>";
  1294.  
  1295.         preg_match("/$motif/mis"$source$arr);
  1296.         $form_init $arr[0];
  1297.         $form_html $arr[1];
  1298.  
  1299.         // take all of inputs
  1300.         $inputs['__ALL'array();
  1301.         $motif "<input[^>]*>";
  1302.         if(preg_match_all("/$motif/i"$form_html$arr))
  1303.             $inputs['__ALL'$arr[0];
  1304.  
  1305.         // take all of attributs
  1306.         $_inputs array()// contains the name of inputs
  1307.         for($i 0$i count($inputs['__ALL'])$i++)
  1308.         {
  1309.             // take the name
  1310.             $name $this->extractStr($inputs['__ALL'][$i]'name="''"');
  1311.             $type $this->extractStr($inputs['__ALL'][$i]'type="''"');
  1312.             $value_set false;
  1313.             if(strpos($inputs['__ALL'][$i]'value="'!== false)
  1314.                 $value_set true;
  1315.             $value $this->extractStr($inputs['__ALL'][$i]'value="''"');
  1316.             $style_set false;
  1317.             if(strpos($inputs['__ALL'][$i]'style="'!== false)
  1318.                 $style_set true;
  1319.             $style $this->extractStr($inputs['__ALL'][$i]'style="''"');
  1320.             $xhtml false;
  1321.  
  1322.             if($inputs['__ALL'][$i][strlen($inputs['__ALL'][$i])-2== '/')$xhtml true;
  1323.             // add the input
  1324.             if(!empty($name))
  1325.             {
  1326.                 if(!in_array($name$_inputs))$_inputs[$name;
  1327.                 $a array('type' => $type'value_set' => $value_set'value' => $value'style_set' => $style_set'style' => $style'xhtml' => $xhtml'html' => $inputs['__ALL'][$i]);
  1328.                 $input[$name][$a;
  1329.             }
  1330.         }
  1331.  
  1332.         // take alll of selects
  1333.         // $selects['__ALL'] = array();
  1334.         //$motif = "<select[^>]*>(.*)<\/select>";
  1335.         //if(preg_match_all("/$motif/mis", $form_html, $arr))
  1336.         //$selects['__ALL'] = $arr[0];
  1337.         $selects['__ALL'array();
  1338.         $tmpi $form_html;
  1339.         $arr array();
  1340.         do
  1341.         {
  1342.             $arri $this->extractStr($tmpi'<select''</select>'true);
  1343.             $tmpi substr($tmpistrpos($tmpi$arri)strlen($arri));
  1344.             if(!empty($arri))$selects['__ALL'][$arri;
  1345.         }
  1346.         while($arri);
  1347.  
  1348.         // take all of attributs
  1349.         $_selects array()// contains the name of selects
  1350.         for($i 0$i count($selects['__ALL'])$i++)
  1351.         {
  1352.             // take the name
  1353.             $name $this->extractStr($selects['__ALL'][$i]'name="''"');
  1354.             $style_set false;
  1355.             if(strpos($selects['__ALL'][$i]'style="'!== false)
  1356.                 $style_set true;
  1357.             $style $this->extractStr($selects['__ALL'][$i]'style="''"');
  1358.  
  1359.             // take the style of options and values
  1360.             //$motif = "<option[^>]*>(.*)<\/option>";
  1361.             //if(preg_match_all("/$motif/im", $selects['__ALL'][$i], $arr))
  1362.             //$options['__ALL'] = $arr[0];
  1363.             $options['__ALL'array();
  1364.  
  1365.             $tmpi $selects['__ALL'][$i];
  1366.             $arr array();
  1367.             do
  1368.             {
  1369.                 $arri $this->extractStr($tmpi'<option''</option>'true);
  1370.                 $tmpi substr($tmpistrpos($tmpi$arri)strlen($arri));
  1371.                 if(!empty($arri))$options['__ALL'][$arri;
  1372.             }
  1373.             while($arri);
  1374.  
  1375.             $option array();
  1376.             for($j 0$j count($options['__ALL'])$j++)
  1377.             {
  1378.                 $value_op $this->extractStr($options['__ALL'][$j]'value="''"');
  1379.                 $style_op_set false;
  1380.                 if(strpos($options['__ALL'][$j]'style="'!== false)
  1381.                     $style_op_set true;
  1382.                 $style_op $this->extractStr($options['__ALL'][$j]'style="''"');
  1383.                 $option[array('value' => $value_op'style_set' => $style_op_set'style' => $style_op'html' => $options['__ALL'][$j]'parsed' => $options['__ALL'][$j]);
  1384.             }
  1385.  
  1386.             // add the select
  1387.             if(!empty($name))
  1388.             {
  1389.                 if(!in_array($name$_selects))$_selects[$name;
  1390.                 $select[$name][array('style' => $style'style_set' => $style_set'option' => $option'html' => $selects['__ALL'][$i]);
  1391.             }
  1392.         }
  1393.  
  1394.         // take the textareas
  1395.         $textareas['__ALL'array();
  1396.         //$motif = "<textarea[^>]*>(.*)<\/textarea>";
  1397.         //if(preg_match_all("/$motif/i", $form_html, $arr))
  1398.         //$textareas['__ALL'] = $arr[0];
  1399.         $tmpi $form_html;
  1400.         $arr array();
  1401.         do
  1402.         {
  1403.             $arri $this->extractStr($tmpi'<textarea''</textarea>'true);
  1404.             $tmpi substr($tmpistrpos($tmpi$arri)strlen($arri));
  1405.             if(!empty($arri))$textareas['__ALL'][$arri;
  1406.         }
  1407.         while($arri);
  1408.  
  1409.         // take all of attributs
  1410.         $_textareas array()// contains name of selects
  1411.         for($i 0$i count($textareas['__ALL'])$i++)
  1412.         {
  1413.             // take the name
  1414.             $name $this->extractStr($textareas['__ALL'][$i]'name="''"');
  1415.             $style_set false;
  1416.             if(strpos($textareas['__ALL'][$i]'style="'!== false)
  1417.                 $style_set true;
  1418.             $style $this->extractStr($textareas['__ALL'][$i]'style="''"');
  1419.             $value $this->extractStr($textareas['__ALL'][$i]'>''</textarea>');
  1420.  
  1421.             // add the input
  1422.             if(!empty($name))
  1423.             {
  1424.                 if(!in_array($name$_textareas))$_textareas[$name;
  1425.                 $textarea[$name][array('value' => $value'style_set' => $style_set'style' => $style'html' => $textareas['__ALL'][$i]);
  1426.             }
  1427.         }
  1428.  
  1429.         // assign our values ***************************************************************************
  1430.         $form_parsed $form_init;
  1431.         $border_color "border:1px solid ".$this->formErrorColor.";";
  1432.         $bg_color "background-color:".$this->formErrorColor.";";
  1433.  
  1434.         foreach($elements as $key => $val)
  1435.         {
  1436.             $name $key;
  1437.             $name_init $key;
  1438.             $multiple_values false;
  1439.             $values array();
  1440.             if(is_array($elements[$key]))
  1441.             {
  1442.                 $multiple_values true;
  1443.                 $name $name '[]';
  1444.             }
  1445.  
  1446.             // input ?
  1447.             if(in_array($name$_inputs))
  1448.             {
  1449.                 if(in_array($input[$name][0]['type']array('text''hidden''password''file')))
  1450.                 {
  1451.                     $t $input[$name][0]['html'];
  1452.                     // value existante or not ?
  1453.                     if(!$input[$name][0]['value_set'])
  1454.                     {
  1455.                         // XHTML ?
  1456.                         if($input[$name][0]['xhtml'])
  1457.                             $t str_replace('/>'' value="' $val '" />'$t);
  1458.                         else
  1459.                             $t str_replace('>'' value="' $val '">'$t);
  1460.                     }
  1461.                     else
  1462.                     {
  1463.                         $t str_replace('value="' $input[$name][0]['value''"'' value="' $val '"'$t);
  1464.                     }
  1465.                     // input text error? ****************************************************************************
  1466.                     if(in_array($name$errs&& ($input[$name][0]['type'== 'text' || $input[$name][0]['type'== 'password' || $input[$name][0]['type'== 'file'))
  1467.                     {
  1468.                         $t2 '';
  1469.                         if($this->error_display_mode == 'I')
  1470.                         {
  1471.                             $t2 '<span style="color:'.$this->formErrorColor.'; font-weight:bold;">';
  1472.                             for($j 0$j count($this->objErrorMsg[$name])$j++)
  1473.                             {
  1474.                                 $t2 .= $this->objErrorMsg[$name][$j];
  1475.                                 $t2 .= '<br>';
  1476.                             }
  1477.                             $t2 .= "</span>";
  1478.                         }
  1479.  
  1480.                         $style trim($input[$name][0]['style']);
  1481.                         if(!empty($style&& $style[strlen($style)-1!= ';')$style .= '; ';
  1482.                         // Style to place ?
  1483.                         if(!$input[$name][0]['style_set'])
  1484.                         {
  1485.                             if($input[$name][0]['xhtml'])
  1486.                                 $t str_replace(' />'' style="' $border_color '" />'$t);
  1487.                             else
  1488.                                 $t str_replace('>'' style="' $border_color '" >'$t);
  1489.                         }
  1490.                         else
  1491.                         {
  1492.                             if($input[$name][0]['xhtml'])
  1493.                                 $t str_replace(' style="' $input[$name][0]['style''"'' style="' $style $border_color '"'$t);
  1494.                             else
  1495.                                 $t str_replace(' style="' $input[$name][0]['style''"'' style="' $style $border_color '"'$t);
  1496.                         }
  1497.                         $t $t2 $t;
  1498.                     }
  1499.                     // *******************************************************************************************
  1500.                     $form_parsed str_replace($input[$name][0]['html']$t$form_parsed);
  1501.                 }
  1502.                 // radio
  1503.                 elseif($input[$name][0]['type'== 'radio')
  1504.                 {
  1505.                     // group of radios have the same name
  1506.                     for($i 0$i count($input[$name])$i++)
  1507.                     {
  1508.                         $t $input[$name][$i]['html'];
  1509.  
  1510.                         if($input[$name][$i]['value'== $val)
  1511.                         {
  1512.                             if(strpos($input[$name][$i]['html']' checked'=== false)
  1513.                             {
  1514.                                 // XHTML ?
  1515.                                 if($input[$name][$i]['xhtml'])
  1516.                                     $t str_replace(' />'' checked />'$t);
  1517.                                 else
  1518.                                     $t str_replace('>'' checked >'$t);
  1519.                             }
  1520.                         }
  1521.                         else // take off the checked
  1522.  
  1523.                         {
  1524.                             $t str_replace(' checked'' '$t);
  1525.                         }
  1526.                         // radio error? ****************************************************************************
  1527.                         if(in_array($name$errs))
  1528.                         {
  1529.                             $t2 '';
  1530.                             if($i == && $this->error_display_mode == 'I')
  1531.                             {
  1532.                                 $t2 '<span style="color:'.$this->formErrorColor.'; font-weight:bold;">';
  1533.                                 for($k 0$k count($this->objErrorMsg[$name])$k++)
  1534.                                 {
  1535.                                     if($k 0)$t .= '';
  1536.                                     $t2 .= $this->objErrorMsg[$name][$k'<br />';
  1537.                                 }
  1538.                                 $t2 .= "</span>";
  1539.                             }
  1540.  
  1541.                             $style trim($input[$name][$i]['style']);
  1542.                             if(!empty($style&& $style[strlen($style)-1!= ';')$style .= '; ';
  1543.                             // Style to place ?
  1544.                             if(!$input[$name][$i]['style_set'])
  1545.                             {
  1546.                                 if($input[$name][$i]['xhtml'])
  1547.                                     $t str_replace(' />'' style="' $border_color '" />'$t);
  1548.                                 else
  1549.                                     $t str_replace('>'' style="' $border_color '" />'$t);
  1550.                             }
  1551.                             else
  1552.                             {
  1553.                                 if($input[$name][$i]['xhtml'])
  1554.                                     $t str_replace(' style="' $input[$name][$i]['style''"'' style="' $style $border_color '"'$t);
  1555.                                 else
  1556.                                     $t str_replace(' style="' $input[$name][$i]['style''"'' style="' $style $border_color '"'$t);
  1557.                             }
  1558.                             $t $t2 $t;
  1559.                         }
  1560.                         // *******************************************************************************************
  1561.                         $form_parsed $this->str_replace_count($input[$name][$i]['html']$t$form_parsed1);
  1562.                     }
  1563.                 // simple checkbox
  1564.                 elseif($input[$name][0]['type'== 'checkbox')
  1565.                 {
  1566.                     // multiple values ?
  1567.                     if($multiple_values)
  1568.                     {
  1569.                         $values array();
  1570.                         for($j 0$j count($elements[$name_init])$j++)
  1571.                             $values[$elements[$name_init][$j];
  1572.                     }
  1573.  
  1574.                     // group of checkboxs which have the same name
  1575.                     for($i 0$i count($input[$name])$i++)
  1576.                     {
  1577.                         $t $input[$name][$i]['html'];
  1578.                         if((!$multiple_values && $input[$name][$i]['value'== $val|| ($multiple_values && in_array($input[$name][$i]['value']$values)))
  1579.                         {
  1580.                             if(strpos($input[$name][$i]['html']' checked'=== false)
  1581.                             {
  1582.                                 // XHTML ?
  1583.                                 if($input[$name][$i]['xhtml'])
  1584.                                     $t str_replace(' />'' checked />'$t);
  1585.                                 else
  1586.                                     $t str_replace('>'' checked >'$t);
  1587.                             }
  1588.                         }
  1589.                         else // take off the checked
  1590.  
  1591.                         {
  1592.                             $t str_replace(' checked'' '$t);
  1593.                         }
  1594.  
  1595.                         // checkbox error ? ****************************************************************************
  1596.                         if(in_array($name$errs))
  1597.                         {
  1598.                             $t2 '';
  1599.                             if($i == && $this->error_display_mode == 'I')
  1600.                             {
  1601.                                 $t2 '<span style="color:'.$this->formErrorColor.'; font-weight:bold;">';
  1602.                                 for($k 0$k count($this->objErrorMsg[$name])$k++)
  1603.                                 {
  1604.                                     if($k 0)$t .= '';
  1605.                                     $t2 .= $this->objErrorMsg[$name][$k'<br />';
  1606.                                 }
  1607.                                 $t2 .= "</span>";
  1608.                             }
  1609.  
  1610.                             $style trim($input[$name][$i]['style']);
  1611.                             if(!empty($style&& $style[strlen($style)-1!= ';')$style .= '; ';
  1612.                             // Style to place ?
  1613.                             if(!$input[$name][$i]['style_set'])
  1614.                             {
  1615.                                 if($input[$name][$i]['xhtml'])
  1616.                                     $t str_replace(' />'' style="' $border_color '" />'$t);
  1617.                                 else
  1618.                                     $t str_replace('>'' style="' $border_color '" >'$t);
  1619.                             }
  1620.                             else
  1621.                             {
  1622.                                 if($input[$name][$i]['xhtml'])
  1623.                                     $t str_replace(' style="' $input[$name][$i]['style''"'' style="' $style $border_color '"'$t);
  1624.                                 else
  1625.                                     $t str_replace(' style="' $input[$name][$i]['style''"'' style="' $style $border_color '"'$t);
  1626.                             }
  1627.                             $t $t2 $t;
  1628.                         }
  1629.                         // *******************************************************************************************
  1630.                         $form_parsed $this->str_replace_count($input[$name][$i]['html']$t$form_parsed1);
  1631.                     }
  1632.                 }
  1633.             }
  1634.             // textarea ?
  1635.             elseif(in_array($name$_textareas))
  1636.             {
  1637.                 $t $textarea[$name][0]['html'];
  1638.                 $t str_replace('>' $textarea[$name][0]['value''</textarea>''>' $val '</textarea>'$t);
  1639.  
  1640.                 // textarea error ? ****************************************************************************
  1641.                 if(in_array($name$errs))
  1642.                 {
  1643.                     $style trim($textarea[$name][0]['style']);
  1644.                     if(!empty($style&& $style[strlen($style)-1!= ';')$style .= '; ';
  1645.                     // Style to place ?
  1646.                     if(!$textarea[$name][0]['style_set'])
  1647.                         $t $this->str_replace_count('>'' style="' $border_color '" >'$t1);
  1648.                     else
  1649.                         $t $this->str_replace_count(' style="' $textarea[$name][0]['style''"'' style="' $style $border_color '"'$t1);
  1650.  
  1651.                     if($this->error_display_mode == 'I')
  1652.                     {
  1653.                         $t2 '<span style="color:'.$this->formErrorColor.'; font-weight:bold;">';
  1654.                         for($j 0$j count($this->objErrorMsg[$name])$j++)
  1655.                         {
  1656.                             $t2 .= $this->objErrorMsg[$name][$j];
  1657.                             $t2 .= '<br />';
  1658.                         }
  1659.                         $t2 .= "</span>";
  1660.                         $t $t2 $t;
  1661.                     }
  1662.                 }
  1663.                 // *******************************************************************************************
  1664.                 $form_parsed str_replace($textarea[$name][0]['html']$t$form_parsed);
  1665.             }
  1666.             // select ?
  1667.             elseif(in_array($name$_selects))
  1668.             {
  1669.                 // simple select && multiple
  1670.                 for($i 0$i count($select[$name])$i++)
  1671.                 {
  1672.                     // multiple values  ?
  1673.                     if($multiple_values)
  1674.                     {
  1675.                         $values array();
  1676.                         for($j 0$j count($elements[$name_init])$j++)
  1677.                             $values[$elements[$name_init][$j];
  1678.                     }
  1679.                     // selected
  1680.                     for($j 0$j count($select[$name][$i]['option'])$j++)
  1681.                     {
  1682.                         if((!$multiple_values && $select[$name][$i]['option'][$j]['value'== $val|| ($multiple_values && in_array($select[$name][$i]['option'][$j]['value']$values)))
  1683.                         {
  1684.                             if(strpos($select[$name][$i]['option'][$j]['html']' selected'=== false)
  1685.                                 $select[$name][$i]['option'][$j]['parsed'$this->str_replace_count('>'' selected>'$select[$name][$i]['option'][$j]['html']1);
  1686.                         }
  1687.                         else // remove the selected
  1688.  
  1689.                         {
  1690.                             $select[$name][$i]['option'][$j]['parsed'$this->str_replace_count(' selected'' '$select[$name][$i]['option'][$j]['html']1);
  1691.                         }
  1692.                     }
  1693.                     // replace the correct select
  1694.                     $t $select[$name][$i]['html'];
  1695.                     for($j 0$j count($select[$name][$i]['option'])$j++)
  1696.                         $t $this->str_replace_count($select[$name][$i]['option'][$j]['html']$select[$name][$i]['option'][$j]['parsed']$t1);
  1697.  
  1698.                     // select error ? ****************************************************************************
  1699.                     if(in_array($name$errs))
  1700.                     {
  1701.                         $style trim($select[$name][$i]['style']);
  1702.                         if(!empty($style&& $style[strlen($style)-1!= ';')$style .= '; ';
  1703.                         // Style to place ?
  1704.                         if(!$select[$name][$i]['style_set'])
  1705.                             $t $this->str_replace_count('>'' style="' $bg_color '" >'$t1);
  1706.                         else
  1707.                             $t $this->str_replace_count(' style="' $select[$name][$i]['style''"'' style="' $style $bg_color '"'$t1);
  1708.  
  1709.                         if($this->error_display_mode == 'I')
  1710.                         {
  1711.                             $t2 '<span style="color:'.$this->formErrorColor.'; font-weight:bold;">';
  1712.                             for($j 0$j count($this->objErrorMsg[$name])$j++)
  1713.                             {
  1714.                                 $t2 .= $this->objErrorMsg[$name][$j'<br />';
  1715.                             }
  1716.                             $t2 .= "</span>";
  1717.                             $t $t2 $t;
  1718.                         }
  1719.                     }
  1720.                     // *******************************************************************************************
  1721.                     $form_parsed str_replace($select[$name][$i]['html']$t$form_parsed);
  1722.                 }
  1723.             }
  1724.         }
  1725.         return $form_parsed;
  1726.     }
  1727.  
  1728.     /**
  1729.      * This method allows to get total errors, it must be palced before the method formIsValid()
  1730.      *
  1731.      * @return int 
  1732.      * @author H2LSOFT */
  1733.     public function formGetTotalError()
  1734.     {
  1735.         return count(array_merge(array_unique($this->msg_err)array()));
  1736.     }
  1737.  
  1738.  
  1739.     /**
  1740.      * No protection for these values
  1741.      * @var array 
  1742.      */
  1743.     public $formInputProtectionException = array();
  1744.  
  1745.     /**
  1746.      *    Default charset for input protection
  1747.      * @var string 
  1748.      */
  1749.     public $formInputHtmlEntitiesCharset = TPLN_OUTPUT_CHARSET;
  1750.     
  1751.     
  1752.  
  1753.     /**
  1754.      * protect data agains user attacks
  1755.      *
  1756.      * @param array $arr 
  1757.      * @param bool $x_html_entities 
  1758.      * @param bool $x_protect_vars 
  1759.      */
  1760.     public function formXEntities($arr$x_html_entities=true$x_protect_vars=true)
  1761.     {        
  1762.         $clean_arr array();
  1763.         foreach($arr as $key => $val)
  1764.         {            
  1765.             if(is_array($val))
  1766.             {                
  1767.                 $clean_arr[$key$this->formXEntities($arr[$key]$x_html_entities$x_protect_vars);
  1768.             }
  1769.             else
  1770.             {
  1771.                 // html entities
  1772.                 if($x_html_entities && !in_array($key$this->formInputProtectionException))
  1773.                 {                                        
  1774.                     $val htmlentities($valENT_COMPAT$this->formInputHtmlEntitiesCharset);
  1775.                 }
  1776.                 
  1777.                 // x protect data
  1778.                 if(!in_array($key$this->formInputProtectionException&& $x_html_entities)
  1779.                 {
  1780.                     $val str_replace(array('{ '' }')array('{''}')$val)# clean
  1781.                     $val str_replace(array('{''}')array('{ '' }')$val);
  1782.                 }
  1783.  
  1784.                 $clean_arr[$key$val;
  1785.             }
  1786.         }        
  1787.         
  1788.         return $clean_arr;
  1789.     }
  1790.  
  1791.  
  1792.     /**
  1793.      * method allows to post the all prospective errors. The parameter is a boolean which allows to generate javascript.
  1794.      *
  1795.      * The javascript will allow to keep the data in the form during a post.
  1796.      * @author H2LSOFT */
  1797.     public function formIsValid(// destroy the error bolck if it has not a post
  1798.     {
  1799.         // check of captcha
  1800.         if($this->captcha)
  1801.             $this->autoVerifyCaptcha();
  1802.  
  1803.         // capture the relevant formulaire
  1804.         if(empty($this->formName))
  1805.             $motif "<form [^>]* [^>]*>(.*)<\/form>";
  1806.         else
  1807.             $motif "<form [^>]* name=\"$this->formName\"[^>]*>(.*)<\/form>";
  1808.         preg_match("/$motif/ims"$this->f[$this->f_no]['buffer']$arr);
  1809.         $form_html $arr[0];
  1810.         
  1811.         if(!$_POST)
  1812.         {
  1813.             // if the block form contains form_error
  1814.             $form_error_inside false;
  1815.             if(strpos($form_html'<bloc::form_error>'!== false)
  1816.                 $form_error_inside true;
  1817.  
  1818.             if($this->init)
  1819.             {
  1820.                 $form_parsed $this->formParse($this->row_val$this->f[$this->f_no]['buffer']);
  1821.                 $this->f[$this->f_no]['buffer'str_replace($form_html$form_parsed$this->f[$this->f_no]['buffer']);
  1822.             }
  1823.  
  1824.             // if($form_error_inside && $this->blocExists('form_error'))
  1825.             if($this->blocExists('form_error'))
  1826.                 $this->EraseBloc('form_error');
  1827.  
  1828.             if($this->blocExists('form_valid'))
  1829.                 $this->EraseBloc('form_valid');
  1830.         }
  1831.         else
  1832.         {
  1833.             
  1834.             if(count($this->msg_err0)
  1835.             {
  1836.                 // errors treantement
  1837.                 $form_parsed $this->formParse($_POST$this->f[$this->f_no]['buffer']);
  1838.                 $this->f[$this->f_no]['buffer'str_replace($form_html$form_parsed$this->f[$this->f_no]['buffer']);
  1839.  
  1840.                 // form valid ?
  1841.                 if($this->blocExists('form_valid'))
  1842.                     $this->EraseBloc('form_valid');
  1843.  
  1844.                 // html coding errors messages
  1845.                 // $this->msg_err = array_unique($this->msg_err);
  1846.                 $this->msg_err = array_merge(array_unique($this->msg_err)array());
  1847.  
  1848.                 foreach($this->msg_err as $key => $val)
  1849.                     $this->msg_err[$keyhtmlentities($val);
  1850.  
  1851.                 if($this->error_display_mode == 'T')
  1852.                 {
  1853.                     for($i 0$i count($this->msg_err)$i++)
  1854.                     {
  1855.                         $m $this->msg_err[$i];
  1856.  
  1857.                         if(!empty($m))
  1858.                         {
  1859.                             $this->Parse('form_error.msg'$m);
  1860.                             $this->Loop('form_error');
  1861.                         }
  1862.                     }
  1863.                 }
  1864.                 elseif($this->error_display_mode == 'I')
  1865.                 {
  1866.                     if($this->blocExists('form_error'))
  1867.                         $this->EraseBloc('form_error');
  1868.                 }
  1869.  
  1870.                 return false;
  1871.             }
  1872.             else
  1873.             {
  1874.                 $form_error_inside_form false;
  1875.                 if($this->blocExists('form_valid'))
  1876.                 {
  1877.                     $f_v $this->getBlocInFile('form_valid');
  1878.                     // if the block form:error is in the form
  1879.                     if(strpos($form_html'<bloc::form_error>'!== false)$form_error_inside_form true;
  1880.                     // replace directly in the buffer
  1881.                     $this->f[$this->f_no]['buffer'str_replace($form_html$f_v$this->f[$this->f_no]['buffer']);
  1882.                 }
  1883.  
  1884.                 // the block form_error is outside, it is automatically remplaced
  1885.                 if(!$form_error_inside_form && $this->blocExists('form_error'))
  1886.                     $this->EraseBloc('form_error');
  1887.  
  1888.                 if($this->blocExists('form_valid'))
  1889.                     $this->EraseBloc('form_valid');
  1890.  
  1891.                 // delete the values of captcha
  1892.                 $this->delCaptcha();
  1893.  
  1894.                 return true;
  1895.             }
  1896.         }
  1897.     }
  1898.  
  1899.     /**
  1900.      * This method allows to add a captcha verification useful to fight against spam attacks
  1901.      *
  1902.      * @return string 
  1903.      * @author H2LSOFT */
  1904.     public function getCaptcha()
  1905.     {
  1906.         $this->captcha = 1;
  1907.  
  1908.         // generate the number id
  1909.         if(!$_POST)$this->generateCaptcha();
  1910.  
  1911.         $sn session_name();
  1912.         $sn  ($sn == 'PHPSESSID''' '?sn='.base64_encode($sn);
  1913.         $str '<img src="'.TPLN_WEB_PATH.'/plugin/form/captcha.php'.$sn.'" alt="Security code" style="border:0px;" /><br />'."\n";
  1914.         $str .= '<input id="tpln_captcha" name="tpln_captcha" type="text" maxlength="5" />';
  1915.  
  1916.         return $str;
  1917.     }
  1918.  
  1919.     /**
  1920.      * delete captcha
  1921.      *
  1922.      * @return boolean 
  1923.      * @author H2LSOFT */
  1924.     protected function delCaptcha()
  1925.     {
  1926.         if(!isset($_SESSION))return;
  1927.  
  1928.         $sn session_name();
  1929.         if($sn == 'PHPSESSID')$sn '';
  1930.         if(empty($sn))
  1931.         {
  1932.             unset($_SESSION['tpln_captcha']);
  1933.             unset($_SESSION['tpln_captcha_nb']);
  1934.         }
  1935.         else
  1936.         {
  1937.             unset($_SESSION[$sn]['tpln_captcha']);
  1938.             unset($_SESSION[$sn]['tpln_captcha_nb']);
  1939.         }
  1940.     }
  1941.  
  1942.     var $captcha_max = 3;
  1943.  
  1944.     /**
  1945.      * This method allows to define a number of error for the user, by default 0: illimited
  1946.      *
  1947.      * @param int $nb 
  1948.      * @author H2LSOFT */
  1949.     public function setCaptchaMax($nb)
  1950.     {
  1951.         $this->captcha_max = $nb;
  1952.     }
  1953.  
  1954.     /**
  1955.      * generate captcha
  1956.      *
  1957.      * @author H2LSOFT */
  1958.     public function generateCaptcha()
  1959.     {
  1960.         $sn session_name();
  1961.         if($sn == 'PHPSESSID')$sn '';
  1962.  
  1963.         if(empty($sn))
  1964.         {
  1965.             $_SESSION['tpln_captcha'substr(md5(uniqid(time()))05);
  1966.             if(!isset($_SESSION['tpln_captcha_nb']))
  1967.                 $_SESSION['tpln_captcha_nb'0;
  1968.             else
  1969.                 $_SESSION['tpln_captcha_nb']++;
  1970.  
  1971.             if($_SESSION['tpln_captcha_nb'== $this->captcha_max)
  1972.             {
  1973.                 unset($_SESSION['tpln_captcha']);
  1974.                 unset($_SESSION['tpln_captcha_nb']);
  1975.                 //die('Error: You can not publish more than '.$this->captcha_max.' times');
  1976.                 //die($this->getMessage(24,array($this->captcha_max)));
  1977.                 trigger_error($this->getMessage(24,array($this->captcha_max))E_USER_ERROR);
  1978.             }
  1979.         }
  1980.         else
  1981.         {
  1982.             $_SESSION[$sn]['tpln_captcha'substr(md5(uniqid(time()))05);
  1983.             if(!isset($_SESSION[$sn]['tpln_captcha_nb']))
  1984.                 $_SESSION[$sn]['tpln_captcha_nb'0;
  1985.             else
  1986.                 $_SESSION[$sn]['tpln_captcha_nb']++;
  1987.  
  1988.             if($_SESSION[$sn]['tpln_captcha_nb'== $this->captcha_max)
  1989.             {
  1990.                 unset($_SESSION[$sn]['tpln_captcha']);
  1991.                 unset($_SESSION[$sn]['tpln_captcha_nb']);
  1992.                 //die('Error: You can not publish more than '.$this->captcha_max.' times');
  1993.                 //die($this->getMessage(24,array($this->captcha_max)));
  1994.                 trigger_error($this->getMessage(24,array($this->captcha_max))E_USER_ERROR);
  1995.             }
  1996.         }
  1997.     }
  1998.  
  1999.     /**
  2000.      * this method verifies automatically captcha
  2001.      *
  2002.      * @author H2LSOFT */
  2003.     protected function autoVerifyCaptcha()
  2004.     {
  2005.         $obj 'tpln_captcha';
  2006.  
  2007.         // verify if the obj is on parameter, per defect or missed
  2008.         if(!$this->rules($obj)) return;
  2009.  
  2010.         $sn session_name();
  2011.  
  2012.         if($sn == 'PHPSESSID')$sn '';
  2013.         if(empty($sn))
  2014.             $session_tpln_captcha $_SESSION['tpln_captcha'];
  2015.         else
  2016.             $session_tpln_captcha $_SESSION[$sn]['tpln_captcha'];
  2017.  
  2018.         if(strcmp($session_tpln_captcha$_POST['tpln_captcha']!= 0)
  2019.         {
  2020.             if(!$this->errorCustom())
  2021.             {
  2022.                 //if($this->formErrorLang == 'fr')
  2023.                 //    $msg = "Le code de sécurité n'est pas valide";
  2024.                 //else
  2025.                 //    $msg = "Your security code is not valid";
  2026.  
  2027.                 $msg $this->getMessage(25);
  2028.  
  2029.                 $this->msg_err[$msg;
  2030.                 $this->objErrorMsg[$this->last_obj][$msg;
  2031.             }
  2032.         }
  2033.  
  2034.         $this->generateCaptcha()// force the generation of captcha
  2035.         $_POST['tpln_captcha'''// delete the field
  2036.     }
  2037.  
  2038. }
  2039.  
  2040.  
  2041.  
  2042. ?>

Documentation generated on Sat, 06 Mar 2010 21:33:57 +0100 by phpDocumentor 1.4.3