<!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 text="#000000" style="margin:0"> 
<?php
$id = mysql_real_escape_string(stripslashes($_REQUEST['id']));
$roomid = mysql_real_escape_string(stripslashes($_REQUEST['roomid']));
$infoid = mysql_real_escape_string(stripslashes($_REQUEST['infoid']));
$name = mysql_real_escape_string(stripslashes($_REQUEST['name']));
$name_en = mysql_real_escape_string(stripslashes($_REQUEST['name_en']));
$name_de = mysql_real_escape_string(stripslashes($_REQUEST['name_de']));
$name_fr = mysql_real_escape_string(stripslashes($_REQUEST['name_fr']));
$name_it = mysql_real_escape_string(stripslashes($_REQUEST['name_it']));
$name_es = mysql_real_escape_string(stripslashes($_REQUEST['name_es']));
$name_ru = mysql_real_escape_string(stripslashes($_REQUEST['name_ru']));
$name_zh = mysql_real_escape_string(stripslashes($_REQUEST['name_zh']));
$name_fr = mysql_real_escape_string(stripslashes($_REQUEST['name_fr']));
$name_it = mysql_real_escape_string(stripslashes($_REQUEST['name_it']));
$name_es = mysql_real_escape_string(stripslashes($_REQUEST['name_es']));
$name_ru = mysql_real_escape_string(stripslashes($_REQUEST['name_ru']));
$name_zh = mysql_real_escape_string(stripslashes($_REQUEST['name_zh']));
$description = mysql_real_escape_string(stripslashes($_REQUEST['description']));
$description_en = mysql_real_escape_string(stripslashes($_REQUEST['description_en']));
$description_de = mysql_real_escape_string(stripslashes($_REQUEST['description_de']));
$description_fr = mysql_real_escape_string(stripslashes($_REQUEST['description_fr']));
$description_it = mysql_real_escape_string(stripslashes($_REQUEST['description_it']));
$description_es = mysql_real_escape_string(stripslashes($_REQUEST['description_es']));
$description_ru = mysql_real_escape_string(stripslashes($_REQUEST['description_ru']));
$description_zh = mysql_real_escape_string(stripslashes($_REQUEST['description_zh']));
$priority = mysql_real_escape_string(stripslashes($_REQUEST['priority']));		  

			$sql1 = "SELECT * FROM photos ORDER BY id";
			$result1 = mysql_query($sql1);
	while ($myrow=mysql_fetch_array($result1)) {
			$pid=$myrow['id'];
}?>
<?php if ($pid=='') { 
$priorityid=1;
}
else {
$priorityid=$pid * 10;
}?>	
<?php if ($roomid=='') { 
$roomid=0;
}?>	
<?php if ($infoid=='') { 
$infoid=0;
}?>		

<?php 
if  (isset($_POST['submit'])) {
			
			$sql = "INSERT INTO photos (room_id, info_id, name, name_en, name_de, name_fr, name_it, name_es, name_ru, name_zh, priority) VALUES ('$roomid', '$infoid', '$name', '$name_en', '$name_de', '$name_fr', '$name_it', '$name_es', '$name_ru', '$name_zh', '$priorityid')";
			$result = mysql_query($sql);
?>

 <?php
            $result10 = mysql_query("SELECT * FROM photos ORDER BY id desc LIMIT 1",$dbh);
			$myrow=mysql_fetch_array($result10); 
			$newid=$myrow['id'];
			
?>

                    <?php 
        $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);
                } 
    
     else{ 
            } }
?>
<?php } ?>    

<meta http-equiv="refresh" content="0;URL=new-photo.php?roomid=<?php echo $roomid ?>&infoid=<?php echo $infoid ?>">
<?php			
}
else  {
?>

<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div><img src="img/frame-add.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="roomid" value="<?php echo $roomid ?>">
  <input type="hidden" name="infoid" value="<?php echo $infoid ?>">
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="text">
  <?php if ($lang1==1) { ?>
    <tr>
      <td width="20"><img src="img/lang1.png" width="16" height="16" alt=""></td> 
      <td width="200">Τίτλος 
        </td>
      <td> 
        <input type="text" name="name" size="100" class="forms">
        </td>
    </tr>
    <?php } ?>
    <?php if ($lang2==1) { ?>
    <tr>
      <td><img src="img/lang2.png" width="16" height="16" alt=""></td> 
      <td>Τίτλος </td>
      <td> 
        <input type="text" name="name_en" size="100" class="forms">
        </td>
      </tr>
      <?php } ?>
    <?php if ($lang3==1) { ?>
    <tr>
      <td><img src="img/lang3.png" width="16" height="16" alt=""></td>
      <td>Τίτλος </td>
      <td><input type="text" name="name_de" size="100" class="forms"></td>
    </tr>
      <?php } ?>
    <?php if ($lang4==1) { ?>
    <tr>
      <td><img src="img/lang4.png" width="16" height="16" alt=""></td>
      <td>Τίτλος </td>
      <td><input type="text" name="name_fr" size="100" class="forms"></td>
    </tr>
      <?php } ?>
    <?php if ($lang5==1) { ?>
    <tr>
      <td><img src="img/lang5.png" width="16" height="16" alt=""></td>
      <td>Τίτλος </td>
      <td><input type="text" name="name_it" size="100" class="forms"></td>
    </tr>
      <?php } ?>
    <?php if ($lang6==1) { ?>
    <tr>
      <td><img src="img/lang6.png" width="16" height="16" alt=""></td>
      <td>Τίτλος </td>
      <td><input type="text" name="name_es" size="100" class="forms"></td>
    </tr>
      <?php } ?>
    <?php if ($lang7==1) { ?>
    <tr>
      <td><img src="img/lang7.png" width="16" height="16" alt=""></td>
      <td>Τίτλος </td>
      <td><input type="text" name="name_ru" size="100" class="forms"></td>
    </tr>
      <?php } ?>
      <?php if ($lang8==1) { ?>
    <tr>
      <td><img src="img/lang8.png" width="16" height="16" alt=""></td>
      <td>Τίτλος </td>
      <td><input type="text" name="name_zh" size="100" class="forms"></td>
    </tr>
      <?php } ?>
    <tr>
      <td>&nbsp;</td>
      <td>Εικόνα</td>
      <td><input type="hidden" name="max_file_size" value="600000">
        <input name="upload" type="file" size="50" 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 ($roomid!='0') { ?>
  <a href="all-photos.php?roomid=<?php echo $roomid ?>" class="links">μεταφορά στην Λίστα</a>
  <?php } ?>
  <?php if ($infoid!='0') { ?>
  <a href="all-photos.php?infoid=<?php echo $infoid ?>" class="links">μεταφορά στην Λίστα</a>
  <?php } ?>
  <?php if ($roomid=='0' AND $infoid=='0') { ?>
  <a href="all-photos.php" class="links">μεταφορά στην Λίστα</a>
  <?php } ?>
</div></td>
  </tr>
</table><?php include 'menudown.php';?>
<?php } ?>
</body>
</html>
