Menu="Scheduler:2"
Title="Mover Settings"
Tag="calendar-check-o"
---
<?PHP
/* Copyright 2005-2023, Lime Technology
 * Copyright 2012-2023, Bergware International.
 *
 * 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.
 */
?>
<?
$setup = true;
if (!$pool_devices) {
  echo "<p class='notice'>"._('No Cache device present')."!</p>";
  $setup = false;
} elseif ($var['shareUser']=='-') {
  echo "<p class='notice'>"._('User shares not enabled')."!</p>";
  $setup = false;
}
$cron = explode(' ',$var['shareMoverSchedule']);
$move = $cron[2]!='*' ? 3 : ($cron[4]!='*' ? 2 : (substr($cron[1],0,1)!='*' ? 1 : 0));
$mode = ['Hourly','Daily','Weekly','Monthly'];
$days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];

$showMoverButton = $setup && $pool_devices;
$moverRunning = file_exists('/var/run/mover.pid');
?>
<script>
<? if ($setup == true):?>
$(function() {
  presetMover(document.mover_schedule);
});
<? endif; ?>
// Fool Unraid by simulating the original input field
function prepareMover(form) {
  var mode = form.shareMoverSchedule.value;
  var min = mode!=0 ? form.min.value : 0;
  var hour = mode!=0 ? form.hour1.value : form.hour2.value;
  form.shareMoverSchedule.options[mode].value = min+' '+hour+' '+form.dotm.value+' * '+form.day.value;
  form.min.disabled = true;
  form.hour1.disabled = true;
  form.hour2.disabled = true;
  form.dotm.disabled = true;
  form.day.disabled = true;
}
function presetMover(form) {
  var mode = form.shareMoverSchedule.value;
  form.min.disabled = false;
  form.day.disabled = mode!=2;
  form.dotm.disabled = mode!=3;
  form.day.value = form.day.disabled ? '*' : (form.day.value=='*' ? 0 : form.day.value);
  form.dotm.value = form.dotm.disabled ? '*' : (form.dotm.value=='*' ? 1 : form.dotm.value);
  if (mode==0) {$('#H1').hide(); $('#H2').show();} else {$('#H2').hide(); $('#H1').show();}
}
</script>
<form markdown="1" name="mover_schedule" method="POST" action="/update.htm" target="progressFrame" onsubmit="prepareMover(this)">
<?if ($setup):?>
_(Mover schedule)_:
: <select name="shareMoverSchedule" onchange="presetMover(this.form)">
  <?for ($m=0; $m<count($mode); $m++):?>
  <?=mk_option($move, strval($m), _($mode[$m]))?>
  <?endfor;?>
  </select>

:mover_schedule_help:

_(Day of the week)_:
: <select name="day">
  <?for ($d=0; $d<count($days); $d++):?>
  <?=mk_option($cron[4], strval($d), _($days[$d],0))?>
  <?endfor;?>
  <?=mk_option($cron[4], "*", "--------", "disabled")?>
  </select>

:mover_day_of_the_week_help:

_(Day of the month)_:
: <select name="dotm">
  <?for ($d=1; $d<=31; $d++):?>
  <?=mk_option($cron[2], strval($d), sprintf("%02d", $d))?>
  <?endfor;?>
  <?=mk_option($cron[2], "*", "--------", "disabled")?>
  </select>

:mover_day_of_the_month_help:

_(Time of the day)_:
: <span id="H1"<?if ($move==0):?> style="display:none"<?endif;?>><select name="hour1" class="narrow">
  <?for ($d=0; $d<=23; $d++):?>
  <?=mk_option($cron[1], strval($d), sprintf("%02d", $d))?>
  <?endfor;?>
  </select>
  <select name="min" class="narrow">
  <?for ($d=0; $d<=55; $d+=5):?>
  <?=mk_option($cron[0], strval($d), sprintf("%02d", $d))?>
  <?endfor;?>
  </select>&nbsp;&nbsp;_(HH:MM)_</span>
: <span id="H2"<?if ($move!=0):?> style="display:none"<?endif;?>><select name="hour2">
  <?=mk_option($cron[1], "*/1", _("Every hour"))?>
  <?=mk_option($cron[1], "*/2", _("Every 2 hours"))?>
  <?=mk_option($cron[1], "*/3", _("Every 3 hours"))?>
  <?=mk_option($cron[1], "*/4", _("Every 4 hours"))?>
  <?=mk_option($cron[1], "*/6", _("Every 6 hours"))?>
  <?=mk_option($cron[1], "*/8", _("Every 8 hours"))?>
  </select></span>

:mover_time_of_the_day_help:

_(Mover logging)_:
: <select name="shareMoverLogging">
  <?=mk_option($var['shareMoverLogging'], "yes", _("Enabled"))?>
  <?=mk_option($var['shareMoverLogging'], "no", _("Disabled"))?>
  </select>

:mover_logging_help:

<?endif;?>
&nbsp;
: <span class="buttons-spaced">
    <input type="submit" name="changeMover" value="_(Apply)_" disabled>
    <input type="button" value="_(Done)_" onclick="done()">
    <?if ($showMoverButton):?>
      <input type="submit" name="cmdStartMover" value="_(Move now)_"<?if ($moverRunning):?> disabled<?endif;?>>
      <?if ($moverRunning):?><span>_(Mover is running)_</span><?endif;?>
    <?endif;?>
  </span>
</form>
