Esempio n. 1
0
 static function registerScripts()
 {
     static $loaded = FALSE;
     if ($loaded) {
         return;
     }
     $loaded = TRUE;
     CRM_Core_Resources::singleton()->addSettingsFactory(function () {
         $config = CRM_Core_Config::singleton();
         return array('PseudoConstant' => array('locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'job_hours_time' => CRM_Hrjobcontract_Page_JobContractTab::getJobHoursTime(), 'working_days' => CRM_Hrjobcontract_Page_JobContractTab::getDaysPerTime()), 'FieldOptions' => CRM_Hrjobcontract_Page_JobContractTab::getFieldOptions(), 'jobContractTabApp' => array('contactId' => CRM_Utils_Request::retrieve('cid', 'Integer'), 'domainId' => CRM_Core_Config::domainID(), 'isLogEnabled' => (bool) $config->logging, 'loggingReportId' => CRM_Report_Utils_Report::getInstanceIDForValue('logging/contact/summary'), 'currencies' => CRM_Hrjobcontract_Page_JobContractTab::getCurrencyFormats(), 'defaultCurrency' => $config->defaultCurrency, 'path' => CRM_Core_Resources::singleton()->getUrl('org.civicrm.hrjobcontract'), 'fields' => CRM_Hrjobcontract_Page_JobContractTab::getFields(), 'contractList' => CRM_Hrjobcontract_Page_JobContractTab::getContractList(), 'maxFileSize' => file_upload_max_size()), 'debug' => $config->debug);
     });
 }
Esempio n. 2
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     $this->_jobHoursTime = CRM_Hrjobcontract_Page_JobContractTab::getJobHoursTime();
     $this->assign('jobHoursTime', $this->_jobHoursTime);
     $this->_aid = CRM_Utils_Request::retrieve('aid', 'Int', $this);
     $session = CRM_Core_Session::singleton();
     $this->_loginUserID = $session->get('userID');
     if (CRM_Utils_Request::retrieve('cid', 'Positive', $this)) {
         $this->assign('contactId', CRM_Utils_Request::retrieve('cid', 'Positive', $this));
     }
     $activityTypes = CRM_Core_PseudoConstant::activityType();
     $resultHoliday = civicrm_api3('Activity', 'get', array('activity_type_id' => array_search('Public Holiday', $activityTypes)));
     $publicHolidays = array();
     foreach ($resultHoliday['values'] as $key => $val) {
         $pubDate = date("M j, Y", strtotime($val['activity_date_time']));
         $publicHolidays[$pubDate] = $val['subject'];
     }
     $publicHolidays = json_encode($publicHolidays);
     $this->assign('publicHolidays', $publicHolidays);
     // Load the activity entity
     $main_activity = entity_load_single('civicrm_activity', $this->_aid);
     // Check if attachment is set
     if (isset($main_activity->field_attachment['und'][0]['uri'])) {
         $imgpath = $main_activity->field_attachment['und'][0]['uri'];
         $markup = '<div class="show-attached-file"><div class="show-attached-file-label"><b>' . t('Attached file: ') . '</b></div>' . l("View Attachment", file_create_url($imgpath), array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . '</div>';
     } else {
         $markup = ts('No File Attached!');
     }
     // Assign the attached file URL
     $this->assign('attachedFile', $markup);
     if ($this->_action == CRM_Core_Action::VIEW || $this->_action == CRM_Core_Action::UPDATE) {
         $this->_activityId = CRM_Utils_Request::retrieve('aid', 'String', $this);
         $this->assign('upActivityId', $this->_activityId);
         $resultAct = civicrm_api3('Activity', 'get', array('sequential' => 1, 'id' => $this->_activityId, 'return.target_contact_id' => 1, 'return.assignee_contact_id' => 1, 'return.source_contact_id' => 1, 'option.limit' => 365));
         $this->_activityTypeID = $resultAct['values'][0]['activity_type_id'];
         $this->_targetContactID = $resultAct['values'][0]['target_contact_id'][0];
         $this->_actStatusId = $resultAct['values'][0]['status_id'];
         //condition to check if it has any manager against this absence
         if (array_key_exists(0, $resultAct['values'][0]['assignee_contact_id'])) {
             $this->_managerContactID = self::getManagerContacts($this->_targetContactID);
         }
         //Mode is edit if user has edit or admisniter permission or is manager to this absence or
         //(target/requested user and action is update and has manage own Absence permission)
         //(else mode is view if the action is view or already reviewed) and has (view permission
         //or (manage own absence permission and logged in user is target contact itself)
         $absenceStatuses = CRM_HRAbsence_BAO_HRAbsenceType::getActivityStatus();
         if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Core_Permission::check('edit HRAbsences') || in_array($this->_loginUserID, $this->_managerContactID) || $absenceStatuses[$this->_actStatusId] == 'Requested' && $this->_action == CRM_Core_Action::UPDATE && $this->_targetContactID == $this->_loginUserID && CRM_Core_Permission::check('manage own HRAbsences')) {
             $this->_mode = 'edit';
         } elseif (($this->_action == CRM_Core_Action::VIEW || $absenceStatuses[$this->_actStatusId] != 'Requested') && (CRM_Core_Permission::check('view HRAbsences') || CRM_Core_Permission::check('manage own HRAbsences') && ($this->_targetContactID = $this->_loginUserID))) {
             $this->_mode = 'view';
         }
         //check for ACL View/Edit permission
         if (empty($this->_mode)) {
             if (self::isContactAccessible($this->_targetContactID) == CRM_Core_Permission::EDIT) {
                 $this->_mode = 'edit';
             } elseif (self::isContactAccessible($this->_targetContactID) == CRM_Core_Permission::VIEW) {
                 $this->_mode = 'view';
             }
         }
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_targetContactID);
         $activityTypes = CRM_HRAbsence_BAO_HRAbsenceType::getActivityTypes();
         $activityType = $activityTypes[$this->_activityTypeID];
         $activity = CRM_HRAbsence_BAO_HRAbsenceType::getActivityStatus();
         $activityStatus = $activity[$this->_actStatusId];
         CRM_Utils_System::setTitle(ts("Absence for  %1 (%2, %3)", array(1 => $displayName, 2 => $activityType, 3 => $activityStatus)));
         if ($this->_action == CRM_Core_Action::VIEW) {
             $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeID);
             CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
         } else {
             $this->assign('activityType', $this->_activityTypeID);
             CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeID, 1, 'Activity', $this->_activityId, TRUE);
             $this->assign('customValueCount', $this->_customValueCount);
         }
     } elseif ($this->_action == CRM_Core_Action::ADD) {
         $this->_mode = 'edit';
         CRM_Utils_System::setTitle(ts('Absence Request: Add'));
         $this->_activityTypeID = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
         if ($this->_activityTypeID) {
             //only custom data has preprocess hence directly call it
             $this->assign('activityType', $this->_activityTypeID);
             CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeID, 1, 'Activity', NULL, TRUE);
             $this->assign('customValueCount', $this->_customValueCount);
         }
         $this->_targetContactID = 0;
         if (CRM_Utils_Request::retrieve('cid', 'Positive', $this) !== NULL) {
             $this->_targetContactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
         } else {
             //if there is no cid passed then consider target contact as logged in user
             //who will applying leave for himself
             $this->_targetContactID = $this->_loginUserID;
         }
         $this->_managerContactID = self::getManagerContacts($this->_targetContactID);
     }
     $this->assign('mode', $this->_mode);
     CRM_Core_Resources::singleton()->addStyleFile('org.civicrm.hrabsence', 'css/hrabsence.css');
     parent::preProcess();
 }