function setStartWeekDay($value)
 {
     $value = trim($value);
     $upf = new UserPreferenceFactory();
     $key = Option::getByValue($value, $upf->getOptions('start_week_day'));
     if ($key !== FALSE) {
         $value = $key;
     }
     if ($this->Validator->inArrayKey('start_week_day', $value, TTi18n::gettext('Incorrect day to start a week on'), $upf->getOptions('start_week_day'))) {
         $this->data['start_week_day'] = $value;
         return FALSE;
     }
     return FALSE;
 }
Ejemplo n.º 2
0
 function createUserPreference($user_id)
 {
     $upf = new UserPreferenceFactory();
     $upf->setUser($user_id);
     $upf->setDateFormat('d-M-y');
     $upf->setTimeFormat('g:i A');
     $upf->setTimeUnitFormat(10);
     $upf->setTimeZone('PST8PDT');
     $upf->setStartWeekDay(0);
     $upf->setItemsPerPage(25);
     if ($upf->isValid()) {
         $insert_id = $upf->Save();
         Debug::Text('User Preference ID: ' . $insert_id, __FILE__, __LINE__, __METHOD__, 10);
         return $insert_id;
     }
     Debug::Text('Failed Creating User Preference!', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
Ejemplo n.º 3
0
 $pay_period_schedule_options = $ppslf->getByCompanyIDArray($current_company->getId());
 $pglf = new PolicyGroupListFactory();
 $policy_group_options = $pglf->getByCompanyIDArray($current_company->getId());
 $pclf = new PermissionControlListFactory();
 $pclf->getByCompanyIdAndUserId($current_company->getId(), $filter_data['user_ids']);
 $permission_control_user_map = $pclf->getUserToPermissionControlMapArrayByListFactory($pclf);
 $ppslf = new PayPeriodScheduleListFactory();
 $ppslf->getByCompanyIdAndUserId($current_company->getId(), $filter_data['user_ids']);
 $pay_period_schedule_user_map = $ppslf->getUserToPayPeriodScheduleMapArrayByListFactory($ppslf);
 $pglf = new PolicyGroupListFactory();
 $pglf->getByCompanyIdAndUserId($current_company->getId(), $filter_data['user_ids']);
 $policy_group_user_map = $pglf->getUserToPolicyGroupMapArrayByListFactory($pglf);
 $crlf = new CurrencyListFactory();
 $crlf->getByCompanyId($current_company->getId());
 $currency_options = $crlf->getArrayByListFactory($crlf, FALSE, TRUE);
 $upf = new UserPreferenceFactory();
 $language_options = TTi18n::getLanguageArray();
 $date_format_options = $upf->getOptions('date_format');
 $time_format_options = $upf->getOptions('time_format');
 $time_unit_format_options = $upf->getOptions('time_unit_format');
 $timesheet_view_options = $upf->getOptions('timesheet_view');
 $start_week_day_options = $upf->getOptions('start_week_day');
 $time_zone_options = $upf->getOptions('time_zone');
 $uwlf = new UserWageListFactory();
 $uwlf->getLastWageByUserIdAndDate($filter_data['user_ids'], TTDate::getTime());
 if ($uwlf->getRecordCount() > 0) {
     foreach ($uwlf as $uw_obj) {
         $user_wage[$uw_obj->getUser()] = array('type_id' => $uw_obj->getType(), 'type' => Option::getByKey($uw_obj->getType(), $uw_obj->getOptions('type')), 'wage' => $uw_obj->getWage(), 'effective_date' => $uw_obj->getEffectiveDate());
     }
     //var_dump($user_wage);
 }
 function getTimeZoneOptions()
 {
     $upf = new UserPreferenceFactory();
     return $upf->getOptions('time_zone');
 }
Ejemplo n.º 5
0
    $permission->Redirect(FALSE);
    //Redirect
}
$smarty->assign('title', TTi18n::gettext($title = 'New Hire Defaults'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'user_data', 'data_saved')));
if (isset($user_data)) {
    if (isset($user_data['hire_date']) and $user_data['hire_date'] != '') {
        $user_data['hire_date'] = TTDate::parseDateTime($user_data['hire_date']);
    }
}
$uf = new UserFactory();
$upf = new UserPreferenceFactory();
$udlf = new UserDefaultListFactory();
$udf = new UserDefaultFactory();
$action = Misc::findSubmitButton();
switch ($action) {
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        if (isset($user_data['id']) and $user_data['id'] != '') {
            $udf->setId($user_data['id']);
        }
        $udf->setCompany($current_company->getId());
        $udf->setTitle($user_data['title_id']);
        $udf->setCity($user_data['city']);
        $udf->setCountry($user_data['country']);
        $udf->setProvince($user_data['province']);
Ejemplo n.º 6
0
    $permission->Redirect(FALSE);
    //Redirect
}
$smarty->assign('title', TTi18n::gettext($title = 'Employee Preferences'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'user_id', 'incomplete', 'pref_data', 'data_saved')));
$hlf = new HierarchyListFactory();
$permission_children_ids = $hlf->getHierarchyChildrenByCompanyIdAndUserIdAndObjectTypeId($current_company->getId(), $current_user->getId());
//Include current user in list.
if ($permission->Check('user_preference', 'edit_own')) {
    $permission_children_ids[] = $current_user->getId();
}
$upf = new UserPreferenceFactory();
$ulf = new UserListFactory();
$action = Misc::findSubmitButton('action');
switch ($action) {
    case 'submit':
        //Debug::setVerbosity( 11 );
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        if ($pref_data['id'] != '') {
            $upf->setId($pref_data['id']);
        }
        if (isset($pref_data['user_id']) and $pref_data['user_id'] != '') {
            $upf->setUser($pref_data['user_id']);
        } else {
            $upf->setUser($current_user->getId());
        }
        $upf->setLanguage($pref_data['language']);
Ejemplo n.º 7
0
 function postSave()
 {
     $this->removeCache($this->getId());
     if ($this->getDeleted() == FALSE and $this->getPermissionControl() !== FALSE) {
         Debug::text('Permission Group is set...', __FILE__, __LINE__, __METHOD__, 10);
         $pclf = new PermissionControlListFactory();
         $pclf->getByCompanyIdAndUserID($this->getCompany(), $this->getId());
         if ($pclf->getRecordCount() > 0) {
             Debug::text('Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             $pc_obj = $pclf->getCurrent();
             if ($pc_obj->getId() == $this->getPermissionControl()) {
                 $add_permission_control = FALSE;
             } else {
                 Debug::text('Permission Group has changed...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $pulf = new PermissionUserListFactory();
                 $pulf->getByPermissionControlIdAndUserID($pc_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $pulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($pulf->getRecordCount() > 0) {
                     foreach ($pulf as $pu_obj) {
                         Debug::text('Deleteing from Permission Group: ' . $pu_obj->getPermissionControl(), __FILE__, __LINE__, __METHOD__, 10);
                         $pu_obj->Delete();
                     }
                 }
                 $add_permission_control = TRUE;
             }
         } else {
             Debug::text('NOT Already assigned to a Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             $add_permission_control = TRUE;
         }
         if ($this->getPermissionControl() !== FALSE and $add_permission_control == TRUE) {
             Debug::text('Adding user to Permission Group...', __FILE__, __LINE__, __METHOD__, 10);
             //Add to new permission group
             $puf = new PermissionUserFactory();
             $puf->setPermissionControl($this->getPermissionControl());
             $puf->setUser($this->getID());
             if ($puf->isValid()) {
                 $puf->Save();
                 //Clear permission class for this employee.
                 $pf = new PermissionFactory();
                 $pf->clearCache($this->getID(), $this->getCompany());
             }
         }
         unset($add_permission_control);
     }
     if ($this->getDeleted() == FALSE and $this->getPayPeriodSchedule() !== FALSE) {
         Debug::text('Pay Period Schedule is set...', __FILE__, __LINE__, __METHOD__, 10);
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($this->getId());
         if ($ppslf->getRecordCount() > 0) {
             $pps_obj = $ppslf->getCurrent();
             if ($this->getPayPeriodSchedule() == $pps_obj->getId()) {
                 Debug::text('Already assigned to this Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
                 $add_pay_period_schedule = FALSE;
             } else {
                 Debug::text('Changing Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $ppsulf = new PayPeriodScheduleUserListFactory();
                 $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($ppsulf->getRecordCount() > 0) {
                     foreach ($ppsulf as $ppsu_obj) {
                         Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
                         $ppsu_obj->Delete();
                     }
                 }
                 $add_pay_period_schedule = TRUE;
             }
         } else {
             Debug::text('Not assigned to ANY Pay Period Schedule...', __FILE__, __LINE__, __METHOD__, 10);
             $add_pay_period_schedule = TRUE;
         }
         if ($this->getPayPeriodSchedule() !== FALSE and $add_pay_period_schedule == TRUE) {
             //Add to new pay period schedule
             $ppsuf = new PayPeriodScheduleUserFactory();
             $ppsuf->setPayPeriodSchedule($this->getPayPeriodSchedule());
             $ppsuf->setUser($this->getID());
             if ($ppsuf->isValid()) {
                 $ppsuf->Save();
             }
         }
         unset($add_pay_period_schedule);
     }
     if ($this->getDeleted() == FALSE and $this->getPolicyGroup() !== FALSE) {
         Debug::text('Policy Group is set...', __FILE__, __LINE__, __METHOD__, 10);
         $pglf = new PolicyGroupListFactory();
         $pglf->getByUserIds($this->getId());
         if ($pglf->getRecordCount() > 0) {
             $pg_obj = $pglf->getCurrent();
             if ($this->getPolicyGroup() == $pg_obj->getId()) {
                 Debug::text('Already assigned to this Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
                 $add_policy_group = FALSE;
             } else {
                 Debug::text('Changing Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
                 //Remove user from current schedule.
                 $pgulf = new PolicyGroupUserListFactory();
                 $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId());
                 Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                 if ($pgulf->getRecordCount() > 0) {
                     foreach ($pgulf as $pgu_obj) {
                         Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10);
                         $pgu_obj->Delete();
                     }
                 }
                 $add_policy_group = TRUE;
             }
         } else {
             Debug::text('Not assigned to ANY Policy Group...', __FILE__, __LINE__, __METHOD__, 10);
             $add_policy_group = TRUE;
         }
         if ($this->getPolicyGroup() !== FALSE and $add_policy_group == TRUE) {
             //Add to new policy group
             $pguf = new PolicyGroupUserFactory();
             $pguf->setPolicyGroup($this->getPolicyGroup());
             $pguf->setUser($this->getID());
             if ($pguf->isValid()) {
                 $pguf->Save();
             }
         }
         unset($add_policy_group);
     }
     if ($this->getDeleted() == FALSE and $this->getHierarchyControl() !== FALSE) {
         Debug::text('Hierarchies are set...', __FILE__, __LINE__, __METHOD__, 10);
         $hierarchy_control_data = array_unique(array_values((array) $this->getHierarchyControl()));
         //Debug::Arr($hierarchy_control_data, 'Setting hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10);
         if (is_array($hierarchy_control_data)) {
             $hclf = new HierarchyControlListFactory();
             $hclf->getObjectTypeAppendedListByCompanyIDAndUserID($this->getCompany(), $this->getID());
             $existing_hierarchy_control_data = array_unique(array_values((array) $hclf->getArrayByListFactory($hclf, FALSE, TRUE, FALSE)));
             //Debug::Arr($existing_hierarchy_control_data, 'Existing hierarchy control data...', __FILE__, __LINE__, __METHOD__, 10);
             $hierarchy_control_delete_diff = array_diff($existing_hierarchy_control_data, $hierarchy_control_data);
             //Debug::Arr($hierarchy_control_delete_diff, 'Hierarchy control delete diff: ', __FILE__, __LINE__, __METHOD__, 10);
             //Remove user from existing hierarchy control
             if (is_array($hierarchy_control_delete_diff)) {
                 foreach ($hierarchy_control_delete_diff as $hierarchy_control_id) {
                     if ($hierarchy_control_id != 0) {
                         $hulf = new HierarchyUserListFactory();
                         $hulf->getByHierarchyControlAndUserID($hierarchy_control_id, $this->getID());
                         if ($hulf->getRecordCount() > 0) {
                             Debug::text('Deleting user from hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10);
                             $hulf->getCurrent()->Delete();
                         }
                     }
                 }
             }
             unset($hierarchy_control_delete_diff, $hulf, $hclf, $hierarchy_control_id);
             $hierarchy_control_add_diff = array_diff($hierarchy_control_data, $existing_hierarchy_control_data);
             //Debug::Arr($hierarchy_control_add_diff, 'Hierarchy control add diff: ', __FILE__, __LINE__, __METHOD__, 10);
             if (is_array($hierarchy_control_add_diff)) {
                 foreach ($hierarchy_control_add_diff as $hierarchy_control_id) {
                     Debug::text('Hierarchy data changed...', __FILE__, __LINE__, __METHOD__, 10);
                     if ($hierarchy_control_id != 0) {
                         $huf = new HierarchyUserFactory();
                         $huf->setHierarchyControl($hierarchy_control_id);
                         $huf->setUser($this->getId());
                         if ($huf->isValid()) {
                             Debug::text('Adding user to hierarchy control ID: ' . $hierarchy_control_id, __FILE__, __LINE__, __METHOD__, 10);
                             $huf->Save();
                         }
                     }
                 }
             }
             unset($hierarchy_control_add, $huf, $hierarchy_control_id);
         }
     }
     if (isset($this->is_new) and $this->is_new == TRUE) {
         $udlf = new UserDefaultListFactory();
         $udlf->getByCompanyId($this->getCompany());
         if ($udlf->getRecordCount() > 0) {
             Debug::Text('Using User Defaults', __FILE__, __LINE__, __METHOD__, 10);
             $udf_obj = $udlf->getCurrent();
             Debug::text('Inserting Default Deductions...', __FILE__, __LINE__, __METHOD__, 10);
             $company_deduction_ids = $udf_obj->getCompanyDeduction();
             if (is_array($company_deduction_ids) and count($company_deduction_ids) > 0) {
                 foreach ($company_deduction_ids as $company_deduction_id) {
                     $udf = new UserDeductionFactory();
                     $udf->setUser($this->getId());
                     $udf->setCompanyDeduction($company_deduction_id);
                     if ($udf->isValid()) {
                         $udf->Save();
                     }
                 }
             }
             unset($company_deduction_ids, $company_deduction_id, $udf);
             Debug::text('Inserting Default Prefs...', __FILE__, __LINE__, __METHOD__, 10);
             $upf = new UserPreferenceFactory();
             $upf->setUser($this->getId());
             $upf->setLanguage($udf_obj->getLanguage());
             $upf->setDateFormat($udf_obj->getDateFormat());
             $upf->setTimeFormat($udf_obj->getTimeFormat());
             $upf->setTimeUnitFormat($udf_obj->getTimeUnitFormat());
             $upf->setTimeZone($udf_obj->getTimeZone());
             $upf->setItemsPerPage($udf_obj->getItemsPerPage());
             $upf->setStartWeekDay($udf_obj->getStartWeekDay());
             $upf->setEnableEmailNotificationException($udf_obj->getEnableEmailNotificationException());
             $upf->setEnableEmailNotificationMessage($udf_obj->getEnableEmailNotificationMessage());
             $upf->setEnableEmailNotificationHome($udf_obj->getEnableEmailNotificationHome());
             if ($upf->isValid()) {
                 $upf->Save();
             }
         }
     }
     if ($this->getDeleted() == TRUE) {
         //Remove them from the authorization hierarchy, policy group, and pay period schedule.
         //Delete any accruals for them as well.
         //Pay Period Schedule
         $ppslf = new PayPeriodScheduleListFactory();
         $ppslf->getByUserId($this->getId());
         if ($ppslf->getRecordCount() > 0) {
             $pps_obj = $ppslf->getCurrent();
             //Remove user from current schedule.
             $ppsulf = new PayPeriodScheduleUserListFactory();
             $ppsulf->getByPayPeriodScheduleIdAndUserID($pps_obj->getId(), $this->getId());
             Debug::text('Record Count: ' . $ppsulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             if ($ppsulf->getRecordCount() > 0) {
                 foreach ($ppsulf as $ppsu_obj) {
                     Debug::text('Deleteing from Pay Period Schedule: ' . $ppsu_obj->getPayPeriodSchedule(), __FILE__, __LINE__, __METHOD__, 10);
                     $ppsu_obj->Delete();
                 }
             }
         }
         //Policy Group
         $pglf = new PolicyGroupListFactory();
         $pglf->getByUserIds($this->getId());
         if ($pglf->getRecordCount() > 0) {
             $pg_obj = $pglf->getCurrent();
             $pgulf = new PolicyGroupUserListFactory();
             $pgulf->getByPolicyGroupIdAndUserId($pg_obj->getId(), $this->getId());
             Debug::text('Record Count: ' . $pgulf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
             if ($pgulf->getRecordCount() > 0) {
                 foreach ($pgulf as $pgu_obj) {
                     Debug::text('Deleteing from Policy Group: ' . $pgu_obj->getPolicyGroup(), __FILE__, __LINE__, __METHOD__, 10);
                     $pgu_obj->Delete();
                 }
             }
         }
         //Hierarchy
         $hclf = new HierarchyControlListFactory();
         $hclf->getByCompanyId($this->getCompany());
         if ($hclf->getRecordCount() > 0) {
             foreach ($hclf as $hc_obj) {
                 $hf = new HierarchyListFactory();
                 $hf->setUser($this->getID());
                 $hf->setHierarchyControl($hc_obj->getId());
                 $hf->Delete();
             }
             $hf->removeCache(NULL, $hf->getTable(TRUE));
             //On delete we have to delete the entire group.
             unset($hf);
         }
         //Accrual balances
         $alf = new AccrualListFactory();
         $alf->getByUserIdAndCompanyId($this->getId(), $this->getCompany());
         if ($alf->getRecordCount() > 0) {
             foreach ($alf as $a_obj) {
                 $a_obj->setDeleted(TRUE);
                 if ($a_obj->isValid()) {
                     $a_obj->Save();
                 }
             }
         }
     }
     return TRUE;
 }
Ejemplo n.º 8
0
        $data['selected_branch_options'] = Misc::arrayIntersectByKey((array) $data['branch_ids'], $branch_options);
        //Get departments
        $dlf = new DepartmentListFactory();
        $dlf->getByCompanyId($current_company->getId());
        $department_options = $dlf->getArrayByListFactory($dlf, FALSE, TRUE);
        $data['src_department_options'] = Misc::arrayDiffByKey((array) $data['department_ids'], $department_options);
        $data['selected_department_options'] = Misc::arrayIntersectByKey((array) $data['department_ids'], $department_options);
        $uglf = new UserGroupListFactory();
        $group_options = $uglf->getArrayByNodes(FastTree::FormatArray($uglf->getByCompanyIdArray($current_company->getId()), 'TEXT', TRUE));
        $data['src_group_options'] = Misc::arrayDiffByKey((array) $data['group_ids'], $group_options);
        $data['selected_group_options'] = Misc::arrayIntersectByKey((array) $data['group_ids'], $group_options);
        $ulf = new UserListFactory();
        $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), NULL);
        $user_options = $ulf->getArrayByListFactory($ulf, FALSE, TRUE);
        $data['src_include_user_options'] = Misc::arrayDiffByKey((array) $data['include_user_ids'], $user_options);
        $data['selected_include_user_options'] = Misc::arrayIntersectByKey((array) $data['include_user_ids'], $user_options);
        $data['src_exclude_user_options'] = Misc::arrayDiffByKey((array) $data['exclude_user_ids'], $user_options);
        $data['selected_exclude_user_options'] = Misc::arrayIntersectByKey((array) $data['exclude_user_ids'], $user_options);
        $data['group_selection_type_options'] = $sf->getOptions('group_selection_type');
        $data['branch_selection_type_options'] = $sf->getOptions('branch_selection_type');
        $data['department_selection_type_options'] = $sf->getOptions('department_selection_type');
        $data['branch_options'] = Misc::prependArray(array(0 => '-- None --'), $branch_options);
        $data['department_options'] = Misc::prependArray(array(0 => '-- None --'), $department_options);
        $upf = new UserPreferenceFactory();
        $timezone_options = Misc::prependArray(array(0 => '-- None --'), $upf->getOptions('time_zone'));
        $data['time_zone_options'] = $timezone_options;
        $smarty->assign_by_ref('data', $data);
        break;
}
$smarty->assign_by_ref('sf', $sf);
$smarty->display('station/EditStation.tpl');
 function setTimeZone($time_zone)
 {
     $time_zone = trim($time_zone);
     $upf = new UserPreferenceFactory();
     $key = Option::getByValue($time_zone, $upf->getOptions('time_zone'));
     if ($key !== FALSE) {
         $time_zone = $key;
     }
     if ($time_zone == 0 or $this->Validator->inArrayKey('time_zone', $time_zone, TTi18n::gettext('Incorrect Time Zone'), $upf->getOptions('time_zone'))) {
         $this->data['time_zone'] = $time_zone;
         return TRUE;
     }
     return FALSE;
 }