| 97 | | if ($action != 'del') { |
|---|
| 98 | | //read in the voicemail.conf and set appropriate variables for display |
|---|
| 99 | | $uservm = getVoicemail(); |
|---|
| 100 | | $vmcontexts = array_keys($uservm); |
|---|
| 101 | | $vm=false; |
|---|
| 102 | | foreach ($vmcontexts as $vmcontext) { |
|---|
| 103 | | if(isset($uservm[$vmcontext][$extdisplay])){ |
|---|
| 104 | | //echo $extdisplay.' found in context '.$vmcontext.'<hr>'; |
|---|
| 105 | | $incontext = $vmcontext; //the context for the current extension |
|---|
| 106 | | $vmpwd = $uservm[$vmcontext][$extdisplay]['pwd']; |
|---|
| 107 | | $name = $uservm[$vmcontext][$extdisplay]['name']; |
|---|
| 108 | | $email = $uservm[$vmcontext][$extdisplay]['email']; |
|---|
| 109 | | $pager = $uservm[$vmcontext][$extdisplay]['pager']; |
|---|
| 110 | | //loop through all options |
|---|
| 111 | | $options=""; |
|---|
| 112 | | if (is_array($uservm[$vmcontext][$extdisplay]['options'])) { |
|---|
| 113 | | $alloptions = array_keys($uservm[$vmcontext][$extdisplay]['options']); |
|---|
| 114 | | if (isset($alloptions)) { |
|---|
| 115 | | foreach ($alloptions as $option) { |
|---|
| 116 | | if ( ($option!="attach") && ($option!="envelope") && ($option!="saycid") && ($option!="delete") && ($option!='') ) |
|---|
| 117 | | $options .= $option.'='.$uservm[$vmcontext][$extdisplay]['options'][$option].'|'; |
|---|
| 118 | | } |
|---|
| 119 | | $options = rtrim($options,'|'); |
|---|
| 120 | | // remove the = sign if there are no options set |
|---|
| 121 | | $options = rtrim($options,'='); |
|---|
| 122 | | |
|---|
| 123 | | } |
|---|
| 124 | | extract($uservm[$vmcontext][$extdisplay]['options'], EXTR_PREFIX_ALL, "vmops"); |
|---|
| | 103 | if ($action != 'del') { |
|---|
| | 104 | $vmbox = voicemail_mailbox_get($extdisplay); |
|---|
| | 105 | if ( $vmbox == null ) { |
|---|
| | 106 | $vm = false; |
|---|
| | 107 | } else { |
|---|
| | 108 | $incontext = $vmbox['vmcontext']; |
|---|
| | 109 | $vmpwd = $vmbox['pwd']; |
|---|
| | 110 | $name = $vmbox['name']; |
|---|
| | 111 | $email = $vmbox['email']; |
|---|
| | 112 | $pager = $vmbox['pager']; |
|---|
| | 113 | $vmoptions = $vmbox['options']; |
|---|
| | 114 | $vm = true; |
|---|
| | 115 | } |
|---|
| | 116 | |
|---|
| | 117 | //loop through all options |
|---|
| | 118 | $options=""; |
|---|
| | 119 | if ( is_array($vmoptions) ) { |
|---|
| | 120 | $alloptions = array_keys($vmoptions); |
|---|
| | 121 | if (isset($alloptions)) { |
|---|
| | 122 | foreach ($alloptions as $option) { |
|---|
| | 123 | if ( ($option!="attach") && ($option!="envelope") && ($option!="saycid") && ($option!="delete") && ($option!='') ) |
|---|
| | 124 | $options .= $option.'='.$uservm[$vmcontext][$extdisplay]['options'][$option].'|'; |
|---|
| 151 | | $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.", "isVoiceMailEnabled() && !isInteger()", $msgInvalidVmPwd, false)); |
|---|
| 152 | | $currentcomponent->addguielem($section, new gui_textbox('email', $email, 'email address', "The email address that voicemails are sent to.", "isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true)); |
|---|
| 153 | | $currentcomponent->addguielem($section, new gui_textbox('pager', $pager, 'pager email address', "Pager/mobile email address that short voicemail notifcations are sent to.", "isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true)); |
|---|
| | 155 | $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_users_isVoiceMailEnabled() && !isInteger()", $msgInvalidVmPwd, false)); |
|---|
| | 156 | $currentcomponent->addguielem($section, new gui_textbox('email', $email, 'email address', "The email address that voicemails are sent to.", "frm_users_isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true)); |
|---|
| | 157 | $currentcomponent->addguielem($section, new gui_textbox('pager', $pager, 'pager email address', "Pager/mobile email address that short voicemail notifcations are sent to.", "frm_users_isVoiceMailEnabled() && !isEmail()", $msgInvalidEmail, true)); |
|---|
| 159 | | $currentcomponent->addguielem($section, new gui_textbox('vmcontext', $vmcontext, 'vm context', '', 'isVoiceMailEnabled() && isEmpty()', $msgInvalidVMContext, false)); |
|---|
| 160 | | } |
|---|
| | 163 | $currentcomponent->addguielem($section, new gui_textbox('vmcontext', $vmcontext, 'vm context', '', 'frm_users_isVoiceMailEnabled() && isEmpty()', $msgInvalidVMContext, false)); |
|---|
| | 164 | } |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| | 167 | function voicemail_configprocess() { |
|---|
| | 168 | //create vars from the request |
|---|
| | 169 | extract($_REQUEST); |
|---|
| | 170 | |
|---|
| | 171 | //if submitting form, update database |
|---|
| | 172 | switch ($action) { |
|---|
| | 173 | case "add": |
|---|
| | 174 | voicemail_mailbox_add($extdisplay, $_REQUEST); |
|---|
| | 175 | needreload(); |
|---|
| | 176 | break; |
|---|
| | 177 | case "del": |
|---|
| | 178 | voicemail_mailbox_del($extdisplay); |
|---|
| | 179 | needreload(); |
|---|
| | 180 | break; |
|---|
| | 181 | case "edit": |
|---|
| | 182 | voicemail_mailbox_del($extdisplay); |
|---|
| | 183 | if ( $vm != 'disabled' ) |
|---|
| | 184 | voicemail_mailbox_add($extdisplay, $_REQUEST); |
|---|
| | 185 | needreload(); |
|---|
| | 186 | break; |
|---|
| | 187 | } |
|---|
| | 188 | } |
|---|
| | 189 | |
|---|
| | 190 | function voicemail_mailbox_get($mbox) { |
|---|
| | 191 | $uservm = voicemail_getVoicemail(); |
|---|
| | 192 | $vmcontexts = array_keys($uservm); |
|---|
| | 193 | |
|---|
| | 194 | foreach ($vmcontexts as $vmcontext) { |
|---|
| | 195 | if(isset($uservm[$vmcontext][$mbox])){ |
|---|
| | 196 | $vmbox['vmcontext'] = $vmcontext; |
|---|
| | 197 | $vmbox['pwd'] = $uservm[$vmcontext][$mbox]['pwd']; |
|---|
| | 198 | $vmbox['name'] = $uservm[$vmcontext][$mbox]['name']; |
|---|
| | 199 | $vmbox['email'] = $uservm[$vmcontext][$mbox]['email']; |
|---|
| | 200 | $vmbox['pager'] = $uservm[$vmcontext][$mbox]['pager']; |
|---|
| | 201 | $vmbox['options'] = $uservm[$vmcontext][$mbox]['options']; |
|---|
| | 202 | return $vmbox; |
|---|
| | 203 | } |
|---|
| | 204 | } |
|---|
| | 205 | |
|---|
| | 206 | return null; |
|---|
| | 207 | } |
|---|
| | 208 | |
|---|
| | 209 | function voicemail_mailbox_del($mbox) { |
|---|
| | 210 | $uservm = voicemail_getVoicemail(); |
|---|
| | 211 | $vmcontexts = array_keys($uservm); |
|---|
| | 212 | |
|---|
| | 213 | foreach ($vmcontexts as $vmcontext) { |
|---|
| | 214 | if(isset($uservm[$vmcontext][$mbox])){ |
|---|
| | 215 | unset($uservm[$vmcontext][$mbox]); |
|---|
| | 216 | voicemail_saveVoicemail($uservm); |
|---|
| | 217 | return true; |
|---|
| | 218 | } |
|---|
| | 219 | } |
|---|
| | 220 | |
|---|
| | 221 | return false; |
|---|
| | 222 | } |
|---|
| | 223 | |
|---|
| | 224 | function voicemail_mailbox_add($mbox, $mboxoptsarray) { |
|---|
| | 225 | //check if VM box already exists |
|---|
| | 226 | if ( voicemail_mailbox_get($mbox) != null ) { |
|---|
| | 227 | trigger_error("Voicemail mailbox '$mbox' already exists, call to voicemail_maibox_add failed"); |
|---|
| | 228 | die(); |
|---|
| | 229 | } |
|---|
| | 230 | |
|---|
| | 231 | $uservm = voicemail_getVoicemail(); |
|---|
| | 232 | extract($mboxoptsarray); |
|---|
| | 233 | |
|---|
| | 234 | if ($vm != 'disabled') |
|---|
| | 235 | { |
|---|
| | 236 | // need to check if there are any options entered in the text field |
|---|
| | 237 | if ($options!=''){ |
|---|
| | 238 | $options = explode("|",$options); |
|---|
| | 239 | foreach($options as $option) { |
|---|
| | 240 | $vmoption = explode("=",$option); |
|---|
| | 241 | $vmoptions[$vmoption[0]] = $vmoption[1]; |
|---|
| | 242 | } |
|---|
| | 243 | } |
|---|
| | 244 | $vmoption = explode("=",$attach); |
|---|
| | 245 | $vmoptions[$vmoption[0]] = $vmoption[1]; |
|---|
| | 246 | $vmoption = explode("=",$saycid); |
|---|
| | 247 | $vmoptions[$vmoption[0]] = $vmoption[1]; |
|---|
| | 248 | $vmoption = explode("=",$envelope); |
|---|
| | 249 | $vmoptions[$vmoption[0]] = $vmoption[1]; |
|---|
| | 250 | $vmoption = explode("=",$delete); |
|---|
| | 251 | $vmoptions[$vmoption[0]] = $vmoption[1]; |
|---|
| | 252 | |
|---|
| | 253 | $uservm[$vmcontext][$extension] = array( |
|---|
| | 254 | 'mailbox' => $extension, |
|---|
| | 255 | 'pwd' => $vmpwd, |
|---|
| | 256 | 'name' => $name, |
|---|
| | 257 | 'email' => $email, |
|---|
| | 258 | 'pager' => $pager, |
|---|
| | 259 | 'options' => $vmoptions |
|---|
| | 260 | ); |
|---|
| | 261 | } |
|---|
| | 262 | voicemail_saveVoicemail($uservm); |
|---|
| | 263 | } |
|---|
| | 264 | |
|---|
| | 265 | function voicemail_saveVoicemail($vmconf) { |
|---|
| | 266 | // just in case someone tries to be sneaky and not call getVoicemail() first.. |
|---|
| | 267 | if ($vmconf == null) die('Error: Trying to write null voicemail file! I refuse to contiune!'); |
|---|
| | 268 | |
|---|
| | 269 | // yes, this is hardcoded.. is this a bad thing? |
|---|
| | 270 | write_voicemailconf("/etc/asterisk/voicemail.conf", $vmconf, $section); |
|---|
| | 271 | } |
|---|
| | 272 | |
|---|
| | 273 | function voicemail_getVoicemail() { |
|---|
| | 274 | $vmconf = null; |
|---|
| | 275 | $section = null; |
|---|
| | 276 | |
|---|
| | 277 | // yes, this is hardcoded.. is this a bad thing? |
|---|
| | 278 | parse_voicemailconf("/etc/asterisk/voicemail.conf", $vmconf, $section); |
|---|
| | 279 | |
|---|
| | 280 | return $vmconf; |
|---|