From 3a17b276638200475d54201fa62566b7440e819a Mon Sep 17 00:00:00 2001
From: ivan
Date: Sun, 16 Mar 2008 19:58:33 +0000
Subject:
---
fs_selfservice/fri/modules/VmX.module | 661 +++++++++++++++++++
fs_selfservice/fri/modules/callmonitor.module | 675 ++++++++++++++++++++
fs_selfservice/fri/modules/featurecodes.module | 152 +++++
fs_selfservice/fri/modules/followme.module | 678 ++++++++++++++++++++
fs_selfservice/fri/modules/phonefeatures.module | 342 ++++++++++
fs_selfservice/fri/modules/settings.module | 813 ++++++++++++++++++++++++
fs_selfservice/fri/modules/voicemail.module | 805 +++++++++++++++++++++++
7 files changed, 4126 insertions(+)
create mode 100644 fs_selfservice/fri/modules/VmX.module
create mode 100644 fs_selfservice/fri/modules/callmonitor.module
create mode 100644 fs_selfservice/fri/modules/featurecodes.module
create mode 100644 fs_selfservice/fri/modules/followme.module
create mode 100644 fs_selfservice/fri/modules/phonefeatures.module
create mode 100644 fs_selfservice/fri/modules/settings.module
create mode 100644 fs_selfservice/fri/modules/voicemail.module
(limited to 'fs_selfservice/fri/modules')
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 @@
+getVmxState($exten,'unavail');
+
+ // and vmx is enabled for this user
+ if ($vmx_enabled !== false)
+ $ret .= "" . _("VmX™ Locator") . "
";
+ }
+ }
+
+ 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") . " " .
+ 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") . " " .
+ 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") . " " .
+ 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") . " " .
+ 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 .= "
+
+
+ ";
+
+ 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 .=
+ "
+
+
+
+
+
+
+
+ ";
+
+
+ // 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 .=
+ "";
+
+ $ret .=
+ "";
+
+ 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 @@
+" . _("Call Monitor") . "
";
+
+ 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 .= "
+
+
+ ";
+
+ 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) . " ";
+ }
+ }
+ $recordings = $this->getRecordings($ASTERISK_CALLMONITOR_PATH,$data);
+
+ // build controls
+ if ($CALLMONITOR_ALLOW_DELETE) {
+ $controls .= "
+
+ " . _("delete") . "
+
+ ";
+ }
+
+ $controls .= "
+ " . _("duration") . "
+
+
+ " . _("ignore") . "
+ ";
+
+ // table header
+ if ($CALLMONITOR_ALLOW_DELETE) {
+ $recording_delete_header = " ";
+ }
+
+ $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 = " ";
+ }
+ else {
+ $currentSort = 'asc';
+ $arrowImg = " ";
+ }
+
+ if ($i==1) {
+ $arrowImg = '';
+ }
+ }
+ else {
+ $arrowImg = '';
+ $currentSort = 'desc';
+ }
+
+ $unicode_q = urlencode($q);
+ $recording_header .= "" . $text . $arrowImg . " ";
+
+ $i++;
+ }
+ $recording_header .= "" . _("Monitor") . " ";
+
+ // 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 = " ";
+ }
+
+ $recordingLink = '';
+ if (is_file($recordings[$value['uniqueid'] . $value['calldate']])) {
+ $recordingLink = "" . _("play") . " ";
+ }
+
+ $recording_body .= "
+ " . $recording_delete_checkbox . "
+ " . $date . "
+ " . $time . "
+ " . $value[clid] . "
+ " . $value[src] . "
+ " . $value[dst] . "
+ " . $value[dcontext] . "
+ " . $value[duration] . " sec
+ " . $recordingLink . "
+ ";
+ }
+ if (!count($data)) {
+ $recording_body .= " ";
+ }
+
+ // 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 .= "
+ ";
+ }
+
+ $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 @@
+" . _("Feature Codes") . " ";
+
+ 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 =
+ "
+
+ " . _("Handset Feature Code") . "
+
+
+ " . _("Action") . "
+
+ ";
+
+ // 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 .=
+ "
+
+ " . $item['keycode'] . "
+
+
+ " . $item['description'] . "
+
+ ";
+ }
+ }
+ }
+ else {
+
+ // handset feature code body
+ foreach($ARI_HELP_FEATURE_CODES as $key => $feature_code) {
+
+ $handset_feature_codes_body .=
+ "
+
+ " . $key . "
+
+
+ " . $feature_code . "
+
+ ";
+ }
+ }
+
+ // build page content
+ $ret .= checkErrorMessage();
+
+ $ret .= $display->displayHeaderText($header_text);
+ $ret .= $display->displayLine();
+
+ // table
+ $ret .= "
+
+ " . $handset_feature_codes_header . "
+ " . $handset_feature_codes_body . "
+
";
+
+ 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 @@
+" . _("Follow Me") . " ";
+ }
+
+ 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") . " " .
+ 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") . " " .
+ 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") . " " .
+ 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") . " " .
+ 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 .= "
+
+
+ ";
+
+ 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.= "";
+ }
+ }
+
+ }
+
+ // 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\n";
+
+ $ret .=
+ "";
+
+ 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 @@
+" . _("Phone Features") . " ";
+
+ 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 .= "
+
+
+ ";
+
+ 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 = "";
+ $dnd_cw_text.= "" . _("Phone Features") . " ";
+
+ $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 .= "
";
+ }
+
+ if ($SETTINGS_ALLOW_CALLFORWARD_SETTINGS) {
+
+ $set_call_forward_text .= "";
+
+ $set_call_forward_text.= "";
+ $set_call_forward_text.= "" . _("Call Forwarding") . " ";
+
+ $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 .= "
";
+ }
+ }
+
+ // 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 .= "
+ ";
+
+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";
+ $ret.= "";
+ $ret.= " ";
+ $ret.= "" . _($title) . " ";
+ $ret.= " ";
+ $ret.= " \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") . " " .
+ 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";
+ $ret.= "" . _($title) . " ";
+ $ret.= "";
+ $ret.= " ";
+ $ret.= " ";
+ $ret.= "";
+ $ret.= " ";
+ $ret.= "" . _("Enable") . " ";
+ $ret.= " ";
+ $ret.= " \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 @@
+ $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 .= "" . _("Settings") . "
";
+ }
+
+ 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") . " " .
+ _("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") . " " .
+ 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") . " " .
+ 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") . " " .
+ _("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") . " " .
+ 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") . " " .
+ 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") . " " .
+ ("'$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") . " " .
+ 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") . " " .
+ 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 .= "
+
+
+ ";
+
+ 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 = "" . _("Language:") . " " . $language->GetForm() . "
";
+ }
+
+
+ // 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 = "
+
+ " . _("Voicemail Password:") . "
+
+
+
+
+
+ " . _("Enter again to confirm:") . "
+
+
+
+
+
+ " . $voicemail_password_length_message . "
+ ";
+ }
+
+ 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 = "
+
+
+ " . _("Email Notification") . "
+ " ._("Enable") . "
+
+
+ " . _("Email Voicemail To:") . "" . ("Email a notification, including audio file if indicated below.") . "
+
+
+
+
+
+ " . _("Pager Email Notification To:") . "" . ("Email a short notification") . "
+
+
+
+
+
+
+ ";
+
+ 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 .= "
+
+
+
+
+ " . $var_text . "
+
+ ";
+ }
+ else {
+
+ $set_voicemail_email_text .= "
+
+
+
+
+ " . $var_text . "
+
+ ";
+ }
+ }
+ }
+
+ $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 = "
+
+ " . _("Audio Format:") . "
+
+
+ " . _("Best Quality") . " (.wav)
+ " . _("Smallest Download") . " (.gsm)
+
+
+ ";
+
+ $set_voicemail_text = "
+
+
+ " . _("Voicemail Settings") . "
+
+ " . $set_voicemail_password_text . "
+ " . $set_voicemail_email_text . "
+ " . $set_voicemail_audio_format_text . "
+
";
+ }
+
+ // 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 = "
+ ";
+ }
+
+ // 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 .= "
+ ";
+
+ $ret .= "
+ " . $setLangText . "
+ ";
+
+ 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 @@
+" . _("Voicemail") . " ";
+ }
+
+ 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 .= "
+
+ " . $fn . " (" . $record_count . ")" . "
+
+
";
+ }
+ }
+ }
+ }
+ }
+ $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 .= "
+
+
+ ";
+
+ 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 .= " " . $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 .= " " . substr($real_name,0,15) . " <" . $username . ">";
+ }
+ }
+ else {
+ $_SESSION['ari_error'] = "File not readable: " . $ASTERISK_VOICEMAIL_CONF;
+ return;
+ }
+
+ // table controls
+ $controls = "
+
+ " . _("delete") . "
+
+
+ " . _("move_to") . "
+
+
+ " . _("Folder") . "
+ " . $move_options . "
+
+
+ " . _("forward_to") . "
+
+
+
+ " . $forward_options . "
+ ";
+
+ // table header
+ $recording_delete_header = " ";
+
+ $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 = " ";
+ }
+ else {
+ $currentSort = 'asc';
+ $arrowImg = " ";
+ }
+
+ if ($i==1) {
+ $arrowImg = '';
+ }
+ }
+ else {
+ $arrowImg = '';
+ $currentSort = 'desc';
+ }
+
+ $unicode_q = urlencode($q);
+ $recording_header .= "" . $text . $arrowImg . " ";
+
+ $i++;
+ }
+ $recording_header .= "" . _("Message") . " ";
+
+ // 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 = "
+ " . _("play") . "
+ ";
+ }
+ else {
+ $_SESSION['ari_error'] = _("Voicemail recording(s) was not found.") . " " .
+ sprintf(_("On settings page, change voicemail audio format. It is currently set to %s"),$voicemail_audio_format);
+ }
+
+ $tableText .= "
+
+
+ " . GetDateFormat($value['origtime']) . "
+ " . GetTimeFormat($value['origtime']) . "
+ " . $value[callerid] . "
+ " . $value[priority] . "
+ " . $value[origmailbox] . "
+ " . $value[duration] . " sec
+ " . $recordingLink . "
+ ";
+ }
+ }
+
+ // 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.") . " " .
+ _("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 .= "
+ ";
+
+ $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
--
cgit v1.2.1