<?php //
/**********************************************************************
***********************************************************************/
function add_site($project_id, $site_name,$project_site_status_code,$contact_no,$comment,$inactive)
{   
        $id_user = $_SESSION['wa_current_user']->user;
        $datetime = date('Y-m-d H:i:s');
                
        $sql = "INSERT INTO ".TB_PREF."project_sites (project_id, description,status_code,contact_nos,comments,inactive, created_by, created_on) 
                VALUES (".db_escape($project_id).", "
                .db_escape($site_name).","
                .db_escape($project_site_status_code).","
                .db_escape($contact_no).","
                .db_escape($comment).","
                .db_escape($inactive).","
                .db_escape($id_user). ","
                .db_escape($datetime).")";

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

function update_site($selected_id, $site_name,$project_site_status_code,$contact_no,$comment,$inactive)
{
               $id_user = $_SESSION['wa_current_user']->user;
              $datetime = date('Y-m-d H:i:s');
 $sql = "UPDATE ".TB_PREF."project_sites SET description=".db_escape($site_name).", 
               status_code=".db_escape($project_site_status_code).",       
                          contact_nos=".db_escape($contact_no).",
                          comments=".db_escape($comment).",
                          inactive=".db_escape($inactive).",                                       
                          updated_on=".db_escape($datetime)."
                          WHERE id=".db_escape($selected_id);

       db_query($sql,"Site could not be updated");		
}
//
//function delete_project_site($project_id, $selected_id)
//{
//	$sql="DELETE FROM ".TB_PREF."project_sites WHERE project_id= ".db_escape($project_id).
//                "AND id = ".db_escape($selected_id);
//	db_query($sql,"task could not be deleted");			
//}
//
//
function get_project_sites($project_id)
{
     
        $sql = "SELECT pu.id,
                        pu.description,
                        pu.status_code,
                        pu.contact_nos,
                        pu.comments,
                        lv.value_name
                FROM ".TB_PREF."project_sites pu,                        
                        ".TB_PREF."projects_master pm,
                        ".TB_PREF."list_values as lv
                        WHERE pu.project_id = pm.project_id AND 
                                lv.list_code = 'PROJ_SITE_STATUS' AND lv.value_code=pu.status_code AND 
                                pu.project_id = ".db_escape($project_id);
                    
               
	return db_query($sql,"tasks could not be retreived");
    
}

function get_project_site_details($site_id)
{
	$sql = "SELECT * FROM ".TB_PREF."project_sites WHERE id=".db_escape($site_id);
	
	$result = db_query($sql,"site details could not be retreived");
	
	return db_fetch($result);
}
//function get_task_approval_path($task_id)
//{
//    $sql = "SELECT pt.approval_path_id, ap.approval_path_name 
//                FROM ".TB_PREF."project_tasks pt 
//                    LEFT JOIN ".TB_PREF."approval_path ap ON pt.approval_path_id = ap.approval_path_id 
//                        WHERE pt.task_id = ".  db_escape($task_id);
//    
//    $result = db_query($sql,"approval path could not be retreived");
//    return db_fetch($result);
//}


function get_site_projects($sites_in)
{
    $sql = "SELECT id site_id, project_id, description site_name FROM ".TB_PREF."project_sites WHERE id IN (".$sites_in.")";
	
	return db_query($sql,"Could not get_site_projects");
	
}

function get_project_site_name($project_site_id)
{
	$sql = "SELECT description project_site_name 
            FROM ".TB_PREF."project_sites 
            WHERE id=".db_escape($project_site_id);

	$result = db_query($sql, "could not get_project_site_name");

	if (db_num_rows($result) == 1)
	{
		$row = db_fetch_row($result);
		return $row[0];
	}

	return "";
}

?>