diff options
author | James Bottomley <JBottomley@Parallels.com> | 2013-04-25 15:21:36 -0700 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2013-04-26 17:38:30 -0700 |
commit | f31c2af09cc825693c65295d859e14d06447f6d9 (patch) | |
tree | 35b9ac61051c896d62127764840b7aab09487386 | |
download | asterisk-aastra-f31c2af09cc825693c65295d859e14d06447f6d9.tar.gz |
Initial import from Aastra files from the XML demo
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
28 files changed, 5986 insertions, 0 deletions
diff --git a/include/AastraAsterisk.class.php b/include/AastraAsterisk.class.php new file mode 100644 index 0000000..7ba33ad --- /dev/null +++ b/include/AastraAsterisk.class.php @@ -0,0 +1,454 @@ +<?php +################################################################################################### +# Aastra XML API - AastraAsterisk.php +# Copyright Aastra Telecom 2010 +# +# Adapted from the phpagi manager available on Sourceforge +# +# This file includes a class that interfaces with the Asterisk Manager +# +# Public methods +# connect(server,username,secret) +# disconnect() +# Command(command,actionid) +# Originate(...) +# database_show(family) +# database_put(family,key,value) +# database_get(family,key) +# database_del(family,key) +# ExtensionState(exten,context,actionid) +# +# Private methods +# send_request(action,parameters) +# wait_response(allow_timeout) +# Logoff() +# log(message) +# +################################################################################################### + +################################################################################################### +# Main code +################################################################################################### +class AGI_AsteriskManager +{ + # Variables + var $config; + var $socket = NULL; + var $server; + var $port; + var $event_handlers; + var $timeout=False; + + # Constructor + function AGI_AsteriskManager() + { + $this->config['username']='aastra-xml'; + $this->config['secret']='aastra-xml'; + + # Add default values to config for uninitialized values + if(!isset($this->config['server'])) $this->config['server']='localhost'; + if(!isset($this->config['port'])) $this->config['port']=5038; + } + + function add_event_handler($event, $callback) + { + $event = strtolower($event); + if(isset($this->event_handlers[$event])) + { + $this->log("$event handler is already defined, not over-writing."); + return false; + } + $this->event_handlers[$event] = $callback; + return true; + } + + function process_event($parameters) + { + $ret = false; + $e = strtolower($parameters['Event']); + $handler = ''; + if(isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e]; + elseif(isset($this->event_handlers['*'])) $handler = $this->event_handlers['*']; + if(function_exists($handler)) $ret = $handler($e, $parameters, $this->server, $this->port); + return $ret; + } + + function send_request($action, $parameters=array()) + { + $req="Action: $action\r\n"; + foreach($parameters as $var=>$val) $req.="$var: $val\r\n"; + $req.="\r\n"; + fwrite($this->socket, $req); + return $this->wait_response(); + } + + function get_socket() + { + if($this->socket) return(True); + else return(False); + } + + function wait_response($allow_timeout=False) + { + $timeout=False; + do + { + $type=''; + $parameters=array(); + $temp=fgets($this->socket, 4096); + if($temp===False) + { + $check=stream_get_meta_data($this->socket); + if($check['timed_out']!='1') + { + $this->socket=NULL; + break; + } + else $buffer=''; + } + else $buffer=trim($temp); + + while($buffer != '') + { + $a = strpos($buffer, ':'); + if($a) + { + if(!count($parameters)) // first line in a response? + { + $type=strtolower(substr($buffer, 0, $a)); + if(substr($buffer,$a+2)=='Follows') + { + # A follows response means there is a multiline field that follows. + $parameters['data'] = ''; + $buff=fgets($this->socket, 4096); + while(substr($buff, 0, 6) != '--END ') + { + $parameters['data'].=$buff; + $buff=fgets($this->socket,4096); + } + } + } + + # Store parameter in $parameters + $parameters[substr($buffer,0,$a)]=substr($buffer,$a+2); + } + $buffer=trim(fgets($this->socket,4096)); + } + + # Process response + switch($type) + { + case '': + $timeout=$allow_timeout; + break; + case 'event': + $this->process_event($parameters); + break; + case 'response': + break; + default: + $this->log('Unhandled response packet from Manager: '.$type); + break; + } + } while($type!='response' && !$timeout); + return $parameters; + } + + function listen($timeout='60') + { + $exit=False; + $time1=time(); + do + { + $type=''; + $parameters=array(); + $temp=fgets($this->socket, 4096); + if($temp===False) + { + $check=stream_get_meta_data($this->socket); + if($check['timed_out']!='1') + { + $this->socket=NULL; + break; + } + else $buffer=''; + } + else $buffer=trim($temp); + while($buffer!='') + { + $a=strpos($buffer, ':'); + if($a) + { + if(!count($parameters)) + { + $type=strtolower(substr($buffer,0,$a)); + if(substr($buffer,$a+2)=='Follows') + { + # A follows response means there is a multiline field that follows. + $parameters['data']=''; + $buff=fgets($this->socket, 4096); + while(substr($buff, 0, 6) != '--END ') + { + $parameters['data'].=$buff; + $buff=fgets($this->socket,4096); + } + } + } + + # Store parameter in $parameters + $parameters[substr($buffer,0,$a)]=substr($buffer,$a+2); + } + $buffer=trim(fgets($this->socket,4096)); + } + + # Process response + switch($type) + { + case 'event': + $this->process_event($parameters); + break; + default: + if($type!='') $this->log('Unhandled response packet from Manager: '.$type); + break; + } + + # Check timeout + $time2=time(); + if($time2>($time1+$timeout)) $exit=True; + } while(!$exit); + return $parameters; + } + + + function connect($server=NULL,$username=NULL,$secret=NULL,$display=True) + { + # OK so far + $return=True; + + # Use config if not specified + if(!isset($server)) $server = $this->config['server']; + if(!isset($username)) $username = $this->config['username']; + if(!isset($secret)) $secret = $this->config['secret']; + + # Get port from server if specified + if(strpos($server, ':') !== false) + { + $c = explode(':', $server); + $this->server = $c[0]; + $this->port = $c[1]; + } + else + { + $this->server = $server; + $this->port = $this->config['port']; + } + + # Connect the socket + $errno = $errstr = NULL; + $this->socket = @fsockopen($this->server, $this->port, $errno, $errstr); + if($this->socket == false) + { + $this->log("Unable to connect to manager {$this->server}:{$this->port} ($errno): $errstr"); + $return=False; + } + + # Read the header + if($return) + { + $str=fgets($this->socket); + if($str==false) + { + # Problem. + $this->log("Asterisk Manager header not received."); + $return=False; + } + } + + # Login + if($return) + { + $res=$this->send_request('login', array('Username'=>$username, 'Secret'=>$secret)); + if($res['Response'] != 'Success') + { + $this->log('Failed to login using ['.$username.'] for username and ['.$secret.'] for the password.'); + fclose($this->socket); + $return=False; + } + } + + # Timeout + if($return) stream_set_timeout($this->socket,30); + + # Error message + if(!$return and $display) + { + $output = "<AastraIPPhoneTextScreen>\n"; + $output .= "<Title>Configuration error</Title>\n"; + $output .= "<Text>The application cannot connect to the Asterisk Manager. Please contact your administrator.</Text>\n"; + $output .= "</AastraIPPhoneTextScreen>\n"; + header('Content-Type: text/xml'); + header('Content-Length: '.strlen($output)); + echo $output; + exit; + } + + # Return result + return($return); + } + + function disconnect() + { + $this->logoff(); + fclose($this->socket); + } + + function Command($command, $actionid=NULL) + { + $parameters = array('Command'=>$command); + if($actionid) $parameters['ActionID'] = $actionid; + return $this->send_request('Command', $parameters); + } + + function Logoff() + { + return $this->send_request('Logoff'); + } + + function ExtensionState($exten,$context,$actionid=NULL) + { + $parameters=array('Exten'=>$exten,'Context'=>$context); + if($actionid) $parameters['ActionID'] = $actionid; + return($this->send_request('ExtensionState', $parameters)); + } + + + function Originate2($channel, + $exten=NULL, $context=NULL, $priority=NULL, + $application=NULL, $data=NULL, + $timeout=NULL, $callerid=NULL, $variable=NULL, $account=NULL, $async=NULL, $actionid=NULL) + { + $parameters = array('Channel'=>$channel); + if($exten) $parameters['Exten'] = $exten; + if($context) $parameters['Context'] = $context; + if($priority) $parameters['Priority'] = $priority; + if($application) $parameters['Application'] = $application; + if($data) $parameters['Data'] = $data; + if($timeout) $parameters['Timeout'] = $timeout; + if($callerid) $parameters['CallerID'] = $callerid; + if($variable) $parameters['Variable'] = $variable; + if($account) $parameters['Account'] = $account; + if(!is_null($async)) $parameters['Async'] = ($async) ? 'true' : 'false'; + if($actionid) $parameters['ActionID']=$actionid; + return($this->send_request('Originate',$parameters)); + } + + function Originate($channel, $exten, $context, $priority, $timeout, $callerid, $variable, $account, $application, $data) + { + $parameters = array(); + if($channel) $parameters['Channel'] = $channel; + if($exten) $parameters['Exten'] = $exten; + if($context) $parameters['Context'] = $context; + if($priority) $parameters['Priority'] = $priority; + if($timeout) $parameters['Timeout'] = $timeout; + if($callerid) $parameters['CallerID'] = $callerid; + if($variable) $parameters['Variable'] = $variable; + if($account) $parameters['Account'] = $account; + if($application) $parameters['Application'] = $application; + if($data) $parameters['Data'] = $data; + return($this->send_request('Originate', $parameters)); + } + + + function log($message) + { + Aastra_debug($message); + } + + function database_show($family='') + { + $r=$this->command('database show '.$family); + $data=explode("\n",$r['data']); + $db=array(); + array_shift($data); + foreach($data as $line) + { + $temp = explode(":",$line); + if (trim($temp[0]) != '') + { + $temp[1] = isset($temp[1])?$temp[1]:null; + $db[ trim($temp[0]) ] = trim($temp[1]); + } + } + return $db; + } + + function database_put($family, $key, $value) + { + $r = $this->command("database put ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)." ".$value); + return (bool)strstr($r["data"], "success"); + } + + function database_get($family,$key) + { + $r=$this->command('database get '.str_replace(' ','/',$family).' '.str_replace(' ','/',$key)); + $data=strpos($r['data'],'Value:'); + if($data!==false) return trim(substr($r['data'],6+$data)); + else return false; + } + + function database_del($family, $key) + { + $r = $this->command("database del ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); + return (bool)strstr($r["data"], "removed"); + } + + function QueueAdd($queue, $interface, $penalty=0) + { + $parameters = array('Queue'=>$queue, 'Interface'=>$interface); + if($penalty) $parameters['Penalty'] = $penalty; + return $this->send_request('QueueAdd', $parameters); + } + + function QueueRemove($queue, $interface) + { + return $this->send_request('QueueRemove', array('Queue'=>$queue, 'Interface'=>$interface)); + } + + function QueuePause($queue, $interface, $pause) + { + return $this->send_request('QueuePause', array('Queue'=>$queue, 'Interface'=>$interface,'Paused'=>$pause)); + } + + function Queues() + { + return $this->send_request('Queues'); + } + + function QueueStatus($actionid=NULL) + { + if($actionid) return $this->send_request('QueueStatus', array('ActionID'=>$actionid)); + else return $this->send_request('QueueStatus'); + } + + function ParkedCalls($actionid=NULL) + { + if($actionid) return $this->send_request('ParkedCalls', array('ActionID'=>$actionid)); + else return $this->send_request('ParkedCalls'); + } + + function Redirect($channel,$extension,$priority,$context) + { + return $this->send_request('Redirect', array('Channel'=>$channel,'Exten'=>$extension,'Priority'=>$priority,'Context'=>$context)); + } + + function Reload($module='') + { + $this->command('reload '.$module); + } + + function UserEvent($event,$data) + { + return $this->send_request('UserEvent', array('Privilege'=>'user,all','UserEvent'=>$event,'Data'=>$data)); + } +} +?> diff --git a/include/AastraIPPhone.class.php b/include/AastraIPPhone.class.php new file mode 100644 index 0000000..2855288 --- /dev/null +++ b/include/AastraIPPhone.class.php @@ -0,0 +1,259 @@ +<?php +################################################################################################### +# Aastra XML API Classes - AastraIPPhone +# Copyright Aastra Telecom 2005-2010 +# +# AastraIPPhone is the root class for all the Aastra XML objects. +# +# Public methods +# setTitle(Title) to setup the title of an object (optional) +# @title string +# setTitleWrap() to set the title to be wrapped on 2 lines (optional) +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setLockInCall() to set the Lock-in tag to 'call' (optional) +# setAllowAnswer() to set the allowAnswer tag to 'yes' (optional only for non softkey phones) +# setAllowDrop() to set the allowDrop tag to 'yes' (optional only for non softkey phones) +# setAllowXfer() to set the allowXfer tag to 'yes' (optional only for non softkey phones) +# setAllowConf() to set the allowConf tag to 'yes' (optional only for non softkey phones) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +################################################################################################### + +################################################################################################### +# Includes +################################################################################################### +require_once('AastraIPPhone.php'); +require_once('AastraIPPhoneSoftkeyEntry.class.php'); +require_once('AastraIPPhoneIconEntry.class.php'); + +class AastraIPPhone { + var $_entries; + var $_softkeys; + var $_icons; + var $_title=''; + var $_title_wrap=''; + var $_destroyOnExit=''; + var $_cancelAction=''; + var $_refreshTimeout=0; + var $_refreshURL=''; + var $_beep=''; + var $_lockin=''; + var $_timeout=0; + var $_allowAnswer=''; + var $_allowDrop=''; + var $_allowXfer=''; + var $_allowConf=''; + var $_encoding='ISO-8859-1'; + + function AastraIPPhone() + { + # Variables for the XML object + $this->_entries = array(); + $this->_softkeys = array(); + $this->_icons = array(); + $this->_title = ''; + $this->_destroyOnExit=''; + $this->_refreshTimeout=0; + $this->_refreshURL=''; + $this->_beep=''; + $this->_lockin=''; + $this->_timeout=0; + $this->_allowAnswer=''; + $this->_allowDrop=''; + $this->_allowXfer=''; + $this->_allowConf=''; + } + + function setEncodingUTF8() + { + $this->_encoding = 'UTF-8'; + } + + function setTitle($title) + { + $this->_title = $title; + } + + function setTitleWrap() + { + $this->_title_wrap = 'yes'; + } + + function setRefresh($timeout,$URL) + { + $this->_refreshTimeout = $timeout; + $this->_refreshURL = $URL; + } + + function setBeep() + { + $this->_beep='yes'; + } + + function setDestroyOnExit() + { + $this->_destroyOnExit='yes'; + } + + function setCancelAction($cancelAction) + { + $this->_cancelAction=$cancelAction; + } + + + function setLockIn() + { + $this->_lockin='yes'; + } + + function setLockInCall() + { + $this->_lockin='call'; + } + + function setTimeout($timeout) + { + $this->_timeout=$timeout; + } + + function setAllowAnswer() + { + $this->_allowAnswer='yes'; + } + + function setAllowDrop() + { + $this->_allowDrop='yes'; + } + + function setAllowXfer() + { + $this->_allowXfer='yes'; + } + + function setAllowConf() + { + $this->_allowConf='yes'; + } + + function output($flush=False) + { + header("Content-Type: text/xml; charset=".$this->_encoding); + if (($this->_refreshTimeout!=0) and ($this->_refreshURL!='')) header("Refresh: ".$this->_refreshTimeout."; url=".$this->_refreshURL); + $output="<?xml version=\"1.0\" encoding=\"".$this->_encoding."\"?>\n"; + $output.=$this->render(); + header('Content-Length: '.strlen($output)); + echo($output); + if($flush) + { + ob_flush(); + flush(); + } + } + + function generate() + { + return($this->render()); + } + + function addSoftkey($index, $label, $uri, $icon=NULL) + { + if(!Aastra_is_icons_supported()) $icon=NULL; + if(($index>=1) and ($index<=Aastra_number_softkeys_supported())) $this->_softkeys[$index] = new AastraIPPhoneSoftkeyEntry($index, $this->escape($label), $this->escape($uri), $icon); + } + + function addIcon($index, $icon) + { + if(Aastra_is_icons_supported()) $this->_icons[$index] = new AastraIPPhoneIconEntry($index, $icon); + } + + function escape($string) + { + return(str_replace( + array('&', '<', '>', '"', "'"), + array('&', '<', '>', '"', '''), + $string + )); + } + + function convert_high_ascii($s) + { + $HighASCII = array( + "!\xc0!" => 'A', # A` + "!\xe0!" => 'a', # a` + "!\xc1!" => 'A', # A' + "!\xe1!" => 'a', # a' + "!\xc2!" => 'A', # A^ + "!\xe2!" => 'a', # a^ + "!\xc4!" => 'Ae', # A: + "!\xe4!" => 'ae', # a: + "!\xc3!" => 'A', # A~ + "!\xe3!" => 'a', # a~ + "!\xc8!" => 'E', # E` + "!\xe8!" => 'e', # e` + "!\xc9!" => 'E', # E' + "!\xe9!" => 'e', # e' + "!\xca!" => 'E', # E^ + "!\xea!" => 'e', # e^ + "!\xcb!" => 'Ee', # E: + "!\xeb!" => 'ee', # e: + "!\xcc!" => 'I', # I` + "!\xec!" => 'i', # i` + "!\xcd!" => 'I', # I' + "!\xed!" => 'i', # i' + "!\xce!" => 'I', # I^ + "!\xee!" => 'i', # i^ + "!\xcf!" => 'Ie', # I: + "!\xef!" => 'ie', # i: + "!\xd2!" => 'O', # O` + "!\xf2!" => 'o', # o` + "!\xd3!" => 'O', # O' + "!\xf3!" => 'o', # o' + "!\xd4!" => 'O', # O^ + "!\xf4!" => 'o', # o^ + "!\xd6!" => 'Oe', # O: + "!\xf6!" => 'oe', # o: + "!\xd5!" => 'O', # O~ + "!\xf5!" => 'o', # o~ + "!\xd8!" => 'Oe', # O/ + "!\xf8!" => 'oe', # o/ + "!\xd9!" => 'U', # U` + "!\xf9!" => 'u', # u` + "!\xda!" => 'U', # U' + "!\xfa!" => 'u', # u' + "!\xdb!" => 'U', # U^ + "!\xfb!" => 'u', # u^ + "!\xdc!" => 'Ue', # U: + "!\xfc!" => 'ue', # u: + "!\xc7!" => 'C', # ,C + "!\xe7!" => 'c', # ,c + "!\xd1!" => 'N', # N~ + "!\xf1!" => 'n', # n~ + "!\xdf!" => 'ss' + ); + $find = array_keys($HighASCII); + $replace = array_values($HighASCII); + $s = preg_replace($find,$replace,$s); + return $s; + } +} +?> diff --git a/include/AastraIPPhone.php b/include/AastraIPPhone.php new file mode 100644 index 0000000..bf632d2 --- /dev/null +++ b/include/AastraIPPhone.php @@ -0,0 +1,1494 @@ +<?php +################################################################################################### +# Aastra XML API - AastraIPPhone.php +# Copyright Aastra Telecom 2005-2010 +# +# This file includes common functions to be used with the Aastra XML API. +# +# Public functions +# Aastra_decode_HTTP_header() +# This function decodes the HTTP header of an XML GET coming from the phone and returns all the +# information. +# Aastra_escape_encode($string) +# Escape encode a string for XML compliancy +# Aastra_escape_decode(string) +# Escape decode a string for XML compliancy +# Aastra_test_phone_version(version,type,header=NULL) +# This function tests if the phone version is at least a certain version. +# Aastra_test_phone_model(models,check,type) +# This function checks if the current phone is part of the list of supported phones for this +# application. +# Aastra_is_wrap_title_supported(header) +# Aastra_is_style_textmenu_supported(header) +# Aastra_is_formattedtextscreen_supported(header) +# Aastra_is_multipleinputfields_supported(header) +# Aastra_is_icons_supported(header) +# Aastra_is_graphics_supported(header) +# Aastra_is_fastreboot_supported(header) +# Aastra_is_ledcontrol_supported(header) +# Aastra_is_configuration_supported(header) +# Aastra_is_lockin_supported(header) +# Aastra_is_emptyphoneexecute_supported(header) +# Aastra_is_triggerdestroyonexit_supported(header) +# Aastra_is_softkeys_supported(header) +# Aastra_number_softkeys_supported(header) +# Aastra_is_doneaction_supported(header) +# Aastra_is_Answer_key_supported(header) +# Aastra_is_Refresh_supported(header) +# Aastra_is_textmenu_wrapitem_supported(header) +# Aastra_is_local_reset_supported(header) +# Aastra_is_allow_DTMF_supported(header) +# Aastra_is_play_wav_supported(header) +# Aastra_is_sip_notify_supported(header) +# Aastra_is_keypress_supported(header) +# Aastra_is_dialkey_supported(header) +# Aastra_is_dial2key_supported(header) +# Aastra_is_dialuri_supported(header) +# Aastra_is_timeout_supported(header) +# Aastra_is_datetime_input_supported(header) +# Aastra_is_dynamic_sip_supported(header) +# Aastra_is_formattedtextscreen_color_supported(header) +# Aastra_is_lockincall_supported(header) +# Aastra_size_formattedtextscreen() +# Returns the number of lines available for formatted text screen +# Aastra_size_display_line() +# Returns the number of characters per line on the display +# Aastra_get_custom_icon(icon_name) +# Returns hex representation of icon matching the given name. If no icon found, empty icon is returned. +# Aastra_push2phone(server,phone,data) +# Push an XML object to the phone. +# Aastra_getvar_safe(var_name,default,method) +# This function helps protect against injection style attacks by formatting the variable value. +# Aastra_getphone_fingerprint() +# This function returns the phone fingerprint which is a md5 hash of its model, MAC address and +# IP address. +# Aastra_phone_type() +# This function returns the type of phone for an XML perspective. +# +# Private functions +# None +################################################################################################### + +################################################################################################### +# Aastra_decode_HTTP_header() +# +# This function decodes the HTTP header of an XML GET coming from the phone and returns all the +# information. +# +# Parameters +# None +# +# Returns an array +# 'model' Phone Type +# 'mac' Phone MAC Address +# 'firmware' Phone firmware version +# 'ip' Phone Remote IP address +# 'language' Phone Language +# 'module'[x] Expansion Modules +# 'rp' Boolean for RP set +################################################################################################### +function Aastra_decode_HTTP_header() +{ +Global $TEST; + +# Debug mode +if($TEST) + { + # Calculate fake mac address suffix based on client's source address + $fake_mac_suffix = strtoupper(substr(md5(Aastra_getvar_safe('REMOTE_ADDR','','SERVER')),0,6)); + $array=array( 'model'=>'Aastra57i', + 'mac'=>'00085D'.$fake_mac_suffix, + 'firmware'=>'2.5.3.26', + 'ip'=>Aastra_getvar_safe('REMOTE_ADDR','','SERVER'), + 'language'=>'en', + 'rp'=>False + ); + return($array); + } + +# User Agent +$user_agent=Aastra_getvar_safe('HTTP_USER_AGENT','','SERVER'); + +if(stristr($user_agent,'Aastra')) + { + $value=preg_split('/ MAC:/',$user_agent); + $fin=preg_split('/ /',$value[1]); + $value[1]=preg_replace('/\-/','',$fin[0]); + $value[2]=preg_replace('/V:/','',$fin[1]); + } +else + { + $value[0]='MSIE'; + $value[1]='NA'; + $value[2]='NA'; + } + +# Modification for RP phones +$rp=False; +if(strstr($value[0],'RP')) + { + $rp=True; + $value[0]=preg_replace(array('/67/','/ RP/'),array('',''),$value[0]); + } + +# Modules +$module[1]=Aastra_getvar_safe('HTTP_X_AASTRA_EXPMOD1','','SERVER'); +$module[2]=Aastra_getvar_safe('HTTP_X_AASTRA_EXPMOD2','','SERVER'); +$module[3]=Aastra_getvar_safe('HTTP_X_AASTRA_EXPMOD3','','SERVER'); + +# Create array +$array=array('model'=>$value[0],'mac'=>$value[1],'firmware'=>$value[2],'ip'=>Aastra_getvar_safe('REMOTE_ADDR','','SERVER'),'module'=>$module,'language'=>Aastra_getvar_safe('HTTP_ACCEPT_LANGUAGE','','SERVER'),'rp'=>$rp); +return($array); +} + +################################################################################################### +# Aastra_escape_encode($string) +# +# Escape encode a string for XML compliancy +# +# Parameters +# @string string to encode +# +# Returns +# Encoded string +################################################################################################### +function Aastra_escape_encode($string) +{ +return(str_replace( + array('<', '>', '&'), + array('<', '>', '&'), + $string + )); +} + +################################################################################################### +# Aastra_escape_decode(string) +# +# Escape decode a string for XML compliancy +# +# Parameters +# @string string to decode +# +# Returns +# Decoded string +################################################################################################### +function Aastra_escape_decode($string) +{ +return(str_replace( + array('<', '>', '&'), + array('<', '>', '&'), + $string + )); +} + +################################################################################################### +# Aastra_test_phone_version(version,type,header=NULL) +# +# This function tests if the phone version is at least a certain version. +# +# Parameters +# @version minimum phone version '1.3.1.' +# @type if 0 then function takes care of the error messages +# if 1 then the result of the test is sent back, no display +# @header info header if you want to test a different phone (optional) +# Returns +# 0 everything is fine +# 1 Not an Aastra phone +# 2 Wrong firmware version +################################################################################################### +function Aastra_test_phone_version($version,$type,$header=NULL) +{ +# OK by default +$return=0; + +# Start with the HTTP header +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Must be an Aastra +if(stristr($header['model'],'Aastra')) + { + # Retrieve firmware version + $phone_version=$header['firmware']; + $piece=preg_split("/\./",$phone_version); + $count=count($piece)-1; + $phone_version=$piece[0]*100; + if($count>1)$phone_version+=$piece[1]*10; + if($count>2)$phone_version+=$piece[2]; + $piece=preg_split("/\./",$version); + $count=count($piece)-1; + $test_version=$piece[0]*100; + if($count>1)$test_version+=$piece[1]*10; + if($count>2)$test_version+=$piece[2]; + + # Compare to passed version + if($test_version>$phone_version) + { + $return=2; + if($type==0) + { + $output = "<AastraIPPhoneTextScreen>\n"; + $output .= "<Title>Firmware not compatible</Title>\n"; + $output .= "<Text>This XML application needs firmware version $version or better.</Text>\n"; + $output .= "</AastraIPPhoneTextScreen>\n"; + header('Content-Type: text/xml'); + header('Content-Length: '.strlen($output)); + echo $output; + exit; + } + } + } +else + { + $return=1; + if($type==0) + { + echo "This XML application works better when using an Aastra SIP phone, not a Web browser.<p>See <a href=\"http://www.aastratelecom.com/cps/rde/xchg/SID-3D8CCB73-C78FC1E1/03/hs.xsl/23485.htm\">here</a> for instructions and information.<p>Copyright Aastra Telecom 2005-2010."; + exit; + } + } + +# Return results +return($return); +} + +################################################################################################### +# Aastra_test_phone_versions(versions,type,header=NULL) +# +# This function tests if the phone version is at least a certain version. +# +# Parameters +# @version array of minimum phone version '1.3.1.' for each phone type ('1'=>'1.3.1') +# @type if 0 then function takes care of the error messages +# if 1 then the result of the test is sent back, no display +# @header info header if you want to test a different phone (optional) +# +# Phone types +# 1=9112i,9133i +# 2=480i,480i Cordless +# 3=6730i,6731i,6751i,6753i,9143i +# 4=6755i,6757i,6757iCT.9480i,9480iCT +# 5=6739i +# +# Returns +# 0 everything is fine +# 1 Not an Aastra phone +# 2 Wrong firmware version +# +# Example +# Aastra_test_phone_versions(array('1'=>'1.4.2.','2'=>'1.4.2.','3'=>'2.5.3.','4'=>'2.5.3.','5'=>'3.0.1.'),'0'); +################################################################################################### +function Aastra_test_phone_versions($versions,$type,$header=NULL) +{ +# Start with the HTTP header +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Retrieve phone type and requested version +$model_type=Aastra_phone_type($header); + +# Perform the check +if(($versions[$model_type]) or ($model_type=='0')) return(Aastra_test_phone_version($versions[$model_type],$type,$header)); +else + { + switch($model_type) + { + case '1': + $models=array('Aastra9112i','Aastra9133i'); + break; + case '2': + $models=array('Aastra480i','Aastra480i Cordless'); + break; + case '3': + $models=array('Aastra6730i','Aastra6731i','Aastra51i','Aastra53i'); + break; + case '4': + $models=array('Aastra55i','Aastra57iCTi','Aastra9480i','Aastra9480iCT'); + break; + case '5': + $models=array('Aastra6739i'); + break; + } + return(Aastra_test_phone_model($models,False,$type)); + } +} + +################################################################################################### +# Aastra_test_phone_model(models,check,type) +# +# This function checks if the current phone is part of the list of supported phones for this +# application. +# +# Parameters +# @models array with the list of supported or not supported phones +# @check boolean that indicates if True or False is expected +# @type if 0 then function takes care of the error messages +# if 1 then the result of the test is displayed +# +# Returns +# Boolean +# +# Example +# Aastra_test_phone_model(array('Aastra55i','Aastra57i'),True,0) +# True if the phone is an Aastra55i or an Aastra57i +################################################################################################### +function Aastra_test_phone_model($models,$check,$type) +{ +Global $TEST; + +# Debug mode +if($TEST) return True; + +# Get phone characteristics +$header=Aastra_decode_HTTP_header(); +if(in_array($header['model'],$models)==$check) return True; +else + { + if($type==0) + { + $output = "<AastraIPPhoneTextScreen>\n"; + $output .= "<Title>Phone not supported</Title>\n"; + $output .= "<Text>This XML application is not supported by your phone.</Text>\n"; + $output .= "</AastraIPPhoneTextScreen>\n"; + header('Content-Type: text/xml'); + header('Content-Length: '.strlen($output)); + echo $output; + exit; + } + return False; + } +} + +################################################################################################### +# Aastra_is_wrap_title_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_wrap_title_supported($header=NULL) +{ +# True by default +$return=True; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Test the model +switch($header['model']) + { + case 'Aastra9112i': + case 'Aastra9133i': + case 'Aastra480i': + case 'Aastra480i Cordless': + $return=False; + break; + } + +# Return Result +return($return); +} + +################################################################################################### +# Aastra_is_style_textmenu_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_style_textmenu_supported($header=NULL) +{ +# True by default +$return=True; + +# Get header info +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Test model/version +switch($header['model']) + { + case 'Aastra9112i': + case 'Aastra9133i': + case 'Aastra480i': + case 'Aastra480i Cordless': + if(Aastra_test_phone_version('1.4.2.',1,$header)!=0) $return=False; + else $return=True; + break; + case 'Aastra6739i': + $return=False; + break; + } + +# Return Result +return($return); +} + +################################################################################################### +# Aastra_is_formattedtextscreen_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_formattedtextscreen_supported($header=NULL) +{ +# True by default +$return=True; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Test model/version +switch($header['model']) + { + case 'Aastra9112i': + case 'Aastra9133i': + case 'Aastra480i': + case 'Aastra480i Cordless': + $return=False; + break; + case 'Aastra6739i': + if(Aastra_test_phone_version('3.0.1.',1,$header)!=0) $return=False; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_multipleinputfields_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_multipleinputfields_supported($header=NULL) +{ +# False by default +$return=False; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Test model/version +switch($header['model']) + { + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + case 'Aastra9480i': + case 'Aastra9480iCT': + if(Aastra_test_phone_version('2.0.2.',1,$header)==0) $return=True; + break; + case 'Aastra6739i': + if(Aastra_test_phone_version('3.0.1.',1,$header)==0) $return=True; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_icons_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_icons_supported($header=NULL) +{ +# False by default +$return=False; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Test Model/version +switch($header['model']) + { + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + case 'Aastra9480i': + case 'Aastra9480iCT': + if(Aastra_test_phone_version('2.0.2.',1,$header)==0) $return=True; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_graphics_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_graphics_supported($header=NULL) +{ +# False by default +$return=False; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Test Model/Version +switch($header['model']) + { + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + if(Aastra_test_phone_version('2.2.0.',1,$header)==0) $return=True; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_fastreboot_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_fastreboot_supported($header=NULL) +{ +# False by default +$return=False; + +# Test version +if(Aastra_test_phone_version('2.0.2.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_ledcontrol_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_ledcontrol_supported($header=NULL) +{ +# False by default +$return=False; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Version OK? +if(Aastra_test_phone_version('2.0.2.',1,$header)==0) + { + # Test model + switch($header['model']) + { + case 'Aastra51i': + case 'Aastra9480i': + case 'Aastra9480iCT': + break; + default: + $return=True; + break; + } + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_configuration_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_configuration_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.0.1.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_lockin_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_lockin_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.0.1.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_emptyphoneexecute_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_emptyphoneexecute_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.0.1.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_triggerdestroyonexit_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_triggerdestroyonexit_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.0.1.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_softkeys_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_softkeys_supported($header=NULL) +{ +# False by default +$return=False; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Check Model/Version +switch($header['model']) + { + case 'Aastra480i': + case 'Aastra480i Cordless': + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + case 'Aastra9480i': + case 'Aastra9480iCT': + case 'Aastra6739i': + $return=True; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_number_softkeys_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Number of softkeys 6 or 10 +################################################################################################### +function Aastra_number_softkeys_supported($header=NULL) +{ +# No by default +$return=0; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Check Model/Version +switch($header['model']) + { + case 'Aastra480i': + case 'Aastra480i Cordless': + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + case 'Aastra9480i': + case 'Aastra9480iCT': + $return=6; + break; + case 'Aastra6739i': + $return=10; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_doneaction_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_doneAction_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.1.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_Answer_key_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_Answer_key_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.1.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_Refresh_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_Refresh_supported($header=NULL) +{ +# False by default +$return=False; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Check version +if(($header['model']!='Aastra6739i') and (Aastra_test_phone_version('2.0.2.',1,$header)==0)) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_textmenu_wrapitem_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_textmenu_wrapitem_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.2.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_local_reset_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_local_reset_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.3.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_allow_DTMF_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_allow_DTMF_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.3.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_play_wav_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_play_wav_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.3.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_sip_notify_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_sip_notify_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.3.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_keypress_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_keypress_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.3.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_dialkey_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_dialkey_supported($header=NULL) +{ +# False by default +$return=False; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Check model/version +switch($header['model']) + { + case 'Aastra480i': + case 'Aastra480i Cordless': + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + case 'Aastra9480i': + case 'Aastra9480iCT': + case 'Aastra6739i': + $return=True; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_dial2key_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_dial2key_supported($header=NULL) +{ +# False by default +$return=False; + +# Get info header if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Check model/version +switch($header['model']) + { + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + case 'Aastra9480i': + case 'Aastra9480iCT': + case 'Aastra6739i': + $return=True; + break; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_dialuri_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_dialuri_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.0.1.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_timeout_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_timeout_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.0.1.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_datetime_input_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_datetime_input_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.0.1.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_dynamic_sip_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_dynamic_sip_supported($header=NULL) +{ +# False by default +$return=False; + +# Check version +if(Aastra_test_phone_version('2.5.0.',1,$header)==0) $return=True; + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_lockincall_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_lockincall_supported($header=NULL) +{ +# False by default +$return=False; + +# Get info header if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# All but the 6739i +if($header['model']!='Aastra6739i') + { + if(Aastra_test_phone_version('2.6.0.',1,$header)==0) $return=True; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_actionuriconnected_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_actionuriconnected_supported($header=NULL) +{ +# False by default +$return=False; + +# Get info header if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# All but the 6739i +if($header['model']!='Aastra6739i') + { + if(Aastra_test_phone_version('2.6.0.',1,$header)==0) $return=True; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_is_formattedtextscreen_color_supported(header) +# +# Parameters +# header phone HTTP header (optional) +# +# Returns +# Boolean +################################################################################################### +function Aastra_is_formattedtextscreen_color_supported($header=NULL) +{ +# False by default +$return=False; + +# Get info header if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Only the 6739i +if($header['model']=='Aastra6739i') + { + if(Aastra_test_phone_version('3.0.1.',1,$header)==0) $return=True; + } + +# Return result +return($return); +} + + +################################################################################################### +# Aastra_size_formattedtextscreen() +# +# Returns the number of lines available for formatted text screen +# +# Parameters +# None +# +# Returns +# Size of the FormattedTextScreen +################################################################################################### +function Aastra_size_formattedtextscreen($header=NULL) +{ +# No size by default +$return=0; + +# Get info header if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + + +switch($header['model']) + { + case 'Aastra51i': + case 'Aastra53i': + case 'Aastra6730i': + case 'Aastra6731i': + case 'Aastra9143i': + $return=2; + break; + case 'Aastra55i': + case 'Aastra9480i': + case 'Aastra9480iCT': + case 'Aastra57i': + case 'Aastra57iCT': + $return=5; + break; + case 'Aastra6739i': + $return=14; + break; + } + +return($return); +} + +################################################################################################### +# Aastra_size_display_line() +# +# Returns the number of characters per line on the display +# +# Parameters +# None +# +# Returns +# Returns the number of characters per line on the display +################################################################################################### +function Aastra_size_display_line($header=NULL) +{ +$return=0; + +# Get info header if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +switch($header['model']) + { + case 'Aastra51i': + case 'Aastra53i': + case 'Aastra9112i': + case 'Aastra9133i': + case 'Aastra9143i': + case 'Aastra6730i': + case 'Aastra6731i': + $return='16'; + break; + case 'Aastra480i': + case 'Aastra480i Cordless': + case 'Aastra9480i': + case 'Aastra9480iCT': + $return='21'; + break; + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + $return='24'; + break; + case 'Aastra6739i': + $return='32'; + break; + default: + $return='24'; + break; + } + +return($return); +} + +################################################################################################### +# Aastra_max_items_textmenu() +# +# Returns the maximum number of items for a TextMenu object +# +# Parameters +# None +# +# Returns +# 15 or 30 +################################################################################################### +function Aastra_max_items_textmenu($header=NULL) +{ +$return=15; +if(Aastra_test_phone_version('2.2.0.',1,$header)==0) $return=30; +return($return); +} + +################################################################################################### +# Aastra_get_custom_icon(icon_name) +# +# Returns hex representation of icon matching the given name. If no icon found, empty icon is returned. +# +# Parameters +# @iconName Icon name. List of icons: see below +# +# Returns +# Hex representation of icon matching the given name +# Empty icon if icon not found +################################################################################################### +function Aastra_get_custom_icon($icon_name) +{ +# Default icon +$return = '000000000000000000000000'; + +if($icon_name == 'BoxChecked') return '0000FEC6AA92AAC6FE000000'; +if($icon_name == 'BoxUnchecked') return '0000FE8282828282FE000000'; +if($icon_name == 'Office') return '000000FEAEFAAEFE00000000'; +if($icon_name == 'Cellphone') return '000000007E565AFE00000000'; +if($icon_name == 'Home') return '000000103E7A3E1000000000'; +if($icon_name == 'ArrowRightBold') return '000038383838FE7C38100000'; +if($icon_name == 'ArrowLeftBold') return '000010387CFE383838380000'; +if($icon_name == 'Bell') return '000000063E7E3E0600000000'; +if($icon_name == 'Phone') return '000000664E5A4E6600000000'; +if($icon_name == 'MessageUnread') return '00FEC6AA928A8A92AAC6FE00'; +if($icon_name == 'MessageRead') return '00FEC6AA924A2A120A060200'; +if($icon_name == 'Keypad') return '000000540054005400000000'; +if($icon_name == 'DND') return '0000007CEEEEEE7C00000000'; +if($icon_name == 'OK') return '0000000804020C30C0000000'; +if($icon_name == 'Available') return '000000664E5A4E6600000000'; +if($icon_name == 'Offhook') return '00000002060E96F200000000'; +if($icon_name == 'Speaker') return '0038387CFE00281044380000'; +if($icon_name == 'Muted') return '0038387CFE00386C6C6C3800'; + +return($return); +} + +################################################################################################### +# Aastra_push2phone(server,phone,data) +# +# Push an XML object to the phone. +# +# Parameters +# @server IP address or name of the server (must be authorized on the phone) +# @phone IP address or name of the phone to send the object to +# @data XML object to send +# +# Returns +# Boolean +################################################################################################### +function Aastra_push2phone($server,$phone,$data) +{ +# KO by default +$return=False; + +# Prepare the message +$xml = 'xml='.$data; +$post = "POST / HTTP/1.1\r\n"; +$post .= "Host: $phone\r\n"; +$post .= "Referer: $server\r\n"; +$post .= "Connection: Keep-Alive\r\n"; +$post .= "Content-Type: text/xml\r\n"; +$post .= 'Content-Length: '.strlen($xml)."\r\n\r\n"; +$fp = @fsockopen($phone,80,$errno, $errstr, 5); +if($fp) + { + fputs($fp, $post.$xml); + fclose($fp); + $return=True; + } + +# Return result +return($return); +} + +################################################################################################### +# Aastra_getvar_safe(var_name,default,method) +# +# This function helps protect against injection style attacks by formatting the variable value. +# +# Parameters +# @var_name name of the submitted variable. +# @default default value returned if the variable was not submitted. +# @method setting the array to look into. This can be set to GET (default), POST, REQUEST, +# SERVER, etc. +# +# Returns +# Boolean +################################################################################################### +function Aastra_getvar_safe($var_name,$default='',$method='GET') +{ +eval('$return = (isset($_'.$method.'["'.$var_name.'"])) ? htmlentities(html_entity_decode(stripslashes((trim($_'.$method.'["'.$var_name.'"]))),ENT_QUOTES),ENT_QUOTES) : $default;'); +return $return; +} + +################################################################################################### +# Aastra_getphone_fingerprint() +# +# This function returns the phone fingerprint which is a md5 hash of its model, MAC address and +# IP address. +# +# Parameters +# None +# +# Returns +# string MD5 signature +################################################################################################### +function Aastra_getphone_fingerprint() +{ +# Retrieve phone information +$header=Aastra_decode_HTTP_header(); + +# Return signature +return(md5($header['model'].$header['mac'].$header['ip'])); +} + +################################################################################################### +# Aastra_phone_type() +# +# This function returns the type of phone for an XML perspective. +# +# Parameters +# None +# +# Return +# Integer 1=9112i,9133i +# 2=480i,480i Cordless +# 3=6730i,6731i,6751i,6753i,9143i +# 4=6755i,6757i,6757iCT +# 5=6739i +################################################################################################### +function Aastra_phone_type($header=NULL) +{ +# No type by default +$return='0'; + +# Get header info if needed +if(!$header) $header=Aastra_decode_HTTP_header(); + +# Test model/version +switch($header['model']) + { + case 'Aastra9112i': + case 'Aastra9133ii': + $return='1'; + break; + case 'Aastra480i': + case 'Aastra480i Cordless': + $return='2'; + break; + case 'Aastra6730i': + case 'Aastra6731i': + case 'Aastra51i': + case 'Aastra53i': + case 'Aastra9143i': + $return='3'; + break; + case 'Aastra55i': + case 'Aastra57i': + case 'Aastra57iCT': + case 'Aastra9480i': + case 'Aastra9480iCT': + $return='4'; + break; + case 'Aastra6739i': + $return='5'; + break; + } + +# Return result +return($return); +} +?> diff --git a/include/AastraIPPhoneConfiguration.class.php b/include/AastraIPPhoneConfiguration.class.php new file mode 100644 index 0000000..65c146d --- /dev/null +++ b/include/AastraIPPhoneConfiguration.class.php @@ -0,0 +1,90 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneConfiguration +# Copyright Aastra Telecom 2007-2010 +# +# AastraIPPhoneConfiguration object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setBeep() to enable a notification beep with the object (optional) +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setType(type) to set the type of configuration object (optional) +# @type string, configuration change type +# addEntry(parameter,value,type) to add a configuration change +# @parameter string, parameter name +# @value string, parameter value +# @type string, conmfiguration change type (optional) +# setTriggerDestroyOnExit() to set the triggerDestroyOnExit tag to +# "yes" (optional) +# +# Example +# require_once('AastraIPPhoneConfiguration.class.php'); +# $configuration = new AastraIPPhoneConfiguration(); +# $configuration->addEntry('softkey1 label','Test'); +# $configuration->addEntry('softkey1 type','xml'); +# $configuration->setTriggerDestroyOnExit(); +# $configuration->setBeep(); +# $configuration->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneConfigurationEntry.class.php'); + +class AastraIPPhoneConfiguration extends AastraIPPhone { + var $_type=''; + var $_triggerDestroyOnExit=''; + + function addEntry($parameter, $value, $type='') + { + $this->_entries[] = new AastraIPPhoneConfigurationEntry($parameter, $value, $type); + } + + function setTriggerDestroyOnExit() + { + $this->_triggerDestroyOnExit="yes"; + } + + function setType($type) + { + $this->_type=$type; + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneConfiguration"; + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # TriggerDestroyOnExit + if($this->_triggerDestroyOnExit=='yes') $out .= " triggerDestroyOnExit=\"yes\""; + + # Type + if($this->_type!='') $out .= " setType=\"{$this->_type}\""; + + # End of root tag + $out .= ">\n"; + + # Configuration Items + if (isset($this->_entries) && is_array($this->_entries)) + { + foreach ($this->_entries as $entry) $out .= $entry->render(); + } + + # End tag + $out .= "</AastraIPPhoneConfiguration>\n"; + + # Return XML object + return($out); + } +} +?>
\ No newline at end of file diff --git a/include/AastraIPPhoneConfigurationEntry.class.php b/include/AastraIPPhoneConfigurationEntry.class.php new file mode 100644 index 0000000..73e0e87 --- /dev/null +++ b/include/AastraIPPhoneConfigurationEntry.class.php @@ -0,0 +1,52 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneConfigurationEntry +# Firmware 2.0 or better +# Copyright Aastra Telecom 2007-2010 +# +# Internal class for AastraIPPhoneConfiguration object. +################################################################################ + +class AastraIPPhoneConfigurationEntry extends AastraIPPhone { + var $_parameter; + var $_value; + var $_type; + + function AastraIPPhoneConfigurationEntry($parameter, $value, $type) + { + $this->setParameter($parameter); + $this->setValue($value); + $this->setType($type); + } + + function setParameter($parameter) + { + $this->_parameter = $parameter; + } + + function setValue($value) + { + $this->_value = $value; + } + + function setType($type) + { + $this->_type = $type; + } + + + function render() + { + $parameter = $this->escape($this->_parameter); + $value = $this->escape($this->_value); + $type = $this->escape($this->_type); + $xml = "<ConfigurationItem"; + if($type!='') $xml.=" setType=\"".$type."\""; + $xml .=">\n"; + $xml .= "<Parameter>".$parameter."</Parameter>\n"; + $xml .= "<Value>".$value."</Value>\n"; + $xml .= "</ConfigurationItem>\n"; + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneDirectory.class.php b/include/AastraIPPhoneDirectory.class.php new file mode 100644 index 0000000..a847c4a --- /dev/null +++ b/include/AastraIPPhoneDirectory.class.php @@ -0,0 +1,189 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneDirectory +# Copyright Aastra Telecom 2005-2010 +# +# AastraIPPhoneDirectory object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setTitle(Title) to setup the title of an object (optional) +# @title string +# setTitleWrap() to set the title to be wrapped on 2 lines (optional) +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setNext(next) to set URI of the next page (optional) +# @next string +# setPrevious(previous) to set URI of the previous page (optional) +# @previous string +# addEntry(name,phone) to add an element in the list to be displayed, at least one is needed. +# @name string +# @number string, number for dialing +# natsortbyname() to order the list +# +# Example +# require_once('AastraIPPhoneDirectory.class.php'); +# $directory = new AastraIPPhoneDirectory(); +# $directory->setTitle('Title'); +# $directory->setNext('http://myserver.com/script.php?page=2'); +# $directory->setPrevious('http://myserver.com/script.php?page=0'); +# $directory->setDestroyOnExit(); +# $directory->addEntry('John Doe', '200'); +# $directory->addEntry('Jane Doe', '201'); +# $directory->natsortByName(); +# $directory->addSoftkey('1', 'Label', 'http://myserver.com/script.php?action=1'); +# $directory->addSoftkey('6', 'Exit', 'SoftKey:Exit'); +# $directory->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneDirectoryEntry.class.php'); + +class AastraIPPhoneDirectory extends AastraIPPhone { + var $_next=""; + var $_previous=""; + var $_maxitems="30"; + + function setNext($next) + { + $this->_next = $next; + } + + function setPrevious($previous) + { + $this->_previous = $previous; + } + + function addEntry($name, $telephone) + { + $this->_entries[] = new AastraIPPhoneDirectoryEntry($name, $telephone); + } + + function natsortByName() + { + $tmpary = array(); + foreach ($this->_entries as $id => $entry) { + $tmpary[$id] = $entry->getName(); + } + natsort($tmpary); + foreach ($tmpary as $id => $name) { + $newele[] = $this->_entries[$id]; + } + $this->_entries = $newele; + } + + function render() + { + # Begining of root tag + $out = "<AastraIPPhoneDirectory"; + + # Previous + if($this->_previous!="") + { + $previous = $this->escape($this->_previous); + $out .= " previous=\"$previous\""; + } + + # Next + if($this->_next!="") + { + $next = $this->escape($this->_next); + $out .= " next=\"$next\""; + } + + # DestroyOnExit + if($this->_destroyOnExit == 'yes') $out .= " destroyOnExit=\"yes\""; + + # CancelAction + if($this->_cancelAction != "") + { + $cancelAction = $this->escape($this->_cancelAction); + $out .= " cancelAction=\"{$cancelAction}\""; + } + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # Lockin + if($this->_lockin=='yes') $out .= " LockIn=\"yes\""; + + # Timeout + if($this->_timeout!=0) $out .= " Timeout=\"{$this->_timeout}\""; + + # End of root tag + $out .= ">\n"; + + # Title + if ($this->_title!='') + { + $title = $this->escape($this->_title); + $out .= "<Title"; + if ($this->_title_wrap=='yes') $out .= " wrap=\"yes\""; + $out .= ">".$title."</Title>\n"; + } + + # Items + $index=0; + if (isset($this->_entries) && is_array($this->_entries)) + { + foreach ($this->_entries as $entry) + { + if($index<$this->_maxitems) $out .= $entry->render(); + $index++; + } + } + + # Softkeys + if (isset($this->_softkeys) && is_array($this->_softkeys)) + { + foreach ($this->_softkeys as $softkey) $out .= $softkey->render(); + } + + # Icons + if (isset($this->_icons) && is_array($this->_icons)) + { + $IconList=False; + foreach ($this->_icons as $icon) + { + if(!$IconList) + { + $out .= "<IconList>\n"; + $IconList=True; + } + $out .= $icon->render(); + } + if($IconList) $out .= "</IconList>\n"; + } + + # End tag + $out .= "</AastraIPPhoneDirectory>\n"; + + # Return XML object + return $out; + } +} +?> diff --git a/include/AastraIPPhoneDirectoryEntry.class.php b/include/AastraIPPhoneDirectoryEntry.class.php new file mode 100644 index 0000000..bb4a0ac --- /dev/null +++ b/include/AastraIPPhoneDirectoryEntry.class.php @@ -0,0 +1,32 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneDirectoryEntry +# Copyright Aastra Telecom 2007-2010 +# +# Internal class for AastraIPPhoneDirectory object. +######################################################################################################## + +class AastraIPPhoneDirectoryEntry extends AastraIPPhone { + var $_name; + var $_telephone; + + function AastraIPPhoneDirectoryEntry($name, $telephone) + { + $this->_name=$name; + $this->_telephone=$telephone; + } + + function getName() + { + return($this->_name); + } + + function render() + { + $name = $this->escape($this->_name); + $telephone = $this->escape($this->_telephone); + return("<MenuItem>\n<Prompt>{$name}</Prompt>\n<URI>{$telephone}</URI>\n</MenuItem>\n"); + } +} + +?> diff --git a/include/AastraIPPhoneExecute.class.php b/include/AastraIPPhoneExecute.class.php new file mode 100644 index 0000000..d1a6b39 --- /dev/null +++ b/include/AastraIPPhoneExecute.class.php @@ -0,0 +1,76 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneExecute +# Copyright Aastra Telecom 2006-2010 +# +# AastraIPPhoneExecute object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setBeep() to enable a notification beep with the object (optional) +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setTriggerDestroyOnExit() to set the triggerDestroyOnExit tag to "yes" (optional) +# addEntry(url,interruptCall) to add an action to be executed. +# @url string +# @interruptCall string, optional, "yes" or "no" +# +# Example +# require_once('AastraIPPhoneExecute.class.php'); +# $execute = new AastraIPPhoneExecute(); +# $execute->addEntry('http://myserver.com/script.php?choice=2'); +# $execute->addEntry('Command: Reset'); +# $execute->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneExecuteEntry.class.php'); + +class AastraIPPhoneExecute extends AastraIPPhone { + var $_defaultIndex=''; + var $_triggerDestroyOnExit=''; + + function addEntry($url,$interruptCall=NULL) + { + $this->_entries[] = new AastraIPPhoneExecuteEntry($url,$interruptCall); + } + + function setTriggerDestroyOnExit() + { + $this->_triggerDestroyOnExit='yes'; + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneExecute"; + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # TriggerDestroyOnExit + if($this->_triggerDestroyOnExit=='yes') $out .= " triggerDestroyOnExit=\"yes\""; + + # End of root tag + $out .= ">\n"; + + # Execute Items + if (isset($this->_entries) && is_array($this->_entries)) + { + foreach ($this->_entries as $entry) $out .= $entry->render(); + } + + # End tag + $out .= "</AastraIPPhoneExecute>\n"; + + # Return XML object + return($out); + } +} +?>
\ No newline at end of file diff --git a/include/AastraIPPhoneExecuteEntry.class.php b/include/AastraIPPhoneExecuteEntry.class.php new file mode 100644 index 0000000..0d85a4b --- /dev/null +++ b/include/AastraIPPhoneExecuteEntry.class.php @@ -0,0 +1,29 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneExecuteEntry +# Firmware 2.0 or better +# Copyright Aastra Telecom 2005-2010 +# +# Internal class for AastraIPPhoneExecute object. +################################################################################ + +class AastraIPPhoneExecuteEntry extends AastraIPPhone { + var $_url; + var $_interruptCall; + + function AastraIPPhoneExecuteEntry($url,$interruptCall) + { + $this->_url = $url; + $this->_interruptCall = $interruptCall; + } + + function render() + { + $url = $this->escape($this->_url); + $xml = "<ExecuteItem URI=\"".$url."\""; + if ($this->_interruptCall=='no') $xml .= " interruptCall=\"no\""; + $xml .= "/>\n"; + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneFormattedTextScreen.class.php b/include/AastraIPPhoneFormattedTextScreen.class.php new file mode 100644 index 0000000..eeb7e0c --- /dev/null +++ b/include/AastraIPPhoneFormattedTextScreen.class.php @@ -0,0 +1,242 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPFormattedPhoneTextScreen +# Copyright Aastra Telecom 2008-2010 +# +# AastraIPPhoneFormattedTextScreen object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setTitle(Title) to setup the title of an object (optional) +# @title string +# setTitleWrap() to set the title to be wrapped on 2 lines (optional) +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setLockInCall() to set the Lock-in tag to 'call' (optional) +# setAllowAnswer() to set the allowAnswer tag to 'yes' (optional only for non softkey phones) +# setAllowDrop() to set the allowDrop tag to 'yes' (optional only for non softkey phones) +# setAllowXfer() to set the allowXfer tag to 'yes' (optional only for non softkey phones) +# setAllowConf() to set the allowConf tag to 'yes' (optional only for non softkey phones) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# addLine(text,size,align,color) to add a formatted line +# @text string +# @size string, optional, "small", "double" or "large" +# @align string, optional, "left", "right" or "center" +# @color string, optional, "red", "black", ... +# addText(text,size,align,$color) to add a formatted text as formatted lines +# @text string, can include carriage returns +# @size string, optional, "double" +# @align string, optional, "left", "right" or "center" +# @color string, optional, "red", "black", ... +# setScrollStart(height) to define the beginning of the scrolling section and its height +# @height integer +# setScrollEnd() to define the end of the scrolling section +# setAllowDTMF() to allow DTMF passthrough on the object +# setDoneAction(uri) to set the URI to be called when the user selects the default "Done" key (optional) +# @uri string +# setScrollUp(uri) to set the URI to be called when the user presses the Up arrow (optional) +# @uri string +# setScrollDown(uri) to set the URI to be called when the user presses the Down arrow (optional) +# @uri string +# setScrollLeft(uri) to set the URI to be called when the user presses the Left arrow (optional) +# @uri string +# setScrollRight(uri) to set the URI to be called when the user presses the Right arrow (optional) +# @uri string +# +# Example +# require_once('AastraIPPhoneFormattedTextScreen.class.php'); +# $ftext = new AastraIPPhoneFormattedTextScreen(); +# $ftext->setDestroyOnExit(); +# $ftext->addLine('Formatted Screen','double','center'); +# $ftext->setScrollStart('2'); +# $ftext->addLine('Scrolled text1'); +# $ftext->addLine('Scrolled text2'); +# $ftext->addLine('Scrolled text3'); +# $ftext->addLine('Scrolled text4'); +# $ftext->addLine('Scrolled text5'); +# $ftext->setScrollEnd(); +# $ftext->addLine('Footer',NULL,'center'); +# $ftext->addSoftkey('1', 'Label', 'http://myserver.com/script.php?action=1','1'); +# $ftext->addSoftkey('6', 'Exit', 'SoftKey:Exit'); +# $ftext->addIcon('1', 'Icon:Envelope'); +# $ftext->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneFormattedTextScreenEntry.class.php'); + +class AastraIPPhoneFormattedTextScreen extends AastraIPPhone { + var $_doneAction=''; + var $_allowDTMF=''; + var $_scrollUp=''; + var $_scrollDown=''; + var $_scrollLeft=''; + var $_scrollRight=''; + + function addLine($text, $size=NULL, $align=NULL, $color=NULL) + { + $this->_entries[] = new AastraIPPhoneFormattedTextScreenEntry($text, $size, $align, $color, 'normal'); + } + + function addText($text, $size=NULL, $align=NULL, $color=NULL) + { + $pieces=explode("\n",wordwrap($text,$this->_display_size,"\n",True)); + foreach($pieces as $value) $this->_entries[] = new AastraIPPhoneFormattedTextScreenEntry($value, $size, $align, $color, 'normal'); + } + + function setScrollStart($height) + { + $this->_entries[] = new AastraIPPhoneFormattedTextScreenEntry(NULL, $height, NULL, NULL, 'scrollstart'); + } + + function setScrollEnd() + { + $this->_entries[] = new AastraIPPhoneFormattedTextScreenEntry(NULL, NULL, NULL, NULL, 'scrollend'); + } + + function setDoneAction($uri) + { + $this->_doneAction = $uri; + } + + function setAllowDTMF() + { + $this->_allowDTMF = 'yes'; + } + + function setScrollUp($uri) + { + $this->_scrollUp = $uri; + } + + function setScrollDown($uri) + { + $this->_scrollDown = $uri; + } + + function setScrollLeft($uri) + { + $this->_scrollLeft = $uri; + } + + function setScrollRight($uri) + { + $this->_scrollRight = $uri; + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneFormattedTextScreen"; + + # DestroyOnExit + if($this->_destroyOnExit == 'yes') $out .= " destroyOnExit=\"yes\""; + + # CancelAction + if($this->_cancelAction != '') + { + $cancelAction = $this->escape($this->_cancelAction); + $out .= " cancelAction=\"{$cancelAction}\""; + } + + # DoneAction + if($this->_doneAction != '') + { + $doneAction = $this->escape($this->_doneAction); + $out .= " doneAction=\"{$doneAction}\""; + } + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # Lockin + if($this->_lockin!='') $out .= " LockIn=\"{$this->_lockin}\""; + + # AllowAnswer + if($this->_allowAnswer == 'yes') $out .= " allowAnswer=\"yes\""; + + # AllowDrop + if($this->_allowDrop == 'yes') $out .= " allowDrop=\"yes\""; + + # AllowXfer + if($this->_allowXfer == 'yes') $out .= " allowXfer=\"yes\""; + + # AllowConf + if($this->_allowConf == 'yes') $out .= " allowConf=\"yes\""; + + # TimeOut + if($this->_timeout!=0) $out .= " Timeout=\"{$this->_timeout}\""; + + # AllowDTMF + if($this->_allowDTMF=='yes') $out .= " allowDTMF=\"yes\""; + + # Scrolls up/down/left/right + if($this->_scrollUp!='') $out .= " scrollUp=\"".$this->escape($this->_scrollUp)."\""; + if($this->_scrollDown!='') $out .= " scrollDown=\"".$this->escape($this->_scrollDown)."\""; + if($this->_scrollLeft!='') $out .= " scrollLeft=\"".$this->escape($this->_scrollLeft)."\""; + if($this->_scrollRight!='') $out .= " scrollRight=\"".$this->escape($this->_scrollRight)."\""; + + # End of Root tag + $out .= ">\n"; + + # Lines + if (isset($this->_entries) && is_array($this->_entries)) + { + foreach ($this->_entries as $entry) $out .= $entry->render(); + } + + # Softkeys + if (isset($this->_softkeys) && is_array($this->_softkeys)) + { + foreach ($this->_softkeys as $softkey) $out .= $softkey->render(); + } + + # Icons + if (isset($this->_icons) && is_array($this->_icons)) + { + $IconList=False; + foreach ($this->_icons as $icon) + { + if(!$IconList) + { + $out .= "<IconList>\n"; + $IconList=True; + } + $out .= $icon->render(); + } + if($IconList) $out .= "</IconList>\n"; + } + + # End tag + $out .= "</AastraIPPhoneFormattedTextScreen>\n"; + + # Return XML object + return $out; + } + + +} +?> diff --git a/include/AastraIPPhoneFormattedTextScreenEntry.class.php b/include/AastraIPPhoneFormattedTextScreenEntry.class.php new file mode 100644 index 0000000..ba06616 --- /dev/null +++ b/include/AastraIPPhoneFormattedTextScreenEntry.class.php @@ -0,0 +1,50 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneFormattedTextScreenEntry +# Firmware 2.0 or better +# Copyright Aastra Telecom 2008-2010 +# +# Internal class for AastraIPPhoneFormattedTextScreen object. +################################################################################ + +class AastraIPPhoneFormattedTextScreenEntry extends AastraIPPhone { + var $_text; + var $_size; + var $_align; + var $_color; + var $_type; + + function AastraIPPhoneFormattedTextScreenEntry($text, $size, $align, $color, $type) + { + if($size=='double')$this->_text=$this->convert_high_ascii($text); + else $this->_text=$text; + $this->_size=$size; + $this->_align=$align; + $this->_color=$color; + $this->_type=$type; + } + + function render() + { + switch($this->_type) + { + case "normal": + $xml = "<Line"; + if($this->_size!=NULL) $xml .= " Size=\"{$this->_size}\""; + if($this->_align!=NULL) $xml .= " Align=\"{$this->_align}\""; + if($this->_color!=NULL) $xml .= " Color=\"{$this->_color}\""; + $xml .= ">"; + $xml .= $this->escape($this->_text)."</Line>\n"; + break; + case "scrollstart": + if($this->_size!='') $xml = "<Scroll Height=\"{$this->_size}\">\n"; + else $xml = "<Scroll>\n"; + break; + case "scrollend": + $xml = "</Scroll>\n"; + break; + } + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneGDImage.class.php b/include/AastraIPPhoneGDImage.class.php new file mode 100644 index 0000000..26125c1 --- /dev/null +++ b/include/AastraIPPhoneGDImage.class.php @@ -0,0 +1,179 @@ +<?php +######################################################################################################### +# Aastra XML API Classes - Aastra XML API Classes - AastraIPPhoneGDImage +# Copyright Aastra Telecom 2007-2010 +# +# Firmware 2.0 or better +# +# AastraIPPhoneGDImage for AastraIPPhoneImageScreen and AastraIPPhoneImageScreen. +# +# php engine needs GD extensions +# ------------------------------ +# +# Public methods +# +# drawttftext(fontsize,angle,x,y,text,colorIndex,fontfile) +# Writes text to the image using TrueType fonts +# fontsize The font size. Depending on your version of GD, this should be specified as the pixel +# size (GD1) or point size (GD2) +# angle The angle in degrees, with 0 degrees being left-to-right reading text. Higher values +# represent a counter-clockwise rotation. For example, a value of 90 would result in +# bottom-to-top reading text. +# x,y The coordinates given by x and y will define the basepoint of the first character +# (roughly the lower-left corner of the character). +# colorIndex 0=White 1=Black +# fontfile Location and name of the ttf file to use +# see php imagettftext() for more details +# +# drawtext(fontsize,x,y,text,colorIndex) +# Writes text to the image using built-in font +# fontsize The font size. From 1 to 5 +# x,y The coordinates given by x and y will define the basepoint of the first character +# (roughly the lower-left corner of the character). +# colorIndex 0=White 1=Black +# see php imagestring() for more details +# +# rectangle(x1,y1,x2,y2,colorIndex,filled) +# Creates a rectangle starting at the specified coordinates. +# x1,y1 Upper left x,y coordinate. 0,0 is the top left corner of the image. +# x2,y2 Bottom right x,y coordinate +# colorIndex 0=White 1=Black +# filled Boolean, optional (default if False) +# see php imagerectangle() and imagefilledrectangle() for more details +# +# ellipse(cx,cy,width,height,colorIndex,filled) +# Draws an ellipse centered at the specified coordinates. +# cx,cy x-coordinate and y-coordinate of the center +# width the ellipse width +# height the ellipse height +# colorIndex 0=White 1=Black +# filled Boolean, optional (default if False) +# see php imageellipse() and imagefilledellipse() for more details +# +# line(x1,y1,x2,y2,colorIndex) +# Draws a line +# x1,y1 x,y coordinates for the first point +# x2,y2 x,y coordinates for the second point +# colorIndex 0=White 1=Black +# see php imageline() for more details +# +# setGDImage(image) +# Imports an externally generated GD image +# image GD image to import +# +# getGDImage() +# Exports the current GD image +# +# setFontPath(fontpath) +# Set directory path for the fonts to use +# fontpath Directory for the ttf fonts +# Default value +# Windows based platform C:\Windows\Fonts +# Linux based platform ../fonts +# +# Example 1 +# require_once('AastraIPPhoneGDImage.class.php'); +# $PhoneImageGD = new AastraIPPhoneGDImage(); +# $time = strftime("%H:%M"); +# $PhoneImageGD->drawttftext(30, 0, 10, 39, $time, 1,'Ni7seg.ttf'); +# +# Example 2 +# require_once('AastraIPPhoneGDImage.class.php'); +# $PhoneImageGD = new AastraIPPhoneGDImage(); +# $utf8text = "东丝丞丟丸"; +# $PhoneImageGD->drawttftext(20, 0, 5, 35, $utf8text, 1,'arialuni.ttf'); +# +######################################################################################################## + +######################################################################################################## +class AastraIPPhoneGDImage +{ + var $_img; + var $_white; + var $_black; + var $_blackNoAntiAliasing; + var $_font; + var $_fontpath; + +function AastraIPPhoneGDImage() +{ + # create the actual image + $this->_img=imagecreate(144, 40); + + # define black and white + $this->_white = imagecolorallocate($this->_img, 255, 255, 255); + $this->_black = imagecolorallocate($this->_img, 0, 0, 0); + + # Black and White only so disable anti-aliasing + $this->_black = $this->_black * -1; + $this->_white = $this->_white * -1; + + # define a default font path + $os = strtolower(PHP_OS); + if(strpos($os, "win") === false) $this->_fontpath='../fonts'; + else $this->_fontpath='C:\Windows\Fonts'; + putenv('GDFONTPATH='.$this->_fontpath); +} + +function importFromPng($file,$x,$y) + { + $image=@imagecreatefrompng($file); + imagecopy($this->_img,$image,$x,$y,0,0,imagesx($image),imagesy($image)); + } + +function setFontPath($fontpath) + { + $this->_fontpath=$fontpath; + putenv('GDFONTPATH='.$this->_fontpath); + } + + +function drawttftext($size, $angle, $x, $y, $text, $colorIndex, $font) + { + imagettftext($this->_img, $size, $angle, $x, $y, $this->getColor($colorIndex), $font, $text); + } + +function drawtext($size, $x, $y, $text, $colorIndex) + { + imagestring($this->_img, $size, $x, $y, $text, $this->getColor($colorIndex)); + } + +function setGDImage($image) + { + $this->_img=$image; + } + +function getGDImage() + { + return $this->_img; + } + +function rectangle($x1, $y1, $x2, $y2, $colorIndex, $filled=False) + { + if($filled) imagefilledrectangle($this->_img, $x1, $y1, $x2, $y2, $this->getColor($colorIndex)); + else imagerectangle($this->_img, $x1, $y1, $x2, $y2, $this->getColor($colorIndex)); + } + +function ellipse($cx, $cy, $width, $height, $colorIndex, $filled=False) + { + if($filled) imagefilledellipse($this->_img, $cx, $cy, $width, $height, $this->getColor($colorIndex)); + else imageellipse($this->_img, $cx, $cy, $width, $height, $this->getColor($colorIndex)); + } + +function line($x1, $y1, $x2, $y2, $colorIndex, $dashed=False) + { + if(!$dashed) imageline($this->_img, $x1, $y1, $x2, $y2, $this->getColor($colorIndex)); + else + { + $style = array($this->_black, $this->_white); + imagesetstyle($this->_img, $style); + imageline($this->_img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); + } + } + +function getColor($index) + { + if ($index == 0) return $this->_white; else return $this->_black; + } +} +?>
\ No newline at end of file diff --git a/include/AastraIPPhoneIconEntry.class.php b/include/AastraIPPhoneIconEntry.class.php new file mode 100644 index 0000000..6057603 --- /dev/null +++ b/include/AastraIPPhoneIconEntry.class.php @@ -0,0 +1,28 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPIconEntry +# Firmware 2.0 or better +# Copyright Aastra Telecom 2007-2010 +# +# Internal class for AastraIPPhone object. +################################################################################ + +class AastraIPPhoneIconEntry { + var $_index; + var $_icon; + + function AastraIPPhoneIconEntry($index, $icon) + { + $this->_index=$index; + $this->_icon=$icon; + } + + function render() + { + $index = $this->_index; + $icon = $this->_icon; + $xml = "<Icon index=\"{$index}\">{$icon}</Icon>\n"; + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneImageMenu.class.php b/include/AastraIPPhoneImageMenu.class.php new file mode 100644 index 0000000..e0a7e82 --- /dev/null +++ b/include/AastraIPPhoneImageMenu.class.php @@ -0,0 +1,218 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneImageMenu +# Copyright Aastra Telecom 2007-2010 +# +# AastraIPPhoneImageMenu object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setLockInCall() to set the Lock-in tag to 'call' (optional) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setImage(image)to define the image to be displayed +# @image string +# setGDImage(GDImage) to use a GDImage for display, the size is forced to 40x144 +# @GDImage GDImage +# setAlignment(vertical,horizontal) to define image alignment +# @vertical string, "left", "right", "center" +# @horizontal string, "left", "right", "center" +# setSize(height,width) to define image size +# @height integer (pixels) +# @width integer (pixels) +# setURIBase(uriBase) to define the base URI for the selections +# @uriBase string +# addURI(key,uri) to add a selection key with its URI +# @key string (1-9, * and #) +# @uri string +# +# Example +# require_once('AastraIPPhoneImageMenu.class.php'); +# $imagem = new AastraIPPhoneImageMenu(); +# $imagem->setDestroyOnExit(); +# $imagem->setSize(40,144); +# $imagem->setImage('fffffffc02fffffffee4ffffbfffc05fffe7ff7a7ffffffffeffeebd7fffffea6bcfffffe796f3feff6fa289f0a86f4866fa20df42414595dd0134f8037ed1637f0e2522b2dd003b6eb936f05fffbd4f4107bba6eb0080e93715000010b754001281271408c640252081b1b22500013c5c66201368004e04467520dc11067152b82094d418e100247205805494780105002601530020131400020a05c91088b002b08c21c0000c200000001fe800000000000000001c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020041000004008300000ff08500000000c900000000710000000000000001401400000140140000014014000001401400000140140000000000000007c0ff00000c30880000081088000008108800000c30700000062000000000003f000001e02000000330200000021000000003301e000001e0330000000021000003f033000002001e0000020000000000001e000c03fc33003c013021007c02101201f00330ff03f001e000039000003e039001e00103f003300101f8021003007c03303f003c01e000000c00001e001c03f033007802002100f002002103e000001203c401702003cc0290ff039c02902101fc02b000007c03f01a003c020039018c0ff02d03c402102703c400001203ec01e000026402b0000264029000026c029000027c01a0000338000000033800000003100000000300000000030003f00003fc03000003fc02000003fc020000030001f0000300000000030001e000030002b000030002900003fc02900003fc01a00003f00000000310030000031c01e000031f003000033f81e00003f383000001e081e000008c003000003c01e00000fc03000001f000000003d001a0000390039000039002d00003f002700000f8012000007c000000001c0000000004000000000000000000000000000'); +# $imagem->addURI('1','http://myserver.com?choice=1'); +# $imagem->addURI('2','http://myserver.com?Choice=2'); +# $imagem->addSoftkey('1', 'Label', 'http://myserver.com/script.php?action=1','1'); +# $imagem->addSoftkey('6', 'Exit', 'SoftKey:Exit'); +# $imagem->addIcon('1', 'Icon:Envelope'); +# $imagem->addIcon('2', 'FFFF0000FFFF0000'); +# $imagem->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneImageMenuEntry.class.php'); + +class AastraIPPhoneImageMenu extends AastraIPPhone { + var $_image; + var $_verticalAlign=NULL; + var $_horizontalAlign=NULL; + var $_height=NULL; + var $_width=NULL; + var $_uriBase=NULL; + + function setImage($image) + { + $this->_image = $image; + } + + function setAlignment($vertical=NULL,$horizontal=NULL) + { + $this->_verticalAlign = $vertical; + $this->_horizontalAlign = $horizontal; + } + + function setSize($height,$width) + { + $this->_height = $height; + $this->_width = $width; + } + + function setURIBase($uriBase) + { + $this->_uriBase = $uriBase; + } + + function addURI($key, $uri) + { + $this->_entries[] = new AastraIPPhoneImageMenuEntry($key, $uri); + } + + function setGDImage($GDImage) + { + $img = $GDImage->getGDImage(); + $byte = 0; + $i = 0; + $imageHexString = ""; + for ($x=0; $x < 144; $x++) + { + for ($y=0; $y < 40; $y++) + { + $rgb = imagecolorat($img, $x, $y); + if ($rgb > 0) $byte = $byte + pow(2,(7-($i%8))); + if ($i%8 == 7) + { + $byteHex = dechex($byte); + if (strlen($byteHex) == 1) $byteHex = "0".$byteHex; + $imageHexString = $imageHexString . $byteHex; + $byte=0; + } + $i++; + } + } + $this->setImage($imageHexString); + $this->setSize(40,144); + } + + + function render() + { + # Beginning of roor tag + $out = "<AastraIPPhoneImageMenu"; + + # DestroyOnExit + if ($this->_destroyOnExit=='yes') $out .= " destroyOnExit=\"yes\""; + + # CancelAction + if($this->_cancelAction != "") + { + $cancelAction = $this->escape($this->_cancelAction); + $out .= " cancelAction=\"{$cancelAction}\""; + } + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # Lockin + if($this->_lockin!='') $out .= " LockIn=\"{$this->_lockin}\""; + + # Timeout + if($this->_timeout!=0) $out .= " Timeout=\"{$this->_timeout}\""; + + # End of roor tag + $out .= ">\n"; + + # Image tag + $out .= "<Image"; + + # VerticalAlign + if($this->_verticalAlign!=NULL) $out .= " verticalAlign=\"{$this->_verticalAlign}\""; + + # HorizontalAlign + if($this->_horizontalAlign!=NULL) $out .= " horizontalAlign=\"{$this->_horizontalAlign}\""; + + # Height + if($this->_height!=NULL) $out .= " height=\"{$this->_height}\""; + + # Width + if($this->_width!=NULL) $out .= " width=\"{$this->_width}\""; + + # Image + $out .= ">{$this->_image}</Image>\n"; + + # URI List + $out .= "<URIList"; + $uriBase = $this->escape($this->_uriBase); + if($uriBase!=NULL) $out .= " base=\"{$uriBase}\""; + $out .= ">\n"; + if (isset($this->_entries) && is_array($this->_entries)) + { + foreach ($this->_entries as $entry) $out .= $entry->render(); + } + $out .= "</URIList>\n"; + + # Softkeys + if (isset($this->_softkeys) && is_array($this->_softkeys)) + { + foreach ($this->_softkeys as $softkey) $out .= $softkey->render(); + } + + # Icons + if (isset($this->_icons) && is_array($this->_icons)) + { + $IconList=False; + foreach ($this->_icons as $icon) + { + if(!$IconList) + { + $out .= "<IconList>\n"; + $IconList=True; + } + $out .= $icon->render(); + } + if($IconList) $out .= "</IconList>\n"; + } + + # End of root tag + $out .= "</AastraIPPhoneImageMenu>\n"; + + # Return XML object + return($out); + } +} +?> diff --git a/include/AastraIPPhoneImageMenuEntry.class.php b/include/AastraIPPhoneImageMenuEntry.class.php new file mode 100644 index 0000000..d252aad --- /dev/null +++ b/include/AastraIPPhoneImageMenuEntry.class.php @@ -0,0 +1,28 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneImageMenuEntry +# Firmware 2.0 or better +# Copyright Aastra Telecom 2007-2010 +# +# Internal class for AastraIPPhoneImageMenu object. +################################################################################ + +class AastraIPPhoneImageMenuEntry extends AastraIPPhone { + var $_key; + var $_uri; + + function AastraIPPhoneImageMenuEntry($key, $uri) + { + $this->_key=$key; + $this->_uri=$uri; + } + + function render() + { + $key = $this->_key; + $uri = $this->escape($this->_uri); + $xml = "<URI key=\"{$key}\">{$uri}</URI>\n"; + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneImageScreen.class.php b/include/AastraIPPhoneImageScreen.class.php new file mode 100644 index 0000000..a4ba6af --- /dev/null +++ b/include/AastraIPPhoneImageScreen.class.php @@ -0,0 +1,271 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneImageScreen +# Copyright Aastra Telecom 2008-2010 +# +# AastraIPPhoneImageScreen object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setLockInCall() to set the Lock-in tag to 'call' (optional) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setImage(image) to define the image to be displayed +# @image string +# setGDImage(GDImage) to use a GDImage for display, the size is forced to 40x144 +# @GDImage GDImage +# setSPImage(SPImage) to use a SPImage for display, the size is forced to 40x144 +# @SPImage SPImage +# setAlignment(vertical,horizontal) to define image alignment +# @vertical string, "left", "right", "center" +# @horizontal string, "left", "right", "center" +# setSize(height,width) to define image size +# @height integer (pixels) +# @width integer (pixels) +# setAllowDTMF() to allow DTMF passthrough on the object +# setScrollUp(uri) to set the URI to be called when the user presses the Up arrow (optional) +# @uri string +# setScrollDown(uri) to set the URI to be called when the user presses the Down arrow (optional) +# @uri string +# setScrollLeft(uri) to set the URI to be called when the user presses the Left arrow (optional) +# @uri string +# setScrollRight(uri) to set the URI to be called when the user presses the Right arrow (optional) +# @uri string +# +# Example +# +# Using a Pixel image +# +# require_once('AastraIPPhoneImageScreen.class.php'); +# $images = new AastraIPPhoneImageScreen(); +# $images->setDestroyOnExit(); +# $images->setSize(40,40); +# $images->setImage('fffffffc02fffffffee4ffffbfffc05fffe7ff7a7ffffffffeffeebd7fffffea6bcfffffe796f3feff6fa289f0a86f4866fa20df42414595dd0134f8037ed1637f0e2522b2dd003b6eb936f05fffbd4f4107bba6eb0080e93715000010b754001281271408c640252081b1b22500013c5c66201368004e04467520dc11067152b82094d418e100247205805494780105002601530020931400020ac5c91088b0f2b08c21c07d0c2006009fdfe81f80efe0107fe0fb1c3ffff8ffc3fffef8f7febffbfcf87ffbff64'); +# $images->addSoftkey('1', 'Mail', 'http://myserver.com/script.php?action=1','1'); +# $images->addSoftkey('6', 'Exit', 'SoftKey:Exit'); +# $images->addIcon('1', 'Icon:Envelope'); +# $images->output(); +# +# Using a GD image +# +# require_once('AastraIPPhoneGDImage.class.php'); +# require_once('AastraIPPhoneImageScreen.class.php'); +# $PhoneImageGD = new AastraIPPhoneGDImage(); +# $object = new AastraIPPhoneImageScreen(); +# $time = strftime("%H:%M"); +# $PhoneImageGD->drawttftext(30, 0, 10, 39, $time, 1,'Ni7seg.ttf'); +# $object->setGDImage($PhoneImageGD); +# $object->output(); +# +# Using a SP image +# +# require_once('AastraIPPhoneImageScreen.class.php'); +# $object = new AastraIPPhoneImageScreen(); +# require_once('AastraIPPhoneSPImage.class.php'); +# $SPimage=new AastraIPPhoneSPImage(); +# $SPimage->addIcon('1','286CEE6C2800'); +# $SPimage->setBitmap('answered',3,1); +# $SPimage->setText('Jean Valjean',1,'left',3); +# $SPimage->setText('9057604454',2,'left',3); +# $SPimage->setText('Sep 9 10:14am',4,'left',3); +# $SPimage->setText('Use #1# to browse',5,'center'); +# $object->setSPImage($SPimage); +# $object->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); + +class AastraIPPhoneImageScreen extends AastraIPPhone { + var $_image; + var $_verticalAlign=NULL; + var $_horizontalAlign=NULL; + var $_height=NULL; + var $_width=NULL; + var $_allowDTMF=''; + var $_scrollUp=''; + var $_scrollDown=''; + var $_scrollLeft=''; + var $_scrollRight=''; + + function setImage($image) + { + $this->_image = $image; + } + + function setAlignment($vertical=NULL,$horizontal=NULL) + { + $this->_verticalAlign = $vertical; + $this->_horizontalAlign = $horizontal; + } + + function setSize($height,$width) + { + $this->_height = $height; + $this->_width = $width; + } + + function setScrollUp($uri) + { + $this->_scrollUp = $uri; + } + + function setScrollDown($uri) + { + $this->_scrollDown = $uri; + } + + function setScrollLeft($uri) + { + $this->_scrollLeft = $uri; + } + + function setScrollRight($uri) + { + $this->_scrollRight = $uri; + } + + function setGDImage($GDImage) + { + $img = $GDImage->getGDImage(); + $byte = 0; + $i = 0; + $imageHexString = ""; + for ($x=0; $x < 144; $x++) + { + for ($y=0; $y < 40; $y++) + { + $rgb = imagecolorat($img, $x, $y); + if ($rgb > 0) $byte = $byte + pow(2,(7-($i%8))); + if ($i%8 == 7) + { + $byteHex = dechex($byte); + if (strlen($byteHex) == 1) $byteHex = "0".$byteHex; + $imageHexString = $imageHexString . $byteHex; + $byte=0; + } + $i++; + } + } + $this->setImage($imageHexString); + $this->setSize(40,144); + } + + function setSPImage($SPImage) + { + $this->setImage($SPImage->getSPImage()); + $this->setSize(40,144); + } + + function setAllowDTMF() + { + $this->_allowDTMF = 'yes'; + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneImageScreen"; + + # DestroyOnExit + if($this->_destroyOnExit == 'yes') $out .= " destroyOnExit=\"yes\""; + + # CancelAction + if($this->_cancelAction != "") + { + $cancelAction = $this->escape($this->_cancelAction); + $out .= " cancelAction=\"{$cancelAction}\""; + } + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # Lockin + if($this->_lockin!='') $out .= " LockIn=\"{$this->_lockin}\""; + + # Timeout + if($this->_timeout!=0) $out .= " Timeout=\"{$this->_timeout}\""; + + # AllowDTMF + if($this->_allowDTMF=='yes') $out .= " allowDTMF=\"yes\""; + + # Scrolls up/down/left/right + if($this->_scrollUp!='') $out .= " scrollUp=\"".$this->escape($this->_scrollUp)."\""; + if($this->_scrollDown!='') $out .= " scrollDown=\"".$this->escape($this->_scrollDown)."\""; + if($this->_scrollLeft!='') $out .= " scrollLeft=\"".$this->escape($this->_scrollLeft)."\""; + if($this->_scrollRight!='') $out .= " scrollRight=\"".$this->escape($this->_scrollRight)."\""; + + # End of root tag + $out .= ">\n"; + + # Beginning of Image tag + $out .= "<Image"; + + # VerticalAlign + if($this->_verticalAlign!=NULL) $out .= " verticalAlign=\"{$this->_verticalAlign}\""; + + # HorizontalAlign + if($this->_horizontalAlign!=NULL) $out .= " horizontalAlign=\"{$this->_horizontalAlign}\""; + + # Height + if($this->_height!=NULL) $out .= " height=\"{$this->_height}\""; + + # Width + if($this->_width!=NULL) $out .= " width=\"{$this->_width}\""; + + # Image and end of image tag + $out .= ">{$this->_image}</Image>\n"; + + # Softkeys + if (isset($this->_softkeys) && is_array($this->_softkeys)) + { + foreach ($this->_softkeys as $softkey) $out .= $softkey->render(); + } + + # Icons + if (isset($this->_icons) && is_array($this->_icons)) + { + $IconList=False; + foreach ($this->_icons as $icon) + { + if(!$IconList) + { + $out .= "<IconList>\n"; + $IconList=True; + } + $out .= $icon->render(); + } + if($IconList) $out .= "</IconList>\n"; + } + + # End tag + $out .= "</AastraIPPhoneImageScreen>\n"; + + # Return XML object + return $out; + } +} +?> diff --git a/include/AastraIPPhoneInputScreen.class.php b/include/AastraIPPhoneInputScreen.class.php new file mode 100644 index 0000000..4ef2f72 --- /dev/null +++ b/include/AastraIPPhoneInputScreen.class.php @@ -0,0 +1,362 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneInputScreen +# Copyright Aastra Telecom 2005-2010 +# +# AastraIPPhoneInputScreen object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setTitle(Title) to setup the title of an object (optional) +# @title string +# setTitleWrap() to set the title to be wrapped on 2 lines (optional) +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setLockInCall() to set the Lock-in tag to 'call' (optional) +# setAllowAnswer() to set the allowAnswer tag to 'yes' (optional only for non softkey phones) +# setAllowDrop() to set the allowDrop tag to 'yes' (optional only for non softkey phones) +# setAllowXfer() to set the allowXfer tag to 'yes' (optional only for non softkey phones) +# setAllowConf() to set the allowConf tag to 'yes' (optional only for non softkey phones) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object - Single Input +# setURL(url) to set the URL to called after the input +# @url string +# setType(type) to set type of input, 'string' by default +# @type enum ('IP', 'string', 'number', 'dateUS'...) +# setDefault(default) to set default value for the input (optional) +# @default string +# setParameter(param) to set the parameter name to be parsed after the input +# @param string +# setInputLanguage(language) to set the language of the input (optional) +# @language enum ("English", "French"....) +# setPassword() to set the Password parameter to 'yes', 'no' by default (optional) +# setNotEditable() to set the editable parameter to 'no', 'yes' by default (optional) +# setEditable() is now replaced by setNotEditable but kept for compatibility reasons (optional) +# setPrompt(prompt) to set the prompt to be displayed for the input. +# @prompt string +# +# Specific to the object - Multiple Inputs +# setURL(url) to set the URL to called after the input +# @url string +# setType(type) to set the default type of input 'string' by default +# @type enum ('IP', 'string', 'number', 'dateUS'...) +# setDefault(default) to set default default value for the input (optional) +# @default string +# setParameter(param) to set the default parameter name to be parsed after the input +# @param string +# setPassword() to set the default Password parameter to 'yes', 'no' by default (optional) +# setNotEditable() to set the default editable parameter to 'no', 'yes' by default (optional) +# setEditable() is now replaced by setNotEditable but kept for compatibility reasons (optional) +# setPrompt(prompt) to set the default prompt to be displayed for the input. +# @prompt string +# setDefaultIndex(index) to define the field index the object will use to start (optional) +# @index integer, optional, default is 1 +# setDisplayMode(display) to define the aspect of the display, normal/condensed (optional) +# @display enum ("normal, "condensed"), default is "normal". +# setInputLanguage(language) to set the language of the input (optional) +# @language enum ("English", "French"....) +# addField(type) to add an input field and setting its type +# @type (IP, string, number, dateUS, timeUS,dateInt, timeInt or empty) if the type is an empty string then the type is inherited from the main object. +# setFieldPassword(password) to set the password mode for the input field, overrides the value set by setPassword for the field +# @password enum ("yes", "no") +# setFieldEditable(editable) to set the input field editable mode ('yes', no'), overrides the value set by setEditable or setNotEditable for the field +# @editable enum ("yes", "no") +# setFieldParameter(parameter) to set the parameter name to be parsed after the global input, overrides the value set by setParameter for the field +# @parameter string +# setFieldPrompt(prompt)to set the prompt to be displayed for the input field, overrides the value set by setPrompt for the field +# @prompt string +# setFieldSelection(selection) to set the Selection tag for the field +# @selection string +# setFieldDefault(default) to set default value for the input field, overrides the value set by setDefault for the field +# @default string +# addFieldSoftkey(index,label,uri,icon) to add custom softkeys to the input field, overrides the softkeys set by addSoftkey. +# @index integer, softkey number +# @label string +# @uri string +# @icon integer, icon number +# +# Example 1 - Single Input +# require_once('AastraIPPhoneInputScreen.class.php'); +# $input = new AastraIPPhoneInputScreen(); +# $input->setTitle('Title'); +# $input->setPrompt('Enter your password'); +# $input->setParameter('param'); +# $input->setType('string'); +# $input->setURL('http://myserver.com/script.php'); +# $input->setPassword(); +# $input->setDestroyOnExit(); +# $input->setDefault('Default'); +# $input->output(); +# +# Example 2 - Multiple Inputs +# require_once('AastraIPPhoneInputScreen.class.php'); +# $input = new AastraIPPhoneInputScreen(); +# $input->setTitle('Example 2'); +# $input->setDisplayMode('condensed'); +# $input->setURL('http://myserver.com/script.php'); +# $input->setDestroyOnExit(); +# $input->addSoftkey('5', 'Done', 'SoftKey:Submit'); +# $input->addField('string'); +# $input->setFieldPrompt('Username:'); +# $input->setFieldParameter('user'); +# $input->addFieldSoftkey('3', 'ABC', 'SoftKey:ChangeMode'); +# $input->addField('number'); +# $input->setFieldPassword('yes'); +# $input->setFieldPrompt('Pass:'); +# $input->setFieldParameter('passwd'); +# $input->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneInputScreenEntry.class.php'); +require_once('AastraIPPhoneSoftkeyEntry.class.php'); + +class AastraIPPhoneInputScreen extends AastraIPPhone { + var $_url; + var $_type='string'; + var $_parameter; + var $_prompt; + var $_editable=''; + var $_default=''; + var $_password=''; + var $_defaultindex=''; + var $_displaymode=''; + var $_inputlanguage=''; + + function setURL($url) + { + $this->_url=$url; + } + function setType($type) + { + $this->_type=$type; + } + + function setEditable() + { + $this->_editable='no'; + } + + function setNotEditable() + { + $this->_editable='no'; + } + + function setDefault($default) + { + $this->_default=$default; + } + + function setParameter($parameter) + { + $this->_parameter=$parameter; + } + + function setPassword() + { + $this->_password='yes'; + } + + function setPrompt($prompt) + { + $this->_prompt=$prompt; + } + + function setDefaultIndex($index) + { + $this->_defaultindex=$index; + } + + function setDisplayMode($display) + { + $this->_displaymode=$display; + } + + function setInputLanguage($input) + { + $this->_inputlanguage=$input; + } + + function addField($type='') + { + $this->_entries[] = new AastraIPPhoneInputScreenEntry($type); + end($this->_entries); + } + + function setFieldType($type) + { + $this->_entries[key($this->_entries)]->_type=$type; + } + + function setFieldPassword($password='yes') + { + $this->_entries[key($this->_entries)]->_password=$password; + } + + function setFieldEditable($editable='yes') + { + $this->_entries[key($this->_entries)]->_editable=$editable; + } + + function setFieldParameter($parameter) + { + $this->_entries[key($this->_entries)]->_parameter=$parameter; + } + + function setFieldPrompt($prompt) + { + $this->_entries[key($this->_entries)]->_prompt=$this->escape($prompt); + } + + function setFieldDefault($default) + { + $this->_entries[key($this->_entries)]->_default=$default; + } + + function setFieldSelection($selection) + { + $this->_entries[key($this->_entries)]->_selection=$selection; + } + + function addFieldSoftkey($index, $label, $uri, $icon=NULL) + { + $this->_entries[key($this->_entries)]->_softkeys[] = new AastraIPPhoneSoftkeyEntry($index, $this->escape($label), $this->escape($uri), $icon); + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneInputScreen type=\"$this->_type\""; + + # Password + if($this->_password == 'yes') $out .= " password=\"yes\""; + + # DestroyOnExit + if($this->_destroyOnExit == 'yes') $out .= " destroyOnExit=\"yes\""; + + # CancelAction + if($this->_cancelAction != "") + { + $cancelAction = $this->escape($this->_cancelAction); + $out .= " cancelAction=\"{$cancelAction}\""; + } + + # Editable + if($this->_editable=='no') $out .= " editable=\"no\""; + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # DefaultIndex + if($this->_defaultindex!='') $out .= " defaultIndex=\"".$this->_defaultindex."\""; + + # InputLanguage + if($this->_inputlanguage!='') $out .= " inputLanguage=\"".$this->_inputlanguage."\""; + + # Display Mode + if($this->_displaymode!='') $out .= " displayMode=\"".$this->_displaymode."\""; + + # Lockin + if($this->_lockin!='') $out .= " LockIn=\"{$this->_lockin}\""; + + # AllowAnswer + if($this->_allowAnswer == 'yes') $out .= " allowAnswer=\"yes\""; + + # AllowDrop + if($this->_allowDrop == 'yes') $out .= " allowDrop=\"yes\""; + + # AllowXfer + if($this->_allowXfer == 'yes') $out .= " allowXfer=\"yes\""; + + # AllowConf + if($this->_allowConf == 'yes') $out .= " allowConf=\"yes\""; + + # TimeOut + if($this->_timeout!=0) $out .= " Timeout=\"{$this->_timeout}\""; + + # End of the root tag + $out .= ">\n"; + + + # Title + if ($this->_title!='') + { + $title = $this->escape($this->_title); + $out .= "<Title"; + if ($this->_title_wrap=='yes') $out .= " wrap=\"yes\""; + $out .= ">".$title."</Title>\n"; + } + + # Prompt + if($this->_prompt != '') + { + $prompt = $this->escape($this->_prompt); + $out .= "<Prompt>{$prompt}</Prompt>\n"; + } + + # URL + $url = $this->escape($this->_url); + $out .= "<URL>{$url}</URL>\n"; + + # Parameter + if($this->_parameter != '') $out .= "<Parameter>{$this->_parameter}</Parameter>\n"; + + # Default + $out .= "<Default>{$this->_default}</Default>\n"; + + # Multiple input fields + if (isset($this->_entries) && is_array($this->_entries)) + { + foreach ($this->_entries as $entry) $out .= $entry->render(); + } + + # Softkeys + if (isset($this->_softkeys) && is_array($this->_softkeys)) + { + foreach ($this->_softkeys as $softkey) $out .= $softkey->render(); + } + + # Icons + if (isset($this->_icons) && is_array($this->_icons)) + { + $IconList=False; + foreach ($this->_icons as $icon) + { + if(!$IconList) + { + $out .= "<IconList>\n"; + $IconList=True; + } + $out .= $icon->render(); + } + if($IconList) $out .= "</IconList>\n"; + } + + # End tag + $out .= "</AastraIPPhoneInputScreen>\n"; + return $out; + } +} +?> diff --git a/include/AastraIPPhoneInputScreenEntry.class.php b/include/AastraIPPhoneInputScreenEntry.class.php new file mode 100644 index 0000000..030031d --- /dev/null +++ b/include/AastraIPPhoneInputScreenEntry.class.php @@ -0,0 +1,42 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneInputScreenEntry +# Firmware 2.0 or better +# Copyright Aastra Telecom 2005-2010 +# +# Internal class for AastraIPPhoneInputScreen object. +################################################################################ + +class AastraIPPhoneInputScreenEntry { + var $_type=''; + var $_password=''; + var $_editable=''; + var $_parameter=''; + var $_prompt=''; + var $_default=''; + var $_selection=''; + var $_softkeys; + + function AastraIPPhoneInputScreenEntry($type) + { + $this->_type = $type; + $this->_softkeys = array(); + } + + function render() + { + $xml = "<InputField"; + if($this->_type != '') $xml .= " type=\"".$this->_type."\""; + if($this->_password != '') $xml .= " password=\"".$this->_password."\""; + if($this->_editable != '') $xml .= " editable=\"".$this->_editable."\""; + $xml .= ">\n"; + if($this->_prompt != '') $xml .= "<Prompt>".$this->_prompt."</Prompt>\n"; + if($this->_parameter != '') $xml .= "<Parameter>".$this->_parameter."</Parameter>\n"; + if($this->_selection != '') $xml .= "<Selection>".$this->_selection."</Selection>\n"; + if($this->_default != '') $xml .= "<Default>".$this->_default."</Default>\n"; + foreach ($this->_softkeys as $softkey) $xml .= $softkey->render(); + $xml .= "</InputField>\n"; + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneSPImage.class.php b/include/AastraIPPhoneSPImage.class.php new file mode 100644 index 0000000..9af1826 --- /dev/null +++ b/include/AastraIPPhoneSPImage.class.php @@ -0,0 +1,343 @@ +<?php +######################################################################################################### +# Aastra XML API Classes - Aastra XML API Classes - AastraIPPhoneSPImage +# Copyright Aastra Telecom 2009 +# +# Firmware 2.2.0 or better +# +# AastraIPPhoneSPImage for AastraIPPhoneImageScreen and AastraIPPhoneImageScreen. +# +# Public methods +# +# setText(text,line,align,offset) +# Writes text to the image using the system font +# text The text to be displayed, text can include %1%..%9% to include a custom icon as a +# character. +# line Line where the text will be displayed (1 to 5). +# align Text alignment in the line be 'left', 'right' or 'center'. 'left' is the default +# value. +# offset Offset in the alignment, not used for 'center'. +# +# addIcon(index,icon) +# Adds the definition of a custom icon as an hex string same as the regular phone icons. +# index Icon index (1 to 9) +# icon Hex string representing the icon +# +# setBitmap(bitmap,line,column) +# Writes a custom bitmap on the display +# bitmap Bitmap name 'answered' or 'unanswered' +# line/column Line/Column to display the bitmap +# +# Example +# require_once('AastraIPPhoneSPImage.class.php'); +# $SPimage->addIcon('1','286CEE6C2800'); +# $SPimage->setBitmap('answered',3,1); +# $SPimage->setText('Jean Valjean',1,'left',3); +# $SPimage->setText('9057604454',2,'left',3); +# $SPimage->setText('Sep 9 10:14am',4,'left',3); +# $SPimage->setText('Use #1# to browse',5,'center'); +######################################################################################################## + +######################################################################################################## +class AastraIPPhoneSPImage +{ + var $_matrix; + var $_icon; + +function setText($text,$line,$align='left',$offset='0') + { + # Remove some non supported accented characters + $text=strtr($text,"ŠŽšžŸ¥µÁÃÅÈËÌÍÐÑÒÓÔÕØÙÚÛÜÝãåìðòõøýÿ","SZszYYuAAAEEIIDNOOOOOUUUUYaaiooooyy"); + + # Check for icons in the text + $vars=preg_match_all('/\#\d+\#/',$text,$matches); + if($vars>0) + { + for ($i=1;$i<10; $i++) + { + $pattern="/\#$i\#/"; + $text=preg_replace($pattern,chr($i+20),$text); + } + } + + # Modify text for positioning + switch($align) + { + case 'left': + if($offset!='0') $text=str_pad($text,strlen($text)+$offset,' ',STR_PAD_LEFT); + break; + case 'right': + if($offset!='0') $text=str_pad($text,strlen($text)+$offset,' ',STR_PAD_RIGHT); + $text=str_pad($text,24,' ',STR_PAD_LEFT); + break; + case 'center': + $text=str_pad($text,24,' ',STR_PAD_BOTH); + break; + } + + # Store text + $len=strlen($text); + $row=$line-1; + if($row<5) + { + for($i=0;($i<$len) and ($i<24);$i++) + { + $char=substr($text,$i,1); + if($char!=' ') $this->_matrix[$row][$i]=$char; + } + } + } + +function addIcon($index,$icon) + { + for($i=0;$i<6;$i++) $array[$i]=substr($icon,$i*2,2); + $this->_icon[$index]=$array; + } + +function setBitmap($icon,$line,$column) + { + switch($icon) + { + case 'answered': + case 'unanswered': + case 'recording': + case 'paused': + for($i=0;$i<2;$i++) + { + for($j=0;$j<2;$j++) $this->_matrix[$line-1+$i][$column-1+$j]=$icon.$i.$j; + } + break; + case 'read': + case 'new': + case 'playing': + for($i=0;$i<2;$i++) + { + for($j=0;$j<3;$j++) $this->_matrix[$line-1+$i][$column-1+$j]=$icon.$i.$j; + } + break; + } + } + +function getSPImage() + { + # Characters + $letter[' ']=array('00','00','00','00','00','00'); + $letter['!']=array('00','00','f2','00','00','00'); + $letter[chr(34)]=array('00','e0','00','e0','00','00'); + $letter['#']=array('28','fe','28','fe','28','00'); + $letter['$']=array('24','54','d6','54','48','00'); + $letter['%']=array('c4','c8','10','26','46','00'); + $letter['&']=array('6c','92','aa','44','0a','00'); + $letter[chr(39)]=array('00','e0','00','00','00','00'); + $letter['(']=array('38','44','82','00','00','00'); + $letter[')']=array('82','44','38','00','00','00'); + $letter['*']=array('28','10','7c','10','28','00'); + $letter['+']=array('10','10','7c','10','10','00'); + $letter[',']=array('00','0a','0c','00','00','00'); + $letter['-']=array('10','10','10','10','10','00'); + $letter['.']=array('00','06','06','00','00','00'); + $letter['/']=array('04','08','10','20','40','00'); + $letter['0']=array('7c','8a','92','a2','7c','00'); + $letter['1']=array('00','42','fe','02','00','00'); + $letter['2']=array('42','86','8a','92','62','00'); + $letter['3']=array('84','82','a2','d2','8c','00'); + $letter['4']=array('18','28','48','fe','08','00'); + $letter['5']=array('e4','a2','a2','a2','9c','00'); + $letter['6']=array('3c','52','92','92','0c','00'); + $letter['7']=array('80','8e','90','a0','c0','00'); + $letter['8']=array('6c','92','92','92','6c','00'); + $letter['9']=array('60','92','92','94','78','00'); + $letter[':']=array('00','6c','6c','00','00','00'); + $letter[';']=array('00','6a','6c','00','00','00'); + $letter['<']=array('10','28','44','82','00','00'); + $letter['=']=array('28','28','28','28','28','00'); + $letter['>']=array('82','44','28','10','00','00'); + $letter['?']=array('40','80','8a','90','60','00'); + $letter['@']=array('4c','92','9e','82','7c','00'); + $letter['A']=array('7e','88','88','88','7e','00'); + $letter['B']=array('fe','92','92','92','6c','00'); + $letter['C']=array('7c','82','82','82','44','00'); + $letter['D']=array('fe','82','82','44','38','00'); + $letter['E']=array('fe','92','92','92','82','00'); + $letter['F']=array('fe','90','90','90','80','00'); + $letter['G']=array('7c','82','92','92','5e','00'); + $letter['H']=array('fe','10','10','10','fe','00'); + $letter['I']=array('00','82','fe','82','00','00'); + $letter['J']=array('04','02','82','fc','80','00'); + $letter['K']=array('fe','10','28','44','82','00'); + $letter['L']=array('fe','02','02','02','02','00'); + $letter['M']=array('fe','40','30','40','fe','00'); + $letter['N']=array('fe','20','10','08','fe','00'); + $letter['O']=array('7c','82','82','82','7c','00'); + $letter['P']=array('fe','90','90','90','60','00'); + $letter['Q']=array('7c','82','8a','84','7a','00'); + $letter['R']=array('fe','90','98','94','62','00'); + $letter['S']=array('62','92','92','92','8c','00'); + $letter['T']=array('80','80','fe','80','80','00'); + $letter['U']=array('fc','02','02','02','fc','00'); + $letter['V']=array('f8','04','02','04','f8','00'); + $letter['W']=array('fc','02','1c','02','fc','00'); + $letter['X']=array('c6','28','10','28','c6','00'); + $letter['Y']=array('e0','10','0e','10','e0','00'); + $letter['Z']=array('86','8a','92','a2','c2','00'); + $letter['[']=array('fe','82','82','00','00','00'); + $letter["\\"]=array('40','20','10','08','04','00'); + $letter[']']=array('82','82','fe','00','00','00'); + $letter['^']=array('20','40','80','40','20','00'); + $letter['_']=array('01','01','01','01','01','00'); + $letter['`']=array('00','00','80','00','00','00'); + $letter['a']=array('04','2a','2a','2a','1e','00'); + $letter['b']=array('fe','12','22','22','1c','00'); + $letter['c']=array('1c','22','22','22','04','00'); + $letter['d']=array('1c','22','22','12','fe','00'); + $letter['e']=array('1c','2a','2a','2a','18','00'); + $letter['f']=array('10','7e','90','80','40','00'); + $letter['g']=array('30','4a','4a','4a','7c','00'); + $letter['h']=array('fe','10','20','20','1e','00'); + $letter['i']=array('00','22','be','02','00','00'); + $letter['j']=array('04','02','22','bc','00','00'); + $letter['k']=array('fe','08','14','22','00','00'); + $letter['l']=array('00','82','fe','02','00','00'); + $letter['m']=array('3e','20','18','20','1e','00'); + $letter['n']=array('3e','10','20','20','1e','00'); + $letter['o']=array('1c','22','22','22','1c','00'); + $letter['p']=array('3e','28','28','28','10','00'); + $letter['q']=array('10','28','28','18','3e','00'); + $letter['r']=array('3e','10','20','20','10','00'); + $letter['s']=array('12','2a','2a','2a','04','00'); + $letter['t']=array('20','fc','22','02','04','00'); + $letter['u']=array('3c','02','02','04','3e','00'); + $letter['v']=array('38','04','02','04','38','00'); + $letter['w']=array('3c','02','0c','02','3c','00'); + $letter['x']=array('22','14','08','14','22','00'); + $letter['y']=array('30','0a','0a','0a','3c','00'); + $letter['z']=array('22','26','2a','32','22','00'); + $letter['{']=array('10','6c','82','00','00','00'); + $letter['|']=array('fe','00','00','00','00','00'); + $letter['}']=array('82','6c','10','00','00','00'); + $letter['~']=array('08','10','10','08','08','10'); + + # Some common accented characters for French Spanish and German + $letter['À']=array('1e','a4','64','24','1e','00'); + $letter['Â']=array('1e','64','a4','64','1e','00'); + $letter['â']=array('04','6a','aa','6a','1e','00'); + $letter['à']=array('04','aa','6a','2a','1e','00'); + $letter['æ']=array('24','2a','1e','2a','1a','00'); + $letter['Æ']=array('7e','90','fe','92','92','00'); + $letter['Ç']=array('7c','83','83','82','44','00'); + $letter['ç']=array('1c','22','23','23','22','00'); + $letter['É']=array('3e','2a','6a','aa','22','00'); + $letter['Ê']=array('3e','6a','aa','6a','22','00'); + $letter['é']=array('1c','2a','6a','aa','18','00'); + $letter['ê']=array('1c','6a','aa','6a','18','00'); + $letter['è']=array('1c','aa','6a','2a','18','00'); + $letter['ë']=array('1c','aa','2a','aa','18','00'); + $letter['Î']=array('00','62','be','62','00','00'); + $letter['î']=array('00','52','9e','42','00','00'); + $letter['ï']=array('00','a2','3e','82','00','00'); + $letter['ô']=array('0c','52','92','52','0c','00'); + $letter['Œ']=array('7c','82','fe','92','92','00'); + $letter['œ']=array('1c','22','1e','2a','1a','00'); + $letter['û']=array('1c','42','82','44','1e','00'); + $letter['ù']=array('3c','82','42','04','3e','00'); + $letter['ü']=array('3c','82','02','84','3e','00'); + $letter['á']=array('04','2a','6a','aa','1e','00'); + $letter['í']=array('00','12','5e','82','00','00'); + $letter['ó']=array('0c','12','52','92','0C','00'); + $letter['ú']=array('3c','02','42','84','3E','00'); + $letter['¿']=array('0c','12','a2','02','04','00'); + $letter['¡']=array('00','00','be','00','00','00'); + $letter['ñ']=array('5e','88','50','50','8E','00'); + $letter['ß']=array('7e','90','92','92','6c','00'); + $letter['Ü']=array('3c','82','02','82','3c','00'); + $letter['Ö']=array('1c','a2','22','a2','1c','00'); + $letter['ö']=array('0c','92','12','92','0c','00'); + $letter['Ä']=array('1e','a4','24','a4','1e','00'); + $letter['ä']=array('04','aa','2a','aa','1e','00'); + + # Custom Icons + for($i=1;$i<10;$i++) + { + if($this->_icon[$i]) $letter[chr(20+$i)]=$this->_icon[$i]; + } + + # Bitmap 'answered' + $letter['answered00']=array('ff','c3','c3','00','00','03'); + $letter['answered01']=array('03','03','00','00','00','00'); + $letter['answered10']=array('00','00','30','70','f0','f0'); + $letter['answered11']=array('f0','f0','f0','70','30','00'); + + # Bitmap 'unanswered' + $letter['unanswered00']=array('00','00','0e','0e','08','0b'); + $letter['unanswered01']=array('0b','0b','08','0e','0e','00'); + $letter['unanswered10']=array('00','00','30','70','f0','f0'); + $letter['unanswered11']=array('f0','f0','f0','70','30','00'); + + # Bitmap 'recording' + $letter['recording00']=array('00','02','03','00','7f','ea'); + $letter['recording01']=array('d5','ea','7f','00','03','02'); + $letter['recording10']=array('00','00','e0','10','c8','e9'); + $letter['recording11']=array('6f','e9','c8','10','e0','00'); + + # Bitmap 'paused' + $letter['paused00']=array('1f','18','18','03','07','0f'); + $letter['paused01']=array('0c','0f','0c','0f','07','03'); + $letter['paused10']=array('fc','0c','0c','e0','f0','f8'); + $letter['paused11']=array('18','f8','18','f8','f0','e0'); + + # Bitmap 'new' + $letter['new00']=array('00','00','00','03','03','02'); + $letter['new01']=array('02','02','02','02','02','02'); + $letter['new02']=array('02','03','03','00','00','00'); + $letter['new10']=array('00','00','00','fe','06','8a'); + $letter['new11']=array('52','22','12','12','22','52'); + $letter['new12']=array('8a','06','fe','00','00','00'); + + # Bitmap 'read' + $letter['read00']=array('00','00','00','03','05','08'); + $letter['read01']=array('10','20','20','20','20','10'); + $letter['read02']=array('08','05','03','00','00','00'); + $letter['read10']=array('00','00','00','fe','06','8a'); + $letter['read11']=array('52','22','22','22','22','52'); + $letter['read12']=array('8a','06','fe','00','00','00'); + + # Bimap 'playing' + $letter['playing00']=array('00','00','00','ff','c3','c3'); + $letter['playing01']=array('00','28','11','45','38','82'); + $letter['playing02']=array('7c','00','00','00','00','00'); + $letter['playing10']=array('00','00','00','00','00','30'); + $letter['playing11']=array('70','f0','f0','f0','f0','70'); + $letter['playing12']=array('30','00','00','00','00','00'); + + # Transform matrix into graphic + for($i=0;$i<5;$i++) $image[$i]=array_fill(0,144,'00'); + + foreach($this->_matrix as $i=>$value1) + { + foreach($value1 as $j=>$value2) + { + $index=$j*6; + if($letter[$value2]) + { + $image[$i][$index]=$letter[$value2][0]; + $image[$i][$index+1]=$letter[$value2][1]; + $image[$i][$index+2]=$letter[$value2][2]; + $image[$i][$index+3]=$letter[$value2][3]; + $image[$i][$index+4]=$letter[$value2][4]; + $image[$i][$index+5]=$letter[$value2][5]; + } + } + } + + # Prepare output + $output=''; + for($i=0;$i<144;$i++) + { + for($j=0;$j<5;$j++) $output.=$image[$j][$i]; + } + + # Return image + return $output; + } +} +?>
\ No newline at end of file diff --git a/include/AastraIPPhoneScrollHandler.php b/include/AastraIPPhoneScrollHandler.php new file mode 100644 index 0000000..f9da102 --- /dev/null +++ b/include/AastraIPPhoneScrollHandler.php @@ -0,0 +1,69 @@ +<?php +############################################################################# +# AastraIPPhoneScrollHandler +# +# Copyright 2009 Aastra Telecom Ltd +# +# Note +# This script is a helper script of the AastraIPPhoneScrollableTextMenu +# and AastraIPPhoneScrollableDirectory class. It should only be called +# by those classes. +# +############################################################################# + +############################################################################# +# PHP customization for includes and warnings +############################################################################# +$os = strtolower(PHP_OS); +if(strpos($os, "win") === false) ini_set('include_path',ini_get('include_path').':include:../include'); +else ini_set('include_path',ini_get('include_path').';include;..\include'); +error_reporting(E_ERROR | E_WARNING | E_PARSE); + +############################################################################# +# Includes +############################################################################# +require_once('AastraCommon.php'); +require_once('AastraIPPhoneTextScreen.class.php'); +require_once('AastraIPPhoneScrollableTextMenu.class.php'); +require_once('AastraIPPhoneScrollableDirectory.class.php'); + +$cookie = Aastra_getvar_safe('listCookie'); +$page = Aastra_getvar_safe('listPage'); +$zoomIndex = Aastra_getvar_safe('zoomIndex'); +$recentSelection = Aastra_getvar_safe('recentSelection'); +$recentPage = Aastra_getvar_safe('recentPage'); + +Aastra_trace_call('LDAP directory',$_SERVER['REQUEST_URI']); + +# Get Language and HTTP header +$language = Aastra_get_language(); +$header = Aastra_decode_HTTP_header(); + +# Load user context +$menu = Aastra_get_user_context($header['mac'],'scrollableTextMenuData'); + +if (!is_object($menu)) { + # If not an object: Something went wrong when fetching the user context. Display error and exit. + $object = new AastraIPPhoneTextScreen(); + $object->setTitle(Aastra_get_label('Server error',$language)); + $object->setText(Aastra_get_label('Context not found. Check cache directory settings.',$language)); + $object->output(); + exit; +} + +if (!$menu->verifyCookie($cookie)) { + # If cookie does not match: Display error and exit. + $object = new AastraIPPhoneTextScreen(); + $object->setTitle(Aastra_get_label('Server error',$language)); + $object->setText(Aastra_get_label('Session not found. Please try again.',$language)); + $object->output(); + exit; +} + +if ($recentSelection != "") $menu->setDefaultIndex($recentSelection); + +if ($zoomIndex != "") $menu->zoom($zoomIndex,$recentPage,$recentSelection); # This means $object is of type AastraIPPhoneScrollableDirectory + else $menu->output($page); +exit; + +?>
\ No newline at end of file diff --git a/include/AastraIPPhoneScrollableDirectory.class.php b/include/AastraIPPhoneScrollableDirectory.class.php new file mode 100644 index 0000000..a8ea998 --- /dev/null +++ b/include/AastraIPPhoneScrollableDirectory.class.php @@ -0,0 +1,340 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneScrollableDirectory +# +# Aastra SIP Phones 1.4.2 or better +# +# Copyright 2009 Aastra Telecom Ltd +# +# Supported Aastra Phones +# All IP phones except Aastra9112i and Aastra9133i +# +# AastraIPPhoneScrollableDirectory object. +# +# Public methods +# setDialKeyPosition(position) Set position of Dial Softkey in list view. Default is 2. +# setNameDisplayFormat(format) Set name display format. 0="Firstname Lastname", 1="Lastname, Firstname" +# natsortByLastname() Sort by lastname (same as natsortByName in case firstname is not provided) +# natsortByFirstname() Sort by firstname (same as natsortByName in case firstname is not provided) +# +# Overwritten methods from AastraIPPhoneScrollableTextMenu +# setEntries(records) Set directory entries by 2 dim array. Inner array fields: See addEntry(record) +# addEntry(record) Add directory entry +# Array fields: (name is mandatory, rest optional) +# name: Lastname or name +# firstname: Firstname (optional) +# title: Title +# department: Department +# company: Company +# icon: Icon +# office: Office number display format +# officeDigits: Office number digits / extension to be dialed. Optional +# mobile: Cell number display format +# mobileDigits: Cell number digits / extension to be dialed. Optional +# home: Home number display format +# homeDigits: Home number digits / extension to be dialed. Optional +# office2: Alternative / 2nd office number display format +# office2Digits: 2nd office number digits / extension to be dialed. Optional +# speedURL: If this field is present, a "+Speed" Softkey will be shown in zoom mode. Selected number will be passed in $selection variable. +# Ex: speedURL=http://xmlserver/xml/speed/speed.php?action=add&name=Peter +# +# Inherited from AastraIPPhoneScrollableTextMenu +# setEntries(entries) Set entries of the list by an 2 dim array. Inner array field names: 'name', 'url', 'selection', 'icon', 'dial' +# verifyCookie(cookie) Verifies if the cookie of the HTTP requests matches the cookie of the saved context. +# setBackURI(URI) Set the cancel parameter with the URI to be called on Cancel or Back Softkey (optional) +# setBackKeyPosition(position) Set position of Back Softkey. Default is 3. +# setNextKeyPosition(position) Set position of Back Softkey. Default is 4. +# setPreviousKeyPosition(position) Set position of Back Softkey. Default is 5. +# setExitKeyPosition(position) Set position of Back Softkey. Default is 6. +# setSelectKeyPosition(position) Set position of Back Softkey. Default is 1. +# setNextKeyIcon(icon) Set icon of Next Softkey. Default is Icon:TailArrowDown. Set NULL to disable icon. +# setPreviousKeyIcon(icon) Set icon of Previous Softkey. Default is Icon:TailArrowUp. Set NULL to disable icon. +# disableExitKey() Disable the Exit Softkey +# setSelectKeyLabel(label) Set the label of the Select Softkey. Default is 'Select'. Make sure the string is in language.ini. +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel or Back Softkey (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# output() to display the object +# addEntry(name,url,selection,icon,dial) to add an element in the list to be displayed +# natsortbyname() to order the list +# +# Example: +# $records[0]['name'] = "Smith"; +# $records[0]['firstname'] = "Lisa"; +# $records[0]['office'] = "+1 (0) 555-123-4321"; +# $records[0]['officeDigits'] = "4321"; +# $records[0]['mobile'] = "079 555 12 34"; +# # ... add as many entries you want +# $records[99]['name'] = "Miller"; +# $records[99]['firstname'] = "Bob"; +# $records[99]['office'] = "+1 (0) 555-123-1234"; +# $records[99]['officeDigits'] = "1234"; +# $records[99]['home'] = "044 555 22 33"; +# $records[99]['company'] = "Aastra Telecom Inc."; +# $directory = new AastraIPPhoneScrollableDirectory(); +# $directory->setTitle('Directory'); +# $directory->setBackURI($XML_SERVER."?action=start"); +# $directory->setEntries($records): +# $directory->output(); # Page scrolling and record zooming will be handled by AastraIPPhoneScrollableTextMenu +######################################################################################################## + +require_once('AastraIPPhoneScrollableTextMenu.class.php'); + +class AastraIPPhoneScrollableDirectory extends AastraIPPhoneScrollableTextMenu +{ + # Variables + var $_dialKeyPosition = 2; + var $_selectKeyLabel = 'Details'; + var $_index = 0; + var $_nameDisplayFormat = 0; # 0="Firstname Lastname", 1="Lastname, Firstname" + + # Constructor + function AastraIPPhoneScrollableDirectory() + { + # Set default style to "none" + $this->setStyle('none'); + + # Set default title + $this->setTitle(Aastra_get_label('Directory',$this->_language)); + + # Call parent constructor + parent::AastraIPPhoneScrollableTextMenu(); + } + + function addEntry($record) + { + # If no name or fistname provided, skip record + if (empty($record['name']) && empty($record['firstname'])) return; + + # Save lastname (needed if we want to sort by lastname) + $record['lastname'] = $record['name']; + + # Set display name + if ($this->_nameDisplayFormat==0) $record['name'] = trim((isset($record['firstname'])) ? $record['firstname'] . ' ' . $record['name'] : $record['name']); + else $record['name'] = trim((isset($record['firstname'])) ? $record['name'] . ', ' . $record['firstname'] : $record['name']); + + # If actual digits are not provided, use display format number. + if (empty($record['officeDigits'])) $record['officeDigits'] = $record['office']; + if (empty($record['mobileDigits'])) $record['mobileDigits'] = $record['mobile']; + if (empty($record['homeDigits'])) $record['homeDigits'] = $record['home']; + if (empty($record['office2Digits'])) $record['office2Digits'] = $record['office2']; + + # Remove non-numeric digits + $record['officeDigits'] = preg_replace('/[^0-9]/','',$record['officeDigits']); + $record['mobileDigits'] = preg_replace('/[^0-9]/','',$record['mobileDigits']); + $record['homeDigits'] = preg_replace('/[^0-9]/','',$record['homeDigits']); + $record['office2Digits'] = preg_replace('/[^0-9]/','',$record['office2Digits']); + + # Set instant dial number (to be dialed when hook is lifted in list view / when dial key is pressed in list view) + if (!empty($record['officeDigits'])) $record['dial'] = $record['officeDigits']; + else if (!empty($record['office2Digits'])) $record['dial'] = $record['office2Digits']; + else if (!empty($record['mobileDigits'])) $record['dial'] = $record['mobileDigits']; + else if (!empty($record['homeDigits'])) $record['dial'] = $record['homeDigits']; + $record['url'] = $this->_scrollHandlerReference.'&zoomIndex='.$this->_index; + + # We need to save the index as a field as the order of $this->_list can change after sorting + $record['index'] = $this->_index; + + # Add record to text menu list entries + $this->_list[$this->_index] = $record; + $this->_index++; + } + + function setEntries($records) + { + # Empty list? + if (empty($records)) return; + + # Clear list + $this->_list = array(); + foreach ($records as $record) $this->addEntry($record); + } + + function zoom($index, $recentPage, $recentSelection) + { + # Find record matching the given index + foreach ($this->_list as $record) + { + if ($record['index']==$index) + { + $myrecord = $record; + break; + } + } + + # Textmenu for the zoom + $menu = new AastraIPPhoneTextMenu(); + $menu->setDestroyOnExit(); + if (Aastra_is_style_textmenu_supported()) $menu->setStyle('none'); + if (Aastra_is_wrap_title_supported())$menu->setTitleWrap(); + if (Aastra_is_textmenu_wrapitem_supported()) $menu->setWrapList(); + $menu->setTitle($myrecord['name']); + + # Default Index + $defaultIndex = 1; + if(!empty($myrecord['title'])) + { + $menu->addEntry($myrecord['title'], NULL, NULL); + $defaultIndex++; + } + if(!empty($myrecord['department'])) + { + $menu->addEntry($myrecord['department'], NULL, NULL); + $defaultIndex++; + } + if(!empty($myrecord['company'])) + { + $menu->addEntry($myrecord['company'], NULL, NULL); + $defaultIndex++; + } + $menu->setDefaultIndex($defaultIndex); + + # If Dial2 softkey is supported, add 'Dial:' Prefix to URL (so number can be dialed by pressing right navigation key) + if (!Aastra_test_phone_version('2.0.1.',1)) $URLprefix = 'Dial:'; else $URLprefix = ''; + + # Office Number + if(!empty($myrecord['office'])) + { + if (Aastra_is_icons_supported()) + { + $iconIndex = 10; + $prompt=''; + } + else + { + $iconIndex = NULL; + $prompt=Aastra_get_label('(W)',$this->_language).' '; + } + if (!Aastra_test_phone_version('2.0.1.',1)) $menu->addEntry($prompt.$myrecord['office'], $URLprefix.$myrecord['officeDigits'], $myrecord['officeDigits'], $iconIndex, $myrecord['officeDigits']); + else $menu->addEntry($prompt.$myrecord['office'], $URLprefix.$myrecord['officeDigits'], $myrecord['officeDigits']); + } + + # Office 2 number + if(!empty($myrecord['office2'])) + { + if (Aastra_is_icons_supported()) + { + $iconIndex = 10; + $prompt=''; + } + else + { + $iconIndex = NULL; + $prompt=Aastra_get_label('(W)',$this->_language).' '; + } + if (!Aastra_test_phone_version('2.0.1.',1)) $menu->addEntry($prompt.$myrecord['office2'], $URLprefix.$myrecord['office2Digits'], $myrecord['officeDigits'], $iconIndex, $myrecord['office2Digits']); + else $menu->addEntry($prompt.$myrecord['office2'], $URLprefix.$myrecord['office2Digits'], $myrecord['officeDigits']); + } + + # Mobile number + if(!empty($myrecord['mobile'])) + { + if (Aastra_is_icons_supported()) + { + $iconIndex = 11; + $prompt=''; + } + else + { + $iconIndex = NULL; + $prompt=Aastra_get_label('(C)',$this->_language).' '; + } + if (!Aastra_test_phone_version('2.0.1.',1)) $menu->addEntry($prompt.$myrecord['mobile'], $URLprefix.$myrecord['mobileDigits'], $myrecord['officeDigits'], $iconIndex, $myrecord['mobileDigits']); + else $menu->addEntry($prompt.$myrecord['mobile'], $URLprefix.$myrecord['mobileDigits'], $myrecord['officeDigits']); + } + + # Home number + if(!empty($myrecord['home'])) + { + if (Aastra_is_icons_supported()) + { + $iconIndex = 12; + $prompt=''; + } + else + { + $iconIndex = NULL; + $prompt=Aastra_get_label('(H)',$this->_language).' '; + } + if (!Aastra_test_phone_version('2.0.1.',1)) $menu->addEntry($prompt.$myrecord['home'], $URLprefix.$myrecord['homeDigits'], $myrecord['officeDigits'], $iconIndex, $myrecord['homeDigits']); + else $menu->addEntry($prompt.$myrecord['home'], $URLprefix.$myrecord['homeDigits'], $myrecord['officeDigits']); + } + + # Softkeys + if (Aastra_is_softkeys_supported()) + { + if (Aastra_number_softkeys_supported()!=10) + { + # Regular phone with 6 softkeys + if (!Aastra_test_phone_version('2.0.1.',1)) $dialKeyType = 'SoftKey:Dial2'; + else $dialKeyType = 'SoftKey:Dial'; + $menu->addSoftkey(1, Aastra_get_label('Dial',$this->_language), $dialKeyType); + $menu->addSoftkey(3, Aastra_get_label('Back',$this->_language), $this->_scrollHandlerReference.'&listPage='.$recentPage.'&recentSelection='.$recentSelection); + $menu->addSoftkey(6, Aastra_get_label('Exit',$this->_language), 'SoftKey:Exit'); + + # Check if speed dial URL is set + if (isset($myrecord['speedURL'])) $menu->addSoftkey(4, Aastra_get_label('Add to Speed Dial',$this->_language), $myrecord['speedURL']); + } + else + { + # 6739i + $menu->addSoftkey(9, Aastra_get_label('Back',$this->_language), $this->_scrollHandlerReference.'&listPage='.$recentPage.'&recentSelection='.$recentSelection); + $menu->addSoftkey(10, Aastra_get_label('Exit',$this->_language), 'SoftKey:Exit'); + + # Check if speed dial URL is set + if (isset($myrecord['speedURL'])) $menu->addSoftkey(6, Aastra_get_label('+Speed',$this->_language), $myrecord['speedURL']); + } + } + + # Icons + if(Aastra_is_icons_supported()) + { + $menu->addIcon(10,Aastra_get_custom_icon('Office')); + $menu->addIcon(11,Aastra_get_custom_icon('Cellphone')); + $menu->addIcon(12,Aastra_get_custom_icon('Home')); + } + + # Cancel action + $menu->setCancelAction($this->_scrollHandlerReference.'&listPage='.$recentPage.'&recentSelection='.$recentSelection); + + # Display XML object + $menu->output(); + } + + function _setupSoftKeys() + { + # Check if softkeys and the Dial2 softkey is supported + if (Aastra_is_softkeys_supported() && !Aastra_test_phone_version('2.0.1.',1)) $this->addSoftkey($this->_dialKeyPosition, Aastra_get_label('Dial',$this->_language), 'SoftKey:Dial2'); + parent::_setupSoftKeys(); + } + + function setDialKeyPosition($position) + { + $this->_dialKeyPosition = $position; + } + + function setNameDisplayFormat($format) + { + $this->_nameDisplayFormat = $format; + } + + function natsortByLastname() + { + if (empty($this->_list)) return; + $tmpary = array(); + foreach ($this->_list as $id => $entry) $tmpary[$id] = $entry['lastname']; + natsort($tmpary); + foreach ($tmpary as $key => $valude) $new[] = $this->_list[$key]; + $this->_list = $new; + } + + function natsortByFirstname() + { + if (empty($this->_list)) return; + $tmpary = array(); + foreach ($this->_list as $id => $entry) $tmpary[$id] = $entry['firstname']; + natsort($tmpary); + foreach ($tmpary as $key => $valude) $new[] = $this->_list[$key]; + $this->_list = $new; + } +} +?>
\ No newline at end of file diff --git a/include/AastraIPPhoneScrollableTextMenu.class.php b/include/AastraIPPhoneScrollableTextMenu.class.php new file mode 100644 index 0000000..41229c1 --- /dev/null +++ b/include/AastraIPPhoneScrollableTextMenu.class.php @@ -0,0 +1,361 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneScrollableTextMenu +# +# Aastra SIP Phones 1.4.2 or better +# +# Copyright 2009-2010 Aastra Telecom Ltd +# +# Supported Aastra Phones +# All IP phones except Aastra9112i and Aastra9133i +# +# AastraIPPhoneScrollableTextMenu object. +# +# Public methods +# setEntries(entries) Set entries of the list by 2 dim array. Inner array field names: 'name', 'url', 'selection', 'icon', 'dial' +# verifyCookie(cookie) Verifies if the cookie of the HTTP requests matches the cookie of the saved context. +# setBackURI(URI) Set the cancel parameter with the URI to be called on Cancel or Back Softkey (optional) +# setBackKeyPosition(position) Set position of Back Softkey. Default is 3. +# setNextKeyPosition(position) Set position of Next Softkey. Default is 4. +# setPreviousKeyPosition(position) Set position of Previous Softkey. Default is 5. +# setExitKeyPosition(position) Set position of Back Softkey. Default is 6. +# setSelectKeyPosition(position) Set position of Back Softkey. Default is 1. +# setNextKeyIcon(icon) Set icon of Next Softkey. Default is Icon:TailArrowDown. Set NULL to disable icon. +# setPreviousKeyIcon(icon) Set icon of Previous Softkey. Default is Icon:TailArrowUp. Set NULL to disable icon. +# disableExitKey() Disable the Exit Softkey +# setSelectKeyLabel(label) Set the label of the Select Softkey. Default is 'Select'. Make sure the string is in language.ini. +# +# Overwritten methods from AastraIPPhoneTextMenu +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel or Back Softkey (optional) +# output() to display the object +# addEntry(name,url,selection,icon,dial) to add an element in the list to be displayed +# natsortbyname() to order the list +# +# Inherited from AastraIPPhoneTextMenu +# setTitle(Title) to setup the title of an object (optional) +# setTitleWrap() to set the title to be wrapped on 2 lines (optional) +# setDestroyOnExit() to set DestroyOnExit parameter to "yes" (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setAllowAnswer() to set the allowAnswer tag to 'yes' (optional) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# addSoftkey(index,label,uri,icon_index) to add custom softkeys to the object (optional) +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# generate() to return the object content +# setDefaultIndex(index) to set the default selection in the list (optional) +# setStyle(style) to set the style of the list numbered/none/radio (optional) +# setWrapList() to allow 2 lines items (optional) +# +# Example 1: +# $menu = new AastraIPPhoneScrollableTextMenu(); +# $menu->setTitle('My Menu'); +# $menu->addEntry('Choice 1', $XML_SERVER."?choice=1", '1'); +# # ... add as many entries you want +# $menu->addEntry('Choice 100', $XML_SERVER."?choice=100", '100'); +# $menu->output(); # Page scrolling will be handled by AastraIPPhoneScrollableTextMenu +# +# Example 2: +# $entries[0]['name'] = "Choice 1"; +# $entries[0]['url'] = $XML_SERVER."?choice=1"; +# $entries[0]['selection'] = "1"; +# # ... add as many entries you want +# $entries[99]['name'] = "Choice 100"; +# $entries[99]['url'] = $XML_SERVER."?choice=100"; +# $entries[99]['selection'] = "100"; +# $menu = new AastraIPPhoneScrollableTextMenu(); +# $menu->setTitle('My Menu'); +# $menu->setEntries($entries): +# $menu->output(); # Page scrolling will be handled by AastraIPPhoneScrollableTextMenu +# +######################################################################################################## +require_once('AastraCommon.php'); +require_once('AastraIPPhoneTextMenu.class.php'); + +class AastraIPPhoneScrollableTextMenu extends AastraIPPhoneTextMenu { + + var $_language; + var $_list = array(); # All entries of the list + var $_count = 0; # Total number of entries + var $_cookie; # Cookie - unique per AastraIPPhoneScrollableTextMenu instance + var $_header; + var $_scrollHandlerReference; + var $_backCancelURL; + var $_maxLines; + var $_exitKeyDisabled; + var $_selectKeyLabel = 'Select'; + var $_backKeyPosition = 3; + var $_exitKeyPosition = 6; + var $_selectKeyPosition = 1; + var $_nextKeyPosition = 4; + var $_previousKeyPosition = 5; + var $_nextKeyIconIndex = 11; + var $_previousKeyIconIndex = 12; + var $_nextKeyIcon = 'Icon:TailArrowDown'; + var $_previousKeyIcon = 'Icon:TailArrowUp'; + + # Constructor + function AastraIPPhoneScrollableTextMenu() + { + # Get Language + $this->_language = Aastra_get_language(); + + # Decode HTTP header + $this->_header = Aastra_decode_HTTP_header(); + + # Generate new cookie + $this->_cookie = $this->_generateCookie(); + + # Generate Scroll Handler reference + global $XML_HTTP, $AA_XML_SERVER, $AA_XMLDIRECTORY; + $this->_scrollHandlerReference = $XML_HTTP.$AA_XML_SERVER."/".$AA_XMLDIRECTORY."/include/AastraIPPhoneScrollHandler.php?listCookie=".$this->_cookie; + + # Calculate max linex + $this->_calculateMaxLines(); + + # Modify some values for 6739i + if(Aastra_number_softkeys_supported()==10) + { + $this->_backKeyPosition = 9; + $this->_exitKeyPosition = 10; + $this->_nextKeyPosition = 8; + $this->_previousKeyPosition = 3; + } + } + + function addEntry($name, $url, $selection=NULL, $icon=NULL, $dial=NULL) + { + $entry['name'] = $name; + $entry['url'] = $url; + $entry['selection'] = $selection; + $entry['icon'] = $icon; + $entry['dial'] = $dial; + $this->_list[] = $entry; + } + + function setEntries($entries) + { + $this->_list = $entries; + } + + function output($page=NULL) + { + # Test phone firmware / model + Aastra_test_phone_version('1.4.2.',0); + Aastra_test_phone_model(array('Aastra9112i','Aastra9133i'),False,0); + + # Force destroyOnExit + $this->_destroyOnExit = 'yes'; + + # Initial call? + if (!isset($page)) + { + # Count number of entries in list + $this->_count = count($this->_list); + + # Setup icons + $this->_setupIcons(); + + # Setup Softkeys + $this->_setupSoftKeys(); + + # Set Cancel URI + if (!empty($this->_backCancelURL)) parent::setCancelAction($this->_backCancelURL); + + # Do some security / compliancy checks + # Protect against wrap list bug in FW < R2.4.0 + if (Aastra_test_phone_version('2.4.0.',1)) $this->_wraplist = 'no'; + if (!Aastra_is_wrap_title_supported())$this->_wraplist = 'no'; + if (!Aastra_is_textmenu_wrapitem_supported()) $this->_title_wrap = 'no'; + if (!Aastra_is_style_textmenu_supported()) $this->_style = ''; + if (!Aastra_is_lockin_supported()) $this->_lockin = 'no'; + + # Save object in user context (context = mac address) + Aastra_save_user_context($this->_header['mac'],'scrollableTextMenuData',$this); + } + else + { + # If beep is set, only beep during initial call + $this->_beep='no'; + } + + # Generate the actual items of the menu for the given page + $this->_generatePage($page); + parent::output(); + } + + function _generatePage($page) + { + # Empty List protection (to avoid 'cannot display') + if ($this->_count==0) + { + $tmpEntry['name'] = '[NO ENTRIES]'; + $this->_list[] = $tmpEntry; + $this->_count++; + } + + # Calculate total number of pages + $last = ceil($this->_count / $this->_maxLines); + + # Invalid page protection + if (empty($page) or $page < 1) $page = 1; + if ($page > $last) $page = $last; + + # On phones without softkeys: Add dummy entry that allows to jump to previous page + if (!Aastra_is_softkeys_supported() && ($page > 1 && $last > 1)) $this->_entries[] = new AastraIPPhoneTextMenuEntry('['.Aastra_get_label('Previous Page',$this->_language).']', $this->_scrollHandlerReference.'&listPage='.($page-1), NULL, NULL, NULL, NULL,NULL); + + # Populate list for current page + for ($i = 0; ($i < $this->_maxLines and ($i + (($page - 1) * $this->_maxLines)) < $this->_count); $i++) + { + # Get entry from list + $tmpEntry = $this->_list[$i + (($page - 1) * $this->_maxLines)]; + + # Add 'recentSelection' and 'recentPage' attribute to URL of the entry. + # Allows to jump back to same page / selection + $tmpURI = $tmpEntry['url']; + + # Check if URI is an HTTP(S) URL (could also be an URI like Dial:1234) + if (preg_match('/^http/i',$tmpURI)) + { + # Check if URL already contains parameters + if (preg_match('/\?/',$tmpURI)) $tmpEntry['url'] = $tmpEntry['url'].'&recentSelection='.($i+1).'&recentPage='.$page; + else $tmpEntry['url'] = $tmpEntry['url'].'?recentSelection='.($i+1).'&recentPage='.$page; + } + + # Make sure we don't add menu items the phone firmware cannot handle + if (!Aastra_is_icons_supported()) $tmpEntry['icon'] = NULL; + if (Aastra_test_phone_version('2.0.1.',1)) $tmpEntry['dial'] = NULL; + $this->_entries[] = new AastraIPPhoneTextMenuEntry($tmpEntry['name'], $tmpEntry['url'], $tmpEntry['selection'], $tmpEntry['icon'], $tmpEntry['dial'], NULL, NULL); + } + + # On phones without softkeys: Add dummy entry that allows to jump to next page + if (!Aastra_is_softkeys_supported() && ($page < $last)) $this->_entries[] = new AastraIPPhoneTextMenuEntry('['.Aastra_get_label('Next Page',$this->_language).']', $this->_scrollHandlerReference.'&listPage='.($page+1), NULL, NULL, NULL, NULL,NULL); + + # On phones with softkeys:Add Next/Previous Softkeys + if(Aastra_is_softkeys_supported()) + { + if ($page < $last) + { + # Add Next key + if (Aastra_is_icons_supported() && !empty($this->_nextKeyIcon)) $this->addSoftkey($this->_nextKeyPosition, Aastra_get_label('Next',$this->_language), $this->_scrollHandlerReference.'&listPage='.($page+1), $this->_nextKeyIconIndex); + else $this->addSoftkey($this->_nextKeyPosition, Aastra_get_label('Next',$this->_language), $this->_scrollHandlerReference.'&listPage='.($page+1)); + } + if ($page > 1 && $last > 1) + { + # Add Previous key + if (Aastra_is_icons_supported() && !empty($this->_previousKeyIcon)) $this->addSoftkey($this->_previousKeyPosition, Aastra_get_label('Previous',$this->_language), $this->_scrollHandlerReference.'&listPage='.($page-1), $this->_previousKeyIconIndex); + else $this->addSoftkey($this->_previousKeyPosition, Aastra_get_label('Previous',$this->_language), $this->_scrollHandlerReference.'&listPage='.($page-1)); + } + } + + # Add page info to title + if ($last > 1) + { + # For phones with big screen + if (Aastra_is_softkeys_supported()) $this->_title = $this->_title.' ('.Aastra_get_label('Pg.',$this->_language).' '.$page.'/'.$last.')'; + # For 3 line phones + else $this->_title = $this->_title.' ('.$page.'/'.$last.')'; + } + } + + function _calculateMaxLines() + { + $this->_maxLines = Aastra_max_items_textmenu(); + if(!Aastra_is_softkeys_supported()) $this->_maxLines = $this->_maxLines - 2; + } + + function _setupIcons() + { + if (Aastra_is_icons_supported()) + { + $this->addIcon($this->_nextKeyIconIndex, $this->_nextKeyIcon); + $this->addIcon($this->_previousKeyIconIndex, $this->_previousKeyIcon); + } + } + + function _setupSoftKeys() + { + if (Aastra_is_softkeys_supported()) + { + $this->addSoftkey($this->_selectKeyPosition, Aastra_get_label($this->_selectKeyLabel,$this->_language), 'SoftKey:Select'); + if (!$this->_exitKeyDisabled) $this->addSoftkey($this->_exitKeyPosition, Aastra_get_label('Exit',$this->_language), 'SoftKey:Exit'); + if (!empty($this->_backCancelURL)) $this->addSoftkey($this->_backKeyPosition, Aastra_get_label('Back',$this->_language), $this->_backCancelURL); + } + } + + function _generateCookie() + { + return md5(time().rand()); + } + + function verifyCookie($cookie) + { + return ($this->_cookie == $cookie); + } + + function setBackURI($URI) + { + $this->_backCancelURL = $URI; + } + + function setBackKeyPosition($position) + { + $this->_backKeyPosition = $position; + } + + function setNextKeyPosition($position) + { + $this->_nextKeyPosition = $position; + } + + function setPreviousKeyPosition($position) + { + $this->_previousKeyPosition = $position; + } + + function setExitKeyPosition($position) + { + $this->_exitKeyPosition = $position; + } + + function setSelectKeyPosition($position) + { + $this->_selectKeyPosition = $position; + } + + function setNextKeyIcon($icon=NULL) + { + $this->_nextKeyIcon = $icon; + } + + function setPreviousKeyIcon($icon=NULL) + { + $this->_previousKeyIcon = $icon; + } + + function disableExitKey() + { + $this->_exitKeyDisabled = 1; + } + + function setSelectKeyLabel($label) + { + $this->_selectKeyLabel = $label; + } + + function setCancelAction($cancelAction) + { + $this->_backCancelURL = $cancelAction; + } + + function natsortByName() + { + if (empty($this->_list)) return; + $tmpary = array(); + foreach ($this->_list as $id => $entry) $tmpary[$id] = $entry['name']; + natsort($tmpary); + foreach ($tmpary as $key => $value) $new[] = $this->_list[$key]; + $this->_list = $new; + } +} + +?> diff --git a/include/AastraIPPhoneSoftkeyEntry.class.php b/include/AastraIPPhoneSoftkeyEntry.class.php new file mode 100644 index 0000000..e4f5701 --- /dev/null +++ b/include/AastraIPPhoneSoftkeyEntry.class.php @@ -0,0 +1,36 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneSoftkeyEntry +# Firmware 2.0 or better +# Copyright Aastra Telecom 2005-2010 +# +# Internal class for AastraIPPhone object. +################################################################################ + +class AastraIPPhoneSoftkeyEntry { + var $_index; + var $_label; + var $_uri; + var $_icon; + + function AastraIPPhoneSoftkeyEntry($index, $label, $uri, $icon) + { + $this->_index = $index; + $this->_label = $label; + $this->_uri = $uri; + $this->_icon = $icon; + } + + function render() + { + $index=$this->_index; + $xml = "<SoftKey index=\"".$index."\""; + if($this->_icon!=NULL) $xml.= " icon=\"".$this->_icon."\""; + $xml .= ">\n"; + $xml .= "<Label>".$this->_label."</Label>\n"; + $xml .= "<URI>".$this->_uri."</URI>\n"; + $xml .= "</SoftKey>\n"; + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneStatus.class.php b/include/AastraIPPhoneStatus.class.php new file mode 100644 index 0000000..2c7f965 --- /dev/null +++ b/include/AastraIPPhoneStatus.class.php @@ -0,0 +1,91 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneStatus +# Copyright Aastra Telecom 2006-2010 +# +# AastraIPPhoneStatus object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setBeep() to enable a notification beep with the object (optional) +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setSession(session) to setup the session ID +# @session string +# setTriggerDestroyOnExit() to set the triggerDestroyOnExit tag to "yes" (optional) +# addEntry(index,message,type,timeout) to add a message to be displayed on the idle screen. +# @index integer +# @message string +# @type enum ("alert") optional +# @timeout integer (seconds) optional +# +# Example +# require_once('AastraIPPhoneStatus.class.php'); +# $status = new AastraIPPhoneStatus(); +# $status->setSession('Session'); +# $status->setBeep(); +# $status->addEntry('1','Message 1','',0); +# $status->addEntry('2','Message 2','alert',5); +# $status->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneStatusEntry.class.php'); + +class AastraIPPhoneStatus extends AastraIPPhone { + var $_session; + var $_triggerDestroyOnExit=""; + + function setSession($session) + { + $this->_session=$session; + } + + function setTriggerDestroyOnExit() + { + $this->_triggerDestroyOnExit="yes"; + } + + function addEntry($index, $message, $type='', $timeout=NULL) + { + $this->_entries[] = new AastraIPPhoneStatusEntry($index, $message, $type, $timeout); + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneStatus"; + + # Beep + if($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # TriggerDestroyOnExit + if($this->_triggerDestroyOnExit=='yes') $out .= " triggerDestroyOnExit=\"yes\""; + + # End of root tag + $out .= ">\n"; + + # Session + $session = $this->escape($this->_session); + $out .= "<Session>".$session."</Session>\n"; + + # Status Items + if (isset($this->_entries) && is_array($this->_entries)) + { + foreach ($this->_entries as $entry) $out .= $entry->render(); + } + + # End tag + $out .= "</AastraIPPhoneStatus>\n"; + + # Return XML object + return($out); + } +} +?> diff --git a/include/AastraIPPhoneStatusEntry.class.php b/include/AastraIPPhoneStatusEntry.class.php new file mode 100644 index 0000000..c8947ef --- /dev/null +++ b/include/AastraIPPhoneStatusEntry.class.php @@ -0,0 +1,39 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneStatusEntry +# Copyright Aastra Telecom 2007-2010 +# +# Internal class for AastraIPPhoneStatus object. +################################################################################ + +class AastraIPPhoneStatusEntry extends AastraIPPhone { + var $_index; + var $_message; + var $_type=''; + var $_timeout=0; + + function AastraIPPhoneStatusEntry($index, $message, $type='', $timeout=NULL) + { + $this->_index = $index; + $this->_message = $this->convert_high_ascii($message); + $this->_type = $type; + $this->_timeout = $timeout; + } + + function render() + { + $index = $this->escape($this->_index); + $message = $this->escape($this->_message); + $type = $this->escape($this->_type); + $timeout = $this->_timeout; + $xml = "<Message index=\"{$index}\""; + if ($type!='') + { + $xml .= " type=\"{$type}\""; + if ($timeout!=NULL) $xml .= " Timeout=\"{$timeout}\""; + } + $xml .= ">{$message}</Message>\n"; + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneTextMenu.class.php b/include/AastraIPPhoneTextMenu.class.php new file mode 100644 index 0000000..a346d26 --- /dev/null +++ b/include/AastraIPPhoneTextMenu.class.php @@ -0,0 +1,269 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneTextMenu +# Copyright Aastra Telecom 2005-2010 +# +# AastraIPPhoneTextMenu object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setTitle(Title) to setup the title of an object (optional) +# @title string +# setTitleWrap() to set the title to be wrapped on 2 lines (optional) +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setLockInCall() to set the Lock-in tag to 'call' (optional) +# setAllowAnswer() to set the allowAnswer tag to 'yes' (optional only for non softkey phones) +# setAllowDrop() to set the allowDrop tag to 'yes' (optional only for non softkey phones) +# setAllowXfer() to set the allowXfer tag to 'yes' (optional only for non softkey phones) +# setAllowConf() to set the allowConf tag to 'yes' (optional only for non softkey phones) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setDefaultIndex(index) to set the default selection in the list (optional) +# @index index (1-30) +# setStyle(style) to set the style of the list (optional) +# @style enum (numbered/none/radio) +# setWrapList() to allow 2 lines items (optional) +# setScrollConstrain() to avoid the list to wrap +# setNumberLaunch() to allow number selection +# setBase(base) to configure the menuItem base URI +# @base string +# resetBase() to reset the menuItem base URI +# addEntry(name,url,selection,icon,dial,line) to add an element in the list to be displayed +# @name string or array(0=>Line1,1=>Line2,2=>Offset,3=>Char,4=>Mode) +# @url string +# @selection string +# @icon integer +# @dial string, phone number to dial +# @line integer, SIP line to use (optional) +# natsortbyname() to order the list, must not be use in conjunction with setBase or resetBase +# +# Example 1 +# require_once('AastraIPPhoneTextMenu.class.php'); +# $menu = new AastraIPPhoneTextMenu(); +# $menu->setTitle('Title'); +# $menu->setDestroyOnExit(); +# $menu->setDeFaultIndex('3'); +# $menu->addEntry('Choice 2', 'http://myserver.com/script.php?choice=2', 'Value=2'); +# $menu->addEntry('Choice 1', 'http://myserver.com/script.php?choice=1', 'Value=1'); +# $menu->addEntry('Choice 3', 'http://myserver.com/script.php?choice=3', 'Value=3'); +# $menu->natsortByName(); +# $menu->addSoftkey('1', 'My Select', 'http://myserver.com/script.php?action=1'); +# $menu->addSoftkey('6', 'Exit', 'SoftKey:Exit'); +# $menu->output(); +# +# Example 2 +# require_once('AastraIPPhoneTextMenu.class.php'); +# $menu = new AastraIPPhoneTextMenu(); +# $menu->setTitle('Title'); +# $menu->setDestroyOnExit(); +# $menu->setDeFaultIndex('2'); +# $menu->addEntry('Choice 2', 'http://myserver.com/script.php?choice=2', 'Value=2','1'); +# $menu->addEntry('Choice 1', 'http://myserver.com/script.php?choice=1', 'Value=1','2'); +# $menu->addEntry('Choice 3', 'http://myserver.com/script.php?choice=3', 'Value=3','3'); +# $menu->natsortByName(); +# $menu->addSoftkey('1', 'My Select', 'http://myserver.com/script.php?action=1'); +# $menu->addSoftkey('6', 'Exit', 'SoftKey:Exit'); +# $menu->addIcon('1', 'Icon:PhoneOnHook'); +# $menu->addIcon('2', 'Icon:PhoneOffHook'); +# $menu->addIcon('3', 'Icon:PhoneRinging'); +# $menu->output(); +# +######################################################################################################## +require_once('AastraIPPhone.class.php'); +require_once('AastraIPPhoneTextMenuEntry.class.php'); + +class AastraIPPhoneTextMenu extends AastraIPPhone { + var $_defaultIndex=''; + var $_style=''; + var $_wraplist=''; + var $_maxitems='30'; + var $_scrollConstrain=''; + var $_numberLaunch=''; + + function setDefaultIndex($defaultIndex) + { + $this->_defaultIndex = $defaultIndex; + } + + function setStyle($style) + { + $this->_style = $style; + } + + function addEntry($name, $url, $selection=NULL, $icon=NULL, $dial=NULL, $line=NULL) + { + $this->_entries[] = new AastraIPPhoneTextMenuEntry($name, $url, $selection, $icon, $dial, $line, NULL); + } + + function setBase($base) + { + $this->_entries[] = new AastraIPPhoneTextMenuEntry(NULL, NULL, NULL, NULL, NULL, NULL, $base); + } + + function resetBase() + { + $this->_entries[] = new AastraIPPhoneTextMenuEntry(NULL, NULL, NULL, NULL, NULL, NULL, 'AASTRA_RESETBASE'); + } + + function setWrapList() + { + $this->_wraplist = 'yes'; + } + + function setScrollConstrain() + { + $this->_scrollConstrain = 'yes'; + } + + function setNumberLaunch() + { + $this->_numberLaunch = 'yes'; + } + + function natsortByName() + { + $tmpary = array(); + foreach ($this->_entries as $id => $entry) $tmpary[$id] = $entry->getName(); + natsort($tmpary); + foreach ($tmpary as $id => $name) $newele[] = $this->_entries[$id]; + $this->_entries = $newele; + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneTextMenu"; + + # DestroyOnExit + if ($this->_destroyOnExit=='yes') $out .= " destroyOnExit=\"yes\""; + + # CancelAction + if($this->_cancelAction != "") + { + $cancelAction = $this->escape($this->_cancelAction); + $out .= " cancelAction=\"{$cancelAction}\""; + } + + # DefaultIndex + if ($this->_defaultIndex!="") $out .= " defaultIndex=\"{$this->_defaultIndex}\""; + + # Style + if ($this->_style!='') $out .= " style=\"{$this->_style}\""; + + # Beep + if ($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # Lockin + if($this->_lockin!='') $out .= " LockIn=\"{$this->_lockin}\""; + + # WrapList + if ($this->_wraplist=='yes') $out .= " wrapList=\"yes\""; + + # AllowAnswer + if ($this->_allowAnswer == 'yes') $out .= " allowAnswer=\"yes\""; + + # AllowDrop + if ($this->_allowDrop == 'yes') $out .= " allowDrop=\"yes\""; + + # AllowXfer + if ($this->_allowXfer == 'yes') $out .= " allowXfer=\"yes\""; + + # AllowConf + if ($this->_allowConf == 'yes') $out .= " allowConf=\"yes\""; + + # Timeout + if ($this->_timeout!=0) $out .= " Timeout=\"{$this->_timeout}\""; + + # Prevent list wrap + if ($this->_scrollConstrain == 'yes') $out .= " scrollConstrain=\"yes\""; + + # Number selection + if ($this->_numberLaunch == 'yes') $out .= " numberLaunch=\"yes\""; + + # End of root tag + $out .= ">\n"; + + # Title + if ($this->_title!='') + { + $title = $this->escape($this->_title); + $out .= "<Title"; + if ($this->_title_wrap=='yes') $out .= " wrap=\"yes\""; + $out .= ">".$title."</Title>\n"; + } + + # Menu items + if (isset($this->_entries) && is_array($this->_entries)) + { + $index=0; + $base=NULL; + $length=Aastra_size_display_line(); + $is_softkeys=Aastra_is_softkeys_supported(); + foreach ($this->_entries as $entry) + { + if($entry->getBase()!=NULL) $base=$entry->getBase(); + else + { + if($base!=NULL) + { + if($index<$this->_maxitems) $out .= $entry->render($this->_style,$length,$is_softkeys,$base); + $base=NULL; + } + else if($index<$this->_maxitems) $out .= $entry->render($this->_style,$length,$is_softkeys); + $index++; + } + } + } + + # Softkeys + if (isset($this->_softkeys) && is_array($this->_softkeys)) + { + foreach ($this->_softkeys as $softkey) $out .= $softkey->render(); + } + + # Icons + if (isset($this->_icons) && is_array($this->_icons)) + { + $IconList=False; + foreach ($this->_icons as $icon) + { + if(!$IconList) + { + $out .= "<IconList>\n"; + $IconList=True; + } + $out .= $icon->render(); + } + if($IconList) $out .= "</IconList>\n"; + } + + # End Tag + $out .= "</AastraIPPhoneTextMenu>\n"; + + # Return XML object + return($out); + } +} +?> diff --git a/include/AastraIPPhoneTextMenuEntry.class.php b/include/AastraIPPhoneTextMenuEntry.class.php new file mode 100644 index 0000000..e39914d --- /dev/null +++ b/include/AastraIPPhoneTextMenuEntry.class.php @@ -0,0 +1,150 @@ +<?php +################################################################################ +# Aastra XML API Classes - AastraIPPhoneTextMenuEntry +# Copyright Aastra Telecom 2005-2010 +# +# Internal class for AastraIPPhoneTextMenu object. +################################################################################ + +class AastraIPPhoneTextMenuEntry extends AastraIPPhone { + var $_name; + var $_url; + var $_selection; + var $_icon; + var $_dial; + var $_line; + var $_base; + + function AastraIPPhoneTextMenuEntry($name, $url, $selection, $icon, $dial, $line, $base) + { + $this->_name=$name; + $this->_url=$url; + $this->_selection=$selection; + $this->_icon=$icon; + $this->_dial=$dial; + $this->_line=$line; + $this->_base=$base; + } + + function getName() + { + return($this->_name); + } + + function getBase() + { + return($this->_base); + } + + function format_line($array_name,$style,$length,$is_softkeys) + { + # Retrieve parameters + $line1=$array_name[0]; + $line2=$array_name[1]; + $offset=$array_name[2]; + $char=$array_name[3]; + if($char==' ') $char=chr(0xa0); + $mode=$array_name[4]; + if($mode=='') $mode='left'; + + # Adjust with the style if softkey phone + if($is_softkeys) + { + switch($style) + { + case 'none': + case 'radio': + $length--; + break; + default: + $length-=4; + break; + } + } + + # Unbreakable space + $nbsp=chr(0xa0); + + # Pad the the first line with regular spaces + switch($mode) + { + case 'center': + $line=str_pad($line1,$length-1-$offset,$char,STR_PAD_BOTH); + break; + case 'right': + $line=str_pad($line1,$length-1-$offset,$char,STR_PAD_LEFT); + break; + default: + $line=str_pad($line1,$length-1-$offset,$char,STR_PAD_RIGHT); + break; + } + + # Crop the line to the correct length (-1 for wrap-space) + $line=substr($line,0,($length-1-$offset)); + + # Append a space so it can wrap to line two, and two non-break spaces to pad below the icon + if($line2!='') + { + $line.=' '.str_repeat($nbsp,$offset); + switch($mode) + { + case 'center': + if($char==chr(0xa0)) $line.=str_repeat($char,($length-$offset-strlen($line2))/2).$line2; + else $line.=str_pad($line2,$length-$offset-1,$char,STR_PAD_BOTH); + break; + case 'right': + $line.=str_repeat($char,$length-$offset-strlen($line2)+1).$line2; + break; + default: + $line.=$line2; + break; + } + } + + # Return formatted prompt + return($line); + } + + + function render($style,$length,$is_softkeys,$base=NULL) + { + # Opening + $base = $this->escape($base); + $xml = '<MenuItem'; + if($base!=NULL) + { + if($base!='AASTRA_RESETBASE') $xml .= " base=\"{$base}\""; + else $xml .= " base=\"\""; + } + if($this->_icon!=NULL) $xml .= " icon=\"{$this->_icon}\""; + $xml .= ">\n"; + + # Prompt + if(is_array($this->_name)) $name = $this->format_line($this->_name,$style,$length,$is_softkeys); + else $name = $this->_name; + $name = $this->escape($name); + $xml .= "<Prompt>{$name}</Prompt>\n"; + + # URI + $url = $this->escape($this->_url); + $xml .= "<URI>{$url}</URI>\n"; + + # Selection + $selection = $this->escape($this->_selection); + if($selection!=NULL) $xml .= "<Selection>{$selection}</Selection>\n"; + + # Dial + if($this->_dial!=NULL) + { + if($this->_line!=NULL) $xml .= "<Dial line=\"{$this->_line}\">{$this->_dial}</Dial>\n"; + else $xml .= "<Dial>{$this->_dial}</Dial>\n"; + } + + # Close + $xml .= '</MenuItem>'."\n"; + + # Return generated vaue + return($xml); + } +} +?> diff --git a/include/AastraIPPhoneTextScreen.class.php b/include/AastraIPPhoneTextScreen.class.php new file mode 100644 index 0000000..483811a --- /dev/null +++ b/include/AastraIPPhoneTextScreen.class.php @@ -0,0 +1,193 @@ +<?php +######################################################################################################## +# Aastra XML API Classes - AastraIPPhoneTextScreen +# Copyright Aastra Telecom 2005-2010 +# +# AastraIPPhoneTextScreen object. +# +# Public methods +# +# Inherited from AastraIPPhone +# setTitle(Title) to setup the title of an object (optional) +# @title string +# setTitleWrap() to set the title to be wrapped on 2 lines (optional) +# setCancelAction(uri) to set the cancel parameter with the URI to be called on Cancel (optional) +# @uri string +# setDestroyOnExit() to set DestroyonExit parameter to 'yes', 'no' by default (optional) +# setBeep() to enable a notification beep with the object (optional) +# setLockIn() to set the Lock-in tag to 'yes' (optional) +# setLockInCall() to set the Lock-in tag to 'call' (optional) +# setAllowAnswer() to set the allowAnswer tag to 'yes' (optional only for non softkey phones) +# setAllowDrop() to set the allowDrop tag to 'yes' (optional only for non softkey phones) +# setAllowXfer() to set the allowXfer tag to 'yes' (optional only for non softkey phones) +# setAllowConf() to set the allowConf tag to 'yes' (optional only for non softkey phones) +# setTimeout(timeout) to define a specific timeout for the XML object (optional) +# @timeout integer (seconds) +# addSoftkey(index,label,uri,icon_index) to add custom soktkeys to the object (optional) +# @index integer, softkey number +# @label string +# @uri string +# @icon_index integer, icon number +# setRefresh(timeout,URL) to add Refresh parameters to the object (optional) +# @timeout integer (seconds) +# @URL string +# setEncodingUTF8() to change encoding from default ISO-8859-1 to UTF-8 (optional) +# addIcon(index,icon) to add custom icons to the object (optional) +# @index integer, icon index +# @icon string, icon name or definition +# generate() to return the generated XML for the object +# output(flush) to display the object +# @flush boolean optional, output buffer to be flushed out or not. +# +# Specific to the object +# setText(text) to set the text to be displayed. +# @text string +# setDoneAction(uri) to set the URI to be called when the user selects the default "Done" key (optional) +# @uri string +# setAllowDTMF() to allow DTMF passthrough on the object +# setScrollUp(uri) to set the URI to be called when the user presses the Up arrow (optional) +# @uri string +# setScrollDown(uri) to set the URI to be called when the user presses the Down arrow (optional) +# @uri string +# setScrollLeft(uri) to set the URI to be called when the user presses the Left arrow (optional) +# @uri string +# setScrollRight(uri) to set the URI to be called when the user presses the Right arrow (optional) +# @uri string +# +# Example +# require_once('AastraIPPhoneTextScreen.class.php'); +# $text = new AastraIPPhoneTextScreen(); +# $text->setTitle('Title'); +# $text->setText('Text to be displayed.'); +# $text->setDestroyOnExit(); +# $text->addSoftkey('1', 'Mail', 'http://myserver.com/script.php?action=1','1'); +# $text->addSoftkey('6', 'Exit', 'SoftKey:Exit'); +# $text->addIcon('1', 'Icon:Envelope'); +# $text->output(); +# +######################################################################################################## + +require_once('AastraIPPhone.class.php'); + +class AastraIPPhoneTextScreen extends AastraIPPhone { + var $_text; + var $_doneAction=''; + var $_allowDTMF=''; + var $_scrollUp=''; + var $_scrollDown=''; + var $_scrollLeft=''; + var $_scrollRight=''; + + function setText($text) + { + $this->_text = $text; + } + + function setDoneAction($uri) + { + $this->_doneAction = $uri; + } + + function setAllowDTMF() + { + $this->_allowDTMF = 'yes'; + } + + function render() + { + # Beginning of root tag + $out = "<AastraIPPhoneTextScreen"; + + # DestroyOnExut + if($this->_destroyOnExit == 'yes') $out .= " destroyOnExit=\"yes\""; + + # CancelAction + if($this->_cancelAction != "") + { + $cancelAction = $this->escape($this->_cancelAction); + $out .= " cancelAction=\"{$cancelAction}\""; + } + + # DoneAction + if($this->_doneAction != "") + { + $doneAction = $this->escape($this->_doneAction); + $out .= " doneAction=\"{$doneAction}\""; + } + + # Beep + if ($this->_beep=='yes') $out .= " Beep=\"yes\""; + + # TimeOut + if ($this->_timeout!=0) $out .= " Timeout=\"{$this->_timeout}\""; + + # Lockin + if($this->_lockin!='') $out .= " LockIn=\"{$this->_lockin}\""; + + # AllowAnswer + if ($this->_allowAnswer == 'yes') $out .= " allowAnswer=\"yes\""; + + # AllowDrop + if ($this->_allowDrop == 'yes') $out .= " allowDrop=\"yes\""; + + # AllowXfer + if ($this->_allowXfer == 'yes') $out .= " allowXfer=\"yes\""; + + # AllowConf + if ($this->_allowConf == 'yes') $out .= " allowConf=\"yes\""; + + # AllowDTMF + if ($this->_allowDTMF=='yes') $out .= " allowDTMF=\"yes\""; + + # Scrolls up/down/left/right + if($this->_scrollUp!='') $out .= " scrollUp=\"".$this->escape($this->_scrollUp)."\""; + if($this->_scrollDown!='') $out .= " scrollDown=\"".$this->escape($this->_scrollDown)."\""; + if($this->_scrollLeft!='') $out .= " scrollLeft=\"".$this->escape($this->_scrollLeft)."\""; + if($this->_scrollRight!='') $out .= " scrollRight=\"".$this->escape($this->_scrollRight)."\""; + + # End of root tag + $out .= ">\n"; + + # Title + if ($this->_title!='') + { + $title = $this->escape($this->_title); + $out .= "<Title"; + if ($this->_title_wrap=='yes') $out .= " wrap=\"yes\""; + $out .= ">".$title."</Title>\n"; + } + + # Text + $text = $this->escape($this->_text); + $out .= "<Text>{$text}</Text>\n"; + + # Softkeys + if (isset($this->_softkeys) && is_array($this->_softkeys)) + { + foreach ($this->_softkeys as $softkey) $out .= $softkey->render(); + } + + # Icons + if (isset($this->_icons) && is_array($this->_icons)) + { + $IconList=False; + foreach ($this->_icons as $icon) + { + if(!$IconList) + { + $out .= "<IconList>\n"; + $IconList=True; + } + $out .= $icon->render(); + } + if($IconList) $out .= "</IconList>\n"; + } + + # End tag + $out .= "</AastraIPPhoneTextScreen>\n"; + + # Return XML object + return $out; + } +} +?> |