#!/usr/bin/php -q 1 && is_numeric($argv[1]) && $argv[1] >= 0) $cardID = $argv[1]; else $cardID = 0; if (($argc > 2) && ($argv[2] >= 0)) $reason = $argv[2]; if (strcasecmp ($reason, "BUSY") != 0) $reason = "unavailable"; else $reason = "busy"; $mode = 'standard'; $ldconfig = 1; $A2B = new A2Billing(); $A2B -> load_conf($agi, NULL, 0, $idconfig); $A2B -> CC_TESTING = isset($A2B->agiconfig['debugshell']) && $A2B->agiconfig['debugshell']; /* GET THE AGI PARAMETER */ $A2B -> get_agi_request_parameter ($agi); if (!$A2B -> DbConnect()) { $agi-> stream_file('prepaid-final', '#'); exit; } $instance_table = new Table(); $A2B -> set_instance_table ($instance_table); // First check if the card ID is passed through the dialplan $query = "SELECT DID,email FROM cc_card WHERE (id=" . $cardID . ")"; $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $query); $ok = (is_array($result)); if (!$ok) exit (); // Save the DID $DID = $result [0][0]; $email = $result [0][1]; settype ($email, "string"); /* // Ask the caller to enter the customer ID while ((!$ok) && ($errorCount < 3)) { $errorCount++; $resDTMF = $agi->get_data ("a2billing/voicemail/enter_customer_id", 10000, 10); $cardID = $resDTMF ["result"]; $query = "SELECT id FROM cc_card WHERE (id=" . $cardID . ")"; $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $query); $ok = (is_array($result)); if (!$ok) { $agi->stream_file ("a2billing/voicemail/wrong_customer_id"); if ($errorCount < 3) $agi->stream_file ("a2billing/voicemail/try_again"); else { $agi->stream_file ("a2billing/voicemail/too_many_errors"); exit (); } } } */ $busyFile = "/var/lib/asterisk/sounds/a2billing/voicemail/busy/" . $cardID; $unavailFile = "/var/lib/asterisk/sounds/a2billing/voicemail/unavailable/" . $cardID; if ($reason == "busy") $useDefault = !file_exists ($busyFile . ".wav"); else $useDefault = !file_exists ($unavailFile . ".wav"); if ($useDefault) { // Play the default message $agi->stream_file ("vm-theperson"); WriteLog ("DID is ${DID}"); $agi->say_digits ($DID); if ($reason == "busy") $agi->stream_file ("vm-isonphone"); else $agi->stream_file ("vm-isunavail"); } else // Play the user recording file if ($reason == "busy") $agi->stream_file ($busyFile); else $agi->stream_file ($unavailFile); // Record the mesasge file $msgfilename = time () . "_" . $agi->request[agi_uniqueid]; $filename = "a2billing/voicemail/messages/" . $msgfilename; $agi->stream_file ("vm-intro"); // Do the recording WriteLog ("Starting recording"); $recordingstart = time (); $agi -> set_variable ("RECORDINGSTART", $recordingstart); $agi -> set_variable ("RECORDINGFILENAME", $msgfilename); $result = $agi->record_file ($filename, "wav", "#", 300000, NULL, 5); WriteLog ("Recording result is ${result}"); $recordingend = time (); WriteLog ("Ended recording"); if (($recordingend - $recordingstart) > 3) { // Messages shorter that 3 seconds will be discarded // Insert a new record into the database $query = "INSERT INTO cc_voicemail (CardNumber,MessageFile,MessageDate,CallerID) VALUES ("; $query .= $cardID . ",'" . $filename ."','" . date ("Y-m-d H:i:s") . "','" . $agi->request['agi_callerid'] . "')"; $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $query, 0); if (strlen ($email) > 0) // Send an email message with an attachement SendEmail ($email, $msgfilename . ".wav"); } else { WriteLog ("Message is too short"); unlink ("/var/lib/asterisk/sounds/a2billing/voicemail/messages/" . $msgfilename); } ?>