<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
require(root."/___simple_config.php");
session_start();
require(root."/".adminFolder."/_common.php");
require(root."/".adminFolder."/_lib/db.php");
require(root."/".adminFolder."/_lib/main.php");
require(root."/".adminFolder."/_lib/bootstraps.php");
$pageSubOf = "pages";
$pageName = "mimpi";
$pageTitle = "Mimpi";
$thisUrl = "mimpi";
$ajax_page = "ajax_mimpi.php";
$pageUrl = "/".adminFolder."/$thisUrl";
$a = cekpost(cleanQuery($_GET["a"]), "");
$err = "";
if ($a=="section_main") {
	$fil_noxd = cekpost(cleanQuery($_REQUEST["fil_noxd"]), "");
	$fil_mimpi = cekpost(cleanQuery($_REQUEST["fil_mimpi"]), "");
	$swhere = "";
	if ($fil_noxd!="") { $swhere .= " AND CONCAT(a.no2d, ' ', a.no3d, ' ', a.no4d, ' ', a.noalt) LIKE '%$fil_noxd%' "; }
	if ($fil_mimpi!="") { $swhere .= " AND a.mimpi LIKE '%$fil_mimpi%' "; }
	$rs=array();$q="SELECT a.* FROM mimpi a WHERE 1=1 $swhere";
	callRS($rs, $q);
	
	if (count($rs)!=0) {
		$ld = 200;
		$cp = cekpost(cleanQuery($_GET["cp"]), "1");
		$tp = intval(count($rs) / $ld) + (count($rs)%$ld==0?0:1);
		$sr = ($cp-1) * $ld;
		$pagination = '';
		if ($tp!=1) {
			$pagination .= ('<ul class="pagination pagination-sm">');
				$disabled = '';
				$purl = '#';
				$onclick = '';
				if ($cp<=1) {
					$disabled = 'disabled';
					$onclick = ' onclick="return false;" ';
				}
				$pagination .= ('<li class="'.$disabled.'"><a href="'.$purl.'" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', 1);return false;"').'>&lt;&lt;</a></li>');
				$pagination .= ('<li class="'.$disabled.'"><a href="'.$purl.'" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.($cp-1).');return false;"').'>&lt;</a></li>');
				for ($c=1;$c<=$tp;$c++) {
					$active = '';
					$purl = '#';
					$disabled = '';
					$onclick = '';
					if ($c==$cp) {
						$active = 'active';
					} else {
						$purl = '#';
						$onclick = ' onclick="filterReload(\''.$pageName.'\', '.$c.');return false;" ';
					}
					$pagination .= ('<li class="'.$active.' '.$disabled.'"><a href="'.$purl.'" '.$onclick.'>'.$c.'</a></li>');
				}
				$disabled = '';
				$onclick = '';
				if ($cp>=$tp) {
					$disabled = 'disabled';
					$onclick = ' onclick="return false;" ';
				}
				$pagination .= ('<li class="'.$disabled.'"><a href="#" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.($cp+1).');return false;"').'>&gt;</a></li>');
				$pagination .= ('<li class="'.$disabled.'"><a href="#" '.($onclick!=""?$onclick:'onclick="filterReload(\''.$pageName.'\', '.$tp.');return false;"').'>&gt;&gt;</a></li>');
			$pagination .= ('</ul>');
		}
		cout('<div class="alert alert-info" role="alert"><strong>Total whole data</strong> <span class="badge">'.count($rs).'</span></div>');
		
		if ($tp!=1) {
			cout($pagination);
		}
		cout('<table class="table table-striped table-bordered">');
			cout('<thead>');
				cout('<tr>');
					cout('<th class="text-center">#</th>');
					cout('<th class="text-center hidden-xs hidden-sm">Type</th>');
					cout('<th class="text-center">No</th>');
					cout('<th class="text-center hidden-xs hidden-sm">Alt. No</th>');
					cout('<th class="text-center">Mimpi</th>');
				cout('</tr>');
			cout('</thead>');
			cout('<tbody>');
			$cnt = 0;
			for ($i=$sr;$i<count($rs) && $cnt<$ld;$i++) {
				$cnt++;
				$kdmimpi = $rs[$i]["kd"];
				if ($rs[$i]["no2d"]!="" && $rs[$i]["no3d"]=="" && $rs[$i]["no4d"]=="") {
					$type = '2D';
					$nomor = $rs[$i]["no2d"];
					$nomor_alt = 'Nalo: '.$rs[$i]["nonalo"].'<br/>HongKong: '.$rs[$i]["nohongkong"].'<br/>Macao: '.$rs[$i]["nomacao"].'<br/>China: '.$rs[$i]["nochina"];
				} else if ($rs[$i]["no2d"]=="" && $rs[$i]["no3d"]!="" && $rs[$i]["no4d"]=="") {
					$type = '3D';
					$nomor = $rs[$i]["no3d"];
					$nomor_alt = $rs[$i]["noalt"];
				} else if ($rs[$i]["no2d"]=="" && $rs[$i]["no3d"]=="" && $rs[$i]["no4d"]!="") {
					$type = '4D';
					$nomor = $rs[$i]["no4d"];
					$nomor_alt = $rs[$i]["noalt"];
				}
				$mimpi = $rs[$i]["mimpi"];
				if ($fil_mimpi!="") {
					$mimpi = str_replace($fil_mimpi, '<strong>'.$fil_mimpi.'</strong>', $mimpi);
					$mimpi = str_replace(ucfirst($fil_mimpi), '<strong>'.ucfirst($fil_mimpi).'</strong>', $mimpi);
				}
				cout('<tr>');
					cout('<td class="text-center">'.($i+1).'</td>');
					cout('<td class="text-center hidden-xs hidden-sm">'.$type.'</td>');
					cout('<td class="text-center">'.$nomor.'</td>');
					cout('<td class="text-center hidden-xs hidden-sm">'.$nomor_alt.'</td>');
					cout('<td class="text-center">'.$mimpi.'</td>');
				cout('</tr>');
			}
			cout('</tbody>');
		cout('</table>');
		
		if ($tp!=1) {
			cout($pagination);
		}
		cout('<div class="alert alert-info" role="alert"><strong>Total whole data</strong> <span class="badge">'.count($rs).'</span></div>');
		$act_ket = "Mimpi: Main List";
		if ($swhere!="") { $act_ket .= ": ".cleanQuery($swhere).""; }
		updateUserActivities($act_ket);
	} else {
		cout('<div class="alert alert-info" role="alert">');
			cout('<strong>No data available.</strong> Please add new data for display.');
		cout('</div>');
	}
}
?>