1: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2:
3: class Backend extends CI_Controller {
4: public function __construct() {
5: parent::__construct();
6: $this->load->library('session');
7: }
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20: public function index($appointment_hash = '') {
21: $this->session->set_userdata('dest_url', $this->config->item('base_url') . 'backend');
22: if (!$this->hasPrivileges(PRIV_APPOINTMENTS)) return;
23:
24: $this->load->model('appointments_model');
25: $this->load->model('providers_model');
26: $this->load->model('services_model');
27: $this->load->model('customers_model');
28: $this->load->model('settings_model');
29: $this->load->model('roles_model');
30: $this->load->model('user_model');
31: $this->load->model('secretaries_model');
32:
33: $view['base_url'] = $this->config->item('base_url');
34: $view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id'));
35: $view['active_menu'] = PRIV_APPOINTMENTS;
36: $view['book_advance_timeout'] = $this->settings_model->get_setting('book_advance_timeout');
37: $view['company_name'] = $this->settings_model->get_setting('company_name');
38: $view['available_providers'] = $this->providers_model->get_available_providers();
39: $view['available_services'] = $this->services_model->get_available_services();
40: $view['customers'] = $this->customers_model->get_batch();
41: $this->setUserData($view);
42:
43: if ($this->session->userdata('role_slug') == DB_SLUG_SECRETARY) {
44: $secretary = $this->secretaries_model->get_row($this->session->userdata('user_id'));
45: $view['secretary_providers'] = $secretary['providers'];
46: } else {
47: $view['secretary_providers'] = array();
48: }
49:
50: if ($appointment_hash != '') {
51: $results = $this->appointments_model->get_batch(array('hash' => $appointment_hash));
52: $appointment = $results[0];
53: $appointment['customer'] = $this->customers_model->get_row($appointment['id_users_customer']);
54: $view['edit_appointment'] = $appointment;
55: } else {
56: $view['edit_appointment'] = NULL;
57: }
58:
59: $this->load->view('backend/header', $view);
60: $this->load->view('backend/calendar', $view);
61: $this->load->view('backend/footer', $view);
62: }
63:
64: 65: 66: 67: 68:
69: public function customers() {
70: $this->session->set_userdata('dest_url', $this->config->item('base_url') . 'backend/customers');
71: if (!$this->hasPrivileges(PRIV_CUSTOMERS)) return;
72:
73: $this->load->model('providers_model');
74: $this->load->model('customers_model');
75: $this->load->model('services_model');
76: $this->load->model('settings_model');
77: $this->load->model('user_model');
78:
79: $view['base_url'] = $this->config->item('base_url');
80: $view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id'));
81: $view['active_menu'] = PRIV_CUSTOMERS;
82: $view['company_name'] = $this->settings_model->get_setting('company_name');
83: $view['customers'] = $this->customers_model->get_batch();
84: $view['available_providers'] = $this->providers_model->get_available_providers();
85: $view['available_services'] = $this->services_model->get_available_services();
86: $this->setUserData($view);
87:
88: $this->load->view('backend/header', $view);
89: $this->load->view('backend/customers', $view);
90: $this->load->view('backend/footer', $view);
91: }
92:
93: 94: 95: 96: 97: 98: 99: 100: 101:
102: public function services() {
103: $this->session->set_userdata('dest_url', $this->config->item('base_url') . 'backend/services');
104: if (!$this->hasPrivileges(PRIV_SERVICES)) return;
105:
106: $this->load->model('customers_model');
107: $this->load->model('services_model');
108: $this->load->model('settings_model');
109: $this->load->model('user_model');
110:
111: $view['base_url'] = $this->config->item('base_url');
112: $view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id'));
113: $view['active_menu'] = PRIV_SERVICES;
114: $view['company_name'] = $this->settings_model->get_setting('company_name');
115: $view['services'] = $this->services_model->get_batch();
116: $view['categories'] = $this->services_model->get_all_categories();
117: $this->setUserData($view);
118:
119: $this->load->view('backend/header', $view);
120: $this->load->view('backend/services', $view);
121: $this->load->view('backend/footer', $view);
122: }
123:
124: 125: 126: 127: 128: 129: 130:
131: public function users() {
132: $this->session->set_userdata('dest_url', $this->config->item('base_url') . 'backend/users');
133: if (!$this->hasPrivileges(PRIV_USERS)) return;
134:
135: $this->load->model('providers_model');
136: $this->load->model('secretaries_model');
137: $this->load->model('admins_model');
138: $this->load->model('services_model');
139: $this->load->model('settings_model');
140: $this->load->model('user_model');
141:
142: $view['base_url'] = $this->config->item('base_url');
143: $view['user_display_name'] = $this->user_model->get_user_display_name($this->session->userdata('user_id'));
144: $view['active_menu'] = PRIV_USERS;
145: $view['company_name'] = $this->settings_model->get_setting('company_name');
146: $view['admins'] = $this->admins_model->get_batch();
147: $view['providers'] = $this->providers_model->get_batch();
148: $view['secretaries'] = $this->secretaries_model->get_batch();
149: $view['services'] = $this->services_model->get_batch();
150: $view['working_plan'] = $this->settings_model->get_setting('company_working_plan');
151: $this->setUserData($view);
152:
153: $this->load->view('backend/header', $view);
154: $this->load->view('backend/users', $view);
155: $this->load->view('backend/footer', $view);
156: }
157:
158: 159: 160: 161: 162: 163: 164:
165: public function settings() {
166: $this->session->set_userdata('dest_url', $this->config->item('base_url') . 'backend/settings');
167: if (!$this->hasPrivileges(PRIV_SYSTEM_SETTINGS, FALSE)
168: && !$this->hasPrivileges(PRIV_USER_SETTINGS)) return;
169:
170: $this->load->model('settings_model');
171: $this->load->model('user_model');
172:
173: $this->load->library('session');
174: $user_id = $this->session->userdata('user_id');
175:
176: $view['base_url'] = $this->config->item('base_url');
177: $view['user_display_name'] = $this->user_model->get_user_display_name($user_id);
178: $view['active_menu'] = PRIV_SYSTEM_SETTINGS;
179: $view['company_name'] = $this->settings_model->get_setting('company_name');
180: $view['role_slug'] = $this->session->userdata('role_slug');
181: $view['system_settings'] = $this->settings_model->get_settings();
182: $view['user_settings'] = $this->user_model->get_settings($user_id);
183: $this->setUserData($view);
184:
185: $this->load->view('backend/header', $view);
186: $this->load->view('backend/settings', $view);
187: $this->load->view('backend/footer', $view);
188: }
189:
190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208:
209: private function hasPrivileges($page, $redirect = TRUE) {
210:
211: $user_id = $this->session->userdata('user_id');
212: if ($user_id == FALSE) {
213: if ($redirect) {
214: header('Location: ' . $this->config->item('base_url') . 'user/login');
215: }
216: return FALSE;
217: }
218:
219:
220: $role_slug = $this->session->userdata('role_slug');
221: $role_priv = $this->db->get_where('ea_roles', array('slug' => $role_slug))->row_array();
222: if ($role_priv[$page] < PRIV_VIEW) {
223: if ($redirect) {
224: header('Location: ' . $this->config->item('base_url') . 'user/no_privileges');
225: }
226: return FALSE;
227: }
228:
229: return TRUE;
230: }
231:
232: 233: 234: 235: 236:
237: public function setUserData(&$view) {
238: $this->load->model('roles_model');
239:
240:
241: $view['user_id'] = $this->session->userdata('user_id');
242: $view['user_email'] = $this->session->userdata('user_email');
243: $view['role_slug'] = $this->session->userdata('role_slug');
244: $view['privileges'] = $this->roles_model->get_privileges($this->session->userdata('role_slug'));
245: }
246: }
247:
248:
249: