@ -3,7 +3,6 @@
use Chamilo\CourseBundle\Entity\CForumPost;
use Chamilo\CourseBundle\Entity\CForumPost;
use Chamilo\CourseBundle\Entity\CForumThread;
use Chamilo\CourseBundle\Entity\CForumThread;
use Chamilo\UserBundle\Entity\User;
use ChamiloSession as Session;
use ChamiloSession as Session;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\Criteria;
@ -2808,7 +2807,7 @@ function updateThread($values)
* @param int $userId Optional. The user ID
* @param int $userId Optional. The user ID
* @param int $sessionId
* @param int $sessionId
*
*
* @return int
* @return CForumThread
*
*
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University
*
*
@ -2993,12 +2992,16 @@ function store_thread(
$lastPostId = $lastPost->getIid();
$lastPostId = $lastPost->getIid();
$lastThread->setThreadLastPost($lastPostId);
$em->merge($lastThread);
$em->flush();
$logInfo = [
$logInfo = [
'tool' => TOOL_FORUM,
'tool' => TOOL_FORUM,
'tool_id' => $values['forum_id'],
'tool_id' => $values['forum_id'],
'tool_id_detail' => $lastThread->getIid(),
'tool_id_detail' => $lastThread->getIid(),
'action' => 'new-post',
'action' => 'new-post',
'action_details' => '',
'info' => $clean_post_title,
'info' => $clean_post_title,
];
];
Event::registerLog($logInfo);
Event::registerLog($logInfo);
@ -3102,7 +3105,7 @@ function store_thread(
Display::addFlash(Display::return_message($message, 'success', false));
Display::addFlash(Display::return_message($message, 'success', false));
}
}
return $lastThread->getIid() ;
return $lastThread;
}
}
/**
/**
@ -3130,14 +3133,16 @@ function show_add_post_form($current_forum, $action, $id = '', $form_values = ''
$myThread = isset($_GET['thread']) ? (int) $_GET['thread'] : '';
$myThread = isset($_GET['thread']) ? (int) $_GET['thread'] : '';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : '';
$forumId = isset($_GET['forum']) ? (int) $_GET['forum'] : '';
$my_post = isset($_GET['post']) ? (int) $_GET['post'] : '';
$my_post = isset($_GET['post']) ? (int) $_GET['post'] : '';
$giveRevision = isset($_GET['give_revision']) & & $_GET['give_revision'] == 1 ? true : false ;
$giveRevision = ( isset($_GET['give_revision']) & & $_GET['give_revision'] == 1) ;
$url = api_get_self().'?'.http_build_query([
$url = api_get_self().'?'.http_build_query(
[
'action' => $action,
'action' => $action,
'forum' => $forumId,
'forum' => $forumId,
'thread' => $myThread,
'thread' => $myThread,
'post' => $my_post,
'post' => $my_post,
]).'&'.api_get_cidreq();
]
).'&'.api_get_cidreq();
$form = new FormValidator(
$form = new FormValidator(
'thread',
'thread',
@ -3310,9 +3315,9 @@ function show_add_post_form($current_forum, $action, $id = '', $form_values = ''
// If we are quoting a message we have to retrieve the information of the post we are quoting so that
// If we are quoting a message we have to retrieve the information of the post we are quoting so that
// we can add this as default to the textarea.
// we can add this as default to the textarea.
if (($action == 'quote' || $action == 'replymessage' || $giveRevision) & & !empty($my_post)) {
// We also need to put the parent_id of the post in a hidden form when
// We also need to put the parent_id of the post in a hidden form when
if (($action == 'quote' || $action == 'replymessage' || $giveRevision) & & !empty($my_post)) {
// we are quoting or replying to a message (< > reply to a thread !!!)
$form->addHidden('post_parent_id', $my_post);
$form->addHidden('post_parent_id', $my_post);
// If we are replying or are quoting then we display a default title.
// If we are replying or are quoting then we display a default title.
@ -3374,17 +3379,32 @@ function show_add_post_form($current_forum, $action, $id = '', $form_values = ''
return false;
return false;
}
}
$postId = 0;
$threadId = 0;
switch ($action) {
switch ($action) {
case 'newthread':
case 'newthread':
$myThread = store_thread($current_forum, $values);
$myThread = store_thread($current_forum, $values);
Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $myThread);
if ($myThread) {
$threadId = $myThread->getIid();
Skill::saveSkills($form, ITEM_TYPE_FORUM_THREAD, $threadId);
$postId = $myThread->getThreadLastPost();
}
break;
break;
case 'quote':
case 'quote':
case 'replythread':
case 'replythread':
case 'replymessage':
case 'replymessage':
$postId = store_reply($current_forum, $values);
$postId = store_reply($current_forum, $values);
break;
}
if ($postId) {
if ($postId) {
$postInfo = get_post_information($postId);
if ($postInfo) {
$threadId = $postInfo['thread_id'];
}
if (isset($values['give_revision']) & & $values['give_revision'] == 1) {
if (isset($values['give_revision']) & & $values['give_revision'] == 1) {
$extraFieldValues = new ExtraFieldValue('forum_post');
$extraFieldValues = new ExtraFieldValue('forum_post');
$params = [
$params = [
@ -3399,11 +3419,11 @@ function show_add_post_form($current_forum, $action, $id = '', $form_values = ''
);
);
}
}
if (in_array($action, ['replythread', 'replymessage', 'quote'])) {
if (in_array($action, ['newthread', 'replythread', 'replymessage', 'quote'])) {
$extraFieldValues = new ExtraFieldValue('forum_post');
$extraFieldValues = new ExtraFieldValue('forum_post');
$params = [
$params = [
'item_id' => $postId,
'item_id' => $postId,
'extra_ask_for_revision' => $values['extra_ask_for_revision'],
'extra_ask_for_revision' => isset( $values['extra_ask_for_revision']) ? $values['extra_ask_for_revision'] : '' ,
];
];
$extraFieldValues->saveFieldValues(
$extraFieldValues->saveFieldValues(
$params,
$params,
@ -3413,13 +3433,11 @@ function show_add_post_form($current_forum, $action, $id = '', $form_values = ''
);
);
}
}
}
}
break;
}
$url = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'& '.http_build_query(
$url = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'& '.http_build_query(
[
[
'forum' => $forumId,
'forum' => $forumId,
'thread' => $myThrea d,
'thread' => $threadI d,
]
]
);
);
@ -4401,26 +4419,22 @@ function send_notification_mails($forumId, $thread_id, $reply_info)
$current_forum_category = null;
$current_forum_category = null;
if (isset($current_forum['forum_category'])) {
if (isset($current_forum['forum_category'])) {
$current_forum_category = get_forumcategory_information(
$current_forum_category = get_forumcategory_information($current_forum['forum_category']);
$current_forum['forum_category']
);
}
}
$send_mails = false;
if ($current_thread['visibility'] == '1' & &
if ($current_thread['visibility'] == '1' & &
$current_forum['visibility'] == '1' & &
$current_forum['visibility'] == '1' & &
($current_forum_category & & $current_forum_category['visibility'] == '1') & &
($current_forum_category & & $current_forum_category['visibility'] == '1') & &
$current_forum['approval_direct_post'] != '1'
$current_forum['approval_direct_post'] != '1'
) {
) {
$send_mails = true;
$send_mails = true;
} else {
$send_mails = false;
}
}
// The forum category, the forum, the thread and the reply are visible to the user
// The forum category, the forum, the thread and the reply are visible to the user
if ($send_mails) {
if ($send_mails & & !empty($forumId)) {
if (!empty($forumId)) {
$postId = isset($reply_info['new_post_id']) ? $reply_info['new_post_id'] : 0;
send_notifications($forumId, $thread_id);
send_notifications($forumId, $thread_id, $postId);
}
} else {
} else {
$table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
$table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
if (isset($current_forum['forum_id'])) {
if (isset($current_forum['forum_id'])) {
@ -4490,7 +4504,8 @@ function handle_mail_cue($content, $id)
$result = Database::query($sql);
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
while ($row = Database::fetch_array($result)) {
send_mail($row, get_thread_information($post_info['forum_id'], $post_info['thread_id']));
$forumInfo = get_forum_information($post_info['forum_id']);
send_mail($row, $forumInfo, get_thread_information($post_info['forum_id'], $post_info['thread_id']), $post_info);
}
}
} elseif ($content == 'thread') {
} elseif ($content == 'thread') {
// Sending the mail to all the users that wanted to be informed for replies on this thread.
// Sending the mail to all the users that wanted to be informed for replies on this thread.
@ -4507,7 +4522,8 @@ function handle_mail_cue($content, $id)
GROUP BY users.email";
GROUP BY users.email";
$result = Database::query($sql);
$result = Database::query($sql);
while ($row = Database::fetch_array($result)) {
while ($row = Database::fetch_array($result)) {
send_mail($row, get_thread_information($row['forum_id'], $id));
$forumInfo = get_forum_information($row['forum_id']);
send_mail($row, $forumInfo, get_thread_information($row['forum_id'], $id));
}
}
// Deleting the relevant entries from the mailcue.
// Deleting the relevant entries from the mailcue.
@ -4538,28 +4554,58 @@ function handle_mail_cue($content, $id)
*
*
* @param array
* @param array
* @param array
* @param array
* @param array
* @param array
*
*
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University
* @author Patrick Cool < patrick.cool @ UGent . be > , Ghent University
*
*
* @version february 2006, dokeos 1.8
* @version february 2006, dokeos 1.8
*/
*/
function send_mail($user_info = [], $thread_information = [])
function send_mail($userInfo, $forumInfo, $thread_information, $postInfo = [])
{
{
if (empty($userInfo) || empty($forumInfo) || empty($thread_information)) {
return false;
}
$_course = api_get_course_info();
$_course = api_get_course_info();
$user_id = api_get_user_id();
$user_id = api_get_user_id();
$subject = get_lang('NewForumPost').' - '.$_course['official_code'];
$thread_link = '';
if (isset($thread_information) & & is_array($thread_information)) {
if (isset($thread_information) & & is_array($thread_information)) {
$thread_link = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$thread_information['forum_id'].'&thread='.$thread_information['thread_id'];
$thread_link = api_get_path(WEB_CODE_PATH).
'forum/viewthread.php?'.api_get_cidreq().'&forum='.$thread_information['forum_id'].'&thread='.$thread_information['thread_id'];
}
$email_body = get_lang('Dear').' '.api_get_person_name($userInfo['firstname'], $userInfo['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).", < br / > \n\r";
$email_body .= get_lang('NewForumPost').': '.$forumInfo['forum_title'].' - '.$thread_information['thread_title']." < br / > \n";
$courseId = api_get_configuration_value('global_forums_course_id');
$subject = get_lang('NewForumPost').' - '.$_course['official_code'].': '.$forumInfo['forum_title'].' - '.$thread_information['thread_title']." < br / > \n";
$courseInfoTitle = get_lang('Course').': '.$_course['name'].' - ['.$_course['official_code']."] - < br / > \n";
if (!empty($courseId) & & $_course['real_id'] == $courseId) {
$subject = get_lang('NewForumPost').': '.$forumInfo['forum_title'].' - '.$thread_information['thread_title']." < br / > \n";
$courseInfoTitle = " < br / > \n";
}
}
$email_body = get_lang('Dear').' '.api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).", < br / > \n\r";
$email_body .= $courseInfoTitle;
$email_body .= get_lang('NewForumPost')."\n";
$email_body .= get_lang('Course').': '.$_course['name'].' - ['.$_course['official_code']."] - < br / > \n";
if (!empty($postInfo) & & isset($postInfo['post_text'])) {
$text = cut(strip_tags($postInfo['post_text']), 100);
if (!empty($text)) {
$email_body .= get_lang('Message').": < br / > \n ";
$email_body .= $text;
$email_body .= "< br / > < br / > \n";
}
}
$email_body .= get_lang('YouWantedToStayInformed')."< br / > \n";
$email_body .= get_lang('YouWantedToStayInformed')."< br / > \n";
if (!empty($thread_link)) {
$email_body .= get_lang('ThreadCanBeFoundHere')." : < br / > < a href = \"".$thread_link."\" > ".$thread_link."< / a > \n";
$email_body .= get_lang('ThreadCanBeFoundHere')." : < br / > < a href = \"".$thread_link."\" > ".$thread_link."< / a > \n";
}
if ($user_info['user_id'] != $user_id) {
if ($userI nfo['user_id'] != $user_id) {
MessageManager::send_message(
MessageManager::send_message(
$user_info['user_id'],
$userI nfo['user_id'],
$subject,
$subject,
$email_body,
$email_body,
[],
[],
@ -5686,19 +5732,19 @@ function get_notifications($content, $id)
*/
*/
function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
{
{
$_course = api_get_course_info();
// $_course = api_get_course_info();
$forumCourseId = api_get_configuration_value('global_forums_course_id');
/* $forumCourseId = api_get_configuration_value('global_forums_course_id');
if (!empty($forumCourseId)) {
if (!empty($forumCourseId)) {
if ($_course['real_id'] == $forumCourseId) {
if ($_course['real_id'] == $forumCourseId) {
return false;
return false;
}
}
}
}*/
$forum_id = (int) $forum_id;
$forum_id = (int) $forum_id;
// The content of the mail
// The content of the mail
$thread_link = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum_id.'&thread='.$thread_id;
// $thread_link = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum_id.'&thread='.$thread_id;
// Users who subscribed to the forum
// Users who subscribed to the forum
if ($forum_id != 0) {
if ($forum_id != 0) {
@ -5708,33 +5754,27 @@ function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
}
}
$current_thread = get_thread_information($forum_id, $thread_id);
$current_thread = get_thread_information($forum_id, $thread_id);
$current_forum = get_forum_information($current_thread['forum_id']);
// $current_forum = get_forum_information($current_thread['forum_id']);
$subject = get_lang('NewForumPost').' - '.$_course['official_code'].' - '.$current_forum['forum_title'].' - '.$current_thread['thread_title'];
// $subject = get_lang('NewForumPost').' - '.$_course['official_code'].' - '.$current_forum['forum_title'].' - '.$current_thread['thread_title'];
// User who subscribed to the thread
// User who subscribed to the thread
if ($thread_id != 0) {
if ($thread_id != 0) {
$users_to_be_notified_by_thread = get_notifications('thread', $thread_id);
$users_to_be_notified_by_thread = get_notifications('thread', $thread_id);
}
}
$postInfo = [];
if (!empty($post_id)) {
$postInfo = get_post_information($post_id);
}
// Merging the two
// Merging the two
$users_to_be_notified = array_merge($users_to_be_notified_by_forum, $users_to_be_notified_by_thread);
$users_to_be_notified = array_merge($users_to_be_notified_by_forum, $users_to_be_notified_by_thread);
$sender_id = api_get_user_id();
$forumInfo = get_forum_information($forum_id );
if (is_array($users_to_be_notified)) {
if (is_array($users_to_be_notified)) {
foreach ($users_to_be_notified as $value) {
foreach ($users_to_be_notified as $value) {
$user_info = api_get_user_info($value['user_id']);
$userInfo = api_get_user_info($value['user_id']);
$email_body = get_lang('Dear').' '.api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).", < br / > \n\r";
send_mail($userInfo, $forumInfo, $current_thread, $postInfo);
$email_body .= get_lang('NewForumPost').": ".$current_forum['forum_title'].' - '.$current_thread['thread_title']." < br / > \n";
$email_body .= get_lang('Course').': '.$_course['name'].' - ['.$_course['official_code']."] < br / > \n";
$email_body .= get_lang('YouWantedToStayInformed')."< br / > \n";
$email_body .= get_lang('ThreadCanBeFoundHere').': < br / > < a href = "'.$thread_link.'" > '.$thread_link."< / a > \n";
MessageManager::send_message_simple(
$value['user_id'],
$subject,
$email_body,
$sender_id
);
}
}
}
}
}
}
@ -6717,6 +6757,10 @@ function postNeedsRevision($postId)
*/
*/
function getAskRevisionButton($postId, $threadInfo)
function getAskRevisionButton($postId, $threadInfo)
{
{
if (api_get_configuration_value('allow_forum_post_revisions') === false) {
return '';
}
$postId = (int) $postId;
$postId = (int) $postId;
$status = 'btn-default';
$status = 'btn-default';
@ -6744,13 +6788,15 @@ function giveRevisionButton($postId, $threadInfo)
return Display::toolbarButton(
return Display::toolbarButton(
get_lang('GiveRevision'),
get_lang('GiveRevision'),
api_get_path(WEB_CODE_PATH).'forum/reply.php?'.api_get_cidreq().'& '.http_build_query([
api_get_path(WEB_CODE_PATH).'forum/reply.php?'.api_get_cidreq().'& '.http_build_query(
[
'forum' => $threadInfo['forum_id'],
'forum' => $threadInfo['forum_id'],
'thread' => $threadInfo['thread_id'],
'thread' => $threadInfo['thread_id'],
'post' => $postId = (int) $postId,
'post' => $postId = (int) $postId,
'action' => 'replymessage',
'action' => 'replymessage',
'give_revision' => 1,
'give_revision' => 1,
]),
]
),
'reply',
'reply',
'primary',
'primary',
['id' => "reply-to-post-{$postId}"]
['id' => "reply-to-post-{$postId}"]