Ticket #3549: func.core.php-sipchandid.3.patch

File func.core.php-sipchandid.3.patch, 6.2 kB (added by Nick_Lewis, 3 years ago)
  • old/functions.inc.php

    old new  
    10091009           
    10101010      } 
    10111011 
    1012       // Now create macro-from-zaptel-nnn for each defined channel to route it to the DID routing 
     1012      // Now create macro-from-channel-nnn for each defined channel to route it to the DID routing 
    10131013      // Send it to from-trunk so it is handled as other dids would be handled. 
    10141014      // 
    10151015      foreach (core_zapchandids_list() as $row) { 
    10161016        $channel = $row['channel']; 
    10171017        $did     = $row['did']; 
    10181018 
    1019         $zap_context = "macro-from-zaptel-{$channel}"; 
    1020         $ext->add($zap_context, 's', '', new ext_noop('Entering '.$zap_context.' with DID = ${DID} and setting to: '.$did)); 
    1021         $ext->add($zap_context, 's', '', new ext_setvar('__FROM_DID',$did)); 
    1022         $ext->add($zap_context, 's', '', new ext_goto('1',$did,'from-trunk')); 
     1019        $channel_context = "macro-from-channel-{$channel}"; 
     1020         
     1021        //magic string 'siptoheader' for extracting DID from sip To: header 
     1022        if ($did == "siptoheader") { 
     1023          $ext->add($channel_context, 's', '', new ext_noop('Entering '.$channel_context.' with DID = ${DID}')); 
     1024          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID','${SIP_HEADER(TO)}')); 
     1025          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID','${CUT(FROM_DID,@,1)}')); 
     1026          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID','${CUT(FROM_DID,:,2)}')); 
     1027          $ext->add($channel_context, 's', '', new ext_noop('Used sip To: header to set DID = ${FROM_DID}')); 
     1028          $ext->add($channel_context, 's', '', new ext_goto('1','${FROM_DID}','from-trunk')); 
     1029        } else { 
     1030          $ext->add($channel_context, 's', '', new ext_noop('Entering '.$channel_context.' with DID = ${DID} and setting to: '.$did)); 
     1031          $ext->add($channel_context, 's', '', new ext_setvar('__FROM_DID',$did)); 
     1032          $ext->add($channel_context, 's', '', new ext_goto('1',$did,'from-trunk')); 
     1033        } 
    10231034      } 
    10241035 
    10251036      /* user extensions */ 
     
    11341145            case 'IAX2': 
    11351146            case 'SIP': 
    11361147              $trunkgroup = $trunkprops['globalvar']; 
    1137               $trunkcontext  = "from-trunk-".strtolower($trunkprops['tech'])."-".$trunkprops['name']; 
    1138               $ext->add($trunkcontext, '_.', '', new ext_setvar('GROUP()',$trunkgroup)); 
    1139               $ext->add($trunkcontext, '_.', '', new ext_goto('1','${EXTEN}','from-trunk')); 
     1148              $context  = "from-trunk-".strtolower($trunkprops['tech'])."-".$trunkprops['name']; 
     1149 
     1150              $exten = '_.'; 
     1151       
     1152              $ext->add($context, $exten, '', new ext_set('DID', '${EXTEN}')); 
     1153              $ext->add($context, $exten, '', new ext_goto(1, 's')); 
     1154 
     1155              $exten = 's'; 
     1156              $ext->add($context, $exten, '', new ext_noop('Entering '.$context.' with DID == ${DID}')); 
     1157              $ext->add($context, $exten, '', new ext_setvar('GROUP()',$trunkgroup)); 
     1158              // Some trunks _require_ a RINGING be sent before an Answer.  
     1159              $ext->add($context, $exten, '', new ext_ringing()); 
     1160              // If ($did == "") { $did = "s"; } 
     1161              $ext->add($context, $exten, '', new ext_set('DID', '${IF($["${DID}"= ""]?s:${DID})}')); 
     1162              $ext->add($context, $exten, '', new ext_noop('DID is now ${DID}')); 
     1163              $ext->add($context, $exten, '', new ext_gotoif('$["${CHANNEL:0:3}"="SIP"]', 'trunkok', 'nottrunk')); 
     1164              $ext->add($context, $exten, 'nottrunk', new ext_goto('1', '${DID}', 'from-trunk')); 
     1165              // If there's no ext-did,s,1, that means there's not a no did/no cid route. Hangup. 
     1166              $ext->add($context, $exten, '', new ext_macro('Hangupcall', 'dummy')); 
     1167              $ext->add($context, $exten, 'trunkok', new ext_noop('Is a SIP Trunk Channel')); 
     1168              $ext->add($context, $exten, '', new ext_set('CHAN', '${CHANNEL:4}')); 
     1169              $ext->add($context, $exten, '', new ext_set('CHAN', '${CUT(CHAN,-,1)}')); 
     1170              $ext->add($context, $exten, '', new ext_macro('from-channel-${CHAN}', '${DID},1')); 
     1171              // If nothing there, then treat it as a DID 
     1172              $ext->add($context, $exten, '', new ext_noop('Returned from Macro from-channel-${CHAN}')); 
     1173              $ext->add($context, $exten, '', new ext_goto(1, '${DID}', 'from-trunk')); 
     1174 
     1175 
    11401176              break; 
    11411177            default: 
    11421178          } 
     
    18741910        $ext->add($context, $exten, '', new ext_set('CHAN', '${CHANNEL:4}')); 
    18751911      }        
    18761912      $ext->add($context, $exten, '', new ext_set('CHAN', '${CUT(CHAN,-,1)}')); 
    1877       $ext->add($context, $exten, '', new ext_macro('from-zaptel-${CHAN}', '${DID},1')); 
     1913      $ext->add($context, $exten, '', new ext_macro('from-channel-${CHAN}', '${DID},1')); 
    18781914      // If nothing there, then treat it as a DID 
    1879       $ext->add($context, $exten, '', new ext_noop('Returned from Macro from-zaptel-${CHAN}')); 
     1915      $ext->add($context, $exten, '', new ext_noop('Returned from Macro from-channel-${CHAN}')); 
    18801916      $ext->add($context, $exten, '', new ext_goto(1, '${DID}', 'from-pstn')); 
    18811917      $ext->add($context, 'fax', '', new ext_goto(1, 'in_fax', 'ext-fax')); 
    18821918 
     
    30413077  global $db; 
    30423078 
    30433079 
    3044   if (!ctype_digit(trim($channel)) || trim($channel) == '') { 
    3045     echo "<script>javascript:alert('"._("Invalid Channel Number, must be numeric and not blank")."')</script>"; 
     3080  if (trim($channel) == '') { 
     3081    echo "<script>javascript:alert('"._("Invalid Channel Number, must not be blank")."')</script>"; 
    30463082    return false; 
    30473083  } 
    30483084  if (trim($did) == '') { 
     
    30503086    return false; 
    30513087  } 
    30523088 
     3089  //permit non numeric channel names 
     3090  if (!is_numeric($channel)) { 
     3091    $tableinfo = $db->tableinfo('zapchandids'); 
     3092    if ($tableinfo[0]['type'] != 'string') { 
     3093      $sql = "ALTER TABLE zapchandids CHANGE COLUMN channel channel VARCHAR(40)";  
     3094      $results = $db->query($sql); 
     3095      if (DB::IsError($results)) {die_freepbx($results->getMessage()."<br><br>".$sql);} 
     3096    } 
     3097  } 
     3098 
    30533099  $description = q($description); 
    30543100  $channel     = q($channel); 
    30553101  $did         = q($did); 
     
    30703116function core_zapchandids_edit($description, $channel, $did) { 
    30713117  global $db; 
    30723118 
     3119  //permit non numeric channel names 
     3120  if (!is_numeric($channel)) { 
     3121    $tableinfo = $db->tableinfo('zapchandids'); 
     3122    if ($tableinfo[0]['type'] != 'string') { 
     3123      $sql = "ALTER TABLE zapchandids CHANGE COLUMN channel channel VARCHAR(40)";  
     3124      $results = $db->query($sql); 
     3125      if (DB::IsError($results)) {die_freepbx($results->getMessage()."<br><br>".$sql);} 
     3126    } 
     3127  } 
     3128 
    30733129  $description = q($description); 
    30743130  $channel     = q($channel); 
    30753131  $did         = q($did);