<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_CHANGE_JOB_CARD_OWNER';
$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc"); 
include_once($path_to_root . "/services/includes/ui/change_job_card_owner_ui.inc"); 
include_once($path_to_root . "/services/includes/ui/job_order_repairs_ui.inc"); 
include_once($path_to_root . "/services/includes/db/job_order_repairs_db.inc"); 
include_once($path_to_root . "/services/includes/ui/job_order_entry_ui.inc"); 
include_once($path_to_root . "/services/includes/db/job_orders_db.inc"); 
include_once($path_to_root . "/assets/includes/db/assets_db.inc");   
include_once($path_to_root . "/services/includes/db/job_activities_db.inc"); 
include_once($path_to_root . "/services/includes/ui/job_activities_ui.inc"); 
include_once($path_to_root . "/payroll/includes/db/employees_db.inc");
include_once($path_to_root . "/admin/db/list_values_db.inc"); 

$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();

global $Ajax, $systypes_array;

$type = ST_CHANGE_JOB_CARD_OWNER;

page(_($help_context = $systypes_array[$type]), false, false, "", $js);

simple_page_mode(true);

if (isset($_POST['CHANGE_OWNER'])) {
    $msg = handle_save_change_job_card_owner(input_num('job_order_id'));
        if ($msg['success'] === false) {
            if (isset($msg['focus_to'])) {
                set_focus($msg['focus_to']);
            }
            display_error($msg['message']);
        } else {
            display_notification($msg['message']);
            $Mode = 'RESET';
        }
}

if ($Mode == 'RESET' || isset($_POST['Refresh'])) {
    unset($_POST['next_job_owner_id']);
    unset($_POST['_next_job_owner_id_edit']);
    unset($_POST['department_id']);
    unset($_POST['section_id']);
    
    $Ajax->activate('change_job_card_owner');
}

start_form();

    start_table();
        amount_cells('Job Card #:', 'job_order_id', null, null, null, 0);
        submit_cells('Refresh', 'Refresh', '', false, false, ICON_SUBMIT);
    end_table(2);
    
    $Ajax->activate('job_order_view');
    div_start('job_order_view');
        if (input_num('job_order_id') > 0) {
            $jo_row = get_job_order_record(input_num('job_order_id'));
                if (is_array($jo_row)) {
                    $hd_name = '';
                    if ($jo_row['parent_jo_id'] > 0) {
                        $hd_name = 'Sub';
                    }
                    $tp_name = $systypes_array[ST_JOB_ORDER];

                        display_heading("$hd_name $tp_name #".input_num('job_order_id'));        br();

                        view_job_order_header(input_num('job_order_id'));        br();

                        view_job_order_repairs(input_num('job_order_id'));       br(2);
                } else {
                    display_note('Unknown job card number.', 1, 1);
                }
        } else {
            display_note('Please enter job card id and click on Refresh button.', 1, 2);
        }
    div_end();
    
    $Ajax->activate('change_job_card_owner');
    div_start('change_job_card_owner');
    
        if (isset($jo_row) && is_array($jo_row)) {
            display_heading("Edit Job Card Fields");        br();

            display_change_job_card_owner_control($jo_row);       

            start_table();
                submit_center_first('CHANGE_OWNER', 'Save Changes', 'Save Changes', false, ICON_SUBMIT);
            end_table(2);
        }
        
    div_end();
    
end_form();
end_page();

?>