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 status int(2) NOT NULL default '1',\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 status integer NOT NULL default '1',\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, status) VALUES (0, '',\n 1, 'Enter your default confirmation email message here',\n 1, 1, 'Enter your default reminder email message here',\n 0, 0, 1)");
}
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;
}
function signup_update_5200() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {signup} ADD status int NOT NULL default '1'");
break;
case 'pgsql':
db_add_column($ret, 'signup', 'status', 'integer', array(
'not null' => TRUE,
'default' => "'1'",
));
break;
}
$ret[] = update_sql("UPDATE {signup} SET status = (1 - completed)");
$ret[] = update_sql("ALTER TABLE {signup} DROP completed");
return $ret;
}
function signup_update_5201() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
if (!_signup_db_column_exists('signup', 'close_signup_limit')) {
$ret[] = update_sql("ALTER TABLE {signup} ADD close_signup_limit int(10) unsigned NOT NULL default '0'");
}
break;
case 'pgsql':
if (!_signup_db_column_exists('signup', 'close_signup_limit')) {
db_add_column($ret, 'signup', 'close_signup_limit', 'integer', array(
'not null' => TRUE,
'default' => "'0'",
));
}
break;
}
return $ret;
}
function signup_update_5202() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("UPDATE {permission} SET perm = CONCAT(perm, ', cancel own signups') WHERE CONCAT(perm, ', ') LIKE '%%sign up for content, %%'");
break;
case 'pgsql':
$ret[] = update_sql("UPDATE {permission} SET perm = perm || ', cancel own signups' WHERE perm || ', ' LIKE '%%sign up for content, %%'");
break;
}
drupal_set_message(t("Added the 'cancel own signups' permission to all roles that have the 'sign up for content' permission.") . '<br />' . t('If you do not want your users to cancel their own signups, go to the <a href="@access_url">Access control</a> page and unset this permission.', array(
'@access_url' => url('/admin/user/access'),
)));
return $ret;
}
function signup_update_5203() {
$old_prefix = 'signup_form_';
$result = db_query("SELECT name FROM {variable} WHERE name LIKE '{$old_prefix}%%'");
while ($row = db_fetch_object($result)) {
$old_name = $row->name;
$new_name = 'signup_node_default_state_' . substr($old_name, strlen($old_prefix));
$new_value = variable_get($old_name, 0) == 1 ? 'enabled_on' : 'disabled';
variable_del($old_name);
variable_set($new_name, $new_value);
}
drupal_set_message(t('Migrated signup settings per content type.'));
return array();
}
function signup_update_5204() {
$ret = array();
if (!isset($_SESSION['signup_update_5204'])) {
$_SESSION['signup_update_5204'] = -1;
$_SESSION['signup_update_5204_max'] = db_result(db_query("SELECT MAX(nid) FROM {signup}"));
}
$replacements = array(
'%%eventurl' => '%%node_url',
'%%event' => '%%node_title',
'%%time' => '%%node_start_time',
'%%username' => '%%user_name',
'%%useremail' => '%%user_mail',
'%%info' => '%%user_signup_info',
);
$reminder_replace = 'reminder_email';
$confirmation_replace = 'confirmation_email';
foreach ($replacements as $from => $to) {
$reminder_replace = "REPLACE({$reminder_replace}, '{$from}', '{$to}')";
$confirmation_replace = "REPLACE({$confirmation_replace}, '{$from}', '{$to}')";
}
$next = min($_SESSION['signup_update_5204'] + 2000, $_SESSION['signup_update_5204_max']);
db_query("UPDATE {signup} SET reminder_email = {$reminder_replace}, confirmation_email = {$confirmation_replace} WHERE nid > %d AND nid <= %d", $_SESSION['signup_update_5204'], $next);
$_SESSION['signup_update_5204'] = $next;
if ($_SESSION['signup_update_5204'] == $_SESSION['signup_update_5204_max']) {
unset($_SESSION['signup_update_5204']);
unset($_SESSION['signup_update_5204_max']);
$tokens = array(
'%event' => '%event',
'%eventurl' => '%eventurl',
'%time' => '%time',
'%username' => '%username',
'%useremail' => '%useremail',
'%info' => '%info',
'%node_title' => '%node_title',
'%node_url' => '%node_url',
'%node_start_time' => '%node_start_time',
'%user_name' => '%user_name',
'%user_mail' => '%user_mail',
'%user_signup_info' => '%user_signup_info',
);
$ret[] = array(
'success' => TRUE,
'query' => t('Replaced %event, %eventurl, %time, %username, %useremail, and %info tokens with %node_title, %node_url, %node_start_time, %user_name, %user_mail, and %user_signup_info in the reminder and confirmation email templates.', $tokens),
);
}
else {
$ret['#finished'] = $_SESSION['signup_update_5204'] / $_SESSION['signup_update_5204_max'];
}
return $ret;
}
function _signup_db_column_exists($table, $column) {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
return db_num_rows(db_query("SHOW COLUMNS FROM {%s} LIKE '%s'", $table, $column));
case 'pgsql':
return db_result(db_query("SELECT COUNT(pg_attribute.attname) FROM pg_class, pg_attribute WHERE pg_attribute.attrelid = pg_class.oid AND pg_class.relname = '{%s}' AND attname='%s'", $table, $column));
}
}