CREATE TABLE IF NOT EXISTS `#__sql2excel_sections` (
  `id` int(11) NOT NULL auto_increment,
  `title` VARCHAR(255) NOT NULL,
  `alias` VARCHAR(255) NOT NULL, 
  `description` TEXT, 
  `published` TINYINT(1) unsigned NOT NULL DEFAULT 0,
  `checked_out` int(11) unsigned NOT NULL default '0',
  `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
  `ordering` INT(11) NOT NULL DEFAULT 0,
  `access` tinyint(3) unsigned NOT NULL default 0,
  `count` int(11) NOT NULL default '0',  
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `#__sql2excel_categories` (
  `id` int(11) NOT NULL auto_increment,
  `parent_id` int(11) NOT NULL default 0,
  `section` int(11) NOT NULL default 0,
  `title` varchar(255) NOT NULL default '',
  `alias` varchar(255) NOT NULL default '',
  `description` text NOT NULL,
  `published` tinyint(1) unsigned NOT NULL default 0,
  `checked_out` int(11) unsigned NOT NULL default '0',
  `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00', 
  `ordering` int(11) NOT NULL default '0',
  `access` tinyint(3) unsigned NOT NULL default 0,
  `count` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `category_idx` (`section`,`published`,`access`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `#__sql2excel_worksheets` (
  `id` int(11) NOT NULL auto_increment,
  `title` VARCHAR(255) NOT NULL,
  `sheetname` VARCHAR(30) NOT NULL default '',
  `published` tinyint(1) unsigned NOT NULL default 0,
  `checked_out` int(11) unsigned NOT NULL default '0',
  `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00', 
  `created` datetime NOT NULL default '0000-00-00 00:00:00',
  `access` tinyint(3) unsigned NOT NULL default 0,  
  `header` TEXT,
  `header_parms` VARCHAR(255) NOT NULL default 'Arial,10,normal,black,none',
  `heading_bg_col` VARCHAR(20) NOT NULL default 'grey',
  `heading_text_col` VARCHAR(20) NOT NULL default 'black',
  `heading_text_size` tinyint(3)  NOT NULL default 10, 
  `data_parms` VARCHAR(255) NOT NULL default 'Arial,10,normal,black,None,silver,1,27,1',
  `show_colheader` tinyint(1) unsigned NOT NULL default 1,  
  `colwidths` TEXT,
  `footer` TEXT,
  `footer_parms` VARCHAR(255) NOT NULL default 'Arial,10,normal,black,none',
  `count` int(11) NOT NULL default '0',
  `include_no_records` tinyint(1) unsigned NOT NULL default 1, 
  `error_norecords` varchar(255),
  `query` TEXT NOT NULL,
  `ordering` int(11) NOT NULL default '0',
  `formulas` VARCHAR(255) NOT NULL default '',
  `nr_parms` int(11) unsigned NOT NULL default '0',
  `parms` TEXT NOT NULL default '',
  `database` int(11) NOT NULL default '1',
  `ws_password` VARCHAR(40) NOT NULL default '',
  `pane_horiz` int(11) NOT NULL default '-1',
  `pane_vert` int(11) NOT NULL default '-1',
  `extracells` TEXT NOT NULL default '',
  `preview_rows` int(11) unsigned default NULL,
  `preview_extracells` ENUM('Global','Show','Hide') NOT NULL default 'Global',  
  `preview_formulas` ENUM('Global','Show','Label','Hide') NOT NULL default 'Global', 
  `preview_hidecols` VARCHAR(255) NOT NULL default '',  
  `print_parms` VARCHAR(255) NOT NULL default '0.75,0.75,1.0,1.0,0,0,0,0,0',
  `hide_grid` tinyint(1) unsigned NOT NULL default 0,
  `cellformat` TEXT NOT NULL default '',
  `zoom` int(11) unsigned NOT NULL default 100,
  `preview_dl_btn` ENUM('Global','Show','Hide') NOT NULL default 'Global',
  `escape_chars_html` tinyint(1) unsigned NOT NULL default 1,    
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `#__sql2excel_workbooks` (
  `id` int(11) NOT NULL auto_increment,
  `title` VARCHAR(100) NOT NULL, 
  `link_title` VARCHAR(255) NOT NULL, 
  `filename` VARCHAR(255) NOT NULL, 
  `section` int(11) NOT NULL default 0,
  `category` int(11) NOT NULL default 0,    
  `published` TINYINT NOT NULL DEFAULT 0,
  `checked_out` int(11) unsigned NOT NULL default '0',
  `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',  
  `created` datetime NOT NULL default '0000-00-00 00:00:00',  
  `access` tinyint(3) unsigned NOT NULL default 0,  
  `ordering` int(11) NOT NULL default '0',
  `count` int(11) NOT NULL default '0',
  `parms` TEXT NOT NULL default '',
  `parms_prompt` int(11) NOT NULL default 1, 
  `parms_length` int(11) NOT NULL default 5,
  `description` text NOT NULL default '',
  `keywords` VARCHAR(255) NOT NULL default '',
  `preview_dl_btn` ENUM('Global','Show','Hide') NOT NULL default 'Global',   
  `cache` ENUM('Global','Yes','No') NOT NULL default 'Global',
  `compress_wb` ENUM('Global','Yes','No') NOT NULL default 'Global',
  `dlformat` tinyint(1) unsigned NOT NULL default 0,  
  `lightbox_x` int(11) default NULL,
  `lightbox_y` int(11) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `#__sql2excel_worksheet2book` (
  `id` int(11) NOT NULL auto_increment,
  `wb_id` int(11) NOT NULL,
  `ws_id` int(11) NOT NULL,
  `ordering` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `wb_id` (`wb_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;  



CREATE TABLE IF NOT EXISTS `#__sql2excel_databases` (
  `id` int(11) NOT NULL auto_increment,
  `db_name` varchar(255) NOT NULL,
  `db_type` int(11) unsigned NOT NULL default '0',
  `db_host` varchar(255) NOT NULL default '',
  `db_username` varchar(255) NOT NULL default '',
  `db_password` varchar(255) NOT NULL default '',
  `db_database` varchar(255) NOT NULL default '',
  `db_prefix` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT IGNORE INTO `#__sql2excel_databases` (`id`, `db_name`, `db_type`) VALUES (1,'Joomla!',1);

  
CREATE TABLE IF NOT EXISTS `#__sql2excel_schedules` (
  `id` int(11) NOT NULL auto_increment,
  `frequency` int(11) NOT NULL default 1,
  `title` varchar(255) NOT NULL default '',
  `next_date` datetime NOT NULL default '0000-00-00 00:00:00', 
  `end_date` datetime NOT NULL default '2100-12-31 00:00:00', 
  `last_date` datetime, 
  `count` int(11) NOT NULL default '0',
  `max_count` int(11), 
  `action` int(11) NOT NULL default 0,
  `email_to` TEXT NOT NULL default '',
  `email_cc` TEXT NOT NULL default '',
  `email_bcc` TEXT NOT NULL default '',
  `email_title` varchar(255) NOT NULL default '',
  `email_body` TEXT NOT NULL default '',
  `email_attach` tinyint(1) unsigned NOT NULL default 1,
  `html` tinyint(1) unsigned NOT NULL default 0,
  `sdata` TEXT NOT NULL default '', 
  `sql_db` tinyint(1) unsigned NOT NULL default 1,
  `published` tinyint(1) unsigned NOT NULL default 0,
  `ordering` int(11) NOT NULL default '0',
  `failures` int(11) NOT NULL default '0', 
  `last_status` tinyint(1) unsigned NOT NULL default 0,
  `created` datetime NOT NULL default '0000-00-00 00:00:00',
  `compress_attachments` tinyint(1) unsigned NOT NULL default 0,
  `run_if_type` tinyint(1) unsigned NOT NULL default 0,   
  `run_if_sql` TEXT NOT NULL default '',
  `run_if_db` tinyint(1) unsigned NOT NULL default 1,
  `run_if_op` varchar(3) NOT NULL default '',
  `run_if_val_1` varchar(80) NOT NULL default '',
  `run_if_val_2` varchar(80) NOT NULL default '',
  `on_success_sql` TEXT NOT NULL default '',
  `on_success_db` tinyint(1) unsigned NOT NULL default 1,
  `on_success_email` varchar(255) NOT NULL default '',
  `on_failure_sql` TEXT NOT NULL default '',
  `on_failure_db` tinyint(1) unsigned NOT NULL default 1,
  `on_failure_email` varchar(255) NOT NULL default '',  
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


CREATE TABLE IF NOT EXISTS `#__sql2excel_schedule2book` (
  `id` int(11) NOT NULL auto_increment,
  `sched_id` int(11) NOT NULL,  
  `wb_id` int(11) NOT NULL,
  `ordering` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `sched_id` (`sched_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 


CREATE TABLE IF NOT EXISTS `#__sql2excel_settings` (
  `param` varchar(40) NOT NULL,
  `value` TEXT NOT NULL default '',
  PRIMARY KEY  (`param`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

