View source
<?php
function webform_report_install() {
drupal_install_schema('webform_report');
}
function webform_report_schema() {
$schema['webform_report'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'wnid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'kcid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'description' => array(
'type' => 'text',
'not null' => TRUE,
),
'sort' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 4,
'size' => 'small',
),
'components' => array(
'type' => 'text',
'not null' => TRUE,
),
'filter_type' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'small',
),
'filter_value' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => '',
'length' => 128,
),
'results_per_page' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 20,
'size' => 'tiny',
),
),
'primary key' => array(
'nid',
),
);
return $schema;
}
function webform_report_uninstall() {
drupal_uninstall_schema('webform_report');
variable_del("webform_report");
$result = db_query("SELECT nid FROM {node} WHERE type = 'webform_report'");
while ($webform_report_node = db_fetch_object($result)) {
node_delete($webform_report_node->nid);
}
node_type_delete('webform_report');
}
function webform_report_update_3() {
$items = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$items[] = update_sql("ALTER TABLE {webform_report} CHANGE COLUMN kcid old_kcid int(10) unsigned NOT NULL default '0'");
break;
case 'pgsql':
$items[] = update_sql("ALTER TABLE {webform_report} RENAME kcid TO old_kcid");
break;
}
$items[] = update_sql("ALTER TABLE {webform_report} ADD kcid int NOT NULL default '0'");
$items[] = update_sql("UPDATE {webform_report} SET kcid = old_kcid");
$items[] = update_sql("ALTER TABLE {webform_report} DROP COLUMN old_kcid");
$items[] = update_sql("ALTER TABLE {webform_report} ADD components text NOT NULL");
$option_results = db_query("SELECT nid, options FROM {webform_report}");
$components = array();
while ($option_result = db_fetch_object($option_results)) {
$options = unserialize(stripslashes($option_result->options));
if (!empty($options->show_user)) {
$components[] = -1;
}
if (!empty($options->show_date)) {
$components[] = -2;
}
if (!empty($options->show_time)) {
$components[] = -3;
}
if (!empty($options->show_ip)) {
$components[] = -4;
}
if (!empty($options->show_edit)) {
$components[] = -5;
}
$component_results = db_query("SELECT cid FROM {webform_report_component} WHERE nid = '" . $option_result->nid . "'");
while ($component_result = db_fetch_object($component_results)) {
$components[] = $component_result->cid;
}
$items[] = update_sql("UPDATE {webform_report} SET components = '" . base64_encode(serialize($components)) . "' WHERE nid = '" . $option_result->nid . "'");
}
$items[] = update_sql("ALTER TABLE {webform_report} DROP COLUMN options");
$items[] = update_sql("DROP TABLE {webform_report_component}");
return $items;
}
function webform_report_update_2() {
$results = db_query("SELECT nid, options FROM {webform_report} ORDER BY nid");
while ($result = db_fetch_object($results)) {
$items[] = update_sql("UPDATE {webform_report} SET options = '" . addslashes(stripslashes($result->options)) . "' WHERE nid = '" . $result->nid . "'");
}
return $items;
}
function webform_report_update_1() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$items[] = update_sql("CREATE TABLE if not exists {webform_report_new} (\n nid int(10) unsigned NOT NULL default '0',\n wnid int(10) unsigned NOT NULL default '0',\n kcid int(10) unsigned NOT NULL default '0',\n description text NOT NULL,\n sort int(2) unsigned NOT NULL default '4',\n options text NOT NULL,\n filter_type int(2) unsigned NOT NULL default '0',\n filter_value varchar(128) NOT NULL default '',\n results_per_page int(1) unsigned NOT NULL default '20',\n PRIMARY KEY (nid)\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
$items[] = update_sql("CREATE TABLE if not exists {webform_report_component} (\n nid int(10) unsigned NOT NULL default '0',\n cid int(10) unsigned NOT NULL default '0',\n PRIMARY KEY (nid, cid)\n ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
$items[] = update_sql("CREATE TABLE {webform_report_new} (\n nid integer NOT NULL default '0',\n wnid integer NOT NULL default '0',\n kcid integer NOT NULL default '0',\n description text NOT NULL,\n sort smallint NOT NULL default '4',\n options text NOT NULL,\n filter_type smallint NOT NULL default '0',\n filter_value varchar(128) NOT NULL default '',\n results_per_page smallint NOT NULL default '20',\n PRIMARY KEY (nid)\n )");
$items[] = update_sql("CREATE TABLE {webform_report_component} (\n nid integer NOT NULL default '0',\n cid integer NOT NULL default '0',\n PRIMARY KEY (nid,cid)\n )");
break;
}
$items[] = update_sql("INSERT INTO {webform_report_new} (nid, wnid, kcid, description, sort) (SELECT DISTINCT nid, wnid, kcid, description, sort FROM {webform_report})");
$items[] = update_sql("INSERT INTO {webform_report_component} (nid, cid) (SELECT nid, cid FROM {webform_report})");
$items[] = update_sql("DROP TABLE {webform_report}");
$items[] = update_sql("ALTER TABLE {webform_report_new} RENAME TO webform_report");
return $items;
}