<?php
define("_VALID_PHP", true);
require_once("../../init.php");
$page = basename($_SERVER["PHP_SELF"]);
$heder = "Liste";
$mali = " > za naručivanje";
$korisnik = $user->username;
$lokal = $user->fname;
$level = $user->userlevel;
$prezime = $user->lname;
$koje = $user->name;
//echo $korisnik;
$ip = $_SERVER['REMOTE_ADDR']; 
$kome = $user->sendto;
$id_user = $user->uid;
//echo $id_user;
//load the database configuration file
include('../../xcrud/xcrud.php');
Xcrud_config::$jquery_no_conflict = true; // jquery conflicts with SyntaxHighlighter
//odavde idu komnade ka xcrud-u
$xcrud = Xcrud::get_instance();
$xcrud->table('orders');
$xcrud->where('status',0);
if($korisnik == 'dejan' or $korisnik == 'mika')
{
}
else
{
$xcrud->where('manager',$id_user);
}
$xcrud->relation('store','users','id','fname');
$xcrud->change_type('datecreation','datetime');
$xcrud->columns('store,datecreation,code,status');
$xcrud->fields('store,datecreation');
$xcrud->readonly('store,datecreation');
$xcrud->order_by('datecreation','DESC');
$xcrud->table_name('Liste');
$xcrud->column_pattern('store', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{id}">{value}</a>');
//$xcrud->unset_edit();
//$xcrud->unset_add(); //ovo sam promenio kad mi deki rekao da menjaju narudzbe
//$xcrud->unset_remove();
$xcrud->create_action('publish', 'publish_order'); // action callback, function publish_action() in functions.php
$xcrud->create_action('unpublish', 'unpublish_order');    $xcrud->button('#', 'unpublished', 'icon-close glyphicon glyphicon-remove', 'xcrud-action', 
        array(  // set action vars to the button
            'data-task' => 'action',
            'data-action' => 'publish',
            'data-primary' => '{id}'), 
        array(  // set condition ( when button must be shown)
            'status',
            '!=',
            '1')
    );
$xcrud->button('#', 'published', 'icon-checkmark glyphicon glyphicon-ok', 'xcrud-action', array(
        'data-task' => 'action',
        'data-action' => 'unpublish',
        'data-primary' => '{id}'), array(
        'status',
        '=',
        '1'));
$lista = $xcrud->nested_table('lista','code','odersdetail','ordersid');
$lista->where('quantity>',0);
$lista->relation('productid','products','id','name');
$lista->columns('productid,quantity');
$lista->unset_view();
$lista->fields('productid,quantity');

?>

<!-- BEGIN PAGE HEADER-->
<h3 class="page-title">
<?php echo $heder;?><small><?php echo $mali;?></small>
</h3>
<div class="page-bar">
	<ul class="page-breadcrumb">
		<li>
			<i class="fa fa-home"></i>
			<a href="index.html">Home</a>
			<i class="fa fa-angle-right"></i>
		</li>
		<li>
			<a href="#"><?php echo $page;?></a>
		</li>
	</ul>
</div>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<div class="row">
	<div class="col-md-12">
	<?php echo $xcrud->render(); ?>
	</div>
</div>
<!-- END PAGE CONTENT-->

