<?php
// $Id: soapclient.install,v 1.1.2.1 2009/10/12 23:50:02 ilo Exp $

/**
 * @file
 * soapclient.install
 *
 * Upgrade paths and install/uninstall functions
 */

/**
 * Implementation of hook_uninstall();
 */
function soapclient_uninstall() {

  variable_del('soapclient_lib');
  variable_del('soapclient_nusoap_path');
  variable_del('soapclient_proxyhost');
  variable_del('soapclient_proxyport');
  variable_del('soapclient_proxyuser');
  variable_del('soapclient_proxypass');
  variable_del('soapclient_reqtimeout');
  variable_del('soapclient_reptimeout');
  variable_del('soapclient_wsdlcache_path');
  variable_del('soapclient_wsdlcache_lifetime');

}


/**
 * Implementation of hook_requirements();
 */
function soapclient_requirements($phase) {
  $requirements = array();
  $t = get_t();

    // check for SOAP library
    $requirements['soapclient'] = array(
      'title' => $t('SOAP Client'),
      'value' => $t('PHP5 SOAP or nuSOAP')
    );

    //Find if nuSOAP library is installed
    $searchdir[] = './'. conf_path();
    $searchdir[] = './sites/all';

    //Get current list of nusoap libraries installed. Just looks for nusoap.php file
    $nusoap_libs = array();
    foreach ($searchdir as $dir) {
      $nusoap_libs = array_merge($nusoap_libs, file_scan_directory($dir, "nusoap\.php$"));
    }

    if (!count($nusoap_libs) && !extension_loaded('soap')) {
      $requirements['soapclient']['severity'] = REQUIREMENT_ERROR;
      $requirements['soapclient']['value'] = $t('Neither nuSOAP nor PHP5 SOAP are available for this system');
      $requirements['soapclient']['description'] = $t('Soapclient module needs nuSOAP or PHP5 SOAP extension available. Currently, none of these two libraries was found installed. Please, follow the instructions about installing nuSOAP or '.
                                                      'enabling SOAP extension if you are using PHP5 in the documentation.');
    }

    if ( count($nusoap_libs) && !file_exists(variable_get('soapclient_nusoap_path', '')) ) {
      $requirements['soapclient']['severity'] = REQUIREMENT_WARNING;
      $requirements['soapclient']['value'] = $t('A nuSOAP library has been detected in the system, but is not configured to be used by the Soap Client module.');
      $requirements['soapclient']['description'] = $t('Please, !configure the SoapClient module to use this library path:<br> !lib',
                                                     array(
                                                       '!configure' => l('configure', 'admin/settings/soapclient'),
                                                       '!lib' => reset($nusoap_libs)->filename)
                                                     );
    }

  return $requirements;
}
