Skip to content

Instantly share code, notes, and snippets.

@mushon
Created June 1, 2011 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mushon/1001819 to your computer and use it in GitHub Desktop.
Save mushon/1001819 to your computer and use it in GitHub Desktop.
XML-RPC for the You Are Not Here project
<?php
//calls the PHP XML-RPC library we're using:
include('IXR_Library.inc.php');
define_syslog_variables();
openlog("[GAZA XML SERVER]", LOG_PID | LOG_PERROR, LOG_LOCAL2);
class SimpleServer extends IXR_Server {
function SimpleServer() {
$this->IXR_Server(array(
//Send the NewSession Method to the newSession function:
'NewSession' => 'this:newSession',
'didClassify' => 'this:classify',
'didVOrequest' => 'this:vo_request',
'didCheckInput' => 'this:check_input'
));
}
//first Call/Response
function newSession($args) {
$result = array('STATUS'=>(int)0);
//Return 0 - The request completed successfully.
return($result);
}
//Second Call/Response
function classify($args) {
//In my case in any way I want to return IVRACCESS & English so I just do that:
return(
array(
//status is 0:
'STATUS' => (int)0,
//classification is IVRACCESS:
'CLASSIFICATION' => 'IVRACCESS',
//language is English:
'LANGUAGE' => 'EN'
)
);
}
//Third Call/Response
function vo_request($args) {
//Check the time for time-based locations:
$localtime = localtime();
$hour = $localtime[2];
//If VO_ID is :
switch ($args['VO_ID']) {
case 0: $play = '0-welcome'; break;
//case 666666: $play = '0-sorry2'; break;
//test clips:
/*
case 1: $play = '1'; break;
case 2: $play = '2'; break;
case 3: $play = '3'; break;
case 4: $play = '4'; break;
case 5: $play = '5'; break;
case 6: $play = '6'; break;
case 7: $play = '7'; break;
case 8: $play = '8'; break;
case 9: $play = '9'; break;
case 10: $play = '10'; break;
case 11: $play = '11'; break;
case 12: $play = '12'; break;
case 13: $play = '13'; break;
case 14: $play = '14'; break;
case 15: $play = '15'; break;
case 16: $play = '16'; break;
case 17: $play = '17'; break;
case 18: $play = '18'; break;
case 19: $play = '19'; break;
case 20: $play = '20'; break;
*/
//real clips:
case 1: $play = '1-Barcelona_Park'; break;
case 2: $play = '2-Roots_Club'; break;
case 3: $play = '3-Duwar_Abu_Mazen'; break;
case 4: $play = '5-Gaza_harbor'; break;
case 5: $play = '4-Arts_and_Crafts_Village'; break;
case 6: $play = '6-Islamic_University'; break;
case 7: $play = '7-UNRWA'; break;
case 8: $play = '8-PLC'; break;
case 9: $play = '9-PLO_Flag_Shop'; break;
case 10: $play = '10-Rafah_Pickup'; break;
case 11: $play = '11-Palestine_Stadium'; break;
case 12: $play = '12-Jundi_il_Majhool'; break;
case 13: $play = '13-Kathems_Ice_Cream'; break;
case 14: $play = '14-Akeelas'; break;
case 15: $play = '15-Saraya_Prison'; break;
case 16: $play = '16-Qattan_Centre'; break;
case 17: $play = '17-Beach_camp'; break;
case 18: $play = '18-Great_Omari_Mosque'; break;
case 19: $play = '19-Qissayriya_Gold_Market'; break;
//if before 5pm- play 'women hours', else play 'men hours':
case 20:
switch($hour){
case($hour<17): $play = '20-Essamara_Baths-women'; break;
default; $play = '20-Essamara_Baths-men'; break;
}
break;
case 1000: $play = '0-bye'; break;
case 9999: $play = 'end'; break;
}
return(
array(
//status is 0:
'STATUS' => (int)0,
//Play the chosen audio file:
'RECORDING' => $play,
//The other two values can stay the default ones
'DTMFWAIT' => (int)3,
//The other two values can stay the default ones
'DTMFLOOP' => (int)1
)
);
}
//Fourth C/R
function check_input($args) {
//[where am I coming from] [what did I input] => [where am I going]
syslog(LOG_INFO,"GAZA: ".print_r($args,TRUE));
syslog(LOG_INFO,"VOID is of type: ".gettype($args['VO_ID']));
syslog(LOG_INFO,"USERINPUT is of type: ".gettype($args['USERINPUT']));
switch ($args['VO_ID']) {
case "0":
switch((int)$args['USERINPUT']) {
//Depending on user input, return the next location number (VO_ID)
//1
case "0001": $nextvoid='1'; break;
case "1382": $nextvoid='1'; break;
case "0271": $nextvoid='1'; break;
case "1185": $nextvoid='1'; break;
case "1383": $nextvoid='1'; break;
//2
case "0002": $nextvoid='2'; break;
case "0238": $nextvoid='2'; break;
case "0328": $nextvoid='2'; break;
//3
case "0003": $nextvoid='3'; break;
case "2136": $nextvoid='3'; break;
case "1373": $nextvoid='3'; break;
case "0073": $nextvoid='3'; break;
//4
case "0004": $nextvoid='4'; break;
case "0045": $nextvoid='4'; break;
case ($args['USERINPUT']>=142 && $args['USERINPUT']<=150): $nextvoid='4'; break;
case ($args['USERINPUT']>=135 && $args['USERINPUT']<=139): $nextvoid='4'; break;
//5
case "0005": $nextvoid='5'; break;
case "0182": $nextvoid='5'; break;
//6
case "0006": $nextvoid='6'; break;
case "1079": $nextvoid='6'; break;
case "1424": $nextvoid='6'; break;
case "1423": $nextvoid='6'; break;
//7
case "0007": $nextvoid='7'; break;
case "0920": $nextvoid='7'; break;
case "1452": $nextvoid='7'; break;
case "1453": $nextvoid='7'; break;
//8
case "0008": $nextvoid='8'; break;
case "2590": $nextvoid='8'; break;
case "2589": $nextvoid='8'; break;
case "2588": $nextvoid='8'; break;
case "2587": $nextvoid='8'; break;
case "2586": $nextvoid='8'; break;
case "9053": $nextvoid='8'; break;
case "1235": $nextvoid='8'; break;
//9
case "0009": $nextvoid='9'; break;
case "3229": $nextvoid='9'; break;
//10
case "0010": $nextvoid='10'; break;
case "6680": $nextvoid='10'; break;
case "4075": $nextvoid='10'; break;
//11
case "0011": $nextvoid='11'; break;
case "6408": $nextvoid='11'; break;
//12
case "0012": $nextvoid='12'; break;
case "2624": $nextvoid='12'; break;
case "2592": $nextvoid='12'; break;
case "2692": $nextvoid='12'; break;
case "2625": $nextvoid='12'; break;
case "2655": $nextvoid='12'; break;
case "2636": $nextvoid='12'; break;
//13
case "0013": $nextvoid='13'; break;
case "3084": $nextvoid='13'; break;
//14
case "0014": $nextvoid='14'; break;
case ($args['USERINPUT']>=500 && $args['USERINPUT']<=510): $nextvoid='14'; break;
//15
case "0015": $nextvoid='15'; break;
case ($args['USERINPUT']>=9500 && $args['USERINPUT']<=9510): $nextvoid='15'; break;
//16
case "0016": $nextvoid='16'; break;
case "0140": $nextvoid='16'; break;
case "0141": $nextvoid='16'; break;
//17
case "0017": $nextvoid='17'; break;
case "2094": $nextvoid='17'; break;
case "2042": $nextvoid='17'; break;
case ($args['USERINPUT']>=20420 && $args['USERINPUT']<=20430): $nextvoid='17'; break;
//18
case "0018": $nextvoid='18'; break;
case "9537": $nextvoid='18'; break;
case "9534": $nextvoid='18'; break;
case "9535": $nextvoid='18'; break;
case "9483": $nextvoid='18'; break;
case "9482": $nextvoid='18'; break;
case "9528": $nextvoid='18'; break;
//19
case "0019": $nextvoid='19'; break;
case "9547": $nextvoid='19'; break;
case "2064": $nextvoid='19'; break;
case "9546": $nextvoid='19'; break;
case "9545": $nextvoid='19'; break;
case "9549": $nextvoid='19'; break;
//20
case "0020": $nextvoid='20'; break;
case "5880": $nextvoid='20'; break;
case "1038": $nextvoid='20'; break;
case "9751": $nextvoid='20'; break;
default:
$nextvoid='0';
break;
}
break;
case "20":
switch($args['USERINPUT']) {
case "0000":
$nextvoid='1000';
break;
default:
$nextvoid='1000';
break;
}
break;
case "1000":
$nextvoid='9999';
break;
default:
$nextvoid="1000";
break;
}
$result = array(
//status is 0:
'STATUS' => (int)0,
//The action I want you to do is Voice Omit:
'ACTION' => 'VOICE_OMIT',
//The action I want you to do is Voice Omit:
'DATA' => array(
//Pass the VOID and USERINPUT as 2 keys for the result:
'NEXT_VO_ID'=>(int)$nextvoid
),
);
return($result);
}
}
$server = new SimpleServer();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment