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
31 class Widget_MyMonitoredForums extends Widget {
32 function __construct() {
33 $this->Widget('mymonitoredforums');
37 return _("Monitored Forums");
40 function getContent() {
41 $html_my_monitored_forums = '';
42 $sql="SELECT DISTINCT groups.group_id, groups.group_name, forum_group_list.group_forum_id ".
43 "FROM groups,forum_group_list,forum_monitored_forums ".
44 "WHERE groups.group_id=forum_group_list.group_id ".
45 "AND groups.status = 'A' ".
46 "AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id ".
47 "AND forum_monitored_forums.user_id=$1 ";
48 $um = UserManager::instance();
49 $current_user = $um->getCurrentUser();
50 if ($current_user->getStatus()=='S') {
51 $projects = $current_user->getProjects();
52 $sql .= "AND groups.group_id IN (". implode(',', $projects) .") ";
54 //$sql .= "GROUP BY groups.group_id ORDER BY groups.group_id ASC LIMIT 100";
55 $sql .= "ORDER BY groups.group_id ASC LIMIT 100";
57 $result=db_query_params($sql,array(user_getid()));
59 while ($r = db_fetch_array($result)) {
60 if (forge_check_perm('project', $r['group_id'], 'read')
61 && forge_check_perm('forum', $r['group_forum_id'], 'read')) {
66 if (!$result || $rows < 1) {
67 $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>';
69 $request =& HTTPRequest::instance();
70 $html_my_monitored_forums .= '<table style="width:100%">';
71 for ($j=0; $j<$rows; $j++) {
72 $group_id = $glist[$j]['group_id'];
74 $sql2="SELECT forum_group_list.group_forum_id,forum_group_list.forum_name ".
75 "FROM groups,forum_group_list,forum_monitored_forums ".
76 "WHERE groups.group_id=forum_group_list.group_id ".
77 "AND groups.group_id=$1".
78 "AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id ".
79 "AND forum_monitored_forums.user_id=$2 LIMIT 100";
81 $result2 = db_query_params($sql2, array($group_id, user_getid()));
83 while ($r = db_fetch_array($result2)) {
84 if (forge_check_perm('forum', $r['group_forum_id'], 'read')) {
89 $rows2 = count($flist);
91 $vItemId = new Valid_UInt('hide_item_id');
93 if ($request->valid($vItemId)) {
94 $hide_item_id = $request->get('hide_item_id');
99 $vForum = new Valid_WhiteList('hide_forum', array(0, 1));
101 if ($request->valid($vForum)) {
102 $hide_forum = $request->get('hide_forum');
107 list($hide_now,$count_diff,$hide_url) = my_hide_url('forum',$group_id,$hide_item_id,$rows2,$hide_forum);
109 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="2">' : '').
110 $hide_url.'<a href="/forum/?group_id='.$group_id.'">'.
111 $glist[$j]['group_name'].'</a> ';
114 $count_new = max(0, $count_diff);
115 for ($i=0; $i<$rows2; $i++) {
117 $group_forum_id = $flist[$i]['group_forum_id'];
119 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'"><td width="99%">'.
120 ' - <a href="/forum/forum.php?forum_id='.$group_forum_id.'">'.
121 $flist[$i]['forum_name'].'</a></td>'.
122 '<td class="align-center"><a href="/forum/monitor.php?forum_id='.$group_forum_id.'&group_id='.$group_id.'&stop=1'.
123 '" onClick="return confirm(\''._("Stop monitoring this Forum?").'\')">'.
124 '<img src="'.$GLOBALS['HTML']->imgroot.'ic/trash.png" height="16" width="16" '.
125 'border="0" alt="'._("Stop monitoring").'" /></a></td></tr>';
129 $html_hdr .= '['.$rows2.($count_new ? ", <b>".sprintf(_('%s new'), $count_new)."</b>]" : ']').'</td></tr>';
130 $html_my_monitored_forums .= $html_hdr.$html;
132 $html_my_monitored_forums .= '</table>';
134 return $html_my_monitored_forums;
137 function getCategory() {
141 function getDescription() {
142 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.");
149 function getAjaxUrl($owner_id, $owner_type) {
150 $request =& HTTPRequest::instance();
151 $ajax_url = parent::getAjaxUrl($owner_id, $owner_type);
152 if ($request->exist('hide_item_id') || $request->exist('hide_forum')) {
153 $ajax_url .= '&hide_item_id=' . $request->get('hide_item_id') . '&hide_forum=' . $request->get('hide_forum');