You are here

function ad_install in Advertisement 5.2

Same name and namespace in other branches
  1. 5 ad.install \ad_install()
  2. 6.3 ad.install \ad_install()
  3. 6 ad.install \ad_install()
  4. 6.2 ad.install \ad_install()
  5. 7 ad.install \ad_install()
  6. 7.2 ad.install \ad_install()

Ad module database schema. Copyright (c) 2005-2007 Jeremy Andrews <jeremy@kerneltrap.org>. All rights reserved.

File

./ad.install, line 9

Code

function ad_install() {
  switch ($GLOBALS['db_type']) {
    case 'pgsql':

      /* The ad table stores administrative information about each ad.  The
       * actual ad itself can be found in the appropriate ad type table.
       */
      db_query("CREATE TABLE {ads} (\n       aid INT NOT NULL UNIQUE DEFAULT '0' PRIMARY KEY,\n       uid INT NOT NULL DEFAULT '0',\n \n       adstatus VARCHAR(255) NOT NULL DEFAULT '',\n       adtype VARCHAR(255) NOT NULL DEFAULT '',\n\n       redirect VARCHAR(255) NOT NULL DEFAULT '',\n\n       autoactivate INT NOT NULL DEFAULT '0',\n       autoactivated INT NOT NULL DEFAULT '0',\n       autoexpire INT NOT NULL DEFAULT '0',\n       autoexpired INT NOT NULL DEFAULT '0',\n\n       activated INT NOT NULL DEFAULT '0',\n       maxviews INT NOT NULL DEFAULT '0',\n       maxclicks INT NOT NULL DEFAULT '0',\n       expired INT NOT NULL DEFAULT '0'\n     );");

      /**
       * This table counts each time a given action occurs on an ad.  Actions
       * include when the ad is viewed, clicked, enabled and disabled.
       * Statistics are collected at an hourly granularity.
       *
       * The source column is used for tracking statistics for externally
       * hosted ads.
       *
       * Actions:
       *  'view', 'click', 'enable', 'disable'
       */
      db_query("CREATE TABLE {ad_statistics} (\n       sid SERIAL NOT NULL PRIMARY KEY,\n       aid INT NOT NULL DEFAULT '0',\n\n       date INT NOT NULL DEFAULT '0',\n       action VARCHAR(255) NOT NULL DEFAULT '',\n       adgroup VARCHAR(255) NULL DEFAULT '',\n       hostid VARCHAR(32) NULL DEFAULT '',\n       count INT NOT NULL DEFAULT '0'\n     );");

      /**
       * The ad_clicks table tracks when a given advertisement was clicked,
       * who clicked it (uid if any and IP address), and what page they were
       * on when they clicked it.
       */
      db_query("CREATE TABLE {ad_clicks} (\n        cid SERIAL NOT NULL PRIMARY KEY,\n        aid INT NOT NULL DEFAULT '0',\n        uid INT NOT NULL DEFAULT '0',\n\n        status INT NOT NULL DEFAULT '0',\n \n        hostname varchar(128) NOT NULL DEFAULT '',\n        user_agent varchar(255) NOT NULL DEFAULT '',\n        adgroup varchar(255) NOT NULL DEFAULT '',\n        hostid varchar(32) NOT NULL DEFAULT '',\n        url varchar(255) DEFAULT '',\n        timestamp INT NOT NULL DEFAULT '0'\n      );");
      break;
    case 'mysql':
    case 'mysqli':
    default:

      /* The ad table stores administrative information about each ad.  The
       * actual ad itself can be found in the appropriate ad type table.
       */
      db_query("CREATE TABLE {ads} (\n        aid INT(10) UNSIGNED NOT NULL DEFAULT '0',\n        uid INT(10) UNSIGNED NOT NULL DEFAULT '0',\n  \n        adstatus VARCHAR(255) NOT NULL DEFAULT '',\n        adtype VARCHAR(255) NOT NULL DEFAULT '',\n\n        redirect VARCHAR(255) NOT NULL DEFAULT '',\n\n        autoactivate INT UNSIGNED NOT NULL DEFAULT '0',\n        autoactivated INT UNSIGNED NOT NULL DEFAULT '0',\n        autoexpire INT UNSIGNED NOT NULL DEFAULT '0',\n        autoexpired INT UNSIGNED NOT NULL DEFAULT '0',\n\n        activated INT UNSIGNED NOT NULL DEFAULT '0',\n        maxviews INT UNSIGNED NOT NULL DEFAULT '0',\n        maxclicks INT UNSIGNED NOT NULL DEFAULT '0',\n        expired INT UNSIGNED NOT NULL DEFAULT '0',\n\n        PRIMARY KEY  (aid),\n        KEY (uid),\n        KEY (autoactivate),\n        KEY (autoexpire)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      /**
       * This table counts each time a given action occurs on an ad.  Actions
       * include when the ad is viewed, clicked, enabled and disabled.
       * Statistics are collected at an hourly granularity.
       *
       * The source column is used for tracking statistics for externally
       * hosted ads.
       *
       * Actions:
       *  'view', 'click', 'enable', 'disable'
       */
      db_query("CREATE TABLE {ad_statistics} (\n        sid INT UNSIGNED NOT NULL AUTO_INCREMENT,\n        aid INT UNSIGNED NOT NULL DEFAULT '0',\n\n        date INT(10) UNSIGNED NOT NULL DEFAULT '0',\n        action VARCHAR(255) NOT NULL DEFAULT '',\n        adgroup VARCHAR(255) NULL DEFAULT '',\n        hostid VARCHAR(32) NULL DEFAULT '',\n        count INT(11) UNSIGNED NOT NULL DEFAULT '0',\n\n        PRIMARY KEY  (sid),\n        KEY (aid),\n        KEY (date),\n        KEY (action),\n        KEY (adgroup),\n        KEY (hostid)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      /**
       * The ad_clicks table tracks when a given advertisement was clicked,
       * who clicked it (uid if any and IP address), and what page they were
       * on when they clicked it.
       */
      db_query("CREATE TABLE {ad_clicks} (\n        cid INT UNSIGNED NOT NULL AUTO_INCREMENT,\n        aid INT UNSIGNED NOT NULL DEFAULT '0',\n        uid int(10) UNSIGNED NOT NULL DEFAULT '0',\n\n        status INT(2) NOT NULL DEFAULT '0',\n\n        hostname varchar(128) NOT NULL DEFAULT '',\n        user_agent varchar(255) NOT NULL DEFAULT '',\n        adgroup varchar(255) NOT NULL DEFAULT '',\n        hostid varchar(32) NOT NULL DEFAULT '',\n        url varchar(255) DEFAULT '',\n        timestamp INT(11) UNSIGNED NOT NULL DEFAULT '0',\n\n        PRIMARY KEY  (cid),\n        KEY  (aid),\n        KEY  (status),\n        KEY  (hostname),\n        KEY  (user_agent),\n        KEY  (adgroup),\n        KEY  (hostid),\n        KEY  (url)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
  }
  drupal_set_message(t('The necessary ad module tables have been created.'));
}