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

$page_security = 'SA_PROJECT_STATUS_VIEW';
$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/projects/includes/ui/copy_project_tasks_ui.inc"); 
include_once($path_to_root . "/projects/includes/db/copy_project_tasks_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_boq_item_groups_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_items_db.inc");
include_once($path_to_root . "/projects/includes/db/project_boq_item_detail_edit_db.inc");

$js = '';
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();

page(_($help_context = "Copy Project Budgets"), false, false, "", $js);

simple_page_mode(true);

if (isset($_POST["CopyProjectBudgets"])) {
    $msg = handle_copy_project_budget_details_to_another_project(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();

    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[AUST_ADD_ONLY] = "Select all lines";
            custom_values_list_cells("Selection Type:", 'copy_type', $values_array, null, "Manual", true);
            submit_cells('SearchOrders', _("Display"),'',_('Search'), 'process'); 
        end_row();
    end_table(2);

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

        if ($_POST['from_project_id'] > 0) {
            display_copy_project_tasks(get_post('from_project_id'), get_post('to_project_id'), get_post('copy_type'), $line_count);

            submit_center_first("CopyProjectBudgets", "Copy Selected Lines"); 
        }

    div_end();

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

?>