<?php
// $Id: mailtoggle.php,v 1.1 2004/07/11 10:27:44 Farsus Exp $
// -------------------------------------------------------------------------//
//			                 RUNCMS                                         //
//                                                                          //
//	 reliable - Unique - Nocost &  Simplicity & ease off use                //
//                       < http://www.runcms.org >                          //
// -------------------------------------------------------------------------//
// Original Author: Half-Dead
// Author Website : http://www.e-xoops.com
// License Type   : Proprietary: See /manual/LICENSES/E-Xoops.txt
// ------------------------------------------------------------------------- //
include_once("../mainfile.php");
include_once(XOOPS_ROOT_PATH."/themes/".getTheme()."/theme.php");
include_once(XOOPS_ROOT_PATH."/class/xoopsmailer.php");

$xoopsMailer = unserialize(urldecode($HTTP_POST_VARS['mail']));
if (!get_class($xoopsMailer) == 'xoopsmailer') {
	exit();
}

xoops_header();
$user_count  = count($xoopsMailer->toUsers);
$email_count = count($xoopsMailer->toEmails);
echo "<br /><div align='center'><h5>".sprintf(_XM_LEFT, ($user_count+$email_count))."</h5></div>";
OpenTable();

if ( $user_count > 0 ) {
	$i=0;
	$toUsers = $xoopsMailer->toUsers;
	foreach ($toUsers as $key => $value) {
		$i++;
		unset($xoopsMailer->errors);
		unset($xoopsMailer->success);
		unset($xoopsMailer->toUsers);
		$xoopsMailer->toUsers[$key] = $value;
		$xoopsMailer->send();
		echo $xoopsMailer->getSuccess();
		echo $xoopsMailer->getErrors();
		unset($toUsers[$key]);
		if ($i == 3) {
			break;
		}
	}
	$xoopsMailer->toUsers = $toUsers;

	} elseif ($email_count > 0) {
		$i=0;
		$toEmails = $xoopsMailer->toEmails;
		foreach ($toEmails as $key => $value) {
			$i++;
			unset($xoopsMailer->errors);
			unset($xoopsMailer->success);
			unset($xoopsMailer->toEmails);
			$xoopsMailer->toEmails[$key] = $value;
			$xoopsMailer->send();
			echo $xoopsMailer->getSuccess();
			echo $xoopsMailer->getErrors();
			unset($toEmails[$key]);
			if ($i == 3) {
				break;
			}
		}
		$xoopsMailer->toEmails = $toEmails;
	}

CloseTable();

if ( !empty($xoopsMailer->toUsers) || !empty($xoopsMailer->toEmails) ) {
	$xoopsMailer = urlencode(serialize($xoopsMailer));
	?>
	<form action="<?php echo XOOPS_URL;?>/include/mailtoggle.php" method="post" id="toggle" name="toggle" target="_self">
	<input type="hidden" name="mail" value="<?php echo $xoopsMailer;?>" />
	<input type="image" class="image" src="<?php echo XOOPS_URL;?>/images/pixel.gif" />
	</form>

	<script type="text/javascript">
		xoopsGetElementById("toggle").submit();
	</script>
	<?php
	} else {
		echo "<br /><div align='center'><input type='button' class='button' value='"._DONE."' onclick='self.close();' /></div>";
	}

xoops_footer(0);
?>
