You are here

function imagepicker_install in Image Picker 5

Same name and namespace in other branches
  1. 5.2 imagepicker.install \imagepicker_install()
  2. 6.2 imagepicker.install \imagepicker_install()
  3. 7 imagepicker.install \imagepicker_install()

File

./imagepicker.install, line 4

Code

function imagepicker_install() {

  // Create a directory structure so that usernames would be divided by letters.
  $drupaldir = str_replace('/', DIRECTORY_SEPARATOR, getcwd()) . DIRECTORY_SEPARATOR;
  $dir = $drupaldir . file_directory_path() . DIRECTORY_SEPARATOR . 'imagepicker';
  if (file_check_directory($dir, TRUE)) {
    $dirlist = range('a', 'z');
    array_push($dirlist, 'others');
    foreach ($dirlist as $v) {
      $newdir = $dir . DIRECTORY_SEPARATOR . $v;
      if (!file_check_directory($newdir, TRUE)) {
        drupal_set_message(t('Directory creation for the Imagepicker module was unsuccessful.'), 'error');
      }
    }
    $errors = drupal_get_messages('error');
    if (!count($errors)) {

      // clear
      drupal_get_messages();
      drupal_set_message(t('Directory creation for the Imagepicker module was successful.'), '');
    }
    else {
      foreach ($errors['error'] as $error) {
        drupal_set_message($error, 'error');
      }
    }
    $created1 = db_query("INSERT INTO {sequences} (name, id) VALUES ('imagepicker_img_id', 0);");
    switch ($GLOBALS['db_type']) {
      case 'mysql':
      case 'mysqli':
        $created2 = db_query("\n          CREATE TABLE IF NOT EXISTS {imagepicker} (\n          `img_id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n          `uid` int(10) unsigned NOT NULL default '0',\n          `img_name` varchar(255) NOT NULL default '',\n          `img_title` varchar(255) NOT NULL default '',\n          `img_description` varchar(255) NOT NULL default '',\n          `img_date` timestamp NOT NULL,\n          PRIMARY KEY (`img_id`),\n          KEY `uid` (`uid`)\n          )\n        ");
        $created3 = db_query("\n          CREATE TABLE IF NOT EXISTS {imagepicker_user_groups} (\n            `gid` int(10) unsigned NOT NULL AUTO_INCREMENT,\n            `uid` int(10) unsigned  NOT NULL default '0',\n            `group_name` varchar(255) NOT NULL default '',\n            `group_description` varchar(255) default NULL,\n            `state` tinyint(4) unsigned NOT NULL default '0',\n            PRIMARY KEY  (`gid`),\n            KEY `uid` (`uid`)\n            )\n        ");
        $created4 = db_query("\n          CREATE TABLE IF NOT EXISTS {imagepicker_group_images} (\n          `gid` int(10) unsigned NOT NULL default '0',\n          `img_id` int(10) unsigned NOT NULL default '0')\n        ");
        break;
    }
    if (!$created1 || !$created2 || !$created3 || !$created4) {
      drupal_set_message(t('Table installation for the Imagepicker module was unsuccessful.'), 'error');
    }
    else {
      drupal_set_message(t('Table installation for the Imagepicker module was successful. Go to Site Configuration to set preferences.'), '');
    }
  }
  else {
    drupal_set_message(t('Directory creation for the Imagepicker module was unsuccessful.'), 'error');
  }
}