<?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';?>
    
<div class="container">
<div class="frame">
<div class="frametitles frametitles1">

<?php 
$id = $mysqli->real_escape_string(stripslashes($_REQUEST['id']));
$language = $mysqli->real_escape_string(stripslashes($_REQUEST['language']));
$dir = $mysqli->real_escape_string(stripslashes($_REQUEST['dir']));
$url = $mysqli->real_escape_string(stripslashes($_REQUEST['url']));
$discount = $mysqli->real_escape_string(stripslashes($_REQUEST['discount']));
$active = $mysqli->real_escape_string(stripslashes($_REQUEST['active']));
$main = $mysqli->real_escape_string(stripslashes($_REQUEST['main']));
			
if  (isset($_POST['changeactive'.$_REQUEST['id']])) {
$result1 = $mysqli->query("SELECT * FROM lang WHERE dir='$dir' AND id!='$id'");
$nrrows = mysqli_num_rows($result1);
?>
<?php if  ($nrrows==0) {?>
<?php 
$sql = "UPDATE lang SET language='$language', dir='$dir', url='$url', discount='$discount', active='$active', main='$main' WHERE id='$id'";
$result = $mysqli->query($sql);
if  ($main==1) {
$sql = "UPDATE lang SET main=0 WHERE id!='$id'";
$result2 = $mysqli->query($sql);
}

$result6 = $mysqli->query("SELECT * FROM lang WHERE main=1");
$nrmain = mysqli_num_rows($result6);
$result7 = $mysqli->query("SELECT * FROM lang WHERE active=1");
$nractive = mysqli_num_rows($result7);
if  ($nrmain==0) {
if  ($nractive==0) {
$sql = "UPDATE lang SET main=1, active=1 WHERE priority=1";
} else {
$sql = "UPDATE lang SET main=1 WHERE active=1 ORDER BY priority LIMIT 1";
}
$result8 = $mysqli->query($sql);	
}

$sql = "UPDATE lang SET active=1 WHERE main=1";
$result3 = $mysqli->query($sql);

$result4 = $mysqli->query("SELECT * FROM lang WHERE id IN (SELECT id FROM lang WHERE active=1) AND id=$langadmin ORDER BY main");
$activelang = mysqli_num_rows($result4);
if  ($activelang==0) {
$result5 = $mysqli->query("SELECT * FROM lang WHERE main=1");
$row = $result5->fetch_array(); 
$lid=$row['id'];
$sql = "UPDATE siteinfo SET langadmin='$lid'";
$result2 = $mysqli->query($sql);
}
?>
<?php } else {?>
<?php echo $adminexist ?> &raquo; 
<?php } ?>
<?php } ?>

<?php
$result = $mysqli->query("SELECT * FROM lang");
$nrrows = mysqli_num_rows($result);
?>
<span class="icon fa-language"></span> <a href="list-lang.php"><?php echo $adminlangs ?></a> (<?php echo $nrrows ?>)
<div class="floatright"><a href="add-lang.php"><img src="img/add.png" alt="<?php echo $adminadditem ?>" title="<?php echo $adminadd ?> <?php echo $adminlang ?>"></a></div>
</div>
<div class="framein">

<div id="contentlistinglang">
<ul class="nospace">
<?php
$result = $mysqli->query("SELECT * FROM lang ORDER BY active desc, priority");
while($row = $result->fetch_array()) {
$id=$row['id'];
$language=$row['language'];
$dir=$row['dir'];
$url=$row['url'];
$discount=$row['discount'];
$active=$row['active'];
$main=$row['main'];
?>

<li id="listarray_<?php echo $id ?>" title="<?php echo $adminreorder ?>">
<div class="framerow<?php if ($active==0) { echo " notpublished"; }?>">
    <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>
            
            <form name="forma" method="post">
              <input type="hidden" name="id" value="<?php echo $id ?>">
              
              <input type="text" name="language" value="<?php echo $language ?>" size="10" maxlength="30" class="inputauto"> &nbsp; 
              <span class="icon fa-folder-open" title="Directory"></span> <input type="text" name="dir" value="<?php echo $dir ?>" size="2" maxlength="20" class="inputauto"> &nbsp;
              <span class="icon fa-link" title="url"></span> <input type="text" name="url" value="<?php echo $url ?>" size="25" maxlength="30" class="inputauto"> &nbsp;
              <span class="icon fa-scissors" title="<?php echo $admindiscount ?>"></span> <span class="icon fa-euro" title="<?php echo $admindiscount ?>"></span> <input type="text" name="discount" value="<?php echo $discount ?>" size="2" maxlength="20" class="inputauto">%
              
              <div class="divinline">
                <?php if ($main==1) { ?> <b><?php echo $admindefault ?></b> <?php } ?>
                <input type="hidden" name="main" value="0">
                <?php if ($main==0) { ?>
                <input type="checkbox" name="main" value="1">  
                <?php }else{?>
                <input type="checkbox" name="main" value="1" checked>  
                <?php } ?>
                </div>
              
              <?php echo $adminactive ?>
              <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 } ?>
              
              <button type="submit" name="changeactive<?php echo $id ?>" class="button buttonsmall"><span class="icon fa-check"></span></button>
              </form>
            
            <div class="divinline">
              <?php if ($active==0) { ?>
              <span class="icon icstyle1 fa-eye-slash" title="<?php echo $adminpublish ?> &raquo; <?php echo $adminno ?>"></span>  
              <?php } ?>
              </div>           
          </td>
         </tr>
      </table>
     </div> 
     </li>
    <?php } ?> 
</ul>
</div>   
      
</div>
</div>
</div>

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

</body>
</html>