<?php 
include("LoginCheckAdmin.php");
error_reporting(0);
session_start();
include("DbCon.php");
include('header.php');
//  $ClientID=$_GET['ClientID'];
 ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Add Event</title>
</head>
<body>

  
 
<form class = "border" action="Admin_EventAdd.php" enctype="multipart/form-data" method="post">
<table class="table table-striped" >

<tr>
    <th>Event Name</th>
    <td><input type="text" class="form-control"name="EventName" required></td>
</tr>
<tr>
<th class="form-label">Event Category</th>
    <td>
        
            <select name="EventCategoryID" id="" class="form-control" required>
            <option hidden disabled selected value> -- select an option -- </option>
                    <?php 
                         //include("DbCon.php");
                        $Qry = "SELECT * FROM `event_category`";
                        $Run = mysqli_query($con,$Qry);
                        if(mysqli_num_rows($Run)<1)
                        {
                            echo" No Record";
                        }
                        else
                        { 
                            //echo $Data['RSOID'];
                            while ($Data = mysqli_fetch_array($Run)) 
                            {
                                //echo $Data["CompanyName"];
                                ?>
                                <option value="<?php echo $Data['EventCategoryID'];?>"><?php echo $Data['EventCategoryName'];?></option>
                                <?php
                            }
                        }
                    ?>
                </select>
            
        
    </td>
</tr>
<tr>

    <th>Event Date</th>
    <td><input type="date" class="form-control"name="EventDate" required></td>
    </tr>

    <tr>
    <th>Event Time</th>
    <td><select name="EventTime" id="to" class="form-control" required>
    <option hidden disabled selected value> -- select an option -- </option>
    
    <option value="1AM">1:00-AM</option>
    <option value="2AM">2:00-AM</option>
    <option value="3AM">3:00-AM</option>
    <option value="4AM">4:00-AM</option>
    <option value="5AM">5:00-AM</option>
    <option value="6AM">6:00-AM</option>
    <option value="7AM">7:00-AM</option>
    <option value="8AM">8:00-AM</option>
    <option value="9AM">9:00-AM</option>
    <option value="10AM">10:00-AM</option>
    <option value="11AM">11:00-AM</option>
    <option value="12AM">12:00-AM</option>

    <option value="1PM">1:00-PM</option>
    <option value="2PM">2:00-PM</option>
    <option value="3PM">3:00-PM</option>
    <option value="4PM">4:00-PM</option>
    <option value="5PM">5:00-PM</option>
    <option value="6PM">6:00-PM</option>
    <option value="7PM">7:00-PM</option>
    <option value="8PM">8:00-PM</option>
    <option value="9PM">9:00-PM</option>
    <option value="10PM">10:00-PM</option>
    <option value="11PM">11:00-PM</option>
    <option value="12PM">12:00-PM</option>
    
  </select>
  </td>
    </tr>

    <tr>
    <th>Description</th>
    <td><input type="text" class="form-control" name="Description" required></td>
</tr>
<tr>
<th class="form-label">Location</th>
    <td>
        
            <select name="Location" id="" class="form-control" required>
            <option hidden disabled selected value> -- select an option -- </option>
                    <?php 
                         //include("DbCon.php");
                        $Qry = "SELECT * FROM `location`";
                        $Run = mysqli_query($con,$Qry);
                        if(mysqli_num_rows($Run)<1)
                        {
                            echo" No Record";
                        }
                        else
                        { 
                            //echo $Data['RSOID'];
                            while ($Data = mysqli_fetch_array($Run)) 
                            {
                                //echo $Data["CompanyName"];
                                ?>
                                <option value="<?php echo $Data['LocationID'];?>"><?php echo $Data['LocationName'];?></option>
                                <?php
                            }
                        }
                    ?>
                </select>
            
        
    </td>
</tr>
<tr>
    <th>Contact Phone</th>
    <td><input type="text" class="form-control" name="ContactPhone" required></td>
</tr>
<tr>
    <th>Contact Email</th>
    <td><input type="text" name="ContactEmail" class="form-control" required></td>

</tr>
    <!-- <tr>
    <th>Daily Count</th>
    <td><input type="text" class="form-control" name="DailyCount" required></td>
    </tr>
    <tr>
    <th>Daily Provided</th>
    <td><input type="text" class="form-control" name="DailyProvided" required></td>
    </tr> -->
    
    <!-- <tr>
    <th>Event Type</th>
            <td><select name="OrderStatus" class="form-control" >
        <option value="Pending">Pending</option>
        <option value="In Progress">In Progress</option>
        <option value="Completed">Completed</option>
        </select></td>
    </tr>  -->

   
<!--     
                        condition public superAdmin
                        RSO admin private, RsO Event -->
     <?php     
      if($_SESSION["UserType"]=="SuperAdmin")
      {
          ?>
        <input type="hidden" name="EventTypeID" value="1">
        <?php
      }
      if($_SESSION["UserType"]=="Admin")
      {
          ?>
           <tr>
           <th>Event Type</th>
                <td><select name="EventTypeID" class="form-control" required >
                <option hidden disabled selected value> -- select an option -- </option>                
                <option value="2">Private</option>
                <option value="3">RSO</option>
                </select></td>
           
        <?php
      }
    ?>
    <tr>
    <th>Picture</th>
    <td><input type="file" class="form-control" name="Picture" required></td>

</tr>
<tr>
    <td colspan="2" align="center"><input type="submit" class="btn btn-success" name="submit" value="submit" required ></td>
</tr>
</table>

</form>

</body>
</html>
<?php
 
if(isset($_POST["submit"]))
{

    $EventName= $_POST["EventName"];
    $EventCategoryID= $_POST["EventCategoryID"];
    $EventTime= $_POST["EventTime"];
    $EventDate= $_POST["EventDate"];
  
    $Description= $_POST["Description"];
    $LocationID= $_POST["Location"];
    
    $ContactPhone= $_POST["ContactPhone"];
    $ContactEmail= $_POST["ContactEmail"];
    $EventTypeID= $_POST["EventTypeID"];
    $UniversityID= $_SESSION["UniversityID"];
    $RSOID= $_SESSION["RSOID"];
   


    $PictureName=$_FILES["Picture"]["name"];
    $PicturetemporaryName=$_FILES["Picture"]["tmp_name"];
    //checking duplicate start
    $Qry3="SELECT * FROM `event` WHERE EventTime = '$EventTime' AND LocationID = '$LocationID' AND EventDate = '$EventDate'";
    $Run3=mysqli_query($con,$Qry3);
    if(mysqli_num_rows($Run3)>0)
    {
        ?>
        <script>
           alert("In this time There is already event at the same location ");
           
        </script>
        <?php
    }
    //checking duplicate End
    else
    {  
   

        // $PictureName=$_FILES["Picture"]["name"];
        // $PicturetemporaryName=$_FILES["Picture"]["tmp_name"];
        // move_uploaded_file($PicturetemporaryName,"Images/UniversityImage/".$PictureName);
        echo $UniversityID;
        $Qry2="INSERT INTO `event`(`EventName`, `EventCategoryID`, `EventDate`, `EventTime`, `Description`, `LocationID`,`ContactPhone`, `ContactEmail`, `EventTypeID`, `Picture` , `RSOID` , `UniversityID`) VALUES ('$EventName','$EventCategoryID','$EventDate', '$EventTime','$Description','$LocationID','$ContactPhone','$ContactEmail', '$EventTypeID', '$PictureName' , '$RSOID','$UniversityID')";
        $Run2 = mysqli_query($con,$Qry2);
        if($Run2==true)
        {
          
            move_uploaded_file($PicturetemporaryName,"Images/EventImage/".$PictureName);

            ?>
            <script>
                alert("Data inserted successfully");
                if ( window.history.replaceState ) 
                {
                window.history.replaceState( null, null, window.location.href );
                }
            </script>
            <?php
            unset($_POST["submit"]);




            // unset($_POST["submit"]);
            // unset($_POST["submit"]);
            // $_POST["submit"] = false;
            ?>
            <!-- <script>
            alert("Data inserted successfully");
            </script> -->
            <?php
            
        }
        else
        {
            ?>
            <script>
        alert("Data inserted failed");
            </script>
            <?php
        }
    }
}


   
    unset($_POST["submit"]);
   
?>




