<?php include 'sets.php';?>
<?php
$superuser="0";
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Webadmin <?php echo $domain ?></title>
<?php include 'codes.php';?>
</head>
<body>

<?php include 'navbar.php';?>

<?php
$id = $mysqli->real_escape_string(stripslashes($_REQUEST['id']));

$result = $mysqli->query("SELECT * FROM extras WHERE type=1 AND insert_id='$id' AND lang_id=$lang");
$row = $result->fetch_array(); 
$category_id1=$row['category_id'];
$item_id1=$row['item_id'];
?>
    
<div class="container">
<div class="frame">
<div class="frametitles fedit"><?php echo $adminedit ?>
<div class="floatright"><a href="add-extra.php?itemid=<?php echo $item_id1?>"><img src="img/add.png" alt="<?php echo $adminadditem ?>" title="<?php echo $adminadditem ?>"></a></div>
</div>
<div class="framein">

<?php
if  (isset($_POST['deleteimg'])) {
unlink("./".$filepath."extras/".$id.".jpg");
$mysqli->query("UPDATE extras SET image='0' WHERE insert_id=$id");
}
if  (isset($_POST['deletefile'])) {
array_map('unlink', glob("./".$filepath."extras/files/".$id.".*"));
$mysqli->query("UPDATE extras SET file='' WHERE insert_id=$id");
}
?>

<?php if ($id) { ?>
<form name="forma" method="post" enctype="multipart/form-data">
<input type="hidden" name="max_file_size" value="5000000">
<input type="hidden" name="id" value="<?php echo $id ?>">
<input type="hidden" name="category_id" value="<?php echo $category_id ?>">
<input type="hidden" name="item_id" value="<?php echo $item_id ?>">

<table>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2"><span class="icon fa-folder-open"></span></td>
      <td>
        
<select name="category_id">
<?php
$result1 = $mysqli->query("SELECT * FROM categories WHERE type=3 AND lang_id=$lang ORDER BY priority");
while($row = $result1->fetch_array()) {
$catid1=$row['insert_id'];
$category1=$row['name'];
?>
  <?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>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-list-alt"></span></td>
      <td>
<select name="item_id">
<?php
$result2 = $mysqli->query("SELECT * FROM items WHERE category_id IN (SELECT insert_id FROM categories WHERE type=2) AND lang_id=$lang ORDER BY category_id, priority");
while($row = $result2->fetch_array()) {
$itemid1=$row['insert_id'];
$item1=$row['name'];
?>
  <?php if ($itemid1 == $item_id ) { ?>
          <option value="<?php echo $item_id ?>" selected> 
            <?php echo $item1 ?>
            <?php } else { ?>
 <?php if ($itemid1 == $item_id1 ) { ?>
          <option value="<?php echo $item_id1 ?>" selected> 
            <?php echo $item1 ?>
            <?php } else { ?>           
            <option value="<?php echo $itemid1 ?>"> 
            <?php echo $item1 ?>
            </option>
<?php }}}?>
      </select>
      </td>
    </tr>
    </table>
    
<?php
$result30 = $mysqli->query("SELECT * FROM lang WHERE active=1 ORDER BY priority");
while($row = $result30->fetch_array()) {
$langid=$row['id'];
$language=$row['language'];
$dir=$row['dir'];
?>

<?php
$result51 = $mysqli->query("SELECT * FROM extras WHERE type=1 AND insert_id=$id AND lang_id=$langid");
while($row = $result51->fetch_array()) {
$name=$row['name'];

$category_id=$row['category_id'];
$item_id=$row['item_id'];
$insert_id=$row['insert_id'];
$lang_id=$row['lang_id'];
$color=$row['color'];
$price=$row['price'];
$weight=$row['weight'];
$image=$row['image'];
$file=$row['file'];
$publish=$row['publish'];
$priority=$row['priority'];
?>

<?php 
if  (isset($_POST['submit'])) {
$category_id = $mysqli->real_escape_string(stripslashes($_REQUEST['category_id']));
$item_id = $mysqli->real_escape_string(stripslashes($_REQUEST['item_id']));	
$name = $mysqli->real_escape_string(stripslashes($_REQUEST["name$langid"]));
$name = str_replace('\r\n', ' ',$name);
$name = preg_replace('/\s+/', ' ',$name);
$color = $mysqli->real_escape_string(stripslashes($_REQUEST['color']));
$price = $mysqli->real_escape_string(stripslashes($_REQUEST['price']));	
$weight = $mysqli->real_escape_string(stripslashes($_REQUEST['weight']));
$image = $mysqli->real_escape_string(stripslashes($_REQUEST['image']));
$filen = $mysqli->real_escape_string(stripslashes($_REQUEST['filen']));
$publish = $mysqli->real_escape_string(stripslashes($_REQUEST['publish']));	  
$priority = $mysqli->real_escape_string(stripslashes($_REQUEST['priority']));

if( $filen=='' ){
$file= "";
}

$mysqli->query("UPDATE extras SET category_id='$category_id', item_id='$item_id', name='$name', color='$color', price='$price', weight='$weight', image='$image', file='$file', publish='$publish', priority='$priority' WHERE insert_id='$id' AND lang_id=$langid");
?> 
<meta http-equiv="refresh" content="0;URL=list-extras.php?itemid=<?php echo $item_id ?>"> 
<?php } ?>

  <table>
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td>
      <td class="tabletd2"><?php echo $admintext ?> </td>
      <td><div class="diveditor"><textarea name="name<?php echo $langid ?>" cols="75" rows="10" class="mceEditor"><?php echo $name ?></textarea></div></td>
    </tr>
    </table>

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

<!--NEW LANG -->

<?php
$result52 = $mysqli->query("SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM extras WHERE type=1 AND insert_id='$id') AND active=1 ORDER BY main desc, priority");
$nrrows52 = mysqli_num_rows($result52);
while($row = $result52->fetch_array()) {
$langid2=$row['id'];
$language2=$row['language'];
$dir2=$row['dir'];
?>

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

  <table>
    <tr>
      <td class="tabletd1"><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td>
      <td class="tabletd2"><?php echo $admintext ?> </td>
      <td><div class="diveditor"><textarea name="name<?php echo $langid2 ?>" cols="75" rows="10" class="mceEditor"></textarea></div></td>
    </tr>
    </table>
    
<?php 
if  (isset($_POST['submit'])) {
$name2 = $mysqli->real_escape_string(stripslashes($_REQUEST["name$langid2"]));
$name2 = str_replace('\r\n', ' ',$name2);
$name2 = preg_replace('/\s+/', ' ',$name2);

$mysqli->query("INSERT INTO extras (category_id, item_id, insert_id, lang_id, name, color, price, weight, image, file, type, publish, priority) VALUES ('$category_id', '$item_id', '$insert_id', '$langid2', '$name2', '$color', '$price', '$weight', '$image', '$file', '1', '$publish', '$priority')");
?>

<meta http-equiv="refresh" content="0;URL=list-extras.php?itemid=<?php echo $item_id ?>">    
    
<?php } ?>
<?php } ?>
<?php } ?>

<!--END NEW LANG -->

<table>
    <tr>
      <td>&nbsp;</td>
      <td><?php echo $admincolor ?>
      <div class="floatright">#</div>
      </td>
      <td>
        <input type="text" name="color" value="<?php echo $color ?>" size="15" maxlength="6" class="inputauto jscolor {position:'right', required:false}"></td>
    </tr>
    
<?php if ($type==2 && $inquiry==0) { ?>    
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-eur price"></span></td>
      <td><input type="text" name="price" value="<?php echo $price ?>" size="15" maxlength="11" class="inputauto"></td>
    </tr>
   <?php } ?>
    <?php if ($adminweight) { ?>
    <tr class="divweight">
      <td>&nbsp;</td>
      <td><span title="<?php echo $adminweight ?> Kg">Kg</span></td>
      <td>
  <input type="text" name="weight" value="<?php echo $weight ?>" size="15" maxlength="11" class="inputauto"> 
      </td>
    </tr>
  <?php } ?>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-image" title="<?php echo $adminimg ?>"></span></td>
      <td>
  <input type="hidden" name="image" value="0">    
  <input type="checkbox" name="image" value="1"<?php if ($image==1) { echo " checked"; }?>> 
        
        <input name="upload" type="file" size="50" title="upload photo .jpg">
        
<?php if (file_exists("./".$filepath."extras/".$id.".jpg")) { ?>
<img src="<?php echo $filepath ?>extras/<?php echo $id ?>.jpg" width="80">

<button type="submit" name="deleteimg" title="<?php echo $admindelete ?> <?php echo $adminimg ?>" class="buttonicon color1"><span class="icon fa-trash-o"></span></button>
<?php } ?>  

        </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-file-text" title="<?php echo $adminfile ?>"></span></td>
      <td><?php if ($file!='') { ?>
        <input type="hidden" name="filen" value="">
        <input type="checkbox" name="filen" value="<?php echo $file ?>" checked>
        <?php } ?>
        <input name="uploadfile" type="file" size="50" title="upload file - max 5 MB">
        <?php if ($file!='') { ?>
        &nbsp; &nbsp; <a href="<?php echo $filepath ?>extras/files/<?php echo $id?>.<?php echo $file ?>" target="blank"><span class="icon icstyle1 fa-file-text color1" title="file"></span></a>
        
        <button type="submit" name="deletefile" title="<?php echo $admindelete ?> file" class="buttonicon color1"><span class="icon fa-trash-o"></span></button>
        <?php } ?></td>
    </tr>
    
    <tr>
      <td class="tabletd1">&nbsp;</td> 
      <td class="tabletd2"><?php echo $adminpublish ?></td>
      <td>
	<input type="hidden" name="publish" value="no"> <input type="checkbox" name="publish" value="yes"<?php if ($publish=='yes') { echo " checked"; }?>>
     </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-sort-numeric-asc" title="<?php echo $adminpriority ?>"></span></td>
      <td><input type="text" name="priority" value="<?php echo $priority ?>" size="15" maxlength="11" class="inputauto"></td>
    </tr>
    </table>

<!--UPLOAD --> 
<?php
if  ( isset($_POST['submit']) AND ($_FILES['upload']['tmp_name'] != "" ) ) {

$file_tmp =$_FILES['upload']['tmp_name'];
	   
		$uploadid=$id;
		$uploaddir = $filepath.'extras/';
		$uploadname = $uploadid.'.jpg'; 
	
		copy($file_tmp,$uploaddir.$uploadname);
		$mysqli->query("UPDATE extras SET image='1' WHERE insert_id=$uploadid");
	
resizephoto($uploaddir.$uploadname,$uploaddir.$uploadname,$thumb_w,$thumb_h);

}
?>

<?php
if  ( isset($_POST['submit']) AND ($_FILES['uploadfile']['tmp_name'] != "" ) ) {

$file_tmpf =$_FILES['uploadfile']['tmp_name'];
		
$filename = $_FILES["uploadfile"]["name"];
$tmp = explode('.', $filename);
$filetype = end($tmp);

if( $filetype == "exe" ){
$file= "";
} else {
$file= $filetype;
}

		$uploadid=$id;
		$uploaddir = $filepath.'extras/files/';
		$uploadnamefile = $uploadid.".".$filetype; 
	
		copy($file_tmpf,$uploaddirfile.$uploadnamefile);
		$mysqli->query("UPDATE extras SET file='$file' WHERE insert_id=$uploadid");

}
?>    
 
   <hr>
  <div class="divallbuttons">
<div class="divlist"><a href="list-extras.php?itemid=<?php echo $item_id ?>" title="<?php echo $adminlist ?>" class="icstyle1 color1"><span class="icon fa-tasks"></span></a></div>
<div class="divbuttons">
  <button type="submit" name="submit" class="button"><span class="icon fa-check"></span> <?php echo $adminsubmit ?></button>
  <button type="reset" name="reset" class="button buttondelete"><span class="icon fa-refresh"></span> <?php echo $adminreset ?></button> 
</div>
   </div>
   
</form>
<?php } ?>

</div>
</div>
</div>

<?php include 'menudown.php';?>

</body>
</html>