protected function validate() { $required = array("section" => "Section", "subject" => "Subject"); 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'; require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/subject_relations_class.php'; $arr = $_POST['subject']; $subRel = new SubjectRelations($objPDO); $teaRel = new SectionTeacherSubjectRelations($objPDO); $teaRel->deleteByClassId($_POST['section']); $subRel->deleteByClassId($_POST['section']); for ($i = 0; $i < count($arr); $i++) { $subRel = new SubjectRelations($objPDO); $subRel->setClassId($_POST['section']); $subRel->setSubjectId(intval($arr[$i])); $subRel->save(); } echo '<meta http-equiv="Refresh" content="0;url=http://localhost/cloud/miscellaneous"/>'; } } else { header('Location:http://localhost/cloud'); } }