1 <?php
2 3 4 5 6 7 8 9 10 11 12 13 14
15
16 App::uses('DashboardAppController', 'Dashboard.Controller');
17
18 19 20 21 22
23 class ServerGroupsController extends DashboardAppController {
24
25 26 27 28 29
30 public $components = array(
31 'RequestHandler'
32 );
33
34
35
36 37 38 39 40
41 public function admin_index() {
42 $serverGroups = $this->ServerGroup->find('all');
43 $this->set('serverGroups', $serverGroups);
44 }
45
46
47
48 49 50 51 52 53 54
55 public function admin_view($id = null) {
56 if (!$this->ServerGroup->exists($id)) {
57 throw new NotFoundException(__('Invalid server group'));
58 }
59 $options = array('conditions' => array('ServerGroup.' . $this->ServerGroup->primaryKey => $id));
60 $this->set('serverGroup', $this->ServerGroup->find('first', $options));
61 }
62
63
64
65 66 67 68 69
70 public function admin_add() {
71 if ($this->request->is('post')) {
72 $this->ServerGroup->create();
73 $this->request->data['ServerGroup']['name'] = strtolower($this->request->data['ServerGroup']['name']);
74 if ($this->ServerGroup->save($this->request->data)) {
75 $this->Session->setFlash(__('The server group has been saved'));
76 $this->redirect(array('action' => 'index'));
77 } else {
78 $this->Session->setFlash(__('The server group could not be saved. Please, try again.'));
79 }
80 }
81 }
82
83
84
85 86 87 88 89 90 91
92 public function admin_edit() {
93 $primaryKey = $this->request->data['pk'];
94 $name = $this->request->data['name'];
95 $value = $this->request->data['value'];
96
97 if ($name == 'name') {
98 $value = strtolower($value);
99 }
100
101 if ($this->request->is('ajax')) {
102 $this->ServerGroup->read(null, $primaryKey);
103 $this->ServerGroup->set($name, $value);
104 if ($this->ServerGroup->save()) {
105 $this->set('value', $value);
106 } else {
107 if (function_exists('http_response_code')) {
108 $this->response->statusCode(400);
109 } else {
110 header('HTTP 400 Bad Request', true, 400);
111 }
112 foreach ($this->ServerGroup->validationErrors[$name] as $validationError) {
113 echo $validationError;
114 }
115 }
116 }
117 }
118
119
120
121 122 123 124 125 126 127
128 public function admin_delete($id = null) {
129 $this->ServerGroup->id = $id;
130 if ($id == 1) {
131 $this->Session->setFlash(__('You cannot delete the default server group'));
132 $this->redirect(array('action' => 'index'));
133 }
134 if (!$this->ServerGroup->exists()) {
135 throw new NotFoundException(__('Invalid server group'));
136 }
137 $this->request->onlyAllow('post', 'delete');
138 if ($this->ServerGroup->delete()) {
139 $this->Session->setFlash(__('Server group deleted'));
140 $this->redirect(array('action' => 'index'));
141 }
142 $this->Session->setFlash(__('Server group was not deleted'));
143 $this->redirect(array('action' => 'index'));
144 }
145
146 }
147