group_id = $group_id;
if ($group_id) {
$this->group_id = $group_id;
$this->g = group_get_object($group_id);
$this->p =& $this->g->getPermission ();
}
}
/**
* PrintAdminMessageOptions - prints the different administrator options for a message
*
* @param integer The Message ID
* @param integer The Project ID
* @param integer The Thread ID : to return to the message if the user cancels (forumhtml only, not message.php)
* @param integer The Forum ID : to return to the message if the user cancels (forumhtml only, not message.php)
* @return The HTML output
*/
function PrintAdminMessageOptions($msg_id,$group_id,$thread_id=0,$forum_id=0,$return_to_message=0) {
$return = '' . html_image('ic/forum_move.gif','37','15',array('alt'=>_('Move thread'))). "";
// Following code (if ...) is to keep old implementation but need to be cleaned
if ($return_to_message) {
$thread_id = 0;
}
$return .= ' ' . html_image('ic/forum_edit.gif','37','15',array('alt'=>_("Edit"))) . "";
$return .= ' ' . html_image('ic/forum_delete.gif','16','18',array('alt'=>_("Delete"))) . "";
// $return .= "
";
return $return;
}
/**
* PrintAdminOptions - prints the different administrator option for the forums (heading).
*
*/
function PrintAdminOptions() {
global $group_id,$forum_id;
echo '
'._('Add forum').'';
echo '
| ' . _('Manage Pending Messages').'
';
}
/**
* PrintAdminOptions - prints the administrator option for an individual forum, to link to the pending messages management
*
* @param int The Forum ID.
*/
function PrintAdminPendingOption($forum_id) {
echo '
' . _('Manage Pending Messages').'
';
}
/**
* GetPermission - Gets the permission for the user
*
* @return object The permission
*/
function &GetPermission() {
return $this->p;
}
/**
* GetGroupObject - Gets the group object of the forum
*
* @return object The group obj
*/
function &GetGroupObject() {
return $this->g;
}
/**
* isGroupAdmin - checks whether the authorized user is a group admin for the forums. The user must be authenticated
*
*/
function isGroupAdmin() {
return forge_check_perm ('forum_admin', $this->group_id) ;
}
/**
* Authorized - authorizes and returns true if the user is authorized for the group, or false.
*
* @param string The group id.
*/
function Authorized($group_id) {
if (!$group_id) {
$this->setGroupIdError();
return false;
}
if (!session_loggedin()) {
$this->setPermissionDeniedError();
return false;
}
$this->group_id = $group_id;
$this->g = group_get_object($group_id);
if (!$this->g || !is_object($this->g) || $this->g->isError()) {
$this->setGroupIdError();
return false;
}
$this->p =& $this->g->getPermission ();
if (!$this->p || !is_object($this->p) || $this->p->isError()) {
$this->setPermissionDeniedError();
return false;
}
return true;
}
/**
* ExecuteAction - Executes the action passed as parameter
*
* @param string action to execute.
*/
function ExecuteAction ($action) {
global $HTML;
$feedback='';
if ($action == "change_status") { //change a forum
$forum_name = getStringFromRequest('forum_name');
$description = getStringFromRequest('description');
$send_all_posts_to = getStringFromRequest('send_all_posts_to');
$group_forum_id = getIntFromRequest('group_forum_id');
/*
Change a forum
*/
$f=new Forum($this->g,$group_forum_id);
if (!$f || !is_object($f)) {
exit_error(_('Error getting Forum'),'forums');
} elseif ($f->isError()) {
exit_error($f->getErrorMessage(),'forums');
}
session_require_perm ('forum_admin', $f->Group->getID()) ;
if (!$f->update($forum_name,$description,0,0,$send_all_posts_to,0)) {
exit_error($f->getErrorMessage(),'forums');
} else {
$feedback = _('Forum Info Updated Successfully');
}
return $feedback;
}
if ($action == "add_forum") { //add forum
$forum_name = getStringFromRequest('forum_name');
$description = getStringFromRequest('description');
$send_all_posts_to = getStringFromRequest('send_all_posts_to');
/*
Adding forums to this group
*/
if (!forge_check_perm ('forum_admin', $this->g->getID())) {
form_release_key(getStringFromRequest("form_key"));
exit_permission_denied('forums');
}
$f=new Forum($this->g);
if (!$f || !is_object($f)) {
form_release_key(getStringFromRequest("form_key"));
exit_error(_('Error getting Forum'),'forums');
} elseif ($f->isError()) {
form_release_key(getStringFromRequest("form_key"));
exit_error($f->getErrorMessage(),'forums');
}
if (!$f->create($forum_name,$description,0,$send_all_posts_to,1,0,0)) {
form_release_key(getStringFromRequest("form_key"));
exit_error($f->getErrorMessage(),'forums');
} else {
$feedback = _('Forum added successfully');
}
return $feedback;
}
if ($action == "delete") { //Deleting messages or threads
$msg_id = getIntFromRequest('deletemsg');
$forum_id = getIntFromRequest('forum_id');
$f=new Forum($this->g,$forum_id);
if (!$f || !is_object($f)) {
exit_error(_('Error getting Forum'),'forums');
} elseif ($f->isError()) {
exit_error($f->getErrorMessage(),'forums');
}
session_require_perm ('forum_admin', $f->Group->getID()) ;
$fm=new ForumMessage($f,$msg_id);
if (!$fm || !is_object($fm)) {
exit_error(_('Error Getting ForumMessage'),'forums');
} elseif ($fm->isError()) {
exit_error($fm->getErrorMessage(),'forums');
}
$count=$fm->delete();
if (!$count || $fm->isError()) {
exit_error($fm->getErrorMessage(),'forums');
} else {
$feedback = sprintf(ngettext('%1$s message deleted', '%1$s messages deleted', $count), $count);
}
return $feedback;
}
if ($action == "delete_forum") { //delete the forum
/*
Deleting entire forum
*/
$group_forum_id = getIntFromRequest('group_forum_id');
$f=new Forum($this->g,$group_forum_id);
if (!$f || !is_object($f)) {
exit_error(_('Error getting Forum'),'forums');
} elseif ($f->isError()) {
exit_error($f->getErrorMessage(),'forums');
}
session_require_perm ('forum_admin', $f->Group->getID()) ;
if (!$f->delete(getStringFromRequest('sure'),getStringFromRequest('really_sure'))) {
exit_error($f->getErrorMessage(),'forums');
} else {
$feedback = _('Successfully Deleted');
}
return $feedback;
}
if ($action=="view_pending") {
//show the pending messages, awaiting moderation
$group_id = $this->group_id;
$forum_id = getStringFromRequest("forum_id");
if ($this->isGroupAdmin()) {
$this->PrintAdminOptions();
}
$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',
array ($group_id));
if (!$res) {
echo db_error();
return;
}
$moderated_forums = array();
for ($i=0;$iwarning_msg(_('No forums are moderated for this group'));
forum_footer(array());
exit();
}
if (!$forum_id) {
//get the first one
$keys = array_keys($moderated_forums);
$forum_id = $keys[0];
}
echo '
';
}
if ($action == "update_pending") {
$group_id = getIntFromRequest("group_id");
$forum_id = getIntFromRequest("forum_id");
$msgids = getStringFromRequest("msgids");//the message ids to update
$doaction = getArrayFromRequest("doaction"); //the actions for the messages
$msgids = explode(",",$msgids);
array_pop($msgids);//this last one is empty
/*if ($this->isGroupAdmin()) {
$this->PrintAdminOptions();
}*/
$results = array(); //messages
for($i=0;$ig,$forum_id);
if (!$f || !is_object($f)) {
exit_error(_('Error getting new Forum'),'forums');
} elseif ($f->isError()) {
exit_error($f->getErrorMessage(),'forums');
}
$fm = new ForumMessage($f); // pending = false
if (!$fm || !is_object($fm)) {
exit_error(_('Error getting new ForumMessage'),'forums');
} elseif ($fm->isError()) {
exit_error(_('Error getting new ForumMessage: ').$fm->getErrorMessage(),'forums');
}
$group_forum_id = db_result($res1,0,"group_forum_id");
$subject = db_result($res1,0,"subject");
$body = db_result($res1,0,"body");
$post_date = db_result($res1,0,"post_date");
$thread_id = db_result($res1,0,"thread_id");
$is_followup_to = db_result($res1,0,"is_followup_to");
$posted_by = db_result($res1,0,"posted_by");
$has_followups = db_result($res1,0,"has_followups");
$most_recent_date = db_result($res1,0,"most_recent_date");
if ($fm->insertreleasedmsg($group_forum_id,$subject, $body,$post_date, $thread_id, $is_followup_to,$posted_by,$has_followups,time())) {
$feedback .= "( $subject ) " . _('Pending message released') . "
";
if (db_numrows($res2)>0) {
//if there's an attachment
$am = NEW AttachManager();//object that will handle and insert the attachment into the db
$am->SetForumMsg($fm);
$userid = db_result($res2,0,"userid");
$dateline = db_result($res2,0,"dateline");
$filename = db_result($res2,0,"filename");
$filedata = db_result($res2,0,"filedata");
$filesize = db_result($res2,0,"filesize");
$visible = db_result($res2,0,"visible");
$msg_id = db_result($res2,0,"msg_id");
$filehash = db_result($res2,0,"filehash");
$mimetype = db_result($res2,0,"mimetype");
$am->AddToDBOnly($userid, $dateline, $filename, $filedata, $filesize, $visible, $filehash, $mimetype);
foreach ($am->Getmessages() as $item) {
$feedback .= "$msg_id - " . $item . "
";
}
}
$deleteok = true;
} else {
if ($fm->isError()) {
if ( $fm->getErrorMessage() == (_('Couldn\'t Update Master Thread parent with current time')) ) {
//the thread which the message was replying to doesn't exist any more
$feedback .= "( " . $subject . " ) " . _('The thread which the message was posted to doesn\'t exist anymore, please delete the message.');
} else {
$error_msg .= "$msg_id - " . $fm->getErrorMessage();
}
$deleteok = false;
}
}
if ( isset($am) && (is_object($am)) ) {
//if there was an attach, check if it was uploaded ok
if ((!$am->isError())) {
$deleteok = true;
} else {
//undo the changes to the forum table
db_begin();
if (!db_query_params ('DELETE FROM forum WHERE msg_id=$1',
array ($fm->getID()))) {
$error_msg .= "DB Error ". db_error();
db_rollback();
break;
}
db_commit();
$deleteok = false;
}
}
if ($deleteok) {
//delete the message and attach
db_begin();
if (!db_query_params ('DELETE FROM forum_pending_attachment WHERE msg_id=$1',
array ($msgids[$i]))) {
$error_msg .= "DB Error: ". db_error();
db_rollback();
break;
}
if (!db_query_params ('DELETE FROM forum_pending_messages WHERE msg_id=$1',
array ($msgids[$i]))) {
$error_msg .= "DB Error: ". db_error();
db_rollback();
break;
}
db_commit();
}
}
}
}
html_feedback_top($feedback);
$page = 0;
$this->ExecuteAction("view_pending");
}
}
}
// Local Variables:
// mode: php
// c-file-style: "bsd"
// End:
?>