<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
/********************************************************/
/* 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");
}
global $admin_file;
if (defined("NSNGROUPS_IS_LOADED")) $grconfig = grget_configs();
else $op = 'NSNGroupsLoadError';
$aid = substr("$aid", 0,25);
$row = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `radminsuper` FROM `".TABLE_AUTHORS."` WHERE `aid`='$aid'"));
$acces = $GLOBALS['db']->XMFbin($row['radminsuper']);
if ($acces == 1) {

$gr_config = grget_configs();

if(!isset($lang)) { $lang = $language; }
if (!stristr("$lang", ".") AND file_exists($lang_dir."language/groups/lang-$lang.php")) {
if (is_file($lang_dir."language/groups/lang-$lang.php")) {
  include_once($lang_dir."language/groups/lang-$lang.php");}
} else {
if (is_file($lang_dir."language/groups/lang-english.php")) {
  include_once($lang_dir."language/groups/lang-english.php");}
}

if($admintest && $adminsecu)  {

function grsave_config($config_name, $config_value){
    $GLOBALS['db']->sql_query("UPDATE `".TABLE_NSNGR_CONFIG."` SET `config_value`='$config_value' WHERE `config_name`='$config_name'");
}

function NSNGroupsAdmin() {
    global $admin_file;
    $sql = "SELECT `gname` FROM `".TABLE_NSNGR_GROUPS."`";
    if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(GENERAL_ERROR, 'Could not obtain config index', '', __LINE__, __FILE__, $sql);}
    $grpnum = $GLOBALS['db']->sql_numrows($result);
    $sql1 = "SELECT `gid` FROM `".TABLE_NSNGR_USERS."`";
    if ( !($result1 = $GLOBALS['db']->sql_query($sql1)) )
{ query_die(GENERAL_ERROR, 'Could not obtain config index', '', __LINE__, __FILE__, $sql1);}
    $usrnum = $GLOBALS['db']->sql_numrows($result1);
    Max_OpenTable();
    echo "<center>\n<table cellpadding=\"3\">\n<tr>\n"
        ."<td align=\"center\" valign=\"top\" width=\"150\">"
        ."<a href=\"".$admin_file.".php?op=NSNGroupsAdd\">"._GR_GROUPSADD."</a><br />"
        ."<a href=\"".$admin_file.".php?op=NSNGroupsView\">"._GR_GROUPSVIEW."</a> ($grpnum)<br />"
        ."</td>\n"
        ."<td align=\"center\" valign=\"top\" width=\"150\">"
        ."<a href=\"".$admin_file.".php?op=NSNGroupsUsersEmail\">"._GR_GROUPSEMAIL."</a><br />"
        ."<a href=\"".$admin_file.".php?op=NSNGroupsConfig\">"._GR_GROUPSCONFIG."</a><br />"
        ."</td>\n"
        ."<td align=\"center\" valign=\"top\" width=\"150\">"
        ."<a href=\"".$admin_file.".php?op=NSNGroupsUsersAdd\">"._GR_GROUPSUSERSADD."</a><br />"
        ."<a href=\"".$admin_file.".php?op=NSNGroupsUsersView\">"._GR_GROUPSUSERSVIEW."</a> ($usrnum)<br />"
        ."</td>\n"
        ."</tr>\n"
        ."<tr>\n<td colspan=\"3\" align=\"center\"><a href=\"".$admin_file.".php\">"._MAINADMINMENU."</a></td>\n</tr>\n"
        ."</table>\n</center>\n";
    Max_CloseTable();
}

function grpagenums($op, $totalselected, $perpage, $max, $gid) {
    global $admin_file;

    $pagesint = ($totalselected / $perpage);
    $pageremainder = ($totalselected % $perpage);
    if ($pageremainder != 0) {
        $pages = ceil($pagesint);
        if ($totalselected < $perpage) { $pageremainder = 0; }
    } else {
        $pages = $pagesint;
    }
    if ($pages != 1 && $pages != 0) {
        $counter = 1;
        $currentpage = ($max / $perpage);
        echo "<table align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">\n"
            ."<tr><form action=\"".$admin_file.".php\" method=\"post\">\n"
            ."<input type=\"hidden\" name=\"op\" value=\"$op\">\n"
            ."<input type=\"hidden\" name=\"gid\" value=\"$gid\">\n"
            ."<td align=\"center\"><b>"._GR_SELECTPAGE.": </b><select name=\"min\">\n";
        while ($counter <= $pages ) {
            $cpage = $counter;
            $mintemp = ($perpage * $counter) - $perpage;
            echo "<option value=\"$mintemp\"";
            if ($counter == $currentpage) { echo " selected"; }
            echo ">$counter</option>\n";
            $counter++;
        }
        echo "</select><b> "._GR_OF." $pages "._GR_PAGES."</b> <input type=\"submit\" value=\""._GR_GO."\"></td>\n"
            ."</form>\n</tr>\n</table>\n";
    }
}

function grformcheck($field_r, $field_d) {
  echo "<script type=\"text/JavaScript\">\n"
      ."<!--\n"
      ."function formCheck(formobj){\n"
      ."  // name of mandatory fields\n"
      ."  var fieldRequired = Array(".$field_r.");\n"
      ."  // field description to appear in the dialog box\n"
      ."  var fieldDescription = Array(".$field_d.");\n"
      ."  // dialog message\n"
      ."  var alertMsg = \"Please complete the following fields:\\n\";\n"
      ."  var l_Msg = alertMsg.length;\n"
      ."  for (var i = 0; i < fieldRequired.length; i++){\n"
      ."    var obj = formobj.elements[fieldRequired[i]];\n"
      ."    if (obj){\n"
      ."      switch(obj.type){\n"
      ."        case \"select-one\":\n"
      ."          if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == \"\"){\n"
      ."            alertMsg += \" - \" + fieldDescription[i] + \"\\n\";\n"
      ."          }\n"
      ."          break;\n"
      ."        case \"select-multiple\":\n"
      ."          if (obj.selectedIndex == -1){\n"
      ."            alertMsg += \" - \" + fieldDescription[i] + \"\\n\";\n"
      ."          }\n"
      ."          break;\n"
      ."        case \"text\":\n"
      ."        case \"textarea\":\n"
      ."          if (obj.value == \"\" || obj.value == null){\n"
      ."            alertMsg += \" - \" + fieldDescription[i] + \"\\n\";\n"
      ."          }\n"
      ."          break;\n"
      ."        default:\n"
      ."      }\n"
      ."      if (obj.type == undefined){\n"
      ."        var blnchecked = false;\n"
      ."        for (var j = 0; j < obj.length; j++){\n"
      ."          if (obj[j].checked){\n"
      ."            blnchecked = true;\n"
      ."          }\n"
      ."        }\n"
      ."        if (!blnchecked){\n"
      ."          alertMsg += \" - \" + fieldDescription[i] + \"\\n\";\n"
      ."        }\n"
      ."      }\n"
      ."    }\n"
      . "  }\n"
      ."  if (alertMsg.length == l_Msg){\n"
      ."    return true;\n"
      ."  }else{\n"
      ."    alert(alertMsg);\n"
      ."    return false;\n"
      ."  }\n"
      ."}\n"
      ."// -->\n"
      ."</script>\n";
}

switch($op) {

    case 'NSNGroups':include('admin/modules/nsngroups/NSNGroups.php');break;
    case 'NSNGroupsAdd':include('admin/modules/nsngroups/NSNGroupsAdd.php');break;
    case 'NSNGroupsAddSave':include('admin/modules/nsngroups/NSNGroupsAddSave.php');break;
    case 'NSNGroupsConfig':include('admin/modules/nsngroups/NSNGroupsConfig.php');break;
    case 'NSNGroupsConfigSave':include('admin/modules/nsngroups/NSNGroupsConfigSave.php');break;
    case 'NSNGroupsDelete':include('admin/modules/nsngroups/NSNGroupsDelete.php');break;
    case 'NSNGroupsDeleteConf':include('admin/modules/nsngroups/NSNGroupsDeleteConf.php');break;
    case 'NSNGroupsEdit':include('admin/modules/nsngroups/NSNGroupsEdit.php');break;
    case 'NSNGroupsEditSave':include('admin/modules/nsngroups/NSNGroupsEditSave.php');break;
    case 'NSNGroupsEmpty':include('admin/modules/nsngroups/NSNGroupsEmpty.php');break;
    case 'NSNGroupsEmptyConf':include('admin/modules/nsngroups/NSNGroupsEmptyConf.php');break;
    case 'NSNGroupsLoadError':include('admin/modules/nsngroups/NSNGroupsLoadError.php');break;
    case 'NSNGroupsUsersAdd':include('admin/modules/nsngroups/NSNGroupsUsersAdd.php');break;
    case 'NSNGroupsUsersAddSave':include('admin/modules/nsngroups/NSNGroupsUsersAddSave.php');break;
    case 'NSNGroupsUsersDelete':include('admin/modules/nsngroups/NSNGroupsUsersDelete.php');break;
    case 'NSNGroupsUsersDeleteConf':include('admin/modules/nsngroups/NSNGroupsUsersDeleteConf.php');break;
    case 'NSNGroupsUsersDeleteSave':include('admin/modules/nsngroups/NSNGroupsUsersDeleteSave.php');break;
    case 'NSNGroupsUsersEmail':include('admin/modules/nsngroups/NSNGroupsUsersEmail.php');break;
    case 'NSNGroupsUsersEmailSend':include('admin/modules/nsngroups/NSNGroupsUsersEmailSend.php');break;
    case 'NSNGroupsUsersExpire':include('admin/modules/nsngroups/NSNGroupsUsersExpire.php');break;
    case 'NSNGroupsUsersExpireDone':include('admin/modules/nsngroups/NSNGroupsUsersExpireDone.php');break;
    case 'NSNGroupsUsersExpireSave':include('admin/modules/nsngroups/NSNGroupsUsersExpireSave.php');break;
    case 'NSNGroupsUsersMove':include('admin/modules/nsngroups/NSNGroupsUsersMove.php');break;
    case 'NSNGroupsUsersMoveSave':include('admin/modules/nsngroups/NSNGroupsUsersMoveSave.php');break;
    case 'NSNGroupsUsersUpdate':include('admin/modules/nsngroups/NSNGroupsUsersUpdate.php');break;
    case 'NSNGroupsUsersUpdateSave':include('admin/modules/nsngroups/NSNGroupsUsersUpdateSave.php');break;
    case 'NSNGroupsUsersView':include('admin/modules/nsngroups/NSNGroupsUsersView.php');break;
    case 'NSNGroupsView':include('admin/modules/nsngroups/NSNGroupsView.php');break;

}
}
} else {
    echo "Access Denied";
}