/**
  * Perform the actions of the page.
  * 
  * The default method sets up a form object to display the form and confirmation pages
  * for the given object.  It handles everything necessary for editing and saving
  * a single object.  Some forms may need to override this if the actions are more complex.
  * Or more simple. 
  */
 protected function action()
 {
     if ($this->user->logged_in) {
         I2CE::raiseError("Attempting to access account verification page while logged in");
         $this->setRedirect('home');
         return true;
     }
     if ($this->request_exists('verify')) {
         $result = $this->verifyAccount($this->request('verify'));
         if ($result) {
             $key = 'verified';
             $message = $this->user->passwordlessLogin($result);
         } else {
             $key = 'not_verified';
         }
         $msg = false;
         I2CE::getConfig()->setIfIsSet($msg, "/modules/RequestAccount-VerifyEmail/user_messages/" . $key);
         if ($msg) {
             $this->userMessage($msg);
         }
         $this->setRedirect('home');
         return true;
         //return $result;
     } else {
         if ($this->request_exists('resend') && $this->request('resend') && $this->isPost()) {
             return $this->resendVerificationEmail();
         } else {
             return parent::action();
         }
     }
 }
 /**
  * Perform the main actions of the page.
  */
 protected function action()
 {
     if ($this->get_exists('health_facility') || $this->post('is_health_facility') == "1") {
         $edit_form = $this->factory->createContainer("facility_institution_edit_fac");
         if ($this->get_exists('health_facility')) {
             $edit_form->getField("health_facility")->setFromDB($this->get('health_facility'));
             $current = $this->search("health_facility", $edit_form->getField("health_facility")->getDBValue());
             $selected = array();
             foreach ($current as $id => $obj) {
                 if ($obj->active == 1) {
                     $selected[] = $obj->getField("training_institution")->getDBValue();
                 }
             }
             $edit_form->getField("training_institution")->setFromDB(implode(",", $selected));
         }
         $this->setObject($edit_form);
     } elseif ($this->get_exists('training_institution') || $this->post('is_training_institution') == "1") {
         $edit_form = $this->factory->createContainer("facility_institution_edit_inst");
         if ($this->get_exists('training_institution')) {
             $edit_form->getField("training_institution")->setFromDB($this->get('training_institution'));
             $current = $this->search("training_institution", $edit_form->getField("training_institution")->getDBValue());
             $selected = array();
             foreach ($current as $id => $obj) {
                 if ($obj->active == 1) {
                     $selected[] = $obj->getField("health_facility")->getDBValue();
                 }
             }
             $edit_form->getField("health_facility")->setFromDB(implode(",", $selected));
         }
         $this->setObject($edit_form);
     }
     parent::action();
     if ($edit_form->getName() == "facility_institution_edit_fac") {
         $this->template->addFile("facility_institution_hf.html", "tbody");
         $this->template->setDisplayData("add_fac_inst", array("type" => 'health_facility', 'id' => $edit_form->getField("health_facility")->getDBValue()));
         $this->template->setDisplayData("facility_institution_header", "Associate Training Institutions with: " . $edit_form->getField("health_facility")->getDisplayValue());
     } elseif ($edit_form->getName() == "facility_institution_edit_inst") {
         $this->template->addFile("facility_institution_ti.html", "tbody");
         $this->template->setDisplayData("add_fac_inst", array("type" => "training_institution", "id" => $edit_form->getField("training_institution")->getDBValue()));
         $this->template->setDisplayData("facility_institution_header", "Associate Health Facilities with: " . $edit_form->getField("training_institution")->getDisplayValue());
     }
 }
 /**
  * Perform the action for this page.
  */
 protected function action()
 {
     if ($this->get_exists('delete') && $this->get('delete') == 1) {
         $parent_id = $this->getPrimary()->getParent();
         $form_id = $this->getPrimary()->getNameId();
         $child_forms = $this->getPrimary()->getChildForms();
         if (count($child_forms) > 0) {
             I2CE::raiseMessage("Tried to delete a child form {$form_id} when there are possible child forms.");
             $message = "This form can not be deleted.";
             I2CE::getConfig()->setIfIsSet($message, "/modules/forms/page_feedback_messages/person_child_delete_not_allowed");
         } else {
             $allowable = false;
             I2CE::getConfig()->setIfIsSet($allowable, "/modules/Person/deleteable_children/" . $this->form_name);
             I2CE::raiseMessage("deleting {$form_id} under {$parent_id} requested by user " . $this->getUser()->getId());
             if ($allowable) {
                 if ($this->checkActionPermission('delete')) {
                     if ($this->getPrimary()->delete()) {
                         $message = "The requested form has been deleted.";
                         I2CE::getConfig()->setIfIsSet($message, "/modules/forms/page_feedback_messages/person_child_delete_success");
                     } else {
                         $message = "An error occurred deleting this form.";
                         I2CE::getConfig()->setIfIsSet($message, "/modules/forms/page_feedback_messages/person_child_delete_fail");
                     }
                 } else {
                     $message = "You do not have permission to delete this form.";
                     I2CE::getConfig()->setIfIsSet($message, "/modules/forms/page_feedback_messages/person_child_delete_not_permitted");
                 }
             } else {
                 $message = "This form can not be deleted.";
                 I2CE::getConfig()->setIfIsSet($message, "/modules/forms/page_feedback_messages/person_child_delete_not_allowed");
             }
         }
         $this->userMessage($message);
         $this->setRedirect("view?id=" . $parent_id);
         return true;
     }
     return parent::action();
 }
 /**
  * Perform the actions of the page.
  * 
  * This handles some special actions because there are three versions of this page:
  * - The list page of all objects that can be edited.
  * - The add/update page for each list object.
  * - The edit form for each list object.
  * 
  * Only in the third case is the parent object action method called since that is the default setup
  * for editing objects used in most other {@link PageForm} objects.
  */
 protected function action()
 {
     if (empty($this->type)) {
         return $this->actionAllLists();
     }
     if (!$this->isPost() && (strlen($this->id) == 0 || $this->id == $this->type . '|0') && !$this->get_exists('add')) {
         if ($this->select_field instanceof I2CE_FormField_MAPPED) {
             if (!$this->actionSelectMapped()) {
                 return false;
             }
         } else {
             if (!$this->actionSelectList()) {
                 return false;
             }
         }
         $this->setDisplayData();
     } else {
         parent::action();
     }
     return true;
 }
 protected function action()
 {
     switch ($this->getAction()) {
         case 'xml':
             header("Content-type: text/xml");
             $children = $this->request_exists('children') && $this->request('children');
             if (!($obj = $this->getPrimary()) instanceof I2CE_Form) {
                 I2CE::raiseError("Bad Object");
                 return false;
             }
             $out = $obj->getXMLRepresentation(false, null, false, $children);
             if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) {
                 I2CE::raiseError("Got errors:\n{$errors}");
             }
             header("Content-disposition: attachment; filename=\"" . $obj->getName() . "_" . $obj->getID() . ".xml");
             echo $out;
             exit(0);
         case 'json':
             header("Content-type: application/json");
             $children = $this->request_exists('children') && $this->request('children');
             if (!($obj = $this->getPrimary()) instanceof I2CE_Form) {
                 I2CE::raiseError("Bad Object");
                 return false;
             }
             $out = json_encode(simplexml_load_string($obj->getXMLRepresentation(false, null, false, $children)));
             if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) {
                 I2CE::raiseError("Got errors:\n{$errors}");
             }
             echo $out;
             exit(0);
         case 'json_small':
             header("Content-type: application/json");
             if (!($obj = $this->getPrimary()) instanceof I2CE_Form) {
                 I2CE::raiseError("Bad Object");
                 return false;
             }
             if ($this->isPost()) {
                 $vals = json_decode($in = file_get_contents('php://input'), true);
                 $out = "{'success':0}";
                 if (is_array($vals)) {
                     if (array_key_exists('id', $vals)) {
                         $obj->setID($vals['id']);
                         $obj->populate();
                     }
                     $ok_fields = $obj->getFieldNames();
                     $ok_fields[] = 'parent';
                     foreach ($vals as $field => $data) {
                         if (!is_string($data) || !in_array($field, $ok_fields) || !($fieldObj = $obj->getField($field)) instanceof I2CE_FormField) {
                             continue;
                         }
                         $fieldObj->setFromDB($data);
                     }
                     I2CE::raiseError("JSON Save:" . $obj->getNameID());
                     $obj->save($this->user);
                     $out = "{'success':1}";
                 }
             } else {
                 $vals = array();
                 $fields = $obj->getFieldNames();
                 $fields = array_merge($fields, array('id', 'parent', 'created', 'last_modified'));
                 foreach ($fields as $field) {
                     if (!($fieldObj = $obj->getField($field)) instanceof I2CE_FormFIeld) {
                         continue;
                     }
                     $vals[$field] = $fieldObj->getDBValue();
                 }
                 $out = json_encode($vals);
             }
             if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) {
                 I2CE::raiseError("Got errors:\n{$errors}");
             }
             echo $out;
             exit(0);
         default:
             return parent::action();
     }
 }
 /**
  * Perform the actions of the page.
  */
 protected function action()
 {
     if (!$this->isPost() && !$this->get_exists('username') && !$this->get_exists('add')) {
         if ($this->hasPermission('task(users_can_edit_all)')) {
             $this->template->addFile("user_list.html");
             $this->listUsersToEdit('user_list');
         } else {
             if ($this->hasPermission('task(users_can_edit)') && I2CE_User::hasDetail('creator')) {
                 $this->template->addFile("user_list.html");
                 $this->listUsersToEdit('user_list', $this->user->username);
             } else {
                 $this->userMessage("You can not edit users", 'notice', false);
                 return false;
             }
         }
     } else {
         parent::action();
     }
 }