<?php


         error_reporting(E_ALL);
         ini_set('display_errors', 1);
        
         include('../../../config/config.php');
        
        
         $campus = $_POST['campus'];
         $userID = $_POST['userID'];
         $usertype = $_POST['usertype'];
         
         if($usertype == 'student')
         {
                     
                     
                     
                     $prosselectstudentinstitutid = mysqli_query($link, "SELECT * FROM `campus`  WHERE CampusID='$campus'");
                     $prosselectstudentinstitutidrow = mysqli_num_rows($prosselectstudentinstitutid);
                     $prosselectstudentinstitutidcnt = mysqli_fetch_assoc($prosselectstudentinstitutid);
                     
                     $InstitutionID =  $prosselectstudentinstitutidcnt['InstitutionID'];
                     
                     
             
             
             
         }else
         {
             
             
             $InstitutionID = $campus;
                                 
             
         }
         

         
         
     
         
         $proslectcalenar = mysqli_query($link," SELECT * FROM `calender` INNER JOIN `calender_purpose` ON `calender`.`Purpose_ID` = `calender_purpose`.`sn`  
         WHERE `calender`.InstitutionID='$InstitutionID' LIMIT 4");
         $proslectcalenarcnt = mysqli_num_rows($proslectcalenar);
         $proslectcalenarcntrow = mysqli_fetch_assoc($proslectcalenar);
         

          
          
          if($proslectcalenarcnt > 0)
          {
              
              
                       $proscheckstudentcount = 0;
              
                  do{
                      
                      
                      
                         $Session =  $proslectcalenarcntrow['Session'];
                         $Title =  $proslectcalenarcntrow['Title'];
                         $End_Date =  $proslectcalenarcntrow['End_Date'];
                         $Start_Date =  $proslectcalenarcntrow['Start_Date'];
                         $Purpose =  $proslectcalenarcntrow['Purpose'];
                         
                         

                         $finaldate = date('jS', strtotime($End_Date));
                      
                         $proscheckstudentcount++;
                        
                         if($proscheckstudentcount == '1')
                         {
                             
                             $prosactiveclass = 'active';
                             
                         }else
                         {
                             $prosactiveclass = ''; 
                         }
                         
                         
                         
                         
                         
                           
                
                                        
                
                
                                        // Get the current date and time
                                                    // $currentDateTime = date('Y-m-d H:i:s');
                
                                                   
                                                    // // Convert the post date and time to a UNIX timestamp
                                                    // $postTimestamp = strtotime($End_Date);
                
                                                    // // Convert the current date and time to a UNIX timestamp
                                                    // $currentTimestamp = strtotime($currentDateTime);
                
                                                    // // Calculate the difference in seconds
                                                    // $difference = $currentTimestamp - $End_Date;
                
                                                    // // Define time intervals in seconds
                                                    // $timeUnits = [
                                                    //     'year' => 31536000,
                                                    //     'month' => 2628000,
                                                    //     'week' => 604800,
                                                    //     'day' => 86400,
                                                    //     'hour' => 3600,
                                                    //     'minute' => 60,
                                                    //     'second' => 1
                                                    // ];
                
                                                    // // Initialize an empty string to store the result
                                                    // $timeElapsed = '';
                
                                                    // // Loop through the time units
                                                    // foreach ($timeUnits as $unit => $seconds) {
                                                    //     // Calculate the quantity of the current time unit
                                                    //     $unitCount = floor($difference / $seconds);
                                                        
                                                    //     // If there's at least one unit, add it to the result string
                                                    //     if ($unitCount > 0) {
                                                    //         $timeElapsed = "$unitCount $unit" . ($unitCount > 1 ? 's' : '') . ' ago';
                                                    //         break; // Stop the loop once the first non-zero unit is found
                                                    //     }
                                                    // }
                         
                         
                         
                         
                         echo  '<div class="card chiPerCardLeft" style="margin-top: 10px;">
                                    <div class="card-body">
                                        <div class="row g-2">
                                            <div class="col-9">
                                                <a href="" style="color: #666666; text-decoration: none;">
                                                    <strong style="font-size: 13px;">'.$Title.'</strong>
                                                    <br>
                                                    <small> '.$Purpose.'</small>
                                                </a>
                                            </div>
                                            <div class="col-3">
                                                <div style="margin-top: 36px;">
                                                    <small style="font-size: 10px;"> '.$End_Date.'</small>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>';
              
                      
                               
                      
                  }while($proslectcalenarcntrow = mysqli_fetch_assoc($proslectcalenar));
              
          }else
          {
              
          }
          
          
         
         
         
         
         
?>