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 ".
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.is_public <> 9 ".
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()));
58 $rows=db_numrows($result);
59 if (!$result || $rows < 1) {
60 $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>';
62 $request =& HTTPRequest::instance();
63 $html_my_monitored_forums .= '<table style="width:100%">';
64 for ($j=0; $j<$rows; $j++) {
65 $group_id = db_result($result, $j, 'group_id');
67 $sql2="SELECT forum_group_list.group_forum_id,forum_group_list.forum_name ".
68 "FROM groups,forum_group_list,forum_monitored_forums ".
69 "WHERE groups.group_id=forum_group_list.group_id ".
70 "AND groups.group_id=$1".
71 "AND forum_group_list.is_public <> 9 ".
72 "AND forum_group_list.group_forum_id=forum_monitored_forums.forum_id ".
73 "AND forum_monitored_forums.user_id=$2 LIMIT 100";
75 $result2 = db_query_params($sql2, array($group_id, user_getid()));
76 $rows2 = db_numrows($result2);
78 $vItemId = new Valid_UInt('hide_item_id');
80 if ($request->valid($vItemId)) {
81 $hide_item_id = $request->get('hide_item_id');
86 $vForum = new Valid_WhiteList('hide_forum', array(0, 1));
88 if ($request->valid($vForum)) {
89 $hide_forum = $request->get('hide_forum');
94 list($hide_now,$count_diff,$hide_url) = my_hide_url('forum',$group_id,$hide_item_id,$rows2,$hide_forum);
96 $html_hdr = ($j ? '<tr class="boxitem"><td colspan="2">' : '').
97 $hide_url.'<a href="/forum/?group_id='.$group_id.'">'.
98 db_result($result,$j,'group_name').'</a> ';
101 $count_new = max(0, $count_diff);
102 for ($i=0; $i<$rows2; $i++) {
104 $group_forum_id = db_result($result2, $i, 'group_forum_id');
106 <tr '. $GLOBALS['HTML']->boxGetAltRowStyle($i) .'"><td width="99%">'.
107 ' - <a href="/forum/forum.php?forum_id='.$group_forum_id.'">'.
108 db_result($result2,$i,'forum_name').'</a></td>'.
109 '<td class="align-center"><a href="/forum/monitor.php?forum_id='.$group_forum_id.'&group_id='.$group_id.'&stop=1'.
110 '" onClick="return confirm(\''._("Stop monitoring this Forum?").'\')">'.
111 '<img src="'.$GLOBALS['HTML']->imgroot.'ic/trash.png" height="16" width="16" '.
112 'border="0" alt="'._("Stop monitoring").'" /></a></td></tr>';
116 $html_hdr .= '['.$rows2.($count_new ? ", <b>".sprintf(_('%s new'), $count_new)."</b>]" : ']').'</td></tr>';
117 $html_my_monitored_forums .= $html_hdr.$html;
119 $html_my_monitored_forums .= '</table>';
121 return $html_my_monitored_forums;
124 function getCategory() {
128 function getDescription() {
129 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.");
136 function getAjaxUrl($owner_id, $owner_type) {
137 $request =& HTTPRequest::instance();
138 $ajax_url = parent::getAjaxUrl($owner_id, $owner_type);
139 if ($request->exist('hide_item_id') || $request->exist('hide_forum')) {
140 $ajax_url .= '&hide_item_id=' . $request->get('hide_item_id') . '&hide_forum=' . $request->get('hide_forum');