root/devel/mod/community/invite.php

Revision 1580, 4.6 kB (checked in by misja, 8 months ago)

Misja Hoebe <misja@curverider.co.uk> Fixes a typo

  • Property svn:eol-style set to native
Line 
1 <?php
2     // Community invite users page
3
4     // Run includes
5     require_once(dirname(dirname(__FILE__))."/../includes.php");
6
7     // Initialise functions for user details, icon management and profile management
8     run("userdetails:init");
9     run("profile:init");
10     run("friends:init");
11     run("communities:init");
12
13     $context = (defined('COMMUNITY_CONTEXT'))?COMMUNITY_CONTEXT:"network";
14
15     define("context", $context);
16     templates_page_setup();
17
18     // Whose friends are we looking at?
19     global $page_owner,$profile_id;
20     
21     // You must be logged on to view this!
22     //    protect(1);
23
24     $title = run("profile:display:name") . " :: " . __gettext("Invite people");
25     
26     $body  = '<h3>'.__gettext("Invite people").'</h3>';
27     $body .= '<p>'.__gettext("Invite people to this community.").'</p>';
28     $body .= '<form action="" method="post">';
29     
30     $submit_search_label = __gettext("Search");
31
32     $name_or_username = __gettext("Name or username:");
33     $invite_search = <<< END
34     <p>
35         {$name_or_username} <input type="text" name="invite_name"/><br/>
36         <input type="submit" name="submit" value="{$submit_search_label}"/>
37     </p>
38 END;
39
40     $invite_name    = optional_param('invite_name');
41     $profile_name   = optional_param('profile_name');
42     $invite_ident   = optional_param('invite_ident');
43     
44     if (empty($invite_name)) {
45         $body .= $invite_search;       
46     } else {
47         $search_sql = "SELECT ident, name, username FROM {$CFG->prefix}users WHERE username LIKE '%{$invite_name}%' OR name LIKE '%{$invite_name}%'";
48         $users = get_records_sql($search_sql);
49
50         if (empty($users)) {
51             global $messages;
52             
53             $messages[] = __gettext('No results found matching your search criteria.');
54             $body .= $invite_search;
55         } else {
56             // Reuse adminTable layout
57             $body .= templates_draw(array(
58                                         'context' => 'adminTable',
59                                         'name' => "<h3>" . __gettext("Invite") . "</h3>",
60                                         'column1' => "<h3>" . __gettext("Name") . "</h3>",
61                                         'column2' => "<h3>" . __gettext("Full name") . "</h3>"
62                                         )
63                                   );
64
65
66             foreach($users as $user) {
67 $block = <<< END
68 <div>
69     <table width="100%">
70     <tr>
71         <td width="25%" valign="top"><input type="checkbox" name="invite_ident" value="$user->ident"/></td>
72         <td width="45%" valign="top">$user->username</td>
73         <td width="30%" valign="top">$user->name</td>
74     </tr>
75     </table>
76 </div>
77 END;
78
79                 $body .= $block;
80
81             }
82
83             $body .= '<input type="submit" name="Invite" value="'.__gettext("Invite").'"/>';
84         }
85     }
86
87     if (!empty($invite_ident)) {
88         global $messages;
89         // We have an ident, process
90         if ($result = get_record('friends','owner',$invite_ident,'friend',$profile_id)) {
91             $messages[] = __gettext("The user already is a member of this community.");
92         } else if ($result = get_record('friends_requests', 'owner', $profile_id, 'friend', $invite_ident)){
93             $messages[] = __gettext("The user already has been invited.");
94         } else {
95             $x = new stdClass();
96             $x->owner  = $profile_id;
97             $x->friend = $invite_ident;
98
99             // Add a callback
100             $x = plugin_hook('community:invite', 'publish', $x);
101             
102             if (empty($x)) {
103                 trigger_error("The community:invite callback didn't receive a return value.", E_USER_ERROR);
104             }
105             
106             insert_record('friends_requests', $x);
107             
108             $community = get_record('users', 'ident', $profile_id );
109
110             $message_body = sprintf(__gettext("You have been invited to join %s!\n\nTo visit this community's profile, click on the following link:\n\n\t%s\n\nTo view all your community invitation requests and approve or deny this user, click here:\n\n\t%s\n\nRegards,\n\nThe %s team."),$community->name, $CFG->wwwroot . $community->username . "/", $CFG->wwwroot . user_info("username",$invite_ident) . "/communities/invitations",$CFG->sitename);
111             $title = sprintf(__gettext("New %s community invitation"), $CFG->sitename);
112             notify_user($x->friend,$title,$message_body);
113             
114             $messages[] = __gettext("The user has been invited.");
115         }
116     }
117     
118     $body .= '</form>';
119     
120     echo templates_page_draw( array(
121             $title, templates_draw(array(
122                 'context' => 'contentholder',
123                 'title' => $title,
124                 'body' => $body
125             )
126             )
127         )
128         );
129 ?>
Note: See TracBrowser for help on using the browser.