/**
  * 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;
 }
 /**
  * Hooked method to drop a cached table
  * @param mixed $args.   an array of two elements whose first element is a form object, the second is the user
  */
 public function dropTable_hook($args)
 {
     if (!is_array($args) || !array_key_exists('form', $args)) {
         return;
     }
     $form = $args['form'];
     if ($form instanceof I2CE_Form) {
         $form = $form->getName();
     }
     if (!is_string($form)) {
         return;
     }
     try {
         $cache = new I2CE_CachedForm($form);
     } catch (Exception $e) {
         return;
     }
     $cache->dropTable();
 }
 /**
  * Update config for given values
  * @param array $vals.  An array of values (presumably from $_POST) to update magic data from
  * @returns  true on sucess
  */
 public function processValues($vals)
 {
     $changed = false;
     foreach (array('provider', 'service', 'facility', 'organization') as $directory) {
         if (array_key_exists($directory, $vals)) {
             $t_changed = $this->getField($directory) != $vals[$directory];
             $changed |= $t_changed;
             if ($t_changed) {
                 I2CE::raiseError("Setting remote CSD {$directory} to {$vals[$directory]}");
                 $this->setField($directory, $vals[$directory]);
             }
         }
     }
     if ($changed) {
         I2CE::raiseError("Dropping all cached forms");
         $forms = I2CE_FormFactory::instance()->getNames();
         $failure = array();
         $config = I2CE::getConfig()->modules->CachedForms;
         if ($config instanceof I2CE_MagicDataNode) {
             $config->cache_all->erase();
         }
         foreach ($forms as $form) {
             try {
                 $cachedForm = new I2CE_CachedForm($form);
             } catch (Exception $e) {
                 if (array_key_exists('HTTP_HOST', $_SERVER)) {
                     //we don't need to check here, b/c it won't error out.  we are doing it to keep the log file clean
                     $this->page->userMessage("Unable to setup cached form {$form}");
                 }
                 continue;
             }
             $cachedForm->dropTable();
         }
         $this->page->userMessage("Dropped Cache For All Forms");
     }
     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;
         }
     }
 }
 /**
  * Attempts to drop caches of  all forms one by one. 
  */
 public function dropAll($forms = null)
 {
     I2CE::raiseError("Dropping all");
     $config = I2CE::getConfig()->modules->CachedForms;
     $factory = I2CE_FormFactory::instance();
     if ($forms === null) {
         $forms = $factory->getNames();
     }
     $failure = array();
     $config->cache_all->erase();
     foreach ($forms as $form) {
         try {
             $cachedForm = new I2CE_CachedForm($form);
         } catch (Exception $e) {
             if (array_key_exists('HTTP_HOST', $_SERVER)) {
                 //we don't need to check here, b/c it won't error out.  we are doing it to keep the log file clean
                 $this->userMessage("Unable to setup cached form {$form}");
             }
             $sucess[] = $form;
             continue;
         }
         if (!$cachedForm->dropTable()) {
             $failure[] = $form;
         }
     }
     if (count($failure) > 0) {
         I2CE::raiseError("DropAll: Could not drop " . implode(',', $failure));
         if (array_key_exists('HTTP_HOST', $_SERVER)) {
             $this->userMessage("Drop Failed:" . implode(',', $failure));
         }
     } else {
         $this->userMessage("Dropped all tables");
     }
     if (array_key_exists('HTTP_HOST', $_SERVER)) {
         $this->redirect("CachedForms");
     }
 }
 public static function add_uuids($form, $field = 'csd_uuid')
 {
     I2CE::raiseError("ADDING UUIDS to {$form} on {$field}");
     try {
         //we probably don't need this, but
         $cache = new I2CE_CachedForm($form);
         $cache->dropTable();
     } catch (Exception $e) {
         I2CE::raiseError("Could not clear cache");
         return false;
     }
     $ff = I2CE_FormFactory::instance();
     $user = new I2CE_User();
     $forms = I2CE_FormStorage::listFields($form, array($field));
     foreach ($forms as $id => $fields) {
         if (is_array($fields) && array_key_exists('csd_uuid', $fields) && $fields['csd_uuid']) {
             continue;
         }
         if (!($form_obj = $ff->createContainer(array($form, $id))) instanceof I2CE_Form) {
             I2CE::raiseError("Could not instantiate {$form}|{$id}");
             return false;
         }
         $form_obj->populate();
         self::set_uuid_on_form($form_obj);
         $form_obj->save($user);
         $form_obj->cleanup();
     }
     try {
         //we probably don't need this, but
         $cache = new I2CE_CachedForm($form);
         $cache->dropTable();
         $cache->generateCachedTable();
     } catch (Exception $e) {
         I2CE::raiseError("Could not clear cache");
         return false;
     }
     return true;
 }