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

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

function update_asset_group($id, $description)
{
    $id_user = $_SESSION['wa_current_user']->user;
    $datetime = date('Y-m-d H:i:s');
        
	$sql = "UPDATE ".TB_PREF."asset_subgroups  
            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 group");
}

function get_all_asset_subgroups($asset_group_id, $all=false)
{
	$sql = "SELECT * FROM ".TB_PREF."asset_subgroups 
            WHERE group_id = ".db_escape($asset_group_id);
    
	if (!$all){ 
            $sql .= " AND  !inactive";        
        }
        
        $sql .= " ORDER BY description ";

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

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

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

	return db_fetch($result);
}

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

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

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

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

?>
