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); }
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); }
$valid_user_first_emails = $valid_user_login_names; } } $valid_cnt = count($valid_email); $invitation_message = nl2br($_POST['message']); for ($counter = 0; $counter < $valid_cnt; $counter++) { $group = new Group(); $group->load((int) $gid); $inv = new Invitation(); $inv->user_id = $login_uid; $inv->username = $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("{$base_url}/register.php?GInvID={$inv->inv_id}", 120, "<br>", 1); $inv->register_url = "<a href=\"{$base_url}/register.php?GInvID={$inv->inv_id}\">{$link_desc}</a>"; $acc_link_desc = wordwrap("{$base_url}/login.php?action=accept&GInvID={$inv->inv_id}{$token}", 120, "<br>", 1); $inv->accept_url = "<a href=\"{$base_url}/login.php?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 = "Invitation from {$user->first_name} {$user->last_name} to join {$group_name}"; $inv->inv_message = !empty($invitation_message) ? $invitation_message : NULL; try { $inv->send(); } catch (PAException $e) { $save_msg = "{$e->message}"; $save_error = TRUE;
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(); } }