d2dc7f7c92e3777139482d23333617ff0ccc27af
[atutor.git] / docs / mods / _standard / social / groups / list.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2009                                                                              */
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 require(AT_SOCIAL_INCLUDE.'classes/SocialGroups/SocialGroup.class.php');
23 require(AT_SOCIAL_INCLUDE.'classes/SocialGroups/SocialGroups.class.php');
24 $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
25
26 $id = intval($_REQUEST['id']);
27 if ($id < 1){
28         exit;
29 }
30
31 // default display all group members
32 $grp_obj = new SocialGroup($id);
33 $grp_members = $grp_obj->getGroupMembers();
34
35 $rand_key = $addslashes($_POST['rand_key']);    //should we excape?
36
37 //if $_GET['q'] is set, handle Ajax.
38 if (isset($_GET['q'])){
39         $query = $addslashes($_GET['q']);
40         $search_result = $grp_obj->searchMembers($query);
41
42         if (!empty($search_result)){
43                 echo '<div class="suggestions">'._AT('suggestions').':<br/>';
44                 $counter = 0;
45                 foreach($search_result as $member_id=>$member_obj){
46                         //display 10 suggestions
47                         if ($counter > 10){
48                                 break;
49                         }
50                         echo '<a href="javascript:void(0);" onclick="document.getElementById(\'search_friends\').value=\''.printSocialName($member_obj->getID(), false).'\'; document.getElementById(\'search_friends_form\').submit();">'.printSocialName($member_obj->getID(), false).'</a><br/>';
51                         $counter++;
52                 }
53                 echo '</div>';
54         }
55         exit;
56 }
57
58 //handle search friends request
59 if($rand_key!='' && isset($_POST['search_friends_'.$rand_key])){
60         if (empty($_POST['search_friends_'.$rand_key])){
61                 $msg->addError('CANNOT_BE_EMPTY');
62                 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/list.php?id='.$id, AT_PRETTY_URL_IS_HEADER));
63                 exit;
64         }
65         $search_field = $addslashes($_POST['search_friends_'.$rand_key]);
66         $grp_members = $grp_obj->searchMembers($search_field);
67
68
69
70 //handle delete friends request
71 if (isset($_GET['remove']) && isset($_GET['member_id'])){
72         //saveguard
73         $member_id = $_GET['member_id'];
74
75         //validate if this is the creator of group
76         if($_SESSION['member_id']==$grp_obj->getUser()){
77                 $grp_obj->removeMember($member_id);
78                 $msg->addFeedback('GRUOP_MEMBER_REMOVED');
79                 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/list.php?id='.$id, AT_PRETTY_URL_IS_HEADER));
80                 exit;
81         }
82 }
83
84 include(AT_INCLUDE_PATH.'header.inc.php');
85 $savant->display('social/pubmenu.tmpl.php');
86 $savant->assign('grp_obj', $grp_obj);
87 $savant->assign('grp_members', $grp_members);
88 $savant->assign('rand_key', $rand_key);
89 $savant->display('social/sgroup_list.tmpl.php');
90 include(AT_INCLUDE_PATH.'footer.inc.php');
91 ?>