<?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/auth.php");
require(root."/".adminFolder."/_lib/bootstraps.php");
$pageSubOf = "pages";
$pageName = "terms-and-conditions";
$pageTitle = "Terms And Conditions";
$thisUrl = "terms-and-conditions";
$ajax_page = "ajax_terms-and-conditions.php";
$pageUrl = "/".adminFolder."/$thisUrl";
$a = cekpost(cleanQuery($_GET["a"]), "");
$err = "";
if ($a=="do_edit") {
	$kd = cekpost(cleanQuery($_REQUEST["kd"]), "0");
	$tanggal = cekpost(cleanQuery($_REQUEST["tanggal"]), "");
	$isi = cekpost(cleanQuery($_REQUEST["isi"]), "");
	if ($tanggal!="") { $tanggal = strtotime($tanggal." ".date('H:i:s', time())); }
	if ($tanggal=="") { $err.= BSErrorMessage('Date must be filled'); }
	if ($isi=="") { $err.= BSErrorMessage('Description must be filled'); }
	if ($err=="") {
		$rsc=array(); $qc="SELECT * FROM s_tnc";
		callRS($rsc, $qc);
		$creby = $_SESSION["user"]["inisial"];
		$cretime = time();
		if (count($rsc)!=0) {
			$modby = $_SESSION["user"]["inisial"];
			$modtime = time();
			$q = "UPDATE s_tnc SET tanggal='$tanggal', isi='$isi', modby='$modby', modtime='$modtime' WHERE kd='$kd'";
		} else {
			$kd = getID("s_tnc", "kd");
			$q = "INSERT INTO s_tnc (kd, tanggal, isi, creby, cretime) VALUES ('$kd', '$tanggal', '$isi', '$creby', '$cretime')";
		}
		execRS($q);
		$act_ket = "Terms And Conditions: Edit: Updated [kd: $kd][tanggal: $tanggal][isi: $isi]";
		updateUserActivities($act_ket);
		cout('<script type="text/javascript">parent.window.location="'.$pageUrl.'/";</script>');
	} else {
		cout('<script type="text/javascript">parent.showError(\''.$err.'\');</script>');
	}
}
if ($a=="section_main") {
	if (!authorizedModule("tnc_main", $ses_kduser)) {
		unAuthorizedAccess("tnc_main");
	} else {
		$rs=array();$q="SELECT a.* FROM s_tnc a";
		callRS($rs, $q);
		cout('<form method="post" target="quick_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do_edit" role="form">');
			cout('<input type="hidden" id="kd" name="kd" value="'.$rs[0]["kd"].'" />');
			cout('<input type="hidden" name="kirim" id="kirim" value="1" />');
			cout('<dl class="dl-horizontal dldata">');
				if (authorizedModule("tnc_element_date", $ses_kduser)) {
					cout('<dt><label for="tanggal">Date</label></dt>');
					cout('<dd>
						<div class="form-group">
							<div class="controls">
								<div class="input-group">
									<input id="tanggal" name="tanggal" type="text" class="tanggal form-control" placeholder="Date" value="'.date('d-m-Y', time()).'" />
									<label for="tanggal" class="input-group-addon btn">
										<span class="glyphicon glyphicon-calendar"></span>
									</label>
								</div>
							</div>
						</div>
					</dd>');
				}
				if (authorizedModule("tnc_element_content", $ses_kduser)) {
					cout('<dt><label for="isi">Content</label></dt>');
					cout('<dd><textarea name="isi" id="isi" rows="10" cols="80" class="form-control">'.$rs[0]["isi"].'</textarea></dd>');
				}
				$creby = (trim($rs[0]["creby"])!=""?'By: <strong>'.$rs[0]["creby"].'</strong>':'By: &lt;<em>no data</em>&gt;').(trim($rs[0]["cretime"])?' ('.date('d M Y, H:i:s A', $rs[0]["cretime"]).')':' &lt;<em>no data</em>&gt;');
				$modby = (trim($rs[0]["modby"])!=""?'By: <strong>'.$rs[0]["modby"].'</strong>':'By: &lt;<em>no data</em>&gt;').(trim($rs[0]["modtime"])?' ('.date('d M Y, H:i:s A', $rs[0]["modtime"]).')':' &lt;<em>no data</em>&gt;');
				if (authorizedModule("tnc_element_creation", $ses_kduser)) {
					cout('<dt>Created</dt>');
					cout('<dd>'.$creby.'</dd>');
				}
				if (authorizedModule("tnc_element_modification", $ses_kduser)) {
					cout('<dt>Modified</dt>');
					cout('<dd>'.$modby.'</dd>');
				}
				cout('<dt></dt>');
				cout('<dd class="err"></dd>');
				
				cout('<dt></dt>');
				cout('<dd><button class="btn btn-primary" type="submit">Save</button></dd>');
			cout('</dl>');
		cout('</form>');
		cout('<script>parent.bindDatePicker(\'.tanggal\');</script>');
		$viewFrame = 0;
		if ($viewFrame==1) {
			cout('<iframe name="quick_iframe" id="quick_iframe" src="/'.adminFolder.'/_ajax/index.php" width="300" 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="300" height="11" style="overflow:hidden;" visibility="hidden" scrolling="no" frameborder="0"></iframe>');
		}
		$act_ket = "Terms And Condtions: Main";
		updateUserActivities($act_ket);
	}
}
?>