<?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']));
?>

<div class="container">
<div class="frame">
<div class="frametitles fedit"><?php echo $adminedit ?>
<div class="floatright"><a href="add-season.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 ?>">

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

$date1 = substr($date1, 2, 4).".".substr($date1, 0, 2);
$date1b = substr($date1b, 2, 4).".".substr($date1b, 0, 2);
$date2 = substr($date2, 2, 4).".".substr($date2, 0, 2);
$date2b = substr($date2b, 2, 4).".".substr($date2b, 0, 2);
$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);
$date1 = $mysqli->real_escape_string(stripslashes($_REQUEST['date1']));	 
$date1b = $mysqli->real_escape_string(stripslashes($_REQUEST['date1b']));	  
$date2 = $mysqli->real_escape_string(stripslashes($_REQUEST['date2']));	 
$date2b = $mysqli->real_escape_string(stripslashes($_REQUEST['date2b']));		  
$priority = $mysqli->real_escape_string(stripslashes($_REQUEST['priority']));

$date1 = substr($date1, 3, 2).substr($date1, 0, 2);
$date1b = substr($date1b, 3, 2).substr($date1b, 0, 2);
$date2 = substr($date2, 3, 2).substr($date2, 0, 2);
$date2b = substr($date2b, 3, 2).substr($date2b, 0, 2);

$mysqli->query("UPDATE seasons SET name='$name', date1='$date1', date1b='$date1b', date2='$date2', date2b='$date2b', priority='$priority' WHERE insert_id='$id' AND lang_id=$langid");
?>
<meta http-equiv="refresh" content="0;URL=list-seasons.php">    
<?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">
        </td>
    </tr>
    </table>

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

<!--NEW LANG -->

<?php
$result52 = $mysqli->query("SELECT * FROM lang WHERE id NOT IN (SELECT lang_id FROM seasons WHERE insert_id='$id') AND active=1 ORDER BY id");
$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">
        </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 seasons (insert_id, lang_id, name, date1, date2, priority) VALUES ('$insert_id', '$langid2', '$name2', '$date1', '$date2', '$priority')");
?>

<meta http-equiv="refresh" content="0;URL=list-seasons.php">    
    
<?php } ?>
<?php } ?>
<?php } ?>

<!--END NEW LANG -->

<table>
    <tr>
      <td class="tabletd1">&nbsp;</td>
      <td class="tabletd2"><span class="icon fa-calendar" title="<?php echo $admindate ?>"></span> 1</td>
      <td>
        <input type="text" name="date1" id="date1" size="15" value="<?php echo $date1 ?>" class="inputauto"> 
        &harr; 
        <input type="text" name="date1b" id="date1b" size="15" value="<?php echo $date1b ?>" class="inputauto">
        </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><span class="icon fa-calendar" title="<?php echo $admindate ?>"></span> 2</td>
      <td>
        <input type="text" name="date2" id="date2" size="15" value="<?php echo $date2 ?>" class="inputauto"> 
        &harr; 
        <input type="text" name="date2b" id="date2b" size="15" value="<?php echo $date2b ?>" class="inputauto"></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>
 
   <hr>
  <div class="divallbuttons">
<div class="divlist"><a href="list-seasons.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>