<?
/*********************** INCLUDES *********************************************/
  $includePath=realpath(__FILE__."/../../");
  require_once ($includePath.'/config/cfg.php');
  //require($includePath.'/constants.php');
  require_once ($includePath.'/lib/phpagi/phpagi.php');
  //require($includePath.'/agi/agifunction.php');
/*********************** INITIALIZATION ***************************************/
  $agi = new AGI();

  //extract the filename from the callerid
  $callerid=$agi->get_variable("CALLERID");
  $callerid=preg_match("/[^<]*<([^>]*)>/",$callerid["data"],$result);
  $filename=$result[1];
  
  //answer the call
  $agi->answer();
  
  //play or record?
  if (substr($filename,-3)=="gsm") {
    $filename=substr($filename,0,-3);
    $agi->stream_file($ivrStartingDir.$filename);    
  } else if ($filename!="")  {
    $agi->text2wav("You can stop recording by pressing any digit");
    //$agi->text2wav("5-4-3-2-1- Start!");
    //$arr=$agi->record_file (string $file, string $format, [string $escape_digits = ''], [integer $timeout = -1], [integer $offset = NULL], [boolean $beep = false], [integer $silence = NULL]) 
    $arr=$agi->record_file ($ivrStartingDir.$filename, "gsm", "0123456789", "30000", null, true); 
    $agi->text2wav('Ok, voice recorded. Thanks, Goodbye');
  } else {
    $agi->text2wav('No file name specified, sorry.');
  }
  $agi->hangup();
?>
