You are here

function captcha_install in CAPTCHA 5.3

Same name and namespace in other branches
  1. 8 captcha.install \captcha_install()
  2. 6.2 captcha.install \captcha_install()
  3. 6 captcha.install \captcha_install()
  4. 7 captcha.install \captcha_install()

Create tables on install

File

./captcha.install, line 11
Installation file for the core CAPTCHA module.

Code

function captcha_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {captcha_points} (\n        form_id varchar(128) NOT NULL,\n        module varchar(64) default NULL,\n        type varchar(64) default NULL,\n        PRIMARY KEY (form_id)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      $succes = TRUE;
      break;
    case 'pgsql':
      db_query("CREATE TABLE {captcha_points} (\n        form_id varchar(128) NOT NULL,\n        module varchar(64) default NULL,\n        type varchar(64) default NULL,\n        PRIMARY KEY (form_id)\n        );");
      $succes = TRUE;
      break;
    default:
      drupal_set_message(t('Unsupported database.'), 'error');
      $succes = FALSE;
  }
  if ($succes) {

    // insert some defaults
    $form_ids = array(
      'comment_form',
      'contact_mail_user',
      'contact_mail_page',
      'user_register',
      'user_pass',
      'user_login',
      'user_login_block',
    );
    foreach ($form_ids as $form_id) {
      db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
    }
    drupal_set_message(t('The installation of the captcha_points table and some default entries was successful.'), 'status');
    drupal_set_message(t('You can now <a href="!captcha_admin">configure the CAPTCHA module</a> for your site.', array(
      '!captcha_admin' => url('admin/user/captcha'),
    )), 'status');
  }
  else {
    drupal_set_message(t('The installation of the CAPTCHA module failed.'), 'error');
  }
}