<?
//***************************************************
// 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 produk ini ?")
	if (answer){
		//alert("Bye bye!")
		window.location = "?m=produk&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"> Produk 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="?m=produk&amp;page=addnew"><font color="#ffffff"><u>Tambah Produk</u></font></a></li>
          </ul>
        </div>
        <!-- ------------------------------------- -->
    </td>
  </tr>
</table>

<!--
<div id="menu_button2"> 
  <ul>
    <li><a href="?m=produk&amp;page=addnew"><u>Tambah Berita</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("berita", $filter);	
  //$db->select("no, userid, nama, kota, testimoni, foto, published, tgl", "newssilver", "userid='$user_session'", "tgl DESC");
  //$db->select("id_berita, id_user, judul, isi_berita, gambar, tanggal, counter, published", "berita", "", "id_berita desc");
  
  //AW 20140208 Edit
if($kat > 0 or !$kat) {
	$order = "id desc";
}
if($kat == "") {  
	$numrows = $db->count_records("product", "");	
	$db->select("id, nama, harga, published, created, catid, file, hit, expire", "product", "", $order, "", "", "$start, $limit"); //AW  
}
$sel = "selected";
?>
<table width="1000" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr bgcolor="#FFFF33" class="tbl_header">
    <td width="4%" align="center"><strong>#</strong></td>
    <td width="4%" align="center"><strong>ID</strong></td>
    <td width="30%" align="center"><strong>Title</strong></td>
    <td width="9%" align="center"><strong>Published</strong></td>
    <td width="11%" align="center"><strong>Harga</strong></td>
    <td width="7%" align="center"><strong>Diorder</strong></td>
    <td width="8%" align="center">&nbsp;</td>
  </tr>
  <?
$db->select("id, nama, harga, published, created, catid, file, hit, expire", "product");

$j=$db->num_rows();
for($i=0;$i<$j;$i++) {
	$nom = $i + 1;
	$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=produk&page=publish&pub=0&no=".$db->result($i, "id")."'><img src='images/tick.png' border=0 title='Click to Unpublish'></a>";
	} else {
		$img = "<a href='?m=produk&page=publish&pub=1&no=".$db->result($i, "id")."'><img src='images/publish_x.png' border=0 title='Click to Publish'></a>";
	} 	
	
?>
  <tr class="<?= $class; ?>">
    <td width="4%"><?= $nom; ?></td>
    <td width="4%"><?= $db->result($i, "id"); ?></td>
    <td><a href="?m=produk&page=addnew&edit=1&no=<?= $db->result($i, "id"); ?>">
      <?= $db->result($i, "nama"); ?>
    </a></td>
    <td align="center"><?= $img; ?></td>
    <td align="right"><?= rupiah($db->result($i, "harga")); ?></td>
    <td align="center"><?= $db->result($i, "hit"); ?></td>
    <td align="center"><div id="delete"><a href="#" onClick='confirmation(<?= $db->result($i, "id"); ?>)' 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=produk&kat=<?= $kat; ?>&show=1" style="font-size:10px; color:#0000CC"><< Awal </a> | <a href="?m=produk&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=produk&kat=<?= $kat; ?>&show=<?= $i; ?>" style="font-size:10px; color:#0000CC">
<?= $i; ?>
</a> ]
<?php
		
		}
	
	}

}

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

}
//
?>
    </td>
  </tr>
</table>
<br />
<div class="bingkai-ket">
<ul>
<br />
    ---------------------------------------------
    ---------------------------------------------
<ul>
</div>
<?
	break;
	case addnew :
	if($edit > 0) {
	$db->select("id, catid, nama, deskripsi, gambar, created, harga, published", "product", "id='$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");
		$foto = $db->result(0, "gambar");
		$isi = $db->result(0, "deskripsi");
		$judul = $db->result(0, "nama");
		$harga = $db->result(0, "harga"); 
		$catid = $db->result(0, "catid"); 
		$userid = $db->result(0, "id");
		
	} else {
		$foto = "";
		$isi = "";
		$judul ="";
	}	
	
?>
<form action="?m=produk&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-info.png" width="29" height="29" align="absmiddle" />Data telah berhasil diupdate ! </div>
	        <?
	}
	?>
            <b><font face="Arial">Input product</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 Berita<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> Produk</strong></font></div></td>
                </tr>
                <tr> 
                  <td align="left"><div align="center"><!--<span class="style5">Judul
                      product : </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 />
                  Nama Produk:<br>                  <textarea name="judul" cols="85" rows="2" class="form"><?= $judul; ?></textarea></td>
                </tr>
                <tr> 
                  <td align="left"><br /><div align="center" class="style14">Judul product
                      , maksimal 255 karakter</div><br /><br /></td>
                </tr>
                <tr> 
                  <td height="7" align="center"><br />
                  Kategori Produk:<br>                  <select name="cat" id="cat">
        <option value="0">- Select Category -</option>
        <?
	 
	$db->select("id, parent_id, title, published", "categories", "section='product' and parent_id=0"); 
	while($data = $db->fetch_row()) {
		if($catid == $data[0]) {
			$sel = "selected";
		} else {
			$sel = "";
		}		
		echo "<option value=$data[0] $sel>$data[2]</option>";
		$sql = mysql_query("select id, parent_id, title, published from categories where section='product' and parent_id=$data[0]");
		while($row=mysql_fetch_row($sql)) {
			if($catid == $row[0]) {
				$sel2 = "selected";
			} else {
				$sel2 = "";
			}
			echo "<option value=$row[0] $sel2>&nbsp;| $row[2]</option>";
		}	
	}
	 
	 ?>
            </select></td>
                </tr>
                <tr> 
                  <td align="left"><br /><div align="center" class="style14">Judul product
                      , maksimal 255 karakter</div><br /><br /></td>
                </tr>
				  				   <tr> 
                  <td height="7" align="center"><br />
                    Harga (Tanpa tanda baca)<br>                    <input name="harga" type="text" id="harga" value="<?= $harga; ?>" size="25"></td>
                </tr>
				   <tr> 
                  <td height="7" align="center"><br /></td>
                </tr>
                <tr bgcolor="#7fa1c2">
                  <td align="left" height="25"><div align="center"><font color="#000000" size="2"><strong>ISI
                    product </strong></font></div></td>
                </tr>
                <tr> 
                  <td align="left"><div align="center"><!--<span class="style5"><strong>Isi
                      product:</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"><br /><textarea name="testi" cols="50" rows="15" class="form" id="testi"><?= $isi; ?></textarea></td>-->
                </tr>
                <tr> 
                  <td align="center"><div align="center" class="style14">Isi product, 
                      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/news/<?= $foto; ?>" alt="<?= $judul; ?>" width="616" border="1" /><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 panjang maksimal 730 pixels,
                      lebar 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/news/$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("product", "nama='$judul', file='$myfile', catid='$cat', harga='$harga', deskripsi='$testi', published='1', expire='$expire', gambar='$foto'", "id='$no'");
				echo "<meta http-equiv='refresh' content='0;URL=?m=produk'>";
				} else {
				$db->update("product", "nama='$judul', file='$myfile', catid='$cat', harga='$harga', deskripsi='$testi', published='1', expire='$expire', gambar='$foto'", "id='$no'");
				echo "<meta http-equiv='refresh' content='0;URL=?m=produk'>";
				}
			} else {
				$clientdate = date("Y-m-d H:i:s");
 
			    $db->insert("product", "catid, nama, deskripsi, harga, gambar, published, created, file, expire", "'$cat', '$judul', '$testi', '$harga', '$foto', '1', '$clientdate', '$myfile', '$expire'");
				
				echo "<meta http-equiv='refresh' content='0;URL=?m=produk'>";
			}
			}

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

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