/home/kkco/public_html/home__2939f42/admin/page/widget_edit.php
<h4 class="text-center"><b>Edit Widget</b></h4>
<?php

if (isset($_GET['act'])&&$_GET['act']=='del')
{
	$sqlDel=mysql_query("delete from widget where id=".$_GET['id']."");
	if ($sqlDel)
	{
	echo "<div class=\"alert alert-info\">Berhasil Dihapus</div>";
	}
}
else
{
$sqlData=mysql_query("select * from widget where id=".$_GET['id']."");
$dataW=mysql_fetch_array($sqlData);

$sqlSimapan='';
if (isset($_POST['simpan']))
{
$sqlSimapan=mysql_query("update widget set title='".$_POST['title']."',type='".$_POST['type']."',content='".($_POST['type']==1?$_POST['file']:$_POST['html'])."' where id='".$_POST['id']."' ");
echo mysql_error();
}
if ($sqlSimapan)
{
	echo "<div class='alert alert-info'>Berhasil Diubah</div>";
}
else
{
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

<strong>Judul Widget</strong>
<input type="text" name="title" value="<?php echo $dataW['title']; ?>" required class="form-control" >
<input type='hidden' name="id" value="<?php echo $_GET['id']; ?>">
<strong>Tipe Widget</strong>
<select onChange="show_isi();" name="type" id="type" class="form-control" required>
<option value="">Silahkan Pilih</option>
<option  <?php echo $dataW['type']==1?"selected":""; ?> value="1">File</option>
<option <?php echo $dataW['type']==2?"selected":""; ?>  value="2">Text HTML/Javascript</option>
</select>


<div id="1" style="display:<?php echo $dataW['type']==1?"block":"none"; ?>">
<strong>File</strong>
<?php
$dir="../widget/";
echo '<select name="file" id="file" class="form-control">';
echo '<option value="">Silahkan Pilih File</option>';
	if(is_dir($dir)) 
	{ 
		if($handle = opendir($dir)) 
		{ 
		 while(($file = readdir($handle)) !== false) 
		 { 
		 	if(substr($file,0,1) != '.')
   			{
				$nmFile=explode(".",$file);
				echo '<option '.($file==$dataW['content']?"selected":"").' value="'.$file.'">'.$file.'</option>';
			}
		 } 
		} 
	}
echo '</select>'; 
?>
</div>


<div id="2" style="display:<?php echo $dataW['type']==2?"block":"none"; ?>">
<b>Isi Artikel</b>
<textarea name="html" class="form-control"><?php echo $dataW['type']==2?$dataW['content']:""; ?></textarea>
<br>
</div>

<br>
<input type="submit" name="simpan" value="Simpan" class="btn btn-success">
<a href="index.php?page=widget_edit&id=<?php echo $_GET['id']; ?>&act=del" class="btn btn-danger">Hapus</a>
</form>
<?php }
}

?>


<script>
function show_isi()
{
	var x = document.getElementById('type').value;
	if (x==1)
	{
	document.getElementById("file").required = true;
	document.getElementById('1').style.display="block";
	document.getElementById('2').style.display="none";
	}
	else if (x==2)
	{
	document.getElementById("file").required = false;
	document.getElementById('1').style.display="none";
	document.getElementById('2').style.display="block";
	}
	else 
	{
	document.getElementById('1').style.display="none";
	document.getElementById('2').style.display="none";
	}
}

</script>