<?php
/**********************************************************************
***********************************************************************/

function add_shift($shift_name, $day_start,
                        $start_time1, $duration1, 
                        $split_shift,
                        $start_time2, $duration2, 
                        $ot_start_gap,
                        $qualifying_hrs_for_ot, $table1_id, $table2_id, 
                        $no_ot, $inactive)
{
        $created_by = $_SESSION['wa_current_user']->user;
        $created_on = date('Y-m-d H:i:s');
        
        
	$sql = "INSERT INTO ".TB_PREF."shifts (
                    shift_name,day_start,
                    start_time1,duration1,
                    split_shift,
                    start_time2,duration2,
                    ot_start_gap, qualifying_hrs_for_ot, 
                    table1_id, table2_id, 
                    no_ot, inactive,
                    created_by, created_on) 
                VALUES ("
                    .db_escape($shift_name).", ".db_escape($day_start).", "
                    .db_escape($start_time1).", ".db_escape($duration1). ", "
                    .db_escape($split_shift).", "
                    .db_escape($start_time2).", ".db_escape($duration2). ", "
                    .db_escape($ot_start_gap).", ".db_escape($qualifying_hrs_for_ot). ", "
                    .db_escape($table1_id).", ".db_escape($table2_id).", " 
                    .db_escape($no_ot).", ".db_escape($inactive).", "
                    .db_escape($created_by).", ".db_escape($created_on).")";
        
        db_query($sql,"Shift could not be added");


}


function update_shift($rec_id, $shift_name, $day_start,
                        $start_time1, $duration1, 
                        $split_shift,
                        $start_time2, $duration2, 
                        $ot_start_gap,
                        $qualifying_hrs_for_ot, $table1_id, $table2_id, 
                        $no_ot, $inactive)
{

         $updated_by = $_SESSION['wa_current_user']->user;
         $updated_on = date('Y-m-d H:i:s');

        $sql = "UPDATE ".TB_PREF."shifts 
                SET 
                    shift_name=".db_escape($shift_name).",
                    day_start=".db_escape($day_start).",
                    start_time1=".db_escape($start_time1).",
                    duration1 =".db_escape($duration1).",
                    split_shift =".db_escape($split_shift).",
                    start_time2=".db_escape($start_time2).",
                    duration2 =".db_escape($duration2).",
                    ot_start_gap =".db_escape($ot_start_gap).",
                    qualifying_hrs_for_ot =".db_escape($qualifying_hrs_for_ot).",
                    table1_id=".db_escape($table1_id).",
                    table2_id=".db_escape($table2_id).",
                    no_ot=".db_escape($no_ot).",
                    updated_by=".db_escape($updated_by).",
                    updated_on=".db_escape($updated_on)." 
                WHERE id=".db_escape($rec_id);

        db_query($sql,"Shift could not be added");
            
}

function get_shift_details($selected_id)
{
    $sql = "SELECT * 
            FROM 
                ".TB_PREF."shifts  
            WHERE id = ".db_escape($selected_id);
  

    $result = db_query($sql, "Shift could not be retrieved");
    
    return db_fetch($result);
}


function get_shift_records()
{
    $sql = "SELECT s.*, 
            lv1.value_name table1_name,
            lv2.value_name table2_name  
            FROM " 
                .TB_PREF."shifts s, "
                .TB_PREF."list_values lv1, "
                .TB_PREF."list_values lv2
            WHERE s.table1_id = lv1.id AND
            	  s.table2_id = lv2.id 
            ";
  

    return db_query($sql, "Shift could not be retrieved");
}


?>