<?php 
include ("kfunctions.php");?>

<html>
<head>
<?php kheader(); ?>
</head>
<body>

    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

<!-- Page Heading -->
              

<div class="panel panel-yellow"><!--Initiative-->
<div class="panel-heading"><h3 class="panel-title">Input expenses</h3></div>
<div class="panel-body">

<?php

if(isset($_POST["submit120"])){

$max = $_POST["max"];

include ("connect.php");
$ouruser = $_SESSION["rolenumber"];

for($y=1; $y<=$max; $y++){
$item = $_POST["item".$y.""];
$item2 = $_POST["item2".$y.""];

if($item == ""){
  $fitem = $item2;
  $exptim = "2";
}elseif($item2 == ""){
  $fitem = $item;
  $exptim = "1";

}

$cost = $_POST["cost".$y.""];
$requestfrom = $_POST["requestfrom".$y.""];
$comment = $_POST["comment".$y.""];

if(($fitem=="")&&($requestfrom == "")){

}else{
$insertexpenses = $dbh->exec("insert into expenses (item,cost,requestfrom,comment,ouruser,exptim) values('$fitem', '$cost', '$requestfrom', '$comment', '$ouruser','$exptim')");
}
}
}

?>
  <form method='post'>
    <input type='submit' style='float:right;' class='btn btn-sm btn-success' value='Submit expenses' name='submit120'>
<table class="table table-bordered table-hover table-striped sortable">
<thead>
  <tr>
    <th>No</th>
    <th colspan='2'>Item</th>
    <th>Cost</th>
  <th>Request from</th>
  <th>Comment</th>
  </tr>
</thead>
<tbody>
  
  <?php

$max = "10";
  for($x=1; $x<=$max; $x++){
 echo "
<tr>
<input type='hidden' name='max' value='".$max."'>
  <td>".$x."</td>
  <td><input type='text'  class='form-control' name='item".$x."' placeholder='Item'></td>
  <td>
  <select class='form-control' name='item2".$x."'>
<option value=''>Item</option>
  ";

  $rolenumber = $_SESSION["rolenumber"];
  $role = $_SESSION["role"];
  
  if($role=="overadmin") {
   $all = "";
  
  }else{
    $all = "ouruser='$rolenumber' and";
  }

  include ("connect.php");
  $result = $dbh->query("select item from expenses where $all exptim='1'");
$row = $result->fetchObject();
$count = $result->rowCount();

if($count>0){
  do{
echo "
<option value='".$row->item."'>".$row->item."</option>
";
  }while($row = $result->fetchObject());

}else{echo "<option value=''>So far, No expense has been submitted</option>";}

  echo "
  </select>
  </td>
<td>
<input type='text' id='cost".$x."' class='form-control' name='cost".$x."' placeholder='Cost'>
  </td>
  <td>
  <input type='text' id='requestfrom".$x."' class='form-control' name='requestfrom".$x."'>
  </td>
  <td>
<textarea name='comment".$x."' placeholder='Comment' class='form-control'></textarea>
  </td>
  </tr>

  ";
}
  ?>
 
  </tbody>
</table>

<input type='submit' style='float:right;' class='btn btn-sm btn-success' value='Submit expenses' name='submit120'>
</form>

</div>
</div>

 </div>

           </div>
           </div>
           </div>


</html>


                <!-- /.row -->

                   
              