PluginProbe
ShiftController Employee Shift Scheduling / 2.2.5
ShiftController Employee Shift Scheduling v2.2.5
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / application / controllers / admin / users.php

users.php in ShiftController Employee Shift Scheduling 2.2.5, at application/controllers/admin/users.php

190 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2
3 class Users_controller extends Backend_controller_crud
4 {
5 function __construct()
6 {
7 $this->conf = array(
8 'model' => 'User_model',
9 'path' => 'admin/users',
10 'entity' => 'user',
11 'export' => 'users',
12 );
13 parent::__construct( User_model::LEVEL_ADMIN );
14 }
15
16 function index( $status = 1 )
17 {
18 /* all statuses counts */
19 $statuses = array();
20 $res = $this->{$this->model}
21 ->select('active')
22 ->select_func('COUNT', '@id', 'count')
23 ->group_by('active')
24 ->order_by('active', 'DESC')
25 ->get();
26
27 foreach( $res as $r )
28 {
29 if( $r->count > 0 )
30 $statuses[ $r->active ] = $r->count;
31 }
32
33 /* no users so far */
34 if( ! $statuses )
35 {
36 ci_redirect( $this->conf['path'] . '/add' );
37 return;
38 }
39 $this->data['statuses'] = $statuses;
40
41 /* load */
42 if( ! isset($statuses[$status]) )
43 {
44 $all_statuses = array_keys( $statuses );
45 $status = $all_statuses[0];
46 }
47
48 $this->{$this->model}->where('active', $status);
49 $this->data['entries'] = $this->{$this->model}->get();
50 $this->data['status'] = $status;
51 $this->set_include( 'index' );
52 $this->load->view( $this->template, $this->data);
53 }
54
55 function disable( $id )
56 {
57 if( ! $this->{$this->model}->id )
58 $this->{$this->model}->get_by_id($id);
59 if( $this->{$this->model}->active )
60 $this->{$this->model}->active = 0;
61 else
62 $this->{$this->model}->active = 1;
63
64 if( $this->{$this->model}->save() )
65 {
66 $msg = $this->{$this->model}->active ? lang('user_restore') : lang('user_archive');
67 $this->session->set_flashdata( 'message', $msg . ': ' . lang('common_ok') );
68 }
69 else
70 {
71 $this->session->set_flashdata( 'error', $this->{$this->model}->error->string );
72 }
73 $redirect_to = array( $this->conf['path'] );
74 ci_redirect( $redirect_to );
75 return;
76 }
77
78 function shifts( $id )
79 {
80 if( ! $this->_load($id) )
81 return;
82 $this->data['shifts'] = $this->{$this->model}->shift->get()->all;
83
84 $this->data['dates'] = array();
85 reset( $this->data['shifts'] );
86 foreach( $this->data['shifts'] as $sh )
87 {
88 $this->data['dates'][ $sh->date ] = $sh->date;
89 }
90 parent::edit( $id, 'shifts' );
91 }
92
93 function edit( $id )
94 {
95 $fields = array_values( array_filter(
96 $this->{$this->model}->get_form_fields(),
97 create_function(
98 '$a',
99 'return (isset($a["type"]) && ("password" == $a["type"])) ? FALSE : TRUE;'
100 )
101 ));
102
103 /* can't change own level */
104 if( $id == $this->auth->check() )
105 {
106 for( $ii = 0; $ii < count($fields); $ii++ )
107 {
108 if( $fields[$ii]['name'] == 'level' )
109 {
110 $fields[$ii]['extra']['disabled'] = 'disabled';
111 }
112 }
113 }
114
115 /* can't edit remotely integrated accounts */
116 $remote_integration = $this->remote_integration();
117 if( $remote_integration )
118 {
119 for( $ii = 0; $ii < count($fields); $ii++ )
120 {
121 if( ! in_array($fields[$ii]['name'], array('level')) )
122 {
123 $fields[$ii]['extra']['disabled'] = 'disabled';
124 }
125 }
126 }
127
128 $this->data['fields'] = $fields;
129 return parent::edit( $id );
130 }
131
132 function password( $id )
133 {
134 $fields = array_values( array_filter(
135 $this->{$this->model}->get_form_fields(),
136 create_function(
137 '$a',
138 'return (isset($a["type"]) && ("password" == $a["type"])) ? TRUE : FALSE;'
139 )
140 ));
141 $this->data['fields'] = $fields;
142 if( ! $this->hc_form->is_set_default('password') )
143 $this->hc_form->set_default( 'password', '' );
144 return parent::edit( $id, 'password' );
145 }
146
147 function savepassword( $id )
148 {
149 if( ! $this->{$this->model}->id )
150 {
151 $this->{$this->model}->get_by_id($id);
152 }
153 if( ! $this->{$this->model}->exists() )
154 {
155 $this->session->set_flashdata( 'message', sprintf(lang('common_not_found'), get_class($this->{$this->model}), $id) );
156 ci_redirect( $this->conf['path'] );
157 return;
158 }
159
160 $post = array();
161 foreach( array('password', 'confirm_password') as $fname )
162 {
163 $supplied = $this->input->post($fname);
164 if( $supplied !== FALSE )
165 {
166 $post[$fname] = $supplied;
167 $this->{$this->model}->{$fname} = $supplied;
168 }
169 }
170
171 if( $this->{$this->model}->save() )
172 {
173 // redirect to list
174 $msg = lang('common_change_password');
175 $this->session->set_flashdata( 'message', $msg . ': ' . lang('common_ok') );
176 $redirect_to = array( $this->conf['path'] );
177 ci_redirect( $redirect_to );
178 return;
179 }
180 else
181 {
182 $this->hc_form->set_errors( $this->{$this->model}->error->all );
183 $this->hc_form->set_defaults( $post );
184 return $this->password( $id );
185 }
186 }
187 }
188
189 /* End of file customers.php */
190 /* Location: ./application/controllers/admin/categories.php */