public function __construct($name, $options)
 {
     parent::__construct($name, $options);
     if (!is_array(self::$prepared)) {
         self::$prepared = array();
     }
     if (!is_array(self::$callback)) {
         self::$callback = array();
     }
     $this->form_field_data_cache = array();
     $this->form_id_cache = array();
 }
 /**
  * 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;
         }
     }
 }