<?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=0 AND insert_id='$id'");
$row = $result->fetch_array(); 
$lang_id=$row['lang_id'];
$category_id=$row['category_id'];
$item_id=$row['item_id'];

$result = $mysqli->query("SELECT * FROM items WHERE insert_id='$item_id'");
$row = $result->fetch_array(); 
$catid=$row['category_id'];
$secid=$row['section_id'];
?>
    
<div class="container">
<div class="frame">
<div class="frametitles fedit"><?php echo $adminedit ?>  <?php echo $priority ?>
</div>
<div class="framein">

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

<table>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2"><span class="icon fa-folder-open"></span></td>
      <td>
<select name="category_id">
<option value="0">------</option>
<?php
$result1 = $mysqli->query("SELECT * FROM categories WHERE level=1 AND type<3 AND lang_id=$lang ORDER BY priority");
while($row = $result1->fetch_array()) {
$catid1=$row['insert_id'];
$category1=$row['name'];
$level=$row['level'];
$parent=$row['parent'];
?>
<option value="<?php echo $catid1 ?>"<?php if ($catid1==$category_id) { echo " selected"; }?>>
<?php echo $category1 ?>
</option>
<?php 
$result2 = $mysqli->query("SELECT * FROM  categories WHERE parent='$catid1' AND lang_id=$lang ORDER BY priority");
while($row = $result2->fetch_array()) {
$catid2=$row['insert_id'];
$category2=$row['name'];
?>
<option value="<?php echo $catid2 ?>"<?php if ($catid2==$category_id) { echo " selected"; }?>>
<?php echo $category1 ?> &raquo; <?php echo $category2 ?>
</option>
<?php } ?>
<?php } ?>
</select>
&nbsp;
<?php if ($category_id) { ?>
<a href="list-items.php?catid=<?php echo $category_id ?>" title="<?php echo $adminlist ?>" class="icstyle1 color1"><span class="icon fa-tasks"></span></a>
<?php } ?>

</td>
      </tr>
		  <tr>
		    <td>&nbsp;</td>
		    <td><span class="icon fa-list-alt"></span></td>
		    <td>
<select name="item_id">
<option value="0">------</option>
<?php
$result3 = $mysqli->query("SELECT * FROM items WHERE lang_id=$lang ORDER BY category_id, priority");
while($row = $result3->fetch_array()) {
$itemid=$row['insert_id'];
$item=$row['name'];
$ipriority=$row['priority'];

if (!$item) {
$item="&rarr; ".$ipriority;
}
?>
<option value="<?php echo $itemid ?>"<?php if ($itemid==$item_id) { echo " selected"; }?>>
<?php echo $item ?>
</option>
<?php } ?>
</select>
&nbsp;
<?php if ($item_id) { ?>
<a href="list-items.php?catid=<?php echo $catid ?>&amp;secid=<?php echo $secid ?>" title="<?php echo $adminlist ?>" class="icstyle1 color1"><span class="icon fa-tasks"></span></a>
<?php } ?>

</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 ($lang_id!=0) {
$result51 = $mysqli->query("SELECT * FROM extras WHERE type=0 AND insert_id=$id AND lang_id=$langid");
} else {
$result51 = $mysqli->query("SELECT * FROM extras WHERE type=0 AND insert_id=$id");	
}

while($row = $result51->fetch_array()) {
$name=$row['name'];
$text=$row['text'];
$url=$row['url'];
$type=$row['type'];

$insert_id=$row['insert_id'];
$lang_id=$row['lang_id'];
$item_id=$row['item_id'];
$category_id=$row['category_id'];
$priority=$row['priority'];

if ($lang_id==0) {
$langid1='0';	
} else {
$langid1=$langid;	
}
?>

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

$mysqli->query("UPDATE extras SET lang_id='$langid', item_id='$item_id', category_id='$category_id', name='$name', text='$text', url='$url', priority='$priority' WHERE insert_id='$id' AND lang_id=$langid1");
?>
<meta http-equiv="refresh" content="0;URL=edit-photo.php?id=<?php echo $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 $admintitle ?></td>
      <td><input type="text" name="name<?php echo $langid ?>" value="<?php echo $name ?>" size="100"></td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir ?>.png" width="16" height="16" title="<?php echo $language ?>" alt="<?php echo $language ?>"></td>
      <td><?php echo $admintext ?> </td>
      <td><textarea name="text<?php echo $langid ?>" cols="75" rows="10"><?php echo $text ?></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-link" title="Link url"></span></td>
      <td><input type="text" name="url<?php echo $langid ?>" value="<?php echo $url ?>" size="100"></td>
    </tr>
    </table>

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

<?php if ($lang_id!=0) { ?> 
<!--NEW LANG -->

<?php
$result52 = $mysqli->query("SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM extras WHERE type=0 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 $admintitle ?></td>
      <td><input type="text" name="name<?php echo $langid2 ?>" size="100"></td>
    </tr>
    <tr>
      <td><img src="img/<?php echo $dir2 ?>.png" width="16" height="16" alt=""></td>
      <td><?php echo $admintext ?> </td>
      <td><textarea name="text<?php echo $langid2 ?>" cols="75" rows="10"></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-link" title="Link url"></span></td>
      <td><input type="text" name="url<?php echo $langid2 ?>" size="100"></td>
    </tr>
    </table>
    
<?php 
if  (isset($_POST['submit'])) {
$name2 = $mysqli->real_escape_string(stripslashes($_REQUEST["name$langid2"]));
$name2 = strip_tags($name2);
$name2 = preg_replace('/\s+/', ' ',$name2);
$text2 = $mysqli->real_escape_string(stripslashes($_REQUEST["text$langid2"]));
$text2 = str_replace('\r\n', ' ',$text2);
$url2 = $mysqli->real_escape_string(stripslashes($_REQUEST["url$langid2"]));
$url2=preg_replace('/\s+/', '', $url2);

$mysqli->query("INSERT INTO extras (insert_id, lang_id, category_id, item_id, name, text, url, type, priority) VALUES ('$insert_id', '$langid2', '$category_id', '$item_id', '$name2', '$text2', '$url2', '$type',  '$priority')");
?>
<meta http-equiv="refresh" content="0;URL=edit-photo.php?id=<?php echo $id ?>">    
    
<?php } ?>
<?php } ?>
<?php } ?>

<!--END NEW LANG -->
<?php } ?>

<table>
    <tr>
            <td class="tabletd1">&nbsp;</td>
            <td class="tabletd2"><span class="icon fa-image" title="<?php echo $adminimg ?>"></span></td>
            <td><table class="tablewidth">
                <tr>
                  <td><input name="upload" type="file" size="50" title="upload photo .jpg"></td>
                  <td><img src="<?php echo $filepath ?>photos/<?php echo $id ?>.jpg" width="80"></td>
                </tr>
              </table>
            </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.'photos/';
		$uploadname = $uploadid.'.jpg'; 
	
		copy($file_tmp,$uploaddir.$uploadname);
	
resizephoto($uploaddir.$uploadname,$uploaddir.$uploadname,$thumb_w,$thumb_h);

}
?> 

   <hr>
  <div class="divallbuttons">
<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>