remove old readme
[atutor.git] / docs / mods / _standard / social / groups / invitation_handler.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.'classes/SocialGroups/SocialGroup.class.php');
20 require(AT_SOCIAL_INCLUDE.'classes/SocialGroups/SocialGroups.class.php');
21 require(AT_SOCIAL_INCLUDE.'friends.inc.php');
22
23 if (isset($_GET['invitation']) || isset($_GET['request'])){
24         $id = intval($_GET['id']);
25         $sender_id = intval($_GET['sender_id']);
26         $status = -1;
27         $group_obj = new SocialGroup($id);
28         if ($id > 0){
29                 //handle invitations
30                 if ($_GET['invitation']=='accept'){
31
32                         $sql = "SELECT sender_id from ".TABLE_PREFIX."social_groups_invitations WHERE  member_id = '$_SESSION[member_id]' AND group_id = '$id'";
33
34                         $result_sender = mysql_query($sql, $db);
35                         $sender = mysql_fetch_array($result_sender);
36
37                         require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
38                         foreach ($sender as $sid){
39
40                                 $sql_notify = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id=$sid";
41                                 $result_notify = mysql_query($sql_notify, $db);
42                                 $row_notify = mysql_fetch_assoc($result_notify);
43                                 //require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
44                                 if ($row_notify['email'] != '') {
45                                         //require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
46                                         $body = _AT('notification_group_invite_accepted', get_display_name($_SESSION['member_id']),$group_obj->getName() , $_base_href.AT_SOCIAL_BASENAME.'index_mystart.php');
47                                         $sender = get_display_name($_SESSION['member_id']);
48                                         $mail = new ATutorMailer;
49                                         $mail->AddAddress($row_notify['email'], $sender);
50                                         $mail->FromName = $_config['site_name'];
51                                         $mail->From     = $_config['contact_email'];
52                                         $mail->Subject  = _AT('group_invitation_accepted');
53                                         $mail->Body     = $body;
54                 
55                                         if(!$mail->Send()) {
56                                                 $msg->addError('SENDING_ERROR');
57                                         }
58                                         unset($mail);
59                                 }
60                         }
61
62                         acceptGroupInvitation($id);
63                         $status = 1;
64                 } elseif ($_GET['invitation']=='reject'){
65                         rejectGroupInvitation($id);
66                         $status = 2;
67                 }
68
69                 //handle requests (requests to join a group from some member)
70                 if ($sender_id > 0){
71                         if ($_GET['request']=='accept'){
72
73                         $sql = "SELECT sender_id from ".TABLE_PREFIX."social_groups_requests WHERE  member_id = '$_SESSION[member_id]' AND group_id = '$id'";
74
75                         $result_sender = mysql_query($sql, $db);
76                         $sender = mysql_fetch_array($result_sender);
77
78                         require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
79                         foreach ($sender as $sid){
80
81                                 $sql_notify = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id=$sid";
82                                 $result_notify = mysql_query($sql_notify, $db);
83                                 $row_notify = mysql_fetch_assoc($result_notify);
84
85                                 if ($row_notify['email'] != '') {
86                                         $body = _AT('notification_group_request_accepted', $group_obj->getName() , $_base_href.AT_SOCIAL_BASENAME.'index_mystart.php');
87                                         $sender = get_display_name($_SESSION['member_id']);
88                                         $mail = new ATutorMailer;
89                                         $mail->AddAddress($row_notify['email'], $sender);
90                                         $mail->FromName = $_config['site_name'];
91                                         $mail->From     = $_config['contact_email'];
92                                         $mail->Subject  = _AT('group_request_accepted');
93                                         $mail->Body     = $body;
94                 
95                                         if(!$mail->Send()) {
96                                                 $msg->addError('SENDING_ERROR');
97                                         }
98                                         unset($mail);
99                                 }
100                         }
101                                 acceptGroupRequest($id, $sender_id);
102                                 $status = 3;
103                         } elseif ($_GET['request']=='reject'){
104                                 rejectGroupRequest($id, $sender_id);
105                                 $status = 4;
106                         }
107                 }
108         }
109
110         switch($status){
111                 case 1:
112                         $msg->addFeedback('ACCEPT_GROUP_INVITATION');
113                         break;
114                 case 2:
115                         $msg->addFeedback('REJECT_GROUP_INVITATION');
116                         break;
117                 case 3:
118                         $msg->addFeedback('ACCEPT_GROUP_REQUEST');
119                         break;
120                 case 4:
121                         $msg->addFeedback('REJECT_GROUP_REQUEST');
122                         break;
123                 default:
124                         break;
125         }
126         header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/view.php?id='.$id, AT_PRETTY_URL_HEADER));
127         exit;
128 }
129
130 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/index.php', AT_PRETTY_URL_HEADER));
131 exit;
132 ?>