/**
  * Find a file (or directory) of a certain category
  * @param string $category  the category of the file
  * @param string $file_name the file name of the file we wish to find
  * @param boolean $find_all Defatults to false
  * @returns mixed.  Returns either a string which is the path and file name of the file 
  * we found, or null if we did not find the file.
  */
 public function search($category, $file_name, $find_all = false)
 {
     if (!array_key_exists($category, $this->ordered_paths)) {
         $factory = I2CE_ModuleFactory::instance();
         $factory->loadPaths(null, $category, false, $this);
     }
     if ($find_all || $this->stale_time < 0) {
         return parent::search($category, $file_name, $find_all);
     }
     if (array_key_exists($category, $this->preferred_locales) && is_array($this->preferred_locales[$category])) {
         $locales = $this->preferred_locales[$category];
     } else {
         $locales = I2CE_Locales::getPreferredLocales();
     }
     if (array_key_exists('I2CE_FileSearch_Caching', $_SESSION) && is_array($_SESSION['I2CE_FileSearch_Caching']) && array_key_exists($category, $_SESSION['I2CE_FileSearch_Caching']) && is_array($_SESSION['I2CE_FileSearch_Caching'][$category]) && array_key_exists($file_name, $_SESSION['I2CE_FileSearch_Caching'][$category]) && is_array($_SESSION['I2CE_FileSearch_Caching'][$category][$file_name])) {
         $data = $_SESSION['I2CE_FileSearch_Caching'][$category][$file_name];
         if (array_key_exists('time', $data) && array_key_exists('location', $data) && array_key_exists('locale', $data)) {
             if (is_readable($data['location']) && time() - $data['time'] < $this->stale_time) {
                 $this->found_locales = $data['locale'];
                 return $data['location'];
             } else {
                 unset($_SESSION['I2CE_FileSearch_Caching'][$category][$file_name]);
             }
         }
     }
     //did not find the file
     $location = parent::search($category, $file_name, false);
     if (!is_string($location) || strlen($location) == 0) {
         return null;
     }
     $_SESSION['I2CE_FileSearch_Caching'][$category][$file_name] = array('time' => time(), 'location' => $location, 'locale' => $this->found_locales);
     return $location;
 }
 /**
  * Return the instance of this factory and create it if it doesn't exist.
  * @return I2CE_ModuleFactory
  */
 public static function instance()
 {
     if (!self::$instance instanceof I2CE_ModuleFactory) {
         self::$instance = new I2CE_ModuleFactory();
     }
     return self::$instance;
 }
 /**
  * Validate this form.
  */
 public function validate()
 {
     if (I2CE_Validate::checkNumber($this->count, 1)) {
         if (!$this->code_start || !I2CE_Validate::checkNumber($this->code_start, 0)) {
             $this->setInvalidMessage('code_start', 'required');
         }
         if ($this->code_format != "") {
             if (preg_match('/%[\\d\\.]*d/', $this->code_format) == 0) {
                 $this->code_format .= "%d";
             }
             $storage = I2CE_ModuleFactory::instance()->getClass("forms-storage");
             if ($storage instanceof I2CE_FormStorage) {
                 $count = $this->count;
                 $code_start = $this->code_start;
                 while ($count--) {
                     $this->code = sprintf($this->code_format, $code_start);
                     $storage->validate_formfield($this->getField("code"));
                     if ($this->getField("code")->hasInvalid()) {
                         $this->setInvalidMessage("code_format", 'unique');
                     }
                     $code_start++;
                 }
             }
         }
     }
     parent::validate();
 }
 /**
  * Create a new instance of a I2CE_FormField
  * @param string $name
  * @param array $options A list of options for this form field.
  */
 public function __construct($name, $options)
 {
     parent::__construct($name, $options);
     $this->use_date_picker = I2CE_ModuleFactory::instance()->isEnabled('DatePicker');
     $this->start_year = 0;
     $this->end_year = 0;
 }
 public function loadRelationship()
 {
     $rel_base = '/modules/CustomReports/relationships';
     if (!array_key_exists('relationship', $this->args) || !is_scalar($this->args['relationship'])) {
         I2CE::raiseError("Invalid relationship");
         return false;
     }
     if (array_key_exists('relationship_base', $this->args) && is_scalar($this->args['relationship_base'])) {
         $rel_base = $this->args['relationship_base'];
     }
     $use_cache = true;
     if (array_key_exists('use_cache', $this->args)) {
         $use_cache = $this->args['use_cache'];
     }
     if ($this->request_exists('use_cache')) {
         $use_cache = $this->request('use_cache');
     }
     $use_cache &= I2CE_ModuleFactory::instance()->isEnabled('CachedForms');
     if ($use_cache) {
         $cache_callback = array('I2CE_CachedForm', 'getCachedTableName');
     } else {
         $cache_callback = null;
     }
     try {
         $this->formRelationship = new I2CE_FormRelationship($this->args['relationship'], $rel_base, $cache_callback);
     } catch (Exception $e) {
         I2CE::raiseError("Could not create form relationship : " . $this->args['relationship']);
         return false;
     }
     if (!array_key_exists('use_display_fields', $this->args) || !$this->args['use_display_fields']) {
         $this->formRelationship->useRawFields();
     }
     return true;
 }
 /**
  * Create a new instance of a page.
  * 
  * The default constructor should be called by any pages extending this object.  It creates the
  * {@link I2CE_Template} and {@link I2CE_User} objects and sets up the basic member variables.
  * @param array $args
  * @param array $request_remainder The remainder of the request path
  */
 public function __construct($args, $request_remainder, $get = null, $post = null)
 {
     parent::__construct($args, $request_remainder, $get, $post);
     $this->form_factory = I2CE_FormFactory::instance();
     $this->check_map = I2CE_ModuleFactory::instance()->isEnabled("Lists");
     $this->locale = I2CE_Locales::DEFAULT_LOCALE;
 }
 /**
  * Run the upgrade for this module.  
  * @param string $old_vers
  * @param string $new_vers
  * @return boolean
  */
 public function upgrade($old_vers, $new_vers)
 {
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.5')) {
         I2CE::raiseError("Disabling training module.");
         I2CE_ModuleFactory::instance()->disable(array("manage-training-simple-competency", "manage-training-institution", "manage-training-course", "training-simple-competency", "training-institution", "training-course"));
     }
     return parent::upgrade($old_vers, $new_vers);
 }
Exemple #8
0
 public function __construct()
 {
     parent::__construct();
     $this->js = '';
     if (I2CE_ModuleFactory::instance()->isEnabled('StretchPage')) {
         $this->js .= 'if ( PageStretch ) { PageStretch.stretchPage(); }';
     }
     $this->js_func = '';
 }
 /**
  * Constructor -- called from page wrangler for URL of form admin/(module_name)/action/arg1/arg2
  * @param string $shortname A module name to show the admin page for. Defaults to null to mean no module.
  * @param string $action The action this pages is to perform
  * @param array $args an array of strings
  * @param string $message. A message to display on the page.  Defaults to null
  */
 public function __construct($args, $request_remainder)
 {
     parent::__construct($args, $request_remainder);
     if (count($request_remainder) == 0) {
         $this->shortname = 'I2CE';
     } else {
         $this->shortname = array_shift($request_remainder);
     }
     $this->mod_factory = I2CE_ModuleFactory::instance();
 }
 public static function userRequestSave($form, $user, $transact = true)
 {
     if (!$form instanceof I2CE_User_Request) {
         return false;
     }
     $mf = I2CE_ModuleFactory::instance();
     $fs = $mf->getClass("forms-storage");
     if (!$fs instanceof I2CE_FormStorage) {
         return false;
     }
     return $fs->save($form, $user, $transact);
 }
 /**
  * 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!");
     }
 }
 /** 
  * Method called before the module is enabled for the first time.
  * @param boolean -- returns true on success. false on error.
  */
 public function action_initialize()
 {
     /*
      * This module was split off from Custom Reports.
      * If Custom Reports has been used previously then we should assume the methods
      * are defined there so they need to be turned off until CustomReports can be
      * upgraded when it is required.
      */
     $cr_vers = null;
     I2CE::getConfig()->setIfIsSet($cr_vers, "/config/data/CustomReports/version");
     if ($cr_vers !== null && I2CE_Validate::checkVersion($cr_vers, '<', '3.2')) {
         I2CE::raiseError("Removing hooks from CustomReports because they were moved to form-limits.");
         I2CE_ModuleFactory::instance()->removeHooks("CustomReports");
     }
     return true;
 }
 /**
  * Perform the migrate actions for this module.
  * @return boolean
  */
 protected function migrate()
 {
     $user = new I2CE_User(1, false, false, false);
     $class_config = I2CE::getConfig()->modules->forms->formClasses;
     $migrate_path = "/I2CE/formsData/migrate_data/4.1.8";
     if (!I2CE_FormStorage::migrateForm("training_classification", "entry", $user, $migrate_path)) {
         return false;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled("CachedForms")) {
         $cachedForm = new I2CE_CachedForm("training_classification");
         $cachedForm->dropTable();
     }
     if (!I2CE_FormStorage::migrateField("training", array("training_classification" => "training_classification"), $migrate_path, $user)) {
         return false;
     }
     return true;
 }
 /**
  * Perform extra validation for the person form.
  * A new person record needs to verify there aren't any existing 
  * records with the same name.
  * @param I2CE_Form $form
  */
 public function validate_form_person($form)
 {
     $search = array();
     $surname_ignore = false;
     if (isset($form->surname_ignore)) {
         $surname_ignore = $form->surname_ignore;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage') && $form->getId() == '0' && !$surname_ignore && I2CE_Validate::checkString($form->surname) && I2CE_Validate::checkString($form->firstname)) {
         $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'surname', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->surname))), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'firstname', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->firstname)))));
         $results = I2CE_FormStorage::listFields('person', array('surname', 'firstname'), false, $where, array('surname', 'firstname'));
         if (count($results) > 0) {
             foreach ($results as $id => &$data) {
                 $data = implode(', ', $data);
             }
             $form->setInvalidMessage('surname', 'unique', array("view?id=" => $results));
         }
     }
 }
 /**
  * Mark this position as closed and remove it from any applications.
  * 
  * The person being assigned the position will have all application positions removed.
  * @param I2CE_User &$user The user performing this action.
  * @param integer $person_id The person being assigned this position.
  */
 public function closePosition(&$user, $person_id)
 {
     $factory = I2CE_FormFactory::instance();
     $this->setStatus("position_status|closed");
     $this->save($user);
     $mod_factory = I2CE_ModuleFactory::instance();
     if ($mod_factory->isEnabled('ihris-manage-Application')) {
         $apps = iHRIS_Applicant::findApplications($this->id);
         if (count($apps) > 0) {
             foreach ($apps as $app_id => $data) {
                 $app = $factory->createContainer("application|" . $app_id);
                 $app->populate();
                 $app->removePosition($this->getNameId());
                 $app->save($user);
             }
         }
     }
 }
 /**
  * Perform any actions for the page
  * 
  * @return boolean.  true on success
  */
 public function action()
 {
     parent::action();
     $this->template->setAttribute("class", "active", "menuSearch", "a[@href='search']");
     $this->template->appendFileById("menu_recent.html", "ul", "menuSearch");
     $this->template->setAttribute("class", "active", "menuSearch", "ul/li/a[@name='menu_recent']");
     if (I2CE_ModuleFactory::instance()->isEnabled('ihris-common-Search')) {
         $report_config = I2CE::getConfig()->traverse("/modules/CustomReports", true);
         foreach ($report_config->search_reports as $report => $report_info) {
             $node = $this->template->appendFileById("menu_search_report.html", "li", "menu_search_reports");
             $this->template->setDisplayDataImmediate("menu_search_link", array("href" => "search/" . $report, "no_results" => 1), $node);
             $this->template->setDisplayDataImmediate("menu_search_name", $report_info->name, $node);
         }
     }
     if (count($this->request_remainder) > 0) {
         return $this->actionRecent();
     } else {
         return $this->actionMenu();
     }
 }
 protected function displayModules($contentNode)
 {
     if (!$contentNode instanceof DOMNode) {
         I2CE::raiseError("Nowhere to display content");
         return false;
     }
     $mod_factory = I2CE_ModuleFactory::instance();
     $modules = $mod_factory->getAvailable();
     foreach ($modules as $module) {
         if (!$mod_factory->isInitialized($module)) {
             continue;
         }
         if (!$mod_factory->hasConfigData($module)) {
             continue;
         }
         $contentNode->appendChild($this->template->createElement('a', array('href' => $this->module() . '/edit/' . $module), 'Edit ' . $module));
         $contentNode->appendChild($this->template->createElement('a', array('href' => $this->module() . '/view/' . $module), 'view ' . $module));
         $contentNode->appendChild($this->template->createElement('br'));
     }
     return true;
 }
 /**
  * Perform extra validation for the trainingprovider form.
  * A new trainingprovider record needs to verify there aren't any existing 
  * records with the same name.
  * @param I2CE_Form $form
  */
 public function validate_form_trainingprovider($form)
 {
     $search = array();
     $name_ignore = false;
     if (isset($form->name_ignore)) {
         $name_ignore = $form->name_ignore;
     }
     if (I2CE_ModuleFactory::instance()->isEnabled('forms-storage') && $form->getId() == 0 && !$name_ignore && I2CE_Validate::checkString($form->name)) {
         $where = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'name', 'style' => 'lowerequals', 'data' => array('value' => strtolower($form->name)))));
         $results = I2CE_FormStorage::listFields('trainingprovider', array('name'), false, $where, array('name'));
         if (count($results) > 0) {
             foreach ($results as $id => &$data) {
                 $data = implode(', ', $data);
             }
             $form->getField('name')->setInvalid("Duplicate records match this record's name:", array("viewprovider?id=" => $results));
         }
     }
     $value = $form->getField('email')->getValue();
     if (I2CE_Validate::checkString($value) && !I2CE_Validate::checkEmail($value)) {
         $form->getField('email')->setInvalid('invalid_email');
     }
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode($this->getTemplate(), 'div', $content_node)) instanceof DOMNode) {
         I2CE::raiseError("Could not load " . $this->getTemplate());
         return false;
     }
     $inputs = array();
     $modules = I2CE_ModuleFactory::instance()->getAvailable();
     if (($listNode = $this->template->getElementByName('module_list', 0, $mainNode)) instanceof DOMNode) {
         foreach ($modules as $module) {
             $val = '';
             $this->storage->setIfIsSet($val, $module);
             $input = 'modules[' . $module . ']';
             $attr = array('value' => $val, 'name' => $input);
             $listNode->appendChild($modNode = $this->template->createElement('span', array('style' => 'display:inline-block;width:33%; min-width:33%')));
             $modNode->appendChild($this->template->createElement('h3', array(), $module));
             $modNode->appendChild($this->template->createElement('input', $attr));
             $inputs[] = $input;
         }
     }
     $this->renameInputs($inputs, $mainNode);
     return true;
 }
 public function getAverageScore()
 {
     if (!I2CE_ModuleFactory::instance()->isEnabled('training-exam')) {
         //the training exam module was not enabled... so let's not calculate anything
         return 0;
     }
     //we want to get all child  training_course_exam and calculate an average from them
     $count = 0;
     $score = 0;
     $this->populateChildren('training_course_exam');
     foreach ($this->getChildren('training_course_exam') as $examObj) {
         if (!$examObj instanceof iHRIS_Training_Course_Exam || !($scoreObj = $examObj->getField('score')) instanceof I2CE_FormField_INT) {
             continue;
         }
         $count++;
         $score += $scoreObj->getDBValue();
     }
     if ($count > 0) {
         return (int) ($score / $count);
     } else {
         return 0;
     }
 }
 /**
  * Create a data tree of the selectable forms.  Deisgned to be fed into tree select
  * @param array $fields an ordered array E.g array('village+county','county','district,'region+country','country').
  * it is an "bottom up" array of string where strings are of the form "$form" or "$form+$link_field".  In the case of
  * the former type, then $link_field is assumed to be the next form.  So for example, "county" has link field "district".
  * If a "$form(+$link_field)" is surrounded by brackets [ ] , it is not displayed.
  * @param array $forms An unorderd array of form names whose values we allow to be selected
  * @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 array $report A report name to use for the query instead of building it from form cache or directly.
  * @return array
  */
 public static function buildDataTree($fields, $forms, $limits, $orders = array(), $show_hidden = 0, $report = null, $style = 'default')
 {
     //$forms = array(village, county) -- order does not matter.
     //$fields -- order matters.
     //Example0:
     //$fields == array('village','county','[district+cssc_region],'cssc_region+cssc_country','country')
     //Example1:
     //$fields == array('village+county','county','district,'region+country','country')  -- you could just as easily have used 'region'
     //Example2:
     //$fields == array('village','county');
     //build the tree top down.  top  = country in Example 0,1 and top = county in Example 2
     if (!is_array($forms) || !is_array($fields) || count($fields) == 0) {
         return array();
     }
     $data = array();
     $displayed = array();
     $last_form = false;
     $fields = array_reverse($fields);
     foreach ($fields as &$field) {
         //start0: $form = country $link_field = false   $last_form = false
         //next0: $form = cssc_region $link_field = country $last_form = country
         //start1: $form = country $link_field = false   $last_form = false
         //next0: $form = region $link_field = country $last_form = country
         //start2: $form = county $link_field = false   $last_form = false
         //next2: $form = village $link_field = county  $last_form = county
         if (!is_string($field)) {
             return array();
         }
         $len = strlen($field);
         if ($len >= 2 && $field[0] == '[' && $field[$len - 1] == ']') {
             $field = substr($field, 1, $len - 2);
             $display = false;
         } else {
             $display = true;
         }
         if (($pos = strpos($field, '+')) !== false) {
             list($form, $link_field) = explode('+', $field, 2);
             if ($last_form == false) {
                 //throw away junk linked field data on the top level form
                 $link_field = false;
             }
         } else {
             $form = $field;
             $link_field = false;
         }
         if (!$form) {
             return array();
         }
         if (!$link_field) {
             $link_field = $last_form;
         }
         $field = array($form, $link_field);
         $displayed[$form] = $display;
         $last_form = $form;
     }
     unset($field);
     $styles = array();
     $ff = I2CE_FormFactory::instance();
     if ($last_form) {
         $avail_styles = array($last_form => $style);
         $curr_style = $style;
         foreach (array_reverse($fields) as $formfield) {
             list($form, $link_field) = $formfield;
             if (!$form || !($formObj = $ff->createContainer($form)) instanceof I2CE_Form) {
                 break;
             }
             if (array_key_exists($form, $avail_styles) && is_string($avail_styles[$form])) {
                 $curr_style = $avail_styles[$form];
             } else {
                 $curr_style = 'default';
             }
             $styles["{$form}+{$link_field}"] = $curr_style;
             if (!$link_field || !($fieldObj = $formObj->getField($link_field)) instanceof I2CE_FormField) {
                 break;
             }
             $avail_styles = I2CE_List::getDisplayFieldStyles($form, $style);
         }
     }
     if (is_array($report)) {
         $results = self::buildReportTree($fields, $forms, $displayed, $limits, $orders, $show_hidden, $report);
         if (count($results) > 0) {
             return $results;
         } else {
             I2CE::raiseError("buildReportTree returned no results so defaulting to regular display.  If there is data then something went wrong so it should be fixed.");
         }
     }
     $use_cache = true;
     if (I2CE_ModuleFactory::instance()->isEnabled("CachedForms")) {
         $fs = I2CE_FormStorage::getMechanismByStorage("cached");
         if ($fs instanceof I2CE_FormStorage_cached) {
             try {
                 return $fs->buildDataTree($fields, $forms, $displayed, $limits, $orders, $show_hidden, $style);
             } catch (Exception $e) {
                 $use_cache = false;
                 I2CE::raiseError("Could not cache {$form}");
             }
         }
     }
     $phonebook = array();
     //indexed by "$form|$id" with values (by reference) the arrays at which contains the 'children' sub-array  for $form|$id node
     $parent_links = array();
     //indexed by "$form|$id" with values "$pform|$pid" which is the form/id that "$form|$id" is linked against
     $display_string = array();
     foreach ($fields as $formfield) {
         list($form, $link_field) = $formfield;
         if (array_key_exists("{$form}+{$link_field}", $limits)) {
             $limit = $limits["{$form}+{$link_field}"];
         } elseif (array_key_exists($form, $limits)) {
             $limit = $limits[$form];
         } else {
             $limit = array();
         }
         if (!($formObj = $ff->createContainer($form)) instanceof I2CE_Form) {
             continue;
         }
         $style = 'default';
         if (array_key_exists("{$form}+{$link_field}", $styles)) {
             $style = $styles["{$form}+{$link_field}"];
         }
         //if we dont show the hidden list memmber we need to include the limit where i2ce_disabled is false
         $limit = self::showHiddenLimit($limit, $show_hidden);
         $disp_fields = I2CE_List::getDisplayFields($form, $style);
         $disp_str = I2CE_List::getDisplayString($form, $style);
         //start0:  $form = country, $fields = (name)
         //next0:  $form = cssc_region, $fields = (name, cssc_country)
         //next0:  $form =  district $fields = (name, cssc_region)
         //next0: $form = county $field = (name,distrcit)
         //end0: $form = villate $field = (name,county)
         //start1:  $form = country, $fields = (name)
         //next1:  $form = region, $fields = (name, country)
         //next1:  $form =  district $fields = (name, region)
         //etc.
         if (array_key_exists($form, $orders)) {
             $order = $orders[$form];
         } else {
             $order = I2CE_List::getSortFields($form, $style);
         }
         ksort($order);
         if ($link_field) {
             $field_datas = I2CE_FormStorage::listFields($form, $link_field, false, $limit, $order, false, -1, $use_cache);
         } else {
             $field_datas = I2CE_FormStorage::listFields($form, 'id', false, $limit, $order, false, -1, $use_cache);
         }
         $display_datas = I2CE_FormStorage::listFields($form, $disp_fields, false, $limit, $order, false, -1, $use_cache);
         $link_id = false;
         $last_link = false;
         $selectable = in_array($form, $forms);
         foreach ($field_datas as $id => $field_data) {
             $formid = $form . '|' . $id;
             if (!$link_field) {
                 //this should only be the case for the top form
                 $parent =& $data;
             } else {
                 //we are not at the top.
                 $link = $field_data[$link_field];
                 unset($field_data[$link_field]);
                 if ($last_link != $link) {
                     if (!array_key_exists($link, $phonebook)) {
                         //don't know where to put this as a child of the previous one so skip it
                         continue;
                     }
                     $last_link = $link;
                     if (!array_key_exists('children', $phonebook[$link])) {
                         $phonebook[$link]['children'] = array();
                     }
                     $parent =& $phonebook[$link]['children'];
                     //example: $diplayed == array(country=>true, region=>false,  district=>true, county=>true village => true)
                     //we have $form = district, $formid = district|30, $parent_link= region|40
                     end($displayed);
                     $disp_form = key($displayed);
                     while ($disp_form !== false && $disp_form !== $form) {
                         prev($displayed);
                         $disp_form = key($displayed);
                     }
                     //we end here either before the beginning of the array or where $disp_form == $form.
                     prev($displayed);
                     //we are now at the one before the $form.  if the current form was district, we are now at region
                     $parent_link = $link;
                 } else {
                     if (!array_key_exists($link, $phonebook) || !$phonebook[$link]) {
                         //don't know where to put this as a child of the previous one so skip it
                         continue;
                     }
                 }
                 $parent_links[$formid] = $link;
             }
             if (!array_key_exists($id, $display_datas)) {
                 continue;
             }
             $disp_array = array();
             foreach ($disp_fields as $field) {
                 if (array_key_exists($field, $display_datas[$id]) && ($fieldObj = $formObj->getField($field)) instanceof I2CE_FormField) {
                     $fieldObj->setFromDB($display_datas[$id][$field]);
                     $disp_array[] = $fieldObj->getDisplayValue(false, $style);
                 } else {
                     $disp_array[] = '';
                 }
             }
             $display = vsprintf($disp_str, $disp_array);
             $child_data = array('display' => $display, 'show' => $displayed[$form]);
             if ($selectable) {
                 $child_data['value'] = $formid;
             }
             $parent[] = $child_data;
             end($parent);
             $phonebook[$formid] =& $parent[key($parent)];
         }
     }
     self::removeNotShownNodes($data);
     return $data;
 }
Exemple #23
0
 protected function addAjaxOptionMenu($input_id, $replace_container_id, $contentNode)
 {
     $mod_factory = I2CE_ModuleFactory::instance();
     $optionsMenu = $this->template->getElementById($input_id . '_options_menu', $contentNode);
     if (!$optionsMenu instanceof DOMNode) {
         I2CE::raiseError("Could not get the option menu for {$input_id}");
         return false;
     }
     $this->renameInputs('*', $optionsMenu);
     $addButton = $this->template->getElementById($input_id, $contentNode);
     $link = $this->getURLRoot('update') . $this->path . $this->factory->getURLQueryString(array(), array('openedLinks'));
     if ($replace_container_id !== false) {
         if ($mod_factory->isEnabled('stub') && $this->template->hasAjax()) {
             if ($addButton instanceof DOMElement) {
                 if (strpos($link, '?') !== false) {
                     $link .= '&';
                 } else {
                     $link .= '?';
                 }
                 $link .= 'noRedirect=1';
                 $link = 'stub/id?request=' . urlencode($link) . '&content=' . urlencode($replace_container_id . ':' . $this->path) . '&keep_javascripts=' . $this->getAjaxJSNodes();
                 if (!$this->page->rewrittenURLS()) {
                     $link = 'index.php/' . $link;
                 }
                 $addButton->setAttribute('ajaxTargetID', $replace_container_id . ':' . $this->path);
                 $addButton->setAttribute('action', $link);
                 $optionsMenu->appendChild($this->template->createElement('input', array('type' => 'hidden', 'name' => 'swiss_path', 'value' => $this->path)));
             }
         }
         $this->template->reIDNodes($replace_container_id, $replace_container_id . ':' . $this->path, $contentNode);
     }
     $pf_input_id = $this->prefixName($input_id);
     $this->template->reIDNodes($input_id, $pf_input_id, $contentNode);
     $this->template->reIDNodes($input_id . '_options_menu', $pf_input_id . '_options_menu', $contentNode);
     $this->changeClassOnNodes($input_id . '_options_hide', $pf_input_id . '_options_hide', $contentNode);
     $this->changeClassOnNodes($input_id . '_options_show', $pf_input_id . '_options_show', $contentNode);
     $this->changeClassOnNodes($input_id . '_options_toggle', $pf_input_id . '_options_toggle', $contentNode);
     return true;
 }
 /**
  * Perform the main actions of the page.
  * @return boolean
  */
 protected function action()
 {
     if (!parent::action()) {
         return false;
     }
     if (!$this->hasPermission("role(admin)")) {
         $this->userMessage("You do not have permission to view this page.");
         return false;
     }
     $pos_mech = I2CE_FormStorage::getStorageMechanism("position");
     $pers_pos_mech = I2CE_FormStorage::getStorageMechanism("person_position");
     if (!$pos_mech instanceof I2CE_FormStorage_entry || !$pers_pos_mech instanceof I2CE_FormStorage_entry) {
         I2CE::raiseMessage("Invalid storage type for position and person position forms. " . get_class($pos_mech) . get_class($pers_pos_mech));
         $this->template->addFile("mass_delete_by_search_error_invalid.html");
         return true;
     }
     $people = $this->post('people');
     if (!is_array($people) || count($people) < 1) {
         $this->template->addFile("mass_delete_by_search_empty.html");
     } else {
         $step = 'choose';
         if ($this->post_exists('step')) {
             $step = $this->post('step');
         }
         if ($step == "delete") {
             if ($this->post('yes') != 'yes') {
                 $this->template->appendFileById("mass_delete_by_search_error_yes.html", "p", "error");
                 $step = "confirm";
             }
             $userAccess = new I2CE_UserAccess_Mechanism();
             if (!$this->post_exists('admin_pass') || !$userAccess->userHasPassword('i2ce_admin', $this->post('admin_pass'))) {
                 $this->template->appendFileById("mass_delete_by_search_error_password.html", "p", "error");
                 $step = "confirm";
             }
         }
         switch ($step) {
             case "choose":
                 $this->template->addFile("mass_delete_by_search_form.html");
                 $msgNode = $this->template->addFile("mass_delete_by_search_confirm_message.html");
                 foreach ($people as $person) {
                     $persObj = I2CE_FormFactory::instance()->createContainer($person);
                     $persObj->populate();
                     $persNode = $this->template->appendFileById("mass_delete_by_search_each.html", "li", "search_list");
                     $this->template->setDisplayDataImmediate("people[]", array('value' => $person, 'id' => "check_{$person}"), $persNode);
                     $this->template->setDisplayDataImmediate("person_name", $persObj->surname . ', ' . $persObj->firstname, $persNode);
                     $label = $this->template->query("label[@name='search_label']", $persNode);
                     if ($label->length == 1) {
                         $label->item(0)->setAttribute("for", "check_{$person}");
                     }
                 }
                 break;
             case "confirm":
                 $list = $this->getDeleteList($people);
                 if ($list === null) {
                     $this->template->addFile("mass_delete_by_search_error_notfound.html");
                 } elseif (count($list) < 1) {
                     I2CE::raiseMessage("Invalid return data from getDeleteList!");
                     $this->template->addFile("mass_delete_by_search_error_unkonwn.html");
                 } else {
                     $formNode = $this->template->addFile("mass_delete_by_search_form.html");
                     $this->template->setDisplayDataImmediate("step", "delete");
                     $addNode = $this->template->addFile("mass_delete_by_search_authenticate_form.html");
                     $would_delete = I2CE_FormStorage_entry::massDelete($list, array());
                     $msgNode = $this->template->addFile("mass_delete_by_search_delete_count.html");
                     $this->template->setDisplayDataImmediate("delete_count", $would_delete, $msgNode);
                     foreach ($people as $person) {
                         $persObj = I2CE_FormFactory::instance()->createContainer($person);
                         $persObj->populate();
                         $persNode = $this->template->appendFileById("mass_delete_by_search_each_final.html", "li", "search_list");
                         $this->template->setDisplayDataImmediate("people[]", $person, $persNode);
                         $this->template->setDisplayDataImmediate("person_name", $persObj->surname . ', ' . $persObj->firstname, $persNode);
                     }
                 }
                 break;
             case "delete":
                 $list = $this->getDeleteList($people);
                 if ($list === null) {
                     $this->template->addFile("mass_delete_by_search_error_notfound.html");
                 } elseif (count($list) < 1) {
                     I2CE::raiseMessage("Invalid return data from getDeleteList!");
                     $this->template->addFile("mass_delete_by_search_error_unkonwn.html");
                 } else {
                     $formNode = $this->template->addFile("mass_delete_by_search_form.html");
                     $this->template->setDisplayDataImmediate("step", "delete");
                     $addNode = $this->template->addFile("mass_delete_by_search_authenticate_form.html");
                     I2CE_ModuleFactory::callHooks("pre_mass_delete_person", $people, $this->post());
                     if (($deleted = I2CE_FormStorage_entry::massDelete($list, array(), false)) !== false) {
                         $node = $this->template->addFile("mass_delete_by_search_success.html");
                         $this->template->setDisplayDataImmediate("delete_count", $deleted, $node);
                         if (I2CE_ModuleFactory::instance()->isEnabled("CachedForms")) {
                             $forms = I2CE_FormFactory::instance()->getNames();
                             $success = array();
                             $failure = array();
                             foreach ($forms as $form) {
                                 try {
                                     $cachedForm = new I2CE_CachedForm($form);
                                 } catch (Exception $e) {
                                     $success[] = $form;
                                     continue;
                                 }
                                 if (!$cachedForm->dropTable()) {
                                     $failure[] = $form;
                                 }
                             }
                             if (count($failure) > 0) {
                                 $this->template->addFile("mass_delete_by_search_cache_fail.html", "p");
                             } else {
                                 $this->template->addFile("mass_delete_by_search_cache_success.html", "p");
                             }
                         }
                     } else {
                         I2CE::raiseError("An error occurred trying to mass delete by search.");
                         $this->template->addFile("mass_delete_by_search_error_unkonwn.html");
                     }
                 }
                 break;
         }
     }
 }
 /**
  * Gets the required fields.
  * @param string $form The form we are select from
  * @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 mixed $where_data array or class implementing ArrayAccess, Iterator, and Countable (e.g. MagicDataNode) . the where data.  
  * @param array $ordering. An array of fields to order by.  Defaults to the empty array.  Prepend a - to order by in descending order.
  * @param mixed $limit. Defaults to false.  It true, returns only one result.  If an integer it is the numeber of records to limit to.
  *  If it is as an array of two integers, it is the offset and then number of results to limit to.  
  * @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"
  * @returns array with keys id's and values the I2CE_Form instance.
  */
 public function getFormsById($form, $parent, $where_data = array(), $ordering = array(), $limit = false)
 {
     $vals = array();
     $ids = $this->getRecords($form);
     $factory = I2CE_FormFactory::instance();
     $form_obj = $factory->createContainer($form);
     if (!$form_obj instanceof I2CE_Form) {
         return array();
     }
     if ((is_array($where_data) || $where_data instanceof ArrayAccess && $where_data instanceof Countable && $where_data instanceof Iterator) && count($where_data) > 0) {
         if (!I2CE_ModuleFactory::instance()->isEnabled('form-limits')) {
             I2CE::raiseError("form-limits module is not enabled");
             return array();
         }
         $check_limit = true;
     } else {
         $check_limit = false;
     }
     $limit_offset = 0;
     $limit_amount = false;
     if ($limit !== false) {
         if (is_array($limit) && count($limit) == 2) {
             list($limit_offset, $limit_amount) = $limit;
         } else {
             if (is_scalar($limit)) {
                 $limit_amount = $limit;
             }
         }
     }
     foreach ($ids as $id) {
         $child_form = $factory->createContainer($form . '|' . $id);
         if (!$child_form instanceof I2CE_Form) {
             continue;
         }
         $child_form->populate();
         if (!is_bool($parent)) {
             if ($child_form->getParent() != $parent) {
                 $child_form->cleanup();
                 continue;
             }
         }
         if ($check_limit && !$child_form->checkWhereClause($where_data)) {
             $child_form->cleanup();
             continue;
         }
         $vals[$id] = $child_form;
     }
     if (is_array($ordering) && count($ordering) > 0) {
         $this->ordering = $ordering;
         uasort($vals, array($this, 'compareFormsByFields'));
     }
     if (is_numeric($limit_amount)) {
         return array_slice($vals, $limit_offset, $limit_amount, true);
     } else {
         return $vals;
     }
 }
 protected function setHeaderVars($segment)
 {
     $rel_base = '/modules/CustomReports/relationships';
     if (array_key_exists('relationship_base', $this->args) && is_scalar($this->args['relationship_base'])) {
         $rel_base = $this->args['relationship_base'];
     }
     $use_cache = I2CE_ModuleFactory::instance()->isEnabled('CachedForms');
     if (array_key_exists('use_cache', $this->args)) {
         $use_cache = $this->args['use_cache'];
     }
     if ($use_cache) {
         $cache_callback = array('I2CE_CachedForm', 'getCachedTableName');
     } else {
         $cache_callback = null;
     }
     try {
         if (!array_key_exists('header_relationship', $this->args) || !is_string($this->args['header_relationship']) || strlen($this->args['header_relationship']) == 0 || !($formRelationship = new I2CE_FormRelationship($this->args['header_relationship'], $rel_base, $cache_callback)) instanceof I2CE_FormRelationship || $formRelationship->getPrimaryForm() != $this->primObj->getName()) {
             return;
         }
         $fields = $this->getFields();
         $data = $formRelationship->getFormData($this->primObj->getName(), $this->primObj->getId(), $fields, array(), true);
         $row = 0;
         foreach ($data as $formfields) {
             if (!$this->setData($segment, $row, $formfields, $formRelationship)) {
                 I2CE::raiseError("Error setting data for row: {$row}");
                 return false;
             }
             break;
             //only do one row
         }
     } catch (Exception $e) {
     }
 }
 /**
  * The business method if this page is called from the commmand line
  * @param array $request_remainder the remainder of the request after the page specfication.  
  * @param array $args the array of unix style command line arguments 
  */
 protected function actionCommandLine($args, $request_remainder)
 {
     $config = I2CE::getConfig();
     if (!$config->is_parent("/config/data")) {
         I2CE::raiseError("No Modules", E_USER_ERROR);
     }
     $modConfig = $config->config->data;
     if ($this->request('only_enabled')) {
         $modules = I2CE_ModuleFactory::instance()->getEnabled();
     } else {
         $modules = $modConfig->getKeys();
     }
     sort($modules);
     switch ($this->page) {
         case 'wiki':
             echo $this->wiki($modules);
             break;
         case 'dot':
             echo $this->dot($modules);
             break;
         case 'text':
         default:
             echo $this->text($modules);
             break;
     }
 }
 public function enrolledStudentsListCompact($node, $template)
 {
     if (!($main_node = $template->appendFileByNode('training_course_exam_base_compact.html', 'div', $node)) instanceof DOMNode) {
         return false;
     }
     if (!($list_node = $template->getElementById('student_exams', $main_node)) instanceof DOMNode) {
         return false;
     }
     $node->appendChild($list_node);
     $list = $this->getEnrolledStudents();
     $template->addHeaderLink("mootools-core.js");
     $template->addHeaderLink("mootools-more.js");
     $template->addHeaderLink("editstudent.js");
     $has_exam = I2CE_ModuleFactory::instance()->isEnabled('training-exam');
     if (!$has_exam) {
         return;
     }
     $where_exam = array('operator' => 'OR', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'no'), array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'null')));
     $exams = I2CE_FormStorage::listDisplayFields('training_course_exam_type', array('name'), false, $where_exam, array('name'));
     $passing_score = '';
     $passing_scores = I2CE_FormStorage::lookupField('training_course', $this->getField('training_course')->getMappedID(), array('passing_score'), false);
     if (count($passing_scores) == 1) {
         $passing_score = current($passing_scores);
         if (!is_numeric($passing_score) || $passing_score < 0 || $passing_score > 100) {
             $passing_score = '';
         }
     }
     $stc_dup_where = array('operator' => 'FIELD_LIMIT', 'field' => 'training_course', 'style' => 'equals', 'data' => array('value' => $this->getField('training_course')->getDBValue()));
     $dup_where = array();
     //this will be a search on person_scheduled_training_course
     foreach (I2CE_FormStorage::search('scheduled_training_course', false, $stc_dup_where) as $stc) {
         if ($stc == $this->getID()) {
             //don't include this course when looking for duplicate scheuling.
             continue;
         }
         $dup_where[] = array('operator' => 'AND', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'scheduled_training_course', 'style' => 'equals', 'data' => array('value' => 'scheduled_training_course|' . $stc)), 1 => array('operator' => 'OR', 'operand' => array(0 => array('operator' => 'FIELD_LIMIT', 'field' => 'attending', 'style' => 'equals', 'data' => array('value' => 1)), 1 => array('operator' => 'FIELD_LIMIT', 'field' => 'attending', 'style' => 'null', 'data' => array())))));
     }
     foreach ($exams as $i => $data) {
         if (!is_array($data) || !array_key_exists('name', $data) || !$data['name']) {
             unset($exams[$i]);
             continue;
         }
     }
     $num_exams = count($exams);
     if ($num_exams > 0) {
         $style = "display:table-cell;width:" . 66 / $num_exams . '%';
     } else {
         $style = "display:table-cell";
     }
     if (($header_node = $template->getElementByID("header_row")) instanceof DOMNode) {
         foreach ($exams as $id => $data) {
             $exam_title_node = $template->createElement("div", array('style' => $style), $data['name']);
             $template->appendNode($exam_title_node, $header_node);
         }
     }
     foreach ($list as $id => $sdata) {
         $studentNode = $template->appendFileByNode('enrolled_students_compact.html', 'div', $list_node);
         if (!$studentNode instanceof DOMNode) {
             return false;
         }
         $studId = 'student_' . $id;
         $studentNode->setAttribute('id', $studId);
         $template->setDisplayDataImmediate('id', 'id=' . $id, $studentNode);
         $template->setDisplayDataImmediate('firstname', $sdata['firstname'], $studentNode);
         $template->setDisplayDataImmediate('surname', $sdata['surname'], $studentNode);
         $scores = I2CE_FormStorage::listFields('training_course_exam', array('score', 'training_course_exam_type'), $sdata['person_scheduled_training_course']);
         foreach ($exams as $examid => $data) {
             $examsNode = $template->createElement("div", array('style' => $style));
             $template->appendNode($examsNode, $studentNode);
             $template->setDisplayData('passing_score', $passing_score, $examsNode);
             $score = false;
             $exam_id = '0';
             foreach ($scores as $sid => $data) {
                 if (!is_array($data) || !array_key_existS('score', $data) || !array_key_exists('training_course_exam_type', $data) || $data['training_course_exam_type'] != "training_course_exam_type|" . $examid) {
                     continue;
                 }
                 $score = $data['score'];
                 break;
             }
             $template->appendFileByNode('student_exam.html', 'div', $examsNode);
             $finalNode = $template->getElementByName('final_exam', 0, $examsNode);
             if (!$finalNode) {
                 continue;
             }
             $template->setDisplayDataImmediate('final_exam', $score, $finalNode);
             if ($passing_score) {
                 if ($score >= $passing_score) {
                     $finalNode->setAttribute('style', 'color:green');
                 } else {
                     $finalNode->setAttribute('style', 'color:red');
                 }
             }
             if (!$passing_score) {
                 $passing_score = 0;
             }
             $js = "changeFinalExamGrade(this,'" . addslashes($examid) . "','" . addslashes($sdata['person_scheduled_training_course']) . "','" . addslashes($exam_id) . "'," . $passing_score . ");";
             $finalNode->setAttribute('onchange', $js);
         }
         $clear_node = $template->createElement("hr", array("style" => "clear: both; max-height:0px; padding:0px; margin:0px;"));
         $template->appendNode($clear_node, $list_node);
     }
 }
 /**
  * Generates a SQL to select the required fields.
  * @param string $form The form we are select from
  * @param array $fields of string.  the fields that we want to select.  the keys are the fields names, the values are what we wish to select them as.
  * Can include the special field 'last_modified' to get the last modification time for any of the fields of that form which is returned in the format  "Y-m-d H:i:s"
  * @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 mixed $expr array or class implementing ArrayAccess, Iterator, and Countable (e.g. MagicDataNode) . the where data.  
  * @param array $ordering. An array of fields to order by.  Defaults to the empty array.  Prepend a - to order by in descending order.
  * @param mixed $limit. Defaults to false.  It true, returns only one result.  If an integer it is the numeber of records to limit to.
  *  If it is as an array of two integers, it is the offset and then number of results to limit to.  
  * @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 $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 SQL Query needed to get the form/field data or false on failure.
  */
 public function getFields($form, $fields = array(), $parent, $where_data = array(), $ordering = array(), $limit = false, $field_reference_callback = null, $mod_time = -1, $user = false)
 {
     if (!is_array($fields) || count($fields) == 0) {
         I2CE::raiseError("No fields given");
         return false;
     }
     $ref_fields = array();
     if (!is_array($ordering)) {
         $ordering = array();
         //just to be sage
     }
     foreach ($fields as $field => $desired_ref) {
         if ($field_reference_callback !== null) {
             if (!is_string($ref = call_user_func($field_reference_callback, $form, $field)) === false) {
                 I2CE::raiseError("Invalid field reference callback function");
                 return false;
             }
         } else {
             $ref = '`' . $form . '+' . $field . '`';
         }
         $ref_fields[] = "{$ref} AS `{$desired_ref}`";
     }
     $field_select = "SELECT SQL_CALC_FOUND_ROWS " . implode(",", $ref_fields);
     foreach ($ordering as $i => &$ord) {
         if (!is_string($ord)) {
             unset($ordering[$i]);
             continue;
         }
         $field = $ord;
         if ($ord[0] == '-') {
             $field = substr($ord, 1);
             $ord = "`{$form}+" . $field . '` DESC';
         } else {
             $ord = "`{$form}+{$field}`  ASC";
         }
         if (!in_array($field, $fields)) {
             $fields[] = $field;
         }
     }
     if ((is_array($where_data) || $where_data instanceof ArrayAccess && $where_data instanceof Countable && $where_data instanceof Iterator) && count($where_data) > 0) {
         if (!I2CE_ModuleFactory::instance()->isEnabled('form-limits')) {
             I2CE::raiseError("module form-limits is not available");
             return false;
         }
         $formObj = I2CE_FormFactory::instance()->createContainer($form);
         if (!$formObj instanceof I2CE_Form) {
             I2CE::raiseError("Could not instantiate {$form}");
             return false;
         }
         $where_qry = $formObj->generateWhereClause($where_data);
         $fields = array_unique(array_merge($fields, $this->getLimitedFields($where_data)));
     } else {
         $where_qry = '';
     }
     $sub_qry = $this->getRequiredFieldsQuery($form, $fields, null, $parent, $field_reference_callback, $mod_time, $user);
     if (!is_string($sub_qry) || strlen($sub_qry) == 0) {
         //this means no valid fields.  just die here.
         //I2CE::raiseError("Cannot get the fields " . implode(',',$fields) . " from $form ");
         return false;
     }
     if (!is_string($where_qry)) {
         I2CE::raiseError("Invalid where clause for {$form} ");
         return false;
     }
     $where_qry = trim($where_qry);
     if (strlen($where_qry) > 0) {
         $where_qry = ' WHERE (' . $where_qry . ')';
     }
     $post_qry = '';
     if (count($ordering) > 0) {
         $post_qry .= ' ORDER BY ' . implode(',', $ordering);
     }
     if ($limit === true) {
         $post_qry .= ' LIMIT 1';
     } else {
         if (is_int($limit) || is_string($limit) && ctype_digit($limit)) {
             $post_qry .= ' LIMIT ' . $limit;
         } else {
             if (is_array($limit) && count($limit) == 2) {
                 $post_qry .= ' LIMIT ' . implode(' , ', $limit);
             }
         }
     }
     return "{$field_select} FROM (" . $sub_qry . ") AS `{$form}` " . $where_qry . $post_qry;
 }
 public function displayValues($contentNode, $transient_options, $action)
 {
     $this->template->addHeaderLink('swiss_default.css');
     $showExpert = $this->factory->getStoredOptions('expert');
     $node = $this->template->appendFileByNode("configuration_main.html", 'div', $contentNode);
     $displayName = $this->storage->getAttribute('displayName');
     if (!$displayName) {
         //the display name has not been set.  set it to the name of this configuration(Group) node
         $displayName = self::humanText($this->storage->getName());
     }
     $this->template->setDisplayDataImmediate('displayName', $this->getDisplayName(), $node);
     $this->template->setDisplayDataImmediate('description', $this->getDescription(), $node);
     $configurationListNode = $this->template->getElementById('configuration_options', $node);
     if (!$configurationListNode instanceof DOMNode) {
         I2CE::raiseError("No place to add scalars");
         return false;
     }
     $configurationGroupListNode = $this->template->getElementById('configurationGroup_options', $node);
     if (!$configurationGroupListNode instanceof DOMNode) {
         I2CE::raiseError("No place to add parents");
         return false;
     }
     if ($this->path == '/') {
         $path = '';
     } else {
         $path = $this->path;
     }
     $added = false;
     $children = $this->getChildNames();
     if (!array_key_exists('leaf_as_link', $transient_options)) {
         $mod_factory = I2CE_ModuleFactory::instance();
         $transient_options['leaf_as_link'] = $mod_factory->isEnabled('stub') && $this->template->hasAjax();
     }
     foreach ($children as $child) {
         $swissChild = $this->factory->getSwiss($this->path, $child);
         if (!$swissChild instanceof I2CE_Swiss) {
             continue;
         }
         $childStorage = $swissChild->getStorage();
         if ($childStorage->is_indeterminate()) {
             continue;
         }
         if ($swissChild->getStatus('visible') === false) {
             continue;
         }
         if (!$showExpert && $swissChild->getStatus('advanced') !== false) {
             continue;
         }
         if ($swissChild instanceof I2CE_Swiss_Default_Leaf && !(array_key_exists('leaf_as_link', $transient_options) && $transient_options['leaf_as_link'])) {
             if (!$swissChild->displayValue($configurationListNode, $transient_options, $action)) {
                 continue;
             }
             $added = true;
         } else {
             $gNode = $this->template->appendFileByNode("configurationGroup_default.html", "li", $configurationGroupListNode);
             if (!$gNode instanceof DOMNode) {
                 I2CE::raiseError("Cannot append configurationGroup_default.html");
                 continue;
             }
             $swissChild->addAjaxLink('configurationGroup_link', 'configuration_main_contents', 'configurationGroup_link_ajax', $gNode, $action);
             $added = true;
         }
     }
     if (!$added && $node instanceof DOMNode) {
         $this->template->removeNode($node);
     }
     return true;
 }