<?php
	require_once("config/koneksi.php");
?>
<!-- end jq -->
<script>
function confirmdelete(delUrl) {
   if (confirm("Anda yakin ingin menghapus?")) {
      document.location = delUrl;
   }
}
</script>

<?php
switch(@$_GET['act']){
  // Tampil Data nilaiatribut
  default:
  	?>
    <h2>Data Nilai Atribut</h2>
<table class="data">
<tr class="data">
	<th width="35" class="data">No. </th>
	<th class="data">Nama Atribut</th>
    <th colspan="2" class="data">Status Atribut</th>
    <th class="data">Nilai Atribut</th>
    <th class="data">Keterangan</th>
	<th width="100" class="data">Aksi</th>
</tr>
<?php
	$tampil=mysql_query("SELECT * FROM tb_atribut ORDER BY id_atribut asc");
    $no = 1;
    while ($r=mysql_fetch_array($tampil)){
      	$j=1;
		$jlhsub = mysql_result(mysql_query("SELECT COUNT(*) as jum FROM tb_nilaiatribut
						where id_atribut='$r[id_atribut]'"),0); // Jumlah Alternatif Kriteria
		$xx=$jlhsub+1;
		echo "<tr class='data'>";
		echo
				"<td class='data' rowspan=".$xx."><center>$no</center></td>
				<td class='data' rowspan=".$xx.">$r[nm_atribut]</td>
				<td class='data' rowspan=".$xx.">$r[status_atribut]</td>
				<td class='data' rowspan=".$xx." width='20'>
					<a href=media.php?module=nilaiatribut&act=forminput&id=$r[id_atribut] title='Tambah Data Nilai Atribut' class='with-tip'>
   					<center><img src='images/plus.png'></a>
				</td>
				</tr>
				";

		$querymarketing = mysql_query("SELECT * FROM tb_nilaiatribut where id_atribut='$r[id_atribut]' ORDER BY id_nilaiatribut asc");

		while ($p = mysql_fetch_array($querymarketing)){
    		echo "
				<tr class='data'>
				<td class='data'>$p[nm_nilaiatribut]</td>
				<td class='data'>$p[ket]</td>
				<td width=80 class='data'>
   				<a href=media.php?module=nilaiatribut&act=tampil&id=$p[id_nilaiatribut] title='Tampil' class='with-tip'>
   				<center><img src='images/view.png'></a>

   				<a href=media.php?module=nilaiatribut&act=edit&id=$p[id_nilaiatribut] title='Edit' class='with-tip'>
   				<img src='images/edit.gif'></a>

   				<a href=javascript:confirmdelete('media.php?module=nilaiatribut&act=hapus&id=$p[id_nilaiatribut]')
				title='Hapus' class='with-tip'>
   				<img src='images/cancel.gif'></center></a>

   				</td>";
				echo "</tr>";
			$j++;
		}

      $no++;
    }
?>
</table>
    <?php
  break;
   case "forminput":
   		$edit = mysql_query("SELECT * FROM tb_atribut WHERE id_atribut='$_GET[id]'");
    	$r    = mysql_fetch_array($edit);
  	?>
    <h2>Input Data Nilai Atribut</h2>
                <hr>
<form action="media.php?module=nilaiatribut&act=simpandata" method="post" id="nilaiatribut" name="nilaiatribut" enctype="multipart/form-data">
<table class="data">
<tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td class="data" width="200">ID Atribut</td>
    <td class="data" width="5">:</td>
	<td class="data"><input type="text" name="id_atribut" class="pendek"
    value="<?php echo $r['id_atribut'];?>" readonly /></td>
 </tr>
 <tr class="data">
	<td class="data">Nama Atribut</td>
    <td class="data">:</td>
	<td class="data"><input type="text" name="nm_atribut" class="panjang" value="<?php echo $r['nm_atribut']?>" readonly="readonly"/></td>
 </tr>
 <tr class="data">
	<td class="data">Status Atribut</td>
    <td class="data">:</td>
	<td class="data"><input type="text" name="status_atribut" class="panjang" value="<?php echo $r['status_atribut']?>" readonly="readonly"/></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td class="data">Nama Nilai Atribut</td>
    <td class="data">:</td>
	<td class="data"><input type="text" name="nm_nilaiatribut" class="sedang"/></td>
 </tr>
    <tr class="data">
        <td class="data">Keterangan</td>
        <td class="data">:</td>
        <td class="data">
            <textarea style="width: 100%" name="ket"></textarea>
        </td>
    </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data">
    <input type="button" name="button"  value="<< Kembali" class="button" onclick="history.go(-1)"/>
    <input type="submit" name="button"  value="Simpan" class="button" /> </td>
 </tr>
 </table>
 </form>
	<?php
  break;

  case "tampil":
  	$edit = mysql_query("SELECT tb_atribut.*, tb_nilaiatribut.* FROM
					tb_atribut join tb_nilaiatribut on tb_atribut.id_atribut=tb_nilaiatribut.id_atribut
					WHERE tb_nilaiatribut.id_nilaiatribut='$_GET[id]'");
    $r    = mysql_fetch_array($edit);
  ?>
    <h2>Detail Data Nilai Atribut</h2>
<form action="" method="post" id="nilaiatribut" name="nilaiatribut" enctype="multipart/form-data">
<table class="data">
<tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td width="200" class="data">ID Atribut</td>
    <td class="data" width="5">:</td>
	<td class="data"><?php echo $r['id_atribut'];?></td>
 </tr>
 <tr class="data">
	<td width="200" class="data">Nama Atribut</td>
    <td class="data" width="5">:</td>
	<td class="data"><?php echo $r['nm_atribut'];?></td>
 </tr>
 <tr class="data">
	<td width="200" class="data">Status Atribut</td>
    <td class="data" width="5">:</td>
	<td class="data"><?php echo $r['status_atribut'];?> &nbsp;%</td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
<tr class="data">
	<td width="200" class="data">ID Nilai Atribut</td>
    <td class="data" width="5">:</td>
	<td class="data"><?php echo $r['id_nilaiatribut'];?></td>
 </tr>
 <tr class="data">
	<td class="data">Nama Nilai Atribut</td>
    <td class="data">:</td>
	<td class="data"><?php echo $r['nm_nilaiatribut'];?></td>
 </tr>
    <tr class="data">
        <td class="data">Keterangan</td>
        <td class="data">:</td>
        <td class="data">
            <?php echo $r['ket'];?>
        </td>
    </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data">
    <input type="button" name="button"  value="<< Kembali" class="button" onclick="history.go(-1)"/></td>
 </tr>
 </table>
 </form>
 <?php
  break;

  case "edit":
  	$edit = mysql_query("SELECT tb_atribut.*, tb_nilaiatribut.* FROM
					tb_atribut join tb_nilaiatribut on tb_atribut.id_atribut=tb_nilaiatribut.id_atribut
					WHERE tb_nilaiatribut.id_nilaiatribut='$_GET[id]'");
    $r    = mysql_fetch_array($edit);
  ?>
    <h2>Edit Data Nilai Atribut</h2>
<form action="media.php?module=nilaiatribut&act=update" method="post" id="nilaiatribut" name="nilaiatribut" enctype="multipart/form-data">
<table class="data">
<tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td class="data" width="200">ID Atribut</td>
    <td class="data" width="5">:</td>
	<td class="data"><input type="text" name="id_atribut" class="pendek"
    value="<?php echo $r['id_atribut'];?>" readonly /></td>
 </tr>
 <tr class="data">
	<td class="data">Nama Atribut</td>
    <td class="data">:</td>
	<td class="data"><input type="text" name="nm_atribut" class="panjang" value="<?php echo $r['nm_atribut']?>" readonly="readonly"/></td>
 </tr>
 <tr class="data">
	<td class="data">Status Atribut</td>
    <td class="data">:</td>
	<td class="data"><input type="text" name="status_atribut" class="panjang" value="<?php echo $r['status_atribut']?>" readonly="readonly"/></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
<tr class="data">
	<td class="data" width="200">ID Nilai Atribut</td>
    <td class="data" width="5">:</td>
	<td class="data"><input type="text" name="id_nilaiatribut" class="pendek"
    value="<?php echo $r['id_nilaiatribut'];?>" readonly /></td>
 </tr>
 <tr class="data">
	<td class="data">Nama Nilai Atribut</td>
    <td class="data">:</td>
	<td class="data"><input type="text" name="nm_nilaiatribut" class="panjang" value="<?php echo $r['nm_nilaiatribut'];?>"/></td>
 </tr>
    <tr class="data">
        <td class="data">Keterangan</td>
        <td class="data">:</td>
        <td class="data">
            <textarea style="width: 100%" name="ket"><?php echo $r['ket'];?></textarea>
        </td>
    </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data"><hr /></td>
 </tr>
 <tr class="data">
	<td colspan="3" align="center" class="data">
    <input type="button" name="button"  value="<< Kembali" class="button" onclick="history.go(-1)"/>
    <input type="submit" name="button"  value="Ubah" class="button" /> </td>
 </tr>
 </table>
 </form>
 <?php
  break;

  case "simpandata":
  			$query=mysql_query("insert into tb_nilaiatribut(
							id_atribut,
							nm_nilaiatribut,
							ket
							)
						values(
							'$_POST[id_atribut]',
							'".strtoupper($_POST['nm_nilaiatribut'])."',
							'$_POST[ket]'
						)");


  	 if($query){
			?><script language="javascript">alert("Data sudah tersimpan")</script><?php
			?><script language="javascript">document.location.href="media.php?module=nilaiatribut"</script><?php
		}else{
			echo mysql_error();
		}
  break;

  case "update":
  			$query=mysql_query("
							UPDATE tb_nilaiatribut SET
							id_atribut      = '$_POST[id_atribut]',
							nm_nilaiatribut = '".strtoupper($_POST['nm_nilaiatribut'])."',
							ket             = '$_POST[ket]'
							WHERE id_nilaiatribut = '$_POST[id_nilaiatribut]'");

		if($query){
			?><script language="javascript">alert("Data sudah diubah !")</script><?php
			?><script language="javascript">document.location.href="media.php?module=nilaiatribut"</script><?php
		}else{
			echo mysql_error();
		}
  break;

  case "hapus":
  	$query=mysql_query("DELETE FROM tb_nilaiatribut WHERE id_nilaiatribut='$_GET[id]'");
		if($query){
			?><script language="javascript">alert("Data sudah dihapus !")</script><?php
			?><script language="javascript">document.location.href="media.php?module=nilaiatribut"</script><?php
		}else{
			echo mysql_error();
		}
  break;
}
  	?>