public function editAction()
 {
     if (!$this->hasACL('edit_employee')) {
         $this->doNoAccessError();
     }
     $db = $this->dbfunc();
     $status = ValidationContainer::instance();
     $params = $this->getAllParams();
     $id = $params['id'];
     #// restricted access?? only show partners by organizers that we have the ACL to view
     #$org_allowed_ids = allowed_org_access_full_list($this);
     #if ($org_allowed_ids && $this->view->mode != 'add') { // doesnt have acl 'training_organizer_option_all'
     #	$validID = $db->fetchCol("SELECT partner.id FROM partner WHERE partner.id = $id AND partner.organizer_option_id in ($org_allowed_ids)"); // check for both
     #	if(empty($validID))
     #		$this->doNoAccessError ();
     #}
     if ($this->getRequest()->isPost()) {
         //validate then save
         $params['location_id'] = regionFiltersGetLastID('', $params);
         $params['dob'] = $this->_date_to_sql($params['dob']);
         $params['agreement_end_date'] = $this->_date_to_sql($params['agreement_end_date']);
         $params['transition_date'] = $this->_date_to_sql($params['transition_date']);
         $params['transition_complete_date'] = $this->_date_to_sql($params['transition_complete_date']);
         $params['site_id'] = $params['facilityInput'];
         $params['option_nationality_id'] = $params['lookup_nationalities_id'];
         $params['facility_type_option_id'] = $params['employee_site_type_option_id'];
         $status->checkRequired($this, 'first_name', t('Frist Name'));
         $status->checkRequired($this, 'last_name', t('Last Name'));
         $status->checkRequired($this, 'last_name', t('Name'));
         $status->checkRequired($this, 'dob', t('Name'));
         if ($this->setting('display_employee_nationality')) {
             $status->checkRequired($this, 'lookup_nationalities_id', t('Employee Nationality'));
         }
         $status->checkRequired($this, 'employee_qualification_option_id', t('Staff Cadre'));
         if ($this->setting('display_employee_salary')) {
             $status->checkRequired($this, 'salary', t('Salary'));
         }
         if ($this->setting('display_employee_benefits')) {
             $status->checkRequired($this, 'benefits', t('Benefits'));
         }
         if ($this->setting('display_employee_additional_expenses')) {
             $status->checkRequired($this, 'additional_expenses', t('Additional Expenses'));
         }
         if ($this->setting('display_employee_stipend')) {
             $status->checkRequired($this, 'stipend', t('Stipend'));
         }
         if ($this->setting('display_employee_partner')) {
             $status->checkRequired($this, 'partner_id', t('Partner'));
         }
         if ($this->setting('display_employee_sub_partner')) {
             $status->checkRequired($this, 'subpartner_id', t('Sub Partner'));
         }
         if ($this->setting('display_employee_intended_transition')) {
             $status->checkRequired($this, 'employee_transition_option_id', t('Intended Transition'));
         }
         if ($this->setting('display_employee_base') && !$params['employee_base_option_id'] || !$this->setting('display_employee_base')) {
             // either one is OK, javascript disables regions if base is on & has a value choice
             $status->checkRequired($this, 'province_id', t('Region A (Province)'));
         }
         if ($this->setting('display_employee_base')) {
             $status->checkRequired($this, 'employee_base_option_id', t('Employee Based at'));
         }
         if (!$status->hasError()) {
             $id = $this->_findOrCreateSaveGeneric('employee', $params);
             if (!$id) {
                 $status->setStatusMessage(t('That person could not be saved.'));
             } else {
                 # converted to optionlist, link table not needed TODO. marking for removal.
                 #MultiOptionList::updateOptions ( 'employee_to_role', 'employee_role_option', 'employee_id', $id, 'employee_role_option_id', $params['employee_role_option_id'] );
                 $status->setStatusMessage(t('The person was saved.'));
                 $this->_redirect("employee/edit/id/{$id}");
             }
         } else {
             $status->setStatusMessage(t('That person could not be saved.'));
         }
     }
     if ($id && !$status->hasError()) {
         // read data from db
         $sql = 'SELECT * FROM employee WHERE employee.id = ' . $id;
         $row = $db->fetchRow($sql);
         if ($row) {
             $params = $row;
         } else {
             $status->setStatusMessage(t('Error finding that record in the database.'));
         }
         $region_ids = Location::getCityInfo($params['location_id'], $this->setting('num_location_tiers'));
         $region_ids = Location::regionsToHash($region_ids);
         $params = array_merge($params, $region_ids);
         #$params['roles'] = $db->fetchCol("SELECT employee_role_option_id FROM employee_to_role WHERE employee_id = $id");
     }
     // assign form drop downs
     $params['dob'] = formhelperdate($params['dob']);
     $params['agreement_end_date'] = formhelperdate($params['agreement_end_date']);
     $params['transition_date'] = formhelperdate($params['transition_date']);
     $params['transition_complete_date'] = formhelperdate($params['transition_complete_date']);
     $params['courses'] = $this->getCourses($id);
     $params['lookup_nationalities_id'] = $params['option_nationality_id'];
     $params['employee_site_type_option_id'] = $params['facility_type_option_id'];
     $this->viewAssignEscaped('employee', $params);
     $validCHWids = $db->fetchCol("select id from employee_qualification_option qual\r\n\t\t\t\t\t\t\t\t\t\tinner join (select id as success from employee_qualification_option where qualification_phrase in ('Community Based Worker','Community Health Worker','NC02 -Community health workers')) parentIDs\r\n\t\t\t\t\t\t\t\t\t\ton (parentIDs.success = qual.id)");
     $this->view->assign('validCHWids', $validCHWids);
     $this->view->assign('expandCHWFields', !(array_search($params['employee_qualification_option_id'], $validCHWids) === false));
     // i.e $validCHWids.contains($employee[qualification])
     $this->view->assign('status', $status);
     $this->view->assign('pageTitle', $this->view->mode == 'add' ? t('Add Employee') : t('Edit Employee'));
     $this->viewAssignEscaped('locations', Location::getAll());
     $titlesArray = OptionList::suggestionList('person_title_option', 'title_phrase', false, 9999);
     $this->view->assign('titles', DropDown::render('title_option_id', $this->translation['Title'], $titlesArray, 'title_phrase', 'id', $params['title_option_id']));
     $this->view->assign('partners', DropDown::generateHtml('partner', 'partner', $params['partner_id'], false, $this->view->viewonly, false));
     $this->view->assign('subpartners', DropDown::generateHtml('partner', 'partner', $params['subpartner_id'], false, $this->view->viewonly, false, false, array('name' => 'subpartner_id'), true));
     $this->view->assign('bases', DropDown::generateHtml('employee_base_option', 'base_phrase', $params['employee_base_option_id']));
     $this->view->assign('site_types', DropDown::generateHtml('employee_site_type_option', 'site_type_phrase', $params['facility_type_option_id']));
     $this->view->assign('cadres', DropDown::generateHtml('employee_qualification_option', 'qualification_phrase', $params['employee_qualification_option_id']));
     $this->view->assign('categories', DropDown::generateHtml('employee_category_option', 'category_phrase', $params['employee_category_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('fulltime', DropDown::generateHtml('employee_fulltime_option', 'fulltime_phrase', $params['employee_fulltime_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('roles', DropDown::generateHtml('employee_role_option', 'role_phrase', $params['employee_role_option_id'], false, $this->view->viewonly, false));
     #$this->view->assign ( 'roles',       CheckBoxes::generateHtml ( 'employee_role_option', 'role_phrase', $this->view, $params['roles'] ) );
     $this->view->assign('transitions', DropDown::generateHtml('employee_transition_option', 'transition_phrase', $params['employee_transition_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('transitions_complete', DropDown::generateHtml('employee_transition_option', 'transition_phrase', $params['employee_transition_complete_option_id'], false, $this->view->viewonly, false, false, array('name' => 'employee_transition_complete_option_id'), true));
     $helper = new Helper();
     $this->viewAssignEscaped('facilities', $helper->getFacilities());
     $this->view->assign('relationships', DropDown::generateHtml('employee_relationship_option', 'relationship_phrase', $params['employee_relationship_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('referrals', DropDown::generateHtml('employee_referral_option', 'referral_phrase', $params['employee_referral_option_id'], false, $this->view->viewonly, false));
     $this->view->assign('provided', DropDown::generateHtml('employee_training_provided_option', 'training_provided_phrase', $params['employee_training_provided_option_id'], false, $this->view->viewonly, false));
     $employees = OptionList::suggestionList('employee', array('first_name', 'CONCAT(first_name, CONCAT(" ", last_name)) as name'), false, 99999);
     $this->view->assign('supervisors', DropDown::render('supervisor_id', $this->translation['Supervisor'], $employees, 'name', 'id', $params['supervisor_id']));
     $this->view->assign('nationality', DropDown::generateHtml('lookup_nationalities', 'nationality', $params['lookup_nationalities_id'], false, $this->view->viewonly, false));
     $this->view->assign('race', DropDown::generateHtml('person_race_option', 'race_phrase', $params['race_option_id'], false, $this->view->viewonly, false));
 }
Пример #2
0
 public static function dropdown($name, $source, $default = null, array $attributes = array())
 {
     $control = new DropDown($name, $source, $default, $attributes);
     $control->setEscaper(self::$escaper);
     echo $control->render();
 }