-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdminController.php
149 lines (116 loc) · 3.97 KB
/
AdminController.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
class AdminController extends BaseController {
/**
* @return mixed
*/
public function menu() {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$data = [];
$data['menu'] = DB::select("select * from menu");
return View::make('admin/menu', $data);
}
/**
* @param null $id
* @return mixed
*/
public function pageEdit($id = null) {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$data = [];
$data['currentPage'] = DB::select("select * from pages where id = ?", array($id))[0];
$data['menu'] = DB::select("SELECT * FROM menu");
$data['pages'] = DB::select("select * from pages");
return View::make('admin/edit', $data);
}
public function menuEdit($id = null) {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$data = [];
$data['currentItem'] = DB::select("SELECT * FROM menu WHERE id = ?", array($id))[0];
$data['menu'] = DB::select("SELECT * FROM menu");
return View::make('admin/editMenu', $data);
}
/**
* @return mixed
*/
public function index() {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$data = [];
$data['pages'] = DB::select("select * from pages");
$data['menu'] = DB::select("SELECT * FROM menu");
return View::make('admin/index', $data);
}
/**
* @return mixed
*/
public function login() {
if (Auth::check()) {
return Redirect::intended('admin');
}
$username = Input::get('username');
$password = Input::get('password');
if (Auth::attempt(array('username' => $username, 'password' => $password))) {
return Redirect::to('admin');
}
return Redirect::to('admin/login');
}
/**
* @return mixed
*/
public function createPage() {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$pageContent = Input::get('pageText');
$pageTitle = Input::get('pageTitle');
$menuId = Input::get('menuId');
DB::insert("INSERT INTO pages (id, title, text, menu_id) VALUES(?, ?, ?, ?)", array(null, $pageTitle, $pageContent, $menuId));
return Redirect::to('admin');
}
public function updatePage() {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$pageContent = Input::get('pageText');
$pageTitle = Input::get('pageTitle');
$id = Input::get('pageId');
$menuId = Input::get('menuId');
DB::update("UPDATE pages SET title = ?, text = ?, menu_id = ? WHERE id = ?", array($pageTitle, $pageContent, $menuId, $id));
return Redirect::to('admin');
}
/**
* @return mixed
*/
public function createMenu() {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$menuName = Input::get('menuName');
$menuUrl = Input::get('menuUrl');
$parentId = Input::get('parentId');
DB::insert("insert into menu (id, name, url, parent_id) values (?, ?, ?, ?)", array(null, $menuName, $menuUrl, $parentId));
return Redirect::to('admin/menu');
}
public function updateMenu() {
if (!Auth::check()) {
return Redirect::to('admin/login');
}
$menuId = Input::get('menuId');
$menuName = Input::get('menuName');
$parentId = Input::get('parentId');
$menuUrl = Input::get('menuUrl');
$deleteMenu = Input::get('deleteMenu');
if (isset($deleteMenu)) {
DB::delete("DELETE FROM menu WHERE id = ?", array($menuId));
} else {
DB::update("UPDATE menu SET name = ?, url = ?, parent_id = ? WHERE id = ?", array($menuName, $menuUrl, $parentId, $menuId));
}
return Redirect::to('admin/menu/');
}
}