<?php
require_once 'dbconfig.inc.php';
require 'dbhandler.inc.php';
header ("Content-Type:text/xml");
$none = 'Es liegen keine Anruferinformation zu dieser Nummer vor.';
$remoteNumber = $none;
if(isset($_GET['number']) && $_GET['number'] != '')
{
$remoteNumber = escapeString($_GET['number']);
}
if(!(isset($_GET['key']) && $_GET['key'] != ''))
{
doXML($remoteNumber, 'Es wurde kein API-Key für die Abfrage unter tel.search.ch gefunden.');
exit;
}
function curl_get($url, array $get = NULL, array $options = array())
{
// CURLOPT_TIMEOUT geändert von 4 nach 1
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 1
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
@trigger_error(curl_error($ch));
exit;
}
curl_close($ch);
return $result;
}
if($remoteNumber != $none)
{
$swissNumberPrefix = '0041';
// ist schweizer nummer?
if(substr($remoteNumber, 0, 4) == $swissNumberPrefix)
{
$localNumber = convertIntNumberFormatToLocalFormat($remoteNumber);
$key = $_GET['key'];
$params = array ( 'was' => $localNumber, 'key' => $key );
@preg_match('#<content type="text">(.+?)</content>#is', curl_get('http://tel.search.ch/api/', $params), $matches);
// schweizer nummer vorhanden in tel.search.ch?
if($matches!=null || count($matches) > 0)
{
// schweizer nummer vothanden in tel.search.ch
doXML($remoteNumber, $matches[1]);
}
else
{
// schweizer nummer nicht vorhanden in tel.search.ch
$db_result = getMySQLRowValues("SELECT lastname, firstname, company, email, street, city, state, zip FROM cards WHERE phone = '".$localNumber."';");
$last_name = $db_result[0];
if($last_name == null || $last_name == '')
{
doXML($remoteNumber, $none);
}
else
{
$first_name = $db_result[1];
$company = $db_result[2];
$email = $db_result[3];
$street = $db_result[4];
$city = $db_result[5];
$state = $db_result[6];
$zip = $db_result[7];
$output = $last_name.' '.$first_name;
if(!($company == null || $company == '' || strtolower($company) == 'privat'))
{
$output = $output.', '.$company;
}
if(!($email == null || $email == ''))
{
$output = $output.', '.$email;
}
if(!($street == null || $street == ''))
{
$output = $output.', '.$street;
}
if(!($city == null || $city == ''))
{
if($state == null)
{
$state = '';
}
else
{
$state = '/'.$state;
}
if(!($zip == null || $zip == '' || $zip == '0' || $zip == 0))
{
$output = $output.', '.'CH-'.$zip.' '.$city.$state;
}
else
{
$output = $output.', '.$city.$state;
}
}
doXML($remoteNumber, $output);
}
}
}
}
else
{
doXML($remoteNumber, $none);
}
function convertIntNumberFormatToLocalFormat($arg1)
{
return '0'.substr($arg1, 4);
}
function getMySQLRowValues($sqlQuery)
{
$resultSet = mysql_query($sqlQuery);
$row = mysql_fetch_array($resultSet);
return $row;
}
function doXML($title, $text)
{
print '<AastraIPPhoneTextScreen>'."\r\n";
print '<Title>'.$title.'</Title>'."\r\n";
print '<Text>'.$text.'</Text>'."\r\n";
print '</AastraIPPhoneTextScreen>';
}
function escapeString($arg1)
{
if(get_magic_quotes_gpc())
{
$arg1=stripslashes($arg1);
}
$arg1=str_replace('%','\%',$arg1);
$arg1=str_replace('_','\_',$arg1);
$arg1=addslashes($arg1);
return $arg1;
}
?>