Files
webgui/emhttp/plugins/dynamix/ParityCheck.page
tom mortensen 0ee14776c1 Merge pull request #2205 from bergware/master
Miscellaneous fixes
2025-05-24 20:59:10 -07:00

275 lines
8.9 KiB
Plaintext

Menu="Scheduler:1"
Title="Parity Check"
Tag="calendar"
Cond="$disks['parity']['device'] || $disks['parity2']['device'] || count(array_filter(array_column($disks,'type'),function($type){return $type=='Data';}))"
---
<?PHP
/* Copyright 2012-2025, Bergware International.
* Copyright 2005-2025, Lime Technology
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
if (_var($disks['parity'],'status')=='DISK_NP_DSBL' && _var($disks['parity2'],'status')=='DISK_NP_DSBL') {
echo "<p class='notice'>"._('No Parity disk present')."!</p>";
}
$width = [166,300];
$mode = ['Disabled','Daily','Weekly','Monthly','Yearly','Custom'];
$days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
$months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
$memory = '/tmp/memory.tmp';
if (file_exists($memory)) {
parse_str(file_get_contents($memory), $parity);
if (empty($parity['hour'])) $parity['hour'] = "";
if (empty($parity['day'])) $parity['day'] = "";
if (empty($parity['dotm'])) $parity['dotm'] = "";
if (empty($parity['month'])) $parity['month'] = "";
if (empty($parity['write'])) $parity['write'] = "NOCORRECT";
}
if ($parity['mode']<2) $parity['cumulative'] = '';
if ($parity['mode']==2) $parity['frequency'] = '1';
// Build day options array based on mode
$day_options = [];
$day_select_attrs = 'name="day"';
if ($parity['mode'] == 2) {
// Weekly mode - regular dropdown
for ($d = 0; $d < count($days); $d++) {
$day_options[] = mk_option($parity['day'], strval($d), ucfirst(_($days[$d],0)));
}
} elseif ($parity['mode'] == 5) {
// Custom mode - multiple select
$day_select_attrs = 'id="s1" name="day" multiple="multiple" style="display:none"';
for ($d = 0; $d < count($days); $d++) {
$day_options[] = mk_option_check($parity['day'], strval($d), ucfirst(_($days[$d],0)));
}
} else {
// Other modes - disabled placeholder
$day_options[] = mk_option($parity['day'], "*", "--------");
}
// Build dotm (day of the month/week) options array based on mode
$dotm_options = [];
if ($parity['mode'] >= 3) {
if ($parity['mode'] == 5) {
// Custom mode - week options
$dotm_options[] = mk_option($parity['dotm'], "*", _("Every week"));
$dotm_options[] = mk_option($parity['dotm'], "W1", _("First week"));
$dotm_options[] = mk_option($parity['dotm'], "W2", _("Second week"));
$dotm_options[] = mk_option($parity['dotm'], "W3", _("Third week"));
$dotm_options[] = mk_option($parity['dotm'], "W4", _("Fourth week"));
$dotm_options[] = mk_option($parity['dotm'], "WL", _("Last week"));
} else {
// Monthly/Yearly mode - day options
$dotm_options[] = mk_option($parity['dotm'], "1", _("First day"));
$dotm_options[] = mk_option($parity['dotm'], "28-31", _("Last day"));
for ($d = 2; $d <= 31; $d++) {
$dotm_options[] = mk_option($parity['dotm'], strval($d), sprintf("%02d", $d));
}
}
} else {
// Other modes - disabled placeholder
$dotm_options[] = mk_option($parity['dotm'], "*", "--------");
}
// Set the label for dotm field based on mode
$dotm_label = ($parity['mode'] < 5) ? _('Day of the month') : _('Week of the month');
// Build month options array based on mode
$month_options = [];
$month_select_attrs = 'name="month"';
if ($parity['mode'] >= 4) {
if ($parity['mode'] == 5) {
// Custom mode - multiple select
$month_select_attrs = 'id="s2" name="month" multiple="multiple" style="display:none"';
for ($m = 0; $m < count($months); $m++) {
$month_options[] = mk_option_check($parity['month'], strval($m+1), ucfirst(_($months[$m],0)));
}
} else {
// Yearly mode - regular dropdown
for ($m = 0; $m < count($months); $m++) {
$month_options[] = mk_option($parity['month'], strval($m+1), ucfirst(_($months[$m],0)));
}
}
} else {
// Other modes - disabled placeholder
$month_options[] = mk_option($parity['month'], "*", "--------");
}
// Build hour options array based on mode
$hour_options = [];
if ($parity['mode'] > 0) {
// Active modes - generate 24-hour options with 30-minute intervals
for ($h = 0; $h < 24; $h++) {
$hour_options[] = mk_option($parity['hour'], sprintf("0 %d", $h), sprintf("%02d:00", $h));
$hour_options[] = mk_option($parity['hour'], sprintf("30 %d", $h), sprintf("%02d:30", $h));
}
} else {
// Disabled mode - placeholder
$hour_options[] = mk_option($parity['hour'], "*", "--------");
}
?>
<script>
<?if ($parity['mode']==5):?>
$(function() {
$("#s1").dropdownchecklist({emptyText:"_(Every day)_", width:<?=$width[0]?>, explicitClose:"..._(close)_"});
$("#s2").dropdownchecklist({emptyText:"_(Every month)_", width:<?=$width[0]?>, explicitClose:"..._(close)_"});
});
// Simulate a single input field
function prepareParity(form) {
var days = '';
for (var i=0,item; item=form.day.options[i]; i++) {
if (item.selected) {
if (days.length) days += ',';
days += item.value;
item.selected = false;
}
}
item = form.day.options[0];
item.value = days || '*';
item.selected = true;
var months = '';
for (var i=0,item; item=form.month.options[i]; i++) {
if (item.selected) {
if (months.length) months += ',';
months += item.value;
item.selected = false;
}
}
item = form.month.options[0];
item.value = months || '*';
item.selected = true;
}
<?else:?>
function prepareParity(form) {
// do nothing
}
<?endif;?>
$(function() {
<?if (file_exists($memory)):?>
setTimeout(function(){$('input[value="_(Apply)_"]').removeAttr('disabled');},0);
$('input[value="_(Done)_"]').val("_(Reset)_").prop('onclick',null).click(function(){refresh($(this).parentsUntil('form').parent().offset().top)});
<?unlink($memory);?>
<?endif;?>
presetParity(document.parity_settings);
});
function presetParity(form) {
var mode = form.mode.value;
form.day.disabled = mode!=2 && mode!=5;
form.dotm.disabled = mode<3;
form.hour.disabled = mode==0;
form.month.disabled = mode<4;
form.write.disabled = mode==0;
}
function showCumulative(val,pace) {
if (val=='') $('#cumulative').hide(pace); else $('#cumulative').show(pace);
}
$(function(){
showCumulative($('select[name="cumulative"]').val());
});
</script>
<form markdown="1" name="parity_settings" method="POST" action="/update.php" target="progressFrame" onsubmit="prepareParity(this)">
<input type="hidden" name="#file" value="dynamix/dynamix.cfg"/>
<input type="hidden" name="#section" value="parity"/>
<input type="hidden" name="#include" value="/webGui/include/update.parity.php"/>
_(Scheduled parity check)_:
: <select name="mode" onchange="submit()">
<?for ($m=0; $m<count($mode); $m++):?>
<?=mk_option($parity['mode'], strval($m), _($mode[$m]))?>
<?endfor;?>
</select>
:parity_check_scheduled_help:
_(Day of the week)_:
: <select <?=$day_select_attrs?>>
<?foreach ($day_options as $option):?>
<?=$option?>
<?endforeach;?>
</select>
:parity_day_of_the_week_help:
<?= $dotm_label ?>:
: <select name="dotm">
<?foreach ($dotm_options as $option):?>
<?=$option?>
<?endforeach;?>
</select>
:parity_week_of_the_month_help:
_(Time of the day)_:
: <select name="hour">
<?foreach ($hour_options as $option):?>
<?=$option?>
<?endforeach;?>
</select>
:parity_time_of_the_day_help:
_(Month of the year)_:
: <select <?=$month_select_attrs?>>
<?foreach ($month_options as $option):?>
<?=$option?>
<?endforeach;?>
</select>
:parity_month_of_the_year_help:
_(Write corrections to parity disk)_:
: <select name="write">
<?=mk_option($parity['write'], "NOCORRECT", _("No"))?>
<?=mk_option($parity['write'], "", _("Yes"))?>
</select>
:parity_write_corrections_help:
_(Cumulative parity check)_:
: <select name="cumulative" onchange="showCumulative(this.value,'slow')" <?=$parity['mode']>1?'':'disabled'?>>
<?=mk_option(_var($parity,'cumulative'), "", _("No"))?>
<?=mk_option(_var($parity,'cumulative'), "1", _("Yes"))?>
</select>
:parity_cumulative_check_help:
<div markdown="1" id="cumulative" style="display:none">
_(Accumulation frequency)_:
: <select name="frequency">
<?=mk_option(_var($parity,'frequency'), "1", _("Daily"),$parity['mode']==2 ? 'disabled' : '')?>
<?=mk_option(_var($parity,'frequency'), "7", _("Weekly"),$parity['mode']==2 ? 'disabled' : '')?>
</select>
:parity_accumulation_frequency_help:
_(Accumulation duration)_:
: <select name="duration">
<?for ($h=1; $h<24; $h++):?>
<?=mk_option(_var($parity,'duration'), $h, $h.' '._('hour'.($h==1?'':'s')))?>
<?endfor;?>
</select>
:parity_accumulation_duration_help:
</div>
&nbsp;
: <span class="inline-block">
<input type="submit" name="#apply" value="_(Apply)_" disabled>
<input type="button" value="_(Done)_" onclick="done()">
</span>
</form>