<?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 . "/estimation/includes/db/est_approve_project_db.inc");
include_once($path_to_root . "/estimation/includes/db/est_projects_db.inc");

include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_groups_db.inc");
include_once($path_to_root . "/estimation/includes/ui/est_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 . "/estimation/includes/ui/est_project_status_view_ui.inc");
include_once($path_to_root . "/estimation/includes/ui/est_approve_project_ui.inc");
include_once($path_to_root . "/includes/approval_functions.inc");
include_once($path_to_root . "/estimation/includes/db/est_project_boq_items_db.inc");

        
$user_comp = user_company();

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

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

if (isset($_POST['est_project_id']))
{
    set_session_variable('Approve_Est_Project_id', $_POST['est_project_id']);
}

$_POST['est_project_id'] = get_session_variable('Approve_Est_Project_id');



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

//    $project = get_project_record($trans_no);
    display_notification_centered($message);

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

    display_footer_exit();
}


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


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

}

if (isset($_POST['Release_Est_Project_For_Approval'])) 
{            
    $project_id = get_session_variable('Approve_Est_Project_id');
    $rpfa_msg = release_est_project_for_approval($project_id);
    if($rpfa_msg['success'] !== true){
        display_error($rpfa_msg['message']);
    }
    else{
        set_session_variable('approve_est_project_messages', $rpfa_msg['message']);
        meta_forward($_SERVER['PHP_SELF'], "Approved_id=$project_id");
    }

}

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

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

start_form(true);
 
$bdget_totals = display_est_project_details($_POST['est_project_id']); 
          
submit_center_first('Recalculate_Est_BOQ_Item_Groups', _("Recalculate BOQ Item Group Summaries"), '', 'default');
echo(get_estimation_trans_view_str(ST_EST_PROJECT_BOQ_ITEM_GROUPS_SUMMARY, $_POST['est_project_id'], "<b>View BOQ Item Group Details</b>"));

br(2);

display_est_component_category_summary($_POST['est_project_id'], $bdget_totals);
            

br(1);

submit_center_first('Release_Est_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']);



?>
