3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
4 * Copyright 2012, Franck Villaume - TrivialDev
6 * This file is a part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with FusionForge. If not, see <http://www.gnu.org/licenses/>.
22 require_once('Widget.class.php');
23 require_once $gfwww.'include/my_utils.php';
26 * Widget_MyMonitoredForums
28 * Forums that are actively monitored
30 class Widget_MyMonitoredForums extends Widget {
31 function Widget_MyMonitoredForums() {
32 $this->Widget('mymonitoredforums');
36 return _("Monitored Forums");
39 function getContent() {
40 $html_my_monitored_forums = '';
41 $sql="SELECT DISTINCT groups.group_id, groups.group_name, forum_group_list.group_forum_id ".
42 "FROM groups,forum_group_list,forum_monitored_forums ".
43 "WHERE groups.group_id=forum_group_list.group_id ".
44 "AND groups.status = 'A' ".
45 "AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id ".
46 "AND forum_monitored_forums.user_id=$1 ";
47 $um = UserManager::instance();
48 $current_user = $um->getCurrentUser();
49 if ($current_user->getStatus()=='S') {
50 $projects = $current_user->getProjects();
51 $sql .= "AND groups.group_id IN (". implode(',', $projects) .") ";
53 //$sql .= "GROUP BY groups.group_id ORDER BY groups.group_id ASC LIMIT 100";
54 $sql .= "ORDER BY groups.group_id ASC LIMIT 100";
56 $result=db_query_params($sql,array(user_getid()));
58 while ($r = db_fetch_array($result)) {
59 if (forge_check_perm('project', $r['group_id'], 'read')
60 && forge_check_perm('forum', $r['group_forum_id'], 'read')) {
65 if (!$result || $rows < 1) {
66 $html_my_monitored_forums .= '<div class="warning">' . _("You are not monitoring any forums.") . '</div><p>' . _("If you monitor forums, you will be sent new posts in the form of an email, with a link to the new message.") . '</p><p>' . _("You can monitor forums by clicking on the appropriate menu item in the discussion forum itself.") . '</p>';
68 $request =& HTTPRequest::instance();
69 $html_my_monitored_forums .= '<table style="width:100%">';
70 for ($j=0; $j<$rows; $j++) {
71 $group_id = $glist[$j]['group_id'];
73 $sql2="SELECT forum_group_list.group_forum_id,forum_group_list.forum_name ".
74 "FROM groups,forum_group_list,forum_monitored_forums ".
75 "WHERE groups.group_id=forum_group_list.group_id ".
76 "AND groups.group_id=$1".
77 "AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id ".
78 "AND forum_monitored_forums.user_id=$2 LIMIT 100";
80 $result2 = db_query_params($sql2, array($group_id, user_getid()));
82 while ($r = db_fetch_array($result2)) {
83 if (forge_check_perm('forum', $r['group_forum_id'], 'read')) {
88 $rows2 = count($flist);
90 $vItemId = new Valid_UInt('hide_item_id');
92 if ($request->valid($vItemId)) {
93 $hide_item_id = $request->get('hide_item_id');
98 $vForum = new Valid_WhiteList('hide_forum', array(0, 1));
100 if ($request->valid($vForum)) {
101 $hide_forum = $request->get('hide_forum');
106 list($hide_now,$count_diff,$hide_url) = my_hide_url('forum',$group_id,$hide_item_id,$rows2,$hide_forum);
108 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="2">' : '').
109 $hide_url.'<a href="/forum/?group_id='.$group_id.'">'.
110 $glist[$j]['group_name'].'</a> ';
113 $count_new = max(0, $count_diff);
114 for ($i=0; $i<$rows2; $i++) {
116 $group_forum_id = $flist[$i]['group_forum_id'];
118 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'"><td width="99%">'.
119 ' - <a href="/forum/forum.php?forum_id='.$group_forum_id.'">'.
120 $flist[$i]['forum_name'].'</a></td>'.
121 '<td class="align-center"><a href="/forum/monitor.php?forum_id='.$group_forum_id.'&group_id='.$group_id.'&stop=1'.
122 '" onClick="return confirm(\''._("Stop monitoring this Forum?").'\')">'.
123 '<img src="'.$GLOBALS['HTML']->imgroot.'ic/trash.png" height="16" width="16" '.
124 'border="0" alt="'._("Stop monitoring").'" /></a></td></tr>';
128 $html_hdr .= '['.$rows2.($count_new ? ", <b>".sprintf(_('%s new'), $count_new)."</b>]" : ']').'</td></tr>';
129 $html_my_monitored_forums .= $html_hdr.$html;
131 $html_my_monitored_forums .= '</table>';
133 return $html_my_monitored_forums;
136 function getCategory() {
140 function getDescription() {
141 return _("List forums that you are currently monitoring, by project.<br />To cancel any of the monitored items just click on the trash icon next to the item label.");
148 function getAjaxUrl($owner_id, $owner_type) {
149 $request =& HTTPRequest::instance();
150 $ajax_url = parent::getAjaxUrl($owner_id, $owner_type);
151 if ($request->exist('hide_item_id') || $request->exist('hide_forum')) {
152 $ajax_url .= '&hide_item_id=' . $request->get('hide_item_id') . '&hide_forum=' . $request->get('hide_forum');