<script type="text/javascript">
function deleteBanner(ID) {
  if(confirm("<?php echo L_G_CONFIRMDELETEBANNER?>"))
   	document.location.href = "index.php?md=Affiliate_Merchants_Views_BannerManager&bid="+ID+"&action=delete"+"&<?php echo SID?>";
}
function addBanner(Type) {
	document.location.href = "index.php?md=Affiliate_Merchants_Views_Banner"+Type+"&campaign=<?php echo $campaignid?>&<?php echo SID?>";
}
function editBanner(Type, ID) {
	document.location.href = "index.php?md=Affiliate_Merchants_Views_Banner"+Type+"&action=edit&bid="+ID+"&<?php echo SID?>";
}

function addBannerCategory() {
    document.location.href = "index.php?md=Affiliate_Merchants_Views_BannerCategory&action=add&<?php echo SID?>";
}

function addBannersForCampaign() {
	document.location.href = "index.php?md=Affiliate_Merchants_Views_BannerManager&action=show&campid=<?php echo $campaignid?>"+"&<?php echo SID?>";
}

function backToCampaigns(ID) {
	document.location.href = "index.php?md=Affiliate_Merchants_Views_CampaignManager&action=addbanners&cid="+ID+"&<?php echo SID?>";
}

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();
}

</script>


<table border=0>
<tr><td align=left>
    <?php echo L_G_BANNERMANAGER_DESCRIPTION; ?>
    </td>
</tr>
<tr>
<td align=left>
<?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;
}

if($this->a_numrows > $paging) {
  echo "<center>";
  echo '<b>'.L_G_PAGGING.'：<b>';
  // draw page numbers

  for($i=1; $i<=$pages; $i++)
  {
      if($i != $_REQUEST['list_page']) {
          echo "&nbsp;<a class=\"paging\" href=\"index.php?md=Affiliate_Merchants_Views_BannerManager&list_page=$i\">$i</a>&nbsp;";
      } else {
          echo "&nbsp;<b>$i</b>&nbsp;";
      }
  }
  echo "</center>";
}

if($this->a_numrows == 0)
    print '<div class="mt10"><b>'.L_G_NOBANNERS.'</b></div>';

$count = 0;
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;
  }
  $data = $this->a_bannerData[$bannerID];
?>
<!-- begin ad item -->
<table class="tblist mt10" width="750" border="0" cellspacing="0" cellpadding="3">
  <tr class="header">
    <td width="20%"><?php echo L_G_ID.' / '.L_G_OTHER_NAME; ?></td>
    <td width="10%"><?php echo L_G_TYPE; ?></td>
    <td width="15%"><?php echo L_G_DATECREATED; ?></td>
    <td width=""><?php echo L_G_DESTURL; ?></td>
    <td width="50"><?php echo L_G_ACTIONS; ?></td>
  </tr>
  <tr>
    <td><?php echo $data['bannerid'].' <br /> <b>'.$data['name'].'</b>'; ?></td>
    <td>
        <?php switch ($data['bannertype']) {
        case BANNERTYPE_HTML:     echo L_G_BANNERTYPE_HTML; break;
        case BANNERTYPE_TEXT:     echo L_G_BANNERTYPE_TEXT; break;
        case BANNERTYPE_IMAGE:    echo L_G_BANNERTYPE_IMAGE; break;
        case BANNERTYPE_POPUP:    echo L_G_BANNERTYPE_POPUP; 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>
    <td><?php echo substr($data['dateinserted'],5,11); ?></td>
    <td><?php if($data['bannertype'] != BANNERTYPE_ROTATOR) { ?>
    <a href="<?php echo $data['destinationurl']?>" target=_blank><?php echo cut_str($data['destinationurl'],20); ?></a>
    <?php } ?></td>
    <td align="center" valign="center">
        <?php if($this->a_action_permission['edit']) {
             $btype = '';
             switch ($data['bannertype']) {
                 case BANNERTYPE_TEXT:     $btype = 'Text'; break;
                 case BANNERTYPE_HTML:     $btype = 'Html'; break;
                 case BANNERTYPE_IMAGE:    $btype = 'Image'; break;
                 case BANNERTYPE_POPUNDER: $btype = 'Popup'; break;
                 case BANNERTYPE_POPUP:    $btype = 'Popup'; break;
                 case BANNERTYPE_ROTATOR:  $btype = 'Rotator'; break;
                 case BANNERTYPE_ARTICLE:  $btype = 'Article'; break;
                 case BANNERTYPE_LIGHTBOX:  $btype = 'Lightbox'; break;
                 case BANNERTYPE_WORD:  $btype = 'Word'; break;
                 case BANNERTYPE_TEARPAGE:  $btype = 'Tearpage'; break;
             }
             ?>
            <a class=mainlink href="javascript:editBanner('<?php echo $btype?>', '<?php echo $data['bannerid']?>');"><img src="<?php echo  QUnit_UI_TemplatePage::getImage('edit.gif'); ?>" border="0" width="16" height="16"></a>
        <?php } ?>
        <?php if($this->a_action_permission['delete']) { ?>
            <a class=mainlink href="javascript:deleteBanner('<?php echo $data['bannerid']?>');"><img src="<?php echo  QUnit_UI_TemplatePage::getImage('delete.png'); ?>" border="0" width="16" height="16"></a>
        <?php } ?>
    </td>
  </tr>
<?php if($_REQUEST['bs_userid'] != '' && $_REQUEST['bs_userid'] != '_') { ?>
  <tr class="header"><td align="center" colspan="5"><?php echo L_G_STATISTICSFORALLAFFS?></td></tr>
<?php } ?>
  <tr>
    <td align=left class=listheaderNoLineLeft colspan="5">
    <table class=smalltext width=100%  border=0 cellspacing=0 cellpadding=0>
    <tr>
      <td class=smalltext width=10% align=center><?php echo L_G_INPERIOD?>&nbsp;</td>
      <td class=smalltext width=30% align=left><?php echo L_G_IMPRESSIONS?> <?php echo L_G_IMPUNIQUEALL?>：<?php echo $data['unique_impressions_period']?> / <?php echo $data['impressions_period']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_CLICKS?>：<?php echo $data['clicks_period']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_RATIO?>：<?php echo $data['ratio_period']?></td>
    </tr>
    <tr>
      <td class=smalltext width=10% align=center><?php echo L_G_ALL?>&nbsp;</td>
      <td class=smalltext width=30% align=left><?php echo L_G_IMPRESSIONS?> <?php echo L_G_IMPUNIQUEALL?>：<?php echo $data['unique_impressions_all']?> / <?php echo $data['impressions_all']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_CLICKS?>：<?php echo $data['clicks_all']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_RATIO?>：<?php echo $data['ratio_all']?></td>
    </tr>
    </table>
    </td>
  </tr>
<?php if($_REQUEST['bs_userid'] != '' && $_REQUEST['bs_userid'] != '_') { ?>
  <tr class="header"><td align="center" colspan="5"><?php echo L_G_STATISTICSFORCHOSENAFF; ?></td></tr>
  <tr>
    <td align=left class=listheaderNoLineLeft colspan="5">
    <table class=smalltext width=100%  border=0 cellspacing=0 cellpadding=0>
    <tr>
      <td class=smalltext width=10% align=center><?php echo L_G_INPERIOD?>&nbsp;</td>
      <td class=smalltext width=30% align=left><?php echo L_G_IMPRESSIONS?> <?php echo L_G_IMPUNIQUEALL?>：<?php echo $data[$_REQUEST['bs_userid']]['unique_impressions_period']?> / <?php echo $data[$_REQUEST['bs_userid']]['impressions_period']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_CLICKS?>：<?php echo $data[$_REQUEST['bs_userid']]['clicks_period']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_RATIO?>：<?php echo $data[$_REQUEST['bs_userid']]['ratio_period']?></td>
    </tr>
    <tr>
      <td class=smalltext width=10% align=center><?php echo L_G_ALL?>&nbsp;</td>
      <td class=smalltext width=30% align=left><?php echo L_G_IMPRESSIONS?> <?php echo L_G_IMPUNIQUEALL?>：<?php echo $data[$_REQUEST['bs_userid']]['unique_impressions_all']?> / <?php echo $data[$_REQUEST['bs_userid']]['impressions_all']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_CLICKS?>：<?php echo $data[$_REQUEST['bs_userid']]['clicks_all']?></td>
      <td class=smalltext width=30% align=left><?php echo L_G_RATIO?>：<?php echo $data[$_REQUEST['bs_userid']]['ratio_all']?></td>
    </tr>
    </table>
    </td>
  </tr>
<?php } ?>

  <tr>
    <td align=center colspan=5>
<?php
if($data['bannertype'] == BANNERTYPE_TEXT)
{
//     if(isset($this->textbanner_tpl)) {
//          $code = $this->textbanner_tpl;
//          $code = str_replace('{TITLE}', $data['description'], $code);
//              $code = str_replace('{DESCRIPTION}', $data['description'], $code);
//              $code = str_replace('{DESTINATION}',
//                 $clickUrlOnly."&".PARAM_A_BID."=".$bannerID.($specialDestUrl != '' ? '&desturl='.urlencode($specialDestUrl) : ''), $code);
//              $code = str_replace('{IMPRESSION_TRACK}', "<IMG SRC='".$GLOBALS['Auth']->getSetting('Aff_scripts_url')."sb.php?".PARAM_A_AID."=".$GLOBALS['Auth']->userID."&".PARAM_A_BID."=".$bannerID."' WIDTH=1 HEIGHT=1 BORDER=0>", $code);
//
//              echo $code;
//     } else {
    echo "<b>".$data['sourceurl']."</b><br>".$data['description'];
//     }
}
else if($data['bannertype'] == BANNERTYPE_TEARPAGE)
{
echo '<input class="btn" type="button" value="'.L_G_PREVIEW.'" onclick="showTearpage(\''.$data['bannerid'].'\')" />';
}
else if($data['bannertype'] == BANNERTYPE_LIGHTBOX)
{
echo '<input class="btn" type="button" value="'.L_G_PREVIEW.'" onclick="showLightbox(\''.$data['bannerid'].'\')" />';
}
else if($data['bannertype'] == BANNERTYPE_HTML)
{
echo $data['description'];
}
else if($data['bannertype'] == BANNERTYPE_WORD)
{
echo '<a target="_blank" href="'.$data['destinationurl'].'">'.$data['sourceurl'].'</a>';
}
else if($data['bannertype'] == BANNERTYPE_ARTICLE)
{
echo cut_str(strip_tags($data['description']),50);
}
else if($data['bannertype'] == BANNERTYPE_IMAGE)
{
echo "<br><img src='".$data['sourceurl']."' border=0 alt='".$data['description']."'><br>";
}
else if($data['bannertype'] == BANNERTYPE_POPUP || $data['bannertype'] == BANNERTYPE_POPUNDER)
{
$banner_details = $this->a_this->parseBannerDescription($data['description'], false);

$banner_content = '';
if($banner_details['display'] == URL_EXIST)
{
  $blBanners =& QUnit_Global::newObj('Affiliate_Merchants_Bl_Banners');
  $original_banner = $blBanners->getBannerInfo(array('bannerid' => $data['sourceurl']));

  $bannerData = $original_banner[$data['sourceurl']];

  if($bannerData['bannertype'] == BANNERTYPE_TEXT)
  {
    $banner_content = "<b>".$bannerData['sourceurl']."</b><br>".$bannerData['description'];
  }
  else if($bannerData['bannertype'] == BANNERTYPE_HTML)
  {
    $banner_content = $bannerData['description'];
  }
  else if($bannerData['bannertype'] == BANNERTYPE_IMAGE)
  {
    $banner_content = "<br><img src=".$bannerData['sourceurl']." border=0 alt=".$bannerData['description']."><br>";
  }
}
else
{
  $banner_content = "<iframe src=".$data['sourceurl']." scrolling=no frameborder=0 marginwidth=0 marginheight=0 width=".$banner_details['rwidth']." height=".$banner_details['rheight']."></iframe>";
}

echo '<input class=formbutton type="button" VALUE="'.L_G_TEST.' '.
     ($data['bannertype'] == BANNERTYPE_POPUNDER ? L_G_POPUNDER : L_G_POPUP).
     '" onClick="showPopupPopunder(\''.urlencode($banner_content).'\',\''.$data['bannertype'].'\',
            \''.$banner_details['rwidth'].'\',\''.$banner_details['rheight'].'\',
            \''.$banner_details['window_resizable'].'\',\''.$banner_details['window_status'].'\',
            \''.$banner_details['window_toolbar'].'\',\''.$banner_details['window_location'].'\',
            \''.$banner_details['window_directories'].'\',\''.$banner_details['window_menubar'].'\',
            \''.$banner_details['window_scrollbars'].'\')">';
}
?>
    </td>
  </tr>
</table>
<!-- end ad item -->
<?php
}
}

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

  echo "<br /><center>";
  echo '<b>'.L_G_PAGGING.':&nbsp;<b>';
  // draw page numbers

  for($i=1; $i<=$pages; $i++)
  {
    if($i != $_REQUEST['list_page'])
      echo "&nbsp;<a class=\"paging\" href=\"index.php?md=Affiliate_Merchants_Views_BannerManager&list_page=$i&campaign=".$_REQUEST['campaign']."\">$i</a>&nbsp;";
    else
      echo "&nbsp;<b>$i</b>&nbsp;";
  }
  echo "</center>";
}
?>
</td>
</tr>
<tr>
 <td width=750 align=left>
    <div class="mt10"><?php echo L_G_CLICKTHROUGHS; ?></div>
 </td>
</tr>
</table>
