forked from theraw/FOS-Streaming-v69
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_admin.php
50 lines (43 loc) · 1.25 KB
/
manage_admin.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
<?php
include('config.php');
logincheck();
$message = [];
$title = "Create admin";
$admin = new Admin;
$edit = 0;
if (isset($_GET['id'])) {
$title = "Edit admin";
$admin = Admin::find($_GET['id']);
}
if (isset($_POST['submit'])) {
$error = 0;
$exists = Admin::where('username', '=', $_POST['username'])->get();
if (empty($_POST['username'])) {
$message['type'] = "error";
$message['message'] = "username field cannot be empty";
$error = 1;
} else if (!isset($_GET['id']) && $_POST['password'] == "") {
$message['type'] = "error";
$message['message'] = "password error";
$error = 1;
}
if ($error == 0) {
$message['type'] = "success";
if (isset($_GET['id'])) {
$message['message'] = "admin edited";
} else {
$message['message'] = "admin Created";
}
$admin->username = $_POST['username'];
if ($_POST['password'] != "") {
$admin->password = md5($_POST['password']);
}
$admin->save();
redirect("manage_admin.php?id=" . $admin->id, 2000);
}
}
echo $template->view()->make('manage_admin')
->with('admin', $admin)
->with('message', $message)
->with('title', $title)
->render();