remove old readme
[atutor.git] / docs / mods / _standard / social / groups / join.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/SocialGroups/SocialGroup.class.php');
21 require(AT_SOCIAL_INCLUDE.'classes/SocialGroups/SocialGroups.class.php');
22
23 //Get group
24 $gid = intval($_GET['id']);
25 $group_obj = new SocialGroup($gid);
26
27 /** If public 
28   * allow anyone to join the group without approval
29   */
30 if ($group_obj->getPrivacy()==0){
31         /*public*/
32         $result = $group_obj->addMember($_SESSION['member_id']);                //adding "myself" into the group 
33         if($result){
34                 $msg->addFeedback('GROUP_JOINED');
35         } else {
36                 $msg->addError('JOIN_REQUEST_FAILED');
37         }
38 } else {
39         /*private*/
40         $result = $group_obj->addRequest();
41         if ($result){
42                 $sql = "SELECT member_id from ".TABLE_PREFIX."social_groups WHERE id = '$gid'";
43
44                 $result_sender = mysql_query($sql, $db);
45                 $grpadmins = mysql_fetch_row($result_sender);
46                 $grpadmin = $grpadmins['0'];
47
48                 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
49                 $sql_notify = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id=$grpadmin";
50                 $result_notify = mysql_query($sql_notify, $db);
51                 $row_notify = mysql_fetch_assoc($result_notify);
52
53                 if ($row_notify['email'] != '') {
54                         $body = _AT('notification_group_request', $group_obj->getName() , $_base_href.AT_SOCIAL_BASENAME.'index_mystart.php');
55                         $sender = get_display_name($_SESSION['member_id']);
56                         $mail = new ATutorMailer;
57                         $mail->AddAddress($row_notify['email'], $sender);
58                         $mail->FromName = $_config['site_name'];
59                         $mail->From     = $_config['contact_email'];
60                         $mail->Subject  = _AT('group_request');
61                         $mail->Body     = $body;
62
63                         if(!$mail->Send()) {
64                                 $msg->addError('SENDING_ERROR');
65                         }
66                         unset($mail);
67                 }
68
69                 $msg->addFeedback('JOIN_REQUEST_SENT');
70         } else {
71                 $msg->addError('JOIN_REQUEST_FAILED');
72         }
73 }
74
75
76
77 //Display
78 header('Location: '.url_rewrite(AT_SOCIAL_BASENAME.'groups/index.php', AT_PRETTY_URL_HEADER));
79 exit;
80 ?>