View source
<?php
function signup_install() {
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$q1 = db_query("CREATE TABLE IF NOT EXISTS {signup} (\n nid int(10) unsigned NOT NULL default '0',\n forwarding_email varchar(64) NOT NULL default '',\n send_confirmation int(2) NOT NULL default '0',\n confirmation_email longtext NOT NULL,\n send_reminder int(2) NOT NULL default '0',\n reminder_days_before int(4) unsigned NOT NULL default '0',\n reminder_email longtext NOT NULL,\n close_in_advance_time int(10) unsigned NOT NULL default '0',\n close_signup_limit int(10) unsigned NOT NULL default '0',\n completed int(2) NOT NULL default '0',\n PRIMARY KEY (nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$q2 = db_query("CREATE TABLE IF NOT EXISTS {signup_log} (\n uid int(10) unsigned NOT NULL default '0',\n nid int(10) unsigned NOT NULL default '0',\n anon_mail varchar(255) NOT NULL default '',\n signup_time int(10) unsigned NOT NULL default '0',\n form_data longtext NOT NULL,\n KEY uid (uid),\n KEY nid (nid)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$q3 = signup_insert_default_signup_info();
if ($q1 && $q2 && $q3) {
$created = TRUE;
}
break;
case 'pgsql':
$q1 = db_query("CREATE TABLE {signup} (\n nid SERIAL,\n forwarding_email text NOT NULL default '',\n send_confirmation integer NOT NULL default '0',\n confirmation_email text NOT NULL default '',\n send_reminder integer NOT NULL default '0',\n reminder_days_before integer NOT NULL default '0',\n reminder_email text NOT NULL default '',\n close_in_advance_time integer NOT NULL default '0',\n close_signup_limit integer NOT NULL default '0',\n completed integer NOT NULL default '0',\n PRIMARY KEY (nid)\n );");
$q2 = db_query("CREATE TABLE {signup_log} (\n uid integer NOT NULL default '0',\n nid integer NOT NULL default '0',\n anon_mail text NOT NULL default '',\n signup_time integer NOT NULL default '0',\n form_data text NOT NULL default ''\n );");
$q3 = db_query("CREATE INDEX {signup_log}_uid_idx ON {signup_log}(uid);");
$q4 = db_query("CREATE INDEX {signup_log}_nid_idx ON {signup_log}(nid);");
$q5 = signup_insert_default_signup_info();
if ($q1 && $q2 && $q3 && $q4 && $q5) {
$created = TRUE;
}
break;
}
if ($created) {
drupal_set_message(t('Signup module installed successfully.'));
}
else {
drupal_set_message(t('Table installation for the Signup module was unsuccessful. The tables may need to be installed by hand. See the signup.install file for a list of the installation queries.'), 'error');
}
}
function signup_uninstall() {
if (db_table_exists('signup')) {
db_query("DROP TABLE {signup}");
}
if (db_table_exists('signup_log')) {
db_query("DROP TABLE {signup_log}");
}
$variables = db_query("SELECT name FROM {variable} WHERE name LIKE 'signup%%'");
while ($variable = db_fetch_object($variables)) {
variable_del($variable->name);
}
}
function signup_insert_default_signup_info() {
return db_query("INSERT INTO {signup} (nid, forwarding_email,\n send_confirmation, confirmation_email,\n send_reminder, reminder_days_before, reminder_email,\n close_in_advance_time, close_signup_limit, completed) VALUES (0, '',\n 1, 'Enter your default confirmation email message here',\n 1, 1, 'Enter your default reminder email message here',\n 0, 0, 0)");
}
function signup_update_1() {
return _system_update_utf8(array(
'signup',
'signup_log',
));
}
function signup_update_2() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {signup} DROP permissions");
return $ret;
}
function signup_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {signup_log} ADD anon_mail VARCHAR( 255 ) NOT NULL default '' AFTER nid;");
$ret[] = update_sql("ALTER TABLE {signup_log} DROP INDEX uid_nid;");
$ret[] = update_sql("ALTER TABLE {signup_log} ADD INDEX (uid);");
$ret[] = update_sql("ALTER TABLE {signup_log} ADD INDEX (nid);");
break;
case 'pgsql':
db_add_column($ret, 'signup_log', 'anon_mail', 'text', array(
'not null' => TRUE,
'default' => "''",
));
$ret[] = update_sql("DROP INDEX {signup_log}_uid_nid_idx;");
$ret[] = update_sql("CREATE INDEX {signup_log}_uid_idx ON {signup_log}(uid);");
$ret[] = update_sql("CREATE INDEX {signup_log}_nid_idx ON {signup_log}(nid);");
break;
}
return $ret;
}
function signup_update_4() {
$ret = array();
$old_perms = array(
'/allow signups/',
'/admin signups/',
'/admin own signups/',
);
$new_perms = array(
'sign up for content',
'administer all signups',
'administer signups for own content',
);
$query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
while ($role = db_fetch_object($query)) {
$fixed_perm = preg_replace($old_perms, $new_perms, $role->perm);
if ($role->rid == 2 && variable_get('signup_user_view', 0)) {
if (!strpos($fixed_perm, 'view all signups')) {
$fixed_perm .= ', view all signups';
drupal_set_message(t('The old %signup_user_view setting was enabled on your site, so the %view_all_signups permission has been added to the %authenticated_user role. Please consider customizing what roles have this permission on the !access_control page.', array(
'%signup_user_view' => t('Users can view signups'),
'%view_all_signups' => 'view all signups',
'%authenticated_user' => 'Authenticated user',
'!access_control' => l(t('Access control'), '/admin/user/access'),
)));
}
}
$ret[] = update_sql("UPDATE {permission} SET perm = '{$fixed_perm}' WHERE rid = {$role->rid}");
}
variable_del('signup_user_view');
drupal_set_message(t('The %signup_user_view setting has been removed.', array(
'%signup_user_view' => t('Users can view signups'),
)));
return $ret;
}