/** * Update config for given values * @param array $vals. An array of values (presumably from $_POST) to update magic data from * @returns true on sucess */ public function processValues($vals) { $required_keys = array('class', 'name'); foreach ($required_keys as $required_key) { if (!array_key_exists($required_key, $vals) || !is_string($vals[$required_key]) || strlen($vals[$required_key]) == 0) { I2CE::raiseError('Missing required key: ' . $required_key); return false; } } $name = $vals['name']; $class = $vals['class']; if (!I2CE_MagicDataNode::checkKey($name)) { I2CE::raiseError("Invalid page name:" . $name); return false; } $existing_pages = $this->storage->getKeys(); if (in_array($name, $existing_pages)) { I2CE::raiseError('Requested New Page:' . $name . ' already exists in ' . implode(',', $existing_pages)); return false; } $handlers = $handlers = $this->getHandlers(); if (!array_key_exists($class, $handlers) || !$handlers[$class]) { I2CE::raiseError('No handler for the class: ' . $class . ' has been registered'); return false; } I2CE::raiseError("Creating page named {$name} with class {$class}"); $this->storage->{$name} = array('class' => $class); //add the new page with its class into root magic data node return true; }
/** * Update config for given values * @param array $vals. An array of values (presumably from $_POST) to update magic data from * @returns true on sucess */ public function processValues($vals) { $required_keys = array('storage', 'name', 'class', 'display'); foreach ($required_keys as $required_key) { if (!array_key_exists($required_key, $vals) || !is_string($val = $vals[$required_key]) || strlen($val) == 0) { I2CE::raiseError('Missing required key: ' . $required_key); return false; } ${$required_key} = $val; //sets is so if $key =='storage', then $storage = $val } $existing_forms = $this->storage->getKeys(); if (!I2CE_MagicDataNode::checkKey($name) || in_array($name, $existing_forms)) { I2CE::raiseError("Invalid form name:" . $name); return false; } if (!in_array($storage, $handlers = I2CE::getConfig()->getKeys('/modules/form-builder/storage_handlers'))) { I2CE::raiseError("Invalid storage ({$storage}) not one of:" . implode(",", $handlers)); return false; } if (!in_array($class, I2CE::getConfig()->getKeys("/modules/forms/formClasses"))) { I2CE::raiseError("Invalid class: {$class}"); } $this->storage->{$name} = array('storage' => $storage, 'class' => $class, 'display' => $display); //add the new page with its class into root magic data node $this->storage->{$name}->setTranslatable('display'); return true; }
/** * Update config for given values * @param array $vals. An array of values (presumably from $_POST) to update magic data from * @returns true on sucess */ public function processValues($vals) { I2CE::raiseError(print_r($vals, true)); if (!parent::processValues($vals)) { return false; } if (array_key_exists('val', $vals) && is_array($vals['val'])) { foreach ($vals['val'] as $key => $val) { if (!is_scalar($val) || !I2CE_MagicDataNode::checkKey($key)) { continue; } $this->setTranslatableField($key, $val); } } if (array_key_exists('do_new', $vals) && array_key_exists('new_key', $vals) && array_key_exists('new_val', $vals) && $vals['do_new'] && is_scalar($key = $vals['new_key']) && is_scalar($val = $vals['new_val']) && I2CE_MagicDataNode::checkKey($key) && !in_array($key, $this->storage->getKeys())) { $this->setTranslatableField($key, $val); } if (array_key_exists('delete', $vals) && is_array($vals['delete'])) { foreach ($vals['delete'] as $key => $selected) { if (!$selected || !is_scalar($val) || !I2CE_MagicDataNode::checkKey($key) || !($mdNode = $this->storage->traverse($key, false, false)) instanceof I2CE_MagicDataNode) { continue; } $mdNode->erase(); } } return true; }
public function processValues($vals) { if (array_key_exists('new', $vals) && I2CE_MagicDataNode::checkKey($new = $vals['new']) && !in_array($new, $this->storage->getKeys())) { $this->storage->{$new} = array(); } return true; }
/** * Update config for given values * @param array $vals. An array of values (presumably from $_POST) to update magic data from * @returns true on sucess */ public function processValues($vals) { //add a new field name,formfield,header foreach (array('name', 'formfield', 'header') as $key) { if (!array_key_exists($key, $vals) || !is_scalar(${$key} = $vals[$key]) || !${$key}) { I2CE::raiseError("Missing {$key} when creating a new field"); return false; } } if (!I2CE_MagicDataNode::checkKey($name) || in_array($name, $this->getFieldNames(true))) { I2CE::raiseError("Could not create a new field named {$name}"); return false; } $formfields = I2CE::getConfig()->getKeys("/modules/forms/FORMFIELD"); if (!in_array($formfield, $formfields)) { I2CE::raiseError("Invalid form field"); return false; } $this->storage->{$name} = array('formfield' => $formfield); if (!($swissField = $this->getChild($name)) instanceof I2CE_Swiss_FormField) { I2CE::raiseError("Could not get field controler"); return false; } if (!($swissHeaders = $swissField->getChild('headers', true)) instanceof I2CE_Swiss_FormField_Headers) { I2CE::raiseError("Could not get headers controler"); return false; } $swissHeaders->processValues(array('val' => array('default' => $header))); return true; }
/** * Update config for given values * @param array $vals. An array of values (presumably from $_POST) to update magic data from * @returns true on sucess */ public function processValues($vals) { $required_keys = array('extends', 'name'); foreach ($required_keys as $required_key) { if (!array_key_exists($required_key, $vals) || !is_string($vals[$required_key]) || strlen($vals[$required_key]) == 0) { I2CE::raiseError('Missing required key: ' . $required_key); return false; } } $name = $vals['name']; $extends = $vals['extends']; $existing_classes = $this->storage->getKeys(); if (!I2CE_MagicDataNode::checkKey($name) || class_exists($name) && !is_subclass_of($name, 'I2CE_Form') || in_array($name, $existing_classes)) { I2CE::raiseError("Invalid class name:" . $name); return false; } $handlers = $this->getHandlers(); $class = $extends; $found = false; while (class_exists($class) && (is_subclass_of($class, 'I2CE_Form') || $class == 'I2CE_Form')) { if (array_key_exists($class, $handlers)) { $found = true; break; } $class = get_parent_class($class); } if (!$found) { I2CE::raiseError('No handler for the class: ' . $extends . ' has been registered'); return false; } I2CE::raiseError("Creating page named {$name} which extends class {$extends}"); $this->storage->{$name} = array('extends' => $extends); //add the new page with its class into root magic data node return true; }
public static function getCSDArgs($csd_cache) { $args = array('relationship' => $csd_cache, 'transform' => '@' . $csd_cache . '.xsl', 'get_all_fields' => 1); if (!I2CE_MagicDataNode::checkKey($csd_cache) || !is_array($t_args = I2CE::getConfig()->getAsArray("/modules/csd_cache/" . $csd_cache . '/args'))) { $t_args = array(); } I2CE_Util::merge_recursive($args, $t_args); return $args; }
/** * Process the where for the field based on the UserStatistics display since this is a special type of field/limit * and return the where clause to use for the query. * @param string $field * @param array $limitStyles * @return string */ protected function processWhereByUserStatistics($field, $limitStyles) { if (!is_array($limitStyles) || count($limitStyles) == 0) { return ''; } $db_field = $field; if (array_key_exists('db_field', $this->fieldData[$field])) { if (is_array($this->fieldData[$field]['db_field'])) { return ''; } else { $db_field = $this->fieldData[$field]['db_field']; } } $config = $this->config->traverse("fields/{$field}/limits", false, false); if (!$config instanceof I2CE_MagicDataNode) { return ''; } $wheres = array(); foreach ($limitStyles as $limitStyle => $values) { if (!isset($config->{$limitStyle})) { continue; } if (!isset($config->{$limitStyle}->enabled) || !$config->{$limitStyle}->enabled) { continue; } if (!is_array($values) || count($values) == 0) { continue; } $formfield = "STRING_LINE"; if (array_key_exists('formfield', $this->fieldData[$field])) { $formfield = $this->fieldData[$field]['formfield']; } $fieldObj = $this->getFieldObj($field, $formfield); if (!$fieldObj instanceof I2CE_FormField) { I2CE::raiseError("Couldn't get formfield for limit {$field}"); continue; } $where = trim($fieldObj->generateLimit(array('style' => $limitStyle, 'data' => $values), "{$db_field}")); if (strlen($where) > 0) { $wheres[] = "( {$where} )"; } } $where = ''; if (count($wheres) > 0) { $where = '(' . implode(' AND ', $wheres) . ' )'; } if ($field == "username") { $where = str_replace("user|", "", $where); } if ($field == "change_type") { $where = str_replace("entry_change_type|", "", $where); } return $where; }
public function processValues($vals) { $oids = $this->storage->getKeys("list"); if (!is_array($oids)) { $oids = array(); } if (array_key_existS('oid', $vals) && I2CE_MagicDataNode::checkKey($oid = $vals['oid']) && !in_array($oid, $oids) && array_key_exists('list', $vals) && is_scalar($list = $vals['list']) && ($listObj = I2CE_FormFactory::instance()->createContainer($list)) instanceof I2CE_List) { $this->storage->lists->{$oid} = array('list' => $list); } return true; }
public function processValues($vals) { $forms = array_diff($this->getAllowedForms(), $this->storage->getKeys()); if (array_key_exists('form', $vals) && I2CE_MagicDataNode::checkKey($form = $vals['form']) && in_array($form, $forms)) { if ($this->makeScalar()) { $this->storage->set_scalar($form, true); } else { $this->storage->set_parent($form, true); } } return true; }
public function processValues($vals) { $msgs = array('report_no_name' => 'No shortname specified for the report', 'report_bad_name' => 'Invalid shortname specified for the report', 'report_name_used' => 'Shortname specified for the report is already in use', 'report_no_relationship' => "No report relationship specified for the report", 'report_bad_relationship' => "Specified report relationship is invalid"); foreach ($msgs as $k => &$v) { I2CE::getConfig()->setIfIsSet($v, "/modules/CustomReports/text/user_messages/{$k}"); } if (!array_key_exists('shortname', $vals)) { $this->userMessage($msgs['report_no_name'], 'notice'); return false; } $shortname = $vals['shortname']; if (!I2CE_MagicDataNode::checkKey($shortname)) { $this->userMessage($msgs['report_bad_name'], 'notice'); return false; } if ($this->getChild($shortname)) { $this->userMessage($msgs['report_name_used'], 'notice'); return false; } if (!array_key_exists('relationship', $vals)) { $this->userMessage($msgs['report_no_relationship'], 'notice'); return false; } $relationship = $vals['relationship']; $swissRelationships = $this->getSwissRelationships(); if (!$swissRelationships instanceof I2CE_Swiss_FormRelationships) { $this->userMessage($msgs['report_bad_relationship'], 'notice'); return false; } if (!$swissRelationships->getChild($relationship) instanceof I2CE_Swiss_FormRelationship) { $this->userMessage($msgs['bad_relationship'], 'notice'); return false; } $child = $this->getChild($shortname, true); if (!$child instanceof I2CE_Swiss_CustomReports_Report) { return false; } $child->setRelationship($relationship); if (array_key_exists('display_name', $vals)) { $child->setDisplayName($vals['display_name']); } if (array_key_exists('description', $vals)) { $child->setDescription($vals['description']); } if (array_key_exists('category', $vals)) { $child->setCategory($vals['category']); } return true; }
/** * Return the md5 Hash of the path of this object. * @param I2CE_MagicDataNode $node * @param string $childPath * @param boolean $show_top defaults to true if we are to show the parent * @return string */ public function getChildPath($node, $childPath, $show_top = true) { if ($show_top) { if ($node instanceof I2CE_MagicData) { return $node->getPath(true) . $node->pathDivider() . $childPath; } else { return $node->getPath(true) . '/' . $childPath; } } else { if ($node instanceof I2CE_MagicData) { return '/' . $childPath; } else { return $node->getPath(false) . '/' . $childPath; } } }
protected function getStyles() { $class = false; if (($formObj = I2CE_FormFactory::instance()->createContainer($this->name)) instanceof I2CE_Form) { $class = get_class($formObj); } $available = array('default'); while (I2CE_MagicDataNode::checkKey($class)) { if (is_array($t_available = I2CE::getConfig()->getKeys("/modules/forms/formClasses/{$class}/meta/list"))) { $available = array_merge($available, $t_available); } $class = get_parent_class($class); } $available = array_unique($available); return $available; }
public function canViewReport($view) { if (!I2CE_MagicDataNode::checkKey($view)) { return false; } $config = I2CE::getConfig()->modules->CustomReports; if ($config->is_scalar("reportViews/{$view}/limit_view_to") && $config->reportViews->{$view}->limit_view_to) { if (!$this->hasPermission(' task(custom_reports_admin) or ' . $config->reportViews->{$view}->limit_view_to)) { return false; } } return iHRIS_Module_SelfService::hasReport($view); $registered_reports = array(); I2CE::getConfig()->setIfIsSet($registered_reports, "/modules/SelfService/reports", true); return in_array($view, $registered_reports); }
public function getFieldNames() { $fields = array(); $class = false; if (($p = $this->parent) instanceof I2CE_Swiss_ListClass_Meta_List && ($gp = $p->parent) instanceof I2CE_Swiss_ListClass_Meta_Lists && ($gpp = $gp->parent) instanceof I2CE_Swiss_ListClass_Meta && ($gppp = $gpp->parent) instanceof I2CE_Swiss_ListClass) { $class = $gppp->name; } I2CE::raiseError("Using class : {$class}"); while (I2CE_MagicDataNode::checkKey($class)) { if (is_array($t_fields = I2CE::getConfig()->getKeys("/modules/forms/formClasses/{$class}/fields"))) { $fields = array_merge($fields, $t_fields); } $class = get_parent_class($class); } $fields = array_unique($fields); return $fields; }
public function hasPermission_satisfies($node, $args) { if (count($args) != 4) { I2CE::raiseError("Two few arguments for permision satosfoes() method"); return null; } if (!I2CE_MagicDataNode::checkKey($relationship = array_shift($args))) { I2CE::raiseError("No valid relationship specified"); return null; } try { $relationshipObj = new I2CE_FormRelationship($relationship); } catch (Exception $e) { I2CE::raiseError("Relationship {$relationship} is not valid"); return null; } return call_user_func_array(array($relationshipObj, 'formSatisfiesRelationship'), $args); }
/** * Update config for given values * @param array $vals. An array of values (presumably from $_POST) to update magic data from * @returns true on sucess */ public function processValues($vals) { if (array_key_exists('defaultHTMLFile', $vals) && is_array($vals['defaultHTMLFile'])) { foreach ($vals['defaultHTMLFile'] as $key => $val) { if (!I2CE_MagicDataNode::checkKey($key) || !is_scalar($val)) { continue; } if ($this->storage->is_scalar("defaultHTMLFile/{$key}") || $val) { //either key was already set and we are ovewriting it, or we are adding a new key with a set value $this->storage->defaultHTMLFile->{$key} = $val; } } } if (array_key_exists('title', $vals)) { $this->setTranslatableField('title', $vals['title']); } return true; }
protected function getMetaDataOptions() { $options = array(); $base_version = "1.0"; $site_module = false; if (I2CE::getConfig()->setIfIsSet($site_module, "/config/site/module") && I2CE_MagicDataNode::checkKey($site_module)) { I2CE::getConfig()->setIfIsSet($base_version, "/config/data/" . $site_module . '/version'); } $defaults = array('description' => 'MagicDataExport on ' . strftime('%c'), 'version' => $base_version . '.' . time(), 'displayName' => 'Site Export'); foreach ($defaults as $key => $default) { if ($this->request_exists($key)) { $options[$key] = $this->request($key); } else { $options[$key] = $default; } } return $options; }
public function publishConceptList($version = false, $lang = 'en-US', $doc = false) { if ($version === false) { $versions = self::getVersions($this->oid); if (count($versions) > 0) { $version = max($versions) + 1; } else { $version = 1; } } if (!$doc) { $doc = $this->generateConceptList($version, $lang, false); } if (!is_string($doc) || !I2CE_MagicDataNode::checkKey($version) || !I2CE_MagicDataNode::checkKey($lang) || !($path = "/modules/SVS/lists/" . $this->oid . "/published/" . $version . '/' . $lang) || !($md = I2CE::getConfig()->traverse($path, true, false)) instanceof I2CE_MagicDataNode) { return false; } $md->setValue(base64_encode($doc)); $md->setAttribute('binary', 1); $md->setAttribute('encoding', 'base64'); $md->setAttribute('mime-type', 'text/xml'); return true; }
/** * Sets an invalid message on a form field * @param string $messageName * @param array $extra Any extra information to be formatted and displayed. * @param string $additional_message Any additional message to be appended. */ public function setInvalidMessage($messageName, $extra = null, $additional_message = '') { if (!($formObj = $this->getContainer()) instanceof I2CE_FieldContainer || !I2CE_MagicDataNode::checkKey($fieldName = $this->getName()) || !I2CE_MagicDataNode::checkKey($formName = $formObj->getName()) || !I2CE_MagicDataNode::checkKey($messageName)) { I2CE::raiseError("Invalid call"); return false; } $msg = ''; $msg_paths = array("/modules/forms/formfield_messages/" . $formName . '/' . $fieldName . '/' . $messageName, "/modules/forms/field_messages/" . $fieldName . '/' . $messageName, "/modules/forms/invalid_field_messages/" . $messageName); foreach ($msg_paths as $msg_path) { if (I2CE::getConfig()->setIfIsSet($msg, $msg_path) && $msg) { $found = true; break; } } if (!$msg) { I2CE::raiseError("No message at any of:\n" . implode("\n", $msg_paths)); $msg = $messageName; } $this->setInvalid($msg . $additional_message, $extra); }
/** * Get the data for the fuzzy method * @param string $className * @param string $method * @returns array */ public function getMethod($className, $method) { if (!is_string($className) || strlen($className) == 0) { I2CE::raiseError("Trying to get fuzzy method for invalid classname"); return array(); } if (!is_subclass_of($className, 'I2CE_Fuzzy')) { I2CE::raiseError("Trying to get invalid fuzzy methods on a non-fuzzy object"); return array(); } if (!is_string($method) || strlen($method) == 0) { I2CE::raiseError("Trying to get invalid fuzzy method"); return array(); } $methodType = 'methods'; if (!I2CE_MagicDataNode::checkKey($method)) { I2CE::raiseError("Trying to get invalid fuzzy method {$method}"); return array(); } while (!$this->config->pathExists("{$methodType}/{$className}/{$method}")) { $className = get_parent_class($className); if (empty($className)) { return array(); } } $not_found = true; $priorities = $this->config->{$methodType}->{$className}->{$method}; if (!$priorities instanceof I2CE_MagicDataNode || count($priorities) == 0) { return array(); } $priority_order = $priorities->getKeys(); sort($priority_order, SORT_NUMERIC); //$priorities->ksort( SORT_NUMERIC ); //foreach ($priorities as $priority=>$shortnames) { foreach ($priority_order as $priority) { $shortnames = $priorities->{$priority}; if (!$shortnames instanceof I2CE_MagicDataNode || count($shortnames) == 0) { unset($priorities->{$priority}); continue; } foreach ($shortnames as $shortname => $implementing_method) { if (!is_string($implementing_method)) { continue; } if (!$this->isEnabled($shortname)) { continue; } if (!$this->getClass($shortname) instanceof I2CE_Module) { continue; } return array('shortname' => $shortname, 'method' => $implementing_method); } } return array(); }
public function processValues($vals) { // Call I2CE_Swiss->processValues() as there are no specific values to process if (!parent::processValues($vals)) { return false; } // Set the form display name if (array_key_exists('form_display_name', $vals)) { $this->setField('form_display_name', $vals['form_display_name']); } // Set the display order if (array_key_exists('display_order', $vals) && is_array($vals['display_order'])) { $display_order = array(); $actual = 0; $correct = 0; $i = 0; foreach ($vals['display_order'] as $v) { $actual += $v; $correct += ++$i; $display_order[] = ''; } if ($correct != $actual) { I2CE::raiseError('Correct: ' . $correct . ' Actual: ' . $actual); return false; } foreach ($vals['display_order'] as $child => $index) { $display_order[$index - 1] = $child; } $comma_sep = implode(',', $display_order); $this->setField('display_order', $comma_sep); } // Set the title for the page if (array_key_exists('title', $vals)) { $this->setField('title', $vals['title']); } if (array_key_exists('task', $vals) && is_array($vals['task']) && ($tasksNode = $this->storage->traverse('task', true, false)) instanceof I2CE_MagicDataNode) { $tasks = I2CE::getConfig()->getAsArray("/I2CE/tasks/task_description"); $new_tasks = array(); foreach ($vals['task'] as $task => $checked) { if (!I2CE_MagicDataNode::checkKey($task) || !is_scalar($checked)) { continue; } if ($this->storage->is_scalar("task/{$task}") || $checked) { //either key was already set and we are ovewriting it, or we are adding a new key with a set value $new_tasks[] = $task; } } $tasksNode->eraseChildren(); $tasksNode->setValue($new_tasks); } /** *This checks to see if there are any checkboxes selected. If not, delete them all. */ if (!array_key_exists('task', $vals) && ($tasksNode = $this->storage->traverse('task', true, false)) instanceof I2CE_MagicDataNode) { $tasksNode->eraseChildren(); } if (array_key_exists('childOrder', $vals) && is_array($vals['childOrder']) && ($orderNode = $this->storage->traverse('child_form_order', true, false)) instanceof I2CE_MagicDataNode) { $new_child_order = array(); $actual = 0; $correct = 0; $i = 0; foreach ($vals['childOrder'] as $v) { $actual += $v; $correct += ++$i; $new_child_order[] = ''; } if ($correct != $actual) { I2CE::raiseError('Correct: ' . $correct . ' Actual: ' . $actual); return false; } foreach ($vals['childOrder'] as $child => $index) { $new_child_order[$index - 1] = $child; } $orderNode->eraseChildren(); $orderNode->setValue($new_child_order); } /* Attempting to // Set the display order if (array_key_exists('childOrder',$vals) && is_array($vals['childOrder']) ) { $display_order = array(); foreach($vals['childOrder'] as $k) { $display_order[] = ''; } foreach($vals['childOrder'] as $child=>$index) { $display_order[($index - 1)] = $child; } $comma_sep = implode( ',', $display_order ); $this->setField('child_form_order', $comma_sep); } */ return true; }
/** * Make a new attribute this object with the given key. The $nosave flag should only be set when * populating a parent node from storage. * @param scalar $key. the key * @param boolean $save Set to true to not save the parent and attribute * @returns mixed. false on failure, the attribute created on succes */ protected function newAttribute($key, $save, $prefix) { if (!self::checkKey($key)) { self::raiseError("Invalid path component {$key}"); return false; } $attr = new I2CE_MagicDataNode('=' . $prefix . ':' . $key, $this, false); $attr->populate(); $attr->type = self::TYPE_STRING_VALUE; //just to be safe $this->attributes[$prefix][$key] = $attr; if ($save) { if (!$attr->save()) { return false; } if (!$this->save()) { return false; } } return $attr; }
/** * Converts configurationGroup data in an array to its DOM representation. * @param array $data. The data for the current node * @param string $name. The name for the current node. * @param DOMNode $node. The parent node we wish to add onto node * @param array $status. The status of the parent node. * @return booolean true on success */ protected function convertConfigDataArray($data, $name, $node, $status) { $options = array('name' => $name); if (!array_key_exists('__status', $data)) { $data['__status'] = array(); } $status = array_merge($status, $data['__status']); unset($data['__status']); $values = null; if (array_key_exists('__values', $data)) { $values = $data['__values']; unset($data['__values']); $options['values'] = 'many'; if (!array_key_exists('__type', $data)) { $all_int = true; $keys = array_keys($values); foreach ($keys as $key) { if (!is_int($key)) { $all_int = false; break; } } if (!$all_int) { //we have an array not indexed only by integers (e.g. a map) //set the type to be delimited if it was not explicitly set $data['__type'] == 'delimited'; } } } else { if (array_key_exists('__value', $data)) { $values = array($data['__values']); unset($data['__value']); } } if (!is_null($values)) { $group = false; $tagName = 'configuration'; if (array_key_exists('__type', $data)) { //we don't handle this via self::$attrirbuteConversion b/c it does not apply to a configurationGroup $type = $data['__type']; $options['type'] = $type; unset($data['__type']); } else { $type = 'string'; } $method = "processYAML_values_{$type}"; if (!$this->_hasMethod($method)) { I2CE::raiseError("Do not know how to handle data {$type}"); return false; } $t_values = $this->{$method}($values, $status); if (!is_array($t_values)) { I2CE::raiseError("Unable to process values of type {$type}:\n" . print_r($values, true)); return false; } $values = $t_values; } else { $group = true; $tagName = 'configurationGroup'; } //we have no values set so we are in a configuration group foreach (self::$attributeConversion as $yaml_key => $dom_attr) { if (!array_key_exists($yaml_key, $data)) { continue; } $options[$dom_attr] = $data[$yaml_key]; unset($data[$yaml_key]); } $configNode = $this->createElement($tagName, $options); $node->appendChild($configNode); foreach ($status as $key => $val) { $method = "processYAML_status_{$key}"; if (!$this->_hasMethod($method)) { $method = "processYAML_status"; } $status_text = $this->{$method}($key, $val); if (!is_string($status_text)) { I2CE::raiseError("Unable to process YAML status values at {$key}"); return false; } $configNode->appendChild($this->createElement('status', array(), $status_text)); } foreach (self::$optionalNodes as $yaml_key => $tag) { if (!array_key_exists($yaml_key, $data)) { continue; } $configNode->appendChild($this->createElement($tag, array(), $data[$yaml_key])); unset($data[$yaml_key]); } if ($group) { //we are a configurationGroup... see if there are any remaining keys in $data to make subnodes for foreach ($data as $key => $t_data) { if (!I2CE_MagicDataNode::checkKey($key)) { I2CE::raiseError("Invalid key {$key}"); return false; } if (!$this->convertConfigDataArray($t_data, $key, $configNode, $status)) { return false; } } } else { foreach ($values as $val) { $configNode->appendChild($this->createElement('value', array(), $val)); } } return true; }
/** * Save the FormField to the database. * @param I2CE_FormField $form_field * @param boolean $do_check : A flag to determine if a check should be made for the same value being saved. * @param I2CE_User $user: The user saving this data. * @return boolean */ public function FF_save($form_field, $do_check, $user) { if (!$form_field->isInDB()) { return true; } if ($form_field->getDBValue() != "" && !$form_field->isValid()) { return true; } $form_config = $this->getFormConfig($form_field, true); if (!$form_config instanceof I2CE_MagicDataNode) { return false; } $fields_config = $form_config->fields; if (!$fields_config instanceof I2CE_MagicDataNode) { return false; } $field_name = $form_field->getName(); if (!I2CE_MagicDataNode::checkKey($field_name)) { return false; } $field_config = $fields_config->traverse($field_name, true, false); if (!$field_config instanceof I2CE_MagicDataNode) { return false; } if ($form_field->getMDB2Type() == 'blob') { $field_config->setAttribute('binary', 1); $field_config->setAttribute('encoding', 'base64'); $field_config->setValue(base64_encode($form_field->getDBValue())); } else { $field_config->setValue($form_field->getDBValue()); } return true; }
/** * Get how the given data should be queried from the db * @param I2CE_MagicDataNode $data * @returns mixed. fasle on failture. string on success */ protected function getFieldData($data) { $col = ''; $data->setIfIsSet($col, 'col'); $col = trim($col); if (strlen($col) > 0) { return $col; } $function = ''; $data->setIfIsSet($function, 'function'); if (strlen($function) > 0) { return $function; } return false; }
/** *Determine the desired displays for the indicated report view * @param string $view *@returns array of string. */ public function getDesiredDisplays($view) { $config = I2CE::getConfig()->modules->CustomReports; $displays = array(); //a list in increasing priority of displays we will try to fall back on. if (count($this->request_remainder) > 1) { $displays[] = $this->request_remainder[1]; } if (I2CE_MagicDataNode::checkKey($view) && $config->is_scalar("reportViews/{$view}/default_display") && $config->reportViews->{$view}->default_display) { $displays[] = $config->reportViews->{$view}->default_display; } if (isset($config->default_display) && is_string($config->default_display) && strlen($config->default_display) > 0) { $displays[] = $config->default_display; } return array_unique($displays); }
protected function actionTasksSave() { if (count($this->request_remainder) == 0) { //adding new task if (!$this->post_exists('task_short_name')) { $this->userMessage("No task short name set", 'notice', false); return; } $task = $this->post('task_short_name'); if (!$task || !I2CE_MagicDataNode::checkKey($task) || I2CE::getConfig()->__isset("/I2CE/tasks/task_description/{$task}") || I2CE::getConfig()->__isset("/I2CE/tasks/task_trickle_down/{$task}")) { $this->userMessage("Bad task short name", 'notice', false); return; } if (!$this->post_exists('task_description') || !$this->post('task_description')) { $this->userMessage("No task description set", 'notice', false); return; } //we are good to go. I2CE::getConfig()->I2CE->tasks->task_description->{$task} = $this->post('task_description'); } else { if (count($this->request_remainder) == 1) { $task = $this->request_remainder[0]; $taskConfig = I2CE::getConfig()->traverse("/I2CE/tasks"); if (!$taskConfig->__isset("task_description/{$task}")) { $this->userMessage("Invalid Task {$task} specified", 'notice', false); return; } $post = $this->post(); if (!array_key_exists('task_description', $post) || !$post['task_description']) { $this->userMessage("No task description set", 'notice', false); return; } if ($taskConfig->is_translatable("task_description/{$task}")) { $locale = I2CE_Locales::getPreferredLocale(); $taskConfig->task_description->setTranslation($locale, $post['task_description'], $task); if ($locale == I2CE_Locales::DEFAULT_LOCALE) { $taskConfig->task_description->{$task} = $post['task_description']; } } else { $taskConfig->task_description->{$task} = $post['task_description']; } if (array_key_exists('task_tasks', $post) && is_array($post['task_tasks'])) { //make sure the tasks are valid. $tasks = $post['task_tasks']; foreach ($tasks as $i => $r) { if (!$taskConfig->__isset("task_description/{$r}")) { unset($tasks[$i]); } } $taskConfig->task_trickle_down->{$task}->erase(); $taskConfig->traverse("task_trickle_down/{$task}", true, false); //recreate what we just erased $taskConfig->task_trickle_down->{$task} = $tasks; } } } $this->setRedirect('tasks-roles/tasks'); }
public function setTranslatableField($field, $value) { if (!I2CE_MagicDataNode::checkKey($field)) { I2CE::raiseError("Bad field name {$field}"); return false; } $locale = $this->getLocale(); if ($this->storage->is_parent($field)) { I2CE::raiseError("Trying to set a parent to a scalar value at " . $this->storage->getPath(false) . "/" . $field); return false; } $fieldStorage = $this->storage->traverse($field, true, false); $fieldStorage->setTranslatable(); if ($fieldStorage->setTranslation($this->getLocale(), $value)) { return true; } else { I2CE::raiseError("Could not set " . $fieldStorage->getPath(false) . " as translatable with value {$value} at locale " . $this->getLocale()); return false; } }
/** * Update config for given values * @param array $vals. An array of values (presumably from $_POST) to update magic data from * @returns true on sucess */ public function processValues($vals) { if (array_key_exists('hook', $vals) && is_scalar($h = $vals['hook'])) { $this->setField('hook', $h); } if (array_key_exists('data', $vals) && is_array($vals['data'])) { foreach ($vals['data'] as $key => $val) { if (!I2CE_MagicDataNode::checkKey($key) || !is_scalar($val)) { continue; } if ($val === '') { if (($md = $this->storage->traverse("data/{$key}", false, false)) instanceof I2CE_MagicDataNode) { I2CE::raiseError("Erasing"); $md->erase(); } } else { if ($this->storage->is_scalar("data/{$key}") || $val) { //either key was already set and we are ovewriting it, or we are adding a new key with a set value $this->storage->data->{$key} = $val; } } } } return parent::processValues($vals); }