[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 13 | |
---|
[1989] | 14 | // Set env |
---|
[0] | 15 | |
---|
[1989] | 16 | $core->blog->settings->addNamespace('maintenance'); |
---|
[1925] | 17 | |
---|
| 18 | $maintenance = new dcMaintenance($core); |
---|
[1989] | 19 | $tasks = $maintenance->getTasks(); |
---|
[1925] | 20 | |
---|
| 21 | $headers = ''; |
---|
| 22 | $p_url = 'plugin.php?p=maintenance'; |
---|
| 23 | $task = null; |
---|
[1940] | 24 | $expired = array(); |
---|
[1925] | 25 | |
---|
| 26 | $code = empty($_POST['code']) ? null : (integer) $_POST['code']; |
---|
[1989] | 27 | $tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab']; |
---|
[1925] | 28 | |
---|
| 29 | // Get task object |
---|
| 30 | |
---|
| 31 | if (!empty($_REQUEST['task'])) { |
---|
| 32 | $task = $maintenance->getTask($_REQUEST['task']); |
---|
| 33 | |
---|
| 34 | if ($task === null) { |
---|
| 35 | $core->error->add('Unknow task ID'); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | $task->code($code); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | // Execute task |
---|
| 42 | |
---|
| 43 | if ($task && !empty($_POST['task']) && $task->id() == $_POST['task']) { |
---|
| 44 | try { |
---|
| 45 | $code = $task->execute(); |
---|
| 46 | if (false === $code) { |
---|
| 47 | throw new Exception($task->error()); |
---|
[0] | 48 | } |
---|
[1925] | 49 | if (true === $code) { |
---|
[1940] | 50 | $maintenance->setLog($task->id()); |
---|
[2389] | 51 | |
---|
| 52 | dcPage::addSuccessNotice($task->success()); |
---|
| 53 | http::redirect($p_url.'&task='.$task->id().'&tab='.$tab.'#'.$tab); |
---|
[1925] | 54 | } |
---|
[0] | 55 | } |
---|
[1925] | 56 | catch (Exception $e) { |
---|
[0] | 57 | $core->error->add($e->getMessage()); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
[2389] | 61 | // Save settings |
---|
| 62 | |
---|
| 63 | if (!empty($_POST['save_settings'])) { |
---|
| 64 | |
---|
| 65 | try { |
---|
| 66 | $core->blog->settings->maintenance->put( |
---|
[2566] | 67 | 'plugin_message', |
---|
| 68 | !empty($_POST['settings_plugin_message']), |
---|
| 69 | 'boolean', |
---|
| 70 | 'Display alert message of late tasks on plugin page', |
---|
| 71 | true, |
---|
[2389] | 72 | true |
---|
| 73 | ); |
---|
| 74 | |
---|
| 75 | foreach($tasks as $t) { |
---|
[2491] | 76 | if (!$t->id()) { |
---|
| 77 | continue; |
---|
| 78 | } |
---|
| 79 | |
---|
[2389] | 80 | if (!empty($_POST['settings_recall_type']) && $_POST['settings_recall_type'] == 'all') { |
---|
| 81 | $ts = $_POST['settings_recall_time']; |
---|
| 82 | } |
---|
| 83 | else { |
---|
| 84 | $ts = empty($_POST['settings_ts_'.$t->id()]) ? 0 : $_POST['settings_ts_'.$t->id()]; |
---|
| 85 | } |
---|
| 86 | $core->blog->settings->maintenance->put( |
---|
[2566] | 87 | 'ts_'.$t->id(), |
---|
| 88 | abs((integer) $ts), |
---|
| 89 | 'integer', |
---|
| 90 | sprintf('Recall time for task %s', $t->id()), |
---|
| 91 | true, |
---|
[2389] | 92 | $t->blog() |
---|
| 93 | ); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | dcPage::addSuccessNotice(__('Maintenance plugin has been successfully configured.')); |
---|
| 97 | http::redirect($p_url.'&tab='.$tab.'#'.$tab); |
---|
| 98 | } |
---|
| 99 | catch(Exception $e) { |
---|
| 100 | $core->error->add($e->getMessage()); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
[1984] | 104 | // Combos |
---|
| 105 | |
---|
| 106 | $combo_ts = array( |
---|
[2044] | 107 | __('Never') => 0, |
---|
[1985] | 108 | __('Every week') => 604800, |
---|
[1984] | 109 | __('Every two weeks') => 1209600, |
---|
| 110 | __('Every month') => 2592000, |
---|
| 111 | __('Every two months') => 5184000 |
---|
| 112 | ); |
---|
| 113 | |
---|
[1925] | 114 | // Display page |
---|
| 115 | |
---|
| 116 | echo '<html><head> |
---|
| 117 | <title>'.__('Maintenance').'</title>'. |
---|
[1984] | 118 | dcPage::jsPageTabs($tab). |
---|
[2044] | 119 | dcPage::jsLoad('index.php?pf=maintenance/js/settings.js'); |
---|
[1925] | 120 | |
---|
[1959] | 121 | if ($task && $task->ajax()) { |
---|
[2566] | 122 | echo |
---|
[1925] | 123 | '<script type="text/javascript">'."\n". |
---|
[1959] | 124 | "//<![CDATA[\n". |
---|
[1925] | 125 | dcPage::jsVar('dotclear.msg.wait', __('Please wait...')). |
---|
| 126 | "//]]>\n". |
---|
| 127 | '</script>'. |
---|
| 128 | dcPage::jsLoad('index.php?pf=maintenance/js/dc.maintenance.js'); |
---|
| 129 | } |
---|
| 130 | |
---|
[2566] | 131 | echo |
---|
[1925] | 132 | $maintenance->getHeaders().' |
---|
[0] | 133 | </head> |
---|
[1925] | 134 | <body>'; |
---|
[0] | 135 | |
---|
[1989] | 136 | // Check if there is somthing to display according to user permissions |
---|
| 137 | if (empty($tasks)) { |
---|
| 138 | echo dcPage::breadcrumb( |
---|
| 139 | array( |
---|
| 140 | __('Plugins') => '', |
---|
[2166] | 141 | __('Maintenance') => '' |
---|
[1989] | 142 | ) |
---|
| 143 | ). |
---|
| 144 | '<p class="warn">'.__('You have not sufficient permissions to view this page.').'</p>'. |
---|
| 145 | '</body></html>'; |
---|
| 146 | |
---|
| 147 | return null; |
---|
| 148 | } |
---|
| 149 | |
---|
[1925] | 150 | if ($task && ($res = $task->step()) !== null) { |
---|
| 151 | |
---|
| 152 | // Page title |
---|
| 153 | |
---|
| 154 | echo dcPage::breadcrumb( |
---|
| 155 | array( |
---|
| 156 | __('Plugins') => '', |
---|
| 157 | '<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '', |
---|
[2166] | 158 | html::escapeHTML($task->name())=> '' |
---|
[1925] | 159 | ) |
---|
| 160 | ); |
---|
| 161 | |
---|
[2483] | 162 | // content |
---|
| 163 | if (substr($res, 0, 1) != '<') { |
---|
| 164 | $res = sprintf('<p class="step-msg">%s</p>', $res); |
---|
| 165 | } |
---|
| 166 | |
---|
[1925] | 167 | // Intermediate task (task required several steps) |
---|
| 168 | |
---|
[2566] | 169 | echo |
---|
[1925] | 170 | '<div class="step-box" id="'.$task->id().'">'. |
---|
[2051] | 171 | '<p class="step-back">'. |
---|
[2483] | 172 | '<a class="back" href="'.$p_url.'&tab='.$task->tab().'#'.$task->tab().'">'.__('Back').'</a>'. |
---|
[2051] | 173 | '</p>'. |
---|
[1925] | 174 | '<h3>'.html::escapeHTML($task->name()).'</h3>'. |
---|
| 175 | '<form action="'.$p_url.'" method="post">'. |
---|
[2483] | 176 | $res. |
---|
[1925] | 177 | '<p class="step-submit">'. |
---|
| 178 | '<input type="submit" value="'.$task->task().'" /> '. |
---|
| 179 | form::hidden(array('task'), $task->id()). |
---|
| 180 | form::hidden(array('code'), (integer) $code). |
---|
| 181 | $core->formNonce(). |
---|
| 182 | '</p>'. |
---|
| 183 | '</form>'. |
---|
| 184 | '</div>'; |
---|
| 185 | } |
---|
| 186 | else { |
---|
| 187 | |
---|
| 188 | // Page title |
---|
| 189 | |
---|
[1358] | 190 | echo dcPage::breadcrumb( |
---|
[1339] | 191 | array( |
---|
| 192 | __('Plugins') => '', |
---|
[2166] | 193 | __('Maintenance') => '' |
---|
[1925] | 194 | ) |
---|
| 195 | ); |
---|
[0] | 196 | |
---|
[1925] | 197 | // Simple task (with only a button to start it) |
---|
| 198 | |
---|
[2044] | 199 | foreach($maintenance->getTabs() as $tab_obj) |
---|
[1955] | 200 | { |
---|
| 201 | $res_group = ''; |
---|
[2044] | 202 | foreach($maintenance->getGroups() as $group_obj) |
---|
[1955] | 203 | { |
---|
| 204 | $res_task = ''; |
---|
[1989] | 205 | foreach($tasks as $t) |
---|
[1955] | 206 | { |
---|
[2566] | 207 | if (!$t->id() |
---|
| 208 | || $t->group() != $group_obj->id() |
---|
[2044] | 209 | || $t->tab() != $tab_obj->id()) { |
---|
[1955] | 210 | continue; |
---|
| 211 | } |
---|
[1925] | 212 | |
---|
[2566] | 213 | $res_task .= |
---|
[1955] | 214 | '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. |
---|
| 215 | '<label class="classic" for="'.$t->id().'">'. |
---|
| 216 | html::escapeHTML($t->task()).'</label>'; |
---|
| 217 | |
---|
[1984] | 218 | // Expired task alert message |
---|
| 219 | $ts = $t->expired(); |
---|
| 220 | if ($core->blog->settings->maintenance->plugin_message && $ts !== false) { |
---|
| 221 | if ($ts === null) { |
---|
[2566] | 222 | $res_task .= |
---|
[1984] | 223 | '<br /> <span class="warn">'. |
---|
| 224 | __('This task has never been executed.').' '. |
---|
| 225 | __('You should execute it now.').'</span>'; |
---|
| 226 | } |
---|
| 227 | else { |
---|
[2566] | 228 | $res_task .= |
---|
[1984] | 229 | '<br /> <span class="warn">'.sprintf( |
---|
| 230 | __('Last execution of this task was on %s.'), |
---|
| 231 | dt::str($core->blog->settings->system->date_format, $ts).' '. |
---|
| 232 | dt::str($core->blog->settings->system->time_format, $ts) |
---|
| 233 | ).' '. |
---|
| 234 | __('You should execute it now.').'</span>'; |
---|
| 235 | } |
---|
[1955] | 236 | } |
---|
| 237 | |
---|
| 238 | $res_task .= '</p>'; |
---|
[1925] | 239 | } |
---|
| 240 | |
---|
[1955] | 241 | if (!empty($res_task)) { |
---|
[2566] | 242 | $res_group .= |
---|
[1955] | 243 | '<div class="fieldset">'. |
---|
[2044] | 244 | '<h4 id="'.$group_obj->id().'">'.$group_obj->name().'</h4>'. |
---|
[1955] | 245 | $res_task. |
---|
| 246 | '</div>'; |
---|
[1940] | 247 | } |
---|
[1925] | 248 | } |
---|
| 249 | |
---|
[1955] | 250 | if (!empty($res_group)) { |
---|
[2566] | 251 | echo |
---|
[2044] | 252 | '<div id="'.$tab_obj->id().'" class="multi-part" title="'.$tab_obj->name().'">'. |
---|
| 253 | '<h3>'.$tab_obj->name().'</h3>'. |
---|
| 254 | // ($tab_obj->option('summary') ? '<p>'.$tab_obj->option('summary').'</p>' : ''). |
---|
[1955] | 255 | '<form action="'.$p_url.'" method="post">'. |
---|
| 256 | $res_group. |
---|
| 257 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
[2044] | 258 | form::hidden(array('tab'), $tab_obj->id()). |
---|
[1955] | 259 | $core->formNonce().'</p>'. |
---|
[1989] | 260 | '<p class="form-note info">'.__('This may take a very long time.').'</p>'. |
---|
[1955] | 261 | '</form>'. |
---|
| 262 | '</div>'; |
---|
[1925] | 263 | } |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | // Advanced tasks (that required a tab) |
---|
| 267 | |
---|
[1989] | 268 | foreach($tasks as $t) |
---|
[1925] | 269 | { |
---|
[2491] | 270 | if (!$t->id() || $t->group() !== null) { |
---|
[1925] | 271 | continue; |
---|
| 272 | } |
---|
| 273 | |
---|
[2566] | 274 | echo |
---|
[1925] | 275 | '<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'. |
---|
| 276 | '<h3>'.$t->name().'</h3>'. |
---|
| 277 | '<form action="'.$p_url.'" method="post">'. |
---|
| 278 | $t->content(). |
---|
| 279 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
| 280 | form::hidden(array('task'), $t->id()). |
---|
| 281 | form::hidden(array('tab'), $t->id()). |
---|
| 282 | $core->formNonce().'</p>'. |
---|
| 283 | '</form>'. |
---|
| 284 | '</div>'; |
---|
| 285 | } |
---|
[2389] | 286 | |
---|
| 287 | // Settings |
---|
| 288 | |
---|
[2566] | 289 | echo |
---|
[2389] | 290 | '<div id="settings" class="multi-part" title="'.__('Alert settings').'">'. |
---|
| 291 | '<h3>'.__('Alert settings').'</h3>'. |
---|
| 292 | '<form action="'.$p_url.'" method="post">'. |
---|
| 293 | |
---|
| 294 | '<h4 class="pretty-title">'.__('Activation').'</h4>'. |
---|
| 295 | '<p><label for="settings_plugin_message" class="classic">'. |
---|
| 296 | form::checkbox('settings_plugin_message', 1, $core->blog->settings->maintenance->plugin_message). |
---|
| 297 | __('Display alert messages on late tasks').'</label></p>'. |
---|
| 298 | |
---|
| 299 | '<p class="info">'.sprintf( |
---|
| 300 | __('You can place list of late tasks on your %s.'), |
---|
| 301 | '<a href="preferences.php#user-favorites">'.__('Dashboard').'</a>' |
---|
| 302 | ).'</p>'. |
---|
| 303 | |
---|
| 304 | '<h4 class="pretty-title vertical-separator">'.__('Frequency').'</h4>'. |
---|
| 305 | |
---|
| 306 | '<p class="vertical-separator">'.form::radio(array('settings_recall_type', 'settings_recall_all'), 'all').' '. |
---|
| 307 | '<label class="classic" for="settings_recall_all">'. |
---|
[2437] | 308 | '<strong>'.__('Use one recall time for all tasks').'</strong></label></p>'. |
---|
[2389] | 309 | |
---|
| 310 | '<p class="field wide vertical-separator"><label for="settings_recall_time">'.__('Recall time for all tasks:').'</label>'. |
---|
| 311 | form::combo('settings_recall_time', $combo_ts, 'seperate', 'recall-for-all'). |
---|
| 312 | '</p>'. |
---|
| 313 | |
---|
| 314 | '<p class="vertical-separator">'.form::radio(array('settings_recall_type', 'settings_recall_separate'), 'separate', 1).' '. |
---|
| 315 | '<label class="classic" for="settings_recall_separate">'. |
---|
[2437] | 316 | '<strong>'.__('Use one recall time per task').'</strong></label></p>'; |
---|
[2389] | 317 | |
---|
| 318 | foreach($tasks as $t) |
---|
| 319 | { |
---|
[2491] | 320 | if (!$t->id()) { |
---|
| 321 | continue; |
---|
[2566] | 322 | } |
---|
[2389] | 323 | echo |
---|
| 324 | '<div class="two-boxes">'. |
---|
| 325 | |
---|
| 326 | '<p class="field wide"><label for="settings_ts_'.$t->id().'">'.$t->task().'</label>'. |
---|
| 327 | form::combo('settings_ts_'.$t->id(), $combo_ts, $t->ts(), 'recall-per-task'). |
---|
| 328 | '</p>'. |
---|
| 329 | |
---|
| 330 | '</div>'; |
---|
| 331 | } |
---|
| 332 | |
---|
[2566] | 333 | echo |
---|
[2389] | 334 | '<p class="field wide"><input type="submit" value="'.__('Save').'" /> '. |
---|
| 335 | form::hidden(array('tab'), 'settings'). |
---|
| 336 | form::hidden(array('save_settings'), 1). |
---|
| 337 | $core->formNonce().'</p>'. |
---|
| 338 | '</form>'. |
---|
| 339 | '</div>'; |
---|
[0] | 340 | } |
---|
| 341 | |
---|
[2044] | 342 | dcPage::helpBlock('maintenance', 'maintenancetasks'); |
---|
[0] | 343 | |
---|
[2566] | 344 | echo |
---|
[2364] | 345 | '</body></html>'; |
---|