<?php

//------------------------ menus start ------------------------//
$igonesd = array(
    'login','firststeps','add','edit','view',
    'delete','approve','pending','suppress','exportcsv',
    'transactions', //
    'manualpay',    //手动支付佣金
    'details',  //支付记录：查看详细会计报告
    'savedetails',  //同上
    'changecommcat',    //变动佣金分类
    'savedefaultcampaign',  //设置默认推广项目
    'backres',  //数据库维护
    'optrep',
    'optimize',
    'repair',
    'add_new',  //新增管理员
    'accounting',   //查看推广员详细会计报告
    'broadcast',    //发送消息
    'activate',     //激活消息
    'deactivate',   //延迟消息
    'createrefundchargeback',    //手动创建退款
    'showresults'   //发邮件后通知结果页
);
$md = !empty($_REQUEST['md'])?$_REQUEST['md']:'home';
$sd = !empty($_REQUEST['action'])?$_REQUEST['action']:(!empty($_REQUEST['reporttype'])?$_REQUEST['reporttype']:'');
$sd = in_array($sd,$igonesd)?'':$sd;  //登陆后进入首页此参数为login,导致子菜单显示不正确

$hidenperms = array(
    'home'=>array('home','Affiliate_Merchants_Views_MerchantProfile')
);

foreach($this->leftMenu as $tkey=>$menutab) {
    foreach($menutab['items'] as $skey=>$submenu) {
        $m = getQueryString('md',$submenu['link']);
        if(empty($sd)) {
            if($m==$md) {
                $currtab = $tkey;
                $currsub = $skey;
                break;
            }
        }else {
            $a = getQueryString('action',$submenu['link']);
            $a = empty($a)?getQueryString('action',$menutab['link']):$a;    //如果子菜单中无项目则在主菜单中找
            $r = getQueryString('reporttype',$submenu['link']);
            $r = empty($r)?getQueryString('reporttype',$menutab['link']):$r;

            if($m==$md && ($sd==$a || $sd==$r)) {
                $currtab = $tkey;
                $currsub = $skey;
                break;
            }
        }
    }
    if($currtab) break;
}
if(!$currtab) die('You do not have permission!');
//------------------------ menus end ------------------------//

$query = 'select * from `wd_pz_settings` where `code`="sitename" || `code`="sitelogo"';
$rs = $GLOBALS['db']->Query($query);
$GLOBALS['dbrequests']++;
if(!$rs->EOF) {
    foreach($rs as $row) $pzoneSettings[$row['code']] = $row;
}
$_SESSION['sitename'] = $siteName = !empty($pzoneSettings['sitename']['svalue'])?$pzoneSettings['sitename']['svalue']:MT_SITETITLE;
$siteLogo = !empty($pzoneSettings['sitelogo']['svalue'])?$pzoneSettings['sitelogo']['svalue']
            :(($logo=$GLOBALS['Auth']->getSetting('Aff_style_logo_url')) != '' ? $logo : $this->a_this->getImage('web_logo.gif'));
define('FINAL_SITELOGO',$siteLogo);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo $_SESSION['sitename']; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="Marketools Inc." name="Copyright" />
<link type="text/css" rel="stylesheet" media="all" href="../templates/affiliate/default/css/globalframe.css" />
<script type="text/javascript" src="../include/QUnit/functions.js"></script>
<script type="text/javascript">
// function for checking or unchecking all items
var checkedAllItems = false;
</script>
<?php //merchants_head(); ?>

</head>

<body>
<table cellpadding="0" cellspacing="0" width="100%" height="100%">
<tr>
<td class="toptd" colspan="2" height="90">
<div class="mainhd">

<div class="logo">Marketools LOGO</div>

<?php echo  $this->a_this->fetchTemplate('logged_field') ?>

<div class="navbg"></div>
<div class="nav">
    <ul id="topmenu">
        <?php
            //输出主菜单
            $s = '<li id="%s" %s ><em><a href="%s" hidefocus="true" target="_self">%s</a></em></li>';
            foreach($this->leftMenu as $tkey=>$menutab) {
                $style = $tkey==$currtab?'class="navon"':'';
                echo sprintf($s,$tkey,$style,$menutab['link'],$menutab['caption']);
            }
        ?>
    </ul>
<div class="navbd"></div>
<div class="currentloca">
    <p id="pam_navigation"></p>
</div>
</div><!--end.nav-->
</div><!--end.mainhd-->
</td>
</tr>


<tr>
<td valign="top" width="160" class="menutd">
<div id="leftmenu" class="menu">
    <ul id="menu_index">
        <?php
            //输出子菜单
            $s = '<li%s><a %s href="%s" hidefocus="true" target="_self">%s</a></li>';
            foreach($this->leftMenu[$currtab]['items'] as $skey=>$submenu) {
                $style = $skey==$currsub?'class="tabon"':'';
                $lstyle = preg_match('/^line_\d$/',$skey)?' class="line" ':'';
                echo sprintf($s,$lstyle,$style,$submenu['link'],$submenu['caption']);
            }
        ?>
    </ul>
    <?php
    //获取待审核信息条数
    if($currtab=='home') {
        $GLOBALS['dbrequests'] += 3;

        //待审推广员
        $query = 'select count(1) as "total" from `wd_g_users` where `rstatus`="1" and `rtype`="4" and `deleted`="0"';
        $rs = $GLOBALS['db']->Query($query);
        if(!$rs || $rs->EOF) {
            $p_affs = 0;
        }else {
            $p_affs = $rs->fields['total'];
        }

        //待审流量
        $query = 'select count(1) as "total" from `wd_pa_transactions` where `rstatus`="1"';
        $rs = $GLOBALS['db']->Query($query);
        if(!$rs || $rs->EOF) {
            $p_trans = 0;
        }else {
            $p_trans = $rs->fields['total'];
        }

        //未查看的消息
        $query = 'select count(*) as "total" from `wd_g_messagestousers` m2u join `wd_g_messages` m on m2u.`messageid`=m.`messageid` where m2u.`userid`="1" and m2u.`rstatus`="1" and m.`deleted`="0"';
        $rs = $GLOBALS['db']->Query($query);
        if(!$rs || $rs->EOF) {
            $p_messages = 0;
        }else {
            $p_messages = $rs->fields['total'];
        }

        //若为0则不显示数字
        //$p_trans = empty($p_trans)?'':$p_trans;
        //$p_affs = empty($p_affs)?'':$p_affs;
        //$p_messages = empty($p_messages)?'':$p_messages;
    ?>
    <script type="text/javascript">
        //try {
            document.getElementById('h_p_trans').innerHTML = "<?php echo $p_trans;?>";
            document.getElementById('h_p_affs').innerHTML = "<?php echo $p_affs;?>";
            document.getElementById('h_p_message').innerHTML = "<?php echo $p_messages;?>";
        //} catch (e) {}
    </script>
    <?php } ?>
</div>
</td>
