[ PHPXref.com ] [ Generated: Sun Jul 20 19:31:32 2008 ] [ phpAdsNew 2.0.8 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/admin/ -> stats-banner-affiliates.php (source)

   1  <?php // $Revision: 2.0.2.5 $
   2  
   3  /************************************************************************/
   4  /* phpAdsNew 2                                                          */
   5  /* ===========                                                          */
   6  /*                                                                      */
   7  /* Copyright (c) 2000-2006 by the phpAdsNew developers                  */
   8  /* For more information visit: http://www.phpadsnew.com                 */
   9  /*                                                                      */
  10  /* This program is free software. You can redistribute it and/or modify */
  11  /* it under the terms of the GNU General Public License as published by */
  12  /* the Free Software Foundation; either version 2 of the License.       */
  13  /************************************************************************/
  14  
  15  
  16  
  17  // Include required files
  18  require  ("config.php");
  19  require  ("lib-statistics.inc.php");
  20  require  ("lib-size.inc.php");
  21  require  ("lib-zones.inc.php");
  22  
  23  
  24  // Register input variables
  25  phpAds_registerGlobal ('expand', 'collapse', 'listorder', 'orderdirection');
  26  
  27  
  28  // Security check
  29  phpAds_checkAccess(phpAds_Admin);
  30  
  31  
  32  
  33  /*********************************************************/
  34  /* Get preferences                                       */
  35  /*********************************************************/
  36  
  37  if (!isset($listorder))
  38  {
  39      if (isset($Session['prefs']['stats-banner-affiliates.php']['listorder']))
  40          $listorder = $Session['prefs']['stats-banner-affiliates.php']['listorder'];
  41      else
  42          $listorder = '';
  43  }
  44  
  45  if (!isset($orderdirection))
  46  {
  47      if (isset($Session['prefs']['stats-banner-affiliates.php']['orderdirection']))
  48          $orderdirection = $Session['prefs']['stats-banner-affiliates.php']['orderdirection'];
  49      else
  50          $orderdirection = '';
  51  }
  52  
  53  if (isset($Session['prefs']['stats-banner-affiliates.php']['nodes']))
  54      $node_array = explode (",", $Session['prefs']['stats-banner-affiliates.php']['nodes']);
  55  else
  56      $node_array = array();
  57  
  58  
  59  
  60  /*********************************************************/
  61  /* HTML framework                                        */
  62  /*********************************************************/
  63  
  64  if (isset($Session['prefs']['stats-campaign-banners.php']['listorder']))
  65      $navorder = $Session['prefs']['stats-campaign-banners.php']['listorder'];
  66  else
  67      $navorder = '';
  68  
  69  if (isset($Session['prefs']['stats-campaign-banners.php']['orderdirection']))
  70      $navdirection = $Session['prefs']['stats-campaign-banners.php']['orderdirection'];
  71  else
  72      $navdirection = '';
  73  
  74  
  75  $res = phpAds_dbQuery("
  76      SELECT
  77          *
  78      FROM
  79          ".$phpAds_config['tbl_banners']."
  80      WHERE
  81          clientid = '$campaignid'
  82      ".phpAds_getBannerListOrder($navorder, $navdirection)."
  83  ") or phpAds_sqlDie();
  84  
  85  while ($row = phpAds_dbFetchArray($res))
  86  {
  87      phpAds_PageContext (
  88          phpAds_buildBannerName ($row['bannerid'], $row['description'], $row['alt']),
  89          "stats-banner-affiliates.php?clientid=".$clientid."&campaignid=".$campaignid."&bannerid=".$row['bannerid'],
  90          $bannerid == $row['bannerid']
  91      );
  92  }
  93  
  94  phpAds_PageShortcut($strClientProperties, 'client-edit.php?clientid='.$clientid, 'images/icon-client.gif');
  95  phpAds_PageShortcut($strCampaignProperties, 'campaign-edit.php?clientid='.$clientid.'&campaignid='.$campaignid, 'images/icon-campaign.gif');
  96  phpAds_PageShortcut($strBannerProperties, 'banner-edit.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid, 'images/icon-banner-stored.gif');
  97  phpAds_PageShortcut($strModifyBannerAcl, 'banner-acl.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid, 'images/icon-acl.gif');
  98  
  99  
 100  phpAds_PageHeader("2.1.2.2.2");
 101      echo "<img src='images/icon-client.gif' align='absmiddle'>&nbsp;".phpAds_getParentName($campaignid);
 102      echo "&nbsp;<img src='images/".$phpAds_TextDirection."/caret-rs.gif'>&nbsp;";
 103      echo "<img src='images/icon-campaign.gif' align='absmiddle'>&nbsp;".phpAds_getClientName($campaignid);
 104      echo "&nbsp;<img src='images/".$phpAds_TextDirection."/caret-rs.gif'>&nbsp;";
 105      echo "<img src='images/icon-banner-stored.gif' align='absmiddle'>&nbsp;<b>".phpAds_getBannerName($bannerid)."</b><br><br>";
 106      echo phpAds_buildBannerCode($bannerid)."<br><br><br><br>";
 107      phpAds_ShowSections(array("2.1.2.2.1", "2.1.2.2.2"));
 108  
 109  
 110  
 111  /*********************************************************/
 112  /* Main code                                             */
 113  /*********************************************************/
 114  
 115  $manual['clicks'] = 0;
 116  $manual['views'] = 0;
 117  
 118  
 119  // Get affiliates and build the tree
 120  $res_affiliates = phpAds_dbQuery("
 121      SELECT 
 122          affiliateid, name
 123      FROM 
 124          ".$phpAds_config['tbl_affiliates']."
 125      ".phpAds_getAffiliateListOrder ($listorder, $orderdirection)."
 126      ") or phpAds_sqlDie();
 127  
 128  
 129  while ($row_affiliates = phpAds_dbFetchArray($res_affiliates))
 130  {
 131      $affiliates[$row_affiliates['affiliateid']] = $row_affiliates;
 132      $affiliates[$row_affiliates['affiliateid']]['expand'] = 0;
 133      $affiliates[$row_affiliates['affiliateid']]['count'] = 0;
 134  }
 135  
 136  // Get the zones for each affiliate
 137  $res_zones = phpAds_dbQuery("
 138      SELECT 
 139          zoneid, affiliateid, zonename, delivery, what
 140      FROM 
 141          ".$phpAds_config['tbl_zones']."
 142          ".phpAds_getZoneListOrder ($listorder, $orderdirection)."
 143      ") or phpAds_sqlDie();
 144  
 145  while ($row_zones = phpAds_dbFetchArray($res_zones))
 146  {
 147      if (isset($affiliates[$row_zones['affiliateid']]))
 148      {
 149          $zones[$row_zones['zoneid']] = $row_zones;
 150          $affiliates[$row_zones['affiliateid']]['count']++;
 151          
 152          $zones[$row_zones['zoneid']]['views'] = 0;
 153          $zones[$row_zones['zoneid']]['clicks'] = 0;
 154      }
 155  }
 156  
 157  
 158  // Get the adviews/clicks for each banner
 159  if ($phpAds_config['compact_stats'])
 160  {
 161      $res_stats = phpAds_dbQuery("
 162          SELECT
 163              zoneid,
 164              sum(views) as views,
 165              sum(clicks) as clicks
 166          FROM 
 167              ".$phpAds_config['tbl_adstats']."
 168          WHERE
 169              bannerid = '".$bannerid."'
 170          GROUP BY
 171              zoneid
 172          ") or phpAds_sqlDie();
 173      
 174      while ($row_stats = phpAds_dbFetchArray($res_stats))
 175      {
 176          if (isset($zones[$row_stats['zoneid']]))
 177          {
 178              $zones[$row_stats['zoneid']]['clicks'] = $row_stats['clicks'];
 179              $zones[$row_stats['zoneid']]['views'] = $row_stats['views'];
 180          }
 181          else
 182          {
 183              $manual['clicks'] += $row_stats['clicks'];
 184              $manual['views'] += $row_stats['views'];
 185          }
 186      }
 187  }
 188  else
 189  {
 190      $res_stats = phpAds_dbQuery("
 191          SELECT
 192              zoneid,
 193              count(*) as views
 194          FROM 
 195              ".$phpAds_config['tbl_adviews']."
 196          WHERE
 197              bannerid = '".$bannerid."'
 198          GROUP BY
 199              zoneid
 200          ") or phpAds_sqlDie();
 201      
 202      while ($row_stats = phpAds_dbFetchArray($res_stats))
 203      {
 204          if (isset($zones[$row_stats['zoneid']]))
 205          {
 206              $zones[$row_stats['zoneid']]['views'] = $row_stats['views'];
 207              $zones[$row_stats['zoneid']]['clicks'] = 0;
 208          }
 209          else
 210          {
 211              $manual['views'] += $row_stats['views'];
 212          }
 213      }
 214      
 215      
 216      $res_stats = phpAds_dbQuery("
 217          SELECT
 218              zoneid,
 219              count(*) as clicks
 220          FROM 
 221              ".$phpAds_config['tbl_adclicks']."
 222          WHERE
 223              bannerid = '".$bannerid."'
 224          GROUP BY
 225              zoneid
 226          ") or phpAds_sqlDie();
 227      
 228      while ($row_stats = phpAds_dbFetchArray($res_stats))
 229      {
 230          if (isset($zones[$row_stats['zoneid']]))
 231          {
 232              $zones[$row_stats['zoneid']]['clicks'] = $row_stats['clicks'];
 233          }
 234          else
 235          {
 236              $manual['clicks'] += $row_stats['clicks'];
 237          }
 238      }
 239  }
 240  
 241  
 242  
 243  // Add ID found in expand to expanded nodes
 244  if (isset($expand) && $expand != '')
 245      $node_array[] = $expand;
 246  
 247  for ($i=0; $i < sizeof($node_array);$i++)
 248  {
 249      if (isset($collapse) && $collapse == $node_array[$i])
 250          unset ($node_array[$i]);
 251      else
 252      {
 253          if (isset($affiliates[$node_array[$i]]))
 254              $affiliates[$node_array[$i]]['expand'] = 1;
 255      }
 256  }
 257  
 258  
 259  
 260  // Build Tree
 261  if (isset($zones) && is_array($zones) && count($zones) > 0)
 262  {
 263      // Add zone to affiliate
 264      foreach (array_keys($zones) as $zkey)
 265          $affiliates[$zones[$zkey]['affiliateid']]['zones'][$zkey] = $zones[$zkey];
 266      
 267      unset ($zones);
 268  }
 269  
 270  $totalviews = 0;
 271  $totalclicks = 0;
 272  
 273  if (isset($affiliates) && is_array($affiliates) && count($affiliates) > 0)
 274  {
 275      // Calculate statistics for affiliates
 276      foreach (array_keys($affiliates) as $key)
 277      {
 278          $affiliatesviews = 0;
 279          $affiliatesclicks = 0;
 280          
 281          if (isset($affiliates[$key]['zones']) && sizeof ($affiliates[$key]['zones']) > 0)
 282          {
 283              $zones = $affiliates[$key]['zones'];
 284              
 285              // Calculate statistics for zones
 286              foreach (array_keys($zones) as $zkey)
 287              {
 288                  $affiliatesviews += $zones[$zkey]['views'];
 289                  $affiliatesclicks += $zones[$zkey]['clicks'];
 290              }
 291          }
 292          
 293          $totalviews += $affiliatesviews;
 294          $totalclicks += $affiliatesclicks;
 295          
 296          $affiliates[$key]['clicks'] = $affiliatesclicks;
 297          $affiliates[$key]['views'] = $affiliatesviews;
 298      }
 299      
 300      unset ($zones);
 301  }
 302  
 303  $totalviews += $manual['views'];
 304  $totalclicks += $manual['clicks'];
 305  
 306  
 307  if ($totalviews > 0 || $totalclicks > 0)
 308  {
 309      echo "<br><br>";
 310      echo "<table border='0' width='100%' cellpadding='0' cellspacing='0'>";    
 311      
 312      echo "<tr height='25'>";
 313      echo '<td height="25" width="40%"><b>&nbsp;&nbsp;<a href="stats-banner-affiliates.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid.'&listorder=name">'.$GLOBALS['strName'].'</a>';
 314      
 315      if (($listorder == "name") || ($listorder == ""))
 316      {
 317          if  (($orderdirection == "") || ($orderdirection == "down"))
 318          {
 319              echo ' <a href="stats-banner-affiliates.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid.'&orderdirection=up">';
 320              echo '<img src="images/caret-ds.gif" border="0" alt="" title="">';
 321          }
 322          else
 323          {
 324              echo ' <a href="stats-banner-affiliates.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid.'&orderdirection=down">';
 325              echo '<img src="images/caret-u.gif" border="0" alt="" title="">';
 326          }
 327          echo '</a>';
 328      }
 329      
 330      echo '</b></td>';
 331      echo '<td height="25"><b><a href="stats-banner-affiliates.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid.'&listorder=id">'.$GLOBALS['strID'].'</a>';
 332      
 333      if ($listorder == "id")
 334      {
 335          if  (($orderdirection == "") || ($orderdirection == "down"))
 336          {
 337              echo ' <a href="stats-banner-affiliates.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid.'&orderdirection=up">';
 338              echo '<img src="images/caret-ds.gif" border="0" alt="" title="">';
 339          }
 340          else
 341          {
 342              echo ' <a href="stats-banner-affiliates.php?clientid='.$clientid.'&campaignid='.$campaignid.'&bannerid='.$bannerid.'&orderdirection=down">';
 343              echo '<img src="images/caret-u.gif" border="0" alt="" title="">';
 344          }
 345          echo '</a>';
 346      }
 347      
 348      echo '</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>';
 349      echo "<td height='25' align='".$phpAds_TextAlignRight."'><b>".$GLOBALS['strViews']."</b></td>";
 350      echo "<td height='25' align='".$phpAds_TextAlignRight."'><b>".$GLOBALS['strClicks']."</b></td>";
 351      echo "<td height='25' align='".$phpAds_TextAlignRight."'><b>".$GLOBALS['strCTRShort']."</b>&nbsp;&nbsp;</td>";
 352      echo "</tr>";
 353      
 354      echo "<tr height='1'><td colspan='5' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>";
 355      
 356      
 357      
 358      $i=0;
 359      
 360      if (isset($affiliates) && is_array($affiliates) && count($affiliates))
 361      {
 362          foreach (array_keys($affiliates) as $key)
 363          {
 364              $affiliate = $affiliates[$key];
 365              
 366              if ($affiliate['views'] || $affiliate['clicks'])
 367              {
 368                  echo "<tr height='25' ".($i%2==0?"bgcolor='#F6F6F6'":"").">";
 369                  
 370                  // Icon & name
 371                  echo "<td height='25'>";
 372                  if (isset($affiliate['zones']))
 373                  {
 374                      if ($affiliate['expand'] == '1')
 375                          echo "&nbsp;<a href='stats-banner-affiliates.php?clientid=".$clientid."&campaignid=".$campaignid."&bannerid=".$bannerid."&collapse=".$affiliate['affiliateid']."'><img src='images/triangle-d.gif' align='absmiddle' border='0'></a>&nbsp;";
 376                      else
 377                          echo "&nbsp;<a href='stats-banner-affiliates.php?clientid=".$clientid."&campaignid=".$campaignid."&bannerid=".$bannerid."&expand=".$affiliate['affiliateid']."'><img src='images/".$phpAds_TextDirection."/triangle-l.gif' align='absmiddle' border='0'></a>&nbsp;";
 378                  }
 379                  else
 380                      echo "&nbsp;<img src='images/spacer.gif' height='16' width='16'>&nbsp;";
 381                      
 382                  echo "<img src='images/icon-affiliate.gif' align='absmiddle'>&nbsp;";
 383                  echo "<a href='stats-affiliate-history.php?affiliateid=".$affiliate['affiliateid']."'>".$affiliate['name']."</a>";
 384                  echo "</td>";
 385                  
 386                  echo "<td height='25'>".$affiliate['affiliateid']."</td>";
 387                  echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($affiliate['views'])."</td>";
 388                  echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($affiliate['clicks'])."</td>";
 389                  echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_buildCTR($affiliate['views'], $affiliate['clicks'])."&nbsp;&nbsp;</td>";
 390                  echo "</tr>";
 391                  
 392                  
 393                  
 394                  if (isset($affiliate['zones']) && sizeof ($affiliate['zones']) > 0 && $affiliate['expand'] == '1')
 395                  {
 396                      $zones = $affiliate['zones'];
 397                      
 398                      foreach (array_keys($zones) as $zkey)
 399                      {
 400                          if ($zones[$zkey]['views'] || $zones[$zkey]['clicks'])
 401                          {
 402                              // Divider
 403                              echo "<tr height='1'>";
 404                              echo "<td ".($i%2==0?"bgcolor='#F6F6F6'":"")."><img src='images/spacer.gif' width='1' height='1'></td>";
 405                              echo "<td colspan='5' bgcolor='#888888'><img src='images/break-l.gif' height='1' width='100%'></td>";
 406                              echo "</tr>";
 407                              
 408                              // Icon & name
 409                              echo "<tr height='25' ".($i%2==0?"bgcolor='#F6F6F6'":"")."><td height='25'>";
 410                              echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
 411                              echo "<img src='images/spacer.gif' height='16' width='16' align='absmiddle'>&nbsp;";
 412                              
 413                              if ($zones[$zkey]['what'] != '')
 414                              {
 415                                  if ($zones[$zkey]['delivery'] == phpAds_ZoneBanner)
 416                                      echo "<img src='images/icon-zone.gif' align='absmiddle'>&nbsp;";
 417                                  elseif ($zones[$zkey]['delivery'] == phpAds_ZoneInterstitial)
 418                                      echo "<img src='images/icon-interstitial.gif' align='absmiddle'>&nbsp;";
 419                                  elseif ($zones[$zkey]['delivery'] == phpAds_ZonePopup)
 420                                      echo "<img src='images/icon-popup.gif' align='absmiddle'>&nbsp;";
 421                                  elseif ($zones[$zkey]['delivery'] == phpAds_ZoneText)
 422                                      echo "<img src='images/icon-textzone.gif' align='absmiddle'>&nbsp;";
 423                              }
 424                              else
 425                              {
 426                                  if ($zones[$zkey]['delivery'] == phpAds_ZoneBanner)
 427                                      echo "<img src='images/icon-zone-d.gif' align='absmiddle'>&nbsp;";
 428                                  elseif ($zones[$zkey]['delivery'] == phpAds_ZoneInterstitial)
 429                                      echo "<img src='images/icon-interstitial-d.gif' align='absmiddle'>&nbsp;";
 430                                  elseif ($zones[$zkey]['delivery'] == phpAds_ZonePopup)
 431                                      echo "<img src='images/icon-popup-d.gif' align='absmiddle'>&nbsp;";
 432                                  elseif ($zones[$zkey]['delivery'] == phpAds_ZoneText)
 433                                      echo "<img src='images/icon-textzone-d.gif' align='absmiddle'>&nbsp;";
 434                              }
 435                              
 436                              //echo "<img src='images/icon-zone.gif' align='absmiddle'>&nbsp;";
 437                              
 438                              echo "<a href='stats-zone-history.php?affiliateid=".$affiliate['affiliateid']."&zoneid=".$zones[$zkey]['zoneid']."'>".$zones[$zkey]['zonename']."</td>";
 439                              echo "</td>";
 440                              
 441                              echo "<td height='25'>".$zones[$zkey]['zoneid']."</td>";
 442                              echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($zones[$zkey]['views'])."</td>";
 443                              echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($zones[$zkey]['clicks'])."</td>";
 444                              echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_buildCTR($zones[$zkey]['views'], $zones[$zkey]['clicks'])."&nbsp;&nbsp;</td>";
 445                              echo "</tr>";
 446                          }
 447                      }
 448                  }
 449                  
 450                  echo "<tr height='1'><td colspan='5' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>";
 451                  $i++;
 452              }
 453          }
 454      }
 455      
 456      if ($manual['views'] || $manual['clicks'])
 457      {
 458          echo "<tr height='25' ".($i%2==0?"bgcolor='#F6F6F6'":"").">";
 459          echo "<td height='25'>&nbsp;&nbsp;".$strUnknown."</td>";
 460          
 461          echo "<td height='25'>-</td>";
 462          echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($manual['views'])."</td>";
 463          echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($manual['clicks'])."</td>";
 464          echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_buildCTR($manual['views'], $manual['clicks'])."&nbsp;&nbsp;</td>";
 465          echo "</tr>";
 466          
 467          echo "<tr height='1'><td colspan='5' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>";
 468      }
 469      
 470      
 471      // Total
 472      echo "<tr height='25'><td height='25'>&nbsp;&nbsp;<b>".$strTotal."</b></td>";
 473      echo "<td height='25'>&nbsp;</td>";
 474      echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($totalviews)."</td>";
 475      echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_formatNumber($totalclicks)."</td>";
 476      echo "<td height='25' align='".$phpAds_TextAlignRight."'>".phpAds_buildCTR($totalviews, $totalclicks)."&nbsp;&nbsp;</td>";
 477      echo "</tr>";
 478      
 479      echo "</table>";
 480      echo "<br><br>";
 481  }
 482  else
 483  {
 484      echo "<br><div class='errormessage'><img class='errormessage' src='images/info.gif' width='16' height='16' border='0' align='absmiddle'>";
 485      echo $strNoStats.'</div>';
 486  }
 487  
 488  
 489  
 490  /*********************************************************/
 491  /* Store preferences                                     */
 492  /*********************************************************/
 493  
 494  $Session['prefs']['stats-banner-affiliates.php']['listorder'] = $listorder;
 495  $Session['prefs']['stats-banner-affiliates.php']['orderdirection'] = $orderdirection;
 496  $Session['prefs']['stats-banner-affiliates.php']['nodes'] = implode (",", $node_array);
 497  
 498  phpAds_SessionDataStore();
 499  
 500  
 501  
 502  /*********************************************************/
 503  /* HTML framework                                        */
 504  /*********************************************************/
 505  
 506  phpAds_PageFooter();
 507  
 508  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]