<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Web management</title>
<link rel="stylesheet" href="styles.css" type="text/css">
<?php include 'codes.php';?>
</head>
<body> 
  <?php
$id = mysql_real_escape_string(stripslashes($_REQUEST['id']));
$room_id = mysql_real_escape_string(stripslashes($_REQUEST['room_id']));
$info_id = mysql_real_escape_string(stripslashes($_REQUEST['info_id']));	  
$name = mysql_real_escape_string(stripslashes($_REQUEST['name']));
$priority = mysql_real_escape_string(stripslashes($_REQUEST['priority']));	  

if  (isset($_POST['submit'])) {
	$sql="UPDATE photos SET room_id='$room_id', info_id='$info_id', name='$name', priority='$priority' WHERE id='$id'";
	$result = mysql_query($sql);	
?>

                    <?php 
        $newid = $id;
		$uploaddir = '../photos/'; 
		$uploadid = $newid; 
		$filetype = '.jpg'; 
		$uploadname = $newid . $filetype; 
		

        if (isset($_POST['submit'])){ 
        if( $_FILES['upload']['tmp_name'] != "" ){
		
        $dest = $uploaddir . $uploadname; 
        if (copy ( $_FILES['upload']['tmp_name'], $dest )){ 
		
	function createthumb($name,$filename,$new_w,$new_h){
	$system=explode('.',$name);
	if (preg_match('/jpg|jpeg/',$system[3])){
		$src_img=imagecreatefromjpeg($name);
	}
	if (preg_match('/png/',$system[3])){
		$src_img=imagecreatefrompng($name);
	}
	
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y) {
	//$thumb_w=$old_x*($new_w/$old_y);
	//$thumb_h=$new_h;
	
	$thumb_w=$new_w;
	$thumb_h=$old_y*($new_h/$old_x);
	
}
if ($old_x == $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$new_h;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 

	
if (preg_match("/png/",$system[3]))
{
	imagepng($dst_img,$filename); 
} else {
	imagejpeg($dst_img,$filename); 
}
imagedestroy($dst_img); 
imagedestroy($src_img); 
}

			createthumb('../photos/'.$uploadid.'.jpg','../photos/thumbs/'.$uploadid.'.jpg',150,150);
                } 
 }
?>
<?php } ?>

<meta http-equiv="refresh" content="0;URL=edit-photo.php?id=<?php echo $id ?>">
<?php
} else {	
			$result = mysql_query("SELECT * FROM photos WHERE id='$id'",$dbh);
			$myrow=mysql_fetch_array($result); 
			$id=$myrow['id'];
			$room_id=$myrow['room_id'];
			$info_id=$myrow['info_id'];
			$name=$myrow['name'];
			$priority=$myrow['priority'];
?>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div><img src="img/frame-edit.png" width="180" height="37" alt=""></div>
<div class="frame">

<form name="forma" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data">
  <input type="hidden" name="id" value="<?php echo $id ?>">
  <table width="100%" border="0" cellspacing="0" cellpadding="4">
    <tr>
      <td>&nbsp;</td>
      <td>Δωμάτιο        </td>
      <td><select name="room_id" class="forms">
        <option value="0">ΚΑΝΕΝΑ</option>
        <?php
			$sql1 = "SELECT * FROM rooms WHERE lang_id=1 ORDER BY priority";
			$result1 = mysql_query($sql1);
			while ($myrow=mysql_fetch_array($result1)) {
				$roomid=$myrow['insert_id'];
				$room=$myrow['name'];
?>
        <?php
	if ($roomid==$room_id ) {
?>
        <option value="<?php echo $roomid ?>" selected> <?php echo $room ?>
          <?php } else { ?>
          <option value="<?php echo $roomid ?>"> <?php echo $room ?> </option>
        <?php 
				}
				}
?>
      </select></td>
    </tr>
		  <tr>
		    <td width="20">&nbsp;</td> 
            <td>
              Καταχώρηση                </td>
            <td> 
              <select name="info_id" class="forms">
                <option value="0">ΚΑMIA</option>
                <?php
			$sql2 = "SELECT * FROM info ORDER BY priority";
			$result2 = mysql_query($sql2);
			while ($myrow=mysql_fetch_array($result2)) {
				$infoid=$myrow['insert_id'];
				$info=$myrow['name'];
?>
                <?php
	if ($infoid==$info_id ) {
?>
                <option value="<?php echo $infoid ?>" selected> 
                <?php echo $infoid ?> <?php echo $info ?>
                <?php } else { ?>
                <option value="<?php echo $infoid ?>"> 
                <?php echo $infoid ?> <?php echo $info ?>
                </option>
                <?php 
				}
				}
?>
              </select>
             
            </td>
          </tr>
           <?php if ($lang1==1) { ?>
    <tr>
      <td width="20">&nbsp;</td> 
      <td width="200">Τίτλος 
        </td>
      <td> 
        <input type="text" name="name" size="100" value="<?php echo $name ?>" class="forms">
        </td>
    </tr>
    <?php } ?>
    <?php if ($lang2==1) { ?>
      <?php } ?>
    <?php if ($lang3==1) { ?>
      <?php } ?>
    <?php if ($lang4==1) { ?>
      <?php } ?>
    <?php if ($lang5==1) { ?>
      <?php } ?>
    <?php if ($lang6==1) { ?>
      <?php } ?>
    <?php if ($lang7==1) { ?>
      <?php } ?>
     <?php if ($lang8==1) { ?>
      <?php } ?>
          <tr>
            <td width="20">&nbsp;</td>
            <td width="200">Εικόνα</td>
            <td width="20"><input type="hidden" name="max_file_size" value="600000">
              <input name="upload" type="file" size="50" class="forms"></td>
          </tr>
          <tr>
            <td>&nbsp;</td> 
            <td>Αριθμός προτεραιότητας</td>
            <td> 
              <input type="text" name="priority" size="20" maxlength="11" value="<?php echo $priority ?>" class="forms">
            </td>
          </tr>
        </table>

  <div align="center" style="padding:5px">
   <input type="submit" name="submit" value="Καταχώρηση" class="button">
        <input type="reset" name="reset" value="Επαναφορά" class="button">  </div>
</form>  
</div>
<div align="right">
  <?php if ($room_id!='0') { ?>
  <a href="all-photos.php?roomid=<?php echo $room_id ?>" class="links">μεταφορά στην Λίστα</a>
  <?php } ?>
  <?php if ($info_id!='0') { ?>
  <a href="all-photos.php?infoid=<?php echo $info_id ?>" class="links">μεταφορά στην Λίστα</a>
  <?php } ?>
  <?php if ($room_id=='0' AND $info_id=='0') { ?>
  <a href="all-photos.php" class="links">μεταφορά στην Λίστα</a>
  <?php } ?>
</div>
<div align="center"><img src="../photos/<?php echo $id ?>.jpg" width="500"></div>
    </td>
  </tr>
</table><?php include 'menudown.php';?>
<?php } ?>
</body>
</html>
