<?php /* -*- php -*- */

function fulcrm_campaign_schema() {
  $schema[ 'fulcrm_campaign' ] = array( 'description' => 'The campaign itself, and a reference to fulcrm.',
                                        'fields' => array( 'fcid' => array( 'type' => 'serial',
                                                                            'not null' => TRUE,
                                                                            'default' => 0,
                                                                            'description' => 'Unique ID' ),
                                                           'name' => array( 'type' => 'text',
                                                                            'description' => 'Campaign name.' ),
                                                           'subject' => array( 'type' => 'text',
                                                                               'description' => 'Campaign subject.' ),
                                                           ),
                                        'primary key' => array( 'fcid' ),
                                        );

  $schema[ 'fulcrm_campaign_node' ] = array( 'description' => 'Which nodes are to be build into a mailshot, and the order.',
                                             'fields' => array( 'fcid' => array( 'type' => 'int',
                                                                                 'not null' => TRUE,
                                                                                 'default' => 0,
                                                                                 'description' => 'fulcrm_campaign.fcid' ),
                                                                'nid' => array( 'type' => 'int',
                                                                                'not null' => TRUE,
                                                                                'default' => 0,
                                                                                'description' => 'node.nid' ),
                                                                'weight' => array( 'type' => 'int',
                                                                                   'default' => 0,
                                                                                   'description' => 'sort order for content' ),
                                                                ),
                                             'primary key' => array( 'nid', 'fcid' ),
                                             );
  $schema[ 'fulcrm_campaign_variable_template' ] = array( 'description' => 'FMS variable templates, to be used as presets.',
                                                          'fields' => array( 'tid' => array( 'type' => 'serial',
                                                                                             'not null' => TRUE,
                                                                                             'default' => 0,
                                                                                             'description' => 'Unique ID' ),
                                                                             'name' => array( 'type' => 'text',
                                                                                              'not null' => TRUE,
                                                                                              'description' => 'Name of the template.' ),
                                                                             ),
                                                          'primary key' => array( 'tid' ),
                                                          );
  $schema[ 'fulcrm_campaign_template_value' ] = array( 'description' => 'Names and values of variables for each template.',
                                                       'fields' => array( 'tid' => array( 'type' => 'int',
                                                                                          'not null' => TRUE,
                                                                                          'default' => 0,
                                                                                          'description' => 'fulcrm_campaign_variable_template.tid' ),
                                                                          'name' => array( 'type' => 'varchar',
                                                                                           'length' => 64,
                                                                                           'not null' => TRUE,
                                                                                           'description' => 'Variable name.' ),
                                                                          'value' => array( 'type' => 'text',
                                                                                            'description' => 'Variable value.' ),
                                                                          ),
                                                       'primary key' => array( 'tid', 'name' ),
                                                       );
  $schema[ 'fulcrm_campaign_variable_value' ] = array( 'description' => 'Names and values of variables for each campaign.',
                                                       'fields' => array( 'fcid' => array( 'type' => 'int',
                                                                                           'not null' => TRUE,
                                                                                           'default' => 0,
                                                                                           'description' => 'fulcrm_campaign.fcid' ),
                                                                          'name' => array( 'type' => 'varchar',
                                                                                           'length' => 64,
                                                                                           'not null' => TRUE,
                                                                                           'description' => 'Variable name.' ),
                                                                          'value' => array( 'type' => 'text',
                                                                                            'description' => 'Variable value.' ),
                                                                          ),
                                                       'primary key' => array( 'fcid', 'name' ),
                                                       );
  
  return $schema;
}