* @copyright Copyright (c) 2010 Broadband Mechanics
* @package PeopleAggregator
*/
//echo "fyi - NetworkDefaultControlModule/action.php not used yet"; exit;
require_once "web/includes/classes/file_uploader.php";
require_once "api/Roles/Roles.php";
if ($_form['operation'] == 'create_network') {
    $return_variable = create_new_network($_form);
    $failure_msg = $return_variable['msg']['failure_msg'];
    $succss_msg = $return_variable['msg']['success_msg'];
    $redirect_url = $return_variable['redirection_url'];
}
$msg_array = array();
$msg_array['failure_msg'] = $failure_msg;
$msg_array['success_msg'] = $succss_msg;
set_web_variables($msg_array, $redirection_url, $query_str);
// Here we made a function for creating the network  ;)
function create_new_network($_form)
{
    // function checks initial settings for network creation
    $can_network_be_created = Network::can_network_be_created();
    if ($can_network_be_created['error'] == TRUE) {
        $config_error = TRUE;
        $error = TRUE;
        $error_msg = $can_network_be_created['error_msg'];
    } else {
        if (!PA::$login_uid) {
            $config_error = TRUE;
        }
    }
    //form_data is array used for form fields
Пример #2
0
<?php

require_once "{$path_prefix}/api/Testimonials/Testimonials.php";
global $page_uid, $login_uid;
if ($_form) {
    $testi = new Testimonials();
    $testi->sender_id = $login_uid;
    $testi->recipient_id = $page_uid;
    $testi->body = $_form['body'];
    try {
        $id = $testi->save();
    } catch (PAException $e) {
        $msg = $e->message;
        $code = $e->code;
    }
}
// Here we call the function
$msg_array = array();
$msg_array['failure_msg'] = $msg;
$msg_array['success_msg'] = 9013;
$login = User::get_login_name_from_id($page_uid);
$current_url = PA::$url . '/' . FILE_USER_BLOG . '?uid=' . $page_uid;
$url_perms = array('current_url' => $current_url, 'login' => $login);
$url = get_url(FILE_USER_BLOG, $url_perms);
$redirect_url = $url;
set_web_variables($msg_array, $redirect_url);
 /** !!
  * Checks to see if all neccassary information has been provided by the user
  * If it has then the passord is updated otherwise it returns an alter stating
  * what information is missing.
  * @param array $request_data contains the data entered by the user
  * @param array $request_method must be POST or will the entire function is skipped
  */
 public function handleChangePassword($request_method, $request_data)
 {
     switch ($request_method) {
         case 'POST':
             $message = NULL;
             //input validations.
             if (empty($request_data['password'])) {
                 $message = __('Please enter your new password');
             } elseif (empty($request_data['confirm_password'])) {
                 $message = __('Please confirm your new password');
             } elseif ($request_data['confirm_password'] != $request_data['password']) {
                 $message = __('Passwords do not match. Please re-enter');
             } elseif (strlen($request_data['password']) < PA::$password_min_length) {
                 $message = sprintf(__('Password should be of %s characters or more.'), PA::$password_min_length);
             } elseif (strlen($request_data['password']) > PA::$password_max_length) {
                 $this->message = sprintf(__('Password should be less than %s charcaters.'), PA::$password_max_length);
             }
             //if $message is set then there is an error
             $redirect_url = $query_str = NULL;
             if (empty($message)) {
                 //inputs are valid, try changing the password
                 try {
                     User::change_password($request_data['password'], $this->forgot_password_id);
                     $msg_array = array('failure_msg' => NULL, 'success_msg' => $message);
                     $redirect_url = PA::$url . '/' . FILE_LOGIN;
                     $query_str = '?msg_id=7004';
                 } catch (PAException $e) {
                     $msg_array = array('failure_msg' => $e->message, 'success_msg' => NULL);
                 }
             } else {
                 $msg_array = array('failure_msg' => $message, 'success_msg' => NULL);
             }
             @set_web_variables($msg_array, $redirect_url, $query_str);
             break;
     }
 }
 /** !!
  * Saves the form-submitted data.
  * 
  * @param string $request_method Should be POST
  * @param array $request_data Submitted data from the blogs/RSS page
  */
 public function handleBlogSetting($request_method, $request_data)
 {
     $msg = NULL;
     $error = FALSE;
     switch ($request_method) {
         case 'POST':
             $field_type = GENRAL;
             $field_name = 'BlogSetting';
             if ($request_data['personal_blog'] && $request_data['external_blog']) {
                 $status = BLOG_SETTING_STATUS_ALLDISPLAY;
             } else {
                 if ($request_data['personal_blog'] && !$request_data['external_blog']) {
                     $status = PERSONAL_BLOG_SETTING_STATUS;
                 } else {
                     if (!$request_data['personal_blog'] && $request_data['external_blog']) {
                         $status = EXTERNAL_BLOG_SETTING_STATUS;
                     } else {
                         $status = BLOG_SETTING_STATUS_NODISPLAY;
                     }
                 }
             }
             $params_profile = array(array($this->uid, $field_name, $status, $field_type, 1, null));
             $this->user->save_user_profile_fields($params_profile, $field_type, $field_name);
             if (!empty($request_data['mode']) && htmlspecialchars($request_data['mode']) == 'blog_rss') {
                 $location = PA::$url . PA_ROUTE_EDIT_PROFILE . '?type=blogs_rss&msg_id=9025';
             } else {
                 $location = PA::$url . PA_ROUTE_USER_PRIVATE . '/' . 'msg_id=9025';
             }
             header('Location:' . $location);
             exit;
             break;
         case 'GET':
             if (!empty($request_data['mode']) && htmlspecialchars($request_data['mode']) == 'blog_rss') {
                 header('Location:' . PA::$url . PA_ROUTE_EDIT_PROFILE . '?type=blogs_rss&msg_id=9025');
                 exit;
             }
             break;
     }
     $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);
 }
 public function handleSaveAnswer($request_method, $request_data)
 {
     $msg = NULL;
     $error = FALSE;
     switch ($request_method) {
         case 'POST':
             filter_all_post($request_data);
             $request_data['answer'] = trim($request_data['answer']);
             if (empty($request_data['answer'])) {
                 $msg = __('Answer can not be left blank');
                 $error = true;
             } else {
                 $comment = new Comment();
                 // setting some variables
                 $usr = PA::$user;
                 $comment->comment = $comment->subject = $request_data['answer'];
                 $comment->parent_type = TYPE_ANSWER;
                 $id = $comment->parent_id = $comment->content_id = $request_data['id'];
                 $comment->user_id = $usr->user_id;
                 $comment->name = $usr->login_name;
                 $comment->email = $usr->email;
                 if ($comment->spam_check()) {
                     $msg = __('Sorry, your Answer cannot be posted as it looks like spam. Try removing any links to possibly suspect sites, and re-submitting.');
                     $error = true;
                     Logger::log('Comment rejected by spam filter', LOGGER_ACTION);
                 } else {
                     $msg = __('Your Answer has been posted successfully');
                     $comment->save_comment();
                     if ($comment->spam_state != SPAM_STATE_OK) {
                         $msg = __('Sorry, your answer cannot be posted as it was classified as spam by Akismet, or contained links to blacklisted sites. Please check the links in your post, and that your name and e-mail address are correct.');
                         $error = true;
                     } else {
                         unset($request_data);
                         //invalidate cache of content block as it is modified now
                         if (PA::$network_info) {
                             $nid = '_network_' . PA::$network_info->network_id;
                         } else {
                             $nid = '';
                         }
                         //unique name
                         $cache_id = 'content_' . $id . $nid;
                         CachedTemplate::invalidate_cache($cache_id);
                     }
                 }
             }
             break;
     }
     $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);
 }
 /**
  * Method will be used for setting the message in the web pages.
  */
 public function setWebPageMessage()
 {
     if (!empty($this->message)) {
         if (!$this->isError) {
             //Success
             $message = array('failure_msg' => NULL, 'success_msg' => $this->message);
         } else {
             //Message is a failure message
             $message = array('failure_msg' => $this->message, 'success_msg' => NULL);
         }
         @set_web_variables($message, $this->redirect2, $this->queryString);
     }
 }
 /** !!
  * This handles the data that is POSTed back to the page upon
  * submission of the form. There is a lot happening in here,
  * but it basically looks at the submitted data, figures out
  * what it is supposed to do with it (based on if the group is
  * being created or modified), then creates a new group or
  * updates the current data using the {@link handle_entity() } method.
  *
  * @param array $request_data  All of the data POSTed back to the form.
  */
 public function handlePOST($request_data)
 {
     require_once "web/includes/classes/CNFileUploader.php";
     require_once "api/CNActivities/CNActivities.php";
     require_once "api/cnapi_constants.php";
     if ($request_data['addgroup']) {
         filter_all_post($request_data);
         $groupname = trim($request_data['groupname']);
         $body = trim($request_data['groupdesc']);
         $tag_entry = trim($request_data['group_tags']);
         $group_category = $request_data['group_category'];
         $header_image = NULL;
         $header_image_action = @$request_data['header_image_action'];
         $display_header_image = @$request_data['display_header_image'];
         $collection_id = NULL;
         $this->extra = NULL;
         if ($request_data['ccid']) {
             $collection_id = (int) $request_data['ccid'];
             $group = new Group();
             $group->load($collection_id);
             // preserve group info we are not editing in this module
             // load group extra
             $extra = $group->extra;
             if (!empty($extra)) {
                 $this->extra = unserialize($extra);
             }
             $header_image = $group->header_image;
             $header_image_action = $group->header_image_action;
             $display_header_image = $group->display_header_image;
         }
         $access = 0;
         // default access is 0 means public
         $reg_type = $request_data['reg_type'];
         if ($reg_type == REG_INVITE) {
             // if reg. type = "Invite" access is PRIVATE
             $access = ACCESS_PRIVATE;
         }
         $is_moderated = 0;
         // is moderated is 0 means contents appear immediately
         $group_tags = $request_data['group_tags'];
         if (empty($request_data['groupname'])) {
             $error_msg = 90222;
         } else {
             if (empty($group_category) && empty($error_msg)) {
                 $error_msg = 90224;
             } else {
                 if (empty($error_msg)) {
                     try {
                         if (empty($_FILES['groupphoto']['name'])) {
                             $upfile = $request_data['file'];
                         } else {
                             $myUploadobj = new FileUploader();
                             //creating instance of file.
                             $image_type = 'image';
                             $file = $myUploadobj->upload_file(PA::$upload_path, 'groupphoto', true, true, $image_type);
                             if ($file == false) {
                                 throw new CNException(GROUP_PARAMETER_ERROR, __("File upload error: ") . $myUploadobj->error);
                             }
                             $upfile = $file;
                             $avatar_uploaded = TRUE;
                         }
                         $exception_message = NULL;
                         $result = Group::save_new_group($collection_id, $_SESSION['user']['id'], $groupname, $body, $upfile, $group_tags, $group_category, $access, $reg_type, $is_moderated, $header_image, $header_image_action, $display_header_image, $this->extra);
                         $ccid = $result;
                         $exception_message = 'Group creation failed: ' . $result;
                         if (!is_numeric($result)) {
                             throw new CNException(GROUP_CREATION_FAILED, $exception_message);
                         } else {
                             if (@$avatar_uploaded) {
                                 Storage::link($upfile, array("role" => "avatar", "group" => (int) $result));
                             }
                             if (@$header_uploaded) {
                                 Storage::link($header_image, array("role" => "header", "group" => (int) $result));
                             }
                             $this->gid = $this->id = $result;
                             if (empty($request_data['gid'])) {
                                 $mail_type = $activity = 'group_created';
                                 $act_text = ' created a new group';
                             } else {
                                 $mail_type = $activity = 'group_settings_updated';
                                 $act_text = ' changed group settings ';
                             }
                             $group = new Group();
                             $group->load((int) $this->gid);
                             PANotify::send($mail_type, PA::$network_info, PA::$login_user, $group);
                             // notify network onwer
                             $_group_url = PA::$url . PA_ROUTE_GROUP . '/gid=' . $result;
                             $group_owner = new User();
                             $group_owner->load((int) $_SESSION['user']['id']);
                             $activity_extra['info'] = $group_owner->first_name . $act_text;
                             $activity_extra['group_name'] = $groupname;
                             $activity_extra['group_id'] = $result;
                             $activity_extra['group_url'] = $_group_url;
                             $extra = serialize($activity_extra);
                             $object = $result;
                             if ($reg_type != REG_INVITE) {
                                 Activities::save($group_owner->user_id, $activity, $object, $extra);
                             }
                             // if we reached here than the group is created
                             if (empty($request_data['gid'])) {
                                 // when a new group is created
                                 // so, we need to assign group admin role to group owner now:
                                 $role_extra = array('user' => false, 'network' => false, 'groups' => array($this->gid));
                                 $user_roles[] = array('role_id' => GROUP_ADMIN_ROLE, 'extra' => serialize($role_extra));
                                 $group_owner->set_user_role($user_roles);
                             }
                             if (!empty(PA::$config->useTypedGroups) && !empty($request_data['type'])) {
                                 $this->gid = $this->id;
                                 switch ($request_data['op']) {
                                     case 'create_entity':
                                     case 'edit_entity':
                                         $this->handleEntity($request_data);
                                         break;
                                 }
                             }
                         }
                     } catch (CNException $e) {
                         if ($e->code == GROUP_PARAMETER_ERROR) {
                             $error_msg = $e->message;
                             if (empty($groupname)) {
                                 $error_msg = 90222;
                             } else {
                                 if (empty($group_category)) {
                                     $error_msg = 90224;
                                 }
                             }
                         } else {
                             $error_msg = $e->message;
                         }
                     }
                 }
             }
         }
     }
     //if form is posted
     $msg_array = array();
     $msg_array['failure_msg'] = @$error_msg;
     $msg_array['success_msg'] = !empty($this->id) ? 90231 : 90221;
     $redirect_url = PA::$url . PA_ROUTE_GROUP;
     $query_str = "?gid=" . @$result;
     set_web_variables($msg_array, $redirect_url, $query_str);
 }
 /** !!
  * 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);
 }
 /** !!
  * Takes the data submitted in the form and gets all of the useful data
  * necessary to send a message.  It takes the name that is being sent to and 
  * gets the id, email, and other assorted data.  It then sends the message and
  * tells the user what the outcome of that process is. It also makes sure the
  *  message is within the correct length.
  *
  *  @param array $request_data  The data to be operated on.
  */
 public function handlePOSTPageSubmit($request_data)
 {
     $error = false;
     if (!empty($request_data)) {
         if (isset($request_data['send'])) {
             $message = NULL;
             filter_all_post($request_data, TRUE);
             // applying input filter to the post data, this function is define in function.php
             $subject = $request_data['subject'];
             $body = $request_data['body'];
             $in_reply_to = $request_data['in_reply_to'];
             if (empty($request_data['to'])) {
                 $message = 8003;
                 $error = true;
             }
             if (strlen($body) > MAX_MESSAGE_LENGTH) {
                 $message = 8002;
                 $error = true;
             }
             if (!$error) {
                 if (empty($subject)) {
                     $subject = '[none]';
                 }
                 $login_names = preg_split("/,\\s*/", $request_data['to']);
                 $valid_recipients = array();
                 //login name of all the valid login names.
                 $invalid_recipients = array();
                 // names of all the invalid recipients.
                 foreach ($login_names as $login_name) {
                     try {
                         $User = new User();
                         $User->load($login_name);
                         $valid_recipients['id'][] = $User->user_id;
                         $valid_recipients['name'][] = $User->login_name;
                         $valid_recipients['display_name'][] = $User->display_name;
                         $valid_recipients['fname'][] = $User->first_name;
                         $valid_recipients['email'][] = $User->email;
                         $valid_recipients['user'][] = $User;
                         $notif_settings = null;
                         $recipient_profile = User::load_user_profile($User->user_id, $User->user_id, 'notifications');
                         if (!empty($recipient_profile)) {
                             $notif_settings = unserialize($recipient_profile[0]['value']);
                         }
                         $valid_recipients['notifications'][] = $notif_settings;
                     } catch (PAException $e) {
                         $invalid_recipients[] = $login_name;
                     }
                 }
                 $message = null;
                 if (count($valid_recipients)) {
                     $is_draft = FALSE;
                     // actually 'send' the message
                     Message::add_message(PA::$login_uid, $valid_recipients['id'], $valid_recipients['name'], $subject, $body, $is_draft, $in_reply_to);
                     // handle 'also send to email' and 'message_waiting_blink'
                     $valid_recipients_count = count($valid_recipients['id']);
                     for ($counter = 0; $counter < $valid_recipients_count; $counter++) {
                         if (!empty($valid_recipients['notifications'][$counter])) {
                             $rec_notif_settings = $valid_recipients['notifications'][$counter];
                             $as_email = false;
                             if (!empty($rec_notif_settings['user_send_message']['value'])) {
                                 switch ($rec_notif_settings['user_send_message']['value']) {
                                     case NET_EMAIL:
                                     case NET_BOTH:
                                         $as_email = true;
                                         PAMail::send("user_send_message", $valid_recipients['user'][$counter], PA::$login_user, array('subject' => $subject, 'message' => $body));
                                         break;
                                     default:
                                         break;
                                 }
                             }
                             // if they are not getting it in email already
                             if (empty($as_email) && !empty($rec_notif_settings['msg_waiting_blink']) && $rec_notif_settings['msg_waiting_blink'] == NET_EMAIL) {
                                 PAMail::send("msg_waiting_blink", $valid_recipients['email'][$counter], PA::$login_user, array());
                             }
                         }
                     }
                     $message = sprintf(__("Message sent successfully to %s"), implode(", ", $valid_recipients['display_name']));
                 }
                 if (count($invalid_recipients)) {
                     //some of the recipients are invalid. So displaying the error message for them.
                     $message .= sprintf(__("Message sending failed for %s  as user(s) doesn't exist"), implode(", ", $invalid_recipients));
                     $error = true;
                 } else {
                     // message sent successfully to all the recipients. Redirecting user to inbox
                     header('Location: ' . PA::$url . PA_ROUTE_MYMESSAGE . "/msg={$message}");
                     exit;
                 }
             }
             if (!empty($message)) {
                 $msg_array = array();
                 $msg_array['failure_msg'] = $message;
                 $msg_array['success_msg'] = NULL;
                 $redirect_url = NULL;
                 $query_str = NULL;
                 set_web_variables($msg_array, $redirect_url, $query_str);
             }
         }
     }
 }
 public function handlePOST_GroupInvitationSubmit($request_data)
 {
     if (isset($request_data['submit'])) {
         filter_all_post($request_data);
         $gid = $request_data['groups'];
         $self_invite = FALSE;
         $error = FALSE;
         // check if groups are there
         if (empty($gid)) {
             $error = TRUE;
             $msg[] = __("Please select a group");
         }
         if (empty($error) && !empty($request_data['email_user_name'])) {
             // if login name are supplied
             $friend_user_name = trim($request_data['email_user_name']);
             $friend_user_name_array = explode(',', $friend_user_name);
             $cnt_usr_name = count($friend_user_name_array);
             for ($counter = 0; $counter < $cnt_usr_name; $counter++) {
                 try {
                     $user_obj = new User();
                     $user_obj->load(trim($friend_user_name_array[$counter]));
                     if ($user_obj->email == PA::$login_user->email) {
                         $self_invite = TRUE;
                         //you can not invite your self
                     } else {
                         $valid_user_login_names[] = $user_obj->login_name;
                         $valid_usr_name_email[] = $user_obj->email;
                     }
                 } catch (PAException $e) {
                     if (!empty($friend_user_name_array[$counter])) {
                         $invalid_login_msg .= $friend_user_name_array[$counter] . ', ';
                     }
                 }
             }
             // end for
             if (!empty($invalid_login_msg)) {
                 $invalid_login_msg = substr($invalid_login_msg, 0, -2);
                 $msg[] = sprintf(__('Invitation could not be sent to following login names- %s'), $invalid_login_msg);
             }
         }
         // end if : if user names are supplied.
         $invalid = null;
         if (empty($error) && !empty($request_data['email_id'])) {
             // if email ids are supplied
             $friend_email = trim($request_data['email_id']);
             $friend_email_array = explode(',', $friend_email);
             $cnt_email = count($friend_email_array);
             // Check for valid-invalid email addresses start
             for ($counter = 0; $counter < $cnt_email; $counter++) {
                 $email_validation = Validation::validate_email(trim($friend_email_array[$counter]));
                 if ($email_validation == '0') {
                     $invalid[] = trim($friend_email_array[$counter]);
                 } else {
                     if ($friend_email_array[$counter] == PA::$login_user->email) {
                         $self_invite = TRUE;
                     } else {
                         $valid_user_first_emails[] = $friend_email_array[$counter];
                         $valid_email[] = trim($friend_email_array[$counter]);
                     }
                 }
             }
         }
         // Check for valid-invalid email addresses end
         // Action for valid-invalid email addresses start
         if (empty($friend_email) && empty($friend_user_name)) {
             // if email field is left empty
             $msg[] = MessagesHandler::get_message(6001);
             $error = TRUE;
         } else {
             if (!empty($friend_email) && !empty($friend_user_name)) {
                 $msg = array();
                 $msg[] = MessagesHandler::get_message(7026);
                 $error = TRUE;
             } else {
                 if (!empty($self_invite) || sizeof($invalid) > 0) {
                     // if self invitation is made
                     if (!empty($self_invite)) {
                         $msg[] = MessagesHandler::get_message(6002);
                     }
                     if (!empty($invalid)) {
                         // if invalid email addresses are supplied
                         $invalid_cnt = count($invalid);
                         $invalid_msg = '';
                         for ($counter = 0; $counter < $invalid_cnt; $counter++) {
                             if (!empty($invalid[$counter])) {
                                 $invalid_msg .= $invalid[$counter] . ', ';
                             }
                         }
                         if (!empty($invalid_msg)) {
                             $invalid_msg = substr($invalid_msg, 0, -2);
                             $msg[] = sprintf(__('Invitation could not be sent to following email addresses- %s'), $invalid_msg);
                         }
                     }
                 }
             }
         }
         if (empty($error)) {
             // At this point invitation could be made
             if (!empty($valid_email) && !empty($valid_usr_name_email)) {
                 $valid_email = array_merge($valid_email, $valid_usr_name_email);
                 $valid_user_first_emails = array_merge($valid_user_first_emails, $valid_user_login_names);
             } else {
                 if (!empty($valid_usr_name_email)) {
                     $valid_email = $valid_usr_name_email;
                     $valid_user_first_emails = $valid_user_login_names;
                 }
             }
             if (!empty($valid_email)) {
                 $valid_cnt = count($valid_email);
                 $invitation_message = nl2br($request_data['message']);
                 for ($counter = 0; $counter < $valid_cnt; $counter++) {
                     $group = new Group();
                     $group->load((int) $gid);
                     $inv = new Invitation();
                     $inv->user_id = PA::$login_uid;
                     $inv->username = PA::$login_user->login_name;
                     // for invitation not for any group invitation collection id is -1
                     $inv->inv_collection_id = $gid;
                     $inv->inv_group_name = $group->title;
                     $inv->inv_status = INVITATION_PENDING;
                     $auth_token = get_invitation_token(LONG_EXPIRES, $valid_email[$counter]);
                     $token = '&amp;token=' . $auth_token;
                     $link_desc = wordwrap(PA::$url . '/' . FILE_REGISTER . "?GInvID={$inv->inv_id}", 120, "<br>", 1);
                     $inv->register_url = "<a href=\"" . PA::$url . '/' . FILE_REGISTER . "?GInvID={$inv->inv_id}\">{$link_desc}</a>";
                     $acc_link_desc = wordwrap(PA::$url . "/" . FILE_LOGIN . "?action=accept&GInvID={$inv->inv_id}{$token}", 120, "<br>", 1);
                     $inv->accept_url = "<a href=\"" . PA::$url . "/" . FILE_LOGIN . "?action=accept&GInvID={$inv->inv_id}{$token}\">{$acc_link_desc}</a>";
                     $inv->inv_user_id = null;
                     $inv->inv_user_first_name = $valid_user_first_emails[$counter];
                     $inv->inv_email = $valid_email[$counter];
                     $inv->inv_summary = sprintf(__("Invitation from %s %s to join %s"), PA::$login_user->first_name, PA::$login_user->last_name, $inv->inv_group_name);
                     $inv->inv_message = !empty($invitation_message) ? $invitation_message : null;
                     $save_error = false;
                     try {
                         $inv->send();
                     } catch (PAException $e) {
                         $save_msg = "{$e->message}";
                         $save_error = true;
                     }
                     if ($save_error == true) {
                         $msg[] = sprintf(__('Sorry: you are unable to invite a friend.  Reason: %s'), $sav_msg);
                     } else {
                         // invitation has been sent, now send email
                         $user_type = Group::get_user_type(PA::$login_uid, $gid);
                         if ($user_type == OWNER) {
                             $mail_type = 'invite_group';
                             $requester = $group;
                         } else {
                             if ($user_type == MEMBER) {
                                 $mail_type = 'invite_group_by_member';
                                 $requester = PA::$login_user;
                             }
                         }
                         PAMail::send($mail_type, $inv->inv_email, $requester, $inv);
                         $succ_msg .= $valid_user_first_emails[$counter] . ', ';
                         if ($counter == $valid_cnt - 1) {
                             $succ_msg = substr($succ_msg, 0, -2);
                             //$msg_1[] = "Invitation has been sent successfully to -" . $succ_msg;
                         }
                     }
                 }
                 // end for : invitation to multiple email
             }
         }
     }
     //..do invite
     if (!empty($msg)) {
         $msg = array_reverse($msg);
         $message = NULL;
         for ($counter = 0; $counter < count($msg); $counter++) {
             $message .= $msg[$counter] . "<br />";
         }
     }
     $msg_array = array();
     $msg_array['failure_msg'] = $message;
     $msg_array['success_msg'] = 6004;
     $redirect_url = PA::$url . PA_ROUTE_GROUP;
     if (!empty($request_data['groups'])) {
         $query_str = "gid=" . $request_data['groups'];
     }
     set_web_variables($msg_array, $redirect_url, $query_str);
 }