<?php


        include("../../../config/config.php");
            
            
        $campus = $_POST["campus"];
        $institution = $_POST["institution"];
        $userID = $_POST["userID"];
        $usertype = $_POST["usertype"];
         $progressclassID = $_POST["progressclassID"];
        
        
        
         $proselectimage =  mysqli_query($link,"SELECT * FROM `defaultimages` WHERE `ImageName`='defaultprofile'");
        $proselectimagecnt = mysqli_fetch_assoc($proselectimage);
        $proselectimagecntrow = mysqli_num_rows($proselectimage);
        
        $BaseSixtyFour = $proselectimagecnt['BaseSixtyFour'];
        

         
      
        $prosselectstaffimage = mysqli_query($link,"SELECT * FROM `staff` WHERE StaffID='$userID' AND InstitutionID='$institution'");
         $prosselectstaffimagecnt = mysqli_fetch_assoc($prosselectstaffimage);
        $prosselectstaffimagerow = mysqli_num_rows($prosselectstaffimage);
        
          $StaffPhoto = $prosselectstaffimagecnt['StaffPhoto'];
          
          $stafffullimage = ($StaffPhoto == '') ? $BaseSixtyFour : $StaffPhoto;

        
         $prosloadsubject = array();
         
         
            if($usertype == 'teacher')
             {
                 
                  $prosslectsubjectcontent = mysqli_query($link, "SELECT * FROM `courseorsubjectallocation`
                      WHERE  `CampusID`='$campus' AND `CourseOrSubjectTeacherUserID`='$userID' AND `ClassOrDepartmentID`='$progressclassID'");
                 
             }else
             {
                 
                 
                  $prosslectsubjectcontent = mysqli_query($link, "SELECT * FROM `courseorsubjectallocation`
                  WHERE  `CampusID`='$campus'  AND `ClassOrDepartmentID`='$progressclassID'");
                 
             }
        
         
         $prosslectsubjectcontentrow = mysqli_fetch_assoc($prosslectsubjectcontent);
        $prosslectsubjectcontentcnt = mysqli_num_rows($prosslectsubjectcontent);
        
        
        
        if($prosslectsubjectcontentcnt > 0)
        {
            
                    do{
                        
                        
                        
                              $SubjectOrCourseIDnew = $prosslectsubjectcontentrow['SubjectOrCourseID'];
                              
                              
                              
                              $prosloadsubject[] = $SubjectOrCourseIDnew;
                           
                        
                        
                    }while($prosslectsubjectcontentrow = mysqli_fetch_assoc($prosslectsubjectcontent));
            
        }else
        {
            
        }
        
        
        $prosnewsubject = implode(',', $prosloadsubject);
        
        
        
        
            // $prosgetprosgetreport = mysqli_query($link, "SELECT * FROM `courseorsubjectallocation`
            //  WHERE  `CampusID`='$campus' AND `CourseOrSubjectTeacherUserID`='$userID'");
             
            //  $prosgetprosgetreportrow = mysqli_fetch_assoc($prosgetprosgetreport);
            //  $prosgetprosgetreport = mysqli_num_rows($prosgetprosgetreport);
            
             $sqlsecsession_startcount = mysqli_query($link, "SELECT * FROM `session` WHERE `sessionStatus`='1'");
              $querysecsession_startcount = mysqli_fetch_assoc($sqlsecsession_startcount);
              $cntsecsession_startcount = mysqli_num_rows($sqlsecsession_startcount);
            
             $session_startcount = $querysecsession_startcount['sessionName'];
             $sessionID_startcount = $querysecsession_startcount['sessionID'];
             
            $sqlsectermorsemesterdebt = mysqli_query($link, "SELECT * FROM `termorsemester` WHERE `status`='1'");
            $querysectermorsemesterdebt = mysqli_fetch_assoc($sqlsectermorsemesterdebt);
            $cntsectermorsemesterdebt = mysqli_num_rows($sqlsectermorsemesterdebt);
            
            $termorsemesterdebt = $querysectermorsemesterdebt['TermOrSemesterName'];
            $TermOrSemesterID = $querysectermorsemesterdebt['TermOrSemesterID'];
                 
             
        
          
            $prosgetsubject =   mysqli_query($link, "SELECT * FROM `progressreport` INNER JOIN `subjectorcourse` ON `progressreport`.`SubjectOrCourseID` =  `subjectorcourse`.`SubjectOrCourseID` 
           WHERE `progressreport`.`SubjectOrCourseID` IN($prosnewsubject)  AND  `progressreport`.`CampusID`='$campus' AND `progressreport`.`ClassOrDepartmentID`='$progressclassID'  GROUP BY `progressreport`.`SubjectOrCourseID` ORDER BY ProgressreportID DESC LIMIT 2");
            
          $prosgetsubjectcnt =  mysqli_num_rows($prosgetsubject);
          $prosgetsubjectcntrow =  mysqli_fetch_assoc($prosgetsubject);
          
          if($prosgetsubjectcnt > 0)
          {
              
              
              
              
                  do{
                      
                      
                      
                                $SubjectOrCourseTitle = $prosgetsubjectcntrow['SubjectOrCourseTitle'];
                                $SubjectOrCourseID = $prosgetsubjectcntrow['SubjectOrCourseID'];
                                $Date = $prosgetsubjectcntrow['Date'];
                                $ClassOrDepartmentIDreport = $prosgetsubjectcntrow['ClassOrDepartmentID'];
                                $CampusIDreport = $prosgetsubjectcntrow['CampusID'];
                                
                                
                                
                                  $prosgetsubjectcountclass =  mysqli_query($link, "SELECT * FROM `progressreport` 
                                 WHERE `SubjectOrCourseID` ='$SubjectOrCourseID'  AND  `progressreport`.`CampusID`='$CampusIDreport' AND `ClassOrDepartmentID`='$ClassOrDepartmentIDreport'");
                                    
                                  $prosgetsubjectcountclassrow =  mysqli_num_rows($prosgetsubjectcountclass);
                                
                                
                                
                                
                                $prosgetstudent = mysqli_query($link,"SELECT * FROM `classordepartmentstudentallocation` INNER JOIN `student` ON `classordepartmentstudentallocation`.`StudentID` =  `student`.`StudentID` WHERE 
                                `classordepartmentstudentallocation`.`CampusID`='$CampusIDreport' 
                                AND `classordepartmentstudentallocation`.`ClassOrDepartmentID`='$ClassOrDepartmentIDreport'");
                                $prosgetstudentcnt = mysqli_num_rows($prosgetstudent);
                                
                                
                                $prosgettotaltopichere = mysqli_query($link," SELECT * FROM `curriculumtopic` WHERE `CampusID`='$CampusIDreport' AND 
                                `SubjectOrCourseID`='$SubjectOrCourseID' AND `ClassOrDepartmentID`='$ClassOrDepartmentIDreport'");
                                $prosgettotaltopicherecnt = mysqli_num_rows($prosgettotaltopichere);
                                
                                $prosgepercentageoftopic = $prosgettotaltopicherecnt/$prosgetsubjectcountclassrow*100;
                                
                                
                                
                               
                                
                                
                                  
                                 echo' <div class="card chiCourseList">
                            				<div class="card-body">
                            					<div class="row g-2">
                            						
                            						<div class="col-sm-4 col-md-4" style="display: flex;">
                            
                            							<div style="margin-top: 5px;">
                            								<img src="'.$stafffullimage.'" style="width: 35px;height: 35px; border-radius: 5px;" alt="">
                            							</div>
                            							<div style="margin-left: 10px;">
                            							
                            								<h6 style="font-size: 14px;">'.$SubjectOrCourseTitle.'</h6>
                            								
                            								<span>
                            								
                            								</span>
                            								
                            							</div>
                            							
                            						</div>
                            						<div class="col-sm-2 col-md-2">
                            							<div>
                            								<h6 style="font-size: 14px;">Duration</h6>
                            								<span>'.$Date.'</span>
                            							</div>
                            						</div>
                            						<div class="col-sm-4 col-md-4">
                            							<div class="row g-2" style="margin-top: 5px;">
                            								<div class="col-2">
                            									<span style="font-size: 10px;">'.$prosgepercentageoftopic.'%</span>
                            								</div>
                            								<div class="col-8">
                            									<div style="margin-top: 5px;">
                            										<div class="progress" style="height: 7px;">
                            											<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: '.$prosgepercentageoftopic.'%" aria-valuenow="'.$prosgepercentageoftopic.'" aria-valuemin="0" aria-valuemax="100"></div>
                            										</div>
                            									</div>
                            								</div>
                            								<div class="col-2">
                            									<span style="font-size: 11px;">'.$prosgetsubjectcountclassrow.'/'.$prosgettotaltopicherecnt.'</span>
                            								</div>
                            							</div>
                            						</div>
                            						<div class="col-sm-2 col-md-2">
                            							<div style="margin-top: 10px;">
                            								<i class="fa fa-user-o ml-5"></i> '.$prosgetstudentcnt.'. 
                            								<i class="fa fa-book ml-1 rounded"></i> '.$prosgettotaltopicherecnt.' .
                            								
                            							</div>
                            						</div>
                            						
                            					</div>
                            				</div>
                            			</div>
                            
                            			';
                      
                      
                      
                  }while($prosgetsubjectcntrow =  mysqli_fetch_assoc($prosgetsubject));
                  
  					echo '<br><a href="#ekene_progress_report" data-bs-toggle="modal" style="font-weight: 600; text-decoration: none; float: right; margin-right: 15px; margin-top: 0px;">View All</a>';
              
              
          }else
          {
              
              
              
              echo' <div class="card chiCourseList">
    				<div class="card-body">
    					<div class="row g-2">
    						
    						<div class="col-sm-12 col-md-12" >
    						
    						
    						  <center>
    						        <img width="48" height="48" src="https://img.icons8.com/external-topaz-kerismaker/48/external-Not-Found-empty-state-topaz-kerismaker.png" alt="external-Not-Found-empty-state-topaz-kerismaker"/>
    						        <p>No Progress Report Found</p>
    						  </center>
    
    							
    						</div>
    						
    						
    					</div>
    				</div>
    			</div>	';
    	echo '<br><a href="#ekene_progress_report" data-bs-toggle="modal" style="font-weight: 600; text-decoration: none; float: right; margin-right: 15px; margin-top: 0px;">View All</a>';
    		

              
              
          }
        
        
        
    
        
   