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

Revision 3790, 12.1 kB (checked in by p_lindheimer, 5 years ago)

Merged revisions 3760,3762-3765,3767-3772,3774-3779,3782,3785,3787-3789 via svnmerge from
https://amportal.svn.sourceforge.net/svnroot/amportal/modules/branches/2.2

........

r3760 | gregmac | 2007-02-09 14:44:33 -0800 (Fri, 09 Feb 2007) | 2 lines


Fix for IVR deleting as default submit action (if you press enter in a form field)

........

r3789 | p_lindheimer | 2007-02-16 10:48:34 -0800 (Fri, 16 Feb 2007) | 1 line


Allow option for IVR to loop back to itself without corrupting the return-to-ivr to the parent

........

  • 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         <table>
117         <tr><td colspan=2><hr /></td></tr>
118         <tr>
119                 <td><a href="#" class="info">Change Name<span>This changes the short name, visible on the right, of this IVR</span></a></td>
120                 <td><input type="text" name="displayname" value="<?php echo $ivr_details['displayname'] ?>"></td>
121         </tr>
122         <tr>
123                 <td><a href="#" class="info">Timeout<span>The amount of time (in seconds) before the 't' option, if specified, is used</span></a></td>
124                 <td><input type="text" name="timeout" value="<?php echo $ivr_details['timeout'] ?>"></td>
125         </tr>
126         <?php if ( function_exists('voicemail_getVoicemail') ) { ?>
127         <tr>
128                 <td><a href="#" class="info">Enable Directory<span>Let callers into the IVR dial '#' to access the directory</span></a></td>
129                 <td><input type="checkbox" name="ena_directory" <?php echo $ivr_details['enable_directory'] ?>></td>
130         </tr>
131         <tr>
132                 <td><a href="#" class="info">Directory Context<span>When # is selected, this is the voicemail directory context that is used</span></a></td>
133                 <td>&nbsp;
134        <select name="dircontext"/>
135                         <?php
136         $tresults = voicemail_getVoicemail();
137         $vmcontexts = array_keys($tresults);
138         foreach ($vmcontexts as $vmc) {
139           if ($vmc != 'general' )
140             echo '<option value="'.$vmc.'"'.($vmc == $ivr_details['dircontext'] ? ' SELECTED' : '').'>'.$vmc."</option>\n";
141         }
142                         ?>
143       </select>
144     </td>
145         </tr>
146         <?php } ?>
147         <tr>
148                 <td><a href="#" class="info">Enable Direct Dial<span>Let callers into the IVR dial an extension directly</span></a></td>
149                 <td><input type="checkbox" name="ena_directdial" <?php echo $ivr_details['enable_directdial'] ?>></td>
150         </tr>
151 <?php
152     $annmsg = isset($ivr_details['announcement'])?$ivr_details['announcement']:'';
153   if(function_exists('recordings_list')) { //only include if recordings is enabled ?>
154         <tr>
155                 <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>
156                 <td>&nbsp;
157                         <select name="annmsg"/>
158                         <?php
159                                 $tresults = recordings_list();
160                                 echo '<option value="">'._("None")."</option>";
161                                 if (isset($tresults[0])) {
162                                         foreach ($tresults as $tresult) {
163                                                 echo '<option value="'.$tresult[2].'"'.($tresult[2] == $annmsg ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
164                                         }
165                                 }
166                         ?>
167                         </select>
168                 </td>
169         </tr>
170  
171 <?php
172   } else {
173 ?>
174   <tr>
175                 <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>
176                 <td>&nbsp;
177       <?php
178         $default = (isset($annmsg) ? $annmsg : '');
179       ?>
180       <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
181     </td>
182   </tr>
183 <?php
184   }
185 ?>
186
187
188         <tr><td colspan=2><hr /></td></tr>
189   <tr><td colspan=2> 
190   <input name="increase" type="submit" value="<?php echo _("Increase Options")?>">
191   &nbsp;
192   <input name="Submit" type="submit" value="<?php echo _("Save")?>">
193   &nbsp;
194   <?php if ($nbroptions > 1) { ?>
195   <input name="decrease" type="submit" value="<?php echo _("Decrease Options")?>">
196   <?php } ?>
197   </td></tr>
198         <tr><td colspan=2><hr /></td></tr>
199 <?php
200   // Draw the destinations
201   $dests = ivr_get_dests($id);
202   $count = 0;
203   if (!empty($dests)) {
204     foreach ($dests as $dest) {
205       drawdestinations($count, $dest['selection'], $dest['dest'], $dest['ivr_ret']);
206       $count++;
207     }
208   }
209   while ($count < $nbroptions) {
210     drawdestinations($count, null, null, 0);
211     $count++;
212   }
213 ?>
214  
215         </table>
216 <?php
217   if ($nbroptions < $count) {
218     echo "<input type='hidden' name='nbroptions' value=$count />\n";
219   } else {
220     echo "<input type='hidden' name='nbroptions' value=$nbroptions />\n";
221   }
222 ?>
223   <input name="increase" type="submit" value="<?php echo _("Increase Options")?>">
224   &nbsp;
225   <input name="Submit" type="submit" value="<?php echo _("Save")?>">
226   &nbsp;
227   <?php if ($nbroptions > 1) { ?>
228   <input name="decrease" type="submit" value="<?php echo _("Decrease Options")?>">
229   <?php } ?>
230  
231   <script language="javascript">
232   <!--
233  
234   var theForm = document.prompt;
235  
236   function prompt_onsubmit() {
237     var msgInvalidOption = "<?php echo _("Invalid option"); ?>";
238     
239     defaultEmptyOK = true;
240
241     // go thru the form looking for options
242     // where the option isn't blank (as that will be removed) do the validation
243       var allelems = theForm.elements;
244         if (allelems != null)
245         {
246           var i, elem;
247             for (i = 0; elem = allelems[i]; i++)
248             {
249               if (elem.type == 'text' && elem.name.indexOf('option') == 0)
250                 {
251                   if (elem.value != '') {
252                       if (!isIVROption(elem.value))
253                           return warnInvalid(elem, msgInvalidOption);
254                         
255                         var gotoNum = elem.name.charAt(6);
256                         var isok = validateSingleDestination(theForm,gotoNum,true);
257                         if (!isok)
258                           return false;
259                     }
260                  }
261             }
262         }
263                                 
264     return true;
265   }
266  
267   //-->
268   </script>
269         </form>
270         </div>
271
272
273 <?php
274
275 echo "</div>\n";
276 }
277
278 function drawdestinations($count, $sel,  $dest, $ivr_ret) { ?>
279   <tr> <td style="text-align:right;">
280
281     <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><input type="checkbox" name="ivr_ret<?php echo $count ?>" "<?php echo $ivr_ret?'CHECKED':''; ?>"<br><br />
282     <input size="2" type="text" name="option<?php echo $count ?>" value="<?php echo $sel ?>"><br />
283 <?php if (strlen($sel)) {  ?>
284     <i style='font-size: x-small'>Leave blank to remove</i>
285 <?php }  ?>
286   </td>
287     <td> <table> <?php echo drawselects($dest,$count); ?> </table> </td>
288   </tr>
289   <tr><td colspan=2><hr /></td></tr>
290 <?php
291 }
292
293 // this can be removed in 2.2 and put back to just runModuleSQL which is in admin/functions.inc.php
294 // I didn't want to do it in 2.1 as there's a significant user base out there, and it will break
295 // them if we do it here.
296
297 function localrunModuleSQL($moddir,$type){
298         global $db;
299         $data='';
300         if (is_file("modules/{$moddir}/{$type}.sql")) {
301                 // run sql script
302                 $fd = fopen("modules/{$moddir}/{$type}.sql","r");
303                 while (!feof($fd)) {
304                         $data .= fread($fd, 1024);
305                 }
306                 fclose($fd);
307
308                 preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP).*);\s*\n/Us", $data, $matches);
309
310                 foreach ($matches[1] as $sql) {
311                                 $result = $db->query($sql);
312                                 if(DB::IsError($result)) {
313                                         return false;
314                                 }
315                 }
316                 return true;
317         }
318                 return true;
319 }
320
321 ?>
Note: See TracBrowser for help on using the browser.