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 /****************************************************************/
13 // $Id: connections.php 8410 2009-04-02 20:49:34Z greg $
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
24 $rand_key = $addslashes($_POST['rand_key']); //should we excape?
27 $page = intval($_GET['p']);
31 $count = (($page-1) * SOCIAL_FRIEND_SEARCH_MAX) + 1;
32 $offset = ($page-1) * SOCIAL_FRIEND_SEARCH_MAX;
35 //if $_GET['q'] is set, handle Ajax.
36 if (isset($_GET['q'])){
37 $query = $addslashes($_GET['q']);
39 //retrieve a list of friends by the search
40 $search_result = searchFriends($query);
43 if (!empty($search_result)){
44 echo '<div class="suggestions">'._AT('suggestions').':<br/>';
46 foreach($search_result as $member_id=>$member_array){
47 //display 10 suggestions
52 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/>';
61 //No friend request on index_public.. need login
63 if (isset($_GET['id'])){
64 $id = intval($_GET['id']);
66 addFriendRequest($id);
67 $msg->addFeedback('REQUEST_FRIEND_ADDED');
68 $sql_notify = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id=$id";
69 $result_notify = mysql_query($sql_notify, $db);
70 $row_notify = mysql_fetch_assoc($result_notify);
72 if ($row_notify['email'] != '') {
73 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
74 $body = _AT('notification_new_contact', get_display_name($_SESSION['member_id']), $_base_href.AT_SOCIAL_BASENAME.'index_mystart.php');
75 $sender = get_display_name($_SESSION['member_id']);
76 $mail = new ATutorMailer;
77 $mail->AddAddress($row_notify['email'], $sender);
78 $mail->FromName = $_config['site_name'];
79 $mail->From = $_config['contact_email'];
80 $mail->Subject = _AT('contact_request');
84 $msg->addError('SENDING_ERROR');
89 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'connections.php', AT_PRETTY_URL_IS_HEADER));
95 //handle search friends request
96 if(($rand_key!='' && isset($_POST['search_friends_'.$rand_key])) || isset($_GET['search_friends'])){
97 if (empty($_POST['search_friends_'.$rand_key]) && !isset($_GET['search_friends'])){
98 $msg->addError('CANNOT_BE_EMPTY');
99 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'index_public.php', AT_PRETTY_URL_IS_HEADER));
102 //to adapt paginator GET queries
103 if($_GET['search_friends']){
104 $search_field = $addslashes($_GET['search_friends']);
106 $search_field = $addslashes($_POST['search_friends_'.$rand_key]);
108 if (isset($_POST['myFriendsOnly'])){
109 //retrieve a list of my friends
110 $friends = searchFriends($search_field, true);
112 //retrieve a list of friends by the search
113 $friends = searchFriends($search_field); //to calculate the total number. TODO: need a better way, wasting runtime.
114 $num_pages = max(ceil(sizeof($friends) / SOCIAL_FRIEND_SEARCH_MAX), 1);
115 $friends = searchFriends($search_field, false, $offset);
119 include(AT_INCLUDE_PATH.'header.inc.php');
120 $savant->assign('page', $page);
121 $savant->assign('num_pages', $num_pages);
122 $savant->assign('search_field', $search_field);
123 $savant->assign('friends', $friends);
124 $savant->assign('rand_key', $rand_key);
125 $savant->display('index_public.tmpl.php');
126 include(AT_INCLUDE_PATH.'footer.inc.php');