move code up one directory
[atutor.git] / mods / _standard / social / index_public.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010                                             */
6 /* Inclusive Design Institute                                          */
7 /* http://atutor.ca                                                                                                        */
8 /*                                                                                                                                         */
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$
14 $_user_location = 'public';
15
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
23
24 $rand_key = $addslashes($_POST['rand_key']);    //should we excape?
25
26 //paginator settings
27 $page = intval($_GET['p']);
28 if (!$page) {
29         $page = 1;
30 }       
31 $count  = (($page-1) * SOCIAL_FRIEND_SEARCH_MAX) + 1;
32 $offset = ($page-1) * SOCIAL_FRIEND_SEARCH_MAX;
33
34
35 //if $_GET['q'] is set, handle Ajax.
36 if (isset($_GET['q'])){
37         $query = $addslashes($_GET['q']);
38
39         //retrieve a list of friends by the search
40         $search_result = searchFriends($query);
41
42
43         if (!empty($search_result)){
44                 echo '<div class="suggestions">'._AT('suggestions').':<br/>';
45                 $counter = 0;
46                 foreach($search_result as $member_id=>$member_array){
47                         //display 10 suggestions
48                         if ($counter > 10){
49                                 break;
50                         }
51
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/>';
53                         $counter++;
54                 }
55                 echo '</div>';
56         }
57         exit;
58 }
59
60 //safe guard
61 //No friend request on index_public.. need login
62 /*
63 if (isset($_GET['id'])){
64         $id = intval($_GET['id']);
65         if($id > 0){
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);
71
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');
81                         $mail->Body     = $body;
82
83                         if(!$mail->Send()) {
84                                 $msg->addError('SENDING_ERROR');
85                         }
86                         unset($mail);
87                 }
88
89                 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'connections.php', AT_PRETTY_URL_IS_HEADER));
90                 exit;
91         }
92 }
93 */
94
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));
100                 exit;
101         }
102         //to adapt paginator GET queries
103         if($_GET['search_friends']){
104                 $search_field = $addslashes($_GET['search_friends']);
105         } else {
106                 $search_field = $addslashes($_POST['search_friends_'.$rand_key]);       
107         }
108         if (isset($_POST['myFriendsOnly'])){
109                 //retrieve a list of my friends
110                 $friends = searchFriends($search_field, true);
111         } else {
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);
116         }
117
118
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('social/index_public.tmpl.php');
126 include(AT_INCLUDE_PATH.'footer.inc.php');
127 ?>