You are here

function userprotect_install in User protect 5

Same name and namespace in other branches
  1. 8 userprotect.install \userprotect_install()
  2. 6 userprotect.install \userprotect_install()
  3. 7 userprotect.install \userprotect_install()

Implementation of hook_install().

File

./userprotect.install, line 7

Code

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) {

    // Default settings
    $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');
  }
}