lollipop

A PHP-framework
Log | Files | Refs

user.php (4060B)


      1 <?php
      2 /* if(isset($_POST["search"])){
      3     $user->load($_POST["search"]);
      4     $data = $user->getData();
      5   }*/
      6 $user_get = function (&$vars) {
      7     global $db;
      8     $user = $db->get(Model\User::class);
      9     $permissions = $db->get(Model\Permission::class);
     10     $permission_user = $db->get(Model\PermissionUser::class);
     11     $vars += get_vars($user, "/user", "/user/search", "", "email", [], $permissions->get_checkboxes(), $permission_user);
     12     return "views/user.html";
     13 };
     14 
     15 $user_post = function (&$vars) {
     16     global $db;
     17     $user = $db->get(Model\User::class);
     18     $permissions = $db->get(Model\Permission::class);
     19     $permission_user = $db->get(Model\PermissionUser::class);
     20 
     21     if(isset($_POST["form_type"])) {
     22         if($_POST["form_type"] == 'Add') {
     23             if($user->add_user() && $permission_user->add_permissions($user)) {
     24                 $vars["response"] = 'succesfully added: ' . $_POST["email"];
     25             }
     26         } elseif($_POST["form_type"] == 'Update') {
     27             if($user->update_user() && $permission_user->update_permissions($user)) {
     28                 $vars["response"] = 'succesfully updated: ' . $_POST["email"];
     29             } else {
     30                 echo"something went wrong";
     31             }
     32         }
     33     }
     34     $vars += get_vars($user, "/user", "/user/search", "", "email", [], $permissions->get_checkboxes(), $permission_user);
     35     return "views/user.html";
     36 };
     37 
     38 $user_query = function (&$vars) {
     39     global $db;
     40     $user = $db->get(Model\User::class);
     41     $permissions = $db->get(Model\Permission::class);
     42     $permission_user = $db->get(Model\PermissionUser::class);
     43     $query = '%' . $vars['search_query'] . '%';
     44     $vars += get_vars($user, "/user", "/user/search", $query, "email", [], $permissions->get_checkboxes(), $permission_user);
     45     return "views/user.html";
     46 };
     47 
     48 $user_search = function (&$vars) {
     49     if(isset($_POST['search'])) {
     50         if($_POST['search'] == "") {
     51             $search = "%";
     52         } else {
     53             $search = $_POST['search'];
     54         }
     55         $header = '/user/search/' . $search;
     56         header('Location: ' . $header);
     57     } else {
     58         echo "wtF?";
     59         var_dump($_POST);
     60     }
     61 };
     62 
     63 $user_edit = function (&$vars) {
     64     global $db;
     65     $user = $db->get(Model\User::class);
     66     $permissions = $db->get(Model\Permission::class);
     67     $permission_user = $db->get(Model\PermissionUser::class);
     68     $templates = new controller\templates($db, $user);
     69     $data = [];
     70     $user->load($vars["primary_key"]);
     71     foreach($user->getData() as $key => $col) {
     72         $data[$key] = $col;
     73     }
     74     $vars += get_vars($user, "/user", "/user/search", "", "email", $data, $permissions->get_checkboxes(), $permission_user);
     75     return "views/user.html";
     76 };
     77 
     78 $user_delete = function (&$vars) {
     79     global $db;
     80     $user = $db->get(Model\User::class);
     81     $permissions = $db->get(Model\Permission::class);
     82 
     83     $permission_user = $db->get(Model\PermissionUser::class);
     84     $user->load($vars["primary_key"]);
     85     $user->delete();
     86     $vars += get_vars($user, "/user", "/user/search", "", "email", $permissions->get_checkboxes(), [], $permission_user);
     87     return "views/user.html";
     88 };
     89 
     90 $user_page = function (&$vars) {
     91     global $db;
     92     $user = $db->get(Model\User::class);
     93     $exam = $db->get(Model\Exam::class);
     94     $user->load($vars['primary_key']);
     95     $data = $user->getData();
     96     if(in_array(3, $_SESSION['user_permissions'])) {
     97         foreach($data as $key => $d) {
     98             $vars['user_data'] .= "<p>your $key = $d<p><br>";
     99         }
    100     } elseif($vars['primary_key'] == $_SESSION['email']) {
    101         foreach($data as $key => $d) {
    102             $vars['user_data'] .= "<p>your $key = $d<p><br>";
    103         }
    104         $vars['user_data'] .= "<h1>your grades</h1><br>";
    105         foreach($db->all_where(Model\Grade::class, ['email' => $vars['primary_key']]) as $grade) {
    106             $exam->load($grade->exam);
    107             $exam_name =$exam->name;
    108             $vars['user_data'] .= "<p>your grade for $exam_name = $grade->grade </p><br>";
    109         }
    110     }
    111     return "views/user_page.html";
    112 };