View source
<?php
function uc_order_install() {
$t = get_t();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {uc_orders} (\n order_id mediumint(9) NOT NULL,\n uid mediumint(9) NOT NULL,\n order_status varchar(32) NOT NULL,\n order_total decimal(10,2) NOT NULL,\n primary_email varchar(96) NOT NULL,\n delivery_first_name varchar(32) NOT NULL,\n delivery_last_name varchar(32) NOT NULL,\n delivery_phone varchar(32) NOT NULL,\n delivery_company varchar(64) NOT NULL,\n delivery_street1 varchar(64) NOT NULL,\n delivery_street2 varchar(64) NOT NULL,\n delivery_city varchar(32) NOT NULL,\n delivery_zone mediumint(9) NOT NULL,\n delivery_postal_code varchar(10) NOT NULL,\n delivery_country mediumint(9) NOT NULL,\n billing_first_name varchar(32) NOT NULL,\n billing_last_name varchar(32) NOT NULL,\n billing_phone varchar(32) NOT NULL,\n billing_company varchar(64) NOT NULL,\n billing_street1 varchar(64) NOT NULL,\n billing_street2 varchar(64) NOT NULL,\n billing_city varchar(32) NOT NULL,\n billing_zone mediumint(9) NOT NULL,\n billing_postal_code varchar(10) NOT NULL,\n billing_country mediumint(9) NOT NULL,\n payment_method varchar(32) NOT NULL,\n data text,\n host varchar(16) NOT NULL DEFAULT '',\n created int(11) NOT NULL,\n modified int(11) NOT NULL,\n PRIMARY KEY (order_id),\n KEY uid (uid),\n KEY order_status (order_status)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {uc_order_admin_comments} (\n comment_id mediumint(9) NOT NULL auto_increment,\n order_id mediumint(9) NOT NULL,\n uid mediumint(9) NOT NULL,\n message text NOT NULL,\n created int(11) NOT NULL,\n PRIMARY KEY (comment_id),\n KEY order_id (order_id)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {uc_order_comments} (\n comment_id mediumint(9) NOT NULL auto_increment,\n order_id mediumint(9) NOT NULL,\n uid mediumint(9) NOT NULL,\n order_status varchar(32) NOT NULL,\n notified tinyint(4) NOT NULL,\n message text NOT NULL,\n created int(11) NOT NULL,\n PRIMARY KEY (comment_id),\n KEY order_id (order_id)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {uc_order_line_items} (\n line_item_id mediumint(9) NOT NULL auto_increment,\n order_id mediumint(9) NOT NULL,\n type varchar(32) NOT NULL,\n title varchar(128) NOT NULL,\n amount decimal(10,2) NOT NULL,\n weight smallint(6) NOT NULL,\n data text,\n PRIMARY KEY (line_item_id),\n KEY order_id (order_id)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {uc_order_log} (\n order_log_id mediumint(9) NOT NULL auto_increment,\n order_id mediumint(9) NOT NULL,\n uid mediumint(9) NOT NULL,\n changes text NOT NULL,\n created int(11) NOT NULL,\n PRIMARY KEY (order_log_id),\n KEY order_id (order_id)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {uc_order_products} (\n order_product_id int(9) NOT NULL auto_increment,\n order_id mediumint(9) NOT NULL,\n nid mediumint(9) NOT NULL,\n title varchar(128) NOT NULL,\n manufacturer varchar(32) NOT NULL,\n model varchar(255) NOT NULL,\n qty smallint(6) NOT NULL,\n cost decimal(10,2) NOT NULL,\n price decimal(10,2) NOT NULL,\n weight float NOT NULL,\n data text NOT NULL,\n PRIMARY KEY (order_product_id),\n KEY order_id (order_id)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("CREATE TABLE {uc_order_statuses} (\n order_status_id varchar(32) NOT NULL,\n title varchar(48) NOT NULL,\n state varchar(32) NOT NULL,\n weight smallint(9) NOT NULL,\n locked tinyint(4) NOT NULL,\n PRIMARY KEY (order_status_id)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES " . "('canceled', '" . $t('Canceled') . "', 'canceled', -20, 1), " . "('in_checkout', '" . $t('In checkout') . "', 'in_checkout', -10, 1), " . "('pending', '" . $t('Pending') . "', 'post_checkout', 0, 1), " . "('processing', '" . $t('Processing') . "', 'post_checkout', 10, 1), " . "('completed', '" . $t('Completed') . "', 'completed', 20, 1);");
break;
case 'pgsql':
db_query("CREATE TABLE {uc_orders} (\n order_id serial NOT NULL,\n uid integer NOT NULL default 0,\n order_status varchar(32) NOT NULL default 0,\n order_total decimal(10,2) NOT NULL default 0.00,\n primary_email varchar(96) NOT NULL default '',\n delivery_first_name varchar(32) NOT NULL default '',\n delivery_last_name varchar(32) NOT NULL default '',\n delivery_phone varchar(32) NOT NULL default '',\n delivery_company varchar(64) NOT NULL default '',\n delivery_street1 varchar(64) NOT NULL default '',\n delivery_street2 varchar(64) NOT NULL default '',\n delivery_city varchar(32) NOT NULL default '',\n delivery_zone integer NOT NULL default 0,\n delivery_postal_code varchar(10) NOT NULL default '',\n delivery_country integer NOT NULL default 0,\n billing_first_name varchar(32) NOT NULL default '',\n billing_last_name varchar(32) NOT NULL default '',\n billing_phone varchar(32) NOT NULL default '',\n billing_company varchar(64) NOT NULL default '',\n billing_street1 varchar(64) NOT NULL default '',\n billing_street2 varchar(64) NOT NULL default '',\n billing_city varchar(32) NOT NULL default '',\n billing_zone integer NOT NULL default 0,\n billing_postal_code varchar(10) NOT NULL default '',\n billing_country integer NOT NULL default 0,\n payment_method varchar(32) NOT NULL default 0,\n data text NOT NULL default '',\n host varchar(16) NOT NULL default '',\n created integer NOT NULL default 0,\n modified integer NOT NULL default 0,\n PRIMARY KEY (order_id)\n );");
db_query("CREATE INDEX {uc_orders}_uid ON {uc_orders} (uid)");
db_query("CREATE INDEX {uc_orders}_order_status ON {uc_orders} (order_status)");
db_query("CREATE TABLE {uc_order_admin_comments} (\n comment_id serial NOT NULL,\n order_id integer NOT NULL default 0,\n uid integer NOT NULL default 0,\n message text NOT NULL default '',\n created integer NOT NULL default 0,\n PRIMARY KEY (comment_id)\n );");
db_query("CREATE INDEX {uc_order_admin_comments}_order_id ON {uc_order_admin_comments} (order_id)");
db_query("CREATE TABLE {uc_order_comments} (\n comment_id serial NOT NULL,\n order_id integer NOT NULL default 0,\n uid integer NOT NULL default 0,\n order_status varchar(32) NOT NULL default 0,\n notified smallint NOT NULL default 0,\n message text NOT NULL default '',\n created integer NOT NULL default 0,\n PRIMARY KEY (comment_id)\n );");
db_query("CREATE INDEX {uc_order_comments}_order_id ON {uc_order_comments} (order_id)");
db_query("CREATE TABLE {uc_order_line_items} (\n line_item_id serial NOT NULL,\n order_id integer NOT NULL default 0,\n type varchar(32) NOT NULL default '',\n title varchar(128) NOT NULL default '',\n amount decimal(10,2) NOT NULL default 0.00,\n weight smallint NOT NULL default 0,\n PRIMARY KEY (line_item_id)\n );");
db_query("CREATE INDEX {uc_order_line_items}_order_id ON {uc_order_line_items} (order_id)");
db_query("CREATE TABLE {uc_order_log} (\n order_log_id serial NOT NULL,\n order_id integer NOT NULL default 0,\n uid integer NOT NULL default 0,\n changes text NOT NULL default '',\n created integer NOT NULL default 0,\n PRIMARY KEY (order_log_id)\n );");
db_query("CREATE INDEX {uc_order_log}_order_id ON {uc_order_log} (order_id)");
db_query("CREATE TABLE {uc_order_products} (\n order_product_id serial NOT NULL,\n order_id integer NOT NULL default 0,\n nid integer NOT NULL default 0,\n title varchar(128) NOT NULL default '',\n manufacturer varchar(32) NOT NULL default '',\n model varchar(255) NOT NULL default '',\n qty smallint NOT NULL default 0,\n cost decimal(10,2) NOT NULL default 0.00,\n price decimal(10,2) NOT NULL default 0.00,\n weight float NOT NULL default 0.0,\n data text NOT NULL default '',\n PRIMARY KEY (order_product_id)\n );");
db_query("CREATE INDEX {uc_order_products}_order_id ON {uc_order_products} (order_id)");
db_query("CREATE TABLE {uc_order_statuses} (\n order_status_id varchar(32) NOT NULL,\n title varchar(48) NOT NULL,\n state varchar(32) NOT NULL,\n weight smallint NOT NULL,\n locked smallint NOT NULL,\n PRIMARY KEY (order_status_id)\n );");
db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES ('canceled', '" . $t('Canceled') . "', 'canceled', -20, 1);");
db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES ('in_checkout', '" . $t('In checkout') . "', 'in_checkout', -10, 1);");
db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES ('pending', '" . $t('Pending') . "', 'post_checkout', 0, 1);");
db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES ('processing', '" . $t('Processing') . "', 'post_checkout', 5, 1);");
db_query("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES ('completed', '" . $t('Completed') . "', 'completed', 20, 1);");
break;
}
}
function uc_order_uninstall() {
db_query("DROP TABLE {uc_orders}");
db_query("DROP TABLE {uc_order_admin_comments}");
db_query("DROP TABLE {uc_order_comments}");
db_query("DROP TABLE {uc_order_line_items}");
db_query("DROP TABLE {uc_order_log}");
db_query("DROP TABLE {uc_order_products}");
db_query("DROP TABLE {uc_order_statuses}");
db_query("DELETE FROM {variable} WHERE name LIKE 'uc_order_pane_%'");
db_query("DELETE FROM {variable} WHERE name LIKE 'uc_state_%'");
variable_del('uc_order_number_displayed');
variable_del('uc_order_logging');
variable_del('uc_order_capitalize_addresses');
variable_del('uc_ubrowser_product_select');
variable_del('uc_cust_view_order_invoices');
variable_del('uc_cust_order_invoice_template');
}
function uc_order_update_1() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_orders} CHANGE delivery_zip delivery_postal_code VARCHAR(10) CHARACTER SET utf8 NOT NULL");
$ret[] = update_sql("ALTER TABLE {uc_orders} CHANGE billing_zip billing_postal_code VARCHAR(10) CHARACTER SET utf8 NOT NULL");
break;
case 'pgsql':
db_change_column($ret, 'uc_orders', 'delivery_zip', 'delivery_postal_code', 'varchar(10) CHARACTER SET utf8', array(
'not null' => true,
'default' => "''",
));
db_change_column($ret, 'uc_orders', 'billing_zip', 'billing_postal_code', 'varchar(10) CHARACTER SET utf8', array(
'not null' => true,
'default' => "''",
));
break;
}
$result = db_query("SELECT order_id FROM {uc_orders} ORDER BY order_id DESC LIMIT 1");
if ($data = db_fetch_object($result)) {
$result = db_query("INSERT INTO {sequences} (name, id) VALUES ('{uc_orders}_order_id', %d)", $data->order_id);
$ret[] = array(
'success' => $result !== false,
'query' => "INSERT INTO {sequences} (name, id) VALUES ('{uc_orders}_order_id'. " . $data->order_id . ")",
);
}
return $ret;
}
function uc_order_update_2() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_order_products} CHANGE weight weight FLOAT NOT NULL DEFAULT 0.0");
break;
case 'pgsql':
db_change_column($ret, 'uc_order_products', 'weight', 'weight', 'float', array(
'not null' => true,
'default' => 0.0,
));
break;
}
return $ret;
}
function uc_order_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_orders} CHANGE order_status order_status VARCHAR(32) NOT NULL");
$ret[] = update_sql("ALTER TABLE {uc_order_comments} CHANGE order_status order_status VARCHAR(32) NOT NULL");
break;
case 'pgsql':
db_change_column($ret, 'uc_orders', 'order_status', 'order_status', 'varchar(32)', array(
'not null' => true,
'default' => "''",
));
db_change_column($ret, 'uc_order_comments', 'order_status', 'order_status', 'varchar(32)', array(
'not null' => true,
'default' => "''",
));
break;
}
$ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'in_checkout' WHERE order_status = '0'");
$ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'pending' WHERE order_status = '1'");
$ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'processing' WHERE order_status = '2' OR order_status = '3'");
$ret[] = update_sql("UPDATE {uc_orders} SET order_status = 'completed' WHERE order_status = '4'");
$ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'in_checkout' WHERE order_status = '0'");
$ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'pending' WHERE order_status = '1'");
$ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'processing' WHERE order_status = '2' OR order_status = '3'");
$ret[] = update_sql("UPDATE {uc_order_comments} SET order_status = 'completed' WHERE order_status = '4'");
if ($_SESSION['statuses'] !== TRUE) {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE order_status_id order_status_id VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
$ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE title title VARCHAR(48) CHARACTER SET utf8 NOT NULL default ''");
$ret[] = update_sql("ALTER TABLE {uc_order_statuses} CHANGE notify state VARCHAR(32) CHARACTER SET utf8 NOT NULL default ''");
$ret[] = update_sql("ALTER TABLE {uc_order_statuses} ADD weight MEDIUMINT(9) NOT NULL");
$ret[] = update_sql("ALTER TABLE {uc_order_statuses} ADD locked TINYINT NOT NULL DEFAULT '0'");
break;
case 'pgsql':
db_change_column($ret, 'uc_order_statuses', 'order_status_id', 'order_status_id', 'varchar(32) CHARACTER SET utf8', array(
'not null' => true,
'default' => "''",
));
db_change_column($ret, 'uc_order_statuses', 'title', 'title', 'varchar(48) CHARACTER SET utf8', array(
'not null' => true,
'default' => "''",
));
db_change_column($ret, 'uc_order_statuses', 'notify', 'state', 'varchar(32) CHARACTER SET utf8', array(
'not null' => true,
'default' => "''",
));
db_add_column($ret, 'uc_order_statuses', 'weight', 'integer', array(
'not null' => true,
'default' => 0,
));
db_add_column($ret, 'uc_order_statuses', 'locked', 'smallint', array(
'not null' => true,
'default' => 0,
));
break;
}
$ret[] = update_sql("DELETE FROM {uc_order_statuses} WHERE order_status_id LIKE '_'");
$_SESSION['statuses'] = TRUE;
}
$t = get_t();
$ret[] = update_sql("INSERT INTO {uc_order_statuses} (order_status_id, title, state, weight, locked) VALUES " . "('canceled', '" . $t('Canceled') . "', 'canceled', -20, 1), " . "('in_checkout', '" . $t('In checkout') . "', 'in_checkout', -10, 1), " . "('pending', '" . $t('Pending') . "', 'post_checkout', 0, 1), " . "('processing', '" . $t('Processing') . "', 'post_checkout', 5, 1), " . "('completed', '" . $t('Completed') . "', 'completed', 20, 1);");
return $ret;
}
function uc_order_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_order_comments} CHANGE order_status order_status VARCHAR(32) NOT NULL");
break;
case 'pgsql':
db_change_column($ret, 'uc_order_comments', 'order_status', 'order_status', 'varchar(32)', array(
'not null' => true,
'default' => "''",
));
break;
}
return $ret;
}
function uc_order_update_5() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_orders} ADD data text");
break;
case 'pgsql':
db_add_column($ret, 'uc_orders', 'data', 'text', array());
break;
}
return $ret;
}
function uc_order_update_6() {
$ret = array();
$max_opid = db_result(db_query("SELECT MAX(order_product_id) AS max_opid FROM {uc_order_products}"));
if ($max_opid) {
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{uc_order_products}_order_product_id', {$max_opid})");
}
return $ret;
}
function uc_order_update_7() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_order_products} CHANGE model model VARCHAR(255) CHARACTER SET utf8 NOT NULL");
break;
case 'pgsql':
db_change_column($ret, 'uc_order_products', 'model', 'model', 'varchar(255)', array(
'not null' => TRUE,
'default' => "''",
));
break;
}
return $ret;
}
function uc_order_update_8() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_orders} ADD host VARCHAR(16) NOT NULL DEFAULT ''");
break;
case 'pgsql':
db_add_column($ret, 'uc_orders', 'host', 'VARCHAR(16)', array(
'not null' => TRUE,
'default' => "''",
));
break;
}
return $ret;
}
function uc_order_update_9() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {uc_order_line_items} ADD data text");
break;
case 'pgsql':
db_add_column($ret, 'uc_order_line_items', 'data', 'text');
break;
}
return $ret;
}