2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
14 $_user_location = 'public';
16 define('AT_INCLUDE_PATH', '../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 require(AT_SOCIAL_INCLUDE.'constants.inc.php');
19 require(AT_SOCIAL_INCLUDE.'friends.inc.php');
20 require(AT_SOCIAL_INCLUDE.'classes/PrivacyControl/PrivacyObject.class.php');
21 require(AT_SOCIAL_INCLUDE.'classes/PrivacyControl/PrivacyController.class.php');
22 $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
25 if (!$_SESSION['valid_user']) {
26 require(AT_INCLUDE_PATH.'header.inc.php');
27 $info = array('INVALID_USER', $_SESSION['course_id']);
28 $msg->printInfos($info);
29 require(AT_INCLUDE_PATH.'footer.inc.php');
33 // default display my friends
34 $friends = getFriends($_SESSION['member_id']);
35 $rand_key = $addslashes($_POST['rand_key']); //should we excape?
38 $page = intval($_GET['p']);
42 $count = (($page-1) * SOCIAL_FRIEND_SEARCH_MAX) + 1;
43 $offset = ($page-1) * SOCIAL_FRIEND_SEARCH_MAX;
46 //if $_GET['q'] is set, handle Ajax.
47 if (isset($_GET['q'])){
48 $query = $_GET['q']; //don't need to addslashes here cause searchFriends will do it.
50 if (isset($_POST['myFriendsOnly'])){
51 //retrieve a list of my friends
52 $search_result = searchFriends($query, true);
54 //retrieve a list of friends by the search
55 $search_result = searchFriends($query);
58 if (!empty($search_result)){
59 echo '<div class="suggestions">'._AT('suggestions').':<br/>';
61 foreach($search_result as $member_id=>$member_array){
62 //display 10 suggestions
67 echo '<a href="javascript:void(0);" onclick="document.getElementById(\'search_friends\').value=\''.printSocialName($member_id, false).'\'; document.getElementById(\'search_friends_form\').submit();">'.printSocialName($member_id, false).'</a><br/>';
76 if (isset($_GET['id'])){
77 $id = intval($_GET['id']);
79 addFriendRequest($id);
80 $msg->addFeedback('REQUEST_FRIEND_ADDED');
81 $sql_notify = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id=$id";
82 $result_notify = mysql_query($sql_notify, $db);
83 $row_notify = mysql_fetch_assoc($result_notify);
85 if ($row_notify['email'] != '') {
86 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
87 $body = _AT('notification_new_contact', get_display_name($_SESSION['member_id']), $_base_href.AT_SOCIAL_BASENAME.'index_mystart.php');
88 $sender = get_display_name($_SESSION['member_id']);
89 $mail = new ATutorMailer;
90 $mail->AddAddress($row_notify['email'], $sender);
91 $mail->FromName = $_config['site_name'];
92 $mail->From = $_config['contact_email'];
93 $mail->Subject = _AT('contact_request');
97 $msg->addError('SENDING_ERROR');
102 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'connections.php', AT_PRETTY_URL_IS_HEADER));
107 //handle search friends request
108 if(($rand_key!='' && isset($_POST['search_friends_'.$rand_key])) || isset($_GET['search_friends'])){
109 if (empty($_POST['search_friends_'.$rand_key]) && !isset($_GET['search_friends'])){
110 $msg->addError('CANNOT_BE_EMPTY');
111 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'connections.php', AT_PRETTY_URL_IS_HEADER));
114 //to adapt paginator GET queries
115 //don't need to apply addslashes here cause searchFriends will do it.
116 if($_GET['search_friends']){
117 $search_field = $_GET['search_friends'];
119 $search_field = $_POST['search_friends_'.$rand_key];
121 if (isset($_POST['myFriendsOnly'])){
122 //retrieve a list of my friends
123 $friends = searchFriends($search_field, true);
125 //retrieve a list of friends by the search
126 $friends = searchFriends($search_field); //to calculate the total number. TODO: need a better way, wasting runtime.
127 $num_pages = max(ceil(sizeof($friends) / SOCIAL_FRIEND_SEARCH_MAX), 1);
128 $friends = searchFriends($search_field, false, $offset);
132 //mark those that are already added
133 $friends = markFriends($_SESSION['member_id'], $friends);
134 include(AT_INCLUDE_PATH.'header.inc.php');
135 $savant->display('pubmenu.tmpl.php');
136 $savant->assign('page', $page);
137 $savant->assign('num_pages', $num_pages);
138 $savant->assign('search_field', $search_field);
139 $savant->assign('friends', $friends);
140 $savant->assign('rand_key', $rand_key);
141 $savant->display('connections.tmpl.php');
142 include(AT_INCLUDE_PATH.'footer.inc.php');