<?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">
<div class="frametitles fedit"><?php echo $adminedit ?>
</div>
<div class="framein">

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

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

<?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 categories WHERE insert_id=$id AND lang_id=$langid");
while($row = $result51->fetch_array()) {
$name=$row['name'];

$insert_id=$row['insert_id'];
$lang_id=$row['lang_id'];
$typec=$row['type'];
$active=$row['active'];
$publish=$row['publish'];
$priority=$row['priority'];
?>

<?php 
if  (isset($_POST['submit'])) {

$name = $mysqli->real_escape_string(stripslashes($_REQUEST["name$langid"]));
$name = strip_tags($name);
$name = preg_replace('/\s+/', ' ',$name);
$active = $mysqli->real_escape_string(stripslashes($_REQUEST['active']));
$publish = $mysqli->real_escape_string(stripslashes($_REQUEST['publish']));
$priority = $mysqli->real_escape_string(stripslashes($_REQUEST['priority']));

$mysqli->query("UPDATE categories SET name='$name', active='$active', publish='$publish', priority='$priority' WHERE insert_id='$id' AND lang_id=$langid");
if  ($active==1) {
$sql = "UPDATE categories SET active=0 WHERE insert_id!='$id'";
$result2 = $mysqli->query($sql);
}
?>
<meta http-equiv="refresh" content="0;URL=edit-categoryt.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 $adminnamed ?> *
        </td>
      <td> 
        <input type="text" name="name<?php echo $langid ?>" value="<?php echo $name ?>" size="100" required>
        </td>
    </tr>
    </table>

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

<!--NEW LANG -->

<?php
$result52 = $mysqli->query("SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM categories WHERE 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 $adminnamed ?> *
        </td>
      <td> 
        <input type="text" name="name<?php echo $langid2 ?>" size="100" required>
        </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);

$mysqli->query("INSERT INTO categories (insert_id, lang_id, name, type, publish, priority) VALUES ('$insert_id', '$langid2', '$name2', '$typec', '$publish', '$priority')");
?>

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

<!--END NEW LANG -->

<table>
<input type="hidden" name="active" value="<?php echo $active ?>">
<input type="hidden" name="publish" value="<?php echo $publish ?>">
<input type="hidden" name="priority" value="<?php echo $priority ?>">
<?php if ($typec==3) { ?>

    <tr>
      <td>&nbsp;</td>
      <td>
	  <?php if ($type==2) { ?><span class="icon fa-eur price"></span> <?php }else{?><span class="icon fa-list-alt price"></span><?php } ?>
      </td>
      <td>
      <input type="hidden" name="active" value="0"> 
      <?php if ($active==0) { ?>
     <input type="checkbox" name="active" value="1">  
     <?php }else{?>
     <input type="checkbox" name="active" value="1" checked>  
     <?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><?php echo $adminpriority ?> <?php if ($type==2 && $inquiry==0) { ?><span class="icon fa-shopping-cart<?php if ($priority==1) { echo " color1"; }?>"></span> (1)<?php } ?></td>
      <td><input type="text" name="priority" value="<?php echo $priority ?>" size="15" maxlength="11" class="inputauto"></td>
    </tr>
    <?php } ?>
    
    </table>
   
   <hr>
  <div class="divallbuttons">
<div class="divlist"><a href="list-categories.php?t=<?php echo $typec ?>" 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>