root/modules/branches/2.2/voicemail/functions.inc.php

Revision 3359, 12.8 kB (checked in by qldrob, 6 years ago)

Fix for #1552, voicemail changes not being updated in device and user mode.

  • Property svn:mime-type set to text/html
  • Property svn:eol-style set to native
Line 
1 <?php
2
3 function voicemail_get_config($engine) {
4   $modulename = 'voicemail';
5  
6   // This generates the dialplan
7   global $ext; 
8   switch($engine) {
9     case "asterisk":
10       if (is_array($featurelist = featurecodes_getModuleFeatures($modulename))) {
11         foreach($featurelist as $item) {
12           $featurename = $item['featurename'];
13           $fname = $modulename.'_'.$featurename;
14           if (function_exists($fname)) {
15             $fcc = new featurecode($modulename, $featurename);
16             $fc = $fcc->getCodeActive();
17             unset($fcc);
18             
19             if ($fc != '')
20               $fname($fc);
21           } else {
22             $ext->add('from-internal-additional', 'debug', '', new ext_noop($modulename.": No func $fname"));
23             var_dump($item);
24           }
25         }
26       }
27     break;
28   }
29 }
30
31 function voicemail_myvoicemail($c) {
32   global $ext;
33
34   $id = "app-vmmain"; // The context to be included
35
36   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
37
38   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
39   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
40   $ext->add($id, $c, '', new ext_macro('user-callerid')); // $cmd,n,Macro(user-callerid)
41   $ext->add($id, $c, '', new ext_macro('get-vmcontext','${CALLERID(num)}'));
42   $ext->add($id, $c, '', new ext_vmmain('${CALLERID(num)}@${VMCONTEXT}')); // n,VoiceMailMain(${VMCONTEXT})
43   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
44 }
45
46 function voicemail_dialvoicemail($c) {
47   global $ext;
48
49   $id = "app-dialvm"; // The context to be included
50
51   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
52
53   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
54   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
55   $ext->add($id, $c, '', new ext_vmmain('')); // n,VoiceMailMain(${VMCONTEXT})
56   $ext->add($id, $c, '', new ext_macro('hangupcall'));
57
58   // Note that with this one, it has paramters. So we have to add '_' to the start and '.' to the end
59   // of $c
60   $c = "_$c.";
61   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
62   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
63   // How long is the command? We need to strip that off the front
64   $clen = strlen($c)-2;
65   $ext->add($id, $c, '', new ext_macro('get-vmcontext','${EXTEN:'.$clen.'}'));
66   $ext->add($id, $c, '', new ext_vmmain('${EXTEN:'.$clen.'}@${VMCONTEXT}')); // n,VoiceMailMain(${VMCONTEXT})
67   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
68 }
69
70 function voicemail_configpageinit($pagename) {
71   global $currentcomponent;
72
73   $action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
74   $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
75   $extension = isset($_REQUEST['extension'])?$_REQUEST['extension']:null;
76   $tech_hardware = isset($_REQUEST['tech_hardware'])?$_REQUEST['tech_hardware']:null;
77
78
79        // We only want to hook 'users' or 'extensions' pages.
80   if ($pagename != 'users' && $pagename != 'extensions') 
81     return true;
82   // On a 'new' user, 'tech_hardware' is set, and there's no extension. Hook into the page.
83   if ($tech_hardware != null ) {
84     voicemail_applyhooks();
85   } elseif ($action=="add") {
86   // We don't need to display anything on an 'add', but we do need to handle returned data.
87     // ** WARNING **
88     // Mailbox must be processed before adding / deleting users, therefore $sortorder = 1
89     $currentcomponent->addprocessfunc('voicemail_configprocess', 1);
90     // JS function needed for checking voicemail = Enabled
91     $js = 'return (theForm.vm.value == "enabled");';
92   } elseif ($extdisplay != '' || $pagename == 'users') {
93   // We're now viewing an extension, so we need to display _and_ process.
94     voicemail_applyhooks();
95     $currentcomponent->addprocessfunc('voicemail_configprocess', 1);
96     $js = 'return (theForm.vm.value == "enabled");';
97     $currentcomponent->addjsfunc('isVoiceMailEnabled(notused)',$js);
98   }
99 }
100
101 function voicemail_applyhooks() {
102   global $currentcomponent;
103
104   // Setup two option lists we need
105   // Enable / Disable list
106   $currentcomponent->addoptlistitem('vmena', 'enabled', 'Enabled');
107   $currentcomponent->addoptlistitem('vmena', 'disabled', 'Disabled');
108   $currentcomponent->setoptlistopts('vmena', 'sort', false);
109   // Yes / No Radio button list
110   $currentcomponent->addoptlistitem('vmyn', 'yes', 'yes');
111   $currentcomponent->addoptlistitem('vmyn', 'no', 'no');
112   $currentcomponent->setoptlistopts('vmyn', 'sort', false);
113
114   // Add the 'proces' function
115   $currentcomponent->addguifunc('voicemail_configpageload');
116 }
117
118
119 function voicemail_configpageload() {
120   global $currentcomponent;
121
122   // Init vars from $_REQUEST[]
123   $action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
124   $ext = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
125   $extn = isset($_REQUEST['extension'])?$_REQUEST['extension']:null;
126   $display = isset($_REQUEST['display'])?$_REQUEST['display']:null;
127  
128   if ($ext==='') {
129     $extdisplay = $extn;
130   } else {
131     $extdisplay = $ext;
132   }
133   if ($action != 'del') {
134     $vmbox = voicemail_mailbox_get($extdisplay);
135     if ( $vmbox == null ) {
136       $vm = false;
137       $incontext = 'default';
138       $vmpwd = null;
139       $name = null;
140       $email = null;
141       $pager = null;
142       $vmoptions = null;
143     } else {
144       $incontext = isset($vmbox['vmcontext'])?$vmbox['vmcontext']:'default';
145       $vmpwd = $vmbox['pwd'];
146       $name = $vmbox['name'];
147       $email = $vmbox['email'];
148       $pager = $vmbox['pager'];
149       $vmoptions = $vmbox['options'];
150       $vm = true;
151     }
152
153     //loop through all options
154     $options="";
155     if ( isset($vmoptions) && is_array($vmoptions) ) {
156       $alloptions = array_keys($vmoptions);
157       if (isset($alloptions)) {
158         foreach ($alloptions as $option) {
159           if ( ($option!="attach") && ($option!="envelope") && ($option!="saycid") && ($option!="delete") && ($option!='') )
160               $options .= $option.'='.$vmoptions[$option].'|';
161         }
162         $options = rtrim($options,'|');
163         // remove the = sign if there are no options set
164         $options = rtrim($options,'=');
165         
166       }
167       extract($vmoptions, EXTR_PREFIX_ALL, "vmops");
168     } else {
169       $vmops_attach = 'no';
170       $vmops_saycid = 'no';
171       $vmops_envelope = 'no';
172       $vmops_delete = 'no';
173     }
174
175     //AMP Users can only add to their department's context
176     $vmcontext = isset($_SESSION["AMP_user"]->_deptname)?$_SESSION["AMP_user"]->_deptname:null;
177
178     if (empty($vmcontext))
179       $vmcontext = (isset($_REQUEST['vmcontext']) ? $_REQUEST['vmcontext'] : $incontext);
180     if (empty($vmcontext))
181       $vmcontext = 'default';
182     
183     if ( $vm==true ) {
184       $vmselect = "enabled";
185     } else {
186       $vmselect = "disabled";
187     }
188     
189     $fc_vm = featurecodes_getFeatureCode('voicemail', 'dialvoicemail');
190
191     $msgInvalidVmPwd = 'Please enter a valid Voicemail Password, using digits only';
192     $msgInvalidEmail = 'Please enter a valid Email Address';
193     $msgInvalidPager = 'Please enter a valid Pager Email Address';
194     $msgInvalidVMContext = 'VM Context cannot be blank';
195
196     $section = 'Voicemail & Directory';
197     $currentcomponent->addguielem($section, new gui_selectbox('vm', $currentcomponent->getoptlist('vmena'), $vmselect, 'Status', '', false));
198     $currentcomponent->addguielem($section, new gui_textbox('vmpwd', $vmpwd, 'voicemail password', "This is the password used to access the voicemail system.<br><br>This password can only contain numbers.<br><br>A user can change the password you enter here after logging into the voicemail system ($fc_vm) with a phone.", "frm_${display}_isVoiceMailEnabled() && !isInteger()", $msgInvalidVmPwd, false));
199     $currentcomponent->addguielem($section, new gui_textbox('email', $email, 'email address', "The email address that voicemails are sent to.", "frm_${display}_isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true));
200     $currentcomponent->addguielem($section, new gui_textbox('pager', $pager, 'pager email address', "Pager/mobile email address that short voicemail notifcations are sent to.", "frm_${display}_isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true));
201     $currentcomponent->addguielem($section, new gui_radio('attach', $currentcomponent->getoptlist('vmyn'), $vmops_attach, 'email attachment', "Option to attach voicemails to email."));
202     $currentcomponent->addguielem($section, new gui_radio('saycid', $currentcomponent->getoptlist('vmyn'), $vmops_saycid, 'Play CID', "Read back caller's telephone number prior to playing the incoming message, and just after announcing the date and time the message was left."));
203     $currentcomponent->addguielem($section, new gui_radio('envelope', $currentcomponent->getoptlist('vmyn'), $vmops_envelope, 'Play Envelope', "Envelope controls whether or not the voicemail system will play the message envelope (date/time) before playing the voicemail message. This settng does not affect the operation of the envelope option in the advanced voicemail menu."));
204     $currentcomponent->addguielem($section, new gui_radio('delete', $currentcomponent->getoptlist('vmyn'), $vmops_delete, 'Delete Vmail', "If set to \"yes\" the message will be deleted from the voicemailbox (after having been emailed). Provides functionality that allows a user to receive their voicemail via email alone, rather than having the voicemail able to be retrieved from the Webinterface or the Extension handset.  CAUTION: MUST HAVE attach voicemail to email SET TO YES OTHERWISE YOUR MESSAGES WILL BE LOST FOREVER."));
205     $currentcomponent->addguielem($section, new gui_textbox('options', $options, 'vm options', 'Separate options with pipe ( | )<br><br>ie: review=yes|maxmessage=60'));
206     $currentcomponent->addguielem($section, new gui_textbox('vmcontext', $vmcontext, 'vm context', '', "frm_${display}_isVoiceMailEnabled() && isEmpty()", $msgInvalidVMContext, false));
207   }
208 }
209
210 function voicemail_configprocess() {
211   //create vars from the request
212   extract($_REQUEST);
213   $action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
214   $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
215  
216   //if submitting form, update database
217   switch ($action) {
218     case "add":
219       voicemail_mailbox_add($extdisplay, $_REQUEST);
220       needreload();
221     break;
222     case "del":
223       voicemail_mailbox_del($extdisplay);
224       needreload();
225     break;
226     case "edit":
227       voicemail_mailbox_del($extdisplay);
228       if ( $vm != 'disabled' )
229         voicemail_mailbox_add($extdisplay, $_REQUEST);
230       needreload();
231     break;
232   }
233 }
234
235 function voicemail_mailbox_get($mbox) {
236   $uservm = voicemail_getVoicemail();
237   $vmcontexts = array_keys($uservm);
238
239   foreach ($vmcontexts as $vmcontext) {
240     if(isset($uservm[$vmcontext][$mbox])){
241       $vmbox['vmcontext'] = $vmcontext;
242       $vmbox['pwd'] = $uservm[$vmcontext][$mbox]['pwd'];
243       $vmbox['name'] = $uservm[$vmcontext][$mbox]['name'];
244       $vmbox['email'] = $uservm[$vmcontext][$mbox]['email'];
245       $vmbox['pager'] = $uservm[$vmcontext][$mbox]['pager'];
246       $vmbox['options'] = $uservm[$vmcontext][$mbox]['options'];
247       return $vmbox;
248     }
249   }
250  
251   return null;
252 }
253
254 function voicemail_mailbox_del($mbox) {
255   $uservm = voicemail_getVoicemail();
256   $vmcontexts = array_keys($uservm);
257
258   foreach ($vmcontexts as $vmcontext) {
259     if(isset($uservm[$vmcontext][$mbox])){
260       unset($uservm[$vmcontext][$mbox]);
261       voicemail_saveVoicemail($uservm);
262       return true;
263     }
264   }
265  
266   return false;
267 }
268
269 function voicemail_mailbox_add($mbox, $mboxoptsarray) {
270   //check if VM box already exists
271   if ( voicemail_mailbox_get($mbox) != null ) {
272     trigger_error("Voicemail mailbox '$mbox' already exists, call to voicemail_maibox_add failed");
273     die();
274   }
275  
276   $uservm = voicemail_getVoicemail();
277   extract($mboxoptsarray);
278  
279   if ($vm != 'disabled')
280   {
281     // need to check if there are any options entered in the text field
282     if ($options!=''){
283       $options = explode("|",$options);
284       foreach($options as $option) {
285         $vmoption = explode("=",$option);
286         $vmoptions[$vmoption[0]] = $vmoption[1];
287       }
288     }
289     $vmoption = explode("=",$attach);
290       $vmoptions[$vmoption[0]] = $vmoption[1];
291     $vmoption = explode("=",$saycid);
292       $vmoptions[$vmoption[0]] = $vmoption[1];
293     $vmoption = explode("=",$envelope);
294       $vmoptions[$vmoption[0]] = $vmoption[1];
295     $vmoption = explode("=",$delete);
296       $vmoptions[$vmoption[0]] = $vmoption[1];
297       
298     $uservm[$vmcontext][$extension] = array(
299       'mailbox' => $extension,
300       'pwd' => $vmpwd,
301       'name' => $name,
302       'email' => $email,
303       'pager' => $pager,
304       'options' => $vmoptions
305       );
306     // Update $_REQUEST with 'devinfo_mailbox, so MWI works.
307     if (empty($_REQUEST['devinfo_mailbox'])) {
308       $_REQUEST['devinfo_mailbox']="$extension@$vmcontext";
309     }
310   }
311   voicemail_saveVoicemail($uservm);
312 }
313
314 function voicemail_saveVoicemail($vmconf) {
315   // just in case someone tries to be sneaky and not call getVoicemail() first..
316   if ($vmconf == null) die('Error: Trying to write null voicemail file! I refuse to contiune!');
317  
318   // yes, this is hardcoded.. is this a bad thing?
319   write_voicemailconf("/etc/asterisk/voicemail.conf", $vmconf, $section);
320 }
321
322 function voicemail_getVoicemail() {
323   $vmconf = null;
324   $section = null;
325  
326   // yes, this is hardcoded.. is this a bad thing?
327   parse_voicemailconf("/etc/asterisk/voicemail.conf", $vmconf, $section);
328  
329   return $vmconf;
330 }
331
332 ?>
Note: See TracBrowser for help on using the browser.