<?php
    $paging = $this->a_Auth->getSetting('Aff_paging');
    if($paging == '' || $paging == 0) {
        $paging = 10;
    }

    if($this->a_numrows > $paging) {
        $pages = floor($this->a_numrows / $paging);
        if($this->a_numrows%$paging) $pages++;
    }

    if($_REQUEST['list_page'] == '' || $_REQUEST['list_page'] > $pages) {
        $_REQUEST['list_page'] = 1;
    }
?>
<style type="text/css">
.jqifade{
	position: absolute;
	background-color: #aaaaaa;
}
div.jqi{
	width: 640px;
	font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
	position: absolute;
	background-color: #ffffff;
	font-size: 11px;
	text-align: left;
	border: solid 1px #eeeeee;
	border-radius: 10px;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	padding: 7px;
}
div.jqi .jqicontainer{
	font-weight: bold;
}
div.jqi .jqiclose{
	position: absolute;
	top: 4px; right: -2px;
	width: 18px;
	cursor: default;
	color: #bbbbbb;
	font-weight: bold;
}
div.jqi .jqimessage{
	padding: 10px;
	line-height: 20px;
	color: #444444;

    width: 618px;
    max-height:350px;
    height: auto !important;
    overflow: auto;
}
div.jqi .jqibuttons{
	text-align: right;
	padding: 5px 0 5px 0;
	border: solid 1px #eeeeee;
	background-color: #f4f4f4;
}
div.jqi button{
	padding: 3px 10px;
	margin: 0 10px;
	background-color: #2F6073;
	border: solid 1px #f4f4f4;
	color: #ffffff;
	font-weight: bold;
	font-size: 12px;
}
div.jqi button:hover{
	background-color: #728A8C;
}
div.jqi button.jqidefaultbutton{
	background-color: #6294ab;
}
.jqiwarning .jqi .jqibuttons{
	background-color: #6294ab;
}
</style>
<script type="text/javascript" src="../scripts/jquery.js"></script>
<script type="text/javascript" src="../scripts/jquery-impromptu.3.1.min.js"></script>
<script type="text/javascript">
function showCode(ID) {
	var wnd = window.open("index_popup.php?md=Affiliate_Affiliates_Views_AffBannerManager&action=showcode&bid="+ID+"&<?php echo SID?>","ShowBannerCodeBanner","scrollbars=0, top=100, left=100, width=450, height=270, status=0")
    wnd.focus();
}

function showBannerCode(ID) {
    if(document.getElementById('bs_show_code_'+ID).style.display != "none") {
        document.getElementById('bs_show_code_'+ID).style.display="none";
        document.getElementById('bs_show_code_link_'+ID).innerHTML='<?php echo L_G_SHOWBANNERCODE?>';
    } else {
        document.getElementById('bs_show_code_'+ID).style.display="block";
        document.getElementById('bs_show_code_link_'+ID).innerHTML='<?php echo L_G_HIDEBANNERCODE?>';
    }
    return;
}

function goToPage(list_page) {
    document.getElementById('list_page').value = list_page;
    document.getElementById('FilterForm').submit();
}

function makeDynamicLink(ID) {
	var wnd = window.open("index_popup.php?md=Affiliate_Affiliates_Views_AffBannerManager&action=dynamiclink&bid="+ID+"&<?php echo SID?>","EditBanner","scrollbars=1, top=100, left=100, width=600, height=320, status=0")
    wnd.focus();
}

function showPopupPopunder(banner_content, btype, rwidth, rheight, rresizable, rstatus, rtoolbar, rlocation, rdirectories, rmenubar, rscrollbars) {
  var TheNewWindow = window.open("<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>testPop.php?banner_content="+banner_content,'ThePop',
        'top=0,left=0,width='+rwidth+',height='+rheight+',toolbar='+rtoolbar+',location='+rlocation+',directories='+rdirectories+',status='+rstatus+',menubar='+rmenubar+',scrollbars='+rscrollbars+',resizable='+rresizable);

  if(btype == '<?php echo BANNERTYPE_POPUNDER?>')
    TheNewWindow.blur();
  else
    TheNewWindow.focus();
}

function showTearpage(id) {
  var TheNewWindow = window.open("<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>testTearpage.php?id="+id,'Tearpage Test','top=0,left=0,width=500,height=500');
  TheNewWindow.focus();
}

function showLightbox(id) {
  var TheNewWindow = window.open("<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>testLightbox.php?id="+id,'Tearpage Test','top=0,left=0,width=850,height=650');
  TheNewWindow.focus();
}

function showbannerpreview(id) {
    $.prompt($('#'+id).html(),{ buttons: { '<?php echo L_G_CLOSEPREVIEW; ?>': false } });
}

</script>

<?php QUnit_Global::includeTemplate('banner_show_filter.tpl.php'); ?>

<form name="FilterForm" id="FilterForm" action="index.php" method="get">
<input type=hidden name=md value='Affiliate_Affiliates_Views_AffBannerManager' />
<input type=hidden name=list_page id=list_page value="<?php echo $_REQUEST['list_page']?>" />

<table border=0 width="100%">
<?php  if($this->a_numrows>$paging) { ?>
     <tr>
     <td align=center>
      <b><?php echo L_G_PAGGING;?>：<b>
<?php
      // draw page numbers
      for($i=1; $i<=$pages; $i++)
      {
        if($i != $_REQUEST['list_page'])
          echo "&nbsp;<a class=\"paging\" href=\"javascript: goToPage('$i');\">$i</a>";
        else
          echo "&nbsp;<b>$i</b>";
      }
      echo "</td></tr>";
    }
?>
   <tr>
   <td align="center">
<?php
   if($this->a_numrows == 0)
        print '<br><br><b>'.L_G_NOBANNERS.'</b><br><br></td></tr>';

   $count = 0;
   $params = $this->a_params;
   if (count($this->a_list_data) > 0) {
   foreach ($this->a_list_data as $bannerID => $data)
    {
      $count++;
      if(!(($_REQUEST['list_page']-1)*$paging<$count && $count<=($_REQUEST['list_page']*$paging)))
      {
        continue;
      }

      // get statistics data (impressions and clicks)
      $data = $this->a_bannerData[$bannerID];

      $clickUrlOnly = Affiliate_Affiliates_Views_AffBannerManager::getClickUrl($data['destinationurl'], $params);
      $banner = $this->a_this->showBannerAndGetCode($clickUrlOnly, $data['bannertype'], $data['bannerid'], $data['sourceurl'], $data['description'], $params);
?>
    <table class="tblist mt10" width="100%" border="0" cellspacing="0" cellpadding="3">
        <tr class="header" align="left">
            <td colspan="2"><?php echo '<b>'.$data['name'].'</b>('.$data['bannerid'].')'; ?></td>
        </tr>
        <tr align="left">
            <td width="90" align="left"><?php echo L_G_TYPE; ?></td>
            <td><?php switch ($data['bannertype']) {
            case BANNERTYPE_HTML:     echo L_G_BANNERTYPE_HTML; break;
            case BANNERTYPE_TEXT:     echo L_G_TEXTBANNER; break;
            case BANNERTYPE_IMAGE:    echo L_G_IMAGEBANNER; break;
            case BANNERTYPE_POPUP:    echo L_G_POPUPAD; break;
            case BANNERTYPE_POPUNDER: echo L_G_BANNERTYPE_POPUNDER; break;
            case BANNERTYPE_ROTATOR:  echo L_G_BANNERTYPE_ROTATOR; break;
            case BANNERTYPE_ARTICLE:  echo L_G_PENS_BANNER; break;
            case BANNERTYPE_LIGHTBOX:  echo L_G_LBOX_BANNER; break;
            case BANNERTYPE_WORD:  echo L_G_WORDBANNER; break;
            case BANNERTYPE_TEARPAGE:  echo L_G_TEARPAGE_BANNER; break;
            default: echo L_G_UNKNOWN; break; } ?>
            </td>
        </tr>
        <tr>
            <td align="left"><?php echo L_G_DESTURL;?></td>
            <td align="left"><?php if($data['bannertype'] != BANNERTYPE_ROTATOR) echo $data['destinationurl']; else echo 'N/A'; ?></td>
        </tr>
        <tr>
            <td align="left"><?php echo L_G_DISPLAYSTATISTICS;?></td>
            <td align="left">
                <?php echo L_G_IMPRESSIONS.L_G_IMPUNIQUEALL; ?>：
                <?php echo $data[$this->a_Auth->getUserID()]['unique_impressions_all']?>/<?php echo $data[$this->a_Auth->getUserID()]['impressions_all']?> |
                <?php echo L_G_CLICKS?>：<?php echo $data[$this->a_Auth->getUserID()]['clicks_all']?> |
                <?php echo L_G_RATIO?>：<?php echo $data[$this->a_Auth->getUserID()]['ratio_all']?>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="left">
                <?php if($data['bannertype']==BANNERTYPE_LIGHTBOX) {    //lightbox 代码分两部分，这是第一部分
                    echo L_G_BANNESOURCERCODE_LBOX;
                ?>
<textarea onclick="javascript:this.select();" class="scode" readonly="readonly">
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>lightbox/css/lightbox.css" />
<script type="text/javascript">
    var fileLoadingImage = "<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>lightbox/images/loading.gif";
    var fileBottomNavCloseImage = "<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>lightbox/images/closelabel.gif";
</script>
<script type="text/javascript" src="<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>lightbox/js/prototype.js"></script>
<script type="text/javascript" src="<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>lightbox/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="<?php echo $this->a_Auth->getSetting('Aff_scripts_url')?>lightbox/js/lightbox.js"></script></textarea>
                <br /><br />
                <?php } ?>


                <?php echo L_G_BANNESOURCERCODE; ?>
                <?php if($data['bannertype'] != BANNERTYPE_ROTATOR) {
                    echo '&nbsp;&nbsp;&nbsp;&nbsp;';
                    switch($data['bannertype']) {
                        case BANNERTYPE_TEARPAGE: echo '<a href="javascript:showTearpage(\''.$data['bannerid'].'\');"><b>'.L_G_CLICK2PREVIEWBANNER.'</b></a>'; break;
                        case BANNERTYPE_LIGHTBOX: echo '<a target="_blank" href="'.$this->a_Auth->getSetting('Aff_scripts_url').'testLightbox.php?id='.$data['bannerid'].'"><b>'.L_G_CLICK2PREVIEWBANNER.'</b></a>'; break;
                        default: echo '<a href="javascript:showbannerpreview(\'preview_'.$data['bannerid'].'\');"><b>'.L_G_CLICK2PREVIEWBANNER.'</b></a>';
                    }
                  }
                ?>
                <br />
                <textarea onclick="javascript:this.select();" class="scode" readonly="readonly"><?php echo htmlspecialchars($banner['bannerCode'])?></textarea>
                <div id="preview_<?php echo $data['bannerid']; ?>" style="display:none;"><?php echo $banner['titleDescription']; ?></div>
            </td>
        </tr>
    </table>
<?php
    }
?>
   </td>
   </tr>
<?php  if($this->a_numrows>$paging) { ?>
     <tr>
     <td align="center">
      <b><?php echo L_G_PAGES?>:&nbsp;<b>
<?php
      // draw page numbers
      for($i=1; $i<=$pages; $i++)
      {
        if($i != $_REQUEST['list_page'])
          echo "&nbsp;<a class=\"paging\" href=\"javascript: goToPage('$i');\">$i</a>";
        else
          echo "&nbsp;<b>$i</b>";
      }
      echo "<br></td></tr>";
    }
?>
<?php
   }
?>
   </table>
   </form>
