/**
  *@returns array where keys are ids, values are arrays with the following keys 'value', 'display'
  */
 public function getMapOptions($type = 'default', $show_hidden = 0, $flat = true, $add_limits = array())
 {
     $forms = $this->getSelectableForms();
     $union_fields = $this->getDisplayedFields($type);
     $limits = $this->getFormLimits($type);
     if (is_array($add_limits) && count($add_limits) > 0) {
         if (!is_array($limits) || count($limits) > 0) {
             $limits = $add_limits;
         } else {
             //need to go through each form and possibly merge limits
             foreach ($add_limits as $form => $formLimits) {
                 if (!array_key_exists($form, $limits) || !is_array($limits[$form]) || count($limits[$form]) == 0) {
                     $limits[$form] = $formLimits;
                 } else {
                     $limits[$form] = array('operator' => 'AND', 'operand' => array(0 => $limits[$form], 1 => $formLimits));
                 }
             }
         }
     }
     $orders = $this->getFormOrders($type);
     $data = array();
     foreach ($union_fields as $form => $fields) {
         $data = array_merge($data, I2CE_List::flattenDataTree(I2CE_List::buildDataTree($fields, array($form), $limits, $orders, $show_hidden)));
     }
     return $data;
 }
Пример #2
0
 protected function _display($supress_output = false)
 {
     $this->template->addHeaderLink('mootools-core.js');
     $this->template->addHeaderLink('mootools-more.js');
     parent::_display($supress_output);
     if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) {
         I2CE::raiseError("Errors:\n" . $errors);
     }
     $this->ff = I2CE_FormFactory::instance();
     if (!$this->request_exists('id') || !($formid = $this->request('id'))) {
         $this->pushError("Bad list id {$id}");
         //needs to be localized
         return false;
     }
     $success = true;
     list($form, $id) = array_pad(explode("|", $formid, 2), 2, '');
     I2CE::raiseError(print_r($this->request(), true));
     if ($id == '*') {
         $where = array('operator' => 'FIELD_LIMIT', 'field' => 'remap', 'style' => 'not_null', 'data' => array());
         $ids = I2CE_FormStorage::search($form, false, $where);
         I2CE::raiseError("Form {$form} has remapping data for " . implode(" ", $ids));
         if (count($ids) > 0) {
             foreach (I2CE_List::getFieldsMappingToList($form) as $rform => $fields) {
                 foreach ($fields as $fieldObj) {
                     $field = $fieldObj->getName();
                     foreach ($ids as $id) {
                         I2CE::raiseError("Checking for remaps on {$rform}+{$field}");
                         $success &= $this->doRemap($rform, $field, $form . '|' . $id);
                     }
                 }
             }
         }
         $url = "index.php/auto_list?form=" . $form;
     } else {
         $form = '';
         if (!$this->request_exists('form') || !($form = $this->request('form')) || !in_array($form, $this->ff->getForms())) {
             $this->pushError("Form {$form} not found");
             return false;
         }
         $field = '';
         if (!$this->request_exists('field') || !($field = $this->request('field'))) {
             $this->pushError("Bad Field {$field}");
             return false;
         }
         $success = $this->doRemap($form, $field, $formid);
         $url = "index.php/auto_list?id={$formid}&form=" . $form;
     }
     if ($success) {
         $this->pushContent("Data was succesully remapped.  Continue on to database lists <a href='{$url}'>site</a>?");
     } else {
         $this->pushContent("Data was <b>not</b> succesully remapped.  Continue on to database lists <a href='{$url}'>site</a>?");
     }
     return true;
 }
Пример #3
0
 /**
  * Return the HTML file name for the form template for this form.
  * @param string $type
  * @return string
  */
 public function getHTMLTemplate($type = 'default')
 {
     if (!$type || $type == 'default') {
         if ($template_file = I2CE::getFileSearch()->search('TEMPLATES', "lists_form_" . $this->getName() . ".html")) {
             return $template_file;
         } else {
             return "lists_form_simple.html";
         }
     } else {
         return parent::getHTMLTemplate($type);
     }
 }
Пример #4
0
 /**
  * Perform the main actions of the page.
  */
 protected function action()
 {
     $factory = I2CE_FormFactory::instance();
     $this->template->setAttribute("class", "active", "menuManage", "a[@href='manage']");
     $this->template->appendFileById("menu_manage.html", "ul", "menuManage");
     switch ($this->get('action')) {
         case "review":
             if (I2CE_ModuleFactory::instance()->isEnabled("ihris-manage-Application")) {
                 $this->template->setAttribute("class", "active", "menuManage", "//li/a[@href='manage?action=review']");
                 $this->template->addFile("applicant_review.html");
                 if ($this->get_exists('position')) {
                     $position_data = explode('|', $this->get('position'), 2);
                     $position_id = $position_data[1];
                     $this->template->setDisplayData("return_link", array("action" => "review"));
                     $this->template->addFile("applicant_review_results.html");
                     $this->template->setDisplayData("position_name", I2CE_List::lookup($position_id, "position"));
                     $results = iHRIS_Applicant::findApplicants($position_id);
                     if (count($results) > 0) {
                         foreach ($results as $app_id => $app_data) {
                             $this->template->appendFileById("applicant_review_row.html", "li", "app_list");
                             $this->template->setDisplayData("app_id", array("id" => "person|" . $app_id));
                             $this->template->setDisplayData("app_name", $app_data['surname'] . ', ' . $app_data['firstname']);
                             //$last_mod = I2CE_Date::fromDB( $app_data['last_modified'] );
                             //$this->template->setDisplayData( "app_modified", $last_mod->displayDate() );
                             $this->template->setDisplayData("make_offer", array("parent" => "person|" . $app_id, "position" => $this->get('position')));
                         }
                     } else {
                         $this->template->appendFileById("applicant_review_no_results.html", "li", "app_list");
                     }
                 } else {
                     $this->template->addFile("applicant_review_list.html");
                     $positions = I2CE_Form::listFields("position", array("code", "title"), array('operator' => 'FIELD_LIMIT', 'field' => 'status', 'style' => 'equals', 'data' => array('value' => 'position_status|open')));
                     $count = 0;
                     foreach ($positions as $id => $data) {
                         $node = $this->template->appendFileById("applicant_review_list_entry.html", "tr", "open_position_list");
                         if (++$count % 2 == 0) {
                             $node->setAttribute("class", "even");
                         }
                         $this->template->setDisplayDataImmediate("view_applicant", array("action" => "review", "position" => "position|" . $id), $node);
                         $this->template->setDisplayDataImmediate("position_name", $data['code'] . " - " . $data['title'], $node);
                     }
                 }
             } else {
                 parent::action();
             }
             break;
         default:
             parent::action();
             break;
     }
 }
 /**
  * Sends any triggers when participants are uploaded
  * @param I2CE_PageFormCSV $page
  */
 public function trigger_upload_save($page)
 {
     if (!$page instanceof I2CE_PageFormCSV) {
         return;
     }
     $module_factory = I2CE_ModuleFactory::instance();
     if ($module_factory->isEnabled("UserTriggers")) {
         $triggers = $module_factory->getClass("UserTriggers");
         $instance = $page->getProviderInstance();
         $details = I2CE_List::lookup($instance->getId(), $instance->getName());
         $triggers->trigger('participant_upload_save', null, 'Participants were uploaded for ' . $details, true, $instance->getNameId());
     } else {
         I2CE::raiseError("Unable to call trigger because UserTriggers isn't enabled!");
     }
 }
 protected function loadList()
 {
     if (is_array($this->list_values)) {
         return;
     }
     $this->list_values = array();
     $path = "meta/list";
     if (!$this->optionsHasPath($path) || !is_string($list_form = $this->getOptionsByPath($path)) || !is_array($list_values = I2CE_List::listOptions($list_form))) {
         return;
     }
     foreach ($list_values as $data) {
         if (!is_array($data) || !array_key_exists('value', $data) || !array_key_exists('display', $data)) {
             continue;
         }
         $this->list_values[$data['value']] = $data['display'];
     }
 }
 /**
  * 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;
 }
Пример #9
0
 /**
  * Perform the main actions of the page.
  */
 protected function action()
 {
     parent::action();
     $this->template->addHeaderLink("view.js");
     $this->template->appendFileById("menu_view.html", "li", "navBarUL", true);
     $this->template->setAttribute("class", "active", "menuConfigure", "a[@href='configure']");
     $this->template->appendFileById("menu_configure.html", "ul", "menuConfigure");
     $this->template->setAttribute("class", "active", "menuLists", "a[@href='lists']");
     $factory = I2CE_FormFactory::instance();
     $job = $factory->createContainer($this->get('id'));
     $job->populate();
     $this->template->setForm($job);
     $positions = $job->getPositions();
     //print_r( $supervised );
     if (count($positions) > 0) {
         $this->template->appendFileById("view_job_positions.html", "div", "job");
         foreach ($positions as $record) {
             $this->template->appendFileById("view_position_row.html", "tr", "positions");
             $this->template->setDisplayData("position", I2CE_List::lookup($record, "position"));
             $this->template->setDisplayData("add_pos_id", array("id" => "position|" . $record));
         }
         $this->template->setAttribute("class", "even", "positions", "tr[position() mod 2 = 0]");
     }
 }
Пример #10
0
 /**
  * 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;
 }
 /**
  * Perform any extra validation for the license.
  * @param I2CE_Form $form
  */
 public function validate_form_person_scheduled_training_course_field_training_course_mod($fieldObj)
 {
     if (!$fieldObj instanceof I2CE_FormField_MAP_MULT || !($pstcObj = $fieldObj->getContainer()) instanceof iHRIS_Person_Scheduled_Training_Course || $pstcObj->hasAttribute('validate_by_course') && !$pstcObj->getAttribute('validate_by_course') || !($stcField = $pstcObj->getField('scheduled_training_course')) instanceof I2CE_FormField_MAP || !($stcObj = $stcField->getMappedFormObject()) instanceof iHRIS_Scheduled_Training_Course || !($tcField = $stcObj->getField('training_course')) instanceof I2CE_FormField_MAP || !($tcObj = $tcField->getMappedFormObject()) instanceof iHRIS_Training_Course || !($modField = $tcObj->getField('training_course_mod')) instanceof I2CE_FormField_MAP_MULT) {
         return;
     }
     $selected = $fieldObj->getValue();
     if (!is_array($selected)) {
         $selected = array();
     }
     $t_allowed = $modField->getValue();
     if (!is_array($t_allowed)) {
         return;
     }
     $allowed = array();
     foreach ($t_allowed as $allow) {
         if (!is_array($allow) || !count($allow) == 2) {
             continue;
         }
         list($allow_form, $allow_id) = $allow;
         $allowed[] = $allow_id;
     }
     $ok = true;
     $bads = array();
     foreach ($selected as $sel) {
         if (!is_array($sel) || !count($sel) == 2) {
             continue;
         }
         list($sel_form, $sel_id) = $sel;
         if (in_array($sel_id, $allowed)) {
             continue;
         }
         $bads[] = I2CE_List::lookup($sel_id, 'training_course_mod');
     }
     if (count($bads) > 0) {
         $fieldObj->setInvalidMessage('bad_mod', '', implode(" ", $bads));
     }
 }
Пример #12
0
 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;
 }
Пример #13
0
 /**
  * Checks to make sure all the required fields are valid.
  *
  * Checks to make sure the username is unique in the system and that the password matches the confirmed password.
  * @global array
  */
 public function validate()
 {
     parent::validate();
     if ($this->id == '0') {
         if (I2CE_User::userExists($this->username, false)) {
             $this->setInvalidMessage('username', 'unique');
         }
     }
     if (strlen($this->password) > 0 && $this->password != $this->confirm) {
         $this->setInvalidMessage('password', 'mismatch');
     }
     if ($this->id == '0' && $this->password == "" && !$this->generate_password) {
         $this->setInvalidMessage('password', 'required');
     }
     $saving_user = new I2CE_User('0', true, true, false);
     if ($saving_user->role != 'admin') {
         // Allow anyone to set the self service role
         $role_field = $this->getField('role');
         $role_val = $role_field->getDBValue();
         $role_val = str_replace('role|', '', $role_val);
         if ($saving_user->role != $role_val) {
             $default_ss = '';
             I2CE::getConfig()->setIfIsSet($default_ss, "/modules/SelfService/default_user_role");
             if ($role_val != $default_ss) {
                 $where = array('operator' => 'AND', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'assignable', 'style' => 'yes'), array('operator' => 'FIELD_LIMIT', 'field' => 'trickle_up', 'style' => 'equals', 'data' => array('value' => $saving_user->role)), array('operator' => 'FIELD_LIMIT', 'field' => 'id', 'style' => 'equals', 'data' => array('value' => $role_val))));
                 $results = I2CE_FormStorage::search('role', false, $where);
                 if (count($results) == 0) {
                     $this->setInvalidMessage('role', 'notallowed');
                 }
             }
         }
     }
 }
Пример #14
0
 /**
  * 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);
 }
 public function checkLimit_MAP_within($fieldObj, $vals)
 {
     if (!is_array($vals) || !array_key_exists('value', $vals)) {
         return null;
     }
     $vals['value'] = '' . $vals['value'];
     if (strlen($vals['value']) == 0) {
         return null;
     }
     $use_values = array();
     foreach (I2CE_List::findLowerMatches($vals['value'], $fieldObj->getDisplayedFields(), $fieldObj->getSelectableForms(), true) as $valid) {
         $use_values[] = "'" . $valid . "'";
     }
     return in_array($fieldObj->getDBValue(), $use_values);
 }
Пример #16
0
 protected function actionDisplayList_row($list, $listConfig)
 {
     $odd = false;
     if ($listConfig['type']) {
         $link = 'auto_list?type=' . $listConfig['type'];
     } else {
         $link = 'auto_list?form=' . $listConfig['form'];
     }
     $imported = $this->template->loadFile("lists_type_row.html", "tr", "lists_body");
     if (!$imported instanceof DOMNode) {
         I2CE::raiseError("Could not find lists_type_row.html");
         return false;
     }
     $remaped = $this->template->loadFile("lists_type_row_remapped.html", "tr", "lists_body");
     if (!$remaped instanceof DOMNode) {
         $remaped = $imported;
     }
     $append = $this->template->getElementById('lists_body');
     if (!$append instanceof DOMNode) {
         I2CE::raiseError("Don't know where to append list rows");
         return false;
     }
     foreach ($list as $data) {
         $id = substr($data['value'], strlen($listConfig['form']) + 1);
         if (in_array($id, $this->remap_ids) && ($remap = I2CE_FormStorage::lookupField($listConfig['form'], $id, 'remap', ''))) {
             $imported_row = $remaped->cloneNode(true);
             if ($listConfig['type']) {
                 $url = 'index.php/auto_list?type=' . $listConfig['type'];
             } else {
                 $url = 'index.php/auto_list?form=' . $listConfig['type'];
             }
             $url .= '&id=' . $listConfig['form'] . '|' . $id;
             $this->template->setDisplayDataImmediate('remapped_link', $url, $imported_row);
             list($rform, $rid) = array_pad(explode('|', $remap, 2), 2, '');
             $this->template->setDisplayDataImmediate('remapped_value', I2CE_List::lookup($rid, $rform), $imported_row);
         } else {
             $imported_row = $imported->cloneNode(true);
         }
         $this->template->appendNode($imported_row, $append);
         if ($odd) {
             $this->template->setNodeAttribute("class", "even", $imported_row);
         }
         $odd = !$odd;
         $this->template->setDisplayDataImmediate("lists_row_link", $link . '&id=' . $data['value'], $imported_row);
         $this->template->setDisplayDataImmediate("lists_row_name", $data['display'], $imported_row);
     }
     return true;
 }
 /**
  * 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 boolean $number_format If true, call number_format on the returned value.
  * @return mixed
  */
 public function getDisplayValue($entry = false, $number_format = false)
 {
     if ($entry instanceof I2CE_Entry) {
         $value = $entry->getValue();
     } else {
         $value = $this->getValue();
     }
     $curr_value = parent::getFromDB($value[0]);
     $curr_string = I2CE_List::lookup($curr_value[1], $curr_value[0]);
     $number_value = $value[1];
     if ($number_format) {
         $number_value = number_format($number_value);
     }
     return $curr_string . $number_value;
 }
 /**
  * Return the display value of this form field as a DOM Node.
  * @param DOMNode $node
  * @param I2CE_Template $template
  * @return DOMNode
  */
 public function getDisplayNode($node, $template)
 {
     $add_node = $template->createElement('span', array('class' => 'mult'));
     if ($href = $this->getHref()) {
         $link_node = $template->createElement("a", array("href" => $href));
         $add_node->append_child($link_node);
     } else {
         $link_node = $add_node;
     }
     $value = $this->getValue();
     $map_list = array();
     foreach ($value as $map_value) {
         $map_list[] = I2CE_List::lookup($map_value[1], $map_value[0]);
     }
     $first = true;
     foreach ($map_list as $text) {
         if ($first) {
             $first = false;
         } else {
             $link_node->appendChild($template->createElement("span", array('class' => 'mult_sep'), ','));
         }
         $link_node->appendChild($template->createElement("span", array('class' => 'mult_val'), $text));
     }
     return $add_node;
 }
 public function studentModules($node, $template)
 {
     //this really should be a fuzzy method in the training exam module
     if (!($tcField = $this->getField('training_course')) instanceof I2CE_FormField_MAP || !($tcObj = $tcField->getMappedFormObject()) instanceof iHRIS_Training_Course || !($modField = $tcObj->getField('training_course_mod')) instanceof I2CE_FormField_MAP_MULT) {
         I2CE::raiseError("Could not get training course modules");
         return false;
     }
     $allowed_ids = $modField->getValue();
     $allowed = array();
     foreach ($allowed_ids as $allowed_id) {
         list($form, $id) = $allowed_id;
         if ($form != 'training_course_mod') {
             continue;
         }
         $dv = I2CE_List::lookup($id, $form);
         if (!$dv) {
             contine;
         }
         $allowed[$form . '|' . $id] = $dv;
     }
     if (!is_array($allowed) || count($allowed) == 0) {
         if (!($main_node = $template->appendFileByNode('training_course_nomods.html', 'div', $node)) instanceof DOMNode) {
             return false;
         }
         return true;
     }
     if (!($main_node = $template->appendFileByNode('training_course_mod_base.html', 'div', $node)) instanceof DOMNode) {
         return false;
     }
     if (!($list_node = $template->getElementById('student_mods', $main_node)) instanceof DOMNode) {
         return false;
     }
     $template->addHeaderLink("editstudent.js");
     $width = (int) floor(100 / (count($allowed) + 1));
     $rowAttrs = array('style' => 'display:table-row;');
     $colAttrs = array('style' => 'display:table-cell;width:' . $width . '%');
     $chkAttrs = $colAttrs;
     $chkAttrs['type'] = 'checkbox';
     $list_node->appendChild($headNode = $template->createElement('div', $rowAttrs));
     $headNode->appendChild($template->createElement('div', $colAttrs, 'Student'));
     foreach ($allowed as $all_id => $all_val) {
         $headNode->appendChild($template->createElement('div', $colAttrs, $all_val));
     }
     $list = $this->getEnrolledStudents();
     $ff = I2CE_FormFactory::instance();
     foreach ($list as $id => $data) {
         if (!($pstcObj = $ff->createContainer($data['person_scheduled_training_course'])) instanceof iHRIS_Person_Scheduled_Training_Course || !($modField = $pstcObj->getField('training_course_mod')) instanceof I2CE_FormField_MAP_MULT) {
             I2CE::raiseError("No training course module");
             continue;
         }
         $pstcObj->populate();
         $list_node->appendChild($rowNode = $template->createElement('div', $rowAttrs));
         $sAttrs = $colAttrs;
         $sAttrs['href'] = 'view?id=' . $id;
         $colNode = $template->createElement('div', $colAttrs);
         $colNode->appendChild($template->createElement('a', $sAttrs, $data['firstname'] . ' ' . $data['surname']));
         $rowNode->appendChild($colNode);
         $selected = $modField->getValue();
         foreach ($selected as &$sel) {
             $sel = implode("|", $sel);
         }
         unset($set);
         foreach ($allowed as $all_id => $all_val) {
             $t_chkAttrs = $chkAttrs;
             if (in_array($all_id, $selected)) {
                 $t_chkAttrs['checked'] = 'checked';
             }
             $t_chkAttrs['onchange'] = 'toggleStudentModule(this,"' . addslashes($id) . '","' . addslashes($pstcObj->getNameID()) . '","' . addslashes($all_id) . '")';
             $colNode = $template->createElement('div', $colAttrs);
             $colNode->appendChild($template->createElement('input', $t_chkAttrs));
             $rowNode->appendChild($colNode);
         }
     }
     return true;
 }
Пример #20
0
 /**
  * Hooked Function to check if a field is unique
  * @param I2CE_FormField $field_obj
  */
 public function validate_formfield($field_obj)
 {
     if (!$field_obj->hasOption('unique') || !$field_obj->getOption('unique') || !$field_obj->isValid()) {
         return;
     }
     if (!$field_obj->hasOption('unique_field')) {
         return;
     }
     $unique = $field_obj->getOption('unique_field');
     if (strpos($unique, ':') === false) {
         //the value is not a mapped thing.  this is handled by hooked mehtod defined in I2CE_FormStorage
         return;
     }
     $form_obj = $field_obj->getContainer();
     if (!$form_obj instanceof I2CE_Form) {
         return;
     }
     $factory = I2CE_FormFactory::instance();
     //$unique should have the form 'unqique_field:form2(+field2):..:..:formM(+fieldM):...:formN
     //example $unique = 'region:country' or 'region+region+country:country' are the same.
     //    means that $field_obj needs to be unqiue when reseticted to the set of forms within a country and all of its regions
     //    the country and the region that is specified is the
     //    in this case, we need that region is a field of $form_obj
     //example: $unqiue = 'county:district+region:region:country' or 'county:district:region:country' are the same
     //    means that $field_obj needs to be unique when resitrcicted to a country, any of its regions any of those regions
     //    in this case, we need that county is a field of $form_obj
     //example: $unqiue = '[location]county:district+region:region:country' or 'county:district:region:country' are the same
     //    means that $field_obj needs to be unique when resitrcicted to a country, any of its regions any of those regions
     //    in this case, we need that location is a field of $form_obj
     $unique_fields = explode(',', $unique);
     $matches = null;
     $names = array();
     $main_where = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $field_obj->getName(), 'data' => array('value' => $field_obj->getDBValue()));
     foreach ($unique_fields as $unique_field) {
         if ($matches === false) {
             break;
         }
         if (strpos($unique_field, ':') === false) {
             //this field is not mapped... just handle it as a regular value.
             if (!($unique_field_obj = $form_obj->getField($unique_field)) instanceof I2CE_FormField) {
                 I2CE::raiseError("Invalid field {$unqiue_field}");
                 return;
             }
             if ($unique_field_obj->hasHeader('default')) {
                 $names[] = $unique_field_obj->getHeader('default');
             } else {
                 $names[] = $unique_field_obj->getName();
             }
             $where = array($main_where);
             if ($unique_field_obj->getDBValue()->isValid()) {
                 $where[] = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue()));
             } else {
                 $where[] = array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue())), 1 => array('operator' => 'FIELD_LIMIT', 'style' => 'null', 'field' => $unique_field_obj->getName())));
             }
             if (count($where) > 1) {
                 $where = array('operator' => 'AND', 'operand' => $where);
             }
             $found = I2CE_FormStorage::search($form_obj->getName(), false, $where);
             foreach ($found as &$f) {
                 $f = (string) $f;
             }
             $matches = count($found) > 0 && in_array((string) $form_obj->getId(), $found, true);
         } else {
             $field_path = explode(':', $unique_field);
             $restricted_field = false;
             if (preg_match('/^\\[(.*?)\\](.*)$/', $field_path[0])) {
                 $restricted_field = $matches[1];
                 $field_path[0] = $matches[2];
             } else {
                 if (preg_match('/^(.*?)\\+(.*)$/', $field_path[0], $matches)) {
                     $restricted_field = $matches[1];
                 } else {
                     $restricted_field = $field_path[0];
                 }
             }
             $restricted_field_obj = $form_obj->getField($restricted_field);
             if (!$restricted_field_obj instanceof I2CE_FormField_MAP) {
                 I2CE::raiseError("Invalid field passed as restricted field for " . $form_obj->getName() . ": {$unique_field}");
                 return;
             }
             if ($restricted_field_obj->hasHeader('default')) {
                 $names[] = $restricted_field_obj->getHeader('default');
             } else {
                 $names[] = $restricted_field_obj->getName();
             }
             //now let's split up field_path into the forms and the fields
             $top_formid = I2CE_List::walkupFieldPath($field_path, $restricted_field_obj->getDBValue());
             if ($top_formid === false) {
                 //the value is not set. or inappropriately set.  error silently.
                 //this is handled by hooked method defined in I2CE_Module_Form.
                 return;
             }
             //now we get all forms under $top_formid defined by the field path
             $field_name = $field_obj->getName();
             $field_val = $field_obj->getDBValue();
             $form_id = $form_obj->getID();
             $dtree_path = $field_path;
             array_unshift($dtree_path, $form_obj->getName());
             list($top_form, $top_id) = explode('|', $top_formid, 2);
             $dtree_limits = array($top_form => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => 'id', 'data' => array('value' => $top_id)), $form_obj->getName() => $main_where);
             $options = I2CE_List::buildDataTree($dtree_path, array($form_obj->getName()), $dtree_limits);
             $options = I2CE_List::flattenDataTree($options);
             if (count($options) == 1) {
                 // If there's only one match and it is this form then don't block
                 // changes.
                 if ($options[0]['value'] != $form_obj->getNameId()) {
                     $matches = true;
                 }
             } elseif (count($options) > 1) {
                 $matches = true;
             }
             /*
             array_pop($field_path);
             $options = I2CE_List::monsterMash(
                 $form_obj->getName(),  //facility
                 $restricted_field, //location
                 $top_formid, //country|10
                 $field_path, //array(county+district,district+region,region+country)            
                 $field_name, //name
                 false
                 );
             
             //starts get all facility where location = country|10  
             //    get all regions region|X where region+country = country|10
             //    this means we need to start with
             //           link_field = country (e.g link_field_path[$len-1] 
             //           list(sub_form,sub_link_field) = explode(+,end(subfields) ) == (region,country)
             //             
             //next get all facility where location = residence|X 
             $option_matches = false;
             foreach ($options as $id=>$data) {
                 if (array_key_exists($field_name,$data) && ($data[$field_name] == $field_val) && ( $id != $form_id)) {
                     $option_matches =true;
                     break;
                 }
             }
             $matches = ($option_matches);
             */
         }
     }
     if ($matches === true) {
         if (count($names) > 1) {
             $field_obj->setInvalidMessage('unique_fields', null, ' ' . implode(', ', $names));
         } else {
             if (count($names) == 1) {
                 $field_obj->setInvalidMessage('unique_field', null, ' ' . implode(', ', $names));
             } else {
                 $field_obj->setInvalidMessage('unique');
             }
         }
         return;
     }
 }
Пример #21
0
 /**
  * Creates a selectable auto-suggest tree view of the options
  * @param I2CE_Template $template
  * @param DOMNode $node -- the node that requested this drop down
  * @param int $show_hidden 0=non-hidden, 1=All, 2=hidden only.  Defaults to 0
  * @returns mixed DOMNode or an array of DOMNodes to add.
  */
 protected function create_DOMEditable_tree($node, $template, $form_node, $show_hidden = 0)
 {
     $ele_name = $this->getHTMLName();
     $ele_id = 'tree:' . $ele_name;
     $tree_options = array();
     if ($form_node->hasAttribute('treeOptions')) {
         $tree_options = $form_node->getAttribute('treeOptions');
         $form_node->removeAttribute('treeOptions');
     }
     $delayed = true;
     //default behavior is delayed load
     if ($form_node->hasAttribute('delayed')) {
         $delayed = $form_node->getAttribute('delayed');
         $form_node->removeAttribute('delayed');
     }
     $auto_complete_options = array();
     if ($form_node->hasAttribute('autoCompleteOptions')) {
         $auto_complete_options = $form_node->getAttribute('autoCompleteOptions');
         $form_node->removeAttribute('autoCompleteOptions');
     }
     $add_limits = $this->getAdditionalLimits($template, $node, $form_node->getAttribute('limit'));
     $display_style = 'default';
     if ($form_node->hasAttribute('display_style')) {
         $display_style = $form_node->getAttribute('display_style');
     }
     $data = $this->getMapOptions($display_style, $show_hidden, false, $add_limits);
     $main = $template->createElement('span');
     $node->appendChild($main);
     if ($this->isSetValue()) {
         $selected = array('value' => $this->getDBValue(), 'display' => I2CE_List::lookup($this->getMappedID(), $this->getMappedForm()));
     } else {
         $selected = array();
     }
     $template->addAutoCompleteInputTree($main, $ele_name, $ele_id, $selected, $data, $tree_options, $auto_complete_options, $delayed);
     $nodes = $template->query('./input[@id="' . $ele_id . '_inputtree_display"]', $main);
     if ($nodes->length > 0) {
         $this->setElement($nodes->item(0));
     }
 }
 /**
  * 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;
 }
 /**
  * Return the display value of this form field as a DOM Node.
  * @param DOMNode $node
  * @param I2CE_Template $template
  * @return DOMNode
  */
 public function getDisplayNode($node, $template)
 {
     $add_node = $template->createElement('span', array('class' => 'mult'));
     if ($href = $this->getHref()) {
         $link_node = $template->createElement("a", array("href" => $href));
         $add_node->append_child($link_node);
     } else {
         $link_node = $add_node;
     }
     $value = $this->getValue();
     $map_text = array();
     foreach ($value as $i => $map_value) {
         $map_text[$i] = I2CE_List::lookup($map_value[1], $map_value[0]);
     }
     $first = true;
     foreach ($map_text as $i => $text) {
         if ($first) {
             $first = false;
         } else {
             $link_node->appendChild($template->createElement("span", array('class' => 'mult_sep'), ','));
         }
         if ($node->hasAttribute('auto_link') && $node->getAttribute('auto_link')) {
             $attrs = array('class' => 'mult_val', 'href' => 'auto_list/view?form_name=' . $value[$i][0] . '&id=' . $value[$i][0] . '|' . $value[$i][1]);
             $link_node->appendChild($template->createElement("a", $attrs, $text));
         } else {
             $link_node->appendChild($template->createElement("span", array('class' => 'mult_val'), $text));
         }
     }
     return $add_node;
 }
 protected function getLinkedFormIds($formObj, &$child_forms)
 {
     if (!$formObj instanceof I2CE_Form) {
         return;
     }
     $formObj->populate();
     $child_forms['form'] = $formObj;
     $links = array();
     $fields = $formObj->getFieldNames();
     $child_forms['links_info'] = array();
     foreach ($fields as $field) {
         $fieldObj = $formObj->getField($field);
         if (!$fieldObj instanceof I2CE_FormField_MAPPED) {
             continue;
         }
         if (!$fieldObj->isValid() || !$fieldObj->isSetValue()) {
             continue;
         }
         if ($fieldObj instanceof I2CE_FormField_MAP) {
             $links[] = $fieldObj->getMappedForm() . '|' . $fieldObj->getMappedID();
             $child_forms['links_info'][$field] = array($fieldObj->getMappedForm() . '|' . $fieldObj->getMappedID());
         } else {
             if ($fieldObj instanceof I2CE_FormField_MAP_MULT) {
                 $child_forms['links_info'][$field] = array();
                 foreach (explode(',', $fieldObj->getDBValue()) as $val) {
                     if (!$val) {
                         continue;
                     }
                     $links[] = $val;
                     $child_forms['links_info'][$field][] = $val;
                 }
             } else {
                 continue;
             }
         }
     }
     if (count($links) > 0) {
         $child_forms['links'] = $links;
     }
     $links_from = array();
     $links_from_info = array();
     if ($formObj instanceof I2CE_List) {
         $data = I2CE_List::getFieldsMappingToList($formObj);
         foreach ($data as $link_form => $link_fields) {
             foreach ($link_fields as $link_field_name => $link_field_obj) {
                 if ($link_field_obj instanceof iHRIS_Currency) {
                     $where = array('operator' => 'FIELD_LIMIT', 'field' => $link_field_name, 'style' => 'like', 'data' => array('value' => $formObj->getFormID() . '=%'));
                 } else {
                     if ($link_field_obj instanceof I2CE_FormField_MAP) {
                         $where = array('operator' => 'FIELD_LIMIT', 'field' => $link_field_name, 'style' => 'equals', 'data' => array('value' => $formObj->getFormID()));
                     } else {
                         $where = array('operator' => 'OR', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => $link_field_name, 'style' => 'like', 'data' => array('value' => $formObj->getFormID() . ',%')), array('operator' => 'FIELD_LIMIT', 'field' => $link_field_name, 'style' => 'like', 'data' => array('value' => '%,' . $formObj->getFormID())), array('operator' => 'FIELD_LIMIT', 'field' => $link_field_name, 'style' => 'like', 'data' => array('value' => '%,' . $formObj->getFormID() . ',%')), array('operator' => 'FIELD_LIMIT', 'field' => $link_field_name, 'style' => 'equals', 'data' => array('value' => $formObj->getFormID()))));
                     }
                 }
                 $matches = I2CE_FormStorage::search($link_form, false, $where);
                 if ($matches) {
                     foreach ($matches as $match) {
                         $links_from[] = $link_form . '|' . $match;
                         if (!array_key_exists($link_form . '+' . $link_field_name, $links_from_info)) {
                             $links_from_info[$link_form . '+' . $link_field_name] = array();
                         }
                         $links_from_info[$link_form . '+' . $link_field_name][] = $link_form . '|' . $match;
                     }
                 }
             }
         }
     }
     if (count($links_from) > 0) {
         $child_forms['links_from'] = $links_from;
         $child_forms['links_from_info'] = $links_from_info;
     }
     if (($parentField = $formObj->getField('parent')) instanceof I2CE_FormField) {
         if ($parent = $parentField->getDBValue()) {
             $child_forms['parent'] = $parent;
         }
     }
     foreach ($formObj->getChildForms() as $child_form) {
         $formObj->populateChildren($child_form);
         $children = $formObj->getChildren($child_form);
         if (!is_array($children) || count($children) == 0) {
             continue;
         }
         foreach ($children as $childObj) {
             if (!$childObj instanceof I2CE_Form) {
                 I2CE::raiseError("Baddness getting {$child_form} of " . $formObj->getFormID() . "\n" . gettype($childObj));
                 continue;
             }
             if (!array_key_exists('children', $child_forms)) {
                 $child_forms['children'] = array();
             }
             $child_forms['children'][$childObj->getFormID()] = array();
             $this->getLinkedFormIds($childObj, $child_forms['children'][$childObj->getFormID()]);
         }
     }
     return;
 }
Пример #25
0
 protected function actionSelectMapped()
 {
     $this->template->addFile("lists_type_mapped.html");
     $this->addAlphabet();
     $add_node = $this->template->getElementById('mapped');
     if (!$add_node instanceof DOMNode) {
         I2CE::raiseError("Don't know where to add mapped field options");
     } else {
         $select_template = "lists_type_mapped_" . $this->type . "_" . $this->select_field->getName() . ".html";
         $select_template = $this->template->findTemplate($select_template, false);
         if (!$select_template) {
             $select_template = "lists_type_mapped_default.html";
         }
         $node = $this->template->appendFileById($select_template, "span", "mapped");
         $form_node = $this->template->getElementById('select_form_field_node');
         if ($form_node instanceof DOMElement) {
             $form_node->setAttribute('show_i2ce_hidden', $this->showHidden());
             $this->select_field->processDOMEditable($node, $this->template, $form_node);
             $add_node->appendChild($node);
         } else {
             I2CE::raiseError("could not find 'select_form_field_node' in " . $select_template);
         }
     }
     $this->template->appendFileById("lists_type_header.html", "th", "lists_header");
     $keys = explode('[', $this->select_field->getHTMLName());
     foreach ($keys as &$key) {
         if (strlen($key) > 0 && substr($key, -1) == ']') {
             $key = substr($key, 0, -1);
         }
     }
     unset($key);
     if (!$this->select_field->isSetValue() && !$this->request_exists($keys)) {
         return true;
         //don't show any options until a value has been selected
     }
     #select_field may be not set.  that's ok.  listOptions does error checking
     $list = I2CE_List::listOptions($this->type, $this->showHidden(), $this->select_field);
     if ($this->get_exists('letter')) {
         $list = array_filter($list, "self::filter_by_" . $this->get('letter'));
     }
     if ($this->request_exists('display') && $this->_hasMethod('actionDisplayList_' . $this->request('display'))) {
         $method = 'actionDisplayList_' . $this->request('display');
         return $this->{$method}($list);
     } else {
         if (count($list) > 0) {
             return $this->paginateList($list);
         } else {
             return true;
         }
     }
 }
Пример #26
0
 /**
  * Internal method to search all the ids for forms that are below
  * the given matched form id.
  * @param string $match The form id to match at the top.
  * @param array $fields The getDisplayedFields() for the field object.
  * @param array $forms The getSelectableFroms() for the field object.
  * @param array $displayed A list of forms that should be included in the results.
  * @param int $show_hidden 0=non-hidden, 1=All, 2=hidden only.
  * @return array
  */
 protected static function _searchLowerMatches($match_form, $match_ids, $fields, $forms, $displayed, $show_hidden)
 {
     $formfield = array_shift($fields);
     if (!is_array($formfield)) {
         return array();
     }
     list($form, $link_field) = $formfield;
     $limit = array('operator' => 'FIELD_LIMIT', 'field' => $link_field, 'style' => 'in', 'data' => array('value' => $match_ids));
     $limit = I2CE_DataTree::showHiddenLimit($limit, $show_hidden);
     $order = I2CE_List::getSortFields($form);
     $field_datas = I2CE_FormStorage::listFields($form, 'id', false, $limit, $order);
     $matched = array();
     foreach (array_keys($field_datas) as $matched_id) {
         $matched[] = $form . "|" . $matched_id;
     }
     if ($displayed[$form]) {
         return array_merge($matched, self::_searchLowerMatches($form, $matched, $fields, $forms, $displayed, $show_hidden));
     } else {
         return self::_searchLowerMatches($form, $matched, $fields, $forms, $displayed, $show_hidden);
     }
 }
 /**
  *  Construct a query (to be used as a sub-select) to view the fields of the given form.  It always will return the id of the form as well
  *  @param string $form
  *  @param mixed $fields.  Either a string, the field, or an array of string, the fields.
  *  @param mixed $id.  Defaults to null.  If non-null it is the id that we wish to limit to.
  *  @param boolean $parent. Defaults to false.  If true, we include the parent id as a referenced field
  *  If it is scalar and non-boolean, it is consider to be the ID of the parent, and then we get all forms with parent the given id.
  *  @param callback $field_refernece_callback.  A callback function whose first arguement is the form, the second arguements
  *  is the field and which returns the way the field value should be references as a field.  If the callback is null (the default) then
  *  the reference used is "$form+$field"
  *  @param integer $mod_time. Defaults to -1.  If non-negative, we only list the requested fields for an id if at least one of them has a modification
  *    time greater than or equal to $mod_time.  If the form storage has no way of tracking modifucation time, all entries are listed.
  * @param mixed $user The user id of the user to limit the results to so it only returns results limited to that user.  This can be a single value or an array
  *  @returns string the query or false on failed.
  */
 public function getRequiredFieldsQuery($form, $fields, $id = null, $parent = false, $field_reference_callback = null, $mod_time = -1, $user = false)
 {
     if ($fields === null) {
         $fields = array();
     }
     if (is_string($fields)) {
         $fields = array($fields);
     }
     if (!is_array($fields)) {
         I2CE::raiseError("Invalid fields");
         return false;
     }
     if (!($options = $this->getStorageOptions($form))) {
         I2CE::raiseError("No valid multi_flat storage options for {$form}");
         return false;
     }
     if (!is_array($this->databases) || count($this->databases) == 0) {
         I2CE::raiseError("No databases specified");
         return false;
     }
     $formObj = $this->getFormObj($form);
     if (!$formObj instanceof I2CE_Form) {
         I2CE::raiseError("Could not instantiate form {$form}");
         return false;
     }
     if (!in_array($form, $this->componentized_forms)) {
         I2CE::raiseError("Form {$form} is not specified as being componentized.  Valid componentized forms:" . print_r($this->componentized_forms, true));
         return false;
     }
     $table = '';
     $options->setIfIsSet($table, 'table');
     $table = trim($table);
     if (strlen($table) == 0) {
         if (array_key_exists('table_prefix', $this->global_options) && is_string($this->global_options['table_prefix']) && strlen(trim($this->global_options['table_prefix'])) > 0) {
             $table_prefix = trim($this->global_options['table_prefix']);
         } else {
             $table_prefix = 'hippo_';
         }
         $table = $table_prefix . $form;
     }
     if (strlen($table) == 0) {
         I2CE::raiseError("No table specified for {$form}");
         return false;
     }
     $id_ref = false;
     if ($field_reference_callback != null) {
         if (!is_string($id_ref = call_user_func($field_reference_callback, $form, 'id'))) {
             I2CE::raiseError("Invalid field reference callback function");
             return false;
         }
     } else {
         $id_ref = "`{$form}+id`";
     }
     $id_qry = 'id';
     if ($options->is_parent('id')) {
         $id_qry = $this->getFieldData($options->id);
     }
     $form_prepended = true;
     $options->setIfIsSet($form_prepended, "id/form_prepended");
     $unions = array();
     $p_componentized = false;
     if (is_scalar($id)) {
         if (($pos = strrpos($id, '@')) === false) {
             //get the last @ sign
             I2CE::raiseError("No component specified in id: {$id} for form {$form}");
             return false;
         }
         $component = substr($id, $pos + 1);
         $id_no_comp = substr($id, 0, $pos);
         if (strlen($component) == 0) {
             I2CE::raiseError("zero length component specified in id:{$id}");
             return false;
         }
         if (!array_key_exists($component, $this->databases)) {
             I2CE::raiseError("Component {$component} is not associated to a database in id {$id} for form {$form}");
             return false;
         }
         $databases = array($component => $this->databases[$component]);
         $componentParentForms = array_intersect(I2CE_Form::getAllowedParentForms($form), $this->componentized_forms);
     } else {
         if (!is_bool($parent) && is_scalar($parent)) {
             list($p_form, $p_id) = explode('|', $parent, 2);
             if (strlen($p_form) == 0) {
                 I2CE::raiseError("sNo parent form given in {$parent}");
                 return false;
             }
             if (strlen($p_id) == 0) {
                 I2CE::raiseError("No parent id given in {$parent}");
                 return false;
             }
             if (in_array($p_form, $this->componentized_forms)) {
                 $p_componentized = true;
                 if (($pos = strrpos($p_id, '@')) === false) {
                     //get the last @ sign
                     I2CE::raiseError("No component specified in parent id: {$parent}");
                     return false;
                 }
                 $component = substr($p_id, $pos + 1);
                 $p_id_no_comp = substr($p_id, 0, $pos);
                 if (strlen($component) == 0) {
                     I2CE::raiseError("zero length component specified in parent id:{$parent}");
                     return false;
                 }
                 if (!array_key_exists($component, $this->databases)) {
                     I2CE::raiseError("Component {$component} is not associated to a database in parent id: {$parent}");
                     return false;
                 }
                 $databases = array($component => $this->databases[$component]);
                 $componentParentForms = array($p_form);
             } else {
                 $componentParentForms = array_intersect(I2CE_Form::getAllowedParentForms($form), $this->componentized_forms);
             }
         } else {
             $databases = $this->databases;
             $componentParentForms = array_intersect(I2CE_Form::getAllowedParentForms($form), $this->componentized_forms);
         }
     }
     //now verify that the databases and associated table are indeed present:
     $db = MDB2::singleton();
     foreach ($databases as $component => $database) {
         $check_qry = "SELECT null FROM information_schema.TABLES WHERE TABLE_SCHEMA = '" . addslashes($database) . "'" . " AND TABLE_NAME = '" . addslashes($table) . "'";
         $result = $db->query($check_qry);
         if (I2CE::pearError($result, "Cannot execute  query:\n{$check_qry}")) {
             return false;
         }
         if ($result->numRows() > 0) {
             //the table exists.
             continue;
         }
         unset($databases[$component]);
     }
     if (count($databases) == 0) {
         I2CE::raiseError("No databases defined for multi-flat formstorage on table {$table}");
         return false;
     }
     foreach ($databases as $component => $database) {
         $select_list = array();
         if ($form_prepended) {
             $select_list[] = "CONCAT( SUBSTRING(" . $id_qry . "," . (strlen($form) + 2) . "),'@','" . mysql_real_escape_string($component) . "') AS {$id_ref}";
         } else {
             $select_list[] = "CONCAT( " . $id_qry . ",'@','" . mysql_real_escape_string($component) . "') AS {$id_ref}";
         }
         foreach ($formObj as $field => $fieldObj) {
             if (!in_array($field, $fields)) {
                 continue;
             }
             if (!$fieldObj->isInDB()) {
                 continue;
             }
             if ($options->is_parent("fields/{$field}")) {
                 $data = $options->traverse("fields/{$field}");
                 if ($data->is_scalar('enabled') && !$data->enabled) {
                     continue;
                 }
                 $f_qry = $this->getFieldData($data, $database, $table);
             } else {
                 if (!$this->hasColumn($field, $database, $table)) {
                     $f_qry = ' NULL ';
                 } else {
                     $f_qry = "`{$field}`";
                     //default to the field name
                 }
             }
             if ($fieldObj instanceof I2CE_FormField_MAPPED) {
                 $comp_map_forms = array_intersect($fieldObj->getSelectableForms(), $this->componentized_forms);
                 $f_qry = $fieldObj->getSQLComponentization($f_qry, $comp_map_forms, $component);
             }
             $f_ref = false;
             if ($field_reference_callback != null) {
                 if (!is_string($f_ref = call_user_func($field_reference_callback, $form, $field))) {
                     I2CE::raiseError("Invalid field reference callback function");
                     return false;
                 }
             } else {
                 $f_ref = "`{$form}+{$field}`";
             }
             $select_list[] = "{$f_qry} AS {$f_ref}";
         }
         $wheres = array();
         if (is_array($mod_time) && array_key_exists('mod_time', $mod_time)) {
             $mod_time = $mod_time['mod_time'];
         }
         $get_mod_time = is_scalar($mod_time) && $mod_time >= 0 || in_array('last_modified', $fields);
         if ($get_mod_time) {
             if ($options->is_scalar('last_modified/enabled') && !$options->last_modified->enabled) {
                 $mod_qry = "NULL";
             } else {
                 if ($options->is_scalar('last_modified/col') && $options->last_modified->col) {
                     if ($this->hasColumn($options->last_modified->col, $database, $table)) {
                         $mod_qry = $options->last_modified->col;
                     } else {
                         $mod_qry = 'NULL';
                     }
                 } else {
                     if ($options->is_scalar('last_modified/function') && $options->last_modified->function) {
                         $mod_qry = $options->last_modified->function;
                     } else {
                         if ($this->hasColumn('last_modified', $database, $table)) {
                             $mod_qry = " last_modified ";
                         } else {
                             //perhaps we are using a hippo_XXX table which does not have a last_modified column
                             $mod_qry = 'NULL';
                         }
                     }
                 }
             }
             if ($field_reference_callback !== null) {
                 if (!is_string($mod_ref = call_user_func($field_reference_callback, $form, 'last_modified'))) {
                     I2CE::raiseError("Invalid parent reference callback function:\nlast_modified --> {$mod_ref}");
                     return false;
                 }
             } else {
                 $mod_ref = '`' . $form . '+last_modified`';
             }
             $select_list[] = "{$mod_qry} AS {$mod_ref}";
             if (is_scalar($mod_time) && $mod_time >= 0) {
                 $wheres[] = "({$mod_qry} IS NULL OR {$mod_qry} > FROM_UNIXTIME(" . $mod_time . "))";
             }
         }
         if ($parent !== false || in_array($parent, $fields)) {
             $p_qry = false;
             $p_ref = false;
             if ($field_reference_callback != null) {
                 if (!is_string($p_ref = call_user_func($field_reference_callback, $form, 'parent'))) {
                     I2CE::raiseError("Invalid field reference callback function");
                     return false;
                 }
             } else {
                 $p_ref = "`{$form}+parent`";
             }
             if (!$options->is_scalar('parent/enabled') || $options->parent->enabled) {
                 if ($options->is_parent('parent')) {
                     $p_qry = $this->getFieldData($options->parent);
                 }
                 if ($p_qry === false) {
                     $p_qry = 'parent';
                 }
             } else {
                 $p_qry = '0';
             }
             $select_list[] = I2CE_List::componentizeQuery($p_qry, $componentParentForms, $component) . " AS {$p_ref}";
             if (!is_bool($parent) && is_scalar($parent)) {
                 if (!$p_componentized) {
                     $wheres[] = " ( " . I2CE_List::componentizeQuery($p_qry, $componentParentForms, $component) . " = '" . mysql_real_escape_string($parent) . "' ) ";
                 } else {
                     $wheres[] = " ( {$p_qry} = '" . mysql_real_escape_string($p_form . '|' . $p_id_no_comp) . "') ";
                 }
             }
         }
         //want either select id as `form+id`, name as `form+name` from table
         //or select id as `form+id`, name as `form+name` from (select * from table where id=5)
         //select  substr(my_id,1,4) as `form+id`, surname as `form+name` from (select * from table where id=5)
         //or with a function..
         //select id as `form+id`, substr(surname,1,3) as `form+name` from table
         //select  id as `form+id`, substr(surname,1,3) as `form+name` from (select * from table where id=5)
         //select  substr(my_id,1,4) as `form+id`, surname as `form+name` from table wher `form+id`
         $qry = 'SELECT ' . implode(',', $select_list) . " FROM `{$database}`.`{$table}`";
         if (is_scalar($id)) {
             if ($form_prepended) {
                 $wheres[] = " ({$id_qry} ='" . mysql_real_escape_string($form . '|' . $id_no_comp) . "') ";
             } else {
                 $wheres[] = " ({$id_qry} ='" . mysql_real_escape_string($id_no_comp) . "') ";
             }
         }
         if (count($wheres) > 0) {
             $qry .= ' WHERE (' . implode("AND", $wheres) . ")";
         }
         $unions[] = $qry;
     }
     if (count($databases) > 1) {
         foreach ($unions as &$union) {
             $union = '(' . $union . ')';
         }
         //I2CE::raiseError("QRY:" . implode('UNION' ,$unions));
         return implode('UNION', $unions);
     } else {
         reset($unions);
         //I2CE::raiseError("QRY:" . current($unions));
         return current($unions);
     }
 }
 /**
  * 
  */
 public function addAllowedConfirmations($node, $template, $person)
 {
     if (!$node instanceof DOMElement || !($parent = $node->parentNode) instanceof DOMElement || !$template instanceof I2CE_Template) {
         return;
     }
     $allowedConfirmations = $this->getAllowedConfirmations($person, true);
     //get the new confirmations
     if (count($allowedConfirmations) == 0) {
         return;
     }
     $imported = $template->loadFile("add_confirmation.html", "span");
     if (!$imported instanceof DOMNode) {
         I2CE::raiseError("Could not find add_conirmation.html");
         return;
     }
     if (!($conf = I2CE_FormFactory::instance()->createForm('confirmation')) instanceof iHRIS_Confirmation) {
         return;
     }
     if (!($type = $conf->getField('confirmation_type')) instanceof I2CE_FormField) {
         continue;
     }
     $typeName = $type->getHTMLName();
     foreach ($allowedConfirmations as $id => $vals) {
         if (!($disp = I2CE_List::lookup($id, 'confirmation_type'))) {
             continue;
         }
         $imported_node = $imported->cloneNode(true);
         if (!($linkNode = $template->getElementById('confirmation_link', $imported_node)) instanceof DOMElement) {
             continue;
         }
         $parent->insertBefore($imported_node, $node);
         $linkNode->setAttribute('href', "confirmation?" . $typeName . "=" . urlencode("confirmation_type|" . $id) . '&parent=');
         $template->setDisplayDataImmediate('confirmation_name', $disp, $imported_node);
     }
     $parent->removeChild($node);
 }
 protected function find_matching($form_obj)
 {
     $wheres = array();
     foreach ($form_obj as $field_name => $field_obj) {
         if (!$field_obj instanceof I2CE_FormField || !$field_obj->hasOption('unique') || !$field_obj->getOption('unique')) {
             continue;
         }
         if (!$field_obj->hasOption('unique_field')) {
             if ($field_obj->isValid()) {
                 $wheres[] = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $field_obj->getName(), 'data' => array('value' => $field_obj->getDBValue()));
             }
         } else {
             $unique = $field_obj->getOption('unique_field');
             $unique_fields = explode(',', $unique);
             foreach ($unique_fields as $unique_field) {
                 //we need to say that this is unique only up to the other values
                 if (strpos($unique_field, ':') !== false) {
                     $main_where = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $field_obj->getName(), 'data' => array('value' => $field_obj->getDBValue()));
                     $field_path = explode(':', $unique_field);
                     $restricted_field = false;
                     if (preg_match('/^\\[(.*?)\\](.*)$/', $field_path[0])) {
                         $restricted_field = $matches[1];
                         $field_path[0] = $matches[2];
                     } else {
                         if (preg_match('/^(.*?)\\+(.*)$/', $field_path[0], $matches)) {
                             $restricted_field = $matches[1];
                         } else {
                             $restricted_field = $field_path[0];
                         }
                     }
                     $restricted_field_obj = $form_obj->getField($restricted_field);
                     if (!$restricted_field_obj instanceof I2CE_FormField_MAP) {
                         $this->raiseError("Invalid field passed as restricted field for " . $form_obj->getName() . ": {$unique_field}");
                         return;
                     }
                     if ($restricted_field_obj->hasHeader('default')) {
                         $names[] = $restricted_field_obj->getHeader('default');
                     } else {
                         $names[] = $restricted_field_obj->getName();
                     }
                     //now let's split up field_path into the forms and the fields
                     $top_formid = I2CE_List::walkupFieldPath($field_path, $restricted_field_obj->getDBValue());
                     if ($top_formid === false) {
                         //the value is not set. or inappropriately set.  error silently.
                         //this is handled by hooked method defined in I2CE_Module_Form.
                         return;
                     }
                     //now we get all forms under $top_formid defined by the field path
                     $field_name = $field_obj->getName();
                     $field_val = $field_obj->getDBValue();
                     $form_id = $form_obj->getID();
                     $dtree_path = $field_path;
                     array_unshift($dtree_path, $form_obj->getName());
                     list($top_form, $top_id) = explode('|', $top_formid, 2);
                     $dtree_limits = array($top_form => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => 'id', 'data' => array('value' => $top_id)), $form_obj->getName() => $main_where);
                     $options = I2CE_List::buildDataTree($dtree_path, array($form_obj->getName()), $dtree_limits);
                     $options = I2CE_List::flattenDataTree($options);
                     if (count($options) == 1) {
                         // There is exactly one match.  we should use it
                         $matched_id = $options[0]['value'];
                         return $this->factory->createContainer($matched_id);
                     }
                 } else {
                     if (!($unique_field_obj = $form_obj->getField($unique_field)) instanceof I2CE_FormField) {
                         $this->raiseError("Invalid field {$unqiue_field}");
                         return;
                     }
                     if ($unique_field_obj->isValid()) {
                         $wheres[] = array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue()));
                     } else {
                         $wheres[] = array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'style' => 'equals', 'field' => $unique_field_obj->getName(), 'data' => array('value' => $unique_field_obj->getDBValue())), 1 => array('operator' => 'FIELD_LIMIT', 'style' => 'null', 'field' => $unique_field_obj->getName())));
                     }
                 }
             }
         }
     }
     if (count($wheres) == 0) {
         //no matching conditions. don't try to do anything
         return false;
     } else {
         if (count($wheres) > 1) {
             $where = array('operator' => 'AND', 'operand' => $wheres);
         } else {
             $where = current($wheres);
         }
     }
     if (!($id = I2CE_FormStorage::search($form_obj->getName(), false, $where, array(), true))) {
         return false;
     }
     $form_obj = $this->factory->createContainer(array($form_obj->getName(), $id));
     //$form_obj->populate();
     return $form_obj;
 }
Пример #30
0
 protected function showMapped()
 {
     $factory = I2CE_FormFactory::instance();
     $maps = array();
     if ($this->request_exists('mapped')) {
         $maps = explode(',', $this->request('mapped'));
     }
     $formConfig = I2CE::getConfig()->traverse("/modules/forms/forms");
     foreach ($maps as $mapped) {
         $template_file = $this->getChildHTMLTemplate($mapped);
         $template_file = $this->template->findTemplate($template_file, false);
         if (!$template_file) {
             continue;
         }
         $appendNode = $this->template->getElementById($mapped);
         if (!$appendNode instanceof DOMElement) {
             continue;
         }
         if (strpos($mapped, '+') !== false) {
             list($mapped, $mapped_field) = explode('+', $mapped, 2);
         } else {
             $mapped_field = $this->list->getName();
         }
         $orders = I2CE_List::getSortFields($mapped);
         $where = array('operator' => 'FIELD_LIMIT', 'field' => $mapped_field, 'style' => 'equals', 'data' => array('value' => $this->list->getNameId()));
         $map_ids = I2CE_FormStorage::search($mapped, false, $where, $orders);
         foreach ($map_ids as $map_id) {
             $mapObj = $factory->createContainer($mapped . '|' . $map_id);
             if (!$mapObj instanceof I2CE_Form) {
                 continue;
             }
             $mapObj->populate();
             $node = $this->template->appendFileByNode($template_file, "div", $appendNode);
             if (!$node instanceof DOMNode) {
                 I2CE::raiseError("Could not import {$template_file} div");
                 continue;
             }
             $this->setForm($mapObj, $node);
         }
     }
     $this->template->addHeaderLink('view.js');
     return true;
 }