function create_wakeup($time_wakeup)
{
    global $parm_chan_ext, $parm_temp_dir, $parm_call_dir, $parm_debug_on, $chan, $sta, $cidn, $agivar, $parm_maxretries, $parm_retrytime, $parm_waittime, $parm_wakeupcallerid, $parm_application, $parm_data, $stdin, $stdout, $stdlog;
    $w = getdate($time_wakeup);
    $wtime = sprintf("%02d%02d", $w['hours'], $w['minutes']);
    if ($parm_chan_ext) {
        $wakefile = "{$parm_temp_dir}/{$wtime}.{$chan}.{$sta}.call";
        $callfile = "{$parm_call_dir}/{$wtime}.{$chan}.{$sta}.call";
    } else {
        $wakefile = "{$parm_temp_dir}/{$wtime}.ext.{$cidn}.call";
        $callfile = "{$parm_call_dir}/{$wtime}.ext.{$cidn}.call";
    }
    if ($parm_debug_on) {
        fputs($stdlog, "Wakeup File [{$wakefile}]\n");
    }
    // Open up a wakeup file to write it out.
    $wuc = fopen($wakefile, 'w');
    if ($wuc) {
        // Delete any old Wakeup call files this one will override
        for ($i = 0; $i < $outc; $i++) {
            if (file_exists("{$parm_call_dir}/{$out[$i]}")) {
                if ($parm_debug_on) {
                    fputs($stdlog, "Unlinking Old File [{$parm_call_dir}/{$out[$i]}]\n");
                }
                unlink("{$parm_call_dir}/{$out[$i]}");
            }
        }
        // I've noticed that the other WAKEUP example has a different format.  This worked for me
        // Here is where we either make the call to the Extension or the Channel.  Extension
        // is the better way to go, but required the caller ID information.  Where Channel
        // should always get you back to where you were called from, provided its on your system
        if ($parm_chan_ext) {
            fputs($wuc, "channel: {$chan}/{$sta}\n");
        } else {
            //			fputs( $wuc, "channel: Local/$cidn@$agivar[agi_context]\n" );
            fputs($wuc, "channel: Local/{$cidn}@from-internal\n");
        }
        fputs($wuc, "maxretries: {$parm_maxretries}\n");
        fputs($wuc, "retrytime: {$parm_retrytime}\n");
        fputs($wuc, "waittime: {$parm_waittime}\n");
        fputs($wuc, "callerid: {$parm_wakeupcallerid}\n");
        fputs($wuc, "application: {$parm_application}\n");
        fputs($wuc, "data: {$parm_data}\n");
        fclose($wuc);
        touch($wakefile, $time_wakeup, $time_wakeup);
        rename($wakefile, $callfile);
    } else {
        // Couldn't open the file.  Make sure you created the /var/lib/asterisk/wakeups directory
        if ($parm_debug_on) {
            fputs($stdlog, "Error opening file [{$wakefile}]\n");
        }
        $rc = execute_agi("STREAM FILE something-terribly-wrong \"\" ");
        if (!$rc[result]) {
            $rc = execute_agi("STREAM FILE goodbye \"\" ");
        }
        if (!$rc[result]) {
            $rc = execute_agi("HANGUP");
        }
        exit;
    }
}
$results_1d = array();
foreach ($results_2d[0] as $key => $value) {
    $results_1d[$key] = $value;
}
$pin = $results_1d['pin'];
if ($debug) {
    fputs($stdlog, "PIN: " . $pin . "\n");
}
# greet the caller;
execute_agi("STREAM FILE en/beep \"\" ");
# say the pin;
execute_agi("SAY DIGITS {$pin} \"\"");
# say goodbye;
execute_agi("STREAM FILE en/beep \"\" ");
# now... GTFO!;
$rc = execute_agi("HANGUP ");
# Kinda like raw command line, but safer because it is Asterisks-specific;
function execute_agi($command)
{
    global $stdin, $stdout, $stdlog, $debug;
    fputs($stdout, $command . "\n");
    fflush($stdout);
    if ($debug) {
        fputs($stdlog, $command . "\n");
    }
    $resp = fgets($stdin, 4096);
    if ($debug) {
        fputs($stdlog, $resp);
    }
    if (preg_match("/^([0-9]{1,3}) (.*)/", $resp, $matches)) {
        if (preg_match('/result=([-0-9a-zA-Z]*)(.*)/', $matches[2], $match)) {
示例#3
0
function say_wakeup($wtime)
{
    global $stdin, $stdout, $stdlog, $parm_debug_on;
    $pm = 0;
    if ($wtime > 1159) {
        $wtime -= 1200;
        $pm = 1;
    }
    if ($wtime <= 59) {
        $wtime += 1200;
    }
    if (strlen($wtime) == 3) {
        $wtime = '0' . $wtime;
    }
    $h = substr($wtime, 0, 2);
    $h1 = substr($wtime, 0, 1);
    $h2 = substr($wtime, 1, 1);
    $m = substr($wtime, 2, 2);
    $m1 = substr($wtime, 2, 1);
    $m2 = substr($wtime, 3, 1);
    if ($parm_debug_on) {
        fputs($stdlog, "Wakeup time is set to {$wtime}\n");
    }
    $rc = execute_agi("STREAM FILE rqsted-wakeup-for \"\" ");
    if (!$rc['result']) {
        if ($h1 == 0) {
            $rc = execute_agi("SAY NUMBER {$h2} \"\"");
        } else {
            $rc = execute_agi("SAY NUMBER {$h} \"\"");
        }
        if (!$rc['result']) {
            if ($m == 0) {
                $rc = execute_agi("STREAM FILE digits/oclock \"\" ");
            } else {
                if ($m1 == 0) {
                    $rc = execute_agi("STREAM FILE digits/oh \"\" ");
                    $rc = execute_agi("SAY NUMBER {$m2} \"\" ");
                } else {
                    $rc = execute_agi("SAY NUMBER {$m} \"\"");
                }
            }
            if (!$rc['result']) {
                if ($pm) {
                    $rc = execute_agi("STREAM FILE digits/p-m \"\" ");
                } else {
                    $rc = execute_agi("STREAM FILE digits/a-m \"\" ");
                }
            }
        }
    }
}
$fd = fopen($tmptext, "w"); 
if (!$fd) {
 echo "<p>Unable to open temporary text file in /tmp for writing. \n"; 
 exit; 
} 
$retcode = fwrite($fd,$value);	
fclose($fd);

$retcode2 = system ("flite -f  $tmptext -o $tmpwave") ;

unlink ("$tmptext") ;

$tmpwave = "tts/tts-$token" ;

execute_agi("SET VARIABLE TMPWAVE $tmpwave"); 

if ($emaildebuglog) :
 system("mime-construct --to $email --subject " . chr(34) . "Nerd Vittles Weather Session Log" . chr(34) . " --attachment $log --type text/plain --file $log") ;
endif ;


// clean up file handlers etc.  
fclose($stdin);  
fclose($stdout);
fclose($stdlog);  
exit;   
  
?>

$NEWTIME = mktime($thishr, $thismin, 1, $thismo, $thisda, $thisyr);
$nowmo = date("n") + 0;
$nowda = date("j") + 0;
$nowyr = date("Y") + 0;
$nowhr = date("G") + 0;
$nowmin = date("i") + 4;
$RIGHTNOW = mktime($nowhr, $nowmin, 1, $nowmo, $nowda, $nowyr);
if ($NEWTIME < $RIGHTNOW) {
    $BADFLAG = 1;
}
if ($BADFLAG != 0) {
    $txt2write = "SET VARIABLE HOTTIME \"BAD\"";
    execute_agi($txt2write);
} else {
    $txt2write = "SET VARIABLE HOTTIME \"" . $NEWTIME . "\"";
    execute_agi($txt2write);
}
if ($debug) {
    if ($emaildebuglog) {
        fputs($stdlog, "\n\nCheckTime session log emailed to " . $email . ".\n");
    }
    fputs($stdlog, "\n\n" . date("F j, Y - H:i:s") . "  *** End of session ***\n\n\n");
}
if ($emaildebuglog) {
    system("mime-construct --to {$email} --subject " . chr(34) . "CheckTime Session Log" . chr(34) . " --attachment {$log} --type text/plain --file {$log}");
}
// clean up file handlers etc.
fclose($stdin);
fclose($stdout);
fclose($stdlog);
exit;