lollipop

A PHP-framework
Log | Files | Refs

course.php (3728B)


      1 <?php
      2 
      3 $course_get = function (&$vars) {
      4     global $db;
      5     $course = $db->get(Model\Course::class);
      6 
      7     if(isset($_POST["search"])) {
      8         $course->load($_POST["search"]);
      9         $data = $course->getData();
     10     }
     11     $vars += get_vars($course, "/course", "/course/search", "", "name");
     12     return "views/course.html";
     13 };
     14 
     15 $course_post = function (&$vars) {
     16     global $db;
     17     $course = $db->get(Model\Course::class);
     18     $user = $db->get(Model\User::class);
     19     if(isset($_POST["form_type"])) {
     20         if($user->load($_POST['lecturer'])) {
     21             if($_POST["form_type"] == 'Add') {
     22                 if($course->add_course()) {
     23                     $vars["response"] = 'succesfully added: ' . $_POST["name"];
     24                 }
     25             } elseif($_POST["form_type"] == 'Update') {
     26                 if($course->update_course()) {
     27                     $vars["response"] = 'succesfully updated: ' . $_POST["name"];
     28                 }
     29             }
     30         } else {
     31             $vars["response"] = 'foreign_key constraint on lecturer';
     32         }
     33     }
     34 
     35 
     36     $vars += get_vars($course, "/course", "/course/search", "", "name");
     37     return "views/course.html";
     38 };
     39 
     40 $course_query = function (&$vars) {
     41     global $db;
     42     $course = $db->get(Model\Course::class);
     43     $vars += get_vars($course, "/course", "/course/search", "", "name");
     44     return "views/course.html";
     45 };
     46 
     47 $course_search = function (&$vars) {
     48     if(isset($_POST['search'])) {
     49         if($_POST['search'] == "") {
     50             $search = "%";
     51         } else {
     52             $search = $_POST['search'];
     53         }
     54         $header = '/course/search/' . $search;
     55         header('Location: ' . $header);
     56     } else {
     57         echo "wtF?";
     58         var_dump($_POST);
     59     }
     60 };
     61 
     62 $course_edit = function (&$vars) {
     63     global $db;
     64     $course = $db->get(Model\Course::class);
     65     $data = [];
     66     $course->load($vars["primary_key"]);
     67     foreach($course->getData() as $key => $col) {
     68         $data[$key] = $col;
     69     }
     70     $vars += get_vars($course, "/course", "/course/search", "", "name", $data);
     71     return "views/course.html";
     72 };
     73 
     74 $course_delete = function (&$vars) {
     75     global $db;
     76     $course = $db->get(Model\Course::class);
     77     $course->load($vars["primary_key"]);
     78     $course->delete();
     79     $vars += get_vars($course, "/course", "/course/search", "", "name");
     80     return "views/course.html";
     81 };
     82 
     83 $course_data = function (&$vars) {
     84     global $db;
     85     $course = $db->get(Model\Course::class);
     86     $exam = $db->get(Model\Exam::class);
     87     $course->where("name", $vars["course"]);
     88     $tmp = $vars["course"];
     89     $table = "<h1>all exams for $tmp </h1><table> <thead> <tr>";
     90     foreach($exam->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\Exam::class, ["course_id" => $course->id]) as $data) {
     97         $table .= "<tr>";
     98         $col_names = $exam->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 };
    110 
    111 $course_enroll = function(&$vars) {
    112     global $db;
    113 
    114     $courseuser = $db->get(Model\CourseUser::class);
    115     $courseuser->id = $vars['primary_key'];
    116     $courseuser->email = $_SESSION['email'];
    117     $courseuser->add();
    118     
    119     header('Location: /dashboard');
    120 };
    121 
    122 $course_disenroll = function(&$vars) {
    123     global $db;
    124 
    125     $courseuser = $db->get(Model\CourseUser::class);
    126     $courseuser->id = $vars['primary_key'];
    127     $courseuser->email = $_SESSION['email'];
    128     $courseuser->delete();
    129 
    130     header('Location: /dashboard');
    131 };