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

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

include($path_to_root . "/includes/db_pager.inc");
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 . "/jobq/includes/db/jobq_requests_db.inc");

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
if (user_use_date_picker())
	$js .= get_js_date_picker();

page(_($help_context = "Job Queue"), false, false, "", $js);

//-----------------------------------------------------------------------------------
// Ajax updates
//
if (get_post('Search'))
{
	$Ajax->activate('journal_tbl');
}
//--------------------------------------------------------------------------------------
if (!isset($_POST['filterType']))
	$_POST['filterType'] = -1;

start_form();

start_table(TABLESTYLE_NOBORDER);
start_row();

system_users_list_cells("User:", "submitted_user_id", null, '');

ref_cells(_("Description:"), 'description', '',null);

date_cells(_("From:"), 'FromDate', '', null, 0, -1, 0);
date_cells(_("To:"), 'ToDate', '', null, 1);

submit_cells('Search', _("Search"), '', '', 'default');
end_row();
end_table();


function systype_name($dummy, $type)
{
	global $systypes_array;
	
	return $systypes_array[$type];
}

function view_link($row) 
{
        return get_trans_view_str(ST_JOB_QUEUE, $row["id"]);
}

function edit_link($row)
{
    if($row['status_id'] > JQ_PROCESSING)
                return null;
  
    return pager_link( _("Edit"),
	"/jobq/update_jobq.php?JobqRequestId=" . $row["id"], ICON_EDIT);
}

function display_started_date($row)
{
	if(substr($row["started_on"],0,4) == "0000"){
            return "";
        }
        else{
            return $row["started_on"];
        }
}
function display_completed_date($row)
{
	if(substr($row["completed_on"],0,4) == "0000"){
            return "";
        }
        else{
            return $row["completed_on"];
        }
}


function request_status_name($dummy, $type)
{
	global $jobq_request_statues;
	
	return $jobq_request_statues[$type];
}

function manage_link($row)
{ 
        if($row['status_id'] == JQ_COMPLETED || $row['status_id'] == JQ_ENDED){
        }
        else{
                return pager_link( _("Manage"),
                        "/jobq/manage_jobq_request.php?jobq_request_id=" .$row['id'], ICON_DOC);
        }
}


$sql = get_sql_for_jobq_requests(get_post('submitted_user_id'), get_post('FromDate'),
	get_post('ToDate'), get_post('description'));

$cols = array(
	//_("#") => array('fun'=>'view_link'), 
        _("#") => array('fun'=>'view_link'), 
	_("Type") => array('fun'=>'systype_name'), 
        _("Description"), 
	_("Submitted By"), 
	_("Submitted On"), 
	_("Started On") => array('fun'=>'display_started_date'),  
	_("Completed On") => array('fun'=>'display_completed_date'), 
        _("Document Id"),
        _("Comments"),
        _("Status") => array('fun'=>'request_status_name'),
        _("") => array('fun'=>'manage_link') 
	//array('insert'=>true, 'fun'=>'edit_link')
);

$table =& new_db_pager('journal_tbl', $sql, $cols);

$table->width = "90%";

display_db_pager($table);

end_form();
end_page();

?>
