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