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

Revision 4025, 14.7 kB (checked in by p_lindheimer, 6 years ago)

Merged revisions 4023 via svnmerge from
https://amportal.svn.sourceforge.net/svnroot/amportal/modules/branches/2.2

........

r4023 | p_lindheimer | 2007-06-08 20:07:37 -0700 (Fri, 08 Jun 2007) | 1 line


#1976 check to make sure mailbox exists - REQUIRES FreePBX 2.2.2

........

  • 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, 'check', new ext_vmexists('${CALLERID(num)}@${VMCONTEXT}')); // n,VoiceMailMain(${VMCONTEXT})
43   $ext->add($id, $c, '', new ext_vmmain('')); // n,VoiceMailMain(${VMCONTEXT})
44   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
45   $ext->add($id, $c, '', new ext_vmmain('${CALLERID(num)}@${VMCONTEXT}'),'check',101); // n,VoiceMailMain(${VMCONTEXT})
46   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
47 }
48
49 function voicemail_dialvoicemail($c) {
50   global $ext;
51
52   $id = "app-dialvm"; // The context to be included
53
54   $ext->addInclude('from-internal-additional', $id); // Add the include from from-internal
55
56   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
57   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
58   $ext->add($id, $c, '', new ext_vmmain('')); // n,VoiceMailMain(${VMCONTEXT})
59   $ext->add($id, $c, '', new ext_macro('hangupcall'));
60
61   // Note that with this one, it has paramters. So we have to add '_' to the start and '.' to the end
62   // of $c
63   $c = "_$c.";
64   $ext->add($id, $c, '', new ext_answer('')); // $cmd,1,Answer
65   $ext->add($id, $c, '', new ext_wait('1')); // $cmd,n,Wait(1)
66   // How long is the command? We need to strip that off the front
67   $clen = strlen($c)-2;
68   $ext->add($id, $c, '', new ext_macro('get-vmcontext','${EXTEN:'.$clen.'}'));
69   $ext->add($id, $c, '', new ext_vmmain('${EXTEN:'.$clen.'}@${VMCONTEXT}')); // n,VoiceMailMain(${VMCONTEXT})
70   $ext->add($id, $c, '', new ext_macro('hangupcall')); // $cmd,n,Macro(user-callerid)
71 }
72
73 function voicemail_configpageinit($pagename) {
74   global $currentcomponent;
75
76   $action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
77   $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
78   $extension = isset($_REQUEST['extension'])?$_REQUEST['extension']:null;
79   $tech_hardware = isset($_REQUEST['tech_hardware'])?$_REQUEST['tech_hardware']:null;
80
81        // We only want to hook 'users' or 'extensions' pages.
82   if ($pagename != 'users' && $pagename != 'extensions') 
83     return true;
84   // On a 'new' user, 'tech_hardware' is set, and there's no extension. Hook into the page.
85   if ($tech_hardware != null ) {
86     voicemail_applyhooks();
87   } elseif ($action=="add") {
88   // We don't need to display anything on an 'add', but we do need to handle returned data.
89     // ** WARNING **
90     // Mailbox must be processed before adding / deleting users, therefore $sortorder = 1
91     $currentcomponent->addprocessfunc('voicemail_configprocess', 1);
92     // JS function needed for checking voicemail = Enabled
93     $js = 'return (theForm.vm.value == "enabled");';
94   } elseif ($extdisplay != '' || $pagename == 'users') {
95   // We're now viewing an extension, so we need to display _and_ process.
96     voicemail_applyhooks();
97     $currentcomponent->addprocessfunc('voicemail_configprocess', 1);
98     $js = 'return (theForm.vm.value == "enabled");';
99     $currentcomponent->addjsfunc('isVoiceMailEnabled(notused)',$js);
100   }
101 }
102
103 function voicemail_applyhooks() {
104   global $currentcomponent;
105
106   // Setup two option lists we need
107   // Enable / Disable list
108   $currentcomponent->addoptlistitem('vmena', 'enabled', 'Enabled');
109   $currentcomponent->addoptlistitem('vmena', 'disabled', 'Disabled');
110   $currentcomponent->setoptlistopts('vmena', 'sort', false);
111   // Enable / Disable vmx list
112   $currentcomponent->addoptlistitem('vmxena', '', 'Disabled');
113   $currentcomponent->addoptlistitem('vmxena', 'checked', 'Enabled');
114   $currentcomponent->setoptlistopts('vmxena', 'sort', false);
115   // Yes / No Radio button list
116   $currentcomponent->addoptlistitem('vmyn', 'yes', 'yes');
117   $currentcomponent->addoptlistitem('vmyn', 'no', 'no');
118   $currentcomponent->setoptlistopts('vmyn', 'sort', false);
119
120   // Add the 'proces' function
121   $currentcomponent->addguifunc('voicemail_configpageload');
122 }
123
124
125 function voicemail_configpageload() {
126   global $currentcomponent;
127
128   // Init vars from $_REQUEST[]
129   $action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
130   $ext = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
131   $extn = isset($_REQUEST['extension'])?$_REQUEST['extension']:null;
132   $display = isset($_REQUEST['display'])?$_REQUEST['display']:null;
133
134   if ($ext==='') {
135     $extdisplay = $extn;
136   } else {
137     $extdisplay = $ext;
138   }
139
140
141   if ($action != 'del') {
142     $vmbox = voicemail_mailbox_get($extdisplay);
143     if ( $vmbox == null ) {
144       $vm = false;
145       $incontext = 'default';
146       $vmpwd = null;
147       $name = null;
148       $email = null;
149       $pager = null;
150       $vmoptions = null;
151
152       $vmx_state = '';
153     } else {
154       $incontext = isset($vmbox['vmcontext'])?$vmbox['vmcontext']:'default';
155       $vmpwd = $vmbox['pwd'];
156       $name = $vmbox['name'];
157       $email = $vmbox['email'];
158       $pager = $vmbox['pager'];
159       $vmoptions = $vmbox['options'];
160       $vm = true;
161
162       $vmx_state = voicemail_vmxGet($extdisplay);
163     }
164
165     //loop through all options
166     $options="";
167     if ( isset($vmoptions) && is_array($vmoptions) ) {
168       $alloptions = array_keys($vmoptions);
169       if (isset($alloptions)) {
170         foreach ($alloptions as $option) {
171           if ( ($option!="attach") && ($option!="envelope") && ($option!="saycid") && ($option!="delete") && ($option!='') )
172               $options .= $option.'='.$vmoptions[$option].'|';
173         }
174         $options = rtrim($options,'|');
175         // remove the = sign if there are no options set
176         $options = rtrim($options,'=');
177         
178       }
179       extract($vmoptions, EXTR_PREFIX_ALL, "vmops");
180     } else {
181       $vmops_attach = 'no';
182       $vmops_saycid = 'no';
183       $vmops_envelope = 'no';
184       $vmops_delete = 'no';
185     }
186
187     //AMP Users can only add to their department's context
188     $vmcontext = isset($_SESSION["AMP_user"]->_deptname)?$_SESSION["AMP_user"]->_deptname:null;
189
190     if (empty($vmcontext))
191       $vmcontext = (isset($_REQUEST['vmcontext']) ? $_REQUEST['vmcontext'] : $incontext);
192     if (empty($vmcontext))
193       $vmcontext = 'default';
194     
195     if ( $vm==true ) {
196       $vmselect = "enabled";
197     } else {
198       $vmselect = "disabled";
199     }
200     
201     $fc_vm = featurecodes_getFeatureCode('voicemail', 'dialvoicemail');
202
203     $msgInvalidVmPwd = 'Please enter a valid Voicemail Password, using digits only';
204     $msgInvalidEmail = 'Please enter a valid Email Address';
205     $msgInvalidPager = 'Please enter a valid Pager Email Address';
206     $msgInvalidVMContext = 'VM Context cannot be blank';
207
208     $section = 'Voicemail & Directory';
209     $currentcomponent->addguielem($section, new gui_selectbox('vm', $currentcomponent->getoptlist('vmena'), $vmselect, 'Status', '', false));
210     $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));
211     $currentcomponent->addguielem($section, new gui_textbox('email', $email, 'email address', "The email address that voicemails are sent to.", "frm_${display}_isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true));
212     $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));
213     $currentcomponent->addguielem($section, new gui_radio('attach', $currentcomponent->getoptlist('vmyn'), $vmops_attach, 'email attachment', "Option to attach voicemails to email."));
214     $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."));
215     $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."));
216     $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."));
217     $currentcomponent->addguielem($section, new gui_textbox('options', $options, 'vm options', 'Separate options with pipe ( | )<br><br>ie: review=yes|maxmessage=60'));
218     $currentcomponent->addguielem($section, new gui_textbox('vmcontext', $vmcontext, 'vm context', '', "frm_${display}_isVoiceMailEnabled() && isEmpty()", $msgInvalidVMContext, false));
219     $currentcomponent->addguielem($section, new gui_selectbox('vmx_state', $currentcomponent->getoptlist('vmxena'), $vmx_state, 'VmX IVR', 'Enable/Disable the Extended Voicemail IVR ability on this extension. Defaults will be set an d the user can make changes in the ARI or equivalent portal. Unchecking will disabled the feature but not delete any existing settings', false));
220   }
221 }
222
223 function voicemail_configprocess() {
224   //create vars from the request
225   extract($_REQUEST);
226   $action = isset($_REQUEST['action'])?$_REQUEST['action']:null;
227   $extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
228  
229   //if submitting form, update database
230   switch ($action) {
231     case "add":
232       voicemail_mailbox_add($extdisplay, $_REQUEST);
233       needreload();
234     break;
235     case "del":
236       voicemail_mailbox_del($extdisplay);
237       needreload();
238     break;
239     case "edit":
240       voicemail_mailbox_del($extdisplay);
241       if ( $vm != 'disabled' )
242         voicemail_mailbox_add($extdisplay, $_REQUEST);
243       needreload();
244     break;
245   }
246 }
247
248 function voicemail_mailbox_get($mbox) {
249   $uservm = voicemail_getVoicemail();
250   $vmcontexts = array_keys($uservm);
251
252   foreach ($vmcontexts as $vmcontext) {
253     if(isset($uservm[$vmcontext][$mbox])){
254       $vmbox['vmcontext'] = $vmcontext;
255       $vmbox['pwd'] = $uservm[$vmcontext][$mbox]['pwd'];
256       $vmbox['name'] = $uservm[$vmcontext][$mbox]['name'];
257       $vmbox['email'] = $uservm[$vmcontext][$mbox]['email'];
258       $vmbox['pager'] = $uservm[$vmcontext][$mbox]['pager'];
259       $vmbox['options'] = $uservm[$vmcontext][$mbox]['options'];
260       return $vmbox;
261     }
262   }
263  
264   return null;
265 }
266
267 function voicemail_mailbox_del($mbox) {
268   $uservm = voicemail_getVoicemail();
269   $vmcontexts = array_keys($uservm);
270
271   foreach ($vmcontexts as $vmcontext) {
272     if(isset($uservm[$vmcontext][$mbox])){
273       unset($uservm[$vmcontext][$mbox]);
274       voicemail_saveVoicemail($uservm);
275       return true;
276     }
277   }
278  
279   return false;
280 }
281
282 function voicemail_mailbox_add($mbox, $mboxoptsarray) {
283   //check if VM box already exists
284   if ( voicemail_mailbox_get($mbox) != null ) {
285     trigger_error("Voicemail mailbox '$mbox' already exists, call to voicemail_maibox_add failed");
286     die();
287   }
288  
289   $uservm = voicemail_getVoicemail();
290   extract($mboxoptsarray);
291  
292   if ($vm != 'disabled')
293   {
294     // need to check if there are any options entered in the text field
295     if ($options!=''){
296       $options = explode("|",$options);
297       foreach($options as $option) {
298         $vmoption = explode("=",$option);
299         $vmoptions[$vmoption[0]] = $vmoption[1];
300       }
301     }
302     $vmoption = explode("=",$attach);
303       $vmoptions[$vmoption[0]] = $vmoption[1];
304     $vmoption = explode("=",$saycid);
305       $vmoptions[$vmoption[0]] = $vmoption[1];
306     $vmoption = explode("=",$envelope);
307       $vmoptions[$vmoption[0]] = $vmoption[1];
308     $vmoption = explode("=",$delete);
309       $vmoptions[$vmoption[0]] = $vmoption[1];
310       
311     $uservm[$vmcontext][$extension] = array(
312       'mailbox' => $extension,
313       'pwd' => $vmpwd,
314       'name' => $name,
315       'email' => $email,
316       'pager' => $pager,
317       'options' => $vmoptions
318       );
319     // Update $_REQUEST with 'devinfo_mailbox, so MWI works.
320     if (empty($_REQUEST['devinfo_mailbox'])) {
321       $_REQUEST['devinfo_mailbox']="$extension@$vmcontext";
322     }
323   }
324   voicemail_saveVoicemail($uservm);
325 }
326
327 function voicemail_saveVoicemail($vmconf) {
328   global $amp_conf;
329
330   // just in case someone tries to be sneaky and not call getVoicemail() first..
331   if ($vmconf == null) die('Error: Trying to write null voicemail file! I refuse to contiune!');
332  
333   // yes, this is hardcoded.. is this a bad thing?
334   write_voicemailconf(rtrim($amp_conf["ASTETCDIR"],"/")."/voicemail.conf", $vmconf, $section);
335 }
336
337 function voicemail_getVoicemail() {
338   global $amp_conf;
339
340   $vmconf = null;
341   $section = null;
342  
343   // yes, this is hardcoded.. is this a bad thing?
344   parse_voicemailconf(rtrim($amp_conf["ASTETCDIR"],"/")."/voicemail.conf", $vmconf, $section);
345  
346   return $vmconf;
347 }
348
349 function voicemail_vmxGet($extension) {
350   global $astman;                                                                                                                                                                                                   
351                                                                                                                                                                                                                         
352   // Retrieve the state
353   $vmx_state=$astman->database_get("AMPUSER",$extension."/vmx/unavail/state");
354   if (isset($vmx_state) && (trim($vmx_state) == 'enabled' || trim($vmx_state) == 'disabled')) {
355     $vmx_state='checked';
356   } else {
357     $vmx_state='';
358   }
359
360   return $vmx_state;
361 }                                                                                                                                                                                                                   
362
363
364 ?>
Note: See TracBrowser for help on using the browser.