Re: Auto dial out
<?php
$base_path = "";
$in = 'in.txt';
$width = 11;
$creation_time = "02 june 2001 15:30";
function create_call_file($name) {
global $creation_time;
global $path;
$call_file = fopen($base_path."call/".$name.".call", "w");
$out = "Channel: SIP/sipout/$name\n";
$out .= "Callerid: 100\n";
$out .= "MaxRetries: 5\n";
$out .= "RetryTime: 60\n";
$out .= "WaitTime: 15\n";
$out .= "Context: from-internal\n";
$out .= "Extension: 100\n";
$out .= "Priority: 1";
fwrite($call_file, $out);
fclose($call_file);
$timestamp = strtotime($creation_time);
if (touch($base_path."call/".$name.".call", $timestamp)) {
print " time changed to ".date("d.m.Y H:i", $timestamp);
}
chmod($base_path."call/".$name.".call", 0777);
}
if (!$width || !is_numeric($width) || (int)$width != $width) die ("invalid width");
if (!is_file($base_path.$in)) die ("file '".$base_path.$in."' not found");
$input = file_get_contents($base_path.$in);
if (!input) die ("input file is empty");
if (!is_dir($base_path.'call')) {
if (!mkdir($base_path.'call')) die ("can't create .call files directory");
}
$input_array = explode("\n", $input);
$str_count = sizeof($input_array);
$counter = 1;
$allowed_chars = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
foreach ($input_array as $str) {
print ("parsing string $counter of $str_count... ");
$number = trim($str);
if ($number && !str_replace($allowed_chars, '', $number)) {
$out_str = "";
$out_str .= str_pad($number, $width, '0', STR_PAD_LEFT);
$out_str .= "\n";
print " ok ";
create_call_file(trim($out_str));
}
else {
print " '$number': invalid phone number";
}
$counter++;
print "<br>\n";
}
?>
|