Make the provisioning use device extension table.

This commit is contained in:
Mark Crane
2013-04-28 07:24:41 +00:00
parent 2616051620
commit b132db8eeb
3 changed files with 213 additions and 181 deletions
+19 -22
View File
@@ -125,6 +125,7 @@ require_once "includes/require.php";
$prep_statement_2->bindParam(':mac', $mac);
$prep_statement_2->execute();
$row = $prep_statement_2->fetch();
$device_uuid = $row["device_uuid"];
$device_label = $row["device_label"];
if (strlen($row["device_vendor"]) > 0) {
$device_vendor = $row["device_vendor"];
@@ -288,29 +289,25 @@ require_once "includes/require.php";
$mac_dash = substr($mac, 0,2).'-'.substr($mac, 2,2).'-'.substr($mac, 4,2).'-'.substr($mac, 6,2).'-'.substr($mac, 8,2).'-'.substr($mac, 10,2);
//lookup the provisioning information for this MAC address.
$sql = "select * from v_extensions ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and (provisioning_list like '%|".$mac.":%' or provisioning_list like '%|".$mac_dash.":%') ";
$sql .= "and enabled = 'true' ";
$sql = "SELECT e.extension, e.password, e.effective_caller_id_name, d.device_extension_uuid, d.extension_uuid, d.device_line ";
$sql .= "FROM v_device_extensions as d, v_extensions as e ";
$sql .= "WHERE e.extension_uuid = d.extension_uuid ";
$sql .= "AND d.device_uuid = '".$device_uuid."' ";
$sql .= "AND d.domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and e.enabled = 'true' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$provisioning_list = $row["provisioning_list"];
$provisioning_list_array = explode("|", $provisioning_list);
foreach ($provisioning_list_array as &$prov_row) {
$prov_row_array = explode(":", $prov_row);
$prov_mac = strtolower($prov_row_array[0]);
$prov_mac = preg_replace('#[^a-fA-F0-9./]#', '', $prov_mac);
if ($prov_mac == $mac) {
$line_number = $prov_row_array[1];
$file_contents = str_replace("{v_line".$line_number."_server_address}", $_SESSION['domain_name'], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_displayname}", $row["effective_caller_id_name"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_shortname}", $row["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_id}", $row["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_password}", $row["password"], $file_contents);
}
}
$result_count = count($result);
foreach($result as $row) {
$line_number = $row['device_line'];
$file_contents = str_replace("{v_line".$line_number."_server_address}", $_SESSION['domain_name'], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_displayname}", $row["effective_caller_id_name"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_shortname}", $row["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_id}", $row["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_password}", $row["password"], $file_contents);
//$vm_password = $row["vm_password"];
//$vm_password = str_replace("#", "", $vm_password); //preserves leading zeros
//$accountcode = $row["accountcode"];
@@ -385,8 +382,8 @@ require_once "includes/require.php";
function mac_exists_in_devices($db, $mac) {
global $domain_uuid;
$sql = "SELECT count(*) as count FROM v_devices ";
$sql .= "where domain_uuid=:domain_uuid ";
$sql .= "and device_mac_address=:mac ";
$sql .= "WHERE domain_uuid=:domain_uuid ";
$sql .= "AND device_mac_address=:mac ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->bindParam(':domain_uuid', $domain_uuid);
+36 -48
View File
@@ -181,54 +181,42 @@ else {
$mac_dash = substr($device_mac_address, 0,2).'-'.substr($device_mac_address, 2,2).'-'.substr($device_mac_address, 4,2).'-'.substr($device_mac_address, 6,2).'-'.substr($device_mac_address, 8,2).'-'.substr($device_mac_address, 10,2);
//lookup the provisioning information for this MAC address.
$sql2 = "select * from v_extensions ";
$sql2 .= "where domain_uuid = '$domain_uuid' ";
$sql2 .= "and (provisioning_list like '%|".$device_mac_address.":%' or provisioning_list like '%|".$mac_dash.":%') ";
$sql2 .= "and enabled = 'true' ";
$prep_statement_2 = $db->prepare(check_sql($sql2));
$prep_statement_2->execute();
$result2 = $prep_statement_2->fetchAll(PDO::FETCH_NAMED);
foreach ($result2 as &$row2) {
$provisioning_list = $row2["provisioning_list"];
if (strlen($provisioning_list) > 1) {
$provisioning_list_array = explode("|", $provisioning_list);
foreach ($provisioning_list_array as $prov_row) {
$prov_row_array = explode(":", $prov_row);
if (strlen($prov_row_array[0]) > 0) {
//echo "mac address: ".$prov_row_array[0]."<br />";
//echo "line_number: ".$prov_row_array[1]."<br />";
if ($prov_row_array[0] == $device_mac_address) {
$line_number = $prov_row_array[1];
//echo "prov_row: ".$prov_row."<br />";
//echo "line_number: ".$line_number."<br />";
//echo "<hr><br />\n";
}
$file_contents = str_replace("{v_line".$line_number."_server_address}", $_SESSION['domain_name'], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_displayname}", $row2["effective_caller_id_name"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_shortname}", $row2["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_id}", $row2["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_password}", $row2["password"], $file_contents);
}
}
//$vm_password = $row["vm_password"];
//$vm_password = str_replace("#", "", $vm_password); //preserves leading zeros
//$accountcode = $row["accountcode"];
//$effective_caller_id_name = $row["effective_caller_id_name"];
//$effective_caller_id_number = $row["effective_caller_id_number"];
//$outbound_caller_id_name = $row["outbound_caller_id_name"];
//$outbound_caller_id_number = $row["outbound_caller_id_number"];
//$vm_enabled = $row["vm_enabled"];
//$vm_mailto = $row["vm_mailto"];
//$vm_attach_file = $row["vm_attach_file"];
//$vm_keep_local_after_email = $row["vm_keep_local_after_email"];
//$user_context = $row["user_context"];
//$call_group = $row["call_group"];
//$auth_acl = $row["auth_acl"];
//$cidr = $row["cidr"];
//$sip_force_contact = $row["sip_force_contact"];
//$enabled = $row["enabled"];
//$description = $row["description"]
}
$sql = "SELECT e.extension, e.password, e.effective_caller_id_name, d.device_extension_uuid, d.extension_uuid, d.device_line ";
$sql .= "FROM v_device_extensions as d, v_extensions as e ";
$sql .= "WHERE e.extension_uuid = d.extension_uuid ";
$sql .= "AND d.device_uuid = '".$device_uuid."' ";
$sql .= "AND d.domain_uuid = '".$_SESSION['domain_uuid']."' ";
$sql .= "and e.enabled = 'true' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
foreach($result as $row) {
$line_number = $row['device_line'];
$file_contents = str_replace("{v_line".$line_number."_server_address}", $_SESSION['domain_name'], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_displayname}", $row["effective_caller_id_name"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_shortname}", $row["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_id}", $row["extension"], $file_contents);
$file_contents = str_replace("{v_line".$line_number."_user_password}", $row["password"], $file_contents);
//$vm_password = $row["vm_password"];
//$vm_password = str_replace("#", "", $vm_password); //preserves leading zeros
//$accountcode = $row["accountcode"];
//$effective_caller_id_name = $row["effective_caller_id_name"];
//$effective_caller_id_number = $row["effective_caller_id_number"];
//$outbound_caller_id_name = $row["outbound_caller_id_name"];
//$outbound_caller_id_number = $row["outbound_caller_id_number"];
//$vm_enabled = $row["vm_enabled"];
//$vm_mailto = $row["vm_mailto"];
//$vm_attach_file = $row["vm_attach_file"];
//$vm_keep_local_after_email = $row["vm_keep_local_after_email"];
//$user_context = $row["user_context"];
//$call_group = $row["call_group"];
//$auth_acl = $row["auth_acl"];
//$cidr = $row["cidr"];
//$sip_force_contact = $row["sip_force_contact"];
//$enabled = $row["enabled"];
//$description = $row["description"]
}
unset ($prep_statement_2);