Changeset 7256

Show
Ignore:
Timestamp:
11/12/08 10:13:26 (3 years ago)
Author:
sasargen
Message:

closes #3262, adds checkRange to enforce extension range limits for admin users, and adds email notification for new accounts

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • contributed_modules/modules/bulkextensions/page.bulkextensions.php

    r7112 r7256  
    1313  exportextensions_allusers(); 
    1414} elseif ($_REQUEST["csv_type"] == "input") { 
     15  // Set email notification variables 
     16  if (isset($_REQUEST["default_email"])) { 
     17    $default_email = $_REQUEST["default_email"]; 
     18  } else { 
     19    $default_email = ""; 
     20  } 
     21  if (isset($_REQUEST["override_email"])) { 
     22    $override_email = $_REQUEST["override_email"]; 
     23  } else { 
     24    $override_email = ""; 
     25  } 
     26  if (isset($_REQUEST["email_from"])) { 
     27    $email_from = $_REQUEST["email_from"]; 
     28  } else { 
     29    $email_from = ""; 
     30  } 
     31  if (isset($_REQUEST["email_replyto"])) { 
     32    $email_replyto = $_REQUEST["email_replyto"]; 
     33  } else { 
     34    $email_replyto = ""; 
     35  } 
     36  if (isset($_REQUEST["email_subject"])) { 
     37    $email_subject = $_REQUEST["email_subject"]; 
     38  } else { 
     39    $email_subject = ""; 
     40  } 
     41  if (isset($_REQUEST["email_body_open"])) { 
     42    $email_body_open = $_REQUEST["email_body_open"]; 
     43  } else { 
     44    $email_body_open = ""; 
     45  } 
     46  if (isset($_REQUEST["email_body_close"])) { 
     47    $email_body_close = $_REQUEST["email_body_close"]; 
     48  } else { 
     49    $email_body_close = ""; 
     50  } 
     51  $line_end = "\n"; 
     52 
    1553    $aFields = array ( 
    1654      "action" => array(false, -1), 
     
    499537        $_REQUEST = $vars; 
    500538 
    501         switch ($vars["action"]) { 
    502           case "add": 
    503       // Only add if no voicemail, no user and no device entry already 
    504       // exist for the extension we're trying to add. 
    505       // Check the list of voicemail entries. 
    506       // user_vmexists == false means add  new voicemail entry. 
    507       $user_vmexists = FALSE; 
    508       if ($vm_exists) { 
    509         $uservm = voicemail_getVoicemail(); 
    510         $vmcontexts = array_keys($uservm); 
    511         foreach ($vmcontexts as $vmcontext) { 
    512           if (isset($uservm[$vmcontext][$vars["extension"]])) { 
    513             $user_vmexists = TRUE;    // DO NOT add. 
     539        if (checkRange($vars["extension"])) { 
     540 
     541          switch ($vars["action"]) { 
     542            case "add": 
     543        // Only add if no voicemail, no user and no device entry already 
     544        // exist for the extension we're trying to add. 
     545        // Check the list of voicemail entries. 
     546        // user_vmexists == false means add  new voicemail entry. 
     547        $user_vmexists = FALSE; 
     548        if ($vm_exists) { 
     549          $uservm = voicemail_getVoicemail(); 
     550          $vmcontexts = array_keys($uservm); 
     551          foreach ($vmcontexts as $vmcontext) { 
     552            if (isset($uservm[$vmcontext][$vars["extension"]])) { 
     553              $user_vmexists = TRUE;    // DO NOT add. 
     554            } 
    514555          } 
    515556        } 
    516       } 
    517       if ($user_vmexists || core_users_get($vars["extension"]) || core_devices_get($vars["extension"])) { 
    518         $output .= "Row $k: Extension " . $vars["extension"] . " already exists" . "<BR>"; 
    519       } else { 
     557        if ($user_vmexists || core_users_get($vars["extension"]) || core_devices_get($vars["extension"])) { 
     558          $output .= "Row $k: Extension " . $vars["extension"] . " already exists" . "<BR>"; 
     559        } else { 
     560          if ($vm_exists) { 
     561            voicemail_mailbox_add($vars["extension"], $vars); 
     562          } 
     563          core_users_add($vars); 
     564          core_devices_add($vars["deviceid"],$vars["tech"],$vars["devinfo_dial"],$vars["devicetype"],$vars["deviceuser"],$vars["description"],$vars["emergency_cid"]); 
     565           
     566          if ($lang_exists) { 
     567            languages_user_update($vars["extension"], $vars["langcode"]); 
     568          } 
     569          if ($dict_exists) { 
     570            dictate_update($vars["extension"], $vars["dictenabled"], $vars["dictformat"], $vars["dictemail"]); 
     571          } 
     572          if ($findme_exists && $followme_set) { 
     573            findmefollow_add($vars["account"], $vars["strategy"], $vars["grptime"], $vars["grplist"], $vars["postdest"], $vars["grppre"], $vars["annmsg_id"], $vars["dring"], $vars["needsconf"], $vars["remotealert_id"], $vars["toolate_id"], $vars["ringing"], $vars["pre_ring"], $vars["ddial"]); 
     574          } 
     575          // begin status output for this row 
     576          $output .= "Row $k: Added: " . $vars["extension"]; 
     577          // send notification email for new voicemail account 
     578          $email_to = ""; 
     579          // first use user email defined for voicemail account 
     580          if (isset($vars["email"])) { 
     581            $email_to = $vars["email"]; 
     582          } 
     583          // if no user email specified, use default email 
     584          if (isset($default_email) && ($email_to == "")) { 
     585            $email_to = $default_email; 
     586          } 
     587          // if an override email is specified, use it 
     588          // if "noemail" is set for override email 
     589          // set email_to = "" so that an email will not be sent 
     590          if (isset($override_email) && ($override_email != "")) { 
     591            if ($override_email == "noemail") { 
     592              $email_to = ""; 
     593            } else { 
     594              $email_to = $override_email; 
     595            } 
     596          } 
     597          if ($email_to != "") { 
     598 
     599            // SUBJECT - set default subject if not set by user 
     600            if (!isset($email_subject) || $email_subject == "") { 
     601              $email_subject = _("Voicemail Account Activated"); 
     602            } 
     603 
     604            // FROM - if specified, use that, otherwise leave blank 
     605            if (isset($email_from) && $email_from != "") { 
     606              $email_from = "From: " . $email_from . $line_end; 
     607            } else { 
     608              $email_from = ""; 
     609            } 
     610 
     611            // REPLY-TO - if specified, use that, otherwise leave blank 
     612            if (isset($email_replyto) && $email_replyto != "") { 
     613              $email_replyto = "Reply-To: " . $email_replyto . $line_end; 
     614            } else { 
     615              $email_replyto = ""; 
     616            } 
     617 
     618            // HEADERS 
     619            $email_headers = $email_from . $email_replyto; 
     620 
     621            // BODY 
     622            if (!isset($email_body_open) || $email_body_open == "") { 
     623              $email_body = _("Login information for your voicemail account is as follows:"). "\n\n"; 
     624            } else { 
     625              $email_body = $email_body_open . "\n\n"; 
     626            } 
     627            $email_body .= "\t" . _("Account Name: ") . $vars["name"] . $line_end; 
     628            $email_body .= "\t" . _("Extension: ") . $vars["extension"] . $line_end; 
     629            $email_body .= "\t" . _("Voicemail Password: ") . $vars["vmpwd"] . $line_end; 
     630            if (isset($email_body_close) && $email_body_close != "") { 
     631              $email_body .= "\n\n" . $email_body_close . $line_end; 
     632            } 
     633             
     634            // Mail it! 
     635            if (mail($email_to, $email_subject, $email_body, $email_headers)) { 
     636              $output .= ", notification sent to: " . $email_to; 
     637            } else { 
     638              $output .= ", notification failed to: " . $email_to; 
     639            } 
     640          } 
     641          // close status output for this row with line break 
     642          $output .= "<br />"; 
     643          $change = true; 
     644        } 
     645        break; 
     646      case "edit": 
     647        // Functions core_devices_del and core_users_del 
     648        // do not check that the device or user actually 
     649        // exists. 
     650        // We check that the device or user exists before 
     651                          // deleting by looking them up by the extension. 
     652        // Only if the device or user exists do we call 
     653        // core_devices_del or core_users_del. 
     654        if (core_devices_get($vars["extension"])) { 
     655          core_devices_del($vars["extension"]); 
     656          $change = true; 
     657        } 
     658        if (core_users_get($vars["extension"])) { 
     659          core_users_del($vars["extension"]); 
     660          core_users_cleanastdb($vars["extension"]); 
     661          if ($findme_exists) { 
     662            findmefollow_del($vars["extension"]); 
     663          } 
     664          if ($dict_exists) { 
     665            dictate_del($vars["extension"]); 
     666          } 
     667          if ($lang_exists) { 
     668            languages_user_del($vars["extension"]); 
     669          } 
     670          $change = true; 
     671        } 
     672        // The voicemail functions have their own internal 
     673        // checking. 
     674        // If the voicemail box in question does not exist, 
     675        // the functions simply return.  No harm done. 
     676        // 
     677        // When editting an existing extension do not call 
     678        // voicemail_mailbox_remove, it will delete existing 
     679        // voicemail messages, which is undesirable. 
    520680        if ($vm_exists) { 
    521           voicemail_mailbox_add($vars["extension"], $vars); 
     681          voicemail_mailbox_del($vars["extension"]); 
    522682        } 
    523         core_users_add($vars); 
    524         core_devices_add($vars["deviceid"],$vars["tech"],$vars["devinfo_dial"],$vars["devicetype"],$vars["deviceuser"],$vars["description"],$vars["emergency_cid"]); 
    525          
    526         if ($lang_exists) { 
    527           languages_user_update($vars["extension"], $vars["langcode"]); 
     683        // Only add if no voicemail, no user and no device entry already 
     684        // exist for the extension we're trying to add. 
     685        // Check the list of voicemail entries. 
     686        // user_vmexists == false means add new voicemail entry. 
     687        $user_vmexists = FALSE; 
     688        if ($vm_exists) { 
     689          $uservm = voicemail_getVoicemail(); 
     690          $vmcontexts = array_keys($uservm); 
     691          foreach ($vmcontexts as $vmcontext) { 
     692            if (isset($uservm[$vmcontext][$vars["extension"]])) { 
     693              $user_vmexists = TRUE;    // DO NOT add. 
     694            } 
     695          } 
    528696        } 
    529         if ($dict_exists) { 
    530           dictate_update($vars["extension"], $vars["dictenabled"], $vars["dictformat"], $vars["dictemail"]); 
     697        if ($user_vmexists || core_users_get($vars["extension"]) || core_devices_get($vars["extension"])) { 
     698          $output .= "Row $k: Extension " . $vars["extension"] . " already exists" . "<BR>"; 
     699        } else { 
     700          if ($vm_exists) { 
     701            voicemail_mailbox_add($vars["extension"], $vars); 
     702          } 
     703          core_users_add($vars); 
     704          core_devices_add($vars["deviceid"],$vars["tech"],$vars["devinfo_dial"],$vars["devicetype"],$vars["deviceuser"],$vars["description"],$vars["emergency_cid"]); 
     705          if ($lang_exists) { 
     706            languages_user_update($vars["extension"], $vars["langcode"]); 
     707          } 
     708          if ($dict_exists) { 
     709            dictate_update($vars["extension"], $vars["dictenabled"], $vars["dictformat"], $vars["dictemail"]); 
     710          } 
     711          if ($findme_exists && $followme_set) { 
     712            findmefollow_add($vars["account"], $vars["strategy"], $vars["grptime"], $vars["grplist"], $vars["postdest"], $vars["grppre"], $vars["annmsg_id"], $vars["dring"], $vars["needsconf"], $vars["remotealert_id"], $vars["toolate_id"], $vars["ringing"], $vars["pre_ring"], $vars["ddial"]); 
     713          } 
     714          $change = true; 
    531715        } 
    532         if ($findme_exists && $followme_set) { 
    533           findmefollow_add($vars["account"], $vars["strategy"], $vars["grptime"], $vars["grplist"], $vars["postdest"], $vars["grppre"], $vars["annmsg_id"], $vars["dring"], $vars["needsconf"], $vars["remotealert_id"], $vars["toolate_id"], $vars["ringing"], $vars["pre_ring"], $vars["ddial"]); 
     716        $output .= "Row $k: Edited: " . $vars["extension"] . "<BR>"; 
     717        break; 
     718      case "del": 
     719        // Functions core_devices_del and core_users_del 
     720        // do not check that the device or user actually 
     721        // exists. 
     722        // We check that the device or user exists before 
     723                          // deleting by looking them up by the extension. 
     724        // Only if the device or user exists do we call 
     725        // core_devices_del or core_users_del. 
     726        if (core_devices_get($vars["extension"])) { 
     727          core_devices_del($vars["extension"]); 
     728          $change = true; 
    534729        } 
    535         $output .= "Row $k: Added: " . $vars["extension"] . "<BR>"; 
    536         $change = true; 
    537       } 
    538       break; 
    539     case "edit": 
    540       // Functions core_devices_del and core_users_del 
    541       // do not check that the device or user actually 
    542       // exists. 
    543       // We check that the device or user exists before 
    544                         // deleting by looking them up by the extension. 
    545       // Only if the device or user exists do we call 
    546       // core_devices_del or core_users_del. 
    547       if (core_devices_get($vars["extension"])) { 
    548         core_devices_del($vars["extension"]); 
    549         $change = true; 
    550       } 
    551       if (core_users_get($vars["extension"])) { 
    552         core_users_del($vars["extension"]); 
    553         core_users_cleanastdb($vars["extension"]); 
    554         if ($findme_exists) { 
    555           findmefollow_del($vars["extension"]); 
     730        if (core_users_get($vars["extension"])) { 
     731          core_users_del($vars["extension"]); 
     732          core_users_cleanastdb($vars["extension"]); 
     733          if ($findme_exists) { 
     734            findmefollow_del($vars["extension"]); 
     735          } 
     736          if ($dict_exists) { 
     737            dictate_del($vars["extension"]); 
     738          } 
     739          if ($lang_exists) { 
     740            languages_user_del($vars["extension"]); 
     741          } 
     742          $change = true; 
    556743        } 
    557         if ($dict_exists) { 
    558           dictate_del($vars["extension"]); 
     744        // The voicemail functions have their own internal 
     745        // checking. 
     746        // If the voicemail box in question does not exist, 
     747        // the functions simply return.  No harm done. 
     748        // 
     749        // call remove BEFORE del 
     750        if ($vm_exists) { 
     751          voicemail_mailbox_remove($vars["extension"]); 
     752          voicemail_mailbox_del($vars["extension"]); 
    559753        } 
    560         if ($lang_exists) { 
    561           languages_user_del($vars["extension"]); 
    562         } 
    563         $change = true; 
    564       } 
    565       // The voicemail functions have their own internal 
    566       // checking. 
    567       // If the voicemail box in question does not exist, 
    568       // the functions simply return.  No harm done. 
    569       // 
    570       // When editting an existing extension do not call 
    571       // voicemail_mailbox_remove, it will delete existing 
    572       // voicemail messages, which is undesirable. 
    573       if ($vm_exists) { 
    574         voicemail_mailbox_del($vars["extension"]); 
    575       } 
    576       // Only add if no voicemail, no user and no device entry already 
    577       // exist for the extension we're trying to add. 
    578       // Check the list of voicemail entries. 
    579       // user_vmexists == false means add new voicemail entry. 
    580       $user_vmexists = FALSE; 
    581       if ($vm_exists) { 
    582         $uservm = voicemail_getVoicemail(); 
    583         $vmcontexts = array_keys($uservm); 
    584         foreach ($vmcontexts as $vmcontext) { 
    585           if (isset($uservm[$vmcontext][$vars["extension"]])) { 
    586             $user_vmexists = TRUE;    // DO NOT add. 
    587           } 
    588         } 
    589       } 
    590       if ($user_vmexists || core_users_get($vars["extension"]) || core_devices_get($vars["extension"])) { 
    591         $output .= "Row $k: Extension " . $vars["extension"] . " already exists" . "<BR>"; 
    592       } else { 
    593         if ($vm_exists) { 
    594           voicemail_mailbox_add($vars["extension"], $vars); 
    595         } 
    596         core_users_add($vars); 
    597         core_devices_add($vars["deviceid"],$vars["tech"],$vars["devinfo_dial"],$vars["devicetype"],$vars["deviceuser"],$vars["description"],$vars["emergency_cid"]); 
    598         if ($lang_exists) { 
    599           languages_user_update($vars["extension"], $vars["langcode"]); 
    600         } 
    601         if ($dict_exists) { 
    602           dictate_update($vars["extension"], $vars["dictenabled"], $vars["dictformat"], $vars["dictemail"]); 
    603         } 
    604         if ($findme_exists && $followme_set) { 
    605           findmefollow_add($vars["account"], $vars["strategy"], $vars["grptime"], $vars["grplist"], $vars["postdest"], $vars["grppre"], $vars["annmsg_id"], $vars["dring"], $vars["needsconf"], $vars["remotealert_id"], $vars["toolate_id"], $vars["ringing"], $vars["pre_ring"], $vars["ddial"]); 
    606         } 
    607         $change = true; 
    608       } 
    609       $output .= "Row $k: Edited: " . $vars["extension"] . "<BR>"; 
    610       break; 
    611     case "del": 
    612       // Functions core_devices_del and core_users_del 
    613       // do not check that the device or user actually 
    614       // exists. 
    615       // We check that the device or user exists before 
    616                         // deleting by looking them up by the extension. 
    617       // Only if the device or user exists do we call 
    618       // core_devices_del or core_users_del. 
    619       if (core_devices_get($vars["extension"])) { 
    620         core_devices_del($vars["extension"]); 
    621         $change = true; 
    622       } 
    623       if (core_users_get($vars["extension"])) { 
    624         core_users_del($vars["extension"]); 
    625         core_users_cleanastdb($vars["extension"]); 
    626         if ($findme_exists) { 
    627           findmefollow_del($vars["extension"]); 
    628         } 
    629         if ($dict_exists) { 
    630           dictate_del($vars["extension"]); 
    631         } 
    632         if ($lang_exists) { 
    633           languages_user_del($vars["extension"]); 
    634         } 
    635         $change = true; 
    636       } 
    637       // The voicemail functions have their own internal 
    638       // checking. 
    639       // If the voicemail box in question does not exist, 
    640       // the functions simply return.  No harm done. 
    641       // 
    642       // call remove BEFORE del 
    643       if ($vm_exists) { 
    644         voicemail_mailbox_remove($vars["extension"]); 
    645         voicemail_mailbox_del($vars["extension"]); 
    646       } 
    647       $output .= "Row $k: Deleted: " . $vars["extension"] . "<BR>"; 
    648       break; 
    649     default: 
    650       $output .= "Row $k: Unrecognized action: the only actions recognized are add, edit, del.\n"; 
    651       break; 
    652         } 
    653  
    654         if ($change) { 
    655       needreload(); 
     754        $output .= "Row $k: Deleted: " . $vars["extension"] . "<BR>"; 
     755        break; 
     756      default: 
     757        $output .= "Row $k: Unrecognized action: the only actions recognized are add, edit, del.\n"; 
     758        break; 
     759          } 
     760   
     761          if ($change) { 
     762        needreload(); 
     763          } 
     764        } else { 
     765          $output .= "Row $k: Access denied to extension " . $vars["extension"] . ".  No action performed.<BR>"; 
    656766        } 
    657767      } // while loop 
     
    699809</p> 
    700810<p> 
    701 The table below explains each column in the CSV file. Modify the CSV file to add, 
    702 edit, or delete Extensions as desired. You can change the column order of the CSV 
    703 file as you like, however, the column names must be preserved. Then load the CSV 
    704 file. After the CSV file is processed, the action taken for each row will be 
    705 displayed. 
     811Modify the CSV file to add, edit, or delete Extensions as desired. Then load 
     812the CSV file. After the CSV file is processed, the action taken for each row 
     813will be displayed. 
    706814</p> 
    707815<p> 
     
    712820 
    713821<form action="<?php $_SERVER["PHP_SELF"] ?>" name="uploadcsv" method="post" enctype="multipart/form-data"> 
    714 <input id="csv_type" name="csv_type" type="hidden" value="none"> 
    715 <input type="submit" onclick="document.getElementById('csv_type').value='output';" value="Export Extensions"> 
    716 <br> 
    717 <br> 
    718 CSV File to Load: <input name="csvFile" type="file"> 
    719 <input type="submit" onclick="document.getElementById('csv_type').value='input';"  value="Load File"> 
     822<input id="csv_type" name="csv_type" type="hidden" value="none" /> 
     823<input type="submit" onclick="document.getElementById('csv_type').value='output';" value="Export Extensions" /> 
     824&nbsp;&nbsp;CSV File to Load: <input name="csvFile" type="file" /> 
     825<input type="submit" onclick="document.getElementById('csv_type').value='input';"  value="Load File" /> 
     826<hr /> 
     827<h3>Email Notification for New Accounts</h3> 
     828<p> 
     829By default, a notification email will be sent to the voicemail email address 
     830set for each account added. The settings below can be used to control the 
     831content and destination of the notification emails. 
     832<table> 
     833  <tr> 
     834    <td> 
     835      <a href="#" class="info"> 
     836      Default Address: 
     837      <span> 
     838      If a Default Address is specified, notification emails 
     839      for new accounts without a voicemail email address will 
     840      be sent to the Default Address. 
     841      </span> 
     842      </a> 
     843    </td> 
     844    <td> 
     845      <input name="default_email" id="default_email" type="text" size="60" value="" /> 
     846    </td> 
     847  </tr> 
     848  <tr> 
     849    <td> 
     850      <a href="#" class="info"> 
     851      Override Address: 
     852      <span> 
     853      If an Override Address is specified, all notification 
     854      emails will be sent to the Override Address only. Type 
     855      "noemail" (without the quotes) as the Override Address 
     856      to stop notification emails from being sent. 
     857      </span> 
     858      </a> 
     859    </td> 
     860    <td> 
     861      <input name="override_email" id="override_email" type="text" size="60" value="" /> 
     862    </td> 
     863  </tr> 
     864  <tr> 
     865    <td> 
     866      <a href="#" class="info"> 
     867      Email From: 
     868      <span> 
     869      The Email From header may be specified. If left blank, 
     870      the system default will be used. 
     871      </span> 
     872      </a> 
     873    </td> 
     874    <td> 
     875      <input name="email_from" id="email_from" type="text" size="60" value="" /> 
     876    </td> 
     877  </tr> 
     878  <tr> 
     879    <td> 
     880      <a href="#" class="info"> 
     881      Email Reply-To: 
     882      <span> 
     883      The Email Reply-To header may be specified. If left blank, 
     884      the system default will be used. 
     885      </span> 
     886      </a> 
     887    </td> 
     888    <td> 
     889      <input name="email_replyto" id="email-replyto" type="text" size="60" value="" /> 
     890    </td> 
     891  </tr> 
     892  <tr> 
     893    <td> 
     894      <a href="#" class="info"> 
     895      Email Subject: 
     896      <span> 
     897      The Email Subject may be specified. If left blank, the 
     898      default subject, "Voicemail Account Activated", will be 
     899      used. 
     900      </span> 
     901      </a> 
     902    </td> 
     903    <td> 
     904      <input name="email_subject" id="email_subject" type="text" size="60" value="" /> 
     905    </td> 
     906  </tr> 
     907  <tr> 
     908    <td> 
     909      <a href="#" class="info"> 
     910      Email Opening: 
     911      <span> 
     912      The Email Opening may be specified. If left blank, the 
     913      default opening, "Login information for your voicemail 
     914      account is as follows:", will be used. The account name, 
     915      extension, and voicemail password will automatically be 
     916      inserted after the opening. 
     917      </span> 
     918      </a> 
     919    </td> 
     920    <td> 
     921      <textarea name="email_body_open" id="email_body_open" rows="2" cols="60"></textarea> 
     922    </td> 
     923  </tr> 
     924  <tr> 
     925    <td> 
     926      <a href="#" class="info"> 
     927      Email Closing: 
     928      <span> 
     929      The Email Closing may be specified. If any text is 
     930      entered, it will be inserted at the end of the email. 
     931      </span> 
     932      </a> 
     933    </td> 
     934    <td> 
     935      <textarea name="email_body_close" id="email_body_close" rows="2" cols="60"></textarea> 
     936    </td> 
     937  </tr> 
     938</table> 
    720939</form> 
    721 <hr
     940<hr /
    722941<h3>Bulk Extensions CSV File Columns</h3> 
     942<p> 
     943The table below explains each column in the CSV file. You can change the column 
     944order of the CSV file as you like, however, the column names must be preserved. 
     945</p> 
    723946<?php 
    724947  print $table_output;