<?php
/*
PluginAdRotate
Copyright (C) 2005 Matthew Wood

This library is free software; you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published by 
the Free Software Foundation; either version 2.1 of the License, or 
(at your option) any later version.
*/

include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php");
include_once(PLOG_CLASS_PATH.
    "plugins/adrotate/class/dao/adrotateadsstats.class.php");
include_once(PLOG_CLASS_PATH.
    "plugins/adrotate/class/dao/adrotateadstats.class.php");
	
	class PluginAdRotate extends PluginBase
	{
		function PluginAdRotate()
		{
			$this->PluginBase();		
		
      /*setup basic information */
			$this->id = "adrotate";
			$this->desc = "Allows site admins to display and maintain simple ad campaigns on their pLog site";
			$this->author = "woodzy";
			$this->locale = Array();				
			
			/*register menu entries*/
			$this->addMenuEntry( "/menu/Manage", "AdRotate", "", "" );	
			$this->addMenuEntry( "/menu/Manage/AdRotate", "ViewAdList", "?op=adrotateViewStats" );
			
			/* register needed actions */
			$this->registerAdminAction( "adrotateViewStats", "AdminAdRotateViewStats" );
			$this->registerAdminAction( "adrotateAddAd", "AdminAdRotateAddAdAction" );			
			$this->registerAdminAction( "adrotateRemoveAd", "AdminAdRotateRemoveAdAction" );
            $this->registerBlogAction( "adrotateRedirect", "AdRotateRedirectAction" );
		}
		
		/**
		 * @private
		 */
		function install()
		{
		  include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
			/** 
       * create the table that will keep track of current banner campaigns
       * and usage statistics for the administrator
       */
      $fields = "
            id I(10) NOTNULL PRIMARY AUTOINCREMENT,
						impressions I(10) NOTNULL,
						clicks I(10) NOTNULL,
						imageurl TEXT NOTNULL,
						redirecturl TEXT NOTNULL,
						clickmd5 C(34) NOTNULL KEY,
						alttext TEXT NOTNULL,
						type I(10) NOTNULL,
						dateadded I(11) NOTNULL";

				  
			$db =& Db::getDb();				  
			$dbPrefix = Db::getPrefix();
			$tableName = $dbPrefix."adrotate_statistics";

      /*lifted from other plugins*/
			// create the data dictionary and create the table if necessary
      $dict = NewPDbDataDictionary( $db );
      $sqlArray = $dict->ChangeTableSQL( $tableName, $fields );
      $result = $dict->ExecuteSQLArray( $sqlArray );
      if( !$result )
        die( "There was an error creating the plugin tables!" );			
      /*endlift*/
		}			
    function generateAdLink()
    {
      $aras = new AdRotateAdsStats();
      $ad = $aras->getRandomAd();
      $aras->incImpressions($ad->getId());

			return $ad;
    }
	}
/* vim:ts=2:sw=2:cin:ai:expandtab:
*/ 
?>
