/**
  * Add any necessary defaults to the given map details.
  * This is currently just a default view and any layers
  * defined in the _order, but not in the layers data.
  * @param array &$maps The maps data
  */
 public function addMapDefaults(&$maps)
 {
     $config = I2CE::getConfig()->modules->OpenLayers;
     if ($config->is_parent('default')) {
         $defaults = array('_height', '_width');
         foreach ($defaults as $default) {
             if (!array_key_exists($default, $maps) && $config->default->is_scalar($default)) {
                 $maps[$default] = $config->default->{$default};
             }
         }
         foreach ($maps as $map_name => &$map) {
             if ($map_name[0] == '_') {
                 continue;
             }
             if ($config->is_parent("default/layers")) {
                 if (array_key_exists('layers', $map) && is_array($map['layers']) && array_key_exists('_order', $map['layers']) && is_array($map['layers']['_order'])) {
                     foreach ($map['layers']['_order'] as $layer => $order) {
                         if (!array_key_exists($layer, $map['layers']) && $config->is_parent("default/layers/{$layer}")) {
                             $map['layers'][$layer] = $config->default->layers->{$layer}->getAsArray();
                         }
                     }
                 }
             }
             if ($config->is_parent("default/view")) {
                 if (array_key_exists('view', $map)) {
                     $map['view'] = array_merge($config->default->view->getAsArray(), $map['view']);
                 } else {
                     $map['view'] = $config->default->view->getAsArray();
                 }
             }
         }
     }
 }
 /**
  * Upgrade this module if necessary
  * @param string $old_vers
  * @param string $new_vers
  * @return boolean
  */
 public function upgrade($old_vers, $new_vers)
 {
     /*
      * In 3.2.3 we moved some lists from entry to magicdata storage so we need to get the
      * old data from entry and save them to the new form storage.
      */
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.3')) {
         $user = new I2CE_User(1, false, false, false);
         $class_config = I2CE::getConfig()->modules->forms->formClasses;
         $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
         if (!I2CE_FormStorage::migrateForm("facility_type", "entry", $user, $migrate_path, false, array("type"))) {
             return false;
         }
         if (I2CE_FormStorage::migrateForm("facility", "entry", $user, $migrate_path, false, array("type"), array("facility_type" => "facility_type", "location" => array("county" => "county", "district" => "district", "country" => "country")))) {
             unset($class_config->iHRIS_Facility->fields->country);
             unset($class_config->iHRIS_Facility->fields->district);
             unset($class_config->iHRIS_Facility->fields->county);
             unset($class_config->iHRIS_Facility->fields->type);
         } else {
             return false;
         }
     } elseif (I2CE_Validate::checkVersion($old_vers, '<', '3.2.4')) {
         $user = new I2CE_User(1, false, false, false);
         $class_config = I2CE::getConfig()->modules->forms->formClasses;
         $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
         if (!I2CE_FormStorage::migrateForm("facility", "entry", $user, $migrate_path, false, array("type"))) {
             return false;
         }
         unset($class_config->iHRIS_Facility->fields->type);
     }
     return parent::upgrade($old_vers, $new_vers);
 }
 public function display($supress_output = false)
 {
     if (!array_key_exists('HTTP_HOST', $_SERVER)) {
         exit("No command line usage for this page");
     }
     if (!$this->get_exists('delay_index')) {
         I2CE::raiseError("Invalid tree data request:  'request' is missing");
         return false;
     }
     $delay_index = $this->get('delay_index');
     if (!array_key_exists('tree_data', $_SESSION) || !is_array($_SESSION['tree_data']) || !array_key_exists($delay_index, $_SESSION['tree_data'])) {
         return false;
     }
     $data = $_SESSION['tree_data'][$delay_index];
     unset($_SESSION['tree_data'][$delay_index]);
     if (!is_array($data)) {
         return false;
     }
     $template = new I2CE_Template();
     $template->loadRootText("<span id='root'>");
     $root = $template->getElementById('root');
     $doc = $template->getDoc();
     I2CE_Module_TreeSelect::createTreeData($template, $root, $data);
     $tdoc = new DOMDocument();
     $tdoc->appendChild($tdoc->importNode($root, true));
     echo $tdoc->saveHTML();
     die;
 }
 /**
  * Create and load data for the objects used for this form.
  * 
  * Create the list object and if this is a form submission load
  * the data from the form data.
  */
 protected function loadObjects()
 {
     $factory = I2CE_FormFactory::instance();
     if ($this->isPost()) {
         $trainingprovider = $factory->createContainer('trainingprovider');
         if (!$trainingprovider instanceof iHRIS_TrainingProvider) {
             I2CE::raiseError("Could not create trainingprovider form");
             return;
         }
         $trainingprovider->load($this->post);
         $name_ignore = $trainingprovider->getField('name_ignore');
         $ignore_path = array('forms', 'trainingprovider', $trainingprovider->getID(), 'ignore', 'name');
         if ($name_ignore instanceof I2CE_FormField && $this->post_exists($ignore_path)) {
             $name_ignore->setFromPost($this->post($ignore_path));
         }
     } else {
         if ($this->get_exists('id')) {
             $id = $this->get('id');
             if (strpos($id, '|') === false) {
                 I2CE::raiseError("Depcreated use of id variable");
                 $id = 'trainingprovider|' . $id;
             }
         } else {
             $id = 'trainingprovider|0';
         }
         $trainingprovider = $factory->createContainer($id);
         if (!$trainingprovider instanceof iHRIS_TrainingProvider) {
             I2CE::raiseError("Could not create valid trainingprovider form from id:{$id}");
             return;
         }
         $trainingprovider->populate();
     }
     $this->setObject($trainingprovider);
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('swiss_formfield_headers.html', 'div', $content_node)) instanceof DOMNode || !($headersNode = $this->template->getElementByName('headers_body', 0, $mainNode)) instanceof DOMNode) {
         I2CE::raiseError("Could not load headers template");
         return false;
     }
     $headers = $this->storage->getAsArray();
     $inputs = array('new_key', 'new_val', 'do_new');
     $delete = 'Delete Header';
     I2CE::getConfig()->setIfIsSet($delete, "/modules/form-builder/messages/delete_header");
     foreach ($headers as $key => $val) {
         if (!is_scalar($val) && !$val === null) {
             continue;
         }
         $headersNode->appendChild($trNode = $this->template->createElement('tr'));
         $trNode->appendChild($keyNode = $this->template->createElement('td'));
         $trNode->appendChild($valNode = $this->template->createElement('td'));
         $keyNode->appendChild($labelNode = $this->template->createElement('h3'));
         $labelNode->appendChild($this->template->createTextNode($key));
         $input = 'val[' . $key . ']';
         $inputs[] = $input;
         $valNode->appendChild($this->template->createElement('input', array('value' => $val, 'name' => $input)));
         $valNode->appendChild($this->template->createElement('br'));
         $input = 'delete[' . $key . ']';
         $inputs[] = $input;
         $keyNode->appendChild($this->template->createElement('input', array('type' => 'checkbox', 'value' => 1, 'name' => $input)));
         $keyNode->appendChild($this->template->createTextNode($delete));
     }
     if (($newNode = $this->template->getElementByName('new_key', 0, $mainNode)) instanceof DOMNode) {
         $this->template->setClassValue($newNode, 'validate_data', array('notinlist' => array_keys($headers)), '%');
     }
     $this->renameInputs($inputs, $mainNode);
     return true;
 }
 public function displayValues($contentNode, $transient_options, $action)
 {
     $mainNode = $this->template->appendFileByNode('view_relationship_forms.html', 'div', $contentNode);
     if (!$mainNode instanceof DOMNode) {
         I2CE::raiseError("Unable to add reported form list template");
         return false;
     }
     $listNode = $this->template->getElementById('report_forms_list', $mainNode);
     if (!$listNode instanceof DOMElement) {
         I2CE::raiseError("Don't knwo where to add forms");
         return false;
     }
     $swissRelationshipForms = $this->getSwissFormsInRelationship();
     foreach ($swissRelationshipForms as $form => $swissRelationshipForm) {
         if ($swissRelationshipForm instanceof I2CE_Swiss_FormRelationship_Join) {
             $swissForm = $this->getChild($form, true);
         } else {
             $swissForm = $this->getChild('primary_form', true);
         }
         if (!$swissForm instanceof I2CE_Swiss_CustomReports_Report_ReportingForm) {
             continue;
         }
         $formNode = $this->template->appendFileByNode('customReports_report_forms_each.html', 'li', $listNode);
         if (!$formNode instanceof DOMNode) {
             continue;
         }
         $this->template->setDisplayDataImmediate('name', $form, $formNode);
         $swissForm->addAjaxLink('form_link', 'form_contents', 'form_ajax', $formNode, $action, $transient_options);
     }
     return true;
 }
 protected function ensureLimits()
 {
     if ($this->ensured) {
         return;
     }
     if ($this->storage->is_scalar()) {
         return false;
     }
     if (!$this->parent instanceof I2CE_Swiss_CustomReports_Report_ReportingForm_Field) {
         return false;
     }
     $factory = I2CE_FormFactory::instance();
     $formName = $this->parent->getForm();
     $formObj = $factory->createForm($formName);
     if (!$formObj instanceof I2CE_Form) {
         I2CE::raiseError("Could not instantiate the form {$formName}  at " . $this->configPath);
         return false;
     }
     $field = $this->parent->getName();
     $allowed_limits = $formObj->getLimitStyles($field);
     $excludes = I2CE::getConfig()->getAsArray("/modules/CustomReports/limit_excludes/displayed");
     foreach ($allowed_limits as $limit => $data) {
         if (in_array($limit, $excludes)) {
             continue;
         }
         $swissLimit = $this->getChild($limit, true);
         if (is_array($data) && count($data) == 1 && in_array('value', $data)) {
             $swissLimit->setAllowPivot(true);
         } else {
             $swissLimit->setAllowPivot(false);
         }
     }
     $this->ensured = true;
 }
 /**
  * Wrapper function to fenerates a UUID via the pecl uuid module.
  * More {@link http://pwet.fr/man/linux/fonctions_bibliotheques/ossp/uuid doucmentation} on ossp uuid.
  *
  * <br/>
  * Version 1 UUIDs are guaranteed to be unique through combinations of hardware addresses, time stamps and random seeds. There is a reference in the UUID to the hardware (MAC) address of the first network interface card (NIC) on the host which generated the UUID this reference is intended to ensure the UUID will be unique in space as the MAC address of every network card is assigned by a single global authority (IEEE) and is guaranteed to be unique. The next component in a UUID is a timestamp which, as clock always (should) move forward, will be unique in time. Just in case some part of the above goes wrong (the hardware address cannot be determined or the clock moved steps backward), there is a random clock sequence component placed into the UUID as a catch-all for uniqueness.
  * <br/>
  * Version 3 and version 5 UUIDs are guaranteed to be inherently globally unique if the combination of namespace and name used to generate them is unique.  It is  not supported at the moment
  * <br/>
  * Version 4 UUIDs are not guaranteed to be globally unique, because they are generated out of locally gathered pseudo-random numbers only. Nevertheless there is still a high likelihood of uniqueness over space and time and that they are computationally difficult to guess. 
  *                                                                                                *
  * http://manpages.ubuntu.com/manpages/dapper/man3/uuid.3ossp.html
  * V1 -- Time an node
  * V4 -- random data
  * 
  * @param string $version.  Defaults to 1
  * @retruns mixed string or false on failure
  */
 public static function generateUUID($version = 4)
 {
     switch ($version) {
         case 3:
             I2CE::raiseError("Version 3 not supported");
             return false;
             break;
         case 5:
             I2CE::raiseError("Version 5 not supported");
             return false;
             break;
         case 4:
             $version = UUID_TYPE_RANDOM;
             break;
         default:
         case 1:
             $version = UUID_TYPE_DEFAULT;
             break;
     }
     // if (  0 != uuid_make ( self::$uuidobject, $version ) > 0 ) { //i think it returns a non-zero on failure
     //     return false;
     // }
     // uuid_export ( self::$uuidobject, UUID_FMT_STR, &$uuidstring );
     return trim(uuid_create($version));
 }
 public function processDOMEditable($node, $template, $form_node)
 {
     $default = $this->getValue();
     $ele_name = $this->getHTMLName();
     if (!$default instanceof I2CE_Date) {
         $default = I2CE_Date::now();
     }
     if ($this->use_date_picker) {
         $date = $default->dbFormat();
         $attrs = array("class" => "datepicker_ymd", "name" => $ele_name, "type" => "text", "value" => $date);
         foreach (array('onclick', 'onchange') as $attr) {
             if ($node->hasAttribute($attr)) {
                 $attrs[$attr] = $node->getAttribute($attr);
                 $node->removeAttribute($attr);
             }
         }
         $element = $template->createElement("input", $attrs);
         $this->setElement($element);
         $node->appendChild($element);
         $args = array('format' => 'F j, Y', 'inputOutputFormat' => 'Y-m-d', 'allowEmpty' => true, 'startView' => 'decades');
         $add_args = I2CE::getConfig()->getAsArray("/modules/DatePicker/options");
         if (is_array($add_args)) {
             $args = array_merge($args, $add_args);
         }
         $template->addDatePicker('datepicker_ymd', $args);
     } else {
         I2CE_Date::addMonthDayElement($template, $ele_name, $default, $this->hasInvalid(), $node);
         I2CE_Date::addYearElement($template, $ele_name, $default, $this->hasInvalid(), $node, $this->getYearRange(), false, true);
     }
 }
 /**
  * Upgrades the modules
  * @param string $old_vers
  * @param string $new_vers
  * @returns boolean
  */
 public function upgrade($old_vers, $new_vers)
 {
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.12')) {
         I2CE::raiseError("Changing contact child forms of training_institution to training_institution_contact");
         if (!iHRIS_Module_Contact::changeContactForm('training_institution', 'contact_type|facility', 'training_institution_contact', true)) {
             I2CE::raiseError("Could not upgrade training instituion contacts");
             return false;
         }
     }
     if (I2CE_Validate::checkVersion($old_vers, '=', '3.2.12')) {
         //the changeContactForm did not remvoe the contact form before
         if (!iHRIS_Module_Contact::removeContactForm('training_institution')) {
             return false;
         }
     }
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.19')) {
         I2CE::raiseError("Changing contact child forms of training_funder to training_funder_contact");
         if (!iHRIS_Module_Contact::changeContactForm('training_funder', 'contact_type|facility', 'training_funder_contact', true)) {
             I2CE::raiseError("Could not upgrade training funder contacts");
             return false;
         }
     }
     if (I2CE_Validate::checkVersion($old_vers, '<', '3.2.20')) {
         $user = new I2CE_User(1, false, false, false);
         $class_config = I2CE::getConfig()->modules->forms->formClasses;
         $migrate_path = "/I2CE/formsData/migrate_data/3.2.3";
         if (!I2CE_FormStorage::migrateField("training_institution", array("location" => array("county" => "county", "district" => "district", "country" => "country")), $migrate_path, $user)) {
             return false;
         }
         if (!I2CE_FormStorage::migrateField("training_funder", array("location" => array("county" => "county", "district" => "district", "country" => "country")), $migrate_path, $user)) {
             return false;
         }
     }
     return true;
 }
 /**
  * Make sure the float column is in the database in the entry/last entry tables.
  */
 public function action_initialize()
 {
     //check to see that the large blobs are there.
     foreach (array('entry', 'last_entry') as $table) {
         $qry_show = "SHOW COLUMNS FROM {$table} LIKE '%_value'";
         $qry_alter = "ALTER TABLE {$table} ADD COLUMN `float_value` float";
         $results = $this->db->query($qry_show);
         if (I2CE::pearError($results, "Error getting columns from {$table} table: on {$qry_show}")) {
             return false;
         }
         $found = false;
         while ($row = $results->fetchRow()) {
             if ($row->field == 'float_value') {
                 $found = true;
             }
         }
         if (!$found) {
             //add the blob column to last_entry
             if (I2CE::pearError($this->db->exec($qry_alter), "Error adding float column to {$table}:")) {
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * Process a result row.
  * @param array $row
  * @param int $row_num The current row number when processing results.  If there was a result limit, it starts the count from the beginning of the
  * result offset.  Othwerwise, it starts counting form zero.
  * @param DOMNode $contentNode. Default to null. A node to append the result onto
  */
 protected function processResultRow($row, $row_num, $contentNode = null)
 {
     parent::processResultRow($row, $row_num, $contentNode);
     $per_page = (int) $this->defaultOptions['limit_per_page'];
     if ($per_page < 1) {
         //check it is not bad, if so make it something reasonable -- in fact make it the default per page in I2CE_CustomReport_Display
         $per_page = 100;
     }
     $page = (int) $this->defaultOptions['limit_page'];
     //$page = (int) $this->page->request('limit_page');
     if ($page < 1) {
         $page = 1;
     }
     $appendCount = $row_num - ($page - 1) * $per_page;
     $cellNode = $this->template->appendFileByName("customReports_table_data_cell.html", "td", "report_row", $appendCount, null, true);
     if (!$cellNode instanceof DOMNode) {
         I2CE::raiseError("Could not add data cell to table");
         return false;
     }
     $field_args = array();
     foreach ($this->page->getActionFields() as $field) {
         $field_args[] = $row->{$field};
     }
     $actionNode = $this->page->getActionNode($field_args);
     $this->template->appendNode($actionNode, $cellNode);
     return true;
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('swiss_form_meta.html', 'div', $content_node)) instanceof DOMNode) {
         I2CE::raiseError("no template ");
         return false;
     }
     $inputs = array('description');
     $forms = I2CE::getConfig()->getKeys("/modules/forms/forms");
     $selected = $this->getSelectedForms();
     if (!is_array($selected)) {
         //in case it wan't ever set
         $selected = array();
     }
     if (($formsNode = $this->template->getElementByName('child_forms', 0, $mainNode)) instanceof DOMNode) {
         foreach ($forms as $form) {
             $input = 'child_forms[' . $form . ']';
             $inputs[] = $input;
             $attr = array('value' => 1, 'name' => $input, 'type' => 'checkbox');
             if (in_array($form, $selected)) {
                 $attr['checked'] = 'checked';
             }
             $formsNode->appendChild($formNode = $this->template->createElement('span', array('style' => 'display:inline-block;width:33%; min-width:33%')));
             $formNode->appendChild($this->template->createElement('input', $attr));
             $formNode->appendChild($this->template->createTextNode($form));
         }
     }
     $this->template->setDisplayDataImmediate('description', $this->getField('description'), $mainNode);
     $this->renameInputs($inputs, $mainNode);
     if (($swissChild = $this->getChild('child_form_data', true)) instanceof I2CE_Swiss && ($childNode = $this->template->getElementById('child_form_data', $mainNode)) instanceof DOMNode) {
         $swissChild->addAjaxLink('child_form_data_link', 'display_container', 'child_form_data_ajax', $childNode, $action, $transient_options);
     }
     return true;
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode($this->getContainerTemplate(), 'div', $content_node)) instanceof DOMNode || !($containerNode = $this->template->getElementByName('forms', 0, $mainNode))) {
         I2CE::raiseError("Could not load " . $this->getContainerTemplate());
         return false;
     }
     if (($formsNode = $this->template->getElementByName('form', 0, $mainNode)) instanceof DOMNode) {
         $forms = array_diff($this->getAllowedForms(), $this->storage->getKeys());
         foreach ($forms as $form) {
             $formsNode->appendChild($this->template->createElement('option', array('value' => $form), $form));
         }
     }
     $this->renameInputs(array('form'), $mainNode);
     foreach ($this->storage->getKeys() as $name) {
         $containerNode->appendChild($liNode = $this->template->createElement('li'));
         if (!($childNode = $this->template->appendFileByNode($this->getFormTemplate(), 'div', $liNode)) instanceof DOMNode || !($swissChild = $this->getChild($name)) instanceof I2CE_Swiss) {
             continue;
         }
         $this->template->setDisplayDataImmediate('name', $name, $childNode);
         $swissChild->addAjaxLink('form_link', $this->getAjaxContainer(), 'form_ajax', $childNode, $action, $transient_options);
         $delete_link = $swissChild->getURLRoot('delete_class') . $swissChild->path;
         $this->template->setDisplayDataImmediate('delete_link', $delete_link, $childNode);
     }
     return true;
 }
 public function action()
 {
     parent::action();
     $init_options = array('root_path' => '/modules/forms/storage_options/CSD/remote_services', 'root_path_create' => true, 'root_url' => 'remote_directory_selector', 'root_type' => 'ServiceDirectorySelector');
     try {
         $swiss_factory = new I2CE_SwissMagicFactory($this, $init_options);
     } catch (Exception $e) {
         I2CE::raiseError("Could not create swissmagic for selectable" . $e->getMessage());
         return false;
     }
     try {
         $swiss_factory->setRootSwiss();
     } catch (Exception $e) {
         I2CE::raiseError("Could not create root swissmagic for selectable" . $e->getMessage());
         return false;
     }
     $swiss_path = $this->request_remainder;
     $action = array_shift($swiss_path);
     if ($action == 'update' && $this->isPost()) {
         if ($swiss_factory->updateValues($this->post())) {
             $this->userMessage("Updated Remote Directories");
         } else {
             $this->userMessage("Unable To Update Remote Directories");
         }
         $this->setRedirect('home');
     }
     $action = 'edit';
     return $swiss_factory->displayValues($this->template->getElementById('siteContent'), $swiss_path, $action);
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('swiss_mapped_limits_form.html', 'div', $content_node)) instanceof DOMNode || !($limitsNode = $this->template->getElementByName('limits', 0, $mainNode))) {
         I2CE::raiseError("Could not load swiss_mapped_limits.html");
         return false;
     }
     $existing = $this->storage->getKeys();
     if (($selectNode = $this->template->getElementByName('new', 0, $mainNode)) instanceof DOMNode) {
         foreach (I2CE::getConfig()->getKeys("/modules/forms/forms") as $key) {
             if (in_array($key, $existing)) {
                 continue;
             }
             $selectNode->appendChild($this->template->createElement('option', array('value' => $key), $key));
         }
     }
     $this->renameInputs(array('new'), $mainNode);
     foreach ($existing as $name) {
         $limitsNode->appendChild($liNode = $this->template->createElement('li'));
         if (!($limitNode = $this->template->appendFileByNode('swiss_mapped_limits_each.html', 'div', $liNode)) instanceof DOMNode || !($swissLimit = $this->getChild($name)) instanceof I2CE_Swiss) {
             continue;
         }
         $this->template->setDisplayDataImmediate('name', $name, $limitNode);
         $swissLimit->addAjaxLink('limit_link', 'relationship_where_container', 'limit_ajax', $limitNode, $action, $transient_options);
         $delete_link = $swissLimit->getURLRoot('delete_class') . $swissLimit->path;
         $this->template->setDisplayDataImmediate('delete_link', $delete_link, $limitNode);
     }
     return true;
 }
 /**
  * Check for duplicates and save the user alert
  * @param I2CE_User $user
  * @param boolean $transact
  * @return boolean
  */
 public function save($user, $transact = true)
 {
     if ($this->getId() === '0') {
         $find_duplicates = array('operator' => 'AND', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'message', 'style' => 'lowerequals', 'data' => array('value' => strtolower($this->message))), array('operator' => 'FIELD_LIMIT', 'field' => 'time_ack', 'style' => 'null'), array('operator' => 'FIELD_LIMIT', 'field' => 'alert_type', 'style' => 'equals', 'data' => array('value' => $this->alert_type))));
         if ($this->link == '') {
             $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link', 'style' => 'null');
         } else {
             $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link', 'style' => 'equals', 'data' => array('value' => $this->link));
         }
         if ($this->link_text == '') {
             $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link_text', 'style' => 'null');
         } else {
             $find_duplicates['operand'][] = array('operator' => 'FIELD_LIMIT', 'field' => 'link_text', 'style' => 'lowerequals', 'data' => array('value' => strtolower($this->link_text)));
         }
         $found = I2CE_FormStorage::search('user_alert', $this->getParent(), $find_duplicates, array("-time_sent"), 1);
         if ($found) {
             I2CE::raiseMessage("found duplicates so increasing repeats. {$found}");
             $duplicate = I2CE_FormFactory::instance()->createContainer("user_alert|" . $found);
             $duplicate->populate();
             $duplicate->repeated++;
             return $duplicate->save($user, $transact);
         }
     }
     return parent::save($user, $transact);
 }
 protected function displayMeta($mainNode, $transient_options, $action)
 {
     foreach (self::$bool_keys as $k => $default) {
         if ($this->hasField($k)) {
             $val = $this->getField($k) ? 1 : 0;
         } else {
             $val = $default;
         }
         $this->template->selectOptionsImmediate($k, array($val), $mainNode);
     }
     $this->renameInputs(array_keys(self::$bool_keys), $mainNode);
     if (!($sortNode = $this->template->getElementByName('key_sort', 0, $mainNode)) instanceof DOMNode) {
         I2CE::raiseError("Don't know where to add key sorts");
         return false;
     }
     $sort = $this->getField('key_sort');
     if (!in_array($sort, self::$allowed_sorts)) {
         $sort = 'SORT_NATURAL_CASE';
         //the default
     }
     foreach (self::$allowed_sorts as $s) {
         $attrs = array('value' => $s);
         if ($sort == $s) {
             $attrs['selected'] = 'selected';
         }
         $sortNode->appendChild($this->template->createElement('option', $attrs, $s));
     }
     $this->renameInputs(array('key_sort'), $mainNode);
     return true;
 }
 public function action_person_record_status($obj)
 {
     if (!$obj instanceof iHRIS_PageView) {
         return;
     }
     $person = $obj->getPerson();
     if (!$person instanceof iHRIS_Person) {
         return false;
     }
     $obj->addChildForms('person_record_status');
     $template = $obj->getTemplate();
     $recordStatusObjs = $person->getChildren('person_record_status');
     if (count($recordStatusObjs) == 1) {
         return true;
     } else {
         if (count($recordStatusObjs) > 1) {
             I2CE::raiseError("Too many record status forms  for " . $person->getId());
             return false;
         } else {
             if ($obj->hasPermission("task(person_can_edit_child_form_person_record_status)")) {
                 $template->appendFileById("view_person_record_status_link.html", 'span', 'record_status_links');
             }
         }
     }
     return true;
 }
 protected function ensureFunctions()
 {
     if ($this->ensured) {
         return true;
     }
     $swissRel = $this->getSwissRelationship();
     if (!$swissRel instanceof I2CE_Swiss_FormRelationship) {
         I2CE::raiseError("Could not get Relationship");
         return false;
     }
     $relFunctions = $swissRel->getSwissFunctions();
     if (!$relFunctions instanceof I2CE_Swiss_FormRelationship_ReportingFunctions) {
         return false;
     }
     $rels = array($relFunctions);
     while (count($rels) > 0) {
         $relFunctions = array_pop($rels);
         foreach ($relFunctions as $func => $swissRelFunction) {
             $this->getChild($func, true);
             if (($t_relFunctions = $swissRelFunction->getChild('reporting_functions')) instanceof I2CE_Swiss_FormRelationship_ReportingFunctions) {
                 $rels[] = $t_relFunctions;
             }
         }
     }
     $this->ensured = true;
 }
 protected function loadObjects()
 {
     $factory = I2CE_FormFactory::instance();
     if ($this->isPost()) {
         $dataset = $factory->createContainer('dataset');
         if (!$dataset instanceof iHRIS_DataSet) {
             I2CE::raiseError("Could not create Data Set form");
             return;
         }
         $dataset->load($this->post);
         //$surname_ignore = $person->getField('surname_ignore');
         //$ignore_path = array('forms','person',$person->getID(),'ignore','surname');
         //            if ($surname_ignore instanceof I2CE_FormField && $this->post_exists($ignore_path)) {
         //                $surname_ignore->setFromPost($this->post($ignore_path));
         //            }
     } else {
         if ($this->get_exists('id')) {
             $id = $this->get('id');
             if (strpos($id, '|') === false) {
                 I2CE::raiseError("Depcreated use of id variable");
                 $id = 'dataset|' . $id;
             }
         } else {
             $id = 'dataset|0';
         }
         $dataset = $factory->createContainer($id);
         if (!$dataset instanceof iHRIS_DataSet) {
             I2CE::raiseError("Could not create valid Data Set form from id:{$id}");
             return;
         }
         $dataset->populate();
         $dataset->load($this->request());
     }
     $this->setObject($dataset);
 }
 protected function ensureFieldsFromForm()
 {
     if ($this->ensured) {
         return;
     }
     $swissForm = $this->getAncestorByClass('I2CE_Swiss_CustomReports_Report_ReportingForm');
     if (!$swissForm instanceof I2CE_Swiss_CustomReports_Report_ReportingForm) {
         I2CE::raiseError("Could not get reported form");
         return;
     }
     $formRel = $this->getSwissRelationshipForm($swissForm->storage->getName());
     if (!$formRel instanceof I2CE_Swiss) {
         I2CE::raiseError("Could not get relationship form for " . $swissForm->storage->getName());
         return;
     }
     $formName = $formRel->getField("form");
     if (!$formName) {
         I2CE::raiseError("Could not get relationship form name for " . $swissForm->storage->getName());
         return;
     }
     $factory = I2CE_FormFactory::instance();
     $fields = $factory->getFieldNames($formName, array('in_db' => true));
     $fields[] = 'last_modified';
     $fields[] = 'created';
     foreach ($fields as $field) {
         $this->getChild($field, true);
     }
     $this->getChild('id', true);
     $this->ensured = true;
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('swiss_xmlrelationship_formfields.html', 'div', $content_node)) instanceof DOMNode) {
         return false;
     }
     $listNode = $this->template->getElementById('forms_list', $mainNode);
     if (!$listNode instanceof DOMElement) {
         I2CE::raiseError("Don't know where to add forms");
         return false;
     }
     foreach ($this->getFormNames() as $formname) {
         if (!($swissChild = $this->getChild($formname, true)) instanceof I2CE_Swiss) {
             continue;
         }
         $formNode = $this->template->appendFileByNode('swiss_xmlrelationship_formfields_each.html', 'li', $listNode);
         if (!$formNode instanceof DOMNode) {
             continue;
         }
         $name = $formname;
         if ($formname == 'primary_form' && ($relObj = $this->getRelationship()) instanceof I2CE_FormRelationship) {
             $name = $relObj->getForm('primary_form') . ' (primary_form)';
         }
         $this->template->setDisplayDataImmediate('name', $name, $formNode);
         $swissChild->addAjaxLink('form_link', 'form_contents', 'form_ajax', $formNode, $action, $transient_options);
     }
     return true;
 }
 /**
  * Create the report display and add it to the page.
  * @param string $query The query string to pass to the action for applying limits.
  * @return boolean
  */
 protected function actionReport($query = '')
 {
     try {
         $this->display = new I2CE_CustomReport_Display_DefaultAction($this, $this->args['report_view']);
     } catch (Exception $e) {
         I2CE::raiseError("Could not get for " . $this->args['report_view'] . "\n" . $e);
         return false;
     }
     $this->template->addHeaderLink($this->args['action_script']);
     $this->template->addHeaderLink("CustomReports.css");
     $this->template->addHeaderLink("CustomReports_iehacks.css", array('ie6' => true));
     $this->template->setDisplayData("limit_description", false);
     $contentNode = $this->template->getElementById("siteContent");
     if (!$contentNode instanceof DOMNode || !$this->display->display($contentNode)) {
         I2CE::raiseError("Couldn't display report.  Either no content node or an error occurred displaying the report.");
         return false;
     }
     $reportLimitsNode = $this->template->getElementById('report_limits');
     if (!$reportLimitsNode instanceof DOMNode) {
         I2CE::raiseError("Unable to find report_limits node.");
     } else {
         $applyNode = $this->template->appendFileByNode("customReports_display_limit_apply_Default.html", "tr", $reportLimitsNode);
         $form = $this->template->query(".//*[@id='limit_form']", $contentNode);
         if ($form->length == 1) {
             $form = $form->item(0)->setAttribute('action', $this->page() . "?{$query}");
         }
     }
     return true;
 }
 public function displayValues($contentNode, $transient_options, $action)
 {
     $mainNode = $this->template->appendFileByNode('customReports_reportView_merge_' . $action . '.html', 'div', $contentNode);
     if (!$mainNode instanceof DOMNode) {
         I2CE::raiseError("Could not load report views template");
         return false;
     }
     if ($this->isEnabled()) {
         $this->template->setDisplayDataImmediate('enabled', 1, $mainNode);
     } else {
         $this->template->setDisplayDataImmediate('enabled', 0, $mainNode);
     }
     if ($this->showBlanks()) {
         $this->template->setDisplayDataImmediate('show_blanks', 1, $mainNode);
     } else {
         $this->template->setDisplayDataImmediate('show_blanks', 0, $mainNode);
     }
     $this->template->setDisplayDataImmediate('merge_report_name', $this->getDisplayName(), $mainNode);
     $header_node = $this->template->getElementById('merge_header', $mainNode);
     if ($header_node instanceof DOMNode) {
         $this->template->setDisplayData('linked_report', $this->getLinkedReport(), $header_node);
     }
     $inputs = array('enabled', 'show_blanks', 'merge_exists');
     if ($action == 'edit') {
         $this->renameInputs($inputs, $mainNode);
     }
     return $this->displayFields($mainNode, $transient_options, $action);
 }
 protected function action()
 {
     if (!parent::action()) {
         return false;
     }
     I2CE::raiseError("aremaC <- sthgiL");
     if (!is_scalar($search_form = array_shift($this->request_remainder)) || !($search_obj = I2CE_FormFactory::instance()->createContainer($search_form)) instanceof CSD_SearchMatches || (!($matches = $search_obj->getField('matches'))) instanceof I2CE_FormField_ASSOC_MAP_RESULTS) {
         return false;
     }
     I2CE::raiseError(print_r($this->request(), true));
     if (($maxField = $search_obj->getField('max')) instanceof I2CE_FormField_INT) {
         if ($maxField->getValue() > 200) {
             $maxField->setValue(200);
         }
     }
     $search_obj->load($this->post, false, false);
     I2CE::raiseError($search_obj->getXMLRepresentation(false));
     $search_obj->setID("1");
     //so it will populate
     $search_obj->populate(true);
     if (count($results = $matches->getValue()) > 200) {
         return false;
         I2CE::raiseError("Too many results");
     }
     $this->data['length'] = count($results);
     $this->data['data'] = $results;
     I2CE::raiseError("REQ=" . print_r($this->request(), true));
     $this->data = array($this->data);
     I2CE::raiseError(print_r($this->data, true));
     return true;
 }
 protected function displayMeta($mainNode, $transient_options, $action)
 {
     if (($styleNode = $this->template->getElementByName('style', 0, $mainNode)) instanceof DOMNode) {
         $styles = I2CE::getConfig()->getKeys("/I2CE/template/page_styles");
         $selected_style = $this->getField('style');
         foreach ($styles as $style) {
             $attrs = array('value' => $style);
             if ($style == $selected_style && $selected_style != '' || $style == 'shell' && $selected_style == '') {
                 $attrs['selected'] = 'selected';
             }
             $styleNode->appendChild($this->template->createElement('option', $attrs, $style));
         }
         $this->renameInputs('style', $mainNode);
     }
     if (($descNode = $this->template->getElementByName('description', 0, $mainNode)) instanceof DOMNode) {
         $this->template->setDisplayData("page", $this->name, $descNode);
         $this->template->setDisplayData("class", $this->getField('class'), $descNode);
     }
     if (($linkNode = $this->template->getElementByName('link_name', 0, $mainNode)) instanceof DOMNode) {
         $page = $this->getName();
         $url = I2CE_Page::getAccessedBaseURL() . '/' . $page;
         $c = 0;
         $formids = $this->getSampleIDs();
         foreach ($formids as $formid) {
             $this->template->setDisplayDataImmediate("link_title_" . $c, "{$page} {$c}", $linkNode);
             $this->template->setDisplayDataImmediate("page_edit_link_" . $c, "{$url}?id={$formid}", $linkNode);
             $c++;
         }
         return true;
     }
 }
 public function displayArgs($mainNode, $transient_options, $action)
 {
     // Display the action link's form field
     $this->template->setDisplayDataImmediate('formfield', $this->getField('formfield'), $mainNode);
     // Display the action link's link location
     $this->template->setDisplayDataImmediate('linkloc', $this->getField('href'), $mainNode);
     // Display the action link's link text field
     $this->template->setDisplayDataImmediate('linktext', $this->getField('text'), $mainNode);
     // Rename the inputs to include swiss instance path
     $inputs = array('linkloc', 'formfield', 'linktext');
     if (($taskNode = $this->template->getElementByName('task', 0, $mainNode)) instanceof DOMNode) {
         $tasks = I2CE::getConfig()->getAsArray("/I2CE/tasks/task_description");
         $selected_task = $this->getField('task');
         foreach ($tasks as $task => $desc) {
             $attrs = array('value' => $task, 'title' => $desc);
             if ($task == $selected_task) {
                 $attrs['selected'] = 'selected';
             }
             $taskNode->appendChild($this->template->createElement('option', $attrs, $task));
         }
         $inputs[] = 'task';
     }
     $this->renameInputs($inputs, $mainNode);
     return true;
 }
 public function displayValues($content_node, $transient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('swiss_form.html', 'div', $content_node)) instanceof DOMNode) {
         I2CE::raiseError("no template form_class_builder_menu.html");
         return false;
     }
     if (($classNode = $this->template->getElementByName('class', 0, $mainNode)) instanceof DOMNode) {
         $selected = $this->getField('class');
         foreach (I2CE::getConfig()->getKeys("/modules/forms/formClasses") as $class) {
             $attrs = array('value' => $class);
             if ($selected == $class) {
                 $attrs['selected'] = $selected;
             }
             $classNode->appendChild($this->template->createElement('option', $attrs, $class));
         }
     }
     $this->template->setDisplayDataImmediate('display', $this->getField('display'), $mainNode);
     $storage = $this->getField('storage');
     if (!$storage) {
         $storage = 'entry';
     }
     $this->template->setDisplayDataImmediate('storage', $storage, $mainNode);
     $this->renameInputs(array('display', 'class'), $mainNode);
     if (($metaChild = $this->getChild('meta', true)) instanceof I2CE_Swiss && ($metaNode = $this->template->getElementById('meta', $mainNode)) instanceof DOMNode) {
         $metaChild->addAjaxLink('meta_link', 'container', 'meta_ajax', $metaNode, $action, $transient_options);
     }
     if (($storage_optionsChild = $this->getChild('storage_options', true)) instanceof I2CE_Swiss && ($storage_optionsNode = $this->template->getElementById('storage_options', $mainNode)) instanceof DOMNode) {
         $storage_optionsChild->addAjaxLink('storage_options_link', 'container', 'storage_options_ajax', $storage_optionsNode, $action, $transient_options);
     }
     return true;
 }
 /**
  * Perform the main actions of the page.
  */
 protected function action()
 {
     parent::action();
     $this->template->setAttribute("class", "active", "menuPassword", "a[@href='password']");
     if ($this->isPost()) {
         $access = I2CE::getUserAccess();
         if (!$access instanceof I2CE_UserAccess_Mechanism || !$access->canChangePassword() || $this->user->getRole() == 'guest') {
             $success = 'no_change';
         } else {
             if (!$this->post('old_password') || !$this->post('new_password')) {
                 $success = 'none';
             } else {
                 if ($this->post('new_password') != $this->post('confirm_password')) {
                     $success = 'no_match';
                 } else {
                     if (!$this->user->changePassword($this->post('old_password'), $this->post('new_password'))) {
                         $success = 'wrong';
                     } else {
                         $success = 'success';
                     }
                 }
             }
         }
         //$this->template->addTextNode( "message", $message );
         if ($success == 'success') {
             $this->template->addFile("password_success.html");
         } else {
             $this->template->addFile("password_form.html");
             $this->template->addFile("password_" . $success . ".html", "td");
         }
     } else {
         $this->template->addFile("password_form.html");
     }
 }