Show
Ignore:
Timestamp:
01/26/10 21:46:19 (3 years ago)
Author:
p_lindheimer
Message:

fix some of the fax detection logic, and fix so legacy mode settings can be saved as they were getting deleted re #4007

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.7/fax/functions.inc.php

    r8686 r8688  
    5757 
    5858function fax_dahdi_faxdetect(){ 
    59   return true; 
    60  
    61   //TODO Get this right 
    6259  /* 
    6360   * kepping this always set to true for freepbx 2.7 as we cant currently properly detect this - MB 
    6461   *  
    6562   */ 
    66   global $asterisk_conf; 
    67   $faxdetect=false; 
    68   $dadset=parse_ini_file($asterisk_conf['astetcdir'].'/'.(ast_with_dahdi()?'chan_dahdi':'zapata').'.conf'); 
    69   return (isset($dadset['faxdetect']) && ($dadset['faxdetect'] == 'incoming' || $dadset['faxdetect'] == 'both')); 
     63  return true; 
    7064} 
    7165 
     
    9488    //check for fax modules 
    9589    $app = $astman->send_request('Command', array('Command' => 'module show like res_fax')); 
    96     if (preg_match('/1 modules loaded/', $app['data'])){ 
     90    if (preg_match('/[1-9] modules loaded/', $app['data'])){ 
    9791      $fax['module']='res_fax'; 
    9892    } else { 
    9993      $recive = $astman->send_request('Command', array('Command' => 'module show like app_fax')); 
    100       if (preg_match('/1 modules loaded/', $recive['data'])){$fax['module']='app_fax';} 
     94      if (preg_match('/[1-9] modules loaded/', $recive['data'])){$fax['module']='app_fax';} 
    10195    } 
    102     //TODO: verify this is the right test, no system to check it on yet 
    10396    if (!isset($fax['module'])) { 
    10497      $app = $astman->send_request('Command', array('Command' => 'module show like app_rxfax.so')); 
    105       $fax['module'] = preg_match('/1 modules loaded/', $app['data']) ? 'spandsp': null; 
     98      $fax['module'] = preg_match('/[1-9] modules loaded/', $app['data']) ? 'spandsp': null; 
    10699    } 
    107100    $response = $astman->send_request('Command', array('Command' => 'module show like app_nv_faxdetect')); 
    108     $fax['nvfax']= preg_match('/1 modules loaded/', $response['data']) ? true : false; 
     101    $fax['nvfax']= preg_match('/[1-9] modules loaded/', $response['data']) ? true : false; 
    109102 
    110103    //get license count 
     
    137130      foreach ($dests as $row) { 
    138131        $exten=$row['user']; 
    139         $ext->add($context, $exten, '', new ext_noop('Reciving Fax for Fax Recipient: '.$row['name'].' ('.$row['user'].'), From: ${CALLERID(all)}')); 
     132        $ext->add($context, $exten, '', new ext_noop('Receiving Fax for: '.$row['name'].' ('.$row['user'].'), From: ${CALLERID(all)}')); 
    140133        $ext->add($context, $exten, '', new ext_set('TO', '"'.$row['faxemail'].'"'));      
    141134        if ($fax['module'] == 'spandsp') { 
     
    151144    //write out res_fax.conf and res_fax_digium.conf 
    152145    fax_write_conf(); 
    153   } 
    154   // generate ext-fax-legacy used for both legacy mode and app-fax feature code 
    155   // 
    156   $context='ext-fax-legacy'; 
    157   $exten = 's'
    158   $ext->add($context, $exten, '', new ext_noop('Reciving Fax for Fax Recipient: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}')); 
    159   if ($fax['module'] == 'spandsp') { 
    160     $ext->add($context, $exten, 'receivefax', new ext_rxfax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif')); //recive fax, then email it on 
    161   } else { 
    162     $ext->add($context, $exten, 'receivefax', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif')); //recive fax, then email it on 
    163   } 
    164   $ext->add($context, 'h', '', new ext_execif('$["${FAX_RX_EMAIL}" != ""]','system','\'${ASTVARLIBDIR}/bin/fax-process.pl --to ${FAX_RX_EMAIL} --from "'.$sender_address['0'].'" --dest "${FROM_DID}" --subject "New fax from ${URIENCODE(${CALLERID(all)})}" --attachment fax_${URIENCODE(${CALLERID(number)})}.pdf --type application/pdf --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif\'')); 
    165  
    166   $modulename = 'fax'
    167   $fcc = new featurecode($modulename, 'simu_fax'); 
    168   $fc_simu_fax = $fcc->getCodeActive(); 
    169   unset($fcc); 
    170  
    171   if ($fc_simu_fax != '') { 
    172     $default_address = sql('SELECT value FROM fax_details WHERE `key` = \'FAX_RX_EMAIL\'','getRow'); 
    173     $ext->addInclude('from-internal-additional', 'app-fax'); // Add the include from from-internal 
    174     $ext->add('app-fax', $fc_simu_fax, '', new ext_setvar('FAX_RX_EMAIL', $default_address[0])); 
    175     $ext->add('app-fax', $fc_simu_fax, '', new ext_goto('1', 's', 'ext-fax-legacy')); 
    176     $ext->add('app-fax', 'h', '', new ext_macro('hangupcall')); 
    177  
     146    // generate ext-fax-legacy used for both legacy mode and app-fax feature code 
     147    // 
     148    $context='ext-fax-legacy'; 
     149    $exten = 's'; 
     150    $ext->add($context, $exten, '', new ext_noop('Receiving Fax for: ${FAX_RX_EMAIL} , From: ${CALLERID(all)}'))
     151    if ($fax['module'] == 'spandsp') { 
     152      $ext->add($context, $exten, 'receivefax', new ext_rxfax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif')); //recive fax, then email it on 
     153    } else { 
     154      $ext->add($context, $exten, 'receivefax', new ext_receivefax('${ASTSPOOLDIR}/fax/${UNIQUEID}.tif')); //recive fax, then email it on 
     155    } 
     156    $ext->add($context, 'h', '', new ext_execif('$["${FAX_RX_EMAIL}" != ""]','system','\'${ASTVARLIBDIR}/bin/fax-process.pl --to ${FAX_RX_EMAIL} --from "'.$sender_address['0'].'" --dest "${FROM_DID}" --subject "New fax from ${URIENCODE(${CALLERID(all)})}" --attachment fax_${URIENCODE(${CALLERID(number)})}.pdf --type application/pdf --file ${ASTSPOOLDIR}/fax/${UNIQUEID}.tif\'')); 
     157   
     158    $modulename = 'fax'; 
     159    $fcc = new featurecode($modulename, 'simu_fax')
     160    $fc_simu_fax = $fcc->getCodeActive(); 
     161    unset($fcc); 
     162   
     163    if ($fc_simu_fax != '') { 
     164      $default_address = sql('SELECT value FROM fax_details WHERE `key` = \'FAX_RX_EMAIL\'','getRow'); 
     165      $ext->addInclude('from-internal-additional', 'app-fax'); // Add the include from from-internal 
     166      $ext->add('app-fax', $fc_simu_fax, '', new ext_setvar('FAX_RX_EMAIL', $default_address[0])); 
     167      $ext->add('app-fax', $fc_simu_fax, '', new ext_goto('1', 's', 'ext-fax-legacy')); 
     168      $ext->add('app-fax', 'h', '', new ext_macro('hangupcall')); 
     169    } 
     170
    178171} 
    179172 
     
    291284     
    292285    //dont allow detection to be set if we have no valid detection types 
    293     if(!$fax_dahdi_faxdetect&&!$fax_sip_faxdetect){ 
     286    if(!$fax_dahdi_faxdetect && !$fax_sip_faxdetect && !$fax_detect['nvfax']){ 
    294287      $js="if ($(this).val() == 'true'){alert('"._('No fax detection methods found or no valid licences. Faxing cannot be enabled.')."');return false;}"; 
    295288      $html.='<td><input type="radio" name="faxenabled" value="false" CHECKED />No'; 
     
    336329      $html.='<table class="legacyemail" >'; 
    337330      $html.='<tr ><td><a href="#" class="info">'._("Fax Email Destination").'<span>'._('Address to email faxes to on fax detection.<br />PLEASE NOTE: In this version of FreePBX, you can now set the fax destination from a list of destinations. Extensions/Users can be fax enabled in the user/extension screen and set an email address there. This will create a new destination type that can be selected. To upgrade this option to the full destination list, select YES to Detect Faxes and select a destination. After clicking submit, this route will be upgraded. This Legacy option will no longer be available after the change, it is provided to handle legacy migrations from previous versions of FreePBX only.').'.</span></a>:</td>'; 
    338       $html.='<td><input name="faxlegacyemail" value="'.$fax['legacy_email'].'"></td></tr>'; 
     331      $html.='<td><input name="legacy_email" value="'.$fax['legacy_email'].'"></td></tr>'; 
    339332      $html.='</table>'; 
    340333      $html.='<table class="faxdest27 faxdetect" style="display: none" >'; 
     
    349342} 
    350343 
    351 //TODO: modify to check for nvfaxdetect before iserting it and nothing if not there. 
    352 //TODO: if not too lazy, put an error into notification panel 
    353344function fax_hookGet_config($engine){ 
    354345  $fax=fax_detect(); 
     
    359350    foreach($routes as $current => $route){ 
    360351      if ($route['detection'] == 'nvfax' && !$fax['nvfax']) { 
     352        //TODO: add notificatoin to notification panel that this was skipped because NVFaxdetec not present 
    361353        continue; // skip this one if there is no NVFaxdetect installed on this system 
    362354      } 
     
    380372        } else { 
    381373          if (!isset($default_fax_rx_email)) { 
    382             //TODO Need to add error checking 
    383             // 
    384374            $default_address = sql('SELECT value FROM fax_details WHERE `key` = \'fax_rx_email\'','getRow'); 
    385375            $default_fax_rx_email = $default_address[0]; 
     
    403393  $display=isset($_REQUEST['display'])?$_REQUEST['display']:''; 
    404394  $action=isset($_REQUEST['action'])?$_REQUEST['action']:''; 
    405   $cidnum=isset($_REQUEST['cidnum'])?$_REQUEST['cidnum']:''; 
    406   $extension=isset($_REQUEST['extension'])?$_REQUEST['extension']:''; 
    407   $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:''; 
    408   $enabled=isset($_REQUEST['faxenabled'])?$_REQUEST['faxenabled']:''; 
    409   $detection=isset($_REQUEST['faxdetection'])?$_REQUEST['faxdetection']:''; 
    410   $detectionwait=isset($_REQUEST['faxdetectionwait'])?$_REQUEST['faxdetectionwait']:''; 
    411   $dest=(isset($_REQUEST['gotoFAX'])?$_REQUEST['gotoFAX'].'FAX':null); 
    412   $dest=isset($_REQUEST[$dest])?$_REQUEST[$dest]:''; 
    413   $legacy_email=isset($_REQUEST['legacy_email'])?$_REQUEST['legacy_email']:NULL; 
    414   if(!isset($legacy_email)||isset($dest)){$legacy_email=null;} 
    415    
    416   if ($display == 'did' && isset($action) && $action!=''){ 
     395  if ($display == 'did' && $action!=''){ 
     396 
     397    $cidnum=isset($_REQUEST['cidnum'])?$_REQUEST['cidnum']:''; 
     398    $extension=isset($_REQUEST['extension'])?$_REQUEST['extension']:''; 
     399    $extdisplay=isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:''; 
     400    $enabled=isset($_REQUEST['faxenabled'])?$_REQUEST['faxenabled']:'false'; 
     401    $detection=isset($_REQUEST['faxdetection'])?$_REQUEST['faxdetection']:''; 
     402    $detectionwait=isset($_REQUEST['faxdetectionwait'])?$_REQUEST['faxdetectionwait']:''; 
     403    $dest=(isset($_REQUEST['gotoFAX'])?$_REQUEST['gotoFAX'].'FAX':null); 
     404    $dest=isset($_REQUEST[$dest])?$_REQUEST[$dest]:''; 
     405    if ($enabled != 'legacy') { 
     406      $legacy_email = null; 
     407    } else { 
     408      $legacy_email=isset($_REQUEST['legacy_email'])?$_REQUEST['legacy_email']:''; 
     409    } 
    417410    fax_delete_incoming($extdisplay); //remove mature entry on edit or delete 
    418     if (($action == 'edtIncoming'||$action == 'addIncoming')&& $enabled=='true'){ 
     411    if (($action == 'edtIncoming' || $action == 'addIncoming') && $enabled != 'false'){ 
    419412      fax_save_incoming($cidnum,$extension,$enabled,$detection,$detectionwait,$dest,$legacy_email); 
    420413    } 
     
    425418function fax_save_incoming($cidnum,$extension,$enabled,$detection,$detectionwait,$dest,$legacy_email){ 
    426419  global $db; 
    427   sql("INSERT INTO fax_incoming (cidnum, extension, detection, detectionwait, destination, legacy_email) VALUES ('".$db->escapeSimple($cidnum)."', '".$db->escapeSimple($extension)."', '".$db->escapeSimple($detection)."', '".$db->escapeSimple($detectionwait)."', '".$db->escapeSimple($dest)."','".$db->quoteSmart($legacy_email)."')"); 
     420  sql("INSERT INTO fax_incoming (cidnum, extension, detection, detectionwait, destination, legacy_email) VALUES ('".$db->escapeSimple($cidnum)."', '".$db->escapeSimple($extension)."', '".$db->escapeSimple($detection)."', '".$db->escapeSimple($detectionwait)."', '".$db->escapeSimple($dest)."','".$db->escapeSimple($legacy_email)."')"); 
    428421} 
    429422 
     
    446439  global $asterisk_conf; 
    447440  return true; 
    448   //TODO Fix This Later 
    449     /* 
    450    * kepping this always set to true for freepbx 2.7 as we cant currently properly detect this - MB 
    451    *  
    452    */ 
    453   //these files probobly shouldnt be hardcoded 
    454   $files=array('sip_general_additional.conf','sip_general_custom.conf','sip_custom.conf'); 
    455   foreach($files as $file){$set.=parse_ini_file($file);}//read setting from files 
    456   return ($set['faxdetect'] == 'yes'); 
    457441} 
    458442