<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
require(root."/___simple_config.php");
session_start();
$pageSubOf = "transactions";
$pageName = "accounts";
$pageTitle = "Accounts";
$thisUrl = "accounts";
$pageUrl = "/".adminFolder."/$thisUrl";
$act_ket = "Main Page of Accounts";
$coutSpecs = array('nl'=>"n");
require(root."/".adminFolder."/_common.php");
require(root."/".adminFolder."/_lib/db.php");
require(root."/".adminFolder."/_lib/main.php");
require(root."/".adminFolder."/_lib/auth.php");
$a = cekpost(cleanQuery($_GET["a"]), "");
require(root."/".adminFolder."/_tpl/tag_html_a.php");
cout('
<style type="text/css">
	
</style>
');
require(root."/".adminFolder."/_tpl/openbody.php");
require(root."/".adminFolder."/_tpl/header.php");
cout('<div class="page-header">');
	cout('<h1>'.$pageTitle.'</h1>');
cout('</div>');
# MAIN
###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ######
if ($a=="" || $a=="main") {
	cout('<div class="section_submenus">');
		cout('<ul class="nav nav-tabs" role="tablist">');
			if (authorizedModule("accounts_main", $ses_kduser)) {
				cout('<li role="presentation" class="active"><a href="'.$pageUrl.'/" title="Main List"><span class="glyphicon glyphicon-list"></span> Main</a></li>');
			}
		cout('</ul>');
	cout('</div>');
	if (authorizedModule("accounts_quick_add", $ses_kduser)) {
		cout('<nav class="navbar navbar-default">
			<div class="container-fluid">
				<!-- Brand and toggle get grouped for better mobile display -->
				<div class="navbar-header">
					<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
						<span class="sr-only">Toggle navigation</span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
					<a class="navbar-brand" href="#">Quick Add</a>
				</div>');
				cout('<!-- Collect the nav links, forms, and other content for toggling -->');
				cout('<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">');
					cout('<form class="navbar-form navbar-left" id="quick-add-form" role="search" method="post" target="quick_iframe" action="/'.adminFolder.'/_ajax/ajax_accounts.php?a=quick_add">');
							cout('<div class="form-group">
								<label for="ikdgame">Games</label>
								<select name="ikdgame" id="ikdgame" class="form-control">
									<option value="">- Select Game -</option>');
									$rsb=array();$qb="SELECT a.*, kodelang FROM games a 
										LEFT JOIN negara b ON b.kdnegara=a.kdnegara
										LEFT JOIN langs c ON c.kdlang=b.kdlang
										WHERE a.isactive=1";
									callRS($rsb, $qb);
									for ($i=0;$i<count($rsb);$i++) {
										cout('<option value="'.$rsb[$i]["kdgame"].'">'.$rsb[$i]["nama"].' - '.(isset($rsb[$i]["kodelang"])?$rsb[$i]["kodelang"]:'All').'</option>');
									}
								cout('
								</select>
							</div>');
							cout('<div class="form-group">
								<label for="iusername">Username</label>
								<input type="text" name="iusername" id="iusername" class="form-control" placeholder="UserName" style="text-transform:uppercase;">
							</div>');
							cout('<div class="form-group">
								<label for="ipassword">Password</label>
								<input type="text" name="ipassword" id="ipassword" class="form-control" placeholder="Password">
							</div>');
						cout('<button type="submit" class="btn btn-primary" onclick="formSubmit(\'quick-add-form\');return false;">Add Account</button>');
						cout('<div id="quick-err" class="err" style="width:100%;"></div>');
					cout('</form>');
					$viewFrame = 0;
					if ($viewFrame==1) {
						cout('<iframe name="quick_iframe" id="quick_iframe" src="/'.adminFolder.'/_ajax/index.php" width="500" height="100" style="overflow:;border:1px red solid;" visibility="" scrolling="yes" frameborder="1"></iframe>');
					} else {
						cout('<iframe name="quick_iframe" id="quick_iframe" src="/'.adminFolder.'/_ajax/index.php" width="500" height="11" style="overflow:hidden;" visibility="hidden" scrolling="no" frameborder="0"></iframe>');
					}
				cout('</div><!-- /.navbar-collapse -->');
			cout('</div><!-- /.container-fluid -->');
		cout('</nav>');
	}
	
	
	cout('<nav class="navbar navbar-default">
		<div class="container-fluid">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2" aria-expanded="false">
					<span class="sr-only">Toggle navigation</span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</button>
				<a class="navbar-brand" href="#">Filter</a>
			</div>');
			cout('<!-- Collect the nav links, forms, and other content for toggling -->');
			cout('<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">');
				cout('<form class="navbar-form navbar-left" role="search" method="post" target="filter_iframe" action="/'.adminFolder.'/_ajax/ajax_accounts.php?a=section_main">');
					if (authorizedModule("accounts_element_games", $ses_kduser)) {
						cout('<div class="form-group">');
							cout('<label for="fil_kdgame">Games</label>');
							cout('<select name="fil_kdgame" id="fil_kdgame" class="form-control">');
								cout('<option value="">- All Game -</option>');
								$rsb=array();$qb="SELECT a.*, kodelang FROM games a 
										LEFT JOIN negara b ON b.kdnegara=a.kdnegara
										LEFT JOIN langs c ON c.kdlang=b.kdlang
										WHERE 1=1";
								callRS($rsb, $qb);
								for ($i=0;$i<count($rsb);$i++) {
									cout('<option value="'.$rsb[$i]["kdgame"].'">'.$rsb[$i]["nama"].' - '.(isset($rsb[$i]["kodelang"])?$rsb[$i]["kodelang"]:'All').'</option>');
								}
							cout('</select>');
						cout('</div>');
					}
					if (authorizedModule("accounts_element_username", $ses_kduser)) {
						cout('<div class="form-group">');
							cout('<label for="fil_username">Username</label>');
							cout('<input type="text" name="fil_username" id="fil_username" class="form-control" placeholder="% UserName %">');
						cout('</div>');
					}
					if (authorizedModule("accounts_element_password", $ses_kduser)) {
						cout('<div class="form-group">');
							cout('<label for="fil_password">Password</label>');
							cout('<input type="text" name="fil_password" id="fil_password" class="form-control" placeholder="% Password %">');
						cout('</div>');
					}
					if (authorizedModule("accounts_element_active", $ses_kduser)) {
						cout('<div class="form-group">');
							cout('<label for="fil_isactive">Active?</label>');
							cout('<select name="fil_isactive" id="fil_isactive" class="form-control">');
								cout('<option value="">All</option>');
								cout('<option value="1">Active</option>');
								cout('<option value="0">Non-Active</option>');
							cout('</select>');
						cout('</div>');
					}
					if (authorizedModule("accounts_element_assign", $ses_kduser)) {
						cout('<div class="form-group">');
							cout('<label for="fil_assigned">Assigned?</label>');
							cout('<select name="fil_assigned" id="fil_assigned" class="form-control">');
								cout('<option value="">All</option>');
								cout('<option value="0">Not Yet</option>');
								cout('<option value="1">Yes</option>');
							cout('</select>');
						cout('</div>');
					}
					cout('<button type="button" class="btn btn-primary" onclick="filterReload(\''.$pageName.'\', 1);return false;">Search</button>');
				cout('</form>');
				cout('<script>
					function doAct(parType, parKd) {
						var pData = "a=do&type="+ parType +"&kd="+ parKd +"";
						if (parType=="edit") {
							pData += "&nfkdgame"+ parKd +"="+ $("#nfkdgame"+ parKd +"").val() +"";
							pData += "&nfusername"+ parKd +"="+ $("#nfusername"+ parKd +"").val() +"";
							pData += "&nfpass"+ parKd +"="+ $("#nfpass"+ parKd +"").val() +"";
							pData += "&nfisactive"+ parKd +"="+ $("#nfisactive"+ parKd +"").val() +"";
						}
						$.ajax({
							type: "GET",
							url: "/'.adminFolder.'/_ajax/ajax_accounts.php",
							data: pData,
							success: function(resp){
								//alert(resp);
								var tsp1 = resp.split("$$$");
								var tsp2 = new Array();
								for (var i=0;i<tsp1.length;i++) {
									if (tsp1[i]=="deleterow") {
										$(".tr-data"+ tsp1[1] +"").fadeOut(1000, function(){
											$(".tr-data"+ tsp1[1] +"").remove();
										});
									} else if (tsp1[i]=="done") {
										$("#myModal").modal("hide");
									} else {
										tsp2 = tsp1[i].split("$$");
										$("."+tsp2[0]).html(tsp2[1]);
									}
								}
								$(".simple").show();
							}
						});
					}
					function prepareAct(parType, parKd) {
						$.ajax({
							type: "GET",
							url: "/'.adminFolder.'/_ajax/ajax_accounts.php",
							data: "a=prepare&type="+ parType +"&kd="+ parKd +"",
							success: function(resp){
								//alert(resp);
								var tsp1 = resp.split("$$$");
								//alert(tsp1[0]);
								if (tsp1[0]=="assign" || tsp1[0]=="reassign" || tsp1[0]=="trydepo" || tsp1[0]=="trywd" || tsp1[0]=="tryview") {
									$(".modal-title").html(tsp1[1]);
									$(".modal-body").html(tsp1[2]);
									$(".modal-footer").html(tsp1[3]);
									$("#myModal").modal("show");
									if (tsp1[0]=="trydepo" || tsp1[0]=="trywd") {
										$("#myModal").on("shown.bs.modal", function () {
											bindDatePicker(".tanggalx");
											$("#myModal #jumlah").number( true, 0 );
										});
									}
								} else {
									var tsp2 = new Array();
									for (var i=0;i<tsp1.length;i++) {
										tsp2 = tsp1[i].split("$$");
										$("."+tsp2[0]).html(tsp2[1]);
									}
									$(".simple").hide();
								}
							}
						});
					}
					function clearQuickAdd() {
						$("#ipassword").val("");
						$("#iusername").focus();
					}
					$("#fil_username, #fil_password").keypress(function (e) {
						if(e.which == 13) {
							filterReload(\''.$pageName.'\', 1);
							return false;
						}
					});
					$("#iusername").focus();
					$("#iusername").bind("blur", function(){
						var username = $.trim($(this).val());
						if (username!="") {
							$.ajax({
								type: "GET",
								url: "/'.adminFolder.'/_ajax/ajax_accounts.php",
								data: "a=randpass",
								success: function(resp){
									$("#ipassword").val(resp);
								}
							});
						}
					});
				</script>');
			cout('</div><!-- /.navbar-collapse -->');
		cout('</div><!-- /.container-fluid -->');
	cout('</nav>');
	cout('<div class="ajax_resp"></div>');
	cout('<script>filterReload(\''.$pageName.'\', 1);</script>');
}
###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ###### ######
require(root."/".adminFolder."/_tpl/footer.php");
require(root."/".adminFolder."/_tpl/tag_html_b.php");
?>