public static function getJSONRecordsData(TS_User &$current_user, array $filter_ar = array())
 {
     // set static variables
     self::$current_user = $current_user;
     self::setFilter($filter_ar);
     // get filtered record id's, and full records when applicable
     $filter_ar['is_in_dienst'] = 1;
     $records_id_ar = TS_DB_HRM_Employees::getFilteredIDs($filter_ar);
     if (!$records_id_ar) {
         return json_encode(array('data' => array()));
     }
     $records_ar = TS_DB_HRM_Employees::getFullRecords($records_id_ar);
     if (!$records_ar) {
         return json_encode(array('data' => array()));
     }
     // check for user rights
     $user_may_edit_employee_presence = $current_user->hasAccess('Personeel Vrij Planning', 'edit_employee_leaves');
     // get presence values for selected period
     $presence_values_id_ar = TS_DB_HRM_PresencePlanning_EmployeePresenceValues::getFilteredIDs(self::$filter_ar);
     if ($presence_values_id_ar) {
         $presence_values_ar = TS_DB_HRM_PresencePlanning_EmployeePresenceValues::getFullRecords($presence_values_id_ar);
     } else {
         $presence_values_ar = array();
     }
     // Process found leaves in dates table, to group by employee
     $employees_presence_values_ar = array();
     foreach ($presence_values_ar as $tmp_presence_value) {
         $tmp_employee_id = $tmp_presence_value['employee_id'];
         $tmp_presence_value_date = $tmp_presence_value['presence_value_date'];
         $employees_presence_values_ar[$tmp_employee_id][$tmp_presence_value_date] = array('num_worked_hours' => $tmp_presence_value['num_worked_hours'], 'presence_value' => $tmp_presence_value['presence_value']);
     }
     //dd::show($employees_presence_values_ar);
     // build return data array
     $data_ar = array();
     foreach ($records_ar as $record) {
         // init variables
         $record_id = $record['id'];
         $record_name = $record['voornaam'] . ' ' . $record['achternaam'];
         $optional_links_ar = array();
         // build cells
         $column_data_ar = array();
         $column_data_ar[] = (int) $record_id;
         $column_data_ar[] = (string) $record_name;
         $column_data_ar[] = (string) $record['function_group_description'];
         // start loop for workdays in selected month/year
         foreach (self::getWorkdays() as $workday_int) {
             $workday_date = date('Y-m-d', $workday_int);
             // determine current value for this employee and date
             $current_value = '';
             if (!empty($employees_presence_values_ar[$record_id][$workday_date])) {
                 if (!empty($employees_presence_values_ar[$record_id][$workday_date]['presence_value'])) {
                     $current_value = $employees_presence_values_ar[$record_id][$workday_date]['presence_value'];
                 } elseif (isset($employees_presence_values_ar[$record_id][$workday_date]['num_worked_hours'])) {
                     $current_value = $employees_presence_values_ar[$record_id][$workday_date]['num_worked_hours'];
                 }
             }
             // get presence cell value, and build cell
             if ($user_may_edit_employee_presence) {
                 $tmp_cell_value = TS_Module_HRM_PresencePlanning_Tables_InlineEditing_PlanningEditing::getPresenceInput($record_id, $workday_date, $current_value);
             } else {
                 $tmp_cell_value = $current_value;
             }
             $tmp_employee_day_span = HTML::Span($tmp_cell_value, '', 'small_rounded_container');
             $tmp_employee_day_span->addStyle('background-color', TS_Module_HRM_PresencePlanning_Constants::getPresenceOptionColor($current_value));
             $column_data_ar[] = (string) $tmp_employee_day_span;
         }
         $data_ar[] = $column_data_ar;
     }
     // return data in JSON format
     return json_encode(array('data' => $data_ar), JSON_HEX_QUOT | JSON_HEX_TAG);
 }
Example #2
0
    case 'set_employee_leave_field_value':
        $selected_leave_id = !empty($_REQUEST['record_id']) ? $_REQUEST['record_id'] : 0;
        $field_name = !empty($_REQUEST['field_name']) ? strtolower($_REQUEST['field_name']) : die;
        $field_value = isset($_REQUEST['field_value']) ? trim($_REQUEST['field_value']) : '';
        if (in_array($field_name, array('leave_start_date', 'leave_end_date')) && !$field_value) {
            $field_value = null;
        }
        die(TS_DB_HRM_PresencePlanning_EmployeeLeaves::update($selected_leave_id, array($field_name => $field_value)));
    case 'ajax_set_employee_presence_value':
        $field_value = isset($_REQUEST['field_value']) ? strtoupper(trim($_REQUEST['field_value'])) : '';
        $pdo_parameters_ar = array('employee_id' => $employee->id, 'presence_value_date' => !empty($_REQUEST['presence_date']) ? $_REQUEST['presence_date'] : null, 'num_worked_hours' => filter_var($field_value, FILTER_SANITIZE_NUMBER_INT), 'presence_value' => in_array($field_value, TS_Module_HRM_PresencePlanning_Constants::getPresenceTextOptions()) ? $field_value : '');
        // delete record when no value is provided, or update otherwise
        if (strlen($field_value) > 0) {
            die(TS_DB_HRM_PresencePlanning_EmployeePresenceValues::store($current_user, $pdo_parameters_ar));
        }
        die(TS_DB_HRM_PresencePlanning_EmployeePresenceValues::destroy($employee->id, $pdo_parameters_ar['presence_value_date']));
    default:
        $show_tabmenu = $show_header = true;
        $page_content_ar[] = HTML::H3('Sorry, de opgevraagde pagina bestaat niet.', '', 'center');
}
// show general page header
if ($show_header) {
    include_once $_SERVER['DOCUMENT_ROOT'] . '/layout/header.php';
    $page_content_ar[] = '</body></html>';
}
// show tabs selection
if ($show_tabmenu) {
    echo TS_Module_HRM_PresencePlanning_TabMenu::get($current_user, CURRENT_PAGE_NAME, $employee);
}
// Show any page content
echo implode('', $page_content_ar);