<?php


function cs_approved_budgets_total_not_updated_records(){
    $sql = "SELECT project_id FROM  ".TB_PREF."projects_master WHERE approved_budgets_total = 0 ";
    return db_query($sql,"cs_approved_budgets_total_not_updated_records");
}

function  cs_update_project_approved_budget($project_id, $approved_budgets_total = 0)
{
    if($approved_budgets_total>0){
        $d=9;
    }
    $sql = "UPDATE ".TB_PREF."projects_master    
            SET approved_budgets_total =".db_escape($approved_budgets_total)." 
            WHERE project_id = ".db_escape($project_id)." AND approved_budgets_total = 0";
    
    db_query($sql,"cs_update_project_approved_budgets_total");
}


function cs_update_project_approved_budgets_total()
{
    $d = cs_approved_budgets_total_not_updated_records();
    while ($row = db_fetch($d)) {
        $budget_details = get_project_tasks_current_budgets_total($row["project_id"]);             
        cs_update_project_approved_budget($row["project_id"], $budget_details['current_budgets_total']);   
    }
}

?>