<?php
 define("_VALID_PHP", true);
 require_once("../../init.php");
$page = basename($_SERVER["PHP_SELF"]);
$heder = "Brojcanici";
$mali = " > forma za popis brojcanika";
$korisnik = $user->username;
$lokal = $user->fname;
$prezime = $user->lname;
$koje = $user->name;
//echo $koje;
$ip = $_SERVER['REMOTE_ADDR']; 
$kome = $user->sendto;
$id_user = $user->uid;
$dept = $user->todept;
$gdeje = "(".$dept.")";
//echo $kome;
//echo $dept;
$firma = $user->country;
$upit = 'manager REGEXP "[[:<:]]'.$id_user.'[[:>:]]"';
$upits = 'serviser REGEXP "[[:<:]]'.$id_user.'[[:>:]]"';
//echo $upit;
	
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('users');
$xcrud->table_name('Popis elektronskih brojcanika');
$xcrud->where('FIND_IN_SET('.$id_user.',send_to) and userlevel=1');
$xcrud->columns('fname');
$xcrud->disabled('fname');
$xcrud->hide_button('edit');
$xcrud->unset_remove();
$xcrud->hide_button('save_return');
$xcrud->hide_button('save_edit');
$xcrud->fields('fname');
$xcrud->label('fname','Lokal');
$xcrud->unset_view();
$xcrud->unset_add();
//$xcrud->unset_csv();
//$xcrud->unset_print();
$xcrud->column_pattern('fname', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{id}">{value}</a>');
$counters = $xcrud->nested_table('c_slots','id','c_slots','ID_Arcade');
$counters->where('status',1);
$counters->hide_button('edit');
$counters->subselect('Zadnji popis','SELECT max(vreme) FROM c_counters WHERE id_slot={id_slot}');
$counters->columns('Place,Game_System,Serial_Number,Zadnji popis');
$counters->change_type('Zadnji popis','datetime');
$counters->disabled('Place,Game_System');
$counters->hide_button('save_return');
$counters->hide_button('save_edit');
$counters->table_name('Aparati');
$counters->limit('50');
$counters->column_pattern('Game_System', '<a href="#" class="xcrud-action" data-task="edit" data-primary="{id_slot}">{value}</a>');
$counters->fields('Place,Game_System,Zadnji popis');
$counters->unset_add();
$counters->unset_remove();
$counters->order_by('Place','ASC');
$meters = $counters->nested_table('c_counters','id_slot','c_counters','id_slot');
$meters->hide_button('save_edit');
$meters->hide_button('save_new');
$meters->pass_var('id_user',$id_user);
$meters->pass_var('id_arcade','{id}');
$meters->where('vreme','> now()'); //prikazuje praznu tabelu
$meters->fields('in_m,out_m,bet_m,win_m,games_m,jackpot,rc,Note');
$meters->label('in_m','In brojač');
$meters->label('out_m','Out brojač');
$meters->label('bet_m','Bet brojač');
$meters->label('win_m','Win brojač');
$meters->label('games_m','Games brojač');
$meters->label('rc','Ram Clear');
$meters->label('Note','Napomena');
$meters->columns('id_slot,in_m,out_m,bet_m,win_m,games_m,jackpot,rc,Note');
$meters->table_name('Popis Brojača');
$meters->change_type('in_m','int','',array('type'=>'number','onkeydown'=>'limit(this, 15);','onkeyup'=>'limit(this, 15);'));
$meters->validation_pattern('in_m', 'numeric');
$meters->validation_required('in_m');
$meters->change_type('out_m','int','',array('type'=>'number','onkeydown'=>'limit(this, 15);','onkeyup'=>'limit(this, 15);'));
$meters->validation_pattern('out_m','numeric');
$meters->validation_required('out_m');
$meters->change_type('bet_m','int','',array('type'=>'number','onkeydown'=>'limit(this, 20);','onkeyup'=>'limit(this, 20);'));
$meters->validation_pattern('bet_m','numeric');
$meters->validation_required('bet_m');
$meters->change_type('win_m','int','',array('type'=>'number','onkeydown'=>'limit(this, 20);','onkeyup'=>'limit(this, 20);'));
$meters->validation_pattern('win_m','numeric');
$meters->validation_required('win_m');
$meters->change_type('games_m','int','',array('type'=>'number','onkeydown'=>'limit(this, 15);','onkeyup'=>'limit(this, 15);'));
$meters->validation_pattern('games_m','numeric');
$meters->validation_required('games_m');
$meters->change_type('jackpot','int','',array('type'=>'number','onkeydown'=>'limit(this, 20);','onkeyup'=>'limit(this, 20);'));
$meters->unset_print();
$meters->unset_csv();
$meters->before_insert('check_meters');
?>
<!-- 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.php">Home</a>
			<i class="fa fa-angle-right"></i>
		</li>
		<li>
			<a href="#"><?php echo $heder;?></a>
		</li>
	</ul>
	</div>
	<div id="alert_green">
	</div>
	<!-- END PAGE HEADER-->
	<!-- BEGIN PAGE CONTENT-->
	<div class="row">
	
	<div class="col-md-12">
	<?php echo $xcrud->render(); ?>

	</div>
</div>
<!-- END PAGE CONTENT-->
<script>
function limit(element, max) {    
    var max_chars = max;
    if(element.value.length > max_chars) {
        element.value = element.value.substr(0, max_chars);
    } 
}
</script>