From: Marcin Haba Date: Sat, 31 Jul 2021 03:29:47 +0000 (+0200) Subject: baculum: New advanced schedule settings X-Git-Tag: Release-11.0.6~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb90c4b40b45cd09375b9c992b6a277bbd208497;p=thirdparty%2Fbacula.git baculum: New advanced schedule settings There has been also changed way of loading all directive controls. Now they are loaded on PreRender event instead of on Load event. --- diff --git a/gui/baculum/protected/API/Class/BaculaSetting.php b/gui/baculum/protected/API/Class/BaculaSetting.php index 4e2d046e2..e5a656de4 100644 --- a/gui/baculum/protected/API/Class/BaculaSetting.php +++ b/gui/baculum/protected/API/Class/BaculaSetting.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -306,34 +306,21 @@ class BaculaSetting extends APIModule { $values ); $overwrite_directive = implode(' ', array_filter($overwrite_directive)); - $hour = $directive_value[$i]['Hour'][0]; - $hourly = ''; $min = 0; - $minute = '00'; /** * Check if Minute key exists because of bug about missing Minute * @see http://bugs.bacula.org/view.php?id=2318 */ if (array_key_exists('Minute', $directive_value[$i])) { $min = $directive_value[$i]['Minute']; - $minute = sprintf('%02d', $min); - } - $day = Params::getDaysConfig($directive_value[$i]['Day']); - $month = Params::getMonthsConfig($directive_value[$i]['Month']); - $week = Params::getWeeksConfig($directive_value[$i]['WeekOfMonth']); - $wday = Params::getWdaysConfig($directive_value[$i]['DayOfWeek']); - if (!empty($day)) { - $day = 'on ' . $day; - } - $value = array($overwrite_directive, $month, $week, $day, $wday); - $hour_len = count($directive_value[$i]['Hour']); - if ($hour_len == 24) { - $value[] = 'hourly'; - } - if ($hour_len == 1 || ($hour_len == 24 && $min != 0)) { - $value[] = 'at'; - $value[] = "$hour:$minute"; } + $moys = Params::getMonthsOfYearConfig($directive_value[$i]['Month']); + $woys = Params::getWeeksOfYearConfig($directive_value[$i]['WeekOfYear']); + $doms = Params::getDaysOfMonthConfig($directive_value[$i]['Day']); + $woms = Params::getWeeksOfMonthConfig($directive_value[$i]['WeekOfMonth']); + $dows = Params::getDaysOfWeekConfig($directive_value[$i]['DayOfWeek']); + $t = Params::getTimeConfig($directive_value[$i]['Hour'], $min); + $value = array($overwrite_directive, $moys, $woys, $doms, $woms, $dows, $t); $value = array_filter($value); if (!array_key_exists($directive_name, $resource[$resource_type])) { $resource[$resource_type][$directive_name] = array(); diff --git a/gui/baculum/protected/Common/Class/BClientScript.php b/gui/baculum/protected/Common/Class/BClientScript.php index ed6afe25a..a32de6434 100644 --- a/gui/baculum/protected/Common/Class/BClientScript.php +++ b/gui/baculum/protected/Common/Class/BClientScript.php @@ -31,7 +31,7 @@ Prado::using('System.Web.UI.WebControls.TClientScript'); */ class BClientScript extends TClientScript { - const SCRIPTS_VERSION = 22; + const SCRIPTS_VERSION = 23; public function getScriptUrl() { diff --git a/gui/baculum/protected/Common/Class/Params.php b/gui/baculum/protected/Common/Class/Params.php index 94f5d92f2..34038340f 100644 --- a/gui/baculum/protected/Common/Class/Params.php +++ b/gui/baculum/protected/Common/Class/Params.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2020 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -66,69 +66,136 @@ class Params extends CommonModule { 'sat' => 'Saturday' ); - public static function getMonthsConfig(array $months_cfg) { + /** + * Get time value in config form. + * Possible is of three modes: + * - hourly at specified minute + * - hourly on every full hour + * - daily at specified hour and minute + * + * @param string $hour time hour + * @param string $minute time minute + * @return string time config value + */ + public static function getTimeConfig(array $hour, $minute) { + $t = ''; + $hour_len = count($hour); + $is_hourly = ($hour_len == 24); + $is_daily = ($hour_len == 1); + if ($is_hourly && is_int($minute) && $minute > 0) { + // hourly at minute + $min = sprintf('%02d', $minute); + $t = "hourly at 0:{$min}"; + } elseif ($is_daily && is_int($minute)) { + // at specified hour and minute + $min = sprintf('%02d', $minute); + $t = "at {$hour[0]}:{$min}"; + } else { + // hourly every full hour + $t = 'hourly'; + } + return $t; + } + /** + * Get months of the year value in config form. + * + * @param array $moys_cfg month array (ex. [0,1,2,3,4]) + * @return string months of the year config value + */ + public static function getMonthsOfYearConfig(array $moys_cfg) { $month = ''; - $month_count = count($months_cfg); $months = array_keys(Params::$months); - if ($month_count < 12) { - if ($month_count > 1) { - $month_start = $months_cfg[0]; - $month_end = $months_cfg[$month_count-1]; - $month .= $months[$month_start] . '-' . $months[$month_end]; - } else { - $month .= $months[$months_cfg[0]]; + $moys_len = count($moys_cfg); + if ($moys_len < 12) { + $moy_value_cfg = []; + for ($i = 0; $i < $moys_len; $i++) { + $moy_value_cfg[] = $months[$moys_cfg[$i]]; } + $month = implode(',', $moy_value_cfg); } return $month; } - public static function getWeeksConfig(array $weeks_cfg) { + /** + * Get weeks of the month value in config form. + * + * @param array $woms_cfg week array (ex. [0,1,4]) + * @return string weeks of the month config value + */ + public static function getWeeksOfMonthConfig(array $woms_cfg) { $week = ''; - $week_count = count($weeks_cfg); + $woms_len = count($woms_cfg); $weeks = array_keys(Params::$weeks); - if ($week_count < 6) { - if ($week_count > 1) { - $week_start = $weeks_cfg[0]; - $week_end = $weeks_cfg[$week_count-1]; - $week .= $weeks[$week_start] . '-' . $weeks[$week_end]; - } else { - $week .= $weeks[$weeks_cfg[0]]; + if ($woms_len < 6) { + $wom_value_cfg = []; + for ($i = 0; $i < $woms_len; $i++) { + $wom_value_cfg[] = $weeks[$woms_cfg[$i]]; } + $week = implode(',', $wom_value_cfg); } return $week; } - public static function getWdaysConfig(array $wdays_cfg) { + /** + * Get days of the week value in config form. + * + * @param array $dows_cfg day array (ex. [0,1,5]) + * @return string days of the week config value + */ + public static function getDaysOfWeekConfig(array $dows_cfg) { $wday = ''; - $wday_count = count($wdays_cfg); + $dows_len = count($dows_cfg); $wdays = array_keys(Params::$wdays); - if ($wday_count < 7) { - if ($wday_count > 1) { - $wday_start = $wdays_cfg[0]; - $wday_end = $wdays_cfg[$wday_count-1]; - $wday .= $wdays[$wday_start] . '-' . $wdays[$wday_end]; - } else { - $wday .= $wdays[$wdays_cfg[0]]; + if ($dows_len < 7) { + $dow_value_cfg = []; + for ($i = 0; $i < $dows_len; $i++) { + $dow_value_cfg[] = $wdays[$dows_cfg[$i]]; } + $wday = implode(',', $dow_value_cfg); } return $wday; } /** - * Get day value in config form. + * Get days of the month value in config form. + * Zero-length $doms_cfg means lastday of the month. * - * @param array $days_cfg days array (ex. array(0,1,2,3,4)) - * @return string days config value + * @param array $doms_cfg day array (ex. [0,1,5,22,30]) + * @return string days of the month config value */ - public static function getDaysConfig(array $days_cfg) { + public static function getDaysOfMonthConfig(array $doms_cfg) { $days = ''; - if (count($days_cfg) < 31) { - $days_map = array_map(array('Params', 'getDayByNo') , $days_cfg); - $days = implode(',', $days_map); + $doms_len = count($doms_cfg); + if ($doms_len === 0) { + $days = 'on lastday'; + } elseif ($doms_len < 31) { + $doms_w = array_map(function($el) { + return ++$el; + }, $doms_cfg); + $days = 'on ' . implode(',', $doms_w); } return $days; } + /** + * Get weeks of year value in config form. + * + * @param array $woy_cfg week array (ex. array(0,1,2,3,4)) + * @return string weeks of the year config value + */ + public static function getWeeksOfYearConfig(array $woys_cfg) { + $weeks = ''; + $woys_len = count($woys_cfg); + if ($woys_len < 54) { + $woys_w = array_map(function($el) { + return ('w' . sprintf('%02d', $el)); + }, $woys_cfg); + $weeks = implode(',', $woys_w); + } + return $weeks; + } + + /** * Simple method to prepare day config value by day number. * diff --git a/gui/baculum/protected/Web/Lang/en/messages.mo b/gui/baculum/protected/Web/Lang/en/messages.mo index 2cd01f7e4..1e4002bf8 100644 Binary files a/gui/baculum/protected/Web/Lang/en/messages.mo and b/gui/baculum/protected/Web/Lang/en/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/en/messages.po b/gui/baculum/protected/Web/Lang/en/messages.po index 70e007b05..11109dfbc 100644 --- a/gui/baculum/protected/Web/Lang/en/messages.po +++ b/gui/baculum/protected/Web/Lang/en/messages.po @@ -3589,3 +3589,144 @@ msgstr "New backup job wizard" msgid "This wizard enables you to create in easy way a new backup job." msgstr "This wizard enables you to create in easy way a new backup job." + +msgid "Monday" +msgstr "Monday" + +msgid "Tuesday" +msgstr "Tuesday" + +msgid "Wednesday" +msgstr "Wednesday" + +msgid "Thursday" +msgstr "Thursday" + +msgid "Friday" +msgstr "Friday" + +msgid "Saturday" +msgstr "Saturday" + +msgid "Sunday" +msgstr "Sunday" + +msgid "Days of the week" +msgstr "Days of the week" + +msgid "Weeks of the month" +msgstr "Weeks of the month" + +msgid "first" +msgstr "first" + +msgid "second" +msgstr "second" + +msgid "third" +msgstr "third" + +msgid "fourth" +msgstr "fourth" + +msgid "fifth" +msgstr "fifth" + +msgid "sixth" +msgstr "sixth" + +msgid "Days of the month" +msgstr "Days of the month" + +msgid "Weeks of the year" +msgstr "Weeks of the year" + +msgid "All weeks" +msgstr "All weeks" + +msgid "All days" +msgstr "All days" + +msgid "Run at specified HH:MM" +msgstr "Run at specified HH:MM" + +msgid "Run at" +msgstr "Run at" + +msgid "All months" +msgstr "All months" + +msgid "January" +msgstr "January" + +msgid "February" +msgstr "February" + +msgid "March" +msgstr "March" + +msgid "April" +msgstr "April" + +msgid "May" +msgstr "May" + +msgid "June" +msgstr "June" + +msgid "July" +msgstr "July" + +msgid "August" +msgstr "August" + +msgid "September" +msgstr "September" + +msgid "October" +msgstr "October" + +msgid "November" +msgstr "November" + +msgid "December" +msgstr "December" + +msgid "Last day of the month" +msgstr "Last day of the month" + +msgid "Months of the year" +msgstr "Months of the year" + +msgid "Hourly" +msgstr "Hourly" + +msgid "Daily" +msgstr "Daily" + +msgid "Weekly" +msgstr "Weekly" + +msgid "Monthly" +msgstr "Monthly" + +msgid "Custom" +msgstr "Custom" + +msgid "Run job every hour at the specified minute" +msgstr "Run job every hour at the specified minute" + +msgid "Run job every day at the specified time" +msgstr "Run job every day at the specified time" + +msgid "Run job every week at the specified time on selected days of the week" +msgstr "Run job every week at the specified time on selected days of the week" + +msgid "Run job every month at the specified time in selected weeks of the month" +msgstr "Run job every month at the specified time in selected weeks of the month" + +msgid "Setup your custom schedule" +msgstr "Setup your custom schedule" + +msgid "Override directives" +msgstr "Override directives" diff --git a/gui/baculum/protected/Web/Lang/ja/messages.mo b/gui/baculum/protected/Web/Lang/ja/messages.mo index 960a676bb..0894da3ba 100644 Binary files a/gui/baculum/protected/Web/Lang/ja/messages.mo and b/gui/baculum/protected/Web/Lang/ja/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/ja/messages.po b/gui/baculum/protected/Web/Lang/ja/messages.po index 35e2c927e..eb7b7e012 100644 --- a/gui/baculum/protected/Web/Lang/ja/messages.po +++ b/gui/baculum/protected/Web/Lang/ja/messages.po @@ -3675,3 +3675,144 @@ msgstr "New backup job wizard" msgid "This wizard enables you to create in easy way a new backup job." msgstr "This wizard enables you to create in easy way a new backup job." + +msgid "Monday" +msgstr "Monday" + +msgid "Tuesday" +msgstr "Tuesday" + +msgid "Wednesday" +msgstr "Wednesday" + +msgid "Thursday" +msgstr "Thursday" + +msgid "Friday" +msgstr "Friday" + +msgid "Saturday" +msgstr "Saturday" + +msgid "Sunday" +msgstr "Sunday" + +msgid "Days of the week" +msgstr "Days of the week" + +msgid "Weeks of the month" +msgstr "Weeks of the month" + +msgid "first" +msgstr "first" + +msgid "second" +msgstr "second" + +msgid "third" +msgstr "third" + +msgid "fourth" +msgstr "fourth" + +msgid "fifth" +msgstr "fifth" + +msgid "sixth" +msgstr "sixth" + +msgid "Days of the month" +msgstr "Days of the month" + +msgid "Weeks of the year" +msgstr "Weeks of the year" + +msgid "All weeks" +msgstr "All weeks" + +msgid "All days" +msgstr "All days" + +msgid "Run at specified HH:MM" +msgstr "Run at specified HH:MM" + +msgid "Run at" +msgstr "Run at" + +msgid "All months" +msgstr "All months" + +msgid "January" +msgstr "January" + +msgid "February" +msgstr "February" + +msgid "March" +msgstr "March" + +msgid "April" +msgstr "April" + +msgid "May" +msgstr "May" + +msgid "June" +msgstr "June" + +msgid "July" +msgstr "July" + +msgid "August" +msgstr "August" + +msgid "September" +msgstr "September" + +msgid "October" +msgstr "October" + +msgid "November" +msgstr "November" + +msgid "December" +msgstr "December" + +msgid "Last day of the month" +msgstr "Last day of the month" + +msgid "Months of the year" +msgstr "Months of the year" + +msgid "Hourly" +msgstr "Hourly" + +msgid "Daily" +msgstr "Daily" + +msgid "Weekly" +msgstr "Weekly" + +msgid "Monthly" +msgstr "Monthly" + +msgid "Custom" +msgstr "Custom" + +msgid "Run job every hour at the specified minute" +msgstr "Run job every hour at the specified minute" + +msgid "Run job every day at the specified time" +msgstr "Run job every day at the specified time" + +msgid "Run job every week at the specified time on selected days of the week" +msgstr "Run job every week at the specified time on selected days of the week" + +msgid "Run job every month at the specified time in selected weeks of the month" +msgstr "Run job every month at the specified time in selected weeks of the month" + +msgid "Setup your custom schedule" +msgstr "Setup your custom schedule" + +msgid "Override directives" +msgstr "Override directives" diff --git a/gui/baculum/protected/Web/Lang/pl/messages.mo b/gui/baculum/protected/Web/Lang/pl/messages.mo index 55eb17021..b3926e400 100644 Binary files a/gui/baculum/protected/Web/Lang/pl/messages.mo and b/gui/baculum/protected/Web/Lang/pl/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pl/messages.po b/gui/baculum/protected/Web/Lang/pl/messages.po index 4c6fe2b0c..08df61c18 100644 --- a/gui/baculum/protected/Web/Lang/pl/messages.po +++ b/gui/baculum/protected/Web/Lang/pl/messages.po @@ -3599,3 +3599,144 @@ msgstr "Kreator nowego zadania backupu" msgid "This wizard enables you to create in easy way a new backup job." msgstr "Ten kreator umożliwia tworzenie w łatwy sposób nowego zadania backupu." + +msgid "Monday" +msgstr "Monday" + +msgid "Tuesday" +msgstr "Tuesday" + +msgid "Wednesday" +msgstr "Wednesday" + +msgid "Thursday" +msgstr "Thursday" + +msgid "Friday" +msgstr "Friday" + +msgid "Saturday" +msgstr "Saturday" + +msgid "Sunday" +msgstr "Sunday" + +msgid "Days of the week" +msgstr "Days of the week" + +msgid "Weeks of the month" +msgstr "Weeks of the month" + +msgid "first" +msgstr "first" + +msgid "second" +msgstr "second" + +msgid "third" +msgstr "third" + +msgid "fourth" +msgstr "fourth" + +msgid "fifth" +msgstr "fifth" + +msgid "sixth" +msgstr "sixth" + +msgid "Days of the month" +msgstr "Days of the month" + +msgid "Weeks of the year" +msgstr "Weeks of the year" + +msgid "All weeks" +msgstr "All weeks" + +msgid "All days" +msgstr "All days" + +msgid "Run at specified HH:MM" +msgstr "Run at specified HH:MM" + +msgid "Run at" +msgstr "Run at" + +msgid "All months" +msgstr "All months" + +msgid "January" +msgstr "January" + +msgid "February" +msgstr "February" + +msgid "March" +msgstr "March" + +msgid "April" +msgstr "April" + +msgid "May" +msgstr "May" + +msgid "June" +msgstr "June" + +msgid "July" +msgstr "July" + +msgid "August" +msgstr "August" + +msgid "September" +msgstr "September" + +msgid "October" +msgstr "October" + +msgid "November" +msgstr "November" + +msgid "December" +msgstr "December" + +msgid "Last day of the month" +msgstr "Last day of the month" + +msgid "Months of the year" +msgstr "Months of the year" + +msgid "Hourly" +msgstr "Hourly" + +msgid "Daily" +msgstr "Daily" + +msgid "Weekly" +msgstr "Weekly" + +msgid "Monthly" +msgstr "Monthly" + +msgid "Custom" +msgstr "Custom" + +msgid "Run job every hour at the specified minute" +msgstr "Run job every hour at the specified minute" + +msgid "Run job every day at the specified time" +msgstr "Run job every day at the specified time" + +msgid "Run job every week at the specified time on selected days of the week" +msgstr "Run job every week at the specified time on selected days of the week" + +msgid "Run job every month at the specified time in selected weeks of the month" +msgstr "Run job every month at the specified time in selected weeks of the month" + +msgid "Setup your custom schedule" +msgstr "Setup your custom schedule" + +msgid "Override directives" +msgstr "Override directives" diff --git a/gui/baculum/protected/Web/Lang/pt/messages.mo b/gui/baculum/protected/Web/Lang/pt/messages.mo index 22e565360..e9d410fbe 100644 Binary files a/gui/baculum/protected/Web/Lang/pt/messages.mo and b/gui/baculum/protected/Web/Lang/pt/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/pt/messages.po b/gui/baculum/protected/Web/Lang/pt/messages.po index 07a66cd26..c3219c7b7 100644 --- a/gui/baculum/protected/Web/Lang/pt/messages.po +++ b/gui/baculum/protected/Web/Lang/pt/messages.po @@ -3599,3 +3599,144 @@ msgstr "New backup job wizard" msgid "This wizard enables you to create in easy way a new backup job." msgstr "This wizard enables you to create in easy way a new backup job." + +msgid "Monday" +msgstr "Monday" + +msgid "Tuesday" +msgstr "Tuesday" + +msgid "Wednesday" +msgstr "Wednesday" + +msgid "Thursday" +msgstr "Thursday" + +msgid "Friday" +msgstr "Friday" + +msgid "Saturday" +msgstr "Saturday" + +msgid "Sunday" +msgstr "Sunday" + +msgid "Days of the week" +msgstr "Days of the week" + +msgid "Weeks of the month" +msgstr "Weeks of the month" + +msgid "first" +msgstr "first" + +msgid "second" +msgstr "second" + +msgid "third" +msgstr "third" + +msgid "fourth" +msgstr "fourth" + +msgid "fifth" +msgstr "fifth" + +msgid "sixth" +msgstr "sixth" + +msgid "Days of the month" +msgstr "Days of the month" + +msgid "Weeks of the year" +msgstr "Weeks of the year" + +msgid "All weeks" +msgstr "All weeks" + +msgid "All days" +msgstr "All days" + +msgid "Run at specified HH:MM" +msgstr "Run at specified HH:MM" + +msgid "Run at" +msgstr "Run at" + +msgid "All months" +msgstr "All months" + +msgid "January" +msgstr "January" + +msgid "February" +msgstr "February" + +msgid "March" +msgstr "March" + +msgid "April" +msgstr "April" + +msgid "May" +msgstr "May" + +msgid "June" +msgstr "June" + +msgid "July" +msgstr "July" + +msgid "August" +msgstr "August" + +msgid "September" +msgstr "September" + +msgid "October" +msgstr "October" + +msgid "November" +msgstr "November" + +msgid "December" +msgstr "December" + +msgid "Last day of the month" +msgstr "Last day of the month" + +msgid "Months of the year" +msgstr "Months of the year" + +msgid "Hourly" +msgstr "Hourly" + +msgid "Daily" +msgstr "Daily" + +msgid "Weekly" +msgstr "Weekly" + +msgid "Monthly" +msgstr "Monthly" + +msgid "Custom" +msgstr "Custom" + +msgid "Run job every hour at the specified minute" +msgstr "Run job every hour at the specified minute" + +msgid "Run job every day at the specified time" +msgstr "Run job every day at the specified time" + +msgid "Run job every week at the specified time on selected days of the week" +msgstr "Run job every week at the specified time on selected days of the week" + +msgid "Run job every month at the specified time in selected weeks of the month" +msgstr "Run job every month at the specified time in selected weeks of the month" + +msgid "Setup your custom schedule" +msgstr "Setup your custom schedule" + +msgid "Override directives" +msgstr "Override directives" diff --git a/gui/baculum/protected/Web/Lang/ru/messages.mo b/gui/baculum/protected/Web/Lang/ru/messages.mo index 6dc6583ed..6d9532b09 100644 Binary files a/gui/baculum/protected/Web/Lang/ru/messages.mo and b/gui/baculum/protected/Web/Lang/ru/messages.mo differ diff --git a/gui/baculum/protected/Web/Lang/ru/messages.po b/gui/baculum/protected/Web/Lang/ru/messages.po index b2064e46d..0b1be3bec 100644 --- a/gui/baculum/protected/Web/Lang/ru/messages.po +++ b/gui/baculum/protected/Web/Lang/ru/messages.po @@ -3600,3 +3600,144 @@ msgstr "Мастер нового задания" msgid "This wizard enables you to create in easy way a new backup job." msgstr "Этот мастер позволяет вам легко создать новое задание." + +msgid "Monday" +msgstr "Monday" + +msgid "Tuesday" +msgstr "Tuesday" + +msgid "Wednesday" +msgstr "Wednesday" + +msgid "Thursday" +msgstr "Thursday" + +msgid "Friday" +msgstr "Friday" + +msgid "Saturday" +msgstr "Saturday" + +msgid "Sunday" +msgstr "Sunday" + +msgid "Days of the week" +msgstr "Days of the week" + +msgid "Weeks of the month" +msgstr "Weeks of the month" + +msgid "first" +msgstr "first" + +msgid "second" +msgstr "second" + +msgid "third" +msgstr "third" + +msgid "fourth" +msgstr "fourth" + +msgid "fifth" +msgstr "fifth" + +msgid "sixth" +msgstr "sixth" + +msgid "Days of the month" +msgstr "Days of the month" + +msgid "Weeks of the year" +msgstr "Weeks of the year" + +msgid "All weeks" +msgstr "All weeks" + +msgid "All days" +msgstr "All days" + +msgid "Run at specified HH:MM" +msgstr "Run at specified HH:MM" + +msgid "Run at" +msgstr "Run at" + +msgid "All months" +msgstr "All months" + +msgid "January" +msgstr "January" + +msgid "February" +msgstr "February" + +msgid "March" +msgstr "March" + +msgid "April" +msgstr "April" + +msgid "May" +msgstr "May" + +msgid "June" +msgstr "June" + +msgid "July" +msgstr "July" + +msgid "August" +msgstr "August" + +msgid "September" +msgstr "September" + +msgid "October" +msgstr "October" + +msgid "November" +msgstr "November" + +msgid "December" +msgstr "December" + +msgid "Last day of the month" +msgstr "Last day of the month" + +msgid "Months of the year" +msgstr "Months of the year" + +msgid "Hourly" +msgstr "Hourly" + +msgid "Daily" +msgstr "Daily" + +msgid "Weekly" +msgstr "Weekly" + +msgid "Monthly" +msgstr "Monthly" + +msgid "Custom" +msgstr "Custom" + +msgid "Run job every hour at the specified minute" +msgstr "Run job every hour at the specified minute" + +msgid "Run job every day at the specified time" +msgstr "Run job every day at the specified time" + +msgid "Run job every week at the specified time on selected days of the week" +msgstr "Run job every week at the specified time on selected days of the week" + +msgid "Run job every month at the specified time in selected weeks of the month" +msgstr "Run job every month at the specified time in selected weeks of the month" + +msgid "Setup your custom schedule" +msgstr "Setup your custom schedule" + +msgid "Override directives" +msgstr "Override directives" diff --git a/gui/baculum/protected/Web/Pages/DirectorView.php b/gui/baculum/protected/Web/Pages/DirectorView.php index 35c507cec..614a8bb07 100644 --- a/gui/baculum/protected/Web/Pages/DirectorView.php +++ b/gui/baculum/protected/Web/Pages/DirectorView.php @@ -49,6 +49,7 @@ class DirectorView extends BaculumWebPage { $this->DirDirectorConfig->setComponentName($component_name); $this->DirDirectorConfig->setResourceName($component_name); $this->DirDirectorConfig->setLoadValues(true); + $this->DirDirectorConfig->IsDirectiveCreated = false; $this->DirDirectorConfig->raiseEvent('OnDirectiveListLoad', $this, null); } } diff --git a/gui/baculum/protected/Web/Pages/NewBackupJobWizard.page b/gui/baculum/protected/Web/Pages/NewBackupJobWizard.page index 5b0e5d95a..3b4dec135 100644 --- a/gui/baculum/protected/Web/Pages/NewBackupJobWizard.page +++ b/gui/baculum/protected/Web/Pages/NewBackupJobWizard.page @@ -73,7 +73,6 @@ @@ -101,7 +100,6 @@ @@ -127,7 +125,6 @@ <%[ Create job ]%>   @@ -211,11 +208,14 @@ SaveDirectiveActionOk="$('#job_wizard_new_fileset').slideUp(); set_new_fileset(); $('#fileset_save_ok').show();" /> + @@ -315,11 +315,14 @@ /> + @@ -451,11 +454,14 @@ /> + diff --git a/gui/baculum/protected/Web/Pages/NewBackupJobWizard.php b/gui/baculum/protected/Web/Pages/NewBackupJobWizard.php index 54c6d0597..2421031be 100644 --- a/gui/baculum/protected/Web/Pages/NewBackupJobWizard.php +++ b/gui/baculum/protected/Web/Pages/NewBackupJobWizard.php @@ -36,23 +36,11 @@ class NewBackupJobWizard extends BaculumWebPage { const PREV_STEP = 'PrevStep'; const JOBDEFS = 'JobDefs'; - public function onLoad($param) { - parent::onLoad($param); - $this->JobDefs->saveDirective(); - $this->Client->saveDirective(); - $this->Fileset->saveDirective(); - $this->Storage->saveDirective(); - $this->Pool->saveDirective(); - $this->FullBackupPool->saveDirective(); - $this->IncrementalBackupPool->saveDirective(); - $this->DifferentialBackupPool->saveDirective(); - $this->Level->saveDirective(); - $this->Messages->saveDirective(); - $this->Schedule->saveDirective(); - } - - public function onLoadComplete($param) { - parent::onLoadComplete($param); + public function onPreRender($param) { + parent::onPreRender($param); + if ($this->IsCallBack) { + return; + } $step_index = $this->NewJobWizard->getActiveStepIndex(); $prev_step = $this->getPrevStep(); $this->setPrevStep($step_index); @@ -120,13 +108,15 @@ class NewBackupJobWizard extends BaculumWebPage { */ public function loadJobDefs() { $jobdefs_list = array(); - $jobdefs = $this->getModule('api')->get(array('config', 'dir', 'jobdefs'))->output; + $jobdefs = $this->getModule('api')->get([ + 'config', 'dir', 'jobdefs' + ])->output; for ($i = 0; $i < count($jobdefs); $i++) { $jobdefs_list[] = $jobdefs[$i]->JobDefs->Name; } asort($jobdefs_list); $this->JobDefs->setData($jobdefs_list); - $this->JobDefs->onLoad(null); + $this->JobDefs->createDirective(); } /** @@ -140,9 +130,9 @@ class NewBackupJobWizard extends BaculumWebPage { return; } $jobdefs = rawurlencode($directive_value); - $result = $this->getModule('api')->get(array( + $result = $this->getModule('api')->get([ 'config', 'dir', 'jobdefs', $jobdefs - )); + ]); if ($result->error === 0) { $value = (array)$result->output; $this->setJobDefs($value); @@ -177,7 +167,7 @@ class NewBackupJobWizard extends BaculumWebPage { if (key_exists('Client', $jobdefs) && is_null($this->Client->getDirectiveValue())) { $this->Client->setDirectiveValue($jobdefs['Client']); } - $this->Client->onLoad(null); + $this->Client->createDirective(); } /** @@ -186,6 +176,14 @@ class NewBackupJobWizard extends BaculumWebPage { * @return none */ public function loadFilesets() { + $this->loadFilesetList(null, null); + $jobdefs = $this->getJobDefs(); + if (key_exists('Fileset', $jobdefs) && is_null($this->Fileset->getDirectiveValue())) { + $this->Fileset->setDirectiveValue($jobdefs['Fileset']); + } + } + + public function loadFilesetList($sender, $param) { $fileset_list = array(); $filesets = $this->getModule('api')->get(array('config', 'dir', 'fileset'))->output; for ($i = 0; $i < count($filesets); $i++) { @@ -193,11 +191,7 @@ class NewBackupJobWizard extends BaculumWebPage { } asort($fileset_list); $this->Fileset->setData($fileset_list); - $jobdefs = $this->getJobDefs(); - if (key_exists('Fileset', $jobdefs) && is_null($this->Fileset->getDirectiveValue())) { - $this->Fileset->setDirectiveValue($jobdefs['Fileset']); - } - $this->Fileset->onLoad(null); + $this->Fileset->createDirective(); } /** @@ -264,8 +258,8 @@ class NewBackupJobWizard extends BaculumWebPage { $jobdefs = $this->getJobDefs(); if (key_exists('Storage', $jobdefs) && is_array($jobdefs['Storage']) && count($jobdefs['Storage']) == 1 && is_null($this->Storage->getDirectiveValue())) { $this->Storage->setDirectiveValue($jobdefs['Storage'][0]); + $this->Storage->createDirective(); } - $this->Storage->onLoad(null); if (key_exists('SpoolData', $jobdefs) && is_null($this->SpoolData->getDirectiveValue())) { $this->SpoolData->setDirectiveValue($jobdefs['SpoolData']); $this->SpoolData->createDirective(); @@ -286,33 +280,39 @@ class NewBackupJobWizard extends BaculumWebPage { * @return none */ public function loadPools() { - $pool_list = array(); - $pools = $this->getModule('api')->get(array('config', 'dir', 'pool'))->output; - for ($i = 0; $i < count($pools); $i++) { - $pool_list[] = $pools[$i]->Pool->Name; - } - asort($pool_list); - $this->Pool->setData($pool_list); + $pool_list = $this->loadPoolList(null, null); $jobdefs = $this->getJobDefs(); $this->FullBackupPool->setData($pool_list); if (key_exists('FullBackupPool', $jobdefs) && is_null($this->FullBackupPool->getDirectiveValue())) { $this->FullBackupPool->setDirectiveValue($jobdefs['FullBackupPool']); } - $this->FullBackupPool->onLoad(null); + $this->FullBackupPool->createDirective(); $this->IncrementalBackupPool->setData($pool_list); if (key_exists('IncrementalBackupPool', $jobdefs) && is_null($this->IncrementalBackupPool->getDirectiveValue())) { $this->IncrementalBackupPool->setDirectiveValue($jobdefs['IncrementalBackupPool']); } - $this->IncrementalBackupPool->onLoad(null); + $this->IncrementalBackupPool->createDirective(); $this->DifferentialBackupPool->setData($pool_list); if (key_exists('DifferentialBackupPool', $jobdefs) && is_null($this->DifferentialBackupPool->getDirectiveValue())) { $this->DifferentialBackupPool->setDirectiveValue($jobdefs['DifferentialBackupPool']); } - $this->DifferentialBackupPool->onLoad(null); + $this->DifferentialBackupPool->createDirective(); if (key_exists('Pool', $jobdefs) && is_null($this->Pool->getDirectiveValue())) { $this->Pool->setDirectiveValue($jobdefs['Pool']); } - $this->Pool->onLoad(null); + $this->Pool->createDirective(); + } + + public function loadPoolList($sender, $param) { + $pool_list = array(); + $pools = $this->getModule('api')->get(array('config', 'dir', 'pool'))->output; + for ($i = 0; $i < count($pools); $i++) { + $pool_list[] = $pools[$i]->Pool->Name; + } + asort($pool_list); + $this->Pool->setData($pool_list); + $this->Pool->createDirective(); + return $pool_list; } public function loadBackupJobDirectives() { @@ -371,7 +371,7 @@ class NewBackupJobWizard extends BaculumWebPage { if (key_exists('Level', $jobdefs)) { $this->Level->setDirectiveValue($jobdefs['Level']); } - $this->Level->onLoad(null); + $this->Level->createDirective(); } /** * Load messages. @@ -390,7 +390,7 @@ class NewBackupJobWizard extends BaculumWebPage { if (key_exists('Messages', $jobdefs)) { $this->Messages->setDirectiveValue($jobdefs['Messages']); } - $this->Messages->onLoad(null); + $this->Messages->createDirective(); } /** @@ -399,6 +399,15 @@ class NewBackupJobWizard extends BaculumWebPage { * @return none */ public function loadSchedules() { + $this->loadScheduleList(null, null); + $jobdefs = $this->getJobDefs(); + if (key_exists('Schedule', $jobdefs)) { + $this->Schedule->setDirectiveValue($jobdefs['Schedule']); + } + $this->Schedule->createDirective(); + } + + public function loadScheduleList($sender, $param) { $schedule_list = array(); $schedules = $this->getModule('api')->get(array('config', 'dir', 'schedule'))->output; for ($i = 0; $i < count($schedules); $i++) { @@ -406,11 +415,7 @@ class NewBackupJobWizard extends BaculumWebPage { } asort($schedule_list); $this->Schedule->setData($schedule_list); - $jobdefs = $this->getJobDefs(); - if (key_exists('Schedule', $jobdefs)) { - $this->Schedule->setDirectiveValue($jobdefs['Schedule']); - } - $this->Schedule->onLoad(null); + $this->Schedule->createDirective(); } public function wizardCompleted($sender, $param) { diff --git a/gui/baculum/protected/Web/Pages/NewCopyJobWizard.page b/gui/baculum/protected/Web/Pages/NewCopyJobWizard.page index dc6176292..9ae29dd9e 100644 --- a/gui/baculum/protected/Web/Pages/NewCopyJobWizard.page +++ b/gui/baculum/protected/Web/Pages/NewCopyJobWizard.page @@ -73,7 +73,6 @@ @@ -101,7 +100,6 @@ @@ -127,7 +125,6 @@ <%[ Create job ]%>   @@ -1754,7 +1751,7 @@ function show_storage_warning(storage, pool, jobs) { JobDefs->saveDirective(); - $this->Pool->saveDirective(); - $this->SelectionType->saveDirective(); - $this->NextPool->saveDirective(); - $this->SourceStorage->saveDirective(); - $this->DestinationStorage->saveDirective(); - $this->Messages->saveDirective(); - $this->Schedule->saveDirective(); - $this->Level->saveDirective(); - $this->Client->saveDirective(); - $this->FileSet->saveDirective(); - } - - public function onLoadComplete($param) { - parent::onLoadComplete($param); + public function onPreRender($param) { + parent::onPreRender($param); + if ($this->IsCallBack) { + return; + } $step_index = $this->NewJobWizard->getActiveStepIndex(); $prev_step = $this->getPrevStep(); $this->setPrevStep($step_index); @@ -148,7 +136,7 @@ class NewCopyJobWizard extends BaculumWebPage { } asort($jobdefs_list); $this->JobDefs->setData($jobdefs_list); - $this->JobDefs->onLoad(null); + $this->JobDefs->createDirective(); } } @@ -212,7 +200,7 @@ class NewCopyJobWizard extends BaculumWebPage { if (key_exists($name, $jobdefs) && is_null($control->getDirectiveValue())) { $control->setDirectiveValue($jobdefs[$name]); } - $control->onLoad(null); + $control->createDirective(); } /** @@ -300,7 +288,7 @@ class NewCopyJobWizard extends BaculumWebPage { */ public function loadSelectionTypes() { $this->SelectionType->setData($this->sel_types); - $this->SelectionType->onLoad(null); + $this->SelectionType->createDirective(); } /** @@ -384,7 +372,7 @@ class NewCopyJobWizard extends BaculumWebPage { if (key_exists('Storage', $jobdefs) && is_array($jobdefs['Storage']) && count($jobdefs['Storage']) == 1 && is_null($control->getDirectiveValue())) { $control->setDirectiveValue($jobdefs['Storage'][0]); } - $control->onLoad(null); + $control->createDirective(); } } @@ -490,7 +478,7 @@ class NewCopyJobWizard extends BaculumWebPage { if (key_exists('Messages', $jobdefs)) { $this->Messages->setDirectiveValue($jobdefs['Messages']); } - $this->Messages->onLoad(null); + $this->Messages->createDirective(); } } @@ -516,7 +504,7 @@ class NewCopyJobWizard extends BaculumWebPage { if (key_exists('Schedule', $jobdefs)) { $this->Schedule->setDirectiveValue($jobdefs['Schedule']); } - $this->Schedule->onLoad(null); + $this->Schedule->createDirective(); } } @@ -537,7 +525,7 @@ class NewCopyJobWizard extends BaculumWebPage { // no level in jobdefs, take first level $this->Level->setDirectiveValue($level_list[0]); } - $this->Level->onLoad(null); + $this->Level->createDirective(); } /** @@ -563,7 +551,7 @@ class NewCopyJobWizard extends BaculumWebPage { } elseif (count($client_list) > 0) { $this->Client->setDirectiveValue($client_list[0]); } - $this->Client->onLoad(null); + $this->Client->createDirective(); } } @@ -590,7 +578,7 @@ class NewCopyJobWizard extends BaculumWebPage { } elseif (count($fileset_list) > 0) { $this->FileSet->setDirectiveValue($fileset_list[0]); } - $this->FileSet->onLoad(null); + $this->FileSet->createDirective(); } } diff --git a/gui/baculum/protected/Web/Pages/Security.php b/gui/baculum/protected/Web/Pages/Security.php index a773d4687..07ab40b0a 100644 --- a/gui/baculum/protected/Web/Pages/Security.php +++ b/gui/baculum/protected/Web/Pages/Security.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2020 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -1279,6 +1279,7 @@ class Security extends BaculumWebPage { } $this->ConsoleConfig->setHost($this->User->getDefaultAPIHost()); $this->ConsoleConfig->setComponentName($_SESSION['dir']); + $this->ConsoleConfig->IsDirectiveCreated = false; $this->ConsoleConfig->raiseEvent('OnDirectiveListLoad', $this, null); } @@ -1344,6 +1345,7 @@ class Security extends BaculumWebPage { ] ]; $this->ConsoleConfig->setData($config); + $this->ConsoleConfig->IsDirectiveCreated = false; $this->ConsoleConfig->raiseEvent('OnDirectiveListLoad', $this, null); $this->getCallbackClient()->callClientFunction('oBaculaConfigSection.show_sections', [true]); } diff --git a/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php b/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php index 5b26246fd..7145a953a 100644 --- a/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php +++ b/gui/baculum/protected/Web/Portlets/BaculaConfigDirectives.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -93,15 +93,6 @@ class BaculaConfigDirectives extends DirectiveListTemplate { } } - public function onPreRender($param) { - /** - * This method overwrites DirectiveListTemplate::onPreRender() - * Not calling parent method is intentional here because this class - * isn't typical control list class and calling parent::onPreRender() - * causes error. - */ - } - private function getConfigData($host, array $parameters) { $default_params = array('config'); $params = array_merge($default_params, $parameters); @@ -115,6 +106,10 @@ class BaculaConfigDirectives extends DirectiveListTemplate { public function loadConfig() { $load_values = $this->getLoadValues(); + if (!$load_values && $this->IsDirectiveCreated) { + // This control is loaded only once, otherwise fields loose assigned values. + return; + } $host = $this->getHost(); $component_type = $this->getComponentType(); @@ -253,6 +248,7 @@ class BaculaConfigDirectives extends DirectiveListTemplate { $this->RepeaterDirectives->DataSource = $directives; $this->RepeaterDirectives->dataBind(); $this->ConfigDirectives->Display = 'Dynamic'; + $this->IsDirectiveCreated = true; } public function loadDirectives($sender, $param) { @@ -286,6 +282,11 @@ class BaculaConfigDirectives extends DirectiveListTemplate { $directive_name = $controls[$j]->getDirectiveName(); $directive_value = $controls[$j]->getDirectiveValue(); + if (is_null($directive_name)) { + // skip controls without data + continue; + } + $default_value = null; if (key_exists($directive_name, $resource_desc)) { $default_value = $resource_desc[$directive_name]->DefaultValue; @@ -356,8 +357,12 @@ class BaculaConfigDirectives extends DirectiveListTemplate { } } $load_values = $this->getLoadValues(); - $res_name_dir = key_exists('Name', $directives) ? $directives['Name'] : ''; + $res_name_dir = key_exists('Name', $directives) ? $directives['Name'] : null; $resource_name = $this->getResourceName(); + if (!$res_name_dir && $resource_name) { + // In some cases with double control load Name value stays empty. Recreate it here. + $directives['Name'] = $res_name_dir = $resource_name; + } if ($load_values === true) { if ($resource_name !== $res_name_dir) { // RENAME RESOURCE diff --git a/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.php b/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.php index 28876cf93..1728223d2 100644 --- a/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.php +++ b/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.php @@ -124,6 +124,7 @@ class BaculaConfigResourceList extends Portlets { $this->ResourceConfig->setComponentType($component_type); $this->ResourceConfig->setComponentName($component_name); $this->ResourceConfig->setResourceType($resource_type); + $this->ResourceConfig->IsDirectiveCreated = false; $this->ResourceConfig->raiseEvent('OnDirectiveListLoad', $this, null); } diff --git a/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.tpl b/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.tpl index 86c1957c1..88bf0967d 100644 --- a/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.tpl +++ b/gui/baculum/protected/Web/Portlets/BaculaConfigResourceList.tpl @@ -133,7 +133,7 @@ var oBaculaConfigResourceList<%=$this->ClientID%> = { -
+
createDirectiveInternal(); - $this->saveDirective(); - parent::onPreRender($param); - } - - public function saveDirective() { - $value = $this->getValue(); - $this->Directive->setSelectedValue($value); - $this->setDirectiveValue($value); - } - public function getValue() { $value = $this->Directive->getSelectedValue(); if (!is_string($value) || empty($value)) { @@ -53,12 +41,11 @@ class DirectiveComboBox extends DirectiveTemplate { return $value; } - public function createDirectiveInternal() { + public function createDirective() { $this->Label->Text = $this->getLabel(); $data = $this->getData(); $resource_names = $this->getResourceNames(); $directive_name = $this->getDirectiveName(); - $required = $this->getRequired(); $resource = $this->getResource(); $in_config = $this->getInConfig(); $items = array(); diff --git a/gui/baculum/protected/Web/Portlets/DirectiveDaysOfMonth.php b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfMonth.php new file mode 100644 index 000000000..c228e8eb1 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfMonth.php @@ -0,0 +1,114 @@ + + * @category Control + * @package Baculum Web + */ +class DirectiveDaysOfMonth extends DirectiveTemplate { + + const SHOW_OPTIONS = 'ShowOptions'; + const DAY_CONTROL_PREFIX = 'day'; + + public function getValue() { + $value = []; + $days = range(1, 31); + for ($i = 0; $i < count($days); $i++) { + if ($this->{self::DAY_CONTROL_PREFIX . $days[$i]}->Checked || $this->AllDaysOfMonth->Checked) { + $value[] = $i; + } + } + if (count($value) == 0) { + $value = $days; + } + if ($this->lastday->Checked) { + $value = []; + } + return $value; + } + + public function createDirective() { + $this->Label->Text = $this->getLabel(); + $directive_value = $this->getDirectiveValue(); + $default_value = $this->getDefaultValue(); + if (!is_array($directive_value)) { + $directive_value = range(0, 30); + } + + $days = range(1, 31); + $d_len = count($days); + $dv_len = count($directive_value); + if ($this->getInConfig() === false && $dv_len == $d_len) { + if (is_array($default_value) && count($default_value) > 0) { + $directive_value = $default_value; + } + } + + for ($i = 0; $i < count($days); $i++) { + $key = self::DAY_CONTROL_PREFIX . $days[$i]; + if ($dv_len > 0 && $dv_len < $d_len) { + // selected days + $this->{$key}->Checked = in_array($i, $directive_value); + } + + if ($this->Disabled) { + $this->{$key}->Enabled = false; + } + if ($this->CssClass) { + $cssclass = $this->CssClass . ' ' . $this->{$key}->getCssClass(); + $this->{$key}->setCssClass($cssclass); + } + } + + // set 'select all' checkbox + if ($this->Disabled) { + $this->AllDaysOfMonth->Enabled = false; + } elseif ($dv_len == $d_len && $this->ShowOptions) { + // all days + $this->AllDaysOfMonth->Checked = true; + } + + // set 'last day of the month' checkbox + if ($dv_len == 0) { + $this->lastday->Checked = true; + } else { + $this->lastday->Checked = false; + } + } + + public function setShowOptions($show) { + $show = TPropertyValue::ensureBoolean($show); + $this->setViewState(self::SHOW_OPTIONS, $show); + } + + public function getShowOptions() { + return $this->getViewState(self::SHOW_OPTIONS, false); + } +} diff --git a/gui/baculum/protected/Web/Portlets/DirectiveDaysOfMonth.tpl b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfMonth.tpl new file mode 100644 index 000000000..b1cb4b04c --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfMonth.tpl @@ -0,0 +1,308 @@ +
+
+ : +
+
+
+   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +
+ +
+
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveDaysOfWeek.php b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfWeek.php new file mode 100644 index 000000000..235bbb587 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfWeek.php @@ -0,0 +1,98 @@ + + * @category Control + * @package Baculum Web + */ +class DirectiveDaysOfWeek extends DirectiveTemplate { + + const SHOW_OPTIONS = 'ShowOptions'; + + public function getValue() { + $value = []; + $wdays = array_values(Params::$wdays); + for ($i = 0; $i < count($wdays); $i++) { + if ($this->{$wdays[$i]}->Checked || $this->AllDaysOfWeek->Checked) { + $value[] = $i; + } + } + if (count($value) == 0) { + $value = range(0, 6); + } + return $value; + } + + public function createDirective() { + $this->Label->Text = $this->getLabel(); + $directive_value = $this->getDirectiveValue(); + $default_value = $this->getDefaultValue(); + $wdays = array_values(Params::$wdays); + if (!is_array($directive_value)) { + $directive_value = $wdays; + } + $wd_len = count($wdays); + $dv_len = count($directive_value); + if ($this->getInConfig() === false && $dv_len == $wd_len) { + if (is_array($default_value) && count($default_value) > 0) { + $directive_value = $default_value; + } + } + + for ($i = 0; $i < $wd_len; $i++) { + if ($dv_len < $wd_len) { + // selected days + $this->{$wdays[$i]}->Checked = in_array($i, $directive_value); + } + if ($this->Disabled) { + $this->{$wdays[$i]}->Enabled = false; + } + if ($this->CssClass) { + $cssclass = $this->CssClass . ' ' . $this->{$wdays[$i]}->getCssClass(); + $this->{$wdays[$i]}->setCssClass($cssclass); + } + } + if ($this->Disabled) { + $this->AllDaysOfWeek->Enabled = false; + } elseif ($dv_len == $wd_len && $this->ShowOptions) { + // all days + $this->AllDaysOfWeek->Checked = true; + } + } + + public function setShowOptions($show) { + $show = TPropertyValue::ensureBoolean($show); + $this->setViewState(self::SHOW_OPTIONS, $show); + } + + public function getShowOptions() { + return $this->getViewState(self::SHOW_OPTIONS, false); + } +} diff --git a/gui/baculum/protected/Web/Portlets/DirectiveDaysOfWeek.tpl b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfWeek.tpl new file mode 100644 index 000000000..c51ea03f9 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveDaysOfWeek.tpl @@ -0,0 +1,86 @@ +
+
+ : +
+
+
+   +
+
+   +   +   +   +   +   +   +
+ +
+
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveFileSet.php b/gui/baculum/protected/Web/Portlets/DirectiveFileSet.php index 64fa90976..6c27c0c48 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveFileSet.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveFileSet.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -286,6 +286,7 @@ class DirectiveFileSet extends DirectiveListTemplate { for ($i = 0; $i < count($this->directive_types); $i++) { $controls = $value->RepeaterFileSetOptions->findControlsByType($this->directive_types[$i]); for ($j = 0; $j < count($controls); $j++) { + $controls[$j]->setValue(); $directive_name = $controls[$j]->getDirectiveName(); $directive_value = $controls[$j]->getDirectiveValue(); $index = $controls[$j]->getGroupName(); @@ -316,6 +317,7 @@ class DirectiveFileSet extends DirectiveListTemplate { $controls = $value->RepeaterFileSetInclude->findControlsByType($this->directive_types[$i]); for ($j = 0; $j < count($controls); $j++) { + $controls[$j]->setValue(); $directive_name = $controls[$j]->getDirectiveName(); $directive_value = $controls[$j]->getDirectiveValue(); if (empty($directive_value)) { @@ -332,6 +334,7 @@ class DirectiveFileSet extends DirectiveListTemplate { } $controls = $value->RepeaterFileSetPlugin->findControlsByType($this->directive_types[$i]); for ($j = 0; $j < count($controls); $j++) { + $controls[$j]->setValue(); $directive_name = $controls[$j]->getDirectiveName(); $directive_value = $controls[$j]->getDirectiveValue(); if (empty($directive_value)) { @@ -375,6 +378,7 @@ class DirectiveFileSet extends DirectiveListTemplate { for ($i = 0; $i < count($this->directive_types); $i++) { $controls = $this->RepeaterFileSetExclude->findControlsByType($this->directive_types[$i]); for ($j = 0; $j < count($controls); $j++) { + $controls[$j]->setValue(); $directive_name = $controls[$j]->getDirectiveName(); $directive_value = $controls[$j]->getDirectiveValue(); if (is_null($directive_value)) { diff --git a/gui/baculum/protected/Web/Portlets/DirectiveListBox.php b/gui/baculum/protected/Web/Portlets/DirectiveListBox.php index 283f308de..79ba93a33 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveListBox.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveListBox.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -33,11 +33,6 @@ Prado::using('Application.Web.Portlets.DirectiveTemplate'); */ class DirectiveListBox extends DirectiveTemplate { - public function onPreRender($param) { - parent::onPreRender($param); - $this->createDirectiveInternal(); - } - public function getValue() { $value = array(); $values = $this->Directive->getSelectedIndices(); @@ -48,7 +43,7 @@ class DirectiveListBox extends DirectiveTemplate { return $value; } - public function createDirectiveInternal() { + public function createDirective() { $this->Label->Text = $this->getLabel(); $data = $this->getData(); $resource_names = $this->getResourceNames(); diff --git a/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php b/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php index 232be6954..bf206146f 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveListTemplate.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -45,6 +45,7 @@ class DirectiveListTemplate extends ConfigListTemplate implements IActiveControl const SHOW = 'Show'; const PARENT_NAME = 'ParentName'; const GROUP_NAME = 'GroupName'; + const IS_DIRECTIVE_CREATED = 'IsDirectiveCreated'; public $display_directive; @@ -69,10 +70,7 @@ class DirectiveListTemplate extends ConfigListTemplate implements IActiveControl public function onPreRender($param) { parent::onPreRender($param); - $cmd = $this->getCmdParam(); - if ($this->getPage()->IsCallBack && (!$cmd || $cmd === 'show_all_directives') && method_exists($this, 'loadConfig')) { - $this->loadConfig(); - } elseif (!$this->getPage()->IsCallBack && !$this->getPage()->IsPostBack) { + if (!$this->getPage()->IsCallBack && !$this->getPage()->IsPostBack) { $this->display_directive = $this->getShow(); } } @@ -188,5 +186,14 @@ class DirectiveListTemplate extends ConfigListTemplate implements IActiveControl public function setGroupName($group_name) { $this->setViewState(self::GROUP_NAME, $group_name); } + + public function getIsDirectiveCreated() { + return $this->getViewState(self::IS_DIRECTIVE_CREATED); + } + + public function setIsDirectiveCreated($is_created) { + $this->setViewState(self::IS_DIRECTIVE_CREATED, $is_created); + } + } ?> diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMessages.php b/gui/baculum/protected/Web/Portlets/DirectiveMessages.php index 2e7b5f818..33359dd29 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveMessages.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveMessages.php @@ -166,6 +166,7 @@ class DirectiveMessages extends DirectiveListTemplate { $directive_values = array(); $where_control = $control->findControlsByType('DirectiveTextBox'); if (count($where_control) === 1 && $where_control[0]->getShow() === true) { + $where_control[0]->setValue(); $directive_values['Where'] = array($where_control[0]->getDirectiveValue()); } $types_control = $control->Types; diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMessages.tpl b/gui/baculum/protected/Web/Portlets/DirectiveMessages.tpl index 0ae54fc23..8a99c2d0d 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveMessages.tpl +++ b/gui/baculum/protected/Web/Portlets/DirectiveMessages.tpl @@ -8,7 +8,6 @@ CssClass="w3-button w3-green w3-right" OnCommand="SourceTemplateControl.removeMessages" CommandName="<%=$this->ItemIndex%>" - CommandParameter="save" >  <%[ Remove ]%> diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMonthsOfYear.php b/gui/baculum/protected/Web/Portlets/DirectiveMonthsOfYear.php new file mode 100644 index 000000000..2d3e8bd72 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveMonthsOfYear.php @@ -0,0 +1,98 @@ + + * @category Control + * @package Baculum Web + */ +class DirectiveMonthsOfYear extends DirectiveTemplate { + + const SHOW_OPTIONS = 'ShowOptions'; + + public function getValue() { + $value = []; + $months = array_values(Params::$months); + for ($i = 0; $i < count($months); $i++) { + if ($this->{$months[$i]}->Checked || $this->AllMonthsOfYear->Checked) { + $value[] = $i; + } + } + if (count($value) == 0) { + $value = range(0, 11); + } + return $value; + } + + public function createDirective() { + $this->Label->Text = $this->getLabel(); + $directive_value = $this->getDirectiveValue(); + $default_value = $this->getDefaultValue(); + $months = array_values(Params::$months); + if (!is_array($directive_value)) { + $directive_value = $months; + } + $m_len = count($months); + $dv_len = count($directive_value); + if ($this->getInConfig() === false && $dv_len == $m_len) { + if (is_array($default_value) && count($default_value) > 0) { + $directive_value = $default_value; + } + } + + for ($i = 0; $i < $m_len; $i++) { + if ($dv_len < $m_len) { + // selected months + $this->{$months[$i]}->Checked = in_array($i, $directive_value); + } + if ($this->Disabled) { + $this->{$months[$i]}->Enabled = false; + } + if ($this->CssClass) { + $cssclass = $this->CssClass . ' ' . $this->{$months[$i]}->getCssClass(); + $this->{$months[$i]}->setCssClass($cssclass); + } + } + if ($this->Disabled) { + $this->AllMonthsOfYear->Enabled = false; + } elseif ($dv_len == $m_len && $this->ShowOptions) { + // all months + $this->AllMonthsOfYear->Checked = true; + } + } + + public function setShowOptions($show) { + $show = TPropertyValue::ensureBoolean($show); + $this->setViewState(self::SHOW_OPTIONS, $show); + } + + public function getShowOptions() { + return $this->getViewState(self::SHOW_OPTIONS, false); + } +} diff --git a/gui/baculum/protected/Web/Portlets/DirectiveMonthsOfYear.tpl b/gui/baculum/protected/Web/Portlets/DirectiveMonthsOfYear.tpl new file mode 100644 index 000000000..225c04d66 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveMonthsOfYear.tpl @@ -0,0 +1,126 @@ +
+
+ : +
+
+
+   +
+
+   +   +   +   +   +   +   +   +   +   +   +   +
+ +
+
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php b/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php index 27e378da1..cf0ddec9c 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveRenderer.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -52,6 +52,7 @@ Prado::using('Application.Web.Portlets.DirectiveMessages'); class DirectiveRenderer extends TItemDataRenderer { const DATA = 'Data'; + const IS_DATA_BOUND = 'IsDataBound'; private $directive_types = array( 'DirectiveCheckBox', @@ -88,8 +89,8 @@ class DirectiveRenderer extends TItemDataRenderer { $this->addSection($data['section']); } - $item = $this->createItem($data); - $this->addParsedObject($item); + $this->createItem($data); + $this->setIsDataBound(true); } public function createItem($data) { @@ -118,6 +119,8 @@ class DirectiveRenderer extends TItemDataRenderer { if ($data['directive_name'] === 'Name') { $control->setDisabled($this->SourceTemplateControl->getDisableRename()); } + $this->addParsedObject($control); + $control->createDirective(); } elseif (in_array($type, $this->directive_list_types)) { $control->setHost($data['host']); $control->setComponentType($data['component_type']); @@ -132,6 +135,10 @@ class DirectiveRenderer extends TItemDataRenderer { $control->setShow($data['show']); $control->setGroupName($data['group_name']); $control->setResource($data['resource']); + $this->addParsedObject($control); + if (!$this->getIsDataBound()) { + $control->raiseEvent('OnDirectiveListLoad', $this, null); + } } return $control; } @@ -159,6 +166,14 @@ class DirectiveRenderer extends TItemDataRenderer { $this->setViewState(self::DATA, $data); } + public function getIsDataBound() { + return $this->getViewState(self::IS_DATA_BOUND); + } + + public function setIsDataBound($is_data_bound) { + $this->setViewState(self::IS_DATA_BOUND, $is_data_bound); + } + private function getField($field_type) { return 'Application.Web.Portlets.Directive' . $field_type; } diff --git a/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php b/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php index 5c2713af9..c3bb03015 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveRunscript.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -36,8 +36,8 @@ class DirectiveRunscript extends DirectiveListTemplate { private $directive_types = array( 'DirectiveCheckBox', - 'DirectiveTextBox', - 'DirectiveComboBox' + 'DirectiveComboBox', + 'DirectiveTextBox' ); public function loadConfig() { @@ -133,6 +133,7 @@ class DirectiveRunscript extends DirectiveListTemplate { for ($i = 0; $i < count($this->directive_types); $i++) { $controls = $this->RepeaterRunscriptOptions->findControlsByType($this->directive_types[$i]); for ($j = 0; $j < count($controls); $j++) { + $controls[$j]->setValue(); $directive_name = $controls[$j]->getDirectiveName(); $directive_value = $controls[$j]->getDirectiveValue(); $default_value = null; @@ -180,7 +181,7 @@ class DirectiveRunscript extends DirectiveListTemplate { } public function newRunscriptDirective() { - $data = $this->getDirectiveValue(true); + $data = $this->getDirectiveValue(); if (is_array($data) && key_exists('Runscript', $data) && is_array($data['Runscript'])) { $data['Runscript'][] = new stdClass; } else { diff --git a/gui/baculum/protected/Web/Portlets/DirectiveSchedule.php b/gui/baculum/protected/Web/Portlets/DirectiveSchedule.php index 102f7bba1..0ef3eae5c 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveSchedule.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveSchedule.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -20,12 +20,19 @@ * Bacula(R) is a registered trademark of Kern Sibbald. */ +Prado::using('System.Web.UI.ActiveControls.TActiveHiddenField'); +Prado::using('System.Web.UI.ActiveControls.TActiveRadioButton'); Prado::using('Application.Common.Class.Params'); Prado::using('Application.Web.Portlets.DirectiveListTemplate'); Prado::using('Application.Web.Portlets.DirectiveCheckBox'); Prado::using('Application.Web.Portlets.DirectiveComboBox'); Prado::using('Application.Web.Portlets.DirectiveTextBox'); Prado::using('Application.Web.Portlets.DirectiveTimePeriod'); +Prado::using('Application.Web.Portlets.DirectiveTime'); +Prado::using('Application.Web.Portlets.DirectiveDaysOfWeek'); +Prado::using('Application.Web.Portlets.DirectiveDaysOfMonth'); +Prado::using('Application.Web.Portlets.DirectiveWeeksOfMonth'); +Prado::using('Application.Web.Portlets.DirectiveWeeksOfYear'); /** * Schedule directive control. @@ -36,12 +43,11 @@ Prado::using('Application.Web.Portlets.DirectiveTimePeriod'); */ class DirectiveSchedule extends DirectiveListTemplate { - private $directive_types = array( - 'DirectiveCheckBox', - 'DirectiveTextBox', - 'DirectiveComboBox', - 'DirectiveTimePeriod' - ); + const SCHEDULE_MODE_HOURLY = 'hourly'; + const SCHEDULE_MODE_DAILY = 'daily'; + const SCHEDULE_MODE_WEEKLY = 'weekly'; + const SCHEDULE_MODE_MONTHLY = 'monthly'; + const SCHEDULE_MODE_CUSTOM = 'custom'; private $directives_dir = [ 'Pool', @@ -67,37 +73,33 @@ class DirectiveSchedule extends DirectiveListTemplate { 'fd' => 'Connect' ]; - private $time_values = array( - 'Minute', - 'Hour', - 'Day', - 'Month', - 'DayOfWeek', - 'WeekOfMonth', - 'WeekOfYear' - ); - - private $time_directives = array( - 'Month', - 'MonthRangeFrom', - 'MonthRangeTo', - 'Week', - 'WeekRangeFrom', - 'WeekRangeTo', - 'Day', - 'DayRangeFrom', - 'DayRangeTo', - 'Wday', - 'WdayRangeFrom', - 'WdayRangeTo', - 'TimeHourAt', - 'TimeMinAt', - 'TimeMinHourly' - ); + private $time_directives = [ + 'TimeHourly', + 'TimeDaily', + 'TimeWeekly', + 'TimeMonthly', + 'TimeCustom', + 'TimeHourlyCustom', + 'DaysOfWeekWeekly', + 'DaysOfWeekMonthly', + 'DaysOfWeekCustom', + 'DaysOfMonthCustom', + 'WeeksOfMonthMonthly', + 'WeeksOfMonthCustom', + 'WeeksOfYearCustom', + 'MonthsOfYearCustom' + ]; public function loadConfig() { $load_values = $this->getLoadValues(); $directives = $this->getData(); + if ($load_values) { + /** + * For existing config without any 'Run' defined don't show sample 'Run' in form. + * The sample 'Run' should be displayed only in new schedule form. + */ + $directives = array_filter($directives); + } $host = $this->getHost(); $component_type = $this->getComponentType(); $component_name = $this->getComponentName(); @@ -105,7 +107,7 @@ class DirectiveSchedule extends DirectiveListTemplate { $resource_name = $this->getResourceName(); $subdirectives = $this->getSubDirectives(); $resource_desc = $this->getResourceDesc(); - $time_directives = $directive_values = array(); + $time_directives = $directive_values = []; foreach ($directives as $index => $directive) { for ($i = 0; $i < count($subdirectives); $i++) { $default_value = null; @@ -131,11 +133,14 @@ class DirectiveSchedule extends DirectiveListTemplate { $resource = 'Pool'; } $in_config = false; - if ($load_values === true) { + if ($load_values === true && is_object($directive)) { $in_config = property_exists($directive, $subdirectives[$i]); } - $directive_value = $in_config ? $directive->{$subdirectives[$i]} : null; + $directive_value = null; + if (is_object($directive) && property_exists($directive, $subdirectives[$i])) { + $directive_value = $directive->{$subdirectives[$i]}; + } $overwrite_directives[$subdirectives[$i]] = array( 'host' => $host, 'component_type' => $component_type, @@ -158,7 +163,7 @@ class DirectiveSchedule extends DirectiveListTemplate { } for ($i = 0; $i < count($this->time_directives); $i++) { - $time_directives[$this->time_directives[$i]] = array( + $time_directives[$this->time_directives[$i]] = [ 'host' => $host, 'component_type' => $component_type, 'component_name' => $component_name, @@ -169,12 +174,12 @@ class DirectiveSchedule extends DirectiveListTemplate { 'default_value' => 0, 'parent_name' => __CLASS__, 'group_name' => $index - ); + ]; } - $directive_values[] = array( + $directive_values[] = [ 'overwrite_directives' => $overwrite_directives, 'time_directives' => $time_directives - ); + ]; } $this->RepeaterScheduleRuns->DataSource = $directive_values; $this->RepeaterScheduleRuns->dataBind(); @@ -235,8 +240,6 @@ class DirectiveSchedule extends DirectiveListTemplate { $control->setShow($data['show']); $control->setResourceNames($data['resource_names']); $control->setParentName($data['parent_name']); - $control->onLoad(null); - $control->createDirective(); } } @@ -255,152 +258,109 @@ class DirectiveSchedule extends DirectiveListTemplate { } } - $directive = $param->Item->Data['time_directives']['Month']['directive_values']; - - $months = array_keys(Params::$months); - - $param->Item->Month->setData(Params::$months); - $param->Item->MonthRangeFrom->setData(Params::$months); - $param->Item->MonthRangeTo->setData(Params::$months); - - $month_single = null; - $month_range_from = null; - $month_range_to = null; - $month_count = $load_values ? count($directive->Month) : 0; - if ($month_count === 12) { - $param->Item->MonthDisable->Checked = true; - } elseif ($month_count == 1) { - $month_single = $months[$directive->Month[0]]; - $param->Item->MonthSingle->Checked = true; - } elseif ($month_count > 0 && $month_count < 12) { - $month_start = $directive->Month[0]; - $month_end = $directive->Month[$month_count-1]; - $month_range_from = $months[$month_start]; - $month_range_to = $months[$month_end]; - $param->Item->MonthRange->Checked = true; - } - $param->Item->Month->setDirectiveValue($month_single); - $param->Item->MonthRangeFrom->setDirectiveValue($month_range_from); - $param->Item->MonthRangeTo->setDirectiveValue($month_range_to); - - $days = range(1, 31); - $param->Item->Day->setData($days); - $param->Item->DayRangeFrom->setData($days); - $param->Item->DayRangeTo->setData($days); - - $day_single = null; - $day_range_from = null; - $day_range_to = null; - $day_count = $load_values ? count($directive->Day) : 0; - if ($day_count === 31) { - $param->Item->DayDisable->Checked = true; - } elseif ($day_count === 1) { - $day_single = $days[$directive->Day[0]]; - $param->Item->DaySingle->Checked = true; - } elseif ($day_count > 0 && $day_count < 31) { - $day_start = $directive->Day[0]; - $day_end = $directive->Day[$day_count-1]; - $day_range_from = $days[$day_start]; - $day_range_to = $days[$day_end]; - $param->Item->DayRange->Checked = true; - } - $param->Item->Day->setDirectiveValue($day_single); - $param->Item->DayRangeFrom->setDirectiveValue($day_range_from); - $param->Item->DayRangeTo->setDirectiveValue($day_range_to); - - $weeks = array_keys(Params::$weeks); - - $param->Item->Week->setData(Params::$weeks); - $param->Item->WeekRangeFrom->setData(Params::$weeks); - $param->Item->WeekRangeTo->setData(Params::$weeks); - $week_single = null; - $week_range_from = null; - $week_range_to = null; - $week_count = $load_values ? count($directive->WeekOfMonth) : 0; - if ($week_count == 6) { - $param->Item->WeekDisable->Checked = true; - } elseif ($week_count == 1) { - $week_single = $weeks[$directive->WeekOfMonth[0]]; - $param->Item->WeekSingle->Checked = true; - } elseif ($week_count > 0 && $week_count < 6) { - $week_start = $directive->WeekOfMonth[0]; - $week_end = $directive->WeekOfMonth[$week_count-1]; - $week_range_from = $weeks[$week_start]; - $week_range_to = $weeks[$week_end]; - $param->Item->WeekRange->Checked = true; - } - $param->Item->Week->setDirectiveValue($week_single); - $param->Item->WeekRangeFrom->setDirectiveValue($week_range_from); - $param->Item->WeekRangeTo->setDirectiveValue($week_range_to); - - $wdays = array_keys(Params::$wdays); - $param->Item->Wday->setData(Params::$wdays); - $param->Item->WdayRangeFrom->setData(Params::$wdays); - $param->Item->WdayRangeTo->setData(Params::$wdays); - - $wday_single = null; - $wday_range_from = null; - $wday_range_to = null; - $wday_count = $load_values ? count($directive->DayOfWeek) : 0; - if ($wday_count === 7) { - $wday_single = ''; - } elseif ($wday_count === 1) { - $wday_single = $wdays[$directive->DayOfWeek[0]]; - $param->Item->WdaySingle->Checked = true; - } elseif ($wday_count > 0 && $wday_count < 7) { - $wday_start = $directive->DayOfWeek[0]; - $wday_end = $directive->DayOfWeek[$wday_count-1]; - $wday_range_from = $wdays[$wday_start]; - $wday_range_to = $wdays[$wday_end]; - $param->Item->WdayRange->Checked = true; - } - $param->Item->Wday->setDirectiveValue($wday_single); - $param->Item->WdayRangeFrom->setDirectiveValue($wday_range_from); - $param->Item->WdayRangeTo->setDirectiveValue($wday_range_to); + $directive = $param->Item->Data['time_directives']['TimeHourly']['directive_values']; + // Hour and minute $hour = null; $minute = null; - if ($load_values) { - $hour = $directive->Hour[0]; // @TODO: Check for many hour values; + $is_hourly = false; + if (is_object($directive)) { + if (count($directive->Hour) == 24) { + $is_hourly = true; + } + $hour = $directive->Hour[0]; /** * Check if Minute property exists because of bug about missing Minute * @see http://bugs.bacula.org/view.php?id=2318 */ $minute = property_exists($directive, 'Minute') ? $directive->Minute : 0; } - $param->Item->TimeHourAt->setDirectiveValue(0); - $param->Item->TimeMinAt->setDirectiveValue(0); - $param->Item->TimeMinHourly->setDirectiveValue(0); - if ($load_values) { - if (count($directive->Hour) == 24) { - if ($minute === 0) { - $param->Item->TimeDisable->Checked = true; - } else { - $param->Item->TimeHourly->Checked = true; - $param->Item->TimeMinHourly->setDirectiveValue($minute); - } - } elseif (count($directive->Hour) == 1) { - $param->Item->TimeAt->Checked = true; - $param->Item->TimeHourAt->setDirectiveValue($hour); - $param->Item->TimeMinAt->setDirectiveValue($minute); - } else { - $param->Item->TimeDisable->Checked = true; - } + + if ($is_hourly && is_integer($minute) && $minute > 0) { + $param->Item->TimeHourlyCustomOption->Checked = true; + $hour = null; + } elseif (!$is_hourly && is_integer($hour) && is_integer($minute)) { + $param->Item->TimeAtCustomOption->Checked = true; } else { - $param->Item->TimeDisable->Checked = true; + $param->Item->TimeEveryHourCustomOption->Checked = true; + $hour = null; + $minute = null; } - // @TODO: Fix controls to avoid forcing onLoad() and createDirective() - for ($i = 0; $i < count($this->time_directives); $i++) { - $control = $param->Item->{$this->time_directives[$i]}; - $control->onLoad(null); - $control->createDirective(); + $time_value = ['hour' => $hour, 'minute' => $minute]; + $param->Item->TimeHourly->setDirectiveValue($time_value); + $param->Item->TimeDaily->setDirectiveValue($time_value); + $param->Item->TimeWeekly->setDirectiveValue($time_value); + $param->Item->TimeMonthly->setDirectiveValue($time_value); + $param->Item->TimeHourlyCustom->setDirectiveValue($time_value); + $param->Item->TimeCustom->setDirectiveValue($time_value); + + // Day of the week + $all_dows = true; + if (is_object($directive)) { + $all_dows = count($directive->DayOfWeek) == 7; + $param->Item->DaysOfWeekWeekly->setDirectiveValue($directive->DayOfWeek); + $param->Item->DaysOfWeekMonthly->setDirectiveValue($directive->DayOfWeek); + $param->Item->DaysOfWeekCustom->setDirectiveValue($directive->DayOfWeek); + } + + // Week of the month + $all_woms = true; + if (is_object($directive)) { + $all_woms = count($directive->WeekOfMonth) == 6; + $param->Item->WeeksOfMonthMonthly->setDirectiveValue($directive->WeekOfMonth); + $param->Item->WeeksOfMonthCustom->setDirectiveValue($directive->WeekOfMonth); + } + + // Days of the month + $all_doms = true; + if (is_object($directive)) { + $all_doms = count($directive->Day) == 31; + $param->Item->DaysOfMonthCustom->setDirectiveValue($directive->Day); + } + + // Months of the year + $all_moys = true; + if (is_object($directive)) { + $all_moys = count($directive->Month) == 12; + $param->Item->MonthsOfYearCustom->setDirectiveValue($directive->Month); + } + + // Weeks of the month + $all_woys = true; + if (is_object($directive)) { + $all_woys = count($directive->WeekOfYear) == 54; + $param->Item->WeeksOfYearCustom->setDirectiveValue($directive->WeekOfYear); + } + + + if (is_object($directive)) { + $custom = $all_doms && $all_moys && $all_woys; + if ($is_hourly && $all_dows && $all_woms && $custom) { + // hourly + $param->Item->ScheduleMode->Value = self::SCHEDULE_MODE_HOURLY; + } elseif (!$is_hourly && is_integer($hour) && is_integer($minute) && $all_dows && $all_woms && $custom) { + // daily + $param->Item->ScheduleMode->Value = self::SCHEDULE_MODE_DAILY; + } elseif (!$is_hourly && is_integer($hour) && is_integer($minute) && !$all_dows && $all_woms && $custom) { + // weekly + $param->Item->ScheduleMode->Value = self::SCHEDULE_MODE_WEEKLY; + } elseif (!$is_hourly && is_integer($hour) && is_integer($minute) && !$all_dows && !$all_woms && $custom) { + // monthly + $param->Item->ScheduleMode->Value = self::SCHEDULE_MODE_MONTHLY; + } else { + // custom + $param->Item->ScheduleMode->Value = self::SCHEDULE_MODE_CUSTOM; + } + } else { + // daily - default for new schedule + $param->Item->ScheduleMode->Value = self::SCHEDULE_MODE_DAILY; } } public function removeSchedule($sender, $param) { if ($param instanceof Prado\Web\UI\TCommandEventParameter) { - $idx = $param->getCommandName(); + $idx = (integer)$param->getCommandName(); $data = $this->getDirectiveValue(true); array_splice($data, $idx, 1); $this->setData($data); @@ -408,6 +368,69 @@ class DirectiveSchedule extends DirectiveListTemplate { } } + private function setTime($directive, &$obj, &$directive_values) { + $t = $directive->getDirectiveValue(); + $obj->Hour = [$t['hour']]; + $obj->Minute = $t['minute']; + $min = sprintf('%02d', $t['minute']); + $directive_values[] = "at {$t['hour']}:{$min}"; + } + + private function setTimeHourly($t, &$obj, &$directive_values) { + $obj->Hour = range(0, 23); + $obj->Minute = $t['minute']; + if ($t['minute'] > 0) { + $min = sprintf('%02d', $t['minute']); + $directive_values[] = "hourly at 0:{$min}"; + } else { + $directive_values[] = 'hourly'; + } + } + + private function setDaysOfWeek($directive, &$obj, &$directive_values) { + $wdays = array_keys(Params::$wdays); + $dows = $directive->getDirectiveValue(); + $dows_len = count($dows); + if ($dows_len == 0) { + $obj->DayOfWeek = range(0, 6); + } else { + $obj->DayOfWeek = $dows; + $directive_values[] = Params::getDaysOfWeekConfig($dows); + } + } + + private function setWeeksOfYear($directive, &$obj, &$directive_values) { + $woys = $directive->getDirectiveValue(); + $obj->WeekOfYear = $woys; + $directive_values[] = Params::getWeeksOfYearConfig($woys); + } + + private function setWeeksOfMonth($directive, &$obj, &$directive_values) { + $woms = $directive->getDirectiveValue(); + $woms_len = count($woms); + if ($woms_len == 0) { + // all weeks + $obj->WeekOfMonth = range(0, 5); + } else { + // selected weeks + $obj->WeekOfMonth = $woms; + $directive_values[] = Params::getWeeksOfMonthConfig($woms); + } + } + + private function setMonthsOfYear($directive, &$obj, &$directive_values) { + $moys = $directive->getDirectiveValue(); + $obj->Month = $moys; + $directive_values[] = Params::getMonthsOfYearConfig($moys); + } + + private function setDaysOfMonth($directive, &$obj, &$directive_values) { + $doms = $directive->getDirectiveValue(); + $doms_len = count($doms); + $obj->Day = $doms; + $directive_values[] = Params::getDaysOfMonthConfig($doms); + } + public function getDirectiveValue($ret_obj = false) { $directive_values = []; $component_type = $this->getComponentType(); @@ -423,6 +446,7 @@ class DirectiveSchedule extends DirectiveListTemplate { $obj = new StdClass; for ($i = 0; $i < count($subdirectives); $i++) { $control = $value->{$subdirectives[$i]}; + $control->setValue(); $subdirective_name = $control->getDirectiveName(); $subdirective_value = $control->getDirectiveValue(); $default_value = $control->getDefaultValue(); @@ -432,6 +456,9 @@ class DirectiveSchedule extends DirectiveListTemplate { if (get_class($control) === 'DirectiveCheckBox') { settype($default_value, 'bool'); } + if (get_class($control) === 'DirectiveTextBox') { + settype($default_value, 'string'); + } if ($subdirective_value === $default_value) { // value the same as default value, skip it @@ -443,86 +470,98 @@ class DirectiveSchedule extends DirectiveListTemplate { } $directive_values[] = "{$subdirective_name}=\"{$subdirective_value}\""; } - - $obj->Month = range(0, 11); - $months = array_keys(Params::$months); - if ($value->MonthSingle->Checked === true) { - $month_val = $value->Month->getDirectiveValue(); - $directive_values[] = $month_val; - $obj->Month = array(array_search($month_val, $months)); - } elseif ($value->MonthRange->Checked === true) { - $from = $value->MonthRangeFrom->getDirectiveValue(); - $to = $value->MonthRangeTo->getDirectiveValue(); - $directive_values[] = "{$from}-{$to}"; - $f = array_search($from, $months); - $t = array_search($to, $months); - $obj->Month = range($f, $t); + for ($i = 0; $i < count($this->time_directives); $i++) { + $value->{$this->time_directives[$i]}->setValue(); } - $obj->WeekOfMonth = range(0, 5); - $weeks = array_keys(Params::$weeks); - if ($value->WeekSingle->Checked === true) { - $week_val = $value->Week->getDirectiveValue(); - $directive_values[] = $week_val; - $obj->WeekOfMonth = array(array_search($week_val, $weeks)); - } elseif ($value->WeekRange->Checked === true) { - $from = $value->WeekRangeFrom->getDirectiveValue(); - $to = $value->WeekRangeTo->getDirectiveValue(); - $directive_values[] = "{$from}-{$to}"; - $f = array_search($from, $weeks); - $t = array_search($to, $weeks); - $obj->WeekOfMonth = range($f, $t); - } + switch ($value->ScheduleMode->Value) { + case self::SCHEDULE_MODE_HOURLY: { + // time (hourly) + $t = $value->TimeHourly->getDirectiveValue(); + $this->setTimeHourly($t, $obj, $directive_values); + break; + } + case self::SCHEDULE_MODE_DAILY: { + // time (HH:MM) + $this->setTime($value->TimeDaily, $obj, $directive_values); + break; + } + case self::SCHEDULE_MODE_WEEKLY: { + // set days of the week + $this->setDaysOfWeek($value->DaysOfWeekWeekly, $obj, $directive_values); - $obj->Day = range(0, 30); - if ($value->DaySingle->Checked === true) { - $day = $value->Day->getDirectiveValue(); - $directive_values[] = 'on ' . $day; - $obj->Day = array($day-1); - } elseif ($value->DayRange->Checked === true) { - $from = $value->DayRangeFrom->getDirectiveValue()-1; - $to = $value->DayRangeTo->getDirectiveValue()-1; - $day_range = range($from, $to); - $directive_values[] = 'on ' . Params::getDaysConfig($day_range); - $obj->Day = $day_range; - } + // time (HH:MM) + $this->setTime($value->TimeWeekly, $obj, $directive_values); + break; + } + case self::SCHEDULE_MODE_MONTHLY: { + // weeks of the month + $this->setWeeksOfMonth($value->WeeksOfMonthMonthly, $obj, $directive_values); - $obj->DayOfWeek = range(0, 6); - $wdays = array_keys(Params::$wdays); - if ($value->WdaySingle->Checked === true) { - $directive_values[] = $value->Wday->getDirectiveValue(); - $obj->DayOfWeek = array(array_search($value->Wday->getDirectiveValue(), $wdays)); - } elseif ($value->WdayRange->Checked === true) { - $from = $value->WdayRangeFrom->getDirectiveValue(); - $to = $value->WdayRangeTo->getDirectiveValue(); - $directive_values[] = "{$from}-{$to}"; - $f = array_search($from, $wdays); - $t = array_search($to, $wdays); - $obj->DayOfWeek = range($f, $t); - } + // days of the week + $this->setDaysOfWeek($value->DaysOfWeekMonthly, $obj, $directive_values); - $obj->Hour = range(0, 23); - $obj->Minute = 0; - if ($value->TimeAt->Checked === true) { - $hour = $value->TimeHourAt->getDirectiveValue(); - $minute = sprintf('%02d', $value->TimeMinAt->getDirectiveValue()); - $directive_values[] = "at {$hour}:{$minute}"; - $obj->Hour = array($hour); - $obj->Minute = $minute; - - } elseif ($value->TimeHourly->Checked === true) { - $hour = '00'; - $minute = sprintf('%02d', $value->TimeMinHourly->getDirectiveValue()); - $directive_values[] = "hourly at {$hour}:{$minute}"; + // time + $this->setTime($value->TimeMonthly, $obj, $directive_values); + break; + } + case self::SCHEDULE_MODE_CUSTOM: { + // months of the year + $this->setMonthsOfYear($value->MonthsOfYearCustom, $obj, $directive_values); + + // weeks of the year + $this->setWeeksOfYear($value->WeeksOfYearCustom, $obj, $directive_values); + + // days of the month + $this->setDaysOfMonth($value->DaysOfMonthCustom, $obj, $directive_values); + + // weeks of the month + $this->setWeeksOfMonth($value->WeeksOfMonthCustom, $obj, $directive_values); + + // days of the week + $this->setDaysOfWeek($value->DaysOfWeekCustom, $obj, $directive_values); + + // time + if ($value->TimeEveryHourCustomOption->Checked) { + $t = ['hour' => 0, 'minute' => 0]; + $this->setTimeHourly($t, $obj, $directive_values); + } elseif ($value->TimeHourlyCustomOption->Checked) { + $t = $value->TimeHourlyCustom->getDirectiveValue(); + $this->setTimeHourly($t, $obj, $directive_values); + } elseif ($value->TimeAtCustomOption) { + $this->setTime($value->TimeCustom, $obj, $directive_values); + } + break; + } + } + // add missing default properties + if (!property_exists($obj, 'Hour')) { $obj->Hour = range(0, 23); - $obj->Minute = $value->TimeMinHourly->getDirectiveValue(); - } else { - $directive_values[] = 'hourly'; } + + if (!property_exists($obj, 'Minute')) { + $obj->Minute = 0; + } + if (!property_exists($obj, 'DayOfWeek')) { + $obj->DayOfWeek = range(0, 6); + } + if (!property_exists($obj, 'WeekOfYear')) { + $obj->WeekOfYear = range(0, 53); + } + if (!property_exists($obj, 'WeekOfMonth')) { + $obj->WeekOfMonth = range(0, 5); + } + if (!property_exists($obj, 'Month')) { + $obj->Month = range(0, 11); + } + if (!property_exists($obj, 'Day')) { + $obj->Day = range(0, 30); + } + + $directive_values = array_filter($directive_values); $values[$directive_name][] = implode(' ', $directive_values); $objs[] = $obj; - $directive_values = array(); - $obj = null; + $directive_values = []; } return (($ret_obj) ? $objs : $values); } @@ -530,7 +569,7 @@ class DirectiveSchedule extends DirectiveListTemplate { public function newScheduleDirective() { $data = $this->getDirectiveValue(true); $obj = new StdClass; - $obj->Hour = range(0, 23); + $obj->Hour = [0]; $obj->Minute = 0; $obj->Day = range(0, 30); $obj->Month = range(0, 11); @@ -541,7 +580,7 @@ class DirectiveSchedule extends DirectiveListTemplate { if (is_array($data)) { $data[] = $obj; } else { - $data = array($obj); + $data = [$obj]; } $this->setData($data); $this->SourceTemplateControl->setShowAllDirectives(true); diff --git a/gui/baculum/protected/Web/Portlets/DirectiveSchedule.tpl b/gui/baculum/protected/Web/Portlets/DirectiveSchedule.tpl index a7c3a99b5..f6376d374 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveSchedule.tpl +++ b/gui/baculum/protected/Web/Portlets/DirectiveSchedule.tpl @@ -7,425 +7,269 @@ CssClass="w3-button w3-green w3-right" OnCommand="SourceTemplateControl.removeSchedule" CommandName="<%=$this->ItemIndex%>" - CommandParameter="save" >  <%[ Remove ]%>

<%=$this->SourceTemplateControl->ComponentType == 'dir' ? 'Run' : ($this->SourceTemplateControl->ComponentType == 'fd' ? 'Connect' : '')%> #<%=($this->ItemIndex+1)%>

- - - - - - - - - - - - - -
-

<%[ Month ]%>

-
-
- - +
+
+
+
-
- - -
-
- - -
-
-
- - - - sender.enabled = ($('#<%=$this->MonthSingle->ClientID%>').prop('checked') && ($('#<%=$this->Month->ClientID%>_Directive').val()).trim() === ''); - - -
-
- - - - - sender.enabled = ($('#<%=$this->MonthRange->ClientID%>').prop('checked') && (($('#<%=$this->MonthRangeFrom->ClientID%>_Directive').val()).trim() === '' || ($('#<%=$this->MonthRangeTo->ClientID%>_Directive').val()).trim() === '')); - - +
<%[ Hourly ]%>
+ <%[ Run job every hour at the specified minute ]%>
-
-
-

<%[ Week ]%>

-
-
- - -
-
- - -
-
- - +
+
+
-
- - - - sender.enabled = ($('#<%=$this->WeekSingle->ClientID%>').prop('checked') && ($('#<%=$this->Week->ClientID%>_Directive').val()).trim() === ''); - - -
-
- - - - - sender.enabled = ($('#<%=$this->WeekRange->ClientID%>').prop('checked') && (($('#<%=$this->WeekRangeFrom->ClientID%>_Directive').val()).trim() === '' || ($('#<%=$this->WeekRangeTo->ClientID%>_Directive').val()).trim() === '')); - - -
-
-
-

<%[ Day ]%>

-
-
- - -
-
- - -
-
- - +
+
+
+
<%[ Daily ]%>
+ <%[ Run job every day at the specified time ]%>
-
- - - - sender.enabled = ($('#<%=$this->DaySingle->ClientID%>').prop('checked') && ($('#<%=$this->Day->ClientID%>_Directive').val()).trim() === ''); - - -
-
- - - - - sender.enabled = ($('#<%=$this->DayRange->ClientID%>').prop('checked') && (($('#<%=$this->DayRangeFrom->ClientID%>_Directive').val()).trim() === '' || ($('#<%=$this->DayRangeTo->ClientID%>_Directive').val()).trim() === '')); - - -
-
-
-

<%[ Day of week ]%>

-
-
- - -
-
- - +
+
+
-
- - -
-
-
- - - - sender.enabled = ($('#<%=$this->WdaySingle->ClientID%>').prop('checked') && ($('#<%=$this->Wday->ClientID%>_Directive').val()).trim() === ''); - -
-
- - - - - sender.enabled = ($('#<%=$this->WdayRange->ClientID%>').prop('checked') && (($('#<%=$this->WdayRangeFrom->ClientID%>_Directive').val()).trim() === '' || ($('#<%=$this->WdayRangeTo->ClientID%>_Directive').val()).trim() === '')); - - +
+
+ +
+
<%[ Weekly ]%>
+ <%[ Run job every week at the specified time on selected days of the week ]%>
-
-
-

<%[ Hour and minute ]%>

-
-
- - +
+
+ +
-
- - +
+
+
+
-
- - +
<%[ Monthly ]%>
+ <%[ Run job every month at the specified time in selected weeks of the month ]%> +
+
+
+ + +
-
- - - - - sender.enabled = ($('#<%=$this->TimeAt->ClientID%>').prop('checked') && (($('#<%=$this->TimeHourAt->ClientID%>_Directive').val()).trim() === '' || ($('#<%=$this->TimeMinAt->ClientID%>_Directive').val()).trim() === '')); - - +
+
+ +
+
<%[ Custom ]%>
+ <%[ Setup your custom schedule ]%>
-
- - - - sender.enabled = ($('#<%=$this->TimeHourly->ClientID%>').prop('checked') && ($('#<%=$this->TimeMinHourly->ClientID%>_Directive').val()).trim() === ''); - - +
+
+
+   +   +   + +
+
+ +
+
+ +
+ + + + + +
+ +

<%[ Override directives ]%>

+ + + + + + + + + + + + +
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveTemplate.php b/gui/baculum/protected/Web/Portlets/DirectiveTemplate.php index e124204c8..a98cd0429 100644 --- a/gui/baculum/protected/Web/Portlets/DirectiveTemplate.php +++ b/gui/baculum/protected/Web/Portlets/DirectiveTemplate.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -58,6 +58,7 @@ class DirectiveTemplate extends DirectiveControlTemplate implements IDirectiveFi const SHOW_REMOVE_BUTTON = 'ShowRemoveButton'; public $display_directive; + private $data_changed = false; private $command_params = array('save', 'add'); @@ -75,6 +76,14 @@ class DirectiveTemplate extends DirectiveControlTemplate implements IDirectiveFi $this->ensureChildControls(); } + public function onLoad($param) { + parent::onLoad($param); + if ($this->getPage()->IsPostBack && $this->getValue() != $this->getDefaultValue()) { + // It has special meaning for directive controls used in wizards + $this->setValue(); + } + } + public function bubbleEvent($sender, $param) { if ($param instanceof TCommandEventParameter) { $this->raiseBubbleEvent($this, $param); @@ -92,15 +101,20 @@ class DirectiveTemplate extends DirectiveControlTemplate implements IDirectiveFi } public function saveValue($sender, $param) { - $command_param = $this->getCmdParam(); - if ($command_param === 'save' && method_exists($this, 'getValue')) { + if ($this->getCmdParam() === 'save') { + $this->setValue(); + } + } + + public function setValue() { + if (method_exists($this, 'getValue')) { $new_value = $this->getValue(); $this->setDirectiveValue($new_value); } } - public function onLoad($param) { - parent::onLoad($param); + public function onPreRender($param) { + parent::onPreRender($param); if (!$this->getIsDirectiveCreated()) { $this->createDirective(); $this->setIsDirectiveCreated(true); @@ -168,6 +182,7 @@ class DirectiveTemplate extends DirectiveControlTemplate implements IDirectiveFi } public function getDirectiveValue() { + $this->saveValue(null, null); return $this->getViewState(self::DIRECTIVE_VALUE); } diff --git a/gui/baculum/protected/Web/Portlets/DirectiveTime.php b/gui/baculum/protected/Web/Portlets/DirectiveTime.php new file mode 100644 index 000000000..b306b270a --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveTime.php @@ -0,0 +1,116 @@ + + * @category Control + * @package Baculum Web + */ +class DirectiveTime extends DirectiveTemplate { + + const SHOW_HOUR = 'ShowHour'; + const SHOW_MINUTE = 'ShowMinute'; + + public function getValue() { + $hour = (integer)$this->Hour->getSelectedValue(); + if (!$this->ShowHour) { + $hour = null; + } + $minute = (integer)$this->Minute->getSelectedValue(); + if (!$this->ShowMinute) { + $minute = null; + } + return $this->getTimeValue($hour, $minute); + } + + private function getTimeValue($hour = null, $minute = null) { + return ['hour' => $hour, 'minute' => $minute]; + } + + public function createDirective() { + $this->Label->Text = $this->getLabel(); + $directive_value = $this->getDirectiveValue(); + $default_value = $this->getDefaultValue(); + if (!is_array($directive_value)) { + $directive_value = $this->getTimeValue(); + } + if ($this->getInConfig() === false && is_null($directive_value['hour']) && is_null($directive_value['minute'])) { + if (is_array($default_value) && !is_null($default_value['hour']) && !is_null($default_value['minute'])) { + $directive_value = $default_value; + } else { + $directive_value = $this->getTimeValue(0, 0); + } + } + $hours = range(0, 23); + $this->Hour->DataSource = array_map(function($h) { + return sprintf('%02d', $h); + }, $hours); + $this->Hour->setSelectedValue($directive_value['hour']); + $this->Hour->dataBind(); + + $minutes = range(0, 59); + $this->Minute->DataSource = array_map(function($m) { + return sprintf('%02d', $m); + }, $minutes); + $this->Minute->setSelectedValue($directive_value['minute']); + $this->Minute->dataBind(); + if ($this->getDisabled()) { + $this->Hour->setReadOnly(true); + $this->Minute->setReadOnly(true); + } + $validate = $this->getRequired(); + $this->TimeValidator->setVisible($validate); + $cssclass = $this->getCssClass(); + if ($cssclass) { + $hcssclass = $cssclass . ' ' . $this->Hour->getCssClass(); + $this->Hour->setCssClass($hcssclass); + $mcssclass = $cssclass . ' ' . $this->Minute->getCssClass(); + $this->Minute->setCssClass($mcssclass); + } + } + + public function getShowHour() { + return $this->getViewState(self::SHOW_HOUR, true); + } + + public function setShowHour($show) { + $show = TPropertyValue::ensureBoolean($show); + $this->setViewState(self::SHOW_HOUR, $show); + } + + public function getShowMinute() { + return $this->getViewState(self::SHOW_MINUTE, true); + } + + public function setShowMinute($show) { + $show = TPropertyValue::ensureBoolean($show); + $this->setViewState(self::SHOW_MINUTE, $show); + } +} diff --git a/gui/baculum/protected/Web/Portlets/DirectiveTime.tpl b/gui/baculum/protected/Web/Portlets/DirectiveTime.tpl new file mode 100644 index 000000000..dab5467df --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveTime.tpl @@ -0,0 +1,38 @@ +
+
+ : +
+
+ ShowHour ? ' style="display: none"' : '' %>> : + <%=$this->getRequired() ? ' ' : ''%> + + + +
+
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfMonth.php b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfMonth.php new file mode 100644 index 000000000..2a3661ca8 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfMonth.php @@ -0,0 +1,96 @@ + + * @category Control + * @package Baculum Web + */ +class DirectiveWeeksOfMonth extends DirectiveTemplate { + + const SHOW_OPTIONS = 'ShowOptions'; + + public function getValue() { + $value = []; + $weeks = array_values(Params::$weeks); + for ($i = 0; $i < count($weeks); $i++) { + if ($this->{$weeks[$i]}->Checked || $this->AllWeeksOfMonth->Checked) { + $value[] = $i; + } + } + return $value; + } + + public function createDirective() { + $this->Label->Text = $this->getLabel(); + $directive_value = $this->getDirectiveValue(); + $default_value = $this->getDefaultValue(); + $weeks = array_values(Params::$weeks); + if (!is_array($directive_value)) { + $directive_value = $weeks; + } + + $w_len = count($weeks); + $dv_len = count($directive_value); + if ($this->getInConfig() === false && $dv_len == $w_len) { + if (is_array($default_value) && count($default_value) > 0) { + $directive_value = $default_value; + } + } + + for ($i = 0; $i < $w_len; $i++) { + if ($dv_len < $w_len) { + // selected weeks + $this->{$weeks[$i]}->Checked = in_array($i, $directive_value); + } + if ($this->Disabled) { + $this->{$weeks[$i]}->Enabled = false; + } + if ($this->CssClass) { + $cssclass = $this->CssClass . ' ' . $this->{$weeks[$i]}->getCssClass(); + $this->{$weeks[$i]}->setCssClass($cssclass); + } + } + if ($this->Disabled) { + $this->AllWeeksOfMonth->Enabled = false; + } elseif ($dv_len == $w_len && $this->ShowOptions) { + // all weeks + $this->AllWeeksOfMonth->Checked = true; + } + } + + public function setShowOptions($show) { + $show = TPropertyValue::ensureBoolean($show); + $this->setViewState(self::SHOW_OPTIONS, $show); + } + + public function getShowOptions() { + return $this->getViewState(self::SHOW_OPTIONS, false); + } +} diff --git a/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfMonth.tpl b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfMonth.tpl new file mode 100644 index 000000000..32011e5ac --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfMonth.tpl @@ -0,0 +1,78 @@ +
+
+ : +
+
+
+   +
+
+   +   +   +   +   +   +
+ +
+
diff --git a/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfYear.php b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfYear.php new file mode 100644 index 000000000..febe53514 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfYear.php @@ -0,0 +1,101 @@ + + * @category Control + * @package Baculum Web + */ +class DirectiveWeeksOfYear extends DirectiveTemplate { + + const SHOW_OPTIONS = 'ShowOptions'; + const WEEK_CONTROL_PREFIX = 'week'; + + public function getValue() { + $value = []; + $weeks = range(0, 53); + for ($i = 0; $i < count($weeks); $i++) { + if ($this->{self::WEEK_CONTROL_PREFIX . $weeks[$i]}->Checked || $this->AllWeeksOfYear->Checked) { + $value[] = $i; + } + } + if (count($value) == 0) { + $value = $weeks; + } + return $value; + } + + public function createDirective() { + $this->Label->Text = $this->getLabel(); + $directive_value = $this->getDirectiveValue(); + $default_value = $this->getDefaultValue(); + $weeks = range(0, 53); + if (!is_array($directive_value)) { + $directive_value = $weeks; + } + + $w_len = count($weeks); + $dv_len = count($directive_value); + if ($this->getInConfig() === false && $dv_len == $w_len) { + if (is_array($default_value) && count($default_value) > 0) { + $directive_value = $default_value; + } + } + + for ($i = 0; $i < $w_len; $i++) { + $key = self::WEEK_CONTROL_PREFIX . $weeks[$i]; + if ($dv_len < $w_len) { + // selected days + $this->{$key}->Checked = in_array($weeks[$i], $directive_value); + } + if ($this->Disabled) { + $this->{$key}->Enabled = false; + } + if ($this->CssClass) { + $cssclass = $this->CssClass . ' ' . $this->{$key}->getCssClass(); + $this->{$key}->setCssClass($cssclass); + } + } + if ($this->Disabled) { + $this->AllWeeksOfYear->Enabled = false; + } elseif ($dv_len == $w_len && $this->ShowOptions) { + // all weeks + $this->AllWeeksOfYear->Checked = true; + } + } + + public function setShowOptions($show) { + $show = TPropertyValue::ensureBoolean($show); + $this->setViewState(self::SHOW_OPTIONS, $show); + } + + public function getShowOptions() { + return $this->getViewState(self::SHOW_OPTIONS, false); + } +} diff --git a/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfYear.tpl b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfYear.tpl new file mode 100644 index 000000000..88a93e814 --- /dev/null +++ b/gui/baculum/protected/Web/Portlets/DirectiveWeeksOfYear.tpl @@ -0,0 +1,476 @@ +
+
+ : +
+
+
+   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +   +   +
+
+   +   +   +   +   +
+ +
+
diff --git a/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php b/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php index 183bcf8d4..b20d3379d 100644 --- a/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php +++ b/gui/baculum/protected/Web/Portlets/JobRunscriptRenderer.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -44,7 +44,6 @@ class JobRunscriptRenderer extends DirectiveRenderer { $alb->CssClass = 'w3-button w3-green w3-right'; $alb->OnCommand = 'SourceTemplateControl.removeRunscript'; $alb->CommandName = $this->ItemIndex / self::DIRECTIVE_COUNT; - $alb->CommandParameter = 'save'; $alb->Text = '  ' . Prado::localize('Remove'); $this->addParsedObject($alb); } diff --git a/gui/baculum/protected/Web/Portlets/MessageTypes.php b/gui/baculum/protected/Web/Portlets/MessageTypes.php index 017b65241..7b16d1401 100644 --- a/gui/baculum/protected/Web/Portlets/MessageTypes.php +++ b/gui/baculum/protected/Web/Portlets/MessageTypes.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2019 Kern Sibbald + * Copyright (C) 2013-2021 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -43,6 +43,7 @@ class MessageTypes extends DirectiveListTemplate { $is_all = false; $types = array(); for ($i = 0; $i < count($type_controls); $i++) { + $type_controls[$i]->setValue(); $directive_name = $type_controls[$i]->getDirectiveName(); $directive_value = $type_controls[$i]->getDirectiveValue(); if (is_null($directive_value) || $directive_value === false) { diff --git a/gui/baculum/protected/Web/Portlets/NewFileSetExcMenu.tpl b/gui/baculum/protected/Web/Portlets/NewFileSetExcMenu.tpl index b6ec8b2b8..68e15fb74 100644 --- a/gui/baculum/protected/Web/Portlets/NewFileSetExcMenu.tpl +++ b/gui/baculum/protected/Web/Portlets/NewFileSetExcMenu.tpl @@ -4,7 +4,6 @@
  • diff --git a/gui/baculum/protected/Web/Portlets/NewFileSetFileOptMenu.tpl b/gui/baculum/protected/Web/Portlets/NewFileSetFileOptMenu.tpl index 6a04f1842..2458ff604 100644 --- a/gui/baculum/protected/Web/Portlets/NewFileSetFileOptMenu.tpl +++ b/gui/baculum/protected/Web/Portlets/NewFileSetFileOptMenu.tpl @@ -4,8 +4,7 @@
  •  <%[ Add single file/directory ]%> @@ -21,7 +20,6 @@
  • @@ -31,7 +29,6 @@
  • diff --git a/gui/baculum/protected/Web/Portlets/NewFileSetIncExcMenu.tpl b/gui/baculum/protected/Web/Portlets/NewFileSetIncExcMenu.tpl index fdff9793b..c6f2bcbc4 100644 --- a/gui/baculum/protected/Web/Portlets/NewFileSetIncExcMenu.tpl +++ b/gui/baculum/protected/Web/Portlets/NewFileSetIncExcMenu.tpl @@ -4,7 +4,6 @@
  • @@ -14,7 +13,6 @@
  • @@ -24,7 +22,6 @@
  • @@ -34,7 +31,6 @@
  • @@ -44,7 +40,6 @@
  • @@ -54,7 +49,6 @@
  • @@ -64,7 +58,6 @@
  • @@ -74,7 +67,6 @@
  • @@ -84,7 +76,6 @@
  • @@ -94,7 +85,6 @@
  • @@ -104,7 +94,6 @@
  • @@ -114,7 +103,6 @@
  • diff --git a/gui/baculum/protected/Web/Portlets/NewRunscriptMenu.tpl b/gui/baculum/protected/Web/Portlets/NewRunscriptMenu.tpl index 14b151a59..9d6ce5df1 100644 --- a/gui/baculum/protected/Web/Portlets/NewRunscriptMenu.tpl +++ b/gui/baculum/protected/Web/Portlets/NewRunscriptMenu.tpl @@ -4,7 +4,6 @@
  • diff --git a/gui/baculum/protected/Web/Portlets/NewScheduleMenu.tpl b/gui/baculum/protected/Web/Portlets/NewScheduleMenu.tpl index a8de99be1..421b52f69 100644 --- a/gui/baculum/protected/Web/Portlets/NewScheduleMenu.tpl +++ b/gui/baculum/protected/Web/Portlets/NewScheduleMenu.tpl @@ -4,8 +4,7 @@
  • <%=$this->SourceTemplateControl->ComponentType == 'dir' ? 'Run' : ($this->SourceTemplateControl->ComponentType == 'fd' ? 'Connect' : '')%> diff --git a/gui/baculum/themes/Baculum-v2/css/baculum.css b/gui/baculum/themes/Baculum-v2/css/baculum.css index 53a5c0bcf..d3ddd9c43 100644 --- a/gui/baculum/themes/Baculum-v2/css/baculum.css +++ b/gui/baculum/themes/Baculum-v2/css/baculum.css @@ -373,6 +373,10 @@ table.status_table td, table.status_table td i { width: 160px; } +.xtinybox { + width: 65px !important; +} + a.raw { text-decoration: none; } @@ -501,6 +505,10 @@ table.component td:nth-of-type(1) { flex-basis: 385px; } +.status_header.schedule > div { + flex-basis: 300px; +} + #status_storage_filters select { width: 250px; margin-left: 10px; @@ -567,3 +575,9 @@ img.job_weather_icon { flex-basis: 140px; height: 28px; } + +/* Schedule setting */ +.day_of_month, .week_of_month, .week_of_year { + width: 14px; +} +