<?
session_start();
include_once "functions.inc.php";
include_once "config.php";
include_once "restrict.inc.php";

if ($_POST['send'] == 'OK') {

if (!is_dir ($doc_root.'/files')) {mkdir($doc_root.'/files');}
if (!is_dir ($doc_root.'/files/thumb')) {mkdir($doc_root.'/files/thumb');}

//upload file
if ($_FILES['photo']['name'] == '') { $_SESSION['note'] = "Photo harus diisi! Tekan tombol back di browser untuk mengulangi"; redirect('gallery_add.php', 0.1);}
if ($_FILES['photo']['name'] != '') { 
$photo = date('YmdHi_').$_FILES['photo']['name']; 
$tempphoto = $_FILES['photo']['tmp_name']; 
if ($_POST['photo_old'] != '') {
unlink ('files/'.$_POST['photo_old']) ;
unlink ('files/thumb/'.$_POST['photo_old']) ;
}
copy($tempphoto, 'files/'.$photo); 

imageresize( 200, 200, 'files/'.$photo, 'files/thumb/'.$photo );
}

$gallery[1] = date('Y-m-d H:i:s');
$gallery[2] = $_POST['kategori'];
$gallery[3] = $_POST['judul'];
$gallery[4] = $photo;
$gallery[5] = $_POST['keterangan'];
	if ($_POST['key'] == '') {add_db('files/gallery.txt',$gallery);}
	else if ($_POST['key'] != '') {
	$gallery[0] = $_POST['key']; edit_db('files/gallery.txt',$gallery);
	}

$_SESSION['note'] = "Gambar berhasil disimpan"; redirect('gallery.php'); die();
}

if ($_GET['id'] != '') {
$column_gallery_detail = key_db('files/gallery.txt',$_GET['id']);
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Administrasi gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style_gallery.css" rel="stylesheet" type="text/css">

<script>

<!--

active1 = new Image(26,26);
 active1.src = "but1b.jpg";
 inactive1 = new Image(26,26);
 inactive1.src = "but1a.jpg";

active2 = new Image(26,26);
 active2.src = "but2b.jpg";
 inactive2 = new Image(26,26);
 inactive2.src = "but2a.jpg";

active3 = new Image(26,26);
 active3.src = "but3b.jpg";
 inactive3 = new Image(26,26);
 inactive3.src = "but3a.jpg";
 
active4 = new Image(26,26);
 active4.src = "but4b.jpg";
 inactive4 = new Image(26,26);
 inactive4.src = "but4a.jpg";

active5 = new Image(26,26);
 active5.src = "but5b.jpg";
 inactive5 = new Image(26,26);
 inactive5.src = "but5a.jpg";
 
active6 = new Image(26,26);
 active6.src = "but6b.jpg";
 inactive6 = new Image(26,26);
 inactive6.src = "but6a.jpg";


//-->

</script>
<style><!--a:hover{color:#000080; text-decoration:underline; }--></style>
<style><!--a{text-decoration:none}; //--></style>
<body topmargin="0" leftmargin="0" bgcolor="#000000">
<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0"  bordercolor="#111111" width="780" id="AutoNumber1" height="100%">
    <tr>
        <td width="100%" height="214" valign="top"><img src="top.jpg" width="900" height="234"> 
        </td>
    </tr>
    <tr>
    <tr>
        <td width="100%" bgcolor="#000000" valign="top">
<table border="0" cellpadding="0" cellspacing="0"  bordercolor="#111111" width="100%" height="100%">
        <tr>
              <td align="center" valign="top" bgcolor="#000000"> 
                <table width="98%" border="0">
                  <tr> 
                    <td> 
                      <table width="100%" border="0">
                        <tr> 
                          <td width="61%" height="21"> 
                            <div align="left"><font face="Arial" size="1" color="#FFFFFF"><span lang="sk"><a href="Index.htm"><font color="#FFFFFF" size="2"><b><font size="3">Home</font></b></font></a></span></font><font color="#FF0000" size="4"><b> 
                              | </b></font><font face="Arial" size="1" color="#FFFFFF"><span lang="sk"><a href="clinic.htm"><font color="#FFFFFF" size="2"><b><font size="3">Photography 
                              Clinic</font></b></font></a></span></font><font color="#FF0000" size="4"><b> 
                              | </b></font><font face="Arial" size="1" color="#FFFFFF"><span lang="sk"><a href="gallery.php"><font color="#FFFFFF" size="2"><b><font size="3">Gallery 
                              Photo</font></b></font></a></span></font><font color="#FF0000" size="4"><b><font face="Arial" size="2" color="#FFFFFF"> 
                              </font>| </b></font><font face="Arial" size="1" color="#FFFFFF"><span lang="sk"><font color="#FFFFFF" size="2"><b><font face="Arial" size="1" color="#FFFFFF"><span lang="sk"><a href="Biography.htm"><font color="#FFFFFF" size="2"><b><font size="3">Biography</font></b></font></a></span></font></b></font> 
                              </span></font><font color="#FF0000" size="4"><b><font face="Arial" size="2" color="#FFFFFF"> 
                              </font>| </b></font><font face="Arial" size="1" color="#FFFFFF"><span lang="sk"><a href="ContactMe.htm"><font color="#FFFFFF" size="2"><b><font size="3">Contact 
                              Me</font></b></font></a></span></font></div>
                          </td>
                          <td width="38%" background="ac568.gif" height="21"> 
                            <div align="right"></div>
                          </td>
                          <td width="1%" height="21">&nbsp;</td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                </table>
                <table width="98%" border="0">
                  <tr> 
                    <td bgcolor="#CC3300"><font color="#FF0000"><b><font size="4" color="#FFFFFF">Gallery 
                      Edit</font></b></font></td>
                  </tr>
                  <tr> 
                    <td align="left" valign="top"> 
                      <form action="" method="post" enctype="multipart/form-data" name="form1">
                        <table width="800" border="0" cellspacing="0" cellpadding="2">
                          <tr align="left" valign="top"> 
                            <td width="295" align="right">Kategori:</td>
                            <td width="497">
                              <select name="kategori" id="kategori">
                                <?
$row_kategori = read_db('files/kategori.txt',1,999);
foreach ($row_kategori as $column_kategori) {
?>
                                <option value="<?=trim($column_kategori[1])?>" <? if (trim($column_kategori[1]) == $_GET['kategori']) {echo "selected";}?>>
                                <?=trim($column_kategori[1])?>
                                </option>
                                <? }?>
                              </select>
                              &nbsp; [<a href="gallery_kategori.php">+</a>] </td>
                          </tr>
                          <tr align="left" valign="top"> 
                            <td align="right">Photo:</td>
                            <td>
                              <input name="photo" type="file" id="photo" size="22">
                              <? if ($column_gallery_detail[4] != '') {?>
                              <br>
                              <img src="files/thumb/<?=$column_gallery_detail[4]?>" width="100"> 
                              <? }?>
                            </td>
                          </tr>
                          <tr align="left" valign="top"> 
                            <td align="right">Judul:</td>
                            <td>
                              <input name="judul" type="text" id="judul" value="<?=$column_gallery_detail[3]?>" size="33">
                            </td>
                          </tr>
                          <tr align="left" valign="top"> 
                            <td align="right">Keterangan:</td>
                            <td>
                              <textarea name="keterangan" cols="44" rows="4" id="keterangan"><?=$column_gallery_detail[5]?></textarea>
                            </td>
                          </tr>
                          <tr align="left" valign="top"> 
                            <td align="right">&nbsp;</td>
                            <td>
                              <input type="submit" name="Submit" value="Simpan">
                              <input name="key" type="hidden" id="key" value="<?=$_GET['id']?>">
                              <input name="send" type="hidden" id="send" value="OK">
                              <input name="photo_old" type="hidden" id="photo_old" value="<?=$column_gallery_detail[4]?>">
                            </td>
                          </tr>
                        </table>
                      </form>
                    </td>
                  </tr>
                </table>
                <p>&nbsp;</p></td>
            </tr>
      </table>
        </td>
    </tr>
    <tr>
        <td width="100%" bgcolor="#CC3300" height="20" style="border-left-width: 1; border-right-width: 1; border-top: 1px solid #606060; border-bottom-width: 1"> 
          <p align="center"><font size="1" face="Arial" color="#FFFFFF">Copyright 
            © 2012 </font> 
        </td>
    </tr>
  </table>
  </center>
</div>

</body>
</html>
<?
$note = $_SESSION['note'] ; 
if ($note != '') {
?>
<script type="text/javascript"> 
<!-----hide from old browsers 
alert('<?php echo $note ;?>'); 
//---------> 
</script> 
<? 
} 
$_SESSION['note'] = ''; $note = '';
?>