Ticket #160: 00_community_invite.diff

File 00_community_invite.diff, 7.9 kB (added by misja, 1 year ago)

Invite people to communities

  • mod/friend/lib/user_friendship_requests.php

    old new  
    1212 
    1313            if ($pending_requests = get_records_sql('SELECT fr.ident AS request_id,u.* 
    1414                                                     FROM '.$CFG->prefix.'friends_requests fr LEFT JOIN '.$CFG->prefix.'users u ON u.ident = fr.owner 
    15                                                      WHERE fr.friend = ? ORDER BY u.name ASC',array($page_owner))) { 
     15                                                     WHERE fr.friend = ? AND u.user_type = \'person\' ORDER BY u.name ASC',array($page_owner))) { 
    1616                $body = "<p>" . __gettext("The following users would like to add you as a friend. They need your approval to do this (to change this setting, visit the 'account settings' page).") . "</p>"; 
    1717 
    1818                foreach($pending_requests as $pending_user) { 
     
    5050            } else { 
    5151                $body = "<p>" . __gettext("You have no pending friendship requests.") . "</p>"; 
    5252            } 
    53                         
    54             $run_result .= $body; 
    5553 
     54            $run_result = templates_draw(array( 
     55                        'context' => 'contentholder', 
     56                        'title' => $title, 
     57                        'body' => $body 
     58                    ) 
     59                    ); 
     60 
    5661        } 
    5762 
    5863    } 
  • mod/community/lib.php

    old new  
    8484              $PAGE->menu_sub[] = array( 'name' => 'community:requests', 
    8585                                         'html' => a_href("{$CFG->wwwroot}{$username}/community/requests", 
    8686                                                           __gettext("View membership requests"))); 
    87             } 
     87 
     88              $PAGE->menu_sub[] = array( 'name' => 'community:invite', 
     89                                         'html' => a_href("{$CFG->wwwroot}{$username}/community/invite", 
     90                                                           __gettext("Invite people"))); 
     91              } 
    8892        } 
    8993         
    9094        if (defined("context") && context == "profile") { 
     
    104108     
    105109            } 
    106110        } 
    107          
    108111    } else if ($usertype == "person") { 
    109112 
    110113        if (defined("context") && context == COMMUNITY_CONTEXT) { 
     
    137140    $PAGE->search_menu[] = array( 'name' => __gettext("Communities"), 
    138141                                  'user_type' => 'community'); 
    139142 
     143    // Add membership requests to the personal network page 
     144    if (defined("context") && context == "network") { 
     145          $PAGE->menu_sub[] = array( 'name' => 'membership:invites', 
     146                                   'html' => a_href( "{$CFG->wwwroot}{$username}/communities/invitations", 
     147                                                      __gettext("Membership invitations"))); 
     148    } 
    140149} 
    141150 
    142151function community_init() { 
     
    209218     
    210219                river_register_friendlyname_hook('community::community', 'community_get_friendly_name'); 
    211220        } 
    212          
    213221} 
    214222 
    215223function community_get_friendly_name($object_type, $object_id) 
  • mod/community/lib/communities_actions.php

    old new  
    1111$friend_id = optional_param('friend_id',0,PARAM_INT); 
    1212 
    1313if (isloggedin()) { 
    14  
    1514    switch($action) { 
    1615 
    1716        // Create a new community 
     
    140139             } 
    141140             break; 
    142141 
     142         case "community:approve:invitation": 
     143         $request_id = optional_param('request_id',0,PARAM_INT); 
     144         if (!empty($request_id) && logged_on && user_type($page_owner) == "person") {  
     145             if ($request = get_record_sql('SELECT u.name, fr.owner, fr.friend FROM '.$CFG->prefix.'friends_requests fr 
     146                                    LEFT JOIN '.$CFG->prefix.'users u ON u.ident = fr.owner  
     147                                    WHERE fr.ident = ?',array($request_id))) { 
     148                 if (run("permissions:check",array("userdetails:change", $page_owner))) { 
     149                     $f = new StdClass; 
     150                     $f->owner = $request->owner; 
     151                     $f->friend = $request->friend; 
     152                     if (insert_record('friends',$f)) { 
     153                         delete_records('friends_requests','ident',$request_id); 
     154                         $messages[] = sprintf(__gettext("You accepted the community invitation. You are now a member of the community %s."),stripslashes($request->name)); 
     155                         $message_body = sprintf(__gettext("%s has approved your community invitation!\n\nRegards,\n\nThe %s team."),user_name($request->friend), $CFG->sitename); 
     156                         $title = __gettext("Community invitation accepted!"); 
     157                         notify_user($request->owner,$title,$message_body); 
     158                     } else { 
     159                         $messages[] = __gettext("An error occurred: couldn't add you as a community member"); 
     160                     } 
     161                 } else { 
     162                     $messages[] = __gettext("Error: you do not have authority to accept this membership invitation."); 
     163                 } 
     164             } else { 
     165                 $messages[] = __gettext("An error occurred: the invitation could not be found."); 
     166             } 
     167              
     168         } 
     169         break; 
     170     case "community:decline:invitation": 
     171         $request_id = optional_param('request_id',0,PARAM_INT); 
     172         if (!empty($request_id) && logged_on && user_type($page_owner) == "person") { 
     173             if ($request = get_record_sql('SELECT u.name, fr.owner, fr.friend FROM '.$CFG->prefix.'friends_requests fr 
     174                                    LEFT JOIN '.$CFG->prefix.'users u ON u.ident = fr.owner  
     175                                    WHERE fr.ident = ?',array($request_id))) { 
     176                 if (run("permissions:check",array("userdetails:change", $page_owner))) { 
     177                     delete_records('friends_requests','ident',$request_id); 
     178                     $messages[] = sprintf(__gettext("You declined the community invitation. You are not a member of community %s."),stripslashes($request->name)); 
     179                     $message_body = sprintf(__gettext("%s has denied your community invitation.\n\nRegards,\n\nThe %s team."),user_name($request->friend), $CFG->sitename); 
     180                     $title = sprintf(__gettext("%s friend request denied"), $CFG->sitename); 
     181                     notify_user($request->owner,$title,$message_body); 
     182                 } else { 
     183                     $messages[] = __gettext("Error: you do not have authority to modify this membership invitation."); 
     184                 } 
     185             } else { 
     186                 $messages[] = __gettext("An error occurred: the invitation could not be found."); 
     187             } 
     188              
     189         } 
     190         break; 
    143191    } 
    144192 
    145193} 
  • htaccess-dist

    old new  
    123123RewriteRule ^([A-Za-z0-9]+)\/community\/leave\/([0-9]+)$ mod/community/index.php?profile_name=$1&friend_id=$2&action=leave 
    124124RewriteRule ^([A-Za-z0-9]+)\/community\/separate\/([0-9]+)$ mod/community/members.php?profile_name=$1&friend_id=$2&action=separate 
    125125RewriteRule ^community\/([0-9]+)\/?$ mod/communities/community.php?community_id=$1 
     126RewriteRule ^([A-Za-z0-9]+)\/community\/invite$ mod/community/invite.php?profile_name=$1 
     127RewriteRule ^([A-Za-z0-9]+)\/communities\/invitations$ mod/community/user_community_invitations.php?profile_name=$1 
    126128 
    127  
    128129# Files 
    129130######## 
    130131RewriteRule ^([A-Za-z0-9]+)\/files\/?$ mod/file/index.php?files_name=$1