| 1 |
<?php
|
| 2 |
// $Id: $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Ad module database schema.
|
| 6 |
* Copyright (c) 2005-2006 Jeremy Andrews <jeremy@kerneltrap.org>.
|
| 7 |
* All rights reserved.
|
| 8 |
*/
|
| 9 |
|
| 10 |
function ad_install() {
|
| 11 |
switch ($GLOBALS['db_type']) {
|
| 12 |
case 'mysql':
|
| 13 |
case 'mysqli':
|
| 14 |
default:
|
| 15 |
|
| 16 |
/* The ad table stores administrative information about each ad. The
|
| 17 |
* actual ad itself can be found in the appropriate ad type table.
|
| 18 |
*/
|
| 19 |
db_query("CREATE TABLE {ads} (
|
| 20 |
aid INT(10) UNSIGNED NOT NULL UNIQUE DEFAULT '0',
|
| 21 |
uid INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
| 22 |
gid INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
| 23 |
|
| 24 |
adstatus VARCHAR(255) NOT NULL DEFAULT '',
|
| 25 |
adtype VARCHAR(255) NOT NULL DEFAULT '',
|
| 26 |
|
| 27 |
redirect VARCHAR(255) NOT NULL DEFAULT '',
|
| 28 |
|
| 29 |
autoactivate INT UNSIGNED NOT NULL DEFAULT '0',
|
| 30 |
autoactivated INT UNSIGNED NOT NULL DEFAULT '0',
|
| 31 |
autoexpire INT UNSIGNED NOT NULL DEFAULT '0',
|
| 32 |
autoexpired INT UNSIGNED NOT NULL DEFAULT '0',
|
| 33 |
|
| 34 |
expire_notified INT UNSIGNED NOT NULL DEFAULT '0',
|
| 35 |
renew_notified INT UNSIGNED NOT NULL DEFAULT '0',
|
| 36 |
|
| 37 |
PRIMARY KEY (aid),
|
| 38 |
KEY (uid),
|
| 39 |
KEY (gid),
|
| 40 |
KEY (autoactivate),
|
| 41 |
KEY (autoexpire),
|
| 42 |
KEY (expire_notified),
|
| 43 |
KEY (renew_notified))");
|
| 44 |
|
| 45 |
/**
|
| 46 |
* All ads are assigned to at least one group. The ad_groups table
|
| 47 |
* defines these groups. It is possible for a group to be comprised of
|
| 48 |
* multiple ad_types. Ads are generally displayed by group, so for
|
| 49 |
* example you may call a group 'header', and then use it to randomly
|
| 50 |
* display ads in your website's header area.
|
| 51 |
*/
|
| 52 |
db_query("CREATE TABLE {ad_groups} (
|
| 53 |
gid INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
| 54 |
name VARCHAR(255) NOT NULL DEFAULT '',
|
| 55 |
description TEXT NOT NULL DEFAULT '',
|
| 56 |
|
| 57 |
PRIMARY KEY (gid),
|
| 58 |
UNIQUE KEY (name))");
|
| 59 |
|
| 60 |
/**
|
| 61 |
* All ads must be assigned to a group. To get started, we create the
|
| 62 |
* default group to which all new ads will be assigned. The default
|
| 63 |
* group can not be deleted or modified. If a non-default group is
|
| 64 |
* deleted, ads in that group are assigned to the default group.
|
| 65 |
*/
|
| 66 |
db_query("INSERT INTO ad_groups (gid,name, description) VALUES(1, 'default', 'All new advertisements will be added to this default group until you create your own custom advertisement groups.')");
|
| 67 |
|
| 68 |
/**
|
| 69 |
* Every ad can have one or more owners.
|
| 70 |
*/
|
| 71 |
db_query("CREATE TABLE {ad_owners} (
|
| 72 |
oid INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
| 73 |
aid INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
| 74 |
uid INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
| 75 |
|
| 76 |
PRIMARY KEY (oid),
|
| 77 |
KEY (aid),
|
| 78 |
KEY (uid))");
|
| 79 |
|
| 80 |
/**
|
| 81 |
* Permissions can be granted to each owner of each ad. The same owner
|
| 82 |
* can own multiple ads, and can have different permissions for each ad.
|
| 83 |
*/
|
| 84 |
db_query("CREATE TABLE {ad_permissions} (
|
| 85 |
oid INT(11) UNSIGNED NOT NULL DEFAULT '0',
|
| 86 |
permissions LONGTEXT NULL DEFAULT '',
|
| 87 |
PRIMARY KEY (oid))");
|
| 88 |
|
| 89 |
/**
|
| 90 |
* Notifications can be granted to each owner of each ad. The same owner
|
| 91 |
* can own multiple ads, and can have different notifications for each
|
| 92 |
* ad. Notifications are defined by their type and an offset in seconds.
|
| 93 |
* For example, 'day, 0' would send a notification at the start of
|
| 94 |
* every day, and 'expire, -86400' would send a notification one day
|
| 95 |
* before the ad expires.
|
| 96 |
*/
|
| 97 |
db_query("CREATE TABLE {ad_notifications} (
|
| 98 |
oid INT(11) UNSIGNED NOT NULL DEFAULT '0',
|
| 99 |
|
| 100 |
seconds INT(11) SIGNED NOT NULL DEFAULT '0',
|
| 101 |
type VARCHAR(255) NOT NULL DEFAULT '',
|
| 102 |
|
| 103 |
PRIMARY KEY (oid))");
|
| 104 |
|
| 105 |
/**
|
| 106 |
* This table counts each time a given action occurs on an ad. Actions
|
| 107 |
* include when the ad is viewed, clicked, enabled and disabled.
|
| 108 |
* Statistics are collected at an hourly granularity.
|
| 109 |
*
|
| 110 |
* The source column is used for tracking statistics for externally
|
| 111 |
* hosted ads.
|
| 112 |
*
|
| 113 |
* Actions:
|
| 114 |
* 'view', 'click', 'enable', 'disable'
|
| 115 |
*/
|
| 116 |
db_query("CREATE TABLE {ad_statistics} (
|
| 117 |
sid INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
| 118 |
aid INT UNSIGNED NOT NULL DEFAULT '0',
|
| 119 |
|
| 120 |
date INT(10) UNSIGNED NOT NULL DEFAULT '0',
|
| 121 |
action VARCHAR(255) NOT NULL DEFAULT '',
|
| 122 |
hostid VARCHAR(32) NULL DEFAULT '',
|
| 123 |
count INT(11) UNSIGNED NOT NULL DEFAULT '0',
|
| 124 |
|
| 125 |
PRIMARY KEY (sid),
|
| 126 |
KEY (aid),
|
| 127 |
KEY (date),
|
| 128 |
KEY (action),
|
| 129 |
KEY (hostid))");
|
| 130 |
|
| 131 |
/**
|
| 132 |
* The ad_clicks table tracks when a given advertisement was clicked,
|
| 133 |
* who clicked it (uid if any and IP address), and what page they were
|
| 134 |
* on when they clicked it.
|
| 135 |
*/
|
| 136 |
db_query("CREATE TABLE {ad_clicks} (
|
| 137 |
cid INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
| 138 |
aid INT UNSIGNED NOT NULL DEFAULT '0',
|
| 139 |
uid int(10) UNSIGNED NOT NULL DEFAULT '0',
|
| 140 |
|
| 141 |
hostname varchar(128) NOT NULL DEFAULT '',
|
| 142 |
hostid varchar(32) NOT NULL DEFAULT '',
|
| 143 |
url varchar(255) DEFAULT '',
|
| 144 |
timestamp INT(11) UNSIGNED NOT NULL DEFAULT '0',
|
| 145 |
|
| 146 |
PRIMARY KEY (cid),
|
| 147 |
KEY (aid),
|
| 148 |
KEY (hostname),
|
| 149 |
KEY (hostid),
|
| 150 |
KEY (url))");
|
| 151 |
|
| 152 |
/**
|
| 153 |
* The ad_hosts table is used to configure users that can display ads
|
| 154 |
* remotely.
|
| 155 |
*/
|
| 156 |
db_query("CREATE TABLE {ad_hosts} (
|
| 157 |
uid INT UNSIGNED NOT NULL DEFAULT '0',
|
| 158 |
|
| 159 |
hostid varchar(32) DEFAULT '',
|
| 160 |
description TEXT NOT NULL DEFAULT '',
|
| 161 |
|
| 162 |
PRIMARY KEY (uid),
|
| 163 |
KEY (hostid))");
|
| 164 |
}
|
| 165 |
|
| 166 |
drupal_set_message(t('The necessary ad module tables have been created.'));
|
| 167 |
}
|