private function handlePOST_inviteSelected($request_data) { $message = trim($request_data['message']); if (empty($message)) { $msg = __("Invite message can't be empty."); } else { $msg = null; $message = nl2br($message); $selected_contacts = !empty($request_data['invite_selected']) ? $request_data['invite_selected'] : null; if ($selected_contacts) { foreach ($selected_contacts as $key => $cntct_id) { $contact = $this->contacts[$key]; // selected index = contacts index $inv = new Invitation(); $inv->user_id = PA::$login_uid; $inv->username = PA::$login_user->login_name; $user = PA::$login_user; // for invitation not for any group invitation collection id is -1 $inv->inv_collection_id = -1; $inv->inv_status = INVITATION_PENDING; $auth_token = get_invitation_token(LONG_EXPIRES, $contact['email']); $token = '&token=' . $auth_token; $link_desc = wordwrap(PA::$url . "/register.php?InvID={$inv->inv_id}", 120, "<br>", 1); $inv->register_url = "<a href=\"" . PA::$url . "/register.php?InvID={$inv->inv_id}\">{$link_desc}</a>"; $acc_link_desc = wordwrap(PA::$url . "/login.php?action=accept&InvID={$inv->inv_id}{$token}", 120, "<br>", 1); $inv->accept_url = "<a href=\"" . PA::$url . "/login.php?action=accept&InvID={$inv->inv_id}{$token}\">{$acc_link_desc}</a>"; $inv->inv_user_id = NULL; $inv->inv_user_first_name = $contact['name']; $inv->inv_email = $contact['email']; $inv->inv_summary = "Invitation from {$user->first_name} {$user->last_name} to join " . PA::$site_name; if ($message != CUSTOM_INVITATION_MESSAGE) { $inv->inv_message = !empty($message) ? $message : null; } try { $inv->send(); } catch (PAException $e) { $msg = "{$e->message}"; $save_error = true; } if (isset($save_error) && $save_error == true) { $msg = "Sorry: you are unable to invite a friend. <br /> Reason: " . $msg; } else { // invitation has been sent, now send mail PAMail::send('invite_pa', $inv->inv_email, PA::$login_user, $inv); $msg .= "<br />" . $contact['name'] . ", " . $contact['email']; } } // end for : invitation to multiple email $msg = "<br />Invitation message has been sent to: " . $msg; } else { $msg = __("Please, select one or more contacts."); } } $redirect_url = PA::$url . PA_ROUTE_USER_CONTACTS . "?type=contacts&stype=" . $this->type . "&msg=" . urlencode($msg); $this->controller->redirect($redirect_url); }
protected function sendNotification() { if (empty($this->message_obj->template_vars["%requester.user_id%"]) || empty($this->message_obj->template_vars["%recipient.login_name%"])) { Logger::log("Error exit: function MessageDispatcher::sendNotification() - Missing Recipient or Requester info."); throw new Exception("MessageDispatcher::sendNotification() - Missing Recipient or Requester info."); } $recipient_notif_settings = null; $destination = NET_NONE; // initial set to NONE $msg_waiting_blink = NET_NONE; // initial set to NONE $msg_categ = $this->message_obj->message['category']; $recipient_id = $this->message_obj->template_vars["%recipient.user_id%"]; $recipient_profile = User::load_user_profile($recipient_id, $recipient_id, 'notifications'); if (!empty($recipient_profile)) { $recipient_notif_settings = unserialize($recipient_profile[0]['value']); } if ($msg_categ == 'notify_network_owner') { // get network notification settings and notify network owner $extra = unserialize(PA::$network_info->extra); if (isset($extra['notify_owner'][$this->message_type]['value'])) { $destination = $extra['notify_owner'][$this->message_type]['value']; } else { // temporrary solution - if no notification settings data defined for a message $destination = NET_BOTH; // message category is 'notify_network_owner', so notify owner } } else { if ($msg_categ == 'notify_group_owner') { $destination = NET_BOTH; // temporrary solution - currently there is no group notification settings } else { if (!empty($recipient_notif_settings) && isset($recipient_notif_settings[$this->message_type]['value'])) { $destination = $recipient_notif_settings[$this->message_type]['value']; } } } if ($msg_categ == 'outgoing_email') { $destination = NET_EMAIL; // override destination if message category is outgoing_email } if ($destination != NET_NONE) { $email_recipient = $this->message_obj->template_vars["%recipient.email_address%"]; $requester = $this->message_obj->template_vars["%requester.user_id%"]; $recipient = $this->message_obj->template_vars["%recipient.login_name%"]; switch ($destination) { case NET_MSG: self::internalMessage($recipient, $requester); // only send message_waiting if the user isn't already recieving the message as email ^^ if (isset($recipient_notif_settings['msg_waiting_blink']) && $recipient_notif_settings['msg_waiting_blink'] == NET_EMAIL) { $msg_waiting_blink = $recipient_notif_settings['msg_waiting_blink']; } break; case NET_EMAIL: self::sendEmail($email_recipient); break; case NET_BOTH: self::internalMessage($recipient, $requester); self::sendEmail($email_recipient); break; } } if ($msg_waiting_blink == NET_EMAIL) { $recipient_id = $this->message_obj->template_vars["%recipient.user_id%"]; $recipient = new User(); $recipient->load((int) $recipient_id); $requester = PA::$network_info; // msg_waiting_blink message is sent by network owner PAMail::send("msg_waiting_blink", $recipient, $requester, array()); } }
try { $newuser->save(); if (!empty($file)) { Storage::link($file, array("role" => "avatar", "user" => $newuser->user_id)); } // creating message basic folders Message::create_basic_folders($newuser->user_id); //token creation $expires = 3600 * 24 * 5; //5days $token = $newuser->get_auth_token($expires); // $user_url = PA::$url .'/mail_action.php?token='.$token.'&action=user'; // $edit_url = PA::$url .'/mail_action.php?token='.$token.'&action=profile'; $user_url = "<a href=\"" . PA::$url . "/mail_action.php?token={$token}&action=user\">" . PA::$url . "/mail_action.php?token={$token}&action=user</a>"; $edit_url = "<a href=\"" . PA::$url . "/mail_action.php?token={$token}&action=profile\">" . PA::$url . "/mail_action.php?token={$token}&action=profile</a>"; PAMail::send("create_new_user_by_admin", $newuser, PA::$network_info, array('greeting.message' => $_POST['greeting_msg'], 'user.password' => $password, 'user.link' => $user_url, 'edit.link' => $edit_url)); // adding default relation if ($newuser->user_id != SUPER_USER_ID) { User_Registration::add_default_relation($newuser->user_id, PA::$network_info); } // adding default media as well as album User_Registration::add_default_media($newuser->user_id, '', PA::$network_info); User_Registration::add_default_media($newuser->user_id, '_audio', PA::$network_info); User_Registration::add_default_media($newuser->user_id, '_video', PA::$network_info); User_Registration::add_default_blog($newuser->user_id); //adding default link categories & links User_Registration::add_default_links($newuser->user_id); // code for adding default desktop image for user $desk_img = uihelper_add_default_desktopimage($newuser->user_id); if (empty($desk_img)) { $desktop_images = array('bay.jpg', 'everglade.jpg', 'bay_boat.jpg', 'delhi.jpg');
public static function send_email_to_change_password($email) { Logger::log("Enter: function User::send_email"); // global var $_base_url has been removed - please, use PA::$url static variable $email_exist = User::get_user_data($email); if ($email_exist['email_exist'] == TRUE) { $first_name = $email_exist['first_name']; $last_name = $email_exist['last_name']; $user_name = $email_exist['login_name']; $password = $email_exist['password']; $user_id = $email_exist['user_id']; $status = 0; $forgot_password_id = md5(uniqid(rand())); // insert data into the database $sql = 'INSERT into {forgot_password} (user_id, forgot_password_id, status) values (?, ?, ?)'; $data = array($user_id, $forgot_password_id, $status); $res = Dal::query($sql, $data); $chng_psw_url = PA::$url . '/' . FILE_CHANGE_PASSWORD . '?log_nam=' . $user_name . '&uid=' . $user_id . '&forgot_password_id=' . $forgot_password_id; $change_password_url = "<a href=\"{$chng_psw_url}\">{$chng_psw_url}</a>"; $forg_user = new User(); $forg_user->load((int) $user_id); $check = PAMail::send('forgot_password', $forg_user, PA::$network_info, array('change_password_url' => $change_password_url)); if ($check == FALSE) { Logger::log("Throwing exception MAIL_FUNCTION_FAILED | Mail is not sent to friend ", LOGGER_ERROR); throw new PAException(MAIL_FUNCTION_FAILED, "Mail is not sent to friend"); } } Logger::log("Exit: function User::send_email"); }
/** * disapprove content/user in moderated queue * @access public * @param int id of user/content * @param string type ie user/content */ public static function disapprove_suggestion($suggestion_id) { Logger::log("Enter : Network::disapprove_suggestion() | Args: \$suggestion_id = {$suggestion_id}"); // nab the author ID for the suggestion $sql = 'SELECT author_id FROM {contents} WHERE content_id = ?'; $data = array($suggestion_id); $res = Dal::query($sql, $data); if ($res->numRows()) { $row = $res->fetchRow(DB_FETCHMODE_ASSOC); $author_id = intval($row['author_id']); } // and email them $suggestion_user = new User(); $suggestion_user->load($author_id); $check = PAMail::send('suggestion_received', $suggestion_user, PA::$login_user, array()); if ($check == FALSE) { Logger::log("Throwing exception MAIL_FUNCTION_FAILED | Mail was not sent to suggester ", LOGGER_ERROR); throw new PAException(MAIL_FUNCTION_FAILED, "Mail was not sent to suggester"); } ModerationQueue::disapprove_suggestion($suggestion_id); Logger::log("Exit : Network::disapprove_suggestion()"); return; }
if (!empty(PA::$network_info)) { if (!Network::member_exists(PA::$network_info->network_id, $newuser->user_id)) { // check is waiting member Network::join(PA::$network_info->network_id, $newuser->user_id); // no - join to network } else { Network::approve(PA::$network_info->network_id, $newuser->user_id); // yes - approve membership } } // register session register_session($newuser->login_name, $newuser->user_id, $newuser->role, $newuser->first_name, $newuser->last_name, $newuser->email, $newuser->picture); PA::$login_user = $newuser; PA::$login_uid = $newuser->user_id; // send welcome message PAMail::send("welcome_message", $newuser, PA::$network_info, array()); if (!empty($_GET['InvID'])) { // if network invitation $invitation_id = $_GET['InvID']; $inv_error = ""; $error_inv = false; try { $is_valid = Invitation::validate_invitation_id($invitation_id); if (!$is_valid) { throw new PAException(INVALID_INV, "Sorry but the invitation ID you are using is no longer valid."); } $new_invite = new Invitation(); $new_invite->inv_id = $invitation_id; $new_invite->inv_user_id = $newuser->user_id; $new_invite->accept(); } catch (PAException $e) {
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 }
/** !! * 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 = '&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); }
public function handlePOSTPageSubmit($request_data) { if (!empty($request_data['submit'])) { filter_all_post($request_data); if (!empty($request_data['email_user_name'])) { $msg = NULL; $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) { $msg = 6002; //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])) { $msg .= '<br />' . $friend_user_name_array[$counter]; } } } // end for if (!empty($msg) && !is_int($msg)) { $msg = sprintf(__('Following user names are not valid %s'), $msg); } } // end if : if user names are supplied. $invalid = array(); if (!empty($request_data['email_id'])) { $friend_email = trim($request_data['email_id']); $friend_email_array = explode(',', $friend_email); $cnt_email = count($friend_email_array); $self_invite = FALSE; $error = FALSE; // 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 if (PA::$network_info->type == MOTHER_NETWORK_TYPE) { $msg = 6003; } else { $msg = 6001; } $error_email = TRUE; $error = TRUE; } else { if (!empty($friend_email) && !empty($friend_user_name)) { $msg = 7026; $error = TRUE; } else { if (!empty($self_invite)) { // if self invitation is made $msg = 6002; $error_email = TRUE; $error = TRUE; } else { if (sizeof($invalid) > 0) { // if invalid email addresses are supplied $invalid_cnt = count($invalid); $msg = ''; for ($counter = 0; $counter < $invalid_cnt; $counter++) { if (!empty($invalid[$counter])) { $msg .= '<br />' . $invalid[$counter]; } } if (!empty($msg)) { $msg = sprintf(__('Following email addresses are not valid: %s'), $msg); } else { $msg = __(' Invalid Email addresses'); } $error_email = TRUE; $error = TRUE; } else { if (empty($msg)) { // At this point invitation could be made $msg = ''; 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; } } $valid_cnt = count($valid_email); $message = nl2br($request_data['message']); for ($counter = 0; $counter < $valid_cnt; $counter++) { $inv = new Invitation(); $inv->user_id = PA::$login_user->user_id; $inv->username = PA::$login_user->login_name; // for invitation not for any group invitation collection id is -1 $inv->inv_collection_id = -1; $inv->inv_status = INVITATION_PENDING; $auth_token = get_invitation_token(LONG_EXPIRES, $valid_email[$counter]); $token = '&token=' . $auth_token; $inv->register_url = PA::$url . "/" . FILE_REGISTER . "?InvID={$inv->inv_id}"; $inv->accept_url = PA::$url . "/" . FILE_LOGIN . "?action=accept&InvID={$inv->inv_id}{$token}"; $inv->inv_user_id = NULL; $inv->inv_user_first_name = $valid_user_first_emails[$counter]; $inv->inv_email = $valid_email[$counter]; $inv->inv_summary = 'Invitation from' . PA::$login_user->first_name . ' ' . PA::$login_user->last_name . ' to join ' . PA::$site_name; if ($message != CUSTOM_INVITATION_MESSAGE) { $inv->inv_message = !empty($message) ? $message : NULL; } if (empty($error)) { try { $inv->send(); } catch (PAException $e) { $msg = "{$e->message}"; $save_error = TRUE; } } if (isset($save_error) && $save_error == TRUE) { $msg = sprintf(__('Sorry: you are unable to invite a friend. Reason: %s'), $msg); } else { // invitation has been sent, now send mail PAMail::send('invite_pa', $inv->inv_email, PA::$login_user, $inv); $msg .= $valid_user_first_emails[$counter]; if ($counter == $valid_cnt - 1) { $msg = sprintf(__('An Invitation has been sent to - %s'), $msg); } } } // end for : invitation to multiple email } } } } } $this->message = $msg; $this->redirect2 = NULL; $this->queryString = NULL; $this->isError = TRUE; $this->setWebPageMessage(); } }