4 * GForge Forum Admin Class
6 * Portions Copyright 1999-2001 (c) VA Linux Systems
7 * The rest Copyright 2002-2004 (c) GForge Team
12 * This file is part of GForge.
14 * GForge is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * GForge 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
25 * along with GForge; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 by Daniel Perez - 2005
33 require_once $gfwww.'include/pre.php';
35 class ForumAdmin extends Error {
39 function ForumAdmin($gid=0) {
41 $this->group_id = $group_id;
43 $this->group_id = $group_id;
44 $this->g =& group_get_object($group_id);
45 $this->p =& $this->g->getPermission( session_get_user() );
50 * PrintAdminMessageOptions - prints the different administrator options for a message
52 * @param integer The Message ID
53 * @param integer The Group ID
54 * @param integer The Thread ID : to return to the message if the user cancels (forumhtml only, not message.php)
55 * @param integer The Forum ID : to return to the message if the user cancels (forumhtml only, not message.php)
56 * @return The HTML output
59 function PrintAdminMessageOptions($msg_id,$group_id,$thread_id=0,$forum_id=0,$return_to_message=0) {
62 $return = '<a href="admin/index.php?movethread=' . $thread_id . '&msg_id=' . $msg_id . '&group_id=' . $group_id . '&forum_id=' . $forum_id .
63 '&return_to_message=' . $return_to_message . '">' . html_image('ic/forum_move.gif','37','15',array('alt'=>_('Move thread'))). "</a>";
65 // Following code (if ...) is to keep old implementation but need to be cleaned
66 if ($return_to_message) {
70 $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>";
71 $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>";
72 // $return .= "<br />";
78 * PrintAdminOptions - prints the different administrator option for the forums (heading).
82 function PrintAdminOptions() {
83 global $group_id,$forum_id;
87 <a href="index.php?group_id='.$group_id.'&add_forum=1">'._('Add forum').'</a>';
89 | <a href="pending.php?action=view_pending&group_id=' . $group_id . '">' . _('Manage Pending Messages').'</a><br /></p>';
93 * PrintAdminOptions - prints the administrator option for an individual forum, to link to the pending messages management
95 * @param int The Forum ID.
98 function PrintAdminPendingOption($forum_id) {
101 <a href="pending.php?action=view_pending&group_id=' . $this->group_id . '&forum_id=' . $forum_id . '">' . _('Manage Pending Messages').'</a><br /></p>';
105 * GetPermission - Gets the permission for the user
107 * @return object The permission
109 function &GetPermission() {
114 * GetGroupObject - Gets the group object of the forum
116 * @return object The group obj
118 function &GetGroupObject() {
123 * isForumAdmin - checks whether the authorized user is a forum admin. The user must be authenticated
125 * @param string The forum id
127 function isForumAdmin($forum_id) {
128 $f = new Forum ($this->g,$forum_id);
129 if (!$f || !is_object($f)) {
130 exit_error('Error','Could Not Get Forum Object');
131 } elseif ($f->isError()) {
132 exit_error('Error',$f->getErrorMessage());
133 } elseif (!$f->userIsAdmin()) {
140 * isGroupAdmin - checks whether the authorized user is a group admin for the forums. The user must be authenticated
143 function isGroupAdmin() {
144 if ($this->p->isForumAdmin()) {
152 * Authorized - authorizes and returns true if the user is authorized for the group, or false.
154 * @param string The group id.
157 function Authorized($group_id) {
159 $this->setGroupIdError();
162 if (!session_loggedin()) {
163 $this->setPermissionDeniedError();
166 $this->group_id = $group_id;
167 $this->g =& group_get_object($group_id);
168 if (!$this->g || !is_object($this->g) || $this->g->isError()) {
169 $this->setGroupIdError();
172 $this->p =& $this->g->getPermission( session_get_user() );
173 if (!$this->p || !is_object($this->p) || $this->p->isError()) {
174 $this->setPermissionDeniedError();
181 * ExecuteAction - Executes the action passed as parameter
183 * @param string action to execute.
185 function ExecuteAction ($action) {
188 if ($action == "change_status") { //change a forum
189 $forum_name = getStringFromRequest('forum_name');
190 $description = getStringFromRequest('description');
191 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
192 $allow_anonymous = getIntFromRequest('allow_anonymous');
193 $is_public = getIntFromRequest('is_public');
194 $moderation_level = getIntFromRequest('moderation_level');
195 $group_forum_id = getIntFromRequest('group_forum_id');
199 $f=new Forum($this->g,$group_forum_id);
200 if (!$f || !is_object($f)) {
201 exit_error(_('Error'),_('Error getting Forum'));
202 } elseif ($f->isError()) {
203 exit_error(_('Error'),$f->getErrorMessage());
205 if (!$f->userIsAdmin()) {
206 exit_permission_denied();
208 if (!$f->update($forum_name,$description,$allow_anonymous,$is_public,$send_all_posts_to,$moderation_level)) {
209 exit_error(_('Error'),$f->getErrorMessage());
211 $feedback = _('Forum Info Updated Successfully');
215 if ($action == "add_forum") { //add forum
216 $forum_name = getStringFromRequest('forum_name');
217 $description = getStringFromRequest('description');
218 $is_public = getStringFromRequest('is_public');
219 $send_all_posts_to = getStringFromRequest('send_all_posts_to');
220 $allow_anonymous = getStringFromRequest('allow_anonymous');
221 $moderation_level = getIntFromRequest('moderation_level');
223 Adding forums to this group
225 if (!$this->p->isForumAdmin()) {
226 form_release_key(getStringFromRequest("form_key"));
227 exit_permission_denied();
229 $f=new Forum($this->g);
230 if (!$f || !is_object($f)) {
231 form_release_key(getStringFromRequest("form_key"));
232 exit_error(_('Error'),_('Error getting Forum'));
233 } elseif ($f->isError()) {
234 form_release_key(getStringFromRequest("form_key"));
235 exit_error(_('Error'),$f->getErrorMessage());
237 if (!$f->create($forum_name,$description,$is_public,$send_all_posts_to,1,$allow_anonymous,$moderation_level)) {
238 form_release_key(getStringFromRequest("form_key"));
239 exit_error(_('Error'),$f->getErrorMessage());
241 $feedback = _('Forum created successfully');
245 if ($action == "delete") { //Deleting messages or threads
246 $msg_id = getStringFromRequest('deletemsg');
247 $forum_id = getIntFromRequest('forum_id');
248 $f=new Forum($this->g,$forum_id);
249 if (!$f || !is_object($f)) {
250 exit_error(_('Error'),_('Error getting Forum'));
251 } elseif ($f->isError()) {
252 exit_error(_('Error'),$f->getErrorMessage());
254 if (!$f->userIsAdmin()) {
255 exit_permission_denied();
258 $fm=new ForumMessage($f,$msg_id);
259 if (!$fm || !is_object($fm)) {
260 exit_error(_('Error'),_('Error Getting ForumMessage'));
261 } elseif ($fm->isError()) {
262 exit_error(_('Error'),$fm->getErrorMessage());
264 $count=$fm->delete();
265 if (!$count || $fm->isError()) {
266 exit_error(_('Error'),$fm->getErrorMessage());
268 $feedback = sprintf(ngettext('%1$s message deleted', '%1$s messages deleted', $count), $count);
272 if ($action == "delete_forum") { //delete the forum
274 Deleting entire forum
276 $group_forum_id = getIntFromRequest('group_forum_id');
277 $f=new Forum($this->g,$group_forum_id);
278 if (!$f || !is_object($f)) {
279 exit_error(_('Error'),_('Error getting Forum'));
280 } elseif ($f->isError()) {
281 exit_error(_('Error'),$f->getErrorMessage());
283 if (!$f->userIsAdmin()) {
284 exit_permission_denied();
286 if (!$f->delete(getStringFromRequest('sure'),getStringFromRequest('really_sure'))) {
287 exit_error(_('Error'),$f->getErrorMessage());
289 $feedback = _('Successfully Deleted');
293 if ($action=="view_pending") {
294 //show the pending messages, awaiting moderation
295 $group_id = $this->group_id;
296 $forum_id = getStringFromRequest("forum_id");
297 if ($this->isGroupAdmin()) {
298 $this->PrintAdminOptions();
300 $res = db_query_params ('SELECT forum_name, group_forum_id FROM forum_group_list WHERE group_id=$1 and moderation_level > 0',
307 global $sys_db_row_pointer;
308 $moderated_forums = array();
309 for ($i=0;$i<db_numrows($res);$i++) {
310 $aux = db_fetch_array($res);
311 $moderated_forums[$aux[1]] = $aux[0];
314 if (count($moderated_forums)==0) {
315 echo $HTML->feedback(_('No forums are moderated for this group'));
316 forum_footer(array());
321 $keys = array_keys($moderated_forums);
322 $forum_id = $keys[0];
326 <script language="JavaScript" type="text/javascript">
328 function confirmDel() {
329 var agree=confirm("Proceed? Actions are permanent!");
337 <p><form name="pending" action="pending.php" method="post">
338 <input type="hidden" name="action" value="update_pending" />
339 <input type="hidden" name="form_key" value="' . form_generate_key() . '" />
340 <input type="hidden" name="group_id" value="' . getIntFromRequest("group_id") . '" />
341 <input type="hidden" name="forum_id" value="' . $forum_id . '" />
345 //$moderated_forums["A"] = "All Forums for this group"; // to show all
346 echo html_build_select_box_from_assoc($moderated_forums,forum_id,$forum_id);
347 echo ' <input name="Go" type="submit" value="Go"><p>';
350 $title[] = _('Forum Name');
351 $title[] = _('Message');
354 $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',
362 $options = array("1" => "No action","2" => "Delete","3" => "Release"); //array with the supported actions
363 //i'll make a hidden variable, helps to determine when the user updates the info, which action corresponds to which msgID
364 for($i=0;$i<db_numrows($res);$i++) {
365 $ids .= db_result($res,$i,'msg_id') . ",";
369 echo $HTML->listTableTop($title);
370 while ($onemsg = db_fetch_array($res)) {
372 //$url = 'pendingmsgdetail.php?msg_id=' . $onemsg[msg_id];
373 //<a href=\"javascript:msgdetail('$url');\">$onemsg[subject]</a>
374 $url = "http://www.google.com";
376 <tr" . $HTML->boxGetAltRowStyle($i++). ">
377 <td>$onemsg[forum_name]</td>
378 <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>
379 <td><div align=\"right\">" . html_build_select_box_from_assoc($options,"doaction[]",1) . "</div></td>
383 echo $HTML->listTableBottom();
386 <input type="hidden" name="msgids" value="' . $ids . '">
387 <div align="right"><input type="submit" onClick="return confirmDel();" name="update" value="' . _('Update') . '"></div>
391 if ($action == "update_pending") {
392 $group_id = getIntFromRequest("group_id");
393 $forum_id = getIntFromRequest("forum_id");
394 $msgids = getStringFromRequest("msgids");//the message ids to update
395 $doaction = getArrayFromRequest("doaction"); //the actions for the messages
397 $msgids = split(",",$msgids);
398 array_pop($msgids);//this last one is empty
400 /*if ($this->isGroupAdmin()) {
401 $this->PrintAdminOptions();
404 $results = array(); //messages
405 for($i=0;$i<count($msgids);$i++) {
406 switch ($doaction[$i]) {
414 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
415 array ($msgids[$i]))) {
416 $feedback .= "DB Error ";
417 $feedback .= db_error() . "<br />";
421 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
422 array ($msgids[$i]))) {
423 $feedback .= "DB Error ";
424 $feedback .= db_error() . "<br />";
429 $feedback .= _('Forum deleted');
434 $res1 = db_query_params ('SELECT * FROM forum_pending_messages WHERE msg_id=$1',
435 array ($msgids[$i]));
437 $feedback .= "DB Error " . db_error() . "<br />";
440 $res2 = db_query_params ('SELECT * FROM forum_pending_attachment WHERE msg_id=$1',
441 array ($msgids[$i]));
443 $feedback .= "DB Error " . db_error() . "<br />";
446 $f = new Forum($this->g,$forum_id);
447 if (!$f || !is_object($f)) {
448 exit_error(_('Error'),_('Error getting new Forum'));
449 } elseif ($f->isError()) {
450 exit_error(_('Error'),$f->getErrorMessage());
452 $fm = new ForumMessage($f); // pending = false
453 if (!$fm || !is_object($fm)) {
454 exit_error(_('Error'), "Error getting new ForumMessage");
455 } elseif ($fm->isError()) {
456 exit_error(_('Error'),"Error getting new ForumMessage: ".$fm->getErrorMessage());
458 $group_forum_id = db_result($res1,0,"group_forum_id");
459 $subject = db_result($res1,0,"subject");
460 $body = db_result($res1,0,"body");
461 $post_date = db_result($res1,0,"post_date");
462 $thread_id = db_result($res1,0,"thread_id");
463 $is_followup_to = db_result($res1,0,"is_followup_to");
464 $posted_by = db_result($res1,0,"posted_by");
465 $has_followups = db_result($res1,0,"has_followups");
466 $most_recent_date = db_result($res1,0,"most_recent_date");
467 if ($fm->insertreleasedmsg($group_forum_id,$subject, $body,$post_date, $thread_id, $is_followup_to,$posted_by,$has_followups,time())) {
468 $feedback .= "( $subject ) " . _('Pending forum released') . "<br />";
469 if (db_numrows($res2)>0) {
470 //if there's an attachment
471 $am = NEW AttachManager();//object that will handle and insert the attachment into the db
472 $am->SetForumMsg($fm);
473 $userid = db_result($res2,0,"userid");
474 $dateline = db_result($res2,0,"dateline");
475 $filename = db_result($res2,0,"filename");
476 $filedata = db_result($res2,0,"filedata");
477 $filesize = db_result($res2,0,"filesize");
478 $visible = db_result($res2,0,"visible");
479 $msg_id = db_result($res2,0,"msg_id");
480 $filehash = db_result($res2,0,"filehash");
481 $mimetype = db_result($res2,0,"mimetype");
482 $am->AddToDBOnly($userid, $dateline, $filename, $filedata, $filesize, $visible, $filehash, $mimetype);
483 foreach ($am->Getmessages() as $item) {
484 $feedback .= "$msg_id - " . $item . "<br />";
489 if ($fm->isError()) {
490 if ( $fm->getErrorMessage() == (_('Couldn\'t Update Master Thread parent with current time')) ) {
491 //the thread which the message was replying to doesn't exist any more
492 $feedback .= "( " . $subject . " ) " . _('The thread which the message was posted to doesn\'t exist anymore, please delete the message.') . "<br />";
494 $feedback .= "$msg_id - " . $fm->getErrorMessage() . "<br />";
500 if ( isset($am) && (is_object($am)) ) {
501 //if there was an attach, check if it was uploaded ok
502 if ((!$am->isError())) {
505 //undo the changes to the forum table
507 if (!db_query_params ('DELETE FROM forum WHERE msg_id=$1',
508 array ($fm->getID()))) {
509 $feedback .= "DB Error ";
510 $feedback .= db_error() . "<br />";
520 //delete the message and attach
522 if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
523 array ($msgids[$i]))) {
524 $feedback .= "DB Error ";
525 $feedback .= db_error() . "<br />";
529 if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
530 array ($msgids[$i]))) {
531 $feedback .= "DB Error ";
532 $feedback .= db_error() . "<br />";
541 html_feedback_top($feedback);
543 $this->ExecuteAction("view_pending");
551 // c-file-style: "bsd"