<?php
/**********************************************************************
***********************************************************************/
function write_approval_group($selected, $approval_group_code, $approval_group_description)
{
    if($selected > 0 ){
		$sql = "UPDATE ".TB_PREF."approval_group SET
                        approval_group_code = ".db_escape($approval_group_code).",
                        approval_group_description = ".db_escape($approval_group_description)."
                WHERE approval_group_id = ".db_escape($selected);
    }
    else{
		$sql = "INSERT INTO ".TB_PREF."approval_group(
                        approval_group_code,
                        approval_group_description) 
                VALUES( ".db_escape($approval_group_code).","
                        .db_escape($approval_group_description).")";
    }

	db_query($sql,"Could not write_approval_group");
}
////
function delete_approval_group($id)
{
	$sql="DELETE FROM ".TB_PREF."approval_group WHERE approval_group_id=".db_escape($id);

	db_query($sql,"An approval group could not be deleted");
}
////
function get_approval_group_details($id)
{
	$sql="SELECT * FROM ".TB_PREF."approval_group WHERE approval_group_id=".db_escape($id);

	$result = db_query($sql,"An approval group could not be retrieved");

	return db_fetch($result);
}

function get_all_approval_groups() {
    $sql = "SELECT * FROM ".TB_PREF."approval_group";
	//if (!$all) $sql .= " WHERE !inactive";
	//$sql .= " ORDER BY approval_path_name";
    return  db_query($sql, "Could not get approval groups");
}

function get_existing_approval_group_code($approval_group_code, $id)
{
    $sql="SELECT approval_group_code FROM ".TB_PREF."approval_group 
            WHERE approval_group_code = ".db_escape($approval_group_code)." AND 
                    approval_group_id <> ".db_escape($id);

	$result = db_query($sql,"Could not get_existing_approval_group_code");

	return db_fetch($result);
}
?>