<?php
/**
 * @file
 * Install, update and uninstall functions for the date_multiselect module.
 */

define('MULTIDATESPICKER_MIN_VERSION', '1.6');

/**
 * Implements hook_requirements().
 */
function date_multiselect_requirements($phase) {
  $requirements = array();

  if ($phase == 'runtime') {
    $t = get_t();
    $library = libraries_detect('multidatespicker');

    if (empty($library['installed'])) {
      $requirements['multidatespicker'] = array(
        'title' => $t('MultiDatesPicker plugin'),
        'value' => $t('At least @a', array('@a' => MULTIDATESPICKER_MIN_VERSION)),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('You need to download the !multidatespicker, extract the archive and place the multidatespicker directory in the %path directory on your server.', array(
          '!multidatespicker' => l($t('MultiDatesPicker plugin'), $library['download url']),
          '%path' => 'sites/all/libraries',
        )),
      );
    }
    elseif (version_compare($library['version'], MULTIDATESPICKER_MIN_VERSION, '>=')) {
      $requirements['multidatespicker'] = array(
        'title' => $t('MultiDatesPicker plugin'),
        'severity' => REQUIREMENT_OK,
        'value' => $library['version'],
      );
    }
    else {
      $requirements['multidatespicker'] = array(
        'title' => $t('MultiDatesPicker plugin'),
        'value' => $t('At least @a', array('@a' => MULTIDATESPICKER_MIN_VERSION)),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('You need to download a later version of the !multidatespicker and replace the old version located in the %path directory on your server.', array(
          '!multidatespicker' => l($t('MultiDatesPicker plugin'), $library['download url']),
          '%path' => $library['library path'],
        )),
      );
    }
  }

  return $requirements;
}
