<?php

/* * ********************************************************************
 * ********************************************************************* */
$page_security = 'SA_ITEMSTRANSVIEW';
$path_to_root = "../..";
include_once($path_to_root . "/includes/db_pager.inc");
include($path_to_root . "/includes/session.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 = "Item List"), @$_REQUEST['popup'], false, "", $js);

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");

include_once($path_to_root . "/projects/includes/db/tasks_db.inc");

$project_id = 0;
if(isset($_GET['popup'])){
    $project_id = $_GET['project_id'];
}

function edit_link($row){
    return '<a href="#" onclick="pass_to_parent(\''.$row['task_id'].'\')">Select</a>';
}

function type_encrypt($row){

    if($row['mb_flag']=='B'){
        return 'Purchased';
    }else if($row['mb_flag']=='M'){
        return 'Manufactured';
    }else{
        return 'Service';
    }
}

start_form();

start_table(TABLESTYLE_NOBORDER,"width=90%");
//start_row();
//echo '<td align="center" colspan=5>&nbsp;</td>';
//end_row();
//
//start_row();
//text_cells_ex(_('Item code').' :', 'code', 20);
//text_cells_ex(_('Item description').' :', 'name', 35);
////check_cells(_('POS'), 'pos');
//end_row();
//
//start_row();
//text_cells_ex(_('Search Code').' :', 'search_code', 20);
//text_cells_ex(_('Long Description').' :', 'desc', 35);
//
////check_cells(_('POS'), 'pos');
//end_row();
//
//start_row();
//text_cells_ex(_('Part No').' :', 'part_no', 20);
//end_row();
//
////start_row();
////echo '<td align="center" colspan=5>&nbsp;</td>';
////end_row();
//
//start_row();
//stock_categories_list_cells(_('Category').' :', 'category',null,_('All'),false);
//stock_item_types_list_cells(_("Item Type:"), 'mb_flag', '', true, 'All', false);
////check_cells(_('POS'), 'pos');
//end_row();
//
//start_row();
//value_list_cells(_('Item Category').' :', 'item_category', 'ITEM_PARAMETER_1',null,_('All'));
//value_list_cells(_("Brand:"), 'brand', 'ITEM_BRANDS',null,_('All'));  
////check_cells(_('Restaurant'), 'restaurant');
//end_row();
//
//start_row();
//value_list_cells(_("Item Group:"), 'type', 'ITEM_PARAMETER_2',null,_('All'));
//end_row();

//start_row();
//value_list_cells(_("Country Of Origin:"), 'country_of_origin', 'COUNTRIES',null,_('All'));
//value_list_cells(_("Country Of Manufacture:"), 'country_of_manufacture', 'COUNTRIES',null,_('All'));
////echo '<td>&nbsp;</td><td>&nbsp;</td>';
////check_cells(_('Laundry'), 'laundry');
//end_row();
//
//start_row();
//supplier_list_cells(_("Supplier:"), 'supplier_id', null, _('All'), false, false, true);
//supplier_list_cells(_("Local Agent:"), 'local_agent', null, _('All'), false, false, true); 
//end_row();

$_POST['country_of_origin'] = $_POST['country_of_manufacture'] = $_POST['supplier_id'] = $_POST['local_agent'] =-1;
        
start_row();
submit_cells('SearchItem', _("Search"), '', _('Select documents'), 'default');
end_row();

start_row();

end_row();
end_table(1);

$sql = get_tasks_advance_search_sql($project_id);

//$sql = get_item_advance_search_sql();

$cols = array(
    _('Item code')=>array('ord'=>''),
    _('Item description'),
    _('Item Category'),
    _('Search Code'),
    _('Part No'),
    _('Brand'),
	array('insert' => true, 'fun' => 'edit_link')
);

//if(isset($_GET['popup'])){
//    array_append($cols, array(
//        array('insert' => true, 'fun' => 'edit_link'),
//    ));
//}
 
$table = & new_db_pager('item_tbl', $sql, $cols);
$table->width = "90%";
display_db_pager($table);

end_form();

if(isset($_GET['popup'])){
    echo get_js_parent_passing_item($_GET['parent']);
}
end_page();