Dotclear

source: plugins/dctribune/index.php @ 1531

Revision 1531, 9.2 KB checked in by Osku, 14 years ago (diff)

dctribune 0.6 * New from scratch

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of dctribune, a plugin for Dotclear 2.
5#
6# Copyright (c) 2009 Osku  and contributors
7# Many thanks to Pep, Tomtom and JcDenis
8# Originally from Antoine Libert
9#
10# Licensed under the GPL version 2.0 license.
11# A copy of this license is available in LICENSE file or at
12# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
13#
14# -- END LICENSE BLOCK ------------------------------------
15
16if (!defined('DC_CONTEXT_ADMIN')) { return; }
17
18require DC_ROOT.'/inc/admin/lib.pager.php';
19
20if (!empty($_REQUEST['edit']) && !empty($_REQUEST['id'])) {
21     include dirname(__FILE__).'/edit.php';
22     return;
23}
24
25if (!empty($_REQUEST['config'])) {
26     include dirname(__FILE__).'/config.php';
27     return;
28}
29
30$default_tab = '';
31$params=array();
32
33$status = isset($_GET['status']) ?      $_GET['status'] : '';
34$nb = !empty($_GET['nb']) ?     trim($_GET['nb']) : 0;
35
36if(empty($_GET['filter']) && !empty($_SESSION['messages_filter'])) {
37     $s = unserialize(base64_decode($_SESSION['messages_filter']));
38     if ($s !== false) {
39          $status = isset($s['status'])        ?  $s['status'] : '';
40          $nb = !empty($s['nb']) ?     trim($s['nb']) : '';
41     }
42} elseif (!empty($_GET['filter'])) {
43     $s = array(
44          'status' => $status,
45          'nb' => $nb);
46     $_SESSION['messages_filter']=base64_encode(serialize($s));
47}
48
49$combo_action = array();
50$combo_action[__('Status')] = array(
51__('publish') => 'publish',
52__('unpublish') => 'unpublish',
53__('delete') => 'delete'
54);
55
56$status_combo = array(
57'-' => '',
58__('published') => '1',
59__('unpublished') => '0'
60);
61
62$sortby_combo = array(
63__('Date') => 'tribune_dt',
64__('Status') => 'tribune_state',
65);
66
67$order_combo = array(
68__('Descending') => 'desc',
69__('Ascending') => 'asc'
70);
71     
72$show_filters =  false;
73$add_message = false;
74
75$sortby = !empty($_GET['sortby']) ?  $_GET['sortby'] : '';
76$order = !empty($_GET['order']) ?  $_GET['order'] : '';
77$page = !empty($_GET['page']) ? $_GET['page'] : 1;
78$ip = !empty($_GET['ip']) ? $_GET['ip'] : '';
79$nb_per_page =  10;
80if ((integer) $nb > 0) {
81     if ($nb_per_page != $nb) {
82          $show_filters = true;
83     }
84     $nb_per_page = (integer) $nb;
85}
86
87# - Status filter
88if ($status !== '' && in_array($status,$status_combo)) {
89     $params['tribune_state'] = $status;
90     $show_filters = true;
91}
92
93# - IP filter
94if ($ip) {
95     $params['tribune_ip'] = $ip;
96     $show_filters = true;
97}
98
99if (!in_array($sortby,$sortby_combo))
100     $sortby="tribune_dt";
101if (!in_array($order,$order_combo))
102     $order="desc";
103# - Sortby and order filter
104if ($sortby !== '' && in_array($sortby,$sortby_combo)) {
105     if ($order !== '' && in_array($order,$order_combo)) {
106          $params['order'] = $sortby.' '.$order;
107     }
108     
109     //$show_filters = true;
110}
111
112if (!empty($_POST['actiontribune']) && !empty($_POST['checked']))
113{
114     switch ($_POST['actiontribune']) {
115     case 'publish' : $status = 1; break;
116     case 'unpublish' : $status = 0; break;
117     case 'delete' : $status = -1; break;
118     default : $status = 1; break;
119     }
120
121     if($status >= 0)
122     {
123          foreach ($_POST['checked'] as $k => $v)
124          {
125               try {
126                    $core->tribune->changeState($v, $status);
127               } catch (Exception $e) {
128                    $core->error->add($e->getMessage());
129                    break;
130               }
131          }
132     
133          if (!$core->error->flag()) {
134               http::redirect($p_url.'&msg='.$status);
135          }
136     } 
137     else
138     {
139          foreach ($_POST['checked'] as $k => $v)
140          {
141               try {
142                    $core->tribune->delMsg($v);
143               } catch (Exception $e) {
144                    $core->error->add($e->getMessage());
145                    break;
146               }
147          }
148     
149          if (!$core->error->flag()) {
150               http::redirect($p_url.'&removed=1');
151          }
152     }
153}
154
155if (!empty($_POST['add_message']))
156{
157     $cur = $core->con->openCursor($core->prefix.'tribune');
158     $cur->tribune_nick = $_POST['tribune_nick'];
159     $cur->tribune_msg = $_POST['tribune_msg'];
160
161     try {
162          $tid = $core->tribune->addMsg($cur);
163          http::redirect($p_url.'&addmsg=1');
164     } catch (Exception $e) {
165          $core->error->add($e->getMessage());
166          $add_message = true;
167     }
168}
169
170if (!empty($_POST['saveconfig']))
171{
172     try
173     {
174          $tribune_flag = (empty($_POST['tribune_flag']))?false:true;
175
176          $core->blog->settings->setNamespace('tribune');
177          $core->blog->settings->put('tribune_flag',$tribune_flag,'boolean','Active the tribune module');
178          $core->blog->triggerBlog();
179
180          $msg = __('Configuration successfully updated.');
181     }
182
183     catch (Exception $e)
184     {
185          $core->error->add($e->getMessage());
186     }
187}
188
189$params['limit'] = array((($page-1)*$nb_per_page),$nb_per_page);
190
191try {
192     $rs = $core->tribune->getMsgs($params);
193     $count = $core->tribune->getMsgs($params,true);
194     $pager = new pager($page,$count->f(0),$nb_per_page);
195     $pager->var_page = 'page';
196} catch (Exception $e) {
197     $core->error->add($e->getMessage());
198}
199?>
200<html>
201<head>
202     <title><?php echo __('Free chatbox'); ?></title>
203     <?php echo dcPage::jsToolMan(); 
204     if (!$show_filters) {
205          echo dcPage::jsLoad('js/filter-controls.js');
206     }
207     if (!$add_message) {
208          echo dcPage::jsLoad('index.php?pf=dctribune/js/_tribune.js');
209     }
210     echo dcPage::jsLoad('index.php?pf=dctribune/js/_messages.js');
211     ?>
212     
213</head>
214
215<body>
216<h2><?php echo html::escapeHTML($core->blog->name); ?> &rsaquo; <?php echo sprintf(__('Free chatbox (%s messages)'),$count->f(0));?>
217 &rsaquo; <a class="button" href="<?php echo $p_url.'&amp;config=1'; ?>"><?php echo html::escapeHTML(
218     __('Configuration')); ?></a> </h2>
219
220<?php
221if (isset($_GET['removed'])) {
222     echo '<p class="message">'.__('Message(s) deleted.').'</p>';
223}
224
225if (isset($_GET['addmsg'])) {
226     echo '<p class="message">'.__('Message added.').'</p>';
227}
228
229if (isset($_GET['msg'])) {
230     if($_GET['msg'] == 0)
231          echo '<p class="message">'.__('Message(s) selected offline.').'</p>';
232     else
233          echo '<p class="message">'.__('Message(s) selected online.').'</p>';
234}
235
236?>
237
238<div id="tribune_messages">
239<?php 
240if (!$show_filters) {
241     echo '<p><a id="filter-control" class="form-control" href="#">'.
242     __('Filters').'</a></p>';
243}
244
245echo
246'<form action="plugin.php" method="get" id="filters-form">'.
247'<fieldset><legend>'.__('Filters').'</legend>'.
248'<div class="three-cols">'.
249
250'<div class="col">'.
251'<p><label>'.__('Status:').
252form::combo('status',$status_combo,$status).
253'</label>'.
254'<label>'.__('IP address:').
255form::field('ip',20,39,html::escapeHTML($ip)).
256'</label>'.
257'</p> '.
258'</div>'.
259
260'<div class="col">'.
261'<p><label>'.__('Order by:').
262form::combo('sortby',$sortby_combo,$sortby).
263'</label></p> '.
264'<p>'.
265'<p><label class="classic">'. form::field('nb',3,3,$nb_per_page).' '.
266__('Messages per page').'</label></p>'.
267'</div>'.
268
269'<div class="col">'.
270'<p><label>'.__('Sort:').
271form::combo('order',$order_combo,$order).
272'</label></p>'.
273'<input type="hidden" name="p" value="dctribune" />'.
274'<input type="submit" name="filter" value="'.__('filter').'" /></p>'.
275'</div>'.
276'</div>'.
277'<br class="clear" />'. //Opera sucks
278'</fieldset>'.
279'</form>'.
280'</div>';
281?>
282<div id="tribune_list">
283<form action="plugin.php" method="post" id="tribune-form">
284          <table class="maximal">
285               <thead>
286                    <tr>
287                         <th colspan="2"><?php echo __('Nick'); ?></th>
288                         <th><?php echo __('Message'); ?></th>
289                         <th><?php echo __('IP'); ?></th>
290                         <th><?php echo __('Date'); ?></th>
291                         <th><?php echo __('Status'); ?></th>
292                         <th>&nbsp;</th>
293                    </tr>
294               </thead>
295               <tbody id="tribune-list">
296<?php
297while ($rs->fetch())
298{
299     if($rs->tribune_state == 0) {
300          $line = 'offline';
301          $status = '<img alt="'.__('unpublished').'" title="'.__('unpublished').'" src="images/check-off.png" />';
302     }
303     else
304     {
305          $line = '';
306          $status = '<img alt="'.__('published').'" title="'.__('published').'" src="images/check-on.png" />';
307     }
308     $edit = '<a href="'.$p_url.'&amp;edit=1&amp;id='.$rs->tribune_id.'"><img src="images/edit-mini.png" alt="" title="'.__('modify this message').'" /></a>';
309     echo
310          '<tr class="line '.$line.'" id="l_'.$rs->tribune_id.'">'.
311          '<td class="minimal">'.form::checkbox(array('checked[]'),$rs->tribune_id).'</td>'.
312          '<td>'.html::escapeHTML($rs->tribune_nick).'</td>'.
313          '<td class="maximal">'.html::escapeHTML($rs->tribune_msg).'</td>'.
314          '<td>'.html::escapeHTML($rs->tribune_ip).'</td>'.
315          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->tribune_dt).'</td>'.
316          '<td class="nowrap status">'.$status.'</td>'.
317          '<td class="nowrap status">'.$edit.'</td>'.
318          '</tr>'
319          ;
320}
321?>
322               </tbody>
323          </table>
324
325          <div class="two-cols">
326         
327               <?php echo '<p class="col checkboxes-helpers"></p>';?>
328<?php echo
329     '<p class="col right">'.__('Selected messages action:').' '.
330     form::hidden(array('p'),'dctribune').
331     form::combo('actiontribune',$combo_action).
332     $core->formNonce().
333     '<input type="submit" value="'.__('ok').'" /></p>';
334?>
335          </div>
336     </form>
337     <?php echo '<p>'.__('Page(s)').' : '.$pager->getLinks().'</p>';?>
338</div>
339
340<br/>
341
342<div id="tribune_add">
343<?php 
344if (!$add_message) {
345     echo '<div class="two-cols"><p><a id="tribune-control" class="button" href="#">'.
346     __('Write a new message').'</a></p></div>';
347}
348?>
349
350
351<?php
352echo
353     '<form action="'.$p_url.'" method="post" id="add-message-form">'.
354     '<fieldset><legend>'.__('Publish a message').'</legend>'.
355
356     '<p><label class="classic required" title="'.__('Required field').'">'.__('Nick:').' '.
357     form::field('tribune_nick',30,255,$core->auth->getInfo('user_displayname'),'',7).'</label></p>'.
358
359     '<p class="area"><label class="classic required" title="'.__('Required field').'">'.__('Message:').' '.
360     form::textarea('tribune_msg',50,3,'','',7).'</label></p>'.
361
362     '<p>'.form::hidden(array('p'),'dctribune').
363     $core->formNonce().
364     '<input type="submit" name="add_message" value="'.__('publish').'" /></p>'.
365     '</fieldset>'.
366     '</form>'.
367     '</div>';
368?>
369
370
371
372
373</body>
374</html>
Note: See TracBrowser for help on using the repository browser.

Sites map