<?php

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

$rootpath = "./../";

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

$divNameList = '';

// ############################ SETUP PAGE CHARSET #############################

SetPageCharacterSet();

function StartMenu()
{
        echo '<table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
          <td bgcolor="#FFFFFF" style="padding-left: 2px; padding-top: 2px; padding-right: 2px; padding-bottom: 0px;">';
}


function PrintMenuTitle($name, $open)
{
        global $stylepath, $divNameList;

        // Save a list of Block Names
        if(strlen($divNameList) > 0)
        $divNameList .= ',';

        $divNameList .= '"' . $name . '"';

        echo '<div class="menutitle" onclick="ToggleDiv(\'' . $name . '\');"><img id="img_' . $name . '" src="' . $stylepath . 'images/'. iif($open, 'closed.gif', 'open.gif') . '" border="0" align="absmiddle">&nbsp;&nbsp;' . $name . '</div>
        <div id="div_' . $name . '" style="display:' . iif($open, 'block', 'none') . ';">';
}

function PrintMenuRow($url, $name)
{
        global $stylepath;

        echo '<div class="menulink-normal" onclick="nav_goto(\'' . $url . '\');" onmouseover="this.className=\'menulink-hover\';" onmouseout="this.className=\'menulink-normal\'"><img src="' . $stylepath . 'images/menu_1.gif" border="0" align="absmiddle">&nbsp;<a href="' . $url . '" target="mainFrame">' . $name . '</a></div>';
}


function EndBlock()
{
        echo '</div>';
}


function EndMenu()
{
        echo '  </td>
        </tr>
        </table>

        <div style="margin-bottom:24px"></div>';
}

function PrintCategories($parentid, $indent)
{
        global $DB;
        //'categories.php?action=displaycategories',

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

        while($cat = $DB->fetch_array($getcategories))
        {
                PrintMenuRow('mycategories.php?categoryid=' . $cat['categoryid'], $indent . $cat['name']);
                PrintCategories($cat['categoryid'], $indent . '--');
        }
}

?>


<html>
<head>
  <link rel=stylesheet href='<?php echo $stylepath; ?>menu.css' />
  <script type="text/javascript">
  var cookieName = 'cwsaMenuCookie';

  if(top.location == self.location)
  {
          self.location.replace("index.php")
  }

  function setCookie(Cookie, value, expiredays)
  {
          var ExpireDate = new Date ();
          ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
          document.cookie = Cookie + "=" + escape(value) +
          ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
  }

  function getCookie(Cookie)
  {
          if (document.cookie.length > 0)
          {
                  begin = document.cookie.indexOf(Cookie+"=");
                  if (begin != -1)
                  {
                          begin += Cookie.length+1;
                          end = document.cookie.indexOf(";", begin);
                          if (end == -1) end = document.cookie.length;
                          return unescape(document.cookie.substring(begin, end));
                  }
          }
          return null;
  }

  function LoadMenu()
  {
          cookieMenu = getCookie(cookieName);
          if(cookieMenu != null)
          {
                  for(i = 0; i < divNames.length; i++)
                  {
                          if(cookieMenu.indexOf(divNames[i]) >= 0)
                          {
                                  document.getElementById('div_' + divNames[i]).style.display = 'block';
                                  document.getElementById('img_' + divNames[i]).src = '<?php echo $stylepath; ?>images/closed.gif';
                          }
                          else
                          {
                                  document.getElementById('div_' + divNames[i]).style.display = 'none';
                                  document.getElementById('img_' + divNames[i]).src = '<?php echo $stylepath; ?>images/open.gif';
                          }
                  }
          }
  }

  function SaveMenu()
  {
          var cookiestring = '';

          for(i = 0; i < divNames.length; i++)
          {
                  var block = document.getElementById('div_' + divNames[i]);

                  if(block.style.display != 'none')
                  {
                          cookiestring += divNames[i] + '|';
                  }
          }

          setCookie(cookieName,cookiestring,1);
  }

  function ToggleDiv(className)
  {
          var img = document.getElementById('img_' + className);
          var div = document.getElementById('div_' + className);

          if(div.style.display == 'none')
          {
                  img.src = '<?php echo $stylepath; ?>images/closed.gif';
                  div.style.display = 'block';
          }
          else
          {
                  img.src = '<?php echo $stylepath; ?>images/open.gif';
                  div.style.display = 'none';
          }
  }

  function nav_goto(targeturl)
  {
          parent.frames.mainFrame.location = targeturl;
  }
  </script>
</head>

<body>



<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
  <td align="center"><a href="mphome.php" target="mainFrame" class="normal" onfocus="this.blur()" title="后台首页"><img src="<?php echo $stylepath; ?>images/logo.gif" border="0" /></a></td>
</tr>
<tr>
  <td align="center" style="padding-top: 8px; padding-bottom: 12px;">
    <a href="mphome.php" target="mainFrame" class="normal">后台首页</a>&nbsp;|&nbsp;
    <?php
	if($sitedefaultlang == 'en') 
	{
		echo '<a href="../index.php?lang=en" target="_blank" class="normal">网站</a>&nbsp;|&nbsp;';
	}
	else
	{
		echo '<a href="../index.php?lang=cn" target="_blank" class="normal">网站</a>&nbsp;|&nbsp;';
	}

	echo '<a href="index.php?logout=1" class="normal" target="_parent" onclick="return confirm(\'确定退出weenCompany闻名企业网站系统吗?\');"><img src="' . $stylepath . 'images/logout.gif" border="0" /> 退出</a>';
	
	if($sitedefaultlang == 'en') 
	{
		echo '<br/><a href="index.php?lang=cn" target="_parent" class="redirect">进入中文后台</a>';
	}
	else
	{
		echo '<br/><a href="index.php?lang=en" target="_parent" class="redirect">进入English后台</a>';
	}
	?>  
  </td>
</tr>
</table>

<table width="150" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
  <td valign="top" align="center">

  <?php

  // admin menus
  if($userinfo['adminaccess'])
  {

          // ########################## Menu_Settings  ##########################

          StartMenu();
          PrintMenuTitle('系统设置', true);
          PrintMenuRow('mainsettings.php', '基本设置');
          PrintMenuRow('templates.php', '网站模板');
          PrintMenuRow('modules.php', '模块管理');
          PrintMenuRow('comments.php', '评论管理');
          PrintMenuRow('forumintegration.php', '论坛接口');

          PrintMenuRow('languages.php', '前台语言');
          EndBlock();
          PrintMenuTitle('系统维护', false);
          PrintMenuRow('sysupgrade.php', '系统升级');
          PrintMenuRow('template_editor.php?action=displayimages', '模板编辑器');
          PrintMenuRow('database.php', '数据库维护');
          PrintMenuRow('info.php', '服务器信息');
          EndBlock();
          EndMenu();


          // ########################## Menu_Categories  ##########################

          StartMenu();
          PrintMenuTitle('菜单管理', true);
          PrintMenuRow('categories.php?action=createcategory', '新建菜单');
          PrintMenuRow('categories.php?action=displaycategories', '菜单管理');
          EndBlock();
          PrintMenuTitle('所有菜单', false);
          PrintCategories(0, '');
          EndBlock();
          EndMenu();


          // ########################## Menu_Image Manager  ##########################

          StartMenu();
          PrintMenuTitle('图片管理', true);
          PrintMenuRow('imagemanager.php?action=displayimages', '网站图片');
          PrintMenuRow('imagemanager.php?action=displaysmilies', '表情图标');
          EndBlock();
          EndMenu();


          // ########################## Menu_Users  ##########################

          StartMenu();
          PrintMenuTitle('用户管理', true);

          PrintMenuRow('users.php?action=displayuserform', '添加用户');
          PrintMenuRow('users.php?action=displayusers', '查找用户');
          PrintMenuRow('usergroups.php', '群组设置');
          EndBlock();
          EndMenu();

  }


  // ########################## Menu_Modules  ##########################

  StartMenu();

  // weencompany modules
  $getsdmodules = $DB->query("SELECT moduleid, name FROM " . TABLE_PREFIX . "modules WHERE authorname = 'weencompany' AND moduleid != '1' ORDER BY moduleid ASC");
  $showmenu = true;
  if($DB->get_num_rows($getsdmodules) > 0)
  {
          while($sdmodule = $DB->fetch_array($getsdmodules))
          {
                  if(@in_array($sdmodule['moduleid'], $userinfo['moduleadminids']))
                  {
                          if($showmenu)
                          {
                                  PrintMenuTitle('系统模块', false);
                                  $showmenu = false;
                          }

                          PrintMenuRow('mymodules.php?moduleid='.$sdmodule['moduleid'].'', $sdmodule['name']);
                  }
          }
  }

  EndBlock();


  // cloned modules
  $getclonedmodules = $DB->query("SELECT moduleid, name FROM " . TABLE_PREFIX . "modules WHERE authorname = 'weencompany_cloner' ORDER BY moduleid ASC");
  $showmenu = true;
  if($DB->get_num_rows($getclonedmodules) > 0)
  {
          while($clonedmodule = $DB->fetch_array($getclonedmodules))
          {
                  if(@in_array($clonedmodule['moduleid'], $userinfo['moduleadminids']))
                  {
                          if($showmenu)
                          {
                                  PrintMenuTitle('复制的模块', false);
                                  $showmenu = false;
                          }

                          PrintMenuRow('mymodules.php?moduleid=' . $clonedmodule['moduleid'] . '', $clonedmodule['name']);
                  }
          }
  }
  EndBlock();


  // custom modules
  $getcustommodules = $DB->query("SELECT custommoduleid, name FROM " . TABLE_PREFIX . "custommodules ORDER BY custommoduleid ASC");
  $showmenu = true;
  if($DB->get_num_rows($getcustommodules) > 0)
  {
          while($custommodule = $DB->fetch_array($getcustommodules))
          {
                  if(@in_array($custommodule['custommoduleid'], $userinfo['custommoduleadminids']))
                  {
                          if($showmenu)
                          {
                                  PrintMenuTitle('自定义模块', false);
                                  $showmenu = false;
                          }

                          PrintMenuRow('custommodules.php?custommoduleid='.$custommodule['custommoduleid'].'', $custommodule['name']);
                  }
          }
  }
  EndBlock();

  // downloaded modules
  $getdwmodules = $DB->query("SELECT moduleid, name FROM " . TABLE_PREFIX . "modules WHERE authorname != 'weencompany' AND authorname != 'weencompany_cloner' ORDER BY moduleid ASC");
  $showmenu = true;
  if($DB->get_num_rows($getdwmodules) > 0)
  {
          while($dwmodule = $DB->fetch_array($getdwmodules))
          {
                  if(@in_array($dwmodule['moduleid'], $userinfo['moduleadminids']))
                  {
                          if($showmenu)
                          {
                                  PrintMenuTitle('下载的模块', false);
                                  $showmenu = false;
                          }

                          PrintMenuRow('mymodules.php?moduleid='.$dwmodule['moduleid'].'', $dwmodule['name']);
                  }
          }
  }

  EndBlock();
  EndMenu();

  ?>

  </td>
</tr>
</table>
<script type="text/javascript">
var divNames = new Array(<?php echo $divNameList; ?>);
window.onload = LoadMenu;
window.onbeforeunload = SaveMenu;
</script>
</body>
</html>