[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) { |
---|
[1984] | 45 | if (!empty($_POST['settings_recall_time']) && $_POST['settings_recall_time'] == 'seperate') { |
---|
| 46 | $ts = empty($_POST['settings_ts_'.$t->id()]) ? 0 : $_POST['settings_ts_'.$t->id()]; |
---|
| 47 | } |
---|
| 48 | else { |
---|
| 49 | $ts = $_POST['settings_recall_time']; |
---|
| 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 | |
---|
| 61 | http::redirect($p_url.'&done=1&tab='.$tab); |
---|
| 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()); |
---|
[1925] | 90 | http::redirect($p_url.'&task='.$task->id().'&done=1&tab='.$tab); |
---|
| 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( |
---|
[1985] | 101 | __('Every week') => 604800, |
---|
[1984] | 102 | __('Every two weeks') => 1209600, |
---|
| 103 | __('Every month') => 2592000, |
---|
| 104 | __('Every two months') => 5184000 |
---|
| 105 | ); |
---|
| 106 | |
---|
| 107 | $full_combo_ts = array_merge(array( |
---|
| 108 | __('Use different periods for each task') => 'seperate'), |
---|
| 109 | $combo_ts |
---|
| 110 | ); |
---|
| 111 | |
---|
| 112 | $task_combo_ts = array_merge(array( |
---|
| 113 | __('Never') => 0), |
---|
| 114 | $combo_ts |
---|
| 115 | ); |
---|
[1940] | 116 | |
---|
[1925] | 117 | // Display page |
---|
| 118 | |
---|
| 119 | echo '<html><head> |
---|
| 120 | <title>'.__('Maintenance').'</title>'. |
---|
[1984] | 121 | dcPage::jsPageTabs($tab). |
---|
| 122 | dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');; |
---|
[1925] | 123 | |
---|
[1959] | 124 | if ($task && $task->ajax()) { |
---|
[1925] | 125 | echo |
---|
| 126 | '<script type="text/javascript">'."\n". |
---|
[1959] | 127 | "//<![CDATA[\n". |
---|
[1925] | 128 | dcPage::jsVar('dotclear.msg.wait', __('Please wait...')). |
---|
| 129 | "//]]>\n". |
---|
| 130 | '</script>'. |
---|
| 131 | dcPage::jsLoad('index.php?pf=maintenance/js/dc.maintenance.js'); |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | echo |
---|
| 135 | $maintenance->getHeaders().' |
---|
[0] | 136 | </head> |
---|
[1925] | 137 | <body>'; |
---|
[0] | 138 | |
---|
[1989] | 139 | // Check if there is somthing to display according to user permissions |
---|
| 140 | if (empty($tasks)) { |
---|
| 141 | echo dcPage::breadcrumb( |
---|
| 142 | array( |
---|
| 143 | __('Plugins') => '', |
---|
| 144 | '<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '', |
---|
| 145 | '<span class="page-title">'.html::escapeHTML($task->name()).'</span>' => '' |
---|
| 146 | ) |
---|
| 147 | ). |
---|
| 148 | '<p class="warn">'.__('You have not sufficient permissions to view this page.').'</p>'. |
---|
| 149 | '</body></html>'; |
---|
| 150 | |
---|
| 151 | return null; |
---|
| 152 | } |
---|
| 153 | |
---|
[1925] | 154 | // Success message |
---|
| 155 | |
---|
[1984] | 156 | if (!empty($_GET['done']) && $tab == 'settings') { |
---|
| 157 | $msg = dcPage::success(__('Settings successfully updated'), true, true, false); |
---|
| 158 | } |
---|
| 159 | elseif (!empty($_GET['done']) && $task) { |
---|
| 160 | $msg = dcPage::success($task->success(), true, true, false); |
---|
| 161 | } |
---|
[1925] | 162 | |
---|
| 163 | if ($task && ($res = $task->step()) !== null) { |
---|
| 164 | |
---|
| 165 | // Page title |
---|
| 166 | |
---|
| 167 | echo dcPage::breadcrumb( |
---|
| 168 | array( |
---|
| 169 | __('Plugins') => '', |
---|
| 170 | '<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '', |
---|
| 171 | '<span class="page-title">'.html::escapeHTML($task->name()).'</span>' => '' |
---|
| 172 | ) |
---|
| 173 | ); |
---|
| 174 | |
---|
[1959] | 175 | echo $msg; |
---|
| 176 | |
---|
[1925] | 177 | // Intermediate task (task required several steps) |
---|
| 178 | |
---|
| 179 | echo |
---|
| 180 | '<div class="step-box" id="'.$task->id().'">'. |
---|
| 181 | '<h3>'.html::escapeHTML($task->name()).'</h3>'. |
---|
| 182 | '<form action="'.$p_url.'" method="post">'. |
---|
| 183 | '<p class="step-msg">'. |
---|
| 184 | $res. |
---|
| 185 | '</p>'. |
---|
| 186 | '<p class="step-submit">'. |
---|
| 187 | '<input type="submit" value="'.$task->task().'" /> '. |
---|
| 188 | form::hidden(array('task'), $task->id()). |
---|
| 189 | form::hidden(array('code'), (integer) $code). |
---|
| 190 | $core->formNonce(). |
---|
| 191 | '</p>'. |
---|
| 192 | '</form>'. |
---|
| 193 | '<p class="step-back">'. |
---|
[1984] | 194 | '<a class="back" href="'.$p_url.'&tab='.$task->tab().'">'.__('Back').'</a>'. |
---|
[1925] | 195 | '</p>'. |
---|
| 196 | '</div>'; |
---|
| 197 | } |
---|
| 198 | else { |
---|
| 199 | |
---|
| 200 | // Page title |
---|
| 201 | |
---|
[1358] | 202 | echo dcPage::breadcrumb( |
---|
[1339] | 203 | array( |
---|
| 204 | __('Plugins') => '', |
---|
| 205 | '<span class="page-title">'.__('Maintenance').'</span>' => '' |
---|
[1925] | 206 | ) |
---|
| 207 | ); |
---|
[0] | 208 | |
---|
[1959] | 209 | echo $msg; |
---|
| 210 | |
---|
[1925] | 211 | // Simple task (with only a button to start it) |
---|
| 212 | |
---|
[1955] | 213 | foreach($maintenance->getTabs() as $tab_id => $tab_name) |
---|
| 214 | { |
---|
| 215 | $res_group = ''; |
---|
[1989] | 216 | foreach($maintenance->getGroups() as $group_id => $group_name) |
---|
[1955] | 217 | { |
---|
| 218 | $res_task = ''; |
---|
[1989] | 219 | foreach($tasks as $t) |
---|
[1955] | 220 | { |
---|
| 221 | if ($t->group() != $group_id || $t->tab() != $tab_id) { |
---|
| 222 | continue; |
---|
| 223 | } |
---|
[1925] | 224 | |
---|
[1955] | 225 | $res_task .= |
---|
| 226 | '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. |
---|
| 227 | '<label class="classic" for="'.$t->id().'">'. |
---|
| 228 | html::escapeHTML($t->task()).'</label>'; |
---|
| 229 | |
---|
[1984] | 230 | // Expired task alert message |
---|
| 231 | $ts = $t->expired(); |
---|
| 232 | if ($core->blog->settings->maintenance->plugin_message && $ts !== false) { |
---|
| 233 | if ($ts === null) { |
---|
| 234 | $res_task .= |
---|
| 235 | '<br /> <span class="warn">'. |
---|
| 236 | __('This task has never been executed.').' '. |
---|
| 237 | __('You should execute it now.').'</span>'; |
---|
| 238 | } |
---|
| 239 | else { |
---|
| 240 | $res_task .= |
---|
| 241 | '<br /> <span class="warn">'.sprintf( |
---|
| 242 | __('Last execution of this task was on %s.'), |
---|
| 243 | dt::str($core->blog->settings->system->date_format, $ts).' '. |
---|
| 244 | dt::str($core->blog->settings->system->time_format, $ts) |
---|
| 245 | ).' '. |
---|
| 246 | __('You should execute it now.').'</span>'; |
---|
| 247 | } |
---|
[1955] | 248 | } |
---|
| 249 | |
---|
| 250 | $res_task .= '</p>'; |
---|
[1925] | 251 | } |
---|
| 252 | |
---|
[1955] | 253 | if (!empty($res_task)) { |
---|
| 254 | $res_group .= |
---|
| 255 | '<div class="fieldset">'. |
---|
| 256 | '<h4 id="'.$group_id.'">'.$group_name.'</h4>'. |
---|
| 257 | $res_task. |
---|
| 258 | '</div>'; |
---|
[1940] | 259 | } |
---|
[1925] | 260 | } |
---|
| 261 | |
---|
[1955] | 262 | if (!empty($res_group)) { |
---|
| 263 | echo |
---|
| 264 | '<div id="'.$tab_id.'" class="multi-part" title="'.$tab_name.'">'. |
---|
| 265 | '<h3>'.$tab_name.'</h3>'. |
---|
| 266 | '<form action="'.$p_url.'" method="post">'. |
---|
| 267 | $res_group. |
---|
| 268 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
| 269 | form::hidden(array('tab'), $tab_id). |
---|
| 270 | $core->formNonce().'</p>'. |
---|
[1989] | 271 | '<p class="form-note info">'.__('This may take a very long time.').'</p>'. |
---|
[1955] | 272 | '</form>'. |
---|
| 273 | '</div>'; |
---|
[1925] | 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | // Advanced tasks (that required a tab) |
---|
| 278 | |
---|
[1989] | 279 | foreach($tasks as $t) |
---|
[1925] | 280 | { |
---|
| 281 | if ($t->group() !== null) { |
---|
| 282 | continue; |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | echo |
---|
| 286 | '<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'. |
---|
| 287 | '<h3>'.$t->name().'</h3>'. |
---|
| 288 | '<form action="'.$p_url.'" method="post">'. |
---|
| 289 | $t->content(). |
---|
| 290 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
| 291 | form::hidden(array('task'), $t->id()). |
---|
| 292 | form::hidden(array('tab'), $t->id()). |
---|
| 293 | $core->formNonce().'</p>'. |
---|
| 294 | '</form>'. |
---|
| 295 | '</div>'; |
---|
| 296 | } |
---|
[1984] | 297 | |
---|
| 298 | // Settings |
---|
| 299 | |
---|
| 300 | echo |
---|
| 301 | '<div id="settings" class="multi-part" title="'.__('Settings').'">'. |
---|
| 302 | '<h3>'.__('Settings').'</h3>'. |
---|
| 303 | '<form action="'.$p_url.'" method="post">'. |
---|
| 304 | |
---|
| 305 | '<p><label for="settings_plugin_message" class="classic">'. |
---|
| 306 | form::checkbox('settings_plugin_message', 1, $core->blog->settings->maintenance->plugin_message). |
---|
[1989] | 307 | __('Display alert messages on late tasks').'</label></p>'. |
---|
[1984] | 308 | |
---|
| 309 | '<p><label for="settings_recall_time">'.__('Recall time for all tasks:').'</label>'. |
---|
| 310 | form::combo('settings_recall_time', $full_combo_ts, 'seperate', 'recall-for-all'). |
---|
| 311 | '</p>'. |
---|
| 312 | |
---|
| 313 | '<p>'.__('Recall time per task:').'</p>'; |
---|
| 314 | |
---|
[1989] | 315 | foreach($tasks as $t) |
---|
[1984] | 316 | { |
---|
| 317 | echo |
---|
| 318 | '<div class="two-boxes">'. |
---|
| 319 | |
---|
| 320 | '<p><label for="settings_ts_'.$t->id().'">'.$t->task().'</label>'. |
---|
| 321 | form::combo('settings_ts_'.$t->id(), $task_combo_ts, $t->ts(), 'recall-per-task'). |
---|
| 322 | '</p>'. |
---|
| 323 | |
---|
| 324 | '</div>'; |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | echo |
---|
| 328 | '<p><input type="submit" value="'.__('Save').'" /> '. |
---|
| 329 | form::hidden(array('tab'), 'settings'). |
---|
| 330 | form::hidden(array('settings'), 1). |
---|
| 331 | $core->formNonce().'</p>'. |
---|
| 332 | '</form>'. |
---|
| 333 | '<p class="info">'.sprintf( |
---|
[1989] | 334 | __('You can place list of late tasks on your %s.'), |
---|
[1984] | 335 | '<a href="preferences.php#user-favorites">'.__('Dashboard').'</a>' |
---|
| 336 | ).'</a></p>'. |
---|
| 337 | '</div>'; |
---|
[0] | 338 | } |
---|
| 339 | |
---|
[186] | 340 | dcPage::helpBlock('maintenance'); |
---|
[0] | 341 | |
---|
[1925] | 342 | echo '</body></html>'; |
---|