PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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 / sh4 / reminders / html / admin / review.php

review.php in ShiftController Employee Shift Scheduling 4.9.26, at sh4/reminders/html/admin/review.php

355 lines 9.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 class SH4_Reminders_Html_Admin_Review
3 {
4 public function __construct(
5 HC3_Ui $ui,
6 HC3_Time $t,
7 HC3_Uri $uri,
8 HC3_Post $post,
9 HC3_Enqueuer $enqueuer,
10
11 SH4_Reminders_Command $remindersCommand,
12 SH4_Reminders_CommandLog $remindersCommandLog,
13 SH4_Reminders_Query $remindersQuery,
14 SH4_Reminders_QueryLog $remindersQueryLog,
15
16 SH4_Reminders_CommandSms $remindersCommandSms,
17 SH4_Reminders_Sms $sms,
18
19 HC3_Users_Presenter $usersPresenter,
20 SH4_Employees_Presenter $employeesPresenter,
21
22 HC3_Request $request,
23 HC3_Ui_Layout1 $layout,
24 HC3_Hooks $hooks
25 )
26 {
27 $this->ui = $ui;
28 $this->t = $t;
29 $this->post = $hooks->wrap( $post );
30 $this->sms = $hooks->wrap( $sms );
31
32 $this->remindersCommand = $hooks->wrap( $remindersCommand );
33 $this->remindersCommandSms = $hooks->wrap( $remindersCommandSms );
34 $this->remindersCommandLog = $hooks->wrap( $remindersCommandLog );
35 $this->remindersQuery = $hooks->wrap( $remindersQuery );
36 $this->remindersQueryLog = $hooks->wrap( $remindersQueryLog );
37
38 $this->uri = $uri;
39 $this->layout = $layout;
40 $this->request = $request;
41 $this->self = $hooks->wrap( $this );
42
43 $this->employeesPresenter = $hooks->wrap( $employeesPresenter );
44 $this->usersPresenter = $hooks->wrap( $usersPresenter );
45
46 if( ! $request->isPrintView() ){
47 $enqueuer
48 ->addScript('datepicker', 'hc3/ui/element/input/datepicker/assets/input.js')
49 ->addStyle('datepicker', 'hc3/ui/element/input/datepicker/assets/input.css')
50 ;
51 }
52 }
53
54 public function breadcrumbs()
55 {
56 $ret = array();
57 $ret['admin'] = array( 'admin', '__Administration__' );
58 $ret['admin/reminders'] = array( 'admin/reminders', '__Reminders__' );
59 return $ret;
60 }
61
62 public function header()
63 {
64 $ret = '__Review Reminders__';
65 return $ret;
66 }
67
68 public function post()
69 {
70 $type = $this->post->get('type');
71 $date = $this->post->get('date');
72
73 $slug = $this->request->getSlug();
74 $params = array(
75 'date' => $date,
76 'type' => $type
77 );
78
79 $to = $this->uri->makeUrl( array($slug, $params) );
80
81 $ret = array( $to, NULL );
82 return $ret;
83 }
84
85 public function postSend()
86 {
87 $params = $this->request->getParams();
88 $date = isset($params['date']) ? $params['date'] : $this->t->setNow()->formatDateDb();
89 $type = isset($params['type']) ? $params['type'] : SH4_Reminders_Model::RANGE_DAILY;
90
91 // reminders
92 $reminders = $this->remindersQuery->find( $type, $date );
93
94 if( in_array($type, [SH4_Reminders_Model::RANGE_DAILY_SMS]) ){
95 $command = $this->remindersCommandSms;
96 }
97 else {
98 $command = $this->remindersCommand;
99 }
100
101 foreach( $reminders as $reminder ){
102 if( $reminder->log ){
103 $this->remindersCommandLog->delete( $reminder->log );
104 }
105
106 $command->send( $reminder );
107 }
108
109 $to = 'admin/reminders/review';
110 $params = array(
111 'date' => $date,
112 'type' => $type
113 );
114 $to = $this->uri->makeUrl( array($to, $params) );
115
116 $msg = '__Reminders Sent__';
117 $ret = array( $to, $msg );
118 return $ret;
119 }
120
121 public function postClear()
122 {
123 $params = $this->request->getParams();
124 $date = isset($params['date']) ? $params['date'] : $this->t->setNow()->formatDateDb();
125 $type = isset($params['type']) ? $params['type'] : SH4_Reminders_Model::RANGE_DAILY;
126
127 // reminders
128 $reminders = $this->remindersQuery->find( $type, $date );
129
130 foreach( $reminders as $reminder ){
131 if( $reminder->log ){
132 $this->remindersCommandLog->delete( $reminder->log );
133 }
134 }
135
136 $to = 'admin/reminders/review';
137 $params = array(
138 'date' => $date,
139 'type' => $type
140 );
141 $to = $this->uri->makeUrl( array($to, $params) );
142
143 $msg = '__Logs Cleared__';
144 $ret = array( $to, $msg );
145 return $ret;
146 }
147
148 public function render()
149 {
150 $params = $this->request->getParams();
151 $date = isset($params['date']) ? $params['date'] : $this->t->setNow()->formatDateDb();
152 $type = isset($params['type']) ? $params['type'] : SH4_Reminders_Model::RANGE_DAILY;
153
154 // post to
155 $slug = $this->request->getSlug();
156 $to = $this->uri->makeUrl( $slug );
157
158 $params = array(
159 'date' => $date,
160 'type' => $type
161 );
162 $toSend = $this->uri->makeUrl( array($slug . '/send', $params) );
163 $toClear = $this->uri->makeUrl( array($slug . '/clear', $params) );
164
165 // reminders
166 $reminders = $this->remindersQuery->find( $type, $date );
167
168 // reminder logs
169 $notSent = array();
170 $logs = array();
171 foreach( $reminders as $reminder ){
172 if( $reminder->log ){
173 $logs[ $reminder->log->id ] = $reminder->log;
174 }
175 else {
176 $notSent[] = 1;
177 }
178 }
179
180 ob_start();
181 ?>
182
183 <?php
184 // _print_r( $logs );
185 ?>
186
187 <div class="hc-mb3">
188 <form action="<?php echo $to; ?>" method="post" accept-charset="utf-8">
189 <fieldset class="hc-p1 hc-border">
190 <legend>__Filter__</legend>
191 <div class="hc-clearfix">
192 <div class="hc-col hc-col-3">
193 <div class="hc-p2">
194 <?php echo $this->ui->makeInputDatepicker( 'date', NULL, $date ); ?>
195 </div>
196 </div>
197 <div class="hc-col hc-col-7">
198 <div class="hc-p2">
199 <?php
200 $types = array(
201 SH4_Reminders_Model::RANGE_DAILY => '__Daily__',
202 SH4_Reminders_Model::RANGE_WEEKLY => '__Weekly__',
203 SH4_Reminders_Model::RANGE_MONTHLY => '__Monthly__',
204 );
205
206 if( $this->sms->isEnabled() ){
207 $types[ SH4_Reminders_Model::RANGE_DAILY_SMS ] = '__Daily__' . ' ' . '__SMS__';
208 }
209 ?>
210
211 <?php foreach( $types as $k => $label ) : ?>
212 <label>
213 <input type="radio" name="hc-type" value="<?php echo $k; ?>"<?php if( $k == $type ) : ?> checked<?php endif; ?>/>
214 <?php echo $label; ?>
215 </label>
216 <?php endforeach; ?>
217 </div>
218 </div>
219 <div class="hc-col hc-col-2">
220 <button type="submit" class="button button-secondary hc-block">__Apply Filter__</button>
221 </div>
222 </div>
223 </fieldset>
224 </form>
225 </div>
226
227 <?php if( $reminders ) : ?>
228
229 <table class="wp-list-table widefat fixed striped">
230
231 <thead>
232 <tr>
233 <td class="hc-col-4">
234 __Employee__
235 </td>
236 <td class="hc-col-4">
237 __User__
238 </td>
239 <td class="hc-col-1">
240 __Shifts__
241 </td>
242 <td class="hc-col-3">
243 __Sent__
244 </td>
245 </tr>
246 </thead>
247
248 <tbody>
249 <?php foreach( $reminders as $r ) : ?>
250 <?php
251 $toParams = array();
252 $toParams[ 'employee' ] = array( $r->employee->getId() );
253 $toParams[ 'type' ] = 'list';
254 $toParams[ 'groupby' ] = 'none';
255
256 if( SH4_Reminders_Model::RANGE_DAILY == $r->range ){
257 $toParams[ 'start' ] = $r->date;
258 $toParams[ 'end' ] = $r->date;
259 }
260
261 if( SH4_Reminders_Model::RANGE_DAILY_SMS == $r->range ){
262 $toParams[ 'start' ] = $r->date;
263 $toParams[ 'end' ] = $r->date;
264 }
265
266 if( SH4_Reminders_Model::RANGE_WEEKLY == $r->range ){
267 $start = $this->t->setDateDb( $r->date )->setStartWeek()->formatDateDb();
268 $end = $this->t->setDateDb( $start )->modify('+1 week')->modify('-1 day')->formatDateDb();
269 $toParams[ 'start' ] = $start;
270 $toParams[ 'end' ] = $end;
271 }
272
273 if( SH4_Reminders_Model::RANGE_MONTHLY == $r->range ){
274 $start = $this->t->setDateDb( $r->date )->setStartMonth()->formatDateDb();
275 $end = $this->t->setDateDb( $start )->modify('+1 month')->modify('-1 day')->formatDateDb();
276 $toParams[ 'start' ] = $start;
277 $toParams[ 'end' ] = $end;
278 }
279
280 $to = 'schedule';
281 $detailsLink = $this->uri->makeUrl( array($to, $toParams) );
282 ?>
283
284 <tr>
285 <td>
286 <?php echo $this->employeesPresenter->presentTitle( $r->employee ); ?>
287 </td>
288 <td>
289 <?php echo $this->usersPresenter->presentTitle( $r->user ); ?>
290 <?php if( in_array($r->range, [SH4_Reminders_Model::RANGE_DAILY_SMS]) ) : ?>
291 <a href="<?php echo esc_attr($this->uri->makeUrl('admin/reminders/sms')); ?>" title="__Phone Number__" class="hc-block">
292 <?php $phone = $this->sms->getUserPhone($r->user->getId()); ?>
293 <?php if( $phone ) : ?>
294 <?php echo esc_html( $phone ); ?>
295 <?php else : ?>
296 __No Phone Number__
297 <?php endif; ?>
298 </div>
299 <?php else : ?>
300 <div title="__Email__"><?php echo esc_html($r->user->getEmail()); ?></div>
301 <?php endif; ?>
302 </td>
303 <td>
304 <a href="<?php echo $detailsLink; ?>" class="hc-block" target="_blank"><?php echo count( $r->shifts ); ?></a>
305 </td>
306 <td>
307 <?php if( $r->log ) : ?>
308 <?php echo $this->t->setDateTimeDb( $r->log->sent_on )->formatDateWithWeekday(); ?> <?php echo $this->t->formatTime(); ?>
309 <?php else : ?>
310 <mark>__Not Sent__</mark>
311 <?php endif; ?>
312 </td>
313 </tr>
314 <?php endforeach; ?>
315 </tbody>
316
317 </table>
318
319 <?php if( $notSent ) : ?>
320 <form action="<?php echo $toSend; ?>" method="post" accept-charset="utf-8">
321 <p>
322 <button type="submit" class="button button-primary hc-xs-block">__Send Reminder Messages__</button>
323 </p>
324 </form>
325 <?php endif; ?>
326
327 <?php if( $logs ) : ?>
328 <form action="<?php echo $toClear; ?>" method="post" accept-charset="utf-8">
329 <p>
330 <button type="submit" class="button button-secondary hc-xs-block">&times; __Clear Logs__</button>
331 </p>
332 </form>
333 <?php endif; ?>
334
335 <?php else: ?>
336
337 <p>
338 __No Reminders__
339 </p>
340
341 <?php endif; ?>
342
343 <?php
344 $ret = trim( ob_get_clean() );
345
346 $this->layout
347 ->setContent( $ret )
348 ->setHeader( $this->self->header() )
349 ->setBreadcrumb( $this->self->breadcrumbs() )
350 ;
351
352 $ret = $this->layout->render();
353 return $ret;
354 }
355 }