<?php include 'sets.php';?>
<?php
$superuser="1";
?>
<!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 langvars WHERE insert_id='$id' AND lang_id=$lang");
$row = $result->fetch_array(); 
$name=$row['name'];
?>
    
<div class="container">
<div class="frame">
<div class="frametitles fedit"><?php echo $adminedit ?>
<div class="floatright"><a href="add-langvar.php"><img src="img/add.png" alt="<?php echo $adminadditem ?>" title="<?php echo $adminadditem ?>"></a></div>
</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"><?php echo $adminnamed ?> *</td>
      <td>
     <input type="text" name="name" value="<?php echo $name ?>" size="100" required> 
      </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 langvars WHERE insert_id=$id AND lang_id=$langid");
while($row = $result51->fetch_array()) {
$name=$row['name'];
$details=$row['details'];
$text=$row['text'];

$insert_id=$row['insert_id'];
$lang_id=$row['lang_id'];
$editable=$row['editable'];
$priority=$row['priority'];
?>

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

$mysqli->query("UPDATE langvars SET name='$name', details='$details', text='$text', editable='$editable', priority='$priority' WHERE insert_id='$id' AND lang_id=$langid");
?>
<meta http-equiv="refresh" content="0;URL=edit-langvar.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 $admintext ?> </td>
      <td><textarea name="text<?php echo $langid ?>" cols="75" rows="6"><?php echo $text ?></textarea>
        <textarea name="details<?php echo $langid ?>" cols="50" rows="6" class="inputauto"><?php echo $details ?></textarea></td>
    </tr>
    </table>

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

<!--NEW LANG -->

<?php
$result52 = $mysqli->query("SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM langvars 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 $admintext ?> </td>
      <td><textarea name="text<?php echo $langid2 ?>" cols="75" rows="6"></textarea>
        <textarea name="details<?php echo $langid2 ?>" cols="50" rows="6" class="inputauto"></textarea></td>
    </tr>
    </table>
    
<?php 
if  (isset($_POST['submit'])) {
$details2 = $mysqli->real_escape_string(stripslashes($_REQUEST["details$langid2"]));
$text2 = $mysqli->real_escape_string(stripslashes($_REQUEST["text$langid2"]));
$text2 = str_replace('\r\n', ' ',$text2);

$mysqli->query("INSERT INTO langvars (insert_id, lang_id, name, details, text, editable, priority) VALUES ('$insert_id', '$langid2', '$name', '$details2', '$text2', '$editable', '$priority')");
?>
<meta http-equiv="refresh" content="0;URL=edit-langvar.php?id=<?php echo $id ?>">    
    
<?php } ?>
<?php } ?>
<?php } ?>

<!--END NEW LANG -->

<table>
<?php if(stripos($name,'admin')=== false){ ?>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2"><span class="icon fa-edit" title="<?php echo $adminedit ?>"></span></td>
      <td>
        <?php if ($editable==0) { ?>
        <input type="hidden" name="editable" value="0"> <input type="checkbox" name="editable" value="1">  
        <?php }else{?>
        <input type="hidden" name="editable" value="0"> <input type="checkbox" name="editable" value="1" checked>  
        <?php } ?>
        </td>
    </tr>
<?php } ?>    
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2"><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>

   <hr>
  <div class="divallbuttons">
<div class="divlist"><a href="list-langvars.php" 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>