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

Revision 1627, 11.1 kB (checked in by mheydon1973, 7 years ago)

IVR brought in line with other modules dependant on System Recordings, i.e. now stores the filename of the recording instead of the database ID number. Also doesn't loose the recordings if the System Recordings module is disabled / uninstalled / re-installed.

Includes upgrade script to fix data from any version prior to this one (v2.2)

  • 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 echo "</div>\n";
26 if (empty($dircontext))
27         $dircontext = 'default';
28 // So. Lets check to make sure everything's happy
29 ivr_init();
30
31 switch ($action) {
32     case "add":
33         $id = ivr_get_ivr_id('Unnamed');
34         // Set the defaults
35         $def['timeout'] = 5;
36         $def['ena_directdial'] = 'CHECKED';
37         $def['ena_directory'] = 'CHECKED';
38         ivr_sidebar($id);
39         ivr_show_edit($id, 3$def);
40         break;
41     case "edit":
42         ivr_sidebar($id);
43         ivr_show_edit($id, $nbroptions, $_POST);
44         break;
45     case "edited":
46         if (isset($_REQUEST['delete'])) {
47             sql("DELETE from ivr where ivr_id='$id'");
48             sql("DELETE FROM ivr_dests where ivr_id='$id'");
49             needreload();
50         } else {
51             ivr_do_edit($id, $_POST);
52             ivr_sidebar($id);
53             if (isset($_REQUEST['increase']))
54                 $nbroptions++;
55             if (isset($_REQUEST['decrease'])) {
56                 $nbroptions--;
57             }
58             if ($nbroptions < 1)
59                 $nbroptions = 1;
60             ivr_show_edit($id, $nbroptions, $_POST);
61             break;
62         }
63     default:
64         ivr_sidebar($id);
65 ?>
66 <div class="content">
67 <h2><?php echo _("Digital Receptionist"); ?></h2>
68 <h3><?php
69 echo _("Instructions")."</h3>";
70 echo _("You use the Digital Receptionist to make IVR's, Interactive Voice Responce systems.")."<br />\n";
71 echo _("When creating a menu option, apart from the standard options of 0-9,* and #, you can also use 'i' and 't' destinations.")."\n";
72 echo _("'i' is used when the caller pushes an invalid button, and 't' is used when there is no response.")."\n";
73 echo _("If those options aren't supplied, the default 't' is to replay the menu three times and then hang up,")."\n";
74 echo _("and the default 'i' is to say 'Invalid option, please try again' and replay the menu.")."\n";
75 echo _("After three invalid attempts, the line is hung up.")."\n"; ?>
76 </div>
77
78 <?php
79 }
80
81
82 function ivr_sidebar($id)  {
83 ?>
84         <div class="rnav">
85         <li><a id="<?php echo empty($id)?'current':'nul' ?>" href="config.php?display=ivr&amp;action=add"><?php echo _("Add IVR")?></a></li>
86 <?php
87
88         $tresults = ivr_list();
89         if (isset($tresults)){
90                 foreach ($tresults as $tresult) {
91                         echo "<li><a id=\"".($id==$tresult['ivr_id'] ? 'current':'nul')."\" href=\"config.php?display=ivr";
92                         echo "&amp;action=edit&amp;id={$tresult['ivr_id']}\">{$tresult['displayname']}</a></li>\n";
93                 }
94         }
95         echo "</div>\n";
96 }
97
98 function ivr_show_edit($id, $nbroptions, $post) {
99     global $db;
100
101     $ivr_details = ivr_get_details($id);
102     $ivr_dests = ivr_get_dests($id);
103 ?>
104     <div class="content">
105         <h2><?php echo _("Digital Receptionist"); ?></h2>
106         <h3><?php echo _("Edit Menu")." ".$ivr_details['displayname']; ?></h3>
107 <?php
108 ?>
109         <form name="prompt" action="<?php $_SERVER['PHP_SELF'] ?>" method="post" onsubmit="return prompt_onsubmit();">
110         <input type="hidden" name="action" value="edited" />
111         <input type="hidden" name="display" value="ivr" />
112         <input type="hidden" name="id" value="<?php echo $id ?>" />
113     <input name="delete" type="submit" value="<?php echo _("Delete")." "._("Digital Receptionist")." {$ivr_details['displayname']}"; ?>">
114         <table>
115         <tr><td colspan=2><hr /></td></tr>
116         <tr>
117                 <td><a href="#" class="info">Change Name<span>This changes the short name, visible on the right, of this IVR</span></a></td>
118                 <td><input type="text" name="displayname" value="<?php echo $ivr_details['displayname'] ?>"></td>
119         </tr>
120         <tr>
121                 <td><a href="#" class="info">Timeout<span>The amount of time (in seconds) before the 't' option, if specified, is used</span></a></td>
122                 <td><input type="text" name="timeout" value="<?php echo $ivr_details['timeout'] ?>"></td>
123         </tr>
124         <tr>
125                 <td><a href="#" class="info">Enable Directory<span>Let callers into the IVR dial '#' to access the directory</span></a></td>
126                 <td><input type="checkbox" name="ena_directory" <?php echo $ivr_details['enable_directory'] ?>></td>
127         </tr>
128         <tr>
129                 <td><a href="#" class="info">Directory Context<span>When # is selected, this is the voicemail directory context that is used</span></a></td>
130                 <td>&nbsp;
131              <select name="dircontext"/>
132                         <?php
133                 $tresults = getVoicemail();
134                 $vmcontexts = array_keys($tresults);
135                 foreach ($vmcontexts as $vmc) {
136                     if ($vmc != 'general' )
137                         echo '<option value="'.$vmc.'"'.($vmc == $ivr_details['dircontext'] ? ' SELECTED' : '').'>'.$vmc."</option>\n";
138                 }
139                         ?>
140             </select>
141         </td>
142         </tr>
143         <tr>
144                 <td><a href="#" class="info">Enable Direct Dial<span>Let callers into the IVR dial an extension directly</span></a></td>
145                 <td><input type="checkbox" name="ena_directdial" <?php echo $ivr_details['enable_directdial'] ?>></td>
146         </tr>
147 <?php
148     $annmsg = isset($ivr_details['announcement'])?$ivr_details['announcement']:'';
149     if(function_exists('recordings_list')) { //only include if recordings is enabled ?>
150         <tr>
151                 <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>
152                 <td>&nbsp;
153                         <select name="annmsg"/>
154                         <?php
155                                 $tresults = recordings_list();
156                                 echo '<option value="">'._("None")."</option>";
157                                 if (isset($tresults[0])) {
158                                         foreach ($tresults as $tresult) {
159                                                 echo '<option value="'.$tresult[2].'"'.($tresult[2] == $annmsg ? ' SELECTED' : '').'>'.$tresult[1]."</option>\n";
160                                         }
161                                 }
162                         ?>
163                         </select>
164                 </td>
165         </tr>
166    
167 <?php
168     } else {
169 ?>
170     <tr>
171                 <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>
172                 <td>&nbsp;
173             <?php
174                 $default = (isset($annmsg) ? $annmsg : '');
175             ?>
176             <input type="hidden" name="annmsg" value="<?php echo $default; ?>"><?php echo ($default != '' ? $default : 'None'); ?>
177         </td>
178     </tr>
179 <?php
180     }
181 ?>
182
183
184         <tr><td colspan=2><hr /></td></tr>
185     <tr><td colspan=2>   
186     <input name="increase" type="submit" value="<?php echo _("Increase Options")?>">
187     &nbsp;
188     <input name="Submit" type="submit" value="<?php echo _("Save")?>">
189     &nbsp;
190     <?php if ($nbroptions > 1) { ?>
191     <input name="decrease" type="submit" value="<?php echo _("Decrease Options")?>">
192     <?php } ?>
193     </td></tr>
194         <tr><td colspan=2><hr /></td></tr>
195 <?php
196     // Draw the destinations
197     $dests = ivr_get_dests($id);
198     $count = 0;
199     if (!empty($dests)) {
200         foreach ($dests as $dest) {
201             drawdestinations($count, $dest['selection'], $dest['dest']);
202             $count++;
203         }
204     }
205     while ($count < $nbroptions) {
206         drawdestinations($count, null, null);
207         $count++;
208     }
209 ?>
210    
211         </table>
212 <?php
213     if ($nbroptions < $count) {
214         echo "<input type='hidden' name='nbroptions' value=$count />\n";
215     } else {
216         echo "<input type='hidden' name='nbroptions' value=$nbroptions />\n";
217     }
218 ?>
219     <input name="increase" type="submit" value="<?php echo _("Increase Options")?>">
220     &nbsp;
221     <input name="Submit" type="submit" value="<?php echo _("Save")?>">
222     &nbsp;
223     <?php if ($nbroptions > 1) { ?>
224     <input name="decrease" type="submit" value="<?php echo _("Decrease Options")?>">
225     <?php } ?>
226    
227     <script language="javascript">
228     <!--
229    
230     var theForm = document.prompt;
231    
232     function prompt_onsubmit() {
233         var msgInvalidOption = "<?php echo _("Invalid option"); ?>";
234        
235         defaultEmptyOK = true;
236
237         // go thru the form looking for options
238         // where the option isn't blank (as that will be removed) do the validation
239         var allelems = theForm.elements;
240         if (allelems != null)
241         {
242             var i, elem;
243             for (i = 0; elem = allelems[i]; i++)
244             {
245                 if (elem.type == 'text' && elem.name.indexOf('option') == 0)
246                 {
247                     if (elem.value != '') {
248                         if (!isIVROption(elem.value))
249                             return warnInvalid(elem, msgInvalidOption);
250                        
251                         var gotoNum = elem.name.charAt(6);
252                         var isok = validateSingleDestination(theForm,gotoNum,true);
253                         if (!isok)
254                             return false;
255                     }
256                  }
257               }
258         }
259                                  
260         return true;
261     }
262    
263     //-->
264     </script>
265         </form>
266         </div>
267
268
269 <?php
270
271 echo "</div>\n";
272 }
273
274 function drawdestinations($count, $sel$dest) { ?>
275     <tr> <td style="text-align:right;">
276         <input size="2" type="text" name="option<?php echo $count ?>" value="<?php echo $sel ?>"><br />
277 <?php if (strlen($sel)) {  ?>
278         <i style='font-size: x-small'>Leave blank to remove</i>
279 <?php ?>
280     </td>
281         <td> <table> <?php echo drawselects($dest,$count); ?> </table> </td>
282     </tr>
283     <tr><td colspan=2><hr /></td></tr>
284 <?php
285 }
286
287 /* this should be in /admin/functions.inc.php
288 function runModuleSQL($moddir,$type){
289         global $db;
290         $data='';
291         if (is_file("modules/{$moddir}/{$type}.sql")) {
292                 // run sql script
293                 $fd = fopen("modules/{$moddir}/{$type}.sql","r");
294                 while (!feof($fd)) {
295                         $data .= fread($fd, 1024);
296                 }
297                 fclose($fd);
298
299                 preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP).*);\s*\n/Us", $data, $matches);
300
301                 foreach ($matches[1] as $sql) {
302                                 $result = $db->query($sql);
303                                 if(DB::IsError($result)) {
304                                         return false;
305                                 }
306                 }
307                 return true;
308         }
309                 return true;
310 }
311
312 */
313
314 ?>
315
Note: See TracBrowser for help on using the browser.