-
Notifications
You must be signed in to change notification settings - Fork 19
/
manage_user.php
79 lines (64 loc) · 2.11 KB
/
manage_user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
include('config.php');
logincheck();
use Carbon\Carbon;
$message = [];
$title = "Create user";
$user = new User();
$categories = Category::all();
if (isset($_GET['id'])) {
$title = "Edit user";
$user = User::find($_GET['id']);
}
if (isset($_POST['submit'])) {
$user->username = $_POST['username'];
$user->password = $_POST['password'];
$user->exp_date = $_POST['expdate'];
$user->max_connections = $_POST['limit'];
if ($_POST['expdate']) {
$user->exp_date = Carbon::parse($_POST['expdate']);
}
$user->active = 0;
if (isset($_POST['active'])) {
$user->active = 1;
}
if (empty($_POST['username'])) {
$message['type'] = "error";
$message['message'] = "username field is empty";
} else if (empty($_POST['password'])) {
$message['type'] = "error";
$message['message'] = "password is empty";
} else if (empty($_POST['category'])) {
$message['type'] = "error";
$message['message'] = "Select one category";
} else {
if (isset($_GET['id'])) {
$message['type'] = "success";
$message['message'] = "User saved";
$user->save();
$user->categories()->sync($_POST['category']);
} else {
$exists = User::where('username', '=', $_POST['username'])->get();
if (count($exists) > 0) {
$message['type'] = "error";
$message['message'] = "Username already in use";
} else {
$message['type'] = "success";
$message['message'] = "User created";
$user->save();
$user->categories()->sync($_POST['category']);
redirect("manage_user.php?id=" . $user->id, 2000);
}
}
}
}
//print_r($user->categories->keyBy('id')->toArray());
//print_r($user->categories->get());
//\Illuminate\Database\Eloquent\Builder::lists($column, $key);
echo $template->view()
->make('manage_user')
->with('user', $user)
->with('categories', $categories)
->with('message', $message)
->with('title', $title)
->render();