<?php
/*
    "NuSOAP and WSDL"
    http://www.nonplus.net/geek/000752.php

    Copyright 2003, Stepan Riha, All right reserved.

    You're free to make derivative and commercial use of this code
    without attribution.

    Version 2.0 - Oct 29, 2003
    Fixed problems with unquoted string constants.

*/
require_once ('config/cfg.php');

//apache htaccess - www authentication
if ( ( !isset( $PHP_AUTH_USER )) || (!isset($PHP_AUTH_PW))  
     || ( $PHP_AUTH_USER != $htaccessUser ) || ( $PHP_AUTH_PW != $htaccessPassword ) ) { 
    header( 'WWW-Authenticate: Basic realm="Private"' ); 
    header( 'HTTP/1.0 401 Unauthorized' ); 
    echo "This folder is protected "; 
    exit; 
} 

//$NAMESPACE = 'urn:Callware';
$NAMESPACE = 'urn:Callware';
$server = new soap_server;

$server->debug_flag=false;
$server->configureWSDL('Callware', $NAMESPACE);
$server->wsdl->schemaTargetNamespace = $NAMESPACE;

// ==== METHOD IMPLEMENTATION ==================================================

//include all files in the function/ folder
if ($handle = opendir('function/')) {
  while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != ".." and substr($file,-4)==".php" ) {
      include ("function/".$file);
    }
  }
  closedir($handle);
}

// ==== WSDL TYPES DECLARATION =================================================

include ("structs.php");

// ==== WSDL METHODS REGISTRATION ==============================================



$server->register(
    'getEntity',
    array('id'=>'xsd:int'),
    array('return'=>'tns:EntityArray'),
    $NAMESPACE);

$server->register(
    'getClient',
    array('id'=>'xsd:int', 'prot'=>'xsd:int'),
    array('return'=>'tns:ClientArray'),
    $NAMESPACE);

$server->register(
    'putClient',
    array('client'=>'tsn:Client'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delClient',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'getOffice',
    array('id'=>'xsd:int'),
    array('return'=>'tns:OfficeArray'),
    $NAMESPACE);

$server->register(
    'putOffice',
    array('dep'=>'tsn:Office'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delOffice',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getProvider',
    array('id'=>'xsd:int'),
    array('return'=>'tns:ProviderArray'),
    $NAMESPACE);

$server->register(
    'putProvider',
    array('res'=>'tsn:Provider'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delProvider',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'getPhoneNumber',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PhoneNumberArray'),
    $NAMESPACE);

$server->register(
    'putPhoneNumber',
    array('number'=>'tsn:PhoneNumber'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delPhoneNumber',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'getGroup',
    array('id'=>'xsd:int', 'type'=>'xsd:int'),
    array('return'=>'tns:GroupArray'),
    $NAMESPACE);
    
$server->register(
    'putGroup',
    array('group'=>'tsn:Group'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delGroup',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getRight',
    array('id'=>'xsd:int'),
    array('return'=>'tns:RightArray'),
    $NAMESPACE);
    
$server->register(
    'putRight',
    array('right'=>'tsn:Right'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delRight',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getApplication',
    array('id'=>'xsd:int'),
    array('return'=>'tns:ApplicationArray'),
    $NAMESPACE);
    
$server->register(
    'getApplicationByName',
    array('name'=>'xsd:string'),
    array('return'=>'tns:ApplicationArray'),
    $NAMESPACE);

$server->register(
    'putApplication',
    array('app'=>'tns:Application'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delApplication',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getQueue',
    array('id'=>'xsd:int'),
    array('return'=>'tns:QueueArray'),
    $NAMESPACE);

 $server->register(
    'getQueueByName',
    array('name'=>'xsd:string'),
    array('return'=>'tns:QueueArray'),
    $NAMESPACE);
   
$server->register(
    'putQueue',
    array('queue'=>'tsn:Queue'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delQueue',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getIvrNode',
    array('id'=>'xsd:int', 'ivr'=>'xsd:int'),
    array('return'=>'tns:IvrNodeArray'),
    $NAMESPACE);
    
$server->register(
    'putIvrNode',
    array('queue'=>'tsn:IvrNode'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delIvrNode',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getIvr',
    array('id'=>'xsd:int'),
    array('return'=>'tns:IvrArray'),
    $NAMESPACE);

$server->register(
    'putIvr',
    array('ivr'=>'tsn:Ivr'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delIvr',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'compileIvr',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getCard',
    array('id'=>'xsd:int'),
    array('return'=>'tns:CardArray'),
    $NAMESPACE);
    
$server->register(
    'putCard',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delCard',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    

$server->register(
    'getIsdnPort',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'updateIsdnPort',
    array('ports'=>'tns:PortArray'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getConfOption',
    array('id'=>'xsd:int','category'=>'xsd:string'),
    array('return'=>'tns:OptionArray'),
    $NAMESPACE);
    
$server->register(
    'getOptionByName',
    array('id'=>'xsd:string','category'=>'xsd:string'),
    array('return'=>'tns:OptionArray'),
    $NAMESPACE);
    
$server->register(
    'putOption',
    array('technology'=>'xsd:int','option'=>'tns:AssociativeArray'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'getIsdnGroup',
    array('id'=>'xsd:int'),
    array('return'=>'tns:IsdnGroupArray'),
    $NAMESPACE);

$server->register(
    'putIsdnGroup',
    array('group'=>'tns:IsdnGroup'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'delIsdnGroup',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getAction',
    array('id'=>'xsd:int'),
    array('return'=>'tns:ActionArray'),
    $NAMESPACE);

$server->register(
    'writeMIsdn',
    array(),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'writeSIP',
    array(),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'writeIAX',
    array(),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'updateNetwork',
    array('option'=>'tns:stringArray'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'getDirectory',
    array(),
    array('return'=>'tns:DirectoryArray'),
    $NAMESPACE);
    
$server->register(
    'initialize',
    array('genKeys' => 'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'getUser',
    array('id'=>'xsd:int'),
    array('return'=>'tns:UserArray'),
    $NAMESPACE);

$server->register(
    'putUser',
    array('user'=>'tns:User'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'checkUser',
    array('username'=>'xsd:string','password'=>'xsd:string'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delUser',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'createAstConfig',
    array('lines'=>'tns:stringArray','filename'=>'xsd:string'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'viewAstConfigFilename',
    array(),
    array('return'=>'tns:stringArray'),
    $NAMESPACE);

$server->register(
    'viewAstConfig',
    array('filename'=>'xsd:string'),
    array('return'=>'xsd:string'),
    $NAMESPACE);

$server->register(
    'getPublicKey',
    array(),
    array('return'=>'xsd:string'),
    $NAMESPACE);

$server->register(
    'getVoiceMail',
    array('id'=>'xsd:int'),
    array('return'=>'tns:VoiceMailArray'),
    $NAMESPACE);

$server->register(
    'putVoiceMail',
    array('voicemail'=>'tns:VoiceMail'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'stats',
    array('request'=>'tns:CdrRequest'),
    array('return'=>'tns:CdrArray'),
    $NAMESPACE); 
    
$server->register(
    'getTechnology',
    array('id'=>'xsd:int'),
    array('return'=>'tns:TechnologyArray'),
    $NAMESPACE);

$server->register(
    'getTimeSegment',
    array('id'=>'xsd:int'),
    array('return'=>'tns:TimeSegmentArray'),
    $NAMESPACE);

$server->register(
    'putTimeSegment',
    array('ts'=>'tns:TimeSegment'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delTimeSegment',
    array('id'=>'xds:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'getRule',
    array('id'=>'xds:int','type'=>'xds:int',),
    array('return'=>'tns:RuleArray'),
    $NAMESPACE);

$server->register(
    'putRule',
    array('id'=>'tns:Rule'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delRule',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getOutgoingRule',
    array('id'=>'xds:int'),
    array('return'=>'tns:OutgoingRuleArray'),
    $NAMESPACE);

$server->register(
    'putOutgoingRule',
    array('id'=>'tns:OutgoingRule'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delOutgoingRule',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getIncomingRule',
    array('id'=>'xds:int'),
    array('return'=>'tns:IncomingRuleArray'),
    $NAMESPACE);

$server->register(
    'putIncomingRule',
    array('id'=>'tns:IncomingRule'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delIncomingRule',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'moveRule',
    array('id'=>'xsd:int', 'direction'=>'xsd:int', 'type'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    

$server->register(
    'getEntityName',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:string'),
    $NAMESPACE);

$server->register(
    'getMacro',
    array('id'=>'xsd:int'),
    array('return'=>'tns:MacroArray'),
    $NAMESPACE);
    
$server->register(
    'getMacroByName',
    array('name'=>'xsd:string'),
    array('return'=>'tns:MacroArray'),
    $NAMESPACE);

$server->register(
    'putMacro',
    array('id'=>'tns:Macro'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delMacro',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getPlugin',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PluginArray'),
    $NAMESPACE);

 $server->register(
    'getPluginByName',
    array('name'=>'xsd:string'),
    array('return'=>'tns:PluginArray'),
    $NAMESPACE);    
    
$server->register(
    'getPluginByPackageName',
    array('name'=>'xsd:string'),
    array('return'=>'tns:PluginArray'),
    $NAMESPACE); 
    
$server->register(
    'getPluginByEntity',
    array('type'=>'xsd:string', 'id'=>'xsd:string'),
    array('return'=>'tns:PluginIdArray'),
    $NAMESPACE); 

$server->register(
    'getPluginEntities',
    array('id'=>'xsd:string'),
    array('return'=>'tns:PluginEntityArray'),
    $NAMESPACE);            
    
$server->register(
    'putPlugin',
    array('xmlinfo'=>'xsd:string','xmldata'=>'xsd:string'),    
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'delPlugin',
    array('xsd'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getTrunk',
    array('id'=>'xsd:int','technology'=>'xsd:int'),
    array('return'=>'tns:ChannelArray'),
    $NAMESPACE);

$server->register(
    'getChannel',
    array('id'=>'xsd:int','technology'=>'xsd:int'),
    array('return'=>'tns:ChannelArray'),
    $NAMESPACE);

$server->register(
    'putChannel',
    array('Channel'=>'tns:Channel'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'delChannel',
    array('id'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'moveTrunk',
    array('id'=>'xsd:int','direction'=>'xsd:int'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'versionCheck',
    array(),
    array('return'=>'tns:AssociativeArray'),
    $NAMESPACE);

$server->register(
    'recordAudioFile',
    array('filename' => 'xsd:string','client' => 'xsd:string'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'getAudioFile',
    array(),
    array('return'=>'tns:AudioFileArray'),
    $NAMESPACE);

$server->register(
    'putAudioFile',
    array('filename' => 'xsd:string','name' => 'xsd:string'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
$server->register(
    'deleteAudioFile',
    array('filename' => 'xsd:string'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
	
$server->register(
    'renameAudioFile',
    array('filename' => 'xsd:string','newfilename' => 'xsd:string','newname' => 'xsd:string'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

$server->register(
    'shutdown',
    array('action' => 'xsd:string'),
    array('return'=>'xsd:int'),
    $NAMESPACE);

//****************               Zapata CARD               *********************
//****************      WEB SERVICE METHOD DEFINITION      *********************
//*****************************************************************************/

$server->register(
    'getZap',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'putZap',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'delZap',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'getZapOption',
    array('protocol'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'getZapGroupChannel',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'getZapChannel',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'getZone',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'getZapataGroup',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'putZapataGroup',
    array('group'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'delZapataGroup',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'getZapPort',
    array('id'=>'xsd:int'),
    array('return'=>'tns:PortArray'),
    $NAMESPACE);

$server->register(
    'updateZapPort',
    array('ports'=>'tns:PortArray'),
    array('return'=>'xsd:int'),
    $NAMESPACE);
    
// ==== PROCESS REQUEST ========================================================

$HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA'])
                        ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($HTTP_RAW_POST_DATA);
exit();

?>