<?php

chdir( "/home/kp/public_html"  );

// echo getcwd() . "<br />\n";
// http://drupal.org/node/201594
// require_once './debuglib_php4.php';

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// bootstrap_invoke_all('init');
// ini_set('memory_limit', '512M');
// echo "Bootstrap successful\n\n";

//Authenticate as user 1
user_authenticate('admin', 'admin');


global $base_url;
global $base_path;
global $base_root;

$base_url  = $base_root;  
$base_path = '/';  


echo '<script type="text/javascript" src="/sites/all/modules/ad/flash/scripts/AC_RunActiveContent.js"></script>' . "\n";

$result = db_query("SELECT aid, title from  ads, node  where ads.aid=node.nid and ads.adstatus = 'active' order by title");

while ( $listing = db_fetch_object( $result )) {
  echo "<hr />\n";
  echo $listing->aid . "<br />\n";
  echo '<h2>' . $listing->title . '</h2>' . "\n";

  $adnode = node_load( $listing->aid );

//  echo "=================================\n";
//  print_r( $adnode );
//  echo "=================================\n";
  $filename = '';
  $filepath = '';
  $filemime = '';

  foreach ($adnode->files as $file) {
    if ( $file->list == 1 )
    {
      $filename = $file->filename;
      $filepath = $file->filepath;
      $filemime = $file->filemime;
      break;
    }
  }

  echo "type: " . $adnode->adtype . "<br />\n";
  echo "url: " . $adnode->url . "<br />\n";
//  echo "filename: " . $filename . "<br />\n";
//  echo "filepath: " . $filepath . "<br />\n";
//  echo "filemime: " . $filemime . "<br />\n";

//   $result2 = db_query("SELECT td.name, v.name vname from term_node tn, term_data td, ads a, vocabulary v WHERE a.aid = tn.nid AND tn.tid = td.tid and td.vid=v.vid and a.aid=$listing->aid order by td.vid");

  $result2 = db_query("SELECT td.vid, td.name from term_node tn, term_data td, ads a WHERE a.aid = tn.nid AND tn.tid = td.tid and a.aid=$listing->aid order by td.vid, td.name");

  $adlocations = array();
  $sections = array();
  $regions = array();

  while ( $term = db_fetch_object( $result2 )) {
    switch ( $term->vid ) {
      case 2:
        $adlocations[] = $term->name;
        break;

      case 3:
        $sections[] = $term->name;
        break;

      case 4:
        $regions[] = $term->name;
        break;
    }
  }

  echo "<strong>Ad Location</strong><br />\n";
  foreach ($adlocations as $adlocation) {
    echo $adlocation . "<br />\n";
  }
  echo "<br />\n";

  echo "<strong>Section</strong><br />\n";
  foreach ($sections as $section) {
    echo $section . "<br />\n";
  }
  echo "<br />\n";

  echo "<strong>Region</strong><br />\n";
  foreach ($regions as $region) {
    echo $region . "<br />\n";
  }
  echo "<br />\n";

  if ( $adnode->adtype == 'flash' )
  {
//    echo "#### flash ad ####<br />\n";
    echo ad_flash_display_ad( $adnode );
//    echo "#### flash ad ####<br />\n";
  }
  else
  {
//    echo "#### image ad ####<br />\n";
    echo ad_image_display_ad( $adnode );
//    echo "#### image ad ####<br />\n";
  }

  unset( $adnode );
}


// show_vars(1);
?>
