<?php

// -----------------------------------------------------------------------
// This file is part of aroundme
// 
// Copyright (C) 2003, 2005 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., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
// -----------------------------------------------------------------------

include "inc/header_sn.inc.php";


//setup language
require_once($languageTextPath . 'message.lang.php');


$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($c_node['dir']['class_path'] . 'Mail/class.phpmailer.php');
	$mail = new PHPMailer();
	$mail->Host = 		$c_node['mail']['host'];
	$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']);
	$mail->language = 	$c_node['mail']['language'];
	
	$sn->mail = $mail;
	
	$sn->txt_subject_im_invite = $lang['subject_im_friendship_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($data);
	
	if (empty($GLOBALS['am_error_log'])) {
		$total_emails_sent = $sn->total_emails_sent;
	}
}


//get pending IM relations
$pending_output = $sn->getPendingRelations();


//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);
}

include "inc/footer.inc.php";

?>
