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 | $msg = ''; |
---|
22 | $headers = ''; |
---|
23 | $p_url = 'plugin.php?p=maintenance'; |
---|
24 | $task = null; |
---|
25 | $expired = array(); |
---|
26 | |
---|
27 | $code = empty($_POST['code']) ? null : (integer) $_POST['code']; |
---|
28 | $tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab']; |
---|
29 | |
---|
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', |
---|
39 | 'Display alert message of late tasks on plugin page', |
---|
40 | true, |
---|
41 | true |
---|
42 | ); |
---|
43 | |
---|
44 | foreach($tasks as $t) { |
---|
45 | if (!empty($_POST['settings_recall_type']) && $_POST['settings_recall_type'] == 'all') { |
---|
46 | $ts = $_POST['settings_recall_time']; |
---|
47 | } |
---|
48 | else { |
---|
49 | $ts = empty($_POST['settings_ts_'.$t->id()]) ? 0 : $_POST['settings_ts_'.$t->id()]; |
---|
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, |
---|
57 | $t->blog() |
---|
58 | ); |
---|
59 | } |
---|
60 | |
---|
61 | http::redirect($p_url.'&done=1&tab='.$tab.'#'.$tab); |
---|
62 | } |
---|
63 | catch(Exception $e) { |
---|
64 | $core->error->add($e->getMessage()); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
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()); |
---|
87 | } |
---|
88 | if (true === $code) { |
---|
89 | $maintenance->setLog($task->id()); |
---|
90 | http::redirect($p_url.'&task='.$task->id().'&done=1&tab='.$tab.'#'.$tab); |
---|
91 | } |
---|
92 | } |
---|
93 | catch (Exception $e) { |
---|
94 | $core->error->add($e->getMessage()); |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | // Combos |
---|
99 | |
---|
100 | $combo_ts = array( |
---|
101 | __('Never') => 0, |
---|
102 | __('Every week') => 604800, |
---|
103 | __('Every two weeks') => 1209600, |
---|
104 | __('Every month') => 2592000, |
---|
105 | __('Every two months') => 5184000 |
---|
106 | ); |
---|
107 | |
---|
108 | // Display page |
---|
109 | |
---|
110 | echo '<html><head> |
---|
111 | <title>'.__('Maintenance').'</title>'. |
---|
112 | dcPage::jsPageTabs($tab). |
---|
113 | dcPage::jsLoad('index.php?pf=maintenance/js/settings.js'); |
---|
114 | |
---|
115 | if ($task && $task->ajax()) { |
---|
116 | echo |
---|
117 | '<script type="text/javascript">'."\n". |
---|
118 | "//<![CDATA[\n". |
---|
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().' |
---|
127 | </head> |
---|
128 | <body>'; |
---|
129 | |
---|
130 | // Check if there is somthing to display according to user permissions |
---|
131 | if (empty($tasks)) { |
---|
132 | echo dcPage::breadcrumb( |
---|
133 | array( |
---|
134 | __('Plugins') => '', |
---|
135 | '<span class="page-title">'.__('Maintenance').'</span>' => '' |
---|
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 | |
---|
144 | // Success message |
---|
145 | |
---|
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 | } |
---|
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 | |
---|
165 | echo $msg; |
---|
166 | |
---|
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">'. |
---|
184 | '<a class="back" href="'.$p_url.'&tab='.$task->tab().'#'.$task->tab().'">'.__('Back').'</a>'. |
---|
185 | '</p>'. |
---|
186 | '</div>'; |
---|
187 | } |
---|
188 | else { |
---|
189 | |
---|
190 | // Page title |
---|
191 | |
---|
192 | echo dcPage::breadcrumb( |
---|
193 | array( |
---|
194 | __('Plugins') => '', |
---|
195 | '<span class="page-title">'.__('Maintenance').'</span>' => '' |
---|
196 | ) |
---|
197 | ); |
---|
198 | |
---|
199 | echo $msg; |
---|
200 | |
---|
201 | // Simple task (with only a button to start it) |
---|
202 | |
---|
203 | foreach($maintenance->getTabs() as $tab_obj) |
---|
204 | { |
---|
205 | $res_group = ''; |
---|
206 | foreach($maintenance->getGroups() as $group_obj) |
---|
207 | { |
---|
208 | $res_task = ''; |
---|
209 | foreach($tasks as $t) |
---|
210 | { |
---|
211 | if ($t->group() != $group_obj->id() |
---|
212 | || $t->tab() != $tab_obj->id()) { |
---|
213 | continue; |
---|
214 | } |
---|
215 | |
---|
216 | $res_task .= |
---|
217 | '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. |
---|
218 | '<label class="classic" for="'.$t->id().'">'. |
---|
219 | html::escapeHTML($t->task()).'</label>'; |
---|
220 | |
---|
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 | } |
---|
239 | } |
---|
240 | |
---|
241 | $res_task .= '</p>'; |
---|
242 | } |
---|
243 | |
---|
244 | if (!empty($res_task)) { |
---|
245 | $res_group .= |
---|
246 | '<div class="fieldset">'. |
---|
247 | '<h4 id="'.$group_obj->id().'">'.$group_obj->name().'</h4>'. |
---|
248 | $res_task. |
---|
249 | '</div>'; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | if (!empty($res_group)) { |
---|
254 | echo |
---|
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>' : ''). |
---|
258 | '<form action="'.$p_url.'" method="post">'. |
---|
259 | $res_group. |
---|
260 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
261 | form::hidden(array('tab'), $tab_obj->id()). |
---|
262 | $core->formNonce().'</p>'. |
---|
263 | '<p class="form-note info">'.__('This may take a very long time.').'</p>'. |
---|
264 | '</form>'. |
---|
265 | '</div>'; |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | // Advanced tasks (that required a tab) |
---|
270 | |
---|
271 | foreach($tasks as $t) |
---|
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 | } |
---|
289 | |
---|
290 | // Settings |
---|
291 | |
---|
292 | echo |
---|
293 | '<div id="settings" class="multi-part" title="'.__('Settings').'">'. |
---|
294 | '<h3>'.__('Settings').'</h3>'. |
---|
295 | '<form action="'.$p_url.'" method="post">'. |
---|
296 | |
---|
297 | '<h4 class="pretty-title">'.__('Activation').'</h4>'. |
---|
298 | '<p><label for="settings_plugin_message" class="classic">'. |
---|
299 | form::checkbox('settings_plugin_message', 1, $core->blog->settings->maintenance->plugin_message). |
---|
300 | __('Display alert messages on late tasks').'</label></p>'. |
---|
301 | |
---|
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>' |
---|
305 | ).'</p>'. |
---|
306 | |
---|
307 | '<h4 class="pretty-title">'.__('Frequency').'</h4>'. |
---|
308 | |
---|
309 | '<p>'.form::radio(array('settings_recall_type', 'settings_recall_all'), 'all').' '. |
---|
310 | '<label class="classic" for="settings_recall_all">'. |
---|
311 | __('Use one recall time for all tasks').'</label>'. |
---|
312 | |
---|
313 | '<p><label for="settings_recall_time">'.__('Recall time for all tasks:').'</label>'. |
---|
314 | form::combo('settings_recall_time', $combo_ts, 'seperate', 'recall-for-all'). |
---|
315 | '</p>'. |
---|
316 | |
---|
317 | '<p>'.form::radio(array('settings_recall_type', 'settings_recall_separate'), 'separate', 1).' '. |
---|
318 | '<label class="classic" for="settings_recall_separate">'. |
---|
319 | __('Use one recall time per task').'</label>'; |
---|
320 | |
---|
321 | foreach($tasks as $t) |
---|
322 | { |
---|
323 | echo |
---|
324 | '<div class="two-boxes">'. |
---|
325 | |
---|
326 | '<p><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><input type="submit" value="'.__('Save this settings').'" /> '. |
---|
335 | form::hidden(array('tab'), 'settings'). |
---|
336 | form::hidden(array('settings'), 1). |
---|
337 | $core->formNonce().'</p>'. |
---|
338 | '</form>'. |
---|
339 | '</div>'; |
---|
340 | } |
---|
341 | |
---|
342 | dcPage::helpBlock('maintenance', 'maintenancetasks'); |
---|
343 | |
---|
344 | echo '</body></html>'; |
---|