/** * Perform any actions for the page * * @returns boolean. true on sucess */ public function action() { parent::action(); if (count($this->request_remainder) != 1) { $this->userMessage("Cannot view archived report"); $this->setRedirect("CustomReports/view/reportViews"); return false; } reset($this->request_remainder); $this->reportView = (string) current($this->request_remainder); if (isset($config->reportViews->{$this}->reportView->limit_view_to) && $config->reportViews->{$this}->reportView->limit_view_to) { if (!$this->hasPermission(' task(custom_reports_admin) or ' . $config->reportViews->{$this}->reportView->limit_view_to)) { $this->userMessage("You do not have permission to view this report"); $this->setRedirect("CustomReports/view/reportViews"); return false; } } if ($this->request_exists('id')) { $id = $this->request('id'); $link = I2CE_FormField_BINARY_FILE::getFieldLink($id, 'report'); $this->redirect($link); return true; } else { $node = $this->template->addFile("archiveReports_menu.html"); if (!$node instanceof DOMNode) { return false; } $dn = $this->reportView; I2CE::getConfig()->setIfIsSet($dn, "/modules/CustomReports/reportViews/{$this->reportView}/display_name"); $this->template->setDisplayDataImmediate('reportView_name', $dn, $node); $where = array('operator' => 'FIELD_LIMIT', 'field' => 'report_view', 'style' => 'equals', 'data' => array('value' => $this->reportView)); $list = I2CE_FormStorage::listDisplayFields('archived_report', I2CE_List::getDisplayFields('archived_report'), false, $where, I2CE_List::getSortFields('archived_report')); $disp_string = I2CE_List::getDisplayString('archived_report'); foreach ($list as &$val) { $val = vsprintf($disp_string, $val); } return $this->paginateList($list); } }
protected function postProcessOptions($options) { if (!array_key_exists('form', $options) || !$this->primaryObject instanceof I2CE_Form) { return $options; } if (!$options['mapped_field']) { $options['mapped_field'] = $this->primaryObject->getName(); } $where = array('operator' => 'FIELD_LIMIT', 'field' => $options['mapped_field'], 'style' => 'equals', 'data' => array('value' => $this->primaryObject->getNameId())); if (count($options['where']) > 0) { $options['where'] = array('operator' => 'AND', 'operand' => array(0 => $where, 1 => $options['where'])); } else { $options['where'] = $where; } $is_list = ($formClass = I2CE_FormFactory::instance()->getClassName($options['form'])) && I2CE_List::isList($formClass); if (count($options['orders']) == 0 && $is_list) { $options['orders'] = I2CE_List::getSortFields($options['form']); } if (count($options['printf_args']) == 0 || !$options['printf']) { if ($is_list) { $options['printf_args'] = I2CE_List::getDisplayFields($options['form'], $options['style']); $options['printf'] = I2CE_List::getDisplayString($options['form'], $options['style']); } } if (!$options['link']) { if ($this->page->module() == 'I2CE') { $url = $this->page->page() . '/' . implode('/', $this->page->request_remainder()); } else { $url = $this->page->module() . '/' . $this->page->page() . '/' . implode('/', $this->page->request_remainder()); } $options['link'] = $url . "?type=" . $options['form'] . "&id="; } if (is_scalar($options['link_field'])) { $options['link_field'] = explode(':', $options['link_field']); } return $options; }
/** * Create a data tree from a report of the selectable forms. Deisgned to be fed into tree select * @param array $fields * @param array $forms An unorderd array of form names whose values we allow to be selected * @param array $displayed The displayed forms for the tree * @param array $limits An array with keys form names and value limit data * @param array $orders An array with keys form names and values array of field orders for that form. * If the form name has no orders, we use default ordering for that form based on its displayed firelds * @param int $show_hidden 0=non-hidden, 1=All, 2=hidden only. Defaults to 0 * @param string $report A report name to use for the query instead of building it from form cache or directly. * @return array */ public static function buildReportTree($fields, $forms, $displayed, $limits, $orders = array(), $show_hidden = 0, $report = null) { if (!is_array($report) || !array_key_exists('report', $report)) { return array(); } $report_table = I2CE_CustomReport::getCachedTableName($report['report']); if (!$report_table) { return array(); } $map = array(); if (array_key_exists('map', $report)) { $map = $report['map']; } $where = array(); $displays = array(); $report_alias = array(); $formObjs = array(); $use_link = ''; foreach ($fields as $formfield) { list($form, $link_field) = $formfield; $ff = $form . ($link_field ? "+{$link_field}" : ""); if (array_key_exists($ff, $map)) { $report_alias[$ff] = $map[$ff]; } elseif (array_key_exists($form, $map)) { $report_alias[$form] = $map[$form]; $report_alias[$ff] = $map[$form]; } else { $report_alias[$form] = $form; $report_alias[$ff] = $form; } //if ( array_key_exists( $ff, $limits ) ) { //$limit = $limits[$ff]; //} else if (array_key_exists($report_alias[$ff], $limits)) { $limit = $limits[$report_alias[$ff]]; } elseif (array_key_exists($form, $limits)) { $limit = $limits[$form]; } else { $limit = array(); } self::addFormIdToLimit($form, $limit); $limit = self::showHiddenLimit($limit, $show_hidden); /* if ( !$show_hidden ) { $hidden = $report_alias[$ff] . '+i2ce_hidden'; $where[] = "( `$hidden` = 0 OR ISNULL( `$hidden` ) )"; } */ $disp_fields = I2CE_List::getDisplayFields($form); if (array_key_exists($form, $orders)) { $order = $orders[$form]; } else { $order = I2CE_List::getSortFields($form); } $sort_list = array(); //if ( array_key_exists( $form, $displayed ) && $displayed[$form] ) { if (array_key_exists($form, $displayed)) { $alias_form = $report_alias[$ff]; if ($displayed[$form]) { $displays[$alias_form]['form'] = $form; if ($use_link == '') { $displays[$alias_form]['link_field'] = $link_field == '' ? $link_field : "{$alias_form}+{$link_field}"; } else { $displays[$alias_form]['link_field'] = $use_link; $use_link = ''; } foreach ($disp_fields as $disp) { $displays[$alias_form]['fields'][$disp] = $alias_form . "+{$disp}"; } foreach ($order as $i => $ord) { if (!is_string($ord)) { unset($order[$i]); continue; } if ($ord[0] == '-') { $field = substr($ord, 1); $all_orders[] = "`{$alias_form}+{$field}` DESC"; } else { $field = $ord; $all_orders[] = "`{$alias_form}+{$field}` ASC"; } } } elseif ($use_link == '') { $use_link = $link_field == '' ? $link_field : "{$alias_form}+{$link_field}"; } } if (!array_key_exists($form, $formObjs)) { $formObjs[$form] = I2CE_FormFactory::instance()->createContainer($form); if (!$formObjs[$form] instanceof I2CE_Form) { I2CE::raiseError("Could not instantiate {$form}"); return array(); } } self::$curr_alias = $report_alias[$ff]; $where[] = $formObjs[$form]->generateWhereClause($limit, array("I2CE_DataTree", "getSQLField")); } $where_clause = ""; $order_by = ""; if (count($where) > 0) { $where_clause = " WHERE " . implode(' AND ', $where); } if (count($all_orders) > 0) { $order_by = " ORDER BY " . implode(',', $all_orders); } $qry = "SELECT * FROM {$report_table} {$where_clause} {$order_by}"; $db = MDB2::singleton(); I2CE::raiseMessage($qry); $res = $db->query($qry); if (I2CE::pearError($res, "Invalid report data tree query: ")) { return array(); } $phonebook = array(); $results = array(); $display_string = array(); $display_copy = $displays; while ($data = $res->fetchRow()) { foreach ($displays as $alias => $disp_data) { $id_field = strtolower($alias . "+id"); if ($data->{$id_field} == null || array_key_exists($data->{$id_field}, $phonebook)) { continue; } $curr = array(); $add_this = false; if (in_array($disp_data['form'], $forms)) { $curr['value'] = $data->{$id_field}; $add_this = true; } if (!$add_this) { $check_ok = false; foreach ($display_copy as $alias_copy => $disp_data_copy) { if ($alias_copy == $alias) { $check_ok = true; continue; } if (!$check_ok) { continue; } if (array_key_exists('link_field', $disp_data_copy) && $disp_data_copy['link_field'] != '') { $link_field_copy = $disp_data_copy['link_field']; if ($data->{$id_field} == $data->{$link_field_copy}) { $add_this = true; break; } } } } if (!$add_this) { continue; } if (!array_key_exists($disp_data['form'], $display_string)) { $display_string[$disp_data['form']] = I2CE_List::getDisplayString($disp_data['form']); } $disp_array = array(); $disp_str = $display_string[$disp_data['form']]; $disp_str_arr = explode('%s', $disp_str); $fo = $formObjs[$disp_data['form']]; $disp_count = 0; foreach ($disp_data['fields'] as $field => $dbfield) { $disp_count++; if ($dbfield == $disp_data['link_field']) { // Don't include the data from the link field since it will already be there. if ($disp_count == 1) { unset($disp_str_arr[$disp_count]); } else { unset($disp_str_arr[$disp_count - 1]); } continue; } $dbfield = strtolower($dbfield); $fieldObj = $fo->getField($field); if (!$fieldObj instanceof I2CE_FormField) { I2CE::raiseError("Could not get field {$field}"); continue; } if (isset($data->{$dbfield})) { $fieldObj->setFromDB($data->{$dbfield}); $disp_array[$field] = $fieldObj->getDisplayValue(); } else { $disp_array[$field] = null; } } $disp_str = implode('%s', $disp_str_arr); $display = vsprintf($disp_str, $disp_array); $curr['display'] = $display; $phonebook[$data->{$id_field}] =& $curr; if ($disp_data['link_field'] != '') { $link_field = $disp_data['link_field']; if (array_key_exists($data->{$link_field}, $phonebook)) { $add_to =& $phonebook[$data->{$link_field}]; if (!array_key_exists('children', $phonebook[$data->{$link_field}])) { $phonebook[$data->{$link_field}]['children'] = array(); } $phonebook[$data->{$link_field}]['children'][] =& $curr; } else { //I2CE::raiseMessage( "Couldn't find $link_field " . $data->$link_field . " in phonebook " ); } } else { $results[] =& $curr; } unset($curr); } } return $results; }
public function generateListData($lang = 'en-US') { I2CE_Locales::setPreferredLocale(strtr($lang, '-', '_')); $display_style = 'default'; I2CE::getConfig()->setIfIsSet($display_style, "/modules/SVS/lists/" . $this->oid . "/meta/display_style"); $code_style = 'code'; I2CE::getConfig()->setIfIsSet($code_style, "/modules/SVS/lists/" . $this->oid . "/meta/code_style"); $code_system_style = false; I2CE::getConfig()->setIfIsSet($code_system_style, "/modules/SVS/lists/" . $this->oid . "/meta/code_system_style"); $meta = $this->getMeta(); $code_system = $meta['Source']; I2CE::getConfig()->setIfIsSet($code_system, "/modules/SVS/lists/" . $this->oid . "/meta/code_system"); $where = I2CE::getConfig()->getAsArray("/modules/SVS/lists/" . $this->oid . "/where"); if (!is_array($where)) { $where = array(); } $inc_hidden = false; I2CE::getConfig()->setIfIsSet($inc_hidden, "/modules/SVS/lists/" . $this->oid . "/hidden"); //include hidden if (!$inc_hidden) { $nohidden = array('operator' => 'OR', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'no', 'data' => array()), array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'null', 'data' => array()))); if (count($where) > 0) { $where = array('operator' => 'AND', 'operand' => array(0 => $where, 1 => $nohidden)); } else { $where = $nohidden; } } $styles = array('displayName' => $display_style, 'code' => $code_style); if ($code_system_style) { $styles['codeSystem'] = $code_system_style; } $all_fields = array(); $disp_strings = array(); $disp_fields = array(); foreach ($styles as $out => $style) { if ($style == 'id') { continue; } $disp_strings[$out] = I2CE_List::getDisplayString($this->list, $style); $disp_fields[$out] = I2CE_List::getDisplayFields($this->list, $style); ksort($disp_fields[$out]); $all_fields = array_merge($all_fields, $disp_fields[$out]); } $all_fields = array_unique($all_fields); $field_data = I2CE_FormStorage::listDisplayFields($this->list, $all_fields, false, $where, array()); $data = array(); foreach ($field_data as $id => $fields) { $data[$id] = array(); foreach ($styles as $out => $style) { if ($style == 'id') { $data[$id][$out] = $id; } else { $values = array(); foreach ($disp_fields[$out] as $field) { if (array_key_exists($field, $fields)) { $val = $fields[$field]; } else { $val = ''; } $values[] = $val; } $data[$id][$out] = @vsprintf($disp_strings[$out], $values); } } if (!in_array('codeSystem', $styles)) { $data[$id]['codeSystem'] = $code_system; } } return $data; }
/** * Build the data tree for the given list of fields * and limits. This is called by I2CE_List::buildDataTree. * See that for more details * @see I2CE_List::buildDataTree * @param array $fields The fields to build the tree * @param array $forms The selectable forms * @param array $displayed The displayed forms for the tree * @param array $limits The list of limits for each form. * @param array $orders The order fields for each given form * @param int $show_hidden 0=non-hidden, 1=All, 2=hidden only. Defaults to 0 * @return array The ordered list of all entries in the tree. */ public function buildDataTree($fields, $forms, $displayed, $limits, $orders, $show_hidden = 0) { $prev_form = false; $form_aliases = array(); $selects = array(); $displays = array(); $all_orders = array(); $formObjs = array(); $skip_links = array(); $skip_link_fields = array(); $this->preserve_ids = true; foreach ($fields as $formfield) { list($form, $link_field) = $formfield; $cachedForm = new I2CE_CachedForm($form); $cachedForm->generateCachedTable(false); unset($cachedForm); $alias_form = $form . ($link_field ? "+{$link_field}" : ""); if (array_key_exists($alias_form, $limits)) { $limit = $limits[$alias_form]; } elseif (array_key_exists($form, $limits)) { $limit = $limits[$form]; } else { $limit = array(); } self::addFormIdToLimit($form, $limit); $limit = I2CE_List::showHiddenLimit($limit, $show_hidden); $disp_fields = I2CE_List::getDisplayFields($form); $field_list = $disp_fields; $field_list[] = 'id'; if ($link_field && !in_array($link_field, $field_list)) { $field_list[] = $link_field; } if (array_key_exists($form, $orders)) { $order = $orders[$form]; } else { $order = I2CE_List::getSortFields($form); } $sort_list = array(); if (array_key_exists($form, $displayed) && $displayed[$form]) { $displays[$alias_form]['form'] = $form; $displays[$alias_form]['link_field'] = $link_field; foreach ($disp_fields as $disp) { $displays[$alias_form]['fields'][$disp] = "{$alias_form}+{$disp}"; } foreach ($order as $i => $ord) { if (!is_string($ord)) { unset($order[$i]); continue; } if ($ord[0] == '-') { $field = substr($ord, 1); $all_orders[] = "`{$alias_form}`.`{$field}` DESC"; } else { $field = $ord; $all_orders[] = "`{$alias_form}`.`{$field}` ASC"; } if (!in_array($field, $field_list)) { $sort_list[] = $field; } } } else { $skip_link_fields[$alias_form] = $link_field; } if (!array_key_exists($form, $formObjs)) { $formObjs[$form] = I2CE_FormFactory::instance()->createContainer($form); if (!$formObjs[$form] instanceof I2CE_Form) { I2CE::raiseError("Could not instantiate {$form}"); return array(); } } $where = false; if (is_array($limit) && count($limit) > 0) { $where = $formObjs[$form]->generateWhereClause($limit, array("I2CE_FormStorage_cached", "getSQLField")); } $query = $this->getRequiredFieldsQuery($form, array_merge($field_list, $sort_list), null, false, array("I2CE_FormStorage_cached", "getSQLField")); if (is_array($prev_form) && array_key_exists('form', $prev_form)) { if ($prev_form['form'] == $form) { $froms[$alias_form] = " LEFT JOIN "; } else { $froms[$alias_form] = " LEFT JOIN "; } } else { $froms[$alias_form] = ""; } $froms[$alias_form] .= "({$query}" . ($where ? " WHERE " . $where : "") . ") AS `{$alias_form}`"; if ($link_field) { $join_ons = array(); $ff = $formObjs[$form]->getField($link_field); if ($ff instanceof I2CE_FormField_MAPPED) { foreach ($ff->getSelectableForms() as $link_form) { if (array_key_exists($link_form, $form_aliases)) { foreach ($form_aliases[$link_form] as $link_alias) { $join_ons[] = "`{$alias_form}`.`{$link_field}` = `{$link_alias}`.`id`"; if (!array_key_exists($link_alias, $displays) && array_key_exists($link_alias, $skip_link_fields)) { $skip_links[$alias_form . '+' . $link_field] = $link_alias . '+' . $skip_link_fields[$link_alias]; } } } } } else { I2CE::raiseMessage("Not sure what to link for {$form} {$link_field} so guessing."); $join_ons[] = "`{$alias_form}`.`{$link_field}` = `" . $prev_form['alias'] . "`.`id`"; } if (count($join_ons) > 0) { $froms[$alias_form] .= " ON (" . implode(' OR ', $join_ons) . ") "; } else { I2CE::raiseError("Don't know how to join on {$form} {$link_field}"); return array(); } } foreach ($field_list as $field) { $selects[] = "`{$alias_form}`.`{$field}` AS `{$alias_form}+{$field}`"; } $prev_form = array('form' => $form, 'alias' => $alias_form); $form_aliases[$form][] = $alias_form; } $or_wheres = array(); foreach ($forms as $selectable) { if (array_key_exists($selectable, $form_aliases)) { foreach ($form_aliases[$selectable] as $required_form) { $or_wheres[] = "`{$required_form}`.`id` IS NOT NULL"; } } } $join_query = "SELECT " . implode(',', $selects) . " FROM " . implode('', $froms) . (count($or_wheres) > 0 ? " WHERE " . implode(' OR ', $or_wheres) : "") . (count($all_orders) > 0 ? " ORDER BY " . implode(',', $all_orders) : ""); //I2CE::raiseMessage( $join_query ); $res = $this->db->query($join_query); if (I2CE::pearError($res, "Bad query -- {$join_query}")) { return array(); } $prev_ids = array(); $results = array(); $phonebook = array(); $display_string = array(); foreach ($displays as $fix_link_alias => &$fix_link_disp_data) { if (array_key_exists('link_field', $fix_link_disp_data) && $fix_link_disp_data['link_field'] != '') { $full_link_field = strtolower($fix_link_alias . "+" . $fix_link_disp_data['link_field']); while (array_key_exists($full_link_field, $skip_links)) { $full_link_field = $skip_links[$full_link_field]; } $fix_link_disp_data['link_field'] = $full_link_field; } } $display_copy = $displays; while ($data = $res->fetchRow()) { unset($prev_disp); foreach ($displays as $alias => $disp_data) { $id_field = strtolower($alias . "+id"); if ($data->{$id_field} == null || array_key_exists($data->{$id_field}, $phonebook)) { continue; } $curr = array(); $add_this = false; if (in_array($disp_data['form'], $forms)) { $curr['value'] = $data->{$id_field}; $add_this = true; } if (!$add_this) { $check_ok = false; foreach ($display_copy as $alias_copy => $disp_data_copy) { if ($alias_copy == $alias) { $check_ok = true; continue; } if (!$check_ok) { continue; } if (array_key_exists('link_field', $disp_data_copy) && $disp_data_copy['link_field'] != '') { $link_field_copy = $disp_data_copy['link_field']; if ($data->{$id_field} == $data->{$link_field_copy}) { $add_this = true; break; } } } } if (!$add_this) { continue; } if (!array_key_exists($disp_data['form'], $display_string)) { $display_string[$disp_data['form']] = I2CE_List::getDisplayString($disp_data['form']); } $disp_array = array(); $disp_str = $display_string[$disp_data['form']]; $disp_str_arr = explode("%s", $disp_str); $fo = $formObjs[$disp_data['form']]; $disp_count = 0; foreach ($disp_data['fields'] as $field => $dbfield) { $disp_count++; if ($field == $disp_data['link_field']) { // Don't include the data from the link field since it will already // be in the tree above it. if ($disp_count == 1) { unset($disp_str_arr[$disp_count]); } else { unset($disp_str_arr[$disp_count - 1]); } continue; } $dbfield = strtolower($dbfield); $fieldObj = $fo->getField($field); if (!$fieldObj instanceof I2CE_FormField) { I2CE::raiseError("Could not get field {$field}"); continue; } if (isset($data->{$dbfield})) { $fieldObj->setFromDB($data->{$dbfield}); $disp_array[$field] = $fieldObj->getDisplayValue(); } else { $disp_array[$field] = null; } } $disp_str = implode('%s', $disp_str_arr); $display = vsprintf($disp_str, $disp_array); //$display = $data->$disp_data['fields']['name']; $curr['display'] = $display; $phonebook[$data->{$id_field}] =& $curr; if ($disp_data['link_field'] != '') { $link_field = $disp_data['link_field']; if (array_key_exists($data->{$link_field}, $phonebook)) { $add_to =& $phonebook[$data->{$link_field}]; if (!array_key_exists('children', $phonebook[$data->{$link_field}])) { $phonebook[$data->{$link_field}]['children'] = array(); } $phonebook[$data->{$link_field}]['children'][] =& $curr; } else { I2CE::raiseMessage("Couldn't find {$link_field} " . $data->{$link_field} . " in phonebook"); } } else { $results[] =& $curr; } unset($curr); } } $this->preserve_ids = false; return $results; }
/** * Returns the value of this field as a human readable format. * @param I2CE_Entry $entry If a I2CE_Entry object has been passed to this method then it will return the value for that entry assuming it's an * entry for this field. * @param string $style. Defaults to 'default' * @return mixed */ public function _getDisplayValue($entry = false, $style = 'default') { if ($entry instanceof I2CE_Entry) { $value = $entry->getValue(); } else { $value = $this->getValue(); } if (!is_array($value) || count($value) != 2) { return ''; } list($form, $id) = $value; if ($id == '0' || $id == '') { return ''; } if (!$form) { return ''; } $formid = "{$form}|{$id}"; $ff = I2CE_FormFactory::instance(); $formObj = $ff->createForm($formid); if (!$formObj instanceof I2CE_Form) { return ''; } $formObj->populate(); if (!$this->isValidForm($form)) { return $formid; } $style = $this->ensureStyle($style); $styles = array($style); if ($style != 'default') { $styles[] = 'default'; } foreach ($styles as $s) { $printf_path = "meta/display/{$s}/print_f/{$form}"; $printfargs_path = "meta/display/{$s}/printf_args/{$form}"; $printfargstyles_path = "meta/display/{$s}/printf_arg_styles/{$form}"; if (!$this->optionsHasPath($printf_path) || !is_string($printf = $this->getOptionsByPath($printf_path))) { continue; } if (!$this->optionsHasPath($printfargs_path) || !is_array($printfargs = $this->getOptionsByPath($printfargs_path))) { continue; } if (!$this->optionsHasPath($printfargstyles_path) || !is_array($printfarg_styles = $this->getOptionsByPath($printfargstyles_path))) { $printfarg_styles = array(); } if (strlen($printf) == 0) { continue; } if (count($printfargs) == 0) { continue; } ksort($printfargs); $printfvals = array(); foreach ($printfargs as $printfarg) { if (!($fieldObj = $formObj->getField($printfarg)) instanceof I2CE_FormField) { $printfvals[] = ''; } else { if ($fieldObj instanceof I2CE_FormField_MAP) { if (!array_key_exists($printfarg, $printfarg_styles) || !is_string($argstyle = $printfarg_styles[$printfarg])) { $argstyle = 'default'; } if (($mapObj = $fieldObj->getMappedFormObject()) instanceof I2CE_List) { $printfvals[] = $mapObj->name($argstyle); } else { $printfvals[] = $fieldObj->getDisplayValue(); } } else { $printfvals[] = $fieldObj->getDisplayValue(); } } } return @vsprintf($printf, $printfvals); } $printf = I2CE_List::getDisplayString($form, $style); $printfargs = I2CE_List::getDisplayFields($form, $style); $printfvals = array(); foreach ($printfargs as $printfarg) { if (!($fieldObj = $formObj->getField($printfarg)) instanceof I2CE_FormField) { $printfvals[] = ''; } else { $printfvals[] = $fieldObj->getDisplayValue(false, $style); } } return @vsprintf($printf, $printfvals); }
protected function show_linked($obj, $data, $node) { $task = false; if (!array_key_exists('task', $data) && I2CE_PermissionParser::taskExists($task)) { $data['task'] = $task; } if ($task && I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})", $containerNode)) { return; } $ff = I2CE_FormFactory::instance(); if (!is_array($data) || !array_key_exists('form', $data) || !($form = $data['form']) || !($formObj = $ff->createContainer($form)) instanceof I2CE_Form) { return false; } $printf = false; $printf_args = array(); $orders = null; $link = false; $mapped_field = $obj->getName(); if ($formObj instanceof I2CE_List) { $style = 'default'; if (array_key_exists('style', $data) && is_scalar($data['style']) && $data['style']) { $style = $data['style']; } $printf_args = I2CE_List::getDisplayFields($form, $style); $printf = I2CE_List::getDisplayString($form, $style); $orders = I2CE_List::getSortFields($form); $link = "auto_list?form={$form}&id="; } if (array_key_exists('link', $data) && is_scalar($data['link']) && $data['link']) { $link = $data['link']; } if (array_key_exists('field', $data) && is_scalar($data['field']) && $data['field']) { $mapped_field = $data['field']; } if (array_key_exists('orders', $data)) { $orders = $data['orders']; } if (array_key_exists('printf', $data) && is_scalar($data['printf']) && $data['printf']) { $printf = $data['printf']; } if (array_key_exists('printf_args', $data) && is_array($data['printf_args']) && count($data['printf_args']) > 0) { $printf_args = $data['printf_args']; } $link_field = array(); if (array_key_exists('link_field', $data) && is_scalar($data['link_field']) && $data['link_field']) { $link_field = explode(':', $data['link_field']); } if (!$printf || count($printf_args) == 0 || !$link) { return; } $where = array('operator' => 'FIELD_LIMIT', 'field' => $mapped_field, 'style' => 'equals', 'data' => array('value' => $obj->getNameId())); if (array_key_exists('where', $data) && is_array($data['where'])) { $where = array('operator' => 'AND', 'operand' => array(0 => $data['where'], 1 => $where)); } $limit = false; if (array_key_exists('limit', $data)) { $limit = $data['limit']; } $title = $formObj->getDisplayName(); if (array_key_exists('title', $data) && is_scalar($data['title']) && $data['title']) { $title = $data['title']; } $arg_walker = array(); 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); if (count($dispDatas = I2CE_FormStorage::listDisplayFields($form, $printf_args, false, $where, $orders, $limit)) == 0) { return false; } $linkedNode = $this->template->appendFileByNode('auto_view_linked.html', 'div', $node); if (($pageDispNode = $this->template->getElementByName('pager_display', 0, $linkedNode)) instanceof DOMNode && ($pageResultsNode = $this->template->getElementByName('pager_results', 0, $linkedNode)) instanceof DOMNode) { $pageDispNode->setAttribute('id', 'linked_' . $form . '_pager_display'); $pageResultsNode->setAttribute('id', 'linked_' . $form . '_results'); if (!($dispDatas = $this->paginateList($dispDatas, 'linked_' . $form))) { return false; } } $this->template->setDisplayDataImmediate('link_title', $title); if (!($tbodyNode = $this->template->getElementByName('link_fields', 0, $node)) instanceof DOMNode) { return false; } foreach ($dispDatas 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($printf, $dispData); //form = person_position $linkid = $form . '|' . $id; foreach ($link_field as $lfield) { list($lform, $lid) = array_pad(explode('|', $linkid, 2), 2, ''); $linkid = I2CE_FormStorage::lookupField($lform, $lid, array($lfield), ''); } $attrs = array('href' => $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)); } }