5 * Functions for the interface to the call monitor recordings
14 var $protocol_config_files;
17 * rank (for prioritizing modules)
30 // determine what protocol user is using
31 global $ASTERISK_PROTOCOLS;
33 foreach ($ASTERISK_PROTOCOLS as $protocol => $value) {
34 $data = $this->getProtocolRecordSettings($value['table'],$_SESSION['ari_user']['extension']);
36 $this->protocol_table = $value['table'];
37 $this->protocol_config_files = $value['config_files'];
44 * Adds menu item to nav menu
49 function navMenu($args) {
52 $exten = $_SESSION['ari_user']['extension'];
54 // and we are not logged in as admin
55 if ($exten!=$ARI_ADMIN_USERNAME) {
56 $ret .= "<p><small><small><a href='" . $_SESSION['ARI_ROOT'] . "?m=Settings&f=display'>" . _("Phone Settings") . "</a></small></small></p><br>";
63 * Acts on the user settings
70 function action($args) {
72 global $ARI_ADMIN_USERNAME;
73 global $ASTERISK_VOICEMAIL_CONF;
74 global $SETTINGS_ALLOW_VOICEMAIL_SETTINGS;
75 global $SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET;
76 global $SETTINGS_VOICEMAIL_PASSWORD_LENGTH;
77 global $SETTINGS_VOICEMAIL_PASSWORD_EXACT;
78 global $SETTINGS_ALLOW_CALL_RECORDING_SET;
81 $m = getArgument($args,'m');
82 $a = getArgument($args,'a');
84 $voicemail_password = getArgument($args,'voicemail_password');
85 $voicemail_password_confirm = getArgument($args,'voicemail_password_confirm');
86 $voicemail_email_address = getArgument($args,'voicemail_email_address');
87 $voicemail_pager_address = getArgument($args,'voicemail_pager_address');
88 $voicemail_email_enable = getArgument($args,'voicemail_email_enable');
89 $voicemail_audio_format = getArgument($args,'voicemail_audio_format');
90 $record_in = getArgument($args,'record_in');
91 $record_out = getArgument($args,'record_out');
93 if (isset($_SESSION['ari_user']['voicemail_email'])) {
94 foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) {
95 $var = "voicemail_email_$key";
96 $$var = getArgument($args,$var);
102 $exten = $_SESSION['ari_user']['extension'];
103 if ($exten!=$ARI_ADMIN_USERNAME) {
105 // Make sure Follow-Me setup has not been deleted for this user since the last refresh
106 $follow_me_disabled_delayed = $_COOKIE['ari_follow_me_disabled'];
108 // voicemail settings
109 if ($SETTINGS_ALLOW_VOICEMAIL_SETTINGS && $_SESSION['ari_user']['voicemail_enabled']==1) {
112 // update voicemail password
113 if ($SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET) {
115 // update voicemail password
116 if ($voicemail_password=='' || $voicemail_password_confirm=='') {
117 $_SESSION['ari_error'] =
118 _("Voicemail password not changed") . "<br>" .
119 _("Password and password confirm must not be blank");
121 else if ((strlen($voicemail_password)<$SETTINGS_VOICEMAIL_PASSWORD_LENGTH) || !is_numeric($voicemail_password)) {
122 $_SESSION['ari_error'] =
123 _("Voicemail password not changed") . "<br>" .
124 sprintf(_("Passwords must be all numbers and greater than %d digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH);
126 else if (strlen($voicemail_password)!=$SETTINGS_VOICEMAIL_PASSWORD_LENGTH && $SETTINGS_VOICEMAIL_PASSWORD_EXACT || !is_numeric($voicemail_password)) {
127 $_SESSION['ari_error'] =
128 _("Voicemail password not changed") . "<br>" .
129 sprintf(_("Passwords must be all numbers and only %d digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH);
131 else if ($voicemail_password!=$voicemail_password_confirm) {
132 $_SESSION['ari_error'] =
133 _("Voicemail password not changed") . "<br>" .
134 _("Password and password confirm do not match");
138 // check for writable the files
139 $temp_file = $ASTERISK_VOICEMAIL_CONF . ".tmp";
140 $fp = fopen($temp_file, "w");
142 $_SESSION['ari_error'] =
143 _("Voicemail password not changed") . "<br>" .
144 sprintf(_("%s does not exist or is not writable"),$temp_file);
146 else if (!is_writable($ASTERISK_VOICEMAIL_CONF)) {
147 $_SESSION['ari_error'] =
148 _("Voicemail password not changed") . "<br>" .
149 sprintf(_("%s does not exist or is not writable"),$ASTERISK_VOICEMAIL_CONF);
154 $_SESSION['ari_user']['voicemail_password'] = $voicemail_password;
157 $lines = file($ASTERISK_VOICEMAIL_CONF);
158 foreach ($lines as $key => $line) {
160 list($var,$value) = split('=>',$line);
162 if ($var==$exten && $value) {
164 // write out line with password change
165 $buf = split(',',$value);
166 $buf[0] = $voicemail_password;
167 $line = $var . " => " . join(',', $buf);
172 // write out original line with no changes
177 unlink($ASTERISK_VOICEMAIL_CONF);
178 rename($temp_file,$ASTERISK_VOICEMAIL_CONF);
180 $voicemail_reload = 1;
184 // voicemail email address
185 if ($voicemail_email_enable &&
186 ($voicemail_email_address && !preg_match('/@/',$voicemail_email_address) ||
187 ($voicemail_pager_address && !preg_match('/@/',$voicemail_pager_address)))) {
188 $_SESSION['ari_error'] =
189 _("Voicemail email and pager address not changed") . "<br>" .
190 ("'$voicemail_email_address' and '$voicemail_pager_address' must be a valid email addresses");
194 // check for writable the files
195 $temp_file = $ASTERISK_VOICEMAIL_CONF . ".tmp";
196 $fp = fopen($temp_file, "w");
198 $_SESSION['ari_error'] =
199 _("Voicemail email settings not changed") . "<br>" .
200 sprintf(_("%s does not exist or is not writable"),$temp_file);
202 else if (!is_writable($ASTERISK_VOICEMAIL_CONF)) {
203 $_SESSION['ari_error'] =
204 _("Voicemail email settings not changed") . "<br>" .
205 sprintf(_("%s does not exist or is not writable"),$ASTERISK_VOICEMAIL_CONF);
210 if ($voicemail_email_enable) {
211 setcookie("ari_voicemail_email_address", $voicemail_email_address, time()+365*24*60*60);
212 setcookie("ari_voicemail_pager_address", $voicemail_pager_address, time()+365*24*60*60);
213 foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) {
214 $var = "voicemail_email_$key";
215 $var_cookie = "ari_" . $var;
216 setcookie("$var_cookie", $$var, time()+365*24*60*60);
221 $_SESSION['ari_user']['voicemail_email_enable'] = $voicemail_email_enable;
222 if ($voicemail_email_enable) {
223 $_SESSION['ari_user']['voicemail_email_address'] = $voicemail_email_address;
224 $_SESSION['ari_user']['voicemail_pager_address'] = $voicemail_pager_address;
225 foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) {
226 $option = "voicemail_email_$key";
227 $_SESSION['ari_user']['voicemail_email'][$key] = $$option;
232 if (!$voicemail_email_enable) {
233 $voicemail_email_address = '';
234 $voicemail_pager_address = '';
237 $lines = file($ASTERISK_VOICEMAIL_CONF);
238 foreach ($lines as $key => $line) {
240 list($var,$value) = split('=>',$line);
242 if ($var==$exten && $value) {
244 // write out line with voicemail email change
245 $buf = split(',',$value);
246 $buf[2] = $voicemail_email_address;
247 $buf[3] = $voicemail_pager_address;
249 foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) {
250 $option = "voicemail_email_$key";
251 if ($$option && $key) {
252 $options .= $key . "=" . $value;
255 $options .= $key . "=no";
259 $buf[4] = substr($options, 0, -1);
261 $line = $var . " =>" . join(',', $buf);
262 if (substr($line, 0, -1)!="\n") {
270 // write out original line with no changes
275 unlink($ASTERISK_VOICEMAIL_CONF);
276 rename($temp_file,$ASTERISK_VOICEMAIL_CONF);
278 $voicemail_reload = 1;
282 // reload asterisk voicemail
283 if ($voicemail_reload) {
284 $this->reloadAsteriskVoicemail();
288 // update voicemail audio format setting
289 setcookie("ari_voicemail_audio_format", $voicemail_audio_format, time()+365*24*60*60);
292 // update call monitor record setting
293 if ($SETTINGS_ALLOW_CALL_RECORDING_SET) {
294 if ($record_in && $record_out) {
295 $this->setRecordSettings($exten,$record_in,$record_out);
301 // redirect to see updated page
306 window.location = \"" . $_SESSION['ARI_ROOT'] . "?m=" . $m . "\"
315 * Displays stats page
320 function display($args) {
321 global $SETTINGS_ALLOW_VOICEMAIL_SETTINGS;
322 global $SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET;
323 global $SETTINGS_VOICEMAIL_PASSWORD_LENGTH;
324 global $SETTINGS_VOICEMAIL_EMAIL_OPTION_DESCRIPTIONS;
325 global $ARI_VOICEMAIL_AUDIO_FORMAT_DEFAULT;
326 global $SETTINGS_ALLOW_CALL_RECORDING_SET;
328 global $loaded_modules;
331 $m = getArgument($args,'m');
332 $q = getArgument($args,'q');
333 $start = getArgument($args,'start');
334 $span = getArgument($args,'span');
336 $displayname = $_SESSION['ari_user']['displayname'];
337 $exten = $_SESSION['ari_user']['extension'];
339 $language = new Language();
340 $display = new DisplaySearch();
343 $data = $this->getRecordSettings($_SESSION['ari_user']['extension']);
345 // lang setting options
346 if (extension_loaded('gettext')) {
347 $setLangText = "<p class='lang'>" . _("Language:") . " " . $language->GetForm() . "</p>";
351 // voicemail settings
352 if ($SETTINGS_ALLOW_VOICEMAIL_SETTINGS && $_SESSION['ari_user']['voicemail_enabled']==1 &&
353 in_array('voicemail',array_keys($loaded_modules))) {
354 if ($SETTINGS_ALLOW_VOICEMAIL_PASSWORD_SET) {
356 if ($SETTINGS_VOICEMAIL_PASSWORD_EXACT) {
357 $voicemail_password_length_message = sprintf(_("Passwords must be all numbers and only %s digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH);
360 $voicemail_password_length_message = sprintf(_("Passwords must be all numbers and at least %s digits"),$SETTINGS_VOICEMAIL_PASSWORD_LENGTH);
363 $set_voicemail_password_text = "
365 <td>" . _("Voicemail Password:") . "</td>
367 <input name='voicemail_password' type='password' size=16 value=" . $_SESSION['ari_user']['voicemail_password'] . ">
371 <td>" . _("Enter again to confirm:") . "</td>
373 <input name='voicemail_password_confirm' type='password' size=16 value=" . $_SESSION['ari_user']['voicemail_password'] . ">
377 <td class='note' colspan=2><small>" . $voicemail_password_length_message . "</small></td>
381 if (isset($_SESSION['ari_user']['voicemail_email'])) {
383 if ($_SESSION['ari_user']['voicemail_email_enable']) {
384 $voicemail_email_address = $_SESSION['ari_user']['voicemail_email_address'];
385 $voicemail_pager_address = $_SESSION['ari_user']['voicemail_pager_address'];
386 $voicemail_email_enable = 'checked';
388 foreach (array_keys($_SESSION['ari_user']['voicemail_email']) as $key) {
389 $var = "voicemail_email_$key";
390 $var_enable = $var . "enable";
391 if ($_SESSION['ari_user']['voicemail_email'][$key]=='yes') {
392 $$var_enable = 'checked';
398 $voicemail_email_address = $_COOKIE['ari_voicemail_email_address'];
399 $voicemail_email_text_box_options = "disabled style='background: #DDD;'";
400 $voicemail_pager_address = $_COOKIE['ari_voicemail_pager_address'];
401 $voicemail_pager_text_box_options = "disabled style='background: #DDD;'";
403 foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) {
404 $var = "voicemail_email_$key";
405 $var_cookie = "ari_" . $var;
406 $var_enable = $var . "enable";
407 $var_text_box_options = $var . "text_box_options";
409 $$var_text_box_options = "disabled";
410 if ($_COOKIE[$var_cookie]=='yes') {
411 $$var_enable = 'checked';
416 $set_voicemail_email_text = "
419 <td> " . _("Email Notification") . " <input " . $voicemail_email_enable . " type=checkbox name='voicemail_email_enable' value='1' OnClick=\"disable_fields(); return true;\">
420 <small> " ._("Enable") . " </small>
423 <td><a href='#' class='info'>" . _("Email Voicemail To:") . "<span>" . ("Email a notification, including audio file if indicated below.") . " </span></a></td>
425 <input " . $voicemail_email_text_box_options . " name='voicemail_email_address' type='text' size=48 value='" . $voicemail_email_address . "'>
429 <td><a href='#' class='info'>" . _("Pager Email Notification To:") . "<span>" . ("Email a short notification") . " </span></a></td>
431 <input " . $voicemail_pager_text_box_options . " name='voicemail_pager_address' type='text' size=48 value='" . $voicemail_pager_address . "'>
438 foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) {
440 $var = "voicemail_email_$key";
441 $var_enable = $var . "enable";
442 $var_text_box_options = $var . "text_box_options";
443 if ($SETTINGS_VOICEMAIL_EMAIL_OPTION_DESCRIPTIONS[$key]) {
444 $var_text = $SETTINGS_VOICEMAIL_EMAIL_OPTION_DESCRIPTIONS[$key];
450 if ($value != 'yes' && $value != 'no' && $value !='') {
452 $size = strlen($value) - 1;
453 $set_voicemail_email_text .= "
457 <input type=text size='" . $size . "' name='" . $var . "' value='" . $value . "' OnClick=\"disable_fields(); return true;\">
458 <small>" . $var_text . "</small>
464 $set_voicemail_email_text .= "
468 <input " . $$var_enable . " " . $$var_text_box_options . " type=checkbox name='" . $var . "' value='yes' OnClick=\"disable_fields(); return true;\">
469 <small>" . $var_text . "</small>
476 $wav_enable = 'selected';
477 if ($_COOKIE['ari_voicemail_audio_format']=='.gsm'||
478 ($_COOKIE['ari_voicemail_audio_format']=='' && $ARI_VOICEMAIL_AUDIO_FORMAT_DEFAULT='.gsm')) {
480 $gsm_enable = 'selected';
483 $set_voicemail_audio_format_text = "
485 <td>" . _("Audio Format:") . "</td>
487 <select name='voicemail_audio_format'>
488 <option value='.wav' " . $wav_enable . ">" . _("Best Quality") . " (.wav)</option>
489 <option value='.gsm' " . $gsm_enable . ">" . _("Smallest Download") . " (.gsm)</option>
494 $set_voicemail_text = "
495 <table class='settings'>
497 <td><h3>" . _("Voicemail Settings") . "</h3></td>
499 " . $set_voicemail_password_text . "
500 " . $set_voicemail_email_text . "
501 " . $set_voicemail_audio_format_text . "
505 // call monitor settings
506 if ($this->getFreePBXVersion() &&
507 $SETTINGS_ALLOW_CALL_RECORDING_SET &&
508 in_array('callmonitor',array_keys($loaded_modules))) {
510 foreach($data as $key=>$value) {
511 if ($key=='record_in') {
512 if ($value=='Always') {
513 $ri_always = 'checked=checked';
515 elseif ($value=='Never') {
516 $ri_never = 'checked=checked';
518 elseif ($value=='Adhoc') {
519 $ri_on_demand = 'checked=checked';
522 if ($key=='record_out') {
523 if ($value=='Always') {
524 $ro_always = 'checked=checked';
526 elseif ($value=='Never') {
527 $ro_never = 'checked=checked';
529 elseif ($value=='Adhoc') {
530 $ro_on_demand = 'checked=checked';
535 $set_callmonitor_text = "
536 <table class='settings'>
538 <td><h3>" . _("Call Monitor Settings") . "</h3></td>
541 <td>" . _("Record INCOMING:") . " </td>
543 <input type='radio' name='record_in' value='Always' " . $ri_always . "/> " . _("Always") . "
544 <input type='radio' name='record_in' value='Never' " . $ri_never . "/> " . _("Never") . "
545 <input type='radio' name='record_in' value='Adhoc' " . $ri_on_demand . "/> " . _("On-Demand") . "
549 <td>" . _("Record OUTGOING:") . " </td>
551 <input type='radio' name='record_out' value='Always' " . $ro_always . "/> " . _("Always") . "
552 <input type='radio' name='record_out' value='Never' " . $ro_never . "/> " . _("Never") . "
553 <input type='radio' name='record_out' value='Adhoc' " . $ro_on_demand . "/> " . _("On-Demand") . "
559 // javascript enable options
560 if (isset($_SESSION['ari_user']['voicemail_email']) &&
561 in_array('voicemail',array_keys($loaded_modules))) {
562 foreach ($_SESSION['ari_user']['voicemail_email'] as $key => $value) {
563 $var = "voicemail_email_$key";
564 $js_voicemail_email_disable .= "
565 document.ari_settings.$var.disabled = false;";
566 $js_voicemail_email_enable .= "
567 document.ari_settings.$var.disabled = true;";
570 $js_voicemail_script = "
571 if (document.ari_settings.voicemail_email_enable.checked) {
572 document.ari_settings.voicemail_email_address.style.backgroundColor = '#FFF';
573 document.ari_settings.voicemail_email_address.disabled = false;
574 document.ari_settings.voicemail_email_address.value='" . $voicemail_email_address . "';
575 document.ari_settings.voicemail_pager_address.style.backgroundColor = '#FFF';
576 document.ari_settings.voicemail_pager_address.disabled = false;
577 document.ari_settings.voicemail_pager_address.value='" . $voicemail_pager_address . "';
578 " . $js_voicemail_email_disable . "
581 document.ari_settings.voicemail_email_address.style.backgroundColor = '#DDD';
582 document.ari_settings.voicemail_email_address.disabled = true;
583 document.ari_settings.voicemail_pager_address.style.backgroundColor = '#DDD';
584 document.ari_settings.voicemail_pager_address.disabled = true;
585 " . $js_voicemail_email_enable . "
589 // build page content
590 $ret .= checkErrorMessage();
592 $headerText = sprintf(_("Phone Settings for %s (%s)"),$displayname,$exten);
594 $ret .= $display->displayHeaderText($headerText);
595 $ret .= $display->displayLine();
598 <SCRIPT LANGUAGE='JavaScript'>
600 function rowCounter(field, maxlimit) {
601 temp = field.value.split('\u000A',maxlimit+1)
602 field.value = temp.join('\u000A')
603 if (temp.length == maxlimit+1) {
604 field.value = field.value.substring(0, field.value.length-1)
608 function disable_fields() {";
609 $ret .= $js_voicemail_script . "
616 <form class='settings' name='ari_settings' action='' method='GET'>
617 <input type=hidden name=m value=" . $m . ">
618 <input type=hidden name=f value='action'>
619 <input type=hidden name=a value='update'>
621 " . $set_voicemail_text . "
623 " . $set_callmonitor_text . "
625 <input name='submit' type='submit' value='" . _("Update") . "'>
637 * Sets Asterisk call recording setting
640 * Extension to modify
646 function setRecordSettings($exten,$state_in,$state_out) {
648 global $asterisk_manager_interface;
650 if (version_compare($this->getFreePBXVersion(), '1.10', '<')) {
652 if ($state_in=="Always") {
654 $value_opt = " " . "ENABLED";
656 elseif ($state_in=="Never") {
658 $value_opt = " " . "DISABLED";
664 $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database $type_opt RECORD-IN $exten $value_opt\r\n\r\n");
666 if ($state_out=="Always") {
668 $value_opt = " " . "ENABLED";
670 elseif ($state_out=="Never") {
672 $value_opt = " " . "DISABLED";
678 $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database $type_opt RECORD-OUT $exten $value_opt\r\n\r\n");
682 $value_opt= "out=".$state_out."|in=".$state_in;
683 $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database put AMPUSER $exten/recording $value_opt\r\n\r\n");
688 * Gets record settings for a protocol
691 * Table to pull information from
693 * Extension to get information about
695 * call monitor record settings
697 function getProtocolRecordSettings($table,$exten) {
699 global $asterisk_manager_interface;
703 if (version_compare($this->getFreePBXVersion(), '1.10', '<')) {
705 $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get RECORD-IN $exten\r\n\r\n");
706 if (preg_match("/ENABLED/",$response)) {
707 $data['record_in'] = 'Always';
709 elseif (preg_match("/DISABLED/",$response)) {
710 $data['record_in'] = 'Never';
713 $data['record_in'] = 'Adhoc';
716 $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get RECORD-OUT $exten\r\n\r\n");
717 if (preg_match("/ENABLED/",$response)) {
718 $data['record_out'] = 'Always';
720 elseif (preg_match("/DISABLED/",$response)) {
721 $data['record_out'] = 'Never';
724 $data['record_out'] = 'Adhoc';
729 $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: database get AMPUSER $exten/recording\r\n\r\n");
730 if (strstr($response,"in=Always")) {
731 $data['record_in'] = 'Always';
733 elseif (strstr($response,"in=Never")) {
734 $data['record_in'] = 'Never';
737 $data['record_in'] = 'Adhoc';
739 if (strstr($response,"out=Always")) {
740 $data['record_out'] = 'Always';
742 elseif (strstr($response,"out=Never")) {
743 $data['record_out'] = 'Never';
746 $data['record_out'] = 'Adhoc';
754 * Gets record settings
757 * Extension to get information about
759 * Reference to the variable to store the data in
761 function getRecordSettings($exten) {
763 // check protocol tables first
764 $data = $this->getProtocolRecordSettings($this->protocol_table,$exten);
770 * Reloads Asterisk Configuration
772 function reloadAsteriskVoicemail() {
774 global $asterisk_manager_interface;
776 $response = $asterisk_manager_interface->Command("Action: Command\r\nCommand: Reload app_voicemail.so\r\n\r\n");
780 * Gets FreePBX Version
782 function getFreePBXVersion() {
784 if (isset($_SESSION['dbh_asterisk'])) {
785 $sql = "SELECT * FROM admin WHERE variable = 'version'";
786 $results = $_SESSION['dbh_asterisk']->getAll($sql);
787 if(DB::IsError($results)) {
788 $_SESSION['ari_error'] = $results->getMessage();
791 return $results[0][1];
795 function lookupSetExtensionFormat($exten) {
797 if (trim($exten) == "") return $exten;
799 $exten = preg_replace("/[^0-9*]/", "", $exten);
801 $sql = "SELECT extension FROM users WHERE extension = '".$exten."'";
802 $asa = $_SESSION['dbh_asterisk']->getrow($sql, DB_FETCHMODE_ASSOC);
803 if (!is_array($asa)) {