Exemplo n.º 1
0
    $msg = "ERROR: User not logged in.";
    echo $msg;
    Logger::log($msg . " in  " . __FILE__);
    exit;
}
if (isset($_POST['del'])) {
    try {
        Relation::delete_relation($uid, '-1', $_POST['network_uid'], $_POST['network']);
    } catch (PAException $e) {
        $msg = "ERROR: There was a problem with deleting the relation<br>" . $e->getMessage();
        echo $msg;
        Logger::log($msg . " in " . __FILE__);
        exit;
    }
    // if we get here, all is ok
    echo '<a href="javascript://" onclick="addrelation(this);">add to Widget</a>';
} else {
    // try and add the relation
    try {
        Relation::add_relation($uid, -1, 2, $_POST['network'], $_POST['network_uid'], $_POST['display_name'], $_POST['thumbnail_url'], $_POST['profile_url']);
    } catch (PAException $e) {
        $msg = "ERROR: There was a problem with adding the relation<br>" . $e->getMessage();
        echo $msg;
        Logger::log($msg . " in " . __FILE__);
        exit;
    }
    // if we get here, all is ok
    echo '<a href="javascript://" onclick="removerelation(this);">remove from Widget</a>';
}
// default output for debug
echo "<!-- " . print_r($_POST, true) . " -->";
Exemplo n.º 2
0
 public function saveProfile($extraSection = NULL)
 {
     // here is where we actually write the data to DB
     Logger::log("Enter: Merger::saveProfile()");
     // we save the DIFF
     $dp = $this->diffProfileSXML;
     // get the core profile fields:
     $core = $dp->xpath("//field[@section='core']");
     foreach ($core as $c) {
         if (in_array($c['name'], $this->coreFields)) {
             $this->user->{$c['name']} = (string) $c['value'];
         }
     }
     // save the core profile
     try {
         $this->user->save();
     } catch (PAException $e) {
         // we stop processing here
         return $e->message;
     }
     // add in the extra section (new)
     $sections = $this->userSections;
     if ($extraSection) {
         $sections[$extraSection] = $extraSection;
     }
     // save the extended profile sections
     foreach ($sections as $sec => $type) {
         $data = $dp->xpath("//field[@section='{$sec}']");
         if (count($data)) {
             $this->save_ext_profile($data, $type);
         }
     }
     // code to save/update relations
     // delete all external relations for this section (=network)
     Relation::delete_relations_of_network($this->user->user_id, $extraSection);
     // add those that are in the profileDiff
     foreach ($dp->xpath("//relation[@network='{$extraSection}']") as $r) {
         // save this relation to the DB
         Relation::add_relation($this->user->user_id, -1, 2, $extraSection, $r['network_uid'], $r['display_name'], $r['thumbnail_url'], $r['profile_url']);
     }
     Logger::log("Exit: Merger::saveProfile()");
 }
 /**
  * accept the invitation
  * @access public
  * @param int $inv_id invitation ID
  */
 public function accept()
 {
     Logger::log("Enter: Invitation::accept()");
     $is_valid = Invitation::validate_invitation_id($this->inv_id);
     if ($is_valid == FALSE) {
         Logger::log("Throwing exception INVALID_ID ", LOGGER_ERROR);
         throw new PAException(INVALID_ID, "You cannot reuse the Invitation link.");
     } else {
         $res = Dal::query("UPDATE {invitations} SET inv_status = ?, inv_user_id = ? WHERE inv_id = ?", array(INVITATION_ACCEPTED, $this->inv_user_id, $this->inv_id));
         $res = Dal::query("SELECT user_id, inv_collection_id, inv_user_id FROM {invitations} WHERE inv_id=?", array($this->inv_id));
         if ($res->numRows()) {
             $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
             $this->user_id = $row->user_id;
             $u = new User();
             $u->load((int) $row->user_id);
             $user = new User();
             $user->load((int) $this->inv_user_id);
             if ($row->inv_collection_id == -1) {
                 // add as a friend in invitation sender user list
                 Relation::add_relation($u->user_id, $user->user_id, 2, PA::$network_info->address, PA::$network_info->network_id);
                 // add as a friend and send mail
                 Relation::add_relation($user->user_id, $u->user_id, 2, PA::$network_info->address, PA::$network_info->network_id);
             }
         }
     }
     Logger::log("Exit: Invitation::accept()");
 }
 public static function add_default_relation($user_id, $network_info)
 {
     $extra = unserialize($network_info->extra);
     $relations_name = $extra['user_defaults']['user_friends'];
     if ($relations_name != '') {
         $relations = explode(',', $relations_name);
         $relations_ids = User::map_logins_to_ids($relations);
         $selected = DEFAULT_RELATIONSHIP_TYPE;
         //  2 for friends
         foreach ($relations_ids as $key => $value) {
             if (!Relation::relation_exists($user_id, (int) $value)) {
                 Relation::add_relation($user_id, (int) $value, $selected, PA::$network_info->address, PA::$network_info->network_id);
             }
         }
     }
 }
function peopleaggregator_editUserRelation($args)
{
    $token = $args['authToken'];
    $dest_login = $args['login'];
    $rel_type_id = Relation::lookup_relation_type_id($args['relation']);
    $user = User::from_auth_token($token);
    $dest_user = new User();
    $dest_user->load($dest_login);
    // make sure there is a relation, and fail if not
    Relation::get_relation($user->user_id, $dest_user->user_id);
    // now make the change
    Relation::add_relation($user->user_id, $dest_user->user_id, $rel_type_id);
    return array('success' => TRUE, 'msg' => 'Edited relation');
}
    $header_tpl = 'header_group.php';
}
if (@$_POST['btn_approve']) {
    $user_id = (int) $_POST['related_id'];
    $relation_id = (int) $_GET['uid'];
    $status = APPROVED;
    try {
        $result = Relation::update_relation_status($user_id, $relation_id, $status, PA::$network_info->network_id);
        if ($result) {
            // if relationship has been made then send mail to the requestor
            $recip_obj = new User();
            $recip_obj->load((int) $relation_id);
            $relation_obj = Relation::getRelationData($user_id, $relation_id, PA::$network_info->network_id);
            PANotify::send("friend_request_approved", $recip_obj, PA::$network_info, $relation_obj);
            if (PA::$extra['reciprocated_relationship'] == NET_YES) {
                Relation::add_relation($relation_id, $user_id, DEFAULT_RELATIONSHIP_TYPE, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                PANotify::send("reciprocated_relation_estab", PA::$network_info, PA::$login_user, $relation_obj);
                // recipient is network owner
            }
        }
    } catch (CNException $e) {
        throw $e;
    }
} else {
    if (@$_POST['btn_deny']) {
        $user_id = (int) $_GET['uid'];
        $relation_id = (int) $_POST['related_id'];
        try {
            $relation_obj = Relation::getRelationData($relation_id, $user_id, PA::$network_info->network_id);
            if (Relation::delete_relation($relation_id, $user_id, PA::$network_info->network_id)) {
                // if relation deleted successfully, send a notification to the requestor
 function handle_join()
 {
     $error_inv = false;
     $invitation_id = isset($_REQUEST['InvID']) ? $_REQUEST['InvID'] : null;
     $group_invitation_id = isset($_REQUEST['GInvID']) ? $_REQUEST['GInvID'] : null;
     $mother_network_info = Network::get_mothership_info();
     $extra = unserialize($mother_network_info->extra);
     if (!$this->reg_user->register($_POST, PA::$network_info)) {
         // registration failed
         return;
     }
     // If the user is joining a network other than the
     if ($mother_network_info->network_id != PA::$network_info->network_id) {
         Network::join(1, $this->reg_user->newuser->user_id, NETWORK_MEMBER);
     }
     if ($extra['email_validation'] == NET_NO || $this->silent) {
         // silent registration - no email validation!
         // Success!
         if (!$this->silent) {
             register_session($this->reg_user->newuser->login_name, $this->reg_user->newuser->user_id, $this->reg_user->newuser->role, $this->reg_user->newuser->first_name, $this->reg_user->newuser->last_name, $this->reg_user->newuser->email, $this->reg_user->newuser->picture);
             $_SESSION['login_source'] = 'password';
             // password recently entered, so enable access to edit profile
             PANotify::send("new_user_registered", PA::$network_info, $this->reg_user->newuser, array());
         }
         if ($invitation_id) {
             // if an invitation to join a network
             $this->inv_error = "";
             $is_valid = Invitation::validate_invitation_id($invitation_id);
             if (!$is_valid) {
                 $msg = 7017;
                 // invalid network invitation
             }
             if (empty($msg)) {
                 try {
                     // try to except invitation
                     $new_invite = new Invitation();
                     $new_invite->inv_id = $invitation_id;
                     $new_invite->inv_user_id = $this->reg_user->newuser->user_id;
                     $new_invite->accept();
                     $inv_obj = Invitation::load($invitation_id);
                     $user_obj = new User();
                     $user_obj->load((int) $inv_obj->user_id);
                     //if invitation is for private network
                     if (PA::$network_info->type == PRIVATE_NETWORK_TYPE) {
                         $user_type = NULL;
                         if (PA::$network_info->owner_id == $inv_obj->user_id) {
                             $user_type = NETWORK_MEMBER;
                         }
                         Network::join(PA::$network_info->network_id, $this->reg_user->newuser->user_id, $user_type);
                     }
                     $msg = 7016;
                     $relation_type = null;
                     $relationship_level = 2;
                     //default relation level id is 2 for friend
                     try {
                         $relation_type_id = Relation::get_relation((int) $inv_obj->user_id, (int) $this->reg_user->newuser->user_id, PA::$network_info->network_id);
                     } catch (PAException $e) {
                         Relation::add_relation((int) $inv_obj->user_id, (int) $this->reg_user->newuser->user_id, $relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                         $relation_type = Relation::lookup_relation_type($relation_type_id);
                     }
                     $new_invite->inv_relation_type = $relation_type;
                     if (!$this->silent) {
                         PANotify::send("invitation_accept", $user_obj, $this->reg_user->newuser, $new_invite);
                     }
                 } catch (PAException $e) {
                     $this->inv_error = $e->message;
                     $this->reg_user->msg = "{$e->message}";
                     $error_inv = TRUE;
                 }
                 if ($error_inv == TRUE) {
                     // if invitation fails, then do login again
                     header("Location: " . PA::$url . "/login.php?msg=" . $this->reg_user->msg . "&return={$return_url}");
                     exit;
                 }
             }
             $redirect_url = PA_ROUTE_HOME_PAGE . '/msg=' . $msg;
         } else {
             if ($group_invitation_id) {
                 // if an invitation to join a group
                 // User registration is in response to a group invitation, so
                 // now that the user is registered, handle the group invitation.
                 try {
                     $is_valid_ginv = Invitation::validate_group_invitation_id($group_invitation_id);
                     if (!$is_valid_ginv) {
                         $msg = 3001;
                     }
                 } catch (PAException $e) {
                     $this->inv_error = "{$e->message}";
                 }
                 if (empty($msg)) {
                     //if group invitation is valid, and no error yet
                     try {
                         $new_invite = new Invitation();
                         $new_invite->inv_id = $group_invitation_id;
                         $new_invite->inv_user_id = $this->reg_user->newuser->user_id;
                         $new_invite->accept();
                         //get collection_id
                         $Ginv = Invitation::load($group_invitation_id);
                         $gid = $Ginv->inv_collection_id;
                         $relationship_level = 2;
                         //default relation level id is 2 for friend
                         try {
                             $relation_type_id = Relation::get_relation((int) $Ginv->user_id, (int) $this->reg_user->newuser->user_id, PA::$network_info->network_id);
                         } catch (PAException $e) {
                             Relation::add_relation((int) $Ginv->user_id, (int) $this->reg_user->newuser->user_id, $relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                             Relation::add_relation((int) $this->reg_user->newuser->user_id, (int) $Ginv->user_id, $relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                         }
                     } catch (PAException $e) {
                         $this->reg_user->msg = "{$e->message}";
                         $this->reg_user->error = TRUE;
                         print $this->reg_user->msg;
                     }
                     $redirect_url = PA_ROUTE_GROUP . "/gid={$gid}&action=join&GInvID={$group_invitation_id}";
                 } else {
                     //else redirect registered user to its page.
                     $redirect_url = PA_ROUTE_USER_PRIVATE . '/' . "msg_id={$msg}";
                 }
                 // end of if group invitation is valid
             }
         }
         if (empty($redirect_url)) {
             // if no url is set yet
             // not a group invitation, so redirect to private user page when done
             $msg = 5003;
             $redirect_url = PA_ROUTE_USER_PRIVATE . '/' . "msg_id={$msg}";
         }
         header("Location: " . PA::$url . $redirect_url);
         exit;
     } else {
         $expires = LONG_EXPIRES;
         // for 15 days
         $user = new User();
         $user->login_name = $this->reg_user->newuser->login_name;
         $user->password = $this->reg_user->newuser->password;
         $token = $user->get_auth_token($expires);
         if (!empty($invitation_id)) {
             $invitation = '&InvID=' . $invitation_id;
         } else {
             if (!empty($group_invitation_id)) {
                 $invitation = '&GInvID=' . $group_invitation_id;
             } else {
                 $invitation = NULL;
             }
         }
         $user_type = NETWORK_WAITING_MEMBER;
         Network::join(PA::$network_info->network_id, $this->reg_user->newuser->user_id, $user_type);
         if (!$this->silent) {
             $activation_url = PA::$url . '/mail_action.php?action=activate&token=' . $token . $invitation;
             PAMail::send("activate_account", $this->reg_user->newuser, PA::$network_info, array('account.activation_url' => $activation_url));
         }
         global $app;
         $er_msg = urlencode("Check your email for activation code.");
         $app->redirect(PA::$url . PA_ROUTE_SYSTEM_MESSAGE . "?show_msg=7013&msg_type=info&redirect_url=" . urlencode(PA::$url . '/' . FILE_LOGIN));
     }
     //end if email validation is set
 }
 /** !!
  * Called by web/dynamic.php, which does the page generation.
  *
  * @param string $request_method Not used. But here for standards.
  * @param array $request_data POST data to save.
  */
 public function handleRequest($request_method, $request_data)
 {
     $msg = NULL;
     $action = isset($request_data['do']) ? $request_data['do'] : NULL;
     if ($action == 'delete') {
         $this->delete_id = $this->relation_uid;
         Relation::delete_relation($this->uid, $this->delete_id, PA::$network_info->network_id);
         $this->cache_id = 'relation_private_' . $this->uid;
         CachedTemplate::invalidate_cache($this->cache_id);
         $this->cache_id = 'relation_public_' . $this->uid;
         CachedTemplate::invalidate_cache($this->cache_id);
         // invalidate cache of user who is being added in relation module
         $this->cache_id = 'in_relation_private_' . $this->delete_id;
         CachedTemplate::invalidate_cache($this->cache_id);
         $this->cache_id = 'in_relation_public_' . $this->delete_id;
         CachedTemplate::invalidate_cache($this->cache_id);
         header('Location:' . PA::$url . PA_ROUTE_USER_PUBLIC . '/' . $this->delete_id . '&delete=1');
     }
     //getting relations of logged in user
     $this->all_relations = Relation::get_all_relations((int) $this->uid);
     $this->relationship_level = 2;
     //default relation level id is 2 for friend
     foreach ($this->all_relations as $relation) {
         if ($this->relation_uid == $relation['user_id']) {
             $this->relationship_level = $relation['relation_type_id'];
             $this->in_family = $relation['in_family'];
             $this->status = $relation['status'];
             if ($this->status == PENDING) {
                 if (PA::$extra['reciprocated_relationship'] == NET_YES && $action == 'add') {
                     $msg = sprintf(__('Your request for adding %s as a relation has already been sent'), $relation['display_name']);
                 }
             }
         }
     }
     try {
         $this->user->load((int) $this->relation_uid);
         $this->title = __('Edit Relationship') . ' - ' . $this->user->display_name;
         //title of the web page
         //picture and login relation
         $this->relation_picture = $this->user->picture;
         $this->login_name = $this->user->login_name;
         $this->display_name = $this->user->display_name;
     } catch (PAException $e) {
         $mesg = $e->message;
         $this->is_error = TRUE;
     }
     if (isset($request_data['submit'])) {
         $this->rel_creater = PA::$user;
         $this->relationship_level = $request_data['level'];
         if (PA::$extra['reciprocated_relationship'] == NET_YES) {
             if (Relation::getRelationData($this->relation_uid, $this->uid, PA::$network_info->network_id)) {
                 Relation::update_relation_status($this->relation_uid, $this->uid, APPROVED, PA::$network_info->network_id);
                 Relation::add_relation($this->uid, $this->relation_uid, $this->relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, APPROVED);
                 $relation_obj = Relation::getRelationData($this->relation_uid, $this->uid, PA::$network_info->network_id);
                 PANotify::send("reciprocated_relation_estab", PA::$network_info, PA::$login_user, $relation_obj);
                 // recipient is network owner
                 $location = PA_ROUTE_USER_PRIVATE . '/msg=' . urlencode(__("The relationship request was approved."));
                 header('Location:' . PA::$url . $location);
                 exit;
             }
             $this->status = PENDING;
         } else {
             $this->status = APPROVED;
         }
         try {
             $this->relation = Relation::get_relation($this->rel_creater->user_id, $this->relation_uid, PA::$network_info->network_id);
             $this->edit = $this->relation ? TRUE : FALSE;
         } catch (PAException $e) {
             $this->edit = FALSE;
         }
         try {
             if (isset($request_data['in_family'])) {
                 // If the user has checked the in_family checkbox.
                 Relation::add_relation($this->uid, $this->relation_uid, $this->relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, true, $this->status);
             } else {
                 Relation::add_relation($this->uid, $this->relation_uid, $this->relationship_level, PA::$network_info->address, PA::$network_info->network_id, NULL, NULL, NULL, NULL, $this->status);
             }
             $this->user = PA::$user;
             // relationship establisher image
             $relation_obj = Relation::getRelationData($this->uid, $this->relation_uid, PA::$network_info->network_id);
             if ($this->edit == FALSE) {
                 if (PA::$extra['reciprocated_relationship'] == NET_YES) {
                     PANotify::send("friend_request_sent", PA::$user, PA::$login_user, $relation_obj);
                 } else {
                     PANotify::send("relation_added", PA::$network_info, PA::$login_user, $relation_obj);
                     // recipient is network owner
                     PANotify::send("relationship_created_with_other_member", PA::$user, PA::$login_user, $relation_obj);
                     //for rivers of people
                     $activity = 'user_friend_added';
                     //for rivers of people
                     $activities_extra['info'] = $this->display_name . ' added new friend with id =' . $request_data['uid'];
                     $extra = serialize($activities_extra);
                     $object = $this->relation_uid;
                     Activities::save(PA::$login_uid, $activity, $object, $extra);
                 }
             }
             //invalidate cache of logged in user's relation module
             $this->cache_id = 'relation_private_' . $this->uid;
             CachedTemplate::invalidate_cache($this->cache_id);
             $this->cache_id = 'relation_public_' . $this->uid;
             CachedTemplate::invalidate_cache($this->cache_id);
             // invalidate cache of user who is being added in relation module
             $this->cache_id = 'in_relation_private_' . $this->relation_uid;
             CachedTemplate::invalidate_cache($this->cache_id);
             $this->cache_id = 'in_relation_public_' . $this->relation_uid;
             CachedTemplate::invalidate_cache($this->cache_id);
             if (PA::$extra['reciprocated_relationship'] == NET_NO) {
                 if ($request_data['do']) {
                     $location = PA_ROUTE_USER_PUBLIC . '/' . $this->relation_uid . "&msg=" . urlencode(__("Relationship estabilished."));
                 }
             } else {
                 $location = PA_ROUTE_USER_PRIVATE . '/msg_id=' . urlencode(__("Your request has been sent for approval"));
             }
             header('Location:' . PA::$url . $location);
         } catch (PAException $e) {
             $message = $e->message;
         }
     }
     $msg_array = array();
     $msg_array['failure_msg'] = $msg;
     $msg_array['success_msg'] = NULL;
     $redirect_url = NULL;
     $query_str = NULL;
     set_web_variables($msg_array, $redirect_url, $query_str);
 }
Exemplo n.º 9
0
     $status = PENDING;
 } else {
     $status = APPROVED;
 }
 try {
     $relation = Relation::get_relation($rel_creater->user_id, $relation_uid);
     $edit = $relation ? TRUE : FALSE;
 } catch (PAException $e) {
     $edit = FALSE;
 }
 try {
     if (isset($_POST['in_family'])) {
         // If the user has checked the in_family checkbox.
         Relation::add_relation($uid, $relation_uid, $relationship_level, NULL, NULL, NULL, NULL, NULL, true, $status);
     } else {
         Relation::add_relation($uid, $relation_uid, $relationship_level, NULL, NULL, NULL, NULL, NULL, NULL, $status);
     }
     // relationship establisher image
     $rel_creater_picture = uihelper_resize_mk_user_img($rel_creater->picture, 80, 80, 'alt="' . $rel_creater->first_name . '" align="left" style="padding: 0px 12px 12px 0px;"');
     if ($edit == FALSE) {
         if ($extra['reciprocated_relationship'] == NET_YES) {
             $approve_deny_url = $base_url . '/view_all_members.php?view_type=in_relations&uid=' . $user->user_id;
             // defining array to be sent, to fill message frame
             $params = array('first_name' => $_SESSION['user']['first_name'], 'last_name' => $_SESSION['user']['last_name'], 'user_id' => $_SESSION['user']['id'], 'approve_deny_url' => $approve_deny_url, 'invited_user_name' => $user->login_name, 'requestor_image' => $rel_creater_picture, 'to' => $user->email, 'requested_user_id' => $user->user_id, 'config_site_name' => $config_site_name);
             // send notification
             auto_email_notification_members('relationship_requested', $params);
         } else {
             $params['related_uid'] = $relation_uid;
             $params['related_user'] = $user->first_name;
             $params['user_name'] = $rel_creater->login_name;
             $params['user_id'] = $rel_creater->user_id;
Exemplo n.º 10
0
 function render_for_ajax()
 {
     $op = $this->params["op"];
     if ($op != 'paging' && empty(PA::$login_user)) {
         return __("Login required");
     }
     switch ($op) {
         case "add_friend":
             do {
                 $extra = array();
                 if (isset(PA::$network_info->extra)) {
                     $extra = unserialize(PA::$network_info->extra);
                 }
                 $status = APPROVED;
                 if (@$extra['reciprocated_relationship'] == NET_YES) {
                     $status = PENDING;
                 }
                 $added = FALSE;
                 try {
                     Relation::add_relation(PA::$login_user->user_id, $this->user->user_id, 2, NULL, NULL, NULL, NULL, NULL, NULL, $status);
                     $added = TRUE;
                 } catch (PAException $e) {
                     $this->err = __("There was a problem with adding the relation: ") . $e->getMessage();
                     $added = FALSE;
                 }
                 if ($added) {
                     if ($status == PENDING) {
                         $this->note = __("You have requested to be friends.");
                     } else {
                         $this->note = __("Friend added successfully.");
                     }
                 }
                 // and now for Notifications etc
                 // relationship establisher image
                 $rel_creater_picture = uihelper_resize_mk_user_img(PA::$login_user->picture, 80, 80, 'alt="' . PA::$login_user->first_name . '" align="left" style="padding: 0px 12px 12px 0px;"');
                 if (@$extra['reciprocated_relationship'] == NET_YES) {
                     // defining array to be sent, to fill message fram
                     $params = array('first_name' => PA::$login_user->first_name, 'last_name' => PA::$login_user->last_name, 'user_id' => PA::$login_user->id, 'approve_deny_url' => PA::$url . '/' . FILE_VIEW_ALL_MEMBERS . '?view_type=in_relations&uid=' . $this->uid, 'invited_user_name' => $this->user->login_name, 'requestor_image' => $rel_creater_picture, 'to' => $this->user->email, 'requested_user_id' => $this->user->user_id, 'config_site_name' => PA::$site_name);
                     // send notification
                     auto_email_notification_members('relationship_requested', $params);
                 } else {
                     $params = array('related_uid' => $this->uid, 'related_user' => $this->user->first_name, 'user_name' => PA::$login_user->login_name, 'user_id' => PA::$login_user->user_id, 'user_image' => $rel_creater_picture, 'to' => $this->user->email, 'my_friends_url' => PA::$url . '/' . FILE_VIEW_ALL_MEMBERS . '?view_type=in_relations&uid=' . $this->uid, 'user_url' => PA::$url . '/' . FILE_USER_BLOG . '?uid=' . PA::$login_user->user_id, 'config_site_name' => PA::$site_name);
                     auto_email_notification('relation_added', $params);
                     auto_email_notification_members('relationship_created_with_other_member', $params);
                     // for rivers of people
                     $activity = 'user_friend_added';
                     $extra = serialize(array('info' => PA::$login_user->login_name . ' added new relation with id = ' . $this->uid));
                     Activities::save(PA::$login_uid, $activity, $this->uid, $extra, array($activity));
                 }
             } while (0);
             break;
         case "deny_friend":
             // deny and remove are essentially equivalent
         // deny and remove are essentially equivalent
         case "remove_friend":
             do {
                 $user_id = PA::$login_user->user_id;
                 $remove_id = (int) $this->params['remove_id'];
                 if ($op == "deny_friend") {
                     try {
                         $res = Relation::delete_relation($remove_id, $user_id);
                         // relation reversed
                         $this->note = __("You denied the friend request successfully.");
                     } catch (PAException $e) {
                         $this->err = __("There was a problem with denying the relation: ") . $e->getMessage();
                     }
                 } else {
                     // remove
                     try {
                         $res = Relation::delete_relation($user_id, $remove_id);
                         $this->note = __("You removed the friend successfully.");
                     } catch (PAException $e) {
                         $this->err = __("There was a problem removing the relation: ") . $e->getMessage();
                     }
                     // make sure we don't leave the relation existing in the other direction
                     try {
                         $res2 = Relation::delete_relation($remove_id, $user_id);
                         // relation reversed
                     } catch (PAException $e) {
                         $this->err = __("There was a problem removing the reversed relation: ") . $e->getMessage();
                     }
                 }
                 if ($res) {
                     $requested_user = User::map_ids_to_logins((int) $remove_id);
                     $requested_user_name = $requested_user[$remove_id];
                     // defining array of values to fill message fram
                     $params = array('user_id' => $user_id, 'first_name' => PA::$login_user->first_name, 'last_name' => PA::$login_user->last_name, 'to' => $this->params['related_email'], 'requested_user_id' => $remove_id, 'requested_user_name' => $requested_user_name, 'network_name' => PA::$network_info->name, 'config_site_name' => PA::$site_name);
                     // send notification
                     auto_email_notification_members('relationship_denied', $params);
                 }
             } while (0);
             break;
         case "approve_friend":
             do {
                 $user_id = PA::$login_user->user_id;
                 $relation_id = (int) $this->params['approve_id'];
                 $status = APPROVED;
                 try {
                     $result = Relation::update_relation_status($user_id, $relation_id, $status);
                     if ($result) {
                         // if relationship has been made then send mail to the requestor
                         $this->note = __("You approved the friend request successfully.");
                         Relation::add_relation($user_id, $relation_id);
                         // for rivers of people
                         // notif approval
                         $activity = 'user_friend_approved';
                         $extra = serialize(array('info' => PA::$login_user->login_name . ' approved  relation with id = ' . $relation_id));
                         Activities::save(PA::$login_uid, $activity, $relation_id, $extra, array($activity));
                         // notify the originator direction also
                         $activity = 'user_friend_added';
                         $ou = new User();
                         $ou->load((int) $relation_id);
                         $extra = serialize(array('info' => $ou->login_name . ' added new relation with id = ' . PA::$login_user->login_name));
                         Activities::save($relation_id, $activity, PA::$login_uid, $extra, array($activity));
                         $from = PA::$login_user->email;
                         $requested_user = User::map_ids_to_logins($relation_id);
                         if (PA::$network_info->type == MOTHER_NETWORK_TYPE) {
                             $network_owner_id = SUPER_USER_ID;
                         } else {
                             $network_owner_id = PA::$network_info->owner_id;
                         }
                         $net_user = new User();
                         $net_user->load((int) $network_owner_id);
                         $relation_type = $relation_type = Relation::lookup_relation_type(Relation::get_relation($relation_id, $user_id));
                         $params['cnt'] = TRUE;
                         $rel_count = Relation::get($params, 'status =\'' . APPROVED . '\'');
                         $friend_list_url = PA::$url . '/' . FILE_VIEW_ALL_MEMBERS . '?view_type=in_relations&uid=' . $relation_id;
                         $user_url = url_for(FILE_USER_BLOG, array('login' => $requested_user[$relation_id]));
                         $member_moderation_url = PA::$url . '/' . FILE_NETWORK_MANAGE_USER;
                         $params = array('first_name' => PA::$login_user->first_name, 'last_name' => PA::$login_user->last_name, 'user_name' => PA::$login_user->login_name, 'invited_user_id' => $relation_id, 'user_id' => $user_id, 'invited_user_name' => $requested_user[$relation_id], 'relation_type' => $relation_type, 'network_name' => PA::$network_info->name, 'member_count' => PA::$network_info->member_count, 'reci_relation_count' => $rel_count, 'network_owner_name' => $net_user->first_name, 'to' => $this->params['related_email'], 'mail_type' => 'friend_response', 'user_url' => $user_url, 'friend_list_url' => $friend_list_url, 'member_moderation_url' => $member_moderation_url, 'config_site_name' => PA::$site_name);
                         // send mail to proper notification
                         auto_email_notification_members('invitation_accept', $params);
                         // add check for network owner's notification
                         $extra = unserialize(PA::$network_info->extra);
                         if (@$extra['notify_owner']['relation_added']['value'] != NET_NONE) {
                             // send mail to network owner
                             $to = $net_user->email;
                             $mail_type = 'reciprocated_relation_estab';
                             $check = pa_mail($to, $mail_type, $params);
                         }
                     }
                 } catch (PAException $e) {
                     $this->err = __("There was a problem with adding the relation: ") . $e->getMessage();
                 }
             } while (0);
             break;
         default:
             // just ignore any others
             $this->note = "Unknown operation {$op}.";
             break;
     }
     return $this->render();
 }
Exemplo n.º 11
0
        $view_type = 'all';
    }
}
if (@$_GET['gid']) {
    $page_name = 'View All Group Members';
    $header_tpl = 'header_group.tpl';
}
if (@$_POST['btn_approve']) {
    $user_id = (int) $_GET['uid'];
    $relation_id = (int) $_POST['related_id'];
    $status = APPROVED;
    try {
        $result = Relation::update_relation_status($user_id, $relation_id, $status);
        if ($result) {
            // if relationship has been made then send mail to the requestor
            Relation::add_relation($user_id, $relation_id);
            $from = $_SESSION['user']['email'];
            $requested_user = User::map_ids_to_logins($relation_id);
            if ($network_info->type == MOTHER_NETWORK_TYPE) {
                $network_owner_id = SUPER_USER_ID;
            } else {
                $network_owner_id = $network_info->owner_id;
            }
            $net_user = new User();
            $net_user->load((int) $network_owner_id);
            $relation_type = $relation_type = Relation::lookup_relation_type(Relation::get_relation($relation_id, $user_id));
            $params['cnt'] = TRUE;
            $rel_count = Relation::get($params, 'status =\'' . APPROVED . '\'');
            $friend_list_url = PA::$url . '/' . FILE_VIEW_ALL_MEMBERS . '?view_type=in_relations&uid=' . $relation_id;
            $user_url = url_for(FILE_USER_BLOG, array('login' => $requested_user[$relation_id]));
            $member_moderation_url = PA::$url . '/' . FILE_NETWORK_MANAGE_USER;