# shiftcontroller/4.9.26/sh4/api/html/view.html.php

ShiftController Employee Shift Scheduling, version 4.9.26. 300 lines.

- Page: https://pluginprobe.com/plugins/shiftcontroller/4.9.26/code/sh4/api/html/view.html.php
- Raw: https://pluginprobe.com/plugins/shiftcontroller/4.9.26/raw/sh4/api/html/view.html.php
- Modified: 2023-03-07T08:19:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/shiftcontroller/4.9.26/code/sh4/api/html/view.html.php#L10-L20`.

```php
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly

$app = 'sh4-rest';

if( isset($_POST[$app . '_submit']) ){
	if( isset($_POST[$app]) ){
		foreach( (array)$_POST[$app] as $key => $value ){
			$option_name = $app . '_' . $key;
			$value = sanitize_text_field( $value );
			update_option( $option_name, $value );
		}
	}

	if( ! isset($_POST[$app]['enabled']) ){
		$k = $app . '_enabled';
		$value = 0;
		update_option( $k, $value );
	}
}

// $this->initOption();

$current = array();
$current['enabled'] = get_option( $app . '_enabled', 1 );
$current['auth_code'] = get_option( $app . '_auth_code', '' );

$startUrl = '/shiftcontroller/v4/';

// spaghetti starts here
?>

<form method="post" action="">
	<?php settings_fields( $app ); ?>
	<?php //do_settings_sections( $this->app ); ?>

	<label>
		<?php $checked = $current['enabled'] ? ' checked' : ''; ?>
		<input type="checkbox" name="<?php echo $app; ?>[enabled]" value="1" <?php echo $checked; ?>/>
		Enable
	</label>
	</br/>

	<label>
		AuthCode<br>
		<input type="text" name="<?php echo $app; ?>[auth_code]" value="<?php echo esc_attr( $current['auth_code'] ); ?>" />
	</label>
	</br/>

	<p>
		<input name="<?php echo $app; ?>_submit" type="submit" class="button-primary" value="Save" />
	</p>
</form>

<?php if( ! $current['enabled'] ) return; ?>


<style>
.sh4-code {
display: block; padding: 1em; border: #999 1px solid; margin-bottom: 1em;
}
</style>

<h3 class="hc-underline">Get Shifts</h3>
<?php
$url = $startUrl . 'shifts';
$fullUrl = get_rest_url( NULL, $url );
?>

<p>
<strong>
GET <?php echo $url; ?>
</strong>
</p>

<p>
<strong>__Headers__</strong>
</p>

<p>
X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
</p>

<p>
<strong>__Arguments__</strong>
</p>

<p>
<strong>calendar_id</strong> (__Calendar Id__)<br>
<strong>employee_id</strong> (__Employee Id__)<br>
<strong>from</strong> (__From Date__, YYYYMMDD / __From Date Time__, YYYYMMDDHHMM)<br>
<strong>to</strong> (__To Date__, YYYYMMDD / __To Date Time__, YYYYMMDDHHMM)<br>
<strong>status_id</strong> (publish, draft)<br>
</p>

<?php if( class_exists('SH4_CFields_Model') ) : ?>
<?php
$f = ShiftController4::$instance->root();
$cfieldsQuery = $f->make('SH4_CFields_Query');
$cfields = $cfieldsQuery->read();
?>
<?php if( $cfields ) : ?>
<p>
<strong>__Optional Arguments__</strong>
</p>

<p>
<?php foreach( $cfields as $cfield ) : ?>
<em><?php echo $cfield->getName(); ?></em> (<?php echo $cfield->getLabel(); ?>)<br>
<?php endforeach; ?>
</p>
<?php endif; ?>
<?php endif; ?>

<p>
<strong>__Examples__</strong>
</p>

<pre class="sh4-code">
GET <?php echo $fullUrl; ?>
</pre>

<pre class="sh4-code">
GET <?php echo $fullUrl; ?>?calendar_id=11&from=20210224
</pre>

<pre class="sh4-code">
GET <?php echo $fullUrl; ?>?from=202102240900&to=202102241430&status_id=draft
</pre>


<h3 class="hc-underline">__Get Shift__</h3>
<?php
$url = $startUrl . 'shifts/&lt;id&gt;';
$fullUrl = get_rest_url( NULL, $url );

$url2 = $startUrl . 'shifts';
$fullUrl2 = get_rest_url( NULL, $url2 );
?>

<p>
<strong>
GET <?php echo $url; ?>
</strong>
</p>

<p>
<strong>__Headers__</strong>
</p>

<p>
X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
</p>

<p>
<strong>__Examples__</strong>
</p>

<pre class="sh4-code">
GET <?php echo $fullUrl2; ?>/123
</pre>

<h3 class="hc-underline">__Delete Shift__</h3>
<?php
$url = $startUrl . 'shifts/&lt;id&gt;';
$fullUrl = get_rest_url( NULL, $url );

$url2 = $startUrl . 'shifts';
$fullUrl2 = get_rest_url( NULL, $url2 );
?>

<p>
<strong>
DELETE <?php echo $url; ?>
</strong>
</p>

<p>
<strong>__Headers__</strong>
</p>

<p>
X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
</p>

<p>
<strong>__Examples__</strong>
</p>

<pre class="sh4-code">
DELETE <?php echo $fullUrl2; ?>/123
</pre>

<h3 class="hc-underline">__Create Shift__</h3>
<?php
$url = $startUrl . 'shifts';
$fullUrl = get_rest_url( NULL, $url );
?>

<p>
<strong>
POST <?php echo $url; ?>
</strong>
</p>

<p>
<strong>__Headers__</strong>
</p>

<p>
X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
</p>

<p>
<strong>__Arguments__</strong>
</p>

<p>
<strong>calendar_id</strong> (__Calendar Id__)<br>
<strong>employee_id</strong> (__Employee Id__)<br>
<strong>start</strong> (__Start Date Time__, YYYYMMDDHHMM)<br>
<strong>end</strong> (__End Date Time__, YYYYMMDDHHMM)<br>
<strong>status_id</strong> (publish, draft)<br>
<strong>conflict</strong> (__Set to 1 to allow creation of shifts with conflicts__) <em>optional</em><br>
</p>

<p>
<strong>Examples</strong>
</p>

<pre class="sh4-code">
POST <?php echo $fullUrl; ?>

calendar_id: 11
employee_id: 22
start: 202102240800
end: 202102241430
status_id: publish
</pre>

<p>
__If success, it returns the id of the new shift. Otherwise error messages will be given.__
</p>


<h3 class="hc-underline">__Update Shift__</h3>
<?php
$url = $startUrl . 'shifts/&lt;id&gt;';
$fullUrl = get_rest_url( NULL, $url );

$url2 = $startUrl . 'shifts/';
$fullUrl2 = get_rest_url( NULL, $url2 );
?>

<p>
<strong>
PUT <?php echo $url; ?>
</strong>
</p>

<p>
<strong>__Headers__</strong>
</p>

<p>
X-WP-ShiftController-AuthCode: <?php echo $current['auth_code']; ?>
</p>

<p>
<strong>__Arguments__</strong>
</p>

<p>
<strong>calendar_id</strong> (__Calendar Id__) <em>optional</em><br>
<strong>employee_id</strong> (__Employee Id__) <em>optional</em><br>
<strong>start</strong> (__Start Date Time__, YYYYMMDDHHMM) <em>optional</em><br>
<strong>end</strong> (__End Date Time__, YYYYMMDDHHMM) <em>optional</em><br>
<strong>status_id</strong> (publish, draft) <em>optional</em><br>
<strong>conflict</strong> (__Set to 1 to allow creation of shifts with conflicts__) <em>optional</em><br>
</p>

<p>
<strong>Examples</strong>
</p>

<pre class="sh4-code">
PUT <?php echo $fullUrl2; ?>/123
start: 202102240900
end: 202102241530
</pre>

<pre class="sh4-code">
PUT <?php echo $fullUrl2; ?>/123
employee_id: 22
</pre>

<pre class="sh4-code">
PUT <?php echo $fullUrl2; ?>/123
status_id: publish
</pre>

```
