Dotclear

source: plugins/maintenance/index.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 10.5 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Simplify licence block at the beginning of each file

Line 
1<?php
2/**
3 * @brief maintenance, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
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$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
31if (!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
43if ($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    } catch (Exception $e) {
56        $core->error->add($e->getMessage());
57    }
58}
59
60// Save settings
61
62if (!empty($_POST['save_settings'])) {
63
64    try {
65        $core->blog->settings->maintenance->put(
66            'plugin_message',
67            !empty($_POST['settings_plugin_message']),
68            'boolean',
69            'Display alert message of late tasks on plugin page',
70            true,
71            true
72        );
73
74        foreach ($tasks as $t) {
75            if (!$t->id()) {
76                continue;
77            }
78
79            if (!empty($_POST['settings_recall_type']) && $_POST['settings_recall_type'] == 'all') {
80                $ts = $_POST['settings_recall_time'];
81            } else {
82                $ts = empty($_POST['settings_ts_' . $t->id()]) ? 0 : $_POST['settings_ts_' . $t->id()];
83            }
84            $core->blog->settings->maintenance->put(
85                'ts_' . $t->id(),
86                abs((integer) $ts),
87                'integer',
88                sprintf('Recall time for task %s', $t->id()),
89                true,
90                $t->blog()
91            );
92        }
93
94        dcPage::addSuccessNotice(__('Maintenance plugin has been successfully configured.'));
95        http::redirect($p_url . '&tab=' . $tab . '#' . $tab);
96    } catch (Exception $e) {
97        $core->error->add($e->getMessage());
98    }
99}
100
101// Combos
102
103$combo_ts = array(
104    __('Never')            => 0,
105    __('Every week')       => 604800,
106    __('Every two weeks')  => 1209600,
107    __('Every month')      => 2592000,
108    __('Every two months') => 5184000
109);
110
111// Display page
112
113echo '<html><head>
114<title>' . __('Maintenance') . '</title>' .
115dcPage::jsPageTabs($tab) .
116dcPage::jsLoad(dcPage::getPF('maintenance/js/settings.js'));
117
118if ($task && $task->ajax()) {
119    echo
120    '<script type="text/javascript">' . "\n" .
121    dcPage::jsVar('dotclear.msg.wait', __('Please wait...')) .
122    '</script>' .
123    dcPage::jsLoad(dcPage::getPF('maintenance/js/dc.maintenance.js'));
124}
125
126echo
127$maintenance->getHeaders() . '
128</head>
129<body>';
130
131// Check if there is somthing to display according to user permissions
132if (empty($tasks)) {
133    echo dcPage::breadcrumb(
134        array(
135            __('Plugins')     => '',
136            __('Maintenance') => ''
137        )
138    ) .
139    '<p class="warn">' . __('You have not sufficient permissions to view this page.') . '</p>' .
140        '</body></html>';
141
142    return;
143}
144
145if ($task && ($res = $task->step()) !== null) {
146
147    // Page title
148
149    echo dcPage::breadcrumb(
150        array(
151            __('Plugins')                                            => '',
152            '<a href="' . $p_url . '">' . __('Maintenance') . '</a>' => '',
153            html::escapeHTML($task->name())                          => ''
154        )
155    ) . dcPage::notices();
156
157    // content
158    if (substr($res, 0, 1) != '<') {
159        $res = sprintf('<p class="step-msg">%s</p>', $res);
160    }
161
162    // Intermediate task (task required several steps)
163
164    echo
165    '<div class="step-box" id="' . $task->id() . '">' .
166    '<p class="step-back">' .
167    '<a class="back" href="' . $p_url . '&amp;tab=' . $task->tab() . '#' . $task->tab() . '">' . __('Back') . '</a>' .
168    '</p>' .
169    '<h3>' . html::escapeHTML($task->name()) . '</h3>' .
170    '<form action="' . $p_url . '" method="post">' .
171    $res .
172    '<p class="step-submit">' .
173    '<input type="submit" value="' . $task->task() . '" /> ' .
174    form::hidden(array('task'), $task->id()) .
175    form::hidden(array('code'), (integer) $code) .
176    $core->formNonce() .
177        '</p>' .
178        '</form>' .
179        '</div>';
180} else {
181
182    // Page title
183
184    echo dcPage::breadcrumb(
185        array(
186            __('Plugins')     => '',
187            __('Maintenance') => ''
188        )
189    ) . dcPage::notices();
190
191    // Simple task (with only a button to start it)
192
193    foreach ($maintenance->getTabs() as $tab_obj) {
194        $res_group = '';
195        foreach ($maintenance->getGroups() as $group_obj) {
196            $res_task = '';
197            foreach ($tasks as $t) {
198                if (!$t->id()
199                    || $t->group() != $group_obj->id()
200                    || $t->tab() != $tab_obj->id()) {
201                    continue;
202                }
203
204                $res_task .=
205                '<p>' . form::radio(array('task', $t->id()), $t->id()) . ' ' .
206                '<label class="classic" for="' . $t->id() . '">' .
207                html::escapeHTML($t->task()) . '</label>';
208
209                // Expired task alert message
210                $ts = $t->expired();
211                if ($core->blog->settings->maintenance->plugin_message && $ts !== false) {
212                    if ($ts === null) {
213                        $res_task .=
214                        '<br /> <span class="warn">' .
215                        __('This task has never been executed.') . ' ' .
216                        __('You should execute it now.') . '</span>';
217                    } else {
218                        $res_task .=
219                        '<br /> <span class="warn">' . sprintf(
220                            __('Last execution of this task was on %s.'),
221                            dt::str($core->blog->settings->system->date_format, $ts) . ' ' .
222                            dt::str($core->blog->settings->system->time_format, $ts)
223                        ) . ' ' .
224                        __('You should execute it now.') . '</span>';
225                    }
226                }
227
228                $res_task .= '</p>';
229            }
230
231            if (!empty($res_task)) {
232                $res_group .=
233                '<div class="fieldset">' .
234                '<h4 id="' . $group_obj->id() . '">' . $group_obj->name() . '</h4>' .
235                    $res_task .
236                    '</div>';
237            }
238        }
239
240        if (!empty($res_group)) {
241            echo
242            '<div id="' . $tab_obj->id() . '" class="multi-part" title="' . $tab_obj->name() . '">' .
243            '<h3>' . $tab_obj->name() . '</h3>' .
244            // ($tab_obj->option('summary') ? '<p>'.$tab_obj->option('summary').'</p>' : '').
245            '<form action="' . $p_url . '" method="post">' .
246            $res_group .
247            '<p><input type="submit" value="' . __('Execute task') . '" /> ' .
248            form::hidden(array('tab'), $tab_obj->id()) .
249            $core->formNonce() . '</p>' .
250            '<p class="form-note info">' . __('This may take a very long time.') . '</p>' .
251                '</form>' .
252                '</div>';
253        }
254    }
255
256    // Advanced tasks (that required a tab)
257
258    foreach ($tasks as $t) {
259        if (!$t->id() || $t->group() !== null) {
260            continue;
261        }
262
263        echo
264        '<div id="' . $t->id() . '" class="multi-part" title="' . $t->name() . '">' .
265        '<h3>' . $t->name() . '</h3>' .
266        '<form action="' . $p_url . '" method="post">' .
267        $t->content() .
268        '<p><input type="submit" value="' . __('Execute task') . '" /> ' .
269        form::hidden(array('task'), $t->id()) .
270        form::hidden(array('tab'), $t->id()) .
271        $core->formNonce() . '</p>' .
272            '</form>' .
273            '</div>';
274    }
275
276    // Settings
277
278    echo
279    '<div id="settings" class="multi-part" title="' . __('Alert settings') . '">' .
280    '<h3>' . __('Alert settings') . '</h3>' .
281    '<form action="' . $p_url . '" method="post">' .
282
283    '<h4 class="pretty-title">' . __('Activation') . '</h4>' .
284    '<p><label for="settings_plugin_message" class="classic">' .
285    form::checkbox('settings_plugin_message', 1, $core->blog->settings->maintenance->plugin_message) .
286    __('Display alert messages on late tasks') . '</label></p>' .
287
288    '<p class="info">' . sprintf(
289        __('You can place list of late tasks on your %s.'),
290        '<a href="' . $core->adminurl->get('admin.user.preferences') . '#user-favorites">' . __('Dashboard') . '</a>'
291    ) . '</p>' .
292
293    '<h4 class="pretty-title vertical-separator">' . __('Frequency') . '</h4>' .
294
295    '<p class="vertical-separator">' . form::radio(array('settings_recall_type', 'settings_recall_all'), 'all') . ' ' .
296    '<label class="classic" for="settings_recall_all">' .
297    '<strong>' . __('Use one recall time for all tasks') . '</strong></label></p>' .
298
299    '<p class="field wide vertical-separator"><label for="settings_recall_time">' . __('Recall time for all tasks:') . '</label>' .
300    form::combo('settings_recall_time', $combo_ts, 'seperate', 'recall-for-all') .
301    '</p>' .
302
303    '<p class="vertical-separator">' . form::radio(array('settings_recall_type', 'settings_recall_separate'), 'separate', 1) . ' ' .
304    '<label class="classic" for="settings_recall_separate">' .
305    '<strong>' . __('Use one recall time per task') . '</strong></label></p>';
306
307    foreach ($tasks as $t) {
308        if (!$t->id()) {
309            continue;
310        }
311        echo
312        '<div class="two-boxes">' .
313
314        '<p class="field wide"><label for="settings_ts_' . $t->id() . '">' . $t->task() . '</label>' .
315        form::combo('settings_ts_' . $t->id(), $combo_ts, $t->ts(), 'recall-per-task') .
316            '</p>' .
317
318            '</div>';
319    }
320
321    echo
322    '<p class="field wide"><input type="submit" value="' . __('Save') . '" /> ' .
323    form::hidden(array('tab'), 'settings') .
324    form::hidden(array('save_settings'), 1) .
325    $core->formNonce() . '</p>' .
326        '</form>' .
327        '</div>';
328}
329
330dcPage::helpBlock('maintenance', 'maintenancetasks');
331
332echo
333    '</body></html>';
Note: See TracBrowser for help on using the repository browser.

Sites map