Dotclear

source: plugins/maintenance/index.php @ 2175:44a940977175

Revision 2175:44a940977175, 6.0 KB checked in by Denis Jean-Chirstian <contact@…>, 12 years ago (diff)

Merge from default

RevLine 
[0]1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
[1179]6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
[0]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
[1989]14// Set env
[0]15
[1989]16$core->blog->settings->addNamespace('maintenance');
[1925]17
18$maintenance = new dcMaintenance($core);
[1989]19$tasks = $maintenance->getTasks();
[1925]20
[1984]21$msg = '';
[1925]22$headers = '';
23$p_url = 'plugin.php?p=maintenance';
24$task = null;
[1940]25$expired = array();
[1925]26
27$code = empty($_POST['code']) ? null : (integer) $_POST['code'];
[1989]28$tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab'];
[1925]29
30// Get task object
31
32if (!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
44if ($task && !empty($_POST['task']) && $task->id() == $_POST['task']) {
45     try {
46          $code = $task->execute();
47          if (false === $code) {
48               throw new Exception($task->error());
[0]49          }
[1925]50          if (true === $code) {
[1940]51               $maintenance->setLog($task->id());
[2045]52               http::redirect($p_url.'&task='.$task->id().'&done=1&tab='.$tab.'#'.$tab);
[1925]53          }
[0]54     }
[1925]55     catch (Exception $e) {
[0]56          $core->error->add($e->getMessage());
57     }
58}
59
[1984]60// Combos
61
62$combo_ts = array(
[2044]63     __('Never')              => 0,
[1985]64     __('Every week')         => 604800,
[1984]65     __('Every two weeks')    => 1209600,
66     __('Every month')        => 2592000,
67     __('Every two months')   => 5184000
68);
69
[1925]70// Display page
71
72echo '<html><head>
73<title>'.__('Maintenance').'</title>'.
[1984]74dcPage::jsPageTabs($tab).
[2044]75dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');
[1925]76
[1959]77if ($task && $task->ajax()) {
[1925]78     echo 
79     '<script type="text/javascript">'."\n".
[1959]80     "//<![CDATA[\n".
[1925]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
87echo 
88$maintenance->getHeaders().'
[0]89</head>
[1925]90<body>';
[0]91
[1989]92// Check if there is somthing to display according to user permissions
93if (empty($tasks)) {
94     echo dcPage::breadcrumb(
95          array(
96               __('Plugins') => '',
[2166]97               __('Maintenance') => ''
[1989]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
[1925]106// Success message
107
[1984]108if (!empty($_GET['done']) && $tab == 'settings') {
109     $msg = dcPage::success(__('Settings successfully updated'), true, true, false);
110}
111elseif (!empty($_GET['done']) && $task) {
112     $msg = dcPage::success($task->success(), true, true, false);
113}
[1925]114
115if ($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>' => '',
[2166]123               html::escapeHTML($task->name())=> ''
[1925]124          )
125     );
126
[1959]127     echo $msg;
128
[1925]129     // Intermediate task (task required several steps)
130
131     echo 
132     '<div class="step-box" id="'.$task->id().'">'.
[2051]133     '<p class="step-back">'.
134          '<a class="back" href="'.$p_url.'&tab='.$task->tab().'#'.$task->tab().'">'.__('Back').'</a>'.
135     '</p>'.
[1925]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}
150else {
151
152     // Page title
153
[1358]154     echo dcPage::breadcrumb(
[1339]155          array(
156               __('Plugins') => '',
[2166]157               __('Maintenance') => ''
[1925]158          )
159     );
[0]160
[1959]161     echo $msg;
162
[1925]163     // Simple task (with only a button to start it)
164
[2044]165     foreach($maintenance->getTabs() as $tab_obj)
[1955]166     {
167          $res_group = '';
[2044]168          foreach($maintenance->getGroups() as $group_obj)
[1955]169          {
170               $res_task = '';
[1989]171               foreach($tasks as $t)
[1955]172               {
[2044]173                    if ($t->group() != $group_obj->id() 
174                     || $t->tab() != $tab_obj->id()) {
[1955]175                         continue;
176                    }
[1925]177
[2044]178                    $res_task .= 
[1955]179                    '<p>'.form::radio(array('task', $t->id()), $t->id()).' '.
180                    '<label class="classic" for="'.$t->id().'">'.
181                    html::escapeHTML($t->task()).'</label>';
182
[1984]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                         }
[1955]201                    }
202
203                    $res_task .= '</p>';
[1925]204               }
205
[1955]206               if (!empty($res_task)) {
207                    $res_group .= 
208                    '<div class="fieldset">'.
[2044]209                    '<h4 id="'.$group_obj->id().'">'.$group_obj->name().'</h4>'.
[1955]210                    $res_task.
211                    '</div>';
[1940]212               }
[1925]213          }
214
[1955]215          if (!empty($res_group)) {
216               echo 
[2044]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>' : '').
[1955]220               '<form action="'.$p_url.'" method="post">'.
221               $res_group.
222               '<p><input type="submit" value="'.__('Execute task').'" /> '.
[2044]223               form::hidden(array('tab'), $tab_obj->id()).
[1955]224               $core->formNonce().'</p>'.
[1989]225               '<p class="form-note info">'.__('This may take a very long time.').'</p>'.
[1955]226               '</form>'.
227               '</div>';
[1925]228          }
229     }
230
231     // Advanced tasks (that required a tab)
232
[1989]233     foreach($tasks as $t)
[1925]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     }
[0]251}
252
[2044]253dcPage::helpBlock('maintenance', 'maintenancetasks');
[0]254
[1925]255echo '</body></html>';
Note: See TracBrowser for help on using the repository browser.

Sites map