Ejemplo n.º 1
0
 /**
  * Function fnValidatePostData will parse the Postdata and Generate
  * ad error message according to the Formula array we send
  * as parameter
  *
  * @param array $arrValidation
  * @return string $strErrorMsg
  */
 function fnValidatePostData($arrValidation = array(), $strReturnErrorFields = false, $strImageBreak = 0, $strReturnMsgs = 0)
 {
     if ($strImageBreak == 1) {
         $strLineBreak = "<br /><img src=\"images/error_small.jpg\" alt=\"error\" border=\"0\" align=\"absmiddle\"  /> ";
     } else {
         $strLineBreak = " <br />";
     }
     $strErrorMsg = false;
     $arrReturnErrorFields = array();
     if (is_array($this->P)) {
         if (count($this->P)) {
             foreach ($this->P as $strFieldName => $strPostValue) {
                 $enmIsErrror = false;
                 $strPostValue = trim($strPostValue);
                 if (array_key_exists($strFieldName, $arrValidation)) {
                     $strValue = $arrValidation[$strFieldName];
                     $arrValue = explode(":", $strValue);
                     if (is_array($arrValue)) {
                         if (count($arrValue)) {
                             foreach ($arrValue as $intKey => $strFormula) {
                                 $strFormula = trim($strFormula);
                                 $arrFormula = explode("-", $strFormula);
                                 if ($arrFormula[0] == "M") {
                                     if ($strPostValue == "") {
                                         if ($strErrorMsg) {
                                             $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                         } else {
                                             $strErrorMsg = $arrFormula[1];
                                         }
                                         $enmIsErrror = true;
                                     }
                                 }
                                 if ($arrFormula[0] == "E") {
                                     if ($strPostValue != "") {
                                         if (!clsUtil::fnValidateEmail($strPostValue)) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                             } else {
                                                 $strErrorMsg = $arrFormula[1];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "COMPANYNAME") {
                                     if ($strPostValue != "") {
                                         if (!clsUtil::fnValidateCompanyName($strPostValue)) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                             } else {
                                                 $strErrorMsg = $arrFormula[1];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "CHAR") {
                                     if ($strPostValue != "") {
                                         if (preg_match('!^[^a-zA-Z]+$!', $strFirstName) == 1) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                             } else {
                                                 $strErrorMsg = $arrFormula[1];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "PH") {
                                     if ($strPostValue != "") {
                                         if (!clsUtil::fnValidatePhone($strPostValue)) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                             } else {
                                                 $strErrorMsg = $arrFormula[1];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "SEL") {
                                     if ($strPostValue == "") {
                                         if ($strErrorMsg) {
                                             $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                         } else {
                                             $strErrorMsg = $arrFormula[1];
                                         }
                                         $enmIsErrror = true;
                                     }
                                 }
                                 if ($arrFormula[0] == "CHK") {
                                     if ($strPostValue == false) {
                                         if ($strErrorMsg) {
                                             $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                         } else {
                                             $strErrorMsg = $arrFormula[1];
                                         }
                                         $enmIsErrror = true;
                                     }
                                 }
                                 if ($arrFormula[0] == "NUM") {
                                     if ($strPostValue != "") {
                                         if (!(int) $strPostValue) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                             } else {
                                                 $strErrorMsg = $arrFormula[1];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "MIN") {
                                     if ($strPostValue != "") {
                                         $intLimit = strlen($strPostValue);
                                         if ($intLimit < (int) $arrFormula[1]) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[2];
                                             } else {
                                                 $strErrorMsg = $arrFormula[2];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "MAX") {
                                     if ($strPostValue != "") {
                                         $intLimit = strlen($strPostValue);
                                         if ($intLimit > (int) $arrFormula[1]) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[2];
                                             } else {
                                                 $strErrorMsg = $arrFormula[2];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "BET") {
                                     $intLimit = strlen($strPostValue);
                                     if ($intLimit < (int) $arrFormula[1] && $intLimit > (int) $arrFormula[2]) {
                                         if ($strErrorMsg) {
                                             $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[3];
                                         } else {
                                             $strErrorMsg = $arrFormula[3];
                                         }
                                         $enmIsErrror = true;
                                     }
                                 }
                                 if ($arrFormula[0] == "COMP") {
                                     $strCompValue = trim($this->P[$arrFormula[2]]);
                                     if ($strCompValue != "") {
                                         if ($arrFormula[1] == "==") {
                                             if ($strPostValue != $strCompValue) {
                                                 if ($strErrorMsg) {
                                                     $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[3];
                                                 } else {
                                                     $strErrorMsg = $arrFormula[3];
                                                 }
                                                 $enmIsErrror = true;
                                             }
                                         }
                                         if ($arrFormula[1] == "!=") {
                                             if ($strPostValue == $strCompValue) {
                                                 if ($strErrorMsg) {
                                                     $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[3];
                                                 } else {
                                                     $strErrorMsg = $arrFormula[3];
                                                 }
                                                 $enmIsErrror = true;
                                             }
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "COMPOR") {
                                     if ($this->P[$arrFormula[1]] != "" && $this->P[$arrFormula[2]] != "") {
                                         if ($strErrorMsg) {
                                             $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[3];
                                         } else {
                                             $strErrorMsg = $arrFormula[3];
                                         }
                                         $enmIsErrror = true;
                                     }
                                     if ($this->P[$arrFormula[1]] == "" && $this->P[$arrFormula[2]] == "") {
                                         if ($strErrorMsg) {
                                             $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[3];
                                         } else {
                                             $strErrorMsg = $arrFormula[3];
                                         }
                                         $enmIsErrror = true;
                                     }
                                 }
                                 if ($arrFormula[0] == "COMPALL") {
                                     $strPostFields = $arrFormula[1];
                                     $arrPostFields = explode("|", $strPostFields);
                                     if (count($arrPostFields) > 0 && is_array($arrPostFields)) {
                                         $intFilledData = 0;
                                         foreach ($arrPostFields as $strPostField) {
                                             if ($this->P[$strPostField] != "") {
                                                 $intFilledData++;
                                             }
                                         }
                                         if ($intFilledData != 0 && $intFilledData != count($arrPostFields)) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[2];
                                             } else {
                                                 $strErrorMsg = $arrFormula[2];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "URL") {
                                     if ($strPostValue != "") {
                                         if (!clsUtil::fnValidateUrl($strPostValue)) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                             } else {
                                                 $strErrorMsg = $arrFormula[1];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                                 if ($arrFormula[0] == "ARRCOUNT") {
                                     if ($strPostValue != "") {
                                         if (count($strPostValue) == 0) {
                                             if ($strErrorMsg) {
                                                 $strErrorMsg = $strErrorMsg . $strLineBreak . $arrFormula[1];
                                             } else {
                                                 $strErrorMsg = $arrFormula[1];
                                             }
                                             $enmIsErrror = true;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($enmIsErrror && $strReturnErrorFields) {
                     if ($strReturnMsgs == 1) {
                         $arrReturnErrorFields[] = $strLineBreak . $arrFormula[1];
                     } else {
                         $arrReturnErrorFields[] = $strFieldName;
                     }
                 }
             }
         }
     }
     if ($strReturnErrorFields) {
         return $arrReturnErrorFields;
     } else {
         return $strErrorMsg;
     }
 }