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