示例#1
0
 /**
  * Process the DOM for this form.
  * @param DOMNode $node
  * @param I2CE_Template $template
  * @param string $method
  * @param array $args
  */
 public function processDOM(&$node, &$template, $method, $args)
 {
     if (!is_callable(array($this, $method))) {
         I2CE::raiseError("Method {$method} not callable in {$this->getName()}", E_USER_NOTICE);
         //do nothing
         return;
     }
     if ($node->hasAttribute("ifset")) {
         $ifset = $node->getAttribute("ifset");
         if ($ifset[0] == "!") {
             $not = true;
             $ifset = substr($ifset, 1);
         } else {
             $not = false;
         }
         if (($ifset == "true" || $ifset == "dateblank") && $method == 'displayField') {
             //we check a field on the current form.  the field name is the argument
             $if_field = $this->getField($args[0]);
         } else {
             $phpfunc = '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*';
             if (preg_match("/^({$phpfunc})\$/", $ifset)) {
                 //we are looking at field of this form
                 $if_field = $this->getField($ifset);
             } else {
                 //we need to check the validity of a field of a different form
                 $if_field = $template->getField($ifset, $node);
             }
         }
         $is_value = true;
         if ($node->hasAttribute("ifvalue")) {
             $ifvalue = $node->getAttribute("ifvalue");
             if ($ifvalue[0] == "!") {
                 $val_not = true;
                 $ifvalue = substr($ifvalue, 1);
             } else {
                 $val_not = false;
             }
             $is_value = $if_field instanceof I2CE_FormField && $if_field->getDBValue() == $ifvalue;
             if ($val_not) {
                 $is_value = !$is_value;
             }
         }
         $is_valid = $if_field instanceof I2CE_FormField && $if_field->isValid();
         if ($ifset == "dateblank") {
             $is_valid = $is_valid && $if_field instanceof I2CE_FormField && $if_field->getValue() instanceof I2CE_Date && $if_field->getValue()->isBlank();
         }
         if (!($is_valid xor $not) || !$is_value) {
             $node->parentNode->removeChild($node);
             return;
         }
         $node->removeAttribute("ifset");
     } elseif ($node->hasAttribute("ifvalue")) {
         $ifvalue = $node->getAttribute("ifvalue");
         $if_field = $this->getField($args[0]);
         if ($ifvalue[0] == "!") {
             $val_not = true;
             $ifvalue = substr($ifvalue, 1);
         } else {
             $val_not = false;
         }
         $is_value = $if_field instanceof I2CE_FormField && $if_field->getDBValue() == $ifvalue;
         if ($val_not) {
             $is_value = !$is_value;
         }
         if (!$is_value) {
             $node->parentNode->removeChild($node);
             return;
         } else {
             if ($node->hasAttribute('display') && strlen($display = $node->getAttribute('display')) > 0) {
                 if ($display[0] == 'f' || !$display) {
                     $node->removeAttribute('type');
                     return;
                 }
             }
         }
     }
     $this->{$method}($node, $template, $args);
 }