<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_PROJECT_SITES';
if (!@$_GET['popup'])
	$path_to_root = "../..";
else	
	$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
include_once($path_to_root . "/includes/ui.inc");

//include_once($path_to_root . "/includes/ui/ui_lists_estimation.inc");

//include_once($path_to_root . "/includes/custom_scripts/custom_script_copy_budgets_to_boq_items.inc");
include_once($path_to_root . "/estimation/includes/est_copy_est_project_to_another_est_project_ui.inc");
include_once($path_to_root . "/estimation/includes/db/est_copy_est_project_to_another_est_project_db.inc");
include_once($path_to_root . "/includes/ui/ui_lists_estimation.inc");
include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_groups_db.inc");
include_once($path_to_root . "/estimation/includes/db/est_project_boq_items_db.inc");

include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_groups_db.inc");
include_once($path_to_root . "/estimation/includes/db/est_project_boq_items_db.inc");
include_once($path_to_root . "/estimation/includes/ui/est_project_boq_item_groups_ui.inc");
include_once($path_to_root . "/estimation/includes/ui/est_project_boq_items_ui.inc");
include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_detail_edit_db.inc");


include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_costs_db.inc");
//include_once($path_to_root . "/projects/includes/db/project_boq_item_costs_db.inc");

include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_material_db.inc");
//include_once($path_to_root . "/projects/includes/db/project_boq_item_material_db.inc");

include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_labour_db.inc");
//include_once($path_to_root . "/projects/includes/db/project_boq_item_labour_db.inc");

include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_assets_db.inc");
//include_once($path_to_root . "/projects/includes/db/project_boq_item_assets_db.inc");

include_once($path_to_root . "/estimation/includes/db/est_project_boq_item_transport_db.inc");
//include_once($path_to_root . "/projects/includes/db/project_boq_item_transport_db.inc");


$js = '';

if (user_use_date_picker()) {
    
        $js .= get_js_date_picker();
}

if (!@$_GET['popup'])
        page(_($help_context = "Copy Estimation Project to Another Estimation Project"),false,false,"",$js);

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

check_db_has_projects(_("There are no projects defined in the system."));

simple_page_mode(true);
//---------------------------------------------------------------------------------------------------
$input_error = 0;

if (isset($_GET['project_id']))
{
	$_POST['project_id'] = $_GET['project_id'];
}

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

//function can_process($Mode)
//{
//    
//        if(empty('competitor')){
//            display_error("Please enter a competitor.");
//            set_focus('competitor');
//            return false;
//        }
//    
//    
//    $inv = $_POST['value'];
//    if (!($inv > 0))
//    {
//        display_error(_("Value can not be minus."));
//        set_focus('value');
//        return false;
//    } 
//
//    if($_POST['bid_winner'] == 1){
//        
//        if(!isset($_POST['id'])){
//            $_POST['id'] = 0;
//        }
//        $existed_winner = get_existing_bid_winner($_POST['est_project_id'],$_POST['id']);
//        if ($existed_winner > 0 )
//        {
//            display_error(_("Bid Winner already added can not add again."));
//            set_focus('bid_winner');
//            return false;
//        } 
//    }
//    
//    return true;
//    
//}
//----------------------------------------------------------------------------------------------------

//$est_project_id = get_post('est_project_id');
//
//if ($Mode=='ADD_ITEM') 
//{             
//    if(can_process($Mode)){
//        add_competitor($_POST['est_project_id'], $_POST['competitor'], input_num('value'),$_POST['bid_winner'],$_POST['comment']);            
//        $msg = _("The new competitor has been added.");
//             
//        clear_competitor_data();
//        $msg = _("Competitor has been added.");
//
//        display_notification($msg);
//        $Mode = 'RESET';  
//    }
//}
//
if (isset($_POST['COPY_PROJECT'])) 
{
//    if(can_process($Mode)){
    $msg = copy_est_project_to_another_est_project($_POST['from_est_project_id'], $_POST['filtering_est_group_id'], $_POST['to_est_project_id']);
    
    if($msg["success"] !== true){
        display_error($msg['message']);
    }
    else{
        display_notification($msg['message']);
    }
        
//    }
}
br(2);

if ($Mode == 'RESET')
{
	$selected_id = -1;
}

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

start_form();

br(2);   
    
start_table(TABLESTYLE_NOBORDER);
start_row();
est_project_list_cells(_("Estimation Project From:"), 'from_est_project_id', null, _('Select an Estimated Project'), true);
end_row();

$from_est_project_id = $_POST['from_est_project_id'];

start_row();
est_project_boq_item_groups_list_cells("BOQ Item Group:", 'filtering_est_group_id', $from_est_project_id, null,  _('Select a BOQ Item Group'), true);
end_row();
end_table();

br(5);

start_table(TABLESTYLE_NOBORDER);
start_row();
est_project_list_cells(_("Estimation Project To:"), 'to_est_project_id', null, _('Select an Estimated Project'), true);
end_row();
end_table();

br();


submit_center("COPY_PROJECT", "Copy Project");


if (!@$_GET['popup'])
{
	end_form();
	end_page(@$_GET['popup'], false, false);
}	
?>































































































































































































































