<?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';?>
    
<div class="container">
<div class="frame">
<?php 
$itemid = $mysqli->real_escape_string(stripslashes($_REQUEST['itemid']));

$result1 = $mysqli->query("SELECT category_id, name FROM items WHERE insert_id='$itemid' AND lang_id=$lang");
$row = $result1->fetch_array(); 
$cid=$row['category_id'];
$item=$row['name'];

$result = $mysqli->query("SELECT insert_id FROM extras GROUP BY insert_id ORDER BY insert_id desc LIMIT 1");
$row = $result->fetch_array(); 
$isid=$row['insert_id'];
$insertid=$isid + 1;
?>
<div class="frametitles fadd"><?php echo $adminadd ?> &raquo; <?php echo $item ?>
<div class="floatright"><a href="list-items.php?catid=<?php echo $cid ?>"><img src="img/list.png" alt="<?php echo $adminlist ?>" title="<?php echo $adminlist ?>"></a></div>
</div>
<div class="framein">

<form name="forma" method="post" enctype="multipart/form-data">
<input type="hidden" name="max_file_size" value="5000000">
 <input type="hidden" name="itemid" value="<?php echo $itemid ?>">
<table>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2"><span class="icon fa-folder-open"></span></td>
      <td>
        
        <select name="category_id">
<?php
$result2 = $mysqli->query("SELECT * FROM categories WHERE type=3 AND lang_id=$lang ORDER BY priority");
while($row = $result2->fetch_array()) {
$catid=$row['insert_id'];
$category=$row['name'];
?>
  <option value="<?php echo $catid ?>"> 
  <?php echo $category ?>
  </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 
if  (isset($_POST['submit'])) {
$category_id = $mysqli->real_escape_string(stripslashes($_REQUEST['category_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']));
$publish = $mysqli->real_escape_string(stripslashes($_REQUEST['publish']));	  
$priority = $mysqli->real_escape_string(stripslashes($_REQUEST['priority']));

$result = $mysqli->query("SELECT priority FROM extras WHERE type=1 AND category_id=$category_id AND item_id=$itemid AND insert_id!=$insertid AND lang_id=$lang ORDER BY priority desc LIMIT 1");
$row = $result->fetch_array(); 
$pid=$row['priority'];
$priorityid=$pid + 10;

$mysqli->query("INSERT INTO extras (insert_id, category_id, item_id, lang_id, name, color, price, weight, file, publish, type, priority) VALUES ('$insertid', '$category_id', '$itemid', '$langid', '$name', '$color', '$price', '$weight', '$file', '$publish', '1', '$priorityid')");
} ?>

  <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"></textarea></div></td>
    </tr>
    </table>

<?php } ?>

<table>
    <tr>
      <td>&nbsp;</td>
      <td><?php echo $admincolor ?>
      <div class="floatright">#</div>
      </td>
      <td>
        <input type="text" name="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" 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" 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 name="upload" type="file" size="50" title="upload photo .jpg"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-file-text" title="<?php echo $adminfile ?>"></span></td>
      <td><input name="uploadfile" type="file" size="50" title="upload file - max 5 MB"></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" checked></td>
    </tr>
    </table>

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

$file_tmp =$_FILES['upload']['tmp_name'];
	   
		$uploadid=$insertid;
		$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=$insertid;
		$uploaddirfile = $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">
<?php if ($cid!='') { ?>
<div class="divlist"><a href="list-items.php?catid=<?php echo $cid ?>" title="<?php echo $adminlist ?>" class="icstyle1 color1"><span class="icon fa-tasks"></span></a></div>
<?php } ?>
</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>  

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

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

</body>
</html>