Browse Source

Social Add friends #6015

unknown 12 years ago
parent
commit
843da79254
4 changed files with 145 additions and 7 deletions
  1. 14 1
      main/css/base.css
  2. BIN
      main/css/send_inv.png
  3. BIN
      main/css/send_msg.png
  4. 131 6
      main/social/search.php

+ 14 - 1
main/css/base.css

@@ -3450,7 +3450,20 @@ a:active{
     display: inline-block;
     margin-right: 4px;
 }
-
+.send_msg_in_text {
+    background: url("send_msg.png") no-repeat scroll right center transparent;
+    height: 16px;
+    width: 17px;
+    display: inline-block;
+    margin-right: 4px;
+}
+.send_inv_in_text {
+    background: url("send_inv.png") no-repeat scroll right center transparent;
+    height: 16px;
+    width: 17px;
+    display: inline-block;
+    margin-right: 4px;
+}
 .teacher_online {
     background: url("teacher.png") no-repeat scroll right center transparent;
     height: 16px;

BIN
main/css/send_inv.png


BIN
main/css/send_msg.png


+ 131 - 6
main/social/search.php

@@ -12,9 +12,125 @@ $language_file = array('registration','admin','userInfo');
 $cidReset = true;
 require_once '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
-
+require_once api_get_path(LIBRARY_PATH).'magpierss/rss_fetch.inc';
+$ajax_url = api_get_path(WEB_AJAX_PATH).'message.ajax.php';
 api_block_anonymous_users();
 
+$htmlHeadXtra[] = '<script>
+
+function checkLength( o, n, min, max ) {
+    if ( o.val().length > max || o.val().length < min ) {
+        o.addClass( "ui-state-error" );
+        //updateTips( "Length of " + n + " must be between " + min + " and " + max + "." );
+        return false;
+    } else {
+        return true;
+    }
+}
+
+function send_message_to_user(user_id) {
+    var subject = $( "#subject_id" );
+    var content = $( "#content_id" );
+
+    $("#send_message_form").show();
+    $("#send_message_div").dialog({
+        modal:true,
+        height:350,
+        buttons: {
+            "'.  addslashes(get_lang('Sent')).'": function() {
+                var bValid = true;
+                bValid = bValid && checkLength( subject, "subject", 1, 255 );
+                bValid = bValid && checkLength( content, "content", 1, 255 );
+
+                if ( bValid ) {
+                    var url = "'.$ajax_url.'?a=send_message&user_id="+user_id;
+                    var params = $("#send_message_form").serialize();
+                    $.ajax({
+                        url: url+"&"+params,
+                        success:function(data) {
+                            $("#message_ajax_reponse").attr("class", "");
+                            $("#message_ajax_reponse").html(data);
+                            $("#message_ajax_reponse").show();
+                            $("#send_message_div").dialog({ buttons:{}});
+                            $("#send_message_form").hide();
+                            $("#send_message_div").dialog("close");
+
+                            $("#subject_id").val("");
+                            $("#content_id").val("");
+                        }
+                    });
+                }
+            },
+        },
+        close: function() {
+        }
+    });
+    $("#send_message_div").dialog("open");
+    //prevent the browser to follow the link
+}
+
+function send_invitation_to_user(user_id) {
+    var content = $( "#content_invitation_id" );
+    $("#send_invitation_form").show();
+    $("#send_invitation_div").dialog({
+        modal:true,
+        buttons: {
+            "'.  addslashes(get_lang('SendInvitation')).'": function() {
+                var bValid = true;
+                bValid = bValid && checkLength( content, "content", 1, 255 );
+                if (bValid) {
+                    var url = "'.$ajax_url.'?a=send_invitation&user_id="+user_id;
+                    var params = $("#send_invitation_form").serialize();
+                    $.ajax({
+                        url: url+"&"+params,
+                        success:function(data) {
+                            $("#message_ajax_reponse").attr("class", "");
+                            $("#message_ajax_reponse").html(data);
+                            $("#message_ajax_reponse").show();
+
+                            $("#send_invitation_div").dialog({ buttons:{}});
+
+                            $("#send_invitation_form").hide();
+                            $("#send_invitation_div").dialog("close");
+                            $("#content_invitation_id").val("");
+                        }
+                    });
+                }
+            },
+        },
+        close: function() {
+        }
+    });
+    $("#send_invitation_div").dialog("open");
+    //prevent the browser to follow the link
+}
+
+$(document).ready(function (){
+    $("input#id_btn_send_invitation").bind("click", function(){
+        if (confirm("'.get_lang('SendMessageInvitation', '').'")) {
+            $("#form_register_friend").submit();
+        }
+    });
+
+    $("#send_message_div").dialog({
+        autoOpen: false,
+        modal    : false,
+        width    : 550,
+        height    : 300
+       });
+
+    $("#send_invitation_div").dialog({
+        autoOpen: false,
+        modal    : false,
+        width    : 550,
+        height    : 300
+       });
+
+});
+
+
+</script>';
+
 if (api_get_setting('allow_social_tool') !='true') {
     api_not_allowed();
 }
@@ -41,14 +157,22 @@ if ($query !='') {
     }
 
     $results = '<div id="online_grid_container"><div class="span9">';
-
-    if (is_array($users) && count($users)> 0) {
+    //$list_friends = SocialManager::get_friends(api_get_user_id());
+    //$count = count($list_friends);
+    //$list_friends = $list_friends[0];
+     if (is_array($users) && count($users)> 0) {
         $results .=  Display::page_subheader(get_lang('Users'));
         $results .= '<ul class="thumbnails">';
         foreach($users as $user) {
+            $send_inv = '';
+            $relation_type =  intval(SocialManager::get_relation_between_contacts(api_get_user_id(), $user['user_id'] ));
             $user_info = api_get_user_info($user['user_id'], true);
             $url = api_get_path(WEB_PATH).'main/social/profile.php?u='.$user['user_id'];
-
+            //Show send invitation icon if they are not friends yet
+            if ($relation_type != 3 && $relation_type != 4 && $user['user_id'] != api_get_user_id()) {
+                $send_inv = '<a href="javascript:void(0);" onclick="javascript:send_invitation_to_user(\''.$user['user_id'].'\');"/>'.Display::span('', array('class' => 'send_inv_in_text')).'</a>';
+            }
+            $send_msg = '<a href="javascript:void(0);" onclick="javascript:send_message_to_user(\''.$user['user_id'].'\');"/>'.Display::span('', array('class' => 'send_msg_in_text')).'</a>';
             if (empty($user['picture_uri'])) {
                 $picture['file'] = api_get_path(WEB_CODE_PATH).'img/unknown_180_100.jpg';
                 $img = '<img src="'.$picture['file'].'">';
@@ -62,7 +186,7 @@ if ($query !='') {
                 $status_icon = Display::span('', array('class' => 'offline_user_in_text'));
             }
             $user['tag'] = isset($user['tag']) ? $user['tag'] : null;
-            $user_info['complete_name'] = Display::url($status_icon.$user_info['complete_name'], $url).'<br />'.$user['tag'];
+            $user_info['complete_name'] = Display::url($status_icon.$user_info['complete_name'], $url).'<br />'.$user['tag'].$send_inv.$send_msg;
             $results .= '<li class="span3"><div class="thumbnail">'.$img.'<div class="caption">'.$user_info['complete_name'].$user['tag'].'</div</div></li>';
         }
         $results .='</ul></div></div>';
@@ -153,7 +277,8 @@ if ($query !='') {
     $visibility = array(true,true,true,true,true);
     $social_right_content .= Display::return_sortable_grid('mygroups', array(), $grid_groups, array('hide_navigation'=>true, 'per_page' => 5), $query_vars, false, $visibility);
 }
-
+$social_right_content .= MessageManager::generate_message_form('send_message');
+$social_right_content .= MessageManager::generate_invitation_form('send_invitation');
 
 $tpl = new Template($tool_name);
 $tpl->assign('social_left_content', $social_left_content);