$post_id = Database::get()->query("INSERT INTO forum_post (topic_id, post_text, poster_id, post_time, poster_ip) VALUES (?d, ?s, ?d, ?t, ?s)", $topic_id, $message, $uid, $time, $poster_ip)->lastInsertID; Indexer::queueAsync(Indexer::REQUEST_STORE, Indexer::RESOURCE_FORUMPOST, $post_id); $forum_user_stats = Database::get()->querySingle("SELECT COUNT(*) as c FROM forum_post \n INNER JOIN forum_topic ON forum_post.topic_id = forum_topic.id\n INNER JOIN forum ON forum.id = forum_topic.forum_id\n WHERE forum_post.poster_id = ?d AND forum.course_id = ?d", $uid, $course_id); Database::get()->query("DELETE FROM forum_user_stats WHERE user_id = ?d AND course_id = ?d", $uid, $course_id); Database::get()->query("INSERT INTO forum_user_stats (user_id, num_posts, course_id) VALUES (?d,?d,?d)", $uid, $forum_user_stats->c, $course_id); Database::get()->query("UPDATE forum_topic\n SET last_post_id = ?d\n WHERE id = ?d\n AND forum_id = ?d", $post_id, $topic_id, $forum_id); Database::get()->query("UPDATE forum\n SET num_topics = num_topics+1,\n num_posts = num_posts+1,\n last_post_id = ?d\n\t\tWHERE id = ?d", $post_id, $forum_id); $topic = $topic_id; $total_forum = get_total_topics($forum_id); $total_topic = get_total_posts($topic) - 1; // subtract 1 because we want the number of replies, not the number of posts. // -------------------------------- // notify users // -------------------------------- $subject_notify = "{$logo} - {$langNewForumNotify}"; $category_id = forum_category($forum_id); $cat_name = category_name($category_id); $c = course_code_to_title($course_code); $name = uid_to_name($uid); $title = course_id_to_title($course_id); $forum_message = "-------- {$langBodyMessage} ({$langSender}: {$name})\n{$message}--------"; $plain_forum_message = q(html2text($forum_message)); $body_topic_notify = "{$langBodyForumNotify} {$langInForums} '" . q($forum_name) . "' \n {$langInCat} '" . q($cat_name) . "' {$langTo} {$langCourseS} '{$c}' <br /><br />" . q($forum_message) . "<br />\n <br />{$gunet}<br /><a href='{$urlServer}courses/{$course_code}'>{$urlServer}courses/{$course_code}</a>"; $plain_body_topic_notify = "{$langBodyForumNotify} {$langInForums} '" . q($forum_name) . "' {$langInCat} '" . q($cat_name) . "' {$langTo} {$langCourseS} '{$c}' \n\n{$plain_forum_message} \n\n{$gunet}\n<a href='{$urlServer}courses/{$course_code}'>{$urlServer}courses/{$course_code}</a>"; $linkhere = " <a href='{$urlServer}main/profile/emailunsubscribe.php?cid={$course_id}'>{$langHere}</a>."; $unsubscribe = "<br /><br />{$langNote}: " . sprintf($langLinkUnsubscribe, $title); $plain_body_topic_notify .= $unsubscribe . $linkhere; $body_topic_notify .= $unsubscribe . $linkhere; $sql = Database::get()->queryArray("SELECT DISTINCT user_id FROM forum_notify\n\t\t\tWHERE (forum_id = ?d OR cat_id = ?d)\n\t\t\tAND notify_sent = 1 AND course_id = ?d AND user_id != ?d", $forum_id, $category_id, $course_id, $uid); foreach ($sql as $r) { if (get_user_email_notification($r->user_id, $course_id)) {
function notify_users($forum_id, $forum_name, $topic_id, $subject, $message, $topic_date) { global $logo, $langNewForumNotify, $course_code, $course_code, $course_id, $langForumFrom, $uid, $langBodyForumNotify, $langInForums, $urlServer, $langdate, $langSender, $langCourse, $langCategory, $langForum, $langSubject, $langNote, $langLinkUnsubscribe, $langHere, $charset, $langMailBody; $subject_notify = "$logo - $langNewForumNotify"; $category_id = forum_category($forum_id); $cat_name = category_name($category_id); $c = course_code_to_title($course_code); $name = uid_to_name($uid); $title = course_id_to_title($course_id); $header_html_topic_notify = "<!-- Header Section --> <div id='mail-header'> <br> <div> <div id='header-title'>$langBodyForumNotify <a href='{$urlServer}courses/$course_code'>".q($title)."</a>.</div> <ul id='forum-category'> <li><span><b>$langCategory:</b></span> <span>" . q($cat_name) . "</span></li> <li><span><b>$langForum:</b></span> <span><a href='{$urlServer}modules/forum/viewforum.php?course=$course_code&forum=$forum_id'>" . q($forum_name) . "</a></span></li> <li><span><b>$langForumFrom :</b></span> <span>$name</span></li> <li><span><b>$langdate:</b></span> <span> $topic_date </span></li> </ul> </div> </div>"; $body_html_topic_notify = "<!-- Body Section --> <div id='mail-body'> <br> <div><b>$langSubject:</b> <span class='left-space'><a href='{$urlServer}modules/forum/viewforum.php?course=$course_code&forum=$forum_id&topic=$topic_id'>" . q($subject) . "</a></span></div><br> <div><b>$langMailBody:</b></div> <div id='mail-body-inner'> $message </div> </div>"; $footer_html_topic_notify = "<!-- Footer Section --> <div id='mail-footer'> <br> <div> <small>" . sprintf($langLinkUnsubscribe, q($title)) ." <a href='${urlServer}main/profile/emailunsubscribe.php?cid=$course_id'>$langHere</a></small> </div> </div>"; $html_topic_notify = $header_html_topic_notify.$body_html_topic_notify.$footer_html_topic_notify; $plain_message = html2text($message); $plain_topic_notify = "$langBodyForumNotify $langInForums\n" . "$langSender: $name\n" . "$langCourse: $title\n {$urlServer}courses/$course_code/\n" . "$langCategory: $cat_name\n" . "$langForum: $forum_name\n {$urlServer}modules/forum/viewforum.php?course=$course_code&forum=$forum_id\n" . "$langSubject: $subject\n {$urlServer}modules/forum/viewforum.php?course=$course_code&forum=$forum_id&topic=$topic_id\n" . "--------------------------------------------\n$plain_message\n" . "--------------------------------------------\n" . "$langNote: " . canonicalize_whitespace(str_replace('<br />', "\n", sprintf($langLinkUnsubscribe, q($title)))) . " $langHere:\n${urlServer}main/profile/emailunsubscribe.php?cid=$course_id\n"; $users = Database::get()->queryArray("SELECT DISTINCT user_id FROM forum_notify WHERE (forum_id = ?d OR cat_id = ?d) AND notify_sent = 1 AND course_id = ?d AND user_id != ?d", $forum_id, $category_id, $course_id, $uid); $email = array(); foreach ($users as $user) { if (get_user_email_notification($user->user_id, $course_id)) { $email[] = uid_to_email($user->user_id); } } send_mail_multipart('', '', '', $email, $subject_notify, $plain_topic_notify, $html_topic_notify, $charset); }