Changeset 2393

Show
Ignore:
Timestamp:
09/10/06 08:10:42 (7 years ago)
Author:
mheydon1973
Message:

Voicemail now more modular (tied in with R.2392)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.2/voicemail/functions.inc.php

    r2390 r2393  
    8585    // Add the 'proces' function 
    8686    $currentcomponent->addguifunc('voicemail_configpageload'); 
     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    $currentcomponent->addjsfunc('isVoiceMailEnabled(notused)',$js); 
    8793  } 
    8894} 
     
    95101  $extdisplay = $_REQUEST['extdisplay']; 
    96102   
    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].'|'; 
    125125        } 
    126         $vm=true; 
     126        $options = rtrim($options,'|'); 
     127        // remove the = sign if there are no options set 
     128        $options = rtrim($options,'='); 
     129         
    127130      } 
    128     } 
    129      
     131      extract($vmoptions, EXTR_PREFIX_ALL, "vmops"); 
     132    } 
     133 
    130134    $vmcontext = $_SESSION["AMP_user"]->_deptname; //AMP Users can only add to their department's context 
    131135    if (empty($vmcontext))  
     
    149153    $section = 'Voicemail & Directory'; 
    150154    $currentcomponent->addguielem($section, new gui_selectbox('vm', $currentcomponent->getoptlist('vmena'), $vmselect, 'Status', '', false)); 
    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)); 
    154158    $currentcomponent->addguielem($section, new gui_radio('attach', $currentcomponent->getoptlist('vmyn'), $vmops_attach, 'email attachment', "Option to attach voicemails to email.")); 
    155159    $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.")); 
     
    157161    $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.")); 
    158162    $currentcomponent->addguielem($section, new gui_textbox('options', $options, 'vm options', 'Separate options with pipe ( | )<br><br>ie: review=yes|maxmessage=60')); 
    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 
     167function 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 
     190function 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 
     209function 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 
     224function 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 
     265function 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 
     273function 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; 
    161281} 
    162282 
  • modules/branches/2.2/voicemail/module.xml

    r2391 r2393  
    22  <rawname>voicemail</rawname> 
    33  <name>Voicemail</name> 
    4   <version>1.2.0</version> 
     4  <version>1.3.0</version> 
    55  <type>setup</type> 
    66  <category>Messaging</category>