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 / timeoffs.php

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

347 lines 8.3 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 Timeoffs_controller extends Backend_controller_crud
4 {
5 function __construct()
6 {
7 $this->conf = array(
8 'model' => 'Timeoff_model',
9 'path' => 'admin/timeoffs',
10 'entity' => 'timeoff',
11 );
12 parent::__construct( User_model::LEVEL_MANAGER );
13 }
14
15 function action()
16 {
17 $action = $this->input->post('nts-action');
18 $ids = $this->input->post('id');
19
20 if( $ids && $action )
21 {
22 $ok_count = 0;
23 $failed_count = 0;
24 $objects = array();
25
26 $this->{$this->model}
27 ->where_in( 'id', $ids )
28 ->get()->all;
29 $total_count = count( $ids );
30
31 $msg = array();
32 $msg[] = lang('timeoff');
33 switch( $action )
34 {
35 case 'active':
36 $msg[] = lang( 'common_approve' );
37 foreach( $this->{$this->model} as $o )
38 {
39 $o->status = TIMEOFF_MODEL::STATUS_ACTIVE;
40 if( $o->save() )
41 $ok_count++;
42 }
43 break;
44
45 case 'pending':
46 $msg[] = $this->{$this->model}->prop_text('status', FALSE, TIMEOFF_MODEL::STATUS_PENDING);
47 foreach( $this->{$this->model} as $o )
48 {
49 $o->status = TIMEOFF_MODEL::STATUS_PENDING;
50 if( $o->save() )
51 $ok_count++;
52 }
53 break;
54
55 case 'denied':
56 $msg[] = lang( 'common_reject' );
57 foreach( $this->{$this->model} as $o )
58 {
59 $o->status = TIMEOFF_MODEL::STATUS_DENIED;
60 if( $o->save() )
61 $ok_count++;
62 }
63 break;
64
65 case 'delete':
66 $msg[] = lang( 'common_delete' );
67 foreach( $this->{$this->model} as $o )
68 {
69 if( $o->delete() )
70 $ok_count++;
71 }
72 break;
73 }
74
75 $failed_count = $total_count - $ok_count;
76 if( $ok_count )
77 $msg[] = lang('common_ok') . ' [' . $ok_count . ']';
78 if( $failed_count > 0 )
79 $msg[] = lang('common_failed') . ' [' . $failed_count . ']';
80
81 $msg = join( ': ', $msg );
82 if( $failed_count > 0 )
83 $this->session->set_flashdata( 'error', $msg );
84 else
85 $this->session->set_flashdata( 'message', $msg );
86 }
87 elseif( ! $ids )
88 {
89 $msg = lang('common_no_selected');
90 $this->session->set_flashdata( 'error', $msg );
91 }
92
93 $redirect_to = method_exists($this, 'after_save') ? $this->after_save() : array($this->conf['path']);
94 $this->redirect( $redirect_to );
95 return;
96 }
97
98 function add()
99 {
100 $this->hc_time->setNow();
101 $this->{$this->model}->date = $this->hc_time->formatDate_Db();
102
103 $args = func_get_args();
104 call_user_func_array( array($this, 'parent::add'), $args );
105 }
106
107 function edit( $id, $view = 'edit' )
108 {
109 $this->data['fixed'] = array('user');
110 return parent::edit( $id, $view );
111 }
112
113 function save()
114 {
115 $args = func_get_args();
116 $id = count($args) ? $args[0] : 0;
117
118 if( $id )
119 {
120 call_user_func_array( array($this, 'parent::save'), $args );
121 return;
122 }
123
124 /* new one */
125 $post = call_user_func_array( array($this, 'save_prepare'), $args );
126 $relations = $this->save_prepare_relations();
127
128 $also_get = array(
129 'repeat',
130 'date_start',
131 );
132 reset( $also_get );
133 foreach( $also_get as $ag )
134 {
135 $post[ $ag ] = $this->input->post( $ag );
136 }
137
138 /* check repeat */
139 $repeat = $this->input->post( 'repeat' );
140
141 /* add validation */
142 switch( $repeat )
143 {
144 case 'multiple':
145 $this->{$this->model}->date_start = $post['date_start'];
146 $this->{$this->model}->date = $this->{$this->model}->date_start;
147 $this->{$this->model}->start = 0;
148 $this->{$this->model}->end = 24*60*60;
149 $this->{$this->model}->validation['date_start'] = $this->{$this->model}->validation['date'];
150 unset( $this->{$this->model}->validation['date'] );
151 unset( $this->{$this->model}->validation['start'] );
152 break;
153
154 case 'single':
155 default:
156 $this->{$this->model}->date_end = $this->{$this->model}->date;
157 $_POST['date_end'] = $this->{$this->model}->date_end;
158 break;
159 }
160
161 $this->{$this->model}->validate($relations);
162 if( ! $this->{$this->model}->valid )
163 {
164 $this->hc_form->set_errors( $this->{$this->model}->error->all );
165 $this->hc_form->set_defaults( $post );
166
167 if( $this->{$this->model}->id )
168 $this->edit( $this->{$this->model}->id );
169 else
170 {
171 array_shift( $args );
172 call_user_func_array( array($this, 'add'), $args );
173 }
174 return;
175 }
176
177 if( $this->{$this->model}->save($relations) )
178 {
179 $notes = $this->input->post( 'notes' );
180 if( strlen($notes) > 0 )
181 {
182 $note = new Note_Model;
183 $note->content = $notes;
184 $note->save(
185 array(
186 'author' => $this->auth->user(),
187 'timeoff' => $this->{$this->model}
188 )
189 );
190 }
191 }
192 else
193 {
194 $this->hc_form->set_errors( $this->{$this->model}->error->all );
195 $this->hc_form->set_defaults( $post );
196
197 if( $this->{$this->model}->id )
198 $this->edit( $this->{$this->model}->id );
199 else
200 {
201 array_shift( $args );
202 call_user_func_array( array($this, 'add'), $args );
203 }
204 return;
205 }
206
207 // redirect to list
208 $msg = lang('timeoff') . ': ' . lang('common_add');
209 $this->session->set_flashdata( 'message', $msg . ': ' . lang('common_ok') );
210
211 $redirect_to = method_exists($this, 'after_save') ? $this->after_save() : array($this->conf['path']);
212 $this->redirect( $redirect_to );
213 return;
214 }
215
216 function index( $status = 0 )
217 {
218 $model = $this->{$this->model};
219 if( ! $status )
220 $status = TIMEOFF_MODEL::STATUS_PENDING;
221
222 /* all statuses counts */
223 $statuses = array();
224 $res = $this->{$this->model}
225 ->select('status')
226 ->select_func('COUNT', '@id', 'count')
227 ->group_by('status')
228 ->order_by('status', 'ASC')
229 ->get();
230
231 foreach( $res as $r )
232 {
233 if( $r->count > 0 )
234 $statuses[ $r->status ] = $r->count;
235 }
236
237 if( isset($statuses[TIMEOFF_MODEL::STATUS_ACTIVE]) && ($statuses[TIMEOFF_MODEL::STATUS_ACTIVE] > 0) )
238 {
239 $this->hc_time->setNow();
240 /* if this week then not yet expired */
241 $this->hc_time->setStartWeek();
242 $check_with = $this->hc_time->formatDate_Db();
243
244 // count archive
245 $archived_count = $this->{$this->model}
246 ->where('status', TIMEOFF_MODEL::STATUS_ACTIVE)
247 ->where('date_end <', $check_with)
248 ->count();
249
250 if( $archived_count > 0 )
251 {
252 $statuses[TIMEOFF_MODEL::STATUS_ARCHIVE] = $archived_count;
253 $statuses[TIMEOFF_MODEL::STATUS_ACTIVE] = $statuses[TIMEOFF_MODEL::STATUS_ACTIVE] - $archived_count;
254 if( $statuses[TIMEOFF_MODEL::STATUS_ACTIVE] <= 0 )
255 unset( $statuses[TIMEOFF_MODEL::STATUS_ACTIVE] );
256 }
257 }
258
259 /* no timeoffs so far */
260 if( ! $statuses )
261 {
262 ci_redirect( $this->conf['path'] . '/add' );
263 return;
264 }
265
266 $this->data['statuses'] = $statuses;
267
268 /* load */
269 if( ! isset($statuses[$status]) )
270 {
271 $all_statuses = array_keys( $statuses );
272 $status = $all_statuses[0];
273 }
274
275 switch( $status )
276 {
277 case TIMEOFF_MODEL::STATUS_ARCHIVE:
278 $this->{$this->model}->where('status', TIMEOFF_MODEL::STATUS_ACTIVE);
279 $this->{$this->model}->where('date_end <', $check_with);
280 break;
281 case TIMEOFF_MODEL::STATUS_ACTIVE:
282 $this->{$this->model}->where('status', $status);
283 $this->{$this->model}->where('date_end >=', $check_with);
284 break;
285 default:
286 $this->{$this->model}->where('status', $status);
287 break;
288 }
289 $this->data['entries'] = $this->{$this->model}->get()->all;
290
291 $this->data['status'] = $status;
292 $this->set_include( 'index' );
293 $this->data['index_child'] = $this->get_view('index_child');
294
295 $this->load->view( $this->template, $this->data);
296 }
297
298 function status( $id, $status )
299 {
300 if( ! $this->{$this->model}->id )
301 $this->{$this->model}->get_by_id($id);
302 $this->{$this->model}->status = $status;
303
304 if( $this->{$this->model}->save() )
305 {
306 $msg = lang('timeoff') . ': ' . $this->{$this->model}->prop_text('status');
307 $this->session->set_flashdata( 'message', $msg );
308 }
309 else
310 {
311 $this->session->set_flashdata( 'error', $this->{$this->model}->error->string );
312 }
313
314 $redirect_to = method_exists($this, 'after_save') ? $this->after_save() : array($this->conf['path']);
315 $this->redirect( $redirect_to );
316 return;
317 }
318
319 protected function after_save()
320 {
321 $this->load->library('user_agent');
322 if( $schedule_view = $this->session->userdata('schedule_view') )
323 {
324 $return = array(
325 'admin/schedules/index'
326 );
327 foreach( $schedule_view as $k => $v )
328 {
329 $return[] = $k;
330 $return[] = $v;
331 }
332 }
333 elseif( $this->agent->is_referral() )
334 {
335 $return = $this->agent->referrer();
336 }
337 else
338 {
339 $return = array( $this->conf['path'] );
340 }
341 return $return;
342 }
343
344 }
345
346 /* End of file customers.php */
347 /* Location: ./application/controllers/admin/categories.php */