Browse Source

Improving group notifications messages ... now we do a nice scroll til the message when editing/answering a thread, fixing also the email that was sent from a group

Julio Montoya 13 years ago
parent
commit
78441938da

+ 25 - 15
main/inc/lib/message.lib.php

@@ -212,13 +212,15 @@ class MessageManager
      * @param bool    sent an email or not (@todo)
 	 * @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, $sent_email = false) {
+	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, $topic_id = 0) {
         global $charset;
 		$table_message      = Database::get_main_table(TABLE_MESSAGE);
         $group_id           = intval($group_id);
         $receiver_user_id   = intval($receiver_user_id);
         $parent_id          = intval($parent_id);
         $edit_message_id    = intval($edit_message_id);
+        $topic_id   		= intval($topic_id);
+                
 		$user_sender_id     = api_get_user_id();
 
 		$total_filesize = 0;
@@ -293,27 +295,31 @@ class MessageManager
 			}
 						
 			//Load user settings			
-			$notification = new Notification();			    
-		    if (empty($group_id)) {                
-		        $sender_info = api_get_user_info($user_sender_id);
+			$notification = new Notification();
+			$sender_info = api_get_user_info($user_sender_id);
+			
+		    if (empty($group_id)) {		    	
                 $notification->save_notification(NOTIFICATION_TYPE_MESSAGE, array($receiver_user_id), $subject, $content, $sender_info);                
 		    } else {
-		        $group_info = GroupPortalManager::get_group_data($group_id);		        
+		        $group_info = GroupPortalManager::get_group_data($group_id);
+		        $group_info['topic_id'] = $topic_id;
+		        $group_info['msg_id'] 	= $inbox_last_id;
+		        
 		        $user_list  = GroupPortalManager::get_users_by_group($group_id, false, array(),0, 1000);
 		        
 		        //Adding more sens to the message group
-		        $subject = sprintf(get_lang('ThereIsANewMessageInTheGroupX'), $group_info['name']);
+		        $subject = sprintf(get_lang('ThereIsANewMessageInTheGroupX'), $group_info['name']);		        
 		        
 		        $new_user_list = array();		   
                 foreach($user_list as $user_data) {
-                    $new_user_list[]= $user_data['user_id'];
+                    $new_user_list[] = $user_data['user_id'];
                 }
+                $group_info = array('group_info'=>$group_info, 'user_info' => $sender_info);
                 $notification->save_notification(NOTIFICATION_TYPE_GROUP, $new_user_list, $subject, $content, $group_info);                     		
 		    }
 			return $inbox_last_id;
-        } else {
-        	return get_lang('UserDoesNotExist');
         }
+        return false;
 	}
 
 	/**
@@ -992,13 +998,13 @@ class MessageManager
      * Displays messages of a group with nested view
      * @param int group id
      */
-    public static function display_message_for_group($group_id, $message_id, $is_member) {
+    public static function display_message_for_group($group_id, $topic_id, $is_member, $message_id ) {
         global $my_group_role;
         
-        $main_message 	= self::get_message_by_id($message_id);                
+        $main_message 	= self::get_message_by_id($topic_id);                
         $group_info		= GroupPortalManager::get_group_data($group_id);
-        $rows 			= self::get_messages_by_group_by_message($group_id, $message_id);            
-        $rows 			= self::calculate_children($rows, $message_id);                
+        $rows 			= self::get_messages_by_group_by_message($group_id, $topic_id);            
+        $rows 			= self::calculate_children($rows, $topic_id);                
         
         $current_user_id  = api_get_user_id();
         
@@ -1007,7 +1013,7 @@ class MessageManager
         
         $count_items = 0;
         $html_messages = '';
-        $query_vars = array('id'=>$group_id, 'topic_id'=>$message_id , 'topics_page_nr'=>0);        
+        $query_vars = array('id'=>$group_id, 'topic_id'=>$topic_id , 'topics_page_nr'=>0);        
         
         
         // Main message        
@@ -1106,8 +1112,12 @@ class MessageManager
                 } else {
                     $indent = intval($topic['indent_cnt'])*$base_padding + $base_padding;
                 }
+                $class = 'group_social_sub_item';
+                if (isset($message_id) && $message_id == $topic['id']) {
+                	$class .= ' group_social_sub_item_highlight';
+                }
                 
-                $html_items = Display::div($html_items, array('class' => 'group_social_sub_item'));
+                $html_items = Display::div($html_items, array('class' => $class, 'id'=>'msg_'.$topic['id']));
                 $html_items = Display::div($html_items, array('class' => '', 'style'=>'margin-left:'.$indent.'px'));            
                 $array_html_items[] = array($html_items);
             }                   

+ 10 - 4
main/inc/lib/notification.lib.php

@@ -171,11 +171,17 @@ class Notification extends Model {
                 $link_to_new_message = Display::url(get_lang('SeeInvitation'), api_get_path(WEB_CODE_PATH).'social/invitations.php');            
                 break;
             case NOTIFICATION_TYPE_GROUP:
-                if (!empty($sender_info)) {            
-                    $sender_name = $sender_info['name'];                    
+            	$topic_page = intval($_REQUEST['topics_page_nr']);
+                if (!empty($sender_info)) {                            
+                    $sender_name = $sender_info['group_info']['name'];                    
                     $new_message_text  = sprintf(get_lang('YouHaveReceivedANewMessageInTheGroupX'), $sender_name);                    
+                    $sender_name = api_get_person_name($sender_info['user_info']['firstname'], $sender_info['user_info']['lastname'], null, PERSON_NAME_EMAIL_ADDRESS);
+                    $sender_name = Display::url($sender_name , api_get_path(WEB_CODE_PATH).'social/profile.php?'.$sender_info['user_info']['user_id']);
+                    $new_message_text  .= '<br />'.get_lang('User').': '.$sender_name;
+                                        
                 }    
-                $link_to_new_message = Display::url(get_lang('SeeMessage'), api_get_path(WEB_CODE_PATH).'social/groups.php?id='.$sender_info['id']);
+                $group_url = api_get_path(WEB_CODE_PATH).'social/group_topics.php?id='.$sender_info['group_info']['id'].'&topic_id='.$sender_info['group_info']['topic_id'].'&msg_id='.$sender_info['group_info']['msg_id'].'&topics_page_nr='.$topic_page;                 
+                $link_to_new_message = Display::url(get_lang('SeeMessage'), $group_url);
                 break;
         }        
         $preference_url = api_get_path(WEB_CODE_PATH).'auth/profile.php';
@@ -192,7 +198,7 @@ class Notification extends Model {
               
         // You have received this message because you are subscribed text
         $content        = $content.'<br /><hr><i>'.
-                          sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).'</i>'; 
+                          sprintf(get_lang('YouHaveReceivedThisNotificationBecauseYouAreSubscribedOrInvolvedInItToChangeYourNotificationPreferencesPleaseClickHereX'), Display::url($preference_url, $preference_url)).'</i>';
         return $content;        
     }
 }

+ 59 - 38
main/social/group_topics.php

@@ -15,6 +15,47 @@ if (api_get_setting('allow_social_tool') !='true') {
 }
 require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
 
+$group_id   = intval($_GET['id']);
+$topic_id   = intval($_GET['topic_id']);
+$message_id  = intval($_GET['msg_id']);
+
+
+
+// save message group
+if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
+
+	if (isset($_POST['action'])) {
+		$title        = isset($_POST['title']) ? $_POST['title'] : null;
+		$content      = $_POST['content'];
+		$group_id     = intval($_POST['group_id']);
+		$parent_id    = intval($_POST['parent_id']);
+
+		if ($_POST['action'] == 'reply_message_group') {
+			$title = cut($content, 50);
+		}
+		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, 0, $topic_id);
+		} else {
+			if ($_POST['action'] == 'add_message_group' && !$is_member) {
+				api_not_allowed();
+			}
+			$res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id, 0, $topic_id);
+		}
+
+		// display error messages
+		if (!$res) {
+			Display::display_error_message(get_lang('Error'));
+		}
+		$topic_id = intval($_GET['topic_id']);
+		if ($_POST['action'] == 'add_message_group') {
+			$topic_id = $res;
+		}
+		$message_id = $res;
+	}
+}
+
+
 $htmlHeadXtra[] = api_get_jquery_ui_js();
 $htmlHeadXtra[] = '<script type="text/javascript"> 
 
@@ -65,8 +106,22 @@ function hide_icon_edit(element_html)  {
     $(ident).hide();
 }  
 
+function validate_text_empty(str,msg) {
+	var str = str.replace(/^\s*|\s*$/g,"");
+	if (str.length == 0) {
+		alert(msg);
+		return true;
+	}
+}
+
 
-$(document).ready(function() {    
+$(document).ready(function() {
+	if ( $("#msg_'.$message_id.'").length) {
+		$("html,body").animate({
+			scrollTop: $("#msg_'.$message_id.'").offset().top
+		})
+	}
+	   
 	$(\'.group_message_popup\').live(\'click\', function() {
 		var url     = this.href;
 	    var dialog  = $("#dialog");
@@ -98,8 +153,8 @@ $interbreadcrumb[]= array ('url' =>'home.php','name' => get_lang('Social'));
 $interbreadcrumb[] = array('url' => 'groups.php','name' => get_lang('Groups'));
 $interbreadcrumb[] = array('url' => '#','name' => get_lang('Thread'));
 
-$group_id   = intval($_GET['id']);
-$topic_id   = intval($_GET['topic_id']);
+Display::display_header($tool_name, 'Groups');
+
 
 //todo @this validation could be in a function in group_portal_manager
 if (empty($group_id)) {
@@ -116,40 +171,6 @@ if (empty($group_id)) {
     }
 }
 
-Display::display_header($tool_name, 'Groups');
-
-// save message group
-if (isset($_POST['token']) && $_POST['token'] === $_SESSION['sec_token']) {
-
-    if (isset($_POST['action'])) {        
-        $title        = isset($_POST['title']) ? $_POST['title'] : null;
-        $content      = $_POST['content'];
-        $group_id     = intval($_POST['group_id']);
-        $parent_id    = intval($_POST['parent_id']);
-                
-        if ($_POST['action'] == 'reply_message_group') {
-            $title = cut($content, 50);
-        }
-        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 {
-            if ($_POST['action'] == 'add_message_group' && !$is_member) {
-                api_not_allowed();
-            }            
-            $res = MessageManager::send_message(0, $title, $content, $_FILES, '', $group_id, $parent_id);
-        }
-
-        // display error messages
-        if (is_string($res)) {
-            Display::display_error_message($res);
-        }
-        $topic_id = intval($_GET['topic_id']);
-        if ($_POST['action'] == 'add_message_group') {
-            $topic_id = $res;    
-        }        
-    }
-}
 
 
 echo '<div id="social-content">';
@@ -163,7 +184,7 @@ echo '<div id="social-content">';
         if (!empty($show_message)){
             Display::display_confirmation_message($show_message);
         }
-        $content = MessageManager::display_message_for_group($group_id, $topic_id, $is_member);
+        $content = MessageManager::display_message_for_group($group_id, $topic_id, $is_member, $message_id);
         echo $content;
     echo '</div>';
 echo '</div>';

+ 6 - 2
main/social/message_for_group_form.inc.php

@@ -69,7 +69,7 @@ $param_item_page .= '&topic_id='.intval($_GET['topic_id']);
 $page_topic  = !empty($_GET['topics_page_nr'])?intval($_GET['topics_page_nr']):1;
 ?>
 
-<form name="form" action="group_topics.php?id=<?php echo $group_id ?>&anchor_topic=<?php echo Security::remove_XSS($_GET['anchor_topic']) ?>&topics_page_nr=<?php echo $page_topic ?><?php echo $param_item_page ?>" method="POST" enctype="multipart/form-data">
+<form name="form" action="group_topics.php?id=<?php echo $group_id ?>&anchor_topic=<?php echo Security::remove_XSS($_GET['anchor_topic']) ?>&topics_page_nr=<?php echo $page_topic.$param_item_page ?>" method="POST" enctype="multipart/form-data">
 <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 ?>" />
@@ -115,8 +115,12 @@ $page_topic  = !empty($_GET['topics_page_nr'])?intval($_GET['topics_page_nr']):1
 			(<?php echo api_xml_http_response_encode(sprintf(get_lang('MaximunFileSizeX'),format_file_size(api_get_setting('message_max_upload_filesize')))) ?>)		   				   				   		
 	   		<br />
 	   		<br />
-	   		<button class="save" onclick="if(validate_text_empty(this.form.title.value,'<?php echo get_lang('YouShouldWriteASubject')?>')){return false;}" 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 if ($allowed_action == 'add_message_group') { ?>
+	   			<button class="save" onclick="if(validate_text_empty(this.form.title.value,'<?php echo get_lang('YouShouldWriteASubject')?>')){return false;}" 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 } else { ?>
+	   			<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 } ?>	
 	<?php } ?>
 	</dl>
 </td>