<?php //
/**********************************************************************
***********************************************************************/
function add_competitor($est_project_id,$competitor,$competitor_type,$company_code,$value,$winner,$comment)
{   
    $id_user = $_SESSION['wa_current_user']->user;
    $datetime = date('Y-m-d H:i:s');

    $sql = "INSERT INTO ".TB_PREF."est_project_competitors(
                    est_project_id, competitor,
                    competitor_type, company_code,
                    value,bid_winner,comment,created_by,created_on) 

            VALUES(".db_escape($est_project_id).", "
                    .db_escape($competitor).","
                    .db_escape($competitor_type).","
                    .db_escape($company_code).","
                    .db_escape($value).","
                    .db_escape($winner).","
                    .db_escape($comment).","
                    .db_escape($id_user). ","
                    .db_escape($datetime).")";

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

function update_competitor($selected_id, $competitor, $competitor_type, $company_code,$value, $winner,$comment)
{
    $id_user = $_SESSION['wa_current_user']->user;
    $datetime = date('Y-m-d H:i:s');

    $sql = "UPDATE ".TB_PREF."est_project_competitors 
            SET competitor = ".db_escape($competitor).", 
                competitor_type = ".db_escape($competitor_type).",
                company_code = ".db_escape($company_code).",
                value = ".db_escape($value).", 
                bid_winner = ".db_escape($winner).", 
                comment = ".db_escape($comment).", 
                updated_by = ".db_escape($id_user).", 
                updated_on=".db_escape($datetime)."
                                 
            WHERE id=".db_escape($selected_id);

    db_query($sql,"Competitor 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_competitors($est_project_id)
{
    $sql = "SELECT c.* 
            FROM ".TB_PREF."est_project_competitors c 
                
            WHERE c.est_project_id = ".db_escape($est_project_id);
    
    return db_query($sql,"can not take get_competitors for this project");
    
}

function get_competitor_details($selected_id)
{
	$sql = "SELECT c.* 
                FROM ".TB_PREF."est_project_competitors c 
                     
                WHERE c.id=".db_escape($selected_id);
	
	$result = db_query($sql,"get_competitor_details 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 "";
}

function get_existing_bid_winner($est_project_id,$id)
{
    $sql = "SELECT id
            FROM ".TB_PREF."est_project_competitors
            WHERE bid_winner = 1 
                AND id <> ".db_escape($id)."
                AND est_project_id = ".db_escape($est_project_id);
    
    $result = db_query($sql);
    return db_result_value($result, 'id', 0);
}


?>













































































