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 ForumAdmin($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 integer The Message ID
51 * @param integer The Project ID
52 * @param integer The Thread ID : to return to the message if the user cancels (forumhtml only, not message.php)
53 * @param integer The Forum ID : to return to the message if the user cancels (forumhtml only, not message.php)
54 * @return The HTML output
57 function PrintAdminMessageOptions($msg_id,$group_id,$thread_id=0,$forum_id=0,$return_to_message=0) {
59 $return = '<a href="admin/index.php?movethread=' . $thread_id . '&msg_id=' . $msg_id . '&group_id=' . $group_id . '&forum_id=' . $forum_id .
60 '&return_to_message=' . $return_to_message . '">' . html_image('ic/forum_move.gif','37','15',array('alt'=>_('Move thread'))). "</a>";
62 // Following code (if ...) is to keep old implementation but need to be cleaned
63 if ($return_to_message) {
67 $return .= ' <a href="admin/index.php?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"))) . "</a>";
68 $return .= ' <a href="admin/index.php?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"))) . "</a>";
69 // $return .= "<br />";
74 * PrintAdminOptions - prints the different administrator option for the forums (heading).
78 function PrintAdminOptions() {
79 global $group_id,$forum_id;
83 <a href="index.php?group_id='.$group_id.'&add_forum=1">'._('Add forum').'</a>';
85 | <a href="pending.php?action=view_pending&group_id=' . $group_id . '">' . _('Manage Pending Messages').'</a><br /></p>';
89 * PrintAdminOptions - prints the administrator option for an individual forum, to link to the pending messages management
91 * @param int The Forum ID.
94 function PrintAdminPendingOption($forum_id) {
97 <a href="pending.php?action=view_pending&group_id=' . $this->group_id . '&forum_id=' . $forum_id . '">' . _('Manage Pending Messages').'</a><br /></p>';
101 * GetPermission - Gets the permission for the user
103 * @return object The permission
105 function &GetPermission() {
110 * GetGroupObject - Gets the group object of the forum
112 * @return object The group obj
114 function &GetGroupObject() {
119 * isGroupAdmin - checks whether the authorized user is a group admin for the forums. The user must be authenticated
122 function isGroupAdmin() {
123 return forge_check_perm ('forum_admin', $this->group_id) ;
127 * Authorized - authorizes and returns true if the user is authorized for the group, or false.
129 * @param string The group id.
132 function Authorized($group_id) {
134 $this->setGroupIdError();
137 if (!session_loggedin()) {
138 $this->setPermissionDeniedError();
141 $this->group_id = $group_id;
142 $this->g = group_get_object($group_id);
143 if (!$this->g || !is_object($this->g) || $this->g->isError()) {
144 $this->setGroupIdError();
147 $this->p =& $this->g->getPermission();
148 if (!$this->p || !is_object($this->p) || $this->p->isError()) {
149 $this->setPermissionDeniedError();
156 * ExecuteAction - Executes the action passed as parameter
158 * @param string action to execute.
160 function ExecuteAction ($action) {
164 if ($action == "change_status") { //change a forum
165 $forum_name = getStringFromRequest('forum_name');
166 $description = getStringFromRequest('description');
167 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
168 $group_forum_id = getIntFromRequest('group_forum_id');
172 $f=new Forum($this->g,$group_forum_id);
173 if (!$f || !is_object($f)) {
174 exit_error(_('Error getting Forum'),'forums');
175 } elseif ($f->isError()) {
176 exit_error($f->getErrorMessage(),'forums');
179 session_require_perm ('forum_admin', $f->Group->getID()) ;
181 if (!$f->update($forum_name,$description,$send_all_posts_to)) {
182 $this->setError($f->getErrorMessage());
184 $feedback = _('Forum Info Updated Successfully');
188 if ($action == "add_forum") { //add forum
189 $forum_name = getStringFromRequest('forum_name');
190 $description = getStringFromRequest('description');
191 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
193 Adding forums to this group
195 if (!forge_check_perm ('forum_admin', $this->g->getID())) {
196 form_release_key(getStringFromRequest("form_key"));
197 exit_permission_denied('forums');
199 $f=new Forum($this->g);
200 if (!$f || !is_object($f)) {
201 form_release_key(getStringFromRequest("form_key"));
202 exit_error(_('Error getting Forum'),'forums');
203 } elseif ($f->isError()) {
204 form_release_key(getStringFromRequest("form_key"));
205 exit_error($f->getErrorMessage(),'forums');
207 if (!$f->create($forum_name,$description,$send_all_posts_to,1)) {
208 form_release_key(getStringFromRequest("form_key"));
209 $this->setError($f->getErrorMessage());
211 $feedback = _('Forum added successfully');
215 if ($action == "delete") { //Deleting messages or threads
216 $msg_id = getIntFromRequest('deletemsg');
217 $forum_id = getIntFromRequest('forum_id');
218 $f=new Forum($this->g,$forum_id);
219 if (!$f || !is_object($f)) {
220 exit_error(_('Error getting Forum'),'forums');
221 } elseif ($f->isError()) {
222 exit_error($f->getErrorMessage(),'forums');
225 session_require_perm ('forum_admin', $f->Group->getID()) ;
227 $fm=new ForumMessage($f,$msg_id);
228 if (!$fm || !is_object($fm)) {
229 exit_error(_('Error Getting ForumMessage'),'forums');
230 } elseif ($fm->isError()) {
231 exit_error($fm->getErrorMessage(),'forums');
233 $count=$fm->delete();
234 if (!$count || $fm->isError()) {
235 exit_error($fm->getErrorMessage(),'forums');
237 $feedback = sprintf(ngettext('%1$s message deleted', '%1$s messages deleted', $count), $count);
241 if ($action == "delete_forum") { //delete the forum
243 Deleting entire forum
245 $group_forum_id = getIntFromRequest('group_forum_id');
246 $f=new Forum($this->g,$group_forum_id);
247 if (!$f || !is_object($f)) {
248 exit_error(_('Error getting Forum'),'forums');
249 } elseif ($f->isError()) {
250 exit_error($f->getErrorMessage(),'forums');
253 session_require_perm ('forum_admin', $f->Group->getID()) ;
255 if (!$f->delete(getStringFromRequest('sure'),getStringFromRequest('really_sure'))) {
256 exit_error($f->getErrorMessage(),'forums');
258 $feedback = _('Successfully Deleted');
262 if ($action=="view_pending") {
263 //show the pending messages, awaiting moderation
264 $group_id = $this->group_id;
265 $forum_id = getStringFromRequest("forum_id");
266 if ($this->isGroupAdmin()) {
267 $this->PrintAdminOptions();
269 $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',
276 $moderated_forums = array();
277 for ($i=0;$i<db_numrows($res);$i++) {
278 $aux = db_fetch_array($res);
279 $moderated_forums[$aux[1]] = $aux[0];
282 if (count($moderated_forums)==0) {
283 echo $HTML->warning_msg(_('No forums are moderated for this group'));
284 forum_footer(array());
289 $keys = array_keys($moderated_forums);
290 $forum_id = $keys[0];
294 <script type="text/javascript">/* <![CDATA[ */
296 function confirmDel() {
297 var agree=confirm("' . _('Proceed? Actions are permanent!') . '");
305 <form name="pending" action="pending.php" method="post">
306 <input type="hidden" name="action" value="update_pending" />
307 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
308 <input type="hidden" name="group_id" value="' . getIntFromRequest("group_id") . '" />
309 <input type="hidden" name="forum_id" value="' . $forum_id . '" />
313 echo html_build_select_box_from_assoc($moderated_forums,'forum_id',$forum_id);
314 echo ' <input name="Go" type="submit" value="Go" />';
317 $title[] = _('Forum Name');
318 $title[] = _('Message');
321 $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',
329 //array with the supported actions
330 $options = array("1" => _("No action"),
332 "3" => _("Release"));
333 //i'll make a hidden variable, helps to determine when the user updates the info, which action corresponds to which msgID
335 for($i=0;$i<db_numrows($res);$i++) {
336 $ids .= db_result($res,$i,'msg_id') . ",";
340 echo $HTML->listTableTop($title);
341 while ($onemsg = db_fetch_array($res)) {
343 //$url = 'pendingmsgdetail.php?msg_id=' . $onemsg[msg_id];
344 //<a href=\"javascript:msgdetail('$url');\">$onemsg[subject]</a>
345 $url = "http://www.google.com";
347 <tr" . $HTML->boxGetAltRowStyle($i++). ">
348 <td>$onemsg[forum_name]</td>
349 <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>
350 <td><div align=\"right\">" . html_build_select_box_from_assoc($options,"doaction[]",1) . "</div></td>
354 echo $HTML->listTableBottom();
356 <input type="hidden" name="msgids" value="' . $ids . '" />
357 <p align="right"><input type="submit" onclick="return confirmDel();" name="update" value="' . _('Update') . '" /></p>
361 if ($action == "update_pending") {
362 $group_id = getIntFromRequest("group_id");
363 $forum_id = getIntFromRequest("forum_id");
364 $msgids = getStringFromRequest("msgids");//the message ids to update
365 $doaction = getArrayFromRequest("doaction"); //the actions for the messages
367 $msgids = explode(",",$msgids);
368 array_pop($msgids);//this last one is empty
370 /*if ($this->isGroupAdmin()) {
371 $this->PrintAdminOptions();
374 $results = array(); //messages
375 for($i=0;$i<count($msgids);$i++) {
376 switch ($doaction[$i]) {
384 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
385 array ($msgids[$i]))) {
386 $error_msg .= "DB Error: ". db_error();
390 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
391 array ($msgids[$i]))) {
392 $error_msg .= "DB Error: ". db_error();
397 $feedback .= _('Forum deleted');
402 $res1 = db_query_params ('SELECT * FROM forum_pending_messages WHERE msg_id=$1',
403 array ($msgids[$i]));
405 $error_msg .= "DB Error: " . db_error();
408 $res2 = db_query_params ('SELECT * FROM forum_pending_attachment WHERE msg_id=$1',
409 array ($msgids[$i]));
411 $error_msg .= "DB Error " . db_error();
414 $f = new Forum($this->g,$forum_id);
415 if (!$f || !is_object($f)) {
416 exit_error(_('Error getting new Forum'),'forums');
417 } elseif ($f->isError()) {
418 exit_error($f->getErrorMessage(),'forums');
420 $fm = new ForumMessage($f); // pending = false
421 if (!$fm || !is_object($fm)) {
422 exit_error(_('Error getting new ForumMessage'),'forums');
423 } elseif ($fm->isError()) {
424 exit_error(_('Error getting new ForumMessage: ').$fm->getErrorMessage(),'forums');
426 $group_forum_id = db_result($res1,0,"group_forum_id");
427 $subject = db_result($res1,0,"subject");
428 $body = db_result($res1,0,"body");
429 $post_date = db_result($res1,0,"post_date");
430 $thread_id = db_result($res1,0,"thread_id");
431 $is_followup_to = db_result($res1,0,"is_followup_to");
432 $posted_by = db_result($res1,0,"posted_by");
433 $has_followups = db_result($res1,0,"has_followups");
434 $most_recent_date = db_result($res1,0,"most_recent_date");
435 if ($fm->insertreleasedmsg($group_forum_id,$subject, $body,$post_date, $thread_id, $is_followup_to,$posted_by,$has_followups,time())) {
436 $feedback .= "( $subject ) " . _('Pending message released') . "<br />";
437 if (db_numrows($res2)>0) {
438 //if there's an attachment
439 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
440 $am->SetForumMsg($fm);
441 $userid = db_result($res2,0,"userid");
442 $dateline = db_result($res2,0,"dateline");
443 $filename = db_result($res2,0,"filename");
444 $filedata = db_result($res2,0,"filedata");
445 $filesize = db_result($res2,0,"filesize");
446 $visible = db_result($res2,0,"visible");
447 $msg_id = db_result($res2,0,"msg_id");
448 $filehash = db_result($res2,0,"filehash");
449 $mimetype = db_result($res2,0,"mimetype");
450 $am->AddToDBOnly($userid, $dateline, $filename, $filedata, $filesize, $visible, $filehash, $mimetype);
451 foreach ($am->Getmessages() as $item) {
452 $feedback .= "$msg_id - " . $item . "<br />";
457 if ($fm->isError()) {
458 if ( $fm->getErrorMessage() == (_('Couldn\'t Update Master Thread parent with current time')) ) {
459 //the thread which the message was replying to doesn't exist any more
460 $feedback .= "( " . $subject . " ) " . _('The thread which the message was posted to doesn\'t exist anymore, please delete the message.');
462 $error_msg .= "$msg_id - " . $fm->getErrorMessage();
468 if ( isset($am) && (is_object($am)) ) {
469 //if there was an attach, check if it was uploaded ok
470 if ((!$am->isError())) {
473 //undo the changes to the forum table
475 if (!db_query_params ('DELETE FROM forum WHERE msg_id=$1',
476 array ($fm->getID()))) {
477 $error_msg .= "DB Error ". db_error();
487 //delete the message and attach
489 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
490 array ($msgids[$i]))) {
491 $error_msg .= "DB Error: ". db_error();
495 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
496 array ($msgids[$i]))) {
497 $error_msg .= "DB Error: ". db_error();
506 html_feedback_top($feedback);
508 $this->ExecuteAction("view_pending");
515 // c-file-style: "bsd"