Show
Ignore:
Timestamp:
03/03/09 16:48:06 (4 years ago)
Author:
sasargen
Message:

Auto Check-in of any outstanding patches

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • contributed_modules/modules/vmailadmin/functions.inc.php

    r7106 r7465  
    1 <? 
    2 // draw list for users and devices with paging 
    3 function vmaildrawListMenu($results, $type="setup", $dispnum="vmailedit", $extdisplay, $description=false) { 
    4         $index = 0; 
    5         echo "<ul>\n"; 
    6         if ($description !== false) { 
    7                 //echo "\t<li><a ".($extdisplay=='' ? 'class="current"':'')." href=\"config.php?type=".$type."&display=".$dispnum."\">"._("Add")." ".$description."</a></li>\n"; 
    8     echo "\t<li><a ".($extdisplay=='' ? 'class="current"':'')." href=\"config.php?type=".$type."&display=".$dispnum."\">"._("". $description. "")."</a></li>\n"; 
    9         } 
    10         if (isset($results)) { 
    11                 foreach ($results as $key=>$result) { 
    12                         $index= $index + 1; 
    13                         echo "\t<li><a".($extdisplay==$result[0] ? ' class="current"':''). " href=\"config.php?type=".$type."&display=".$dispnum."&extdisplay={$result[0]}\">{$result[1]} &lt;{$result[0]}&gt;</a></li>\n"; 
    14                 } 
    15         } 
    16         echo "</ul>\n"; 
     1<?php 
     2function vmailadmin_get_title($action, $context="", $account="") { 
     3  $title = "<h3>" . _("Voicemail Administration") . "<br />&nbsp;&nbsp;"; 
     4  switch ($action) { 
     5    case "tz": 
     6      $title .= _("Timezone Definitions"); 
     7      break; 
     8    case "bsettings": 
     9      if (!empty($account)) { 
     10        $title .= _("Basic Settings For: ") . "&nbsp;&nbsp;&nbsp;$account&nbsp;&nbsp;&nbsp;($context)"; 
     11      } else { 
     12        $title .= _("Basic settings view is for individual accounts."); 
     13      } 
     14      break; 
     15    case "settings": 
     16      if (!empty($account)) { 
     17        $title .= _("Advanced Settings For: ") . "&nbsp;&nbsp;&nbsp;$account&nbsp;&nbsp;&nbsp;($context)"; 
     18      } else { 
     19        $title .= _("System Settings"); 
     20      } 
     21      break; 
     22    case "usage": 
     23      if (!empty($account)) { 
     24        $title .= _("Usage Statistics For: ") . "&nbsp;&nbsp;&nbsp;$account&nbsp;&nbsp;&nbsp;($context)"; 
     25      } else { 
     26        $title .= _("System Usage Statistics"); 
     27      } 
     28      break; 
     29    default: 
     30      $title .= "&nbsp;&nbsp;" . _("Invalid Action"); 
     31      break; 
     32  } 
     33  $title .= "</h3>"; 
     34  return $title; 
     35
     36function vmailadmin_get_scope($extension) { 
     37  if (!empty($extension)) { 
     38    return "account"; 
     39  } else { 
     40    return "system"; 
     41  } 
     42
     43function vmailadmin_update_settings($action, $context="", $extension="", $args=null) { 
     44  global $astman; 
     45  global $tz_settings; 
     46  global $gen_settings; 
     47  /* Ensure we get the most up-to-date voicemail.conf data. */ 
     48  $vmconf = voicemail_getVoicemail(); 
     49  if ($vmconf !== null) { 
     50    switch ($action) { 
     51      case "tz": 
     52        /* First update all zonemessages opts that are already in vmconf */ 
     53        foreach ($vmconf["zonemessages"] as $key => $val) { 
     54          $id = "tz__$key"; 
     55          $vmconf["zonemessages"][$key] = isset($args[$id])?$args[$id]:$vmconf["zonemessages"][$key]; 
     56          /* Bad to have empty fields in vmconf. */ 
     57          /* And remove deleted fields, too.     */ 
     58          if (empty($vmconf["zonemessages"][$key]) || ($args["tzdel__$key"] == "true")) { 
     59            unset($vmconf["zonemessages"][$key]); 
     60          } 
     61          /* Add new field, if one was specified */ 
     62          if (!empty($args["tznew_name"]) && !empty($args["tznew_def"])) { 
     63            $vmconf["zonemessages"][$args["tznew_name"]] = $args["tznew_def"]; 
     64          } 
     65          unset($args[$id]); 
     66        } 
     67        /* Next record any new zonemessages opts that were on the page but not already in vmconf. */ 
     68        foreach ($tz_settings as $key) { 
     69          $id = "tz__$key"; 
     70          if (isset($args[$id]) && !empty($args[$id])) { 
     71            $vmconf["zonemessages"][$key] = $args[$id]; 
     72          } 
     73        } 
     74        break; 
     75      case "settings": 
     76        if (empty($extension) && $action == "settings") { 
     77          /* First update all general opts that are already in vmconf */ 
     78          foreach ($vmconf["general"] as $key => $val) { 
     79            $id = "gen__$key"; 
     80            $vmconf["general"][$key] = isset($args[$id])?$args[$id]:$vmconf["general"][$key]; 
     81            /* Bad to have empty fields in vmconf. */ 
     82            if (empty($vmconf["general"][$key])) { 
     83              unset($vmconf["general"][$key]); 
     84            } 
     85            unset($args[$id]); 
     86          } 
     87          /* Next record any new general opts that were on the page but not already in vmconf. */ 
     88          foreach ($gen_settings as $key => $descrip) { 
     89            $id = "gen__$key"; 
     90            if (isset($args[$id]) && !empty($args[$id])) { 
     91              $vmconf["general"][$key] = $args[$id]; 
     92            } 
     93          } 
     94        } else if (!empty($extension)) { 
     95          global $acct_settings;      /* We need this to know the type for each option (text value or flag) */ 
     96          /* Delete user's old settings. */ 
     97          voicemail_mailbox_del($extension); 
     98          /* Prepare values for user's new settings.        */ 
     99          /* Each voicemail account has a line in voicemail.conf like this: */ 
     100          /* extension => password,name,email,pager,options     */ 
     101          /* Take care of password, name, email and pager.                  */ 
     102          $pwd = isset($args["acct__pwd"])?$args["acct__pwd"]:""; 
     103          unset($args["acct__pwd"]); 
     104          if (isset($args["acct__name"]) && $args["acct__name"] != "") { 
     105            $name = $args["acct__name"]; 
     106          } else { 
     107            $this_exten = core_users_get($extension); 
     108            $name = $this_exten["name"]; 
     109          } 
     110          unset($args["acct__name"]); 
     111          $email = isset($args["acct__email"])?$args["acct__email"]:""; 
     112          unset($args["acct__email"]); 
     113          $pager = isset($args["acct__pager"])?$args["acct__pager"]:""; 
     114          unset($args["acct__pager"]); 
     115 
     116          /* Now handle the options. */ 
     117          $options = array(); 
     118          foreach ($acct_settings as $key => $descrip) { 
     119            $id = "acct__$key"; 
     120            if (isset($args[$id]) && !empty($args[$id]) && $args[$id] != "undefined") { 
     121              $options[$key] = $args[$id]; 
     122            } 
     123          } 
     124          /* Remove call me num from options - that is set in ast db */ 
     125          unset($options["callmenum"]); 
     126          /* New account values to vmconf */ 
     127          $vmconf[$context][$extension] = array( 
     128                    "mailbox" => $extension, 
     129                    "pwd"     => $pwd, 
     130                    "name"    => $name, 
     131                    "email"   => $email, 
     132                    "pager"   => $pager, 
     133                    "options"   => $options 
     134                       ); 
     135          $callmenum = (isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]))?$args["acct__callmenum"]:$extension; 
     136          // Save call me num. 
     137          $cmd = "database put AMPUSER $extension/callmenum $callmenum"; 
     138          $astman->send_request("Command", array("Command" => $cmd)); 
     139        } 
     140        break; 
     141      case "bsettings": 
     142        if (!empty($extension)) { 
     143          /* Get user's old settings, since we are only replacing the basic settings. */ 
     144          $vmbox = voicemail_mailbox_get($extension); 
     145          /* Delete user's old settings. */ 
     146          voicemail_mailbox_del($extension); 
     147 
     148          /* Prepare values for user's new BASIC settings.      */ 
     149          /* Each voicemail account has a line in voicemail.conf like this: */ 
     150          /* extension => password,name,email,pager,options     */ 
     151          /* Take care of password, name, email and pager.                  */ 
     152          $pwd = isset($args["acct__pwd"])?$args["acct__pwd"]:""; 
     153          unset($args["acct__pwd"]); 
     154          if (isset($args["acct__name"]) && $args["acct__name"] != "") { 
     155            $name = $args["acct__name"]; 
     156          } else { 
     157            $this_exten = core_users_get($extension); 
     158            $name = $this_exten["name"]; 
     159          } 
     160          unset($args["acct__name"]); 
     161          $email = isset($args["acct__email"])?$args["acct__email"]:""; 
     162          unset($args["acct__email"]); 
     163          $pager = isset($args["acct__pager"])?$args["acct__pager"]:""; 
     164          unset($args["acct__pager"]); 
     165 
     166          /* THESE ARE COMING FROM THE USER'S OLD SETTINGS.                     */ 
     167          $options = $vmbox["options"]; /* An array */ 
     168          /* Update the four options listed on the "bsettings" page as needed. */ 
     169          $basic_opts_list = array("attach", "saycid", "envelope", "delete"); 
     170          foreach ($basic_opts_list as $basic_opt) { 
     171            $id = "acct__" . $basic_opt; 
     172            if (isset($args[$id]) && !empty($args[$id]) && $args[$id] != "undefined") { 
     173              $options[$basic_opt] = $args[$id]; 
     174            } else if ($args[$id] == "undefined") { 
     175              unset($options[$basic_opt]); 
     176            } 
     177          } 
     178          /* Remove call me num from options - that is set in ast db. Should not be here anyway, since options are coming from the old settings... */ 
     179          unset($options["callmenum"]); 
     180          /* New account values to vmconf */ 
     181          $vmconf[$context][$extension] = array( 
     182                    "mailbox" => $extension, 
     183                    "pwd"     => $pwd, 
     184                    "name"    => $name, 
     185                    "email"   => $email, 
     186                    "pager"   => $pager, 
     187                    "options"   => $options 
     188                       ); 
     189          $callmenum = (isset($args["acct__callmenum"]) && !empty($args["acct__callmenum"]))?$args["acct__callmenum"]:$extension; 
     190          // Save call me num. 
     191          $cmd = "database put AMPUSER $extension/callmenum $callmenum"; 
     192          $astman->send_request("Command", array("Command" => $cmd)); 
     193        } 
     194        break; 
     195      default: 
     196        return false; 
     197    } 
     198    voicemail_saveVoicemail($vmconf); 
     199    $astman->send_request("Command", array("Command" => "reload app_voicemail.so")); 
     200    return true; 
     201  } 
     202  return false; 
     203
     204 
     205function vmailadmin_get_settings($vmconf, $action, $extension="") { 
     206  $settings = array(); 
     207  switch ($action) { 
     208    case "tz": 
     209      if (is_array($vmconf) && is_array($vmconf["zonemessages"])) { 
     210        foreach ($vmconf["zonemessages"] as $key => $val) { 
     211          $settings[$key] = $val; 
     212        } 
     213      } 
     214      break; 
     215    case "bsettings": 
     216    case "settings": 
     217      /* Settings can apply to system-wide settings OR to account-specific settings.           */ 
     218      /* Specifying a context and extension indicates account-specific settings are being requested. */ 
     219      if (!empty($extension)) { 
     220        $vmbox = voicemail_mailbox_get($extension); 
     221        if ($vmbox !== null) { 
     222          $settings["enabled"] = true; 
     223        } else { 
     224          $settings["enabled"] = false; 
     225        } 
     226        $settings["vmcontext"] = $c = isset($vmbox["vmcontext"])?$vmbox["vmcontext"]:"default"; 
     227        $settings["pwd"] = isset($vmbox["pwd"])?$vmbox["pwd"]:""; 
     228        $settings["name"] = (isset($vmbox["name"]) && $vmbox["name"] != "")?$vmbox["name"]:""; 
     229        if ($settings["name"] == "") { 
     230          $this_exten = core_users_get($extension); 
     231          $settings["name"] = $this_exten["name"]; 
     232        } 
     233        $settings["email"] = isset($vmbox["email"])?$vmbox["email"]:""; 
     234        $settings["pager"] = isset($vmbox["pager"])?$vmbox["pager"]:""; 
     235        $options = isset($vmbox["options"])?$vmbox["options"]:array(); 
     236        foreach ($options as $key => $val) { 
     237          $settings[$key] = $val; 
     238        } 
     239 
     240        /* Get Call Me number */ 
     241        global $astman; 
     242        $cmd    = "database get AMPUSER $extension/callmenum"; 
     243        $callmenum  = ""; 
     244        $results  = $astman->send_request("Command", array("Command" => $cmd)); 
     245        if (is_array($results)) 
     246        { 
     247          foreach ($results as $results_elem) 
     248          { 
     249            if (preg_match('/Value: [^\s]*/', $results_elem, $matches) > 0) 
     250            { 
     251              $parts = split(' ', trim($matches[0])); 
     252              $callmenum = $parts[1]; 
     253              break; 
     254            } 
     255          } 
     256        } 
     257        $settings["callmenum"] = $callmenum; 
     258        /* End - Call Me number obtained */ 
     259      } else { 
     260        if (is_array($vmconf) && is_array($vmconf["general"])) { 
     261          $settings = $vmconf["general"]; 
     262        } 
     263      } 
     264      break; 
     265    default: 
     266      break; 
     267  } 
     268  return $settings; 
     269
     270function vmailadmin_update_usage($vmail_info, $context="", $extension="", $args) { 
     271  global $vmail_root; 
     272  $take_action = false; 
     273  if (isset($args["del_msgs"]) && $args["del_msgs"] == "true") { 
     274    $msg = true; 
     275    $take_action = true; 
     276  } else { 
     277    $msg = false; 
     278  } 
     279  if (isset($args["del_names"]) && $args["del_names"] == "true") { 
     280    $name = true; 
     281    $take_action = true; 
     282  } else { 
     283    $name = false; 
     284  } 
     285  if (isset($args["del_unavail"]) && $args["del_unavail"] == "true") { 
     286    $unavail = true; 
     287    $take_action = true; 
     288  } else { 
     289    $unavail = false; 
     290  } 
     291  if (isset($args["del_busy"]) && $args["del_busy"] == "true") { 
     292    $busy = true; 
     293    $take_action = true; 
     294  } else { 
     295    $busy = false; 
     296  } 
     297  if (isset($args["del_temp"]) && $args["del_temp"] == "true") { 
     298    $temp = true; 
     299    $take_action = true; 
     300  } else { 
     301    $temp = false; 
     302  } 
     303  if (isset($args["del_abandoned"]) && $args["del_abandoned"] == "true") { 
     304    $abandoned = true; 
     305    $take_action = true; 
     306  } else { 
     307    $abandoned = false; 
     308  } 
     309  if (!$take_action) { 
     310    return; 
     311  } 
     312  $vmail_path = $vmail_root; 
     313  $scope = "system"; 
     314  if (!empty($extension) && !empty($context)) { 
     315    $scope = "account"; 
     316  } 
     317 
     318  switch ($scope) { 
     319    case "system": 
     320      if ($msg) { 
     321        exec ("rm -f $vmail_root/*/*/*/msg*"); 
     322      } 
     323      foreach ($vmail_info["contexts"] as $c) { 
     324        vmailadmin_del_greeting_files($vmail_root, $c, "", $name, $unavail, $busy, $temp, $abandoned); 
     325      } 
     326      break; 
     327    case "account": 
     328      if (isset($vmail_info["activated_info"][$extension]) && $vmail_info["activated_info"][$extension] == $context) { 
     329        $vmail_path = $vmail_root . "/" . $context . "/" . $extension; 
     330        if ($msg) { 
     331          exec ("rm -f $vmail_path/*/msg*"); 
     332        } 
     333        vmailadmin_del_greeting_files($vmail_root, $context, $extension, $name, $unavail, $busy, $temp, $abandoned); 
     334      } 
     335      break; 
     336  } 
     337
     338function vmailadmin_del_greeting_files($vmail_root, $context="", $exten="", $name=false, $unavail=false, $busy=false, $temp=false, $abandoned=false) { 
     339  $path = $vmail_root; 
     340  if (!empty($context) && !empty($exten)) { 
     341    $path .= "/" . $context . "/" . $exten; 
     342    $ab_name_cmd    = "ls $path/greet.tmp.*"; 
     343    $ab_temp_cmd    = "ls $path/temp.tmp.*"; 
     344    $ab_busy_cmd    = "ls $path/busy.tmp.*"; 
     345    $ab_unavail_cmd = "ls $path/unavail.tmp.*"; 
     346    $name_cmd       = "ls $path/greet.*"; 
     347    $unavail_cmd    = "ls $path/unavail.*"; 
     348    $busy_cmd       = "ls $path/busy.*"; 
     349    $temp_cmd       = "ls $path/temp.*"; 
     350  } else { 
     351    $ab_name_cmd    = "ls $path/*/*/greet.tmp.*"; 
     352    $ab_temp_cmd    = "ls $path/*/*/temp.tmp.*"; 
     353    $ab_busy_cmd    = "ls $path/*/*/busy.tmp.*"; 
     354    $ab_unavail_cmd = "ls $path/*/*/unavail.tmp.*"; 
     355    $name_cmd       = "ls $path/*/*/greet.*"; 
     356    $unavail_cmd    = "ls $path/*/*/unavail.*"; 
     357    $busy_cmd       = "ls $path/*/*/busy.*"; 
     358    $temp_cmd       = "ls $path/*/*/temp.*"; 
     359  } 
     360   
     361  if (is_dir($path)) { 
     362    if ($abandoned) { 
     363      /* First handle abandoned greetings.  Delete abandoned greetings that are at least a day old. */ 
     364      $ab_names     = vmailadmin_get_ab_greetings("greet", $ab_name_cmd); 
     365      $ab_temps     = vmailadmin_get_ab_greetings("temp", $ab_temp_cmd); 
     366      $ab_busys     = vmailadmin_get_ab_greetings("busy", $ab_busy_cmd); 
     367      $ab_unavails  = vmailadmin_get_ab_greetings("unavail", $ab_unavail_cmd); 
     368      $ab_greetings   = array_merge($ab_names, $ab_temps, $ab_busys, $ab_unavails); 
     369      $current_time = time(); 
     370      $one_day  = 24 * 60 * 60; 
     371      foreach ($ab_greetings as $greeting_path) { 
     372        if (time() - filemtime($greeting_path) > $one_day) { 
     373          exec("rm -f $greeting_path"); 
     374        } 
     375      } 
     376    } 
     377    if ($name) { 
     378      $names    = vmailadmin_get_greetings("greet", $name_cmd); 
     379    } 
     380    if ($unavail) { 
     381      $unavails = vmailadmin_get_greetings("unavail", $unavail_cmd); 
     382    } 
     383    if ($busy) { 
     384      $busys    = vmailadmin_get_greetings("busy", $busy_cmd); 
     385    } 
     386    if ($temp) { 
     387      $temps    = vmailadmin_get_greetings("temp", $temp_cmd); 
     388    } 
     389    $greetings   = array_merge($names, $temps, $busys, $unavails); 
     390    if (!empty($greetings)) { 
     391      foreach ($greetings as $greeting_path) { 
     392        exec ("rm -f $greeting_path"); 
     393      } 
     394    } 
     395  } 
     396
     397function vmailadmin_get_storage($path) { 
     398  $cmd            = escapeshellcmd("du -khs $path"); 
     399  $storage_result = array(); 
     400  $matches        = array(); 
     401  exec($cmd, $storage_result); 
     402  if (preg_match("/[0-9]*\.*[0-9]*[a-zA-Z]*/", $storage_result[0], $matches) > 0) { 
     403    $storage = $matches[0]; 
     404    unset($matches); 
     405    $matches = array(); 
     406    # Expecting storage value as #.#U where # = number, . = dot, and U = units (e.g. M, K, etc.) 
     407    # Massage the string so that there is a space between the number value and character(s) 
     408    # denoting the unit 
     409    # 
     410    # Extract the numeric part. /[0-9]*\.*[0-9]*[a-zA-Z]*/ 
     411    if (preg_match("/[0-9]*\.*[0-9]*/", $storage, $matches)) { 
     412      $st_num = $matches[0]; 
     413    } else { 
     414      $st_num = "0"; 
     415    } 
     416    unset($matches); 
     417    $matches = array(); 
     418    if (preg_match("/[a-zA-Z]+$/", $storage, $matches)) { 
     419      $st_unit = $matches[0]; 
     420    } else { 
     421      $st_unit = "";   
     422    } 
     423    # reset $storage to new string 
     424    $storage = $st_num . "&nbsp;" . $st_unit; 
     425  } else { 
     426    $storage = "unknown"; 
     427  } 
     428  return $storage; 
     429
     430function vmailadmin_get_usage($vmail_info, $scope, &$acts_total, &$acts_act, &$acts_unact, &$disabled_count, 
     431                                  &$msg_total, &$msg_in, &$msg_other, 
     432                                  &$name, &$unavail, &$busy, &$temp, &$abandoned, 
     433                &$storage, 
     434          $context="", $extension="") { 
     435  global $vmail_root; 
     436  $msg_total = 0; 
     437  $msg_in    = 0; 
     438  $msg_other = 0; 
     439  $name      = 0; 
     440  $unavail   = 0; 
     441  $busy      = 0; 
     442  $temp      = 0; 
     443  $abandoned = 0; 
     444  switch ($scope) { 
     445    case "system": 
     446      $acts_act       = sizeof($vmail_info["activated_info"]); 
     447      $acts_unact     = sizeof($vmail_info["unactivated_info"]); 
     448      $disabled_count = sizeof($vmail_info["disabled_list"]); 
     449      $acts_total = $acts_act + $acts_unact + $disabled_count; 
     450      $storage    = vmailadmin_get_storage($vmail_root); 
     451      foreach ($vmail_info["contexts"] as $c) { 
     452        $count_msg_in  = 0; 
     453        $count_msg_oth = 0; 
     454        $count_name    = 0; 
     455        $count_unavail = 0; 
     456        $count_busy    = 0; 
     457        $count_temp    = 0; 
     458        $count_abandon = 0; 
     459        $vmail_path = $vmail_root . "/" . $c; 
     460        vmailadmin_file_usage($vmail_path, $count_msg_in, $count_msg_oth, $count_name, $count_unavail, $count_busy, $count_temp, $count_abandon); 
     461        $msg_in    += $count_msg_in; 
     462        $msg_other += $count_msg_oth; 
     463        $name      += $count_name; 
     464        $unavail   += $count_unavail; 
     465        $busy      += $count_busy; 
     466        $temp      += $count_temp; 
     467        $abandoned += $count_abandon; 
     468         
     469      } 
     470      $msg_total = $msg_in + $msg_other; 
     471      break; 
     472    case "account": 
     473      if (isset($vmail_info["activated_info"][$extension]) && $vmail_info["activated_info"][$extension] == $context) { 
     474        $vmail_path = $vmail_root . "/" . $context . "/" . $extension; 
     475        vmailadmin_file_usage($vmail_path, $msg_in, $msg_other, $name, $unavail, $busy, $temp, $abandoned, true); 
     476        $storage    = vmailadmin_get_storage($vmail_path); 
     477        $msg_total = $msg_in + $msg_other; 
     478        $acts_act = 1; 
     479        $acts_unact = 0; 
     480      } else { 
     481        $acts_unact = 1; 
     482      } 
     483      break; 
     484    default: 
     485      break; 
     486  } 
     487
     488function vmailadmin_file_usage($path, &$inmsg_cnt, &$othmsg_cnt, &$greet_cnt, &$unavail_cnt, &$busy_cnt, &$temp_cnt, &$abandoned_cnt, $acct_flag=false) { 
     489  if ($acct_flag) { /* account-specific; account included in path passed in */ 
     490    # greetings, all 
     491    $greet_cmd  = "ls $path/greet.*"; 
     492    $unavail_cmd  = "ls $path/unavail.*"; 
     493    $busy_cmd = "ls $path/busy.*"; 
     494    $temp_cmd = "ls $path/temp.*"; 
     495   
     496    # abandoned greetings 
     497    $agreet_cmd = "ls $path/greet.tmp.*"; 
     498    $aunavail_cmd = "ls $path/unavail.tmp.*"; 
     499    $abusy_cmd  = "ls $path/busy.tmp.*"; 
     500    $atemp_cmd  = "ls $path/temp.tmp.*"; 
     501 
     502    # inbox messages 
     503    $inmsg_cmd  = "ls $path/INBOX/msg*.txt"; 
     504 
     505    # all messages 
     506    $allmsg_cmd = "ls $path/*/msg*.txt"; 
     507  } else { /* system-wide */ 
     508    # greetings, all 
     509    $greet_cmd  = "ls $path/*/greet.*"; 
     510    $unavail_cmd  = "ls $path/*/unavail.*"; 
     511    $busy_cmd = "ls $path/*/busy.*"; 
     512    $temp_cmd = "ls $path/*/temp.*"; 
     513   
     514    # abandoned greetings 
     515    $agreet_cmd = "ls $path/*/greet.tmp.*"; 
     516    $aunavail_cmd = "ls $path/*/unavail.tmp.*"; 
     517    $abusy_cmd  = "ls $path/*/busy.tmp.*"; 
     518    $atemp_cmd  = "ls $path/*/temp.tmp.*"; 
     519 
     520    # inbox messages 
     521    $inmsg_cmd  = "ls $path/*/INBOX/msg*.txt"; 
     522 
     523    # all messages 
     524    $allmsg_cmd = "ls $path/*/*/msg*.txt"; 
     525  } 
     526 
     527  if (is_dir($path)) { 
     528    $greet_cnt    = vmailadmin_count_greetings("greet", $greet_cmd); 
     529    $temp_cnt     = vmailadmin_count_greetings("temp", $temp_cmd); 
     530    $busy_cnt     = vmailadmin_count_greetings("busy", $busy_cmd); 
     531    $unavail_cnt  = vmailadmin_count_greetings("unavail", $unavail_cmd); 
     532 
     533 
     534    $agreet_cnt   = vmailadmin_count_ab_greetings("greet", $agreet_cmd); 
     535    $aunavail_cnt   = vmailadmin_count_ab_greetings("unavail", $aunavail_cmd); 
     536    $abusy_cnt  = vmailadmin_count_ab_greetings("busy", $abusy_cmd); 
     537    $atemp_cnt  = vmailadmin_count_ab_greetings("temp", $atemp_cmd); 
     538 
     539 
     540    $inmsg_cnt  = vmailadmin_count_msg($inmsg_cmd); 
     541    $allmsg_cnt   = vmailadmin_count_msg($allmsg_cmd); 
     542     
     543    $othmsg_cnt   = $allmsg_cnt - $inmsg_cnt; 
     544    $abandoned_cnt  = $agreet_cnt + $abusy_cnt + $atemp_cnt + $aunavail_cnt; 
     545     
     546  } 
     547 
     548
     549function vmailadmin_strip_exten_from_greet_path($greet_path) { 
     550  $path_array = explode("/", $greet_path); 
     551  $n = sizeof($path_array); 
     552  $exten = $path_array[$n-2]; 
     553  return $exten; 
     554
     555function vmailadmin_count_greetings($greeting, $cmd) { 
     556  /* get a list of all greeting files */ 
     557  $file_list = vmailadmin_get_greetings($greeting, $cmd); 
     558  $greet_list = array(); 
     559  /* greeting can be in multiple formats, making file count greater than greeting */ 
     560  /* count, so make array with one entry for each extension that has the greeting */ 
     561  foreach ($file_list as $greeting_file) { 
     562    $greet_list[vmailadmin_strip_exten_from_greet_path($greeting_file)] = true; 
     563  } 
     564  return sizeof($greet_list); 
     565
     566function vmailadmin_get_greetings($greeting, $cmd) { 
     567  $results = array(); 
     568  $greet_list = array(); 
     569  exec($cmd, $results); 
     570  /* filter out abandoned greeting recordings */ 
     571  foreach ($results as $r) { 
     572    $pat = "/.*" . $greeting . "\.tmp\..+/"; 
     573    if (!preg_match($pat, $r)) 
     574      $greet_list[] = $r; 
     575  } 
     576  return $greet_list; 
     577
     578function vmailadmin_count_ab_greetings($greeting, $cmd) { 
     579  $file_list = vmailadmin_get_ab_greetings($greeting, $cmd); 
     580  $greet_list = array(); 
     581  /* greeting can be in multiple formats, making file count greater than greeting */ 
     582  /* count, so make array with one entry for each extension that has the greeting */ 
     583  foreach ($file_list as $greeting_file) { 
     584    $greet_list[vmailadmin_strip_exten_from_greet_path($greeting_file)] = true; 
     585  } 
     586  return sizeof($greet_list); 
     587
     588function vmailadmin_get_ab_greetings($greeting, $cmd) { 
     589  $results = array(); 
     590  $greet_list = array(); 
     591  exec($cmd, $results); 
     592  foreach ($results as $r) { 
     593    $greet_list[] = $r; 
     594  } 
     595  return $greet_list;  
     596
     597function vmailadmin_count_msg($msg_cmd) { 
     598  $results = array(); 
     599  $msg_cnt = 0; 
     600  exec($msg_cmd, $results); 
     601  /* Message can be recorded in multiple formats, but there is always one text */ 
     602  /* file for each message, so count the text files. */ 
     603  foreach ($results as $r) { 
     604    if (preg_match("/.+\/msg[0-9][0-9][0-9][0-9]\.txt\/{0,1}/", $r)) { 
     605      $msg_cnt++; 
     606    } 
     607  } 
     608  return $msg_cnt; 
     609
     610function vmailadmin_get_greeting_timestamps($name=0, $unavail=0, $busy=0, $temp=0, $context="", $extension="") { 
     611  global $vmail_root; 
     612  if ($context == "" || $extension == "") { 
     613    return null; 
     614  } 
     615  $vmail_path = $vmail_root . "/$context/$extension"; 
     616  $ts["name"] = 0; 
     617  $ts["unavail"] = 0; 
     618  $ts["busy"] = 0; 
     619  $ts["temp"] = 0; 
     620  if ($name) { 
     621    $listing = array(); 
     622    exec("ls $vmail_path/greet.*", $listing); 
     623    foreach ($listing as $entry) { 
     624      if (!preg_match("/greet\.tmp\..+/", $entry)) { 
     625        $ts["name"] = date("Y-m-d", filemtime("$entry")); 
     626        break; 
     627      } 
     628    } 
     629  } 
     630  if ($unavail) { 
     631    $listing = array(); 
     632    exec("ls $vmail_path/unavail.*", $listing); 
     633    foreach ($listing as $entry) { 
     634      if (!preg_match("/unavail\.tmp\..+/", $entry)) { 
     635        $ts["unavail"] = date("Y-m-d", filemtime("$entry")); 
     636        break; 
     637      } 
     638    } 
     639  } 
     640  if ($busy) { 
     641    $listing = array(); 
     642    exec("ls $vmail_path/busy.*", $listing); 
     643    foreach ($listing as $entry) { 
     644      if (!preg_match("/busy\.tmp\..+/", $entry)) { 
     645        $ts["busy"] = date("Y-m-d", filemtime("$entry")); 
     646        break; 
     647      } 
     648    } 
     649  } 
     650  if ($temp) { 
     651    $listing = array(); 
     652    exec("ls $vmail_path/temp.*", $listing); 
     653    foreach ($listing as $entry) { 
     654      if (!preg_match("/temp\.tmp\..+/", $entry)) { 
     655        $ts["temp"] = date("Y-m-d", filemtime("$entry")); 
     656        break; 
     657      } 
     658    } 
     659  } 
     660  return $ts; 
    17661} 
    18662?> 
  • contributed_modules/modules/vmailadmin/page.vmailadmin.php

    r7106 r7465  
    1 <div class ="rnav"> 
    21<?php 
    3 global $astman; 
    4 $extens = core_users_list(); 
    5 $extension = $extdisplay = (isset($_REQUEST["extdisplay"]) && $_REQUEST["extdisplay"] != "")?$_REQUEST["extdisplay"]:$extens[0][0]; 
    6 vmaildrawListMenu($extens, $type="setup", $dispnum="vmailadmin", $extdisplay, $description=false); 
    7 ?> 
    8 </div> 
    9 <?php 
    10 // For the module: 
    11 $type = isset($_REQUEST["type"])?$_REQUEST["type"]:""; 
    12 $display = isset($_REQUEST["display"])?$_REQUEST["display"]:""; 
    13 $action = isset($_REQUEST["action"])?$_REQUEST["action"]:""; 
    14 // Was an update to a user's voicemail account performed? ($update_flag is true in such a case) 
    15 $update_flag = isset($_REQUEST["update_flag"])?$_REQUEST["update_flag"]:"false"; 
    16  
    17 // Verify that voicemail module exists on the system. 
    18 if (function_exists("voicemail_getVoicemail") && function_exists("voicemail_saveVoicemail") && function_exists("voicemail_mailbox_get") && function_exists("voicemail_mailbox_add") && function_exists("voicemail_mailbox_del")) { 
    19   $vm_exists = TRUE; 
     2/* 
     3  This program is free software; you can redistribute it and/or 
     4  modify it under the terms of the GNU General Public License 
     5  as published by the Free Software Foundation; either version 2 
     6  of the License, or (at your option) any later version. 
     7 
     8  This program is distributed in the hope that it will be useful, 
     9  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     11  GNU General Public License for more details. 
     12*/ 
     13 
     14/* All extensions. */ 
     15$extens     = core_users_list(); 
     16/* All voicemail.conf settings. */ 
     17$uservm     = voicemail_getVoicemail(); 
     18/* VMAIL info - needed for rnav menu and other page content. */ 
     19$vmail_info["activated_info"]   = array(); 
     20$vmail_info["bycontext"]        = array(); 
     21$vmail_info["unactivated_info"] = array(); 
     22$vmail_info["disabled_list"]    = array(); 
     23$vmail_info["contexts"]         = array(); 
     24$vmail_info["contexts"]   = array_keys($uservm);    /* All voicemail contexts. */ 
     25 
     26$extdisplay       = isset($_REQUEST["ext"])?$_REQUEST["ext"]:""; 
     27$type       = (isset($_REQUEST["type"]) && $_REQUEST["type"] != "")?$_REQUEST["type"]:"setup"; 
     28$display      = (isset($_REQUEST["display"]) && $_REQUEST["display"] != "")?$_REQUEST["display"]:"vmailadmin"; 
     29 
     30$rnav_list        = ""; 
     31$rnav_enabled_index     = array(); 
     32$rnav_entries       = array(); 
     33 
     34/* Activated mailboxes are those which have a subdirectory on disk. */ 
     35global $amp_conf; 
     36$vmail_root = "/" . trim($amp_conf["ASTSPOOLDIR"] , "/") . "/voicemail"; 
     37 
     38if (isset($extens) && is_array($extens)) { 
     39  $i = 0; 
     40  foreach ($extens as $key => $exten) { 
     41    $vmbox = null; 
     42    /* Voicemail is enabled for this extension when it is associated with a voicemail context. */ 
     43    foreach ($vmail_info["contexts"] as $vmcontext) { 
     44      if (isset($uservm[$vmcontext][$exten[0]])) { 
     45        $vmbox["context"] = $vmcontext; 
     46        break; 
     47      } 
     48    } 
     49 
     50    /* FOR RNAV MENU */ 
     51    $name = $exten[1]; 
     52    $unactivated_style = ""; 
     53    $unactivated_txt = ""; 
     54    $disabled_style = ""; 
     55    $disabled_txt = ""; 
     56    $c = ""; 
     57    $c = isset($vmbox["context"])?$vmbox["context"]:""; 
     58    if ($vmbox !== null) { 
     59      $vmail_info["bycontext"][$vmbox["context"]][] = $exten[0]; 
     60      $vmbox["path"] = $vmail_root . "/" . $vmbox["context"] . "/" . $exten[0]; 
     61      $rnav_enabled_index[$vmbox["context"]][] = $i; 
     62      if (is_dir($vmbox["path"])) { 
     63        $vmail_info["activated_info"][$exten[0]] = $vmbox["context"]; 
     64      } else { 
     65        $vmail_info["unactivated_info"][$exten[0]] = $vmbox["context"]; 
     66        $unactivated_style = " style='background: #abc9ff;'"; 
     67        $unactivated_txt = " [unactivated]"; 
     68      } 
     69      $link = "config.php?type=" . $type . "&display=" . $display . "&ext=" . $exten[0] . "&action=bsettings#" . $exten[0]; 
     70    } else { 
     71      /* Voicemail is disabled for this extension. */ 
     72      $vmail_info["disabled_list"][] = $exten[0]; 
     73      $disabled_txt = "disabled"; 
     74      $disabled_style = " style='background: #ffffcc; text-decoration: line-through;'"; 
     75      /* Distinguish between "extensions" and "deviceanduser" modes. */ 
     76      if (isset($amp_conf["AMPEXTENSIONS"]) && ($amp_conf["AMPEXTENSIONS"] == "extensions")) { 
     77        $link = "config.php?type=setup&display=extensions&extdisplay=" . $exten[0] . "#" . $exten[0]; 
     78      } else { 
     79        $link = "config.php?type=setup&display=users&extdisplay=" . $exten[0] . "#" . $exten[0]; 
     80      } 
     81    } 
     82    $rnav_entries[$i] = "\t<li id='vmailadmin_list_" . $exten[0] . "'${disabled_style}${unactivated_style}><a" . ($extdisplay==$exten[0] ? ' class="current"':'') . "${disabled_style}${unactivated_style} href=\"$link\" onHover='menuUpdatePos();'>{$name} &lt;" . $exten[0] . "&gt;&nbsp;&nbsp;(${c}${disabled_txt})${unactivated_txt}</a></li>\n"; 
     83    $i++; 
     84  } 
     85
     86 
     87/* End VMAIL info processing. */ 
     88 
     89/* Settings options */ 
     90$dlen = 800;  /* default max length on text entry */ 
     91$gen_settings = array(    "adsifdn"       => array("ver" => 1.2, "len" => 4, "type" => "char"), 
     92        "adsisec"       => array("ver" => 1.2, "len" => 4, "type" => "char"), 
     93        "adsiver"       => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     94        "attach"      => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     95        "authpassword"      => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     96              "authuser"      => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     97        "backupdeleted"     => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     98        "callback"      => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     99        "charset"       => array("ver" => 1.2, "len" => 32, "type" => "char"), 
     100              "cidinternalcontexts"     => array("ver" => 1.2, "len" => 640, "type" => "char"), 
     101        "dialout"       => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     102        "emailbody"       => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     103        "emaildateformat"     => array("ver" => 1.2, "len" => 32, "type" => "char"), 
     104        "emailsubject"                  => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     105        "envelope"                      => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     106        "exitcontext"                   => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     107        "expungeonhangup"               => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     108        "externnotify"                  => array("ver" => 1.2, "len" => 160, "type" => "char"), 
     109        "externpass"                    => array("ver" => 1.2, "len" => 128, "type" => "char"), 
     110        "externpassnotify"              => array("ver" => 1.6, "len" => 128, "type" => "char"), 
     111        "forcegreetings"                => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     112        "forcename"                     => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     113        "format"                        => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     114        "fromstring"                    => array("ver" => 1.2, "len" => 100, "type" => "char"), 
     115        "greetingsfolder"               => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     116        "imapclosetimeout"              => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     117        "imapflags"                     => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     118        "imapfolder"                    => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     119        "imapgreetings"                 => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     120        "imapopentimeout"               => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     121        "imapparentfolder"              => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     122        "imapport"                      => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     123        "imapreadtimeout"               => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     124        "imapserver"                    => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     125        "imapwritetimeout"              => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     126        "listen-control-forward-key"    => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     127        "listen-control-pause-key"      => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     128        "listen-control-restart-key"    => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     129        "listen-control-reverse-key"    => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     130        "listen-control-stop-key"       => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     131        "mailcmd"                       => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     132        "maxgreet"                      => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     133        "maxlogins"                     => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     134        "maxmessage"      => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     135        "maxmsg"                        => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     136        "maxsecs"                       => array("ver" => 1.6, "len" => $dlen, "type" => "num"), 
     137        "maxsilence"                    => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     138        "minsecs"                       => array("ver" => 1.6, "len" => $dlen, "type" => "num"), 
     139        "moveheard"                     => array("ver" => 1.6, "len" => 0, "type" => "flag"), 
     140        "nextaftercmd"                  => array("ver" => 1.2, "len" => 0, "type" => "flag"), 
     141        "obdcstorage"                   => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     142        "odbctable"                     => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     143        "operator"                      => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     144        "pagerbody"                     => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     145        "pagerfromstring"               => array("ver" => 1.2, "len" => 100, "type" => "char"), 
     146        "pagersubject"                  => array("ver" => 1.2, "len" => $dlen, "type" => "char"), 
     147        "pbxskip"                       => array("ver" => 1.2, "len" => 0, "type" => "flag"), 
     148        "pollfreq"                      => array("ver" => 1.6, "len" => $dlen, "type" => "num"), 
     149        "pollmailboxes"                 => array("ver" => 1.6, "len" => 0, "type" => "flag"), 
     150        "review"                        => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     151        "saycid"                        => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     152        "sayduration"                   => array("ver" => 1.2, "len" => $dlen, "type" => "flag"), 
     153        "saydurationm"                  => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     154        "searchcontexts"                => array("ver" => 1.2, "len" => 0, "type" => "flag"), 
     155        "sendvoicemail"                 => array("ver" => 1.2, "len" => 0, "type" => "flag"), 
     156        "serveremail"                   => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     157        "silencethreshold"              => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     158        "skipms"                        => array("ver" => 1.2, "len" => $dlen, "type" => "num"), 
     159        "smdienable"                    => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     160        "smdiport"                      => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     161        "tempgreetwarn"                 => array("ver" => 1.4, "len" => $dlen, "type" => "flag"), 
     162        "usedirectory"                  => array("ver" => 1.4, "len" => 0, "type" => "flag"), 
     163        "userscontext"                  => array("ver" => 1.4, "len" => $dlen, "type" => "char"), 
     164        "vm-mismatch"                   => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     165        "vm-newpassword"                => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     166        "vm-passchanged"                => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     167        "vm-password"                   => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     168        "vm-reenterpassword"            => array("ver" => 1.6, "len" => $dlen, "type" => "char"), 
     169        "volgain"       => array("ver" => 1.4, "len" => $dlen, "type" => "num")   ); 
     170 
     171$acct_settings = array(   "attach"      => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     172        "attachfmt"     => array("ver" => 1.4, "len" => 20, "type" => "char"), 
     173        "backupdeleted"     => array("ver" => 1.6, "len" => 0,  "type" => "num"), 
     174                    "callback"      => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     175        "callmenum"     => array("ver" => 1.2, "len" => 0,  "type" => "num"), 
     176        "delete"      => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     177        "dialout"     => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     178                    "email"                         => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     179                    "envelope"      => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     180                    "exitcontext"     => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     181                    "forcegreetings"    => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     182                    "forcename"     => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     183                    "hidefromdir"     => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     184                    "imappassword"      => array("ver" => 1.4, "len" => 80, "type" => "char"), 
     185                    "imapuser"      => array("ver" => 1.4, "len" => 80, "type" => "char"), 
     186                    "language"      => array("ver" => 1.4, "len" => 20, "type" => "char"), 
     187        "maxmessage"      => array("ver" => 1.2, "len" => 0, "type" => "num"), 
     188        "maxmsg"      => array("ver" => 1.2, "len" => 0,  "type" => "num"), 
     189                    "maxsecs"     => array("ver" => 1.6, "len" => 0,  "type" => "num"), 
     190                    "moveheard"     => array("ver" => 1.6, "len" => 0,  "type" => "flag"), 
     191        "name"                    => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     192                    "operator"      => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     193                    "pager"                         => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     194        "pwd"                           => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     195        "review"      => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     196                    "saycid"      => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     197                    "sayduration"     => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     198                    "saydurationm"      => array("ver" => 1.2, "len" => 0,  "type" => "num"), 
     199                    "sendvoicemail"     => array("ver" => 1.2, "len" => 0,  "type" => "flag"), 
     200        "serveremail"     => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     201                    "tempgreetwarn"     => array("ver" => 1.4, "len" => 0,  "type" => "flag"), 
     202                    "tz"        => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     203        "vmcontext"     => array("ver" => 1.2, "len" => 80, "type" => "char"), 
     204                    "volgain"     => array("ver" => 1.4, "len" => 0,  "type" => "num") ); 
     205 
     206$tooltips = array("tz"      => array("name"         => _("Timezone definition name"), 
     207             "def"        => _("Time announcement for message playback"), 
     208             "del"        => _("Remove the timezone definition")), 
     209            "general" => array("adsifdn"        => _("The ADSI feature descriptor number to download to"), 
     210             "adsisec"        => _("The ADSI security lock code"), 
     211             "adsiver"        => _("The ADSI voicemail application version number."), 
     212             "attach"         => _("Option to attach voicemails to email."), 
     213             "authpassword"     => _("IMAP server master password."), 
     214             "authuser"       => _("IMAP server master username."), 
     215             "backupdeleted"      => _("No. of deleted messages saved per mailbox (can be a number or yes/no, yes meaning MAXMSG, no meaning 0)."), 
     216             "callback"       => _("Context to call back from; if not listed, calling the sender back will not be permitted."), 
     217             "charset"        => _("The character set for voicemail messages"), 
     218             "cidinternalcontexts"    => _("Comma separated list of internal contexts to use caller ID."), 
     219             "dialout"        => _("Context to dial out from [option 4 from the advanced menu] if not listed, dialing out will not be permitted."), 
     220             "emailbody"      => _("Email body."), 
     221             "emaildateformat"      => _("Load date format config for voicemail mail."), 
     222             "emailsubject"     => _("Email subject"), 
     223             "maxsilence"     => _("How many seconds of silence before we end the recording"), 
     224             "envelope"       => _("Turn on/off envelope playback before message playback. [ON by default] This does NOT affect option 3,3 from the advanced options menu."), 
     225             "exitcontext"      => _("Context to check for handling * or 0 calls to operator. \"Operator Context\""), 
     226             "expungeonhangup"      => _("Expunge on exit."), 
     227             "externnotify"     => _("External voicemail notify application."), 
     228             "externpass"     => _("External password changing command (overrides externpassnotify)."), 
     229             "externpassnotify"     => _("Command specified runs after a user changes his password."), 
     230             "forcegreetings"     => _("Force new user to record greetings (the same as forcename, except for recording greetings).  The default is \"no\"."), 
     231             "forcename"      => _("Force a new user to record their name.  A new user is determined by the password being the same as the mailbox number.  The default is \"no\"."), 
     232             "format"       => _("Formats for writing Voicemail.  Note that when using IMAP storage for voicemail, only the first format specified will be used."), 
     233             "fromstring"     => _("From: string for email"), 
     234             "imapclosetimeout"     => _("For IMAP storage"), 
     235             "imapflags"      => _("IMAP server flags."), 
     236             "imapfolder"     => _("IMAP voicemail folder."), 
     237             "imapgreetings"      => _("If using IMAP storage, specify whether voicemail greetings should be stored via IMAP. If no, then greetings are stored as if IMAP storage were not enabled"), 
     238             "greetingsfolder"      => _("(yes/no) If imapgreetings=yes, then specify which folder to store your greetings in. If you do not specify a folder, then INBOX will be used."), 
     239             "imapopentimeout"      => _("For IMAP storage - TCP open timeout in seconds"), 
     240             "imapparentfolder"     => _("Set the parent folder (default is to have no parent folder set)."), 
     241             "imapport"       => _("IMAP server port."), 
     242             "imapreadtimeout"      => _("For IMAP storage - TCP read timeout in seconds"), 
     243             "imapserver"     => _("IMAP server address."), 
     244             "imapwritetimeout"     => _("For IMAP storage - TCP write timeout in seconds"), 
     245             "listen-control-forward-key" => _("Customize the key that fast-forwards message playback"), 
     246             "listen-control-pause-key"   => _("Customize the key that pauses/unpauses message playback"), 
     247             "listen-control-restart-key" => _("Customize the key that restarts message playback"), 
     248             "listen-control-reverse-key" => _("Customize the key that rewinds message playback"), 
     249             "listen-control-stop-key"    => _("Customize the key that stops message playback"), 
     250             "mailcmd"        => _("Mail command."), 
     251             "maxgreet"       => _("Max message greeting length."), 
     252             "maxlogins"      => _("Max failed login attempts."), 
     253             "maxmessage"       => _("Max message time length."), 
     254             "maxsecs"        => _("Max message time length."), 
     255             "maxmsg"       => _("Maximum number of messages per folder.  If not specified, a default value (100) is used.  Maximum value for this option is 9999."), 
     256             "minsecs"        => _("Min message time length - maxsilence should be less than minsecs or you may get empty messages."), 
     257             "moveheard"      => _("Move heard messages to the 'Old' folder automagically.  Defaults to on."), 
     258             "nextaftercmd"     => _("Skip to the next message after save/delete."), 
     259             "obdcstorage"      => _("The value of odbcstorage is the database connection configured in res_odbc.conf."), 
     260             "odbctable"      => _("The default table for ODBC voicemail storage is voicemessages."), 
     261             "operator"       => _("Operator break. Allow sender to hit 0 before/after/during  leaving a voicemail to reach an operator  [OFF by default]"), 
     262             "pagerbody"      => _("Body of message sent to pager."), 
     263             "pagerfromstring"      => _("From: string sent to pager."), 
     264             "pagersubject"     => _("Subject sent to pager."), 
     265             "pbxskip"        => _("Skip the \"[PBX]:\" string from the message title"), 
     266             "pollfreq"       => _("If the \"pollmailboxes\" option is enabled, this option sets the polling frequency.  The default is once every 30 seconds."), 
     267             "pollmailboxes"      => _("If mailboxes are changed anywhere outside of app_voicemail, then this option must be enabled for MWI to work.  This enables polling mailboxes for changes.  Normally, it will expect that changes are only made when someone called in to one of the voicemail applications. Examples of situations that would require this option are web interfaces to voicemail or an email client in the case of using IMAP storage."), 
     268             "review"       => _("Allow sender to review/rerecord their message before saving it [OFF by default]"), 
     269             "saycid"       => _("Read back caller's telephone number prior to playing the incoming message, and just after announcing the date and time the message was left. If not described, or set to no, it will be in the envelope."), 
     270             "sayduration"      => _("Turn on/off saying duration information before the message playback. [ON by default]"), 
     271             "saydurationm"     => _("Specify in minutes the minimum duration to say. Default is 2 minutes."), 
     272             "searchcontexts"     => _("Yes to search all contexts, no to search current context (if one is not specified)."), 
     273             "sendvoicemail"      => _("Send voicemail message. If not listed, sending messages from inside voicemail will not be permitted."), 
     274             "serveremail"      => _("Who the e-mail notification should appear to come from"), 
     275             "silencethreshold"     => _("Silence threshold (what we consider silence: the lower, the more sensitive)"), 
     276             "skipms"       => _("How many milliseconds to skip forward/back when rew/ff in message playback"), 
     277             "smdienable"     => _("Enable Simple Message Desk Interface (SMDI) integration"), 
     278             "smdiport"       => _("Valid port as specified in smdi.conf for using smdi for external notification."), 
     279             "tempgreetwarn"      => _("Temporary greeting reminder."), 
     280             "usedirectory"     => _("Permit finding entries for forward/compose from the directory"), 
     281             "userscontext"     => _("User context is where entries from users.conf are registered.  The default value is 'default'"), 
     282             "vm-mismatch"      => _("Customize which sound file is used instead of the default prompt that says: \"The passwords you entered and re-entered did not match.  Please try again.\""), 
     283             "vm-newpassword"     => _("Customize which sound file is used instead of the default prompt that says: \"Please enter your new password followed by the pound key.\""), 
     284             "vm-passchanged"     => _("Customize which sound file is used instead of the default prompt that says: \"Your password has been changed.\""), 
     285             "vm-password"      => _("Customize which sound file is used instead of the default prompt that says: \"password\""), 
     286             "vm-reenterpassword"   => _("Customize which sound file is used instead of the default prompt that says: \"Please re-enter your password followed by the pound key\""), 
     287             "volgain"        => _("Emails bearing the voicemail may arrive in a volume too quiet to be heard.  This parameter allows you to specify how much gain to add to the message when sending a voicemail. NOTE: sox must be installed for this option to work.") 
     288             ), 
     289      "account" => array("pwd"        => _("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 (*98) with a phone."), 
     290             "attach"         => _("Option to attach voicemails to email."), 
     291             "attachfmt"      => _("Which format of audio file to attach to the email."), 
     292             "backupdeleted"      => _("No. of deleted messages saved per mailbox (can be a number or yes/no, yes meaning MAXMSG, no meaning 0)."), 
     293             "callback"       => _("Context to call back from; if not listed, calling the sender back will not be permitted."), 
     294             "delete"         => _("After notification, the voicemail is deleted from the server. [per-mailbox only] This is intended for use with users who wish to receive their voicemail ONLY by email. Note:  deletevoicemail is provided as an equivalent option for Realtime configuration."), 
     295             "dialout"        => _("Context to dial out from [option 4 from the advanced menu] if not listed, dialing out will not be permitted."), 
     296             "email"        => _("The email address that voicemails are sent to."), 
     297             "envelope"       => _("Turn on/off envelope playback before message playback. [ON by default] This does NOT affect option 3,3 from the advanced options menu."), 
     298             "exitcontext"      => _("Context to check for handling * or 0 calls to operator. \"Operator Context\""), 
     299             "forcegreetings"       => _("Force new user to record greetings (the same as forcename, except for recording greetings).  The default is \"no\"."), 
     300             "forcename"      => _("Force a new user to record their name.  A new user is determined by the password being the same as the mailbox number.  The default is \"no\"."), 
     301             "fullname"       => _("Name of voicemail account"), 
     302             "hidefromdir"      => _("Hide this mailbox from the directory produced by app_directory. The default is \"no\"."), 
     303             "imappassword"       => _("IMAP password."), 
     304             "imapuser"       => _("IMAP user."), 
     305             "language"       => _("Asterisk language code"), 
     306             "maxmsg"         => _("Maximum number of messages per folder.  If not specified, a default value (100) is used.  Maximum value for this option is 9999."), 
     307             "maxmessage"       => _("Max message time length."), 
     308             "maxsecs"        => _("Max message time length."), 
     309             "moveheard"      => _("Move heard messages to the 'Old' folder automagically.  Defaults to on."), 
     310             "name"       => _("Name of account/user"), 
     311             "operator"       => _("Operator break. Allow sender to hit 0 before/after/during  leaving a voicemail to reach an operator  [OFF by default]"), 
     312             "pager"        => _("Pager/mobile email address that short voicemail notifications are sent to."), 
     313             "review"       => _("Allow sender to review/rerecord their message before saving it [OFF by default]"), 
     314             "saycid"         => _("Read back caller's telephone number prior to playing the incoming message, and just after announcing the date and time the message was left. If not described, or set to no, it will be in the envelope."), 
     315             "sayduration"      => _("Turn on/off saying duration information before the message playback. [ON by default]"), 
     316             "saydurationm"       => _("Specify in minutes the minimum duration to say. Default is 2 minutes."), 
     317             "sendvoicemail"      => _("Send voicemail message. If not listed, sending messages from inside voicemail will not be permitted."), 
     318             "serveremail"      => _("Who the e-mail notification should appear to come from"), 
     319             "tempgreetwarn"      => _("Remind the user that their temporary greeting is set"), 
     320             "tz"         => _("Timezone from zonemessages context.  Irrelevant if envelope=no."), 
     321             "vmcontext"      => _("This is the Voicemail Context which is normally set to default. Do not change unless you understand the implications."), 
     322             "volgain"        => _("Emails bearing the voicemail may arrive in a volume too quiet to be heard.  This parameter allows you to specify how much gain to add to the message when sending a voicemail. NOTE: sox must be installed for this option to work."), 
     323             "callmenum"      => _("Call me number. Can be used from within ARI.") 
     324             ) 
     325     ); 
     326 
     327/* End settings options */ 
     328 
     329/* Data needed to display correct page. */ 
     330$type   = (isset($_REQUEST["type"]) && $_REQUEST["type"] != "")?$_REQUEST["type"]:"setup"; 
     331$display  = (isset($_REQUEST["display"]) && $_REQUEST["display"] != "")?$_REQUEST["display"]:"vmailadmin"; 
     332if (isset($_REQUEST["updated"])) { 
     333  if ($_REQUEST["updated"] == "true") { 
     334    $update_flag = true; 
     335  } else { 
     336    $update_flag = false; 
     337  } 
    20338} else { 
    21   $vm_exists = FALSE
     339  $update_flag = null
    22340} 
    23 // If submitting form, update selected user's voicemail settings. 
     341$action   = isset($_REQUEST["action"])?$_REQUEST["action"]:""; 
     342if (isset($_REQUEST["ext"])) { 
     343    $extension = $_REQUEST["ext"]; 
     344    if (isset($vmail_info["activated_info"][$extension])) { 
     345      $context = $vmail_info["activated_info"][$extension]; 
     346    } else if (isset($vmail_info["unactivated_info"][$extension])) { 
     347      $context = $vmail_info["unactivated_info"][$extension]; 
     348    } else { 
     349      // Force vmailadmin to "system" mode by clearing context and extension values 
     350      $context   = ""; 
     351      $extension = ""; 
     352    } 
     353} else { 
     354  // System mode 
     355  $context   = ""; 
     356  $extension = ""; 
     357
     358 
     359/* Special handling for action specified by form submission. */ 
     360if ($action == "Go") { 
     361  /* This is for viewing a particular context's usage. */ 
     362  $action = "usage"; 
     363  /* Clear extension */ 
     364  $extension = ""; 
     365} else if ($action == "Submit") { 
     366  /* "Submit" is for performing some kind of update to settings (for page type of general, account OR timezone settings) OR to the files on disk. */ 
     367  /* page_type can be settings, account, tz or usage. */ 
     368  $action = (isset($_REQUEST["page_type"]) && !empty($_REQUEST["page_type"]))?$_REQUEST["page_type"]:"";; 
     369  $need_update = true; 
     370} else { 
     371  $need_update = false; 
     372
     373 
     374/* If no action specified, default to a view of the entire system's usage. */ 
     375if (empty($action)) { 
     376  $context     = ""; 
     377  $extension   = ""; 
     378  $need_update = false; 
     379  $action      = "usage"; 
     380
     381 
     382/* Need to generate rnav div menu */ 
     383/* system-wide rnav menu (lists all accounts) */ 
     384$rnav_list = implode("\n", $rnav_entries); 
     385 
     386$rnav_menu = "<ul name='vmailadmin_menu' id='vmailadmin_menu' style='max-width:400px;'>\n" . $rnav_list . "</ul>"; 
     387$title    = vmailadmin_get_title($action, $context, $extension); 
     388$output   = ""; 
     389$output   .= "<div class='rnav'>$rnav_menu</div>"; 
     390$output   .= "<div class='content'>\n"; 
     391$output   .= "<form name='frm_vmailadmin' action='" . $_SERVER['PHP_SELF'] . "' method='post'>"; 
     392$output   .= "<input type='hidden' name='type' id='type' value='$type' />"; 
     393$output   .= "<input type='hidden' name='display' id='display' value='$display' />"; 
     394$output   .= "<input type='hidden' name='ext' id='ext' value='$extension' />"; 
     395$output   .= "<input type='hidden' name='page_type' id='page_type' value='$action' />"; 
     396/* Javascript for remembering scroll position of rnav menu */ 
     397$output .= "<script type='text/javascript'><!--\n"; 
     398$output .= "\n 
     399function find_in_menu(id) { 
     400  var objToFind   = document.getElementById(id); 
     401  document.getElementById('vmailadmin_menu').scrollTop = objToFind.offsetTop - 2 * objToFind.offsetHeight; 
     402}"; 
     403if ($extension != "") { 
     404  $output .= "\n\n" . "find_in_menu('vmailadmin_list_" . $extension . "');\n"; 
     405
     406$output .= "\n--></script>"; 
     407/* END of Javascript for remembering scroll position of rnav menu */ 
     408 
     409$sys_view_flag = empty($extension)?true:false; 
     410$settings_link = "<a" . (($sys_view_flag && $action == "settings")?" style='color:#ff9933;' ":" ") . "href='config.php?type=$type&display=$display&action=settings'>Settings</a>"; 
     411$usage_link    = "<a" . (($sys_view_flag && $action == "usage")?" style='color:#ff9933;' ":" ") . "href='config.php?type=$type&display=$display&action=usage'>Usage</a>"; 
     412$tzone_link    = "<a" . (($sys_view_flag && $action == "tz")?" style='color:#ff9933;' ":" ") . "href='config.php?type=$type&display=$display&action=tz'>Timezone Definitions</a>"; 
     413$output        .= "<table border='0' cellpadding='0.3px' cellspacing='2px'>"; 
     414$output        .= "<tr><td colspan='3'>$title</td></tr>"; 
     415$output        .= "<tr><td><h5>" . _("System View Links:") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h5></td><td colspan='2'><h5>$settings_link&nbsp;&nbsp;|&nbsp;&nbsp;$usage_link&nbsp;&nbsp;|&nbsp;&nbsp;$tzone_link</h5></td></tr>"; 
     416 
     417if ($need_update) { 
     418  /* set args */ 
     419  $args = array(); 
     420  if (vmailadmin_update_settings($action, $context, $extension, $_REQUEST)) { 
     421    $url = "config.php?type=$type&display=$display&action=$action&ext=$extension&updated=true"; 
     422    redirect($url); 
     423  } else { 
     424    $url = "config.php?type=$type&display=$display&action=$action&ext=$extension&updated=false"; 
     425    redirect($url); 
     426  } 
     427
    24428switch ($action) { 
    25   case "changevmailsettings": 
    26     // The voicemail functions have their own internal 
    27     // checking. 
    28     // If the voicemail box in question does not exist, 
    29     // the functions simply return.  No harm done. 
    30     // 
    31     // We do NOT call voicemail_mailbox_remove - we do NOT want to delete 
    32     // anything from the user's mailbox. 
    33     if ($vm_exists) { 
    34       $mbox = isset($_REQUEST["extension"])?$_REQUEST["extension"]:NULL; 
    35       $vm = isset($_REQUEST["vm"])?$_REQUEST["vm"]:"disabled"; 
    36       // Delete the user's current voicemail settings. 
    37       voicemail_mailbox_del($_REQUEST["extension"]); 
    38       if ($vm != "disabled") { 
    39         // Prepare all data for being saved into the voicemail configuration. 
    40         // We do not use voicemail_mailbox_add, since that function also 
    41         // tweaks the vmx settings.  This module only accesses the voicemail  
    42         // configuration stored in voicemail.conf. 
    43         if ($mbox !== NULL) { 
    44           $uservm = voicemail_getVoicemail(); 
    45           $vmpwd = isset($_REQUEST["vmpwd"])?$_REQUEST["vmpwd"]:""; 
    46           //$name = (isset($_REQUEST["name"]) && $_REQUEST["name"] != "")?$_REQUEST["name"]:$this_exten[1]; 
    47           if (isset($_REQUEST["name"]) && $_REQUEST["name"] != "") { 
    48             $name = $_REQUEST["name"]; 
    49           } else { 
    50             $this_exten = core_users_get($extension); 
    51             $name = $this_exten["name"]; 
     429  case "tz": 
     430    /* get tz settings */ 
     431    $settings = vmailadmin_get_settings($uservm, $action, $extension); 
     432    $output .= "<tr><td colspan='2'><hr /></td><td></td></tr>"; 
     433    $output .= "<tr><td style='max-width: 60px' colspan='2'>" . _("A timezone definition specifies how the voicemail system announces the time.") . "</td><td></td></tr>"; 
     434    $output .= "<tr><td style='max-width: 60px' colspan='2'>" . _("For example, the time a message was left will be announced according to the user's timezone on message playback.") . "</td><td></td></tr>"; 
     435    $output .= "<tr><td></td><td></td></tr>"; 
     436    $output .= "<tr><td style='max-width: 60px' colspan='2'><b>" . _("Entries below will be written to voicemail configuration as-is.") . "</b></td><td></td></tr>"; 
     437    $output .= "<tr><td style='max-width: 60px' colspan='2'><b>" . _("Please be sure to follow the format for timezone definitions described below.") . "</b></td></tr>"; 
     438    $output .= "<tr><td colspan='2'><hr /></td><td></td></tr>"; 
     439    $output .= "<tr><td><a href='#' class='info'><h4>" . _("Name") . "</h4><span>" . $tooltips["tz"]["name"] . "</span></a></td><td><a href='#' class='info'><h4>" . _("Timezone Definition") . "</h4><span>" . $tooltips["tz"]["def"] . "</span></a>"; 
     440    $output .= "</td></tr>";  
     441    if (is_array($settings) && !empty($settings)) { 
     442      foreach ($settings as $key => $val) { 
     443        $output .= "<tr>"; 
     444        $output .= "<td>$key</td>"; 
     445        $output .= "<td><input size='50' type='text' name='tz__$key' id='tz__$key' tabindex='1' value=\"$val\" />"; 
     446        $output .= "&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox' name='tzdel__$key' id='tzdel__$key' value='true' />&nbsp;&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . $tooltips["tz"]["del"] . "</span></a></td></tr>"; 
     447      } 
     448    } 
     449    $output .= "<tr><td coslpan='2'></td></tr>"; 
     450    $output .= "<tr><td><a href='#' class='info'><h4>" . _("New Name") . "</h4><span>" . $tooltips["tz"]["name"] . "</span></a></td><td><a href='#' class='info'><h4>" . _("New Timezone Definition") . "</h4><span>" . $tooltips["tz"]["def"] . "</span></a></td>"; 
     451    $output .= "<tr><td><input size='10' type='text' name='tznew_name' id='tznew_name' tabindex='1' value='' /></td>"; 
     452    $output .= "<td><input size='50' type='text' name='tznew_def' id='tznew_def' tabindex='1' value='' /></td></tr>"; 
     453 
     454    $update_notice = ($update_flag == false)?"&nbsp;&nbsp;<b><u>UPDATE FAILED</u></b>":""; 
     455    $update_notice = ($update_flag == true)?"&nbsp;&nbsp;<b><u>UPDATE COMPLETED</u></b>":""; 
     456    $output .= "<tr><td></td><td colspan='2'><input type='submit' name='action' id='action' value='Submit' />" . $update_notice . "</td></tr>"; 
     457 
     458    $output .= "<tr><td colspan='2'><hr /></td></tr>"; 
     459    $output .= "<tr><td style='max-width: 60px' colspan='2'>" . _("Timezone definition format is: ") . "&nbsp;&nbsp;<b style='font-family:courier;'>" . _("timezone|values") . "</b></td><td></td></tr>"; 
     460    $output .= "<tr><td style='max-width: 60px' colspan='2'><br /><b>" . _("<i>Timezones</i> are listed in /usr/share/zoneinfo") . "</td></tr>"; 
     461    $output .= "<tr><td style='max-width: 60px' colspan='2'><b>" . _("The <i>values</i> supported in the timezone definition string include:") . "</b></td></tr>" . 
     462    "<tr><td>" . _("'filename'") . "</td><td style='max-width: 60px' colspan='2'>" . _("The name of a sound file (the file name must be single-quoted)") . "</td></tr>" . 
     463    "<tr><td>" . _("variable") . "</td><td style='max-width: 60px' colspan='2'>" . _("A variable to be substituted (see below for supported variable values)") . "</td></tr>"; 
     464    $output .= "<tr><td style='max-width: 60px' colspan='2'><b>" . _("Supported <i>variables</i>:") . "</b></td></tr>" . 
     465         "<tr><td style='max-width: 60px'>" . _("A or a")    . "</td><td style='max-width: 60px' colspan='2'>" . _("Day of week (Saturday, Sunday, ...)") . "</td></tr>" . 
     466         "<tr><td style='max-width: 60px'>" . _("B or b or h") . "</td><td style='max-width: 60px' colspan='2'>" . _("Month name (January, February, ...)") . "</td></tr>" . 
     467         "<tr><td style='max-width: 60px'>" . _("d or e")    . "</td><td style='max-width: 60px' colspan='2'>" . _("numeric day of month (first, second, ..., thirty-first)") . "</td></tr>" . 
     468         "<tr><td style='max-width: 60px'>" . _("Y")     . "</td><td style='max-width: 60px' colspan='2'>" . _("Year") . "</td></tr>" . 
     469         "<tr><td style='max-width: 60px'>" . _("I or l")    . "</td><td style='max-width: 60px' colspan='2'>" . _("Hour, 12 hour clock") . "</td></tr>" . 
     470         "<tr><td style='max-width: 60px'>" . _("H")     . "</td><td style='max-width: 60px' colspan='2'>" . _("Hour, 24 hour clock (single digit hours preceded by \"oh\")") . "</td></tr>" . 
     471         "<tr><td style='max-width: 60px'>" . _("k")     . "</td><td style='max-width: 60px' colspan='2'>" . _("Hour, 24 hour clock (single digit hours NOT preceded by \"oh\")") . "</td></tr>" . 
     472         "<tr><td style='max-width: 60px'>" . _("M")     . "</td><td style='max-width: 60px' colspan='2'>" . _("Minute, with 00 pronounced as \"o'clock\"") . "</td></tr>" . 
     473         "<tr><td style='max-width: 60px'>" . _("N")     . "</td><td style='max-width: 60px' colspan='2'>" . _("Minute, with 00 pronounced as \"hundred\" (US military time)") . "</td></tr>" . 
     474         "<tr><td style='max-width: 60px'>" . _("P or p")    . "</td><td style='max-width: 60px' colspan='2'>" . _("AM or PM") . "</td></tr>" . 
     475         "<tr><td style='max-width: 60px'>" . _("Q")     . "</td><td style='max-width: 60px' colspan='2'>" . _("\"today\", \"yesterday\" or ABdY") . "</td></tr>" . 
     476         "<tr><td style='max-width: 60px'>" . _("q")     . "</td><td style='max-width: 60px' colspan='2'>" . _("\"\" (for today), \"yesterday\", weekday, or ABdY") . "</td></tr>" . 
     477         "<tr><td style='max-width: 60px'>" . _("R")     . "</td><td style='max-width: 60px' colspan='2'>" . _("24 hour time, including minute") . "</td></tr>"; 
     478    break; 
     479  case "bsettings": 
     480  case "settings": 
     481    /* get settings */ 
     482    $settings = vmailadmin_get_settings($uservm, $action, $extension); 
     483    /* Get Asterisk version. */ 
     484    $ast_info = engine_getinfo(); 
     485    $version = $ast_info["version"]; 
     486    $text_size = 40; 
     487 
     488    if (!empty($extension)) { 
     489      $acct_title_links  = "<tr><td><h5>" . _("Account View Links:") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h5></td><td colspan='2'><h5><a href='config.php?type=$type&display=$display&action=bsettings&ext=$extension'>" . _("Settings") . "</a>&nbsp;&nbsp;|&nbsp;&nbsp;"; 
     490      $acct_title_links .= "<a href='config.php?type=$type&display=$display&action=usage&ext=$extension'>" . _("Usage") . "</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a style='color:#ff9933;' href='config.php?type=$type&display=$display&action=settings&ext=$extension'>" . _("Advanced Settings") . "</a></h5></td></tr><tr><td colspan='2'><hr /></td></tr>"; 
     491      $display_settings = $acct_settings; 
     492      $display_tips     = $tooltips["account"]; 
     493      $id_prefix        = "acct"; 
     494    } else { 
     495      $acct_title_links = ""; 
     496      $output .= "<tr><td colspan='2'><hr /></td></tr>"; 
     497      $display_settings = $gen_settings; 
     498      $display_tips     = $tooltips["general"]; 
     499      $id_prefix        = "gen"; 
     500    } 
     501    $display_name_row = ""; 
     502    if ($action == "bsettings") { 
     503      # Overwrite account title links 
     504      $acct_title_links = "<tr><td><h5>" . _("Account View Links:") . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</h5></td><td colspan='2'><h5><a style='color:#ff9933;' href='config.php?type=$type&display=$display&action=bsettings&ext=$extension'>" . _("Settings") . "</a>&nbsp;&nbsp;|&nbsp;&nbsp;"; 
     505      $acct_title_links .= "<a href='config.php?type=$type&display=$display&action=usage&ext=$extension'>" . _("Usage") . "</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='config.php?type=$type&display=$display&action=settings&ext=$extension'>" . _("Advanced Settings") . "</a></h5></td></tr><tr><td colspan='2'><hr /></td></tr>"; 
     506      /* Display account name */ 
     507      $display_name = isset($settings["name"])?$settings["name"]:_("No name defined; this is configured from the Extensions or Users page."); 
     508      $display_name_row = "<tr><td><a href='#' class='info'>" . _("Name") . "<span>" . $tooltips["account"]["name"] . "</span></a></td><td>&nbsp;&nbsp;&nbsp;&nbsp;" . $display_name . "</td></tr>"; 
     509      # Override display settings, so only the basic account settings appear. 
     510      unset($display_settings); 
     511      $basic_settings["pwd"]    = isset($settings["pwd"])?$settings["pwd"]:""; 
     512      $basic_settings["email"]  = isset($settings["email"])?$settings["email"]:""; 
     513      $basic_settings["pager"]  = isset($settings["pager"])?$settings["pager"]:""; 
     514      $basic_settings["attach"]   = isset($settings["attach"])?$settings["attach"]:""; 
     515      $basic_settings["saycid"]   = isset($settings["saycid"])?$settings["saycid"]:""; 
     516      $basic_settings["envelope"]   = isset($settings["envelope"])?$settings["envelope"]:""; 
     517      $basic_settings["delete"]   = isset($settings["delete"])?$settings["delete"]:""; 
     518      $basic_settings["callmenum"]  = isset($settings["callmenum"])?$settings["callmenum"]:""; 
     519      unset($settings); 
     520      $settings     = $basic_settings; 
     521      $display_settings["pwd"]  = $acct_settings["pwd"]; 
     522      $display_settings["email"]  = $acct_settings["email"]; 
     523      $display_settings["pager"]  = $acct_settings["pager"]; 
     524      $display_settings["attach"]   = $acct_settings["attach"]; 
     525      $display_settings["saycid"]   = $acct_settings["saycid"]; 
     526      $display_settings["envelope"]   = $acct_settings["envelope"]; 
     527      $display_settings["delete"]   = $acct_settings["delete"]; 
     528      $display_settings["callmenum"]  = $acct_settings["callmenum"]; 
     529      $opt_headings = $display_settings; 
     530      $opt_headings["pwd"]    = _("Voicemail Password"); 
     531      $opt_headings["email"]    = _("Email Address"); 
     532      $opt_headings["pager"]    = _("Pager Email Address"); 
     533      $opt_headings["attach"]   = _("Email Attachment"); 
     534      $opt_headings["saycid"]   = _("Play CID"); 
     535      $opt_headings["envelope"] = _("Play Envelope"); 
     536      $opt_headings["delete"]   = _("Delete Voicemail"); 
     537      $opt_headings["callmenum"]  = _("Call-Me Number"); 
     538    } 
     539    $output .= $acct_title_links . $display_name_row; 
     540 
     541 
     542    foreach ($display_settings as $key => $descrip) { 
     543      $tooltip = isset($display_tips[$key])?$display_tips[$key]:""; 
     544      $len = ($descrip["len"] > 0)?$descrip["len"]:$dlen; 
     545      $id = $id_prefix . "__" . $key; 
     546      if (isset($settings[$key]) || ($version >= $descrip["ver"])) { 
     547        $val = isset($settings[$key])?$settings[$key]:""; 
     548        unset($settings[$key]); 
     549        $opt_name = ($action == "bsettings")?$opt_headings[$key]:$key; 
     550        $output .= "<tr><td><a href='#' class='info'>$opt_name<span>$tooltip</span></a></td>"; 
     551        /* check box or not */ 
     552        if ($descrip["type"] == "flag") { 
     553          switch ($val) { 
     554            case "yes": 
     555              $yes_selected = "checked=checked"; 
     556              $no_selected  = ""; 
     557              $undef_selected = ""; 
     558              break; 
     559            case "no": 
     560              $yes_selected = ""; 
     561              $no_selected = "checked=checked"; 
     562              $undef_selected = ""; 
     563              break; 
     564            default: 
     565              $yes_selected = ""; 
     566              $no_selected = ""; 
     567              $undef_selected = "checked=checked"; 
     568              break; 
    52569          } 
    53           $email = isset($_REQUEST["email"])?$_REQUEST["email"]:""; 
    54           $pager = isset($_REQUEST["pager"])?$_REQUEST["pager"]:""; 
    55           $options = isset($_REQUEST["options"])?$_REQUEST["options"]:""; 
    56           if ($options!="") { 
    57             $options = explode("|", $options); 
    58             foreach ($options as $option) { 
    59               $vmoption = explode("=", $option); 
    60               $vmoptions[$vmoption[0]] = $vmoption[1]; 
    61             } 
    62           } 
    63           $attach = isset($_REQUEST["attach"])?$_REQUEST["attach"]:""; 
    64           $saycid = isset($_REQUEST["saycid"])?$_REQUEST["saycid"]:""; 
    65           $envelope = isset($_REQUEST["envelope"])?$_REQUEST["envelope"]:""; 
    66           $delete = isset($_REQUEST["delete"])?$_REQUEST["delete"]:""; 
    67           $vmoption = explode("=", $attach); 
    68           $vmoptions[$vmoption[0]] = $vmoption[1]; 
    69           $vmoption = explode("=", $saycid); 
    70           $vmoptions[$vmoption[0]] = $vmoption[1]; 
    71           $vmoption = explode("=", $envelope); 
    72           $vmoptions[$vmoption[0]] = $vmoption[1]; 
    73           $vmoption = explode("=", $delete); 
    74           $vmoptions[$vmoption[0]] = $vmoption[1]; 
    75           $vmcontext = (isset($_REQUEST["vmcontext"]) && ($_REQUEST["vmcontext"] != ""))?$_REQUEST["vmcontext"]:"default"; 
    76           $uservm[$vmcontext][$mbox] = array( 
    77             "mailbox" => $mbox, 
    78             "pwd" => $vmpwd, 
    79             "name" => $name, 
    80             "email" => $email, 
    81             "pager" => $pager, 
    82             "options" => $vmoptions 
    83             ); 
    84           // Save the user's new voicemail settings. 
    85           voicemail_saveVoicemail($uservm); 
    86           $astman->send_request("Command", array("Command"=>"reload app_voicemail.so")); 
     570          $output .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;<input type='radio' name='$id' id='$id' tabindex='1' value='yes' $yes_selected />" . _("yes"); 
     571          $output .= "<input type='radio' name='$id' id='$id' tabindex='1' value='no' $no_selected />" . _("no"); 
     572          $output .= "<input type='radio' name='$id' id='$id' tabindex='1' value='undefined' $undef_selected /><a href='#' class='info'>" . _("undefined") . "<span>" . _("Selecting \"undefined\" will remove this option from the user's voicemail configuration entry. (System default will be used.)") . "</span></a></td></tr>"; 
    87573        } else { 
    88           $output_buf .= "INVALID MAILBOX NUMBER <BR/>"; 
     574          $text_type = ($key == "pwd" || $key == "authpassword")?"password":"text"; 
     575          $output .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;<input size='$text_size' maxlength='$len' type='$text_type' name='$id' id='$id' tabindex='1' value=\"$val\" /></td></tr>"; 
    89576        } 
    90577      } 
     578      unset($id); 
     579    } 
     580    /* Any additional setting? */ 
     581    unset($settings["enabled"]);  # ignore this value; we will not enable/disable from vmailadmin 
     582    if (is_array($settings) && !empty($settings)) { 
     583      foreach ($settings as $key => $val) { 
     584        $id = $id_prefix . "__" . $key; 
     585        # no tooltip available 
     586        $output .= "<tr><td>$key</td>"; 
     587        $output .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;<input size='$text_size' type='text' name='$id' id='$id' tabindex='1' value=\"$val\" /></td></tr>"; 
     588      } 
     589    } 
     590    $update_notice = ($update_flag == false)?"&nbsp;&nbsp;<b><u>UPDATE FAILED</u></b>":""; 
     591    $update_notice = ($update_flag == true)?"&nbsp;&nbsp;<b><u>UPDATE COMPLETED</u></b>":""; 
     592    $output .= "<tr><td></td><td colspan='2'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='action' id='action' value='Submit' />" . $update_notice . "</td></tr>"; 
     593    break; 
     594  case "usage": 
     595    /* Usage information and options available for system-wide, 
     596       and individual account views. 
     597    */ 
     598    $scope = vmailadmin_get_scope($extension); 
     599    if ($need_update) { 
     600      vmailadmin_update_usage($vmail_info, $context, $extension, $_REQUEST); 
     601      if (!empty($extension)) { 
     602        $url = "config.php?type=$type&display=$display&ext=$extension&action=$action&updated=true"; 
     603      } else { 
     604        $url = "config.php?type=$type&display=$display&action=$action&updated=true"; 
     605      } 
     606      redirect($url); 
     607    } 
     608 
     609    vmailadmin_get_usage($vmail_info, $scope, $acts_total, $acts_act, $acts_unact, $disabled_count, 
     610                                         $msg_total, $msg_in, $msg_other, 
     611                 $name, $unavail, $busy, $temp, $abandoned, 
     612                 $storage, 
     613                 $context, $extension); 
     614    $lp = "<tr><td colspan='3'><br /></td></tr>"; 
     615    if ($scope == "system") { 
     616      $output .= "<tr><td colspan='3'><hr /></td></tr>"; 
     617      $accounts_row = "<tr><td><a href='#' class='info'>" . _("Number of Accounts:") . "<span>" . _("Total ( Activated / Unactivated / Disabled )") . "</span></a></td>"; 
     618      $accounts_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$acts_total&nbsp;&nbsp;(&nbsp;$acts_act&nbsp;/&nbsp;$acts_unact&nbsp;/&nbsp;$disabled_count&nbsp;)</td></tr>"; 
     619      $accounts_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     620 
     621      $msg_row = "<tr><td><a href='#' class='info'>" . _("Number of Messages:") . "<span>" . _("Total ( Messages in inboxes / Messages in other folders )") . "</span></a></td>"; 
     622      $msg_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$msg_total&nbsp;&nbsp;(&nbsp;$msg_in&nbsp;/&nbsp;$msg_other&nbsp;)</td>"; 
     623      $msg_row .= "<td><input type='checkbox' name='del_msgs' id='del_msgs' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all messages") . "</span></a></td></tr>"; 
     624      $msg_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     625 
     626      $name_row = "<tr><td><a href='#' class='info'>" . _("Recorded Names:") . "<span>" . _("Number of recorded name greetings") . "</span></a></td>"; 
     627      $name_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$name</td>"; 
     628      $name_row .= "<td><input type='checkbox' name='del_names' id='del_names' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all recorded names") . "</span></a></td></tr>"; 
     629      $name_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     630 
     631      $unavail_row = "<tr><td><a href='#' class='info'>" . _("Unavailable Greetings:") . "<span>" . _("Number of recorded unavailable greetings") . "</span></a></td>"; 
     632      $unavail_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$unavail</td>"; 
     633      $unavail_row .= "<td><input type='checkbox' name='del_unavail' id='del_unavail' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all unavailable greetings") . "</span></a></td></tr>"; 
     634      $unavail_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     635 
     636      $busy_row = "<tr><td><a href='#' class='info'>" . _("Busy Greetings:") . "<span>" . _("Number of recorded busy greetings") . "</span></a></td>"; 
     637      $busy_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$busy</td>"; 
     638      $busy_row .= "<td><input type='checkbox' name='del_busy' id='del_busy' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all busy greetings") . "</span></a></td></tr>"; 
     639      $busy_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     640 
     641      $temp_row = "<tr><td><a href='#' class='info'>" . _("Temporary Greetings:") . "<span>" . _("Number of recorded temporary greetings") . "</span></a></td>"; 
     642      $temp_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$temp</td>"; 
     643      $temp_row .= "<td><input type='checkbox' name='del_temp' id='del_temp' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all temporary greetings") . "</span></a></td></tr>"; 
     644      $temp_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     645 
     646      $abandoned_row = "<tr><td><a href='#' class='info'>" . _("Abandoned Greetings:") . "<span>" . _("Number of abandoned greetings. Such greetings were recorded by the user but were NOT accepted, so the sound file remains on disk but is not used as a greeting.") . "</span></a></td>"; 
     647      $abandoned_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$abandoned</td>"; 
     648      $abandoned_row .= "<td><input type='checkbox' name='del_abandoned' id='del_abandoned' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all abandoned greetings (> 1 day old)") . "</span></a></td></tr>"; 
     649      $abandoned_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     650 
     651      $storage_row = "<tr><td><a href='#' class='info'>" . _("Storage Used:") . "<span>" . _("Disk space currently in use by voicemail data") . "</span></a></td>"; 
     652      $storage_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$storage</td>"; 
     653      $storage_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     654       
     655      $output .= $lp . $accounts_row . $msg_row . $name_row . $unavail_row . $busy_row . $temp_row . $abandoned_row . $storage_row;      
    91656    } else { 
    92       $output_buf .= "<BR/>Voicemail is not supported on this system<BR/>"; 
    93     } 
     657      $accounts_row = ""; 
     658      $output .= "<tr><td><h5>" . _("Account View Links:") . "</h5></td><td colspan='3'><h5><a href='config.php?type=$type&display=$display&action=bsettings&ext=$extension'>" . _("Settings") . "</a>&nbsp;&nbsp;|&nbsp;&nbsp;"; 
     659      $output .= "<a style='color:#ff9933;' href='config.php?type=$type&display=$display&action=usage&ext=$extension'>" . _("Usage") . "</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='config.php?type=$type&display=$display&action=settings&ext=$extension'>" . _("Advanced Settings") . "</a></h5></td></tr><tr><td colspan='3'><hr /></td></tr>"; 
     660 
     661      $msg_row = "<tr><td><a href='#' class='info'>" . _("Number of Messages:") . "<span>" . _("Total ( Messages in inboxes / Messages in other folders )") . "</span></a>&nbsp;&nbsp;&nbsp;</td>"; 
     662      $msg_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$msg_total&nbsp;&nbsp;(&nbsp;$msg_in&nbsp;/&nbsp;$msg_other&nbsp;)</td>"; 
     663      $msg_row .= "<td><input type='checkbox' name='del_msgs' id='del_msgs' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all messages") . "</span></a></td></tr>"; 
     664      $msg_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     665 
     666      /* Get timestamps, if applicable */ 
     667      $ts = vmailadmin_get_greeting_timestamps($name, $unavail, $busy, $temp, $context, $extension); 
     668      $name_ts = ($ts["name"] > 0)?$ts["name"]:""; 
     669      $unavail_ts = ($ts["unavail"] > 0)?$ts["unavail"]:""; 
     670      $busy_ts = ($ts["busy"] > 0)?$ts["busy"]:""; 
     671      $temp_ts = ($ts["temp"] > 0)?$ts["temp"]:""; 
     672 
     673      /* Convert count of greetings to yes/no */ 
     674      $name = ($name > 0)?"<a href='#' class='info'>" . _("yes") . "<span>" . _("File timestamp: ") . $name_ts . "</span></a>":_("no"); 
     675      $name_row = "<tr><td><a href='#' class='info'>" . _("Recorded Name:") . "<span>" . _("Has a recorded name greeting?") . "</span></a>&nbsp;&nbsp;&nbsp;</td>"; 
     676      $name_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$name</td>"; 
     677      $name_row .= "<td><input type='checkbox' name='del_names' id='del_names' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove recorded name") . "</span></a>&nbsp;&nbsp;&nbsp;</td></tr>"; 
     678      $name_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     679 
     680      $unavail = ($unavail > 0)?"<a href='#' class='info'>" . _("yes") . "<span>" . _("File timestamp: ") . $unavail_ts . "</span></a>":_("no"); 
     681      $unavail_row = "<tr><td><a href='#' class='info'>" . _("Unavailable Greeting:") . "<span>" . _("Has a recorded unavailable greeting?") . "</span></a>&nbsp;&nbsp;&nbsp;</td>"; 
     682      $unavail_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$unavail</td>"; 
     683      $unavail_row .= "<td><input type='checkbox' name='del_unavail' id='del_unavail' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove unavailable greeting") . "</span></a>&nbsp;&nbsp;&nbsp;</td></tr>"; 
     684      $unavail_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     685 
     686      $busy = ($busy > 0)?"<a href='#' class='info'>" . _("yes") . "<span>" . _("File timestamp: ") . $busy_ts . "</span></a>":_("no"); 
     687      $busy_row = "<tr><td><a href='#' class='info'>" . _("Busy Greetings:") . "<span>" . _("Has a recorded busy greeting?") . "</span></a>&nbsp;&nbsp;&nbsp;</td>"; 
     688      $busy_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$busy</td>"; 
     689      $busy_row .= "<td><input type='checkbox' name='del_busy' id='del_busy' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove busy greeting") . "</span></a>&nbsp;&nbsp;&nbsp;</td></tr>"; 
     690      $busy_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     691 
     692      $temp = ($temp > 0)?"<a href='#' class='info'>" . _("yes") . "<span>" . _("File timestamp: ") . $temp_ts . "</span></a>":_("no"); 
     693      $temp_row = "<tr><td><a href='#' class='info'>" . _("Temporary Greeting:") . "<span>" . _("Has a recorded temporary greeting?") . "</span></a>&nbsp;&nbsp;&nbsp;</td>"; 
     694      $temp_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$temp</td>"; 
     695      $temp_row .= "<td><input type='checkbox' name='del_temp' id='del_temp' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove temporary greeting") . "</span></a></td></tr>"; 
     696      $temp_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     697 
     698      # It is conceivable a user has more than one abandoned greeting. 
     699      $abandoned_row = "<tr><td><a href='#' class='info'>" . _("Abandoned Greetings:") . "<span>" . _("Number of abandoned greetings. Such greetings were recorded by the user but were NOT accepted, so the sound file remains on disk but is not used as a greeting.") . "</span></a></td>"; 
     700      $abandoned_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$abandoned</td>"; 
     701      $abandoned_row .= "<td><input type='checkbox' name='del_abandoned' id='del_abandoned' value='true' />&nbsp;<a href='#' class='info'>" . _("Delete") . "<span>" . _("Remove all abandoned greetings (> 1 day old)") . "</span></a></td></tr>"; 
     702      $abandoned_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     703 
     704      $storage_row = "<tr><td><a href='#' class='info'>" . _("Storage Used") . "<span>" . _("Disk space currently in use by voicemail data") . "</span></a></td>"; 
     705      $storage_row .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;$storage</td>"; 
     706      $storage_row .= "<tr><td colspan='3'><hr style='height:0.1px;' /></td></tr>"; 
     707 
     708      $output .= $lp . $msg_row . $name_row . $unavail_row . $busy_row . $temp_row . $abandoned_row . $storage_row; 
     709    } 
     710 
     711    $update_notice = ($update_flag == false)?"&nbsp;&nbsp;<b><u>UPDATE FAILED</u></b>":""; 
     712    $update_notice = ($update_flag == true)?"&nbsp;&nbsp;<b><u>UPDATE COMPLETED</u></b>":""; 
     713    $output .= "<tr><td></td><td colspan='2'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='submit' name='action' id='action' value='Submit' />" . $update_notice . "</td></tr>"; 
    94714    break; 
    95715  default: 
    96716    break; 
    97717} 
    98 // Get mailbox settings. 
    99 $vmbox = null; 
    100 if ($extens === NULL) { 
    101   $page_output = "<div class='content'> 
    102         <BR/>$output_buf<BR/> 
    103         <h2>" . _("Voicemail") . "</h2> 
    104         <h3>No voicemail users are defined on this system.</h3>"; 
    105 
    106 else { 
    107   $vmbox = voicemail_mailbox_get($extension); 
    108   if ($vmbox !== null) { 
    109     $status_enabled = "selected"; 
    110     $status_disabled = ""; 
    111   } else { 
    112     $status_enabled = ""; 
    113     $status_disabled = "selected"; 
    114   } 
    115   $context = isset($vmbox["vmcontext"])?$vmbox["vmcontext"]:"default"; 
    116   $pwd = isset($vmbox["pwd"])?$vmbox["pwd"]:""; 
    117   $name = (isset($vmbox["name"]) && $vmbox["name"] != "")?$vmbox["name"]:""; 
    118   if ($name == "") { 
    119     $this_exten = core_users_get($extension); 
    120     $name = $this_exten["name"]; 
    121   } 
    122   $email = isset($vmbox["email"])?$vmbox["email"]:""; 
    123   $pager = isset($vmbox["pager"])?$vmbox["pager"]:""; 
    124   $options = isset($vmbox["options"])?$vmbox["options"]:array(); 
    125   if ($options !== NULL) { 
    126     if (isset($options["attach"])) { 
    127       if ($options["attach"] == "yes") { 
    128         $yes_attach = "checked=checked"; 
    129         $no_attach = ""; 
    130       } else { 
    131         $yes_attach = ""; 
    132         $no_attach = "checked=checked"; 
    133       } 
    134     } else { 
    135       $yes_attach = ""; 
    136       $no_attach = "checked=checked"; 
    137     } 
    138     if (isset($options["saycid"])) { 
    139       if ($options["saycid"] == "yes") { 
    140         $yes_cid = "checked=checked"; 
    141         $no_cid = ""; 
    142       } else { 
    143         $yes_cid = ""; 
    144         $no_cid = "checked=checked"; 
    145       } 
    146     } else { 
    147       $yes_cid = ""; 
    148       $no_cid = "checked=checked"; 
    149     } 
    150     if (isset($options["envelope"])) { 
    151       if ($options["envelope"] == "yes") { 
    152         $yes_envelope = "checked=checked"; 
    153         $no_envelope = ""; 
    154       } else { 
    155         $yes_envelope = ""; 
    156         $no_envelope = "checked=checked"; 
    157       } 
    158     } else { 
    159       $yes_envelope = ""; 
    160       $no_envelope = "checked=checked"; 
    161     } 
    162     if (isset($options["delete"])) { 
    163       if ($options["delete"] == "yes") { 
    164         $yes_delete = "checked=checked"; 
    165         $no_delete = ""; 
    166       } else { 
    167         $yes_delete = ""; 
    168         $no_delete = "checked=checked"; 
    169       } 
    170     } else { 
    171       $yes_delete = ""; 
    172       $no_delete = "checked=checked"; 
    173     } 
    174     $opts = ""; 
    175     if (isset($options) && is_array($options)) { 
    176       $alloptions = array_keys($options); 
    177       if (isset($alloptions)) { 
    178         foreach ($alloptions as $opt) { 
    179           if (($opt != "attach") && ($opt != "envelope") && ($opt != "saycid") && ($opt != "delete") && ($opt != "")) { 
    180             $opts .= $opt . "=" . $options[$opt] . "|"; 
    181           } 
    182         } 
    183         $opts = rtrim($opts, "|"); 
    184         // remove the = if no options were set. 
    185         $opts = rtrim($opts, "="); 
    186       } 
    187     } 
    188   } 
    189  
    190   $js_functions = "<script type='text/javascript'><!-- 
    191   function frm_vmailedit_voicemailEnabled(notused) { 
    192  
    193       if (document.getElementById('vm').value == 'disabled') { 
    194         var dval=true; 
    195       } else { 
    196         var dval=false; 
    197       } 
    198       document.getElementById('vmpwd').disabled=dval; 
    199       document.getElementById('email').disabled=dval; 
    200       document.getElementById('pager').disabled=dval; 
    201       document.getElementById('attach0').disabled=dval; 
    202       document.getElementById('attach1').disabled=dval; 
    203       document.getElementById('saycid0').disabled=dval; 
    204       document.getElementById('saycid1').disabled=dval; 
    205       document.getElementById('envelope0').disabled=dval; 
    206       document.getElementById('envelope1').disabled=dval; 
    207       document.getElementById('delete0').disabled=dval; 
    208       document.getElementById('delete1').disabled=dval; 
    209       document.getElementById('options').disabled=dval; 
    210       document.getElementById('vmcontext').disabled=dval; 
    211       return true; 
    212   } 
    213   //--></script>"; 
    214  
    215   $status_html   = "<tr><td>Status</td>"; 
    216   $status_html  .= "<td><select name='vm' id='vm' tabindex=1 onchange='frm_vmailedit_voicemailEnabled();'>"; 
    217   $status_html  .= "<option value='enabled' " . $status_enabled . ">Enabled</option>"; 
    218   $status_html  .= "<option value='disabled' " . $status_disabled . ">Disabled</option>"; 
    219   $status_html  .= "</select></td></tr>"; 
    220  
    221   $pwd_html = "<tr><td><a href='#' class='info'> 
    222       Voicemail Password<span>This is the password used to access the voicemail system. 
    223       <br /><br />This password can only contain numbers. 
    224       <br /><br />A user can change the password you enter here after logging into the voicemail system (*98) with a phone. 
    225       </span></a></td> 
    226       <td> 
    227       <input type='password' name='vmpwd' id='vmpwd' tabindex=1 value='" . $pwd . "'></td></tr>"; 
    228  
    229   $email_html = "<tr> 
    230       <td><a href='#' class='info'>Email Address<span>The email address that voicemails are sent to.</span></a></td> 
    231       <td><input type='text' name='email' id='email' tabindex=1 value='" . $email . "'></td></tr>"; 
    232  
    233   $pager_html = "<tr> 
    234       <td><a href='#' class='info'>Pager Email Address<span>Pager/mobile email address that short voicemail notifications are sent to.</span></a></td> 
    235       <td><input type='text' name='pager' id='pager'   tabindex=1 value='" . $pager . "'></td></tr>"; 
    236  
    237   $att_html = "<tr><td><a href='#' class='info'>Email Attachment<span>Option to attach voicemails to email.</span></a></td> 
    238       <td><input type='radio' name='attach' id='attach0'  tabindex=1 value='attach=yes' " . $yes_attach .  " />yes&nbsp;&nbsp;&nbsp;&nbsp; 
    239       <input type='radio' name='attach' id='attach1'  tabindex=1 value='attach=no' " . $no_attach . "/>no&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"; 
    240  
    241   $cid_html = "<tr> 
    242       <td><a href='#' class='info'>Play CID<span>Read back caller's telephone number prior to playing the incoming message, and just after announcing the date and time the message was left.</span></a></td> 
    243       <td><input type='radio' name='saycid' id='saycid0'  tabindex=1 value='saycid=yes' " . $yes_cid . " />yes&nbsp;&nbsp;&nbsp;&nbsp; 
    244       <input type='radio' name='saycid' id='saycid1'  tabindex=1 value='saycid=no' " . $no_cid . " />no&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"; 
    245  
    246   $envelope_html = "<tr> 
    247       <td><a href='#' class='info'>Play Envelope<span>Envelope controls whether or not the voicemail system will play the message envelope (date/time) before playing the voicemail message. This setting does not affect the operation of the envelope option in the advanced voicemail menu.</span></a></td> 
    248       <td><input type='radio' name='envelope' id='envelope0'  tabindex=1 value='envelope=yes' " . $yes_envelope . " />yes&nbsp;&nbsp;&nbsp;&nbsp; 
    249       <input type='radio' name='envelope' id='envelope1'  tabindex=1 value='envelope=no' " . $no_envelope . " />no&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"; 
    250  
    251   $delete_html = "<tr> 
    252       <td><a href='#' class='info'>Delete Voicemail<span>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.</span></a></td> 
    253       <td><input type='radio' name='delete' id='delete0'  tabindex=1 value='delete=yes' " . $yes_delete . " />yes&nbsp;&nbsp;&nbsp;&nbsp; 
    254       <input type='radio' name='delete' id='delete1'  tabindex=1 value='delete=no' " . $no_delete . " />no&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>"; 
    255  
    256   $opts_html = "<tr> 
    257       <td><a href='#' class='info'>VM Options<span>Separate options with pipe ( | )<br /><br />ie: review=yes|maxmessage=60</span></a></td> 
    258       <td><input type='text' name='options' id='options'   tabindex=1 value='" . $opts . "'></td></tr>"; 
    259  
    260   $context_html = "<tr> 
    261       <td><a href='#' class='info'>VM Context<span>This is the Voicemail Context which is normally set to default. Do not change unless you understand the implications.</span></a></td> 
    262       <td><input type='text' name='vmcontext' id='vmcontext'   tabindex=1 value='" . $context . "'></td></tr>"; 
    263  
    264  
    265   $submit_html = "<tr><td><h6><input name='Submit' type='submit' tabindex='1' value='Submit'></h6></td>"; 
    266   if ($update_flag == "true") { 
    267     $submit_html .= "<td><b>Settings update complete.</b></td>"; 
    268   } 
    269   $submit_html .= "</tr>"; 
    270  
    271   $table_output = $status_html . $pwd_html . $name_html . $email_html . $pager_html . $att_html . $cid_html . $envelope_html . $delete_html . $opts_html . $context_html . $submit_html; 
    272  
    273   $page_output = "<div class='content'> 
    274           <BR/>$output_buf<BR/> 
    275           <h2>" . _("Voicemail: $extension $name") . "</h2> 
    276           <form autocomplete='off' name='ampuserVoicemailEdit' action='config.php' method='post'> 
    277             <input type='hidden' name='update_flag' value='true'/> 
    278             <input type='hidden' name='display' value='$display'/> 
    279             <input type='hidden' name='action' id='action' value='changevmailsettings'/> 
    280             <input type='hidden' name='extension' id='extension' value='$extension'/> 
    281             <input type='hidden' name='extdisplay' id='extdisplay' value='$extension'/> 
    282             <input type='hidden' name='name' id='name' value='$name'> 
    283             <table>$table_output</table> 
    284           </form> 
    285           $js_functions 
    286           <script type='text/javascript'>frm_vmailedit_voicemailEnabled();</script>"; 
    287 }  
    288 echo $page_output; 
     718 
     719$output .= "</table>"; 
     720$output .= "</form>"; 
     721 
     722echo $output; 
    289723?>