<?php
/**********************************************************************
***********************************************************************/
function add_asset_type($code, $description)
{
    $id_user = $_SESSION['wa_current_user']->user;
    $datetime = date('Y-m-d H:i:s');
        
	$sql = "INSERT INTO ".TB_PREF."asset_groups(
                        code, description, 
                        created_by, created_on)                                                    
            VALUES (". db_escape($code).", ".db_escape($description).","
                        . "".db_escape($id_user).", ".db_escape($datetime).")";

    db_query($sql, "could not add asset type");
    return db_insert_id();
 
}

function update_asset_type($id, $description)
{
    $id_user = $_SESSION['wa_current_user']->user;
    $datetime = date('Y-m-d H:i:s');
        
	$sql = "UPDATE ".TB_PREF."asset_groups  
            SET description=".db_escape($description).", 
                updated_by=".db_escape($id_user).", 
                updated_on=".db_escape($datetime)." 
            WHERE id=".db_escape($id);

	db_query($sql, "could not update asset type");
}

function get_all_asset_groups($all=false)
{
	$sql = "SELECT * FROM ".TB_PREF."asset_groups ";
	if (!$all) $sql .= " WHERE !inactive";
        
	$sql .= " ORDER BY description";

	return db_query($sql, "could not get_all_asset_groups");
}

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

	$result = db_query($sql, "could not get asset type");

	return db_fetch($result);
}

function delete_asset_type($id)
{
	$sql="DELETE FROM ".TB_PREF."asset_groups WHERE id=".db_escape($id);

	db_query($sql, "could not delete asset type");
}

function asset_groups_in_assets($selected_id)
{
	$sql="SELECT COUNT(asset_id) FROM ".TB_PREF."asset_master WHERE group_id = ".db_escape($selected_id);

	$result = db_query($sql, "could not query assets");
	$myrow = db_fetch_row($result);
	return ($myrow[0] > 0); 
}

?>
