<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
// 
// Copyright (C) 2003 - 2006 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

include "inc/header_sn.inc.php";

if (isset($me['user_id'])) {
	$sn->im = $im;
	$sn->me = $me;
	$sn->date = $date;
	$sn->relation_type_ids = $c_node['user']['relation_type'];
}

if (isset($_POST['send_invite'])) {
	//get my details
	$user_id = $me['user_id'];
	$user->user_id = $user_id;
	$output_user = $user->getUser();

	//setup email
	require_once('class/Mail/class.phpmailer.php');
	$mail = new PHPMailer();
	$mail->Host = 		$c_node['mail']['host'];
	$mail->Port = 		$c_node['mail']['port'];
	$mail->Mailer = 	$c_node['mail']['mailer'];
	
	if (isset($c_node['mail']['smtp']['username'])) {
		$mail->SMTPAuth = true;
		$mail->Username = $c_node['mail']['smtp']['username'];
		$mail->Password = $c_node['mail']['smtp']['password'];
	}
				
	$mail->From = 		$output_user['user_email'];
	$mail->FromName = 	$output_user['user_firstname'] . " " . $output_user['user_surname'];
	$mail->WordWrap = 	$c_node['mail']['wordwrap'];
	$mail->AddReplyTo($c_node['mail']['no_reply_address'], $lang['subject_noreply']);
	
	$sn->mail = $mail;
	
	$sn->txt_subject_im_invite = $lang['subject_im_relation_invite'];
	
	//get text files
	$body_mail_file = readTxtFile($languageTextPath . "mail_invite.txt.php");
	//echo $body_mail_file;
	$sn->body_mail_file = $body_mail_file;
	
	$body_im_file = readTxtFile($languageTextPath . "im_invite.txt.php");
	//$body_im_file = htmlspecialchars($body_im_file);
	$sn->body_im_file = $body_im_file;
	
	//send invites
	$sn->sendInvite($frmdata);
	
	if (empty($GLOBALS['am_error_log'])) {
		$total_emails_sent = $sn->total_emails_sent;
	}
}

if (isset($me['user_id']) && $user_acs->checkPermission($c_acs['arr_acs']['resource']['node']['network'], $c_acs['arr_acs']['privilege']['allow_network_ext'])) { //resourece_id, Priv_id
	//get pending IM relations
	$pending_output = $sn->getPendingRelations();
	
	$display = "invite";
}



//move to template
if (!empty($total_emails_sent)) {
    $body->set('total_emails_sent', $total_emails_sent);
}

if (!empty($pending_output)) {
    $body->set('pending', $pending_output);
}

if (!empty($display)) {
    $body->set('display', $display);
}

include "inc/footer.inc.php";

?>
