<?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");
}

$gname = strip_tags($gname, "<b><i><u>");
$gdesc = strip_tags($gdesc, "<br /><b><i><u>");
$gname = stripslashes($gname);
$gdesc = stripslashes($gdesc);
$mname = strip_tags($mname);
$mname = stripslashes($mname);
if ($gname == "" || $mname == "") {
  incoh();
  Max_OpenTable();
  echo "<center><b>"._GR_MISSINGDATA."</b></center><br />\n";
  echo "<center>"._GOBACK."</center>\n";
  Max_CloseTable();
  incof();
}
if (!get_magic_quotes_gpc()) { $gname = addslashes($gname); $gdesc = addslashes($gdesc); }
list($phpBB) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `phpBB` FROM `".TABLE_NSNGR_GROUPS."` WHERE `gid`='$gid'"));
list($muid) = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".TABLE_USERS."` WHERE `username`='$mname'"));
$GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNGR_GROUPS."` SET `gname`='$gname', `gdesc`='$gdesc', `gpublic`='$gpublic', `glimit`='$glimit', `muid`='$muid' WHERE `gid`='$gid'");
$GLOBALS['db']->sql_query("UPDATE `".$prefix."_bbgroups` SET `group_name`='$gname', `group_description`='$gdesc', `group_moderator`='$muid' WHERE `group_id`='$phpBB'");
$GLOBALS['db']->sql_query("OPTIMIZE TABLE `".TABLE_NSNGR_GROUPS."`");
$GLOBALS['db']->sql_query("OPTIMIZE TABLE `".$prefix."_bbgroups`");
if($muid <> $old_muid) {
  $stime = time();
  $GLOBALS['db']->sql_query("DELETE FROM `".TABLE_NSNGR_USERS."` WHERE `gid`='$gid' AND `uid`='$old_muid'");
  $GLOBALS['db']->sql_query("DELETE FROM `".$prefix."_bbuser_group` WHERE `group_id`='$phpBB' AND `user_id`='$old_muid'");
  $gidnum = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `uid` FROM `".TABLE_NSNGR_USERS."` WHERE `gid`='$gid' AND `uid`='$muid'"));
  $phpnum = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `user_id` FROM `".$prefix."_bbuser_group` WHERE `group_id`='$phpBB' AND `user_id`='$muid'"));
  if(!$gidnum || $gidnum == 0) {$GLOBALS['db']->sql_query("INSERT INTO `".TABLE_NSNGR_USERS."` VALUES ('$gid', '$muid', '$mname' , '0', '0', '$stime', '0')"); }
  if(!$phpnum || $phpnum == 0) {$GLOBALS['db']->sql_query("INSERT INTO` ".$prefix."_bbuser_group` VALUES ('$phpBB', '$muid', '0')"); }
  $GLOBALS['db']->sql_query("OPTIMIZE TABLE `".TABLE_NSNGR_USERS."`");
  $GLOBALS['db']->sql_query("OPTIMIZE TABLE `".$prefix."_bbuser_group`");
}
redirect_url("".$admin_file.".php?op=NSNGroupsView");