function auto_email_notification_members($activity_type, $params)
{
    global $network_info;
    global $to, $mail_type, $mail_sub_msg_array, $from, $no_id, $network_owner, $subject, $message, $owner;
    if (!$network_info) {
        return;
    }
    //setting common variables
    // mail to
    // FIXME: these two seemed not to be set in occasion
    $gid = @$params['gid'] ? $params['gid'] : @$_GET['gid'];
    $rid = @$params['related_uid'];
    if ($gid) {
        $network_owner_id = Group::get_admin_id($gid);
        $network_owner = User::map_ids_to_logins($network_owner_id['user_id']);
        $group_owner = new User();
        $group_owner->load((int) $network_owner_id['user_id']);
        $to = $group_owner->email;
        $group_owner_name = $group_owner->login_name;
        //mail from
        $from = (int) $_SESSION['user']['id'];
        $array_of_data = array('to' => $to, 'from' => $from, 'owner_name' => $group_owner_name, 'group_owner_id' => $network_owner_id['user_id']);
    }
    if ($rid) {
        $network_owner = User::map_ids_to_logins(array($rid));
        foreach ($network_owner as $key => $value) {
            $rel_user = new User();
            $rel_user->load((int) $key);
            $related_name = $rel_user->login_name;
            $to = $rel_user->email;
        }
        $from = (int) $_SESSION['user']['id'];
        $array_of_data = array('to' => $to, 'from' => $from, 'related_name' => $related_name);
    }
    //making $array_of_data['params'] = $params
    $array_of_data['params'] = $params;
    call_user_func_array($activity_type, array($array_of_data));
}
function auto_email_notification_members($activity_type, $params)
{
    if (!PA::$network_info) {
        return;
    }
    //setting common variables
    $notification = new EmailNotification();
    // mail to
    // FIXME: these two seemed not to be set in occasion
    $gid = @$params['gid'] ? $params['gid'] : @$_GET['gid'];
    $rid = @$params['related_uid'];
    if ($gid) {
        $network_owner_id = Group::get_owner_id($gid);
        $notification->network_owner = User::map_ids_to_logins($network_owner_id['user_id']);
        $group_owner = new User();
        $group_owner->load((int) $network_owner_id['user_id']);
        $notification->to = $group_owner->email;
        $group_owner_name = $group_owner->login_name;
        //mail from
        $notification->from = (int) PA::$login_uid;
        $array_of_data = array('to' => $notification->to, 'from' => $notification->from, 'owner_name' => $group_owner_name, 'group_owner_id' => $network_owner_id['user_id']);
    }
    if ($rid) {
        $notification->network_owner = User::map_ids_to_logins(array($rid));
        foreach ($notification->network_owner as $key => $value) {
            $rel_user = new User();
            $rel_user->load((int) $key);
            $related_name = $rel_user->login_name;
            $notification->to = $rel_user->email;
        }
        $notification->from = (int) PA::$login_uid;
        $array_of_data = array('to' => $notification->to, 'from' => $notification->from, 'related_name' => $related_name);
    }
    $array_of_data['params'] = $params;
    $notification->send($activity_type, $array_of_data);
}
 if ($_POST['route_to_pa_home'] == 1) {
     $display_on_homepage = DISPLAY_ON_HOMEPAGE;
     //its zero
 } else {
     $display_on_homepage = NO_DISPLAY_ON_HOMEPAGE;
     //This will not show up on homepage - flag has opposite values
 }
 $post_saved = BlogPost::save_blogpost(0, $login_uid, $_POST["blog_title"], $_POST["description"], NULL, $terms, -1, 1, $display_on_homepage);
 $permalink_cid = $post_saved['cid'];
 if ($extra['network_content_moderation'] == NET_YES && $network_info->owner_id != $user->user_id) {
     Network::moderate_network_content(-1, $permalink_cid);
     // -1 for contents; not a part of any collection
     $error_msg = "&err=" . urlencode(MessagesHandler::get_message(1004));
 }
 $content_author_image = uihelper_resize_mk_user_img($user->picture, 80, 80, 'alt="' . $user->first_name . '" align="left" style="padding: 0px 12px 12px 0px;"');
 $network_owner_name = User::map_ids_to_logins($network_info->owner_id);
 $params['cid'] = $permalink_cid;
 $params['first_name'] = $user->first_name;
 $params['user_id'] = $user->user_id;
 $params['user_image'] = $content_author_image;
 $params['content_title'] = $_POST["blog_title"];
 $params['network_name'] = $network_info->name;
 $params['content_url'] = PA::$url . '/' . FILE_CONTENT . '?cid=' . $permalink_cid;
 $params['content_moderation_url'] = PA::$url . '/' . FILE_NETWORK_MANAGE_CONTENT;
 $params['config_site_name'] = $config_site_name;
 $params['network_owner_name'] = $network_owner_name[$network_info->owner_id];
 auto_email_notification('content_posted', $params);
 if ($_POST['route_to_pa_home'] == 1) {
     auto_email_notification('content_posted_to_comm_blog', $params);
 }
 //for rivers of people
 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();
 }
                $to = $net_user->email;
                $mail_type = 'reciprocated_relation_estab';
                $check = pa_mail($to, $mail_type, $array_of_data);
            }
        }
    } catch (PAException $e) {
        throw $e;
    }
} else {
    if (@$_POST['btn_deny']) {
        $user_id = (int) $_GET['uid'];
        $relation_id = (int) $_POST['related_id'];
        try {
            if (Relation::delete_relation($relation_id, $user_id)) {
                // if relation deleted successfully, send a notification to the requestor
                $requested_user = User::map_ids_to_logins((int) $relation_id);
                $requested_user_name = $requested_user[$relation_id];
                // defining array of values to fill message frame
                $params = array('user_id' => $_SESSION['user']['id'], 'first_name' => $_SESSION['user']['first_name'], 'last_name' => $_SESSION['user']['last_name'], 'to' => $_POST['related_email'], 'requested_user_id' => $relation_id, 'requested_user_name' => $requested_user_name, 'config_site_name' => $config_site_name);
                // send notification
                auto_email_notification_members('relationship_denied', $params);
            }
        } catch (PAException $e) {
            throw $e;
        }
    }
}
function setup_module($column, $moduleName, $obj)
{
    global $network_info, $uid, $paging, $user, $view_type;
    switch ($column) {