Fix recurring maintenance days

This commit is contained in:
Tony Murray
2020-06-25 22:12:21 -05:00
parent 0f2ddba10b
commit 04251cdc94
2 changed files with 7 additions and 20 deletions

View File

@@ -14,8 +14,6 @@ use Illuminate\Support\Str;
* the source code distribution for details.
*/
use Carbon\Carbon;
if (!Auth::user()->hasGlobalAdmin()) {
header('Content-type: text/plain');
die('ERROR: You need to be admin');
@@ -43,7 +41,7 @@ if ($sub_type == 'new-maintenance') {
$end_recurring_hr = mres($_POST['end_recurring_hr']);
$recurring_day = mres($_POST['recurring_day']);
$start = mres($_POST['start']);
list($duration_hour, $duration_min) = explode(':', mres($_POST['duration']));
[$duration_hour, $duration_min] = explode(':', mres($_POST['duration']));
$end = mres($_POST['end']);
$maps = mres($_POST['maps']);
@@ -60,19 +58,20 @@ if ($sub_type == 'new-maintenance') {
}
// check values if recurring is set to yes
$recurring_day = null;
if ($recurring == 1) {
if (empty($start_recurring_dt)) {
$message .= 'Missing start recurring date<br />';
} else {
// check if date is correct
list($ysrd, $msrd, $dsrd) = explode('-', $start_recurring_dt);
[$ysrd, $msrd, $dsrd] = explode('-', $start_recurring_dt);
if (!checkdate($msrd, $dsrd, $ysrd)) {
$message .= 'Please check start recurring date<br />';
}
}
// end recurring dt not mandatory.. but if set, check if correct
if (!empty($end_recurring_dt) && $end_recurring_dt != '0000-00-00' && $end_recurring_dt != '') {
list($yerd, $merd, $derd) = explode('-', $end_recurring_dt);
[$yerd, $merd, $derd] = explode('-', $end_recurring_dt);
if (!checkdate($merd, $derd, $yerd)) {
$message .= 'Please check end recurring date<br />';
}
@@ -89,9 +88,7 @@ if ($sub_type == 'new-maintenance') {
}
if (isset($_POST['recurring_day']) && is_array($_POST['recurring_day']) && !empty($_POST['recurring_day'])) {
$recurring_day = implode(',', $_POST['recurring_day']);
} else {
$recurring_day = null;
$recurring_day = $_POST['recurring_day'];
}
// recurring = 1 => empty no reccurency values to be sure.
@@ -111,7 +108,6 @@ if ($sub_type == 'new-maintenance') {
$end_recurring_dt = '1970-01-02';
$start_recurring_hr = '00:00:00';
$end_recurring_hr = '00:00:00';
$recurring_day = null;
}
if (!is_array($_POST['maps'])) {
@@ -131,6 +127,7 @@ if ($sub_type == 'new-maintenance') {
$alert_schedule->start_recurring_hr = $start_recurring_hr;
$alert_schedule->end_recurring_dt = $end_recurring_dt;
$alert_schedule->end_recurring_hr = $end_recurring_hr;
$alert_schedule->recurring_day = $recurring_day;
}
$alert_schedule->save();