<?
//***************************************************
// http://www.scriptindonesia.com
// Solusi Hemat Script Bisnis Online Anda
// Menerima Jasa Pembuatan Website & Template Website
//***************************************************
?>
<?
//Edit Script AW 20160221
//if (session_is_registered("valid_admin")) {
  if (isset($_SESSION['valid_admin'])) {
?>

<!--- Start TinyMCE -->
	<script src="../tinymcpuk/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
	<script src="../tinymcpuk/jscripts/tiny_mce/tiny_lokomedia.js" type="text/javascript"></script>
<!-- Finish TinyMCE -->

<script type="text/javascript">
<!--
function confirmation(noid) {
	var answer = confirm("Apakah anda ingin menghapus halaman depan ini ?")
	if (answer){
		//alert("Bye bye!")
		window.location = "?m=editpage&page=delete&no=" + noid;

	}

}
//-->
</script>
<style type="text/css">
<!--
.style1 {font-size: x-small}
.style3 {color: #FF0000}
.style5 {
	color: #99CC00;
	font-weight: bold;
}
.style13 {color: #666666}
.style14 {font-size: x-small; color: #666666; }
-->
</style>

<table width="100%" border="0" cellpadding="2" cellspacing="0" bgcolor="#bfd6ed">
  <tr bgcolor="#8c759a">
    <td>
        <h2>&nbsp;&nbsp;<img src="images/scriptindonesia.png" width="48" height="48" align="absmiddle" />&nbsp; <font style="font-family: sans-serif, Arial, Helvetica"> Halaman Depan Manager ... </font></h2>
    </td>
  </tr>
  <tr>
    <td width="100%" height="2" bgcolor="#EF9400"></td>
  </tr>
  <tr>
    <td width="100%" height="4" bgcolor="#333333">
        <!-- ------------------------------------- -->
        <div id="menu_button2">
          <ul>
            <li><a href="#"><font color="#ffffff"><u><?= $db->config("bank2") ?></u></font></a></li>
            <!--<li><a href="?m=editpage&amp;page=addnew"><font color="#ffffff"><u>Tambah Halaman Depan</u></font></a></li>-->
          </ul>
        </div>
        <!-- ------------------------------------- -->
    </td>
  </tr>
</table>

<!--
<div id="menu_button2">
  <ul>
    <li><a href="?m=editpage&amp;page=addnew"><u>Tambah Halaman Depan</u></a></li>
  </ul>
</div>
-->

<?
switch($page) {
	default :
?>
<?
//---pagination----------------
$limit = '50';        // How many results should be shown at a time
$scroll = '0';        // Do you want the scroll function to be on (1 = YES, 2 = NO)
$scrollnumber = '50'; // How many elements to the record bar are shown at a time when the scroll function is on
//-------------pagination--------------
if (!isset ($_GET['show'])) {
	$display = 1;
} else {
	$display = $_GET['show'];
}
$start = (($display * $limit) - $limit);

//if($uidm == 001) {
//$db->select("*", "member", $kat);

  //$numrows = $db->count_records("page", $filter);
  //$db->select("no, userid, nama, kota, testimoni, foto, published, tgl", "newssilver", "userid='$user_session'", "tgl DESC");
  //$db->select("id_page, id_user, judul, isi_page, gambar, tanggal, counter, published", "page", "", "id_page desc");

  //AW 20140208 Edit
if($kat > 0 or !$kat) {
	$order = "id_page asc";
}
if($kat == "") {
	$numrows = $db->count_records("page", "");
	$db->select("id_page, id_user, judul, isi_page, gambar, tanggal, counter, published", "page", "", $order, "", "", "$start, $limit"); //AW
}
$sel = "selected";
?>
<table width="100%" border="0" cellspacing="0" cellpadding="5">

  <tr class="tbl_header">
    <td width="4%" align="center">#</td>
    <td width="26%" align="center">Judul Halaman</td>
    <td width="63%" align="center">Isi Halaman</td>
    <td width="7%" align="center">Published</td>
    <!--<td width="9%" align="center">&nbsp;</td>-->
  </tr>
<?


$j=$db->num_rows();
for($i=0;$i<$j;$i++) {
//	$nom = $i + 1;
	$nom = $i + 1 + $start; //AW
	$lid = $i - 1;
	if(is_odd($i) == 0) {
		$class = "tblrow_ganjil";
	} else {
		$class = "tblrow_genap";
	}
	if($db->result($i, "published") > 0) {
		$img = "<a href='?m=editpage&page=publish&pub=0&no=".$db->result($i, "id_page")."'><img src='images/tick.png' border=0 title='Click to Unpublish'></a>";
	} else {
		$img = "<a href='?m=editpage&page=publish&pub=1&no=".$db->result($i, "id_page")."'><img src='images/publish_x.png' border=0 title='Click to Publish'></a>";
	}
?>

  <tr class="<?= $class; ?>">
    <td width="4%"><?= $nom; ?> </td>
    <td width="26%"><a href="?m=editpage&page=addnew&edit=1&no=<?= $db->result($i, "id_page"); ?>"><?= $db->result($i, "judul"); ?></a></td>
    <!--<td width="73%"><?= substr($db->result($i, "isi_page"),0,100); ?></td>-->
    <td width="63%" align="left">Untuk melihat detail isi halaman ini silahkan klik judul halaman...</td>
    <td width="7%" align="center"><?= $img; ?></td>
    <!--<td><div id="delete"><a href="#" onclick='confirmation(<?= $db->result($i, "id_page"); ?>)' style='cursor:hand; padding-left:15px'>Delete</a></div></td>-->
  </tr>
<?
	}
?>
</table>
<br />
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td align="center">
     <?php

//}
//

$paging = ceil ($numrows / $limit);

// Display the navigation
if ($display > 1) {
	$previous = $display - 1;
?>
  <a href="?m=editpage&kat=<?= $kat; ?>&show=1" style="font-size:10px; color:#0000CC"><< Awal </a> | <a href="?m=editpage&kat=<?= $kat; ?>&show=<?= $previous; ?>" style="font-size:10px; color:#0000CC">< Sebelumnya </a> |
  <?php

}

if ($numrows != $limit) {
	if ($scroll == 1) {
		if ($paging > $scrollnumber) {
			$first = $display;
			$last = ($scrollnumber - 1) + $display;
		}
	} else {
		$first = 1;
		$last = $paging;
	}
	if ($last > $paging ) {
		$first = $paging - ($scrollnumber - 1);
		$last = $paging;
	}

	for ($i = $first;$i <= $last;$i++){
		if ($display == $i) {
?>
[ <b>
<?= $i ?>
</b> ]
<?php

		} else {

?>
[ <a href="?m=editpage&kat=<?= $kat; ?>&show=<?= $i; ?>" style="font-size:10px; color:#0000CC">
<?= $i; ?>
</a> ]
<?php

		}

	}

}

if ($display < $paging) {
	$next = $display + 1;
?>
| <a href="?m=editpage&kat=<?= $kat; ?>&show=<?= $next; ?>" style="font-size:10px; color:#0000CC">Selanjutnya ></a> | <a href="?m=editpage&kat=<?= $kat; ?>&show=<?= $paging; ?>" style="font-size:10px; color:#0000CC">Terakhir >></a>
<?php

}
//
?>
    </td>
  </tr>
</table>
<br />
<div class="bingkai-ket">
<ul>
    Ket : lihat kolom <strong>published</strong><br />
    --------------------------------------------------
    <li>icon <strong>silang</strong>&nbsp; = hal.depan belum diterbitkan</li>
    <li>icon <strong>ceklist</strong> = hal.depan sudah diterbitkan</li>
    --------------------------------------------------
<ul>
</div>
<?
	break;
	case addnew :
	if($edit > 0) {
	$db->select("id_page, id_user, judul, isi_page, gambar, tanggal, counter, published", "page", "id_page='$no'");
  //$db->select("no, userid, nama, kota, testimoni, foto, published, tgl, judul, website, email, hp, company, tayang", "newssilver", "no=$no");
		$no = $db->result(0, "id_page");
		$foto = $db->result(0, "gambar");
		$isi = $db->result(0, "isi_page");
		$judul = $db->result(0, "judul");
		$userid = $db->result(0, "id_user");

	} else {
		$foto = "";
		$isi = "";
		$judul ="";
	}

?>
<form action="?m=editpage&amp;page=submit" method="post" enctype="multipart/form-data">
  <div align="center">
    <center>
      <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber1" bordercolor="#EDEDE9">
        <tr class="tbl_header">
          <td width="100%" align="center"><?
		  if($act == 1 or $act) {
?>
<div id="notice"><img src="images/notice-page.png" width="29" height="29" align="absmiddle" />Data telah berhasil diupdate ! </div>
	        <?
	}
	?>
            <b><font face="Arial">Input Halaman</font></b></td>
        </tr>
        <tr>
          <td width="100%" style="border-style: none; border-width: medium"><div align="center">
              <table width="100%" border="0" cellspacing="0" cellpadding="1">
                <tr>
                  <td align="left"><div align="left"></div></td>
                </tr>
                <!--<tr>
                  <td align="left">
<p align="center" class="style5">Form Pengisian Page<font color="#00CC00" size="2" face="Tahoma, Arial, Helvetica, sans-serif"><strong>
                      </strong> </font> </p>
                    </td>
                </tr>-->
                <tr bgcolor="#7fa1c2">
                  <td align="left" height="25"><div align="center"><font color="#000000" size="2"><strong>JUDUL</strong></font></div></td>
                </tr>
                <tr>
                  <td align="left"><div align="center"><!--<span class="style5">Judul
                      Page : </span><span class="style3">*</span>-->
                      <input name="userid" type="hidden" class="form" id="userid" value="<?= $userid; ?>" size="75" />
                      <input name="edit" type="hidden" id="edit" value="<?= $edit; ?>" />
                      <input name="no" type="hidden" class="form" id="no" value="<?= $no; ?>" size="10" />
                    </div></td>
                </tr>
                <tr>                  
                  <td height="7" align="center"><br />
                      <input name="judul" type="hidden" id="judul" value="<?= $judul; ?>" size="100" />
                      <b>... <font size="5" face="Tahoma,Arial" color="#ff6700"><?= $judul; ?></font> ...</b>
                      <!--<textarea name="judul" cols="85" rows="2" class="form"><?= $judul; ?></textarea>-->
                      <br /><br />
                  </td>
                </tr>
                <!--
                <tr>
                  <td align="left"><br /><div align="center" class="style14"><font color="#ffffff"> Edit Page
                      , maksimal 100 karakter</font></div><br /></td>
                </tr>
                -->
                <tr bgcolor="#7fa1c2">
                  <td align="left" height="25"><div align="center"><font color="#000000" size="2"><strong>ISI
                      HALAMAN </strong></font></div></td>
                </tr>
                <tr>
                  <td align="left"><div align="center"><!--<span class="style5"><strong>Isi
                      page:</strong></span> <span class="style3">*</span>--> </div></td>
                </tr>
                <tr>
                  <td align="center"><br /><textarea id="loko" name="testi" cols="50" rows="35" class="form"><?= $isi; ?></textarea></td>
              <!--<td align="center"><textarea id="loko" name="testi" cols="50" rows="15" class="form" id="testi"><?= $isi; ?></textarea></td>-->
                </tr>
                <tr>
                  <td align="center"><div align="center" class="style14">Isi Halaman,
                      maksimal unlimited karakter<br />Tips : agar lebih rapih sebaiknya ketik dulu di aplikasi word anda, lalu copy dan paste di atas.</div></td>
                </tr>
                <tr>
                  <td align="center">&nbsp;</td>
                </tr>
                <!--
                <tr>
                  <td align="center"><div align="center" class="style5">Gambar
                      : </div></td>
                </tr>
                <tr>
                  <td align="center"><div align="center">
                      <label>
                      <?
		  	if($foto <> "") {
		?>
                      <img src="../images/page/<?= $foto; ?>" alt="<?= $judul; ?>" /><br />
                      <?
		 }
		 ?>
                      <input name="img1" type="file" id="img1" size="20" class="form" />
                      </label>
                      <input name="foto" type="hidden" class="form" id="foto" value="<?= $foto; ?>" size="12" />
                    </div></td>
                </tr>
                <tr>
                  <td align="left"><div align="center" class="style1 style13">Upload
                      gambar baru anda (hanya JPG)<br>
                      Ukuran maksimal 200KB, dimensi lebar maksimal 730 pixels,
                      tinggi maksimal 300 pixels</div></td>
                </tr>
                <tr>
                  <td align="left">&nbsp;</td>
                </tr>
                -->
                <tr>
                  <td align="left">&nbsp;</td>
                </tr>
                <tr>
                  <td align="left" class="bingkai-ket"><div align="center">
                      <br /><label>
                      <input name="Submit" type="submit" class="button"  value="SAVE" />
                      </label>
                      <label>
                      <input type="button" name="cancel" id="cancel" value="CANCEL" onclick="javascript:history.go(-1)" class="cancelbutton" />
                      </label><br /><br />
                  </div></td>
                </tr>
              </table>
          </div></td>
        </tr>
      </table>
    </center>
  </div>
</form>
<?
	break;

	case submit :
	function getFileExtension($filename){
  return substr($filename, strrpos($filename, '.'));
}
if(getFileExtension($img1_name) == ".php" or getFileExtension($img1_name) == ".PHP" or getFileExtension($img1_name) == ".php4" or getFileExtension($img1_name) == ".PHP4" or getFileExtension($img1_name) == ".php5" or getFileExtension($img1_name) == ".PHP5" or getFileExtension($img1_name) == ".exe" or getFileExtension($img1_name) == ".EXE "or getFileExtension($img1_name) == ".htm" or getFileExtension($img1_name) == ".HTM" or getFileExtension($img1_name) == ".html" or getFileExtension($img1_name) == ".HTML" or getFileExtension($img1_name) == ".bat" or getFileExtension($img1_name) == ".BAT") {
		echo "<p>&nbsp;</p><p align=center style='color:red'><b>File harus berupa file image (jpg, gif atau png)</b></p>";

	} else {
	//---------upload foto
		if($img1 <> "") {
			$foto = $img1_name;
			$file = "../images/page/$img1_name";
			@copy("$img1" , $file);
			//$ukr2=getimagesize("../images/$img1_name");
					//	$w2=$ukr2[0];
					//	$h2=$ukr2[1];
		} else {
			$foto = $foto2;
		}
		//$nama = $db->dataku("nama", $userid);
		if($edit > 0) {
				$tgl_sekarang = date("Y-m-d");
				$jam_sekarang = date("H:i:s");
				$clientdate = date("Y-m-d H:i:s");
				if (empty($img1)) {
				$db->update("page", "isi_page='$testi', judul='$judul', tanggal='$clientdate'", "id_page='$no'");
				//echo "<meta http-equiv='refresh' content='0;URL=?m=editpage'>";
                                echo "<meta http-equiv='refresh' content='0;URL=?m=editpage&page=addnew&edit=1&no=$no'>";
				} else {
				$db->update("page", "isi_page='$testi', judul='$judul', tanggal='$clientdate', gambar='$foto'", "id_page='$no'");
				echo "<meta http-equiv='refresh' content='0;URL=?m=editpage'>";
				}
			} else {
				$clientdate = date("Y-m-d H:i:s");
				$db->insert("page", "", "'', 'admin', '$judul', '$testi', '$foto', '$clientdate', 0, 0");

				echo "<meta http-equiv='refresh' content='0;URL=?m=editpage'>";
			}
			}

		break;

		case publish :
		$db->update("page", "published='$pub'", "id_page='$no'");
		echo "<meta http-equiv='refresh' content='0;URL=?m=editpage'>";
	break;
	case delete :
		//echo "delete no $no";
		$db->delete("page", "id_page=$no");
		echo "<meta http-equiv='refresh' content='0;URL=?m=editpage'>";
	break;
}
?>

<?
} else {
echo "<meta http-equiv=\"refresh\" content=\"1; url=illegal.html\">";
}
?>