PluginProbe
ShiftController Employee Shift Scheduling / trunk
ShiftController Employee Shift Scheduling vtrunk
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 / api / html / view.html.php

view.html.php in ShiftController Employee Shift Scheduling trunk, at sh4/api/html/view.html.php

778 lines 15.1 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
3 $app = 'sh4-rest';
4
5 if( isset($_POST[$app . '_submit']) ){
6 if( isset($_POST[$app]) ){
7 foreach( (array)$_POST[$app] as $key => $value ){
8 $option_name = $app . '_' . $key;
9 $value = sanitize_text_field( $value );
10 update_option( $option_name, $value );
11 }
12 }
13
14 if( ! isset($_POST[$app]['enabled']) ){
15 $k = $app . '_enabled';
16 $value = 0;
17 update_option( $k, $value );
18 }
19 }
20
21 // $this->initOption();
22
23 $current = array();
24 $current['enabled'] = get_option( $app . '_enabled', 1 );
25 $current['auth_code'] = get_option( $app . '_auth_code', '' );
26
27 $startUrl = '/shiftcontroller/v4/';
28
29 // spaghetti starts here
30 ?>
31
32 <form method="post" action="">
33 <?php settings_fields( $app ); ?>
34 <?php //do_settings_sections( $this->app ); ?>
35
36 <label>
37 <?php $checked = $current['enabled'] ? ' checked' : ''; ?>
38 <input type="checkbox" name="<?php echo $app; ?>[enabled]" value="1" <?php echo $checked; ?>/>
39 Enable
40 </label>
41 </br/>
42
43 <label>
44 AuthCode<br>
45 <input type="text" name="<?php echo $app; ?>[auth_code]" value="<?php echo esc_attr( $current['auth_code'] ); ?>" />
46 </label>
47 </br/>
48
49 <p>
50 <input name="<?php echo $app; ?>_submit" type="submit" class="button-primary" value="Save" />
51 </p>
52 </form>
53
54 <?php if( ! $current['enabled'] ) return; ?>
55
56
57 <style>
58 .sh4-code {
59 display: block; padding: 1em; border: #999 1px solid; margin-bottom: 1em;
60 }
61 </style>
62
63 <h3 class="hc-underline">Get Shifts</h3>
64 <?php
65 $url = $startUrl . 'shifts';
66 $fullUrl = get_rest_url( NULL, $url );
67 ?>
68
69 <p>
70 <strong>
71 GET <?php echo $url; ?>
72 </strong>
73 </p>
74
75 <p>
76 <strong>__Headers__</strong>
77 </p>
78
79 <p>
80 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
81 </p>
82
83 <p>
84 <strong>__Arguments__</strong>
85 </p>
86
87 <p>
88 <strong>calendar_id</strong> (__Calendar Id__)<br>
89 <strong>employee_id</strong> (__Employee Id__)<br>
90 <strong>from</strong> (__From Date__, YYYYMMDD / __From Date Time__, YYYYMMDDHHMM)<br>
91 <strong>to</strong> (__To Date__, YYYYMMDD / __To Date Time__, YYYYMMDDHHMM)<br>
92 <strong>status_id</strong> (publish, draft)<br>
93 </p>
94
95 <?php
96 $cfields = array();
97 ?>
98 <?php if( class_exists('SH4_CFields_Model') or class_exists('SH4_CFields2_Model') ) : ?>
99 <?php
100 $cfields = array();
101 $f = null;
102 if (class_exists('ShiftController4Legacy_Pro')) {
103 $f = ShiftController4Legacy_Pro::$instance->root();
104 } elseif (class_exists('ShiftController4')) {
105 $f = ShiftController4::$instance->root();
106 }
107 if (null !== $f) {
108 $cfieldsQuery = $f->make('SH4_CFields_Query');
109 $cfields = $cfieldsQuery->read();
110 }
111 ?>
112 <?php if( $cfields ) : ?>
113 <p>
114 <strong>__Optional Arguments__</strong>
115 </p>
116
117 <p>
118 <?php foreach( $cfields as $cfield ) : ?>
119 <em><?php echo $cfield->getName(); ?></em> (<?php echo $cfield->getLabel(); ?>)<br>
120 <?php endforeach; ?>
121 </p>
122 <?php endif; ?>
123 <?php endif; ?>
124
125 <?php
126 $today = date( 'Ymd' );
127 ?>
128
129 <p>
130 <strong>__Examples__</strong>
131 </p>
132
133 <pre class="sh4-code">
134 GET <?php echo $fullUrl; ?>
135 </pre>
136
137 <pre class="sh4-code">
138 GET <?php echo $fullUrl; ?>?calendar_id=11&from=<?php echo $today; ?>
139 </pre>
140
141 <pre class="sh4-code">
142 GET <?php echo $fullUrl; ?>?from=<?php echo $today; ?>0900&to=<?php echo $today; ?>1430&status_id=draft
143 </pre>
144
145 <h3 class="hc-underline">__Get Shift__</h3>
146 <?php
147 $url = $startUrl . 'shifts/&lt;id&gt;';
148 $fullUrl = get_rest_url( NULL, $url );
149
150 $url2 = $startUrl . 'shifts';
151 $fullUrl2 = get_rest_url( NULL, $url2 );
152 ?>
153
154 <p>
155 <strong>
156 GET <?php echo $url; ?>
157 </strong>
158 </p>
159
160 <p>
161 <strong>__Headers__</strong>
162 </p>
163
164 <p>
165 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
166 </p>
167
168 <p>
169 <strong>__Examples__</strong>
170 </p>
171
172 <pre class="sh4-code">
173 GET <?php echo $fullUrl2; ?>/123
174 </pre>
175
176 <h3 class="hc-underline">__Delete Shift__</h3>
177 <?php
178 $url = $startUrl . 'shifts/&lt;id&gt;';
179 $fullUrl = get_rest_url( NULL, $url );
180
181 $url2 = $startUrl . 'shifts';
182 $fullUrl2 = get_rest_url( NULL, $url2 );
183 ?>
184
185 <p>
186 <strong>
187 DELETE <?php echo $url; ?>
188 </strong>
189 </p>
190
191 <p>
192 <strong>__Headers__</strong>
193 </p>
194
195 <p>
196 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
197 </p>
198
199 <p>
200 <strong>__Examples__</strong>
201 </p>
202
203 <pre class="sh4-code">
204 DELETE <?php echo $fullUrl2; ?>/123
205 </pre>
206
207 <h3 class="hc-underline">__Create Shift__</h3>
208 <?php
209 $url = $startUrl . 'shifts';
210 $fullUrl = get_rest_url( NULL, $url );
211 ?>
212
213 <p>
214 <strong>
215 POST <?php echo $url; ?>
216 </strong>
217 </p>
218
219 <p>
220 <strong>__Headers__</strong>
221 </p>
222
223 <p>
224 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
225 </p>
226
227 <p>
228 <strong>__Arguments__</strong>
229 </p>
230
231 <p>
232 <strong>calendar_id</strong> (__Calendar Id__)<br>
233 <strong>employee_id</strong> (__Employee Id__)<br>
234 <strong>start</strong> (__Start Date Time__, YYYYMMDDHHMM)<br>
235 <strong>end</strong> (__End Date Time__, YYYYMMDDHHMM)<br>
236 <strong>status_id</strong> (publish, draft)<br>
237 <strong>conflict</strong> (__Set to 1 to allow creation of shifts with conflicts__) <em>__optional__</em><br>
238 <?php foreach( $cfields as $cfield ) : ?>
239 <strong><?php echo $cfield->getName(); ?></strong> (<?php echo $cfield->getLabel(); ?>)<br>
240 <?php endforeach; ?>
241 </p>
242
243 <p>
244 <strong>__Examples__</strong>
245 </p>
246
247 <pre class="sh4-code">
248 POST <?php echo $fullUrl; ?>
249
250 calendar_id: 11
251 employee_id: 22
252 start: <?php echo $today; ?>0800
253 end: <?php echo $today; ?>1430
254 status_id: publish
255 </pre>
256
257 <p>
258 __If success, it returns the id of the new shift. Otherwise error messages will be given.__
259 </p>
260
261 <h3 class="hc-underline">__Update Shift__</h3>
262 <?php
263 $url = $startUrl . 'shifts/&lt;id&gt;';
264 $fullUrl = get_rest_url( NULL, $url );
265
266 $url2 = $startUrl . 'shifts/';
267 $fullUrl2 = get_rest_url( NULL, $url2 );
268 if( '/' == substr($fullUrl2, -1) ){
269 $fullUrl2 = substr( $fullUrl2, 0, -1 );
270 }
271 ?>
272
273 <p>
274 <strong>
275 PUT <?php echo $url; ?>
276 </strong>
277 </p>
278
279 <p>
280 <strong>__Headers__</strong>
281 </p>
282
283 <p>
284 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
285 </p>
286
287 <p>
288 <strong>__Arguments__</strong>
289 </p>
290
291 <p>
292 <strong>calendar_id</strong> (__Calendar Id__) <em>__optional__</em><br>
293 <strong>employee_id</strong> (__Employee Id__) <em>__optional__</em><br>
294 <strong>start</strong> (__Start Date Time__, YYYYMMDDHHMM) <em>__optional__</em><br>
295 <strong>end</strong> (__End Date Time__, YYYYMMDDHHMM) <em>__optional__</em><br>
296 <strong>status_id</strong> (publish, draft) <em>__optional__</em><br>
297 <strong>conflict</strong> (__Set to 1 to allow creation of shifts with conflicts__) <em>__optional__</em><br>
298 <?php foreach( $cfields as $cfield ) : ?>
299 <strong><?php echo $cfield->getName(); ?></strong> (<?php echo $cfield->getLabel(); ?>)<br>
300 <?php endforeach; ?>
301 </p>
302
303 <p>
304 <strong>__Examples__</strong>
305 </p>
306
307 <pre class="sh4-code">
308 PUT <?php echo $fullUrl2; ?>/123
309 start: <?php echo $today; ?>0900
310 end: <?php echo $today; ?>1530
311 </pre>
312
313 <pre class="sh4-code">
314 PUT <?php echo $fullUrl2; ?>/123
315 employee_id: 22
316 </pre>
317
318 <pre class="sh4-code">
319 PUT <?php echo $fullUrl2; ?>/123
320 status_id: publish
321 </pre>
322
323 <h3 class="hc-underline">__Get Available Employees__</h3>
324 <?php
325 $url = $startUrl . 'available-employees';
326 $fullUrl = get_rest_url( NULL, $url );
327 ?>
328
329 <p>
330 <strong>
331 GET <?php echo $url; ?>
332 </strong>
333 </p>
334
335 <p>
336 <strong>__Headers__</strong>
337 </p>
338
339 <p>
340 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
341 </p>
342
343 <p>
344 <strong>__Arguments__</strong>
345 </p>
346
347 <p>
348 <strong>calendar_id</strong> (__Calendar Id__) <em>__optional__</em><br>
349 <em>__default value__</em>: __all shift-type calendars__<br>
350
351 <strong>from</strong> (__Start Date Time__, YYYYMMDDHHMM) <em>__optional__</em><br>
352 <em>__default value__</em>: __beginning of today__<br>
353
354 <strong>to</strong> (__End Date Time__, YYYYMMDDHHMM) <em>__optional__</em><br>
355 <em>__default value__</em>: __one day from the start__<br>
356
357 </p>
358
359 <p>
360 <strong>__Examples__</strong>
361 </p>
362
363 <pre class="sh4-code">
364 GET <?php echo $fullUrl; ?>
365 </pre>
366
367 <pre class="sh4-code">
368 GET <?php echo $fullUrl; ?>?from=<?php echo $today; ?>0900&to=<?php echo $today; ?>1430
369 </pre>
370
371 <pre class="sh4-code">
372 GET <?php echo $fullUrl; ?>?from=<?php echo $today; ?>&calendar_id=123
373 </pre>
374
375 <pre class="sh4-code">
376 GET <?php echo $fullUrl; ?>?calendar_id[]=123&calendar_id[]=456
377 </pre>
378
379 <p>
380 <strong>__Example return__</strong>
381 </p>
382
383 <pre class="sh4-code">
384 {
385 "from": "<?php echo $today; ?>0900",
386 "to": "<?php echo $today; ?>1430",
387 "employees": [
388 {
389 "id": "523",
390 "title": "Alice",
391 "email": "alice@host.local",
392 "username": "alice"
393 },
394 {
395 "id": "527",
396 "title": "Eve",
397 "email": "eve@host.local",
398 "username": "eve"
399 }
400 ]
401 }
402 </pre>
403
404 <h3 class="hc-underline">__Get All Calendars__</h3>
405 <?php
406 $url = $startUrl . 'calendars';
407 $fullUrl = get_rest_url( NULL, $url );
408 ?>
409
410 <p>
411 <strong>
412 GET <?php echo $url; ?>
413 </strong>
414 </p>
415
416 <p>
417 <strong>__Headers__</strong>
418 </p>
419
420 <p>
421 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
422 </p>
423
424 <p>
425 <strong>__Examples__</strong>
426 </p>
427
428 <pre class="sh4-code">
429 GET <?php echo $fullUrl; ?>
430 </pre>
431
432 <p>
433 <strong>__Example return__</strong>
434 </p>
435
436 <pre class="sh4-code">
437 [
438 {
439 "id": "12",
440 "title": "Barista",
441 "type": "shift",
442 "active": "1"
443 },
444 {
445 "id": "13",
446 "title": "Server",
447 "type": "shift",
448 "active": "0"
449 },
450 {
451 "id": "14",
452 "title": "Holidays",
453 "type": "timeoff",
454 "active": "0"
455 }
456 ]
457 </pre>
458
459 <h3 class="hc-underline">__Get All Employees__</h3>
460 <?php
461 $url = $startUrl . 'employees';
462 $fullUrl = get_rest_url( NULL, $url );
463 ?>
464
465 <p>
466 <strong>
467 GET <?php echo $url; ?>
468 </strong>
469 </p>
470
471 <p>
472 <strong>__Headers__</strong>
473 </p>
474
475 <p>
476 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
477 </p>
478
479 <p>
480 <strong>__Examples__</strong>
481 </p>
482
483 <pre class="sh4-code">
484 GET <?php echo $fullUrl; ?>
485 </pre>
486
487 <p>
488 <strong>__Example return__</strong>
489 </p>
490
491 <pre class="sh4-code">
492 [
493 {
494 "id": "523",
495 "title": "Alice",
496 "email": "alice@host.local",
497 "username": "alice"
498 },
499 {
500 "id": "527",
501 "title": "Eve",
502 "email": "eve@host.local",
503 "username": "eve"
504 }
505 ]
506 </pre>
507
508 <h3 class="hc-underline">__Get Calendars For Employee__</h3>
509 <?php
510 $url = $startUrl . 'employees/&lt;id&gt;/calendars';
511 $fullUrl = get_rest_url( null, $url );
512
513 $url2 = $startUrl . 'employees';
514 $fullUrl2 = get_rest_url( null, $url2 );
515 ?>
516
517 <p>
518 <strong>
519 GET <?php echo $url; ?>
520 </strong>
521 </p>
522
523 <p>
524 <strong>__Headers__</strong>
525 </p>
526
527 <p>
528 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
529 </p>
530
531 <p>
532 <strong>__Examples__</strong>
533 </p>
534
535 <pre class="sh4-code">
536 GET <?php echo $fullUrl2; ?>/123/calendars
537 </pre>
538
539 <h3 class="hc-underline">__Get Employees Eligible For Calendar__</h3>
540 <?php
541 $url = $startUrl . 'calendars/&lt;id&gt;/employees';
542 $fullUrl = get_rest_url( null, $url );
543
544 $url2 = $startUrl . 'calendars';
545 $fullUrl2 = get_rest_url( null, $url2 );
546 ?>
547
548 <p>
549 <strong>
550 GET <?php echo $url; ?>
551 </strong>
552 </p>
553
554 <p>
555 <strong>__Headers__</strong>
556 </p>
557
558 <p>
559 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
560 </p>
561
562 <p>
563 <strong>__Examples__</strong>
564 </p>
565
566 <pre class="sh4-code">
567 GET <?php echo $fullUrl2; ?>/654/employees
568 </pre>
569
570 <h3 class="hc-underline">__Add Employee To Calendar__</h3>
571 <?php
572 $url = $startUrl . 'calendars/&lt;cid&gt;/employees/&lt;eid&gt;';
573 $fullUrl = get_rest_url( null, $url );
574
575 $url2 = $startUrl . 'calendars';
576 $fullUrl2 = get_rest_url( null, $url2 );
577 ?>
578
579 <p>
580 <strong>
581 POST <?php echo $url; ?>
582 </strong>
583 </p>
584
585 <?php
586 $url = $startUrl . 'employees/&lt;eid&gt;/calendars/&lt;cid&gt;';
587 $fullUrl = get_rest_url( null, $url );
588
589 $url3 = $startUrl . 'employees';
590 $fullUrl3 = get_rest_url( null, $url3 );
591 ?>
592
593 <p>
594 <strong>
595 POST <?php echo $url; ?>
596 </strong>
597 </p>
598
599 <p>
600 <strong>__Headers__</strong>
601 </p>
602
603 <p>
604 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
605 </p>
606
607 <p>
608 <strong>__Examples__</strong>
609 </p>
610
611 <pre class="sh4-code">
612 POST <?php echo $fullUrl2; ?>/654/employees/123
613 </pre>
614
615 <pre class="sh4-code">
616 POST <?php echo $fullUrl3; ?>/123/calendars/654
617 </pre>
618
619 <h3 class="hc-underline">__Remove Employee From Calendar__</h3>
620 <?php
621 $url = $startUrl . 'calendars/&lt;cid&gt;/employees/&lt;eid&gt;';
622 $fullUrl = get_rest_url( null, $url );
623
624 $url2 = $startUrl . 'calendars';
625 $fullUrl2 = get_rest_url( null, $url2 );
626 ?>
627
628 <p>
629 <strong>
630 DELETE <?php echo $url; ?>
631 </strong>
632 </p>
633
634 <?php
635 $url = $startUrl . 'employees/&lt;eid&gt;/calendars/&lt;cid&gt;';
636 $fullUrl = get_rest_url( null, $url );
637
638 $url3 = $startUrl . 'employees';
639 $fullUrl3 = get_rest_url( null, $url3 );
640 ?>
641
642 <p>
643 <strong>
644 DELETE <?php echo $url; ?>
645 </strong>
646 </p>
647
648 <p>
649 <strong>__Headers__</strong>
650 </p>
651
652 <p>
653 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
654 </p>
655
656 <p>
657 <strong>__Examples__</strong>
658 </p>
659
660 <pre class="sh4-code">
661 DELETE <?php echo $fullUrl2; ?>/654/employees/123
662 </pre>
663
664 <pre class="sh4-code">
665 DELETE <?php echo $fullUrl3; ?>/123/calendars/654
666 </pre>
667
668 <h3 class="hc-underline">__Get Employee__</h3>
669 <?php
670 $url = $startUrl . 'employees/&lt;id&gt;';
671 $fullUrl = get_rest_url( null, $url );
672
673 $url2 = $startUrl . 'employees';
674 $fullUrl2 = get_rest_url( null, $url2 );
675 ?>
676
677 <p>
678 <strong>
679 GET <?php echo $url; ?>
680 </strong>
681 </p>
682
683 <p>
684 <strong>__Headers__</strong>
685 </p>
686
687 <p>
688 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
689 </p>
690
691 <p>
692 <strong>__Examples__</strong>
693 </p>
694
695 <pre class="sh4-code">
696 GET <?php echo $fullUrl2; ?>/123
697 </pre>
698
699 <h3 class="hc-underline">__Get Employee By User Id__</h3>
700 <?php
701 $url = $startUrl . 'users/&lt;id&gt;/employee';
702 $fullUrl = get_rest_url( null, $url );
703
704 $url2 = $startUrl . 'users';
705 $fullUrl2 = get_rest_url( null, $url2 );
706 ?>
707
708 <p>
709 <strong>
710 GET <?php echo $url; ?>
711 </strong>
712 </p>
713
714 <p>
715 <strong>__Headers__</strong>
716 </p>
717
718 <p>
719 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
720 </p>
721
722 <p>
723 <strong>__Examples__</strong>
724 </p>
725
726 <pre class="sh4-code">
727 GET <?php echo $fullUrl2; ?>/321/employee
728 </pre>
729
730 <h3 class="hc-underline">__Create Employee__</h3>
731 <?php
732 $url = $startUrl . 'employees';
733 $fullUrl = get_rest_url( NULL, $url );
734 ?>
735
736 <p>
737 <strong>
738 POST <?php echo $url; ?>
739 </strong>
740 </p>
741
742 <p>
743 <strong>__Headers__</strong>
744 </p>
745
746 <p>
747 X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
748 </p>
749
750 <p>
751 <strong>__Arguments__</strong>
752 </p>
753
754 <p>
755 <strong>title</strong><br>
756 <strong>user_id</strong> <em>__optional__</em><br>
757 <strong>description</strong> <em>__optional__</em><br>
758 </p>
759
760 <p>
761 __Either title or user_id required.__ __If user_id is given, it will link the new employee to this WordPress user.__
762 __If user_id is given without the title, it will create a new employee with this WordPress user's full name as employee's title and link this employee to this user.__
763 </p>
764
765 <p>
766 <strong>__Examples__</strong>
767 </p>
768
769 <pre class="sh4-code">
770 POST <?php echo $fullUrl; ?>
771
772 title: James
773 </pre>
774
775 <p>
776 __If success, it returns the id of the new employee. Otherwise error messages will be given.__
777 </p>
778