Exemplo n.º 1
0
 /**
  * Recursive method to add all selected values into a multidimentionnal array representing a formular source
  * 
  * @param multidimentionnal array &$definition : the XML definition to treat (by reference)
  * @param array $fields : all form fields to get default values
  * @param array $fieldsError : all form fields malformed or required
  * @param (inplicit) the current global $_POST values
  * @access private
  * @return void
  */
 protected function _fillSelectedFormValues(&$definition, $fields, $fieldsError)
 {
     global $mod_cms_forms, $cms_user;
     if (is_array($definition) && is_array($definition[0])) {
         //loop on subtags
         foreach (array_keys($definition) as $key) {
             $fieldValue = null;
             if (isset($definition[$key]['attributes']['name'])) {
                 if (in_array($definition[$key]['attributes']['id'], $fieldsError)) {
                     //set class cms_field_error to field
                     $definition[$key]['attributes']['class'] = 'cms_field_error';
                 }
                 if (isset($_POST[$definition[$key]['attributes']['name']])) {
                     //set value from POST
                     $fieldValue = $_POST[$definition[$key]['attributes']['name']];
                 } else {
                     //set value from default field value
                     foreach ($fields as $field) {
                         if ($field->getAttribute('name') == $definition[$key]['attributes']['name'] && $field->getAttribute('value')) {
                             //set current page ID as a parameter
                             $parameters['pageID'] = sensitiveIO::isPositiveInteger($mod_cms_forms['pageID']) ? $mod_cms_forms['pageID'] : 1;
                             //evaluate default value if needed
                             $fieldValue = eval(sensitiveIO::sanitizeExecCommand('return "' . CMS_polymod_definition_parsing::preReplaceVars($field->getAttribute('value')) . '";'));
                         }
                     }
                 }
             }
             if (isset($definition[$key]['nodename']) && $definition[$key]['nodename'] == 'input' && $definition[$key]['attributes']['type'] == 'file') {
                 unset($definition[$key]['attributes']['value']);
             }
             if (isset($fieldValue)) {
                 switch ($definition[$key]['nodename']) {
                     case 'select':
                         foreach (array_keys($definition[$key]['childrens']) as $optionKey) {
                             if (isset($definition[$key]['childrens'][$optionKey]['attributes']['value']) && $definition[$key]['childrens'][$optionKey]['attributes']['value'] == $fieldValue) {
                                 $definition[$key]['childrens'][$optionKey]['attributes']['selected'] = 'selected';
                             }
                         }
                         break;
                     case 'textarea':
                         $definition[$key]['childrens']['0']['textnode'] = sensitiveIO::sanitizeHTMLString($fieldValue);
                         break;
                     case 'input':
                         if ($definition[$key]['attributes']['type'] == 'text' || $definition[$key]['attributes']['type'] == 'hidden') {
                             $definition[$key]['attributes']['value'] = sensitiveIO::sanitizeHTMLString($fieldValue);
                         } elseif ($definition[$key]['attributes']['type'] == 'checkbox') {
                             $definition[$key]['attributes']['checked'] = 'checked';
                         }
                         break;
                 }
             }
             if (isset($definition[$key]['childrens'])) {
                 $this->_fillSelectedFormValues($definition[$key]['childrens'], $fields, $fieldsError);
             }
         }
     } else {
         $this->raiseError("Malformed definition to compute : " . print_r($definition, true));
         return false;
     }
 }
    /**
     * Compute an atm-blockvar tag
     *
     * @param array $tag : the reference tag to compute
     * @return string the PHP / HTML content computed
     * @access private
     */
    protected function _blockVarTag(&$tag)
    {
        //check tags requirements
        if (!$this->checkTagRequirements($tag, array('id' => true, 'varname' => 'alphanum', 'vartype' => true, 'label' => true, 'mandatory' => '(true)|(false)'))) {
            return;
        }
        switch ($tag['attributes']['vartype']) {
            case 'string':
                if (!$this->checkTagValues($tag, array('maxLength' => array('value' => '([-+]?[0-9]+)', 'mandatory' => false), 'default' => array('value' => 'alphanum', 'mandatory' => false)))) {
                    return;
                }
                break;
            case 'integer':
                if (!$this->checkTagValues($tag, array('maxValue' => array('value' => '([-+]?[0-9]+)', 'mandatory' => false), 'minValue' => array('value' => '([-+]?[0-9]+)', 'mandatory' => false), 'default' => array('value' => '([-+]?[0-9]+)', 'mandatory' => false)))) {
                    return;
                }
                break;
            case 'boolean':
                if (!$this->checkTagValues($tag, array('default' => array('value' => '[0-1]', 'mandatory' => false)))) {
                    return;
                }
                break;
            case 'date':
                // do nothing
                break;
            case 'float':
                $pattern = '[-+]?[0-9]*\\.?[0-9]+';
                if (isset($tag['attributes']['separator'])) {
                    if ($tag['attributes']['separator'] != '.') {
                        $pattern = '[-+]?[0-9]*' . $tag['attributes']['separator'] . '?[0-9]+';
                    }
                }
                if (!$this->checkTagValues($tag, array('separator' => array('value' => '\\.|,', 'mandatory' => false), 'default' => array('value' => $pattern, 'mandatory' => false)))) {
                    return;
                }
                break;
            case 'page':
                if (!$this->checkTagValues($tag, array('root' => array('value' => 'page', 'mandatory' => false), 'default' => array('value' => 'page', 'mandatory' => false)))) {
                    return;
                }
                break;
            default:
                // handle polymod stuff
                if (strpos($tag['attributes']['vartype'], 'fields') !== false) {
                    if (!$this->checkTagValues($tag, array('vartype' => array('value' => 'field', 'mandatory' => true)))) {
                        return;
                    }
                } else {
                    // Assume it's an object
                    if (!$this->checkTagValues($tag, array('vartype' => array('value' => 'object', 'mandatory' => true)))) {
                        return;
                    }
                }
                break;
        }
        if ($this->_mode == self::BLOCK_PARAM_MODE) {
            // handle i18n on label and description
            $tag['attributes']['label'] = eval(sensitiveIO::sanitizeExecCommand('return "' . CMS_polymod_definition_parsing::preReplaceVars($tag['attributes']['label']) . '";'));
            if (isset($tag['attributes']['description'])) {
                $tag['attributes']['description'] = eval(sensitiveIO::sanitizeExecCommand('return "' . CMS_polymod_definition_parsing::preReplaceVars($tag['attributes']['description']) . '";'));
            }
            if (isset($tag['attributes']['possibleValues'])) {
                $tag['attributes']['possibleValues'] = eval(sensitiveIO::sanitizeExecCommand('return "' . CMS_polymod_definition_parsing::preReplaceVars($tag['attributes']['possibleValues']) . '";'));
            }
            $this->_blockParams['var'][$tag['attributes']['id']][$tag['attributes']['varname']] = $tag['attributes'];
        }
        $tag['attributes']['value'] = '".@$blockAttributes[\'var\'][\'' . $tag['attributes']['id'] . '\'][\'' . $tag['attributes']['varname'] . '\']."';
        return '
			$varname_' . $tag['attributes']['id'] . ' = "' . $this->replaceVars($tag['attributes']['varname'], null) . '";
			${$varname_' . $tag['attributes']['id'] . '} = CMS_polymod_definition_parsing::replaceVars("' . $this->replaceVars($tag['attributes']['value'], null) . '", @$replace);
			unset($varname_' . $tag['attributes']['id'] . ');' . "\n";
    }