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

$page_security = 'SA_PROJECTS';
$path_to_root = "../..";
include($path_to_root . "/includes/session.inc");
include_once ($path_to_root . "/trace.php");

$js = "";
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();
	
page(_($help_context = "Copy Project Approval Paths"), @$_REQUEST['popup'], false, "", $js);

include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/projects/includes/ui/copy_project_approval_paths_ui.inc"); 
include_once($path_to_root . "/projects/includes/db/project_approval_path_db.inc");
include_once($path_to_root . "/projects/includes/db/projects_db.inc");

if (isset($_POST['SAVE_CPAP'])) {
    $msg = save_copy_project_approval_paths($_POST['to_project_id'], $_POST['from_project_id']);
        if ($msg['success'] === false) {
            if (isset($ms['set_focus'])) {
                set_focus($msg['set_focus']);
            }
            
            display_error($msg['message']);
        } else {
            display_notification($msg['message']);
        }
}

if (isset($_POST['Refresh'])) {
    clear_copy_project_approval_paths($_POST['to_project_id'], $_POST['from_project_id']);
}

start_form(true);

    global $Ajax;

    display_copy_project_approval_path_selection_parameters();

    $Ajax->activate('copy_project_approval_paths');
    div_start('copy_project_approval_paths');
    
        if (! ($_POST['to_project_id'] > 0 && $_POST['from_project_id'] > 0)) {
            display_note('Please select To Project and From Project.', 1, 2, 'style=color:red');
        } elseif ($_POST['to_project_id'] > 0 && $_POST['from_project_id'] > 0 && $_POST['to_project_id'] == $_POST['from_project_id']) {
            display_note('To Project and From Project cannot same.', 1, 2, 'style=color:red');
        } else {
            display_copy_project_approval_path_details($_POST['to_project_id'], $_POST['from_project_id']);
        }

        if ($_POST['to_project_id'] > 0 && $_POST['from_project_id'] > 0) {
            submit_center('SAVE_CPAP', 'Save', true, 'Save Copy Project Approval Paths', false, ICON_SUBMIT);
        }
        
    div_end();
    
end_form(2);

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

?>