5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2002-2004 (c) GForge Team
7 * Copyright 2005 (c) Daniel Perez
8 * Copyright 2010 (c) Franck Villaume - Capgemini
9 * Copyright (C) 2010-2012 Alain Peyrat - Alcatel-Lucent
10 * http://fusionforge.org/
12 * This file is part of FusionForge. FusionForge is free software;
13 * you can redistribute it and/or modify it under the terms of the
14 * GNU General Public License as published by the Free Software
15 * Foundation; either version 2 of the Licence, or (at your option)
18 * FusionForge is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 class ForumAdmin extends Error {
32 function __construct($group_id) {
34 $this->group_id = $group_id;
36 $this->group_id = $group_id;
37 $this->g = group_get_object($group_id);
38 $this->p =& $this->g->getPermission();
39 if (!$this->g->usesForum()) {
40 $this->setError(sprintf(_('%s does not use the Forum tool.'),
41 $this->g->getPublicName()));
48 * PrintAdminMessageOptions - prints the different administrator options for a message
50 * @param int $msg_id The Message ID
51 * @param int $group_id The Project ID
52 * @param int $thread_id The Thread ID : to return to the message if the user cancels (forumhtml only, not message.php)
53 * @param int $forum_id The Forum ID : to return to the message if the user cancels (forumhtml only, not message.php)
54 * @param int $return_to_message
55 * @return string The HTML output
58 function PrintAdminMessageOptions($msg_id,$group_id,$thread_id=0,$forum_id=0,$return_to_message=0) {
60 $return = util_make_link('/forum/admin/?movethread='.$thread_id.'&msg_id='.$msg_id.'&group_id='.$group_id.'&forum_id='.$forum_id.'&return_to_message='.$return_to_message, html_image('ic/forum_move.gif', '37', '15', array('alt' => _('Move Thread'))));
62 // Following code (if ...) is to keep old implementation but need to be cleaned
63 if ($return_to_message) {
67 $return .= util_make_link('/forum/admin/?editmsg='.$msg_id.'&group_id='.$group_id.'&thread_id='.$thread_id.'&forum_id='.$forum_id, html_image('ic/forum_edit.gif', '37', '15', array('alt' => _("Edit"))));
68 $return .= util_make_link('/forum/admin/?deletemsg='.$msg_id.'&group_id='.$group_id.'&thread_id='.$thread_id.'&forum_id='.$forum_id, html_image('ic/forum_delete.gif', '16', '18', array('alt'=>_("Delete"))));
69 // $return .= "<br />";
74 * PrintAdminOptions - prints the different administrator option for the forums (heading).
78 function PrintAdminOptions() {
79 global $group_id, $forum_id;
81 echo '<p>'.util_make_link('/forum/admin/?group_id='.$group_id.'&add_forum=1', _('Add Forum'));
82 echo ' | '.util_make_link('/forum/admin/pending.php?action=view_pending&group_id='.$group_id, _('Manage Pending Messages')).'<br /></p>';
86 * PrintAdminOptions - prints the administrator option for an individual forum, to link to the pending messages management
88 * @param int $forum_id The Forum ID.
91 function PrintAdminPendingOption($forum_id) {
92 echo '<p>'.util_make_link('/forum/admin/pending.php?action=view_pending&group_id='.$this->group_id.'&forum_id='.$forum_id, _('Manage Pending Messages')).'<br /></p>';
96 * GetPermission - Gets the permission for the user
98 * @return object The permission
100 function &GetPermission() {
105 * GetGroupObject - Gets the group object of the forum
107 * @return object The group obj
109 function &GetGroupObject() {
114 * isGroupAdmin - checks whether the authorized user is a group admin for the forums. The user must be authenticated
117 function isGroupAdmin() {
118 return forge_check_perm ('forum_admin', $this->group_id) ;
122 * Authorized - authorizes and returns true if the user is authorized for the group, or false.
124 * @param string $group_id The group id.
128 function Authorized($group_id) {
130 $this->setGroupIdError();
133 if (!session_loggedin()) {
134 $this->setPermissionDeniedError();
137 $this->group_id = $group_id;
138 $this->g = group_get_object($group_id);
139 if (!$this->g || !is_object($this->g) || $this->g->isError()) {
140 $this->setGroupIdError();
143 $this->p =& $this->g->getPermission();
144 if (!$this->p || !is_object($this->p) || $this->p->isError()) {
145 $this->setPermissionDeniedError();
152 * ExecuteAction - Executes the action passed as parameter
154 * @param string $action action to execute.
157 function ExecuteAction ($action) {
161 if ($action == "change_status") { //change a forum
162 $forum_name = getStringFromRequest('forum_name');
163 $description = getStringFromRequest('description');
164 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
165 $group_forum_id = getIntFromRequest('group_forum_id');
169 $f=new Forum($this->g,$group_forum_id);
170 if (!$f || !is_object($f)) {
171 exit_error(_('Error getting Forum'),'forums');
172 } elseif ($f->isError()) {
173 exit_error($f->getErrorMessage(),'forums');
176 session_require_perm ('forum_admin', $f->Group->getID()) ;
178 if (!$f->update($forum_name,$description,$send_all_posts_to)) {
179 exit_error($f->getErrorMessage(),'forums');
181 $feedback = _('Forum Info Updated Successfully');
185 if ($action == "add_forum") { //add forum
186 $forum_name = getStringFromRequest('forum_name');
187 $description = getStringFromRequest('description');
188 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
190 Adding forums to this group
192 if (!forge_check_perm ('forum_admin', $this->g->getID())) {
193 form_release_key(getStringFromRequest("form_key"));
194 exit_permission_denied('forums');
196 $f=new Forum($this->g);
197 if (!$f || !is_object($f)) {
198 form_release_key(getStringFromRequest("form_key"));
199 exit_error(_('Error getting Forum'),'forums');
200 } elseif ($f->isError()) {
201 form_release_key(getStringFromRequest("form_key"));
202 exit_error($f->getErrorMessage(),'forums');
204 if (!$f->create($forum_name,$description,$send_all_posts_to,1)) {
205 form_release_key(getStringFromRequest("form_key"));
206 exit_error($f->getErrorMessage(),'forums');
208 $feedback = _('Forum added successfully');
212 if ($action == "delete") { //Deleting messages or threads
213 $msg_id = getIntFromRequest('deletemsg');
214 $forum_id = getIntFromRequest('forum_id');
215 $f=new Forum($this->g,$forum_id);
216 if (!$f || !is_object($f)) {
217 exit_error(_('Error getting Forum'),'forums');
218 } elseif ($f->isError()) {
219 exit_error($f->getErrorMessage(),'forums');
222 session_require_perm ('forum_admin', $f->Group->getID()) ;
224 $fm=new ForumMessage($f,$msg_id);
225 if (!$fm || !is_object($fm)) {
226 exit_error(_('Error Getting ForumMessage'),'forums');
227 } elseif ($fm->isError()) {
228 exit_error($fm->getErrorMessage(),'forums');
230 $count=$fm->delete();
231 if (!$count || $fm->isError()) {
232 exit_error($fm->getErrorMessage(),'forums');
234 $feedback = sprintf(ngettext('%s message deleted', '%s messages deleted', $count), $count);
238 if ($action == "delete_forum") { //delete the forum
240 Deleting entire forum
242 $group_forum_id = getIntFromRequest('group_forum_id');
243 $f=new Forum($this->g,$group_forum_id);
244 if (!$f || !is_object($f)) {
245 exit_error(_('Error getting Forum'),'forums');
246 } elseif ($f->isError()) {
247 exit_error($f->getErrorMessage(),'forums');
250 session_require_perm ('forum_admin', $f->Group->getID()) ;
252 if (!$f->delete(getStringFromRequest('sure'),getStringFromRequest('really_sure'))) {
253 exit_error($f->getErrorMessage(),'forums');
255 $feedback = _('Successfully Deleted.');
259 if ($action=="view_pending") {
260 //show the pending messages, awaiting moderation
261 $group_id = $this->group_id;
262 $forum_id = getStringFromRequest("forum_id");
263 if ($this->isGroupAdmin()) {
264 $this->PrintAdminOptions();
266 $res = db_query_params ('SELECT fgl.forum_name, fgl.group_forum_id FROM forum_group_list fgl, forum_pending_messages fpm WHERE fgl.group_id=$1 AND fpm.group_forum_id = fgl.group_forum_id GROUP BY fgl.forum_name, fgl.group_forum_id',
273 $moderated_forums = array();
274 for ($i=0;$i<db_numrows($res);$i++) {
275 $aux = db_fetch_array($res);
276 $moderated_forums[$aux[1]] = $aux[0];
279 if (count($moderated_forums)==0) {
280 echo $HTML->feedback(_('No forums are moderated for this group'));
286 $keys = array_keys($moderated_forums);
287 $forum_id = $keys[0];
291 <script type="text/javascript">/* <![CDATA[ */
293 function confirmDel() {
294 var agree=confirm("' . _('Proceed? Actions are permanent!') . '");
302 <form name="pending" action="'.util_make_uri('forum/admin/pending.php').'" method="post">
303 <input type="hidden" name="action" value="update_pending" />
304 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
305 <input type="hidden" name="group_id" value="' . getIntFromRequest("group_id") . '" />
306 <input type="hidden" name="forum_id" value="' . $forum_id . '" />
310 echo html_build_select_box_from_assoc($moderated_forums,'forum_id',$forum_id);
311 echo ' <input name="Go" type="submit" value="Go" />';
314 $title[] = _('Forum Name');
315 $title[] = _('Message');
318 $res = db_query_params ('SELECT msg_id,subject,pm.group_forum_id,gl.forum_name FROM forum_pending_messages pm, forum_group_list gl WHERE pm.group_forum_id=$1 AND pm.group_forum_id=gl.group_forum_id AND gl.group_forum_id=$2',
326 //array with the supported actions
327 $options = array("1" => _("No action"),
329 "3" => _("Release"));
330 //i'll make a hidden variable, helps to determine when the user updates the info, which action corresponds to which msgID
332 for($i=0;$i<db_numrows($res);$i++) {
333 $ids .= db_result($res,$i,'msg_id') . ",";
337 echo $HTML->listTableTop($title);
338 while ($onemsg = db_fetch_array($res)) {
340 //$url = 'pendingmsgdetail.php?msg_id=' . $onemsg[msg_id];
341 //<a href=\"javascript:msgdetail('$url');\">$onemsg[subject]</a>
342 $url = "http://www.google.com";
344 <tr " . $HTML->boxGetAltRowStyle($i++). ">
345 <td>$onemsg[forum_name]</td>
346 <td><a href=\"#\" onclick=\"window.open('pendingmsgdetail.php?msg_id=$onemsg[msg_id]&forum_id=$onemsg[group_forum_id]&group_id=$group_id','PendingMessageDetail','width=800,height=600,status=no,resizable=yes');\">$onemsg[subject]</a></td>
347 <td><div class=\"align-right\">" . html_build_select_box_from_assoc($options,"doaction[]",1) . "</div></td>
351 echo $HTML->listTableBottom();
353 <input type="hidden" name="msgids" value="' . $ids . '" />
354 <p class="align-right"><input type="submit" onclick="return confirmDel();" name="update" value="' . _('Update') . '" /></p>
358 if ($action == "update_pending") {
359 $group_id = getIntFromRequest("group_id");
360 $forum_id = getIntFromRequest("forum_id");
361 $msgids = getStringFromRequest("msgids");//the message ids to update
362 $doaction = getArrayFromRequest("doaction"); //the actions for the messages
364 $msgids = explode(",",$msgids);
365 array_pop($msgids);//this last one is empty
367 /*if ($this->isGroupAdmin()) {
368 $this->PrintAdminOptions();
371 $results = array(); //messages
372 for($i=0;$i<count($msgids);$i++) {
373 switch ($doaction[$i]) {
381 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
382 array ($msgids[$i]))) {
383 $error_msg .= "DB Error: ". db_error();
387 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
388 array ($msgids[$i]))) {
389 $error_msg .= "DB Error: ". db_error();
394 $feedback .= _('Forum deleted');
399 $res1 = db_query_params ('SELECT * FROM forum_pending_messages WHERE msg_id=$1',
400 array ($msgids[$i]));
402 $error_msg .= "DB Error " . db_error() . "<br />";
405 $res2 = db_query_params ('SELECT * FROM forum_pending_attachment WHERE msg_id=$1',
406 array ($msgids[$i]));
408 $error_msg .= "DB Error " . db_error() . "<br />";
411 $f = new Forum($this->g,$forum_id);
412 if (!$f || !is_object($f)) {
413 exit_error(_('Error getting new Forum'),'forums');
414 } elseif ($f->isError()) {
415 exit_error($f->getErrorMessage(),'forums');
417 $fm = new ForumMessage($f); // pending = false
418 if (!$fm || !is_object($fm)) {
419 exit_error(_('Error getting new forum message'),'forums');
420 } elseif ($fm->isError()) {
421 exit_error(_('Error getting new forum message')._(': ').$fm->getErrorMessage(),'forums');
423 $group_forum_id = db_result($res1,0,"group_forum_id");
424 $subject = db_result($res1,0,"subject");
425 $body = db_result($res1,0,"body");
426 $post_date = db_result($res1,0,"post_date");
427 $thread_id = db_result($res1,0,"thread_id");
428 $is_followup_to = db_result($res1,0,"is_followup_to");
429 $posted_by = db_result($res1,0,"posted_by");
430 $has_followups = db_result($res1,0,"has_followups");
431 $most_recent_date = db_result($res1,0,"most_recent_date");
432 if ($fm->insertreleasedmsg($group_forum_id,$subject, $body,$post_date, $thread_id, $is_followup_to,$posted_by,$has_followups,time())) {
433 $feedback .= "($subject) " . _('Pending message released') . "<br />";
434 if (db_numrows($res2)>0) {
435 //if there's an attachment
436 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
437 $am->SetForumMsg($fm);
438 $userid = db_result($res2,0,"userid");
439 $dateline = db_result($res2,0,"dateline");
440 $filename = db_result($res2,0,"filename");
441 $filedata = db_result($res2,0,"filedata");
442 $filesize = db_result($res2,0,"filesize");
443 $visible = db_result($res2,0,"visible");
444 $msg_id = db_result($res2,0,"msg_id");
445 $filehash = db_result($res2,0,"filehash");
446 $mimetype = db_result($res2,0,"mimetype");
447 $am->AddToDBOnly($userid, $dateline, $filename, $filedata, $filesize, $visible, $filehash, $mimetype);
448 foreach ($am->Getmessages() as $item) {
449 $feedback .= "$msg_id - " . $item . "<br />";
454 if ($fm->isError()) {
455 if ( $fm->getErrorMessage() == (_('Could not Update Master Thread parent with current time')) ) {
456 //the thread which the message was replying to doesn't exist any more
457 $feedback .= "( " . $subject . " ) " . _('The thread which the message was posted to doesn\'t exist anymore, please delete the message.') . "<br />";
459 $error_msg .= "$msg_id - " . $fm->getErrorMessage() . "<br />";
465 if ( isset($am) && (is_object($am)) ) {
466 //if there was an attach, check if it was uploaded ok
467 if ((!$am->isError())) {
470 //undo the changes to the forum table
472 if (!db_query_params ('DELETE FROM forum WHERE msg_id=$1',
473 array ($fm->getID()))) {
474 $error_msg .= "DB Error ". db_error();
484 //delete the message and attach
486 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
487 array ($msgids[$i]))) {
488 $error_msg .= "DB Error: ". db_error();
492 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
493 array ($msgids[$i]))) {
494 $error_msg .= "DB Error: ". db_error();
503 html_feedback_top($feedback);
505 $this->ExecuteAction("view_pending");
512 // c-file-style: "bsd"