root/modules/branches/2.4/ivr/page.ivr.php

Revision 7860, 13.4 kB (checked in by p_lindheimer, 4 years ago)

Merged revisions 7858-7859 via svnmerge from
http://svn.freepbx.org/modules/branches/2.5

........

r7858 | p_lindheimer | 2009-06-23 10:15:37 -0700 (Tue, 23 Jun 2009) | 1 line


fixes #3734 set FORWARD_CONTEXT before paging to block client side CF

........

r7859 | p_lindheimer | 2009-06-23 12:40:39 -0700 (Tue, 23 Jun 2009) | 1 line


ref #3732 missing enclosing ()

........

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?php
2 /* $Id$ */
3 //Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
4 //
5 //This program is free software; you can redistribute it and/or
6 //modify it under the terms of the GNU General Public License
7 //as published by the Free Software Foundation; either version 2
8 //of the License, or (at your option) any later version.
9 //
10 //This program is distributed in the hope that it will be useful,
11 //but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //GNU General Public License for more details.
14
15 // The Digital Receptionist code is a rat's nest.  If you are planning on making significant modifications, just re-write from scratch.
16 // OK! You're the boss. --Rob
17 // Re-written from the ground up by Rob Thomas <xrobau@gmail.com> 23rd March, 2006.
18
19
20 $action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
21 $id = isset($_REQUEST['id'])?$_REQUEST['id']:'';
22 $dircontext = isset($_SESSION["AMP_user"]->_deptname)?$_SESSION["AMP_user"]->_deptname:'';
23 $nbroptions = isset($_REQUEST['nbroptions'])?$_REQUEST['nbroptions']:'3';
24
25 if (empty($dircontext))
26         $dircontext = 'default';
27 // So. Lets check to make sure everything's happy
28 ivr_init();
29
30 switch ($action) {
31     case "add":
32         $id = ivr_get_ivr_id('Unnamed');
33         // Set the defaults
34         $def['timeout'] = 5;
35         $def['ena_directdial'] = 'CHECKED';
36         $def['ena_directory'] = 'CHECKED';
37         ivr_sidebar($id);
38         ivr_show_edit($id, 3$def);
39         break;
40     case "edit":
41         ivr_sidebar($id);
42         ivr_show_edit($id, $nbroptions, $_POST);
43         break;
44     case "edited":
45         if (isset($_REQUEST['delete'])) {
46             sql("DELETE from ivr where ivr_id='$id'");
47             sql("DELETE FROM ivr_dests where ivr_id='$id'");
48             needreload();
49         } else {
50             ivr_do_edit($id, $_POST);
51             ivr_sidebar($id);
52             if (isset($_REQUEST['increase']))
53                 $nbroptions++;
54             if (isset($_REQUEST['decrease'])) {
55                 $nbroptions--;
56             }
57             if ($nbroptions < 1)
58                 $nbroptions = 1;
59             //ivr_show_edit($id, $nbroptions, $_POST);
60             $url = 'config.php?type=setup&display=ivr&action=edit&id='.$id.'&nbroptions='.$nbroptions;
61             redirect($url);
62             break;
63         }
64     default:
65         ivr_sidebar($id);
66 ?>
67 <div class="content">
68 <h2><?php echo _("Digital Receptionist"); ?></h2>
69 <h3><?php
70 echo _("Instructions")."</h3>";
71 echo _("You use the Digital Receptionist to make IVR's, Interactive Voice Responce systems.")."<br />\n";
72 echo _("When creating a menu option, apart from the standard options of 0-9,* and #, you can also use 'i' and 't' destinations.")."\n";
73 echo _("'i' is used when the caller pushes an invalid button, and 't' is used when there is no response.")."\n";
74 echo _("If those options aren't supplied, the default 't' is to replay the menu three times and then hang up,")."\n";
75 echo _("and the default 'i' is to say 'Invalid option, please try again' and replay the menu.")."\n";
76 echo _("After three invalid attempts, the line is hung up.")."\n"; ?>
77 </div>
78
79 <?php
80 }
81
82
83 function ivr_sidebar($id)  {
84 ?>
85         <div class="rnav"><ul>
86         <li><a id="<?php echo empty($id)?'current':'nul' ?>" href="config.php?display=ivr&amp;action=add"><?php echo _("Add IVR")?></a></li>
87 <?php
88
89         $tresults = ivr_list();
90         if (isset($tresults)){
91                 foreach ($tresults as $tresult) {
92                         echo "<li><a id=\"".($id==$tresult['ivr_id'] ? 'current':'nul')."\" href=\"config.php?display=ivr";
93                         echo "&amp;action=edit&amp;id={$tresult['ivr_id']}\">{$tresult['displayname']}</a></li>\n";
94                 }
95         }
96         echo "</ul></div>\n";
97 }
98
99 function ivr_show_edit($id, $nbroptions, $post) {
100     global $db;
101
102     $ivr_details = ivr_get_details($id);
103     $ivr_dests = ivr_get_dests($id);
104 ?>
105     <div class="content">
106     <h2><?php echo _("Digital Receptionist"); ?></h2>
107     <h3><?php echo _("Edit Menu")." ".$ivr_details['displayname']; ?></h3>
108 <?php
109 ?>
110     <form name="prompt" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return prompt_onsubmit();">
111     <input type="hidden" name="action" value="edited" />
112     <input type="hidden" name="display" value="ivr" />
113     <input type="hidden" name="id" value="<?php echo $id ?>" />
114     <input name="Submit" type="submit" style="display:none;" value="save" />
115     <input name="delete" type="submit" value="<?php echo _("Delete")." "._("Digital Receptionist")." {$ivr_details['displayname']}"; ?>" />
116     <?php
117     if ($id) {
118         $usage_list = framework_display_destination_usage(ivr_getdest($id));
119         if (!empty($usage_list)) {
120         ?>
121             <br /><a href="#" class="info"><?php echo $usage_list['text']?>:<span><?php echo $usage_list['tooltip']?></span></a>
122         <?php
123         }
124     }
125     ?>
126     <table>
127         <tr><td colspan=2><hr /></td></tr>
128         <tr>
129             <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>
130             <td><input type="text" name="displayname" value="<?php echo $ivr_details['displayname'] ?>"></td>
131         </tr>
132         <tr>
133             <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>
134             <td><input type="text" name="timeout" value="<?php echo $ivr_details['timeout'] ?>"></td>
135         </tr>
136         <?php if ( function_exists('voicemail_getVoicemail') ) { ?>
137         <tr>
138             <td><a href="#" class="info"><?php echo _("Enable Directory");?><span><?php echo _("Let callers into the IVR dial '#' to access the directory");?></span></a></td>
139             <td><input type="checkbox" name="ena_directory" <?php echo $ivr_details['enable_directory'] ?>></td>
140         </tr>
141         <tr>
142             <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>
143             <td>
144                 <select name="dircontext">
145                     <?php
146                     $tresults = voicemail_getVoicemail();
147                     $vmcontexts = array_keys($tresults);
148                     foreach ($vmcontexts as $vmc) {
149                         if (($vmc != 'general') && ($vmc != 'zonemessages')) {
150                             echo '<option value="'.$vmc.'"'.($vmc == $ivr_details['dircontext'] ? ' SELECTED' : '').'>'.$vmc."</option>\n";
151             }
152                     }
153                     ?>
154                 </select>
155             </td>
156         </tr>
157         <?php } ?>
158         <tr>
159             <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>
160             <td><input type="checkbox" name="ena_directdial" <?php echo $ivr_details['enable_directdial'] ?>></td>
161         </tr>
162         <tr>
163             <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 begining if no input is provided for the designated loop counts prior to going to the timeout (t) destination.");?></span></a></td>
164             <td><input type="checkbox" name="alt_timeout" <?php echo $ivr_details['alt_timeout'] ?>></td>
165         </tr>
166         <tr>
167             <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 begining for the designated loop counts prior to going to the invalid (i) destination.");?></span></a></td>
168             <td><input type="checkbox" name="alt_invalid" <?php echo $ivr_details['alt_invalid'] ?>></td>
169         </tr>
170         <tr>
171             <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>
172             <td>
173                 <select name="loops">
174                 <?php
175                     $default = (isset($ivr_details['loops']) ? $ivr_details['loops'] : 2);
176                     for ($i=0; $i <= 9; $i++) {
177                         echo '<option value="'.$i.'" '.($i == $default ? 'SELECTED' : '').'>'.$i.'</option>';
178                     }
179                 ?>       
180                 </select>       
181             </td>
182         </tr>
183 <?php
184             $annmsg = isset($ivr_details['announcement'])?$ivr_details['announcement']:'';
185             if(function_exists('recordings_list')) { //only include if recordings is enabled ?>
186         <tr>
187             <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>
188             <td>
189                 <select name="annmsg">
190                 <?php
191                     $tresults = recordings_list();
192                     echo '<option value="">'._("None")."</option>";
193                     if (isset($tresults[0])) {
194                         foreach ($tresults as $tresult) {
195                             echo '<option value="'.$tresult[2].'"'.($tresult[2] == $annmsg ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
196                         }
197                     }
198                 ?>
199                 </select>
200             </td>
201         </tr>
202    
203 <?php
204     } else {
205 ?>
206         <tr>
207             <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>
208             <td>
209             <?php
210                 $default = (isset($annmsg) ? $annmsg : '');
211             ?>
212                 <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
213             </td>
214         </tr>
215 <?php
216     }
217 ?>
218
219
220         <tr><td colspan=2><hr /></td></tr>
221         <tr><td colspan=2>   
222             <input name="increase" type="submit" value="<?php echo _("Increase Options")?>">
223             &nbsp;
224             <input name="Submit" type="submit" value="<?php echo _("Save")?>">
225             &nbsp;
226             <?php if ($nbroptions > 1) { ?>
227             <input name="decrease" type="submit" value="<?php echo _("Decrease Options")?>">
228             <?php } ?>
229         </td>
230     </tr>
231     <tr><td colspan=2><hr /></td></tr>
232 <?php
233     // Draw the destinations
234     $dests = ivr_get_dests($id);
235     $count = 0;
236     if (!empty($dests)) {
237         foreach ($dests as $dest) {
238             drawdestinations($count, $dest['selection'], $dest['dest'], $dest['ivr_ret']);
239             $count++;
240         }
241     }
242     while ($count < $nbroptions) {
243         drawdestinations($count, null, null, 0);
244         $count++;
245     }
246 ?>
247    
248 </table>
249 <?php
250     if ($nbroptions < $count) {
251         echo "<input type='hidden' name='nbroptions' value=$count />\n";
252     } else {
253         echo "<input type='hidden' name='nbroptions' value=$nbroptions />\n";
254     }
255 ?>
256     <input name="increase" type="submit" value="<?php echo _("Increase Options")?>">
257     &nbsp;
258     <input name="Submit" type="submit" value="<?php echo _("Save")?>">
259     &nbsp;
260     <?php if ($nbroptions > 1) { ?>
261     <input name="decrease" type="submit" value="<?php echo _("Decrease Options")?>">
262     <?php } ?>
263    
264     <script language="javascript">
265     <!--
266    
267     var theForm = document.prompt;
268    
269     function prompt_onsubmit() {
270         var msgInvalidOption = "<?php echo _("Invalid option"); ?>";
271        
272         defaultEmptyOK = true;
273
274         // go thru the form looking for options
275         // where the option isn't blank (as that will be removed) do the validation
276         var allelems = theForm.elements;
277         if (allelems != null)
278         {
279             var i, elem;
280             for (i = 0; elem = allelems[i]; i++)
281             {
282                 if (elem.type == 'text' && elem.name.indexOf('option') == 0)
283                 {
284                     if (elem.value != '') {
285                         if (!isIVROption(elem.value))
286                             return warnInvalid(elem, msgInvalidOption);
287                        
288                         var gotoNum = elem.name.charAt(6);
289                         var isok = validateSingleDestination(theForm,gotoNum,true);
290                         if (!isok)
291                             return false;
292                     }
293                  }
294               }
295         }
296                                  
297         return true;
298     }
299    
300     //-->
301     </script>
302         </form>
303         </div>
304
305
306 <?php
307
308 echo "</div>\n";
309 }
310
311 function drawdestinations($count, $sel$dest, $ivr_ret) { ?>
312     <tr> <td style="text-align:right;">
313
314     <small><a href="#" class="info"><?php echo _("Return to IVR")?><span><?php echo _("Check this box to have this option return to a parent IVR if it was called from a parent IVR. If not, it will go to the chosen destination.<br><br>The return path will be to any IVR that was in the call path prior to this IVR which could lead to strange results if there was an IVR called in the call path but not immediately before this")?></span></a></small>
315     <input type="checkbox" name="ivr_ret<?php echo $count ?>" value="ivr_ret" <?php echo $ivr_ret?'CHECKED':''; ?>><br><br />
316         <input size="2" type="text" name="option<?php echo $count ?>" value="<?php echo $sel ?>"><br />
317 <?php if (strlen($sel)) {  ?>
318         <i style='font-size: x-small'>Leave blank to remove</i>
319 <?php ?>
320     </td>
321         <td> <table> <?php echo drawselects($dest,$count); ?> </table> </td>
322     </tr>
323     <tr><td colspan=2><hr /></td></tr>
324 <?php
325 }
326
327 // this can be removed in 2.2 and put back to just runModuleSQL which is in admin/functions.inc.php
328 // I didn't want to do it in 2.1 as there's a significant user base out there, and it will break
329 // them if we do it here.
330
331 function localrunModuleSQL($moddir,$type){
332         global $db;
333         $data='';
334         if (is_file("modules/{$moddir}/{$type}.sql")) {
335                 // run sql script
336                 $fd = fopen("modules/{$moddir}/{$type}.sql","r");
337                 while (!feof($fd)) {
338                         $data .= fread($fd, 1024);
339                 }
340                 fclose($fd);
341
342                 preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP).*);\s*\n/Us", $data, $matches);
343
344                 foreach ($matches[1] as $sql) {
345                                 $result = $db->query($sql);
346                                 if(DB::IsError($result)) {
347                                         return false;
348                                 }
349                 }
350                 return true;
351         }
352                 return true;
353 }
354
355 ?>
356
Note: See TracBrowser for help on using the browser.