<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_UNAPPROVED_PROJECTS_INQ';
if (!@$_GET['popup'])
	$path_to_root = "../..";
else	
	$path_to_root = "..";
include_once($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 . "/includes/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/projects/includes/db/unapproved_projects_inquiry_db.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 = "Unapproved Projects Inquiry", false, false, "", $js);
//---------------------------------------------------------------------------------------------
simple_page_mode(true);

if (isset($_GET['order_no']))
{
    $_POST['order_no'] = $_GET['order_no'];
}


function code($row)
{
    return $row['project_code'];
}

function description($row)
{
   return $row['description'];
}

function department($row)
{       
    return $row['department_name'];
}


function customer_name($row)
{
    return $row['customer_name'];  
}


function start_date($row)
{
    return sql2date($row['start_date']);  
}


function end_date($row)
{
    return sql2date($row['end_date']);  
}

function project_manager_name($row)
{
    return $row['project_manager_name'];   
}

function project_value($row)
{
    return number_format($row['editing_project_value'], 2);   
}



function project_manager($row)
{
    return $row['user_name'];    
}

function project_cost($row)
{
    return number_format($row['estimated_cost'], 2);   
}

function edit_link($row) 
{
    if (@$_GET['popup'])
    global $trans_type;
    $modify = "Project_id";
  
    return pager_link(_("Approve"), "/projects/approve_projects.php?$modify=".$row['project_id'], ICON_EDIT);
    
}


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

if ($Mode == 'Delete')
{
        $recs = delete_i_owe_u($selected_id, $_POST['employee_code']);
        
        if($recs == 1){
                display_notification(_("Salary advance has been deleted."));
        }
        else{
                display_error(_("Salary advance could not be deleted."));
        }

	$Mode = 'RESET';
}

if ($Mode == 'RESET')
{
	$selected_id = -1;
}

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

//if (list_updated('employee_code')) 
	$Ajax->activate('_page_body');
//--------------------------------------------------------------------------------------------------

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

    start_row();
        project_list_cells(_("Project:"), 'project_id', null, _('Select a project'), true);
        customer_list_cells("Customer:", 'customer_id', null, 'Select a customer', true);
        value_list_cells("Department:", 'department_id', 'DEPARTMENTS', null, 'Select a department', true);
        submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
    end_row();
 
   
end_table(1);

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

$project_id = "";
if(isset($_POST['project_id'])){
    $project_id = $_POST['project_id'];
}

$customer_id = "";
if(isset($_POST['customer_id'])){
    $customer_id = $_POST['customer_id'];
}

$department_id = "";
if(isset($_POST['department_id'])){
    $department_id = $_POST['department_id'];
}

$current_user_id = $_SESSION['wa_current_user']->user;

    $sql = get_sql_unapproved_project_inquiry($current_user_id, $project_id, $customer_id, $department_id);    
    
    $cols = array(                             
                _("Department")=>array('fun'=>'department','align'=>'left'),
                _("Code")=> array('fun'=>'code','align'=>'left'),
                _("Description")=>array('fun'=>'description','align'=>'left'),
                
                _("Customer")=> array('fun'=>'customer_name','align'=>'left'),
                _("Start Date")=>array('fun'=>'start_date','align'=>'center'),           
                _("End Date")=>array('fun'=>'end_date','align'=>'center'),          
                _("Project Manager Name")=>array('fun'=>'project_manager_name','align'=>'left'),    
                _("Project Value")=>array('fun'=>'project_value','align'=>'right'),  
                _("Project Cost")=>array('fun'=>'project_cost','align'=>'right'),  
//                _("Project Manager")=>array('fun'=>'project_manager','align'=>'left'),  
                
            );
    
        array_append($cols, array(
                array('insert'=>true, 'fun'=>'edit_link')));


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

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

$table->width = "95%";

display_db_pager($table);

br();

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




?>
