Dotclear

source: plugins/activityReport/inc/lib.activity.report.index.php @ 1457

Revision 1457, 7.2 KB checked in by JcDenis, 14 years ago (diff)

activityReport 0.2:

  • First lab release
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of activityReport, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13if (!defined('DC_CONTEXT_ADMIN')){return;}
14
15class activityReportLib
16{
17     public static function settingTab($core,$title,$global=false)
18     {
19          $O =& $core->activityReport;
20          if ($global)
21          {
22               $O->setGlobal();
23               $t = 'super';
24          }
25          else
26          {
27               $t = 'blog';
28          }
29
30          $combo_int = array(
31               __('every hour') => 3600,
32               __('every 2 hours') => 7200,
33               __('2 times by day') => 43200,
34               __('every day') => 86400,
35               __('every 2 days') => 172800,
36               __('every week') => 604800
37          );
38
39          $redirect = false;
40          if (!empty($_POST[$t.'_settings']))
41          {
42               # Active notification on this blog
43               $O->setSetting('active',isset($_POST['active']));
44               # Add dashboard items
45               $O->setSetting('dashboardItem',isset($_POST['dashboardItem']));
46               # Report interval
47               if (in_array($_POST['interval'],$combo_int))
48               {
49                    $O->setSetting('interval',(integer) $_POST['interval']);
50               }
51               # mail list
52               $O->setSetting('mailinglist',explode(';',$_POST['mailinglist']));
53               # request infos
54               $requests = isset($_POST['requests']) ? $_POST['requests'] : array();
55               $O->setSetting('requests',$requests);
56               #blogs
57               $blogs = isset($_POST['blogs']) ? $_POST['blogs'] : array();
58               $O->setSetting('blogs',$blogs);
59               
60               $redirect = true;
61          }
62
63          # force to send report now
64          if (!empty($_POST[$t.'_force_report']))
65          {
66               $core->activityReport->needReport(true);
67               $redirect = true;
68          }
69
70          # force to delete all logs now
71          if (!empty($_POST[$t.'_force_delete']))
72          {
73               $core->activityReport->deleteLogs();
74               $redirect = true;
75          }
76
77          if ($redirect)
78          {
79               http::redirect('plugin.php?p=activityReport&tab='.$t.'_settings');
80          }
81
82          $bl = $O->getSetting('lastreport');
83          $blog_last = !$bl ? __('never') : dt::str('%Y-%m-%d %H:%M:%S',$bl,$core->blog->settings->blog_timezone);
84
85          $bi = $O->getSetting('interval');
86          $blog_next = !$bl ? __('on new activity') : dt::str('%Y-%m-%d %H:%M:%S',$bl+$bi,$core->blog->settings->blog_timezone);
87
88          $emails = implode(';',$O->getSetting('mailinglist'));
89
90          ?>
91          <div class="multi-part" id="<?php echo $t; ?>_settings" title="<?php echo $title; ?>">
92          <form method="post" action="plugin.php">
93
94          <fieldset><legend><?php echo __('Settings'); ?></legend>
95
96          <p><label class="classic"><?php echo
97          form::checkbox(array('active'),'1',
98           $O->getSetting('active')).' '.
99          ($global ? 
100               __('Enable super administrator report') :
101               __('Enable report on this blog')
102          ); ?>
103          </label></p>
104          <?php
105
106          if (!$global)
107          {
108
109               ?>
110               <p><label class="classic"><?php echo
111               form::checkbox(array('dashboardItem'),'1',
112                    $O->getSetting('dashboardItem')).' '.
113                    __('Add activity report on dashboard items'); ?>
114               </label></p>
115               <?php
116
117          }
118
119          ?>
120          <p><label class="classic"><?php echo __('Send report:').'<br />'.
121           form::combo(array('interval'),$combo_int,$O->getSetting('interval')); ?>
122          </label></p>
123
124          <p><label class="classic"><?php echo __('Recipients:').'<br />'.
125           form::field(array('mailinglist'),60,255,$emails); ?>
126          </label></p>
127          <p class="form-note"><?php echo __('Separate multiple email addresses with a semicolon ";"'); ?></p>
128
129          <ul>
130          <li><?php echo __('Last report by email:').' '.$blog_last; ?></li>
131          <li><?php echo __('Next report by email:').' '.$blog_next; ?></li>
132          </ul>
133
134          </fieldset>
135          <?php
136
137          if ($global)
138          {
139               ?>
140               <fieldset><legend><?php echo __('Blogs'); ?></legend>
141               <div class="three-cols">
142               <?php
143
144               $i = 0;
145               $selected_blogs = $O->getSetting('blogs');
146               $blogs = $core->getBlogs();
147               while($blogs->fetch())
148               {
149                    $blog_id = $core->con->escape($blogs->blog_id);
150                    ?>
151                    <div class="col">
152                    <p><label class="classic"><?php echo
153                    form::checkbox(array('blogs['.$i.']'),$blog_id,
154                    in_array($blog_id,$selected_blogs)).' '.
155                    $blogs->blog_name.' ('.$blog_id.')'; ?>
156                    </label></p>
157                    </div>
158                    <?php
159
160                    $i++;
161               }
162
163               ?>
164               </div>
165               </fieldset>
166               <?php
167          }
168
169          ?>
170          <fieldset><legend><?php echo __('Report'); ?></legend>
171          <div class="three-cols">
172          <?php
173
174          $groups = $O->getGroups();
175          $blog_request = $O->getSetting('requests');
176
177          foreach($groups as $k_group => $v_group)
178          {
179
180               ?>
181               <div class="col">
182               <h3><?php echo __($v_group['title']); ?></h3>
183               <?php
184
185               foreach($v_group['actions'] as $k_action => $v_action)
186               {
187                    ?>
188                    <p><label class="classic"><?php echo 
189                    form::checkbox(array('requests['.$k_group.']['.$k_action.']'),'1',
190                    isset($blog_request[$k_group][$k_action])).' '.__($v_action['title']); ?>
191                    </label></p>
192                    <?php
193               }
194
195               ?>
196               </div>
197               <?php
198
199          }
200
201          ?>
202          </div>
203          </fieldset>
204
205          <p>
206           <input type="submit" name="<?php echo $t; ?>_settings" value="<?php echo __('Save'); ?>" />
207           <?php 
208           if (!empty($emails))
209           {
210               ?>
211               <input type="submit" name="<?php echo $t; ?>_force_report" value="<?php echo __('Send report by email now'); ?>" />
212               <?php
213           }
214           if ($global)
215           {
216               ?>
217               <input type="submit" name="<?php echo $t; ?>_force_delete" value="<?php echo __('Delete all logs'); ?>" />
218               <?php
219           }
220           echo 
221           form::hidden(array('p'),'activityReport').
222           form::hidden(array('tab'),$t.'_settings').
223           $core->formNonce();
224           ?>
225          </p>
226          </form>
227          </div>
228          <?php
229          $O->unsetGlobal();
230     }
231
232     public static function logTab($core,$title,$global=false)
233     {
234          $O =& $core->activityReport;
235          if ($global)
236          {
237               $O->setGlobal();
238               $t = 'super';
239          }
240          else
241          {
242               $t = 'blog';
243          }
244
245          $params = array();
246          $logs = $O->getLogs($params);
247
248          ?>
249          <div class="multi-part" id="<?php echo $t; ?>_logs" title="<?php echo $title; ?>">
250          <?php
251
252          if ($logs->isEmpty())
253          {
254               echo '<p>'.__('No log').'</p>';
255          }
256          else
257          {
258
259               ?>
260               <table>
261               <thead>
262               <tr>
263               <th><?php echo __('Action'); ?></th>
264               <th><?php echo __('Message'); ?></th>
265               <th><?php echo __('Date'); ?></th>
266               <?php if ($global) { ?>
267               <th><?php echo __('Blog'); ?></th>
268               <?php } ?>
269               </tr>
270               </thead>
271               <tbody>
272               <?php
273
274               while($logs->fetch())
275               {
276                    $off = $global && $logs->activity_blog_status == 1 ?
277                         ' offline' : '';
278                    $date = dt::str(
279                         '%Y-%m-%d %H:%M:%S',
280                         strtotime($logs->activity_dt),
281                         $core->blog->settings->blog_timezone
282                    );
283                    $action = $O->getGroups($logs->activity_group,$logs->activity_action);
284                    $msg = vsprintf(__($action['msg']),$O->decode($logs->activity_logs));
285                    ?>
286                    <tr class="line<?php echo $off; ?>">
287                    <td class="nowrap"><?php echo __($action['title']); ?></td>
288                    <td class="maximal"><?php echo $msg; ?></td>
289                    <td class="nowrap"><?php echo $date; ?></td>
290                    <?php if ($global) { ?>
291                    <td class="nowrap"><?php echo $logs->blog_id; ?></td>
292                    <?php } ?>
293                    </tr>
294                    <?php
295               }
296
297               ?>
298               </tbody>
299               </table>
300               <?php
301
302          }
303
304          ?>
305          </div>
306          <?php
307
308          $O->unsetGlobal();
309     }
310}
311?>
Note: See TracBrowser for help on using the repository browser.

Sites map