<?php
// $Id $

/**
 * Implementation of hook_install().
 */
function affiliates_install() {
  drupal_install_schema('affiliates');
  
  db_query("INSERT INTO {affiliates_cats} VALUES (NULL, 'Email Signature', 'Y');");
  db_query("INSERT INTO {affiliates_cats} VALUES (NULL, 'Buttons', 'Y');");
  db_query("INSERT INTO {affiliates_cats} VALUES (NULL, 'Ad Banners', 'Y');");
}

/**
 * Implementation of hook_uninstall().
 */
function sfx_affiliates_uninstall() {
  drupal_uninstall_schema('affiliates');
}


/**
* Implementation of hook_schema().
*/
function affiliates_schema() {
  $schema['affiliates'] = array(
    'fields' => array(
      'id' => array('type' => 'serial', 'length' => '10','unsigned' => TRUE, 'not null' => TRUE ),
      'user_id' => array('type' => 'int', 'length' => '10','unsigned' => TRUE,'default' => NULL ),
      'cookie_id' => array('type' => 'varchar', 'length' => '56','default' => NULL ),
      'ip' => array('type' => 'varchar', 'length' => '15','default' => NULL),
      'referer' => array('type' => 'varchar', 'length' => '80','default' => NULL),
      'ad_id' => array('type' => 'int', 'length' => '5','unsigned' => TRUE,'default' => NULL),
      'click_time' => array('type' => 'int', 'length' => '11','default' => NULL),  
    ),
    'indexes' => array(
      'affiliates_user_id' => array('user_id'),
      'affiliates_cookie_id' => array('cookie_id'),
      'affiliates_ip' => array('ip'),
      'affiliates_click_time' => array('click_time'),
    ),
    'primary key' => array('id'),
  );  
  $schema['affiliates_ads'] = array(
    'fields' => array(
      'ad_id' => array('type' => 'serial', 'length' => '5','unsigned' => TRUE, 'not null' => TRUE),
      'label' => array('type' => 'varchar', 'length' => '30','default' => NULL),
      'points' => array('type' => 'int', 'length' => '6','default' => NULL),
      'anchor' => array('type' => 'varchar', 'length' => '100','default' => NULL),
      'type' => array('type' => 'varchar', 'length' => '5','default' => NULL),
      'cat_id' => array('type' => 'int', 'length' => '3','unsigned' => TRUE, 'default' => NULL),
      'order_by' => array('type' => 'int', 'length' => '5','default' => NULL),
      'redirect' => array('type' => 'varchar', 'length' => '100','default' => NULL),
      'status' => array('type' => 'char', 'length' => '1','default' => 'a'),
     ),
    'indexes' => array(
      'affiliates_ads_label' => array('label'),
      'affiliates_ads_type' => array('type'),
      'affiliates_ads_cat_id' => array('cat_id'),
      'affiliates_ads_status' => array('status'),
    ),
    'primary key' => array('ad_id'),
  );  
  $schema['affiliates_cats'] = array(
    'fields' => array(
      'cat_id' => array('type' => 'serial', 'length' => '3','unsigned' => TRUE, 'not null' => TRUE),
      'cat_name' => array('type' => 'varchar', 'length' => '30', 'default' => NULL),     
      'active' => array('type' => 'char', 'length' => '1','default' => NULL),
    ),
    'primary key' => array('cat_id'),
  ); 
    
  return $schema;
} 
