<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_APPROVE_PROJECT';
$path_to_root = "..";
include($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/trace.php");
$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(900, 500);
if (user_use_date_picker())
	$js .= get_js_date_picker();
	
page(_($help_context = "Approve Project"), @$_REQUEST['popup'], false, "", $js);

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
;
include_once($path_to_root . "/projects/includes/db/approve_projects_db.inc");
include_once($path_to_root . "/projects/includes/db/project_sites_db.inc");
//include_once($path_to_root . "/projects/includes/db/project_approval_path_db.inc");
//include_once($path_to_root . "/projects/includes/db/project_serial_categories_db.inc");
include_once($path_to_root . "/projects/includes/db/tasks_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc");

include_once($path_to_root . "/projects/includes/db/project_boq_item_groups_db.inc");
include_once($path_to_root . "/projects/includes/ui/project_boq_item_groups_ui.inc");
include_once($path_to_root . "/projects/includes/db/project_task_detail_types_db.inc");
include_once($path_to_root . "/projects/includes/ui/project_status_view_ui.inc");
include_once($path_to_root . "/projects/includes/ui/approve_projects_ui.inc");
include_once($path_to_root . "/includes/approval_functions.inc");

include_once($path_to_root . "/projects/includes/db/approve_projects_db.inc");
include_once($path_to_root . "/projects/includes/db/unapproved_project_budgets_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_billing_schedule_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_expenses_schedule_db.inc");


        
$user_comp = user_company();

//------------------------------------------------------------------------------------

if (isset($_GET['Project_id']))
{
    $_POST['Project_id'] = $_GET['Project_id'];
    set_session_variable('Approve_Project_id', $_POST['Project_id']);
}

if (isset($_POST['Project_id']))
{
    set_session_variable('Approve_Project_id', $_POST['Project_id']);
}

$_POST['Project_id'] = get_session_variable('Approve_Project_id');



if (isset($_GET['Approved_id'])) 
{
    $trans_no = $_GET['Approved_id'];
    
    $message = get_session_variable('approve_project_messages');
    clear_session_variable('approve_project_messages');

    display_notification_centered($message);

    hyperlink_no_params("$path_to_root/projects/inquiry/unapproved_projects_inquiry.php", _("Approve another project."));

    display_footer_exit();
}



function clear_data()
{
    unset($_POST['project_code']);
    unset($_POST['project_name']);
    unset($_POST['company_category_code']);
    unset($_POST['group_serial_no']);
    unset($_POST['company_serial_no']);
    unset($_POST['year']);
    unset($_POST['customer_category_code']);
    unset($_POST['project_category_code']);
    unset($_POST['category_serial_no']);
    unset($_POST['project_start_date']);
    unset($_POST['project_end_date']);
    unset($_POST['project_value']);
    unset($_POST['estimated_cost']);
    unset($_POST['project_manager_id']);
    unset($_POST['long_description']);
    unset($_POST['inactive']); 
    unset($_POST['customer_id']);
    unset($_POST['project_manager_name']);
    unset($_POST['contact_person']);
    unset($_POST['NewProjectID']);
	
}





function approve_selected_project($project_id){
    
//    $project_id = get_session_variable('Approve_Project_id');

        
    
}
	




//------------------------------------------------------------------------------------


if (isset($_POST['Back_To_Originator'])) 
{            
    $project_id = get_session_variable('Approve_Project_id');
    $spbo_msg = send_project_back_to_originator($project_id);
    if($spbo_msg['success'] !== true){
        display_error($spbo_msg['message']);
    }
    else{
        set_session_variable('approve_project_messages', $spbo_msg['message']);
        meta_forward($_SERVER['PHP_SELF'], "Approved_id=$project_id");
    }

}

if (isset($_POST['Release_Project_For_Approval'])) 
{            
    $project_id = get_session_variable('Approve_Project_id');
    $rpfa_msg = release_project_for_approval($project_id);
    if($rpfa_msg['success'] !== true){
        display_error($rpfa_msg['message']);
    }
    else{
        set_session_variable('approve_project_messages', $rpfa_msg['message']);
        meta_forward($_SERVER['PHP_SELF'], "Approved_id=$project_id");
    }

}

if(isset($_POST['Recalculate_BOQ_Item_Groups'])){
    
    recalculate_boq_item_groups(get_post('project_id'));
    display_note("BOQ Item Groups have been recalculated.");    
}



      
//-------------------------------------------------------------------------------------------- 

$from_date = INFINITE_START_DATE;
$to_date = INFINITE_END_DATE;

start_form(true);
 
$bdget_totals = display_project_details($_POST['Project_id'], $from_date, $to_date); 
br(1);
display_project_billing_details($_POST['Project_id']);    
br(2);

display_project_expenses_schedule_details($_POST['Project_id']);
    
br(2);

submit_center_first('Recalculate_BOQ_Item_Groups', _("Recalculate BOQ Item Group Summaries"), '', 'default');
echo(get_project_trans_view_str(ST_PROJECT_BOQ_ITEM_GROUPS_SUMMARY, $_POST['Project_id'], "<b>View BOQ Item Group Details</b>"));

br(2);

display_task_category_summary($_POST['Project_id'], $bdget_totals);
            

br(1);

submit_center_first('Release_Project_For_Approval', "Release for Approval", '', 'default');
submit_center_last('Back_To_Originator', "Back To Originator", '', 'default');

br(2);

hidden('popup', @$_REQUEST['popup']);

end_form();

//------------------------------------------------------------------------------------

end_page(@$_REQUEST['popup']);



?>
