/** * Insert data into the forum db * * @return - true or false */ function addMessage() { // // get user_id // $user_id = $this->getUserId(); if ($user_id) { // // Set up this user's session before posting // session_set_new($user_id); } //DBG( "AddMessage 1\n"); $Forum =& $this->getForum(); if (!$Forum || !is_object($Forum)) { $this->setError("Could Not Get Forum"); return false; } elseif ($Forum->isError()) { $this->setError("Forum Error: " . $Forum->getErrorMessage()); return false; } if (!$user_id && !$Forum->AllowAnonymous()) { $this->setError("Could Not Match Sender Email Address to User and Forum Does Not Allow Anonymous Posts"); return false; } //DBG( "AddMessage 2\n"); // // Create a blank forum message // $ForumMessage = new ForumMessage($Forum); if (!$ForumMessage || !is_object($Forum)) { $this->setError("Could Not Get Forum Message"); return false; } elseif ($ForumMessage->isError()) { $this->setError("ForumMessage Error: " . $ForumMessage->getErrorMessage()); return false; } //DBG( "AddMessage 3\n"); if ($this->Message != "") { if (!$ForumMessage->create($this->Subject, $this->Message, $this->ThreadId, $this->Parent)) { //DBG( "AddMessage 4.".$ForumMessage->getErrorMessage()."\n"); $this->setError("ForumMessage Create Error: " . $ForumMessage->getErrorMessage()); return false; } else { //DBG( "AddMessage 5.".$ForumMessage->getErrorMessage()."\n"); return true; } } else { return true; } }
/** * create - use this function to create a new entry in the database. * * @param string The name of the forum. * @param string The description of the forum. * @param int Pass (1) if it should be public (0) for private. * @param string The email address to send all new posts to. * @param int Pass (1) if a welcome message should be created (0) for no welcome message. * @param int Pass (1) if we should allow non-logged-in users to post (0) for mandatory login. * @param int Pass (0) if the messages that are posted in the forum should go to moderation before available. 0-> no moderation 1-> moderation for anonymous and non-project members 2-> moderation for everyone * @return boolean success. */ function create($forum_name, $description, $is_public = 1, $send_all_posts_to = '', $create_default_message = 1, $allow_anonymous = 1, $moderation_level = 0) { if (strlen($forum_name) < 3) { $this->setError(_('Forum Name Must Be At Least 3 Characters')); return false; } if (strlen($description) < 10) { $this->setError(_('Forum Description Must Be At Least 10 Characters')); return false; } if (eregi('[^_\\.0-9a-z-]', $forum_name)) { $this->setError(_('Illegal Characters in Forum Name')); return false; } if ($send_all_posts_to) { $invalid_mails = validate_emails($send_all_posts_to); if (count($invalid_mails) > 0) { $this->setInvalidEmailError(); return false; } } $project_name = $this->Group->getUnixName(); $result_list_samename = db_query('SELECT 1 FROM mail_group_list WHERE list_name = \'' . $project_name . '-' . $forum_name . '\' AND group_id=' . $this->Group->getID() . ''); if (db_numrows($result_list_samename) > 0) { $this->setError(_('Mailing List Exists with same name')); return false; } // This is a hack to allow non-site-wide-admins to post // news. The news/submit.php checks for proper permissions. // This needs to be revisited. global $sys_news_group; if ($this->Group->getID() == $sys_news_group) { // Future check will be added. } else { // Current permissions check. $perm =& $this->Group->getPermission(session_get_user()); if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) { $this->setPermissionDeniedError(); return false; } } $sql = "INSERT INTO forum_group_list (group_id,forum_name,is_public,description,send_all_posts_to,allow_anonymous,moderation_level)\n\t\t\tVALUES ('" . $this->Group->getId() . "',\n\t\t\t'" . strtolower($forum_name) . "',\n\t\t\t'{$is_public}',\n\t\t\t'" . htmlspecialchars($description) . "',\n\t\t\t'{$send_all_posts_to}',\n\t\t\t'{$allow_anonymous}','{$moderation_level}')"; db_begin(); $result = db_query($sql); if (!$result) { db_rollback(); $this->setError(_('Error Adding Forum') . db_error()); return false; } $this->group_forum_id = db_insertid($result, 'forum_group_list', 'group_forum_id'); $this->fetchData($this->group_forum_id); if ($create_default_message) { $fm = new ForumMessage($this); if (!$fm->create("Welcome to " . $forum_name, "Welcome to " . $forum_name)) { $this->setError($fm->getErrorMessage()); return false; } } db_commit(); return true; }