Exemple #1
0
 function GetClientScript($bInGroup = false)
 {
     $sScript = '';
     if ($this->ClientValidate()) {
         $sLet = $bInGroup ? 'i' : 'v';
         $sScript = "{$sLet}=new Object();";
         $sType = $this->oNode->sName == 'vlgroup' ? 'group' : strtolower($this->oNode->aAttrs['type']);
         $sScript .= " {$sLet}.type=\"{$sType}\";";
         if (!$bInGroup) {
             $sName = VDEscape($this->oNode->aAttrs['name']);
             $sScript .= " {$sLet}.name=\"{$sName}\";";
             $sErrMsg = isset($this->oNode->aAttrs['errmsg']) ? VDEscape($this->oNode->aAttrs['errmsg']) : '';
             $sScript .= " {$sLet}.errmsg=\"{$sErrMsg}\";";
         }
         if ($sType != 'group' && ($sType != 'custom' || isset($this->oNode->aAttrs['control']))) {
             $sControl = VDEscape($this->oNode->aAttrs['control']);
             $sScript .= " {$sLet}.control=\"{$sControl}\";";
         }
         if ($sType == 'group') {
             $sScript .= "v.items=new Array();\n";
             foreach ($this->oNode->aSubNodes as $nIdx => $mTmp) {
                 $oSubNode =& $this->oNode->aSubNodes[$nIdx];
                 if (is_object($oSubNode) && $oSubNode->sName == 'vlvalidator') {
                     $oSubValidator =& new CVDValidator($oSubNode);
                     $sScript .= $oSubValidator->GetClientScript(true);
                 }
             }
             $sScript .= "f.validators[v.name]=v;\n";
         } else {
             $sCase = isset($this->oNode->aAttrs['casesensitive']) && strtolower($this->oNode->aAttrs['casesensitive']) != 'false' ? 'true' : 'false';
             $sValidType = isset($this->oNode->aAttrs['validtype']) ? strtolower($this->oNode->aAttrs['validtype']) : '';
             $sDateOrder = isset($this->oNode->aAttrs['dateorder']) ? strtolower($this->oNode->aAttrs['dateorder']) : 'mdy';
             switch ($sType) {
                 case 'required':
                     $sMinLength = isset($this->oNode->aAttrs['minlength']) ? $this->oNode->aAttrs['minlength'] : '1';
                     $sMaxLength = isset($this->oNode->aAttrs['maxlength']) ? $this->oNode->aAttrs['maxlength'] : '-1';
                     $sScript .= " {$sLet}.minlength={$sMinLength};";
                     $sScript .= " {$sLet}.maxlength={$sMaxLength};";
                     break;
                 case 'checktype':
                     $sScript .= " {$sLet}.validtype=\"{$sValidType}\";";
                     if ($sValidType == 'date') {
                         $sScript .= " {$sLet}.dateorder=\"{$sDateOrder}\";";
                     }
                     break;
                 case 'range':
                     $sMin = isset($this->oNode->aAttrs['minvalue']) ? VDEscape($this->oNode->aAttrs['minvalue']) : '';
                     $sMax = isset($this->oNode->aAttrs['maxvalue']) ? VDEscape($this->oNode->aAttrs['maxvalue']) : '';
                     $sScript .= " {$sLet}.validtype=\"{$sValidType}\";";
                     if ($sValidType == 'date') {
                         $sScript .= " {$sLet}.dateorder=\"{$sDateOrder}\";";
                     }
                     $sScript .= " {$sLet}.casesensitive={$sCase};";
                     $sScript .= " {$sLet}.minvalue=\"{$sMin}\";";
                     $sScript .= " {$sLet}.maxvalue=\"{$sMax}\";";
                     break;
                 case 'compare':
                     if (isset($this->oNode->aAttrs['comparevalue'])) {
                         $sAttr = 'comparevalue';
                         $sVal = VDEscape($this->oNode->aAttrs['comparevalue']);
                     } else {
                         $sAttr = 'comparecontrol';
                         $sVal = VDEscape($this->oNode->aAttrs['comparecontrol']);
                     }
                     $sOperator = isset($this->oNode->aAttrs['operator']) ? strtolower($this->oNode->aAttrs['operator']) : 'e';
                     $sScript .= " {$sLet}.validtype=\"{$sValidType}\";";
                     if ($sValidType == 'date') {
                         $sScript .= " {$sLet}.dateorder=\"{$sDateOrder}\";";
                     }
                     $sScript .= " {$sLet}.casesensitive={$sCase};";
                     $sScript .= " {$sLet}.{$sAttr}=\"{$sVal}\";";
                     $sScript .= " {$sLet}.operator=\"{$sOperator}\";";
                     break;
                 case 'regexp':
                     $sRegExp = isset($this->oNode->aAttrs['clientregexp']) ? VDEscape($this->oNode->aAttrs['clientregexp']) : VDEscape($this->oNode->aAttrs['regexp']);
                     $sScript .= " {$sLet}.clientregexp=\"{$sRegExp}\";";
                     break;
                 case 'custom':
                     $sFunc = isset($this->oNode->aAttrs['clientfunction']) ? $this->oNode->aAttrs['clientfunction'] : '';
                     $sScript .= " {$sLet}.clientfunction=\"{$sFunc}\";";
                     break;
             }
             if ($bInGroup) {
                 $sScript .= " v.items[v.items.length]=i;\n";
             } else {
                 $sScript .= " f.validators[v.name]=v;\n";
             }
         }
     }
     return $sScript;
 }
Exemple #2
0
 function GetClientScript()
 {
     $sScript = '';
     if ($this->ClientValidate()) {
         $sScript = "v[i]=new Object();";
         $sType = $this->oNode->sName == 'vlgroup' ? 'group' : strtolower($this->oNode->aAttrs['type']);
         $sScript .= " v[i].type=\"{$sType}\";";
         $sName = isset($this->oNode->aAttrs['name']) ? VDEscape($this->oNode->aAttrs['name']) : '';
         $sScript .= " v[i].name=\"{$sName}\";";
         $sErrMsg = isset($this->oNode->aAttrs['errmsg']) ? VDEscape($this->oNode->aAttrs['errmsg']) : '';
         $sScript .= " v[i].errmsg=\"{$sErrMsg}\";";
         if ($sType != 'group' && ($sType != 'custom' || isset($this->aCtrlName))) {
             $bFocus = !isset($this->oNode->aAttrs['setfocus']) || $this->oNode->aAttrs['setfocus'] !== 'false';
             if ($bFocus) {
                 $sControl = VDEscape($this->oNode->aAttrs['control']);
                 $sScript .= " v[i].fcontrol=\"{$sControl}\";";
             }
             $sScript .= " v[i].control=new Array();";
             foreach ($this->aCtrlName as $sIndex) {
                 $sControl = VDEscape($sIndex);
                 $sScript .= " v[i].control[v[i].control.length]=\"{$sControl}\";";
             }
         }
         if ($sType == 'group') {
             $sOperator = isset($this->oNode->aAttrs['operator']) ? strtolower($this->oNode->aAttrs['operator']) : 'or';
             $sScript .= " v[i].operator=\"{$sOperator}\";";
             $sScript .= " v[i].validators=new Array(); i++;\n";
             foreach ($this->aValidators as $nIdx => $mTmp) {
                 $sScript .= $this->aValidators[$nIdx]->GetClientScript();
             }
             $sScript .= "i=i-1; v[i-1].validators[v[i-1].validators.length]=v[i];\n";
         } else {
             $sCase = isset($this->oNode->aAttrs['casesensitive']) && strtolower($this->oNode->aAttrs['casesensitive']) != 'false' ? 'true' : 'false';
             $sValidType = isset($this->oNode->aAttrs['validtype']) ? strtolower($this->oNode->aAttrs['validtype']) : '';
             $sDateOrder = isset($this->oNode->aAttrs['dateorder']) ? strtolower($this->oNode->aAttrs['dateorder']) : 'mdy';
             $sTimeFormat = isset($this->oNode->aAttrs['timeformat']) ? strtolower($this->oNode->aAttrs['timeformat']) : '12';
             $sRequired = isset($this->oNode->aAttrs['required']) && strtolower($this->oNode->aAttrs['required']) != 'false' ? 'true' : 'false';
             $sNegation = isset($this->oNode->aAttrs['negation']) && strtolower($this->oNode->aAttrs['negation']) != 'false' ? 'true' : 'false';
             $sDecimalChar = isset($this->oNode->aAttrs['decimalchar']) ? $this->oNode->aAttrs['decimalchar'] : '.';
             $sDecimalChar = VDEscape(VDPregEscape($sDecimalChar));
             $sGroupChar = isset($this->oNode->aAttrs['groupchar']) ? $this->oNode->aAttrs['groupchar'] : '';
             $sGroupChar = VDEscape(VDPregEscape($sGroupChar));
             switch ($sType) {
                 case 'required':
                     $sMinLength = isset($this->oNode->aAttrs['minlength']) ? $this->oNode->aAttrs['minlength'] : '1';
                     $sMaxLength = isset($this->oNode->aAttrs['maxlength']) ? $this->oNode->aAttrs['maxlength'] : '-1';
                     $sScript .= " v[i].minlength={$sMinLength};";
                     $sScript .= " v[i].maxlength={$sMaxLength};";
                     $sScript .= " v[i].negation={$sNegation};";
                     break;
                 case 'checktype':
                     $sScript .= " v[i].required={$sRequired};";
                     $sScript .= " v[i].negation={$sNegation};";
                     $sScript .= " v[i].validtype=\"{$sValidType}\";";
                     if (in_array($sValidType, array('date', 'datetime'))) {
                         $sScript .= " v[i].dateorder=\"{$sDateOrder}\";";
                     }
                     if (in_array($sValidType, array('time', 'datetime'))) {
                         $sScript .= " v[i].timeformat=\"{$sTimeFormat}\";";
                     }
                     if (in_array($sValidType, array('float', 'currency'))) {
                         $sScript .= " v[i].decimalchar=\"{$sDecimalChar}\";";
                     }
                     if (in_array($sValidType, array('integer', 'float', 'currency'))) {
                         $sScript .= " v[i].groupchar=\"{$sGroupChar}\";";
                     }
                     break;
                 case 'range':
                     $sScript .= " v[i].required={$sRequired};";
                     $sScript .= " v[i].negation={$sNegation};";
                     $sMin = isset($this->oNode->aAttrs['minvalue']) ? VDEscape($this->oNode->aAttrs['minvalue']) : '';
                     $sMax = isset($this->oNode->aAttrs['maxvalue']) ? VDEscape($this->oNode->aAttrs['maxvalue']) : '';
                     $sScript .= " v[i].validtype=\"{$sValidType}\";";
                     if (in_array($sValidType, array('date', 'datetime'))) {
                         $sScript .= " v[i].dateorder=\"{$sDateOrder}\";";
                     }
                     if (in_array($sValidType, array('time', 'datetime'))) {
                         $sScript .= " v[i].timeformat=\"{$sTimeFormat}\";";
                     }
                     if (in_array($sValidType, array('float', 'currency'))) {
                         $sScript .= " v[i].decimalchar=\"{$sDecimalChar}\";";
                     }
                     if (in_array($sValidType, array('integer', 'float', 'currency'))) {
                         $sScript .= " v[i].groupchar=\"{$sGroupChar}\";";
                     }
                     $sScript .= " v[i].casesensitive={$sCase};";
                     $sScript .= " v[i].minvalue=\"{$sMin}\";";
                     $sScript .= " v[i].maxvalue=\"{$sMax}\";";
                     break;
                 case 'compare':
                     $sScript .= " v[i].required={$sRequired};";
                     $sScript .= " v[i].negation={$sNegation};";
                     $sScript .= " v[i].validtype=\"{$sValidType}\";";
                     if (in_array($sValidType, array('date', 'datetime'))) {
                         $sScript .= " v[i].dateorder=\"{$sDateOrder}\";";
                     }
                     if (in_array($sValidType, array('time', 'datetime'))) {
                         $sScript .= " v[i].timeformat=\"{$sTimeFormat}\";";
                     }
                     if (in_array($sValidType, array('float', 'currency'))) {
                         $sScript .= " v[i].decimalchar=\"{$sDecimalChar}\";";
                     }
                     if (in_array($sValidType, array('integer', 'float', 'currency'))) {
                         $sScript .= " v[i].groupchar=\"{$sGroupChar}\";";
                     }
                     $sScript .= " v[i].casesensitive={$sCase};";
                     if (isset($this->oNode->aAttrs['comparevalue'])) {
                         $sVal = VDEscape($this->oNode->aAttrs['comparevalue']);
                         $sScript .= " v[i].comparevalue=\"{$sVal}\";";
                     } else {
                         $aCompareCtrlName = VDGetPhpControlName($this->oNode->aAttrs['comparecontrol']);
                         $sScript .= " v[i].comparecontrol=new Array();";
                         foreach ($aCompareCtrlName as $sIndex) {
                             $sVal = VDEscape($sIndex);
                             $sScript .= " v[i].comparecontrol[v[i].comparecontrol.length]=\"{$sVal}\";";
                         }
                     }
                     $sOperator = isset($this->oNode->aAttrs['operator']) ? strtolower($this->oNode->aAttrs['operator']) : 'e';
                     $sScript .= " v[i].operator=\"{$sOperator}\";";
                     break;
                 case 'format':
                     $sScript .= " v[i].required={$sRequired};";
                     $sScript .= " v[i].negation={$sNegation};";
                     $sFormat = strtolower($this->oNode->aAttrs['format']);
                     $sScript .= " v[i].format=\"{$sFormat}\";";
                     break;
                 case 'regexp':
                     $sScript .= " v[i].required={$sRequired};";
                     $sScript .= " v[i].negation={$sNegation};";
                     $sRegExp = isset($this->oNode->aAttrs['clientregexp']) ? VDEscape($this->oNode->aAttrs['clientregexp']) : VDEscape($this->oNode->aAttrs['regexp']);
                     $sScript .= " v[i].clientregexp=\"{$sRegExp}\";";
                     break;
                 case 'custom':
                     $sFunc = isset($this->oNode->aAttrs['clientfunction']) ? $this->oNode->aAttrs['clientfunction'] : '';
                     $sScript .= " v[i].clientfunction=\"{$sFunc}\";";
                     break;
             }
             $sScript .= " v[i-1].validators[v[i-1].validators.length]=v[i];\n";
         }
     }
     return $sScript;
 }