<?php
// $Id: uc_deliverytimeslot.install,v 1.1 2009/09/17 18:54:36 mogtofu33 Exp $

/**
 * @file
 */

/**
 * Implementation of hook_schema().
 */

function uc_deliverytimeslot_schema() {
  $schema = array();
  $schema['uc_deliverytimeslot_default'] = array(
    'description' => t('Store default timeslot table.'),
    'fields' => array(
      'ddid' => array(
        'description' => t('Id of each day/timeslot relation.'),
        'type' => 'serial',
        'size' => 'medium',
        'not null' => TRUE,
      ),
      'day' => array(
        'description' => t('Day concerned (String relative to date("d") php function.'),
        'type' => 'varchar',
        'length' => '11',
        'not null' => TRUE,
      ),
      'sid' => array(
        'description' => t('Timeslot id.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_limit' => array(
        'description' => t('Maximum booking of this day/tymeslot.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('ddid'),
  );
  $schema['uc_deliverytimeslot_order'] = array(
    'description' => t('Store day/time of delivery to order.'),
    'fields' => array(
      'doid' => array(
        'description' => t('Id of order timeslot.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'size' => 'medium',
        'not null' => TRUE,
      ),
      'order_id' => array(
        'description' => t('Order id, same as uc_orders table.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'date' => array(
        'description' => t('Timestamp of the day concerned.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'sid' => array(
        'description' => t('Timeslot id.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'confirmed' => array(
        'description' => t('Status of delivery timeslot regards of order worflow.'),
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('doid'),
    'indexes' => array(
      'order_id' => array('order_id'),
    ),
  );
  $schema['uc_deliverytimeslot_special'] = array(
    'description' => t('Store special date timeslot table'),
    'fields' => array(
      'dsid' => array(
        'description' => t('Id of this special date.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'size' => 'medium',
        'not null' => TRUE,
      ),
      'date' => array(
        'description' => t('Timestamp of the day concerned.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'sid' => array(
        'description' => t('Timeslot id.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_limit' => array(
        'description' => t('Maximum booking of this day/tymeslot.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array('dsid'),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */

function uc_deliverytimeslot_install() {
  // Create tables.
  drupal_install_schema('uc_deliverytimeslot');
  drupal_set_message(t('Visit <a href="!url">delivery timeslot settings</a> to set-up your delivery.', array('!url' => url('admin/store/settings/deliverytimeslot'))));
}

/**
 * Implementation of hook_uninstall().
 */

function uc_deliverytimeslot_uninstall() {
  // Remove tables.
  drupal_uninstall_schema('uc_deliverytimeslot');
  // Remove variables
  variable_del('uc_deliverytimeslot_timeslot');
  variable_del('uc_deliverytimeslot_week_days');
  variable_del('uc_deliverytimeslot_display_days');
  variable_del('uc_deliverytimeslot_display_text');
  variable_del('uc_deliverytimeslot_display_mode');
  variable_del('uc_deliverytimeslot_quote');
}
