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

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/payroll/includes/payroll_db.inc");

include_once($path_to_root . "/payroll/includes/payroll_calculation.inc");
include_once($path_to_root . "/payroll/includes/db/payroll_calculation_db.inc");
include_once($path_to_root . "/jobq/includes/jobq_requests.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 = "Payroll Run"));

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

$jobq_request_id = 0;
if(isset($_GET['jobq_request_id'])){
    $jobq_request_id = $_GET['jobq_request_id'];
}
        
$run = false;



if (isset($_GET['AddedID'])) 
{
	$trans_no = $_GET['AddedID'];
        
        display_notification_centered("Request $trans_no has been reprocessed");
        
	display_footer_exit();
}




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


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

if (isset($_POST['_selected_id_update']) )
{
	$selected_id = $_POST['selected_id'];
	$Ajax->activate('_page_body');
}

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

if (isset($_POST['resubmit_jobq_request']) )
{
        
        $submitted_by = $_SESSION['wa_current_user']->user;

        process_jobq_request($_POST['jobq_request_id']);

        meta_forward($_SERVER['PHP_SELF'], "AddedID=".$_POST['jobq_request_id']);

}


if (!@$_GET['popup'])
	start_form();


br();	

    div_end();

////-----------------------------------------------------------------------------------------------
//    $_POST['id'] = 0;
//    $_POST['payroll_id'] = "";
//    $_POST['payroll_name'] = "";
//    $_POST['description'] = "";
//    $_POST['period_start_date'] = 0;
//    $_POST['period_end_date'] = 0;
//    $_POST['tran_date'] = 0;
//    
//

$jq_row = view_jobq_request($jobq_request_id);

start_table(TABLESTYLE2);

global $systypes_array, $jobq_request_statues ;

if($jq_row){
        label_row("Job Queue Request Id", $jobq_request_id);
        label_row("Type", $systypes_array[$jq_row['type']]);
        label_row("Description", $jq_row['description']);
        label_row("Submitted By", $jq_row['submitted_user_name']);
        label_row("Submitted On", $jq_row['submitted_on']);
        label_row("Started On", $jq_row['started_on']);
        label_row("Ststus", $jobq_request_statues[$jq_row['status_id']]);
        label_row("Comments", $jq_row['comments']);
}

//$_POST['jobq_request_id'] = $jobq_request_id;
hidden('jobq_request_id', $jobq_request_id);

end_table(1);
br();
submit("resubmit_jobq_request", "Rerun" );

br();



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