grade.php (2581B)
1 <?php 2 3 $grade_get = function (&$vars) { 4 global $db; 5 $grade = $db->get(Model\Grade::class); 6 $templates = new Controller\Templates($db, $grade); 7 8 if(isset($_POST["search"])) { 9 $grade->load($_POST["search"]); 10 $data = $grade->getData(); 11 } 12 $vars += get_vars($grade, "/grade", "/grade/search", "", "email"); 13 return "views/grade.html"; 14 }; 15 16 $grade_post = function (&$vars) { 17 global $db; 18 $grade = $db->get(Model\Grade::class); 19 $user = $db->get(Model\User::class); 20 $exam = $db->get(Model\Exam::class); 21 if($exam->load($_POST['exam'])) { 22 if($user->load($_POST['email'])) { 23 if(isset($_POST["form_type"])) { 24 if($_POST["form_type"] == 'Add') { 25 if($grade->add_grade()) { 26 $vars["response"] = 'succesfully added: ' . $_POST["email"]; 27 } 28 } elseif($_POST["form_type"] == 'Update') { 29 if($grade->update_grade()) { 30 $vars["response"] = 'succesfully updated: ' . $_POST["email"]; 31 } 32 } 33 } 34 } else { 35 $vars["response"] = 'foreign_key constraint on email'; 36 } 37 } else { 38 $vars["response"] = 'foreign_key constraint on exam'; 39 } 40 $vars += get_vars($grade, "/grade", "/grade/search", "", "email"); 41 return "views/grade.html"; 42 }; 43 44 $grade_query = function (&$vars) { 45 global $db; 46 $grade = $db->get(Model\Grade::class); 47 $vars += get_vars($grade, "/grade", "/grade/search", "", "email"); 48 return "views/grade.html"; 49 }; 50 51 $grade_search = function (&$vars) { 52 if(isset($_POST['search'])) { 53 if($_POST['search'] == "") { 54 $search = "%"; 55 } else { 56 $search = $_POST['search']; 57 } 58 $header = '/grade/search/' . $search; 59 header('Location: ' . $header); 60 } else { 61 echo "wtF?"; 62 var_dump($_POST); 63 } 64 }; 65 66 $grade_edit = function (&$vars) { 67 global $db; 68 $grade = $db->get(Model\Grade::class); 69 70 $data = []; 71 $grade->load($vars["primary_key"]); 72 foreach($grade->getData() as $key => $col) { 73 $data[$key] = $col; 74 } 75 76 $vars += get_vars($grade, "/grade", "/grade/search", "", "email", $data); 77 return "views/grade.html"; 78 }; 79 80 $grade_delete = function (&$vars) { 81 global $db; 82 $grade = $db->get(Model\Grade::class); 83 84 $grade->load($vars["primary_key"]); 85 $grade->delete(); 86 87 $vars += get_vars($grade, "/grade", "/grade/search", "", "email"); 88 return "views/grade.html"; 89 };