<?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">
<?php
$itemid = $mysqli->real_escape_string(stripslashes($_REQUEST['itemid']));
$item_id = $mysqli->real_escape_string(stripslashes($_REQUEST['item_id']));	  
$season_id = $mysqli->real_escape_string(stripslashes($_REQUEST['season_id']));
$day_id = $mysqli->real_escape_string(stripslashes($_REQUEST['day_id']));
$price = $mysqli->real_escape_string(stripslashes($_REQUEST['price']));
if ($availability==0) {
$available='0';  
}else{ 
$available='1'; }

$result = $mysqli->query("SELECT * FROM items WHERE insert_id='$itemid' AND lang_id=$lang");
$row = $result->fetch_array(); 
$category_id=$row['category_id'];
$item=$row['name'];
?>
<div class="frametitles fadd"><?php echo $adminadd ?> &raquo; <?php echo $item ?>
<div class="floatright"><a href="list-items.php?catid=<?php echo $category_id ?>"><img src="img/list.png" alt="<?php echo $adminlist ?>" title="<?php echo $adminlist ?>"></a></div>
</div>
<div class="framein">

<?php
if  (isset($_POST['submit'])) {
$mysqli->query("INSERT INTO prices (item_id, season_id, day_id, price, available) VALUES ('$itemid', '$season_id', '$day_id', '$price', '$available')");

$results = $mysqli->query("SELECT * FROM seasons WHERE lang_id=$lang");
$rowss = mysqli_num_rows($results);

$resultd = $mysqli->query("SELECT id FROM days");
$rowsd = mysqli_num_rows($resultd);
if ($rowsd==0) {
$rowsd='1';  
}

$resultp = $mysqli->query("SELECT * FROM prices WHERE item_id='$itemid'");
$rowsp = mysqli_num_rows($resultp);
?>

<?php if  ($rowsp==$rowss*$rowsd) { ?>
<meta http-equiv="refresh" content="0;URL=list-items.php?catid=<?php echo $category_id ?>">
<?php } else {?>
<meta http-equiv="refresh" content="0;URL=add-price.php?itemid=<?php echo $itemid ?>">
<?php }?>

<?php
}
else  {
?>

<form name="forma" method="post" enctype="multipart/form-data">
<input type="hidden" name="itemid" value="<?php echo $itemid ?>">
<input type="hidden" name="category_id" value="<?php echo $category_id ?>">
  <table>
          <tr>
            <td class="tabletd1">&nbsp;</td>
            <td class="tabletd2"><span class="icon fa-calendar-o" title="<?php echo $adminseason ?>"></span></td>
            <td>
<select name="season_id">
<?php 
$result = $mysqli->query("SELECT * FROM seasons WHERE lang_id=$lang ORDER BY id");
while($row = $result->fetch_array()) {
$seasonid=$row['insert_id'];
$season=$row['name'];

$resultd = $mysqli->query("SELECT id FROM days");
$nrrowsd = mysqli_num_rows($resultd);

$result1p = $mysqli->query("SELECT * FROM prices WHERE item_id='$itemid' AND season_id=$seasonid");
$rowsp1 = mysqli_num_rows($result1p);
?>
<?php if  ($rowsp1<$nrrowsd OR $rowsp1==0) {?>
 <option value="<?php echo $seasonid ?>"> <?php echo $season ?> </option>
 <?php }?>
<?php }?>
</select>

<?php if  ($nrrowsd>0) { ?>
<select name="day_id">
<?php 
$result = $mysqli->query("SELECT * FROM days ORDER BY nr1");
while($row = $result->fetch_array()) {
$dayid=$row['id'];
$nr1=$row['nr1'];
$nr2=$row['nr2'];

$results = $mysqli->query("SELECT * FROM seasons WHERE lang_id=$lang");
$nrrowss = mysqli_num_rows($results);

$result2p = $mysqli->query("SELECT * FROM prices WHERE item_id='$itemid' AND day_id=$dayid");
$rowsp2 = mysqli_num_rows($result2p);
?>
<?php if  ($rowsp2<$nrrowss) {?>
 <option value="<?php echo $dayid ?>"> <?php echo $nr1 ?>-<?php echo $nr2 ?> </option>
 <?php }?>
<?php }?>
</select>
<?php }?>
            </td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><span class="icon fa-eur price"></span></td>
            <td><input type="text" name="price" size="15" class="inputauto"></td>
          </tr>
          </table>

     <hr>
  <div class="divallbuttons">
<div class="divlist"><a href="list-items.php?catid=<?php echo $category_id ?>" 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>