3 * FusionForge Monitored Forums Track Page
5 * Portions Copyright 1999-2001 (c) VA Linux Systems
6 * The rest Copyright 2002-2004 (c) GForge Team
7 * Copyright 2005 (c) - Daniel Perez
8 * Copyright 2010 (c) Franck Villaume - Capgemini
9 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
10 * Copyright 2014,2016, Franck Villaume - TrivialDev
11 * http://fusionforge.org/
13 * This file is part of FusionForge. FusionForge is free software;
14 * you can redistribute it and/or modify it under the terms of the
15 * GNU General Public License as published by the Free Software
16 * Foundation; either version 2 of the Licence, or (at your option)
19 * FusionForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 require_once '../env.inc.php';
30 require_once $gfcommon.'include/pre.php';
31 require_once $gfcommon.'forum/ForumHTML.class.php';
32 require_once $gfcommon.'forum/Forum.class.php';
33 require_once $gfcommon.'forum/ForumFactory.class.php';
34 require_once $gfcommon.'forum/ForumMessageFactory.class.php';
35 require_once $gfcommon.'forum/ForumMessage.class.php';
36 require_once $gfcommon.'include/MonitorElement.class.php';
40 session_require_login();
42 $user_id = user_getid();
43 $group_id = getIntFromRequest("group_id");
45 // If the link comes from the project, display the project header. If it comes from the user page, display the normal site header
47 forum_header(array('title'=>_('My Monitored Forums')));
49 site_user_header(array('title'=>_('My Monitored Forums')));
52 //get the user monitored forums
53 $MonitorElementObject = new MonitorElement('forum');
55 $monitoredForumsIdsArray = $MonitorElementObject->getMonitoredIdsByGroupIdByUserIdInArray($group_id, $user_id);
57 $monitoredForumsIdsArray = $MonitorElementObject->getMonitoredByUserIdInArray($user_id);
59 if (!is_array($monitoredForumsIdsArray)) {
60 echo $HTML->error_msg($MonitorElementObject->getErrorMessage());
65 if (count($monitoredForumsIdsArray) < 1) {
66 echo $HTML->information(_('You have no monitored forums'));
71 echo $HTML->listTableTop(array(_('Project'),_('Forum'), _('Threads'), _('Posts'), _('Last Post'), _('New Content?')), array(), '', '', array(), array(),
72 array(array(), array(), array('class' => 'align-center'), array('class' => 'align-center'), array('class' => 'align-center'), array('class' => 'align-center')));
74 //CHECK : if we won't ever be needing to store each forum/fmf, etc for each pass, don't use an array and use the same variable like $fmf instead of $fmf[$i], etc
75 for($i = 0; $i < sizeof($monitoredForumsIdsArray); $i++) {
76 if (forge_check_perm('forum', $monitoredForumsIdsArray[$i], 'read')) {
77 $forumObject = forum_get_object($monitoredForumsIdsArray[$i]);
78 if ($forumObject->isError()) {
79 echo $forumObject->getErrorMessage();
81 //check if the forum has new content
83 $fh = new ForumHTML($forumObject);
84 if (!$fh || !is_object($fh)) {
85 exit_error(_('Error getting new ForumHTML'), 'forums');
86 } elseif ($fh->isError()) {
87 exit_error($fh->getErrorMessage(), 'forums');
90 $fmf = new ForumMessageFactory($forumObject);
91 if (!$fmf || !is_object($fmf)) {
92 exit_error(_('Error getting new ForumMessageFactory'), 'forums');
93 } elseif ($fmf->isError()) {
94 exit_error($fmf->getErrorMessage(), 'forums');
98 $msg_arr = $fmf->nestArray($fmf->getNested());
99 $new_content = ' ';
100 //this loops through every message AND followup, in search of new messages.
101 //anything that's new ( new thread or followup) is considered to be a "new thing" and the forum
102 //is considered to have new contents
103 if (!empty($msg_arr)) {
104 foreach ($msg_arr as $forum_msg_arr) {
105 foreach ($forum_msg_arr as $forum_msg) {
106 if ($forumObject->getSavedDate() < $forum_msg->getPostDate()) {
107 //we've got ourselves a new message or followup for this forum. note that, exit the search
108 $new_content = $HTML->getNewPic('', 'new');
112 if ($new_content != ' ') {
118 $this_forum_group = $forumObject->getGroup();
119 $date = $forumObject->getMostRecentDate()? date(_('Y-m-d H:i'),$forumObject->getMostRecentDate()) : '';
121 $cells[][] = $this_forum_group->getPublicName();
122 $cells[][] = util_make_link('/forum/forum.php?forum_id='.$forumObject->getID().'&group_id='.$this_forum_group->getID(), $HTML->getForumPic().' '.$forumObject->getName());
123 $cells[] = array($forumObject->getThreadCount(), 'class' => 'align-center');
124 $cells[] = array($forumObject->getMessageCount(), 'class' => 'align-center');
125 $cells[] = array($date, 'class' => 'align-center');
126 $cells[] = array($new_content, 'class' => 'align-center');
127 echo $HTML->multiTableRow(array(), $cells);
130 // Oh ho! we found some monitored elements where user has no read access. Let's clean the situation
131 $monitorElementObject->disableMonitoringByUserId($monitoredForumsIdsArray[$i], user_getid());
135 echo $HTML->listTableBottom();