<?php


    include('../../config/config.php');

    $userid = $_POST['UserID'];
    $UserType = $_POST['UserType'];
    
    $groupschoolID_new =$_POST['institution'];

    $select_schoolowner = mysqli_query($link, "SELECT * FROM `institution` WHERE `InstitutionID`='$groupschoolID_new'");
    $select_schoolowner_row = mysqli_fetch_assoc($select_schoolowner);
    $select_schoolowner_row_cnt = mysqli_num_rows($select_schoolowner);

   

   

    
    if($UserType == 'admin')
    {
      
      
       $selectverify_campus_new = mysqli_query($link, "SELECT * FROM `campus` WHERE `InstitutionID` = '$groupschoolID_new' AND FIND_IN_SET('$userid', `Admin`) > 0  ORDER BY `CampusName` ASC");  
    }else
    {
        $selectverify_campus_new = mysqli_query($link, "SELECT * FROM `section` INNER JOIN campus ON section.CampusID = campus.CampusID WHERE PrincipalOrDeanOrHeadTeacherUserID = '$userid' ORDER BY CampusName ASC LIMIT 1");  
    }
   
   
   
    
    $selectverify_campuscnt_new = mysqli_num_rows($selectverify_campus_new);
    $selectverify_campuscnt_row_new = mysqli_fetch_assoc($selectverify_campus_new);

    $campusID_new = $selectverify_campuscnt_row_new['CampusID'];

    $tagstatecampusmain = $selectverify_campuscnt_row_new['TagState'];

  

    echo '<input type="hidden" id="confirmschoolfor-owner" value="schoolavailable">';
    $numcamp = 2;

    do {

                    $groupschoolID = $select_schoolowner_row['InstitutionID'];
                    $schoolname = $select_schoolowner_row['InstitutionGeneralName'];

                    $TrashStatusschool = $select_schoolowner_row['TrashStatus'];


                if($TrashStatusschool == '1')
                {
                            $disabledcardschool = 'disabledschoolcampuscard';
                            $disabledcardclickschool = 'disabledschoolcampus';
                }else
                {

                    $disabledcardschool = '';
                    $disabledcardclickschool = '';

                }

                    

                      echo '<div class="col-9  '.$disabledcardclickschool.'">
                    
                            <h1 class="section-title mb-4" style="font-weight:600;font-size: 1.8rem;color:black;">' . $schoolname . '
                          <div class="dropdown">';
                          
                          
                          
                            
                             
                             
                                
                                    
                                if($UserType == 'owner')
                                 {
                                     
                                      echo ' <span data-bs-toggle="dropdown" aria-expanded="false" class="fa fa-edit text-primary" style="cursor:pointer;font-size:18px;"></span>';
                                 }else
                                 {
                                     
                                 }
                             
                             
                                echo '<div class="dropdown-menu" style="width:100px;height:140px;background-color:white;border-radius:10px;position:absolute;right:20rem;">
                                   ';
                                    
                                    
                                    
                                    
                                     if($UserType == 'owner')
                                 {
                                     
                                      echo '<a class="dropdown-item" data-bs-toggle="modal" href="#pros-editschool-modal" data-id="' . $groupschoolID . '"  id="editschoolbtn"  style="cursor:pointer;font-size:13px;">
                                       <i class="fa fa-edit text-warning" aria-hidden="true"> </i> Edit School</a>';
                                 }else
                                 {
                                     
                                 }
                                    
                                    echo '<a class="dropdown-item" data-bs-toggle="modal" href="#pros-deleteschool-modal" data-schoolname="'.$schoolname .'" data-school="'.$groupschoolID.'"  id="deleteschoolbtn"  style="cursor:pointer;font-size:13px;">   <i class="fa fa-trash text-danger" aria-hidden="true"> </i> Delete School</a>
                                   
                                </div>
                               
                                 </div>';
                                 
                                 if($UserType == 'owner')
                                 {
                                     
                                     
                                     echo '<a  style="color:blue;font-size:13px;cursor:pointer;display: block;" data-bs-toggle="modal" data-bs-target="#pros-invitestaff-usertype" data-id="' . $groupschoolID . '" id="invitestaffclick">   invite staff</a>';
                                     
                                 }else
                                 {
                                     
                                 }
                                 
                                 
                               
                        echo '</div>';

                        $selectverify_campus = mysqli_query($link, "SELECT  * FROM `campus` WHERE   InstitutionID='$groupschoolID'");
                        $selectverify_campuscnt = mysqli_num_rows($selectverify_campus);
                        $selectverify_campuscnt_row = mysqli_fetch_assoc($selectverify_campus);

        if ($selectverify_campuscnt > 0) {

            $counter = 0;
            do {
                $campusname = $selectverify_campuscnt_row['CampusName'];
                $campusID = $selectverify_campuscnt_row['CampusID'];
                $campusemail = $selectverify_campuscnt_row['CampusEmail'];
                $campusphone = $selectverify_campuscnt_row['CampusPhone'];
                $address = $selectverify_campuscnt_row['CampusAddress'];
                $campustagstate = $selectverify_campuscnt_row['TagState'];
                $TrashPeriodcampus = $selectverify_campuscnt_row['CampusTrashStatus'];

                
                $maxcampus_length = 30;

                if (strlen($campusname) > $maxcampus_length) {

                    $shortened_campus = substr($campusname, 0, 30) . "...";

                } else {
                    $shortened_campus = $campusname;
                }

                $counter++;


                if($TrashPeriodcampus == '1')
                {
                            $disabledcard = 'disabledschoolcampuscard';
                            $disabledcardclick = 'disabledschoolcampus';
                }else
                {

                    $disabledcard = '';
                    $disabledcardclick = '';

                }


               

                
                if ($counter == 1) {
                    
                   
                    echo '<div class="col-sm-4 mb-4">
                            <div class="card '.$disabledcard.' '.$disabledcardclick.'" style="background-image: linear-gradient(180deg,#007bff,#00008B);height:180px;border:1px solid #DFE0EB;border-radius:15px;">
                            <div class="card-header" style="background-image: linear-gradient(180deg,#007bff,#00008B);border-top-right-radius:15px;border-top-left-radius:15px;">
                                <div class="dropdown " style="margin-right:10rem;position:absolute;top:0.5rem;right:-8.5rem;">';
                                
                                
                                if($UserType == 'owner')
                                 {
                                     
                                     
                                     echo ' <span class="fa fa-ellipsis-v  text-light"  data-bs-toggle="dropdown" aria-expanded="false" style="cursor:pointer;font-size:14px;"></span>';
                                     
                                 }else
                                 {
                                     
                                 }
                                        
                                    
                                   echo '<div class="dropdown-menu" style="width:30px !important;height:140px;background-color:white;border-radius:10px;">
                                        <a class="dropdown-item" data-bs-toggle="modal" href="#pros-editcampus-modal"   id="editcampusbtn" data-camp="' . $campusID . '" data-sch="' . $groupschoolID . '" style="cursor:pointer;font-size:12px;">   <i class="fa fa-edit text-warning" aria-hidden="true"> </i> Edit</a>
                                        <a class="dropdown-item" data-bs-toggle="modal" href="#pros-deletecampus-modal"   id="prosdeletecampusbtnload"  data-campname="'.$campusname.'" data-camp="'.$campusID . '" data-sch="' . $groupschoolID . '" style="cursor:pointer;font-size:12px;"> <i class="fa fa-trash text-danger" aria-hidden="true"></i>   Delete </a>
                                        
                                    
                                    </div>
                                </div>
                                
                                    <h3 class="card-title text-light" style="font-weight:600;text-transform: uppercase;font-size: 0.87rem;">Main campus</h3>
                                
                                
                                </div>
                                <div class="card-body">
                                        <h5 class="section-title text-light prosdisplaycampusnameedit'.$campusID.'"  style="font-weight:600;font-size: 0.77rem;">' . $shortened_campus . '</h5>';


                                        if($TrashPeriodcampus == '1')
                                        {


                                            echo '<a    data-id="'.$campusID.'" data-school="'.$groupschoolID.'"   class="pros-undoncampusdeletebtn prosundodeleteschoolorcampusdelbtn"  style="color:white;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">Undo Delete</a>';
                                        }else
                                        {

                                                    if ($campustagstate == '' || $tagstatecampusmain == '15' || $campustagstate == '16' || $campustagstate == '17' || $campustagstate == '18' || $campustagstate == '19' || $campustagstate == '20' || $campustagstate == '21' || $campustagstate == '22' || $campustagstate == '23' || $campustagstate == '24' || $campustagstate == '25' || $campustagstate == '26' || $campustagstate == '27' || $campustagstate == '28')
                                                    {
                                                            echo '<u class="opensetupmodalforschool" data-maintag="'.$tagstatecampusmain.'" data-tag="'.$campustagstate.'" data-id="'.$groupschoolID.'" data-campus="'.$campusID.'" data-access="granted" data-maincam="main" style="color:white;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">Complete setup</u>';
                                                    }else
                                                    {
                                                        
                                                        echo '<a  data-bs-toggle="modal" data-bs-target="#prosloadset-configurationhere" data-id="'.$campusID.'"   class="prosloadinstitutionbtn"  style="color:white;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">Make changes</a>';
                                                    }


                                        }

                                       

                                        
                                echo '</div>
                            </div>
                    </div>';

                } else {


                    echo '<div class="col-sm-4 mb-4">
                            <div class="card '.$disabledcard.' '.$disabledcardclick.'" style="background:#FCFCFC;border:1px solid #DFE0EB;height:180px;border-radius:15px;">
                                <div class="card-header" style="background:#FCFCFC;border-top-right-radius:15px;border-top-left-radius:15px;">
                                    <div class="dropdown" style="margin-right:10rem;position:absolute;top:0.5rem;right:-8.5rem;">';

                                       
                                if($UserType == 'owner')
                                 {
                                     
                                     
                                     echo ' <span class="fa fa-ellipsis-v  text-light"  data-bs-toggle="dropdown" aria-expanded="false" style="cursor:pointer;font-size:14px;"></span>';
                                     
                                 }else
                                 {
                                     
                                 }

                                        echo '<div class="dropdown-menu" style="width:30px !important;height:140px;background-color:white;border-radius:10px;">
                                            <a class="dropdown-item"  data-bs-toggle="modal" href="#pros-editcampus-modal"   id="editcampusbtn" data-camp="' . $campusID . '" data-sch="' . $groupschoolID . '" style="cursor:pointer;font-size:12px;">  <i class="fa fa-edit text-warning" aria-hidden="true"></i> Edit </a>
                                            <a class="dropdown-item" data-bs-toggle="modal" href="#pros-deletecampus-modal"   id="prosdeletecampusbtnload"  data-campname="'.$campusname.'" data-camp="' . $campusID . '" data-sch="' . $groupschoolID . '"  style="cursor:pointer;font-size:12px;">  <i class="fa fa-trash text-danger" aria-hidden="true"></i>  Delete </a>
                                           
                                            
                                        </div>

                                    </div>

                                    <h3 class="card-title" style="font-weight:600;text-transform: uppercase;font-size: 0.87rem;">Campus ' .$numcamp++ . '</h3>
                                    
                                </div>

                                <div class="card-body">
                                    <h5 class="section-title prosdisplaycampusnameedit'.$campusID.'" style="font-weight:600;font-size:14px;">' .$shortened_campus . '</h5>';
                                    //  <u class="text-danger" style="float:left;font-size:13px;text-decoration:none;margin-top:4rem;">0% completed</u>
                                    // echo '<a href="" class=""  style="color:white;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">View setup</a>';
                                    

                                    if($TrashPeriodcampus == '1')
                                    {


                                        echo '<a    data-id="'.$campusID.'" data-school="'.$groupschoolID.'"    class="pros-undoncampusdeletebtn prosundodeleteschoolorcampusdelbtn"  style="color:blue;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">Undo Delete</a>';
                                    }else
                                    {
                                        


                                                if ($tagstatecampusmain == '' || $tagstatecampusmain == '15' || $tagstatecampusmain == '16' || $tagstatecampusmain == '17' || $tagstatecampusmain == '18' || $tagstatecampusmain == '19' || $tagstatecampusmain == '20' || $tagstatecampusmain == '21' || $tagstatecampusmain == '22' || $tagstatecampusmain == '23' || $tagstatecampusmain == '24' || $tagstatecampusmain == '25' || $tagstatecampusmain == '26')
                                                {
                                                    
                                                            echo '<u  class="opensetupmodalforschool" data-id="'.$groupschoolID.'" data-campus="'.$campusID.'" data-access="notgranted" style="color:blue;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">Complete setup</u>';
                                                }else
                                                {

                                                    if ($campustagstate == '' ||  $campustagstate == '15' || $campustagstate == '16' || $campustagstate == '17' || $campustagstate == '18' || $campustagstate == '19' || $campustagstate == '20' || $campustagstate == '21' || $campustagstate == '22' || $campustagstate == '23' || $campustagstate == '24' || $campustagstate == '25' || $campustagstate == '26' || $campustagstate == '27' || $campustagstate == '28')
                                                    {
                                                                echo '<u  class="opensetupmodalforschool" data-maintag="'.$tagstatecampusmain.'" data-tag="'.$campustagstate.'" data-id="'.$groupschoolID.'" data-campus="'.$campusID.'" data-maincam="notmain" data-access="granted" style="color:blue;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">Complete setup</u>';  
                                                    }else
                                                    {
                                                                echo '<a data-bs-toggle="modal" data-bs-target="#prosloadset-configurationhere" data-id="'.$campusID.'"   class="prosloadinstitutionbtn"   style="color:blue;float:right;font-size:13px;text-decoration:underline;cursor:pointer;margin-top:4rem;">Make changes</a>';
                                                    } 


                                                        
                                                }

                                    }
                                        
                                    
                                    
                                echo '</div>
                            </div>
                    </div>';
                }



            } while ($selectverify_campuscnt_row = mysqli_fetch_assoc($selectverify_campus));
        } else {

        }

         //Add new campus btn here

         
        

            // echo '<div class="col-sm-4 mb-4">
            //         <div class="card '.$disabledcardclickschool.' '.$disabledcardschool.'" data-bs-toggle="modal" id="proscreatescampusgetid" data-school="'.$groupschoolID.'"  data-bs-target="#pros-createnewcampus" style="height:180px;border-radius:15px;cursor:pointer;border:1px solid #007bff;color:#007bff;display: flex;justify-content: center;align-items: center;">
            //         <div class="card-body" style="display: flex;justify-content: center;align-items: center;">
            //             <center>
            //                 <span class="fa fa-plus" style="color:blue;font-size:15px;cursor:pointer;"></span><br>
            //                 <span>Add Campus</span>
            //             </center>
                        
            //         </div>
            //         </div>
            // </div>';

        //Add new campus btn here

    } while ($select_schoolowner_row = mysqli_fetch_assoc($select_schoolowner));


    $sqlGetSchool = ("SELECT * FROM `section` WHERE CampusID='$campusID_new'");
    $resultGetSchool = mysqli_query($link, $sqlGetSchool);
    $rowGetSchool = mysqli_fetch_assoc($resultGetSchool);
    $row_cntGetSchool = mysqli_num_rows($resultGetSchool);


    $sqlGetSchool_assigned  = ("SELECT * FROM `section` WHERE CampusID='$campusID_new' AND PrincipalOrDeanOrHeadTeacherUserID != '0'");
    $resultGetSchool_assigned  = mysqli_query($link, $sqlGetSchool_assigned);
    $rowGetSchool_assigned  = mysqli_fetch_assoc($resultGetSchool_assigned);
    $row_cntGetSchool_assigned  = mysqli_num_rows($resultGetSchool_assigned);

  


    //    <!--prompt stup modal -->

          // <!--prompt stup modal --> 
          echo '<div class="modal fade" id="pros-createstaff-modal" style="background-color: rgba(0, 0, 0, 0.9); z-index: 1050;" tabindex="-1" role="dialog" aria-labelledby="pros-createstaff-modalLabel" aria-hidden="true">
          <div class="modal-dialog modal-dialog-scrollable modal-xl" id="pros-reducemodalclasstypesetup"  style="max-width:86%;margin: 1.75rem auto;color: rgb(56, 58, 63);" role="document">
              <div class="modal-content" id="prosscrollinside-modalbody" style="border:none;width: 100%;border-radius: 5px;">

                <div class="modal-header" style="border:none;">

                  <u style="color:blue;font-size:13px;text-decoration:underline;cursor:pointer;display:none;" id="movebackbtn-setup"><i class="fa fa-arrow-left"></i> Back</u>
                      <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                  
                  <div class="modal-body"  style="padding:6% 8%;overflow: auto;">';
                        echo '<div id="pros-displaysetup-content"></div>'; //load setup modal
                  echo '</div>

            </div>
        </div>
        </div>';
                  //    prompt stup modal 







   









?>