public function executeManageServices(\Library\HttpRequest $rq)
 {
     // Set $current_project for breadcrumb
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentProject, $sessionProject[\Library\Enums\SessionKeys::ProjectObject]);
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user());
     //Task tab status
     $tab_status_arr = \Applications\PMTool\Helpers\TaskHelper::TabStatusFor($sessionTask);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_tab_status_keys, $tab_status_arr);
     //Task tab status
     //Analyte Matrix tab status
     $showLabMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Lab');
     $showFieldMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Field');
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_lab_matrix, $showLabMatrixTabs);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_field_matrix, $showFieldMatrixTabs);
     //Analyte Matrix tab status
     \Applications\PMTool\Helpers\TaskHelper::SetActiveTab($this->user(), \Applications\PMTool\Resources\Enums\TaskTabKeys::ServicesTab);
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $pm_services = \Applications\PMTool\Helpers\ServiceHelper::GetPmServices($this, $sessionPm);
     $task_services = \Applications\PMTool\Helpers\ServiceHelper::GetAndStoreTaskServices($this, $sessionTask);
     // filter the pm services after we retrieve the task services
     $pm_services = \Applications\PMTool\Helpers\ServiceHelper::FilterServicesToExcludeTaskServices($pm_services, $task_services);
     $task_services = \Applications\PMTool\Helpers\ServiceHelper::CategorizeTheList($task_services, "service_type");
     $pm_services = \Applications\PMTool\Helpers\ServiceHelper::CategorizeTheList($pm_services, "service_type");
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentPm, $sessionPm[\Library\Enums\SessionKeys::PmObject]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentTask, $sessionTask[\Library\Enums\SessionKeys::TaskObj]);
     $this->page->addVar("HasItemsToDisplay", \Applications\PMTool\Helpers\PmHelper::DoesPmHaveActiveServices($this->user()));
     $data = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => strtolower($this->module()), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::categorized_list_right => $pm_services, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::categorized_list_left => $task_services, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_right => \Applications\PMTool\Helpers\CommonHelper::SetPropertyNamesForDualList(strtolower("service")), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_left => \Applications\PMTool\Helpers\CommonHelper::SetPropertyNamesForDualList(strtolower("service")));
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data, $data);
     //tab status
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::tabStatus, \Applications\PMTool\Helpers\TaskHelper::GetTabsStatus($this->user()));
     //form modules
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::form_modules, $this->app()->router()->selectedRoute()->phpModules());
 }
 /**
  * Method that receives the call from JS Client to login a user
  *
  * @param \Library\HttpRequest $rq: the request
  * @return json object A JSON object with the result bool value and success/error message
  */
 public function executeAuthenticate(\Library\HttpRequest $rq)
 {
     //Initialize the response to error.
     $result = $this->InitResponseWS();
     //Let's retrieve the inputs from AJAX POST request
     $data_sent = $this->dataPost();
     $authProvider = new AuthProvider($this->app->config->get("encryption_key"), $this->managers->getManagerOf('Login'));
     $authProvider->prepareUser($data_sent);
     if ($authProvider->getUser() instanceof \Library\Interfaces\IUser) {
         $this->app->auth->authenticate($authProvider->getUser());
         $this->user->setAttribute(\Library\Enums\SessionKeys::UserTypeObject, $authProvider->getUserType());
         if ($authProvider->getUser()) {
             $user = $this->app->user;
             $routes = array_filter($this->app->router->routes(), function ($route) use($user) {
                 return count($route->role()) == 0 || in_array($user->getRole(), $route->role());
             });
             \Applications\PMTool\Helpers\UserHelper::SaveRoutes($user, $routes);
             switch ($authProvider->getUser()->getType()) {
                 case 'technician_id':
                     \Applications\PMTool\Helpers\TaskHelper::UnsetCurrentSessionTask($this->user);
                     break;
                 case 'pm_id':
                     \Applications\PMTool\Helpers\PmHelper::StoreSessionPm($this, $authProvider->getUserType(), true);
                     break;
             }
             $result = $this->InitResponseWS("success");
             $result['role'] = $user->getRole();
         }
     }
     //return the JSON data
     echo \Library\HttpResponse::encodeJson($result);
 }
 public function executeManageForms(\Library\HttpRequest $rq)
 {
     // Set $current_project for breadcrumb
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user());
     //Task tab status
     $tab_status_arr = \Applications\PMTool\Helpers\TaskHelper::TabStatusFor($sessionTask);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_tab_status_keys, $tab_status_arr);
     //Task tab status
     //Analyte Matrix tab status
     $showLabMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Lab');
     $showFieldMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Field');
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_lab_matrix, $showLabMatrixTabs);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_field_matrix, $showFieldMatrixTabs);
     //Analyte Matrix tab status
     \Applications\PMTool\Helpers\TaskHelper::SetActiveTab($this->user(), \Applications\PMTool\Resources\Enums\TaskTabKeys::FormsTab);
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     //$pm_services = \Applications\PMTool\Helpers\ServiceHelper::GetPmServices($this, $sessionPm);
     $masterForms = \Applications\PMTool\Helpers\FormHelper::GetMasterForms($this, $sessionProject);
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $userForms = \Applications\PMTool\Helpers\FormHelper::GetUserForms($this, $sessionProject);
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     \Applications\PMTool\Helpers\FormHelper::GetProjectForms($this, $sessionProject);
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $projectForms = \Applications\PMTool\Helpers\FormHelper::GetFormsFromProjectForms($this->user(), $sessionProject);
     $taskForms = \Applications\PMTool\Helpers\FormHelper::GetTaskForms($this, $sessionTask);
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user());
     if (isset($projectForms[\Applications\PMTool\Resources\Enums\ViewVariablesKeys::master_forms]) && !empty($projectForms[\Applications\PMTool\Resources\Enums\ViewVariablesKeys::master_forms])) {
         $filteredMasterForms = \Applications\PMTool\Helpers\FormHelper::FilterFormsToExclude($projectForms[\Applications\PMTool\Resources\Enums\ViewVariablesKeys::master_forms], $taskForms, 'master_form_id');
     }
     if (isset($projectForms[\Applications\PMTool\Resources\Enums\ViewVariablesKeys::user_forms]) && !empty($projectForms[\Applications\PMTool\Resources\Enums\ViewVariablesKeys::user_forms])) {
         $filteredUserForms = \Applications\PMTool\Helpers\FormHelper::FilterFormsToExclude($projectForms[\Applications\PMTool\Resources\Enums\ViewVariablesKeys::user_forms], $taskForms, 'user_form_id');
     }
     $taskForms = \Applications\PMTool\Helpers\FormHelper::GetFormsFromTaskForms($this->user(), $sessionProject, $sessionTask);
     //$this->page->addVar("HasItemsToDisplay", \Applications\PMTool\Helpers\PmHelper::DoesPmHaveActiveServices($this->user()));
     if (!empty($filteredMasterForms)) {
         $filteredMasterForms = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::master_forms => $filteredMasterForms);
     } else {
         $filteredMasterForms = array();
     }
     if (!empty($filteredUserForms)) {
         $filteredUserForms = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::user_forms => $filteredUserForms);
     } else {
         $filteredUserForms = array();
     }
     $templateForms = array_merge($filteredUserForms, $filteredMasterForms);
     $data = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => strtolower($this->module()), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::categorized_list_right => $templateForms, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::categorized_list_left => $taskForms, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_right => \Applications\PMTool\Helpers\FormHelper::SetPropertyNamesForDualList(), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_left => \Applications\PMTool\Helpers\FormHelper::SetPropertyNamesForDualList());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data, $data);
     //tab status
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::tabStatus, \Applications\PMTool\Helpers\TaskHelper::GetTabsStatus($this->user()));
     //form modules
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::form_modules, $this->app()->router()->selectedRoute()->phpModules());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentProject, $sessionProject[\Library\Enums\SessionKeys::ProjectObject]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentPm, $sessionPm[\Library\Enums\SessionKeys::PmObject]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentTask, $sessionTask[\Library\Enums\SessionKeys::TaskObj]);
 }
 public function executeServiceDiscussion(\Library\HttpRequest $rq)
 {
     $discussionId = $rq->getData("discussion_id");
     $currentUserObject = $this->user->getAttribute(\Library\Enums\SessionKeys::UserConnected);
     $data["username"] = $rq->getData("username");
     $data["pwd"] = $rq->getData("password");
     $data["encrypted_pwd"] = true;
     //check if user is already logged in and if username and password aren't sent through url
     if ($currentUserObject instanceof \Applications\PMTool\Models\Dao\User && !isset($data["username"]) && !isset($data["pwd"])) {
     } else {
         $authProvider = new \Applications\PMTool\AuthProvider($this->app->config->get("encryption_key"), $this->managers->getManagerOf('Login'));
         $authProvider->prepareUser($data);
         if ($authProvider->getUser() instanceof \Library\Interfaces\IUser) {
             $this->app->auth->authenticate($authProvider->getUser());
             $this->user->setAttribute(\Library\Enums\SessionKeys::UserTypeObject, $authProvider->getUserType());
             if ($authProvider->getUser()) {
                 $user = $this->app->user;
                 $routes = array_filter($this->app->router->routes(), function ($route) use($user) {
                     return count($route->role()) == 0 || in_array($user->getRole(), $route->role());
                 });
                 \Applications\PMTool\Helpers\UserHelper::SaveRoutes($user, $routes);
                 switch ($authProvider->getUser()->getType()) {
                     case 'technician_id':
                         break;
                     case 'pm_id':
                         \Applications\PMTool\Helpers\PmHelper::StoreSessionPm($this, $authProvider->getUserType(), true);
                         break;
                 }
             }
         }
         $currentUserObject = $this->user->getAttribute(\Library\Enums\SessionKeys::UserConnected);
     }
     $discussionArray = \Applications\PMTool\Helpers\DiscussionHelper::GetDiscussionByIdFromDB($this, $discussionId);
     $user = \Applications\PMTool\Helpers\CommonHelper::FindObjectByIntValue(intval($currentUserObject->user_id()), 'user_id', $discussionArray[\Library\Enums\SessionKeys::DiscussionPeople]);
     //check if logged in user is the part of this discussion
     if ($user) {
         \Applications\PMTool\Helpers\DiscussionHelper::SetCurrentDiscussion($this->user, $discussionArray[\Library\Enums\SessionKeys::DiscussionObj], $discussionArray[\Library\Enums\SessionKeys::DiscussionPeople]);
         $currentDiscussion = $discussionArray;
         if ($currentDiscussion) {
             $manager = $this->managers()->getManagerOf('User');
             $discussion_person = \Applications\PMTool\Helpers\CommonHelper::FindObjectByIntValue(1, 'discussion_person_is_author', $currentDiscussion[\Library\Enums\SessionKeys::DiscussionPeople]);
             $discussion_user_type = $manager->selectUserTypeObjectByUserId($discussion_person->user_id());
             if ($discussion_user_type) {
                 $currentDiscussion['comm_with'] = $discussion_user_type;
                 $currentDiscussion['comm_type'] = \Applications\PMTool\Helpers\UserHelper::FindUserTypeFromObject($discussion_user_type);
             }
             $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentDiscussion, $currentDiscussion);
         }
     } else {
         \Applications\PMTool\Helpers\DiscussionHelper::UnsetCurrentDiscussion($this->user);
     }
     $modules = $this->app()->router()->selectedRoute()->phpModules();
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::form_modules, $modules);
 }
 public function executeGetItem(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     $field_analyte_id = intval($this->dataPost["field_analyte_id"]);
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     if (count($pm[\Library\Enums\SessionKeys::PmFieldAnalytes]) > 0) {
         $analyte_selected = \Applications\PMTool\Helpers\CommonHelper::FindIndexInObjectListById($field_analyte_id, "field_analyte_id", $pm, \Library\Enums\SessionKeys::PmFieldAnalytes);
     }
     $result["field_analyte"] = $analyte_selected["object"];
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::FieldAnalyte, "resx_key" => $this->action(), "step" => $analyte_selected !== NULL ? "success" : "error"));
 }
 public function run()
 {
     \Library\Core\Utility\TimeLogger::StartLog($this, \Library\Enums\ResourceKeys\GlobalAppKeys::log_http_request);
     $this->i8n->loadResources();
     $controller = $this->getController();
     //Get add the Project Manager object to the page
     //The variable PM will be available accross the application
     $pmSession = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $controller->page()->addVar('pm', $pmSession[\Library\Enums\SessionKeys::PmObject]);
     $controller->execute();
     $this->httpResponse->setPage($controller->page());
     $this->httpResponse->send();
 }
 public static function GetUserForms($caller, $sessionProject)
 {
     $result = array();
     if ($sessionProject !== NULL) {
         $manager = $caller->managers()->getManagerOf("UserForm");
         $userForm = new \Applications\PMTool\Models\Dao\User_form();
         $projectId = $sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id();
         $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($caller->user());
         $userForm->setPm_id($pm[\Library\Enums\SessionKeys::PmObject]->pm_id());
         $result = $sessionProject[\Library\Enums\SessionKeys::ProjectAvailableForms][\Library\Enums\SessionKeys::ProjectUserForms] = $manager->selectMany($userForm, "pm_id");
         \Applications\PMTool\Helpers\ProjectHelper::SetCurrentSessionProject($caller->user(), $sessionProject);
     }
     return $result;
 }
 public function executeLabMatrix(\Library\HttpRequest $rq)
 {
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     \Applications\PMTool\Helpers\AnalyteHelper::StoreListsData($this);
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user());
     //Task tab status
     $tab_status_arr = \Applications\PMTool\Helpers\TaskHelper::TabStatusFor($sessionTask);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_tab_status_keys, $tab_status_arr);
     //Task tab status
     //Analyte Matrix tab status
     $showLabMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Lab');
     $showFieldMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Field');
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_lab_matrix, $showLabMatrixTabs);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_field_matrix, $showFieldMatrixTabs);
     //Analyte Matrix tab status
     //Get task specific lab analytes
     $task_lab_analytes = \Applications\PMTool\Helpers\AnalyteHelper::GetAndStoreTaskLabAnalytes($this, $sessionTask);
     //Check which page to render
     $pg = is_null($rq->getData('pg')) ? 1 : intval($rq->getData('pg')) == 0 ? 1 : intval($rq->getData('pg'));
     //Calculate pages
     $pages = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::returnTotalPagesOfAnalytes($task_lab_analytes, $this->app);
     //Filter paged result set of analytes
     //$task_lab_analytes = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::returnPagedAnalyteObjects($task_lab_analytes, $pg, $this->app);
     //Fetch ELLIPSIS tooltip settings from xml and pass to view as an array
     $ellipsis_tooltip_settings = \Applications\PMTool\Helpers\PopUpHelper::getTooltipEllipsisSettings('{"targetcontroller":"taskLabAnalyte", "targetaction": "labMatrix"}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::ellipsis_tooltip_settings, $ellipsis_tooltip_settings);
     //Task specific locations
     $project_locations = \Applications\PMTool\Helpers\LocationHelper::GetProjectLocations($this, $sessionProject);
     $task_locations = \Applications\PMTool\Helpers\LocationHelper::GetAndStoreTaskLocations($this, $sessionTask);
     //Get LocationLabMatrix relation
     $id_map = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::GetAnalyteMatrixForTask($this, $sessionTask[\Library\Enums\SessionKeys::TaskObj]->task_id(), 'Lab');
     \Applications\PMTool\Helpers\TaskHelper::SetActiveTab($this->user(), \Applications\PMTool\Resources\Enums\TaskTabKeys::LabSampleMatrixTab);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentProject, $sessionProject[\Library\Enums\SessionKeys::ProjectObject]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentTask, $sessionTask[\Library\Enums\SessionKeys::TaskObj]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::task_locations, $task_locations);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::task_lab_analytes, $task_lab_analytes);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::task_analytes_pages, $pages);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::current_page, $pg);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::task_lab_analytes_idmap, $id_map);
     //tab status
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::tabStatus, \Applications\PMTool\Helpers\TaskHelper::GetTabsStatus($this->user()));
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::form_modules, $this->app()->router()->selectedRoute()->phpModules());
 }
 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 executeListAll(\Library\HttpRequest $rq)
 {
     $tabsStatus = \Applications\PMTool\Helpers\CommonHelper::GetTabsStatus($this->user(), \Library\Enums\SessionKeys::TabActiveAnalyte);
     if ($tabsStatus === NULL) {
         \Applications\PMTool\Helpers\AnalyteHelper::AddTabsStatus($this->user());
         $tabsStatus = \Applications\PMTool\Helpers\CommonHelper::GetTabsStatus($this->user(), \Library\Enums\SessionKeys::TabActiveAnalyte);
     }
     $this->page()->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::tabStatus, $tabsStatus);
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     //Check if a project needs to be selected in order to display this page
     if (!$sessionProject) {
         $this->Redirect(\Library\Enums\ResourceKeys\UrlKeys::ProjectsSelectProject . "?onSuccess=" . \Library\Enums\ResourceKeys\UrlKeys::AnalyteListAll);
     }
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentProject, $sessionProject[\Library\Enums\SessionKeys::ProjectObject]);
     //Fetch tooltip data from xml and pass to view as an array
     $tooltip_array = \Applications\PMTool\Helpers\PopUpHelper::getTooltipMsgForAttribute('{"targetcontroller":"analyte", "targetaction": "list", "targetattr": ["active-fieldanalyte-header","inactive-fieldanalyte-header","active-labanalyte-header","inactive-labanalyte-header"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::tooltip_message, $tooltip_array);
     //Get confirm msg for analyte deletion from showForm screen
     $confirm_msg = \Applications\PMTool\Helpers\PopUpHelper::getConfirmBoxMsg('{"targetcontroller":"analyte", 
             "targetaction": "list", "operation": ["deleteField", "deleteLab", "noAnalyteForProject", 
             "noAnalyteAvailable", "faExists"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::confirm_message, $confirm_msg);
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     if (!isset($pm[\Library\Enums\SessionKeys::PmFieldAnalytes]) && count($pm[\Library\Enums\SessionKeys::PmFieldAnalytes]) > 0) {
         \Applications\PMTool\Helpers\AnalyteHelper::StoreListsData($this);
     }
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     //Fetch prompt box data from xml and pass to view as an array
     $prompt_msg = \Applications\PMTool\Helpers\PopUpHelper::getPromptBoxMsg('{"targetcontroller":"analyte", "targetaction": "listAll", "operation": ["edit"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::prompt_message, $prompt_msg);
     //variables for the field analyte module
     $field_object_properties = \Applications\PMTool\Helpers\CommonHelper::SetDynamicPropertyNamesForDualList("field_analyte", \Applications\PMTool\Helpers\AnalyteHelper::GetListPropertiesForFieldAnalyte());
     $field_analytes = $pm[\Library\Enums\SessionKeys::PmFieldAnalytes];
     $project_field_analytes = \Applications\PMTool\Helpers\AnalyteHelper::FilterAnalytesByProjectAnalytesList($this);
     $field_analytes = \Applications\PMTool\Helpers\CommonHelper::FilterObjectsToExcludeRelatedObject($field_analytes, $project_field_analytes, "field_analyte_id");
     $data_field_analyte = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => "fieldanalyte", \Applications\PMTool\Resources\Enums\ViewVariablesKeys::objects_list_right => $field_analytes, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::objects_list_left => $project_field_analytes, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_right => $field_object_properties, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_left => $field_object_properties);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Analyte::data_field_analyte, $data_field_analyte);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::form_modules, $this->app()->router()->selectedRoute()->phpModules());
 }
 public function executeViewSessionArrays(\Library\HttpRequest $rq)
 {
     $output = array();
     switch ($rq->getData("type")) {
         case "pm":
             $output = var_dump(\Applications\PMTool\Helpers\PmHelper::GetSessionPms($this->user()));
             break;
         case "project":
             $output = var_dump(\Applications\PMTool\Helpers\ProjectHelper::GetSessionProjects($this->user()));
             break;
         case "task":
             $output = var_dump(\Applications\PMTool\Helpers\TaskHelper::GetSessionTasks($this->user()));
             break;
         case "route":
             $output = var_dump($this->user->getAttribute(\Library\Enums\SessionKeys::SessionRoutes));
             break;
         default:
             break;
     }
     echo '<pre>', print_r($output), '</pre>';
     //\Library\HttpResponse::encodeJson($output);
     die;
 }
 public function executeManageTechnicians(\Library\HttpRequest $rq)
 {
     // Set $current_project for breadcrumb
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentProject, $sessionProject[\Library\Enums\SessionKeys::ProjectObject]);
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user());
     //Analyte Matrix tab status
     $showLabMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Lab');
     $showFieldMatrixTabs = \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::DoesAnalytesAndLocationsExistsFor($sessionTask, $this, 'Field');
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_lab_matrix, $showLabMatrixTabs);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_show_field_matrix, $showFieldMatrixTabs);
     //Analyte Matrix tab status
     //Task tab status
     $tab_status_arr = \Applications\PMTool\Helpers\TaskHelper::TabStatusFor($sessionTask);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Task::task_tab_status_keys, $tab_status_arr);
     //Task tab status
     //Fetch tooltip data from xml and pass to view as an array
     $tooltip_array = \Applications\PMTool\Helpers\PopUpHelper::getTooltipMsgForAttribute('{"targetcontroller":"taskTechnician", "targetaction": "list", "targetattr": ["active-taskTechnician-header","inactive-taskTechnician-header"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::tooltip_message, $tooltip_array);
     \Applications\PMTool\Helpers\TaskHelper::SetActiveTab($this->user(), \Applications\PMTool\Resources\Enums\TaskTabKeys::TechniciansTab);
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $pm_technicians = \Applications\PMTool\Helpers\TechnicianHelper::GetPmTechnicians($this, $sessionPm);
     $task_technicians = \Applications\PMTool\Helpers\TechnicianHelper::GetAndStoreTaskTechnicians($this, $sessionTask);
     // filter the pm technicians after we retrieve the task technicians
     $pm_technicians = \Applications\PMTool\Helpers\TechnicianHelper::FilterTechniciansToExcludeTaskTechnicians($pm_technicians, $task_technicians);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentPm, $sessionPm[\Library\Enums\SessionKeys::PmObject]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentTask, $sessionTask[\Library\Enums\SessionKeys::TaskObj]);
     $this->page->addVar("HasItemsToDisplay", \Applications\PMTool\Helpers\PmHelper::DoesPmHaveActiveTechnicians($this->user()));
     $data_left = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => strtolower($this->module()), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::objects_list_left => $task_technicians, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_left => \Applications\PMTool\Helpers\CommonHelper::SetPropertyNamesForDualList(strtolower("technician")));
     $data_right = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => strtolower($this->module()), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::objects_list_right => $pm_technicians, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_right => \Applications\PMTool\Helpers\CommonHelper::SetPropertyNamesForDualList(strtolower("technician")));
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data_left, $data_left);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data_right, $data_right);
     //tab status
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::tabStatus, \Applications\PMTool\Helpers\TaskHelper::GetTabsStatus($this->user()));
     //form modules
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::form_modules, $this->app()->router()->selectedRoute()->phpModules());
 }
 /**
  * Ajax response for auto complete
  * returns JSON of matching service categories
  */
 public function executeGetServiceCategoriesAutoComplete(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     // Init result
     //Get services
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $pm_services = \Applications\PMTool\Helpers\ServiceHelper::GetPmServices($this, $sessionPm, NULL, TRUE);
     $categories = \Applications\PMTool\Helpers\ServiceHelper::GetMatchingServiceCategories($pm_services, $this->dataPost['search']);
     $result['matches'] = $categories;
     $scFound = true;
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Service, "resx_key" => $this->action(), "step" => $scFound ? "success" : "error"));
 }
 public function executeUpdateItems(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     // Init result
     $rows_affected = 0;
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->app()->user());
     //Get the technician objects from ids received
     $technician_ids = str_getcsv($this->dataPost["technician_ids"], ',');
     $matchedElements = $this->FindObjectsFromIds(array("filter" => "technician_id", "ids" => $technician_ids, "objects" => $pm[\Library\Enums\SessionKeys::PmTechnicians]));
     foreach ($matchedElements as $technician) {
         //With the line below, you will update the item $pm[\Library\Enums\SessionKeys::PmTechnicians]
         //Therefore, you just need to save the variable $pm at the end of the processing
         $active = $this->dataPost["action"] === "active" ? TRUE : FALSE;
         $technician->setTechnician_active($active);
         $manager = $this->managers->getManagerOf($this->module);
         $rows_affected += $manager->edit($technician, "technician_id") ? 1 : 0;
         $task_technician = new \Applications\PMTool\Models\Dao\Task_technician();
         $task_technician->setTechnician_id($technician->technician_id());
         $manager = $this->managers->getManagerOf('TaskTechnician');
         $manager->delete($task_technician, 'technician_id');
     }
     if ($rows_affected === count($technician_ids)) {
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->app()->user(), $pm);
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Technician, "resx_key" => $this->action(), "step" => $rows_affected === count($technician_ids) ? "success" : "error"));
 }
 public function executeListTasks(\Library\HttpRequest $rq)
 {
     $modules = $this->app()->router()->selectedRoute()->phpModules();
     \Applications\PMTool\Helpers\DiscussionHelper::UnsetCurrentDiscussion($this->user());
     $technician = $this->user()->getAttribute(\Library\Enums\SessionKeys::UserTypeObject);
     $project = new \Applications\PMTool\Models\Dao\Project();
     $project->setPm_id($technician->pm_id());
     //Load interface to query the database for projects
     $manager = $this->managers->getManagerOf('Project');
     $lists[\Library\Enums\SessionKeys::UserProjects] = $manager->selectMany($project, "pm_id");
     //Load interface to query the database for facilities
     $manager = $this->managers->getManagerOf('Facility');
     $lists[\Library\Enums\SessionKeys::UserProjectFacilityList] = $manager->selectMany($project, "pm_id");
     //Load interface to query the database for clients
     $manager = $this->managers->getManagerOf('Client');
     $lists[\Library\Enums\SessionKeys::UserProjectClientList] = $manager->selectMany($project, "pm_id");
     //SessionPM
     $manager = $this->managers->getManagerOf('Pm');
     $pm = new \Applications\PMTool\Models\Dao\Project_manager();
     $pm->setPm_id($technician->pm_id());
     $pms = $manager->selectMany($pm, 'pm_id');
     \Applications\PMTool\Helpers\PmHelper::StoreSessionPm($this, $pms[0], true);
     $ProjectsSession = \Applications\PMTool\Helpers\ProjectHelper::StoreSessionProjects($this, $lists);
     \Applications\PMTool\Helpers\TaskHelper::GetTasksForTechnician($this, $technician);
     $tasks = \Applications\PMTool\Helpers\TaskHelper::GetSessionTasks($this->user());
     if (!is_array($tasks)) {
         $tasks = array();
     }
     $task_id = $rq->getData("task_id");
     $data = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => 'task', \Applications\PMTool\Resources\Enums\ViewVariablesKeys::objects => \Applications\PMTool\Helpers\CommonHelper::GetObjectListFromSessionArrayBySessionKey($tasks, \Library\Enums\SessionKeys::TaskObj), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties => \Applications\PMTool\Helpers\CommonHelper::SetPropertyNamesForDualList(strtolower('task')));
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data, $data);
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user());
     if ($sessionTask) {
         \Applications\PMTool\Helpers\ProjectHelper::GetAndStoreCurrentProject($this->user(), $sessionTask[\Library\Enums\SessionKeys::TaskObj]->project_id());
     } else {
         $this->user()->unsetAttribute(\Library\Enums\SessionKeys::CurrentProject);
     }
     if (count($tasks) == 1) {
         $firstTask = reset($tasks);
         $task_id = $firstTask[\Library\Enums\SessionKeys::TaskObj]->task_id();
     }
     //Set passed task as current task
     if ($task_id !== '' && !is_null($task_id)) {
         $sessionTask = \Applications\PMTool\Helpers\TaskHelper::SetCurrentSessionTask($this->user(), NULL, $task_id);
         $taskObj = $sessionTask[\Library\Enums\SessionKeys::TaskObj];
         $manager = $this->managers()->getManagerOf('Project');
         $project = new \Applications\PMTool\Models\Dao\Project();
         $project->setProject_id($taskObj->project_id());
         $projects = $manager->selectMany($project, 'project_id');
         if ($projects) {
             \Applications\PMTool\Helpers\ProjectHelper::GetAndStoreCurrentProject($this->user(), $taskObj->project_id());
         }
         //check if we passed a redirect URL too
         if ($rq->getData("onSuccess") !== '' && !is_null($rq->getData("onSuccess"))) {
             //rediect to it
             $this->Redirect($rq->getData("onSuccess"));
         }
     }
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->user);
     if (count($tasks) == 1) {
         $this->Redirect(\Library\Enums\ResourceKeys\UrlKeys::MobileMap);
     }
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentTask, $sessionTask[\Library\Enums\SessionKeys::TaskObj]);
     //Fetch tooltip data from xml and pass to view as an array
     $tooltip_array = \Applications\PMTool\Helpers\PopUpHelper::getTooltipMsgForAttribute('{"targetcontroller":"task", "targetaction": "list", "targetattr": ["active-task-header","inactive-task-header"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::tooltip_message, $tooltip_array);
     //Get confirm msg for project deletion from context menu
     $confirm_msg = \Applications\PMTool\Helpers\PopUpHelper::getConfirmBoxMsg('{"targetcontroller":"task", "targetaction": "list", "operation": ["activate","addUniqueCheck"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::confirm_message, $confirm_msg);
     //Fetch prompt box data from xml and pass to view as an array
     //Also let's just fetch the message for the showForm view and reuse it
     $prompt_msg = \Applications\PMTool\Helpers\PopUpHelper::getPromptBoxMsg('{"targetcontroller":"task", "targetaction": "view", "operation": ["addNullCheck","addNullCheckForCopy"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::prompt_message, $prompt_msg);
     $modules = $this->app()->router()->selectedRoute()->phpModules();
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::active_list, $modules[\Applications\PMTool\Resources\Enums\PhpModuleKeys::active_list]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::popup_msg, $modules[\Applications\PMTool\Resources\Enums\PhpModuleKeys::popup_msg]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::prompt_msg, $modules[\Applications\PMTool\Resources\Enums\PhpModuleKeys::popup_prompt]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::tooltip_message_module, $modules[\Applications\PMTool\Resources\Enums\PhpModuleKeys::tooltip_msg]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentProject, $sessionProject[\Library\Enums\SessionKeys::ProjectObject]);
 }
 public function executeGetList(\Library\HttpRequest $rq, $isNotAjaxCall = FALSE)
 {
     // Init result
     $result = $this->InitResponseWS();
     //Init PDO
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $this->dataPost["pm_id"] = $pm === NULL ? NULL : $pm[\Library\Enums\SessionKeys::PmObject]->pm_id();
     $service = $this->_PrepareServiceObject($this->dataPost());
     $result["data"] = $service;
     //Load interface to query the database for services
     $manager = $this->managers->getManagerOf($this->module);
     $list[\Library\Enums\SessionKeys::PmServices] = $manager->selectMany($service, "pm_id");
     $result["lists"] = $list;
     if ($isNotAjaxCall) {
         return $list;
     } else {
         $step_result = $step_result = $result[\Library\Enums\SessionKeys::PmServices] !== NULL ? "success" : "error";
         $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Service, "resx_key" => $this->action(), "step" => $step_result));
     }
 }
 public static function UpdateTechnicians($caller)
 {
     $result = $caller->InitResponseWS();
     // Init result
     $dataPost = $caller->dataPost();
     $rows_affected = 0;
     //Get the technician objects from ids received
     $result["technician_ids"] = str_getcsv($dataPost["technician_ids"], ',');
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($caller->user());
     $technicians = $sessionPm[\Library\Enums\SessionKeys::PmTechnicians];
     $matchedElements = $caller->FindObjectsFromIds(array("filter" => "technician_id", "ids" => $result["technician_ids"], "objects" => $technicians));
     $result["rows_affected"] = 0;
     foreach ($matchedElements as $technician) {
         $technician->setTechnician_active($dataPost["action"] === "active" ? TRUE : FALSE);
         $manager = $caller->managers()->getManagerOf($caller->module());
         $result["rows_affected"] += $manager->edit($technician, "technician_id") ? 1 : 0;
         self::DeleteTechnician($caller, "TaskTechnician", $technician, "technician_id");
     }
     \Applications\PMTool\Helpers\PmHelper::SetSessionPm($caller->user(), $sessionPm);
     return $result;
 }
 public static function SetCurrentProjectIfPmHasOnlyOneAndReturnProjects(\Library\User $user)
 {
     $projects = \Applications\PMTool\Helpers\ProjectHelper::GetSessionProjects($user);
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($user);
     $project_ids = count($pm[\Library\Enums\SessionKeys::PmProjectIds]) > 0 ? $pm[\Library\Enums\SessionKeys::PmProjectIds] : FALSE;
     if (count($projects) === 1 && $project_ids !== FALSE) {
         \Applications\PMTool\Helpers\ProjectHelper::SetCurrentSessionProject($user, $projects[\Library\Enums\SessionKeys::ProjectKey . $project_ids[0]]);
     } else {
         if (count($projects) > 1 && $project_ids !== FALSE) {
             $project_objects = \Applications\PMTool\Helpers\CommonHelper::GetListObjectsInSessionByKey($user, \Library\Enums\SessionKeys::ProjectObject);
             $project = \Applications\PMTool\Helpers\CommonHelper::FindObjectByIntValue(1, 'project_is_default', $project_objects);
             if ($project !== false) {
                 \Applications\PMTool\Helpers\ProjectHelper::SetCurrentSessionProject($user, $projects[\Library\Enums\SessionKeys::ProjectKey . $project->project_id()]);
             }
         }
     }
     return $projects;
 }
 /**
  * Method that edits a project and returns the result of operation
  * 
  * @param \Library\HttpRequest $rq
  * @return JSON
  */
 public function executeEdit(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     //Init PDO
     $pmSession = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $this->dataPost["pm_id"] = $pmSession === NULL ? NULL : $pmSession[\Library\Enums\SessionKeys::PmObject]->pm_id();
     $project = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Project());
     $result["data"] = $project;
     $result["dataId"] = $project->project_id();
     $manager = $this->managers->getManagerOf($this->module());
     $result_insert = $manager->edit($project, "project_id");
     $this->executeGetItem($rq, $project);
     //\Applications\PMTool\Helpers\ProjectHelper::UpdateUserSessionProject($this->app()->user(), $project);
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Project, "resx_key" => $this->action(), "step" => $result_insert ? "success" : "error"));
 }
 /**
  * Find a pm from an id
  * 
  * @param int $pm_id : the id of the pm to find
  * @return \Applications\PMTool\Models\Dao\Pm $pmMatch : the match
  */
 private function _GetPmFromSession($pm_id)
 {
     $pms = array();
     $pmMatch = NULL;
     $pm = \Applications\PMTool\Helpers\PmHelper::GetSessionPm($this->app->user(), $pm_id);
     $pmMatch = $pm[\Library\Enums\SessionKeys::PmObject];
     return $pmMatch;
 }
 public function executeCommunications(\Library\HttpRequest $rq)
 {
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->user());
     //Check if a project needs to be selected in order to display this page
     if (!$sessionProject) {
         $this->Redirect(\Library\Enums\ResourceKeys\UrlKeys::ProjectsSelectProject . "?onSuccess=" . \Library\Enums\ResourceKeys\UrlKeys::TaskAddPrompt);
     }
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::SetCurrentSessionTask($this->user(), NULL, $rq->getData("task_id"));
     //\Applications\PMTool\Helpers\CommonHelper::pr($sessionTask);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentProject, $sessionProject[\Library\Enums\SessionKeys::ProjectObject]);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentTask, $sessionTask[\Library\Enums\SessionKeys::TaskObj]);
     \Applications\PMTool\Helpers\ActiveTaskHelper::SetActiveTab($this->user(), \Applications\PMTool\Resources\Enums\ActiveTaskTabKeys::ActiveTaskCommTab);
     //Get current Discussion from session and set for view
     $currentDiscussion = \Applications\PMTool\Helpers\DiscussionHelper::GetCurrentDiscussion($this->user);
     if ($currentDiscussion) {
         $manager = $this->managers()->getManagerOf('User');
         $discussion_person = \Applications\PMTool\Helpers\DiscussionHelper::GetOtherDiscussionPerson($this->user(), $currentDiscussion[\Library\Enums\SessionKeys::DiscussionPeople]);
         $discussion_user_type = $manager->selectUserTypeObjectByUserId($discussion_person->user_id());
         if ($discussion_user_type) {
             $currentDiscussion['comm_with'] = $discussion_user_type;
             $currentDiscussion['comm_type'] = \Applications\PMTool\Helpers\UserHelper::FindUserTypeFromObject($discussion_user_type);
         }
         $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::currentDiscussion, $currentDiscussion);
     }
     //Let's get this task specific services
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $pm_services = \Applications\PMTool\Helpers\ServiceHelper::GetPmServices($this, $sessionPm);
     $task_services = \Applications\PMTool\Helpers\ServiceHelper::GetAndStoreTaskServices($this, $sessionTask);
     // filter the pm services after we retrieve the task services
     $pm_services = \Applications\PMTool\Helpers\ServiceHelper::FilterServicesToExcludeTaskServices($pm_services, $task_services);
     //Categorize the list for showing in the list
     $task_services = \Applications\PMTool\Helpers\ServiceHelper::CategorizeTheList($task_services, "service_type");
     //load forms
     $documents = \Applications\PMTool\Helpers\ActiveTaskHelper::GetDocumentsForActiveTask($sessionTask, $this);
     //Set data for frontend
     $data = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => strtolower($this->module()), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::categorized_list_left => $task_services, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_left => \Applications\PMTool\Helpers\CommonHelper::SetPropertyNamesForDualList(strtolower("service")));
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data, $data);
     //use group list right for popup task location form attachments
     $data_right = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => strtolower('document'), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::objects_list_right => $documents, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_right => \Applications\PMTool\Helpers\ActiveTaskHelper::SetPropertyNamesOfDocumentsForDualList());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data_right, $data_right);
     //Similarly let's get the task specific technicians
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $pm_technicians = \Applications\PMTool\Helpers\TechnicianHelper::GetPmTechnicians($this, $sessionPm);
     $task_technicians = \Applications\PMTool\Helpers\TechnicianHelper::GetAndStoreTaskTechnicians($this, $sessionTask);
     // filter the pm technicians after we retrieve the task technicians
     $pm_technicians = \Applications\PMTool\Helpers\TechnicianHelper::FilterTechniciansToExcludeTaskTechnicians($pm_technicians, $task_technicians);
     //\Applications\PMTool\Helpers\CommonHelper::pr($task_technicians);
     //Check if the technician count for this task is only one, if so
     //startComm for this technician
     if (count($task_technicians) === 1 and !$currentDiscussion) {
         //Only one, let's start comm
         \Applications\PMTool\Helpers\ActiveTaskHelper::StartCommunicationWith($this, 'technician_id', $task_technicians[0]->technician_id());
         header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
         exit;
     }
     $data_left = array(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::module => strtolower($this->module()), \Applications\PMTool\Resources\Enums\ViewVariablesKeys::objects_list_left => $task_technicians, \Applications\PMTool\Resources\Enums\ViewVariablesKeys::properties_left => \Applications\PMTool\Helpers\CommonHelper::SetPropertyNamesForDualList(strtolower("technician")));
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::data_left, $data_left);
     //Fetch tooltip data from xml and pass to view as an array
     $tooltip_array = \Applications\PMTool\Helpers\PopUpHelper::getTooltipMsgForAttribute('{"targetcontroller":"activeTask", "targetaction": "communications", "targetattr": ["h4-taskcomm-leftcol-gi", "h4-taskcomm-rightcol-gi","h4-taskcomm-services-gi","h4-taskcomm-technicians-gi"]}', $this->app->name());
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::tooltip_message, $tooltip_array);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::activeTaskTabStatus, \Applications\PMTool\Helpers\ActiveTaskHelper::GetTabsStatus($this->app()->user()));
     $modules = $this->app()->router()->selectedRoute()->phpModules();
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariablesKeys::form_modules, $modules);
     $this->page->addVar(\Applications\PMTool\Resources\Enums\ViewVariables\Popup::popup_prompt_list, $modules['group_list_right']);
 }