<?php
//$Id: date_popup.install,v 1.5.6.6 2009/07/29 10:53:38 karens Exp $
/**
 * Implementation of hook_requirements().
 * Added to be sure the Date API version matches this code so invalid
 * functions are not called.
 */
function date_popup_requirements($phase) {
  $requirements = array();
  $t = get_t();
  switch ($phase) {
    case 'runtime':
      if (!module_exists('jquery_ui')) {
        $requirements['date_popup_jquery_ui'] = array(
          'title' => $t('Date Popup requirements'),
          'value' => $t('The Date Popup module needs code added by the <a href="http://drupal.org/project/jquery_ui">jQuery UI module.</a> This is not yet a requirement, but soon will be, so you are encouraged to install that module as soon as possible. In the meantime, a version of the needed code is included here.'),
          'severity' => REQUIREMENT_WARNING,
          );
      }
      break;
  }
  return $requirements;
}

/**
 * Implementation of hook_install().
 */
function date_popup_install() {
  if (module_exists('content')) {
    drupal_load('module', 'content');
    if (!db_table_exists(content_instance_tablename())) {
      return;
    }
    if (module_exists('date_repeat')) {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=1 WHERE widget_type='%s' OR widget_type='%s'", 'date_popup', 'date_popup_repeat');
    }
    else {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=1 WHERE widget_type='%s'", 'date_popup');
    }
    content_clear_type_cache(TRUE);
  }
}

/**
 * Implementation of hook_uninstall().
 */
function date_popup_uninstall() {
  if (module_exists('content')) {
    drupal_load('module', 'content');
    if (!db_table_exists(content_instance_tablename())) {
      return;
    }
    if (module_exists('date_repeat')) {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_type='%s' OR widget_type='%s'", 'date_popup', 'date_popup_repeat');
    }
    else {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_type='%s'", 'date_popup');
    }
    content_clear_type_cache(TRUE);
  }
}

/**
 * Implementation of hook_enable().
 */
function date_popup_enable() {
  if (module_exists('content')) {
    drupal_load('module', 'content');
    if (!db_table_exists(content_instance_tablename())) {
      return;
    }
    if (module_exists('date_repeat')) {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=1 WHERE widget_type='%s' OR widget_type='%s'", 'date_popup', 'date_popup_repeat');
    }
    else {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=1 WHERE widget_type='%s'", 'date_popup');
    }
    content_clear_type_cache(TRUE);
  }
}

/**
 * Implementation of hook_disable().
 */
function date_popup_disable() {
  if (module_exists('content')) {
    drupal_load('module', 'content');
    if (!db_table_exists(content_instance_tablename())) {
      return;
    }
    if (module_exists('date_repeat')) {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_type='%s' OR widget_type='%s'", 'date_popup', 'date_popup_repeat');
    }
    else {
      db_query("UPDATE {". content_instance_tablename() ."} SET widget_active=0 WHERE widget_type='%s'", 'date_popup');
    }
    content_clear_type_cache(TRUE);
  }
}