exam.php (3097B)
1 <?php 2 3 $exam_get = function (&$vars) { 4 global $db; 5 $exam = $db->get(Model\Exam::class); 6 7 if(isset($_POST["search"])) { 8 $exam->load($_POST["search"]); 9 $data = $exam->getData(); 10 } 11 $vars += get_vars($exam, "/exam", "/exam/search", "", "name"); 12 return "views/exam.html"; 13 }; 14 15 $exam_post = function (&$vars) { 16 global $db; 17 $exam = $db->get(Model\Exam::class); 18 $course = $db->get(Model\Course::class); 19 if(isset($_POST["form_type"])) { 20 if($course->load($_POST['course_id'])) { 21 if($_POST["form_type"] == 'Add') { 22 if($exam->add_exam()) { 23 $vars["response"] = 'succesfully added: ' . $_POST["name"]; 24 } 25 } elseif($_POST["form_type"] == 'Update') { 26 if($exam->update_exam()) { 27 $vars["response"] = 'succesfully updated: ' . $_POST["name"]; 28 } 29 } 30 } else { 31 $vars["response"] = 'foreign_key constraint on course'; 32 } 33 } 34 35 36 $vars += get_vars($exam, "/exam", "/exam/search", "", "name"); 37 return "views/exam.html"; 38 }; 39 40 $exam_query = function (&$vars) { 41 global $db; 42 $exam = $db->get(Model\Exam::class); 43 $vars += get_vars($exam, "/exam", "/exam/search", "", "name"); 44 return "views/exam.html"; 45 }; 46 47 $exam_search = function (&$vars) { 48 if(isset($_POST['search'])) { 49 if($_POST['search'] == "") { 50 $search = "%"; 51 } else { 52 $search = $_POST['search']; 53 } 54 $header = '/exam/search/' . $search; 55 header('Location: ' . $header); 56 } else { 57 echo "wtF?"; 58 var_dump($_POST); 59 } 60 }; 61 62 $exam_edit = function (&$vars) { 63 global $db; 64 $exam = $db->get(Model\Exam::class); 65 $data = []; 66 $exam->load($vars["primary_key"]); 67 foreach($exam->getData() as $key => $col) { 68 $data[$key] = $col; 69 } 70 $vars += get_vars($exam, "/exam", "/exam/search", "", "name", $data); 71 return "views/exam.html"; 72 }; 73 74 $exam_delete = function (&$vars) { 75 global $db; 76 $exam = $db->get(Model\Exam::class); 77 $exam->load($vars["primary_key"]); 78 $exam->delete(); 79 $vars += get_vars($exam, "/exam", "/exam/search", "", "name"); 80 return "views/exam.html"; 81 }; 82 83 $exam_data = function (&$vars) { 84 global $db; 85 $exam = $db->get(Model\Exam::class); 86 $grade = $db->get(Model\Grade::class); 87 $exam->where("name", $vars["exam"]); 88 $tmp = $vars["exam"]; 89 $table = "<h1>all grades for $tmp </h1><table> <thead> <tr>"; 90 foreach($grade->get_column_names() as $column) { 91 $table .= "<th>$column</th>"; 92 } 93 $table .= "</tr> </thead>"; 94 $table .= "<tbody>"; 95 96 foreach($db->all_where(Model\Grade::class, ["exam" => $exam->id]) as $data) { 97 $table .= "<tr>"; 98 $col_names = $grade->get_column_names(); 99 foreach($col_names as $col) { 100 $table .= '<td>' . $data->{$col} . '</td>'; 101 } 102 $table .= "</tr>"; 103 }; 104 105 $table .= " 106 </tbody></table>"; 107 $vars['table'] = $table; 108 return "views/parent_child.html"; 109 };