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

function add_workcentre_shifts($workcentre_id, 
                               $start_date, $shift_id, 
                               $saturday_work_time_id, 
                               $sunday_work_time_id)
{
        $created_by = $_SESSION['wa_current_user']->user;
        $created_on = date('Y-m-d H:i:s');
        
	$sql = "INSERT INTO ".TB_PREF."workcentre_shifts(
                        workcentre_id, start_date, 
                        shift_id,saturday_work_time_id, sunday_work_time_id                        
                        ) 
                VALUES ("
                        .db_escape($workcentre_id).", ".db_escape($start_date).", "
                        .db_escape($shift_id).", "
                        .db_escape($saturday_work_time_id).", ".db_escape($sunday_work_time_id).") " ;                       
                        
	db_query($sql,"Workcentre shift could not be added");
}

function update_workcentre_shifts($selected_id, $workcentre_id, 
                                $start_date, $shift_id,  
                                $saturday_work_time_id, $sunday_work_time_id)
{
        $updated_by = $_SESSION['wa_current_user']->user;
        $updated_on = date('Y-m-d H:i:s');
    
        $sql = "UPDATE ".TB_PREF."workcentre_shifts 
                SET 
                    start_date =".db_escape($start_date).",
                    shift_id=".db_escape($shift_id).",                    
                    saturday_work_time_id=".db_escape($saturday_work_time_id).",
                    sunday_work_time_id=".db_escape($sunday_work_time_id)." 
                   
		WHERE id=".db_escape($selected_id)." AND 
                    workcentre_id = ".db_escape($workcentre_id);
        
	db_query($sql,"Workcentre shift could not be updated");
}

function delete_workcentre_shifts($selected_id)
{
	return;
        $sql = "DELETE FROM ".TB_PREF."workcentre_shifts WHERE id=".db_escape($selected_id);
        
	db_query($sql,"could not delete workcentre shift");
}


function get_workcentre_shifts($workcentre_id)
{
   $sql = "SELECT ws.*, 
                    s.shift_name, 
                     wc.description workcentre_name  
            FROM ".TB_PREF."workcentre_shifts AS ws 
                INNER JOIN ".TB_PREF."shifts s ON
                    ws.shift_id = s.id
                INNER JOIN ".TB_PREF."workcentres wc ON
                    ws.workcentre_id = wc.id       
            WHERE ws.workcentre_id  = ".db_escape($workcentre_id)." 
            ORDER BY start_date";
                    
    return db_query($sql, "Workcentre shifts could not be retrieved");
}


function get_workcentre_shifts_details($selected_id)
{
   $sql = "SELECT * FROM ".TB_PREF."workcentre_shifts WHERE id  = ".$selected_id;
                    
    $result =  db_query($sql, "Workcentre shift details could not be retrieved");
    
    return db_fetch($result);
}



?>