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 | // Get task object |
---|
31 | |
---|
32 | if (!empty($_REQUEST['task'])) { |
---|
33 | $task = $maintenance->getTask($_REQUEST['task']); |
---|
34 | |
---|
35 | if ($task === null) { |
---|
36 | $core->error->add('Unknow task ID'); |
---|
37 | } |
---|
38 | |
---|
39 | $task->code($code); |
---|
40 | } |
---|
41 | |
---|
42 | // Execute task |
---|
43 | |
---|
44 | if ($task && !empty($_POST['task']) && $task->id() == $_POST['task']) { |
---|
45 | try { |
---|
46 | $code = $task->execute(); |
---|
47 | if (false === $code) { |
---|
48 | throw new Exception($task->error()); |
---|
49 | } |
---|
50 | if (true === $code) { |
---|
51 | $maintenance->setLog($task->id()); |
---|
52 | http::redirect($p_url.'&task='.$task->id().'&done=1&tab='.$tab.'#'.$tab); |
---|
53 | } |
---|
54 | } |
---|
55 | catch (Exception $e) { |
---|
56 | $core->error->add($e->getMessage()); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | // Combos |
---|
61 | |
---|
62 | $combo_ts = array( |
---|
63 | __('Never') => 0, |
---|
64 | __('Every week') => 604800, |
---|
65 | __('Every two weeks') => 1209600, |
---|
66 | __('Every month') => 2592000, |
---|
67 | __('Every two months') => 5184000 |
---|
68 | ); |
---|
69 | |
---|
70 | // Display page |
---|
71 | |
---|
72 | echo '<html><head> |
---|
73 | <title>'.__('Maintenance').'</title>'. |
---|
74 | dcPage::jsPageTabs($tab). |
---|
75 | dcPage::jsLoad('index.php?pf=maintenance/js/settings.js'); |
---|
76 | |
---|
77 | if ($task && $task->ajax()) { |
---|
78 | echo |
---|
79 | '<script type="text/javascript">'."\n". |
---|
80 | "//<![CDATA[\n". |
---|
81 | dcPage::jsVar('dotclear.msg.wait', __('Please wait...')). |
---|
82 | "//]]>\n". |
---|
83 | '</script>'. |
---|
84 | dcPage::jsLoad('index.php?pf=maintenance/js/dc.maintenance.js'); |
---|
85 | } |
---|
86 | |
---|
87 | echo |
---|
88 | $maintenance->getHeaders().' |
---|
89 | </head> |
---|
90 | <body>'; |
---|
91 | |
---|
92 | // Check if there is somthing to display according to user permissions |
---|
93 | if (empty($tasks)) { |
---|
94 | echo dcPage::breadcrumb( |
---|
95 | array( |
---|
96 | __('Plugins') => '', |
---|
97 | __('Maintenance') => '' |
---|
98 | ) |
---|
99 | ). |
---|
100 | '<p class="warn">'.__('You have not sufficient permissions to view this page.').'</p>'. |
---|
101 | '</body></html>'; |
---|
102 | |
---|
103 | return null; |
---|
104 | } |
---|
105 | |
---|
106 | // Success message |
---|
107 | |
---|
108 | if (!empty($_GET['done']) && $tab == 'settings') { |
---|
109 | $msg = dcPage::success(__('Settings successfully updated'), true, true, false); |
---|
110 | } |
---|
111 | elseif (!empty($_GET['done']) && $task) { |
---|
112 | $msg = dcPage::success($task->success(), true, true, false); |
---|
113 | } |
---|
114 | |
---|
115 | if ($task && ($res = $task->step()) !== null) { |
---|
116 | |
---|
117 | // Page title |
---|
118 | |
---|
119 | echo dcPage::breadcrumb( |
---|
120 | array( |
---|
121 | __('Plugins') => '', |
---|
122 | '<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '', |
---|
123 | html::escapeHTML($task->name())=> '' |
---|
124 | ) |
---|
125 | ); |
---|
126 | |
---|
127 | echo $msg; |
---|
128 | |
---|
129 | // Intermediate task (task required several steps) |
---|
130 | |
---|
131 | echo |
---|
132 | '<div class="step-box" id="'.$task->id().'">'. |
---|
133 | '<p class="step-back">'. |
---|
134 | '<a class="back" href="'.$p_url.'&tab='.$task->tab().'#'.$task->tab().'">'.__('Back').'</a>'. |
---|
135 | '</p>'. |
---|
136 | '<h3>'.html::escapeHTML($task->name()).'</h3>'. |
---|
137 | '<form action="'.$p_url.'" method="post">'. |
---|
138 | '<p class="step-msg">'. |
---|
139 | $res. |
---|
140 | '</p>'. |
---|
141 | '<p class="step-submit">'. |
---|
142 | '<input type="submit" value="'.$task->task().'" /> '. |
---|
143 | form::hidden(array('task'), $task->id()). |
---|
144 | form::hidden(array('code'), (integer) $code). |
---|
145 | $core->formNonce(). |
---|
146 | '</p>'. |
---|
147 | '</form>'. |
---|
148 | '</div>'; |
---|
149 | } |
---|
150 | else { |
---|
151 | |
---|
152 | // Page title |
---|
153 | |
---|
154 | echo dcPage::breadcrumb( |
---|
155 | array( |
---|
156 | __('Plugins') => '', |
---|
157 | __('Maintenance') => '' |
---|
158 | ) |
---|
159 | ); |
---|
160 | |
---|
161 | echo $msg; |
---|
162 | |
---|
163 | // Simple task (with only a button to start it) |
---|
164 | |
---|
165 | foreach($maintenance->getTabs() as $tab_obj) |
---|
166 | { |
---|
167 | $res_group = ''; |
---|
168 | foreach($maintenance->getGroups() as $group_obj) |
---|
169 | { |
---|
170 | $res_task = ''; |
---|
171 | foreach($tasks as $t) |
---|
172 | { |
---|
173 | if ($t->group() != $group_obj->id() |
---|
174 | || $t->tab() != $tab_obj->id()) { |
---|
175 | continue; |
---|
176 | } |
---|
177 | |
---|
178 | $res_task .= |
---|
179 | '<p>'.form::radio(array('task', $t->id()), $t->id()).' '. |
---|
180 | '<label class="classic" for="'.$t->id().'">'. |
---|
181 | html::escapeHTML($t->task()).'</label>'; |
---|
182 | |
---|
183 | // Expired task alert message |
---|
184 | $ts = $t->expired(); |
---|
185 | if ($core->blog->settings->maintenance->plugin_message && $ts !== false) { |
---|
186 | if ($ts === null) { |
---|
187 | $res_task .= |
---|
188 | '<br /> <span class="warn">'. |
---|
189 | __('This task has never been executed.').' '. |
---|
190 | __('You should execute it now.').'</span>'; |
---|
191 | } |
---|
192 | else { |
---|
193 | $res_task .= |
---|
194 | '<br /> <span class="warn">'.sprintf( |
---|
195 | __('Last execution of this task was on %s.'), |
---|
196 | dt::str($core->blog->settings->system->date_format, $ts).' '. |
---|
197 | dt::str($core->blog->settings->system->time_format, $ts) |
---|
198 | ).' '. |
---|
199 | __('You should execute it now.').'</span>'; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | $res_task .= '</p>'; |
---|
204 | } |
---|
205 | |
---|
206 | if (!empty($res_task)) { |
---|
207 | $res_group .= |
---|
208 | '<div class="fieldset">'. |
---|
209 | '<h4 id="'.$group_obj->id().'">'.$group_obj->name().'</h4>'. |
---|
210 | $res_task. |
---|
211 | '</div>'; |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | if (!empty($res_group)) { |
---|
216 | echo |
---|
217 | '<div id="'.$tab_obj->id().'" class="multi-part" title="'.$tab_obj->name().'">'. |
---|
218 | '<h3>'.$tab_obj->name().'</h3>'. |
---|
219 | // ($tab_obj->option('summary') ? '<p>'.$tab_obj->option('summary').'</p>' : ''). |
---|
220 | '<form action="'.$p_url.'" method="post">'. |
---|
221 | $res_group. |
---|
222 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
223 | form::hidden(array('tab'), $tab_obj->id()). |
---|
224 | $core->formNonce().'</p>'. |
---|
225 | '<p class="form-note info">'.__('This may take a very long time.').'</p>'. |
---|
226 | '</form>'. |
---|
227 | '</div>'; |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | // Advanced tasks (that required a tab) |
---|
232 | |
---|
233 | foreach($tasks as $t) |
---|
234 | { |
---|
235 | if ($t->group() !== null) { |
---|
236 | continue; |
---|
237 | } |
---|
238 | |
---|
239 | echo |
---|
240 | '<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'. |
---|
241 | '<h3>'.$t->name().'</h3>'. |
---|
242 | '<form action="'.$p_url.'" method="post">'. |
---|
243 | $t->content(). |
---|
244 | '<p><input type="submit" value="'.__('Execute task').'" /> '. |
---|
245 | form::hidden(array('task'), $t->id()). |
---|
246 | form::hidden(array('tab'), $t->id()). |
---|
247 | $core->formNonce().'</p>'. |
---|
248 | '</form>'. |
---|
249 | '</div>'; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | dcPage::helpBlock('maintenance', 'maintenancetasks'); |
---|
254 | |
---|
255 | echo '</body></html>'; |
---|