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 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) {
33 $this->group_id = $group_id;
35 $this->group_id = $group_id;
36 $this->g = group_get_object($group_id);
37 $this->p =& $this->g->getPermission ();
42 * PrintAdminMessageOptions - prints the different administrator options for a message
44 * @param integer The Message ID
45 * @param integer The Project ID
46 * @param integer The Thread ID : to return to the message if the user cancels (forumhtml only, not message.php)
47 * @param integer The Forum ID : to return to the message if the user cancels (forumhtml only, not message.php)
48 * @return The HTML output
51 function PrintAdminMessageOptions($msg_id,$group_id,$thread_id=0,$forum_id=0,$return_to_message=0) {
53 $return = '<a href="admin/index.php?movethread=' . $thread_id . '&msg_id=' . $msg_id . '&group_id=' . $group_id . '&forum_id=' . $forum_id .
54 '&return_to_message=' . $return_to_message . '">' . html_image('ic/forum_move.gif','37','15',array('alt'=>_('Move thread'))). "</a>";
56 // Following code (if ...) is to keep old implementation but need to be cleaned
57 if ($return_to_message) {
61 $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>";
62 $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>";
63 // $return .= "<br />";
68 * PrintAdminOptions - prints the different administrator option for the forums (heading).
72 function PrintAdminOptions() {
73 global $group_id,$forum_id;
77 <a href="index.php?group_id='.$group_id.'&add_forum=1">'._('Add forum').'</a>';
79 | <a href="pending.php?action=view_pending&group_id=' . $group_id . '">' . _('Manage Pending Messages').'</a><br /></p>';
83 * PrintAdminOptions - prints the administrator option for an individual forum, to link to the pending messages management
85 * @param int The Forum ID.
88 function PrintAdminPendingOption($forum_id) {
91 <a href="pending.php?action=view_pending&group_id=' . $this->group_id . '&forum_id=' . $forum_id . '">' . _('Manage Pending Messages').'</a><br /></p>';
95 * GetPermission - Gets the permission for the user
97 * @return object The permission
99 function &GetPermission() {
104 * GetGroupObject - Gets the group object of the forum
106 * @return object The group obj
108 function &GetGroupObject() {
113 * isGroupAdmin - checks whether the authorized user is a group admin for the forums. The user must be authenticated
116 function isGroupAdmin() {
117 return forge_check_perm ('forum_admin', $this->group_id) ;
121 * Authorized - authorizes and returns true if the user is authorized for the group, or false.
123 * @param string The group id.
126 function Authorized($group_id) {
128 $this->setGroupIdError();
131 if (!session_loggedin()) {
132 $this->setPermissionDeniedError();
135 $this->group_id = $group_id;
136 $this->g = group_get_object($group_id);
137 if (!$this->g || !is_object($this->g) || $this->g->isError()) {
138 $this->setGroupIdError();
141 $this->p =& $this->g->getPermission ();
142 if (!$this->p || !is_object($this->p) || $this->p->isError()) {
143 $this->setPermissionDeniedError();
150 * ExecuteAction - Executes the action passed as parameter
152 * @param string action to execute.
154 function ExecuteAction ($action) {
158 if ($action == "change_status") { //change a forum
159 $forum_name = getStringFromRequest('forum_name');
160 $description = getStringFromRequest('description');
161 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
162 $group_forum_id = getIntFromRequest('group_forum_id');
166 $f=new Forum($this->g,$group_forum_id);
167 if (!$f || !is_object($f)) {
168 exit_error(_('Error getting Forum'),'forums');
169 } elseif ($f->isError()) {
170 exit_error($f->getErrorMessage(),'forums');
173 session_require_perm ('forum_admin', $f->Group->getID()) ;
175 if (!$f->update($forum_name,$description,0,0,$send_all_posts_to,0)) {
176 exit_error($f->getErrorMessage(),'forums');
178 $feedback = _('Forum Info Updated Successfully');
182 if ($action == "add_forum") { //add forum
183 $forum_name = getStringFromRequest('forum_name');
184 $description = getStringFromRequest('description');
185 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
187 Adding forums to this group
189 if (!forge_check_perm ('forum_admin', $this->g->getID())) {
190 form_release_key(getStringFromRequest("form_key"));
191 exit_permission_denied('forums');
193 $f=new Forum($this->g);
194 if (!$f || !is_object($f)) {
195 form_release_key(getStringFromRequest("form_key"));
196 exit_error(_('Error getting Forum'),'forums');
197 } elseif ($f->isError()) {
198 form_release_key(getStringFromRequest("form_key"));
199 exit_error($f->getErrorMessage(),'forums');
201 if (!$f->create($forum_name,$description,0,$send_all_posts_to,1,0,0)) {
202 form_release_key(getStringFromRequest("form_key"));
203 exit_error($f->getErrorMessage(),'forums');
205 $feedback = _('Forum added successfully');
209 if ($action == "delete") { //Deleting messages or threads
210 $msg_id = getIntFromRequest('deletemsg');
211 $forum_id = getIntFromRequest('forum_id');
212 $f=new Forum($this->g,$forum_id);
213 if (!$f || !is_object($f)) {
214 exit_error(_('Error getting Forum'),'forums');
215 } elseif ($f->isError()) {
216 exit_error($f->getErrorMessage(),'forums');
219 session_require_perm ('forum_admin', $f->Group->getID()) ;
221 $fm=new ForumMessage($f,$msg_id);
222 if (!$fm || !is_object($fm)) {
223 exit_error(_('Error Getting ForumMessage'),'forums');
224 } elseif ($fm->isError()) {
225 exit_error($fm->getErrorMessage(),'forums');
227 $count=$fm->delete();
228 if (!$count || $fm->isError()) {
229 exit_error($fm->getErrorMessage(),'forums');
231 $feedback = sprintf(ngettext('%1$s message deleted', '%1$s messages deleted', $count), $count);
235 if ($action == "delete_forum") { //delete the forum
237 Deleting entire forum
239 $group_forum_id = getIntFromRequest('group_forum_id');
240 $f=new Forum($this->g,$group_forum_id);
241 if (!$f || !is_object($f)) {
242 exit_error(_('Error getting Forum'),'forums');
243 } elseif ($f->isError()) {
244 exit_error($f->getErrorMessage(),'forums');
247 session_require_perm ('forum_admin', $f->Group->getID()) ;
249 if (!$f->delete(getStringFromRequest('sure'),getStringFromRequest('really_sure'))) {
250 exit_error($f->getErrorMessage(),'forums');
252 $feedback = _('Successfully Deleted');
256 if ($action=="view_pending") {
257 //show the pending messages, awaiting moderation
258 $group_id = $this->group_id;
259 $forum_id = getStringFromRequest("forum_id");
260 if ($this->isGroupAdmin()) {
261 $this->PrintAdminOptions();
263 $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',
270 $moderated_forums = array();
271 for ($i=0;$i<db_numrows($res);$i++) {
272 $aux = db_fetch_array($res);
273 $moderated_forums[$aux[1]] = $aux[0];
276 if (count($moderated_forums)==0) {
277 echo $HTML->warning_msg(_('No forums are moderated for this group'));
278 forum_footer(array());
283 $keys = array_keys($moderated_forums);
284 $forum_id = $keys[0];
288 <script language="JavaScript" type="text/javascript">/* <![CDATA[ */
290 function confirmDel() {
291 var agree=confirm("' . _('Proceed? Actions are permanent!') . '");
299 <form name="pending" action="pending.php" method="post">
300 <input type="hidden" name="action" value="update_pending" />
301 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
302 <input type="hidden" name="group_id" value="' . getIntFromRequest("group_id") . '" />
303 <input type="hidden" name="forum_id" value="' . $forum_id . '" />
307 echo html_build_select_box_from_assoc($moderated_forums,'forum_id',$forum_id);
308 echo ' <input name="Go" type="submit" value="Go" />';
311 $title[] = _('Forum Name');
312 $title[] = _('Message');
315 $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',
323 //array with the supported actions
324 $options = array("1" => _("No action"),
326 "3" => _("Release"));
327 //i'll make a hidden variable, helps to determine when the user updates the info, which action corresponds to which msgID
329 for($i=0;$i<db_numrows($res);$i++) {
330 $ids .= db_result($res,$i,'msg_id') . ",";
334 echo $HTML->listTableTop($title);
335 while ($onemsg = db_fetch_array($res)) {
337 //$url = 'pendingmsgdetail.php?msg_id=' . $onemsg[msg_id];
338 //<a href=\"javascript:msgdetail('$url');\">$onemsg[subject]</a>
339 $url = "http://www.google.com";
341 <tr" . $HTML->boxGetAltRowStyle($i++). ">
342 <td>$onemsg[forum_name]</td>
343 <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>
344 <td><div align=\"right\">" . html_build_select_box_from_assoc($options,"doaction[]",1) . "</div></td>
348 echo $HTML->listTableBottom();
350 <input type="hidden" name="msgids" value="' . $ids . '" />
351 <p align="right"><input type="submit" onclick="return confirmDel();" name="update" value="' . _('Update') . '" /></p>
355 if ($action == "update_pending") {
356 $group_id = getIntFromRequest("group_id");
357 $forum_id = getIntFromRequest("forum_id");
358 $msgids = getStringFromRequest("msgids");//the message ids to update
359 $doaction = getArrayFromRequest("doaction"); //the actions for the messages
361 $msgids = explode(",",$msgids);
362 array_pop($msgids);//this last one is empty
364 /*if ($this->isGroupAdmin()) {
365 $this->PrintAdminOptions();
368 $results = array(); //messages
369 for($i=0;$i<count($msgids);$i++) {
370 switch ($doaction[$i]) {
378 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
379 array ($msgids[$i]))) {
380 $error_msg .= "DB Error: ". db_error();
384 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
385 array ($msgids[$i]))) {
386 $error_msg .= "DB Error: ". db_error();
391 $feedback .= _('Forum deleted');
396 $res1 = db_query_params ('SELECT * FROM forum_pending_messages WHERE msg_id=$1',
397 array ($msgids[$i]));
399 $error_msg .= "DB Error: " . db_error();
402 $res2 = db_query_params ('SELECT * FROM forum_pending_attachment WHERE msg_id=$1',
403 array ($msgids[$i]));
405 $error_msg .= "DB Error " . db_error();
408 $f = new Forum($this->g,$forum_id);
409 if (!$f || !is_object($f)) {
410 exit_error(_('Error getting new Forum'),'forums');
411 } elseif ($f->isError()) {
412 exit_error($f->getErrorMessage(),'forums');
414 $fm = new ForumMessage($f); // pending = false
415 if (!$fm || !is_object($fm)) {
416 exit_error(_('Error getting new ForumMessage'),'forums');
417 } elseif ($fm->isError()) {
418 exit_error(_('Error getting new ForumMessage: ').$fm->getErrorMessage(),'forums');
420 $group_forum_id = db_result($res1,0,"group_forum_id");
421 $subject = db_result($res1,0,"subject");
422 $body = db_result($res1,0,"body");
423 $post_date = db_result($res1,0,"post_date");
424 $thread_id = db_result($res1,0,"thread_id");
425 $is_followup_to = db_result($res1,0,"is_followup_to");
426 $posted_by = db_result($res1,0,"posted_by");
427 $has_followups = db_result($res1,0,"has_followups");
428 $most_recent_date = db_result($res1,0,"most_recent_date");
429 if ($fm->insertreleasedmsg($group_forum_id,$subject, $body,$post_date, $thread_id, $is_followup_to,$posted_by,$has_followups,time())) {
430 $feedback .= "( $subject ) " . _('Pending message released') . "<br />";
431 if (db_numrows($res2)>0) {
432 //if there's an attachment
433 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
434 $am->SetForumMsg($fm);
435 $userid = db_result($res2,0,"userid");
436 $dateline = db_result($res2,0,"dateline");
437 $filename = db_result($res2,0,"filename");
438 $filedata = db_result($res2,0,"filedata");
439 $filesize = db_result($res2,0,"filesize");
440 $visible = db_result($res2,0,"visible");
441 $msg_id = db_result($res2,0,"msg_id");
442 $filehash = db_result($res2,0,"filehash");
443 $mimetype = db_result($res2,0,"mimetype");
444 $am->AddToDBOnly($userid, $dateline, $filename, $filedata, $filesize, $visible, $filehash, $mimetype);
445 foreach ($am->Getmessages() as $item) {
446 $feedback .= "$msg_id - " . $item . "<br />";
451 if ($fm->isError()) {
452 if ( $fm->getErrorMessage() == (_('Couldn\'t Update Master Thread parent with current time')) ) {
453 //the thread which the message was replying to doesn't exist any more
454 $feedback .= "( " . $subject . " ) " . _('The thread which the message was posted to doesn\'t exist anymore, please delete the message.');
456 $error_msg .= "$msg_id - " . $fm->getErrorMessage();
462 if ( isset($am) && (is_object($am)) ) {
463 //if there was an attach, check if it was uploaded ok
464 if ((!$am->isError())) {
467 //undo the changes to the forum table
469 if (!db_query_params ('DELETE FROM forum WHERE msg_id=$1',
470 array ($fm->getID()))) {
471 $error_msg .= "DB Error ". db_error();
481 //delete the message and attach
483 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
484 array ($msgids[$i]))) {
485 $error_msg .= "DB Error: ". db_error();
489 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
490 array ($msgids[$i]))) {
491 $error_msg .= "DB Error: ". db_error();
500 html_feedback_top($feedback);
502 $this->ExecuteAction("view_pending");
509 // c-file-style: "bsd"