/home/kkco/public_html/home__2939f42/admin/page/widget_add.php
<h4 class="text-center"><b>Tambah Widget Baru</b></h4>
<?php
$sqlSimapan='';
if (isset($_POST['simpan']))
{
$sql=mysql_query("select max(posisi) as maks from widget");
$data=mysql_fetch_array($sql);
$sqlSimapan=mysql_query("insert into widget (title,type,content,posisi) values ('".$_POST['title']."','".$_POST['type']."','".($_POST['type']==1?$_POST['file']:$_POST['html'])."','".($data['maks']+1)."')");
echo mysql_error();
}
if ($sqlSimapan)
{
	echo "<div class='alert alert-info'>Berhasil Disimpan</div>";
}
else
{
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

<strong>Judul Widget</strong>
<input type="text" name="title" required class="form-control" >

<strong>Tipe Widget</strong>
<select onChange="show_isi();" name="type" id="type" class="form-control" required>
<option value="">Silahkan Pilih</option>
<option value="1">File</option>
<option value="2">Text HTML/Javascript</option>
</select>


<div id="1" style="display: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 value="'.$file.'">'.$file.'</option>';
			}
		 } 
		} 
	}
echo '</select>'; 
?>
</div>


<div id="2" style="display:none">
<b>Isi Artikel</b>
<textarea name="html" required class="form-control"></textarea>
<br>
</div>

<br>
<input type="submit" name="simpan" value="Simpan" class="btn btn-success">

</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>