<?php
ini_set('display_errors','On');
//error_reporting(E_ALL);
require_once('config.inc.php');
require_once('db_mysql.inc.php');
// Get users from a DMS
// Something like:
// <parent>
// <USER first_name="" last_name="" organization="" universal_id="" email="" work_phone="" cell_phone="" />
// </parent>
// organization -> context
// univeral_id -> mac_address of polycom phone
$url = "";
$xml = simplexml_load_file($url);
if ($xml) {
// save dmsdata.php
$fp=fopen("/var/lib/asterisk/agi-bin/dmsdata.php", "w");
if ($fp) {
fprintf($fp,"<?php\n".
"\$dmsuser=array(\n");
for ($i=0; $i<count($xml->USER); $i++) {
fprintf($fp, "\"". $xml->USER[$i]["work_phone"] ."\" => array(\"cell_phone\" => \"". $xml->USER[$i]["cell_phone"] ."\", ".
"\"home_phone\" => \"".$xml->USER[$i]["home_phone"]."\",".
"\"first_name\" => \"".$xml->USER[$i]["first_name"]."\",".
"\"last_name\" => \"".$xml->USER[$i]["last_name"]."\",".
"\"organization\" => \"".$xml->USER[$i]["organization"]."\",".
"\"email\" => \"".$xml->USER[$i]["email"]."\",".
"\"universal_id\" => \"".$xml->USER[$i]["universal_id"]."\",".
"\"user_role_id\" => \"".$xml->USER[$i]["user_role_id"]."\"".
"),\n");
}
fprintf($fp, ");\n?>");
fclose($fp);
} else {
print "Failed opening dmsdata: ". strerror($errorno);
}
// write out users as extensions
$conn=DBConnect($db_server,$db_user,$db_pass,$db_name);
if ($conn) {
for ($i=0; $i<count($xml->USER); $i++) {
$extension=preg_replace("/.*x/", "", $xml->USER[$i]["work_phone"]);
$p=array("extension"=> $extension,
"secret"=>"8".$extension,
"name"=> $xml->USER[$i]["first_name"]." ". $xml->USER[$i]["last_name"],
"context"=> $xml->USER[$i]["organization"],
"vm_pin"=> "8".$extension,
"email"=> $xml->USER[$i]["email"],
"cell_phone"=>$xml->USER[$i]["cell_phone"],
"mac_address"=> $xml->USER[$i]["universal_id"],
"nat_ip"=>"",
"nat_signalPort"=>"",
"custom_ringTone0"=>"",
"custom_ringTone1"=>"",
"custom_ringTone2"=>"",
"custom_ringTone3"=>"",
"custom_ringTone4"=>"",
"custom_ringTone5"=>"",
"custom_ringTone6"=>"",
"custom_ringTone7"=>"",
"custom_ringTone8"=>"",
"custom_ringTone9"=>"",
"vm_callback"=>"85".$extension,
"custom_dial1"=>"",
"custom_dialdur1"=>"",
"custom_dial2"=>"",
"custom_dialdur2"=>""
);
if (!strlen($p["context"])) {
$p["context"]="mie";
}
if (!Person_DBUpdate($conn, $p)) {
print "Error updating person ext:". $p["extension"] ." name:".$p["name"]." err: ".DBErrorMsg($conn) ."\n";
}
}
DBClose($conn);
} else {
print "Failed to connect to DB\n";
}
} else {
print "Failed parsing XML from DMS";
}
?>