/**
  * Method that edits a a client and returns the result of operation
  * 
  * @param \Library\HttpRequest $rq
  * @return JSON
  */
 public function executeEdit(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     //Load interface to query the database
     $manager = $this->managers->getManagerOf($this->module());
     $result_edit = $manager->edit(\Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Client()), "client_id");
     $result["dataId"] = $this->dataPost["client_id"];
     if ($result_edit) {
         \Applications\PMTool\Helpers\UserHelper::EditUser($this, 'client_id');
         $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetUserSessionProject($this->app()->user(), $this->dataPost["project_id"]);
         $sessionProject[\Library\Enums\SessionKeys::ClientObject] = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Client());
         \Applications\PMTool\Helpers\ProjectHelper::UpdateUserSessionProject($this->app()->user(), $sessionProject);
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Client, "resx_key" => $this->action(), "step" => $result_edit ? "success" : "error"));
 }
 public function executeEdit(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     \Applications\PMTool\Helpers\CommonHelper::SetActiveTab($this->user(), \Applications\PMTool\Resources\Enums\AnalyteTabKeys::FieldTab, \Library\Enums\SessionKeys::TabActiveAnalyte);
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $analyte = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Field_analyte());
     $result["data"] = $analyte;
     $manager = $this->managers->getManagerOf($this->module());
     $result_edit = $manager->edit($analyte, "field_analyte_id");
     if ($result_edit) {
         $analyteMatch = \Applications\PMTool\Helpers\CommonHelper::FindIndexInObjectListById($analyte->field_analyte_id(), "field_analyte_id", $pm, \Library\Enums\SessionKeys::PmFieldAnalytes);
         $pm[\Library\Enums\SessionKeys::PmFieldAnalytes][$analyteMatch["key"]] = $analyte;
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->user(), $pm);
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::FieldAnalyte, "resx_key" => $this->action(), "step" => $result_edit ? "success" : "error"));
 }
 public function executeGetTaskCoc(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     $task_id = intval($this->dataPost["task_id"]);
     //Init PDO
     $task_coc_info = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Task_coc_info());
     $manager = $this->managers->getManagerOf($this->module());
     $result_coc = $manager->selectMany($task_coc_info, "task_id");
     $task_coc_info = count($result_coc) > 0 ? $result_coc[0] : new \Applications\PMTool\Models\Dao\Task_coc_info();
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->user());
     $task_coc_info->setProject_number($sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id());
     $task_coc_info->setResults_to_name($sessionPm[\Library\Enums\SessionKeys::PmObject]->pm_name());
     $task_coc_info->setResults_to_company($sessionPm[\Library\Enums\SessionKeys::PmObject]->pm_comp_name());
     $task_coc_info->setResults_to_address($sessionPm[\Library\Enums\SessionKeys::PmObject]->pm_address());
     $task_coc_info->setResults_to_phone($sessionPm[\Library\Enums\SessionKeys::PmObject]->pm_phone());
     $task_coc_info->setResults_to_email($sessionPm[\Library\Enums\SessionKeys::PmObject]->pm_email());
     $result["task_coc"] = $task_coc_info;
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Task, "resx_key" => $this->action(), "step" => $result_coc !== NULL ? "success" : "error"));
 }
 public function executeIfAllLocationsExist(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     // Init result
     //get current project
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     //get locations of the current project
     $sessionLocations = $sessionProject[\Library\Enums\SessionKeys::ProjectLocations];
     $postData = $this->dataPost();
     $location_names = \Applications\PMTool\Helpers\CommonHelper::StringToArray("\n", $postData["location_names"]);
     //Loop on the names
     $redundantLocs = array();
     foreach ($location_names as $the_locname) {
         $location = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject(array('location_name' => $the_locname), new \Applications\PMTool\Models\Dao\Location());
         $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($location->location_name(), "location_name", $sessionLocations);
         if ($match && !empty($match)) {
             array_push($redundantLocs, $the_locname);
         }
     }
     $result['record_count'] = empty($redundantLocs) ? 0 : count($redundantLocs);
     $result['duplicate_locations'] = $redundantLocs;
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Location, "resx_key" => $this->action(), "step" => $result['record_count'] > 0 ? "success" : "error"));
 }
 public function executeGetList(\Library\HttpRequest $rq, $isNotAjaxCall = FALSE, $pm = NULL)
 {
     // Init result
     $result = $this->InitResponseWS();
     //Init PDO
     $this->dataPost["pm_id"] = $pm === NULL ? NULL : $pm[\Library\Enums\SessionKeys::PmObject]->pm_id();
     $technician = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Technician());
     $result["data"] = $technician;
     //Load interface to query the database for technicians
     $manager = $this->managers->getManagerOf($this->module);
     $pm[\Library\Enums\SessionKeys::PmTechnicians] = $manager->selectMany($technician, "pm_id");
     if ($pm !== NULL) {
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->app()->user(), $pm);
     }
     $result["technicians"] = $pm[\Library\Enums\SessionKeys::PmTechnicians];
     //Can be used for an AJAX call
     if (!$isNotAjaxCall) {
         $step_result = $step_result = $result[\Library\Enums\SessionKeys::UserTechnicianList] !== NULL ? "success" : "error";
         $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Technician, "resx_key" => $this->action(), "step" => $step_result));
     }
 }
 public function executeIfTaskExists(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     // Init result
     $taskSession = \Applications\PMTool\Helpers\TaskHelper::GetSessionTasks($this->user());
     $task = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Task());
     $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($task->task_name(), "task_name", $taskSession, \Library\Enums\SessionKeys::TaskObj);
     $result['record_count'] = !$match || empty($match) ? 0 : 1;
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Task, "resx_key" => $this->action(), "step" => $result['record_count'] > 0 ? "success" : "error"));
 }
 /**
  * Method that edits a facility based on request params and returns the result of operation
  *
  * @param \Library\HttpRequest $rq
  * @return JSON
  */
 public function executeMapEdit(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $db_result = false;
     //load facility for current project
     $facility = $sessionProject[\Library\Enums\SessionKeys::FacilityObject];
     if ($facility !== NULL) {
         //Init PDO
         $facility = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), $facility);
         $result["data"] = $facility;
         $manager = $this->managers->getManagerOf($this->module());
         $result_edit = $manager->edit($facility, "facility_id");
     }
     //Clear the location and facility list from session for the connect PM
     if ($result_edit) {
         $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
         $sessionProject[\Library\Enums\SessionKeys::FacilityObject] = $facility;
         \Applications\PMTool\Helpers\ProjectHelper::UpdateUserSessionProject($this->app()->user(), $sessionProject);
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Facility, "resx_key" => $this->action(), "step" => $result_edit ? "success" : "error"));
 }
 public function executeGetNotes(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     // Init result
     //Get current task
     $currSessTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user());
     //Init data structure
     $data['task_id'] = $currSessTask['task_info_obj']->task_id();
     //Init PDO
     $task_note = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($data, new \Applications\PMTool\Models\Dao\Task_note());
     $manager = $this->managers->getManagerOf($this->module());
     $result_note = $manager->selectMany($task_note, "task_id");
     $result_get = 1;
     $onlyLoggedInUser = $this->dataPost['onlyuser'];
     $userConnected = \Applications\PMTool\Helpers\UserHelper::GetUserConnectedSession($this->user());
     if (!empty($result_note)) {
         $user_arr = array();
         foreach ($result_note as $note_key => $note_obj) {
             $datauser = null;
             if (isset($onlyLoggedInUser) && $onlyLoggedInUser == true && $note_obj->task_note_category_value() != $userConnected->user_value()) {
                 unset($result_note[$note_key]);
             } else {
                 //Fetch user details who posted that note
                 if ($note_obj->task_note_category_type() == 'pm_id') {
                     //Project Manager
                     //Init data structure
                     $datauser['pm_id'] = $note_obj->task_note_category_value();
                     //Init PDO
                     $pm_user = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($datauser, new \Applications\PMTool\Models\Dao\Project_manager());
                     $manager = $this->managers->getManagerOf($this->module());
                     $result_pm_user = $manager->selectMany($pm_user, "pm_id");
                     //Stuff into main array
                     array_push($user_arr, $result_pm_user[0]->pm_name());
                 } else {
                     //Technician
                     //Init data structure
                     $datauser['technician_id'] = $note_obj->task_note_category_value();
                     //Init PDO
                     $tech_user = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($datauser, new \Applications\PMTool\Models\Dao\Technician());
                     $manager = $this->managers->getManagerOf($this->module());
                     $result_tech_user = $manager->selectMany($tech_user, "technician_id");
                     //Stuff into main array
                     array_push($user_arr, $result_tech_user[0]->technician_name());
                 }
             }
         }
         $result_note = array_values($result_note);
         $result_get = 1;
     }
     //cleanup into a nice array
     $result['notes'] = $result_note;
     $result['users'] = !empty($user_arr) ? $user_arr : array();
     //\Applications\PMTool\Helpers\CommonHelper::pr($user_arr);
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::ActiveTask, "resx_key" => $this->action(), "step" => $result_get ? "success" : "error"));
 }
 public function executeIfProviderExists(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     // Init result
     $pmSession = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     //Check if already list exists in Session
     $service = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Service());
     if (!array_key_exists(\Library\Enums\SessionKeys::PmServices, $pmSession)) {
         //No, we have to query db and then populate the list into Session
         $manager = $this->managers->getManagerOf($this->module());
         $allServiceProviders = $manager->selectMany($service, "", true);
         $pmSession[\Library\Enums\SessionKeys::PmServices] = $allServiceProviders;
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->user(), $pmSession);
     }
     //Now check if Service provider already exists
     $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($service->service_name(), "service_name", $pmSession[\Library\Enums\SessionKeys::PmServices]);
     $result['record_count'] = !$match || empty($match) ? 0 : 1;
     //While editing, check if comparing with self
     if (!empty($match) && $service->service_id() !== '') {
         if ($match->service_id() == $service->service_id()) {
             $result['record_count'] = 0;
         }
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Service, "resx_key" => $this->action(), "step" => $result['record_count'] > 0 ? "success" : "error"));
 }
 /**
  * Method that edits a project and facility from map modal
  *
  * @param \Library\HttpRequest $rq
  * @return JSON
  */
 public function executeMapEdit(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     $dataPost = json_decode($this->dataPost["params"], true);
     $sessionProjects = \Applications\PMTool\Helpers\ProjectHelper::GetSessionProjects($this->user());
     if ($dataPost["project"]["project_id"]) {
         $sessionProject = $sessionProjects[\Library\Enums\SessionKeys::ProjectKey . $dataPost["project"]["project_id"]];
         $facility = $sessionProject[\Library\Enums\SessionKeys::FacilityObject];
         $project = $sessionProject[\Library\Enums\SessionKeys::ProjectObject];
     }
     if ($facility !== NULL && $project !== NULL) {
         //Init PDO
         $facility = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($dataPost["facility"], $facility);
         $project = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($dataPost["project"], $project);
         $manager = $this->managers->getManagerOf($this->module());
         $result_edit["facility"] = $manager->edit($facility, "facility_id");
         $manager = $this->managers->getManagerOf("Project");
         $result_edit["project"] = $manager->edit($project, "project_id");
         $result["data"]["facility"] = $facility;
         $result["data"]["project"] = $project;
     }
     //Update this project in session projects list
     if ($result_edit) {
         $sessionProject[\Library\Enums\SessionKeys::ProjectObject] = $project;
         $sessionProject[\Library\Enums\SessionKeys::FacilityObject] = $facility;
         $sessionProjects[\Library\Enums\SessionKeys::ProjectKey . $dataPost["project"]["project_id"]] = $sessionProject;
         \Applications\PMTool\Helpers\ProjectHelper::SetSessionProjects($this->user(), $sessionProjects);
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Project, "resx_key" => $this->action(), "step" => $result_edit ? "success" : "error"));
 }
 /**
  * Method that logout a user from the session and then redirect him to Login page.
  *
  * @param \Library\HttpRequest $rq
  */
 public function executeCreate(\Library\HttpRequest $rq)
 {
     $protect = new \Library\BL\Core\Encryption();
     $data = array("user_login" => $rq->getData("login"), "user_password" => $rq->getData("password"), "user_type" => $rq->getData("type"), "user_role" => \Applications\PMTool\Helpers\UserHelper::GetRoleFromType($rq->getData("type")));
     $user = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($data, new Applications\PMTool\Models\Dao\User());
     $user->setUser_password($protect->Encrypt($this->app->config->get("encryption_key"), $user->user_password()));
     $loginDal = $this->managers->getManagerOf("Login");
     $id = $loginDal->add($pm);
     $redirect = intval($id) > 0 ? TRUE : FALSE;
     if ($redirect) {
         $this->Redirect("login");
     }
 }
 /**
  * Creates a new relation in the "field_analyte_location" table based on 
  * the passed task_id, fa_id. so more or les same as the above method, only
  * iterates over location instead of FAs
  */
 public static function CreateLocationFARelationForFT($caller, $task_id, $fa_id)
 {
     //Get the location data for the task id
     $tlDAO = new \Applications\PMTool\Models\Dao\Task_location();
     $tlDAO->setTask_id($task_id);
     $dal = $caller->managers()->getManagerOf("TaskLocation");
     $relation_data = $dal->selectMany($tlDAO, "task_id");
     //Loop on the above and start preparing data for "field_analyte_location"
     if (count($relation_data) > 0) {
         $manager = $caller->managers()->getManagerOf('FieldAnalyteLocation');
         foreach ($relation_data as $loc_rec) {
             //Check if the relationship is not already existing
             if (!$manager->ifMatrixDataExistsFor($task_id, $loc_rec->location_id(), $fa_id)) {
                 //Add to the "field_analyte_location" table
                 $data = array('task_id' => $task_id, 'location_id' => $loc_rec->location_id(), 'field_analyte_id' => $fa_id, 'field_analyte_location_result' => '');
                 //Init PDO
                 $field_analyte_location = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($data, new \Applications\PMTool\Models\Dao\Field_analyte_location());
                 $result_save_relation = $manager->add($field_analyte_location);
             }
         }
     }
 }
 public function executeEdit(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     //Init PDO
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $this->dataPost["pm_id"] = $pm[\Library\Enums\SessionKeys::PmObject]->pm_id();
     $service = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Service());
     $result["data"] = $service;
     $manager = $this->managers->getManagerOf($this->module);
     $result_edit = $manager->edit($service, "service_id");
     if ($result_edit) {
         $match = \Applications\PMTool\Helpers\CommonHelper::FindIndexInObjectListById($service->service_id(), "service_id", $pm, \Library\Enums\SessionKeys::PmServices);
         $pm[\Library\Enums\SessionKeys::PmServices][$match["key"]] = $service;
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->user(), $pm);
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Service, "resx_key" => $this->action(), "step" => $result_edit ? "success" : "error"));
 }