protected function validaterelation()
 {
     $required = array("section" => "Section", "subject" => "Subject", "teacher" => "Teacher");
     global $user;
     if ($user->checkAdmin() == true) {
         if (isset($_POST)) {
             foreach ($required as $key => $value) {
                 if (!isset($_POST[$key]) || $_POST[$key] == '' || $_POST[$key] == 'select') {
                     echo $value . ' is Required<br/>';
                     return;
                 }
             }
             echo 'Saving...';
             global $objPDO;
             require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/section_teacher_subject_class.php';
             $arr_sub = $_POST['subject'];
             $arr_teacher = $_POST['teacher'];
             for ($i = 0; $i < count($arr_sub); $i++) {
                 $subRel = new SectionTeacherSubjectRelations($objPDO);
                 $subRel->setSectionId($_POST['section']);
                 $subRel->setSubjectId(intval($arr_sub[$i]));
                 $subRel->loadByClassSubject();
                 $subRel->setTeacherId(intval($arr_teacher[$i]));
                 $subRel->save();
             }
             echo '<meta http-equiv="Refresh" content="0;url=http://localhost/cloud/miscellaneous"/>';
         }
     } else {
         header('Location:http://localhost/cloud');
     }
 }
 protected function validate()
 {
     $required = array("section" => "Section");
     global $user;
     if ($user->checkAdmin() == true) {
         if (isset($_POST)) {
             foreach ($required as $key => $value) {
                 if (!isset($_POST[$key]) || $_POST[$key] == '' || $_POST[$key] == 'select') {
                     echo $value . ' is Required<br/>';
                     return;
                 }
             }
             global $objPDO;
             include $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/timetable_settings_class.php';
             $sett = new TimetableSettings($objPDO);
             $slots = $sett->getAllSlots();
             if (!isset($slots)) {
                 $num_slots = 0;
             } else {
                 $num_slots = count($slots);
             }
             require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/timetable_class.php';
             require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/section_teacher_subject_class.php';
             require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/controller/utility_class.php';
             for ($i = 0; $i < count($_POST['time_table']); $i++) {
                 $spl = array();
                 $spl = explode("-", $_POST['time_table'][$i]);
                 if (isset($spl[1])) {
                     $ttab = new Timetable($objPDO);
                     $ttab->setSectionId($_POST['section']);
                     $ttab->setSlot($spl[1]);
                     $ttab->getBySecSlot();
                     if ($spl[0] != '0') {
                         $rel = new SectionTeacherSubjectRelations($objPDO);
                         $tid = $rel->getByClassSubject($_POST['section'], $spl[0]);
                         if ($ttab->checkTeacherSlot($spl[1], $tid, $_POST['section'])) {
                             $ttab->setSubjectId($spl[0]);
                             $ttab->setTeacherId($tid);
                         } else {
                             $ttab->markForDeletion();
                             include_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/subject_class.php';
                             $sub = new Subject($objPDO, $spl[0]);
                             $day = floor($spl[1] / $num_slots);
                             $slot = $spl[1] % $num_slots;
                             echo "Teacher Slot Unavailable for " . $sub->getName() . " at " . Utility::getDay($day + 1) . " " . $slots[$slot] . "<br/>";
                             return;
                             $label = false;
                         }
                     } else {
                         if ($spl[0] == '0') {
                             $ttab->markForDeletion();
                         }
                     }
                     if (!isset($label) || $label != false) {
                     }
                     $ttab->save();
                 }
             }
             echo 'Saving...';
             if (!isset($label) || $label != false) {
                 echo '<meta http-equiv="Refresh" content="0;url=http://localhost/cloud/timetable"/>';
             }
         }
     } else {
         header('Location:http://localhost/cloud');
     }
 }