protected function action() { if (!parent::action()) { return false; } $action = 'RetrieveValueSet'; if (count($this->request_remainder) > 0) { reset($this->request_remainder); $action = current($this->request_remainder); } $task = 'SVS_allow_' . $action; if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission('task(' . $task . ')')) { I2CE::raiseError("No permission"); return false; } if ($action == 'config') { return $this->action_config(); } else { if ($this->isGet()) { return $this->action_get($action); } else { return $this->action_post(); } } }
public function generate($node) { if (!$node instanceof DOMNode || !$this->primaryObject instanceof I2CE_Form || I2CE_PermissionParser::taskExists($this->options['task']) && !$this->page->hasPermission("task(" . $this->options['task'] . ")", $node) || !($linkedNode = $this->template->appendFileByNode($this->options['template'], 'div', $node)) instanceof DOMNode || !($tbodyNode = $this->template->getElementByName('child_fields', 0, $node)) instanceof DOMNode) { return false; } $added = 0; if (count($this->options['action_links']) > 0 && ($ulNode = $this->template->getElementByName('child_links', 0, $linkedNode)) instanceof DOMNode) { $added = $this->addLinks('li', $this->options['action_links'], $ulNode); } if ($added == 0 && ($containerNode = $this->template->getElementByName('child_actions', 0, $linkedNode)) instanceof DOMNode) { $this->template->removeNode($containerNode); } $this->template->setDisplayDataImmediate('child_title', $this->options['title'], $linkedNode); $dispDatas = array(); $arg_walker = array(); if ($this->options['printf'] && is_array($this->options['printf_args'])) { foreach ($this->options['printf_args'] as $i => &$arg) { $t_arg = explode(":", $arg); if (count($t_arg) > 1) { $arg_walker[$i] = $t_arg; $arg = $t_arg[0]; } } unset($arg); $dispDatas = I2CE_FormStorage::listDisplayFields($this->options['form'], $this->options['printf_args'], $this->primaryObject->getNameId(), $this->options['where'], $this->options['orders'], $this->options['limit']); $ids = array_keys($dispDatas); } else { $ids = I2CE_FormStorage::search($this->options['form'], $this->primaryObject->getNameId(), $this->options['where'], $this->options['orders'], $this->options['limit']); } if (count($ids) == 0) { return false; } foreach ($ids as $id) { $text = $this->options['title']; //default text for child in case printf wasn't set. if (array_key_exists($id, $dispDatas) && is_array($dispDatas)) { $dispFields = $dispDatas[$id]; foreach ($this->options['printf_args'] as $i => $arg) { $dispData[$i] = $dispFields[$arg]; } foreach ($arg_walker as $i => $fields) { $val = $dispData[$i]; $count = 0; foreach ($fields as $field) { $count++; if ($count == 1) { continue; } list($wform, $wid) = array_pad(explode('|', $val, 2), 2, ''); $val = I2CE_FormStorage::lookupField($wform, $wid, array($field), ''); } $dispData[$i] = $val; } $text = @vsprintf($this->options['printf'], $dispData); } $this->generateAjaxLink($id, $text, $tbodyNode); } }
public function generate($node) { if ($this->options['task'] && I2CE_PermissionParser::taskExists($this->options['task']) && !$this->page->hasPermission("task(" . $this->options['task'] . ")", $node) || !($linkedNode = $this->template->appendFileByNode($this->options['template'], 'div', $node)) instanceof DOMNode || !($pageDispNode = $this->template->getElementByName('pager_display', 0, $linkedNode)) instanceof DOMNode || !($pageResultsNode = $this->template->getElementByName('pager_results', 0, $linkedNode)) instanceof DOMNode || !($tbodyNode = $this->template->getElementByName('link_fields', 0, $node)) instanceof DOMNode) { return; } $arg_walker = array(); $printf_args = $this->options['printf_args']; foreach ($printf_args as $i => &$arg) { $t_arg = explode(":", $arg); if (count($t_arg) > 1) { $arg_walker[$i] = $t_arg; $arg = $t_arg[0]; } } unset($arg); $dispData = I2CE_FormStorage::listDisplayFields($this->options['form'], $printf_args, false, $this->options['where'], $this->options['orders'], $this->options['limit']); if (count($dispData) == 0) { return; } $pageDispNode->setAttribute('id', 'linked_' . $this->options['form'] . '_pager_display'); $pageResultsNode->setAttribute('id', 'linked_' . $this->options['form'] . '_results'); $dispData = $this->paginateList($dispData, array('form' => $this->options['form']), 'linked_' . $this->options['form']); $this->template->setDisplayDataImmediate('link_title', $this->options['title']); foreach ($dispData as $id => $r_dispData) { $dispData = array(); foreach ($printf_args as $i => $arg) { $dispData[$i] = $r_dispData[$arg]; } foreach ($arg_walker as $i => $fields) { $val = $dispData[$i]; $count = 0; foreach ($fields as $field) { $count++; if ($count == 1) { continue; } list($wform, $wid) = array_pad(explode('|', $val, 2), 2, ''); $val = I2CE_FormStorage::lookupField($wform, $wid, array($field), ''); } $dispData[$i] = $val; } $text = @vsprintf($this->options['printf'], $dispData); //form = person_position $linkid = $this->options['form'] . '|' . $id; foreach ($this->options['link_field'] as $lfield) { list($lform, $lid) = array_pad(explode('|', $linkid, 2), 2, ''); $linkid = I2CE_FormStorage::lookupField($lform, $lid, array($lfield), ''); } $attrs = array('href' => $this->options['link'] . $linkid); $tbodyNode->appendChild($trNode = $this->template->createElement('tr', array('colspan' => 2))); $trNode->appendChild($tdNode = $this->template->createElement('td', array('colspan' => 2))); $tdNode->appendChild($this->template->createElement('a', $attrs, $text)); } }
protected function generateAutoParentTemplate($data, $appendNode) { $form = $this->primaryObject->getName(); if (array_key_exists('task', $data) && $data['task']) { $task = $data['task']; if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})", $appendNode)) { return false; } } $node = $this->template->appendFileById("auto_view_parent_form.html", 'div', $appendNode); if (!$node instanceof DOMNode) { I2CE::raiseError("Could not load auto_view_parent_form.html"); return false; } $added = 0; if (($ulNode = $this->template->getElementByName('parent_form_edit_links', 0, $node)) instanceof DOMNode && array_key_exists('edit_links', $data) && is_array($data['edit_links'])) { $added = $this->addLinks('li', $data['edit_links'], $ulNode); } $this->template->setDisplayData('has_edit_links', $added, $node); if (($pNode = $this->template->getElementByName('parent_form_action_links', 0, $node)) instanceof DOMNode) { $added = 0; if (array_key_exists('action_links', $data) && is_array($data['action_links'])) { $added = $this->addLinks('span', $data['action_links'], $pNode); } if ($added == 0) { $this->template->removeNode($pNode); } } if (($tbodyNode = $this->template->getElementByName('parent_form_fields', 0, $node)) instanceof DOMNode) { $all_field_names = $this->primaryObject->getFieldNames(); $display_order = array(); if (array_key_exists('display_order', $data) && is_string($data['display_order'])) { $display_order = explode(",", $data['display_order']); } $field_names = array(); foreach ($display_order as $field_name) { if (($pos = array_search($field_name, $all_field_names)) === false) { continue; } unset($display_order[$pos]); $field_names[] = $field_name; } $field_names = array_unique(array_merge($field_names, $all_field_names)); $field_data = array(); if (array_key_exists('fields', $data) && is_array($data['fields'])) { $field_data = $data['fields']; } $default_enabled = 1; if (array_key_exists('default_disabled', $data)) { $default_enabled = !$data['default_disabled']; } $added = false; foreach ($field_names as $field_name) { if (!array_key_exists($field_name, $field_data) || !is_array($field_data[$field_name])) { $f_data = array(); } else { $f_data = $field_data[$field_name]; } if (array_key_exists('enabled', $f_data)) { if (!$f_data['enabled']) { continue; } } else { if (!$default_enabled) { continue; } } $attrs = array('type' => 'form', 'name' => $form . ':' . $field_name); if (array_key_exists('attributes', $f_data) && is_array($f_data['attributes'])) { $attrs = $f_data['attributes']; } if (!array_key_exists('showhead', $attrs)) { $attrs['showhead'] = 'default'; } if (!$attrs['showhead']) { unset($attrs['showhead']); } $tbodyNode->appendChild($this->template->createElement('span', $attrs)); $added = true; } $this->template->setDisplayData('has_field_data', $added, $node); } if (array_key_exists('display_name', $data) && $data['display_name']) { $display_name = $data['display_name']; } else { $display_name = $this->primaryObject->getDisplayName(); } $this->setDisplayDataImmediate('parent_form_display_name', $display_name, $node); if (array_key_exists('title', $data) && $data['title']) { $title = $data['title']; if (array_key_exists('title_args', $data) && is_array($data['title_args'])) { $args = array(); foreach ($data['title_args'] as $i => $fieldName) { $val = ''; if (($fieldObj = $this->primaryObject->getField($fieldName)) instanceof I2CE_FormField) { $val = $fieldObj->getDisplayValue(); } $args[$i] = $val; } ksort($args); if (count($args) > 0) { $title = @vsprintf($title, $args); } } } else { $title = $this->getTitle(); } if (array_key_exists('subtitle', $data) && !is_array($data['subtitle'])) { $subtitle = $data['subtitle']; if (array_key_exists('subtitle_args', $data) && is_array($data['subtitle_args'])) { $args = array(); foreach ($data['subtitle_args'] as $i => $fieldName) { $val = ''; if (($fieldObj = $this->primaryObject->getField($fieldName)) instanceof I2CE_FormField) { $val = $fieldObj->getDisplayValue(); } $args[$i] = $val; } ksort($args); if (count($args) > 0) { $subtitle = @vsprintf($subtitle, $args); } } } else { $subtitle = $this->primaryObject->getDisplayName(); } $this->setDisplayDataImmediate('parent_form_title', $title, $node); $this->setDisplayDataImmediate('parent_form_subtitle', $subtitle, $node); return $node; }
/** * Perform the main actions of the page. */ protected function action() { $task = $this->getViewChildTask(); if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) { $this->userMessage("You do not have permission to view this {$childForm}", true); return false; } $tag = array_key_exists('template_tag', $this->args) && is_scalar($this->args['template_tag']) ? $this->args['template_tag'] : 'div'; $append_id = array_key_exists('template_id', $this->args) && is_scalar($this->args['template_id']) ? $this->args['template_id'] : 'child_form'; $appendNode = $this->template->getElementById($append_id); if (!$appendNode instanceof DOMNode) { I2CE::raiseError("No {$append_id} to add child form " . $this->childForm); return false; } $limit_page = $this->request_exists('limit_page') ? $this->request('limit_page') : 1; if ($limit_page < 1) { $limit_page = 1; } $order_by = $this->getOrderBy(); $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1)); if (!$found && $limit_page > 1) { $limit_page = 1; $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1)); } if (!$found) { $this->redirect("view?id=" . $this->parent->getNameId()); return true; } $total_rows = I2CE_FormStorage::getLastListCount($this->childForm); if ($total_rows <= 1) { $this->template->setAttribute('style', 'display:none;', 'child_pager_div'); } else { $query = $this->request(); unset($query['limit_page']); $query = I2CE_Page::flattenRequestVars($query); $this->makeScalingJumper('child', $limit_page, $total_rows, $this->pageRoot(), $query, 'limit_page'); } $this->child = I2CE_FormFactory::instance()->createContainer($this->childForm . "|" . $found); $this->child->populate(); I2CE_ModuleFactory::callHooks('pre_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'set_on_node' => null, 'append_node' => $appendNode)); $childNode = $this->template->appendFileByNode($this->getViewChildTemplate(), $tag, $appendNode); $this->template->setForm($this->child, $childNode); I2CE_ModuleFactory::callHooks('post_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'node' => $childNode, 'set_on_node' => null, 'append_node' => $appendNode)); $this->template->setDisplayDataImmediate("child_form_header", "View " . $this->child->getDisplayName()); if (array_key_exists('show_edit', $this->args) ? !$this->args['show_edit'] : true) { $this->template->findAndRemoveNodes("//div[@class='editRecord']"); } // Do we want this? // $this->template->findAndRemoveNodes( "//span[@history='false']" ); return true; }
protected function addLinks($tag, $data, $containerNode) { $added = 0; foreach ($data as $name => $link_data) { if (array_key_exists('task', $link_data) && $link_data['task']) { $task = $link_data['task']; if (I2CE_PermissionParser::taskExists($task) && !$this->page->hasPermission("task({$task})", $containerNode)) { continue; } } if (!array_key_exists('href', $link_data) || !$link_data['href'] || !array_key_exists('text', $link_data) || !$link_data['text']) { continue; } if (array_key_exists('formfield', $link_data) && $link_data['formfield']) { $attrs = array('type' => 'form', 'name' => $link_data['formfield'], 'href' => $link_data['href']); if (array_key_exists('attributes', $link_data) && is_array($link_data['attributes'])) { foreach ($link_data['attributes'] as $attr => $val) { if (!is_scalar($val)) { continue; } $attrs[$attr] = $val; } } if (!array_key_exists('class', $attrs)) { $attrs['class'] = ''; } $attrs['class'] .= ' action_link_' . $name; $tagNode = $this->template->createElement($tag); $tagNode->appendChild($this->template->createElement('span', $attrs, $link_data['text'])); $containerNode->appendChild($tagNode); } else { $attrs = array('href' => $link_data['href'], 'class' => 'action_link_' . $name); $tagNode = $this->template->createElement($tag); $tagNode->appendChild($this->template->createElement('a', $attrs, $link_data['text'])); $containerNode->appendChild($tagNode); } $added++; } return $added; }
/** * Return the array of tasks that are directly given by a * role. * @param string $user_role * @return array */ protected static function getRoleTasks($user_role) { if (!self::$role_tasks || !is_array(self::$role_tasks)) { self::$role_tasks = array(); } if (!$user_role) { return array(); } if (!array_key_exists($user_role, self::$role_tasks)) { $checked_roles = array(); $user_roles = array(); if ($user_role) { $user_roles[] = $user_role; } $roles = I2CE::getConfig()->I2CE->formsData->forms->role; while (count($user_roles) > 0) { $role = array_shift($user_roles); if (!is_string($role) || strlen($role) == 0) { continue; } if (array_key_exists($role, $checked_roles) && $checked_roles[$role]) { continue; } $checked_roles[$role] = true; foreach ($roles as $r => $desc) { $role_trickle = self::getRoleTrickleUp($r); if (in_array($role, $role_trickle)) { if ($r == 'any' || $r == 'all') { continue; } if ($r == 'admin') { self::$role_tasks[$user_role] = 'admin'; return 'admin'; } $user_roles[] = $r; } } } // all the possible roles the user is considered to have $user_roles = array_keys($checked_roles); // this will store all tasks for any of the roles the user // has (not each task can have a trickle down) $role_tasks = array(); foreach ($user_roles as $r) { if (!is_string($r) || strlen($r) == 0) { continue; } $t_role_tasks = array(); I2CE::getConfig()->setIfIsSet($t_role_tasks, "/I2CE/tasks/role_trickle_down/" . $r, true); $role_tasks = array_unique(array_merge($role_tasks, $t_role_tasks)); } self::$role_tasks[$user_role] = array_flip($role_tasks); } return self::$role_tasks[$user_role]; }
protected function generateAutoTemplate($data, $appendNode) { if (!$this->primaryObject instanceof I2CE_Form) { return false; } $form = $this->primaryObject->getName(); if (array_key_exists('task', $data) && $data['task']) { $task = $data['task']; if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})", $appendNode)) { return false; } } $node = $this->template->appendFileById("auto_edit_parent_form.html", 'div', $appendNode); if (!$node instanceof DOMNode) { I2CE::raiseError("Could not load auto_edit_parent_form.html"); return false; } $formNode = $this->template->getElementByTagName('form', 0, $node); if (!$node instanceof DOMNode) { I2CE::raiseError("Couldn't get form node"); return false; } $formNode->setAttribute('action', $this->page); if (($tbodyNode = $this->template->getElementByID('list_fields', $node)) instanceof DOMNode) { $all_field_names = $this->primaryObject->getFieldNames(); if ($this->primaryObject instanceof I2CE_List) { //shouldn't be here! $all_field_names = array_diff($all_field_names, array('remap', 'i2ce_hidden')); } $display_order = array(); if (array_key_exists('display_order', $data) && is_string($data['display_order'])) { $display_order = explode(",", $data['display_order']); } $field_names = array(); foreach ($display_order as $field_name) { if (($pos = array_search($field_name, $all_field_names)) === false) { continue; } unset($display_order[$pos]); $field_names[] = $field_name; } $field_names = array_unique(array_merge($field_names, $all_field_names)); $field_data = array(); if (array_key_exists('fields', $data) && is_array($data['fields'])) { $field_data = $data['fields']; } $count = 0; $default_enabled = 1; if (array_key_exists('default_disabled', $data)) { $default_enabled = !$data['default_disabled']; } foreach ($field_names as $field_name) { if (!array_key_exists($field_name, $field_data) || !is_array($field_data[$field_name])) { $f_data = array(); } else { $f_data = $field_data[$field_name]; } if (array_key_exists('enabled', $f_data)) { if (!$f_data['enabled']) { continue; } } else { if (!$default_enabled) { continue; } } if ($count % 2 == 0) { $trNode = $this->template->createElement('tr'); $tbodyNode->appendChild($trNode); } $count++; $attrs = array('type' => 'form', 'name' => $form . ':' . $field_name); if (array_key_exists('attributes', $f_data) && is_array($f_data['attributes'])) { $attrs = $f_data['attributes']; } if (!array_key_exists('showhead', $attrs)) { $attrs['showhead'] = 'default'; } if (!$attrs['showhead']) { unset($attrs['showhead']); } $tdNode = $this->template->createElement('td'); $tdNode->appendChild($this->template->createElement('span', $attrs)); $trNode->appendChild($tdNode); } } if (array_key_exists('display_name', $data) && $data['display_name']) { $display_name = $data['display_name']; } else { $display_name = $this->primaryObject->getDisplayName(); } $this->setDisplayDataImmediate('form_display_name', $display_name, $node); if (array_key_exists('title', $data) && $data['title']) { $title = $data['title']; if (array_key_exists('title_args', $data) && is_array($data['title_args'])) { $args = array(); foreach ($data['title_args'] as $i => $fieldName) { $val = ''; if (($fieldObj = $this->primaryObject->getField($fieldName)) instanceof I2CE_FormField) { $val = $fieldObj->getDisplayValue(); } $args[$i] = $val; } ksort($args); if (count($args) > 0) { $title = @vsprintf($title, $args); } } } else { $title = $this->getTitle(); } $this->setDisplayDataImmediate('form_title', $title, $node); if (array_key_exists('parent_display', $data) && is_array($data['parent_display']) && array_key_exists('printf', $data['parent_display']) && is_string($data['parent_display']['printf']) && $data['parent_display']['printf'] && array_key_exists('printf_args', $data['parent_display']) && is_array($data['parent_display']['printf_args'])) { ksort($data['parent_display']['printf_args']); foreach ($data['parent_display']['printf_args'] as $field) { $fieldObj = $this->parentObj->getField($field); if ($fieldObj instanceof I2CE_FormField) { $vals[] = $fieldObj->getDisplayValue(); } else { $vals[] = ''; } } $purpose = @vsprintf($this->printf, $vals); $this->setDisplayDataImmediate('purpose', $pupose, $node); } return $node; }
/** * Remove any restricted access elements of the page. * * This method processes all elements in the document that have a role attribute. * If there is no known user or the user doesn't have access to that role then the * entire node will be removed from the document. * @param I2CE_User $user * @param DOMNode $node. Defaults to null, meaning we check the whole document. Otherwise, we check * relaive to that role */ public function checkRolesTasksAndPermissions($node = null) { if ($node instanceof DOMNode) { $results = $this->query("./descendant-or-self::node()[@role!='' or @task!='' or @permission!='']", $node); } else { $results = $this->query("//*[@role!='' or @task!='' or @permission!='']"); } $permissionParser = new I2CE_PermissionParser($this, $this->user); for ($i = 0; $i < $results->length; $i++) { $node = $results->item($i); if (!$node instanceof DOMElement) { return true; //not removed. } $role = trim($node->getAttribute('role')); $task = trim($node->getAttribute('task')); $permission = trim($node->getAttribute('permission')); if ($role) { $role = 'role(' . $role . ')'; if ($permission) { $permission = $permission . ' or ' . $role; } else { $permission = $role; } } if ($task) { $task = 'task(' . $task . ')'; if ($permission) { $permission = $permission . ' or ' . $task; } else { $permission = $task; } } $node->removeAttribute("role"); $node->removeAttribute("task"); $node->removeAttribute("permission"); $permission = trim($permission); if ($permission && !$permissionParser->hasPermission($permission)) { $this->removeNode($node); } } }
protected function getListConfig($type = null, $form = null) { $listConfig = null; if ($type === null) { if ($this->request_exists('type') && I2CE_MagicDataNode::checkKey($this->request('type'))) { $type = $this->request('type'); } } if (!$form && $type) { $listConfig = I2CE::getConfig()->getAsArray('/modules/Lists/auto_list/' . $type); $listConfig['type'] = $type; } if (!is_array($listConfig)) { $listConfig = array(); } if ($form === null && !array_key_exists('form', $listConfig) && $this->request_exists('form') && I2CE_MagicDataNode::checkKey($this->request('form'))) { $form = $this->request('form'); } if ($form) { $listConfig['form'] = $form; $listConfig['type'] = 0; $task = 'can_view_database_list_' . $form; if (I2CE_PermissionParser::taskExists($task)) { $listConfig['task'] = $task; } $edit_task = 'can_edit_database_list_' . $form; if (I2CE_PermissionParser::taskExists($edit_task)) { $listConfig['edit_task'] = $edit_task; } } if (!$listConfig['form']) { return false; } $form = $listConfig['form']; if (!array_key_exists('text', $listConfig) || !$listConfig['text']) { $listConfig['text'] = I2CE_FormFactory::instance()->getDisplayName($form); } if (!array_key_exists('title', $listConfig)) { $title = "Add/Update %s"; I2CE::getConfig()->setIfIsSet($title, '/modules/Lists/messages/edit_title'); $title = @vsprintf($title, $listConfig['text']); $listConfig['title'] = $title; } if ($this->request('remap') && $this->primaryObject instanceof I2CE_Form) { if (!array_key_exists('fields', $listConfig) || !is_array($listConfig['fields'])) { $listConfig['fields'] = array(); } foreach ($this->primaryObject->getFieldNames() as $field) { if ($field == 'remap') { $listConfig['fields']['remap'] = array('enabled' => 1); } else { if (!array_key_exists($field, $listConfig['fields']) || !is_array($listConfig['fields'][$field])) { $listConfig['fields'][$field] = array(); } $data =& $listConfig['fields'][$field]; if (!array_key_exists('attributes', $data) || !is_array($data['attributes'])) { $data['attributes'] = array(); } $data['attributes']['noedit'] = 'strict'; unset($data); } } $listConfig['fields']['remap'] = array('enabled' => 1); } else { $listConfig['fields']['remap'] = array('enabled' => 0); } if (!array_key_exists('display_order', $listConfig)) { if ($this->getPrimary() instanceof I2CE_Form) { $all_field_names = $this->getPrimary()->getFieldNames(); $display_first = array_diff($all_field_names, array('remap', 'i2ce_hidden')); $listConfig['display_order'] = implode(',', $display_first); } } return $listConfig; }
protected function getListLinkNode($listConfig) { $task = false; if (array_key_exists('task', $listConfig) && is_scalar($listConfig['task'])) { $task = $listConfig['task']; } if ($task && I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) { return false; } $form = false; if (array_key_exists('form', $listConfig) && is_scalar($listConfig['form'])) { $form = $listConfig['form']; } if (!$form || !in_array($form, $this->all_lists)) { return false; } $text = ''; if (array_key_exists('text', $listConfig) && is_scalar($listConfig['text'])) { $text = $listConfig['text']; } if (!$text) { $text = I2CE_FormStorage::instance()->getDisplayName($form); } if (!$listConfig['type']) { $attrs = array('href' => 'index.php/auto_list?form=' . $form); } else { $attrs = array('href' => 'index.php/auto_list?type=' . $listConfig['type']); } return $this->template->createElement('a', $attrs, $text); }
/** * Set up the default editable display for this form field. * @return array of DOMNode */ protected function _processDOMEditable($node, $template, $form_node, $display) { $permissionParser = new I2CE_PermissionParser($template, new I2CE_User()); $show_hidden = 0; if ($form_node->hasAttribute('show_i2ce_hidden') && $permissionParser->hasTask('can_hide_list_members')) { $show_hidden = (int) $form_node->getAttribute('show_i2ce_hidden'); if ($show_hidden < 0 || $show_hidden > 2) { $show_hidden = 0; } } $form_node->removeAttribute('show_i2ce_hidden'); if ($form_node->hasAttribute('selectableforms')) { $forms = $this->getSelectableForms(); $t_forms = explode(':', $form_node->getAttribute('selectableforms')); $t_forms = array_intersect($forms, $t_forms); if (count($t_forms) > 0) { $forms = $t_forms; } $form_node->removeAttribute('selectableforms'); } else { $forms = $this->getSelectableForms(); } if ($form_node->hasAttribute('show')) { $type = $form_node->getAttribute('show'); $form_node->removeAttribute('show'); } else { $type = 'default'; } $limits = $this->getFormLimits($type); $limit_val = false; $calculated_limit_val = null; if ($form_node->hasAttribute('limit_field') && ($limit_field = $form_node->getAttribute('limit_field')) && $form_node->hasAttribute('limit_val') && ($limit_val = $form_node->getAttribute('limit_val'))) { if (strpos($limit_val, ':') !== false) { list($form, $field) = array_pad(explode(':', $limit_val), 2, ''); //var_dump($template->getForm($form,$form_node)); if (($formObj = $template->getForm($form, $node)) instanceof I2CE_Form && $formObj->getName() == $form && ($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) { $calculated_limit_val = $fieldObj->getDBValue(); } $limit_val = $template->getData('DISPLAY', substr($limit_val, 1), $form_node); } else { if (strlen($limit_val) > 0 && $limit_val[0] == '$') { $limit_val = $template->getData('DISPLAY', substr($limit_val, 1), $form_node); } else { $calculated_limit_val = $limit_val; } } if (is_scalar($calculated_limit_val)) { $new_limits = array('operator' => 'FIELD_LIMIT', 'field' => $limit_field, 'style' => 'equals', 'data' => array('value' => $calculated_limit_val)); $limit_index = $this->getName(); if (is_array($limits) && array_key_exists($limit_index, $limits) && is_array($limits[$limit_index]) && count($limits[$limit_index]) > 0) { $limits[$limit_index] = array('operator' => 'AND', 'operand' => array(0 => $limits[$limit_index], 1 => $new_limits)); } else { $limits[$limit_index] = $new_limits; } $this->setAlternateLimits($limits); } } $orders = $this->getFormOrders($type); $style = $this->getDisplayedStyle($display); $method = 'create_DOMEditable_' . $display; if (!$this->_hasMethod($method)) { $method = 'create_DOMEditable_' . $style; if (!$this->_hasMethod($method)) { $method = 'create_DOMEditable_' . $this->getDefaultDisplayStyle($type); } } $this->{$method}($node, $template, $form_node, $show_hidden); $this->restoreLimits(); }
public function generate($top_node) { if (!$top_node instanceof DOMNode || !($node = $this->template->appendFileByNode($this->options['template'], 'div', $top_node)) || !$this->primaryObject instanceof I2CE_Form || $this->options['task'] && I2CE_PermissionParser::taskExists($this->options['task']) && !$this->page->hasPermission("task(" . $this->options['task'] . ")", $node)) { return false; } I2CE::raiseError("Generating for " . $this->primaryObject->getNameID()); if ($this->options['is_edit']) { if (!($formNode = $this->template->getElementByTagName('form', 0, $node)) instanceof DOMNode) { return false; } $formNode->setAttribute('action', $this->options['save_link']); } $this->template->setForm($this->primaryObject, $node); $this->template->setDisplayDataImmediate('form_display_name', $this->options['display_name'], $node); $this->template->setDisplayDataImmediate('form_title', $this->options['title'], $node); $this->template->setDisplayDataImmediate('form_subtitle', $this->options['subtitle'], $node); foreach ($this->getLinkTypes() as $type) { $added = 0; if (($ulNode = $this->template->getElementByName('form_' . $type . '_links', 0, $node)) instanceof DOMNode) { $added = $this->addLinks('li', $this->options[$type . '_links'], $ulNode); } if ($added == 0 && ($linkContainer = $this->template->getElementByName('form_' . $type, 0, $node)) instanceof DOMNode) { $this->template->removeNode($linkContainer); } } if (($fieldsNode = $this->template->getElementByName('form_fields', 0, $node)) instanceof DOMNode) { $field_tasks = array(); $all_field_names = $this->primaryObject->getFieldNames(); $field_names = array(); $display_order = $this->options['display_order']; foreach ($display_order as $field_name) { if (($pos = array_search($field_name, $all_field_names)) === false) { continue; } unset($display_order[$pos]); $field_names[] = $field_name; } $listed_fields = array_keys($this->options['field_data']); $field_names = array_unique(array_merge($field_names, $all_field_names, $listed_fields)); $count = 0; foreach ($field_names as $field_name) { if (!$this->options['field_data'][$field_name]['enabled']) { continue; } if ($this->options['is_edit']) { if ($count % 2 == 0) { $trNode = $this->template->createElement('tr'); $fieldsNode->appendChild($trNode); } $this->fieldEdit($field_name, $this->options['field_data'][$field_name], $trNode); } else { $this->fieldView($field_name, $this->options['field_data'][$field_name], $fieldsNode, $count % 2); } $count++; } } return true; }
public function action() { $this->template->addHeaderLink('I2CE_AjaxTabPanel.js'); $this->template->addHeaderLink('tabs.css'); if (!array_key_exists('tabs', $this->args) || !is_array($this->args['tabs'])) { I2CE::raiseError("No Tabs Defined"); return false; } $tabs = $this->args['tabs']; if (!($tabsNode = $this->template->getElementByID('tabs_link'))) { I2CE::raiseError("Don't know where to put tab links"); return false; } if (!($tabContentsNode = $this->template->getElementByID('tabs_content'))) { I2CE::raiseError("Don't know where to put tab content"); return false; } $selected = false; if (array_key_exists('selected_tab', $this->args) && is_scalar($this->args['selected_tab']) && $this->args['selected_tab']) { $selected = $this->args['tab']; } if ($this->request_exists('selected_tab') && is_scalar($this->request('selected_tab')) && $this->request('selected_tab')) { $selected = $this->request('tab'); } $order = array(); if (array_key_exists('tab_order', $this->args) && is_scalar($this->args['tab_order'])) { $order = explode(",", $this->args['tab_order']); } $order = array_unique(array_merge($order, array_keys($tabs))); foreach ($order as $i => $tab) { if (!array_key_exists($tab, $tabs) || !is_array($data = $tabs[$tab]) || !array_key_exists('href', $data) || !is_scalar($data['href']) || array_key_exists('task', $data) && is_scalar($data['task']) && ($task = $data['task']) && I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) { I2CE::raiseError("Skipping tab {$tab} as not valid"); unset($order[$i]); } } if (count($order) == 0) { I2CE::raiseError("No valid tabs"); return false; } if (!in_array($selected, $order)) { reset($order); $selected = current($order); } $sources = array(); $ff = I2CE_FormFactory::instance(); foreach ($order as $tab) { $data = $tabs[$tab]; if (!array_key_exists('content', $data) || !is_scalar($data['content']) || !$data['content']) { $data['content'] = 'siteContent'; } $title = $tab; if (array_key_exists('title', $data) && is_scalar($data['title']) && $data['title']) { $title = $data['title']; } $attrs = array('class' => 'tab_link', 'id' => 'tab_link_' . $tab); $tabsNode->appendChild($liNode = $this->template->createElement('li', $attrs, $title)); $href = $data['href']; $reqs = array(); if (array_key_exists('request_vars', $data) && is_array($data['request_vars'])) { $reqs = array(); foreach ($data['request_vars'] as $tgt_var => $src_var) { if (!$this->request_exists($src_var)) { continue; } $reqs[$tgt_var] = $this->request[$src_var]; } } if (count($reqs) > 0) { $reqs = http_build_query(self::flattenRequestVars($reqs)); if (strpos($href, '?') !== false) { $href .= '&' . $reqs; } else { $href .= '?' . $reqs; } } $attrs = array('class' => 'tab_content', 'id' => 'tab_content_' . $tab, 'href' => $href); if (array_key_exists('formfield', $data) && is_scalar($data['formfield']) && $data['formfield']) { $attrs['type'] = 'form'; $attrs['name'] = $data['formfield']; } $tabContentsNode->appendChild($contentNode = $this->template->createElement('span', $attrs)); $sources[$tab] = '#' . $data['content']; $formObj = false; $formID = false; if (array_key_exists('form', $data) && is_scalar($form = $data['form'])) { $where = array(); $order = null; if (array_key_exists('where', $data) && is_array($data['where'])) { $where = $data['where']; } if (array_key_exists('order', $data) && is_scalar($data['order'])) { $order = $data['order']; } if ($formID = I2CE_FormStorage::search($form, $this->primaryObject->getNameID(), $where, $order, 1)) { $formObj = $ff->createContainer($form . '|' . $formID); } } if ($formObj instanceof I2CE_Form) { $formObj->populate(); $this->template->setForm($formObj, $liNode); $this->template->setForm($formObj, $contentNode); } } $options = json_encode(array('responseFilters' => $sources)); $js = 'document.addEvent("domready", function() { var tab = new I2CE_AjaxTabPanel("tab_panel",' . $options . '); if (tab) {; tab.showTab("' . addslashes($selected) . '")}; });'; $this->template->addHeaderText($js, 'script', 'create_tabs'); }