View source
<?php
function userprotect_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$query1 = db_query("CREATE TABLE {userprotect} (\n uid int(10) unsigned NOT NULL default '0',\n up_name int(1) unsigned NOT NULL default '0',\n up_mail int(1) unsigned NOT NULL default '0',\n up_pass int(1) unsigned NOT NULL default '0',\n up_status int(1) unsigned NOT NULL default '0',\n up_roles int(1) unsigned NOT NULL default '0',\n up_delete int(1) unsigned NOT NULL default '0',\n up_edit int(1) unsigned NOT NULL default '0',\n up_type char(20) NOT NULL default '',\n UNIQUE KEY uid_up_type (uid, up_type)\n ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
break;
case 'pgsql':
$query1 = db_query("CREATE TABLE {userprotect} (\n uid integer NOT NULL default '0',\n up_name smallint NOT NULL default '0',\n up_mail smallint NOT NULL default '0',\n up_pass smallint NOT NULL default '0',\n up_status smallint NOT NULL default '0',\n up_roles smallint NOT NULL default '0',\n up_delete smallint NOT NULL default '0',\n up_edit smallint NOT NULL default '0',\n up_type char(20) NOT NULL default '',\n UNIQUE (uid, up_type)\n );");
break;
}
if ($query1) {
$query2 = db_query("INSERT INTO {userprotect} VALUES (0, 0, 0, 0, 0, 0, 1, 1, 'user')");
$query3 = db_query("INSERT INTO {userprotect} VALUES (1, 0, 0, 0, 0, 0, 1, 1, 'user')");
$query4 = db_query("INSERT INTO {userprotect} VALUES (1, 1, 1, 1, 1, 1, 1, 1, 'admin')");
$query5 = db_result(db_query('SELECT perm FROM {permission} WHERE rid = 2'));
$query6 = db_query("UPDATE {permission} SET perm = '%s' WHERE rid = 2", $query5 . ', change own e-mail, change own password');
}
if ($query1 && $query2 && $query3 && $query4 && $query5 && $query6) {
drupal_set_message('The User Protect module was installed successfully.');
}
else {
drupal_set_message('There was an error installing the User Protect database tables.', 'error');
}
}
function userprotect_update_5000() {
$ret = array();
menu_rebuild();
$ret[] = array(
'success' => TRUE,
'query' => "Successfully rebuilt menus.",
);
return $ret;
}
function userprotect_uninstall() {
if (db_table_exists('userprotect')) {
$query1 = db_query('DROP TABLE {userprotect}');
}
variable_del('userprotect_protection_defaults');
variable_del('userprotect_autoprotect');
variable_del('userprotect_administrator_bypass_defaults');
variable_del('userprotect_role_protections');
if ($query1) {
drupal_set_message('The User Protect module was uninstalled successfully.');
}
else {
drupal_set_message('There was an error removing the User Protect database tables.', 'error');
}
}