<!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 
$insertid = mysql_real_escape_string(stripslashes($_REQUEST['id']));
$category_id = mysql_real_escape_string(stripslashes($_REQUEST['category_id']));
?>

<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">
<?php
$result = mysql_query("SELECT * FROM info WHERE insert_id='$insertid' AND lang_id=1",$dbh);
$myrow=mysql_fetch_array($result); 
$category_id1=$myrow['category_id'];
?>

<form name="forma" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $insertid ?>">
<input type="hidden" name="category_id" value="<?php echo $category_id ?>">

<table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
      <td width="20">&nbsp;</td>
      <td width="200">Ενότητα</td>
      <td>
     <select name="category_id" class="forms">
<?php
$sql1 = "SELECT * FROM infocategories WHERE lang_id=1 ORDER BY priority";
$result1 = mysql_query($sql1);
while ($myrow=mysql_fetch_array($result1)) {
$catid1=$myrow['insert_id'];
$category1=$myrow['title'];
?>
  <?php if ($catid1 == $category_id ) { ?>
          <option value="<?php echo $category_id ?>" selected> 
            <?php echo $category1 ?>
            <?php } else { ?>
 <?php if ($catid1 == $category_id1 ) { ?>
          <option value="<?php echo $category_id1 ?>" selected> 
            <?php echo $category1 ?>
            <?php } else { ?>           
            <option value="<?php echo $catid1 ?>"> 
            <?php echo $category1 ?>
            </option>
<?php }}}?>
      </select> 
      </td>
    </tr>
    </table>
    
<?php
$sql50 = "SELECT * FROM lang WHERE active=1 ORDER BY id";
$result50 = mysql_query($sql50);
while ($myrow=mysql_fetch_array($result50)) {
$langid=$myrow['id'];
$language=$myrow['language'];
$dir=$myrow['dir'];
?>

<?php
$sql51 = "SELECT * FROM info WHERE insert_id='$insertid' AND lang_id='$langid'";
$result51 = mysql_query($sql51);
while ($myrow=mysql_fetch_array($result51)) {
$category_id=$myrow['category_id'];
$insert_id=$myrow['insert_id'];
$lang_id=$myrow['lang_id'];
$name=$myrow['name'];
$text=$myrow['text'];
$script=$myrow['script'];
$image=$myrow['image'];
$file=$myrow['file'];
$publish=$myrow['publish'];
$priority=$myrow['priority'];
?>

<?php 
if  (isset($_POST['submit'])) {
$category_id = mysql_real_escape_string(stripslashes($_REQUEST['category_id']));
$namelang = mysql_real_escape_string(stripslashes($_REQUEST["name$langid"]));
$textlang = mysql_real_escape_string(stripslashes($_REQUEST["text$langid"]));
$name = mysql_real_escape_string(stripslashes($_REQUEST["name$langid"]));
$text = mysql_real_escape_string(stripslashes($_REQUEST["text$langid"]));
$script = mysql_real_escape_string(stripslashes($_REQUEST['script']));
$image = mysql_real_escape_string(stripslashes($_REQUEST['image']));
$file = mysql_real_escape_string(stripslashes($_REQUEST['file']));
$publish = mysql_real_escape_string(stripslashes($_REQUEST['publish']));	  
$priority = mysql_real_escape_string(stripslashes($_REQUEST['priority']));

$sql="UPDATE info SET category_id='$category_id', name='$namelang', text='$textlang', script='$script', image='$image', file='$file', publish='$publish', priority='$priority' WHERE insert_id='$insertid' AND lang_id='$langid'";
$result = mysql_query($sql);
?>
<meta http-equiv="refresh" content="0;URL=edit-info.php?id=<?php echo $insertid ?>">    
<?php } ?>

  <table width="100%" border="0" cellspacing="0" cellpadding="4">
    <tr>
      <td width="20"><img src="img/<?php echo $dir ?>.png" width="16" height="16" alt=""></td> 
      <td width="200">Τίτλος 
        </td>
      <td> 
        <input type="text" name="name<?php echo $langid ?>" value="<?php echo $name ?>" size="100" class="forms">
        </td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir ?>.png" width="16" height="16" alt=""></td>
      <td>Κείμενο </td>
      <td><textarea name="text<?php echo $langid ?>" rows="10" class="mceEditor"><?php echo $text ?></textarea></td>
    </tr>
    </table>

<?php } ?>
<?php } ?>

<!--NEW LANG -->

<?php
$sql52 = "SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM info WHERE insert_id='$insertid') AND active=1 ORDER BY id";
$result52 = mysql_query($sql52);
$nu_row52 = mysql_num_rows($result52);
while ($myrow=mysql_fetch_array($result52)) {
$langid2=$myrow['id'];
$language2=$myrow['language'];
$dir2=$myrow['dir'];
?>

<?php if  ($nu_row52>0) { ?>

  <table width="100%" border="0" cellspacing="0" cellpadding="4">
    <tr>
      <td width="20"><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td> 
      <td width="200">Τίτλος 
        </td>
      <td> 
        <input type="text" name="name<?php echo $langid2 ?>" size="100" class="forms">
        </td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td>
      <td>Κείμενο </td>
      <td><textarea name="text<?php echo $langid2 ?>" rows="10" class="mceEditor"></textarea></td>
    </tr>
    </table>
    
<?php 
if  (isset($_POST['submit'])) {
$namelang2 = mysql_real_escape_string(stripslashes($_REQUEST["name$langid2"]));
$textlang2 = mysql_real_escape_string(stripslashes($_REQUEST["text$langid2"]));

$sql = "INSERT INTO info (category_id, insert_id, lang_id, name, text, script, image, file, publish, priority) VALUES ('$category_id', '$insert_id', '$langid2', '$namelang2', '$textlang2', '$script', '$image', '$file', '$publish', '$priority')";
$result = mysql_query($sql);
?>

<meta http-equiv="refresh" content="0;URL=edit-info.php?id=<?php echo $insertid ?>">    
    
<?php } ?>
<?php } ?>
<?php } ?>

<!--END NEW LANG -->

<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td>&nbsp;</td>
    <td>Κώδικας</td>
    <td><textarea name="script" cols="115" rows="6" class="forms"><?php echo $script ?></textarea></td>
  </tr>
    <tr>
      <td width="20">&nbsp;</td> 
      <td width="200">Εικόνα</td>
      <td>
      <select name="image" class="forms">
        <?php if ($image=="yes") { ?>
        <option value="yes" selected>yes</option>
        <option value="no">no</option>
        <?php }else{?> 
        <option value="no" selected>no</option>
        <option value="yes">yes</option>
        <?php } ?>
        </select>
        <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>Τύπος
        <select name="file" class="forms">
          <option value="<?php echo $file ?>" selected><?php echo $file ?></option>
          <option value="">KANENA</option>
          <option value=".doc">doc</option>
          <option value=".docx">docx</option>
          <option value=".pdf">pdf</option>
          <option value=".ppt">powerpoint</option>
          <option value=".pptx">powerpoint-x</option>
          <option value=".wmv">video wmv</option>
        </select>
        <input name="upload1" type="file" size="50" class="forms"></td>
    </tr>
    <tr>
      <td>&nbsp;</td> 
      <td>Δημοσίευση στο site?</td>
      <td><select name="publish" class="forms">
        <?php if ($publish=="yes") { ?>
        <option value="yes" selected>yes</option>
        <option value="no">no</option>
        <?php }else{?> 
        <option value="no" selected>no</option>
        <option value="yes">yes</option>
        <?php } ?>
        </select></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>
 
 <?php
	   $uploadid=$insertid;

        $uploaddir = '../images/info/'; 
		$uploaddir1 = '../images/info/files/'; 
		$filetype = '.jpg';
		$filetype1 = $_REQUEST['file']; 
		$uploadname = $uploadid . $filetype; 
		$uploadname1 = $uploadid . $filetype1; 
		
 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('../images/info/'.$uploadid.'.jpg','../images/info/thumbs/'.$uploadid.'.jpg',150,150);

  $sql="UPDATE info SET image='yes' WHERE insert_id='$insertid'";
  $result = mysql_query($sql);         
 } } 
 
  if( $_FILES['upload1']['tmp_name'] != "" ){ 
		
   $dest1 = $uploaddir1 . $uploadname1; 
   if (copy ( $_FILES['upload1']['tmp_name'], $dest1 )){ 
  } }
 
 }?>
   
  <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"><a href="all-info.php?catid=<?php echo $category_id ?>" class="links">μεταφορά στην Λίστα</a></div></td>
  </tr>
</table>
<?php if ($image==yes) { ?>
<div align="center"><img src="../images/info/thumbs/<?php echo $insertid ?>.jpg" width="150"> </div>
<?php } ?>
<?php include 'menudown.php';?>

</body>
</html>
