diff options
author | ivan <ivan> | 2008-03-16 19:58:33 +0000 |
---|---|---|
committer | ivan <ivan> | 2008-03-16 19:58:33 +0000 |
commit | 3a17b276638200475d54201fa62566b7440e819a (patch) | |
tree | e287d32efc93c5924bc63dec88a79d36e4383961 /fs_selfservice/fri/modules | |
parent | 46c6025ca0759b96e5bd16e7ce4b16d4df8a0988 (diff) |
Diffstat (limited to 'fs_selfservice/fri/modules')
-rw-r--r-- | fs_selfservice/fri/modules/VmX.module | 661 | ||||
-rw-r--r-- | fs_selfservice/fri/modules/callmonitor.module | 675 | ||||
-rw-r--r-- | fs_selfservice/fri/modules/featurecodes.module | 152 | ||||
-rw-r--r-- | fs_selfservice/fri/modules/followme.module | 678 | ||||
-rw-r--r-- | fs_selfservice/fri/modules/phonefeatures.module | 342 | ||||
-rw-r--r-- | fs_selfservice/fri/modules/settings.module | 813 | ||||
-rw-r--r-- | fs_selfservice/fri/modules/voicemail.module | 805 |
7 files changed, 4126 insertions, 0 deletions
diff --git a/fs_selfservice/fri/modules/VmX.module b/fs_selfservice/fri/modules/VmX.module new file mode 100644 index 000000000..61ef653a2 --- /dev/null +++ b/fs_selfservice/fri/modules/VmX.module @@ -0,0 +1,661 @@ +<?php + +/** + * @file + * Functions for the interface to the call monitor recordings + */ + +/** + * Class for Followme + */ +class VmX { + + var $protocol_table; + var $protocol_config_files; + + /* + * rank (for prioritizing modules) + */ + function rank() { + + $rank = 6; + return $rank; + } + + /* + * init + */ + function init() { + + } + + /* + * Adds menu item to nav menu + * + * @param $args + * Common arguments + */ + function navMenu($args) { + + global $SETTINGS_ALLOW_VMX_SETTINGS; + global $ARI_ADMIN_USERNAME; + + $ret = ""; + + // We are only going to show the menu + // if VmX is allowed + if ($SETTINGS_ALLOW_VMX_SETTINGS) { + + $exten = $_SESSION['ari_user']['extension']; + + // and we are not logged in as admin + if ($exten!=$ARI_ADMIN_USERNAME) { + + $vmx_enabled = $this->getVmxState($exten,'unavail'); + + // and vmx is enabled for this user + if ($vmx_enabled !== false) + $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=VmX&f=display'>" . _("VmX™ Locator") . "</a></small></small></p>"; + } + } + + return $ret; + } + + /* + * Acts on the user settings + * + * @param $args + * Common arguments + * @param $a + * action + */ + function action($args) { + + global $STANDALONE; + global $ARI_ADMIN_USERNAME; + global $SETTINGS_ALLOW_VMX_SETTINGS; + + // args + $m = getArgument($args,'m'); + $a = getArgument($args,'a'); + + $follow_me_disabled = getArgument($args,'follow_me_disabled'); + + $vmx_option_0_number = getArgument($args, 'vmx_option_0_number'); + $vmx_option_0_system_default = getArgument($args, 'vmx_option_0_system_default'); + $vmx_option_1_number = getArgument($args, 'vmx_option_1_number'); + $vmx_option_1_system_default = getArgument($args, 'vmx_option_1_system_default'); + $vmx_option_2_number = getArgument($args, 'vmx_option_2_number'); + $vmx_unavail_enabled = getArgument($args, 'vmx_unavail_enabled'); + $vmx_busy_enabled = getArgument($args, 'vmx_busy_enabled'); + $vmx_play_instructions = getArgument($args, 'vmx_play_instructions'); + $vmx_disabled = getArgument($args, 'vmx_disabled'); + + $exten = $_SESSION['ari_user']['extension']; + + // The action is 'update + if ($a=='update') { + + $follow_me_disabled = ($this->getFollowMeListRingTime($exten) > 0)?0:1; + + + $vmx_disabled = $this->getVmxState($exten,'unavail'); + if ($vmx_disabled === false) { + $vmx_disabled = true; + $SETTINGS_ALLOW_VMX_SETTINGS=false; + } else { + $vmx_disabled = false; + } + if ($vmx_disabled) { + + setcookie("ari_vmx_disabled", $vmx_disabled, time()+365*24*60*60); + $vmx_disabled_delayed = $vmx_disabled; + $_SESSION['ari_error'] = + _("Your Premium VmX Locator service has been disabled, REFRESH your browser to remove this message") . "<br>" . + sprintf(_("Check with your Telephone System Administrator if you think there is a problem")); + } + + if (! $vmx_disabled) { + + // set database + $this->setVmxState($exten,'unavail',$vmx_unavail_enabled); + $this->setVmxState($exten,'busy',$vmx_busy_enabled); + $this->setVmxPlayInstructions($exten,'unavail',$vmx_play_instructions); + $this->setVmxPlayInstructions($exten,'busy',$vmx_play_instructions); + + // store cookie + setcookie("ari_vmx_unavail_enabled", $vmx_unavail_enabled, time()+365*24*60*60); + setcookie("ari_vmx_busy_enabled", $vmx_busy_enabled, time()+365*24*60*60); + setcookie("ari_vmx_play_instructions", $vmx_play_instructions, time()+365*24*60*60); + + $stripped_vmx_option_0_number = preg_replace('/-|\(|\)|\s/','',$vmx_option_0_number); + + if ($vmx_option_0_system_default) { + $this->setVmxOptionNumber($exten,'0','unavail',""); + $this->setVmxOptionNumber($exten,'0','busy',""); + setcookie("ari_vmx_option_0_system_default", $vmx_option_0_system_default, time()+365*24*60*60); + if (is_numeric($stripped_vmx_option_0_number) || !$stripped_vmx_option_0_number) { + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_vmx_option_0_number']); + if ($vmx_option_0_number && $stripped!=$stripped_vmx_option_0_number) { + setcookie("ari_vmx_option_0_number", $call_vmx_option_0_number, time()+365*24*60*60); + } + } + } else { + if (!is_numeric($stripped_vmx_option_0_number) && $stripped_vmx_option_0_number) { + $_SESSION['ari_error'] = + _("Option 0 not changed") . "<br>" . + sprintf(_("Number %s must contain dial numbers (characters like '(', '-', and ')' are ok)"),$vmx_option_0_number); + } + else { + + // set database + $this->setVmxOptionNumber($exten,'0','unavail',$stripped_vmx_option_0_number); + $this->setVmxOptionNumber($exten,'0','busy',$stripped_vmx_option_0_number); + + // store cookie + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_vmx_option_0_number']); + if ($vmx_option_0_number && $stripped!=$stripped_vmx_option_0_number) { + setcookie("ari_vmx_option_0_number", $call_vmx_option_0_number, time()+365*24*60*60); + } + } + } + + $stripped_vmx_option_1_number = preg_replace('/-|\(|\)|\s/','',$vmx_option_1_number); + if ($vmx_option_1_system_default && !$follow_me_disabled) { + $this->setVmxOptionFollowMe($exten,'1','unavail'); + $this->setVmxOptionFollowMe($exten,'1','busy'); + setcookie("ari_vmx_option_1_system_default", $vmx_option_1_system_default, time()+365*24*60*60); + if (is_numeric($stripped_vmx_option_1_number) || !$stripped_vmx_option_1_number) { + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_vmx_option_1_number']); + if ($vmx_option_1_number && $stripped!=$stripped_vmx_option_1_number) { + setcookie("ari_vmx_option_1_number", $call_vmx_option_1_number, time()+365*24*60*60); + } + } + } + else { + + if (!is_numeric($stripped_vmx_option_1_number) && $stripped_vmx_option_1_number) { + $_SESSION['ari_error'] = + _("Option 1 not changed") . "<br>" . + sprintf(_("Number %s must contain dial numbers (characters like '(', '-', and ')' are ok)"),$vmx_option_1_number); + } + else { + + // set database + $this->setVmxOptionNumber($exten,'1','unavail',$stripped_vmx_option_1_number); + $this->setVmxOptionNumber($exten,'1','busy',$stripped_vmx_option_1_number); + + // store cookie + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_vmx_option_1_number']); + if ($vmx_option_1_number && $stripped!=$stripped_vmx_option_1_number) { + setcookie("ari_vmx_option_1_number", $call_vmx_option_1_number, time()+365*24*60*60); + } + } + } + + $stripped_vmx_option_2_number = preg_replace('/-|\(|\)|\s/','',$vmx_option_2_number); + if (!is_numeric($stripped_vmx_option_2_number) && $stripped_vmx_option_2_number) { + $_SESSION['ari_error'] = + _("Option 2 not changed") . "<br>" . + sprintf(_("Number %s must contain dial numbers (characters like '(', '-', and ')' are ok)"),$vmx_option_2_number); + } + else { + + // set database + $this->setVmxOptionNumber($exten,'2','unavail',$stripped_vmx_option_2_number); + $this->setVmxOptionNumber($exten,'2','busy',$stripped_vmx_option_2_number); + + // store cookie + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_vmx_option_2_number']); + if ($vmx_option_2_number && $stripped!=$stripped_vmx_option_2_number) { + setcookie("ari_vmx_option_2_number", $call_vmx_option_2_number, time()+365*24*60*60); + } + } + } // vmx_disabled false + } + + // redirect to see updated page + $ret .= " + <head> + <script> + <!-- + window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "\" + // --> + </script> + </head>"; + + return $ret; + } + + /* + * Displays stats page + * + * @param $args + * Common arguments + */ + function display($args) { + global $SETTINGS_ALLOW_VMX_SETTINGS; + + global $loaded_modules; + + // args + $m = getArgument($args,'m'); + $q = getArgument($args,'q'); + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + + $displayname = $_SESSION['ari_user']['displayname']; + $exten = $_SESSION['ari_user']['extension']; + + $display = new DisplaySearch(); + + $follow_me_listring_time = $this->getFollowMeListRingTime($exten); + + //TODO: Set this better than this? + $follow_me_disabled = ($follow_me_listring_time > 0)?0:1; + setcookie("ari_follow_me_disabled", $follow_me_disabled, time()+365*24*60*60); + + + $vmx_unavail_enabled=$this->getVmxState($exten,'unavail'); + if ($vmx_unavail_enabled === false) { + $vmx_disabled = true; + setcookie("ari_vmx_disabled", $vmx_disabled, time()+365*24*60*60); + $SETTINGS_ALLOW_VMX_SETTINGS=false; + } else { + $vmx_disabled = false; + setcookie("ari_vmx_disabled", false, time()+365*24*60*60); + $vmx_busy_enabled=$this->getVmxState($exten,'busy'); + $vmx_play_instructions=$this->getVmxPlayInstructions($exten); + $vmx_option_0_number=$this->getVmxOptionNumber($exten,'0');; + $vmx_option_1_number=$this->getVmxOptionNumber($exten,'1');; + $vmx_option_2_number=$this->getVmxOptionNumber($exten,'2');; + + if (is_numeric($vmx_option_0_number)) { + $vmx_option_0_system_default=''; + $vmx_option_0_number_text_box_options=''; + } else { + $vmx_option_0_system_default='checked'; + $vmx_option_0_number_text_box_options="disabled style='background: #DDD;'"; + } + + // if follow-me is enabled then the options are a numberic value (dial a phone number) + // or a followme target (FMnnn) which should not be displayed but means the box is checked + // or otherwise blank (or garbage in which case blank it) + // + if (!$follow_me_disabled) { + $vmx_option_1_system_default=$this->getVmxOptionFollowMe($exten,'1'); + if ($vmx_option_1_system_default) { + $vmx_option_1_number = ''; + $vmx_option_1_number_text_box_options="disabled style='background: #DDD;'"; + } + } + } + + $set_vmx_text .= + " + <br> + <table class='settings'> + <tr> + <td><a href='#' class='info'>" . _("Use When:") . "<span>" . _("Menu options below are available during your personal voicemail greeting playback. <br/><br/>Check both to use at all times.") . "<br></span></a></td> <td> + <input " . $vmx_unavail_enabled . " type=checkbox name='vmx_unavail_enabled' value='checked'> + <small>" . _("unavailable") . "</small> + </td> + <td> + <input " . $vmx_busy_enabled . " type=checkbox name='vmx_busy_enabled' value='checked'> + <small>" . _("busy") . "</small> + </td> + </tr> + <tr> + <td><a href='#' class='info'>" . _("Voicemail Instructions:") ."<span>" . _("Uncheck to play a beep after your personal voicemail greeting.") . "<br></span></a></td> + <td> + <input " . $vmx_play_instructions . " type=checkbox name='vmx_play_instructions' value='checked'> + <small>" . _("Standard voicemail prompts.") . "</small> + </td> + </tr> + </table> + <br> + <br> + <table class='settings'> + <tr> + <td><a href='#' class='info'>" . _("Press 0:") . "<span>" . _("Pressing 0 during your personal voicemail greeing goes to the Operator. + Uncheck to enter another destination here.") . "<br></span></a> + </td> + <td> + <input " . $vmx_option_0_number_text_box_options . " name='vmx_option_0_number' type='text' size=24 value='" . $vmx_option_0_number . "'> + </td> + <td> + <input " . $vmx_option_0_system_default . " type=checkbox name='vmx_option_0_system_default' value='checked' OnClick=\"disable_fields(); return true;\"> + <small>" . _("Go To Operator") . "</small> + </td> + </tr> + <tr> + <td><a href='#' class='info'>" . _("Press 1:") . "<span>"; + + if ($follow_me_disabled) + $set_vmx_text .= _("The remaining options can have internal extensions, ringgroups, queues and external numbers that may be rung. It is often used to include your cell phone. You should run a test to make sure that the number is functional any time a change is made so you don't leave a caller stranded or receiving invalid number messages."); + else + $set_vmx_text .= _("Enter an alternate number here, then change your personal voicemail greeting to let callers know to press 1 to reach that number. <br/><br/>If you'd like to use your Follow Me List, check \"Send to Follow Me\" and disable Follow Me above."); + + + $set_vmx_text .= + " <br></span></a> + </td> + <td> + <input " . $vmx_option_1_number_text_box_options . " name='vmx_option_1_number' type='text' size=24 value='" . $vmx_option_1_number . "'> + </td> + <td>"; + + + if (!$follow_me_disabled) + $set_vmx_text .= "<input " . $vmx_option_1_system_default . " type=checkbox name='vmx_option_1_system_default' value='checked' OnClick=\"disable_fields(); return true;\"><small>" . _("Send to Follow-Me") . "</small>"; + + + $set_vmx_text .= + " + </td> + </tr> + <tr> + <td><a href='#' class='info'>" . _("Press 2:") . "<span>" . _("Use any extensions, ringgroups, queues or external numbers. <br/><br/>Remember to re-record your personal voicemail greeting and include instructions. Run a test to make sure that the number is functional.") . "<br></span></a></td> + <td> + <input " . $vmx_option_2_number_text_box_options . " name='vmx_option_2_number' type='text' size=24 value='" . $vmx_option_2_number . "'> + </td> + </tr> + </table> + <br> + <br> + "; + + + // Now we should be ready to build the page + $ret .= checkErrorMessage(); + + $headerText = sprintf(_("VmX Locator™ Settings for %s (%s)"),$displayname,$exten); + + $ret .= $display->displayHeaderText($headerText); + $ret .= $display->displayLine(); + + $ret .= + "<SCRIPT LANGUAGE='JavaScript'> + <!-- Begin + function disable_fields() { + + if (document.ari_settings.vmx_option_0_system_default.checked) { + document.ari_settings.vmx_option_0_number.style.backgroundColor = '#DDD'; + document.ari_settings.vmx_option_0_number.disabled = true; + } + else { + document.ari_settings.vmx_option_0_number.style.backgroundColor = '#FFF'; + document.ari_settings.vmx_option_0_number.disabled = false; + }"; + + if (!$follow_me_disabled) { + $ret .= " + if (document.ari_settings.vmx_option_1_system_default.checked) { + document.ari_settings.vmx_option_1_number.style.backgroundColor = '#DDD'; + document.ari_settings.vmx_option_1_number.disabled = true; + } + else { + document.ari_settings.vmx_option_1_number.style.backgroundColor = '#FFF'; + document.ari_settings.vmx_option_1_number.disabled = false; + }"; + } + $ret .= + "} + // End --> + </script>"; + + $ret .= + "<form class='settings' name='ari_settings' action='' method='GET'> + <input type=hidden name=m value=" . $m . "> + <input type=hidden name=f value='action'> + <input type=hidden name=a value='update'> + " . $set_vmx_text . " + <br> + <input name='submit' type='submit' value='" . _("Update") . "'> + </form>"; + + return $ret; + } + + /* + * Gets VMX option FollowMe + * + * @param $exten + * Extension to get information about + * @param $digit + * Option number to get + * @param $mode + * Mode to get (unavail/busy) + * @return $response + * checked if set to got to extesion's follow-me on this option + */ + function getVmxOptionFollowMe($exten, $digit, $mode='unavail') { + + global $asterisk_manager_interface; + + $digit = trim($digit); + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/vmx/$mode/$digit/ext\r\n\r\n"); + return (($response == 'FM'.$exten) ? 'checked':''); + } + + /* + * Sets VMX option FollowMe + * + * @param $exten + * Extension to set information about + * @param $digit + * Option number to set + * @param $mode + * Mode to set (unavail/busy) + * @param $context + * Context to set ext to (default from-findmefollow) + * @param $priority + * Priority to set ext to (default 1) + */ + function setVmxOptionFollowMe($exten, $digit, $mode, $context='ext-findmefollow', $priority='1') { + + global $asterisk_manager_interface; + + $value_opt = "FM$exten"; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/$digit/ext $value_opt\r\n\r\n"); + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/$digit/context $context\r\n\r\n"); + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/$digit/pri $priority\r\n\r\n"); + } + + /* + * Gets VMX option number + * + * @param $exten + * Extension to get information about + * @param $digit + * Option number to get + * @param $mode + * Mode to get (unavail/busy) + * @return $number + * Number to use or blank if disabled + */ + function getVmxOptionNumber($exten, $digit, $mode='unavail') { + + global $asterisk_manager_interface; + + $number = ''; + $digit = trim($digit); + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/vmx/$mode/$digit/ext\r\n\r\n"); + if (is_numeric($response)) { + $number = $response; + } + + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE["ari_vmx_option_${digit}_number"]); + if ($stripped==$number) { + $number = $_COOKIE["ari_vmx_option_${digit}_number"]; + } + + return $number; + } + + /* + * Sets VMX option number + * + * @param $exten + * Extension to set information about + * @param $digit + * Option number to set + * @param $mode + * Mode to set (unavail/busy) + * @param $number + * Number to set ext to (blank will delete it) + * @param $context + * Context to set ext to (default from-internal) + * @param $priority + * Priority to set ext to (default 1) + */ + function setVmxOptionNumber($exten, $digit, $mode, $number, $context='from-internal', $priority='1') { + + global $asterisk_manager_interface; + + $value_opt = trim($number); + + if (is_numeric($value_opt)) { + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/$digit/ext $value_opt\r\n\r\n"); + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/$digit/context $context\r\n\r\n"); + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/$digit/pri $priority\r\n\r\n"); + } else { + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database deltree AMPUSER $exten/vmx/$mode/$digit\r\n\r\n"); + } + } + + /* + * Sets VMX State + * + * @param $exten + * Extension to modify + * @param $mode + * Mode to set (unavail/busy) + * @param $vmx_state + * enabled/disabled state based on check box value + */ + function setVmxState($exten,$mode,$vmx_state) { + + global $asterisk_manager_interface; + + $value_opt = ($vmx_state)?'enabled':'disabled'; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/state $value_opt\r\n\r\n"); + } + + /* + * Gets VMX State + * + * @param $exten + * Extension to get information about + * @param $mode + * Mode to get (unavail/busy) + * @return $data + * state of variable (checked/blank) or false if no poper value + */ + function getVmxState($exten, $mode='unavail') { + + global $asterisk_manager_interface; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/vmx/$mode/state\r\n\r\n"); + + if (preg_match("/enabled/",$response)) { + $response='checked'; + } + elseif (preg_match("/disabled/",$response)) { + $response=''; + } + else { + $response = false; + } + + //TODO: really need to check for a bogus response, see how other side does it + // + return $response; + + } + + /* + * Sets VMX Play Instructions + * + * @param $exten + * Extension to modify + * @param $vmx_play_instructions + * play instructions or just beep (checked, blank) + * @param $mode + * Mode to set (unavail/busy) + */ + function setVmxPlayInstructions($exten,$mode,$vmx_play_instructions) { + + global $asterisk_manager_interface; + + $value_opt = ($vmx_play_instructions)?'""':'s'; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/vmx/$mode/vmxopts/timeout $value_opt\r\n\r\n"); + } + + /* + * Get VMX Play Instructions + * + * @param $exten + * Extension to get information about + * @param $mode + * Mode to get (unavail/busy) + * @return $data + * state of variable (checked/blank) or false if no poper value + */ + function getVmxPlayInstructions($exten, $mode='unavail') { + + global $asterisk_manager_interface; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/vmx/$mode/vmxopts/timeout\r\n\r\n"); + + if (preg_match("/s/",$response)) { + $response=''; + } + else { + $response='checked'; + } + + //TODO: really need to check for a bogus response, see how other side does it + // + return $response; + + } + + + /* + * Gets Follow Me List-Ring Time if set + * + * @param $exten + * Extension to get information about + * @return $number + * follow me list-ring time returned if set + */ + function getFollowMeListRingTime($exten) { + + global $asterisk_manager_interface; + + $number = ''; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/followme/grptime\r\n\r\n"); + if (is_numeric($response)) { + $number = $response; + } + + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_follow_me_listring_time']); + if ($stripped==$number) { + $number = $_COOKIE['ari_follow_me_listring_time']; + } + + return $number; + } + + +} // class + +?> diff --git a/fs_selfservice/fri/modules/callmonitor.module b/fs_selfservice/fri/modules/callmonitor.module new file mode 100644 index 000000000..25924d52d --- /dev/null +++ b/fs_selfservice/fri/modules/callmonitor.module @@ -0,0 +1,675 @@ +<?php + +/** + * @file + * Functions for the interface to the call monitor recordings + */ + +/** + * Class for Callmonitor + */ +class Callmonitor { + + /* + * rank (for prioritizing modules) + */ + function rank() { + + $rank = 2; + return $rank; + } + + /* + * init + */ + function init() { + } + + /* + * Adds menu item to nav menu + * + * @param $args + * Common arguments + */ + function navMenu($args) { + + $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Callmonitor&f=display'>" . _("Call Monitor") . "</a></small></small></p><br>"; + + return $ret; + } + + /* + * Acts on the selected call monitor recordings in the method indicated by the action and updates page + * + * @param $args + * Common arguments + */ + function recAction($args) { + + // args + $m = getArgument($args,'m'); + $a = getArgument($args,'a'); + $q = getArgument($args,'q'); + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + $order = getArgument($args,'order'); + $sort = getArgument($args,'sort'); + $duration_filter = getArgument($args,'duration_filter'); + + // get files + $files = array(); + foreach($_REQUEST as $key => $value) { + if (preg_match('/selected/',$key)) { + array_push($files, $value); + } + } + + if ($a=='delete') { + $this->deleteRecData($files); + } + + if ($a=='ignore') { + + $start = 0; + + setcookie("ari_duration_filter", $duration_filter, time()+365*24*60*60); + } + + // redirect to see updated page + $ret .= " + <head> + <script> + <!-- + window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&q=" . $q . "&start=" . $start . "&span=" . $span . "&order=" . $order . "&sort=" . $sort . "&duration_filter=" . $duration_filter . "\" + // --> + </script> + </head>"; + + return $ret; + } + + /* + * Displays stats page + * + * @param $args + * Common arguments + */ + function display($args) { + + global $ASTERISK_CALLMONITOR_PATH; + global $CALLMONITOR_ALLOW_DELETE; + global $AJAX_PAGE_REFRESH_ENABLE; + + $display = new DisplaySearch(); + + // get the search string + $m = getArgument($args,'m'); + $f = getArgument($args,'f'); + $q = getArgument($args,'q'); + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + $order = getArgument($args,'order'); + $sort = getArgument($args,'sort'); + $duration_filter = getArgument($args,'duration_filter'); + + $start = $start=='' ? 0 : $start; + $span = $span=='' ? 15 : $span; + $order = $order=='' ? 'calldate' : $order; + $sort = $sort=='' ? 'desc' : $sort; + + $displayname = $_SESSION['ari_user']['displayname']; + $extension = $_SESSION['ari_user']['extension']; + + // get data + $record_count = $this->getCdrCount($q,$duration_filter); + $data = $this->getCdrData($q,$duration_filter,$start,$span,$order,$sort); + + // get the call monitor recording files + $paths = split(';',$ASTERISK_CALLMONITOR_PATH); + foreach($paths as $key => $path) { + if (!is_dir($path)) { + $_SESSION['ari_error'] .= sprintf(_("Path is not a directory: %s"),$path) . "<br>"; + } + } + $recordings = $this->getRecordings($ASTERISK_CALLMONITOR_PATH,$data); + + // build controls + if ($CALLMONITOR_ALLOW_DELETE) { + $controls .= " + <button class='infobar' type='submit' onclick=\"document.callmonitor_form.a.value='delete'\"> + " . _("delete") . " + </button> + "; + } + + $controls .= " + <small>" . _("duration") . "</small> + <input name='duration_filter' type='text' size=4 maxlength=8 value='" . $_COOKIE['ari_duration_filter'] . "'> + <button class='infobar' type='submit' onclick=\"document.callmonitor_form.a.value='ignore'\"> + " . _("ignore") . " + </button>"; + + // table header + if ($CALLMONITOR_ALLOW_DELETE) { + $recording_delete_header = "<th></th>"; + } + + $fields[0]['field'] = "calldate"; + $fields[0]['text'] = _("Date"); + $fields[1]['field'] = "calldate"; + $fields[1]['text'] = _("Time"); + $fields[2]['field'] = "clid"; + $fields[2]['text'] = _("Caller ID"); + $fields[3]['field'] = "src"; + $fields[3]['text'] = _("Source"); + $fields[4]['field'] = "dst"; + $fields[4]['text'] = _("Destination"); + $fields[5]['field'] = "dcontext"; + $fields[5]['text'] = _("Context"); + $fields[6]['field'] = "duration"; + $fields[6]['text'] = _("Duration"); + + $i = 0; + while ($fields[$i]) { + + $field = $fields[$i]['field']; + $text = $fields[$i]['text']; + if ($order==$field) { + if ($sort=='asc') { + $currentSort = 'desc'; + $arrowImg = "<img src='theme/images/arrow-asc.gif' alt='sort'>"; + } + else { + $currentSort = 'asc'; + $arrowImg = "<img src='theme/images/arrow-desc.gif' alt='sort'>"; + } + + if ($i==1) { + $arrowImg = ''; + } + } + else { + $arrowImg = ''; + $currentSort = 'desc'; + } + + $unicode_q = urlencode($q); + $recording_header .= "<th><a href=" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&f=" . $f . "&q=" . $unicode_q . "&order=" . $field . "&sort=" . $currentSort . ">" . $text . $arrowImg . "</a></th>"; + + $i++; + } + $recording_header .= "<th>" . _("Monitor") . "</th>"; + + // table body + foreach($data as $key=>$value) { + + // recording file + $recording = $recordings[$value['uniqueid'] . $value['calldate']]; + + // date and time + $buf = split(' ', $value[calldate]); + $date = $buf[0]; + $time = $buf[1]; + + // recording delete checkbox + if ($CALLMONITOR_ALLOW_DELETE) { + $recording_delete_checkbox = "<td class='checkbox'><input type=checkbox name='selected" . ++$i . "' value=" . $recording . "></td>"; + } + + $recordingLink = ''; + if (is_file($recordings[$value['uniqueid'] . $value['calldate']])) { + $recordingLink = "<a href='#' onClick=\"javascript:popUp('misc/recording_popup.php?recording=" . $recording . "&date=" . $date . "&time=" . $time . "'); return false;\">" . _("play") . "</a>"; + } + + $recording_body .= "<tr> + " . $recording_delete_checkbox . " + <td width=70>" . $date . "</td> + <td>" . $time . "</td> + <td>" . $value[clid] . "</td> + <td>" . $value[src] . "</td> + <td>" . $value[dst] . "</td> + <td>" . $value[dcontext] . "</td> + <td width=90>" . $value[duration] . " sec</td> + <td>" . $recordingLink . "</td> + </tr>"; + } + if (!count($data)) { + $recording_body .= "<tr></tr>"; + } + + // options + $url_opts = array(); + $url_opts['sort'] = $sort; + $url_opts['order'] = $order; + $url_opts['duration_filter'] = $duration_filter; + + // build page content + $ret .= checkErrorMessage(); + + // ajax page refresh script + if ($AJAX_PAGE_REFRESH_ENABLE) { + // $ret .= ajaxRefreshScript($args); + } + + // header + if ($_SESSION['ari_user']['admin_callmonitor']) { + $header_text = _("Call Monitor"); + } else { + $header_text = sprintf(_("Call Monitor for %s (%s)"),$displayname,$extension); + } + $ret .= $display->displayHeaderText($header_text); + $ret .= $display->displaySearchBlock('left',$m,$q,$url_opts,true); + + // start form + if ($CALLMONITOR_ALLOW_DELETE) { + + $ret .= " + <form name='callmonitor_form' action='" . $_SESSION['ARI_ROOT'] . "' method='GET'> + <input type=hidden name=m value=" . $m . "> + <input type=hidden name=f value=recAction> + <input type=hidden name=a value=''> + <input type=hidden name=q value=" . $q . "> + <input type=hidden name=start value=" . $start . "> + <input type=hidden name=span value=" . $span . "> + <input type=hidden name=order value=" . $order . "> + <input type=hidden name=sort value=" . $sort . ">"; + } + + $ret .= $display->displayInfoBarBlock($controls,$q,$start,$span,$record_count); + + // javascript for popup and message actions + $ret .= " + <SCRIPT LANGUAGE='JavaScript'> + <!-- Begin + function popUp(URL) { + eval(\"page = window.open(URL, 'play', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=324,height=110');\"); + } + + function checkAll(form,set) { + var elem = 0; + var i = 0; + while (elem = form.elements[i]) { + if (set) { + elem.checked = true; + } else { + elem.checked = false; + } + i++; + } + return true; + } + // End --> + </script>"; + + // call monitor delete recording controls + if ($CALLMONITOR_ALLOW_DELETE) { + $ret .= " + <table> + <tr> + <td> + <small>" . _("select") . ": </small> + <small><a href='' OnClick=\"checkAll(document.callmonitor_form,true); return false;\">" . _("all") . "</a></small> + <small><a href='' OnClick=\"checkAll(document.callmonitor_form,false); return false;\">" . _("none") . "</a></small> + </td> + </tr> + </table>"; + } + else { + $ret .= "<br>"; + } + + // table + $ret .= " + <table class='callmonitor'> + <tr> + " . $recording_delete_header . " + " . $recording_header . " + </tr> + " . $recording_body . " + </table>"; + + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + $order = getArgument($args,'order'); + $sort = getArgument($args,'sort'); + + // end form + if ($CALLMONITOR_ALLOW_DELETE) { + $ret .= "</form>"; + } + + $ret .= $display->displaySearchBlock('center',$m,$q,$url_opts,false); + $ret .= $display->displayNavigationBlock($m,$q,$url_opts,$start,$span,$record_count); + + return $ret; + } + + /* + * Checks for a recording file + * + * @param $asterisk_callmonitor_path + * path call monitor recording directory on the asterisk server + * @param $data + * current call monitor recordings on the asterisk server + * @return $recording + * returns an array of $recording file names if found + */ + function getRecordings($asterisk_callmonitor_path,$data) { + + global $CALLMONITOR_ONLY_EXACT_MATCHING; + global $CALLMONITOR_AGGRESSIVE_MATCHING; + + $recordings = array(); + + $extension = $_SESSION['ari_user']['extension']; + + $paths = split(';',$asterisk_callmonitor_path); + foreach($paths as $key => $path) { + $paths[$key] = fixPathSlash($paths[$key]); + } + + $files = array(); + if (!$CALLMONITOR_ONLY_EXACT_MATCHING) { + $filter = ''; + $recursiveMax = 6; + $recursiveCount = 0; + foreach($paths as $key => $path) { + $path_files = getFiles($path,$filter,$recursiveMax,$recursiveCount); + if ($path_files) { + $files = array_merge($files,$path_files); + } + } + rsort($files); + } + + foreach($data as $data_key => $data_value) { + + $recording=''; + + $calldate = $data_value['calldate']; + $duration = $data_value['duration']; + $lastdata = $data_value['lastdata']; + $uniqueid = $data_value['uniqueid']; + $userfield = $data_value['userfield']; + + // timestamps + $st = trim(strtotime($calldate)); + $et = trim(strtotime($calldate) + $duration); // for on-demand call recordings + + // unique file key + if ($uniqueid) { + $buf = preg_replace('/\-|\:/', '', $calldate); + $calldate_key = preg_replace('/\s+/', '-', $buf); + $unique_file_key = $calldate_key . "-" . $uniqueid; + } + if ($unique_file_key=='') { + $buf = preg_split("/\|/", $lastdata); + $unique_file_key = $buf[1]; + } + + $recordingLink = ''; + foreach($paths as $callmonitor_key => $path) { + + // try to find an exact match using the uniqueid + if (isset($uniqueid)) { + + $check_files = array(); + array_push($check_files,$path . $uniqueid . ".WAV"); + array_push($check_files,$path . $uniqueid . ".wav"); + array_push($check_files,$path . $uniqueid . ".gsm"); + + array_push($check_files,$path . $unique_file_key . ".WAV"); + array_push($check_files,$path . $unique_file_key . ".wav"); + array_push($check_files,$path . $unique_file_key . ".gsm"); + + array_push($check_files,$path . "g" . $extension . "-" . $unique_file_key . ".WAV"); + array_push($check_files,$path . "g" . $extension . "-" . $unique_file_key . ".wav"); + array_push($check_files,$path . "g" . $extension . "-" . $unique_file_key . ".gsm"); + + array_push($check_files,$path . "q" . $extension . "-" . $unique_file_key . ".WAV"); + array_push($check_files,$path . "q" . $extension . "-" . $unique_file_key . ".wav"); + array_push($check_files,$path . "q" . $extension . "-" . $unique_file_key . ".gsm"); + + array_push($check_files,$path . "OUT" . $extension . "-" . $unique_file_key . ".WAV"); + array_push($check_files,$path . "OUT" . $extension . "-" . $unique_file_key . ".wav"); + array_push($check_files,$path . "OUT" . $extension . "-" . $unique_file_key . ".gsm"); + + array_push($check_files,$path . $userfield); + + // try to match + foreach($check_files as $check_file) { + if (is_file($check_file)) { + $recording = $check_file; + break; + } + } + } + + // if found do not need to check the rest of the paths + if ($recording!='') { + break; + } + } + + // get all the callmonitor recordings on server and try to find a non-exact match for this log entry + if (!$CALLMONITOR_ONLY_EXACT_MATCHING) { + + // try to find a file using the uniqueid + if (!$recording) { + + // try and match the unique id + if (!$recording) { + foreach($files as $key => $path) { + if (strlen($uniqueid)>1 && strpos($path,$uniqueid)!==FALSE) { + $recording = $path; + $files[$key] = ''; // remove it from the recording files so it will not be matched twice + break; + } + } + } + } + + // try and match a file using the calldate (if no unique number from database) + if (!$recording) { + + foreach($files as $key => $path) { + $parts = split("-", $path); + if (strlen($st)>1 && + (strpos($path,$st)!==FALSE) || + (strpos($path,"auto")!==FALSE && $parts[1] >= $st && $parts[1] <= $et)) { + $recording = $path; + $files[$key] = ''; // remove it from the recording files so it will not be matched twice + break; + } + } + } + + if ($CALLMONITOR_AGGRESSIVE_MATCHING) { + + // one last stab at finding a recording by adding one or two seconds to the call time + if (!$recording) { + $st_1 = trim($st+1); + $st_2 = trim($st+2); + $et_1 = trim($et+1); + $et_2 = trim($et+2); + foreach($files as $key => $path) { + $split = explode("-", $path); + if (strlen($st)>1 + && ((strpos($path,$st_1)!==FALSE) || + (strpos($path,$st_2)!==FALSE) || + (strpos($path,"auto")!==FALSE && $parts[1] >= $st_1 && $parts[1] <= $et_1) || + (strpos($path,"auto")!==FALSE && $parts[1] >= $st_2 && $parts[1] <= $et_2))) { + $recording = $path; + $files[$key] = ''; // remove it from the recording files so it will not be matched twice + break; + } + } + } + } + } + + // add to array to be returned + if ($recording) { + $recordings[$uniqueid . $calldate] = $recording; + } + } + + return $recordings; + } + + /* + * Deletes selected call monitor recordings + * + * @param $files + * Array of files to delete + */ + function deleteRecData($files) { + + foreach($files as $key => $file) { + if (is_writable($file)) { + unlink($file); + } else { + $_SESSION['ari_error'] = _("Only deletes recording files, not cdr log"); + } + } + } + + /* + * Gets cdr record count + * + * @param $q + * query text + */ + function getSearchText($q,$duration_filter) { + + // search text + if ($q!='*' && $q!=NULL) { + $searchText .= "WHERE "; + $tok = strtok($q," \n\t"); + while ($tok) { + $searchText .= " (calldate regexp '" . $tok . "' + OR clid regexp '" . $tok . "' + OR src regexp '" . $tok . "' + OR dst regexp '" . $tok . "' + OR dstchannel regexp '" . $tok . "' + OR dcontext regexp '" . $tok . "' + OR duration regexp '" . $tok . "' + OR disposition regexp '" . $tok . "' + OR uniqueid regexp '" . $tok . "' + OR userfield regexp '" . $tok . "' + )"; + $tok = strtok(" \n\t"); + if ($tok) { + $searchText .= " AND"; + } + } + } + + // duration_filter + if ($duration_filter) { + if (!$searchText) { + $searchText .= "WHERE "; + } else { + $searchText .= "AND "; + } + $searchText .= "duration>" . $duration_filter . " "; + } + + // admin + if (!$_SESSION['ari_user']['admin_callmonitor']) { + if (!$searchText) { + $searchText .= "WHERE "; + } else { + $searchText .= "AND "; + } + + // allow entries to be viewed with users extension + $searchText .= "(src = '" . $_SESSION['ari_user']['extension'] . "' + OR dst = '" . $_SESSION['ari_user']['extension'] . "' + + OR channel LIKE 'IAX2/" . $_SESSION['ari_user']['extension'] ."-%' + OR dstchannel LIKE 'IAX2/" . $_SESSION['ari_user']['extension'] ."-%' + + OR channel LIKE 'SIP/" . $_SESSION['ari_user']['extension'] ."-%' + OR dstchannel LIKE 'SIP/" . $_SESSION['ari_user']['extension'] ."-%')"; + + // allow entries to be viewed with users outbound CID + if (isset($_SESSION['ari_user']['outboundCID']) && trim($_SESSION['ari_user']['outboundCID']) != '') { + $searchText .= "OR (src = '" . $_SESSION['ari_user']['outboundCID'] . "' + OR dst = '" . $_SESSION['ari_user']['outboundCID'] . "')"; + } + } + + return $searchText; + } + + /* + * Gets cdr record count + * + * @param $q + * query text + * @return $count + * Number of cdr records counted + */ + function getCdrCount($q,$duration_filter) { + + global $ASTERISKCDR_DBTABLE; + + $searchText = $this->getSearchText($q,$duration_filter); + + $dbh = $_SESSION['dbh_cdr']; + $sql = "SELECT count(*) + FROM " . $ASTERISKCDR_DBTABLE . " + " . $searchText; + + $result = $dbh->getAll($sql); + if (DB::isError($result)) { + $_SESSION['ari_error'] = $result->getMessage(); + return; + } + $count = $result[0][0]; + + return $count; + } + + /* + * Gets cdr data + * + * @param $q + * query text + * @param $start + * start record + * @param $span + * number of records to return + * @return $data + * cdr data to be returned + */ + function getCdrData($q,$duration_filter,$start,$span,$order,$sort) { + + global $ASTERISKCDR_DBTABLE; + + $data = array(); + + $searchText = $this->getSearchText($q,$duration_filter); + + $dbh = $_SESSION['dbh_cdr']; + $sql = "SELECT * + FROM " . $ASTERISKCDR_DBTABLE . " + " . $searchText . " + ORDER BY " . $order . " " . $sort . " + LIMIT " . $start . "," . $span; + $result = $dbh->getAll($sql,DB_FETCHMODE_ASSOC); + if (DB::isError($result)) { + $_SESSION['ari_error'] = $result->getMessage(); + return; + } + $data = $result; + + return $data; + } + + +} + + +?> diff --git a/fs_selfservice/fri/modules/featurecodes.module b/fs_selfservice/fri/modules/featurecodes.module new file mode 100644 index 000000000..75d1d5c4e --- /dev/null +++ b/fs_selfservice/fri/modules/featurecodes.module @@ -0,0 +1,152 @@ +<?php + +/** + * @file + * Functions for the interface to the help page + */ + +/** + * Class for help + */ +class featurecodes { + + /* + * rank (for prioritizing modules) + */ + function rank() { + + $rank = 7; + return $rank; + } + + /* + * init + */ + function init() { + } + + /* + * Adds menu item to nav menu + * + * @param $args + * Common arguments + */ + function navMenu($args) { + + $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=featurecodes&f=display'>" . _("Feature Codes") . "</a></small></small></p><br>"; + + return $ret; + } + + /* + * Displays stats page + * + * @param $args + * Common arguments + */ + function display($args) { + + global $ARI_HELP_FEATURE_CODES; + + $display = new Display(); + + // args + $m = getArgument($args,'m'); + $q = getArgument($args,'q'); + + $displayname = $_SESSION['ari_user']['displayname']; + $extension = $_SESSION['ari_user']['extension']; + + // build page content + $ret .= checkErrorMessage(); + + $header_text = _("Feature Codes"); + if (!$_SESSION['ari_user']['admin_help']) { + $header_text .= sprintf(_(" for %s (%s)"), $displayname, $extension); + } + + // handset feature code header + $handset_feature_codes_header = + "<tr> + <th class='feature_codes'> + " . _("Handset Feature Code") . " + </th> + <th> + " . _("Action") . " + </th> + </tr>"; + + // handset feature code body + if (isset($_SESSION['dbh_asterisk'])) { + + $sql = " + SELECT keycode, description + FROM ( + SELECT modulename, description, defaultcode keycode + FROM featurecodes + WHERE customcode IS NULL + AND enabled = '1' + UNION ALL SELECT modulename, description, customcode keycode + FROM featurecodes + WHERE customcode IS NOT NULL + AND enabled = '1' + )c + WHERE modulename NOT + IN ( 'core', 'recordings', 'infoservices', 'polycomreassign') + ORDER BY modulename, keycode + "; + + $results = $_SESSION['dbh_asterisk']->getAll($sql, DB_FETCHMODE_ASSOC); + if(DB::IsError($results)) { + $_SESSION['ari_error'] = $results->getMessage(); + } + else { + foreach ($results as $item ) { + $handset_feature_codes_body .= + "<tr> + <td class='feature_codes'> + " . $item['keycode'] . " + </td> + <td> + " . $item['description'] . " + </td> + </tr>"; + } + } + } + else { + + // handset feature code body + foreach($ARI_HELP_FEATURE_CODES as $key => $feature_code) { + + $handset_feature_codes_body .= + "<tr> + <td class='feature_codes'> + " . $key . " + </td> + <td> + " . $feature_code . " + </td> + </tr>"; + } + } + + // build page content + $ret .= checkErrorMessage(); + + $ret .= $display->displayHeaderText($header_text); + $ret .= $display->displayLine(); + + // table + $ret .= " + <table class='help'> + " . $handset_feature_codes_header . " + " . $handset_feature_codes_body . " + </table>"; + + return $ret; + } + +} + +?> diff --git a/fs_selfservice/fri/modules/followme.module b/fs_selfservice/fri/modules/followme.module new file mode 100644 index 000000000..85a1f3776 --- /dev/null +++ b/fs_selfservice/fri/modules/followme.module @@ -0,0 +1,678 @@ +<?php + +/** + * @file + * Functions for the interface to the call monitor recordings + */ + +/** + * Class for Followme + */ +class followme { + + var $protocol_table; + var $protocol_config_files; + + /* + * rank (for prioritizing modules) + */ + function rank() { + + $rank = 5; + return $rank; + } + + /* + * init + */ + function init() { + + } + + /* + * Adds menu item to nav menu + * + * @param $args + * Common arguments + */ + function navMenu($args) { + global $ARI_ADMIN_USERNAME; + + $exten = $_SESSION['ari_user']['extension']; + if ($exten!=$ARI_ADMIN_USERNAME) { + $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=followme&f=display'>" . _("Follow Me") . "</a></small></small></p>"; + } + + return $ret; + } + + /* + * Acts on the user settings + * + * @param $args + * Common arguments + * @param $a + * action + */ + function action($args) { + + global $STANDALONE; + global $ARI_ADMIN_USERNAME; + global $SETTINGS_ALLOW_VMX_SETTINGS; + + // args + $m = getArgument($args,'m'); + $a = getArgument($args,'a'); + + $lang_code = getArgument($args,'lang_code'); + + $follow_me_prering_time = getArgument($args,'follow_me_prering_time'); + $follow_me_listring_time = getArgument($args,'follow_me_listring_time'); + $follow_me_list = getArgument($args,'follow_me_list'); + $follow_me_confirm = getArgument($args,'follow_me_confirm'); + $follow_me_ddial = getArgument($args,'follow_me_ddial'); + $follow_me_disabled = getArgument($args,'follow_me_disabled'); + + $language = new Language(); + + // Lets see if we can make heads or tails of this code?!? + + // The action is 'update + if ($a=='update') { + + // Get the extension and make sure we are not in + // admin mode + $exten = $_SESSION['ari_user']['extension']; + if ($exten!=$ARI_ADMIN_USERNAME) { + + + // Make sure Follow-Me setup has not been deleted for this user since the last refresh + $follow_me_disabled_delayed = $_COOKIE['ari_follow_me_disabled']; + if (! $_COOKIE['ari_follow_me_disabled']) { + + $follow_me_disabled = ($this->getFollowMeListRingTime($exten) > 0)?0:1; + + if ($follow_me_disabled) { + + setcookie("ari_follow_me_disabled", $follow_me_disabled, time()+365*24*60*60); + $follow_me_disabled_delayed = $follow_me_disabled; + $_SESSION['ari_error'] = + _("Your Follow-Me has been disabled, REFRESH your browser to remove this message") . "<br>" . + sprintf(_("Check with your Telephone System Administrator if you think there is a problem")); + } + } + + + + if (! $follow_me_disabled_delayed) { + + // assume no errors, don't update SQL if errors occured + $follow_me_update_succeeded=1; + + // update follow me pre-ring time + if (!$STANDALONE['use']) { + + $stripped_follow_me_prering_time = preg_replace('/-|\s/','',$follow_me_prering_time); + if (!is_numeric($stripped_follow_me_prering_time)) { + $_SESSION['ari_error'] = + _("Follow-Me pre-ring time not changed") . "<br>" . + sprintf(_("Number %s must be an interger number of seconds"),$follow_me_prering_time); + $follow_me_update_succeeded=0; + } + else { + + // set database + $this->setFollowMePreRingTime($exten,$stripped_follow_me_prering_time); + + // store cookie + $stripped = preg_replace('/-|\s/','',$_COOKIE['ari_follow_me_prering_time']); + if ($follow_me_prering_time && $stripped!=$stripped_follow_me_prering_time) { + setcookie("ari_follow_me_prering_time", $follow_me_prering_time, time()+365*24*60*60); + } + } + } + + // update follow me list ring time + if (!$STANDALONE['use']) { + + $stripped_follow_me_listring_time = preg_replace('/-|\s/','',$follow_me_listring_time); + if (!is_numeric($stripped_follow_me_listring_time)) { + $_SESSION['ari_error'] = + _("Follow-Me list ring time not changed") . "<br>" . + sprintf(_("Number %s must be an interger number of seconds"),$follow_me_listring_time); + $follow_me_update_succeeded=0; + } + else { + + // set database + $this->setFollowMeListRingTime($exten,$stripped_follow_me_listring_time); + + // store cookie + $stripped = preg_replace('/-|\s/','',$_COOKIE['ari_follow_me_listring_time']); + if ($follow_me_listring_time && $stripped!=$stripped_follow_me_listring_time) { + setcookie("ari_follow_me_listring_time", $follow_me_listring_time, time()+365*24*60*60); + } + } + } + + // update follow me list + if (!$STANDALONE['use']) { + + $grplist = explode("\n", $follow_me_list); + + if (!$grplist) { + $grplist = null; + } + + foreach (array_keys($grplist) as $key) { + //trim it + $grplist[$key] = trim($grplist[$key]); + + // Lookup the extension and append hash if not a user, and remove invalid chars + $grplist[$key] = $this->lookupSetExtensionFormat($grplist[$key]); + + // remove blanks + if ($grplist[$key] == "") unset($grplist[$key]); + } + + // check for duplicates, and re-sequence + $grplist = array_values(array_unique($grplist)); + + $stripped_follow_me_list = implode("-",$grplist); + + if ($stripped_follow_me_list == "") { + $_SESSION['ari_error'] = + _("Follow-Me list must contain at least one valid number") . "<br>" . + sprintf(_("The following: %s is not valid"),$follow_me_list); + $follow_me_update_succeeded=0; + } + else { + + // set database + $this->setFollowMeList($exten,$stripped_follow_me_list); + + // store cookie + $stripped = preg_replace('/|\(|\)|\s/','',$_COOKIE['ari_follow_me_list']); + if ($follow_me_list && $stripped!=$stripped_follow_me_list) { + setcookie("ari_follow_me_list", $follow_me_list, time()+365*24*60*60); + } + } + } + + // update follow me confirm + if (!$STANDALONE['use']) { + + // set database + $this->setFollowMeConfirm($exten,$follow_me_confirm); + $this->setFollowMeDDial($exten,$follow_me_ddial); + + // store cookie + setcookie("ari_follow_me_confirm", $follow_me_confirm, time()+365*24*60*60); + setcookie("ari_follow_me_ddial", $follow_me_ddial, time()+365*24*60*60); + } + + //If no errors than update the SQL table to keep in sync + if ($follow_me_update_succeeded) { + $this->setFollowMeMySQL($exten, $follow_me_prering_time, $follow_me_listring_time, $follow_me_list, $follow_me_confirm); + } + + } //if !follow_me_disabled + } + } + + // redirect to see updated page + $ret .= " + <head> + <script> + <!-- + window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "\" + // --> + </script> + </head>"; + + return $ret; + } + + /* + * Displays stats page + * + * @param $args + * Common arguments + */ + function display($args) { + + global $STANDALONE; + global $ARI_ADMIN_USERNAME; + global $SETTINGS_PRERING_LOW; + global $SETTINGS_PRERING_HIGH; + global $SETTINGS_LISTRING_LOW; + global $SETTINGS_LISTRING_HIGH; + + global $SETTINGS_FOLLOW_ME_LIST_MAX; + + global $loaded_modules; + + // args + $m = getArgument($args,'m'); + $q = getArgument($args,'q'); + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + + $displayname = $_SESSION['ari_user']['displayname']; + $exten = $_SESSION['ari_user']['extension']; + + $language = new Language(); + $display = new DisplaySearch(); + + // build controls + if ($exten!=$ARI_ADMIN_USERNAME) { + + // call forward settings + if (!$STANDALONE['use']) { + + $follow_me_prering_time = $this->getFollowMePreRingTime($exten); + $follow_me_listring_time = $this->getFollowMeListRingTime($exten); + $follow_me_list = explode("-", $this->getFollowMeList($exten) ); + $follow_me_confirm = $this->getFollowMeConfirm($exten); + $follow_me_ddial = $this->getFollowMeDDial($exten); + + $FOLLOW_ME_LIST_MAX = (count($follow_me_list) > $SETTINGS_FOLLOW_ME_LIST_MAX) ? count($follow_me_list):$SETTINGS_FOLLOW_ME_LIST_MAX; + + //TODO: Set this better than this? + $follow_me_disabled = ($follow_me_listring_time > 0)?0:1; + setcookie("ari_follow_me_disabled", $follow_me_disabled, time()+365*24*60*60); + + $followme_text.= "<table class='settings'>"; + + if (!$follow_me_disabled) { + // $followme_text .= "<tr><td><h3><br>" . _("Follow Me") . "</h3></td></tr>"; + $followme_text .= "<tr><td> </td></tr>"; // Blank Line + + $followme_text .= "<tr><td><a href='#' class='info'>" . _("Enable") . "<span>"; + $followme_text .= _( "Dial-by-name Directory, IVR, and internal + calls will ring the numbers in the FollowMe + List. Any FreePBX routes that directly + reference a FollowMe are unaffected by this + enable/disable setting."); + $followme_text .= "<br></span></a></td>"; + + $followme_text .= "<td><input " . $follow_me_ddial . " type=checkbox name='follow_me_ddial' value='checked'></td></tr>"; + + $followme_text .= "<tr><td> </td></tr>"; // Blank Line + $followme_text .= "<tr><td valign='top'><a href='#' class='info'>" . _("Follow Me List:"); + $followme_text .= "<span>" . sprintf(_("Extensions and outside numbers to ring next.")) ."<br/><br/>"; + $followme_text .= sprintf(_("Include %s to keep it ringing."),"<strong>".$exten."</strong>") . "<br></span></a></td>"; + $followme_text .= "<td><textarea " . $follow_me_list_options . " id='follow_me_list' name='follow_me_list' type='text' cols='20' rows='".$FOLLOW_ME_LIST_MAX."' value='' onKeyUp='rowCounter(this.form.follow_me_list, ".$FOLLOW_ME_LIST_MAX.");' onKeyDown='rowCounter(this.form.follow_me_list, ".$FOLLOW_ME_LIST_MAX.");'>".implode("\n",$follow_me_list)."</textarea>"; + $followme_text .= "</td></tr>"; + + $followme_text .= "<tr><td> </td></tr>"; // Blank Line + $followme_text .= "<tr><td><a href='#' class='info'>"; + $followme_text .= sprintf(_("Ring %s First For:"), $exten); + $followme_text .= "<span>" . sprintf( _("Time to ring extension %s before ringing the %s Follow Me List %s"), "<strong>".$exten."</strong>","<strong>","</strong>"); + $followme_text .= "<br></span></a></td><td>"; + + $followme_text .= "<select " . $follow_me_prering_time_text_box_options . " name='follow_me_prering_time'/>"; + $default_prering = $follow_me_prering_time; + for ($i=$SETTINGS_PRERING_LOW; $i <= $SETTINGS_PRERING_HIGH; $i++) { + $followme_text .= '<option value="'.$i.'" '.($i == $default_prering ? 'SELECTED' : '').'>'.$i.'</option>'; + } + $followme_text .= "</select>"; + + $followme_text .= "<small>" . _("seconds") . "</small>"; + $followme_text .= "</td></tr>"; + + $followme_text .= "<tr><td><a href='#' class='info'>" . _("Ring Followme List for:") . "<span>" . _("Time to ring the Follow Me List.") . "<br></span></a></td>"; + $followme_text .= "<td>"; + + $followme_text .= "<select " . $follow_me_listring_time_text_box_options . " name='follow_me_listring_time'/>"; + $default_listring = $follow_me_listring_time; + for ($i=$SETTINGS_LISTRING_LOW; $i <= $SETTINGS_LISTRING_HIGH; $i++) { + $followme_text .= '<option value="'.$i.'" '.($i == $default_listring ? 'SELECTED' : '').'>'.$i.'</option>'; + } + $followme_text .= "</select>"; + + $followme_text .= "<small>" . _("seconds") . "</small></td></tr>"; + + + $followme_text .= "<tr><td> </td></tr>"; // Blank Line + + $followme_text .= "<tr><td><a href='#' class='info'>" . _("Use Confirmation:") . "<span>". _("Outside lines that are part of the Follow Me List will be called and offered a menu:<br/><br/> \"You have an incoming call. Press 1 to accept or 2 to decline.\"<br/><br/> This keeps calls from ending up in external voicemail. Make sure that the List Ring Time is long enough to allow for you to hear and react to this message."); + $followme_text .= "<br></span></a></td><td>"; + $followme_text .= "<input " . $follow_me_confirm . " type=checkbox name='follow_me_confirm' value='checked'>"; + $followme_text .= "<small>" . _("Enable") . "</small></td></tr>"; + $followme_text .= "<tr><td> </td></tr>"; // Blank Line + $followme_text .= "</table>"; + } + } + + } + + // build page content + $ret .= checkErrorMessage(); + + if ($_SESSION['ari_user']['admin_settings']) { + $headerText = _("Followme Settings"); + } else { + $headerText = sprintf(_("Followme Settings for %s (%s)"),$displayname,$exten); + } + + $ret .= $display->displayHeaderText($headerText); + $ret .= $display->displayLine(); + + $ret .= + "\n<SCRIPT LANGUAGE='JavaScript'> + <!-- Begin + function rowCounter(field, maxlimit) { + temp = field.value.split('\u000A',maxlimit+1) + field.value = temp.join('\u000A') + if (temp.length == maxlimit+1) { + field.value = field.value.substring(0, field.value.length-1) + } + } + // End --> + </script>\n"; + + $ret .= + "<form class='settings' name='ari_settings' action='' method='GET'> + <input type=hidden name=m value=" . $m . "> + <input type=hidden name=f value='action'> + <input type=hidden name=a value='update'> + " . $followme_text . " + <br> + <input name='submit' type='submit' value='" . _("Update") . "'> + </form>"; + + return $ret; + } + + + /* + * Sets Follow Me Pre-Ring Time + * + * @param $exten + * Extension to modify + * @param $follow_me_prering_time + * Pre-Ring Time to ring + */ + function setFollowMePreRingTime($exten,$follow_me_prering_time) { + + global $asterisk_manager_interface; + + $value_opt = $follow_me_prering_time; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/followme/prering $value_opt\r\n\r\n"); + } + + /* + * Gets Follow Me Pre-Ring Time if set + * + * @param $exten + * Extension to get information about + * @return $number + * follow me pre-ring time returned if set + */ + function getFollowMePreRingTime($exten) { + + global $asterisk_manager_interface; + + $number = ''; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/followme/prering\r\n\r\n"); + if (is_numeric($response)) { + $number = $response; + } + + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_follow_me_prering_time']); + if ($stripped==$number) { + $number = $_COOKIE['ari_follow_me_prering_time']; + } + + return $number; + } + + /* + * Sets Follow Me List Ring Time + * + * @param $exten + * Extension to modify + * @param $follow_me_listring_time + * List Ring Time to ring + */ + function setFollowMeListRingTime($exten,$follow_me_listring_time) { + + global $asterisk_manager_interface; + + $value_opt = $follow_me_listring_time; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/followme/grptime $value_opt\r\n\r\n"); + } + + /* + * Gets Follow Me List-Ring Time if set + * + * @param $exten + * Extension to get information about + * @return $number + * follow me list-ring time returned if set + */ + function getFollowMeListRingTime($exten) { + + global $asterisk_manager_interface; + + $number = ''; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/followme/grptime\r\n\r\n"); + if (is_numeric($response)) { + $number = $response; + } + + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_follow_me_listring_time']); + if ($stripped==$number) { + $number = $_COOKIE['ari_follow_me_listring_time']; + } + + return $number; + } + + /* + * Sets Follow Me List + * + * @param $exten + * Extension to modify + * @param $follow_me_list + * Follow Me List + */ + function setFollowMeList($exten,$follow_me_list) { + + global $asterisk_manager_interface; + + $value_opt = $follow_me_list; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/followme/grplist $value_opt\r\n\r\n"); + } + + /* + * Gets Follow Me List if set + * + * @param $exten + * Extension to get information about + * @return $data + * follow me list if set + */ + function getFollowMeList($exten) { + + global $asterisk_manager_interface; + + $number = ''; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/followme/grplist\r\n\r\n"); + + //TODO: really need to check for a bogus response, see how other side does it + // + return preg_replace("/[^0-9*\-]/", "", $response); + } + + /* + * Sets Follow Confirmation Setting + * + * @param $exten + * Extension to modify + * @param $follow_me_cofirm + * Follow Me Confirm Setting + */ + function setFollowMeConfirm($exten,$follow_me_confirm) { + + global $asterisk_manager_interface; + + $value_opt = ($follow_me_confirm)?'ENABLED':'DISABLED'; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/followme/grpconf $value_opt\r\n\r\n"); + } + + /* + * Gets Follow Me Confirmation Setting + * + * @param $exten + * Extension to get information about + * @return $data + * follow me confirm setting + */ + function getFollowMeConfirm($exten) { + + global $asterisk_manager_interface; + + $number = ''; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/followme/grpconf\r\n\r\n"); + + if (preg_match("/ENABLED/",$response)) { + $response='checked'; + } + else { + $response=''; + } + + //TODO: really need to check for a bogus response, see how other side does it + // + return $response; + + } + + /* + * Sets Follow Ddial Setting + * + * @param $exten + * Extension to modify + * @param $follow_me_ddial + * Follow Me Ddial Setting + */ + function setFollowMeDDial($exten,$follow_me_ddial) { + + global $asterisk_manager_interface; + + $value_opt = ($follow_me_ddial)?'DIRECT':'EXTENSION'; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/followme/ddial $value_opt\r\n\r\n"); + } + + /* + * Gets Follow Me Ddial Setting + * + * @param $exten + * Extension to get information about + * @return $data + * follow me ddial setting + */ + function getFollowMeDDial($exten) { + + global $asterisk_manager_interface; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/followme/ddial\r\n\r\n"); + + if (preg_match("/EXTENSION/",$response)) { + $response=''; + } + else { + $response='checked'; + } + + //TODO: really need to check for a bogus response, see how other side does it + // + return $response; + + } + + + + + + /* + * Gets FreePBX Version + */ + function getFreePBXVersion() { + + if (isset($_SESSION['dbh_asterisk'])) { + $sql = "SELECT * FROM admin WHERE variable = 'version'"; + $results = $_SESSION['dbh_asterisk']->getAll($sql); + if(DB::IsError($results)) { + $_SESSION['ari_error'] = $results->getMessage(); + } + + return $results[0][1]; + } + } + + /* + * Sets Follow-Me Settings in FreePBX MySQL Database + * + * @param $exten + * Extension to modify + * @param $follow_me_prering_time + * Pre-Ring Time to ring + * @param $follow_me_listring_time + * List Ring Time to ring + * @param $follow_me_list + * Follow Me List + * @param $follow_me_list + * Follow Me Confirm Setting + * + */ + function setFollowMeMySQL($exten, $follow_me_prering_time, $follow_me_listring_time, $follow_me_list, $follow_me_confirm) { + + if (isset($_SESSION['dbh_asterisk'])) { + + //format for SQL database + $follow_me_confirm = ($follow_me_confirm)?'CHECKED':''; + + $sql = "UPDATE findmefollow SET grptime = '" . $follow_me_listring_time . "', grplist = '". + str_replace("'", "''", trim($follow_me_list)) . "', pre_ring = '" . $follow_me_prering_time . + "', needsconf = '" . $follow_me_confirm . "' WHERE grpnum = $exten LIMIT 1"; + $results = $_SESSION['dbh_asterisk']->query($sql); + + if(DB::IsError($results)) { + $_SESSION['ari_error'] = $results->getMessage(); + } + + return 1; + } + } + + function lookupSetExtensionFormat($exten) { + + if (trim($exten) == "") return $exten; + + $exten = preg_replace("/[^0-9*]/", "", $exten); + + $sql = "SELECT extension FROM users WHERE extension = '".$exten."'"; + $asa = $_SESSION['dbh_asterisk']->getrow($sql, DB_FETCHMODE_ASSOC); + if (!is_array($asa)) { + return $exten.'#'; + } else { + return $exten; + } + } + + +} // class + +?> diff --git a/fs_selfservice/fri/modules/phonefeatures.module b/fs_selfservice/fri/modules/phonefeatures.module new file mode 100644 index 000000000..89dc903bf --- /dev/null +++ b/fs_selfservice/fri/modules/phonefeatures.module @@ -0,0 +1,342 @@ +<?php +//***************************************************************************** +class PhoneFeatures { +//***************************************************************************** + function rank() { + + $rank = 4; + return $rank; + } + +//***************************************************************************** + function init() { + } +//***************************************************************************** + function navMenu($args) { + + global $ARI_NO_LOGIN; + global $SETTINGS_ALLOW_PHONE_SETTINGS; + global $SETTINGS_ALLOW_CALLFORWARD_SETTINGS; + + // If we're not allowing call forwarding AND PHONE SETTINGS get out of here + if (!$SETTINGS_ALLOW_PHONE_SETTINGS && !$SETTINGS_ALLOW_CALLFORWARD_SETTINGS) return ""; + + $ret .= " + <p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=PhoneFeatures&f=display'>" . _("Phone Features") . "</a></small></small></p>"; + + return $ret; + } +//***************************************************************************** + function action($args) { + + global $ARI_ADMIN_USERNAME; + global $SETTINGS_ALLOW_PHONE_SETTINGS; + global $SETTINGS_ALLOW_CALLFORWARD_SETTINGS; + + // args + $m = getArgument($args,'m'); + $a = getArgument($args,'a'); + $lang_code = getArgument( $args,'lang_code'); + $exten = $_SESSION['ari_user']['extension']; + + if ($a=='update') { + + if ($SETTINGS_ALLOW_PHONE_SETTINGS) { + if ($exten!=$ARI_ADMIN_USERNAME) { + $this->storePhoneSetting( $args, $exten, 'call_waiting', 'CW', 'ENABLED'); + $this->storePhoneSetting( $args, $exten, 'do_not_disturb', 'DND', 'YES'); + } + } + + if ($SETTINGS_ALLOW_CALLFORWARD_SETTINGS) { + if ($exten!=$ARI_ADMIN_USERNAME) { + $this->storeCallForwardNumber( $args, $exten, 'call_forward', 'CF'); + $this->storeCallForwardNumber( $args, $exten, 'call_forward_busy', 'CFB'); + $this->storeCallForwardNumber( $args, $exten, 'call_forward_unavailable', 'CFU'); + } + } + } + + // redirect to see updated page + $ret .= " + <head> + <script> + <!-- + window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "\" + // --> + </script> + </head>"; + + return $ret; + } +//***************************************************************************** +function display($args) { + + global $STANDALONE; + global $ARI_ADMIN_USERNAME; + global $SETTINGS_ALLOW_PHONE_SETTINGS; + global $SETTINGS_ALLOW_CALLFORWARD_SETTINGS; + + // args + $m = getArgument($args,'m'); + $a = getArgument($args,'a'); + $lang_code = getArgument( $args,'lang_code'); + $exten = $_SESSION['ari_user']['extension']; + + $displayname = $_SESSION['ari_user']['displayname']; + $exten = $_SESSION['ari_user']['extension']; + + $display = new DisplaySearch(); + + // build controls + if ($exten!=$ARI_ADMIN_USERNAME) { + + if ($SETTINGS_ALLOW_PHONE_SETTINGS) { + $dnd_cw_text = "<table class='settings'>"; + $dnd_cw_text.= "<tr><td><h3>" . _("Phone Features") . "</h3></td></tr>"; + + $dnd_cw_text.= $this->displayPhoneControls( $exten, 'call_waiting', 'CW', "Call Waiting"); + $dnd_cw_text.= $this->displayPhoneControls( $exten, 'do_not_disturb', 'DND', "Do Not Disturb"); + + $dnd_cw_text .= "</table>"; + } + + if ($SETTINGS_ALLOW_CALLFORWARD_SETTINGS) { + + $set_call_forward_text .= "<SCRIPT LANGUAGE='JavaScript'> + <!-- Begin + function rowCounter(field, maxlimit) { + temp = field.value.split('\u000A',maxlimit+1) + field.value = temp.join('\u000A') + if (temp.length == maxlimit+1) { + field.value = field.value.substring(0, field.value.length-1) + } + } + + function disable_fields() { + + if (document.ari_settings.call_forward_enable.checked) { + document.ari_settings.call_forward_number.style.backgroundColor = '#FFF'; + document.ari_settings.call_forward_number.disabled = false; + } + else { + document.ari_settings.call_forward_number.style.backgroundColor = '#DDD'; + document.ari_settings.call_forward_number.disabled = true; + } + + if (document.ari_settings.call_forward_busy_enable.checked) { + document.ari_settings.call_forward_busy_number.style.backgroundColor = '#FFF'; + document.ari_settings.call_forward_busy_number.disabled = false; + } + else { + document.ari_settings.call_forward_busy_number.style.backgroundColor = '#DDD'; + document.ari_settings.call_forward_busy_number.disabled = true; + } + + if (document.ari_settings.call_forward_unavailable_enable.checked) { + document.ari_settings.call_forward_unavailable_number.style.backgroundColor = '#FFF'; + document.ari_settings.call_forward_unavailable_number.disabled = false; + } + else { + document.ari_settings.call_forward_unavailable_number.style.backgroundColor = '#DDD'; + document.ari_settings.call_forward_unavailable_number.disabled = true; + } + } + // End --> + </script>"; + + $set_call_forward_text.= "<table class='settings'>"; + $set_call_forward_text.= "<tr><td><h3>" . _("Call Forwarding") . "</h3></td></tr>"; + + $set_call_forward_text.= $this->displayCallForwardControls( $exten, 'call_forward', 'CF', "Unconditional:"); + $set_call_forward_text.= $this->displayCallForwardControls( $exten, 'call_forward_unavailable', 'CFU', "Unavailable:"); + $set_call_forward_text.= $this->displayCallForwardControls( $exten, 'call_forward_busy', 'CFB', "Busy:"); + + $set_call_forward_text .= "</table>"; + } + } + + // build page content + $ret .= checkErrorMessage(); + + if ($_SESSION['ari_user']['admin_settings']) { + $headerText = _("Phone Features"); + } else { + $headerText = sprintf(_("Phone Features for %s (%s)"),$displayname,$exten); + } + + $ret .= $display->displayHeaderText($headerText); + $ret .= $display->displayLine(); + $ret .= " + <form class='settings' name='ari_settings' action='' method='GET'> + <input type=hidden name=m value=" . $m . "> + <input type=hidden name=f value='action'> + <input type=hidden name=a value='update'> + <br> + " . $dnd_cw_text . " + <br> + " . $set_call_forward_text . " + <br> + <input name='submit' type='submit' value='" . _("Update") . "'> + </form>"; + +return $ret; +} +//***************************************************************************** + function setPhoneSetting( $databaseCallFwdType, $exten, $state_value) { + + global $asterisk_manager_interface; + + $type_opt = ($state_value != "") ? "put":"del"; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database $type_opt $databaseCallFwdType $exten $state_value\r\n\r\n"); + } + +//***************************************************************************** + function getPhoneSetting($exten, $databaseCallFwdType) { + + global $asterisk_manager_interface; + $number = ''; + + $result = false; + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get $databaseCallFwdType $exten\r\n\r\n"); + if (stristr($response, 'ENABLED')) { + $result = true; + } + elseif (stristr($response, 'YES')) { + $result = true; + } + + return $result; + } +//***************************************************************************** + function storePhoneSetting( $args, $exten, $settingType, $databaseCallFwdType, $state_value) + { + $setting_enable = getArgument( $args, $settingType . '_enable'); + + $this->setPhoneSetting( $databaseCallFwdType, $exten, ($setting_enable == 'checked')?$state_value:""); + } + +//***************************************************************************** + function displayPhoneControls( $exten, $callFwdType, $databaseCallFwdType, $title) + { + + $phone_setting_enable = ($this->getPhoneSetting($exten, $databaseCallFwdType)) ? 'checked':''; + + $ret = "\n<tr>"; + $ret.= "<td>"; + $ret.= "<label><input " . $phone_setting_enable . " type=checkbox name='" . $callFwdType . "_enable' value='checked' >"; + $ret.= "<small>" . _($title) . "</small></label>"; + $ret.= "</td>"; + $ret.= "</tr>\n"; + + return $ret; + } +//***************************************************************************** + /* + * Sets Asterisk call forward setting + * + * @param $exten + * Extension to modify + * @param $state + * Call forward enable or disable + * @param $call_forward_number + * Call forward number + * @param $variable_opt + * Call forward type (CF, CFU, CFB) + */ + function setCallForward($exten,$state,$call_forward_number, $variable_opt = "CF") { + + global $asterisk_manager_interface; + + if ($state) { + $type_opt = "put"; + $value_opt = $call_forward_number; + } + else { + $type_opt = "del"; + } + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database $type_opt $variable_opt $exten $value_opt\r\n\r\n"); + } + + /* + * Gets call forward number if set + * + * @param $exten + * Extension to get information about + * @return $number + * call forward number returned if set + * @param $variable_opt + * Call forward type (CF, CFU, CFB) + */ + function getCallForwardNumber($exten, $variable_opt = "CF") { + + global $asterisk_manager_interface; + + $number = ''; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get $variable_opt $exten\r\n\r\n"); + if (is_numeric($response)) { + $number = $response; + } + + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_call_forward_number']); + if ($stripped==$number) { + $number = $_COOKIE['ari_call_forward_number']; + } + + return $number; + } + + + function storeCallForwardNumber( $args, $exten, $callFwdType, $databaseCallFwdType) + { + $call_forward_enable = getArgument($args, $callFwdType . '_enable'); + $call_forward_number = getArgument($args, $callFwdType . '_number'); + + $stripped_call_forward_number = preg_replace('/-|\(|\)|\s/','',$call_forward_number); + + if ($call_forward_enable && !is_numeric($stripped_call_forward_number)) { + $_SESSION['ari_error'] = _("Call forward number not changed") . "<br>" . + sprintf(_("Number %s must contain dial numbers (characters like '(', '-', and ')' are ok)"), $call_forward_number); + } + else { + $this->setCallForward( $exten, $call_forward_enable, $stripped_call_forward_number, $databaseCallFwdType); + + // store cookie + $stripped = preg_replace('/-|\(|\)|\s/','',$_COOKIE['ari_' . $callFwdType]); + if ($call_forward_number && $stripped!=$stripped_call_forward_number) { + setcookie('ari_' . $callFwdType, $call_forward_number, time()+365*24*60*60); + } + } + } + + function displayCallForwardControls( $exten, $callFwdType, $databaseCallFwdType, $title) + { + $call_forward_number = $this->getCallForwardNumber($exten, $databaseCallFwdType); + + // If we have a value, we want the item checked + if ($call_forward_number) { + $call_forward_enable = 'checked'; + } + else { + $call_forward_number = $_COOKIE['ari_' . $callFwdType ]; + $call_forward_text_box_options = "disabled style='background: #DDD;'"; + } + + $ret = "\n<tr>"; + $ret.= "<td>" . _($title) . "</td>"; + $ret.= "<td>"; + $ret.= "<input " . $call_forward_text_box_options . " name='" . $callFwdType . "_number' type='text' size=24 value='" . $call_forward_number . "'>"; + $ret.= "</td>"; + $ret.= "<td>"; + $ret.= "<input " . $call_forward_enable . " type=checkbox name='" . $callFwdType . "_enable' value='checked' OnClick=\"disable_fields(); return true;\">"; + $ret.= "<small>" . _("Enable") . "</small>"; + $ret.= "</td>"; + $ret.= "</tr>\n"; + + return $ret; + } +} // class +?> diff --git a/fs_selfservice/fri/modules/settings.module b/fs_selfservice/fri/modules/settings.module new file mode 100644 index 000000000..314ce40c5 --- /dev/null +++ b/fs_selfservice/fri/modules/settings.module @@ -0,0 +1,813 @@ +<?php + +/** + * @file + * Functions for the interface to the call monitor recordings + */ + +/** + * Class for settings + */ +class Settings { + + var $protocol_table; + var $protocol_config_files; + + /* + * rank (for prioritizing modules) + */ + function rank() { + + $rank = 9; + return $rank; + } + + /* + * init + */ + function init() { + + // determine what protocol user is using + global $ASTERISK_PROTOCOLS; + + foreach ($ASTERISK_PROTOCOLS as $protocol => $value) { + $data = $this->getProtocolRecordSettings($value['table'],$_SESSION['ari_user']['extension']); + if (count($data)) { + $this->protocol_table = $value['table']; + $this->protocol_config_files = $value['config_files']; + break; + } + } + } + + /* + * Adds menu item to nav menu + * + * @param $args + * Common arguments + */ + function navMenu($args) { + + $ret = ""; + $exten = $_SESSION['ari_user']['extension']; + + // and we are not logged in as admin + if ($exten!=$ARI_ADMIN_USERNAME) { + $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Settings&f=display'>" . _("Settings") . "</a></small></small></p><br>"; + } + + return $ret; + } + + /* + * Acts on the user settings + * + * @param $args + * Common arguments + * @param $a + * action + */ + function action($args) { + + global $ARI_ADMIN_USERNAME; + global $ASTERISK_VOICEMAIL_CONF; + global $SETTINGS_ALLOW_VOICEMAIL_SETTINGS; + global $SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET; + global $SETTINGS_VOICEMAIL_PASSWORD_LENGTH; + global $SETTINGS_VOICEMAIL_PASSWORD_EXACT; + global $SETTINGS_ALLOW_CALL_RECORDING_SET; + + // args + $m = getArgument($args,'m'); + $a = getArgument($args,'a'); + + $voicemail_password = getArgument($args,'voicemail_password'); + $voicemail_password_confirm = getArgument($args,'voicemail_password_confirm'); + $voicemail_email_address = getArgument($args,'voicemail_email_address'); + $voicemail_pager_address = getArgument($args,'voicemail_pager_address'); + $voicemail_email_enable = getArgument($args,'voicemail_email_enable'); + $voicemail_audio_format = getArgument($args,'voicemail_audio_format'); + $record_in = getArgument($args,'record_in'); + $record_out = getArgument($args,'record_out'); + + if (isset($_SESSION['ari_user']['voicemail_email'])) { + foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) { + $var = "voicemail_email_$key"; + $$var = getArgument($args,$var); + } + } + + if ($a=='update') { + + $exten = $_SESSION['ari_user']['extension']; + if ($exten!=$ARI_ADMIN_USERNAME) { + + // Make sure Follow-Me setup has not been deleted for this user since the last refresh + $follow_me_disabled_delayed = $_COOKIE['ari_follow_me_disabled']; + + // voicemail settings + if ($SETTINGS_ALLOW_VOICEMAIL_SETTINGS && $_SESSION['ari_user']['voicemail_enabled']==1) { + + + // update voicemail password + if ($SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET) { + + // update voicemail password + if ($voicemail_password=='' || $voicemail_password_confirm=='') { + $_SESSION['ari_error'] = + _("Voicemail password not changed") . "<br>" . + _("Password and password confirm must not be blank"); + } + else if ((strlen($voicemail_password)<$SETTINGS_VOICEMAIL_PASSWORD_LENGTH) || !is_numeric($voicemail_password)) { + $_SESSION['ari_error'] = + _("Voicemail password not changed") . "<br>" . + sprintf(_("Passwords must be all numbers and greater than %d digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH); + } + else if (strlen($voicemail_password)!=$SETTINGS_VOICEMAIL_PASSWORD_LENGTH && $SETTINGS_VOICEMAIL_PASSWORD_EXACT || !is_numeric($voicemail_password)) { + $_SESSION['ari_error'] = + _("Voicemail password not changed") . "<br>" . + sprintf(_("Passwords must be all numbers and only %d digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH); + } + else if ($voicemail_password!=$voicemail_password_confirm) { + $_SESSION['ari_error'] = + _("Voicemail password not changed") . "<br>" . + _("Password and password confirm do not match"); + } + else { + + // check for writable the files + $temp_file = $ASTERISK_VOICEMAIL_CONF . ".tmp"; + $fp = fopen($temp_file, "w"); + if (!$fp) { + $_SESSION['ari_error'] = + _("Voicemail password not changed") . "<br>" . + sprintf(_("%s does not exist or is not writable"),$temp_file); + } + else if (!is_writable($ASTERISK_VOICEMAIL_CONF)) { + $_SESSION['ari_error'] = + _("Voicemail password not changed") . "<br>" . + sprintf(_("%s does not exist or is not writable"),$ASTERISK_VOICEMAIL_CONF); + } + else { + + // update session + $_SESSION['ari_user']['voicemail_password'] = $voicemail_password; + + // save password + $lines = file($ASTERISK_VOICEMAIL_CONF); + foreach ($lines as $key => $line) { + unset($value); + list($var,$value) = split('=>',$line); + $var = trim($var); + if ($var==$exten && $value) { + + // write out line with password change + $buf = split(',',$value); + $buf[0] = $voicemail_password; + $line = $var . " => " . join(',', $buf); + + fwrite($fp, $line); + } + else { + // write out original line with no changes + fwrite($fp, $line); + } + } + fclose($fp); + unlink($ASTERISK_VOICEMAIL_CONF); + rename($temp_file,$ASTERISK_VOICEMAIL_CONF); + + $voicemail_reload = 1; + } + } + + // voicemail email address + if ($voicemail_email_enable && + ($voicemail_email_address && !preg_match('/@/',$voicemail_email_address) || + ($voicemail_pager_address && !preg_match('/@/',$voicemail_pager_address)))) { + $_SESSION['ari_error'] = + _("Voicemail email and pager address not changed") . "<br>" . + ("'$voicemail_email_address' and '$voicemail_pager_address' must be a valid email addresses"); + } + else { + + // check for writable the files + $temp_file = $ASTERISK_VOICEMAIL_CONF . ".tmp"; + $fp = fopen($temp_file, "w"); + if (!$fp) { + $_SESSION['ari_error'] = + _("Voicemail email settings not changed") . "<br>" . + sprintf(_("%s does not exist or is not writable"),$temp_file); + } + else if (!is_writable($ASTERISK_VOICEMAIL_CONF)) { + $_SESSION['ari_error'] = + _("Voicemail email settings not changed") . "<br>" . + sprintf(_("%s does not exist or is not writable"),$ASTERISK_VOICEMAIL_CONF); + } + else { + + // store cookie + if ($voicemail_email_enable) { + setcookie("ari_voicemail_email_address", $voicemail_email_address, time()+365*24*60*60); + setcookie("ari_voicemail_pager_address", $voicemail_pager_address, time()+365*24*60*60); + foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) { + $var = "voicemail_email_$key"; + $var_cookie = "ari_" . $var; + setcookie("$var_cookie", $$var, time()+365*24*60*60); + } + } + + // update session + $_SESSION['ari_user']['voicemail_email_enable'] = $voicemail_email_enable; + if ($voicemail_email_enable) { + $_SESSION['ari_user']['voicemail_email_address'] = $voicemail_email_address; + $_SESSION['ari_user']['voicemail_pager_address'] = $voicemail_pager_address; + foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) { + $option = "voicemail_email_$key"; + $_SESSION['ari_user']['voicemail_email'][$key] = $$option; + } + } + + // save settings + if (!$voicemail_email_enable) { + $voicemail_email_address = ''; + $voicemail_pager_address = ''; + } + + $lines = file($ASTERISK_VOICEMAIL_CONF); + foreach ($lines as $key => $line) { + unset($value); + list($var,$value) = split('=>',$line); + $var = trim($var); + if ($var==$exten && $value) { + + // write out line with voicemail email change + $buf = split(',',$value); + $buf[2] = $voicemail_email_address; + $buf[3] = $voicemail_pager_address; + + foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) { + $option = "voicemail_email_$key"; + if ($$option && $key) { + $options .= $key . "=" . $value; + } + else { + $options .= $key . "=no"; + } + $options .= "|"; + } + $buf[4] = substr($options, 0, -1); + + $line = $var . " =>" . join(',', $buf); + if (substr($line, 0, -1)!="\n") { + $line .= "\n"; + } + + fwrite($fp, $line); + } + else { + + // write out original line with no changes + fwrite($fp, $line); + } + } + fclose($fp); + unlink($ASTERISK_VOICEMAIL_CONF); + rename($temp_file,$ASTERISK_VOICEMAIL_CONF); + + $voicemail_reload = 1; + } + } + + // reload asterisk voicemail + if ($voicemail_reload) { + $this->reloadAsteriskVoicemail(); + } + } + + // update voicemail audio format setting + setcookie("ari_voicemail_audio_format", $voicemail_audio_format, time()+365*24*60*60); + } + + // update call monitor record setting + if ($SETTINGS_ALLOW_CALL_RECORDING_SET) { + if ($record_in && $record_out) { + $this->setRecordSettings($exten,$record_in,$record_out); + } + } + } + } + + // redirect to see updated page + $ret .= " + <head> + <script> + <!-- + window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "\" + // --> + </script> + </head>"; + + return $ret; + } + + /* + * Displays stats page + * + * @param $args + * Common arguments + */ + function display($args) { + global $SETTINGS_ALLOW_VOICEMAIL_SETTINGS; + global $SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET; + global $SETTINGS_VOICEMAIL_PASSWORD_LENGTH; + global $SETTINGS_VOICEMAIL_EMAIL_OPTION_DESCRIPTIONS; + global $ARI_VOICEMAIL_AUDIO_FORMAT_DEFAULT; + global $SETTINGS_ALLOW_CALL_RECORDING_SET; + + global $loaded_modules; + + // args + $m = getArgument($args,'m'); + $q = getArgument($args,'q'); + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + + $displayname = $_SESSION['ari_user']['displayname']; + $exten = $_SESSION['ari_user']['extension']; + + $language = new Language(); + $display = new DisplaySearch(); + + // get data + $data = $this->getRecordSettings($_SESSION['ari_user']['extension']); + + // lang setting options + if (extension_loaded('gettext')) { + $setLangText = "<p class='lang'>" . _("Language:") . " " . $language->GetForm() . "</p>"; + } + + + // voicemail settings + if ($SETTINGS_ALLOW_VOICEMAIL_SETTINGS && $_SESSION['ari_user']['voicemail_enabled']==1 && + in_array('voicemail',array_keys($loaded_modules))) { + if ($SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET) { + + if ($SETTINGS_VOICEMAIL_PASSWORD_EXACT) { + $voicemail_password_length_message = sprintf(_("Passwords must be all numbers and only %s digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH); + } + else { + $voicemail_password_length_message = sprintf(_("Passwords must be all numbers and at least %s digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH); + } + + $set_voicemail_password_text = " + <tr> + <td>" . _("Voicemail Password:") . "</td> + <td> + <input name='voicemail_password' type='password' size=16 value=" . $_SESSION['ari_user']['voicemail_password'] . "> + </td> + </tr> + <tr> + <td>" . _("Enter again to confirm:") . "</td> + <td> + <input name='voicemail_password_confirm' type='password' size=16 value=" . $_SESSION['ari_user']['voicemail_password'] . "> + </td> + </tr> + <tr> + <td class='note' colspan=2><small>" . $voicemail_password_length_message . "</small></td> + </tr>"; + } + + if (isset($_SESSION['ari_user']['voicemail_email'])) { + + if ($_SESSION['ari_user']['voicemail_email_enable']) { + $voicemail_email_address = $_SESSION['ari_user']['voicemail_email_address']; + $voicemail_pager_address = $_SESSION['ari_user']['voicemail_pager_address']; + $voicemail_email_enable = 'checked'; + + foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) { + $var = "voicemail_email_$key"; + $var_enable = $var . "enable"; + if ($_SESSION['ari_user']['voicemail_email'][$key]=='yes') { + $$var_enable = 'checked'; + } + } + } + else { + + $voicemail_email_address = $_COOKIE['ari_voicemail_email_address']; + $voicemail_email_text_box_options = "disabled style='background: #DDD;'"; + $voicemail_pager_address = $_COOKIE['ari_voicemail_pager_address']; + $voicemail_pager_text_box_options = "disabled style='background: #DDD;'"; + + foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) { + $var = "voicemail_email_$key"; + $var_cookie = "ari_" . $var; + $var_enable = $var . "enable"; + $var_text_box_options = $var . "text_box_options"; + + $$var_text_box_options = "disabled"; + if ($_COOKIE[$var_cookie]=='yes') { + $$var_enable = 'checked'; + } + } + } + + $set_voicemail_email_text = " + + <tr> + <td> " . _("Email Notification") . " <input " . $voicemail_email_enable . " type=checkbox name='voicemail_email_enable' value='1' OnClick=\"disable_fields(); return true;\"> + <small> " ._("Enable") . " </small> + </td> + </tr><tr> + <td><a href='#' class='info'>" . _("Email Voicemail To:") . "<span>" . ("Email a notification, including audio file if indicated below.") . " </span></a></td> + <td> + <input " . $voicemail_email_text_box_options . " name='voicemail_email_address' type='text' size=48 value='" . $voicemail_email_address . "'> + </td> + </tr> + <tr> + <td><a href='#' class='info'>" . _("Pager Email Notification To:") . "<span>" . ("Email a short notification") . " </span></a></td> + <td> + <input " . $voicemail_pager_text_box_options . " name='voicemail_pager_address' type='text' size=48 value='" . $voicemail_pager_address . "'> + </td> + </tr> + <tr> + <td></td> + </tr>"; + + foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) { + + $var = "voicemail_email_$key"; + $var_enable = $var . "enable"; + $var_text_box_options = $var . "text_box_options"; + if ($SETTINGS_VOICEMAIL_EMAIL_OPTION_DESCRIPTIONS[$key]) { + $var_text = $SETTINGS_VOICEMAIL_EMAIL_OPTION_DESCRIPTIONS[$key]; + } + else { + $var_text = $key; + } + + if ($value != 'yes' && $value != 'no' && $value !='') { + + $size = strlen($value) - 1; + $set_voicemail_email_text .= " + <tr> + <td></td> + <td> + <input type=text size='" . $size . "' name='" . $var . "' value='" . $value . "' OnClick=\"disable_fields(); return true;\"> + <small>" . $var_text . "</small> + </td> + </tr>"; + } + else { + + $set_voicemail_email_text .= " + <tr> + <td></td> + <td> + <input " . $$var_enable . " " . $$var_text_box_options . " type=checkbox name='" . $var . "' value='yes' OnClick=\"disable_fields(); return true;\"> + <small>" . $var_text . "</small> + </td> + </tr>"; + } + } + } + + $wav_enable = 'selected'; + if ($_COOKIE['ari_voicemail_audio_format']=='.gsm'|| + ($_COOKIE['ari_voicemail_audio_format']=='' && $ARI_VOICEMAIL_AUDIO_FORMAT_DEFAULT='.gsm')) { + $wav_enable = ''; + $gsm_enable = 'selected'; + } + + $set_voicemail_audio_format_text = " + <tr> + <td>" . _("Audio Format:") . "</td> + <td> + <select name='voicemail_audio_format'> + <option value='.wav' " . $wav_enable . ">" . _("Best Quality") . " (.wav)</option> + <option value='.gsm' " . $gsm_enable . ">" . _("Smallest Download") . " (.gsm)</option> + </select> + </td> + </tr>"; + + $set_voicemail_text = " + <table class='settings'> + <tr> + <td><h3>" . _("Voicemail Settings") . "</h3></td> + </tr> + " . $set_voicemail_password_text . " + " . $set_voicemail_email_text . " + " . $set_voicemail_audio_format_text . " + </table>"; + } + + // call monitor settings + if ($this->getFreePBXVersion() && + $SETTINGS_ALLOW_CALL_RECORDING_SET && + in_array('callmonitor',array_keys($loaded_modules))) { + + foreach($data as $key=>$value) { + if ($key=='record_in') { + if ($value=='Always') { + $ri_always = 'checked=checked'; + } + elseif ($value=='Never') { + $ri_never = 'checked=checked'; + } + elseif ($value=='Adhoc') { + $ri_on_demand = 'checked=checked'; + } + } + if ($key=='record_out') { + if ($value=='Always') { + $ro_always = 'checked=checked'; + } + elseif ($value=='Never') { + $ro_never = 'checked=checked'; + } + elseif ($value=='Adhoc') { + $ro_on_demand = 'checked=checked'; + } + } + } + + $set_callmonitor_text = " + <table class='settings'> + <tr> + <td><h3>" . _("Call Monitor Settings") . "</h3></td> + </tr> + <tr> + <td>" . _("Record INCOMING:") . " </td> + <td> + <input type='radio' name='record_in' value='Always' " . $ri_always . "/> " . _("Always") . " + <input type='radio' name='record_in' value='Never' " . $ri_never . "/> " . _("Never") . " + <input type='radio' name='record_in' value='Adhoc' " . $ri_on_demand . "/> " . _("On-Demand") . " + </td> + </tr> + <tr> + <td>" . _("Record OUTGOING:") . " </td> + <td> + <input type='radio' name='record_out' value='Always' " . $ro_always . "/> " . _("Always") . " + <input type='radio' name='record_out' value='Never' " . $ro_never . "/> " . _("Never") . " + <input type='radio' name='record_out' value='Adhoc' " . $ro_on_demand . "/> " . _("On-Demand") . " + </td> + </tr> + </table>"; + } + + // javascript enable options + if (isset($_SESSION['ari_user']['voicemail_email']) && + in_array('voicemail',array_keys($loaded_modules))) { + foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) { + $var = "voicemail_email_$key"; + $js_voicemail_email_disable .= " + document.ari_settings.$var.disabled = false;"; + $js_voicemail_email_enable .= " + document.ari_settings.$var.disabled = true;"; + } + + $js_voicemail_script = " + if (document.ari_settings.voicemail_email_enable.checked) { + document.ari_settings.voicemail_email_address.style.backgroundColor = '#FFF'; + document.ari_settings.voicemail_email_address.disabled = false; + document.ari_settings.voicemail_email_address.value='" . $voicemail_email_address . "'; + document.ari_settings.voicemail_pager_address.style.backgroundColor = '#FFF'; + document.ari_settings.voicemail_pager_address.disabled = false; + document.ari_settings.voicemail_pager_address.value='" . $voicemail_pager_address . "'; + " . $js_voicemail_email_disable . " + } + else { + document.ari_settings.voicemail_email_address.style.backgroundColor = '#DDD'; + document.ari_settings.voicemail_email_address.disabled = true; + document.ari_settings.voicemail_pager_address.style.backgroundColor = '#DDD'; + document.ari_settings.voicemail_pager_address.disabled = true; + " . $js_voicemail_email_enable . " + }"; + } + + // build page content + $ret .= checkErrorMessage(); + + $headerText = sprintf(_("Settings for %s (%s)"),$displayname,$exten); + + $ret .= $display->displayHeaderText($headerText); + $ret .= $display->displayLine(); + + $ret .= " + <SCRIPT LANGUAGE='JavaScript'> + <!-- Begin + function rowCounter(field, maxlimit) { + temp = field.value.split('\u000A',maxlimit+1) + field.value = temp.join('\u000A') + if (temp.length == maxlimit+1) { + field.value = field.value.substring(0, field.value.length-1) + } + } + + function disable_fields() {"; + $ret .= $js_voicemail_script . " + } + // End --> + </script>"; + + $ret .= " + " . $setLangText . " + <form class='settings' name='ari_settings' action='' method='GET'> + <input type=hidden name=m value=" . $m . "> + <input type=hidden name=f value='action'> + <input type=hidden name=a value='update'> + <br> + " . $set_voicemail_text . " + <br> + " . $set_callmonitor_text . " + <br> + <input name='submit' type='submit' value='" . _("Update") . "'> + </form>"; + + return $ret; + } + + + + + + + /* + * Sets Asterisk call recording setting + * + * @param $exten + * Extension to modify + * @param $direction + * Call direction + * @param $state + * State to set to + */ + function setRecordSettings($exten,$state_in,$state_out) { + + global $asterisk_manager_interface; + + if (version_compare($this->getFreePBXVersion(), '1.10', '<')) { + + if ($state_in=="Always") { + $type_opt = "put"; + $value_opt = " " . "ENABLED"; + } + elseif ($state_in=="Never") { + $type_opt = "put"; + $value_opt = " " . "DISABLED"; + } + else { + $type_opt = "del"; + $value_opt = ""; + } + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database $type_opt RECORD-IN $exten $value_opt\r\n\r\n"); + + if ($state_out=="Always") { + $type_opt = "put"; + $value_opt = " " . "ENABLED"; + } + elseif ($state_out=="Never") { + $type_opt = "put"; + $value_opt = " " . "DISABLED"; + } + else { + $type_opt = "del"; + $value_opt = ""; + } + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database $type_opt RECORD-OUT $exten $value_opt\r\n\r\n"); + } + else { + + $value_opt= "out=".$state_out."|in=".$state_in; + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/recording $value_opt\r\n\r\n"); + } + } + + /* + * Gets record settings for a protocol + * + * @param $table + * Table to pull information from + * @param $exten + * Extension to get information about + * @return $data + * call monitor record settings + */ + function getProtocolRecordSettings($table,$exten) { + + global $asterisk_manager_interface; + + $data = array(); + + if (version_compare($this->getFreePBXVersion(), '1.10', '<')) { + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get RECORD-IN $exten\r\n\r\n"); + if (preg_match("/ENABLED/",$response)) { + $data['record_in'] = 'Always'; + } + elseif (preg_match("/DISABLED/",$response)) { + $data['record_in'] = 'Never'; + } + else { + $data['record_in'] = 'Adhoc'; + } + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get RECORD-OUT $exten\r\n\r\n"); + if (preg_match("/ENABLED/",$response)) { + $data['record_out'] = 'Always'; + } + elseif (preg_match("/DISABLED/",$response)) { + $data['record_out'] = 'Never'; + } + else { + $data['record_out'] = 'Adhoc'; + } + } + else { + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/recording\r\n\r\n"); + if (strstr($response,"in=Always")) { + $data['record_in'] = 'Always'; + } + elseif (strstr($response,"in=Never")) { + $data['record_in'] = 'Never'; + } + else { + $data['record_in'] = 'Adhoc'; + } + if (strstr($response,"out=Always")) { + $data['record_out'] = 'Always'; + } + elseif (strstr($response,"out=Never")) { + $data['record_out'] = 'Never'; + } + else { + $data['record_out'] = 'Adhoc'; + } + } + + return $data; + } + + /* + * Gets record settings + * + * @param $exten + * Extension to get information about + * @param $data + * Reference to the variable to store the data in + */ + function getRecordSettings($exten) { + + // check protocol tables first + $data = $this->getProtocolRecordSettings($this->protocol_table,$exten); + + return $data; + } + + /* + * Reloads Asterisk Configuration + */ + function reloadAsteriskVoicemail() { + + global $asterisk_manager_interface; + + $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: Reload app_voicemail.so\r\n\r\n"); + } + + /* + * Gets FreePBX Version + */ + function getFreePBXVersion() { + + if (isset($_SESSION['dbh_asterisk'])) { + $sql = "SELECT * FROM admin WHERE variable = 'version'"; + $results = $_SESSION['dbh_asterisk']->getAll($sql); + if(DB::IsError($results)) { + $_SESSION['ari_error'] = $results->getMessage(); + } + + return $results[0][1]; + } + } + + function lookupSetExtensionFormat($exten) { + + if (trim($exten) == "") return $exten; + + $exten = preg_replace("/[^0-9*]/", "", $exten); + + $sql = "SELECT extension FROM users WHERE extension = '".$exten."'"; + $asa = $_SESSION['dbh_asterisk']->getrow($sql, DB_FETCHMODE_ASSOC); + if (!is_array($asa)) { + return $exten.'#'; + } else { + return $exten; + } + } + + +} // class + +?> diff --git a/fs_selfservice/fri/modules/voicemail.module b/fs_selfservice/fri/modules/voicemail.module new file mode 100644 index 000000000..aad14564f --- /dev/null +++ b/fs_selfservice/fri/modules/voicemail.module @@ -0,0 +1,805 @@ +<?php + +/** + * @file + * Functions for the interface to the voicemail recordings + */ + +/** + * Class for voicemail + */ +class Voicemail { + + /* + * rank (for prioritizing modules) + */ + function rank() { + + $rank = 1; + return $rank; + } + + /* + * init + */ + function init() { + } + + /* + * Adds menu item to nav menu + * + * @param $args + * Common arguments + */ + function navMenu($args) { + + global $ARI_NO_LOGIN; + + // check logout + if ($_SESSION['ari_user'] && !$ARI_NO_LOGIN) { + $logout = 1; + } + + if ($logout!='') { + $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Voicemail&f=display'>" . _("Voicemail") . "</a></small></small></p>"; + } + + return $ret; + } + + /* + * Deletes selected voicemails and updates page + * + * @param $args + * Common arguments + */ + function navSubMenu($args) { + + global $ASTERISK_VOICEMAIL_PATH; + global $ASTERISK_VOICEMAIL_FOLDERS; + + // args + $m = getArgument($args,'m'); + $q = getArgument($args,'q'); + $current_folder = getArgument($args,'folder'); + + $context = $_SESSION['ari_user']['context']; + $extension = $_SESSION['ari_user']['extension']; + + // check for voicemail enabled or admin + if ($_SESSION['ari_user']['voicemail_enabled']!=1 || + $extension=='admin') { + return; + } + + // make folder list + $paths = split(';',$ASTERISK_VOICEMAIL_PATH); + $i = 0; + while ($ASTERISK_VOICEMAIL_FOLDERS[$i]) { + + $f = $ASTERISK_VOICEMAIL_FOLDERS[$i]['folder']; + $fn = $ASTERISK_VOICEMAIL_FOLDERS[$i]['name']; + + foreach($paths as $key => $path) { + + $path = appendPath($path,$context); + $path = appendPath($path,$extension); + + if (is_dir($path) && is_readable($path)) { + $dh = opendir($path); + while (false!== ($folder = readdir($dh))) { + + $folder_path = AppendPath($path,$folder); + + if($folder!="." && $folder!=".." && + filetype($folder_path)=='dir') { + + if ($f==$folder) { + + // get message count + $indexes = $this->getVoicemailIndex($folder_path,$q,$order,$sort); + $record_count = 0; + $record_count += $this->getVoicemailCount($indexes); + + // set current folder color + $class=''; + if ($current_folder==$folder || + ($current_folder=='' && $ASTERISK_VOICEMAIL_FOLDERS[0]['folder']==$folder)) { + $class = "class='current'"; + } + + // add folder to list + $ret .= "<p><small><small> + <a " . $class . " href='" . $_SESSION['ARI_ROOT'] . "?m=Voicemail&q=" . $q . "&folder=" . $f. "'> + " . $fn . " (" . $record_count . ")" . " + </a> + </small></small></p>"; + } + } + } + } + } + $i++; + } + + return $ret; + } + + /* + * Acts on the selected voicemails in the method indicated by the action and updates page + * + * @param $args + * Common arguments + */ + function msgAction($args) { + + global $ASTERISK_VOICEMAIL_FOLDERS; + + // args + $m = getArgument($args,'m'); + $a = getArgument($args,'a'); + $folder = getArgument($args,'folder'); + $q = getArgument($args,'q'); + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + $order = getArgument($args,'order'); + $sort = getArgument($args,'sort'); + + // get files + $files = array(); + foreach($_REQUEST as $key => $value) { + if (preg_match('/selected/',$key)) { + array_push($files, $value); + } + } + + if ($a=='delete') { + $this->deleteVoicemailData($files); + } + else if ($a=='move_to') { + $folder_rx = getArgument($args,'folder_rx'); + if ($folder_rx=='') { + $_SESSION['ari_error'] + = _("A folder must be selected before the message can be moved."); + } + else { + $context = $_SESSION['ari_user']['context']; + $extension = $_SESSION['ari_user']['extension']; + $this->moveVoicemailData($files, $context, $extension, $folder_rx); + } + } + else if ($a=='forward_to') { + + $mailbox_rx = getArgument($args,'mailbox_rx'); + list($context_rx,$extension_rx) = split('/',$mailbox_rx); + if ($extension_rx=='') { + $_SESSION['ari_error'] + = _("An extension must be selected before the message can be forwarded."); + } + else { + $folder_rx = $ASTERISK_VOICEMAIL_FOLDERS[0]['folder']; + $this->moveVoicemailData($files, $context_rx, $extension_rx, $folder_rx); + } + } + + // redirect to see updated page + $ret .= " + <head> + <script> + <!-- + window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&folder=" . $folder . "&q=" . $q . "&start=" . $start . "&span=" . $span . "&order=" . $order . "&sort=" . $sort . "\" + // --> + </script> + </head>"; + + return $ret; + } + + /* + * Displays stats page + * + * @param $args + * Common arguments + */ + function display($args) { + + global $ASTERISK_VOICEMAIL_CONF; + global $ASTERISK_VOICEMAIL_PATH; + global $ASTERISK_VOICEMAIL_FOLDERS; + global $AJAX_PAGE_REFRESH_ENABLE; + + $voicemail_audio_format = $_COOKIE['ari_voicemail_audio_format']; + + $display = new DisplaySearch(); + + // args + $m = getArgument($args,'m'); + $f = getArgument($args,'f'); + $q = getArgument($args,'q'); + $start = getArgument($args,'start'); + $span = getArgument($args,'span'); + $order = getArgument($args,'order'); + $sort = getArgument($args,'sort'); + + $start = $start=='' ? 0 : $start; + $span = $span=='' ? 15 : $span; + $order = $order=='' ? 'calldate' : $order; + $sort = $sort=='' ? 'desc' : $sort; + + $paths = split(';',$ASTERISK_VOICEMAIL_PATH); + + $displayname = $_SESSION['ari_user']['displayname']; + $extension = $_SESSION['ari_user']['extension']; + $context = $_SESSION['ari_user']['context']; + $folder = getArgument($args,'folder'); + if (!$folder) { + $folder = $ASTERISK_VOICEMAIL_FOLDERS[0]['folder']; + } + + // get data + $data = array(); + foreach($paths as $key => $path) { + $path = fixPathSlash($path); + $vm_path = $path . "$context/$extension/$folder"; + $indexes = $this->getVoicemailIndex($vm_path,$q,$order,$sort); + $record_count += $this->getVoicemailCount($indexes); + $data = array_merge($data,$this->getVoicemailData($indexes,$start,$span)); + } + + // build controls + + // get the recordings from the asterisk server + $filter = ''; + $recursiveMax = 1; + $recursiveCount = 0; + $files = array(); + foreach($paths as $key => $path) { + $path_files = GetFiles($path,$filter,$recursiveMax,$recursiveCount); + $files = array_merge($files,$path_files); + } + + // move options + $i=0; + while ($ASTERISK_VOICEMAIL_FOLDERS[$i]) { + $cf = $ASTERISK_VOICEMAIL_FOLDERS[$i]['folder']; + $fn = $ASTERISK_VOICEMAIL_FOLDERS[$i]['name']; + if ($cf!=$folder) { + $move_options .= "<option VALUE='" . $cf . "'> " . $fn; + } + $i++; + } + + // forward options + if (is_readable($ASTERISK_VOICEMAIL_CONF)) { + $lines = file($ASTERISK_VOICEMAIL_CONF); + $ext_array = array(); + foreach ($lines as $key => $line) { + + // get context for forward to mailbox + if (preg_match("/\[.*\]/i",$line)) { + $forwardContext = trim(preg_replace('/\[|\]/', '', $line)); + } + + // get username and add to options + if (preg_match("/\=\>/i",$line)) { + list($username,$value) = split('=>',$line); + $username = trim($username); + if ($username!=$_SESSION['ari_user']['extension']) { + //$ext_array[] = $username . "|" . $forwardContext; + list(,$real_name,) = split(",",$value,3); + $ext_array[] = $real_name . "|" . $username . "|" . $forwardContext; + } + } + } //foreach + //sort the array + sort($ext_array); + + //get the size of the array + $array_size = count($ext_array) - 1; + + //loop through the array and build the drop down list + foreach ($ext_array as $item) + { + //split the values apart + list($real_name,$username,$context) = explode("|",$item); + + //add it to the drop down + $forward_options .= "<option VALUE='" . $context . "/" . $username . "'>" . substr($real_name,0,15) . " <" . $username . ">"; + } + } + else { + $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF; + return; + } + + // table controls + $controls = " + <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='delete'\"> + " . _("delete") . " + </button> + <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='move_to'\"> + " . _("move_to") . " + </button> + <select name='folder_rx' style='width:124px;'> + <option VALUE=''>" . _("Folder") . " + " . $move_options . " + </select> + <button class='infobar' type='submit' onclick=\"document.voicemail_form.a.value='forward_to'\"> + " . _("forward_to") . " + </button> + <select name='mailbox_rx'> + <option VALUE=''> + " . $forward_options . " + </select>"; + + // table header + $recording_delete_header = "<th></th>"; + + $fields[0]['field'] = "calldate"; + $fields[0]['text'] = _("Date"); + $fields[1]['field'] = "calldate"; + $fields[1]['text'] = _("Time"); + $fields[2]['field'] = "clid"; + $fields[2]['text'] = _("Caller ID"); + $fields[3]['field'] = "priority"; + $fields[3]['text'] = _("Priority"); + $fields[4]['field'] = "origmailbox"; + $fields[4]['text'] = _("Orig Mailbox"); + $fields[5]['field'] = "duration"; + $fields[5]['text'] = _("Duration"); + $i = 0; + while ($fields[$i]) { + + $field = $fields[$i]['field']; + $text = $fields[$i]['text']; + if ($order==$field) { + if ($sort=='asc') { + $currentSort = 'desc'; + $arrowImg = "<img src='theme/images/arrow-asc.gif' alt='sort'>"; + } + else { + $currentSort = 'asc'; + $arrowImg = "<img src='theme/images/arrow-desc.gif' alt='sort'>"; + } + + if ($i==1) { + $arrowImg = ''; + } + } + else { + $arrowImg = ''; + $currentSort = 'desc'; + } + + $unicode_q = urlencode($q); + $recording_header .= "<th><a href=" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "&f=" . $f . "&q=" . $unicode_q . "&order=" . $field . "&sort=" . $currentSort . ">" . $text . $arrowImg . "</a></th>"; + + $i++; + } + $recording_header .= "<th>" . _("Message") . "</th>"; + + // table body + if (isset($data)) { + foreach($data as $file=>$value) { + + // recording popup link + $voicemail_audio_format = $voicemail_audio_format=='' ? '.wav' : $voicemail_audio_format; + $recording = preg_replace('/.txt/', $voicemail_audio_format, $file); + if (is_file($recording)) { + $recordingLink = "<a href='#' onClick=\"javascript:popUp('misc/recording_popup.php?recording=" . $recording . "&date=" . $date . "&time=" . $time . "'); return false;\"> + " . _("play") . " + </a>"; + } + else { + $_SESSION['ari_error'] = _("Voicemail recording(s) was not found.") . "<br>" . + sprintf(_("On settings page, change voicemail audio format. It is currently set to %s"),$voicemail_audio_format); + } + + $tableText .= " + <tr> + <td class='checkbox'><input type=checkbox name='selected" . ++$i . "' value=" . $file . "></td> + <td width=68>" . GetDateFormat($value['origtime']) . "</td> + <td>" . GetTimeFormat($value['origtime']) . "</td> + <td width=100>" . $value[callerid] . "</td> + <td>" . $value[priority] . "</td> + <td width=90>" . $value[origmailbox] . "</td> + <td>" . $value[duration] . " sec</td> + <td>" . $recordingLink . "</td> + </tr>"; + } + } + + // options + $url_opts = array(); + $url_opts['folder'] = $folder; + $url_opts['sort'] = $sort; + $url_opts['order'] = $order; + + $error = 0; + + // check for voicemail enabled + if ($_SESSION['ari_user']['voicemail_enabled']!=1) { + $_SESSION['ari_error'] = _("Voicemail Login not found.") . "<br>" . + _("No access to voicemail"); + $error = 1; + } + + // check admin + if ($extension=='admin') { + $_SESSION['ari_error'] = _("No Voicemail Recordings for Admin"); + $error = 1; + } + + // build page content + $ret .= checkErrorMessage(); + if ($error) { + return $ret; + } + + // ajax page refresh script + if ($AJAX_PAGE_REFRESH_ENABLE) { +// $ret .= ajaxRefreshScript($args); + } + + // header + $ret .= $display->displayHeaderText(sprintf(_("Voicemail for %s (%s)"),$displayname,$extension)); + $ret .= $display->displaySearchBlock('left',$m,$q,$url_opts,true); + + // start form + $ret .= " + <form name='voicemail_form' action='" . $_SESSION['ARI_ROOT'] . "' method='GET'> + <input type=hidden name=m value=" . $m . "> + <input type=hidden name=f value=msgAction> + <input type=hidden name=a value=''> + <input type=hidden name=q value=" . $q . "> + <input type=hidden name=folder value=" . $folder . "> + <input type=hidden name=start value=" . $start . "> + <input type=hidden name=span value=" . $span . "> + <input type=hidden name=order value=" . $order . "> + <input type=hidden name=sort value=" . $sort . ">"; + + $ret .= $display->displayInfoBarBlock($controls,$q,$start,$span,$record_count); + + // add javascript for popup and message actions + $ret .= " + <SCRIPT LANGUAGE='JavaScript'> + <!-- Begin + function popUp(URL) { + popup = window.open(URL, 'play', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=324,height=110'); + } + + function checkAll(form,set) { + var elem = 0; + var i = 0; + while (elem = form.elements[i]) { + if (set) { + elem.checked = true; + } else { + elem.checked = false; + } + i++; + } + return true; + } + // End --> + </script>"; + + // voicemail delete recording controls + $ret .= " + <table> + <tr> + <td> + <small>" . _("select") . ": </small> + <small><a href='' OnClick=\"checkAll(document.voicemail_form,true); return false;\">" . _("all") . "</a></small> + <small><a href='' OnClick=\"checkAll(document.voicemail_form,false); return false;\">" . _("none") . "</a></small> + </td> + </tr> + </table>"; + + // table + $ret .= " + <table class='voicemail'> + <tr> + " . $recording_delete_header . " + " . $recording_header . " + </tr> + " . $tableText . " + </table>"; + + // end form + $ret .= "</form>"; + + $ret .= $display->displaySearchBlock('center',$m,$q,$url_opts,false); + $ret .= $display->displayNavigationBlock($m,$q,$url_opts,$start,$span,$record_count); + + return $ret; + } + + /* + * Gets voicemail data + * + * @param $data + * Reference to the variable to store the data in + * @param $q + * search string + */ + function getVoicemailIndex($path,$q,$order,$sort) { + + $indexes = array(); + + $filter = '.txt'; + $recursiveMax = 0; + $recursiveCount = 0; + $files = getFiles($path,$filter,$recursiveMax,$recursiveCount); + + if (isset($files)) { + + // ugly, but sorts array by time stamp + foreach ($files as $file) { + + if (is_file($file)) { + + $lines = file($file); + foreach ($lines as $key => $line) { + unset($value); + list($key,$value) = split('=',$line); + if ($value) { + + if ($key=="origtime") { + $calldate = $value; + $date = GetDateFormat($value); + $time = GetTimeFormat($value); + } + if ($key=="callerid") { + $callerid = $value; + } + if ($key=="priority") { + $priority = $value; + } + if ($key=="origmailbox") { + $origmailbox = $value; + } + if ($key=="duration") { + $duration = (int)$value; + } + } + } + + // search filter + $found = 1; + if ($q) { + + $found = 0; + + if (preg_match("/" . $q . "/", $origmailbox) || + preg_match("/" . $q . "/", $callerid) || + preg_match("/" . $q . "/", $date) || + preg_match("/" . $q . "/", $time)) { + $found = 1; + } + } + } + + // add to index + if ($found) { + $indexes[$file] = $$order; + } + } + + if (count($indexes)) { + if ($sort=='desc') { + arsort($indexes); + } + else { + asort($indexes); + } + } + } + + return $indexes; + } + + /* + * Deletes selected voicemails + * + * @param $files + * Array of files to delete + */ + function deleteVoicemailData($files) { + + foreach($files as $key => $path) { + + // get file parts for search + $path_parts = pathinfo($path); + $path = fixPathSlash($path_parts['dirname']); + + list($name,$ext) = split("\.",$path_parts['basename']); + + // delete all related files using a wildcard + if (is_dir($path)) { + $hdl = opendir($path); + while ($fn = readdir($hdl)) { + if (preg_match("/" . $name ."/",$fn)) { + $file = $path . $fn; + unlink($file); + } + } + closedir($hdl); + } + } + } + + /* + * Moves selected voicemails to a specified folder + * + * @param $files + * Array of files to delete + * @param $extension_rx + * Mailbox to move message to + * @param $folder_rx + * Folder to move the messages to + */ + function moveVoicemailData($files,$context_rx,$extension_rx,$folder_rx) { + + global $ASTERISK_VOICEMAIL_PATH; + + $perm = fileperms($ASTERISK_VOICEMAIL_PATH); + $uid = fileowner($ASTERISK_VOICEMAIL_PATH); + $gid = filegroup($ASTERISK_VOICEMAIL_PATH); + + // recieving path + $paths = split(';',$ASTERISK_VOICEMAIL_PATH); + $path_rx = appendPath($paths[0],$context_rx); + if (!is_dir($path_rx)) { + mkdir($path_rx, $perm); + chown($path_rx,intval($uid)); + chgrp($path_rx,intval($gid)); + } + $path_rx = appendPath($path_rx,$extension_rx); + if (!is_dir($path_rx)) { + mkdir($path_rx, $perm); + chown($path_rx,intval($uid)); + chgrp($path_rx,intval($gid)); + } + $path_rx = appendPath($path_rx,$folder_rx); + if (!is_dir($path_rx)) { + mkdir($path_rx, $perm); + chown($path_rx,intval($uid)); + chgrp($path_rx,intval($gid)); + } + + // get recieving folder last message number + if (is_dir($path_rx)) { + + $lastNum = -1; + $lastNumLen = 4; + + $dh = opendir($path_rx); + while (false != ($filename = readdir($dh))) { + if($filename!="." && $filename!="..") { + + $msg_path = $path_rx; + $msg_path = appendPath($msg_path,$filename); + if (is_file($msg_path)) { + $path_parts = pathinfo($msg_path); + $num = preg_replace("/[a-zA-Z]|\./",'', $path_parts['basename']); + if ($num > $lastNum) { + $lastNum = $num; + $lastNumLen = strlen($lastNum); + } + } + } + } + } + else { + $_SESSION['ari_error'] = sprintf(_("Could not create mailbox folder %s on the server"),$folder_rx); + return; + } + + // copy files to new location, incrementing each message number + asort($files); + foreach($files as $key => $path) { + + // get file parts for search + $path_parts = pathinfo($path); + $path = $path_parts['dirname']; + $path = fixPathSlash($path); + list($name,$ext) = split("\.",$path_parts['basename']); + if (is_dir($path)) { + + $lastNum++; + $hdl = opendir($path); + while ($fn = readdir($hdl)) { + if (preg_match("/" . $name . "/",$fn)) { + $src = $path . $fn; + $path_parts = pathinfo($src); + $folder_rx = preg_replace("/\d+/",sprintf("%0" . $lastNumLen . "d",$lastNum),$path_parts['basename']); + $dst = appendPath($path_rx,$folder_rx); + if (is_writable($src) && is_writable($path_rx)) { + + $perm = fileperms($src); + $uid = fileowner($src); + $gid = filegroup($src); + + copy($src,$dst); + + if (is_writable($dst)) { + chmod($dst, $perm); + chown($dst,intval($uid)); + chgrp($dst,intval($gid)); + } + + unlink($src); + } + else { + $_SESSION['ari_error'] = sprintf(_("Permission denied on folder %s or %s"),$src,$path_rx); + return; + } + } + } + closedir($hdl); + } + } + } + + /* + * Gets voicemail record count + * + * @param $indexes + * array of files to be counted + * @return $count + * number of cdr records counted + */ + function getVoicemailCount($indexes) { + + $count = count($indexes); + + return $count; + } + + /* + * Gets voicemail data + * + * @param $indexes + * array of voicemail files + * @param $start + * message number to start page with + * @param $span + * number of messages to display on page + * @param $data + * Reference to the variable to store the data in + */ + function getVoicemailData($indexes,$start,$span) { + + $data = array(); + + if (!isset($indexes)) { + return; + } + + // populate array + $i = 0; + foreach ($indexes as $file => $index) { + if ($i>$start-1+$span) { + return $data; + } + elseif ($i>$start-1 && $i<$start+$span) { + $lines = file($file); + foreach ($lines as $key => $line) { + unset($value); + list($key,$value) = split('=',$line); + if ($value) { + $data[$file][$key] = $value; + } + } + } + $i++; + } + + return $data; + } + +} + + +?>
\ No newline at end of file |