1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
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 | |
---|
14 | // Set env |
---|
15 | |
---|
16 | $core->blog->settings->addNamespace('maintenance'); |
---|
17 | |
---|
18 | $maintenance = new dcMaintenance($core); |
---|
19 | $tasks = $maintenance->getTasks(); |
---|
20 | |
---|
21 | $headers = ''; |
---|
22 | $p_url = $core->adminurl->get('admin.plugin.maintenance'); |
---|
23 | $task = null; |
---|
24 | $expired = array(); |
---|
25 | |
---|
26 | $code = empty($_POST['code']) ? null : (integer) $_POST['code']; |
---|
27 | $tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab']; |
---|
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()); |
---|
48 | } |
---|
49 | if (true === $code) { |
---|
50 | $maintenance->setLog($task->id()); |
---|
51 | |
---|
52 | dcPage::addSuccessNotice($task->success()); |
---|
53 | http::redirect($p_url.'&task='.$task->id().'&tab='.$tab.'#'.$tab); |
---|
54 | } |
---|
55 | } |
---|
56 | catch (Exception $e) { |
---|
57 | $core->error->add($e->getMessage()); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | // Save settings |
---|
62 | |
---|
63 | if (!empty($_POST['save_settings'])) { |
---|
64 | |
---|
65 | try { |
---|
66 | $core->blog->settings->maintenance->put( |
---|
67 | 'plugin_message', |
---|
68 | !empty($_POST['settings_plugin_message']), |
---|
69 | 'boolean', |
---|
70 | 'Display alert message of late tasks on plugin page', |
---|
71 | true, |
---|
72 | true |
---|
73 | ); |
---|
74 | |
---|
75 | foreach($tasks as $t) { |
---|
76 | if (!$t->id()) { |
---|
77 | continue; |
---|
78 | } |
---|
79 | |
---|
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( |
---|
87 | 'ts_'.$t->id(), |
---|
88 | abs((integer) $ts), |
---|
89 | 'integer', |
---|
90 | sprintf('Recall time for task %s', $t->id()), |
---|
91 | true, |
---|
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 | |
---|
104 | // Combos |
---|
105 | |
---|
106 | $combo_ts = array( |
---|
107 | __('Never') => 0, |
---|
108 | __('Every week') => 604800, |
---|
109 | __('Every two weeks') => 1209600, |
---|
110 | __('Every month') => 2592000, |
---|
111 | __('Every two months') => 5184000 |
---|
112 | ); |
---|
113 | |
---|
114 | // Display page |
---|
115 | |
---|
116 | echo '<html><head> |
---|
117 | <title>'.__('Maintenance').'</title>'. |
---|
118 | dcPage::jsPageTabs($tab). |
---|
119 | dcPage::jsLoad(dcPage::getPF('maintenance/js/settings.js')); |
---|
120 | |
---|
121 | if ($task && $task->ajax()) { |
---|
122 | echo |
---|
123 | '<script type="text/javascript">'."\n". |
---|
124 | "//<![CDATA[\n". |
---|
125 | dcPage::jsVar('dotclear.msg.wait', __('Please wait...')). |
---|
126 | "//]]>\n". |
---|
127 | '</script>'. |
---|
128 | dcPage::jsLoad(dcPage::getPF('maintenance/js/dc.maintenance.js')); |
---|
129 | } |
---|
130 | |
---|
131 | echo |
---|
132 | $maintenance->getHeaders().' |
---|
133 | </head> |
---|
134 | <body>'; |
---|
135 | |
---|
136 | // Check if there is somthing to display according to user permissions |
---|
137 | if (empty($tasks)) { |
---|
138 | echo dcPage::breadcrumb( |
---|
139 | array( |
---|
140 | __('Plugins') => '', |
---|
141 | __('Maintenance') => '' |
---|
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 | |
---|
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 | html::escapeHTML($task->name())=> '' |
---|
159 | ) |
---|
160 | ).dcPage::notices(); |
---|
161 | |
---|
162 | // content |
---|
163 | if (substr($res, 0, 1) != '<') { |
---|
164 | $res = sprintf('<p class="step-msg">%s</p>', $res); |
---|
165 | } |
---|
166 | |
---|
167 | // Intermediate task (task required several steps) |
---|
168 | |
---|
169 | echo |
---|
170 | '<div class="step-box" id="'.$task->id().'">'. |
---|
171 | '<p class="step-back">'. |
---|
172 | '<a class="back" href="'.$p_url.'&tab='.$task->tab().'#'.$task->tab().'">'.__('Back').'</a>'. |
---|
173 | '</p>'. |
---|
174 | '<h3>'.html::escapeHTML($task->name()).'</h3>'. |
---|
175 | '<form action="'.$p_url.'" method="post">'. |
---|
176 | $res. |
---|
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 | |
---|
190 | echo dcPage::breadcrumb( |
---|
191 | array( |
---|
192 | __('Plugins') => '', |
---|
193 | __('Maintenance') => '' |
---|
194 | ) |
---|
195 | ).dcPage::notices(); |
---|
196 | |
---|
197 | // Simple task (with only a button to start it) |
---|
198 | |
---|
199 | foreach($maintenance->getTabs() as $tab_obj) |
---|
200 | { |
---|
201 | $res_group = ''; |
---|
202 | foreach($maintenance->getGroups() as $group_obj) |
---|
203 | { |
---|
204 | $res_task = ''; |
---|
205 | foreach($tasks as $t) |
---|
206 | { |
---|
207 | if (!$t->id() |
---|
208 | || $t->group() != $group_obj->id() |
---|
209 | || $t->tab() != $tab_obj->id()) { |
---|
210 | continue; |
---|
211 | } |
---|
212 | |
---|
213 | $res_task .= |
---|
214 | '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. |
---|
215 | '<label class="classic" for="'.$t->id().'">'. |
---|
216 | html::escapeHTML($t->task()).'</label>'; |
---|
217 | |
---|
218 | // Expired task alert message |
---|
219 | $ts = $t->expired(); |
---|
220 | if ($core->blog->settings->maintenance->plugin_message && $ts !== false) { |
---|
221 | if ($ts === null) { |
---|
222 | $res_task .= |
---|
223 | '<br /> <span class="warn">'. |
---|
224 | __('This task has never been executed.').' '. |
---|
225 | __('You should execute it now.').'</span>'; |
---|
226 | } |
---|
227 | else { |
---|
228 | $res_task .= |
---|
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 | } |
---|
236 | } |
---|
237 | |
---|
238 | $res_task .= '</p>'; |
---|
239 | } |
---|
240 | |
---|
241 | if (!empty($res_task)) { |
---|
242 | $res_group .= |
---|
243 | '<div class="fieldset">'. |
---|
244 | '<h4 id="'.$group_obj->id().'">'.$group_obj->name().'</h4>'. |
---|
245 | $res_task. |
---|
246 | '</div>'; |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | if (!empty($res_group)) { |
---|
251 | echo |
---|
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>' : ''). |
---|
255 | '<form action="'.$p_url.'" method="post">'. |
---|
256 | $res_group. |
---|
257 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
258 | form::hidden(array('tab'), $tab_obj->id()). |
---|
259 | $core->formNonce().'</p>'. |
---|
260 | '<p class="form-note info">'.__('This may take a very long time.').'</p>'. |
---|
261 | '</form>'. |
---|
262 | '</div>'; |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | // Advanced tasks (that required a tab) |
---|
267 | |
---|
268 | foreach($tasks as $t) |
---|
269 | { |
---|
270 | if (!$t->id() || $t->group() !== null) { |
---|
271 | continue; |
---|
272 | } |
---|
273 | |
---|
274 | echo |
---|
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 | } |
---|
286 | |
---|
287 | // Settings |
---|
288 | |
---|
289 | echo |
---|
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="'.$core->adminurl->get('admin.user.preferences').'#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">'. |
---|
308 | '<strong>'.__('Use one recall time for all tasks').'</strong></label></p>'. |
---|
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">'. |
---|
316 | '<strong>'.__('Use one recall time per task').'</strong></label></p>'; |
---|
317 | |
---|
318 | foreach($tasks as $t) |
---|
319 | { |
---|
320 | if (!$t->id()) { |
---|
321 | continue; |
---|
322 | } |
---|
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 | |
---|
333 | echo |
---|
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>'; |
---|
340 | } |
---|
341 | |
---|
342 | dcPage::helpBlock('maintenance', 'maintenancetasks'); |
---|
343 | |
---|
344 | echo |
---|
345 | '</body></html>'; |
---|