<?php
/**********************************************************************
***********************************************************************/
function update_asset_department($selected_id, $department_id, $start_date)
{
    $user = $_SESSION['wa_current_user']->user;
    $date = date('Y-m-d H:i:s');
    
    //if($selected_id != '')
    //{
        $sql = "UPDATE ".TB_PREF."asset_departments 
                SET
                    department_id = ".db_escape($department_id).",                   
                    start_date=".db_escape(date2sql($start_date)).",                   
                    updated_by = ".db_escape($user).",
                    updated_on = ".db_escape($date)."
                WHERE id = ".db_escape($selected_id);
        
        db_query($sql, "Employee Department could not be updated");
    }
//}

function add_asset_department($asset_id, $department_id, $start_date)
{
    $user = $_SESSION['wa_current_user']->user;
    $date = date('Y-m-d H:i:s');
    
        $sql = "INSERT INTO ".TB_PREF."asset_departments
            
                   (asset_id, department_id, start_date, created_by, created_on)  
                          
                     VALUES
                
                (".db_escape($asset_id).","
                  .db_escape($department_id).","
                  .db_escape(date2sql($start_date)).","
                  .db_escape($user).","
                  .db_escape($date).")";  
        
       db_query($sql, "Asset Department could not be added");
       return db_insert_id(); 
       
}
////
function delete_asset_department($selected_id)
{
	$sql="DELETE FROM ".TB_PREF."asset_departments 
              WHERE id=".db_escape($selected_id);

	db_query($sql,"Selected employee department could not be deleted");
}
////
function get_asset_department($selected_id)
{
	$sql="SELECT id,
                     department_id, 
                     start_date
              FROM ".TB_PREF."asset_departments 
              WHERE id=".db_escape($selected_id);

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

function get_all_asset_departments($asset_id) 
{  
        $sql = "SELECT ad.id,
                       ad.department_id, 
                       ad.start_date,
                       lv.value_name
                   
                FROM ".TB_PREF."asset_departments ad, 
                     ".TB_PREF."list_values lv
               
                WHERE ad.department_id = lv.id AND
                      ad.asset_id=".db_escape($asset_id);
        
        return  db_query($sql, "Could not get employee departments");
}

?>