<?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 = "news";
$pageTitle = "News";
$thisUrl = "news";
$ajax_page = "ajax_news.php";
$pageUrl = "/".adminFolder."/$thisUrl";
$a = cekpost(cleanQuery($_GET["a"]), "");
$err = "";
if ($a=="section_main") {
	if (!authorizedModule("news_main", $ses_kduser)) {
		unAuthorizedAccess("news_main");
	} else {
		$fil_judul = trim(cekpost(cleanQuery($_REQUEST["fil_judul"]), ""));
		$fil_isi = trim(cekpost(cleanQuery($_REQUEST["fil_isi"]), ""));
		$fil_isactive = trim(cekpost(cleanQuery($_REQUEST["fil_isactive"]), ""));
		$swhere = '';
		if ($fil_judul!="") { $swhere .= " AND a.judul LIKE '%$fil_judul%' "; }
		if ($fil_isi!="") { $swhere .= " AND a.isi LIKE '%$fil_isi%' "; }
		if ($fil_isactive!="") { $swhere .= " AND a.isactive = '$fil_isactive' "; }
		
		$rs=array(); $q="SELECT a.* FROM news a WHERE 1=1 $swhere ORDER BY tanggal DESC";
		callRS($rs, $q);
		if (count($rs)!=0) {
			$ld = 20;
			$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>');
						if (authorizedModule("news_element_title", $ses_kduser)) {
							cout('<th class="text-center">Title</th>');
						}
						if (authorizedModule("news_element_url", $ses_kduser)) {
							cout('<th class="text-center">URL</th>');
						}
						cout('<th class="text-center">Short URL</th>');
						if (authorizedModule("news_element_date", $ses_kduser)) {
							cout('<th class="text-center">Date</th>');
						}
						if (authorizedModule("news_element_active", $ses_kduser)) {
							cout('<th class="text-center">Active Status</th>');
						}
						cout('<th class=""></th>');
					cout('</tr>');
				cout('</thead>');
				cout('<tbody>');
				$cnt = 0;
				for ($i=$sr;$i<count($rs) && $cnt<$ld;$i++) {
					$cnt++;
					$kdnews = $rs[$i]["kdnews"];
					if (intval($rs[$i]["isactive"])==0) {
						$isactive = '<a href="#" title="Activate" onclick="chActive(\''.$pageName.'\', '.$kdnews.', '.$rs[$i]["isactive"].');return false;">Non-Active</a>';
					} else {
						$isactive = '<a href="#" title="Deactivate" onclick="chActive(\''.$pageName.'\', '.$kdnews.', '.$rs[$i]["isactive"].');return false;">Active</a>';
					}
					$isi = str_replace("\n", "<br/>", $rs[$i]["isi"]);
					cout('<tr>');
						cout('<td class="text-center">'.($i+1).'</td>');
						if (authorizedModule("news_element_title", $ses_kduser)) {
							cout('<td class="text-center"><a href="'.$pageUrl.'/view/'.$rs[$i]["kdnews"].'/">'.$rs[$i]["judul"].'</a></td>');
						}
						if (authorizedModule("news_element_url", $ses_kduser)) {
							cout('<td class="text-center">'.$rs[$i]["url"].'</td>');
						}
						cout('<td class="text-center">'.$rs[$i]["short_url"].'</td>');
						if (authorizedModule("news_element_date", $ses_kduser)) {
							cout('<td class="text-center">'.date('d M Y', $rs[$i]["tanggal"]).'</td>');
						}
						if (authorizedModule("news_element_active", $ses_kduser)) {
							cout('<td class="text-center isactive'.$kdnews.'">'.$isactive.'</td>');
						}
						cout('<td class="text-center">');
							if (authorizedModule("news_edit", $ses_kduser)) {
								cout('<a href="'.$pageUrl.'/edit/'.$kdnews.'/"><span class="glyphicon glyphicon-pencil"></span><span class="hidden-xs hidden-sm"> Edit</span></a>');
								cout(BSTextSeparator());
							}
							if (authorizedModule("news_edit", $ses_kduser)) {
								cout('<a href="'.$pageUrl.'/image/'.$kdnews.'/"><span class="glyphicon glyphicon-picture"></span><span class="hidden-xs hidden-sm"> Image</span></a>');
								cout(BSTextSeparator());
							}
							if (authorizedModule("news_delete", $ses_kduser)) {
								cout('<a href="'.$pageUrl.'/delete/'.$kdnews.'/"><span class="glyphicon glyphicon-trash"></span><span class="hidden-xs hidden-sm"> Delete</span></a>');
							}
						cout('</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 = "News: 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>');
		}
	}
}
if ($a=="chactive") {
	$kd = cekpost(cleanQuery($_REQUEST["kd"]), "");
	$ca = cekpost(cleanQuery($_REQUEST["ca"]), "");
	$kd = (trim($kd)=="undefined")?'':$kd;
	$ca = (trim($ca)=="undefined")?'':$ca;
	if ($kd!="" && $kd!=0 && $ca!="") {
		$na = $ca==0?1:0;
		$modby = $_SESSION["user"]["inisial"];
		$modtime = time();
		$qu = "UPDATE news SET isactive='$na', modby='$modby', modtime='$modtime' WHERE kdnews='$kd'";
		execRS($qu);
		$act_ket = "News: Ch. Active [kd: $kd][from Act: $ca][to Act: $na]";
		updateUserActivities($act_ket);
		if (intval($na)==0) {
			$isactive = '<a href="#" title="Activate" onclick="chActive(\''.$pageName.'\', '.$kd.', '.$na.');return false;">Non-Active</a>';
		} else {
			$isactive = '<a href="#" title="Deactivate" onclick="chActive(\''.$pageName.'\', '.$kd.', '.$na.');return false;">Active</a>';
		}
		echo $isactive;
	}
}

if ($a=="section_image") {
	$id = cekpost(cleanQuery($_GET["id"]), "0");
	$rs=array(); $q="SELECT * FROM news WHERE kdnews='$id'";
	callRS($rs, $q);
	
	
	$rsi=array(); $qi="SELECT * FROM u_files WHERE kdnews='$id'";
	callRS($rsi, $qi);
	if (count($rsi)!=0) {
		#loadFormUploadImage(parPageName, parKd, parTipeForm, parTipeData, parKdFolder)
		#loadUploadedImage(parPageName, parKd, parKdFolder)
		#cout('<script type="text/javascript">parent.loadFormUploadImage(\''.$pageName.'\', \''.$id.'\', 0, 0, 0);</script>');
		cout('<script type="text/javascript">parent.loadUploadedImage(\''.$pageName.'\', \''.$id.'\', 0);</script>');
	} else {
		cout('<script type="text/javascript">parent.loadFormUploadImage(\''.$pageName.'\', \''.$id.'\', 0, 0);</script>');
	}
	$act_ket = "News: Upload Image... [kd: ".$rs[0]["kdpost"]."][judul: ".$rs[0]["judul"]."]";
	updateUserActivities($act_ket);
	exit;
}

if ($a=="section_view") {
	if (!authorizedModule("news_view", $ses_kduser)) {
		unAuthorizedAccess("news_view");
	} else {
		$id = cekpost(cleanQuery($_GET["id"]), "0");
		$rs=array(); $q="SELECT a.* FROM news a WHERE kdnews='$id'";
		callRS($rs, $q);
		if (intval($rs[0]["isactive"])==0) {
			$isactive = '<a href="#" title="Activate" onclick="chActive(\''.$pageName.'\', '.$rs[0]["kdnews"].', '.$rs[0]["isactive"].');return false;">Non-Active</a>';
		} else {
			$isactive = '<a href="#" title="Deactivate" onclick="chActive(\''.$pageName.'\', '.$rs[0]["kdnews"].', '.$rs[0]["isactive"].');return false;">Active</a>';
		}
		$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;');
		cout('<dl class="dl-horizontal dldata">');
			if (authorizedModule("news_element_title", $ses_kduser)) {
				cout('<dt>Title</dt>');
				cout('<dd>'.$rs[0]["judul"].'</dd>');
			}
			if (authorizedModule("news_element_url", $ses_kduser)) {
				cout('<dt>URL</dt>');
				cout('<dd>'.absDom.'/news/story/'.$rs[0]["url"].'&nbsp;&nbsp;<a href="'.absDom.'/news/story/'.$rs[0]["url"].'" target="_blank"><span class="glyphicon glyphicon-share"></span></a></dd>');
			}
			cout('<dt>Short URL</dt>');
			cout('<dd>'.$rs[0]["short_url"].'&nbsp;&nbsp;<a href="'.$rs[0]["short_url"].'" target="_blank"><span class="glyphicon glyphicon-share"></span></a></dd>');
			if (authorizedModule("news_element_date", $ses_kduser)) {
				cout('<dt>Date</dt>');
				cout('<dd>'.date('d M Y', $rs[0]["tanggal"]).'</dd>');
			}
			if (authorizedModule("news_element_active", $ses_kduser)) {
				cout('<dt>Active Status</dt>');
				cout('<dd class="isactive'.$rs[0]["kdnews"].'">'.$isactive.'</dd>');
			}
			if (authorizedModule("news_element_content", $ses_kduser)) {
				$isi = str_replace("\n", "<br/>", $rs[0]["isi"]);
				$isi = str_replace("../../../", "/", $isi);
				$isi = str_replace("../../", "/", $isi);
				$isi = str_replace("../", "/", $isi);
				cout('<dt>Content</dt>');
				cout('<dd>'.$isi.'</dd>');
			}
			if (authorizedModule("news_element_creation", $ses_kduser)) {
				cout('<dt>Created</dt>');
				cout('<dd>'.$creby.'</dd>');
			}
			if (authorizedModule("news_element_modification", $ses_kduser)) {
				cout('<dt>Modified</dt>');
				cout('<dd>'.$modby.'</dd>');
			}
			
		cout('</dl>');
		
		$act_ket = "News: View: [kd: ".$rs[0]["kdnews"]."][kode: ".$rs[0]["kode"]."][nama: ".$rs[0]["nama"]."]";
		updateUserActivities($act_ket);
		exit;
	}
}
if ($a=="do_delete") {
	$kirim = cekpost(cleanQuery($_REQUEST["kirim"]), "");
	if ($kirim=="1") {
		$delby = $_SESSION["user"]["inisial"];
		$deltime = time();
		$kdnews = cekpost(cleanQuery($_POST["kdnews"]), "0");
		$rs=array(); $q="SELECT * FROM news WHERE kdnews='$kdnews'";
		callRS($rs, $q);
		
		$q = "DELETE FROM news WHERE kdnews='$kdnews'";
		execRS($q);
		$act_ket = "News: Delete: Deleted [kd: $kdnews][judul: ".$rs[0]["judul"]."][tanggal: ".$rs[0]["tanggal"]."][isactive: ".$rs[0]["isactive"]."][isi: ".$rs[0]["isi"]."]";
		updateUserActivities($act_ket);
		cout('<script type="text/javascript">parent.window.location="'.$pageUrl.'/";</script>');
		exit;
	}
}
if ($a=="section_delete") {
	if (!authorizedModule("news_delete", $ses_kduser)) {
		unAuthorizedAccess("news_delete");
	} else {
		$id = cekpost(cleanQuery($_GET["id"]), "0");
		$rs=array(); $q="SELECT * FROM news WHERE kdnews='$id'";
		callRS($rs, $q);
		
		cout('<form method="post" target="quick_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do_delete" role="form">');
			cout('<input type="hidden" name="kirim" id="kirim" value="1" />');
			cout('<input type="hidden" name="kdnews" id="kdnews" value="'.$rs[0]["kdnews"].'" />');
			cout('<dl class="dl-horizontal dldata">');
				if (authorizedModule("news_element_title", $ses_kduser)) {
					cout('<dt>Title</dt>');
					cout('<dd>'.$rs[0]["judul"].'</dd>');
				}
				if (authorizedModule("news_element_date", $ses_kduser)) {
					cout('<dt>Date</dt>');
					cout('<dd>'.date('d M Y', $rs[0]["tanggal"]).'</dd>');
				}
				cout('<dt></dt>');
				cout('<dd><button class="btn btn-primary" type="submit">Delete</button></dd>');
			cout('</dl>');
		cout('</form>');
		$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 = "News: Deleting... [kd: ".$rs[0]["kdnews"]."][nama: ".$rs[0]["nama"]."]";
		updateUserActivities($act_ket);
		exit;
	}
}
if ($a=="do_edit") {
	$kirim = cekpost(cleanQuery($_REQUEST["kirim"]), "");
	$err = "";
	if ($kirim=="1") {
		$kdnews = cekpost(cleanQuery($_REQUEST["kdnews"]), "0");
		$judul = cekpost(cleanQuery($_REQUEST["judul"]), "");
		$short_url = cekpost(cleanQuery($_REQUEST["short_url"]), "");
		$tanggal = cekpost(cleanQuery($_REQUEST["tanggal"]), "");
		$isi = cekpost(cleanQuery($_REQUEST["isi"]), "");
		$isactive = cekpost(cleanQuery($_REQUEST["isactive"]), 0);
		if ($tanggal!="") { $tanggal = strtotime($tanggal." ".date('H:i:s', time())); }
		if ($judul=="") { $err.= BSErrorMessage('Title must be filled'); }
		if ($short_url=="") { $err.= BSErrorMessage('Short URL must be filled'); }
		if ($tanggal=="") { $err.= BSErrorMessage('Date must be filled'); }
		if ($isi=="") { $err.= BSErrorMessage('Description must be filled'); }
		if ($err=="") {
			$modby = $_SESSION["user"]["inisial"];
			$modtime = time();
			$flag = 0;
			$url = cleanURL($judul);
			do {
				$rscek = array(); $qcek = "SELECT kdnews FROM news WHERE url = '$url' AND kdnews!='$kdnews'";
				callRS($rscek, $qcek);
				if (count($rscek)!=0) {
					$flag = 0;
					$url = $url."-";
				} else {
					$flag = 1;
				}
			} while($flag==0);
			$q = "UPDATE news SET judul='$judul', url='$url', short_url='$short_url', tanggal='$tanggal', isi='$isi', isactive='$isactive', modby='$modby', modtime='$modtime' 
				WHERE kdnews='$kdnews'";
			execRS($q);
			$act_ket = "News: Edit: Updated [kd: $kdnews][judul: $judul][tanggal: $tanggal][isi: $isi][isactive: $isactive]";
			updateUserActivities($act_ket);
			cout('<script type="text/javascript">parent.window.location="'.$pageUrl.'/view/'.$kdnews.'/";</script>');
		} else {
			cout('<script type="text/javascript">parent.showError(\''.$err.'\');</script>');
		}
		exit;
	}
	exit;
}
if ($a=="section_edit") {
	if (!authorizedModule("news_edit", $ses_kduser)) {
		unAuthorizedAccess("news_edit");
	} else {
		$id = cekpost(cleanQuery($_GET["id"]), "0");
		$rs=array(); $q="SELECT * FROM news WHERE kdnews='$id'";
		callRS($rs, $q);
		cout('<form method="post" target="quick_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do_edit" role="form">');
			cout('<input type="hidden" name="kirim" id="kirim" value="1" />');
			cout('<input type="hidden" name="kdnews" id="kdnews" value="'.$rs[0]["kdnews"].'" />');
			cout('<dl class="dl-horizontal dldata">');
				if (authorizedModule("news_element_title", $ses_kduser)) {
					cout('<dt><label for="judul">Title</label></dt>');
					cout('<dd><input class="form-control" type="text" name="judul" id="judul" value="'.$rs[0]["judul"].'" /></dd>');
				}
				cout('<dt><label for="judul">Short URL</label></dt>');
				cout('<dd><input class="form-control" type="text" name="short_url" id="short_url" value="'.$rs[0]["short_url"].'" /></dd>');
				if (authorizedModule("news_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', $rs[0]["tanggal"]).'" />
									<label for="tanggal" class="input-group-addon btn">
										<span class="glyphicon glyphicon-calendar"></span>
									</label>
								</div>
							</div>
						</div>
					</dd>');
				}
				if (authorizedModule("news_element_active", $ses_kduser)) {
					$isactive0 = intval($rs[0]["isactive"])==0?'selected="selected"':'';
					$isactive1 = intval($rs[0]["isactive"])==1?'selected="selected"':'';
					cout('<dt><label for="isactive">Active Status</label></dt>');
					cout('<dd>
						<select name="isactive" id="isactive" class="form-control">
							<option value="0" '.$isactive0.'>Non-Active</option>
							<option value="1" '.$isactive1.'>Active</option>
						</select>
					</dd>');
				}
				if (authorizedModule("news_element_content", $ses_kduser)) {
					cout('<dt><label for="isi">Description</label></dt>');
					cout('<dd><textarea name="isi" id="isi" rows="10" cols="80" class="form-control">'.$rs[0]["isi"].'</textarea></dd>');
				}
				cout('<dt></dt>');
				cout('<dd class="err"></dd>');
				
				cout('<dt></dt>');
				cout('<dd><button class="btn btn-primary" type="submit">Update</button></dd>');
			cout('</dl>');
		cout('</form>');
		cout('<script>parent.bindDatePicker(\'.tanggal\');</script>');
		cout('<script>
			parent.tinymce.init({
				selector: "#isi",
				theme: "modern",
				plugins: [
					"advlist autolink lists link image charmap print preview hr anchor pagebreak",
					"searchreplace wordcount visualblocks visualchars code fullscreen",
					"insertdatetime media nonbreaking contextmenu directionality",
					"emoticons template paste textcolor colorpicker textpattern imagetools"
				],
				menubar: "edit",
				toolbar1: "insertfile undo redo | styleselect | bold italic | bullist numlist | link image | preview code | template",
				image_advtab: true,
				style_formats: [
					{ title: "Ashtanga Blue Bold text (14px)", inline: "span", styles: { color: "#4c5aa2", "font-weight": "bold", "font-size": "14px" } },
					{ title: "Ashtanga Blue Bold text (default)", inline: "span", styles: { color: "#4c5aa2", "font-weight": "bold" } },
					{ title: "Red text", inline: "span", styles: { color: "#ff0000" } },
					{ title: "Default text", inline: "span", styles: { color: "inherit", "font-family":"inherit", "font-weight":"normal", "font-size":"100%", "font-style":"normal", "line-height":"inherit" } },
					//{ title: "Green text", inline: "span", styles: { color: "#00ff00" } },
					//{ title: "Blue text", inline: "span", styles: { color: "#0000ff" } }
				],
				templates: [
					{ title: "Test template 1", content: "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus urna sapien, eleifend at magna sed, vestibulum semper diam. Aenean neque ligula, congue sed porta volutpat, ultrices eu purus. Curabitur vestibulum ex id nisi lobortis mollis. Pellentesque consectetur ultricies mattis. Praesent et ornare dui. Proin et iaculis nisl. Proin quam nisl, aliquam non dolor in, commodo lobortis ligula. Vestibulum aliquam orci urna, ac pulvinar eros pulvinar in. Aenean at lorem ipsum. Quisque dignissim odio pulvinar, aliquet nulla et, viverra nibh. Suspendisse non urna id odio dapibus commodo tempor quis lorem. Nunc quis tempus urna, quis egestas nulla. Aliquam sollicitudin et massa sed congue. Maecenas et nibh sit amet neque aliquam congue ut id turpis. Vivamus vel pretium eros, non tristique nisl. Morbi sed dictum risus, in finibus lectus.</p><p>Mauris <strong>lacus dolor, imperdiet sit amet sapien quis, dignissim efficitur arcu. Fusce in pretium enim, sit amet ornare urna. Duis nec ipsum nunc. Fusce rutrum nibh vulputate auctor lacinia. Pellentesque viverra interdum pharetra. Nunc et justo condimentum, aliquam neque molestie, efficitur dolor. Suspendisse in dignissim orci. Nunc dui mauris, tincidunt id odio vitae, egestas vehicula quam. Donec ac tortor eget nulla aliquet iaculis. Vivamus imperdiet nisi in neque luctus bibendum. Integer neque est, pulvinar vitae efficitur ut, condimentum quis risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis</strong> egestas.</p><p>Ut <em>aliquet nec tortor blandit bibendum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ornare elit blandit augue hendrerit hendrerit. Maecenas vel dui condimentum, tempor urna et, consequat risus. Integer ullamcorper diam vel felis pharetra, eget congue magna tincidunt. Quisque pharetra mauris sed justo imperdiet vulputate. In eu purus id nisi facilisis facilisis quis sit amet libero. Morbi pulvinar imperdiet accumsan. Etiam vehicula orci nec quam pulvinar efficitur. Aliquam hendrerit justo mi, tempus lacinia arcu efficitur</em> at.</p><p>Duis <span style=\"color: #4c5aa2; font-weight: bold; font-size: 14px;\">auctor ornare sapien et feugiat. Morbi interdum laoreet mi quis tempor. Curabitur nec molestie nunc, in ullamcorper nisl. Nunc diam lectus, posuere a lorem eu, laoreet iaculis dolor. Duis et nisi finibus, iaculis mauris et, elementum elit. Praesent ut tincidunt purus, vel efficitur massa. Pellentesque at bibendum quam. Aenean iaculis neque vitae commodo suscipit. Morbi sit amet velit eu mi sagittis semper. Cras vitae libero sagittis, viverra lectus non, varius nunc. In consequat tortor quis justo tincidunt, et pharetra neque scelerisque. Aliquam eleifend tincidunt lorem eget condimentum. Nunc finibus cursus augue, id molestie sapien scelerisque quis. Sed enim nunc, vulputate et ullamcorper lacinia, varius a turpis. Suspendisse vitae aliquam</span> diam.</p><p>Cras <span style=\"color: #4c5aa2; font-weight: bold;\">in lacus a ex luctus laoreet. Vivamus ornare mollis dictum. Nam bibendum sit amet ante quis ornare. Sed ipsum metus, aliquam a nisi et, cursus congue lorem. Integer suscipit finibus ex vitae lobortis. Donec tempus mauris eget congue vestibulum. Donec eu iaculis est. Ut nec efficitur nulla, quis facilisis</span> nisi.</p><p>Aliquam <span style=\"color: #ff0000;\">vel ipsum auctor, consequat dolor ac, tempor</span> purus. Integer <span style=\"color: #00ff00;\">mollis varius elit, eget venenatis sem ullamcorper</span> in. Donec <span style=\"color: #0000ff;\">scelerisque ultricies risus eget</span> ullamcorper. Mauris massa est, volutpat sit amet tristique ut, ultricies in sapien. Mauris vel finibus arcu. Sed fermentum, nulla ac molestie mollis, justo magna vulputate ex, sed tincidunt dolor nunc eget sem. Suspendisse varius ante vitae aliquam eleifend. Proin quam nibh, condimentum id dapibus id, consequat vel tellus. Pellentesque pellentesque id dui varius auctor.</p><ul><li>Duis pharetra turpis ipsum, at maximus enim placerat vitae.</li><li>Duis nec finibus mauris.</li></ul><p>Ut sollicitudin eget nisl a vehicula.</p><ul style=\"list-style-type: circle;\"><li>Duis bibendum, velit id convallis eleifend, arcu elit lobortis massa, id finibus ante nibh sit amet ligula.</li><li>Nulla facilisi.</li></ul><p>Praesent id ligula consectetur magna gravida varius at malesuada risus.</p><ul style=\"list-style-type: square;\"><li>Suspendisse potenti.</li><li>Nunc vitae laoreet arcu, at porttitor nulla.</li></ul><p>Fusce scelerisque porta dui ac interdum.</p><ol style=\"list-style-type: lower-alpha;\"><li>Praesent eget velit orci.</li><li>Donec turpis nisi, suscipit et ipsum nec, elementum molestie ex.</li></ol><p>Vestibulum elementum, lorem vel pulvinar hendrerit, diam justo sollicitudin velit, sed volutpat lorem tellus eget mi.</p><ol style=\"list-style-type: lower-greek;\"><li>Donec sodales lobortis consectetur.</li><li>Nulla viverra ornare tortor.</li><li>Duis dictum ante eu elit tempus tempus.</li></ol><p>Integer molestie metus sit amet ipsum laoreet maximus.</p><ol style=\"list-style-type: lower-roman;\"><li>Maecenas vel risus at lacus malesuada varius et quis quam.</li><li>Ut cursus lectus at lorem placerat, ut sollicitudin orci congue.</li></ol><p>Fusce et sodales ipsum.</p><ol style=\"list-style-type: upper-alpha;\"><li>Ut ac dolor et arcu mollis rutrum et ut velit.</li><li>Donec sagittis a mi id venenatis.</li></ol><p>Integer fringilla, orci at scelerisque rhoncus, nisl magna tincidunt nulla, id vulputate nunc orci vel nunc.</p><ol style=\"list-style-type: upper-roman;\"><li>Donec consectetur nulla ac pretium ultricies.</li><li>Fusce vel mi ut turpis tincidunt placerat id eu ligula.</li><li>Quisque vel posuere metus, in molestie neque.</li></ol><p>Nam feugiat nunc quis leo blandit interdum. Quisque sit amet imperdiet mauris. Pellentesque a nibh egestas, bibendum orci et, scelerisque lectus. Cras posuere, urna quis congue tempus, nunc dolor volutpat augue, ut tempor libero justo non magna. Mauris tempor magna orci, et luctus mi ornare sit amet. Nulla facilisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. In sagittis vulputate felis id commodo. Aliquam in nibh ornare, euismod ante eu, hendrerit metus.</p><p>&nbsp;</p>" },
					{ title: "Test template 2", content: "Test 2" }
				],
				//plugins: ["image, code"],
				file_browser_callback: function(field, url, type, win) {
					tinyMCE.activeEditor.windowManager.open({
						file: "/'.adminFolder.'/kcfinder/browse.php?opener=tinymce4&field=" + field + "&type=" + type,
						title: "KCFinder",
						width: 700,
						height: 500,
						inline: true,
						close_previous: false
					}, {
						window: win,
						input: field
					});
					return false;
				}
			});
		</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 = "News: Editing... [kd: ".$rs[0]["kdnews"]."][nama: ".$rs[0]["nama"]."]";
		updateUserActivities($act_ket);
		exit;
	}
}
if ($a=="do_add") {
	$kirim = cekpost(cleanQuery($_REQUEST["kirim"]), "");
	$err = "";
	if ($kirim=="1") {
		$judul = cekpost(cleanQuery($_REQUEST["judul"]), "");
		$tanggal = cekpost(cleanQuery($_REQUEST["tanggal"]), "");
		$isi = cekpost(cleanQuery($_REQUEST["isi"]), "");
		$isactive = cekpost(cleanQuery($_REQUEST["isactive"]), 0);
		if ($tanggal!="") { $tanggal = strtotime($tanggal." ".date('H:i:s', time())); }
		if ($judul=="") { $err.= BSErrorMessage('Title must be filled'); }
		if ($tanggal=="") { $err.= BSErrorMessage('Date must be filled'); }
		if ($isi=="") { $err.= BSErrorMessage('Description must be filled'); }
		if ($err=="") {
			$creby = $_SESSION["user"]["inisial"];
			$cretime = time();
			$flag = 0;
			$url = cleanURL($judul);
			do {
				$rscek = array(); $qcek = "SELECT kdnews FROM news WHERE url = '$url'";
				callRS($rscek, $qcek);
				if (count($rscek)!=0) {
					$flag = 0;
					$url = $url."-";
				} else {
					$flag = 1;
				}
			} while($flag==0);
			$kdnews = getID("news", "kdnews");
			$q = "INSERT INTO news (kdnews, judul, url, tanggal, isi, isactive, creby, cretime) 
				VALUES ('$kdnews', '$judul', '$url', '$tanggal', '$isi', '$isactive', '$creby', '$cretime')";
			execRS($q);
			$act_ket = "News: Add [kd: $kdnews][judul: $judul][tanggal: $tanggal][isi: $isi][isactive: $isactive]";
			updateUserActivities($act_ket);
			cout('<script type="text/javascript">parent.window.location="'.$pageUrl.'/view/'.$kdnews.'/";</script>');
		} else {
			cout('<script type="text/javascript">parent.showError(\''.$err.'\');</script>');
		}
		exit;
	}
	exit;
}
if ($a=="section_add") {
	if (!authorizedModule("news_add", $ses_kduser)) {
		unAuthorizedAccess("news_add");
	} else {
		cout('<form method="post" target="quick_iframe" action="/'.adminFolder.'/_ajax/'.$ajax_page.'?a=do_add" role="form">');
			cout('<input type="hidden" name="kirim" id="kirim" value="1" />');
			cout('<dl class="dl-horizontal dldata">');
				cout('<dt><label for="judul">Title</label></dt>');
				cout('<dd><input class="form-control" type="text" name="judul" id="judul" /></dd>');
				
				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>');
				
				cout('<dt><label for="isactive">Active Status</label></dt>');
				cout('<dd>
					<select name="isactive" id="isactive" class="form-control">
						<option value="0">Non-Active</option>
						<option value="1">Active</option>
					</select>
				</dd>');
				
				cout('<dt><label for="isi">Description</label></dt>');
				cout('<dd><textarea name="isi" id="isi" rows="10" cols="80" class="form-control"></textarea></dd>');
				
				cout('<dt></dt>');
				cout('<dd class="err"></dd>');
				
				cout('<dt></dt>');
				cout('<dd><button class="btn btn-primary" type="submit">Add</button></dd>');
			cout('</dl>');
		cout('</form>');
		cout('<script>parent.bindDatePicker(\'.tanggal\');</script>');
		cout('<script>
			parent.tinymce.init({
				selector: "#isi",
				theme: "modern",
				plugins: [
					"advlist autolink lists link image charmap print preview hr anchor pagebreak",
					"searchreplace wordcount visualblocks visualchars code fullscreen",
					"insertdatetime media nonbreaking contextmenu directionality",
					"emoticons template paste textcolor colorpicker textpattern imagetools"
				],
				menubar: "edit",
				toolbar1: "insertfile undo redo | styleselect | bold italic | bullist numlist | link image | preview code | template",
				image_advtab: true,
				style_formats: [
					{ title: "Ashtanga Blue Bold text (14px)", inline: "span", styles: { color: "#4c5aa2", "font-weight": "bold", "font-size": "14px" } },
					{ title: "Ashtanga Blue Bold text (default)", inline: "span", styles: { color: "#4c5aa2", "font-weight": "bold" } },
					{ title: "Red text", inline: "span", styles: { color: "#ff0000" } },
					{ title: "Default text", inline: "span", styles: { color: "inherit", "font-family":"inherit", "font-weight":"normal", "font-size":"100%", "font-style":"normal", "line-height":"inherit" } },
					//{ title: "Green text", inline: "span", styles: { color: "#00ff00" } },
					//{ title: "Blue text", inline: "span", styles: { color: "#0000ff" } }
				],
				templates: [
					{ title: "Test template 1", content: "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus urna sapien, eleifend at magna sed, vestibulum semper diam. Aenean neque ligula, congue sed porta volutpat, ultrices eu purus. Curabitur vestibulum ex id nisi lobortis mollis. Pellentesque consectetur ultricies mattis. Praesent et ornare dui. Proin et iaculis nisl. Proin quam nisl, aliquam non dolor in, commodo lobortis ligula. Vestibulum aliquam orci urna, ac pulvinar eros pulvinar in. Aenean at lorem ipsum. Quisque dignissim odio pulvinar, aliquet nulla et, viverra nibh. Suspendisse non urna id odio dapibus commodo tempor quis lorem. Nunc quis tempus urna, quis egestas nulla. Aliquam sollicitudin et massa sed congue. Maecenas et nibh sit amet neque aliquam congue ut id turpis. Vivamus vel pretium eros, non tristique nisl. Morbi sed dictum risus, in finibus lectus.</p><p>Mauris <strong>lacus dolor, imperdiet sit amet sapien quis, dignissim efficitur arcu. Fusce in pretium enim, sit amet ornare urna. Duis nec ipsum nunc. Fusce rutrum nibh vulputate auctor lacinia. Pellentesque viverra interdum pharetra. Nunc et justo condimentum, aliquam neque molestie, efficitur dolor. Suspendisse in dignissim orci. Nunc dui mauris, tincidunt id odio vitae, egestas vehicula quam. Donec ac tortor eget nulla aliquet iaculis. Vivamus imperdiet nisi in neque luctus bibendum. Integer neque est, pulvinar vitae efficitur ut, condimentum quis risus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis</strong> egestas.</p><p>Ut <em>aliquet nec tortor blandit bibendum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum ornare elit blandit augue hendrerit hendrerit. Maecenas vel dui condimentum, tempor urna et, consequat risus. Integer ullamcorper diam vel felis pharetra, eget congue magna tincidunt. Quisque pharetra mauris sed justo imperdiet vulputate. In eu purus id nisi facilisis facilisis quis sit amet libero. Morbi pulvinar imperdiet accumsan. Etiam vehicula orci nec quam pulvinar efficitur. Aliquam hendrerit justo mi, tempus lacinia arcu efficitur</em> at.</p><p>Duis <span style=\"color: #4c5aa2; font-weight: bold; font-size: 14px;\">auctor ornare sapien et feugiat. Morbi interdum laoreet mi quis tempor. Curabitur nec molestie nunc, in ullamcorper nisl. Nunc diam lectus, posuere a lorem eu, laoreet iaculis dolor. Duis et nisi finibus, iaculis mauris et, elementum elit. Praesent ut tincidunt purus, vel efficitur massa. Pellentesque at bibendum quam. Aenean iaculis neque vitae commodo suscipit. Morbi sit amet velit eu mi sagittis semper. Cras vitae libero sagittis, viverra lectus non, varius nunc. In consequat tortor quis justo tincidunt, et pharetra neque scelerisque. Aliquam eleifend tincidunt lorem eget condimentum. Nunc finibus cursus augue, id molestie sapien scelerisque quis. Sed enim nunc, vulputate et ullamcorper lacinia, varius a turpis. Suspendisse vitae aliquam</span> diam.</p><p>Cras <span style=\"color: #4c5aa2; font-weight: bold;\">in lacus a ex luctus laoreet. Vivamus ornare mollis dictum. Nam bibendum sit amet ante quis ornare. Sed ipsum metus, aliquam a nisi et, cursus congue lorem. Integer suscipit finibus ex vitae lobortis. Donec tempus mauris eget congue vestibulum. Donec eu iaculis est. Ut nec efficitur nulla, quis facilisis</span> nisi.</p><p>Aliquam <span style=\"color: #ff0000;\">vel ipsum auctor, consequat dolor ac, tempor</span> purus. Integer <span style=\"color: #00ff00;\">mollis varius elit, eget venenatis sem ullamcorper</span> in. Donec <span style=\"color: #0000ff;\">scelerisque ultricies risus eget</span> ullamcorper. Mauris massa est, volutpat sit amet tristique ut, ultricies in sapien. Mauris vel finibus arcu. Sed fermentum, nulla ac molestie mollis, justo magna vulputate ex, sed tincidunt dolor nunc eget sem. Suspendisse varius ante vitae aliquam eleifend. Proin quam nibh, condimentum id dapibus id, consequat vel tellus. Pellentesque pellentesque id dui varius auctor.</p><ul><li>Duis pharetra turpis ipsum, at maximus enim placerat vitae.</li><li>Duis nec finibus mauris.</li></ul><p>Ut sollicitudin eget nisl a vehicula.</p><ul style=\"list-style-type: circle;\"><li>Duis bibendum, velit id convallis eleifend, arcu elit lobortis massa, id finibus ante nibh sit amet ligula.</li><li>Nulla facilisi.</li></ul><p>Praesent id ligula consectetur magna gravida varius at malesuada risus.</p><ul style=\"list-style-type: square;\"><li>Suspendisse potenti.</li><li>Nunc vitae laoreet arcu, at porttitor nulla.</li></ul><p>Fusce scelerisque porta dui ac interdum.</p><ol style=\"list-style-type: lower-alpha;\"><li>Praesent eget velit orci.</li><li>Donec turpis nisi, suscipit et ipsum nec, elementum molestie ex.</li></ol><p>Vestibulum elementum, lorem vel pulvinar hendrerit, diam justo sollicitudin velit, sed volutpat lorem tellus eget mi.</p><ol style=\"list-style-type: lower-greek;\"><li>Donec sodales lobortis consectetur.</li><li>Nulla viverra ornare tortor.</li><li>Duis dictum ante eu elit tempus tempus.</li></ol><p>Integer molestie metus sit amet ipsum laoreet maximus.</p><ol style=\"list-style-type: lower-roman;\"><li>Maecenas vel risus at lacus malesuada varius et quis quam.</li><li>Ut cursus lectus at lorem placerat, ut sollicitudin orci congue.</li></ol><p>Fusce et sodales ipsum.</p><ol style=\"list-style-type: upper-alpha;\"><li>Ut ac dolor et arcu mollis rutrum et ut velit.</li><li>Donec sagittis a mi id venenatis.</li></ol><p>Integer fringilla, orci at scelerisque rhoncus, nisl magna tincidunt nulla, id vulputate nunc orci vel nunc.</p><ol style=\"list-style-type: upper-roman;\"><li>Donec consectetur nulla ac pretium ultricies.</li><li>Fusce vel mi ut turpis tincidunt placerat id eu ligula.</li><li>Quisque vel posuere metus, in molestie neque.</li></ol><p>Nam feugiat nunc quis leo blandit interdum. Quisque sit amet imperdiet mauris. Pellentesque a nibh egestas, bibendum orci et, scelerisque lectus. Cras posuere, urna quis congue tempus, nunc dolor volutpat augue, ut tempor libero justo non magna. Mauris tempor magna orci, et luctus mi ornare sit amet. Nulla facilisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. In sagittis vulputate felis id commodo. Aliquam in nibh ornare, euismod ante eu, hendrerit metus.</p><p>&nbsp;</p>" },
					{ title: "Test template 2", content: "Test 2" }
				],
				//plugins: ["image, code"],
				file_browser_callback: function(field, url, type, win) {
					tinyMCE.activeEditor.windowManager.open({
						file: "/'.adminFolder.'/kcfinder/browse.php?opener=tinymce4&field=" + field + "&type=" + type,
						title: "KCFinder",
						width: 700,
						height: 500,
						inline: true,
						close_previous: false
					}, {
						window: win,
						input: field
					});
					return false;
				}
			});
		</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 = "News: Adding...";
		updateUserActivities($act_ket);
		exit;
	}
}
?>