added pagination, edit a message who sent it, added fckeditor to message form, fixed token for message form - partial CT#190

skala
Cristian Fasanando 15 years ago
parent 30e25adca1
commit 6e2ec5494d
  1. 2
      main/inc/lib/database.lib.php
  2. 8
      main/inc/lib/group_portal_manager.lib.php
  3. 285
      main/inc/lib/message.lib.php
  4. 1
      main/install/dokeos_main.sql
  5. 2
      main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql
  6. 4
      main/messages/new_message.php
  7. 47
      main/social/groups.php
  8. 46
      main/social/message_for_group_form.inc.php

@ -68,7 +68,7 @@ define('TABLE_MAIN_USER_REL_TAG', 'user_rel_tag');
//User groups
define('TABLE_MAIN_GROUP', 'group');
define('TABLE_MAIN_GROUP', 'groups');
define('TABLE_MAIN_USER_REL_GROUP', 'group_rel_user');
define('TABLE_MAIN_GROUP_REL_TAG', 'group_rel_tag');

@ -219,6 +219,7 @@ class GroupPortalManager
$result=Database::query($sql,__FILE__,__LINE__);
$array = array();
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
if ($with_image == true) {
$picture = self::get_picture_group($row['id'], $row['picture_uri'],80);
@ -227,6 +228,7 @@ class GroupPortalManager
}
$array[$row['id']] = $row;
}
}
return $array;
}
@ -1129,7 +1131,7 @@ class GroupPortalManager
// I'm just a reader
echo get_lang('IamAReader');
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'" class="thickbox" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('message_new.png', get_lang('NewTopic')).'&nbsp;'.get_lang('NewTopic').'</a></li>';
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="thickbox" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('message_new.png', get_lang('NewTopic')).'&nbsp;'.get_lang('NewTopic').'</a></li>';
echo '<li><a href="groups.php?id='.$group_id.'">'. Display::return_icon('notebook.gif', get_lang('MessageList')).'&nbsp;'.get_lang('MessageList').'</a></li>';
echo '<li><a href="group_invitation.php?id='.$group_id.'">'. Display::return_icon('login_as.gif', get_lang('InviteFriends')).'&nbsp;'.get_lang('InviteFriends').'</a></li>';
echo '<li><a href="groups.php?id='.$group_id.'&action=leave&u='.api_get_user_id().'">'.get_lang('LeaveGroup').'</a></li>';
@ -1137,7 +1139,7 @@ class GroupPortalManager
break;
case GROUP_USER_PERMISSION_ADMIN:
echo get_lang('IamAnAdmin');
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'" class="thickbox" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('message_new.png', get_lang('NewTopic')).'&nbsp;'.get_lang('NewTopic').'</a></li>';
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="thickbox" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('message_new.png', get_lang('NewTopic')).'&nbsp;'.get_lang('NewTopic').'</a></li>';
echo '<li><a href="groups.php?id='.$group_id.'">'. Display::return_icon('notebook.gif', get_lang('MessageList')).'&nbsp;'.get_lang('MessageList').'</a></li>';
echo '<li><a href="group_edit.php?id='.$group_id.'">'. Display::return_icon('edit.gif', get_lang('EditGroup')).'&nbsp;'.get_lang('EditGroup').'</a></li>';
@ -1154,7 +1156,7 @@ class GroupPortalManager
break;
case GROUP_USER_PERMISSION_MODERATOR:
echo get_lang('IamAModerator');
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'" class="thickbox" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('message_new.png', get_lang('NewTopic')).'&nbsp;'.get_lang('NewTopic').'</a></li>';
echo '<li><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=400&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&action=add_message_group" class="thickbox" title="'.get_lang('ComposeMessage').'">'.Display::return_icon('message_new.png', get_lang('NewTopic')).'&nbsp;'.get_lang('NewTopic').'</a></li>';
echo '<li><a href="groups.php?id='.$group_id.'">'. Display::return_icon('notebook.gif', get_lang('MessageList')).'&nbsp;'.get_lang('MessageList').'</a></li>';
echo '<li><a href="group_members.php?id='.$group_id.'">'. Display::return_icon('coachs.gif', get_lang('MemberList')).'&nbsp;'.get_lang('MemberList').'</a></li>';

@ -186,7 +186,19 @@ class MessageManager
return $message_list;
}
public static function send_message ($receiver_user_id, $title, $content, $file_attachments = array(), $file_comments = '', $group_id = 0, $parent_id = 0) {
/**
* save message for social network
* @param int receiver user id
* @param string subject
* @param string content
* @param array attachment files array($_FILES) (optional)
* @param array comments about attachment files (optional)
* @param int group id (optional)
* @param int parent id (optional)
* @param int message id for updating the message (optional)
* @return bool
*/
public static function send_message ($receiver_user_id, $subject, $content, $file_attachments = array(), $file_comments = array(), $group_id = 0, $parent_id = 0, $edit_message_id = 0) {
global $charset;
$table_message = Database::get_main_table(TABLE_MESSAGE);
$group_id = intval($group_id);
@ -207,11 +219,10 @@ class MessageManager
if (!empty($receiver_user_id) || !empty($group_id)) {
// message for user friend
$title = api_convert_encoding($title,$charset);
$title = Database::escape_string($title);
$subject = api_convert_encoding($subject,$charset);
$subject = Database::escape_string($subject);
$content = api_convert_encoding($content,$charset);
$content = Database::escape_string($content);
//message in inbox
//useless query
//echo $sql = "SELECT COUNT(*) as count FROM $table_message WHERE user_sender_id = ".$user_sender_id." AND user_receiver_id='$receiver_user_id' AND title = '$title' AND content ='$content' AND group_id = '$group_id' AND parent_id = '$parent_id'";
@ -222,10 +233,16 @@ class MessageManager
//if ($row_exist['count'] == 0) {
//message in inbox for user friend
$query = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id ) ".
" VALUES ('$user_sender_id', '$receiver_user_id', '1', '".date('Y-m-d H:i:s')."','$title','$content','$group_id','$parent_id')";
if ($edit_message_id) {
$query = " UPDATE $table_message SET update_date = '".date('Y-m-d H:i:s')."', title = '$subject', content = '$content' WHERE id = '$edit_message_id' ";
$result = Database::query($query,__FILE__,__LINE__);
$inbox_last_id = $edit_message_id;
} else {
$query = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ".
" VALUES ('$user_sender_id', '$receiver_user_id', '1', '".date('Y-m-d H:i:s')."','$subject','$content','$group_id','$parent_id', '".date('Y-m-d H:i:s')."')";
$result = Database::query($query,__FILE__,__LINE__);
$inbox_last_id = Database::insert_id();
}
// save attachment file for inbox messages
if (is_array($file_attachments)) {
@ -240,8 +257,8 @@ class MessageManager
if (empty($group_id)) {
//message in outbox for user friend or group
$sql = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id ) ".
" VALUES ('$user_sender_id', '$receiver_user_id', '4', '".date('Y-m-d H:i:s')."','$title','$content', '$group_id', '$parent_id')";
$sql = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ".
" VALUES ('$user_sender_id', '$receiver_user_id', '4', '".date('Y-m-d H:i:s')."','$subject','$content', '$group_id', '$parent_id', '".date('Y-m-d H:i:s')."')";
$rs = Database::query($sql,__FILE__,__LINE__);
$outbox_last_id = Database::insert_id();
@ -341,6 +358,16 @@ class MessageManager
return false;
}
/**
* save message attachment files
* @param array $_FILES['name']
* @param string a comment about the uploaded file
* @param int message id
* @param int receiver user id (optional)
* @param int sender user id (optional)
* @param int group id (optional)
* @return void
*/
public static function save_message_attachment_file($file_attach,$file_comment,$message_id,$receiver_user_id=0,$sender_user_id=0,$group_id=0) {
$tbl_message_attach = Database::get_main_table(TABLE_MESSAGE_ATTACHMENT);
@ -389,15 +416,14 @@ class MessageManager
$sql="INSERT INTO $tbl_message_attach(filename,comment, path,message_id,size)
VALUES ( '$safe_file_name', '$safe_file_comment', '$safe_new_file_name' , '$message_id', '".$file_attach['size']."' )";
$result=Database::query($sql, __LINE__, __FILE__);
$message.=' / '.get_lang('FileUploadSucces').'<br />';
}
}
/**
* Delete message attachment file (logicaly updating the row with a suffix _DELETE_id)
* Delete message attachment files (logically updating the row with a suffix _DELETE_id)
* @param int message id
* @param int message user id (receiver user id or sender user id)
* @param int group id (optional)
* @return void
*/
public static function delete_message_attachment_file($message_id,$message_uid,$group_id=0) {
@ -430,21 +456,38 @@ class MessageManager
}
}
public static function update_message ($user_id, $id) {
if ($id != strval(intval($id)) || $user_id != strval(intval($user_id))) return false;
/**
* update messages by user id and message id
* @param int user id
* @param int message id
* @return resource
*/
public static function update_message ($user_id, $message_id) {
if ($message_id != strval(intval($message_id)) || $user_id != strval(intval($user_id))) return false;
$table_message = Database::get_main_table(TABLE_MESSAGE);
$query = "UPDATE $table_message SET msg_status = '0' WHERE msg_status<>4 AND user_receiver_id=".Database::escape_string($user_id)." AND id='".Database::escape_string($id)."'";
$query = "UPDATE $table_message SET msg_status = '0' WHERE msg_status<>4 AND user_receiver_id=".intval($user_id)." AND id='".intval($message_id)."'";
$result = Database::query($query,__FILE__,__LINE__);
}
public static function get_message_by_user ($user_id,$id) {
if ($id != strval(intval($id)) || $user_id != strval(intval($user_id))) return false;
/**
* get messages by user id and message id
* @param int user id
* @param int message id
* @return array
*/
public static function get_message_by_user ($user_id,$message_id) {
if ($message_id != strval(intval($message_id)) || $user_id != strval(intval($user_id))) return false;
$table_message = Database::get_main_table(TABLE_MESSAGE);
$query = "SELECT * FROM $table_message WHERE user_receiver_id=".Database::escape_string($user_id)." AND id='".Database::escape_string($id)."'";
$query = "SELECT * FROM $table_message WHERE user_receiver_id=".intval($user_id)." AND id='".intval($message_id)."'";
$result = Database::query($query,__FILE__,__LINE__);
return $row = Database::fetch_array($result);
}
/**
* get messages by group id
* @param int group id
* @return array
*/
public static function get_messages_by_group($group_id) {
if ($group_id != strval(intval($group_id))) return false;
$table_message = Database::get_main_table(TABLE_MESSAGE);
@ -461,6 +504,43 @@ class MessageManager
return $data;
}
/**
* get messages by parent id optionally with limit
* @param int parent id
* @param int group id (optional)
* @param int offset (optional)
* @param int limit (optional)
* @return array
*/
public static function get_messages_by_parent($parent_id,$group_id = '',$offset = 0,$limit = 0) {
if ($parent_id != strval(intval($parent_id))) return false;
$table_message = Database::get_main_table(TABLE_MESSAGE);
$current_uid = api_get_user_id();
$parent_id = intval($parent_id);
$condition_group_id = "";
if ($group_id !== '') {
$group_id = intval($group_id);
$condition_group_id = " AND group_id = '$group_id' ";
}
$condition_limit = "";
if ($offset && $limit) {
$offset = ($offset - 1) * $limit;
$condition_limit = " LIMIT $offset,$limit ";
}
$query = "SELECT * FROM $table_message WHERE parent_id='$parent_id' AND msg_status <> 4 $condition_group_id ORDER BY send_date DESC $condition_limit ";
$rs = Database::query($query,__FILE__,__LINE__);
$data = array();
if (Database::num_rows($rs) > 0) {
while ($row = Database::fetch_array($rs)) {
$data[$row['id']] = $row;
}
}
return $data;
}
/**
* Gets information about if exist messages
* @author Isaac FLores Paz <isaac.flores@dokeos.com>
@ -756,54 +836,157 @@ class MessageManager
$rows = self::get_messages_by_group($group_id);
$rows = self::calculate_children($rows);
$group_info = GroupPortalManager::get_group_data($group_id);
$current_user_id = api_get_user_id();
$count=0;
$html = '';
if (is_array($rows) && count($rows)> 0) {
foreach ($rows as $message) {
$indent = $message['indent_cnt']*'20';
$user_sender_info = UserManager::get_user_info_by_id($message['user_sender_id']);
if (!empty($message['parent_id'])) {
$message_parent_info = self::get_message_by_id($message['parent_id']);
$user_parent_info = UserManager::get_user_info_by_id($message_parent_info['user_sender_id']);
$name_user_parent = api_get_person_name($user_parent_info['firstname'], $user_parent_info['lastname']);
$message_item = 'message-item';
$message_title_item = 'message-group-title';
// prepare array for topics with its items
$topics = array();
$x = 0;
foreach ($rows as $index=>$value) {
if (empty($value['parent_id'])) {
$x = $index;
$topics[$x] = $value;
} else {
$message_item = 'message-topic';
$message_title_item = 'message-group-title-topic';
$topics[$x]['items'][] = $value;
}
}
uasort($topics,array('MessageManager','order_desc_date'));
// get file attachments by message id
$files_attachments = self::get_links_message_attachment_files($message['id']);
$name = api_get_person_name($user_sender_info['firstname'], $user_sender_info['lastname']);
$html.= '<div class="'.$message_item.'" id="message-item-'.$count.'" style="margin-left: '.$indent.'px;">';
// pager
$page = isset($_GET['page_nr'])?intval($_GET['page_nr']):1;
$total_topics = count($topics);
$topics_per_page = 5;
$pager = self::get_pager_for_message_group($group_id,$page,$total_topics,$topics_per_page);
$html .= ' <div class="pager">
<table width="100%">
<tr><td style="width:25%">&nbsp;</td><td style="text-align:center">'.$pager['details'].'</td><td style="text-align:right;width:25%">'.$pager['links'].'</td></tr></table></div>';
//if (!isset($message['children'])) {
//only for admins
//$html.= '<div id="message-reply-link"><a href="'.api_get_path(WEB_CODE_PATH).'social/groups.php?action=delete_message&group_id='.$group_id.'&message_id='.$message['id'].'">'.Display :: return_icon('delete.gif', get_lang('Delete')).'&nbsp;'.get_lang('Delete').'</a></div>';
$html.= '<div id="message-reply-link"><a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=390&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&message_id='.$message['id'].'" class="thickbox" title="'.get_lang('Reply').'">'.Display :: return_icon('forumthread_new.gif', get_lang('Reply')).'&nbsp;'.get_lang('Reply').'</a></div>';
// topics and items
$parents = array_keys(self::get_messages_by_parent(0,$group_id,$page,$topics_per_page));
$html .= '<div id="accordion">';
foreach ($topics as $index => $topic) {
//echo '<a href="/main/messages/new_message.php?group_id='.$group_id.'&message_id='.$message['id'].'">'.Display::return_icon('forumthread_new.gif',api_xml_http_response_encode(get_lang('Reply'))).'&nbsp;'.api_xml_http_response_encode(get_lang('Reply')).'</a>';
//}
if (!in_array($index,$parents)) continue;
$html.= '<div class="'.$message_title_item.'">'.$message['title'].'&nbsp;</div>';
// topics
$indent = 0;
$user_sender_info = UserManager::get_user_info_by_id($topic['user_sender_id']);
$files_attachments = self::get_links_message_attachment_files($topic['id']);
$name = api_get_person_name($user_sender_info['firstname'], $user_sender_info['lastname']);
$html .= '<div class="message-topic" >';
$html .= '<a href="#" class="head" id="head_'.$topic['id'].'">
'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align: middle')).'
<span class="message-group-title-topic">'.$topic['title'].'</span>
<span class="message-group-date">('.get_lang('PostIn').' '.date_to_str_ago($topic['send_date']).($topic['send_date']!=$topic['update_date']?' - '.get_lang('UpdatedIn').' '.date_to_str_ago($topic['send_date']):'').')</span>
</a>';
$html .= '<div>';
$html.= '<div style="margin-left: '.$indent.'px;margin-bottom:10px">';
$html.= '<div id="message-reply-link" style="margin-right:10px">
<a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=390&width=610&&user_friend='.$current_user_id.'&group_id='.$group_id.'&message_id='.$topic['id'].'&action=reply_message_group" class="thickbox" title="'.get_lang('Reply').'">'.Display :: return_icon('forumthread_new.gif', get_lang('Reply')).'</a>';
$html.= '<div class="message-group-author">'.get_lang('From').'&nbsp;<a href="'.api_get_path(WEB_PATH).'main/social/profile.php?u='.$message['user_sender_id'].'">'.$name.'&nbsp;</a></div>';
$html.= '<div class="message-group-content">'.$message['content'].'</div>';
$html.= '<div class="message-group-date">'.get_lang('PostIn').' '.date_to_str_ago($message['send_date']).'</div>';
if ($topic['user_sender_id'] == $current_user_id) {
$html.= '&nbsp;&nbsp;<a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=390&width=610&&user_friend='.$current_user_id.'&group_id='.$group_id.'&message_id='.$topic['id'].'&action=edit_message_group" class="thickbox" title="'.get_lang('Edit').'">'.Display :: return_icon('edit.gif', get_lang('Edit')).'</a>';
}
$html.= '</div>';
//$html.= '<div class="message-group-title-topic">'.$topic['title'].'&nbsp;</div>';
$html.= '<div class="message-group-author">'.get_lang('From').'&nbsp;<a href="'.api_get_path(WEB_PATH).'main/social/profile.php?u='.$topic['user_sender_id'].'">'.$name.'&nbsp;</a></div>';
$html.= '<div class="message-group-content">'.$topic['content'].'</div>';
//$html.= '<div class="message-group-date">'.get_lang('PostIn').' '.date_to_str_ago($topic['send_date']).'</div>';
$html.= '<div class="message-attach">'.(!empty($files_attachments)?implode('&nbsp;|&nbsp;',$files_attachments):'').'</div>';
$html.= '</div>';
$count++;
// items
if (is_array($topic['items'])) {
foreach ($topic['items'] as $item) {
$indent = $item['indent_cnt']*'15';
$user_sender_info = UserManager::get_user_info_by_id($item['user_sender_id']);
$files_attachments = self::get_links_message_attachment_files($item['id']);
$name = api_get_person_name($user_sender_info['firstname'], $user_sender_info['lastname']);
$html.= '<div class="message-item" style="margin-left: '.$indent.'px;">';
$html.= '<div id="message-reply-link">
<a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=390&width=610&&user_friend='.api_get_user_id().'&group_id='.$group_id.'&message_id='.$item['id'].'&action=reply_message_group" class="thickbox" title="'.get_lang('Reply').'">'.Display :: return_icon('forumthread_new.gif', get_lang('Reply')).'</a>';
if ($item['user_sender_id'] == $current_user_id) {
$html.= '&nbsp;&nbsp;<a href="'.api_get_path(WEB_CODE_PATH).'social/message_for_group_form.inc.php?view_panel=1&height=390&width=610&&user_friend='.$current_user_id.'&group_id='.$group_id.'&message_id='.$item['id'].'&action=edit_message_group" class="thickbox" title="'.get_lang('Edit').'">'.Display :: return_icon('edit.gif', get_lang('Edit')).'</a>';
}
$html.= '</div>';
$html.= '<div class="message-group-title">'.$item['title'].'&nbsp;</div>';
$html.= '<div class="message-group-author">'.get_lang('From').'&nbsp;<a href="'.api_get_path(WEB_PATH).'main/social/profile.php?u='.$item['user_sender_id'].'">'.$name.'&nbsp;</a></div>';
$html.= '<div class="message-group-content">'.$item['content'].'</div>';
$html.= '<div class="message-group-date">'.get_lang('PostIn').' '.date_to_str_ago($item['send_date']).($item['send_date']!=$item['update_date']?' - '.get_lang('UpdatedIn').' '.date_to_str_ago($item['send_date']):'').'</div>';
$html.= '<div class="message-attach">'.(!empty($files_attachments)?implode('&nbsp;|&nbsp;',$files_attachments):'').'</div>';
$html.= '</div>';
}
}
$html .= '</div>';
$html .= '</div>';
}
$html .= '</div>';
// pager
$html .= ' <div class="pager">
<table width="100%">
<tr><td style="width:25%">&nbsp;</td><td>&nbsp;</td><td style="text-align:right;width:25%">'.$pager['links'].'</td></tr></table></div>';
}
return $html;
}
/**
* Get pager for messages of group
* @param int group id
* @param int current page
* @param int total rows
* @param int rows per page
* @return array pager with details and links
*/
public static function get_pager_for_message_group($group_id,$page,$num_rows,$rows_per_page) {
$link = '';
$details = '';
$pager = array();
$group_id = intval($group_id);
$page = intval($page);
$num_rows = intval($num_rows);
$first_page = 1;
$last_page = ceil($num_rows/$rows_per_page);
// get details
if ($page == $first_page) {
$details = $page.' - '.($page*$rows_per_page).' / '.$num_rows;
} else if ($page > $first_page && $page < $last_page) {
$details = ((($page-1)*$rows_per_page)+1).' - '.($page*$rows_per_page).' / '.$num_rows;
} else {
$details = ((($page-1)*$rows_per_page)+1).' - '.($num_rows).' / '.$num_rows;
}
$pager['details'] = $details;
// get links for pager
$href = api_get_path(WEB_CODE_PATH).'social/groups.php?id='.$group_id;
if ($page > 1) {
$link .= '<a title="'.get_lang('FirstPage').'" href="'.$href.'&page_nr='.$first_page.'">';
$link .= Display::return_icon('first.png',get_lang('FirstPage'),array('style'=>'vertical-align: middle'));
$link .= '</a>';
$link .= '<a title="'.get_lang('PreviousPage').'" href="'.$href.'&page_nr='.($page-1).'">';
$link .= Display::return_icon('prev.png',get_lang('PreviousPage'),array('style'=>'vertical-align: middle'));
$link .= '</a>';
}
$link .= $page.'/'.$last_page;
if ($page < $last_page) {
$link .= '<a title="'.get_lang('NextPage').'" href="'.$href.'&page_nr='.($page+1).'">';
$link .= Display::return_icon('next.png',get_lang('NextPage'),array('style'=>'vertical-align: middle'));
$link .= '</a>';
$link .= '<a title="'.get_lang('LastPage').'" href="'.$href.'&page_nr='.$last_page.'">';
$link .= Display::return_icon('last.png',get_lang('PreviousPage'),array('style'=>'vertical-align: middle'));
$link .= '</a>';
}
$pager['links'] = $link;
return $pager;
}
/**
* Add children to messages by id is used for nested view messages
* @param array rows of messages
@ -843,6 +1026,16 @@ class MessageManager
}
}
/**
* Sort date by desc from a multi-dimensional array
* @param array1 first array to compare
* @param array2 second array to compare
* @return bool
*/
public function order_desc_date($array1,$array2) {
return strcmp($array2['send_date'],$array1['send_date']);
}
/**
* Get array of links (download) for message attachment files
* @param int message id

@ -2196,6 +2196,7 @@ CREATE TABLE message(
content text not null,
group_id int unsigned not null default 0,
parent_id int unsigned not null default 0,
update_date datetime not null default '0000-00-00 00:00:00',
PRIMARY KEY(id)
);
ALTER TABLE message ADD INDEX idx_message_user_sender(user_sender_id);

@ -86,6 +86,8 @@ INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_send
INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('message_max_upload_filesize', NULL, 'textfield', 'Tools', '20971520', 'MessageMaxUploadFilesizeTitle','MessageMaxUploadFilesizeComment',NULL,NULL, 0);
ALTER TABLE message ADD COLUMN update_date DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00';
-- xxSTATSxx
ALTER TABLE track_e_exercices ADD COLUMN expired_time_control datetime NOT NULL DEFAULT '0000-00-00 00:00:00';
ALTER TABLE track_e_online ADD INDEX (course);

@ -188,8 +188,8 @@ function manage_form ($default, $select_from_user_list = null) {
}
$form->add_textfield('title', get_lang('Title'),true ,array('size' => 77));
//$form->add_html_editor('content', '', false, false, array('ToolbarSet' => 'Messages', 'Width' => '95%', 'Height' => '250'));
$form->addElement('textarea','content', get_lang('Message'), array('cols' => 75,'rows'=>8));
$form->add_html_editor('content', get_lang('Message'), false, false, array('ToolbarSet' => 'Messages', 'Width' => '95%', 'Height' => '250'));
//$form->addElement('textarea','content', get_lang('Message'), array('cols' => 75,'rows'=>8));
if (isset($_GET['re_id'])) {
$form->addElement('hidden','re_id',Security::remove_XSS($_GET['re_id']));

@ -60,32 +60,61 @@ function add_image_form() {
}
}
jQuery(document).ready(function() {
$(".head").click(function() {
$(this).next().slideToggle("slow");
image_clicked = $("#" + this.id + " img").attr("src");
image_clicked_info = image_clicked.split("/");
image_real_clicked = image_clicked_info[image_clicked_info.length-1];
image_path = image_clicked.split("img");
current_path = image_path[0]+"img/";
if (image_real_clicked == "div_show.gif") {
current_path = current_path+"div_hide.gif";
$("#" + this.id + " img").attr("src", current_path);
} else {
current_path = current_path+"div_show.gif";
$("#" + this.id + " img").attr("src", current_path)
}
return false;
}).next().hide();
});
</script>';
$interbreadcrumb[]= array ('url' =>'profile.php','name' => get_lang('Social'));
$interbreadcrumb[]= array ('url' =>'#','name' => get_lang('Groups'));
Display :: display_header($tool_name, 'Groups');
echo '<div class="actions-title">';
echo get_lang('Groups');
echo '</div>';
// save message group
if (isset($_POST['token']) && $_POST['token'] == $_SESSION['sec_token']) {
if (isset($_POST['action']) && $_POST['action']=='send_message_group') {
if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
if (isset($_POST['action'])) {
$title = $_POST['title'];
$content = $_POST['content'];
$group_id = $_POST['group_id'];
$parent_id = $_POST['parent_id'];
$group_id = intval($_POST['group_id']);
$parent_id = intval($_POST['parent_id']);
if ($_POST['action'] == 'edit_message_group') {
$edit_message_id = intval($_POST['message_id']);
$res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, $edit_message_id);
} else {
$res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id);
}
if (is_string($res)) {
Display::display_error_message($res);
}
Security::clear_token();
}
} else {
$tok = Security::get_token();
}
// getting group information
@ -94,7 +123,7 @@ $group_id = intval($_GET['id']);
echo '<div id="social_wrapper">';
//this include the social menu div
SocialManager::show_social_menu(array('messages'));
//SocialManager::show_social_menu(array('messages'));
echo '<div id="social_main">';
@ -134,7 +163,7 @@ if ($group_id != 0 ) {
//---
//-- Show message groups
echo '<div id="layout_right" style="margin-left: 282px;">';
echo '<div id="layout_right" style="margin-left: 290px;">';
echo '<div class="messages">';
if (GroupPortalManager::is_group_member($group_id)) {
$content = MessageManager::display_messages_for_group($group_id);

@ -7,6 +7,9 @@ require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'message.lib.php';
require_once api_get_path(LIBRARY_PATH).'social.lib.php';
require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
require_once api_get_path(LIBRARY_PATH).'fckeditor/fckeditor.php';
$tok = Security::get_token();
if (api_is_anonymous()) {
api_not_allowed();
@ -29,24 +32,35 @@ if ( isset($_REQUEST['user_friend']) ) {
$group_id = intval($_GET['group_id']);
$message_id = intval($_GET['message_id']);
$actions = array('add_message_group','edit_message_group','reply_message_group');
$allowed_action = (isset($_GET['action']) && in_array($_GET['action'],$actions))?Security::remove_XSS($_GET['action']):'';
$to_group = '';
$title_group = '';
if (!empty($group_id)) {
$subject = '';
$message = '';
if (!empty($group_id) && $allowed_action) {
$group_info = GroupPortalManager::get_group_data($group_id);
$to_group = $group_info['name'];
if (!empty($message_id)) {
$message_info = MessageManager::get_message_by_id($message_id);
$title_group = get_lang('Re:').api_xml_http_response_encode($message_info['title']);
if ($allowed_action == 'reply_message_group') {
$subject = get_lang('Re:').api_xml_http_response_encode($message_info['title']);
} else {
$subject = api_xml_http_response_encode($message_info['title']);
$message = api_xml_http_response_encode($message_info['content']);
}
}
}
?>
<form name="form" action="groups.php?id=<?php echo $group_id ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="send_message_group" />
<input type="hidden" name="action" value="<?php echo $allowed_action ?>" />
<input type="hidden" name="group_id" value="<?php echo $group_id ?>" />
<input type="hidden" name="parent_id" value="<?php echo $message_id ?>" />
<input type="hidden" name="token" value="<?php echo $_SESSION['sec_token'] ?>" />
<input type="hidden" name="message_id" value="<?php echo $message_id ?>" />
<input type="hidden" name="token" value="<?php echo $tok ?>" />
<table width="600" border="0" height="220">
<tr height="180">
<td align="left">
@ -59,26 +73,26 @@ if (!empty($group_id)) {
echo api_xml_http_response_encode(get_lang('To')); ?> :&nbsp;&nbsp;&nbsp;&nbsp;<?php echo api_xml_http_response_encode($to_group); ?>
<br />
<br /><?php echo api_xml_http_response_encode(get_lang('Subject')); ?> :<br />
<input id="txt_subject_id" name="title" type="text" style="width:450px;" value="<?php echo $title_group ?>"><br/>
<input id="txt_subject_id" name="title" type="text" style="width:450px;" value="<?php echo $subject ?>"><br/>
<br /><?php echo api_xml_http_response_encode(get_lang('Message')); ?> :<br />
<textarea id="txt_area_invite" name="content" rows="3" cols="68"></textarea><br/>
<br /><?php echo api_xml_http_response_encode(get_lang('AttachmentFiles')); ?> :<br />
<?php
$oFCKeditor = new FCKeditor('content') ;
$oFCKeditor->ToolbarSet = 'profile';
$oFCKeditor->Width = '100%';
$oFCKeditor->Height = '120';
$oFCKeditor->Value = $message;
$return = $oFCKeditor->CreateHtml();
echo $return;
?>
<br /><br /><?php echo api_xml_http_response_encode(get_lang('AttachmentFiles')); ?> :<br />
<span id="filepaths"><div id="filepath_1"><input type="file" name="attach_1" size="20" /></div></span>
<div id="link-more-attach"><a href="javascript://" onclick="return add_image_form()"><?php echo get_lang('AddOneMoreFile') ?></a>&nbsp;(<?php echo api_xml_http_response_encode(sprintf(get_lang('MaximunFileSizeX'),format_file_size(api_get_setting('message_max_upload_filesize')))) ?>)</div>
<!--button class="save" type="button" value="<?php echo api_xml_http_response_encode(get_lang('SendMessage')); ?>" onclick="return ajaxFileUpload()"><?php echo api_xml_http_response_encode(get_lang('SendMessage')) ?></button-->
<br />
<button class="save" type="submit" value="<?php echo api_xml_http_response_encode(get_lang('SendMessage')); ?>"><?php echo api_xml_http_response_encode(get_lang('SendMessage')) ?></button>
<?php } ?>
</dl>
</td>
</tr>
</div>
<tr>
<td>
<div id="display_response_id" style="position:relative"></div>
</td>
</tr>
</table>
</form>
Loading…
Cancel
Save