/**
  * let the user leave network
  * @access public
  * @param id of the network,uid of user
  * @return flag for joining request moderated or success message
  */
 static function leave($network_id, $uid)
 {
     Logger::log("Enter: static function Network leave");
     //     if (Network::is_mother_network($network_id)) {
     //       throw new PAException(OPERATION_NOT_PERMITTED, "You cant delete mother network.");
     //     }
     if (!Network::member_exists($network_id, $uid)) {
         throw new PAException(OPERATION_NOT_PERMITTED, "You are not member of this network.");
     }
     $user_type = Network::get_user_type($network_id, $uid);
     if ($user_type == NETWORK_OWNER) {
         throw new PAException(OPERATION_NOT_PERMITTED, "You cant leave your own network!!.");
     }
     $res = Dal::query("DELETE FROM {networks_users} WHERE network_id = ? AND user_id = ? ", array($network_id, $uid));
     // delete all user roles for this network
     Roles::delete_user_roles($uid, -1);
     // -1 means: all user roles will be deleted
     // Update cached member count
     Network::update_network_member_count($network_id);
     Logger::log("Exit: static function Network leave");
     return TRUE;
 }
 /**
   Purpose : this function is core funtion of this Navigation class. It is used to make links level_1,level_2,level_3
   Some links need extra parameters
   append them here but first set them in their methods
   e.g.
     public function set_group_id($group_id){
       $this->group_id = $group_id;
     }
     public function get_group_id() {
       return $this->group_id();
     }
   Scope : public
   @param - it needs no direct input
   @return - it sets class variables level_1,level_2,level_3 which can be used further.
   **/
 function make_links()
 {
     $user_id = isset($_SESSION['user']['id']) ? $_SESSION['user']['id'] : 0;
     ////These are level 1 links shown in top navigation bar
     $level_1 = array('home_network' => array('caption' => __('Return to home network'), 'url' => $this->mothership_info['url']));
     // Display network directory, if network operation is enabled.
     if (PA::$network_capable) {
         $level_1['networks_directory'] = array('caption' => __('Network directory'), 'url' => $this->base_url . '/' . FILE_NETWORKS_HOME);
     }
     $owner = Network::is_admin($this->network_info->network_id, $user_id);
     //is_member will be true when user is registered member of the nework.
     $is_member = Network::member_exists($this->network_info->network_id, $this->get_uid());
     if (!$this->is_anonymous && $this->network_info && !$is_member && $this->network_info->type != MOTHER_NETWORK_TYPE) {
         $level_1['join_network'] = array('caption' => __('JOIN Network'), 'url' => $this->base_url . '/' . FILE_NETWORK_ACTION . '?action=join&nid=' . $this->network_info->network_id . '&cid=' . $this->network_info->category_id);
     } else {
         if (!$this->is_anonymous && $is_member && !$owner && $this->network_info->type != MOTHER_NETWORK_TYPE) {
             $level_1['unjoin_network'] = array('caption' => __('Unjoin Network'), 'url' => $this->base_url . '/' . FILE_NETWORK_ACTION . '?action=leave&nid=' . $this->network_info->network_id . '&cid=' . $this->network_info->category_id);
         } else {
             if (Network::is_admin($this->network_info->network_id, (int) $user_id)) {
                 $level_1['configure_network'] = array('caption' => __('Configure'), 'url' => $this->base_url . PA_ROUTE_CONFIGURE_NETWORK);
             }
         }
     }
     if ($this->network_info->type == MOTHER_NETWORK_TYPE) {
         unset($level_1['home_network']);
     }
     if (PA::$config->enable_network_spawning) {
         $level_1['create_network'] = array('caption' => __('Create a network'), 'url' => $this->mothership_info['extra']['links']['create_network']);
     }
     ////END OF These are level 1 links shown in top navigation bar
     ////These are level 2 links shown in second navigation bar
     $level_2 = array('home' => array('caption' => __('Home'), 'url' => $this->base_url . PA_ROUTE_HOME_PAGE), 'user' => array('caption' => __(PA::$mypage_noun), 'url' => $this->base_url . PA_ROUTE_USER_PRIVATE), 'people' => array('caption' => __(PA::$people_noun), 'url' => $this->base_url . PA_ROUTE_PEOPLES_PAGE), 'groups' => array('caption' => __(PA::$group_noun_plural), 'url' => $this->base_url . PA_ROUTE_GROUPS));
     if (!empty(PA::$config->useTypedGroups)) {
         $level_2 = $level_2 + array('directory' => array('caption' => __('Orgs'), 'url' => $this->base_url . PA_ROUTE_TYPED_DIRECTORY));
         if (!empty(PA::$config->simple['use_families'])) {
             $level_2 = $level_2 + array('families' => array('caption' => __('Neighbors'), 'url' => $this->base_url . PA_ROUTE_FAMILY_DIRECTORY));
         }
     }
     $level_2 = $level_2 + array('forum' => array('caption' => __('Forum'), 'url' => $this->base_url . PA_ROUTE_FORUMS . "/network_id=" . $this->network_info->network_id), 'search' => array('caption' => __('Search'), 'url' => $this->base_url . PA_ROUTE_SEARCH_HOME . '/btn_searchContent=Search+Content'));
     ////END OF These are level 2 links shown in second navigation bar
     /// children of user 2nd level link
     $uid = $this->get_uid();
     //we need uid for some links
     $user_children = array();
     $user_children = $user_children + array('user_private' => array('caption' => __('My Page'), 'url' => $this->base_url . PA_ROUTE_USER_PRIVATE));
     $user_children = $user_children + array('user_widgets' => array('caption' => __('My Widgets'), 'url' => $this->base_url . '/' . FILE_WIDGET));
     $user_children = $user_children + array('messages' => array('caption' => __('My Messages'), 'url' => $this->base_url . PA_ROUTE_MYMESSAGE));
     $user_children = $user_children + array('my_gallery' => array('caption' => __('My Gallery'), 'url' => $this->base_url . PA_ROUTE_MEDIA_GALLEY_IMAGES . "/uid={$uid}"));
     $user_children = $user_children + array('my_events' => array('caption' => __('My Events'), 'url' => $this->base_url . '/' . FILE_USER_CALENDAR), 'my_friends' => array('caption' => __('My Friends'), 'url' => $this->base_url . "/view_all_members.php?view_type=in_relations&uid={$uid}"));
     $user_children = $user_children + array('my_forum' => array('caption' => __('My Forum'), 'url' => $this->base_url . PA_ROUTE_FORUMS . "/network_id=" . $this->network_info->network_id . '&user_id=' . $uid));
     $user_children = $user_children + array('my_points' => array('caption' => __('My Points'), 'url' => $this->base_url . PA_ROUTE_POINTS_DIRECTORY . "?uid={$uid}"));
     if (!empty(PA::$config->simple['use_families'])) {
         // get this users Family or Families
         require_once "api/Entity/TypedGroupEntityRelation.php";
         $userfamilyRelations = TypedGroupEntityRelation::get_relation_for_user($uid, 'family');
         if (count($userfamilyRelations) == 1) {
             $user_children = $user_children + array('my_family' => array('caption' => __('My Family'), 'url' => $this->base_url . PA_ROUTE_FAMILY . "?gid=" . $userfamilyRelations[0]->object_id));
         } else {
             $html = "<ul>";
             foreach ($userfamilyRelations as $i => $relation) {
                 $group = ContentCollection::load_collection((int) $relation->object_id, PA::$login_uid);
                 $html .= "<li>";
                 $html .= "<a href=\"" . $this->base_url . PA_ROUTE_FAMILY . "?gid=" . $relation->object_id . "\">" . $group->title . "</a>";
                 $html .= "</li>";
             }
             $html .= "</ul>";
             $user_children = $user_children + array('my_family' => array('caption' => __('My Families'), 'html' => $html));
         }
     }
     // end of !empty(PA::$config->simple['use_families'])
     $user_children = $user_children + array('settings' => array('caption' => __('Edit My Account'), 'url' => $this->base_url . PA_ROUTE_EDIT_PROFILE));
     $user_children = $user_children + array('customize_ui' => array('caption' => __('Themes'), 'url' => $this->base_url . PA_ROUTE_CUSTOMIZE_USER_GUI . "/theme/uid={$uid}"));
     if ($this->is_anonymous) {
         //these links are not for anonymous
         unset($user_children);
     }
     ///END OF children of user 2nd level link
     /// children of people 2nd level link
     //required friend id in some places
     $friend_id = $this->get_friend_uid();
     $people_children = array('find_people' => array('caption' => sprintf(__('Find %s'), __(PA::$people_noun)), 'url' => $this->base_url . PA_ROUTE_PEOPLES_PAGE), 'my_friends' => array('caption' => __('My friends'), 'url' => $this->base_url . '/' . FILE_VIEW_ALL_MEMBERS . '?view_type=relations&amp;uid=' . $uid), 'friends_gallery' => array('caption' => __('Friends gallery'), 'url' => $this->base_url . PA_ROUTE_MEDIA_GALLEY_IMAGES . "/uid={$friend_id}&view=friends"));
     if ($this->is_anonymous) {
         //these links are not for anonymous
         unset($people_children);
     }
     ///EOF children of people 2nd level link
     $family_children = array('neighbors' => array('caption' => __("Neighbors"), 'url' => $this->base_url . PA_ROUTE_FAMILY_DIRECTORY), 'family_home' => array('caption' => __("Family Homepage"), 'url' => $this->base_url . PA_ROUTE_FAMILY . "/gid=" . $this->group_id), 'family_members' => array('caption' => __("Family Members"), 'url' => $this->base_url . PA_ROUTE_FAMILY_MEMBERS . "/gid=" . $this->group_id));
     /// group general children
     //    $users_first_group_id = $this->get_users_first_group_id();
     $groups_general = array('find_groups' => array('caption' => sprintf(__('Find %s'), __(PA::$group_noun_plural)), 'url' => $this->base_url . PA_ROUTE_GROUPS), 'create_group' => array('caption' => __('Create'), 'url' => $this->base_url . '/' . FILE_ADDGROUP), 'invite' => array('caption' => __('Invite'), 'url' => $this->base_url . '/' . FILE_GROUP_INVITATION));
     if ($this->is_anonymous) {
         //these links are not for anonymous
         unset($groups_general['create_group']);
         unset($groups_general['invite']);
         unset($groups_general['group_media_gallery']);
     }
     /// EOF group general children
     ///group specific menu children
     $gid = $group_id = $this->get_group_id();
     $group_specific = array('group_home' => array('caption' => sprintf(__('%s Home'), __(PA::$group_noun)), 'url' => $this->base_url . PA_ROUTE_GROUP . '/gid=' . $group_id), 'group_forum' => array('caption' => sprintf(__('%s Forum'), __(PA::$group_noun)), 'url' => $this->base_url . PA_ROUTE_FORUMS . "/network_id=" . $this->network_info->network_id . '&gid=' . $group_id), 'group_members' => array('caption' => sprintf(__('%s Members'), __(PA::$group_noun)), 'url' => $this->base_url . '/' . FILE_VIEW_ALL_MEMBERS . '?gid=' . $group_id), 'group_gallery' => array('caption' => sprintf(__('%s Gallery'), __(PA::$group_noun)), 'url' => $this->base_url . PA_ROUTE_MEDIA_GALLEY_IMAGES . '/view=groups_media&amp;gid=' . $group_id), 'group_events' => array('caption' => sprintf(__('%s Events'), __(PA::$group_noun)), 'url' => $this->base_url . '/' . FILE_GROUP_CALENDAR . '?gid=' . $group_id));
     $group_member = FALSE;
     $group_may_post = FALSE;
     $group_may_invite = FALSE;
     $group_moderator = FALSE;
     $group_manange_ads = FALSE;
     $group_owner = FALSE;
     if (PA::$login_uid) {
         if (Group::member_exists($gid, PA::$login_uid)) {
             $group_member = TRUE;
             // TODO: split this out to it's own perm check
             $group_may_post = TRUE;
             $group_may_invite = TRUE;
         }
         if (PermissionsHandler::can_group_user(PA::$login_uid, $gid, array('permissions' => 'manage_groups, manage_roles')) || Group::is_admin($gid, PA::$login_uid)) {
             $group_owner = TRUE;
             $group_moderator = TRUE;
         } else {
             if (PermissionsHandler::can_group_user(PA::$login_uid, $gid, array('permissions' => 'manage_groups'))) {
                 $group_moderator = TRUE;
             }
         }
         // network level ad manager?
         $group_manange_ads = PermissionsHandler::can_user(PA::$login_uid, array('permissions' => 'manage_ads'));
         // check for manageads of group permissions
         if (!$group_manange_ads) {
             // we do this check only if the user is not already permitted to manage ads
             $group_manange_ads = PermissionsHandler::can_group_user(PA::$login_uid, $gid, array('permissions' => 'manage_ads'));
         }
         if ($group_may_invite) {
             $group_specific = array('invite' => array('caption' => __("Invite a Friend"), 'url' => PA::$url . PA_ROUTE_GROUP_INVITE . '/gid=' . $gid)) + $group_specific;
         }
         if ($group_may_post) {
             // member get's a 'Create Post' link on top
             $group_specific = array('create_post' => array('caption' => __("Create post"), 'url' => PA::$url . '/post_content.php?ccid=' . $gid)) + $group_specific;
         }
         // admin / owner
         if ($group_owner) {
             $group_specific = $group_specific + array('settings' => array('caption' => __("Group Settings"), 'url' => PA::$url . '/addgroup.php?gid=' . $gid), 'group_poll_select' => array('caption' => sprintf(__('%s Poll Select'), __(PA::$group_noun)), 'url' => $this->base_url . '/group_poll.php?gid=' . $group_id . '&type=select'), 'group_poll_create' => array('caption' => sprintf(__('%s Poll Create'), __(PA::$group_noun)), 'url' => $this->base_url . '/group_poll.php?gid=' . $group_id . '&type=create'));
         }
         // admin / moderator
         if ($group_moderator) {
             $group_specific = $group_specific + array('bulletin' => array('caption' => __("Group Bulletin"), 'url' => PA::$url . PA_ROUTE_GROUP_BULLETINS . '?gid=' . $gid), 'moderate' => array('caption' => __("Moderate"), 'url' => PA::$url . PA_ROUTE_GROUP_MODERATION . '/view=members&amp;gid=' . $gid), 'manage_members' => array('caption' => __("Manage Content"), 'url' => PA::$url . '/manage_group_content.php?gid=' . $gid), 'group_customize_ui' => array('caption' => __('Group Appearance'), 'url' => $this->base_url . PA_ROUTE_CUSTOMIZE_GROUP_GUI . '/theme/gid=' . $group_id));
         }
         // ads
         if ($group_manange_ads) {
             $group_specific = $group_specific + array('ads' => array('caption' => __("Manage Ads"), 'url' => PA::$url . PA_ROUTE_GROUP_AD_CENTER . '?gid=' . $gid));
         }
         // the join/unjoin/delete go last
         if ($group_owner) {
             // only the owner can delete
             $group_specific = $group_specific + array('delete_group' => array('caption' => __('Delete'), 'url' => $this->base_url . PA_ROUTE_GROUP . '/action=delete&amp;gid=' . $group_id, 'extra' => ' onclick ="return delete_confirmation_msg(\'' . __('Are you sure you want to delete this group') . '?\') "'));
         } else {
             // anyone else
             if ($group_member) {
                 $group_specific = $group_specific + array('unjoin' => array('caption' => __('Unjoin'), 'url' => $this->base_url . PA_ROUTE_GROUP . '/gid=' . $group_id . '&amp;action=leave'));
             } else {
                 $group_specific = $group_specific + array('join' => array('caption' => __('Join'), 'url' => $this->base_url . PA_ROUTE_GROUP . '/gid=' . $group_id . '&amp;action=join'));
             }
         }
     }
     ///EOF group specific menu children
     /// children of group
     $groups_children = array('groups_general' => $groups_general, 'group_specific' => $group_specific);
     ///EOF children of group
     //for network option at 3 level
     $network = array('configure_network' => array('caption' => __('Configure'), 'url' => $this->base_url . PA_ROUTE_CONFIGURE_NETWORK)) + $level_2;
     $network_notify = array('email_notification' => array('caption' => __('Email Notification'), 'url' => $this->base_url . '/' . FILE_EMAIL_NOTIFICATION), 'network_bulletins' => array('caption' => __('Bulletins'), 'url' => $this->base_url . '/' . FILE_NETWORK_BULLETINS));
     $network_setting = array('network_feature' => array('caption' => __('Set Feature Network'), 'url' => $this->base_url . '/' . FILE_NETWORK_FEATURE), 'manage_emblem' => array('caption' => __('Manage Emblem'), 'url' => $this->base_url . '/' . FILE_MANAGE_EMBLEM), 'manage_taketour' => array('caption' => __('Personalized Video'), 'url' => $this->base_url . '/' . FILE_MANAGE_TAKETOUR), 'splash_page' => array('caption' => __('Configure Splash Page'), 'url' => $this->base_url . '/' . FILE_CONFIGURE_SPLASH_PAGE), 'top_bar' => array('caption' => __('Top Bar Enable/Disable'), 'url' => '#'));
     $network_default = array('new_user_by_admin' => array('caption' => __('Create User'), 'url' => $this->base_url . '/' . FILE_NEW_USER_BY_ADMIN), 'user_defaults' => array('caption' => __('User Defaults'), 'url' => $this->base_url . '/' . FILE_NETWORK_USER_DEFAULTS), 'relationship_settings' => array('caption' => __('Relationships'), 'url' => $this->base_url . '/' . FILE_RELATIONSHIP_SETTINGS));
     $manage_network = array('manage_user' => array('caption' => __('Manage Users'), 'url' => $this->base_url . '/' . FILE_NETWORK_MANAGE_USER), 'manage_content' => array('caption' => __('Manage Contents'), 'url' => $this->base_url . '/' . FILE_NETWORK_MANAGE_CONTENT), 'manage_links' => array('caption' => __('Manage Links'), 'url' => $this->base_url . '/' . FILE_NETWORK_LINKS));
     $network_stats = array('statistics' => array('caption' => __('General'), 'url' => $this->base_url . PA_ROUTE_CONFIGURE_NETWORK), 'customize_ui' => array('caption' => __('Customize UI'), 'url' => $this->base_url . '/' . FILE_NETWORK_CUSTOMIZE_UI_PAGE));
     $network_module_selector = array('home_page_id' => array('caption' => __('Home Page'), 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=home_page_id'), 'user_default_page_id' => array('caption' => __('User Default Page'), 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=user_default_page_id'), 'group_directory_page_id' => array('caption' => __('Group Directory Page'), 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=group_directory_page_id'), 'network_directory_page_id' => array('caption' => __('Network Directory Page'), 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=network_directory_page_id'));
     if ($this->network_info->type != MOTHER_NETWORK_TYPE) {
         unset($network['meta_network']);
     }
     if ($this->network_info->type != MOTHER_NETWORK_TYPE) {
         unset($network['manage_taketour']);
         unset($network['manage_emblem']);
     }
     //end
     /// second level menu for network
     $level_3 = array('user' => @$user_children, 'people' => @$people_children, 'family' => @$family_children, 'groups' => $groups_children, 'network' => $network, 'network_notify' => $network_notify, 'network_module_selector' => $network_module_selector, 'network_setting' => $network_setting, 'network_default' => $network_default, 'manage_network' => $manage_network, 'network_stats' => $network_stats);
     ///EOF second level menu children
     ///set level menu items
     $this->level_1 = $level_1;
     $this->level_2 = $level_2;
     $this->level_3 = $level_3;
 }
* [description including history]
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* @author [creator, or "Original Author"]
* @license http://bit.ly/aVWqRV PayAsYouGo License
* @copyright Copyright (c) 2010 Broadband Mechanics
* @package PeopleAggregator
*/
$login_required = FALSE;
include_once "web/includes/page.php";
//require_once "web/includes/functions/auto_email_notify.php";
require_once "api/Messaging/MessageDispatcher.class.php";
require_once "api/Roles/Roles.php";
if ($_GET['action'] == 'join') {
    $nid = (int) $_GET['nid'];
    // here we check that user is already join or not
    if ($_SESSION['user']['id'] && Network::member_exists($nid, $_SESSION['user']['id'])) {
        $redirect_url = "http://" . PA::$network_info->address . "." . PA::$domain_suffix . BASE_URL_REL . PA_ROUTE_HOME_PAGE . "/msg=7021";
        header("Location:{$redirect_url}");
        exit;
    }
    $error = 0;
    if (!$nid) {
        $error = 1;
    }
    if ($_SESSION['user']['id']) {
        try {
            $suc = Network::join($nid, $_SESSION['user']['id']);
            if ($suc) {
                // adding default relation
                if ($_SESSION['user']['id'] != SUPER_USER_ID) {
                    uihelper_add_default_relation($_SESSION['user']['id']);
            $invitation_id = $_GET['InvID'];
            try {
                $new_invite = new Invitation();
                $new_invite->inv_id = $invitation_id;
                $new_invite->inv_user_id = $_SESSION['user']['id'];
                $new_invite->accept();
                $inv_obj = Invitation::load($invitation_id);
                $user_obj = new User();
                $user_obj->load((int) $inv_obj->user_id);
                $user_accepting_inv_obj = new User();
                $user_accepting_inv_obj->load((int) $_SESSION['user']['id']);
                $relation_type_id = Relation::get_relation((int) $inv_obj->user_id, (int) $user_accepting_inv_obj->user_id, PA::$network_info->network_id);
                $relation_type = Relation::lookup_relation_type($relation_type_id);
                $new_invite->inv_relation_type = $relation_type;
                PANotify::send("invitation_accept", $user_obj, $user_accepting_inv_obj, $new_invite);
                if (!Network::member_exists(PA::$network_info->network_id, (int) $_SESSION['user']['id'])) {
                    Network::join(PA::$network_info->network_id, $_SESSION['user']['id']);
                    PANotify::send("network_join", PA::$network_info, $user_accepting_inv_obj, array());
                }
                header("Location: " . PA::$url . PA_ROUTE_USER_PRIVATE . '/' . "msg_id=7016");
                exit;
            } catch (CNException $e) {
                $msg = $e->message;
            }
        }
    } else {
        $msg = $token_arr[0] == FALSE ? $token_arr[1] : 7018;
        header("Location: " . PA_ROUTE_HOME_PAGE . "/msg={$msg}");
        exit;
    }
}
 $found = array();
 $found_name = array();
 $user_names = explode(",", $_POST['user_friends']);
 foreach ($user_names as $name) {
     $n = trim($name);
     if (!empty($n)) {
         if (!in_array($n, $found_name)) {
             //check for repeated login names
             try {
                 $related_user_id_array = User::map_logins_to_ids($n);
                 //getting login_name=>user_id array
                 foreach ($related_user_id_array as $key => $values) {
                     $related_user_id = $values;
                     //getting user_id
                 }
                 if (Network::member_exists((int) PA::$network_info->network_id, (int) $related_user_id)) {
                     //if user_id exist for this network
                     $found[] = (int) $related_user_id;
                     $found_name[] = $n;
                 } else {
                     $not_found[] = $n;
                 }
             } catch (CNException $e) {
                 $not_found[] = $n;
             }
         }
     }
 }
 if (sizeof($found)) {
     $related = implode(",", $found_name);
 }
/**
 * @author   Z.Hron
 * @name     delete_users
 * @brief    This function delete array of users
 * @return   array of error messages
 *
 *
 */
function delete_users($params, $true_delete = FALSE)
{
    $message_array = array();
    $user_id_array = $params['user_id_array'];
    foreach ($user_id_array as $user_id) {
        if (PA::$network_info->type == MOTHER_NETWORK_TYPE) {
            if (!Network::member_exists(PA::$network_info->network_id, (int) $user_id)) {
                $message_array[] = "UserID {$user_id} does not exists.";
                continue;
            }
            //deleting user data from mothership
            try {
                User::delete_user($user_id);
                Activities::delete_for_user($user_id);
            } catch (CNException $e) {
                $message_array[] = $e->message;
            }
            $user_networks = Network::get_user_networks($user_id);
            if (count($user_networks)) {
                foreach ($user_networks as $network) {
                    if ($network->user_type != NETWORK_OWNER) {
                        $network_prefix = $network->address;
                        try {
                            User::delete_user($user_id);
                            Activities::delete_for_user($user_id);
                            Network::leave($network->network_id, $user_id);
                            //leave
                        } catch (CNException $e) {
                            $message_array[] = $e->message;
                        }
                    } else {
                        try {
                            Network::delete($network->network_id);
                        } catch (CNException $e) {
                            $message_array[] = $e->message;
                        }
                    }
                }
            }
            //deleting user
            try {
                User::delete($user_id, $true_delete);
            } catch (CNException $e) {
                Logger::log('User has been already deleted');
            }
        } else {
            //user delete for network owner
            if (!Network::member_exists(PA::$network_info->network_id, (int) $user_id)) {
                $message_array[] = "UserID {$user_id} does not exists.";
                continue;
            }
            $network_prefix = PA::$network_info->address;
            try {
                User::delete_user($user_id);
                Activities::delete_for_user($user_id);
                Network::leave(PA::$network_info->network_id, $user_id);
                //network leave
            } catch (CNException $e) {
                $message_array[] = $e->message;
            }
        }
    }
    return $message_array;
}
示例#7
0
 /**
   Purpose : this function is core funtion of this Navigation class. It is used to make links level_1,level_2,level_3
   Some links need extra parameters
   append them here but first set them in their methods
   e.g.
     public function set_group_id($group_id){
       $this->group_id = $group_id;
     }
     public function get_group_id() {
       return $this->group_id();
     }
   Scope : public
   @param - it needs no direct input
   @return - it sets class variables level_1,level_2,level_3 which can be used further.
   **/
 function make_links()
 {
     global $_PA;
     ////These are level 1 links shown in top navigation bar
     $level_1 = array('home_network' => array('caption' => __('Return to home network'), 'url' => $this->mothership_info['url']));
     // Display network directory, if network operation is enabled.
     if (PA::$network_capable) {
         $level_1['networks_directory'] = array('caption' => __('Network directory'), 'url' => $this->base_url . '/' . FILE_NETWORKS_HOME);
     }
     $owner = Network::is_admin($this->network_info->network_id, @$_SESSION['user']['id']);
     //is_member will be true when user is registered member of the nework.
     $is_member = Network::member_exists($this->network_info->network_id, $this->get_uid());
     if (!$this->is_anonymous && $this->network_info && !$is_member && $this->network_info->type != MOTHER_NETWORK_TYPE) {
         $level_1['join_network'] = array('caption' => 'JOIN Network', 'url' => $this->base_url . '/' . FILE_NETWORK_ACTION . '?action=join&amp;nid=' . $this->network_info->network_id . '&amp;cid=' . $this->network_info->category_id);
     } else {
         if (!$this->is_anonymous && $is_member && !$owner && $this->network_info->type != MOTHER_NETWORK_TYPE) {
             $level_1['unjoin_network'] = array('caption' => 'Unjoin Network', 'url' => $this->base_url . '/' . FILE_NETWORK_ACTION . '?action=leave&amp;nid=' . $this->network_info->network_id . '&amp;cid=' . $this->network_info->category_id);
         } else {
             if (Network::is_admin($this->network_info->network_id, (int) @$_SESSION['user']['id'])) {
                 $level_1['configure_network'] = array('caption' => __('Configure'), 'url' => $this->base_url . '/' . FILE_NETWORK_STATS);
             }
         }
     }
     if ($this->network_info->type == MOTHER_NETWORK_TYPE) {
         unset($level_1['home_network']);
     }
     if ($_PA->enable_network_spawning) {
         $level_1['create_network'] = array('caption' => __('Create a network'), 'url' => $this->mothership_info['extra']['links']['create_network']);
     }
     ////END OF These are level 1 links shown in top navigation bar
     ////These are level 2 links shown in second navigation bar
     $level_2 = array('home' => array('caption' => __('Home'), 'url' => $this->base_url . '/' . FILE_HOMEPAGE), 'user' => array('caption' => __('Me'), 'url' => $this->base_url . '/' . FILE_USER), 'people' => array('caption' => __('People'), 'url' => $this->base_url . '/' . FILE_PEOPLES), 'groups' => array('caption' => __('Groups'), 'url' => $this->base_url . '/' . FILE_GROUPS_HOME), 'search' => array('caption' => __('Search'), 'url' => $this->base_url . '/' . FILE_SEARCH_HOME . '?btn_searchContent=Search+Content'));
     ////END OF These are level 2 links shown in second navigation bar
     /// children of user 2nd level link
     $uid = $this->get_uid();
     //we need uid for some links
     $user_children = array('user_private' => array('caption' => __('My Page'), 'url' => $this->base_url . '/' . FILE_USER), 'user_widgets' => array('caption' => __('My Widgets'), 'url' => $this->base_url . '/' . FILE_WIDGET), 'messages' => array('caption' => __('My Messages'), 'url' => $this->base_url . '/' . FILE_MYMESSAGE), 'my_gallery' => array('caption' => __('My Gallery'), 'url' => $this->base_url . '/' . FILE_MEDIA_GALLERY), 'my_events' => array('caption' => __('My Events'), 'url' => $this->base_url . '/' . FILE_USER_CALENDAR), 'settings' => array('caption' => __('Edit My Account'), 'url' => $this->base_url . '/' . FILE_EDIT_PROFILE), 'customize_ui' => array('caption' => __('Themes'), 'url' => $this->base_url . '/' . FILE_CUSTOMIZE_UI));
     if ($this->is_anonymous) {
         //these links are not for anonymous
         unset($user_children);
     }
     ///END OF children of user 2nd level link
     /// children of people 2nd level link
     //required friend id in some places
     $friend_id = $this->get_friend_uid();
     $people_children = array('find_people' => array('caption' => 'Find people', 'url' => $this->base_url . '/' . FILE_PEOPLES), 'my_friends' => array('caption' => 'My friends', 'url' => $this->base_url . '/' . FILE_VIEW_ALL_MEMBERS . '?view_type=relations&amp;uid=' . $uid), 'people_who_call_me_friend' => array('caption' => 'People who call me friend', 'url' => $this->base_url . '/' . FILE_VIEW_ALL_MEMBERS . '?view_type=in_relations&amp;uid=' . $uid), 'friends_gallery' => array('caption' => 'Friends gallery', 'url' => $this->base_url . '/' . FILE_MEDIA_GALLERY . '?view=friends&amp;uid=' . $friend_id));
     if ($this->is_anonymous) {
         //these links are not for anonymous
         unset($people_children);
     }
     ///EOF children of people 2nd level link
     /// group general children
     //    $users_first_group_id = $this->get_users_first_group_id();
     $groups_general = array('find_groups' => array('caption' => 'Find groups', 'url' => $this->base_url . '/' . FILE_GROUPS_HOME), 'create_group' => array('caption' => 'Create', 'url' => $this->base_url . '/' . FILE_ADDGROUP), 'invite' => array('caption' => 'Invite', 'url' => $this->base_url . '/' . FILE_GROUP_INVITATION));
     /*    if ($users_first_group_id) {
     	$groups_general['group_media_gallery'] = array(
     	    'caption'=>'Groups gallery',
     	    'url'=>$this->base_url.'/'.FILE_GROUP_MEDIA_GALLERY.'?view=groups_media&amp;gid='.$users_first_group_id
     	    );
         }*/
     if ($this->is_anonymous) {
         //these links are not for anonymous
         unset($groups_general['create_group']);
         unset($groups_general['invite']);
         unset($groups_general['group_media_gallery']);
     }
     /// EOF group general children
     ///group specific menu children
     $group_id = $this->get_group_id();
     $group_specific = array('group_home' => array('caption' => 'Group Home', 'url' => $this->base_url . '/' . FILE_GROUP . '?gid=' . $group_id), 'group_forum' => array('caption' => 'Forum', 'url' => $this->base_url . '/' . FILE_FORUM_HOME . '?gid=' . $group_id), 'group_members' => array('caption' => 'Members', 'url' => $this->base_url . '/' . FILE_VIEW_ALL_MEMBERS . '?gid=' . $group_id), 'group_gallery' => array('caption' => 'Group gallery', 'url' => $this->base_url . '/' . FILE_GROUP_MEDIA_GALLERY . '?view=groups_media&amp;gid=' . $group_id), 'group_events' => array('caption' => 'Group Events', 'url' => $this->base_url . '/' . FILE_GROUP_CALENDAR . '?gid=' . $group_id), 'join' => array('caption' => 'Join', 'url' => $this->base_url . '/' . FILE_GROUP . '?gid=' . $group_id . '&amp;action=join'), 'unjoin' => array('caption' => 'Unjoin', 'url' => $this->base_url . '/' . FILE_GROUP . '?gid=' . $group_id . '&amp;action=leave'), 'delete_group' => array('caption' => 'Delete', 'url' => $this->base_url . '/' . FILE_GROUP . '?action=delete&amp;gid=' . $group_id, 'extra' => ' onclick ="return delete_confirmation_msg(\'Are you sure you want to delete this group?\') "'), 'group_customize_ui' => array('caption' => 'Themes', 'url' => $this->base_url . '/' . FILE_CUSTOMIZE_GROUP . '?gid=' . $group_id));
     /// group links are having some more complicated logic
     // following links are not visible to anonymous
     if ($this->is_anonymous) {
         unset($group_specific['create_group']);
         unset($group_specific['join']);
         unset($group_specific['unjoin']);
         unset($group_specific['edit_group']);
         unset($group_specific['invite']);
         unset($group_specific['delete_group']);
         unset($group_specific['moderate_group']);
         unset($group_specific['group_customize_ui']);
     } else {
         if (!empty($group_id) && !Group::is_admin($group_id, $_SESSION['user']['id'])) {
             unset($group_specific['edit_group']);
             unset($group_specific['delete_group']);
             unset($group_specific['moderate_group']);
             if (Group::member_exists($group_id, $_SESSION['user']['id']) == TRUE) {
                 unset($group_specific['join']);
             } else {
                 if (Group::member_exists($group_id, $_SESSION['user']['id']) == FALSE) {
                     unset($group_specific['unjoin']);
                 }
             }
             unset($group_specific['group_customize_ui']);
         } else {
             if (!empty($group_id) && Group::is_admin($group_id, $_SESSION['user']['id'])) {
                 unset($group_specific['join']);
                 unset($group_specific['unjoin']);
             }
         }
     }
     ///EOF group specific menu children
     /// children of group
     $groups_children = array('groups_general' => $groups_general, 'group_specific' => $group_specific);
     ///EOF children of group
     //for network option at 3 level
     $network = array('configure_network' => array('caption' => 'Configure', 'url' => $this->base_url . '/' . FILE_NETWORK_STATS), 'home' => array('caption' => 'Home', 'url' => $this->base_url . '/' . FILE_HOMEPAGE), 'user' => array('caption' => 'Me', 'url' => $this->base_url . '/' . FILE_USER), 'people' => array('caption' => 'People', 'url' => $this->base_url . '/' . FILE_PEOPLES), 'groups' => array('caption' => 'Groups', 'url' => $this->base_url . '/' . FILE_GROUPS_HOME), 'search' => array('caption' => 'Search', 'url' => $this->base_url . '/' . FILE_SEARCH_HOME . '?btn_searchContent=Search+Content'));
     //     'home' => array('caption'=>'Home',
     //                                   'url'=>$this->base_url.'/'.FILE_HOMEPAGE
     //                                   ),
     //                       'statistics' => array('caption'=>'Setting',
     //                                   'url'=>$this->base_url.'/'.FILE_NETWORK_STATS
     //                                   ),
     //                       'manage_user' => array('caption'=>'Manage',
     //                                   'url'=>$this->base_url.'/'.FILE_NETWORK_MANAGE_USER
     //                                   ),
     //                        'user_defaults' => array('caption'=>'Defaults',
     //                                   'url'=>$this->base_url.'/'.FILE_NEW_USER_BY_ADMIN
     //                                   ),
     //                        'email_notification' => array('caption'=>'Notify',
     //                                   'url'=>$this->base_url.'/'.FILE_EMAIL_NOTIFICATION
     //                                   ),
     //                       'meta_network' => array('caption'=>'Meta Network',
     //                                   'url'=>$this->base_url.'/'.FILE_NETWORK_FEATURE
     //                                   ),
     //                       'module_selector' => array('caption'=>'Module Selector',
     //                                                  'url'=>$this->base_url.'/'
     //                                                  .FILE_MODULE_SELECTOR.
     //                                                  '?page_id=home_page_id'
     //                                                  ),
     // 			     );
     $network_notify = array('email_notification' => array('caption' => 'Email Notification', 'url' => $this->base_url . '/' . FILE_EMAIL_NOTIFICATION), 'network_bulletins' => array('caption' => 'Bulletins', 'url' => $this->base_url . '/' . FILE_NETWORK_BULLETINS));
     $network_setting = array('network_feature' => array('caption' => 'Set Feature Network', 'url' => $this->base_url . '/' . FILE_NETWORK_FEATURE), 'manage_emblem' => array('caption' => 'Manage Emblem', 'url' => $this->base_url . '/' . FILE_MANAGE_EMBLEM), 'manage_taketour' => array('caption' => 'Personalized Video', 'url' => $this->base_url . '/' . FILE_MANAGE_TAKETOUR), 'splash_page' => array('caption' => 'Configure Splash Page', 'url' => $this->base_url . '/' . FILE_CONFIGURE_SPLASH_PAGE), 'top_bar' => array('caption' => 'Top Bar Enable/Disable', 'url' => '#'));
     $network_default = array('new_user_by_admin' => array('caption' => 'Create User', 'url' => $this->base_url . '/' . FILE_NEW_USER_BY_ADMIN), 'user_defaults' => array('caption' => 'User Defaults', 'url' => $this->base_url . '/' . FILE_NETWORK_USER_DEFAULTS), 'relationship_settings' => array('caption' => 'Relationships', 'url' => $this->base_url . '/' . FILE_RELATIONSHIP_SETTINGS));
     $manage_network = array('manage_user' => array('caption' => 'Manage Users', 'url' => $this->base_url . '/' . FILE_NETWORK_MANAGE_USER), 'manage_content' => array('caption' => 'Manage Contents', 'url' => $this->base_url . '/' . FILE_NETWORK_MANAGE_CONTENT), 'manage_links' => array('caption' => 'Manage Links', 'url' => $this->base_url . '/' . FILE_NETWORK_LINKS));
     $network_stats = array('statistics' => array('caption' => 'General', 'url' => $this->base_url . '/' . FILE_NETWORK_STATS), 'customize_ui' => array('caption' => 'Customize Ui', 'url' => $this->base_url . '/' . FILE_NETWORK_CUSTOMIZE_UI_PAGE));
     $network_module_selector = array('home_page_id' => array('caption' => 'Home Page', 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=home_page_id'), 'user_default_page_id' => array('caption' => 'User Default Page', 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=user_default_page_id'), 'group_directory_page_id' => array('caption' => 'Group Directory Page', 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=group_directory_page_id'), 'network_directory_page_id' => array('caption' => 'Network Directory Page', 'url' => $this->base_url . '/' . FILE_MODULE_SELECTOR . '?page_id=network_directory_page_id'));
     if ($this->network_info->type != MOTHER_NETWORK_TYPE) {
         unset($network['meta_network']);
     }
     if ($this->network_info->type != MOTHER_NETWORK_TYPE) {
         unset($network['manage_taketour']);
         unset($network['manage_emblem']);
     }
     //end
     /// second level menu for network
     $level_3 = array('user' => @$user_children, 'people' => @$people_children, 'groups' => $groups_children, 'network' => $network, 'network_notify' => $network_notify, 'network_module_selector' => $network_module_selector, 'network_setting' => $network_setting, 'network_default' => $network_default, 'manage_network' => $manage_network, 'network_stats' => $network_stats);
     ///EOF second level menu children
     ///set level menu items
     $this->level_1 = $level_1;
     $this->level_2 = $level_2;
     $this->level_3 = $level_3;
 }
 private function checkUser($request_data)
 {
     $this->login_user = PA::$login_user;
     if (PA::$login_uid && is_object($this->board)) {
         $member = null;
         $members = PaForumsUsers::listPaForumsUsers("user_id = " . PA::$login_uid . " AND board_id = " . $this->board->get_id());
         if (isset($members[0])) {
             $member = $members[0];
         }
         if ($member) {
             // check is user a member
             $this->forum_user = $member;
             $user_status = $this->forum_user->get_user_status();
             $this->shared_data['board_member'] = $this->forum_user;
         } else {
             // logged user but not member of this board!
             $is_member = false;
             switch ($this->board_type) {
                 case PaForumBoard::network_board:
                     $is_member = Network::member_exists($this->shared_data['network_id'], PA::$login_uid);
                     break;
                 case PaForumBoard::group_board:
                     $is_member = Group::member_exists($this->gid, PA::$login_uid);
                     break;
                 case PaForumBoard::personal_board:
                     $is_member = false;
                     break;
                 default:
                     $is_member = false;
             }
             if ($is_member) {
                 $user_status = PaForumsUsers::_allowed;
                 try {
                     $params = array("user_id" => PA::$login_uid, "board_id" => $this->board->get_id(), "user_status" => $user_status, "is_active" => 1, "date_join" => date("Y-m-d H:i:s"));
                     PaForumsUsers::insertPaForumsUsers($params);
                     $members = PaForumsUsers::listPaForumsUsers("user_id = " . PA::$login_uid . " AND board_id = " . $this->board->get_id());
                     if (isset($members[0])) {
                         $this->forum_user = $members[0];
                     }
                 } catch (Exception $e) {
                     $error_msg = "Exception in ForumModule, function checkUser();<br />Message: " . $e->getMessage();
                 }
             } else {
                 $user_status = PaForumsUsers::_notmember | PaForumsUsers::_anonymous;
                 $this->forum_user = null;
             }
         }
         $params = array('permissions' => 'manage_forum', 'board' => $this->board, 'gid' => !empty($this->gid) ? $this->gid : null);
         if (PermissionsHandler::can_user(PA::$login_uid, $params)) {
             $user_status = $user_status | PaForumsUsers::_admin;
         }
         if ($user_status & PaForumsUsers::_banned) {
             $board = $this->getDefaultBoard($request_data, false);
             $this->setupBoard($board);
             $user = new User();
             $user->load((int) $this->forum_user->get_user_id());
             $this->title = __('Banned User');
             $this->set_inner_template('cnmodule_content_banned_user.php');
             $this->inner_HTML = $this->generate_inner_html(array('page_id' => $this->page_id, 'forum_user' => $user, 'user_status' => $user_status, 'board_settings' => $this->board_settings));
             return false;
         }
     } else {
         $this->forum_user = null;
         $user_status = PaForumsUsers::_anonymous;
     }
     return $user_status;
 }
 // creating message basic folders
 Message::create_basic_folders($newuser->user_id);
 // adding default relation
 if ($newuser->user_id != SUPER_USER_ID) {
     User_Registration::add_default_relation($newuser->user_id, PA::$network_info);
 }
 // adding default media as well as album
 User_Registration::add_default_media($newuser->user_id, '', PA::$network_info);
 User_Registration::add_default_media($newuser->user_id, '_audio', PA::$network_info);
 User_Registration::add_default_media($newuser->user_id, '_video', PA::$network_info);
 User_Registration::add_default_blog($newuser->user_id);
 //adding default link categories & links
 User_Registration::add_default_links($newuser->user_id);
 // Making user member of a network if he is registering to PA from a network
 if (!empty(PA::$network_info)) {
     if (!Network::member_exists(PA::$network_info->network_id, $newuser->user_id)) {
         // check is waiting member
         Network::join(PA::$network_info->network_id, $newuser->user_id);
         // no - join to network
     } else {
         Network::approve(PA::$network_info->network_id, $newuser->user_id);
         // yes - approve membership
     }
 }
 // register session
 register_session($newuser->login_name, $newuser->user_id, $newuser->role, $newuser->first_name, $newuser->last_name, $newuser->email, $newuser->picture);
 PA::$login_user = $newuser;
 PA::$login_uid = $newuser->user_id;
 // send welcome message
 PAMail::send("welcome_message", $newuser, PA::$network_info, array());
 if (!empty($_GET['InvID'])) {
 $user_accepting_inv_obj->load((int) $u);
 try {
     // check token before accepting invitation
     $new_invite = new Invitation();
     $new_invite->inv_id = $invitation_id;
     $new_invite->inv_user_id = $u;
     $new_invite->accept();
     $inv_obj = Invitation::load($invitation_id);
     $user_obj = new User();
     $user_obj->load((int) $inv_obj->user_id);
     $relation_type_id = Relation::get_relation((int) $inv_obj->user_id, (int) $user_accepting_inv_obj->user_id, PA::$network_info->network_id);
     $relation_type = Relation::lookup_relation_type($relation_type_id);
     $new_invite->inv_relation_type = $relation_type;
     PANotify::send("invitation_accept", $user_obj, $user_accepting_inv_obj, $new_invite);
     if (!empty(PA::$network_info) && PA::$network_info->type != MOTHER_NETWORK_TYPE) {
         if (!Network::member_exists(PA::$network_info->network_id, $u)) {
             if (PA::$network_info->type == PRIVATE_NETWORK_TYPE && $inv_obj->user_id == PA::$network_info->owner_id) {
                 $user_type = NETWORK_MEMBER;
             }
             Network::join(PA::$network_info->network_id, $u, $user_type);
             PANotify::send("network_join", PA::$network_info, $user_accepting_inv_obj, array());
         }
     }
 } catch (CNException $e) {
     $msg = "{$e->message}";
     $error_inv = TRUE;
 }
 if ($error_inv == TRUE) {
     // if error occured
     $location = CNUrlHelper::url_for(PA::$url . '/cnuser_login.php', array('msg' => $msg, 'return' => $return_url), 'https');
     header("Location: {$location}");
示例#11
0
$login_required = FALSE;
$use_theme = 'Beta';
include "includes/page.php";
require_once "{$path_prefix}/api/User/User.php";
require_once "{$path_prefix}/api/Relation/Relation.php";
require_once "{$path_prefix}/api/Testimonials/Testimonials.php";
require_once "{$path_prefix}/api/ExternalFeed/ExternalFeed.php";
require_once "{$path_prefix}/ext/UserProfileFeed/UserProfileFeed.php";
require_once "./includes/classes/file_uploader.php";
require_once "user_page_functions.php";
// user_blog.php requires a user ID to be specified - so give a 404 page if no user is specified
if (empty(PA::$page_user)) {
    header("HTTP/1.0 404 Not Found");
    throw new PAException(INVALID_ID, "No user ID specified.");
}
if ($network_info->type != MOTHER_NETWORK_TYPE && !Network::member_exists($network_info->network_id, $page_user->user_id)) {
    if (PA::$page_uid != PA::$login_uid) {
        throw new PAException(NON_MEMBER_ACCESS_TO_NETWORK, "{$page_user->login_name} is not a member of {$network_info->name} network");
    } else {
        throw new PAException(NON_MEMBER_ACCESS_TO_NETWORK, "you are not a member of {$network_info->name} network");
    }
}
// save view counts for this profile
if (PA::$page_uid != PA::$login_uid) {
    // if current blog is not user's blog
    // FIXME: this will be incredibly slow as implemented.  We should
    // have some sort of 'counters' table which we can increment easily.
    // The following should do it: --Phil
    //Counters::increment(PA::$page_uid, "profile_view"); // # of times PA::$page_user's profile has been viewed
    //if (!empty(PA::$login_uid)) {
    //  Counters::increment(PA::$page_uid, "profile_view_login"); // # of times PA::$page_user's profile has been viewed by logged-in users