[go: up one dir, main page]

Menu

[166f65]: / syncfromdms.php  Maximize  Restore  History

Download this file

96 lines (82 with data), 2.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?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";
}
?>