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

$page_security = 'SA_PROJECT_STATUS_VIEW';
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/data_checks.inc");
//include_once($path_to_root . "/inventory/includes/inventory_db.inc");
include_once($path_to_root . "/projects/includes/db/project_inquiry_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_groups_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_details_view_db.inc");
include_once($path_to_root . "/projects/includes/db/copy_project_boq_item_details_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_material_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_detail_edit_db.inc");

include_once($path_to_root . "/projects/includes/db/project_boq_items_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_costs_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_material_db.inc");
include_once($path_to_root . "/inventory/includes/db/material_groups_db.inc");

include_once($path_to_root . "/projects/includes/db/project_boq_item_assets_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_labour_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_transport_db.inc");

include_once($path_to_root . "/projects/includes/db/projects_db.inc");
include_once($path_to_root . "/projects/includes/db/tasks_db.inc");

//include_once($path_to_root . "/projects/includes/ui/project_boq_item_groups_ui.inc");
include_once($path_to_root . "/projects/includes/ui/copy_project_boq_item_groups_ui.inc");


$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 = "Copy Project BOQ Item Groups"), false, false, "", $js);


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

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

simple_page_mode(true);
//---------------------------------------------------------------------------------------------------


if(isset($_POST["CopyBOQItemDetails"])){
    $msg = handle_copy_BOQ_group(get_post('from_project_id'), get_post('to_project_id'));
    if(!($msg["success"] === true)){
        display_error_cancel($msg["message"]);
    }else{
        display_notification($msg["message"]);
    }
}

global $Ajax;

	start_form();

	br();
    
start_table(TABLESTYLE_NOBORDER);
start_row();
project_list_cells(_("Copy Fropm Project:"), 'from_project_id', null, _('Select a project'), false); 
start_row();
end_row();
project_list_cells(_("Copy To Project:"), 'to_project_id', null, _('Select a project'), false);
//end_row();
//start_row();

//$values_array['ADD_BOQ_COM_DETAILS'] = "Create New Budgets";
//$values_array[AUST_ADD_ONLY] = "Select all lines";
//$values_array[AUST_UPDATE_ONLY] = "Update Existing Only";
//$values_array[AUST_ADD_OR_UPDATE] = "Add and Update ";

//custom_values_list_cells("Selection Type:", 'copy_type', $values_array, null, "Manual", true);

submit_cells('SearchOrders', _("Display"),'',_('Search'), 'process'); 

//	check_cells(_("Show inactive:"), 'show_inactive', null, true);
end_row();
end_table();

br();

$Ajax->activate('proj_boq_details');
div_start('proj_boq_details');
$line_count = 0;

if(isset($_POST['SearchOrders']) || isset($_POST["CopyBOQItemDetails"])){
    hangle_display_project_boq_item_groups(get_post('from_project_id'), get_post('to_project_id'), get_post('copy_type'), $line_count);
}

br();

if($line_count > 0){
    submit_center_first("CopyBOQItemDetails", "Copy Selected Lines"); 
}
    
div_end();

br();


br();
//------------------------------------------------------------------------------------------------



    end_form();
    end_page(@$_GET['popup'], false, false);



?>
