<?php
// +---------------------------------------------+
// |     Copyright  2003 - 2005 weenCompany      |
// |     http://www.weentech.com                 |
// |     This file may not be redistributed.     |
// +---------------------------------------------+

define('IN_ADMIN', true);
define('IN_WEENCOMPANY', true);

$rootpath = "./../";

include($rootpath . 'includes/core.php');

PrintHeader('群组设置');

// get the value of $action
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : 'displaydefault');

// module bitfield data
$modulebitfield = array('canview'     => 1,
                        'cansubmit'   => 2,
                        'candownload' => 4,
                        'cancomment'  => 8,
                        'canadmin'    => 16);



// ############################## DELETE USERGROUP #############################

if($action == 'deleteusergroup')
{
  $usergroupid   = isset($_GET['usergroupid']) ? $_GET['usergroupid'] : $_POST['usergroupid'];
  $confirmdelete = isset($_POST['confirmdelete']) ? $_POST['confirmdelete'] : '0';

  if($confirmdelete == ' 取消 ')
  {
    $action = 'displaydefault';
  }
  else if($confirmdelete == '0')
  {
    // get the usergroupname
    $usergroup = $DB->query_first("SELECT name FROM " . TABLE_PREFIX . "usergroups WHERE usergroupid = $usergroupid");

    $description = '<b>删除群组: "' . $usergroup['name'] . '"?</b><br /><br />
                    注: 删除群组后, 属于此群组的所有用户将转至"注册用户"组.';

    $hiddenvalues = '<input type="hidden" name="usergroupid" value="' . $usergroupid . '" />
                     <input type="hidden" name="action" value="deleteusergroup" />';

    // arguments: description, hidden input values, form redirect page
    ConfirmDelete($description, $hiddenvalues, 'usergroups.php');
  }
  else if($confirmdelete == ' 确定 ')
  {
    $DB->query("DELETE FROM " . TABLE_PREFIX . "usergroups WHERE usergroupid = '" . $usergroupid . "'");
    $DB->query("UPDATE " . TABLE_PREFIX . "users SET usergroupid = 3 WHERE usergroupid = '" . $usergroupid . "'");
    // redirect
    PrintRedirect('usergroups.php', 1);
  }
}



// ############################# INSERT USERGROUP ##############################

if($action == 'insertusergroup')
{
  $name                  = trim($_POST['name']);
  if ($name == '')
  {
   Errmsg('请输入群组名称!');
  }
  
  $usergroupid           = $_POST['usergroupid'];  // set to 0
  $forumusergroupid      = isset($_POST['forumusergroupid']) ? $_POST['forumusergroupid'] : 0;

  $adminaccess           = $_POST['adminaccess'];
  $commentaccess         = $_POST['commentaccess'];
  $offlinecategoryaccess = $_POST['offlinecategoryaccess'];

  $categoryviewids       = @implode(',', $_POST['categoryviewids']);
  $categorymenuids       = @implode(',', $_POST['categorymenuids']);

  $moduleviewids         = @implode(',', $_POST['moduleviewids']);
  $modulesubmitids       = @implode(',', $_POST['modulesubmitids']);
  $moduledownloadids     = @implode(',', $_POST['moduledownloadids']);
  $modulecommentids      = @implode(',', $_POST['modulecommentids']);
  $moduleadminids        = @implode(',', $_POST['moduleadminids']);

  $custommoduleviewids   = @implode(',', $_POST['custommoduleviewids']);
  $custommoduleadminids  = @implode(',', $_POST['custommoduleadminids']);

  $DB->query("INSERT INTO " . TABLE_PREFIX . "usergroups
              VALUES ('$usergroupid', '$forumusergroupid', '$name', '$adminaccess', '$commentaccess', '$offlinecategoryaccess', '$categoryviewids', '$categorymenuids',
                      '$moduleviewids', '$modulesubmitids', '$moduledownloadids', '$modulecommentids', '$moduleadminids', '$custommoduleviewids', '$custommoduleadminids') ");

  PrintRedirect('./usergroups.php?action=editusergroup&usergroupid=' . $DB->insert_id(), 1);
}



// ############################# UPDATE USERGROUP ##############################

if($action == 'updateusergroup')
{
  $name                  = trim($_POST['name']);
  if ($name == '')
  {
	   Errmsg('群组名称不能为空!');
  }
  $usergroupid           = $_POST['usergroupid'];
  $forumusergroupid      = isset($_POST['forumusergroupid']) ? $_POST['forumusergroupid'] : 0;

  $adminaccess           = $_POST['adminaccess'];
  $commentaccess         = $_POST['commentaccess'];
  $offlinecategoryaccess = $_POST['offlinecategoryaccess'];

  $categoryviewids       = @implode(',', $_POST['categoryviewids']);
  $categorymenuids       = @implode(',', $_POST['categorymenuids']);

  $moduleviewids         = @implode(',', $_POST['moduleviewids']);
  $modulesubmitids       = @implode(',', $_POST['modulesubmitids']);
  $moduledownloadids     = @implode(',', $_POST['moduledownloadids']);
  $modulecommentids      = @implode(',', $_POST['modulecommentids']);
  $moduleadminids        = @implode(',', $_POST['moduleadminids']);

  $custommoduleviewids   = @implode(',', $_POST['custommoduleviewids']);
  $custommoduleadminids  = @implode(',', $_POST['custommoduleadminids']);

  $DB->query("UPDATE " . TABLE_PREFIX . "usergroups SET forumusergroupid= '$forumusergroupid',
                                                        name= '$name',
                                                        adminaccess           = '$adminaccess',
                                                        commentaccess         = '$commentaccess',
                                                        offlinecategoryaccess = '$offlinecategoryaccess',
                                                        categoryviewids       = '$categoryviewids',
                                                        categorymenuids       = '$categorymenuids',
                                                        moduleviewids         = '$moduleviewids',
                                                        modulesubmitids       = '$modulesubmitids',
                                                        moduledownloadids     = '$moduledownloadids',
                                                        modulecommentids      = '$modulecommentids',
                                                        moduleadminids        = '$moduleadminids',
                                                        custommoduleviewids   = '$custommoduleviewids',
                                                        custommoduleadminids  = '$custommoduleadminids'
                                                  WHERE usergroupid           = '$usergroupid'");

  echo '<BODY onLoad="parent.leftFrame.location.reload(true)">';
  PrintRedirect('./usergroups.php?action=editusergroup&usergroupid=' . $usergroupid, 1);
}



// ############################## DISPLAY DEFAULT ##############################

if($action == 'displaydefault')
{
  global $stylepath;

  // get the current usergroups
  $getusergroups = $DB->query("SELECT usergroupid, forumusergroupid, name FROM " . TABLE_PREFIX . "usergroups ORDER BY usergroupid");
  $usergrouprows = $DB->get_num_rows($getusergroups);

  PrintSection('创建用户组');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1" colspan="2">创建用户组</td>
        </tr>
        <tr>
          <td class="tdrow2" width="70%">创建新的用户群组:</td>
          <td class="tdrow3">
            <form method="post" action="usergroups.php">
            <input type="hidden" name="action" value="createusergroup" />
            <input type="submit" value=" 创建群组 " />
            </form>
          </td>
        </tr>
        </table>';
  EndSection();

  PrintSection('群组权限设置');
  if($usergrouprows)
  {
    if($forum = $DB->query_first("SELECT name FROM " . TABLE_PREFIX . "usersystems WHERE activated = '1' AND name != 'weenCompany'"))
    {
      $forumintegration = 1;
    }
    else
    {
      $forumintegration = 0;
    }

    echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
		  <tr>
            <td class="tdrow1" colspan="3">群组权限说明</td>
          </tr>
		  <tr>
            <td class="tdrow3" colspan="3">默认状态下, 群组权限说明:<br/>1. 系统管理员: 所有网站权限.<br/>2. 信息管理员: 所有模块设置及内容管理权限.<br/>3. 注册用户: 网站前台发表评论, 文章, 图片等权限.<br/>4. 游客: 权限等同于未注册用户.</td>
          </tr>
		  <tr>
            <td class="tdrow1">群组名称</td>
            ' . iif(!$forumintegration, '<td class="tdrow1">用户数量</td>') . '
            <td class="tdrow1">删除</td>
          </tr>';

    // usergroupids that can't be deleted
    $dontdeleteids = array(1, 2, 3, 4);

    while($usergroup = $DB->fetch_array($getusergroups))
    {
      if($forumintegration == 0)
      {
        $totalusergroupusers = $DB->query_first("SELECT COUNT(*) AS value FROM " . TABLE_PREFIX . "users WHERE usergroupid = '" . $usergroup['usergroupid'] . "'");
      }

      echo '<tr>
              <td class="tdrow2"><a href="./usergroups.php?action=editusergroup&usergroupid=' . $usergroup['usergroupid'] . '">' . iif(strlen($usergroup['name']), $usergroup['name'], '未命名') . '</a>&nbsp;(ID: '.$usergroup['usergroupid'].')</td>
              ' . iif(!$forumintegration, '<td class="tdrow3">' . $totalusergroupusers['value'] . '</td>') . '
              <td class="tdrow2">' . iif(in_array($usergroup['usergroupid'], $dontdeleteids), '<img src="' . $stylepath . 'images/notrash.gif" />', '<a href="usergroups.php?action=deleteusergroup&usergroupid=' . $usergroup['usergroupid'] . '"><img src="' . $stylepath . 'images/trash.gif" /></a>') . '</td>
            </tr>';
    }
  }

  echo '</table>';
  EndSection();
}



// ######################## DISPLAY MODULES PERMISSIONS ########################

function DisplayModulesPermissions($modules, $modulestype, $formgroup)
{
  global $DB, $modulebitfield, $moduleviewids, $modulesubmitids, $moduledownloadids,
         $modulecommentids, $moduleadminids, $custommoduleviewids, $custommoduleadminids;

  // return if there are no rows to print
  if($DB->get_num_rows($modules) == 0)
  {
    return;
  }

  // print label columns
    echo '<tr>
            <td class="tdrow1" width="12.5%">' . $modulestype . '</td>
            <td class="tdrow1" width="12.5%"><input type="checkbox" checkall="view_' . $formgroup . '" onclick="javascript: return select_deselectAll (\'usergroups\', this, \'view_' . $formgroup . '\');"> 允许查看</td>
            <td class="tdrow1" width="12.5%"><input type="checkbox" checkall="submit_' . $formgroup . '" onclick="javascript: return select_deselectAll (\'usergroups\', this, \'submit_' . $formgroup . '\');"> 允许发表</td>
            <td class="tdrow1" width="12.5%"><input type="checkbox" checkall="download_' . $formgroup . '" onclick="javascript: return select_deselectAll (\'usergroups\', this, \'download_' . $formgroup . '\');"> 允许下载</td>
            <td class="tdrow1" width="12.5%"><input type="checkbox" checkall="comment_' . $formgroup . '" onclick="javascript: return select_deselectAll (\'usergroups\', this, \'comment_' . $formgroup . '\');"> 允许评论</td>
            <td class="tdrow1" width="12.5%" style="background: #FF7D7D; color: #000000; border: 1px solid #000000;"><input type="checkbox" checkall="admin_' . $formgroup . '" onclick="javascript: return select_deselectAll (\'usergroups\', this, \'admin_' . $formgroup . '\');"> 允许管理</td>
          </tr>';


  // start printing the modules
  if($modulestype == '自定义模块')
  {
    while($module = $DB->fetch_array($modules))
    {
      $canviewstatus     = in_array($module['custommoduleid'], $custommoduleviewids)     ? 'CHECKED' : '';
      $canadminstatus    = in_array($module['custommoduleid'], $custommoduleadminids)    ? 'CHECKED' : '';

      echo '<tr>
              <td class="tdrow2">' . $module['name'] . '</td>
              <td class="tdrow3">' . iif($module['settings'] & $modulebitfield['canview'],     '<input type="checkbox" name="custommoduleviewids[]"     value="' . $module['custommoduleid'] . '" ' . $canviewstatus     . '  checkme="view_' . $formgroup . '" />', '<input type="checkbox" DISABLED/>') . '</td>
              <td class="tdrow2"><input type="checkbox" DISABLED/></td>
              <td class="tdrow3"><input type="checkbox" DISABLED/></td>
              <td class="tdrow2"><input type="checkbox" DISABLED/></td>
              <td class="tdrow3">' . iif($module['settings'] & $modulebitfield['canadmin'],    '<input type="checkbox" name="custommoduleadminids[]"    value="' . $module['custommoduleid'] . '" ' . $canadminstatus    . ' checkme="admin_' . $formgroup . '" />', '<input type="checkbox" DISABLED/>') . '</td>
            </tr>';
    }
  }
  else
  {
    while($module = $DB->fetch_array($modules))
    {
      $canviewstatus     = in_array($module['moduleid'], $moduleviewids)     ? 'CHECKED' : '';
      $cansubmitstatus   = in_array($module['moduleid'], $modulesubmitids)   ? 'CHECKED' : '';
      $candownloadstatus = in_array($module['moduleid'], $moduledownloadids) ? 'CHECKED' : '';
      $cancommentstatus  = in_array($module['moduleid'], $modulecommentids)  ? 'CHECKED' : '';
      $canadminstatus    = in_array($module['moduleid'], $moduleadminids)    ? 'CHECKED' : '';

      echo '<tr>
              <td class="tdrow2">' . $module['name'] . '</td>
              <td class="tdrow3">' . iif($module['settings'] & $modulebitfield['canview'],     '<input type="checkbox" name="moduleviewids[]"     value="' . $module['moduleid'] . '" ' . $canviewstatus     . ' checkme="view_' . $formgroup . '"  />', '<input type="checkbox" DISABLED/>') . '</td>
              <td class="tdrow2">' . iif($module['settings'] & $modulebitfield['cansubmit'],   '<input type="checkbox" name="modulesubmitids[]"   value="' . $module['moduleid'] . '" ' . $cansubmitstatus   . ' checkme="submit_' . $formgroup . '" />', '<input type="checkbox" DISABLED/>') . '</td>
              <td class="tdrow3">' . iif($module['settings'] & $modulebitfield['candownload'], '<input type="checkbox" name="moduledownloadids[]" value="' . $module['moduleid'] . '" ' . $candownloadstatus . ' checkme="download_' . $formgroup . '" />', '<input type="checkbox" DISABLED/>') . '</td>
              <td class="tdrow2">' . iif($module['settings'] & $modulebitfield['cancomment'],  '<input type="checkbox" name="modulecommentids[]"  value="' . $module['moduleid'] . '" ' . $cancommentstatus  . ' checkme="comment_' . $formgroup . '" />', '<input type="checkbox" DISABLED/>') . '</td>
              <td class="tdrow3">' . iif($module['settings'] & $modulebitfield['canadmin'],    '<input type="checkbox" name="moduleadminids[]"    value="' . $module['moduleid'] . '" ' . $canadminstatus    . ' checkme="admin_' . $formgroup . '" />', '<input type="checkbox" DISABLED/>') . '</td>
            </tr>';
    }
  }
}


// ############################ DISPLAY CATEGORIES #############################
function DisplayCategories($categorymenuids, $categoryviewids, $parentid = 0, $sublevelmarker = '')
{
  global $DB;
  global $listedcategories; 

  // start table
  if($parentid != 0)
  {
    $sublevelmarker .= '- ';
  }

  $getcategories = $DB->query("SELECT categoryid, name, parentid FROM " . TABLE_PREFIX . "categories WHERE parentid = $parentid ORDER BY displayorder");

  while($category = $DB->fetch_array($getcategories))
  {
    $listedcategories[] = $category['name'];
    $menuitemstatus  = in_array($category['categoryid'], $categorymenuids) ? 'CHECKED' : '';
    $canaccessstatus = in_array($category['categoryid'], $categoryviewids) ? 'CHECKED' : '';

    echo '<tr>
            <td class="tdrow2">' . $sublevelmarker . iif(strlen($category['name']), $category['name'], '<b>未命名</b>') . '</td>
            <td class="tdrow3"><input type="checkbox" name="categorymenuids[]" value="' . $category['categoryid'] . '" ' . $menuitemstatus  . ' checkme="display" /></td>
            <td class="tdrow2"><input type="checkbox" name="categoryviewids[]" value="' . $category['categoryid'] . '" ' . $canaccessstatus . ' checkme="view" /></td>
          </tr>';

    DisplayCategories($categorymenuids, $categoryviewids, $category['categoryid'], $sublevelmarker);
  }
}

// ########################## DISPLAY USERGROUP FORM ###########################

if($action == 'createusergroup' OR $action == 'editusergroup')
{
  if($action == 'createusergroup')
  {
    $usergroup = array('usergroupid'           => 0,
                       'name'                  => '',
                       'forumusergroupid'      => 0,
                       'adminaccess'           => 0,
                       'commentaccess'         => 0,
                       'offlinecategoryaccess' => 0);

    $categoryviewids   = array();
    $categorymenuids   = array();

    $moduleviewids     = array();
    $modulesubmitids   = array();
    $moduledownloadids = array();
    $modulecommentids  = array();
    $moduleadminids    = array();

    $custommoduleviewids  = array();
    $custommoduleadminids = array();

    PrintSection('创建群组');
  }
  else if($action == 'editusergroup')
  {
    $usergroupid = isset($_POST['usergroupid']) ? $_POST['usergroupid'] : $_GET['usergroupid'];
    $usergroup = $DB->query_first("SELECT * FROM " . TABLE_PREFIX . "usergroups WHERE usergroupid = '$usergroupid'");

    $categoryviewids   = @explode(',', $usergroup['categoryviewids']);
    $categorymenuids   = @explode(',', $usergroup['categorymenuids']);

    $moduleviewids     = @explode(',', $usergroup['moduleviewids']);
    $modulesubmitids   = @explode(',', $usergroup['modulesubmitids']);
    $moduledownloadids = @explode(',', $usergroup['moduledownloadids']);
    $modulecommentids  = @explode(',', $usergroup['modulecommentids']);
    $moduleadminids    = @explode(',', $usergroup['moduleadminids']);

    $custommoduleviewids  = @explode(',', $usergroup['custommoduleviewids']);
    $custommoduleadminids = @explode(',', $usergroup['custommoduleadminids']);

    PrintSection('编辑群组: ' . $usergroup['name']);
  }

  echo '<form method="post" action="usergroups.php" name="usergroups">
        <input type="hidden" name="action" value="' . iif($action == 'createusergroup', 'insertusergroup', 'updateusergroup') . '" />
        <input type="hidden" name="usergroupid" value="' . $usergroup['usergroupid'] . '" />

        <table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1" colspan="2">群组名称</td>
        </tr>
        <tr>
          <td class="tdrow2" width="70%">输入用户群组的名称:</td>
          <td class="tdrow3"><input type="text" name="name" value="' . $usergroup['name'] . '" /></td>
        </tr>';

  if($forum = $DB->query_first("SELECT name, dbname, tblprefix FROM " . TABLE_PREFIX . "usersystems WHERE activated = '1' AND name != 'weenCompany'"))
  {
    switch($forum['name'])
    {
      case 'Discuz5':
        $forumusergroup_sql = "SELECT groupid AS usergroupid, grouptitle AS usergroupname FROM " . $forum['tblprefix'] . "usergroups ORDER BY groupid";
        break;

      case 'vBulletin 2':
        $forumusergroup_sql = "SELECT usergroupid AS usergroupid, title AS usergroupname FROM " . $forum['tblprefix'] . "usergroup ORDER BY usergroupid";
      break;
	  
      case 'vBulletin 3':
        $forumusergroup_sql = "SELECT usergroupid AS usergroupid, title AS usergroupname FROM " . $forum['tblprefix'] . "usergroup ORDER BY usergroupid";
      break;

      case 'phpBB2':
        $forumusergroup_sql = "SELECT group_id AS usergroupid, group_name AS usergroupname FROM " . $forum['tblprefix'] . "groups WHERE group_name != '' ORDER BY group_id";
      break;

      case 'Invision Power Board 2':
        $forumusergroup_sql = "SELECT g_id AS usergroupid, g_title AS usergroupname FROM " . $forum['tblprefix'] . "groups ORDER BY g_id";
      break;

      case 'Simple Machines Forum 1':
        $forumusergroup_sql = "SELECT ID_GROUP AS usergroupid, groupName AS usergroupname FROM " . $forum['tblprefix'] . "membergroups ORDER BY ID_GROUP";
      break;
    }

    // switch database? $dbname is include from config.php
    if($forum['dbname'] != $dbname)
    {
      $DB->select_db($forum['dbname']);
    }

    $getforumusergroups = $DB->query($forumusergroup_sql);

    // switch back to weencompany database? $dbname is include from config.php
    if($forum['dbname'] != $dbname)
    {
      $DB->select_db($dbname);
    }

    echo '<tr>
            <td class="tdrow1" colspan="2">' . $forum['name'] . '论坛接口</td>
          </tr>
          <tr>
            <td class="tdrow2" width="70%">选择一个论坛用户群组与系统群组进行关联:</td>
            <td class="tdrow3">
              <select name="forumusergroupid">
                <option value=""></option>';

    if($forum['name'] == 'phpBB2')
    {
      echo '<option value="-3" ' . iif($usergroup['forumusergroupid'] == -3, 'SELECTED', '') . '>注册用户</option>';
    }

    while($forumusergroup = $DB->fetch_array($getforumusergroups))
    {
      echo '<option value="' . $forumusergroup['usergroupid'] . '" ' . iif($usergroup['forumusergroupid'] == $forumusergroup['usergroupid'], 'SELECTED', '') . '>' . $forumusergroup['usergroupname'] . '</option>';
    }

    echo '    </select>
            </td>
          </tr>';
  }

  echo '</table>';
  EndSection();


  PrintSection('管理员权限');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1" colspan="2">完全管理权限</td>
        </tr>
        <tr>
          <td class="tdrow2" width="70%">是否拥有网站系统完全管理权限?<br/>注: 模块权限可由下面"模块权限"设置中的是否允许管理来决定.</td>
          <td class="tdrow3"><input type="radio" name="adminaccess" value="1" ' . iif($usergroup['adminaccess'] == 1, 'CHECKED', '') . ' /> 是 <input type="radio" name="adminaccess" value="0" ' . iif($usergroup['adminaccess'] == 0, 'CHECKED', '') . ' /> 否</td>
        </tr>
        <tr>
          <td class="tdrow1" colspan="2">前台评论管理权限</td>
        <tr>
          <td class="tdrow2" width="70%">是否拥有在网站前台管理用户评论的权限?</td>
          <td class="tdrow3"><input type="radio" name="commentaccess" value="1" ' . iif($usergroup['commentaccess'] == 1, 'CHECKED', '') . ' /> 是 <input type="radio" name="commentaccess" value="0" ' . iif($usergroup['commentaccess'] == 0, 'CHECKED', '') . ' /> 否</td>
        </tr>
        <tr>
          <td class="tdrow1" colspan="2">网站关闭浏览权限</td>
        </tr>
        <tr>
          <td class="tdrow2" width="70%">当网站关闭后, 是否仍可以浏览网站?<br/>注: 仅当用户以"记住我"的方式登陆登陆后, 设置才有效.</td>
          <td class="tdrow3"><input type="radio" name="offlinecategoryaccess" value="1" ' . iif($usergroup['offlinecategoryaccess'] == 1, 'CHECKED', '') . ' /> 是 <input type="radio" name="offlinecategoryaccess" value="0" ' . iif($usergroup['offlinecategoryaccess'] == 0, 'CHECKED', '') . ' /> 否</td>
        </tr>
        </table>';
  EndSection();


  PrintSection('模块权限');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">';

  // WEENCOMPANY MODULES
  $modules = $DB->query("SELECT moduleid, name, settings FROM " . TABLE_PREFIX . "modules WHERE moduleid != 1 AND authorname = 'weencompany' ORDER BY name");
  DisplayModulesPermissions($modules, '系统模块', 'main');

  // CLONED MODULES
  $modules = $DB->query("SELECT moduleid, name, settings FROM " . TABLE_PREFIX . "modules WHERE moduleid != 1 AND authorname = 'weencompany_cloner' ORDER BY name");
  DisplayModulesPermissions($modules, '复制的模块', 'clone');

  // CUSTOM MODULES
  $modules = $DB->query("SELECT custommoduleid, name, settings FROM " . TABLE_PREFIX . "custommodules ORDER BY name");
  DisplayModulesPermissions($modules, '自定义模块', 'custom');

  // DOWNLOADED MODULES
  $modules = $DB->query("SELECT moduleid, name, settings FROM " . TABLE_PREFIX . "modules WHERE moduleid != 1 AND authorname != 'weencompany' AND authorname != 'weencompany_cloner' ORDER BY name");
  DisplayModulesPermissions($modules, '下载的模块', 'downloaded');

  echo '</table>';
  EndSection();


  PrintSection('菜单权限');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1" width="200">菜单名称</td>
          <td class="tdrow1" width="200"><input type="checkbox" checkall="display" onclick="javascript: return select_deselectAll (\'usergroups\', this, \'display\');"> 显示在菜单栏</td>
          <td class="tdrow1"><input type="checkbox" checkall="view" onclick="javascript: return select_deselectAll (\'usergroups\', this, \'view\');"> 允许查看</td>
        </tr>';

  // Category Permissions, get all categories
  DisplayCategories($categorymenuids,$categoryviewids);

  echo '</table>';
  EndSection();

  echo '<table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td align="center"><input type="submit" name="" value="' . iif($action == 'createusergroup', ' 创建群组 ', ' 保存更新 ') . '" />
        </tr>
        </table>

        </form>';
  
  // INITIALISE CHECKBOX GROUPS
  echo' <script type="text/javascript">

        function initGroups()
        {
          initCheckboxGroup("usergroups", "view_main");
          initCheckboxGroup("usergroups", "submit_main");
          initCheckboxGroup("usergroups", "download_main");
          initCheckboxGroup("usergroups", "comment_main");
          initCheckboxGroup("usergroups", "admin_main");
          
          initCheckboxGroup("usergroups", "view_clone");
          initCheckboxGroup("usergroups", "submit_clone");
          initCheckboxGroup("usergroups", "download_clone");
          initCheckboxGroup("usergroups", "comment_clone");
          initCheckboxGroup("usergroups", "admin_clone");
          
          initCheckboxGroup("usergroups", "view_custom");
          initCheckboxGroup("usergroups", "submit_custom");
          initCheckboxGroup("usergroups", "download_custom");
          initCheckboxGroup("usergroups", "comment_custom");
          initCheckboxGroup("usergroups", "admin_custom");
          
          initCheckboxGroup("usergroups", "view_downloaded");
          initCheckboxGroup("usergroups", "submit_downloaded");
          initCheckboxGroup("usergroups", "download_downloaded");
          initCheckboxGroup("usergroups", "comment_downloaded");
          initCheckboxGroup("usergroups", "admin_downloaded");
          
          initCheckboxGroup("usergroups", "display");
          initCheckboxGroup("usergroups", "view");
        }
        
        window.onload = initGroups;
        
        </script>';

}



// ############################### PRINT FOOTER ################################

PrintFooter();

?>