Show
Ignore:
Timestamp:
11/09/11 13:27:55 (2 years ago)
Author:
mbrevda
Message:

closes #5443 - paging improvements, revert some accidental checkins. Bugs/more features in NEW tickets please

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/paging/functions.inc.php

    r11761 r12942  
    3838      $callinfo  = 'Call-Info: <uri>\;answer-after=0'; 
    3939      $sipuri    = 'intercom=true'; 
    40       $doptions = 'A(beep)'; 
     40      //$doptions = 'A(beep)'; 
    4141      $vxml_url = ''; 
    4242      $dtime = '5'; 
     
    7373      } 
    7474 
    75       $extpaging = 'ext-paging'; 
     75      $apppaging = 'app-paging'; 
    7676      if (!empty($intercom_code)) { 
    7777        $code = '_'.$intercom_code.'.'; 
     
    130130        $ext->add($context, $code, '', new ext_macro('hangupcall')); 
    131131        if (!$ast_ge_14) { 
    132           $ext->add($context, $code, '', new ext_execif('$[${INTERCOM_RETURN}]', 'Return'),'check',101); 
    133           $ext->add($context, $code, '', new ext_busy()); 
    134           $ext->add($context, $code, '', new ext_macro('hangupcall')); 
     132             $ext->add($context, $code, '', new ext_execif('$[${INTERCOM_RETURN}]', 'Return'),'check',101); 
     133        $ext->add($context, $code, '', new ext_busy()); 
     134        $ext->add($context, $code, '', new ext_macro('hangupcall')); 
    135135        } 
    136136        $ext->add($context, $code, 'pagemode', new ext_setvar('ITER', '1')); 
    137137        $ext->add($context, $code, '', new ext_setvar('DIALSTR', '')); 
    138         $ext->add($context, $code, 'begin', new ext_setvar('DIALSTR', '${DIALSTR}&LOCAL/PAGE${CUT(DEVICES,&,${ITER})}@'.$extpaging)); 
     138        $ext->add($context, $code, 'begin', new ext_setvar('DIALSTR', '${DIALSTR}&LOCAL/PAGE${CUT(DEVICES,&,${ITER})}@'.$apppaging)); 
    139139        $ext->add($context, $code, '', new ext_setvar('ITER', '$[${ITER} + 1]')); 
    140140        $ext->add($context, $code, '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin')); 
     
    142142        $ext->add($context, $code, '', new ext_setvar('_AMPUSER', '${AMPUSER}')); 
    143143        $ext->add($context, $code, '', new ext_page('${DIALSTR},d')); 
    144         $ext->add($context, $code, '', new ext_execif('$[${INTERCOM_RETURN}]', 'Return')); 
     144           $ext->add($context, $code, '', new ext_execif('$[${INTERCOM_RETURN}]', 'Return')); 
    145145        $ext->add($context, $code, '', new ext_busy()); 
    146146        $ext->add($context, $code, '', new ext_macro('hangupcall')); 
    147147 
    148148        $ext->add($context, $code, 'nointercom', new ext_noop('Intercom disallowed by ${dialnumber}')); 
    149         $ext->add($context, $code, '', new ext_execif('$[${INTERCOM_RETURN}]', 'Return')); 
     149           $ext->add($context, $code, '', new ext_execif('$[${INTERCOM_RETURN}]', 'Return')); 
    150150        $ext->add($context, $code, '', new ext_playback('intercom&for&extension')); 
    151151        $ext->add($context, $code, '', new ext_saydigits('${dialnumber}')); 
     
    324324        $ext->add($macro, "s", 'macro2', new ext_macro('${ANSWERMACRO}','${ARG1}'), 'n',2); 
    325325      } 
    326  
    327  
    328       // Create the paging context that is used in the paging application for each phone to auto-answer 
    329       // 
    330       $ext->addInclude('from-internal-noxfer-additional',$extpaging); 
    331          
     326       
     327      //auto answer stuff 
     328      //set autoanswer variables 
     329      $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_SIPURI', '')); 
     330      if (isset($alertinfo) && trim($alertinfo) != "") { 
     331              $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_ALERTINFO', $alertinfo)); 
     332      } 
     333       
     334      if (isset($callinfo) && trim($callinfo) != "") { 
     335              $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_CALLINFO', $callinfo)); 
     336      } 
     337      if (isset($sipuri) && trim($sipuri) != "") { 
     338              $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_SIPURI', $sipuri)); 
     339      } 
     340      if (isset($vxml_url) && trim($vxml_url) != "") { 
     341              $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_VXML_URL', $vxml_url)); 
     342      } 
     343      if (isset($doptions) && trim($doptions) != "") { 
     344              $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_DOPTIONS', $doptions)); 
     345      } 
     346      $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_DTIME', $dtime)); 
     347      $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_ANSWERMACRO', '')); 
     348      foreach ($custom_vars as $key => $value) { 
     349              $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('_'.ltrim($key,'_'), $value)); 
     350      } 
     351      $ext->add($apppaging, '_AUTOASWER.', '', new ext_setvar('__FORWARD_CONTEXT', 'block-cf')); 
     352      $ext->add($apppaging, '_AUTOASWER.', '', new ext_macro('autoanswer','${EXTEN:9}')); 
     353      $ext->add($apppaging, '_AUTOASWER.', '', new ext_return()); 
     354       
    332355      // Normal page version 
    333       $ext->add($extpaging, "_PAGE.", '', new ext_gotoif('$[ ${AMPUSER} = ${EXTEN:4} ]','skipself')); 
    334       if ($ast_ge_14) { 
    335         $ext->add($extpaging, "_PAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:4}/dial)}', 's')); 
    336         $ext->add($extpaging, "_PAGE.", '', new ext_noop_trace('AVAILCHAN: ${AVAILCHAN}, AVAILORIGCHAN: ${AVAILORIGCHAN}, AVAILSTATUS: ${AVAILSTATUS}',5)); 
    337         $ext->add($extpaging, "_PAGE.", '', new ext_gotoif('$["${AVAILORIGCHAN}" = ""]', 'skipself'));       
    338       } else { 
    339         $ext->add($extpaging, "_PAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:4}/dial)}', 'js')); 
    340       } 
    341       $ext->add($extpaging, "_PAGE.", '', new ext_gotoif('$["${DB(DND/${DB(DEVICE/${EXTEN:4}/user)})}" = "YES"]', 'skipself'));      
    342       $ext->add($extpaging, "_PAGE.", 'SKIPCHECK', new ext_macro('autoanswer','${EXTEN:4}')); 
    343       $ext->add($extpaging, "_PAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
    344       $ext->add($extpaging, "_PAGE.", 'skipself', new ext_hangup()); 
    345       if (!$ast_ge_14) { 
    346         $ext->add($extpaging, "_PAGE.", '', new ext_hangup(''), 'AVAIL',101); 
    347       } 
     356      $ext->add($apppaging, "_PAGE.", '', new ext_gotoif('$[ "${AMPUSER}" = "${EXTEN:4}" ]','skipself')); 
     357      $ext->add($apppaging, "_PAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:4}/dial)}', 'js')); 
     358      $ext->add($apppaging, "_PAGE.", '', new ext_gotoif('$["${DB(DND/${DB(DEVICE/${EXTEN:4}/user)})}" = "YES"]', 'skipself'));      
     359      $ext->add($apppaging, "_PAGE.", 'SKIPCHECK', new ext_gosub('AUTOASWER${EXTEN:4},1')); 
     360      $ext->add($apppaging, "_PAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
     361      $ext->add($apppaging, "_PAGE.", 'skipself', new ext_hangup()); 
     362      $ext->add($apppaging, "_PAGE.", '', new ext_hangup(''), 'AVAIL',101); 
    348363 
    349364      // Try ChanSpy Version 
    350       $ext->add($extpaging, "_SPAGE.", '', new ext_gotoif('$[ ${AMPUSER} = ${EXTEN:5} ]','skipself')); 
    351       if ($ast_ge_14) { 
    352         $ext->add($extpaging, "_SPAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:5}/dial)}', 's')); 
    353         $ext->add($extpaging, "_SPAGE.", '', new ext_noop_trace('AVAILCHAN: ${AVAILCHAN}, AVAILORIGCHAN: ${AVAILORIGCHAN}, AVAILSTATUS: ${AVAILSTATUS}',5)); 
    354         $ext->add($extpaging, "_SPAGE.", '', new ext_gotoif('$["${AVAILORIGCHAN}" = ""]', 'chanspy'));       
    355       } else { 
    356         $ext->add($extpaging, "_SPAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:5}/dial)}', 'js')); 
    357       } 
    358       $ext->add($extpaging, "_SPAGE.", '', new ext_gotoif('$["${DB(DND/${DB(DEVICE/${EXTEN:5}/user)})}" = "YES"]', 'chanspy'));      
    359       $ext->add($extpaging, "_SPAGE.", 'SKIPCHECK', new ext_macro('autoanswer','${EXTEN:5}')); 
    360       $ext->add($extpaging, "_SPAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
    361       $ext->add($extpaging, "_SPAGE.", 'skipself', new ext_hangup()); 
    362       $ext->add($extpaging, "_SPAGE.", 'chanspy', new ext_execif('$["${CUT(DB(DEVICE/${EXTEN:5}/dial),/,1)}" = "SIP"]', 'ChanSpy','${DB(DEVICE/${EXTEN:5}/dial)}-,qW')); 
    363       $ext->add($extpaging, "_SPAGE.", '', new ext_noop_trace('Comparison: ${EXTEN:5}, "${CUT(DB(DEVICE/${EXTEN:5}/dial),/,1)}" = "SIP"',9)); 
    364       $ext->add($extpaging, "_SPAGE.", '', new ext_hangup()); 
    365       if (!$ast_ge_14) { 
    366         $ext->add($extpaging, "_SPAGE.", '', new ext_hangup(''), 'AVAIL',101); 
    367       } 
     365      $ext->add($apppaging, "_SPAGE.", '', new ext_gotoif('$[ "${AMPUSER}" = "${EXTEN:5}" ]','skipself')); 
     366      $ext->add($apppaging, "_SPAGE.", 'AVAIL', new ext_chanisavail('${DB(DEVICE/${EXTEN:5}/dial)}', 'js')); 
     367      $ext->add($apppaging, "_SPAGE.", '', new ext_gotoif('$["${DB(DND/${DB(DEVICE/${EXTEN:5}/user)})}" = "YES"]', 'chanspy'));      
     368      $ext->add($apppaging, "_SPAGE.", 'SKIPCHECK', new ext_gosub('AUTOASWER${EXTEN:5},1')); 
     369      $ext->add($apppaging, "_SPAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
     370      $ext->add($apppaging, "_SPAGE.", 'skipself', new ext_hangup()); 
     371      $ext->add($apppaging, "_SPAGE.", 'chanspy', new ext_execif('$["${CUT(DB(DEVICE/${EXTEN:5}/dial),/,1)}" = "SIP"]', 'ChanSpy','${DB(DEVICE/${EXTEN:5}/dial)}-,qW')); 
     372      $ext->add($apppaging, "_SPAGE.", '', new ext_noop_trace('Comparison: ${EXTEN:5}, "${CUT(DB(DEVICE/${EXTEN:5}/dial),/,1)}" = "SIP"',9)); 
     373      $ext->add($apppaging, "_SPAGE.", '', new ext_hangup()); 
     374      $ext->add($apppaging, "_SPAGE.", '', new ext_hangup(''), 'AVAIL',101); 
     375 
    368376 
    369377      // Force page version 
    370       $ext->add($extpaging, "_FPAGE.", '', new ext_gotoif('$[ ${AMPUSER} = ${EXTEN:5} ]','skipself')); 
    371       $ext->add($extpaging, "_FPAGE.", 'SKIPCHECK', new ext_macro('autoanswer','${EXTEN:5}')); 
    372       $ext->add($extpaging, "_FPAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
    373       $ext->add($extpaging, "_FPAGE.", 'skipself', new ext_hangup()); 
    374  
    375       // 
     378      $ext->add($apppaging, "_FPAGE.", '', new ext_gotoif('$[ "${AMPUSER}" = "${EXTEN:5}" ]','skipself')); 
     379      $ext->add($apppaging, "_FPAGE.", 'SKIPCHECK', new ext_gosub('AUTOASWER${EXTEN:5},1')); 
     380      $ext->add($apppaging, "_FPAGE.", '', new ext_dial('${DIAL}','${DTIME},${DOPTIONS}')); 
     381      $ext->add($apppaging, "_FPAGE.", 'skipself', new ext_hangup()); 
     382       
    376383      // Now get a list of all the paging groups... 
    377384      $sql = "SELECT page_group, force_page, duplex FROM paging_config"; 
     
    394401        $all_exts = $db->getAll($sql); 
    395402        $dialstr=''; 
     403         
     404        // Create the paging context that is used in the paging application for each phone to auto-answer 
     405        //add ext-paging with goto's to our app-paging context and a hint for the page 
     406        $extpaging = 'ext-paging'; 
     407        $ext->add($extpaging, $grp, '', new ext_goto($apppaging . ',' . $grp . ',1')); 
     408        $ext->addInclude('from-internal-noxfer-additional',$extpaging); 
     409        $ext->addHint($extpaging, $grp, 'Custom:PAGE' . $grp); 
     410         
     411        //app-page dialplan 
    396412        foreach($all_exts as $local_dial) { 
    397413          if (strtoupper(substr($local_dial[0],-1)) == "X") { 
    398414            $local_dial[0] = rtrim($local_dial[0],"xX"); 
    399415          } 
    400  
    401           $dialstr .= "LOCAL/$pagemode".trim($local_dial[0])."@".$extpaging."&"; 
    402         } 
    403         // It will always end with an &, so lets take that off. 
    404         $dialstr = rtrim($dialstr, "&"); 
    405  
    406         if ($thisgroup['duplex']) { 
    407           $dialstr .= ",d"; 
    408         } 
    409         $ext->add($extpaging, $grp, '', new ext_answer('')); 
    410         $ext->add($extpaging, $grp, '', new ext_macro('user-callerid')); 
    411         // make AMPUSER inherited here, so we can skip the proper 'self' if using cidnum masquerading 
    412         $ext->add($extpaging, $grp, '', new ext_setvar('_AMPUSER', '${AMPUSER}')); 
    413  
    414         $ext->add($extpaging, $grp, '', new ext_setvar('_SIPURI', '')); 
    415         if (isset($alertinfo) && trim($alertinfo) != "") { 
    416           $ext->add($extpaging, $grp, '', new ext_setvar('_ALERTINFO', $alertinfo)); 
    417         } 
    418         if (isset($callinfo) && trim($callinfo) != "") { 
    419           $ext->add($extpaging, $grp, '', new ext_setvar('_CALLINFO', $callinfo)); 
    420         } 
    421         if (isset($sipuri) && trim($sipuri) != "") { 
    422           $ext->add($extpaging, $grp, '', new ext_setvar('_SIPURI', $sipuri)); 
    423         } 
    424         if (isset($vxml_url) && trim($vxml_url) != "") { 
    425           $ext->add($extpaging, $grp, '', new ext_setvar('_VXML_URL', $vxml_url)); 
    426         } 
    427         if (isset($doptions) && trim($doptions) != "") { 
    428           $ext->add($extpaging, $grp, '', new ext_setvar('_DOPTIONS', $doptions)); 
    429         } 
    430         $ext->add($extpaging, $grp, '', new ext_setvar('_DTIME', $dtime)); 
    431         $ext->add($extpaging, $grp, '', new ext_setvar('_ANSWERMACRO', '')); 
    432         foreach ($custom_vars as $key => $value) { 
    433           $ext->add($extpaging, $grp, '', new ext_setvar('_'.ltrim($key,'_'), $value)); 
    434         } 
    435         $ext->add($extpaging, $grp, '', new ext_setvar('__FORWARD_CONTEXT', 'block-cf')); 
    436  
    437         $ext->add($extpaging, $grp, '', new ext_page($dialstr)); 
    438       } 
     416          $page_memebers[] = "LOCAL/$pagemode".trim($local_dial[0])."@".$apppaging; 
     417 
     418        } 
     419         
     420        $ext->add($apppaging, $grp, '', new ext_macro('user-callerid')); 
     421        $ext->add($apppaging, $grp, '', new ext_setvar('_PAGEGROUP', $grp)); 
     422        $ext->add($apppaging, $grp, '', new ext_setvar('PAGE${PAGEGROUP}ADMIN', 'TRUE')); 
     423         
     424        //if page group it in use, got to busy 
     425        $ext->add($apppaging, $grp, '',  
     426          new ext_gotoif('$[${TRYLOCK(apppaging'. $grp .')}]', '', 'busy')); 
     427         
     428        //set blf to in use 
     429        $ext->add($apppaging, $grp, 'devstate',  
     430          new ext_setvar('DEVICE_STATE(Custom:PAGE' . $grp .')', 'INUSE')); 
     431         
     432        $ext->add($apppaging, $grp, '', new ext_answer('')); 
     433        $ext->add($apppaging, $grp, '', new ext_set('PAGE_CONF', '${EPOCH}${RAND(100,999)}')); 
     434        $ext->add($apppaging, $grp, '',  
     435          new ext_set('PAGE_CONF_OPTS', '1doqsx' . (!$thisgroup['duplex'] ? 'm' : ''))); 
     436        $ext->add($apppaging, $grp, 'agi', new ext_agi('page.agi,' 
     437                        . 'extensions=' . implode(':',$page_memebers) . ',' 
     438                        . 'meetmeopts=${PAGE_CONF}\,${PAGE_CONF_OPTS}\,\,,' 
     439                        . 'AMPUSER=${AMPUSER}' 
     440                        )); 
     441        //we cant use originate from the dialplan as the dialplan command is not asynchronous 
     442        //we would like to though... 
     443        //this code here as a sign of hope -MB 
     444        /*foreach ($page_memebers as $member) { 
     445          $ext->add($apppaging, $grp, 'page', new ext_originate($member,'app','meetme', '${PAGE_CONF}\,${PAGE_CONF_OPTS}')); 
     446        }*/          
     447        unset($page_memebers); 
     448        $ext->add($apppaging, $grp, 'page', new ext_meetme('${PAGE_CONF},doqwxCAG(beep)')); 
     449        $ext->add($apppaging, $grp, '', new ext_hangup()); 
     450        $ext->add($apppaging, $grp, 'busy', new ext_set('PAGE${PAGEGROUP}BUSY', 'TRUE')); 
     451        $ext->add($apppaging, $grp, 'play-busy', new ext_busy(3)); 
     452        $ext->add($apppaging, $grp, 'busy-hang', new ext_goto('ext-paging,h,1')); 
     453         
     454      } 
     455      //h 
     456      $ext->add($apppaging, 'h', '',  
     457        new ext_execif('$[' 
     458                . '$["${PAGE${PAGEGROUP}ADMIN}" = "TRUE"]' 
     459                . ' & $[${ISNULL(${PAGE${PAGEGROUP}BUSY})}]' 
     460                . ']',  
     461                'Set', 'DEVICE_STATE(Custom:PAGE${PAGEGROUP})=NOT_INUSE')); 
    439462       
    440463    break;