function ivr_show_edit($id, $nbroptions, $post) { global $db; global $tabindex; $ivr_details = ivr_get_details($id); $ivr_dests = ivr_get_dests($id); ?> <div class="content"> <h2><?php echo _("Digital Receptionist"); ?> </h2> <h3><?php echo _("Edit Menu") . " " . $ivr_details['displayname']; ?> </h3> <?php ?> <form name="prompt" action="<?php $_SERVER['PHP_SELF']; ?> " method="post" onsubmit="return prompt_onsubmit();"> <input type="hidden" name="action" value="edited" /> <input type="hidden" name="display" value="ivr" /> <input type="hidden" name="id" value="<?php echo $id; ?> " /> <input name="Submit" type="submit" value="<?php echo _("Save"); ?> " tabindex="<?php echo ++$tabindex; ?> " disabled> <?php $usage_list = array(); if (function_exists('queues_ivr_usage')) { $usage_list = queues_ivr_usage($id); } if (count($usage_list)) { ?> <a href="#" class="info"><?php echo _("Queue Breakout Menu Usage List"); ?> <span><?php echo _("This IVR is being used by the following Queues, providing an ability for callers to hear this Queue's announcement periodically and giving callers an option to break out of the queue into this IVR's menu options. This queue can not be deleted when being used in this mode"); ?> </span></a> <?php $count = 0; foreach ($usage_list as $link) { $label = '<span><img width="16" height="16" border="0" title="' . $link['description'] . '" alt="" src="images/queue_link.png"/> ' . $link['description'] . '</span>'; echo "<br /><a href=" . $link['url_query'] . ">" . $label . "</a>"; } echo "<br />"; } else { ?> <input name="delete" type="submit" value="<?php echo _("Delete") . " " . _("Digital Receptionist") . " {$ivr_details['displayname']}"; ?> " disabled/> <?php } if ($id) { $usage_list = framework_display_destination_usage(ivr_getdest($id)); if (!empty($usage_list)) { ?> <br /><a href="#" class="info"><?php echo $usage_list['text']; ?> :<span><?php echo $usage_list['tooltip']; ?> </span></a> <?php } } ?> <table> <tr><td colspan=2><hr /></td></tr> <tr> <td><a href="#" class="info"><?php echo _("Change Name"); ?> <span><?php echo _("This changes the short name, visible on the right, of this IVR"); ?> </span></a></td> <td><input type="text" name="displayname" value="<?php echo $ivr_details['displayname']; ?> " tabindex="<?php echo ++$tabindex; ?> "></td> </tr> <?php $annmsg_id = isset($ivr_details['announcement_id']) ? $ivr_details['announcement_id'] : ''; if (function_exists('recordings_list')) { //only include if recordings is enabled ?> <tr> <td><a href="#" class="info"><?php echo _("Announcement"); ?> <span><?php echo _("Message to be played to the caller. To add additional recordings please use the \"System Recordings\" MENU to the left"); ?> </span></a></td> <td> <select name="annmsg_id" tabindex="<?php echo ++$tabindex; ?> "> <?php $tresults = recordings_list(); echo '<option value="">' . _("None") . "</option>"; if (isset($tresults[0])) { foreach ($tresults as $tresult) { echo '<option value="' . $tresult['id'] . '"' . ($tresult['id'] == $annmsg_id ? ' SELECTED' : '') . '>' . $tresult['displayname'] . "</option>\n"; } } ?> </select> </td> </tr> <?php } else { ?> <tr> <td><a href="#" class="info"><?php echo _("Announcement"); ?> <span><?php echo _("Message to be played to the caller.<br><br>You must install and enable the \"Systems Recordings\" Module to edit this option"); ?> </span></a></td> <td> <?php $default = isset($annmsg_id) ? $annmsg_id : ''; ?> <input type="hidden" name="annmsg_id" value="<?php echo $default; ?> "><?php echo $default != '' ? $default : 'None'; ?> </td> </tr> <?php } ?> <tr> <td><a href="#" class="info"><?php echo _("Timeout"); ?> <span><?php echo _("The amount of time (in seconds) before the 't' option, if specified, is used"); ?> </span></a></td> <td><input type="text" name="timeout" value="<?php echo $ivr_details['timeout']; ?> " tabindex="<?php echo ++$tabindex; ?> "></td> </tr> <?php if ($ivr_details['enable_directory'] && function_exists('voicemail_getVoicemail')) { ?> <tr> <td><a href="#" class="info"><?php echo _("Enable Directory"); ?> <span><?php echo _("Let callers into the IVR dial '#' to access the directory. WARNING: this feature is deprecated and will be removed from future versions. You should install the Directory module and assign an IVR destination to use Directory functionality."); ?> </span></a></td> <td><input type="checkbox" name="ena_directory" <?php echo $ivr_details['enable_directory']; ?> tabindex="<?php echo ++$tabindex; ?> "></td> </tr> <tr> <td><a href="#" class="info"><?php echo _("Directory Context"); ?> <span><?php echo _("When # is selected, this is the voicemail directory context that is used"); ?> </span></a></td> <td> <select name="dircontext" tabindex="<?php echo ++$tabindex; ?> "> <?php $vm_results = voicemail_getVoicemail(); $vmcontexts = array_keys($vm_results); foreach ($vmcontexts as $vmc) { if ($vmc != 'general' && $vmc != 'zonemessages') { echo '<option value="' . $vmc . '"' . ($vmc == $ivr_details['dircontext'] ? ' SELECTED' : '') . '>' . $vmc . "</option>\n"; } } ?> </select> </td> </tr> <?php } ?> <tr> <td><a href="#" class="info"><?php echo _("VM Return to IVR"); ?> <span><?php echo _("If checked, upon exiting voicemail a caller will be returned to this IVR if they got a users voicemail"); ?> </span></a></td> <td><input type="checkbox" name="retvm" <?php echo $ivr_details['retvm']; ?> tabindex="<?php echo ++$tabindex; ?> "></td> </tr> <?php if (!function_exists('directory_list')) { ?> <tr> <td><a href="#" class="info"><?php echo _("Enable Direct Dial"); ?> <span><?php echo _("Let callers into the IVR dial an extension directly"); ?> </span></a></td> <td><input type="checkbox" name="ena_directdial" <?php echo $ivr_details['enable_directdial']; ?> tabindex="<?php echo ++$tabindex; ?> "></td> </tr> <?php } else { ?> <tr> <td><a href="#" class="info"><?php echo _("Direct Dial Options"); ?> <span><?php echo _("Provides options for callers to direct dial an extension. Direct dialing can be completely disabled, it can be enabled for all extensions on a system, or it can be tied to a Company Directory allowing any member listed in that directory to be dialed directly if their extension is known. If an extension in the chosen directory is overridden, only that overridden number is dialable"); ?> </span></a></td> <td> <select name="ena_directdial" tabindex="<?php echo ++$tabindex; ?> "> <?php $dlist = directory_list(); echo '<option value=""' . ($ivr_details['enable_directdial'] == '' ? ' SELECTED' : '') . '>' . _('Disabled') . "</option>\n"; echo '<option value="CHECKED"' . (strtoupper($ivr_details['enable_directdial']) == 'CHECKED' ? ' SELECTED' : '') . '>' . _('All Extensions') . "</option>\n"; foreach ($dlist as $dir) { echo '<option value="' . $dir['id'] . '"' . ($ivr_details['enable_directdial'] == $dir['id'] ? ' SELECTED' : '') . '>' . $dir['dirname'] . "</option>\n"; } ?> </select> </td> </tr> <?php } ?> <tr> <td><a href="#" class="info"><?php echo _("Loop Before t-dest"); ?> <span><?php echo _("If checked, and there is a 't' (timeout) destination defined below, the IVR will loop back to the beginning if no input is provided for the designated loop counts prior to going to the timeout (t) destination."); ?> </span></a></td> <td><input type="checkbox" name="alt_timeout" <?php echo $ivr_details['alt_timeout']; ?> tabindex="<?php echo ++$tabindex; ?> "></td> </tr> <?php $timeout_id = isset($ivr_details['timeout_id']) ? $ivr_details['timeout_id'] : ''; if (function_exists('recordings_list')) { //only include if recordings is enabled ?> <tr> <td><a href="#" class="info"><?php echo _("Timeout Message"); ?> <span><?php echo _("If a timeout occurs and a message is selected, it will be played in place of the announcement message when looping back to the top of the IVR. It will not be played if the t destination is the next target."); ?> </span></a></td> <td> <select name="timeout_id" tabindex="<?php echo ++$tabindex; ?> "> <?php //$tresults obtained above echo '<option value="">' . _("None") . "</option>"; if (isset($tresults[0])) { foreach ($tresults as $tresult) { echo '<option value="' . $tresult['id'] . '"' . ($tresult['id'] == $timeout_id ? ' SELECTED' : '') . '>' . $tresult['displayname'] . "</option>\n"; } } ?> </select> </td> </tr> <?php } ?> <tr> <td><a href="#" class="info"><?php echo _("Loop Before i-dest"); ?> <span><?php echo _("If checked, and there is an 'i' (invalid extension) destination defined below, the IVR will play invalid option and then loop back to the beginning for the designated loop counts prior to going to the invalid (i) destination."); ?> </span></a></td> <td><input type="checkbox" name="alt_invalid" <?php echo $ivr_details['alt_invalid']; ?> tabindex="<?php echo ++$tabindex; ?> "></td> </tr> <?php $invalid_id = isset($ivr_details['invalid_id']) ? $ivr_details['invalid_id'] : ''; if (function_exists('recordings_list')) { //only include if recordings is enabled ?> <tr> <td><a href="#" class="info"><?php echo _("Invalid Message"); ?> <span><?php echo _("If an invalid extension is pressed and a message is selected, it will be played in place of the announcement message when looping back to the top of the IVR. It will not be played if the t destination is the next target. If nothing is selected, the system will play a default invalid extension message before going back to the main announcement"); ?> </span></a></td> <td> <select name="invalid_id" tabindex="<?php echo ++$tabindex; ?> "> <?php //$tresults obtained above echo '<option value="">' . _("None") . "</option>"; if (isset($tresults[0])) { foreach ($tresults as $tresult) { echo '<option value="' . $tresult['id'] . '"' . ($tresult['id'] == $invalid_id ? ' SELECTED' : '') . '>' . $tresult['displayname'] . "</option>\n"; } } ?> </select> </td> </tr> <?php } ?> <tr> <td><a href="#" class="info"><?php echo _("Repeat Loops:"); ?> <span><?php echo _("The number of times we should loop when invalid input or no input has been entered before going to the defined or default generated 'i' or 't' options. If the 'i' or 't' options are defined, the above check boxes must be checked in order to loop."); ?> </span></a></td> <td> <select name="loops" tabindex="<?php echo ++$tabindex; ?> "> <?php $default = isset($ivr_details['loops']) ? $ivr_details['loops'] : 2; for ($i = 0; $i <= 9; $i++) { echo '<option value="' . $i . '" ' . ($i == $default ? 'SELECTED' : '') . '>' . $i . '</option>'; } ?> </select> </td> </tr> <tr><td colspan=2><hr /></td></tr> <tr><td colspan=2> <input name="increase" type="submit" value="<?php echo _("Increase Options"); ?> " disabled> <input name="Submit" type="submit" value="<?php echo _("Save"); ?> " tabindex="<?php echo ++$tabindex; ?> " disabled> <?php if ($nbroptions > 1) { ?> <input name="decrease" type="submit" value="<?php echo _("Decrease Options"); ?> " disabled> <?php } ?> </td> </tr> <tr><td colspan=2><hr /></td></tr></table> <style type="text/css"> #ivr-dests tr:nth-child(odd){ background-color: #FCE7CE; } </style> <table id="ivr-dests"> <?php // Draw the destinations $dests = ivr_get_dests($id); $count = 0; if (!empty($dests)) { foreach ($dests as $dest) { drawdestinations($count, $dest['selection'], $dest['dest'], $dest['ivr_ret']); $count++; } } while ($count < $nbroptions) { drawdestinations($count, null, null, 0); $count++; } ?> </table> <?php if ($nbroptions < $count) { echo "<input type='hidden' name='nbroptions' value={$count} />\n"; } else { echo "<input type='hidden' name='nbroptions' value={$nbroptions} />\n"; } global $module_hook; echo $module_hook->hookHtml; ?> <input name="increase" type="submit" value="<?php echo _("Increase Options"); ?> " disabled> <input name="Submit" type="submit" value="<?php echo _("Save"); ?> " disabled> <?php if ($nbroptions > 1) { ?> <input name="decrease" type="submit" value="<?php echo _("Decrease Options"); ?> " disabled> <?php } ?> <script language="javascript"> <!-- $(document).ready(function() { $(':submit:disabled').removeAttr('disabled'); }); function delEntry(e){ $('[name=option'+e+'],[name=goto'+e+']').val('').parent().parent().fadeOut(500,function(){$(this).remove();}); } var theForm = document.prompt; theForm.displayname.focus(); function prompt_onsubmit() { var msgInvalidOption = "<?php echo _("Invalid option"); ?> "; defaultEmptyOK = true; // go thru the form looking for options // where the option isn't blank (as that will be removed) do the validation var allelems = theForm.elements; if (allelems != null) { var i, elem; for (i = 0; elem = allelems[i]; i++) { if (elem.type == 'text' && elem.name.indexOf('option') == 0) { if (elem.value != '') { if (!isIVROption(elem.value)) return warnInvalid(elem, msgInvalidOption); var gotoNum = elem.name.charAt(6); var isok = validateSingleDestination(theForm,gotoNum,true); if (!isok) return false; } } } } return true; } //--> </script> </form> </div> <?php }
function ivr_get_config($engine) { global $ext; switch ($engine) { case "asterisk": $ddial_contexts = array(); $ivrlist = ivr_list(); if (is_array($ivrlist)) { foreach ($ivrlist as $item) { $id = "ivr-" . $item['ivr_id']; $details = ivr_get_details($item['ivr_id']); $announcement_id = isset($details['announcement_id']) ? $details['announcement_id'] : ''; $timeout_id = isset($details['timeout_id']) ? $details['timeout_id'] : ''; $invalid_id = isset($details['invalid_id']) ? $details['invalid_id'] : ''; $loops = isset($details['loops']) ? $details['loops'] : '2'; $retvm = isset($details['retvm']) ? $details['retvm'] : ''; if (!empty($details['enable_directdial'])) { if ($details['enable_directdial'] == 'CHECKED') { $ext->addInclude($id, 'from-did-direct-ivr'); //generated in core module } else { $ext->addInclude($id, 'from-ivr-directory-' . $details['enable_directdial']); $ddial_contexts[$details['enable_directdial']] = true; } } // I'm not sure I like the ability of people to send voicemail from the IVR. // Make it a config option, possibly? // $ext->addInclude($item[0],'app-messagecenter'); if (!empty($details['enable_directory'])) { $ext->addInclude($id, 'app-directory'); $dir = featurecodes_getFeatureCode('infoservices', 'directory'); $ext->add($id, '#', '', new ext_dbdel('${BLKVM_OVERRIDE}')); $ext->add($id, '#', '', new ext_setvar('__NODEST', '')); $ext->add($id, '#', '', new ext_goto("app-directory,{$dir},1")); } $ext->add($id, 'h', '', new ext_hangup('')); if ($announcement_id) { $announcement_msg = recordings_get_file($announcement_id); $ext->add($id, 's', '', new ext_setvar('MSG', "{$announcement_msg}")); } else { $ext->add($id, 's', '', new ext_setvar('MSG', "")); } $ext->add($id, 's', '', new ext_setvar('LOOPCOUNT', 0)); $ext->add($id, 's', '', new ext_setvar('__DIR-CONTEXT', $details['dircontext'])); $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT}')); $ext->add($id, 's', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}')); $ext->add($id, 's', '', new ext_gotoif('$["${CDR(disposition)}" = "ANSWERED"]', 'begin')); $ext->add($id, 's', '', new ext_answer('')); $ext->add($id, 's', '', new ext_wait('1')); $ext->add($id, 's', 'begin', new ext_digittimeout(3)); $ext->add($id, 's', '', new ext_responsetimeout($details['timeout'])); if ($retvm) { $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', 'RETURN')); } else { $ext->add($id, 's', '', new ext_setvar('__IVR_RETVM', '')); } $ext->add($id, 's', '', new ext_execif('$["${MSG}" != ""]', 'Background', '${MSG}')); $ext->add($id, 's', '', new ext_waitexten()); $ext->add($id, 'hang', '', new ext_playback('vm-goodbye')); $ext->add($id, 'hang', '', new ext_hangup('')); $default_t = true; // Actually add the IVR commands now. $dests = ivr_get_dests($item['ivr_id']); $timeout = false; $invalid = false; $addloop = false; if (!empty($dests)) { foreach ($dests as $dest) { if ($dest['selection'] == 't' && empty($details['alt_timeout'])) { $timeout = true; } elseif ($dest['selection'] == 'i' && empty($details['alt_invalid'])) { $invalid = true; } elseif ($dest['selection'] == 't' && !empty($details['alt_timeout'])) { $timeout = true; if ($timeout_id) { $timeout_msg = recordings_get_file($timeout_id); $ext->add($id, $dest['selection'], '', new ext_setvar('MSG', "{$timeout_msg}")); } $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]')); $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= ' . $loops . ']', 's,begin')); } elseif ($dest['selection'] == 'i' && !empty($details['alt_invalid'])) { $invalid = true; $ext->add($id, $dest['selection'], '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]')); if ($invalid_id) { $invalid_msg = recordings_get_file($invalid_id); $ext->add($id, $dest['selection'], '', new ext_setvar('MSG', "{$invalid_msg}")); } else { $ext->add($id, $dest['selection'], '', new ext_execif('$[${LOOPCOUNT} <= ' . $loops . ']', 'Playback', 'invalid')); } $ext->add($id, $dest['selection'], '', new ext_gotoif('$[${LOOPCOUNT} <= ' . $loops . ']', 's,begin')); } $ext->add($id, $dest['selection'], '', new ext_dbdel('${BLKVM_OVERRIDE}')); $ext->add($id, $dest['selection'], '', new ext_setvar('__NODEST', '')); // if the goto goes loops back to this ivr, then don't go to the begining or it will break the return to previous ivr info // $dest_context = trim(strtok($dest['dest'], ",|")); if ($dest_context == $id) { $dest['dest'] = $id . ',s,begin'; } if ($dest['ivr_ret']) { $ext->add($id, $dest['selection'], '', new ext_gotoif('$["x${IVR_CONTEXT_${CONTEXT}}" = "x"]', $dest['dest'] . ':${IVR_CONTEXT_${CONTEXT}},return,1')); } else { $ext->add($id, $dest['selection'], '', new ext_goto($dest['dest'])); } } } // Apply invalid if required if (!$invalid) { if ($invalid_id) { $invalid_msg = recordings_get_file($invalid_id); $ext->add($id, 'i', '', new ext_setvar('MSG', "{$invalid_msg}")); } else { $ext->add($id, 'i', '', new ext_playback('invalid')); } $ext->add($id, 'i', '', new ext_goto('loop,1')); $addloop = true; } if (!$timeout) { if ($timeout_id) { $timeout_msg = recordings_get_file($timeout_id); $ext->add($id, 't', '', new ext_setvar('MSG', "{$timeout_msg}")); } $ext->add($id, 't', '', new ext_goto('loop,1')); $addloop = true; } if ($addloop) { $ext->add($id, 'loop', '', new ext_setvar('LOOPCOUNT', '$[${LOOPCOUNT} + 1]')); $ext->add($id, 'loop', '', new ext_gotoif('$[${LOOPCOUNT} > ' . $loops . ']', 'hang,1')); $ext->add($id, 'loop', '', new ext_goto($id . ',s,begin')); // these need to be reset or inheritance problems makes them go away in some conditions and infinite inheritance creates other problems // reset the message including blanking it if set by a sub-ivr $announcement_msg = $announcement_id ? $announcement_msg : ''; $ext->add($id, 'return', '', new ext_setvar('MSG', "{$announcement_msg}")); $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT', '${CONTEXT}')); $ext->add($id, 'return', '', new ext_setvar('_IVR_CONTEXT_${CONTEXT}', '${IVR_CONTEXT_${CONTEXT}}')); $ext->add($id, 'return', '', new ext_goto($id . ',s,begin')); } } if (!empty($ddial_contexts)) { global $version; $ast_lt_14 = version_compare($version, '1.4', 'lt'); foreach (array_keys($ddial_contexts) as $dir_id) { $context = 'from-ivr-directory-' . $dir_id; $entries = function_exists('directory_get_dir_entries') ? directory_get_dir_entries($dir_id) : array(); foreach ($entries as $dstring) { $exten = $dstring['dial'] == '' ? $dstring['foreign_id'] : $dstring['dial']; if ($exten == '' || $exten == 'custom') { continue; } if ($ast_lt_14) { $ext->add($context, $exten, '', new ext_execif('$["${BLKVM_OVERRIDE}" != ""]', 'dbDel', '${BLKVM_OVERRIDE}')); } else { $ext->add($context, $exten, '', new ext_execif('$["${BLKVM_OVERRIDE}" != ""]', 'Noop', 'Deleting: ${BLKVM_OVERRIDE}: ${DB_DELETE(${BLKVM_OVERRIDE})}')); } $ext->add($context, $exten, '', new ext_setvar('__NODEST', '')); $ext->add($context, $exten, '', new ext_goto('1', $exten, 'from-internal')); } } } } break; } }