mode = PUB; $obj->uid = $login_uid; $obj->block_type = 'media_management'; if ($module=='InvitationStatusModule') { $groups = Group::get_user_groups($login_uid, FALSE, 'ALL'); $user_groups = array(); for ( $i=0; $icollection_id_array = $user_groups; } else if ($module=='GroupInvitationModule') { $obj->entered_people = $entered_people; } break; } } // array of first names / last names / email addresses to be displayed if there was an error $entered_people = array(); $array_msg = array(); if($_POST['do']=='SendInvite') { filter_all_post($_POST); $error = FALSE; $msg = array(); // check if groups are there if ( empty( $_POST['groups'] ) ) { $error = TRUE; $array_msg[]= "Please select group"; } //check email and first name $empty = TRUE; foreach ($_POST['email'] as $i => $email) { $email = trim($email); $included = (@$_POST['included'][$i] == "on"); $fname = trim($_POST['firstname'][$i]); $lname = trim($_POST['lastname'][$i]); if (!$included || (!$email && !$fname && !$lname)) continue; $e = NULL; if (empty($email)) { $e = "Please enter an email address."; } else if ($email == $_SESSION['user']['email']) { $e = "You can't invite yourself"; } else if (!validate_email($email)) { $e = "Please enter a valid email address"; } else if (empty($fname)) { $e = "Please enter a first name for this person"; } if (!empty($email) || !empty($fname) || !empty($lname)) { $empty = FALSE; } $entered_people[] = array( 'email' => $email, 'firstname' => $fname, 'lastname' => $lname, 'error' => $e, ); if ($e) { $error = TRUE; $array_msg[] = $e; } } if ($empty) { $error = TRUE; $array_msg[] = "Please enter at least one person to invite"; } $subject = GROUP_INVITE_SUBJECT; $subject = str_replace("%first_name%", $_SESSION['user']['first_name'], $subject); $subject = str_replace("%last_name%", $_SESSION['user']['last_name'], $subject); $message = trim($_POST['message']); if ( empty( $message ) ) { $error = TRUE; $array_msg[] = "Message can't be left blank"; } // if no error send the invitation if ( !$error ) { /* for ( $i = 0; $i < count($_POST['groups']); $i++ ) {*/ foreach ($entered_people as $person) { if (!$person['email']) continue; $gid = (int)$_POST['groups']; $group = new Group(); $group->load($gid); $inv = new Invitation(); $inv->user_id = $_SESSION['user']['id']; $inv->username = $_SESSION['user']['name']; // for invitation not for any group invitation collection id is -1 //$inv->inv_collection_id = $_POST['groups'][$i]; $inv->inv_collection_id = $gid; $inv->inv_group_name = $group->title; $inv->inv_status = PENDING; $inv->register_url = $base_url."/register.php?GInvID=".$inv->inv_id; $inv->accept_url = $base_url."/login.php?action=accept&GInvID=".$inv->inv_id; $inv->inv_user_id = NULL; $inv->inv_username = NULL; $inv->inv_user_first_name = $person['firstname']; $inv->inv_user_last_name = $person['lastname']; $inv->inv_email = $person['email']; $inv->inv_summary = "Invitation from $user->first_name $user->last_name to join PeopleAggregator"; $inv->inv_message = $message; try { $inv->send(); $success = 1; $array_msg[] = "Successfully sent invitation to ".$person['email']."."; } catch (PAException $e) { $array_msg[] = "$e->message"; $error = TRUE; } }//..foreach } //..$error if if ( count($array_msg)>0 ) { $msg = ""; for ($i=0;$iset('message', $msg); $page->add_module("middle", "top", $msg_tpl->fetch()); } if ($show_options) { $page->header->show_options = TRUE; } echo $page->render(); ?>