SELECT (@sort_order:=MAX(sort_order)+1) FROM admin_pages WHERE menu_key='tools';
INSERT INTO admin_pages (page_key, language_key, main_page, page_params, menu_key, display_on_menu, sort_order) VALUES ('PollManager', 'BOX_TOOLS_POLL_MANAGER', 'PM_FILENAME_POLL_MANAGER', '', 'tools', 'Y', @sort_order);

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE TABLE IF NOT EXISTS poll (
  p_id int(11) NOT NULL AUTO_INCREMENT,
  p_description varchar(64) NOT NULL,
  p_question varchar(64) NOT NULL,
  p_status tinyint(1) unsigned NOT NULL DEFAULT '0',
  p_type tinyint(1) unsigned NOT NULL DEFAULT '0',
  p_multivote ENUM('Y','N') NOT NULL DEFAULT 'N',
  p_prim ENUM('Y','N') NOT NULL DEFAULT 'N',
  p_show_cust ENUM('Y','N') NOT NULL DEFAULT 'N',
  PRIMARY KEY (p_id),
  KEY p_status (p_status),
  KEY p_show_cust (p_show_cust)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;


CREATE TABLE IF NOT EXISTS poll_options (
  o_id int(10) unsigned NOT NULL AUTO_INCREMENT,
  o_poll_id int(10) unsigned NOT NULL,
  o_option int(10) unsigned NOT NULL DEFAULT '1',
  o_text varchar(64) NOT NULL,
  o_inpf tinyint(3) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (o_id),
  KEY o_poll_id (o_poll_id)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;


CREATE TABLE IF NOT EXISTS poll_results (
  r_id int(11) NOT NULL AUTO_INCREMENT,
  r_ip varchar(15) NOT NULL,
  r_poll_id int(10) unsigned NOT NULL DEFAULT '0',
  r_option int(11) NOT NULL DEFAULT '0',
  r_option_text varchar(32) NOT NULL,
  r_timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (r_id),
  KEY r_poll_id (r_poll_id),
  KEY r_ip (r_ip)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;
