<?php
/********************************************************/
/* NSN Groups                                           */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright  2000-2005 by NukeScripts Network         */
/********************************************************/
if (!defined('ADMIN_ALLOW') && !defined('ADMIN_MAX')) {
	die ("Access Denied");
}

$gcontent = stripslashes($gcontent);
$headers  = "MIME-Version: 1.0\n";
if ($etype < 1) {
  $headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
  $gcontent .= "\n--------------------\n"._GR_THANK.";\n$aname <$amail>";
} else {
  $headers .= "Content-Type: text/html; charset=iso-8859-1\n";
  $gcontent .= "<hr>"._GR_THANK.";<br /><a href='mailto:$amail'>$aname</a>";
}
$headers .= "From: $aname <$amail>\r\n";
$headers .= "Return-Path: $amail\r\n";
$headers .= "Reply-To: $amail\r\n";
$headers .= "X-Mailer: NSN Groups";
if ($gid == 0) {
  $gsubject = "[$sitename "._GR_GLET."]: ".stripslashes($gsubject)."";
  $result = $GLOBALS['db']->sql_query("SELECT `uid` FROM `".$user_prefix."_nsngr_users`");
  while(list($guid) = $GLOBALS['db']->sql_fetchrow($result)) {
    list($email) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `user_email` FROM `".TABLE_USERS."` WHERE `user_id`='$guid'"));
    $to = ""._GR_GLET." <$email>";
    mail($to, $gsubject, $gcontent, $headers);
  }
  redirect_url("".$admin_file.".php?op=NSNGroups");
} else {
  list($gname) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."` WHERE `gid`='$gid'"));
  $gsubject = "[$gname "._GR_GLET."]: ".stripslashes($gsubject)."";
  $result = $GLOBALS['db']->sql_query("SELECT `uid` FROM `".TABLE_NSNGR_USERS."` WHERE `gid`='$gid'");
  while(list($guid) = $GLOBALS['db']->sql_fetchrow($result)) {
    list($email) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `user_email` FROM `".TABLE_USERS."` WHERE `user_id`='$guid'"));
    $to = "$gname <$email>";
    mail($to, $gsubject, $gcontent, $headers);
  }
  redirect_url("".$admin_file.".php?op=NSNGroups");
}