Dotclear

source: plugins/maintenance/index.php @ 2017:a1702eaaaf80

Revision 2017:a1702eaaaf80, 8.3 KB checked in by Anne Kozlika <kozlika@…>, 12 years ago (diff)

Améliorations présentation et vocabulaire pour Maintenance.

Line 
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 -----------------------------------------
12if (!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
32if (!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_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, 
57                    $t->blog()
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
68// Get task object
69
70if (!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
82if ($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);
91          }
92     }
93     catch (Exception $e) {
94          $core->error->add($e->getMessage());
95     }
96}
97
98// Combos
99
100$combo_ts = array(
101     __('Every week')         => 604800,
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);
116
117// Display page
118
119echo '<html><head>
120<title>'.__('Maintenance').'</title>'.
121dcPage::jsPageTabs($tab).
122dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');;
123
124if ($task && $task->ajax()) {
125     echo 
126     '<script type="text/javascript">'."\n".
127     "//<![CDATA[\n".
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
134echo 
135$maintenance->getHeaders().'
136</head>
137<body>';
138
139// Check if there is somthing to display according to user permissions
140if (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
154// Success message
155
156if (!empty($_GET['done']) && $tab == 'settings') {
157     $msg = dcPage::success(__('Settings successfully updated'), true, true, false);
158}
159elseif (!empty($_GET['done']) && $task) {
160     $msg = dcPage::success($task->success(), true, true, false);
161}
162
163if ($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
175     echo $msg;
176
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">'.
194          '<a class="back" href="'.$p_url.'&tab='.$task->tab().'">'.__('Back').'</a>'.
195     '</p>'.
196     '</div>';
197}
198else {
199
200     // Page title
201
202     echo dcPage::breadcrumb(
203          array(
204               __('Plugins') => '',
205               '<span class="page-title">'.__('Maintenance').'</span>' => ''
206          )
207     );
208
209     echo $msg;
210
211     // Simple task (with only a button to start it)
212
213     foreach($maintenance->getTabs() as $tab_id => $tab_name)
214     {
215          $res_group = '';
216          foreach($maintenance->getGroups() as $group_id => $group_name)
217          {
218               $res_task = '';
219               foreach($tasks as $t)
220               {
221                    if ($t->group() != $group_id || $t->tab() != $tab_id) {
222                         continue;
223                    }
224
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
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                         }
248                    }
249
250                    $res_task .= '</p>';
251               }
252
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>';
259               }
260          }
261
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>'.
271               '<p class="form-note info">'.__('This may take a very long time.').'</p>'.
272               '</form>'.
273               '</div>';
274          }
275     }
276
277     // Advanced tasks (that required a tab)
278
279     foreach($tasks as $t)
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     }
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     '<h4 class="pretty-title">'.__('Activation').'</h4>'.
306     '<p><label for="settings_plugin_message" class="classic">'.
307     form::checkbox('settings_plugin_message', 1, $core->blog->settings->maintenance->plugin_message).
308     __('Display alert messages on late tasks').'</label></p>'.
309
310     '<p class="info">'.sprintf(
311          __('You can place list of late tasks on your %s.'),
312          '<a href="preferences.php#user-favorites">'.__('Dashboard').'</a>'
313     ).'</a></p>'.
314
315     '<h4 class="pretty-title">'.__('Frequency').'</h4>'.
316
317     '<p><label for="settings_recall_time">'.__('Recall time for all tasks:').'</label>'.
318     form::combo('settings_recall_time', $full_combo_ts, 'seperate', 'recall-for-all').
319     '</p>'.
320
321     '<h5 class="vertical-separator">'.__('Recall time per task:').'</h5>';
322
323     foreach($tasks as $t)
324     {
325          echo
326          '<div class="two-boxes">'.
327
328          '<p><label for="settings_ts_'.$t->id().'">'.$t->task().'</label>'.
329          form::combo('settings_ts_'.$t->id(), $task_combo_ts, $t->ts(), 'recall-per-task').
330          '</p>'.
331
332          '</div>';
333     }
334
335     echo 
336     '<p><input type="submit" value="'.__('Save this settings').'" /> '.
337     form::hidden(array('tab'), 'settings').
338     form::hidden(array('settings'), 1).
339     $core->formNonce().'</p>'.
340     '</form>'.
341     '</div>';
342}
343
344dcPage::helpBlock('maintenance');
345
346echo '</body></html>';
Note: See TracBrowser for help on using the repository browser.

Sites map