Enhance the extension class to include voicemail database management.

This commit is contained in:
Mark Crane 2013-04-12 23:30:48 +00:00
parent 7c6c6e9f71
commit 75368a2d65
3 changed files with 413 additions and 339 deletions

View File

@ -217,6 +217,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//add or update the database
if ($_POST["persistformvar"] != "true") {
//add the extension to the database
if ($action == "add" && permission_exists('extension_add')) {
$user_email = '';
if ($autogen_users == "true") {
@ -232,7 +233,6 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
unset($auto_user);
}
$db->beginTransaction();
for ($i=1; $i<=$range; $i++) {
if (extension_exists($extension)) {
//extension exists
@ -352,85 +352,49 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$db->exec(check_sql($sql));
unset($sql);
}
//set the voicemail password
if (strlen($vm_password) == 0) {
$vm_password = generate_password(9, 1);
}
//add or update voicemail
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension;
$ext->db = $db;
$ext->domain_uuid = $domain_uuid;
$ext->extension = $extension;
$ext->number_alias = $number_alias;
$ext->vm_password = $vm_password;
$ext->vm_mailto = $vm_mailto;
$ext->vm_attach_file = $vm_attach_file;
$ext->vm_keep_local_after_email = $vm_keep_local_after_email;
$ext->vm_enabled = $vm_enabled;
$ext->description = $description;
$ext->voicemail();
unset($ext);
//unset the voicemail password
$vm_password = "";
//increment the extension number
$extension++;
}
$db->commit();
//synchronize configuration
if (is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once "app/extensions/resources/classes/extension.php";
$extension = new extension;
$extension->xml();
}
//write the provision files
if (strlen($provisioning_list)>0) {
require_once "app/provision/provision_write.php";
}
//prepare for alternating the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//show the action and redirect the user
require_once "includes/header.php";
echo "<br />\n";
echo "<div align='center'>\n";
if (count($generated_users) == 0) {
//action add
echo "<meta http-equiv=\"refresh\" content=\"2;url=extensions.php\">\n";
echo " <table width='40%'>\n";
echo " <tr>\n";
echo " <th align='left'>Message</th>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class='row_style1'><strong>Add Complete</strong></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " <br />\n";
}
else {
// auto-generate user with extension as login name
echo " <table width='40%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td colspan='2'><strong>New User Accounts</strong></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <th>Username</th>\n";
echo " <th>Password</th>\n";
echo " </tr>\n";
foreach($generated_users as $tmp_user){
echo " <tr>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$tmp_user['username']."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$tmp_user['password']."</td>\n";
echo " </tr>\n";
}
if ($c==0) { $c=1; } else { $c=0; }
echo " </table>";
}
echo "</div>\n";
require_once "includes/footer.php";
return;
} //if ($action == "add")
//update the database
if ($action == "update" && permission_exists('extension_edit')) {
//generate a password
if (strlen($password) == 0) {
$password = generate_password(12,4);
}
//set the voicemail password
if (strlen($vm_password) == 0) {
$vm_password = generate_password(9, 1);
}
//update extensions
$sql = "update v_extensions set ";
$sql .= "extension = '$extension', ";
$sql .= "number_alias = '$number_alias', ";
$sql .= "password = '$password', ";
$sql .= "provisioning_list = '$provisioning_list', ";
if (strlen($vm_password) > 0) {
$sql .= "vm_password = '$vm_password', ";
}
else {
$sql .= "vm_password = '".generate_password(9, 1)."', ";
}
$sql .= "accountcode = '$accountcode', ";
$sql .= "effective_caller_id_name = '$effective_caller_id_name', ";
$sql .= "effective_caller_id_number = '$effective_caller_id_number', ";
@ -490,6 +454,26 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
$db->exec(check_sql($sql));
unset($sql);
//add or update voicemail
require_once "app/extensions/resources/classes/extension.php";
$ext = new extension;
$ext->db = $db;
$ext->domain_uuid = $domain_uuid;
$ext->extension = $extension;
$ext->number_alias = $number_alias;
$ext->vm_password = $vm_password;
$ext->vm_mailto = $vm_mailto;
$ext->vm_attach_file = $vm_attach_file;
$ext->vm_keep_local_after_email = $vm_keep_local_after_email;
$ext->vm_enabled = $vm_enabled;
$ext->description = $description;
$ext->voicemail();
unset($ext);
} //if ($action == "update")
//check the permissions
if (permission_exists('extension_add') || permission_exists('extension_edit')) {
//synchronize configuration
if (is_readable($_SESSION['switch']['extensions']['dir'])) {
require_once "app/extensions/resources/classes/extension.php";
@ -501,99 +485,86 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
//write the provision files
if (strlen($provisioning_list) > 0) {
require_once "app/provision/provision_write.php";
$ext = new extension;
}
//determine the voicemail_id
if (is_numeric($extension)) {
$voicemail_id = $extension;
}
else {
$voicemail_id = $number_alias;
}
//update the voicemail settings
$sql = "select * from v_voicemails ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and voicemail_id = '$voicemail_id' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) == 0) {
//add the voicemail box
$sql = "insert into v_voicemails ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "voicemail_uuid, ";
$sql .= "voicemail_id, ";
$sql .= "voicemail_password, ";
if (strlen($greeting_id) > 0) {
$sql .= "greeting_id, ";
}
$sql .= "voicemail_mail_to, ";
$sql .= "voicemail_attach_file, ";
$sql .= "voicemail_local_after_email, ";
$sql .= "voicemail_enabled, ";
$sql .= "voicemail_description ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'$domain_uuid', ";
$sql .= "'".uuid()."', ";
$sql .= "'$voicemail_id', ";
$sql .= "'$vm_password', ";
$sql .= "'$vm_mailto', ";
$sql .= "'$vm_attach_file', ";
$sql .= "'$vm_keep_local_after_email', ";
$sql .= "'$vm_enabled', ";
$sql .= "'$description' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
else {
//update the voicemail box
$sql = "update v_voicemails set ";
$sql .= "voicemail_password = '$vm_password', ";
$sql .= "voicemail_mail_to = '$vm_mailto', ";
$sql .= "voicemail_attach_file = '$vm_attach_file', ";
$sql .= "voicemail_local_after_email = '$vm_keep_local_after_email', ";
$sql .= "voicemail_enabled = '$vm_enabled', ";
$sql .= "voicemail_description = '$description' ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and voicemail_id = '$voicemail_id'";
$db->exec(check_sql($sql));
unset($sql);
}
unset ($prep_statement);
//delete extension from memcache
$fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
if ($fp) {
$switch_cmd = "memcache delete directory:".$extension."@".$_SESSION['domain_name'];
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
}
}
//show the action and redirect the user
if ($action == "add") {
//prepare for alternating the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//show the action and redirect the user
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=extensions.php\">\n";
echo "<br />\n";
echo "<div align='center'>\n";
//action update
if (count($generated_users) == 0) {
//action add
echo "<meta http-equiv=\"refresh\" content=\"2;url=extensions.php\">\n";
echo " <table width='40%'>\n";
echo " <tr>\n";
echo " <th align='left'>Message</th>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td class='row_style1'><strong>Update Complete</strong></td>\n";
echo " <td class='row_style1'><strong>Add Complete</strong></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " <br />\n";
}
else {
//auto-generate user with extension as login name
echo " <table width='40%' border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td colspan='2'><strong>New User Accounts</strong></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <th>Username</th>\n";
echo " <th>Password</th>\n";
echo " </tr>\n";
foreach($generated_users as $tmp_user){
echo " <tr>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$tmp_user['username']."</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".$tmp_user['password']."</td>\n";
echo " </tr>\n";
}
if ($c==0) { $c=1; } else { $c=0; }
echo " </table>";
}
echo "</div>\n";
require_once "includes/footer.php";
}
if ($action == "update") {
require_once "includes/header.php";
echo "<meta http-equiv=\"refresh\" content=\"2;url=extensions.php\">\n";
echo "<br />\n";
echo "<div align='center'>\n";
echo " <table width='40%'>\n";
echo " <tr>\n";
echo " <th align='left'>Message</th>\n";
echo " </tr>\n";
echo " <tr>\n";
if ($action == "update") {
echo " <td class='row_style1'><strong>Update Complete</strong></td>\n";
}
else {
echo " <td class='row_style1'><strong>Add Complete</strong></td>\n";
}
echo " </tr>\n";
echo " </table>\n";
echo "<br />\n";
echo "</div>\n";
require_once "includes/footer.php";
return;
} //if ($action == "update")
}
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)

View File

@ -61,7 +61,7 @@ require_once "includes/paging.php";
//get the number of rows in v_extensions
$sql = "select count(*) as num_rows from v_extensions ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "where domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();

View File

@ -30,6 +30,43 @@
public $domain_uuid;
public $domain_name;
private $app_uuid;
public $extension_uuid;
public $extension;
public $voicemail_id;
public $number_alias;
public $password;
public $provisioning_list;
public $vm_password;
public $accountcode;
public $effective_caller_id_name;
public $effective_caller_id_number;
public $outbound_caller_id_name;
public $outbound_caller_id_number;
public $emergency_caller_id_number;
public $directory_full_name;
public $directory_visible;
public $directory_exten_visible;
public $limit_max;
public $limit_destination;
public $vm_enabled;
public $vm_mailto;
public $vm_attach_file;
public $vm_keep_local_after_email;
public $user_context;
public $toll_allow;
public $call_timeout;
public $call_group;
public $hold_music;
public $auth_acl;
public $cidr;
public $sip_force_contact;
public $sip_force_expires;
public $nibble_account;
public $mwi_account;
public $sip_bypass_media;
public $dial_string;
public $enabled;
public $description;
public function __construct() {
require_once "includes/classes/database.php";
@ -50,6 +87,72 @@
$this->domain_uuid = $domain_uuid;
}
public function voicemail() {
//determine the voicemail_id
if (is_numeric($this->extension)) {
$this->voicemail_id = $this->extension;
}
else {
$this->voicemail_id = $this->number_alias;
}
//update the voicemail settings
$sql = "select * from v_voicemails ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
$prep_statement = $this->db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) == 0) {
//add the voicemail box
$sql = "insert into v_voicemails ";
$sql .= "(";
$sql .= "domain_uuid, ";
$sql .= "voicemail_uuid, ";
$sql .= "voicemail_id, ";
$sql .= "voicemail_password, ";
if (strlen($this->greeting_id) > 0) {
$sql .= "greeting_id, ";
}
$sql .= "voicemail_mail_to, ";
$sql .= "voicemail_attach_file, ";
$sql .= "voicemail_local_after_email, ";
$sql .= "voicemail_enabled, ";
$sql .= "voicemail_description ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$this->domain_uuid."', ";
$sql .= "'".uuid()."', ";
$sql .= "'".$this->voicemail_id."', ";
$sql .= "'".$this->vm_password."', ";
$sql .= "'".$this->vm_mailto."', ";
$sql .= "'".$this->vm_attach_file."', ";
$sql .= "'".$this->vm_keep_local_after_email."', ";
$sql .= "'".$this->vm_enabled."', ";
$sql .= "'".$this->description."' ";
$sql .= ")";
$this->db->exec(check_sql($sql));
unset($sql);
}
else {
//update the voicemail box
$sql = "update v_voicemails set ";
$sql .= "voicemail_password = '".$this->vm_password."', ";
$sql .= "voicemail_mail_to = '".$this->vm_mailto."', ";
$sql .= "voicemail_attach_file = '".$this->vm_attach_file."', ";
$sql .= "voicemail_local_after_email = '".$this->vm_keep_local_after_email."', ";
$sql .= "voicemail_enabled = '".$this->vm_enabled."', ";
$sql .= "voicemail_description = '".$this->description."' ";
$sql .= "where domain_uuid = '".$this->domain_uuid."' ";
$sql .= "and voicemail_id = '".$this->voicemail_id."' ";
$this->db->exec(check_sql($sql));
unset($sql);
}
unset ($prep_statement);
}
public function xml() {
if (isset($_SESSION['switch']['extensions']['dir'])) {
//declare global variables