/**
  * 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;
 }
 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;
 }
Ejemplo n.º 3
0
 /**
  * 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 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;
 }
Ejemplo n.º 5
0
 public function handleMessages($page)
 {
     $template = $page->getTemplate();
     if (!is_array($this->immediate_messages)) {
         $this->immediate_messages = array();
     }
     if (!array_key_exists('user_messages', $_SESSION) || !is_array($_SESSION['user_messages'])) {
         $_SESSION['user_messages'] = array();
     }
     if (!array_key_exists('current', $_SESSION['user_messages']) || !is_array($_SESSION['user_messages']['current'])) {
         $_SESSION['user_messages']['current'] = array();
     }
     foreach ($_SESSION['user_messages']['current'] as $class => $msgs) {
         if (!array_key_exists($class, $this->immediate_messages)) {
             $this->immediate_messages[$class] = array();
         }
         $this->immediate_messages[$class] = array_merge($this->immediate_messages[$class], $msgs);
     }
     foreach ($this->immediate_messages as $class => $msgs) {
         $msgs = array_unique($msgs);
         I2CE_ModuleFactory::callHooks("display_messages_{$class}", array('template' => $template, 'messages' => $msgs));
     }
     $this->immediate_messages = array();
     $_SESSION['user_messages']['current'] = array();
 }
Ejemplo n.º 6
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Ejemplo n.º 8
0
 public function __construct()
 {
     I2CE_ModuleFactory::callHooks('formfactory_pre_construct');
     $this->classes = I2CE::getConfig()->modules->forms->forms;
     $this->classHierarchy = array();
     parent::__construct();
     I2CE_ModuleFactory::callHooks('formfactory_post_construct');
 }
 /**
  * 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);
 }
Ejemplo n.º 10
0
 public function __construct()
 {
     parent::__construct();
     $this->js = '';
     if (I2CE_ModuleFactory::instance()->isEnabled('StretchPage')) {
         $this->js .= 'if ( PageStretch ) { PageStretch.stretchPage(); }';
     }
     $this->js_func = '';
 }
 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);
 }
Ejemplo n.º 12
0
 /**
  * Perform the main actions of the page.
  */
 protected function action()
 {
     $factory = I2CE_FormFactory::instance();
     $this->template->setAttribute("class", "active", "menuManage", "a[@href='manage']");
     $this->template->appendFileById("menu_manage.html", "ul", "menuManage");
     switch ($this->get('action')) {
         case "review":
             if (I2CE_ModuleFactory::instance()->isEnabled("ihris-manage-Application")) {
                 $this->template->setAttribute("class", "active", "menuManage", "//li/a[@href='manage?action=review']");
                 $this->template->addFile("applicant_review.html");
                 if ($this->get_exists('position')) {
                     $position_data = explode('|', $this->get('position'), 2);
                     $position_id = $position_data[1];
                     $this->template->setDisplayData("return_link", array("action" => "review"));
                     $this->template->addFile("applicant_review_results.html");
                     $this->template->setDisplayData("position_name", I2CE_List::lookup($position_id, "position"));
                     $results = iHRIS_Applicant::findApplicants($position_id);
                     if (count($results) > 0) {
                         foreach ($results as $app_id => $app_data) {
                             $this->template->appendFileById("applicant_review_row.html", "li", "app_list");
                             $this->template->setDisplayData("app_id", array("id" => "person|" . $app_id));
                             $this->template->setDisplayData("app_name", $app_data['surname'] . ', ' . $app_data['firstname']);
                             //$last_mod = I2CE_Date::fromDB( $app_data['last_modified'] );
                             //$this->template->setDisplayData( "app_modified", $last_mod->displayDate() );
                             $this->template->setDisplayData("make_offer", array("parent" => "person|" . $app_id, "position" => $this->get('position')));
                         }
                     } else {
                         $this->template->appendFileById("applicant_review_no_results.html", "li", "app_list");
                     }
                 } else {
                     $this->template->addFile("applicant_review_list.html");
                     $positions = I2CE_Form::listFields("position", array("code", "title"), array('operator' => 'FIELD_LIMIT', 'field' => 'status', 'style' => 'equals', 'data' => array('value' => 'position_status|open')));
                     $count = 0;
                     foreach ($positions as $id => $data) {
                         $node = $this->template->appendFileById("applicant_review_list_entry.html", "tr", "open_position_list");
                         if (++$count % 2 == 0) {
                             $node->setAttribute("class", "even");
                         }
                         $this->template->setDisplayDataImmediate("view_applicant", array("action" => "review", "position" => "position|" . $id), $node);
                         $this->template->setDisplayDataImmediate("position_name", $data['code'] . " - " . $data['title'], $node);
                     }
                 }
             } else {
                 parent::action();
             }
             break;
         default:
             parent::action();
             break;
     }
 }
 /**
  * Sends any triggers when participants are uploaded
  * @param I2CE_PageFormCSV $page
  */
 public function trigger_upload_save($page)
 {
     if (!$page instanceof I2CE_PageFormCSV) {
         return;
     }
     $module_factory = I2CE_ModuleFactory::instance();
     if ($module_factory->isEnabled("UserTriggers")) {
         $triggers = $module_factory->getClass("UserTriggers");
         $instance = $page->getProviderInstance();
         $details = I2CE_List::lookup($instance->getId(), $instance->getName());
         $triggers->trigger('participant_upload_save', null, 'Participants were uploaded for ' . $details, true, $instance->getNameId());
     } else {
         I2CE::raiseError("Unable to call trigger because UserTriggers isn't enabled!");
     }
 }
 /** 
  * 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;
 }
Ejemplo n.º 16
0
 /**
  * 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);
             }
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * 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));
         }
     }
 }
 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');
     }
 }
Ejemplo n.º 20
0
/**
 * The autoload function is used to load class files when needed
 * 
 * This function will be used to load any class files when they
 * are required instead of in every file.
 * 
 * It searchs the configuration array for the common class directory
 * as well as the class directory specifically for this project.
 * @global array
 * @param string $class_name The name of the class being loaded
 */
function i2ce_class_autoload($class_name)
{
    $class_file = I2CE::getfileSearch()->search('CLASSES', $class_name . '.php');
    $class_found = false;
    if ($class_file) {
        require_once $class_file;
        if (class_exists($class_name, false) || interface_exists($class_name, false)) {
            $class_found = true;
        } else {
            I2CE::raiseError("Defintion for class {$class_name} is not contained in {$class_file}", E_USER_WARNING);
        }
    }
    if (!$class_found) {
        $classes = I2CE_ModuleFactory::callHooks('autoload_search_for_class', $class_name);
        $count = count($classes);
        foreach ($classes as $class) {
            if (!is_string($class) || strlen($class) == 0) {
                continue;
            }
            if (false === eval($class)) {
                I2CE::raiseError("While looking for {$class_name}, could not parse: {$class}");
            }
            if (class_exists($class_name, false)) {
                $class_found = true;
                break;
            }
        }
    }
    if (!$class_found) {
        $debug = debug_backtrace();
        $msg = "Cannot find the defintion for class ({$class_name})";
        if (array_key_exists(1, $debug) && array_key_exists('line', $debug[1])) {
            $msg .= "called from  line " . $debug[1]['line'] . ' of file ' . $debug[1]['file'];
        }
        $msg .= "\nSearch Path is:\n" . print_r(I2CE::getFileSearch()->getSearchPath('CLASSES'), true);
        //        I2CE::raiseError( $msg, E_USER_NOTICE);
    }
}
 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;
     }
 }
Ejemplo n.º 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;
         }
     }
 }
 /**
  * Make sure all the appropriate module limits are available.
  */
 protected function ensureModuleLimits()
 {
     if ($this->ensured) {
         return;
     }
     if ($this->storage->is_scalar()) {
         return false;
     }
     if (!$this->parent instanceof I2CE_Swiss_CustomReports_Report_ReportingForm_Field) {
         return false;
     }
     if (($fieldObj = $this->parent->getFieldObj()) instanceof I2CE_FormField) {
         I2CE::raiseError("Calling get_report_module_limit_options on " . $fieldObj->getHTMLName());
         $limits = I2CE_ModuleFactory::callHooks("get_report_module_limit_options");
         I2CE::raiseError("get_report_module_limit_options returns" . print_r($limits, true));
         foreach ($limits as $limit) {
             if (!is_array($limit) || !array_key_exists('fields', $limit) || !is_array($limit['fields'])) {
                 continue;
             }
             if ($fieldObj->getName() == 'id' && ($formObj = $fieldObj->getContainer()) instanceof I2CE_Form && array_key_exists($form = $formObj->getName(), $limit['fields'])) {
                 $limit['fields'] = array($form => $limit['fields'][$form]);
             } elseif ($fieldObj instanceof I2CE_FormField_MAPPED && count($field_forms = $fieldObj->getSelectableForms()) == 1) {
                 //check to see if the fields mapped value can be one of the selectable form
                 I2CE::raiseError("Have a mapped Field with selectable forms:\n\t" . implode(" ", $field_forms) . "\ncomapring against access_facility+location selectable:\n\t" . implode(" ", array_keys($limit['fields'])));
                 foreach ($limit['fields'] as $form => $formName) {
                     if (!in_array($form, $field_forms)) {
                         unset($limit['fields'][$form]);
                     }
                 }
             } else {
                 $limit['fields'] = array();
             }
             if (count($limit['fields']) == 0) {
                 continue;
             }
             $swissModuleLimit = $this->getChild($limit['module'], true);
             if (!$swissModuleLimit instanceof I2CE_Swiss_CustomReports_Report_ReportingForm_Field_ModuleLimit) {
                 I2CE::raiseError("Bad swiss child for " . $limit['module']);
             }
             $swissModuleLimit->setFieldOptions($limit['fields']);
             $this->allowed[] = $limit['module'];
         }
     }
     $this->ensured = true;
 }
Ejemplo n.º 26
0
 /**
  * Display the recent changes list for the given form.
  * @return boolean
  */
 protected function actionRecent()
 {
     $form = array_shift($this->request_remainder);
     $form_config = I2CE::getConfig()->traverse("/modules/forms/forms");
     if (!$form_config->is_parent($form) || !I2CE::getConfig()->is_parent("/modules/RecentForm/forms/{$form}")) {
         return $this->actionMenu();
     }
     $page_size = 25;
     $days = "today";
     $user = false;
     if (count($this->request_remainder) > 0) {
         $days = array_shift($this->request_remainder);
     }
     $user_list = false;
     if (count($this->request_remainder) > 0) {
         $user_list = array_shift($this->request_remainder);
         $user = explode(',', $user_list);
         foreach ($user as $key => $uid) {
             if ($uid == "me") {
                 $uobj = new I2CE_User();
                 $user[$key] = $uobj->getId();
             }
         }
         $user = array_filter($user, "is_numeric");
         if (count($user) == 0) {
             $user = false;
         } elseif (count($user) == 1) {
             $user = array_pop($user);
         }
     }
     switch ($days) {
         case "yesterday":
             $mod_time = mktime(0, 0, 0, date("n"), date("j") - 1);
             break;
         case "week":
             $mod_time = mktime(0, 0, 0, date("n"), date("j") - 7);
             break;
         default:
             $mod_time = mktime(0, 0, 0);
             break;
     }
     $form_name = $form;
     $form_config->setIfIsSet($form_name, "{$form}/display");
     $user_link = "";
     if ($user_list) {
         $user_link = "/" . $user_list;
     }
     $this->template->setDisplayDataImmediate("display_form_name", ": " . $form_name);
     $header = $this->template->appendFileById("recent_display.html", "div", "recent_forms");
     $this->template->setDisplayDataImmediate("recent_name", $form_name, $header);
     $this->template->setDisplayDataImmediate("recent_date", date("d M Y", $mod_time), $header);
     $this->template->setDisplayDataImmediate("recent_today_link", array("href" => "recent/{$form}/today" . $user_link), $header);
     $this->template->setDisplayDataImmediate("recent_yesterday_link", array("href" => "recent/{$form}/yesterday" . $user_link), $header);
     $this->template->setDisplayDataImmediate("recent_week_link", array("href" => "recent/{$form}/week" . $user_link), $header);
     $this->template->setDisplayDataImmediate("recent_me_link", array("href" => "recent/{$form}/{$days}/me"), $header);
     $this->template->setDisplayDataImmediate("recent_all_link", array("href" => "recent/{$form}/{$days}"), $header);
     $recent_form_config = I2CE::getConfig()->traverse("/modules/RecentForm/forms/{$form}", true);
     $fields = $recent_form_config->fields->getAsArray();
     ksort($fields);
     if (!is_array($fields)) {
         $fields = array();
     }
     $display = implode(" ", array_fill(0, count($fields), "%s"));
     $recent_form_config->setIfIsSet($display, "display");
     $link = "recent";
     $recent_form_config->setIfIsSet($link, "link");
     $parent = false;
     $recent_form_config->setIfIsSet($parent, "parent");
     if ($parent) {
         $parent = true;
     }
     $order = $fields;
     array_unshift($order, "-last_modified");
     if ($this->request_exists("page")) {
         $limit_start = ((int) $this->request("page") - 1) * $page_size;
     } else {
         $limit_start = 0;
     }
     $results = I2CE_FormStorage::listDisplayFields($form, $fields, $parent, array(), $order, array($limit_start, $page_size), $mod_time, false, $user);
     $num_found = I2CE_FormStorage::getLastListCount($form);
     $this->template->setDisplayDataImmediate("recent_found", $num_found, $header);
     foreach ($results as $id => $data) {
         $record = $this->template->appendFileById("recent_display_form.html", "li", "recent_list");
         if ($parent) {
             $this->template->setDisplayDataImmediate("form_link", array("href" => $link . $data['parent']), $record);
         } else {
             $this->template->setDisplayDataImmediate("form_link", array("href" => $link . $form . "|" . $id), $record);
         }
         $extra_display = I2CE_ModuleFactory::callHooks("recent_form_{$form}_display", $data);
         array_unshift($extra_display, vsprintf($display, $data));
         $this->template->setDisplayDataImmediate("record_display", implode(' ', $extra_display), $record);
     }
     if ($this->module == "I2CE") {
         $url = $this->page . "/" . $form . "/" . $days;
     } else {
         $url = $this->module . "/" . $this->page . "/" . $form . "/" . $days;
     }
     $total_pages = max(1, ceil($num_found / $page_size));
     if ($total_pages > 1) {
         $page_num = (int) $this->request('page');
         $page_num = min(max(1, $page_num), $total_pages);
         $this->makeJumper("recent", $page_num, $total_pages, $url, array());
     }
 }
 /**
  * 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);
     }
 }