Changeset 10159

Show
Ignore:
Timestamp:
07/15/10 18:31:36 (3 years ago)
Author:
p_lindheimer
Message:

suggested solution to add option to the Dial patterns wiazrd for trunks and routes to upload from a CSV file re #4445 - if feedback is positive and with proper testing we can back port the end result to 2.8

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.9/core/core.css

    r9653 r10159  
    1111  max-height: 15em;  
    1212  max-width: 100%;  
     13  width: 500px; 
    1314  overflow: auto;  
    1415  border: 1px solid #CCCCCC; 
    1516} 
    16  
     17#pattern_file { 
     18  display: none; 
     19
  • modules/branches/2.9/core/page.routing.php

    r9965 r10159  
    3030$repotrunkkey = isset($_REQUEST['repotrunkkey'])?$_REQUEST['repotrunkkey']:''; 
    3131 
     32// Check if they uploaded a CSV file for their route patterns 
     33// 
     34if (isset($_FILES['pattern_file']) && $_FILES['pattern_file']['tmp_name'] != '') { 
     35  $fh = fopen($_FILES['pattern_file']['tmp_name'], 'r'); 
     36  if ($fh !== false) { 
     37    $csv_file = array(); 
     38    $index = array(); 
     39 
     40    // Check first row, ingoring empty rows and get indices setup 
     41    // 
     42    while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) { 
     43      if (count($row) == 1 && $row[0] == '') { 
     44        continue; 
     45      } else { 
     46        $count = count($row) > 4 ? 4 : count($row); 
     47        for ($i=0;$i<$count;$i++) { 
     48          switch (strtolower($row[$i])) { 
     49          case 'prepend': 
     50          case 'prefix': 
     51          case 'match pattern': 
     52          case 'callerid': 
     53            $index[strtolower($row[$i])] = $i; 
     54          break; 
     55          default: 
     56          break; 
     57          } 
     58        } 
     59        // If no headers then assume standard order 
     60        if (count($index) == 0) { 
     61          $index['prepend'] = 0; 
     62          $index['prefix'] = 1; 
     63          $index['match pattern'] = 2; 
     64          $index['callerid'] = 3; 
     65          if ($count == 4) { 
     66            $csv_file[] = $row; 
     67          } 
     68        } 
     69        break; 
     70      } 
     71    } 
     72    $row_count = count($index); 
     73    while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) { 
     74      if (count($row) == $row_count) { 
     75        $csv_file[] = $row; 
     76      } 
     77    } 
     78  } 
     79} 
     80 
    3281// 
    3382// Use a hash of the value inserted to get rid of duplicates 
     
    3685$n_idx = 0; 
    3786 
    38 if (isset($_POST["prepend_digit"])) { 
     87// If we have a CSV file it replaces any existing patterns 
     88// 
     89if (!empty($csv_file)) { 
     90  foreach ($csv_file as $row) { 
     91    $this_prepend = isset($index['prepend']) ? htmlspecialchars(trim($row[$index['prepend']])) : ''; 
     92    $this_prefix = isset($index['prefix']) ? htmlspecialchars(trim($row[$index['prefix']])) : ''; 
     93    $this_match_pattern = isset($index['match pattern']) ? htmlspecialchars(trim($row[$index['match pattern']])) : ''; 
     94    $this_callerid = isset($index['callerid']) ? htmlspecialchars(trim($row[$index['callerid']])) : ''; 
     95 
     96    if ($this_prepend != '' || $this_prefix  != '' || $this_match_pattern != '' || $this_callerid != '') { 
     97      $dialpattern_insert[] = array( 
     98        'prepend_digits' => $this_prepend, 
     99        'match_pattern_prefix' => $this_prefix, 
     100        'match_pattern_pass' => $this_match_pattern, 
     101        'match_cid' => $this_callerid, 
     102      ); 
     103    } 
     104  } 
     105} else if (isset($_POST["prepend_digit"])) { 
    39106  $prepend_digit = $_POST["prepend_digit"]; 
    40107  $pattern_prefix = $_POST["pattern_prefix"]; 
     
    336403}  
    337404?> 
    338   <form autocomplete="off" id="routeEdit" name="routeEdit" action="config.php" method="POST" onsubmit="return routeEdit_onsubmit('<?php echo ($extdisplay != '' ? "editroute" : "addroute") ?>');"> 
     405  <form enctype="multipart/form-data" autocomplete="off" id="routeEdit" name="routeEdit" action="config.php" method="POST" onsubmit="return routeEdit_onsubmit('<?php echo ($extdisplay != '' ? "editroute" : "addroute") ?>');"> 
    339406    <input type="hidden" name="display" value="<?php echo $display?>"/> 
    340407    <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/> 
     
    521588          <?php echo _("These options provide a quick way to add outbound dialing rules. Follow the prompts for each.")?><br> 
    522589          <strong><?php echo _("Lookup local prefixes")?></strong> <?php echo _("This looks up your local number on www.localcallingguide.com (NA-only), and sets up so you can dial either 7, 10 or 11 digits (5551234, 6135551234, 16135551234) to access this route.")?><br> 
     590          <strong><?php echo _("Upload from CSV")?></strong> <?php echo sprintf(_("Upload patterns from a CSV file replacing existing entries. If there are no headers then the file must have 4 columns of patterns in the same order as in the GUI. You can also supply headers: %s, %s, %s and %s in the first row. If there are less then 4 recognized headers then the remaining columns will be blank"),'<strong>prepend</strong>','<strong>prefix</strong>','<strong>match pattern</strong>','<strong>callerid</strong>')?><br> 
    523591          </span></a>: 
    524592      <input id="npanxx" name="npanxx" type="hidden" /> 
     
    549617 
    550618      function insertCode() { 
     619        // hide the file box if nothing was set 
     620        if ($('#pattern_file').val() == '') { 
     621          $('#pattern_file').hide(); 
     622        } 
    551623        code = document.getElementById('inscode').value; 
    552624        insert = ''; 
     
    577649            insert = ''; 
    578650          break; 
     651          case 'csv': 
     652            $('#pattern_file').show().click(); 
     653            return true; 
     654          break; 
    579655        } 
    580656 
     
    600676      <option value="emerg"><?php echo _("Emergency")?></option> 
    601677      <option value="lookup"><?php echo _("Lookup local prefixes")?></option> 
     678      <option value="csv"><?php echo _("Upload from CSV")?></option> 
    602679        </select> 
     680        <input type="file" name="pattern_file" id="pattern_file" tabindex="<?php echo ++$tabindex;?>"/> 
    603681      </td> 
    604682    </tr> 
  • modules/branches/2.9/core/page.trunks.php

    r9975 r10159  
    4242$failtrunk_enable = ($failtrunk == "")?'':'CHECKED'; 
    4343 
     44// Check if they uploaded a CSV file for their route patterns 
     45// 
     46if (isset($_FILES['pattern_file']) && $_FILES['pattern_file']['tmp_name'] != '') { 
     47  $fh = fopen($_FILES['pattern_file']['tmp_name'], 'r'); 
     48  if ($fh !== false) { 
     49    $csv_file = array(); 
     50    $index = array(); 
     51 
     52    // Check first row, ingoring empty rows and get indices setup 
     53    // 
     54    while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) { 
     55      if (count($row) == 1 && $row[0] == '') { 
     56        continue; 
     57      } else { 
     58        $count = count($row) > 3 ? 3 : count($row); 
     59        for ($i=0;$i<$count;$i++) { 
     60          switch (strtolower($row[$i])) { 
     61          case 'prepend': 
     62          case 'prefix': 
     63          case 'match pattern': 
     64            $index[strtolower($row[$i])] = $i; 
     65          break; 
     66          default: 
     67          break; 
     68          } 
     69        } 
     70        // If no headers then assume standard order 
     71        if (count($index) == 0) { 
     72          $index['prepend'] = 0; 
     73          $index['prefix'] = 1; 
     74          $index['match pattern'] = 2; 
     75          if ($count == 3) { 
     76            $csv_file[] = $row; 
     77          } 
     78        } 
     79        break; 
     80      } 
     81    } 
     82    $row_count = count($index); 
     83    while (($row = fgetcsv($fh, 5000, ",", "\"")) !== false) { 
     84      if (count($row) == $row_count) { 
     85        $csv_file[] = $row; 
     86      } 
     87    } 
     88  } 
     89  freepbx_debug($index); 
     90  freepbx_debug($csv_file); 
     91} 
     92 
    4493// 
    4594// Use a hash of the value inserted to get rid of duplicates 
     
    4897$n_idx = 0; 
    4998 
    50 if (isset($_POST["prepend_digit"])) { 
     99// If we have a CSV file it replaces any existing patterns 
     100// 
     101if (!empty($csv_file)) { 
     102  foreach ($csv_file as $row) { 
     103    $this_prepend = isset($index['prepend']) ? htmlspecialchars(trim($row[$index['prepend']])) : ''; 
     104    $this_prefix = isset($index['prefix']) ? htmlspecialchars(trim($row[$index['prefix']])) : ''; 
     105    $this_match_pattern = isset($index['match pattern']) ? htmlspecialchars(trim($row[$index['match pattern']])) : ''; 
     106 
     107    if ($this_prepend != '' || $this_prefix  != '' || $this_match_pattern != '') { 
     108      $dialpattern_insert[] = array( 
     109        'prepend_digits' => $this_prepend, 
     110        'match_pattern_prefix' => $this_prefix, 
     111        'match_pattern_pass' => $this_match_pattern, 
     112      ); 
     113    } 
     114  } 
     115} else if (isset($_POST["prepend_digit"])) { 
    51116  $prepend_digit = $_POST["prepend_digit"]; 
    52117  $pattern_prefix = $_POST["pattern_prefix"]; 
     
    403468?> 
    404469   
    405     <form name="trunkEdit" action="config.php" method="post" onsubmit="return trunkEdit_onsubmit('<?php echo ($extdisplay ? "edittrunk" : "addtrunk") ?>');"> 
     470    <form enctype="multipart/form-data" name="trunkEdit" action="config.php" method="post" onsubmit="return trunkEdit_onsubmit('<?php echo ($extdisplay ? "edittrunk" : "addtrunk") ?>');"> 
    406471      <input type="hidden" name="display" value="<?php echo $display?>"/> 
    407472      <input type="hidden" name="extdisplay" value="<?php echo $extdisplay ?>"/> 
     
    557622          <strong><?php echo _("Setup Google for directory assistance")?></strong> <?php echo _("is useful to translate a call to directory assistance (default: 411) to Google's toll free directory (default: 18004664411) or any other number of your choosing")?><br> 
    558623          <strong><?php echo _("Lookup numbers for local trunk")?></strong> <?php echo _("This looks up your local number on www.localcallingguide.com (NA-only), and sets up so you can dial either 7 or 10 digits (regardless of what your PSTN is) on a local trunk (where you have to dial 1+area code for long distance, but only 5551234 (7-digit dialing) or 6135551234 (10-digit dialing) for local calls")?><br> 
     624          <strong><?php echo _("Upload from CSV")?></strong> <?php echo sprintf(_("Upload patterns from a CSV file replacing existing entries. If there are no headers then the file must have 3 columns of patterns in the same order as in the GUI. You can also supply headers: %s, %s and %s in the first row. If there are less then 3 recognized headers then the remaining columns will be blank"),'<strong>prepend</strong>','<strong>prefix</strong>','<strong>match pattern</strong>')?><br> 
    559625          </span></a>: 
    560626        </td><td valign="top"><select id="autopop"  tabindex="<?php echo ++$tabindex;?>" name="autopop" onChange="changeAutoPop(); "> 
     
    565631            <option value="lookup7"><?php echo _("Lookup numbers for local trunk (7-digit dialing)")?></option> 
    566632            <option value="lookup10"><?php echo _("Lookup numbers for local trunk (10-digit dialing)")?></option> 
     633            <option value="csv"><?php echo _("Upload from CSV")?></option> 
    567634          </select> 
     635          <input type="file" name="pattern_file" id="pattern_file" tabindex="<?php echo ++$tabindex;?>"/> 
    568636        </td> 
    569637      </tr> 
     
    663731      function changeAutoPop() { 
    664732        var idx = false; 
     733        // hide the file box if nothing was set 
     734        if ($('#pattern_file').val() == '') { 
     735          $('#pattern_file').hide(); 
     736        } 
    665737        switch(document.getElementById('autopop').value) { 
    666738          case "always": 
     
    688760            populateLookup(10); 
    689761          break; 
     762          case 'csv': 
     763            $('#pattern_file').show().click(); 
     764            return true; 
     765          break; 
    690766        } 
    691767        document.getElementById('autopop').value = '';