Changeset 2763

Show
Ignore:
Timestamp:
10/18/06 05:58:23 (7 years ago)
Author:
diego_iastrubni
Message:

this patch removes an obosolete code:

if ($extstate > 0 && $extstate != 4)
{

/// blabla bla
...
if ( ($extstate == 4) )
{
}

}

as you see, the inner if is not reached at all. time to remove...

i also modified the format of the indentations, removed trailing spaces, trhe general purpose is to make the file
more readable by removing empty lines (you see more code on screen, which should help debug this crap).

todo:
remove comments from the code, to more readable central places. move code into functions...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/agi-bin/dialparties.agi

    r2666 r2763  
    11#!/usr/bin/php -q 
    22<?php  
    3 // 
     3 
    44// Copyright (C) 2003 Zac Sprackett <zsprackett-asterisk@sprackett.com> 
    55// 
     
    1818// info@coalescentsystems.ca 
    1919//  
    20 // This script has been ported to PHP by Diego Iastrubni <diego.iastrubni@xorcom.com> 
     20// This script has been ported to PHP by  
     21// Diego Iastrubni <diego.iastrubni@xorcom.com> and the freePBX community 
    2122 
    2223$config = parse_amportal_conf( "/etc/amportal.conf" ); 
     
    2728$debug = 4; 
    2829 
    29 $ext="";      // Hash that will contain our list of extensions to call 
    30 $ext_hunt=""; // Hash that will contain our list of extensions to call used by huntgroup 
    31 $cidnum="";   // Caller ID Number for this call 
    32 $cidname="";  // Caller ID Name for this call 
    33 $timer="";    // Call timer for Dial command 
    34 $dialopts=""; // options for dialing 
    35 $rc="";       // Catch return code 
    36 $priority=""; // Next priority  
    37 $rgmethod=""; // If Ring Group what ringing method was chosen 
    38 $dsarray = array(); // This will hold all the dial strings, used to check for duplicate extensions 
     30$ext   = "";   // Hash that will contain our list of extensions to call 
     31$ext_hunt  = "";   // Hash that will contain our list of extensions to call used by huntgroup 
     32$cidnum    = "";   // Caller ID Number for this call 
     33$cidname = "";   // Caller ID Name for this call 
     34$timer   = "";   // Call timer for Dial command 
     35$dialopts  = "";   // options for dialing 
     36$rc    = "";   // Catch return code 
     37$priority  = "";   // Next priority  
     38$rgmethod  = "";   // If Ring Group what ringing method was chosen 
     39$dsarray = array();  // This will hold all the dial strings, used to check for duplicate extensions 
    3940 
    4041$AGI = new AGI(); 
    41 debug("Starting New Dialparties.agi", 0); 
     42debug("Starting New Dialparties.agi", 1); 
    4243 
    4344$priority = get_var( $AGI, "priority" ) + 1; 
    44 debug( "priority is $priority" ); 
     45debug( "priority is $priority", 1 ); 
    4546 
    4647// Caller ID info is stored in $request in AGI class, passed from Asterisk 
     
    5152// From this point forward, Set KEEPCID in the channel so subsequent calls, CF, etc. retain the incoming 
    5253// CID that get sent down channel local. 
    53 // 
    54 $AGI->set_variable('_KEEPCID','TRUE');             
     54$AGI->set_variable('_KEEPCID','TRUE'); 
    5555 
    5656$timer    = get_var( $AGI, "ARG1" ); 
     
    5858$rgmethod = get_var( $AGI, "RingGroupMethod" ); 
    5959 
    60 $use_confirmation = get_var( $AGI, "USE_CONFIRMATION" ); 
    61 $ringgroup_index  = get_var( $AGI, "RINGGROUP_INDEX" ); 
     60$use_confirmation  = get_var( $AGI, "USE_CONFIRMATION" ); 
     61$ringgroup_index = get_var( $AGI, "RINGGROUP_INDEX" ); 
    6262 
    6363if (empty($timer))  $timer    = 0; 
     
    6565if (empty($rgmethod)) $rgmethod = "none"; 
    6666 
    67 if (empty($use_confirmation)) $use_confirmation  = "FALSE"; 
     67if (empty($use_confirmation)) $use_confirmation = "FALSE"; 
    6868 
    6969debug("Methodology of ring is  '$rgmethod'", 1); 
    70  
    7170debug("USE_CONFIRMATION:  '$use_confirmation'", 4); 
    7271debug("RINGGROUP_INDEX:   '$ringgroup_index'", 4); 
     
    7574// master mode. 
    7675 
    77 if ($rgmethod == "ringall-prim")  
    78 
    79   $rgmethod = "ringall"; 
    80   $mastermode = 1; 
    81 } elseif ($rgmethod == "hunt-prim")  
    82 
    83   $rgmethod = "hunt"; 
    84   $mastermode = 1; 
    85 } elseif ($rgmethod == "memoryhunt-prim")  
    86 
    87   $rgmethod = "memoryhunt"; 
    88   $mastermode = 1; 
     76if ($rgmethod == "ringall-prim") { 
     77  $rgmethod = "ringall"; 
     78  $mastermode = 1; 
     79} elseif ($rgmethod == "hunt-prim") { 
     80  $rgmethod = "hunt"; 
     81  $mastermode = 1; 
     82} elseif ($rgmethod == "memoryhunt-prim") { 
     83  $rgmethod = "memoryhunt"; 
     84  $mastermode = 1; 
    8985} else  
    90 
    91   $mastermode = 0; 
    92 
     86  $mastermode = 0; 
    9387 
    9488// call confirmation only works with ringall and ringall-prim. The javascripts in ringgroups 
     
    10296} 
    10397 
    104  
    105  
    10698// Start with Arg Count set to 3 as two args are used 
    10799$arg_cnt = 3; 
    108 while( ($arg = get_var($AGI,"ARG". $arg_cnt))
    109 { 
    110   if ($arg == '-')  
     100while($arg = get_var($AGI,"ARG". $arg_cnt)
     101{ 
     102  if ($arg == '-') 
    111103  {  // not sure why, dialparties will get stuck in a loop if noresponse 
    112104    debug("get_variable got a \"noresponse\"!  Exiting",3); 
     
    137129  $cf  = $AGI->database_get('CF',$k); 
    138130  $cf  = $cf['data']; 
    139   if (strlen($cf))  
     131  if (strlen($cf)) 
    140132  { 
    141133    // append a hash sign so we can send out on chan_local below. 
     
    151143      debug("Primary ext is CF so disabling mastermode if it was set", 4); 
    152144    } 
    153   }  
    154   else  
    155   { 
     145  } 
     146  else 
    156147    debug("Extension $k cf is disabled", 3); 
    157   } 
    158148  $count++; 
    159149} 
     
    163153// sort of flag that says master mode DND so skip everything else below (set them all to ""). 
    164154// 
    165  
    166155 
    167156// Hacky. 
     
    170159// Now check for DND 
    171160foreach ( $ext as $k ) 
    172 
    173   //if ( !preg_match($k, "/\#/", $matches) ) 
     161{ //if ( !preg_match($k, "/\#/", $matches) ) 
    174162  if ( (strpos($k,"#")==0) ) 
    175   {    
     163  { 
    176164    // no point in doing if cf is enabled 
    177165    $dnd = $AGI->database_get('DND',$k); 
     
    191179      } 
    192180    }  
    193     else  
    194     { 
     181    else 
    195182      debug("Extension $k do not disturb is disabled", 3); 
    196     } 
    197183  } 
    198184  $count++; 
     
    200186 
    201187// Main calling loop 
    202  
    203188$skipremaining = 0; // used to allow primary to ring but skip the rest 
    204189 
     
    217202  // if dnd was set on the primary then dndprimary will already be set resulting in a completly blanked out list 
    218203  // since dnd on the primary means don't bother me on any. 
    219   // 
    220   // 
    221   // 
    222204 
    223205  // Don't bother checking these if we will be blanking the extnum anyhow 
    224   // 
    225206  if ($skipremaining == 1) 
    226207  { 
     
    229210  if ($dndprimary == 0) 
    230211  { 
     212    // TODO what are these comments...? do we need to remove them...? 
    231213    $extnum    = $k; 
    232214    $exthascw  = $AGI->database_get('CW', $extnum);// ? 1 : 0; 
     
    251233    // above. If CF unconditional was set, we never get here because we alread reset mastermode. If DND 
    252234    // were set then we never get here becasue didprimary was set 
    253  
    254235    if ($mastermode == 1) 
    255236    { 
     
    275256      // should not be effected 
    276257    } 
    277  
    278   } 
    279  
    280   // clear the current extension if dndprimary has been set. This will only be the case if in mastermode so no need to check 
    281   // that. Use this to skip remaining extensions also if just ringing the primary. 
    282   // 
     258  } // end if ($dndprimary == 0) 
    283259  else // $dndprimary == 1 so clear the extension 
    284260  { 
     261    // clear the current extension if dndprimary has been set. This will only be the case if in mastermode so no need to check 
     262    // that. Use this to skip remaining extensions also if just ringing the primary. 
    285263    $extnum = ''; 
    286264  } 
    287265 
    288266  // if CF is not in use or $dndprimary is set so $extnum has been cleared and nothing to do 
    289   // 
    290267  if ( (strpos($k,"#")==0) || $dndprimary == 1) 
    291268  { 
     
    306283            $extnum = $extcfu . '#';   # same method as the normal cf, i.e. send to Local 
    307284        } 
    308         else  
     285        else 
    309286        { 
    310287          debug("Extension $extnum has call forward on no answer set and is unavailable",1); 
     
    313290        } 
    314291      } 
    315       elseif ( ($exthascw == 0) || ($exthascfb == 1) )  
    316       {   
     292      elseif ( ($exthascw == 0) || ($exthascfb == 1) ) 
     293      { 
    317294        debug("Checking CW and CFB status for extension $extnum",3); 
    318295       
     
    326303            $extnum = $extcfb . '#';   # same method as the normal cf, i.e. send to Local 
    327304          } 
    328           else 
     305          elseif ($exthascw == 0)  
     306          { // CW not in use 
     307            debug("Extension $extnum has call waiting disabled",1); 
     308            $extnum = ''; 
     309            $AGI->set_variable('DIALSTATUS','BUSY');             
     310          }  
     311          else  
    329312          { 
    330             if ( ($extstate == 4) ) // Unavailable so CW options a bit pointless! 
    331             { 
    332               debug("Extension $extnum is Unavailable",1); 
    333               $extnum = ''; 
    334               $AGI->set_variable('DIALSTATUS','CHANUNAVAIL');              
    335             } 
    336             elseif ($exthascw == 0)  
    337             { // CW not in use 
    338               debug("Extension $extnum has call waiting disabled",1); 
    339               $extnum = ''; 
    340               $AGI->set_variable('DIALSTATUS','BUSY');             
    341             }  
    342             else  
    343             { 
    344               debug("Extension $extnum has call waiting enabled",1); 
    345             } 
     313            debug("Extension $extnum has call waiting enabled",1); 
    346314          } 
    347315        } 
     
    351319        debug("ExtensionState for $extnum could not be read...assuming ok",3); 
    352320      }  
    353       else  
     321      else 
    354322      { 
    355323        debug("Extension $extnum is available",1); 
     
    382350          if ($rc['result'] == 1)  
    383351          { 
    384             debug("DbSet CALLTRACE/$k to $cidnum", 3); 
    385           }  
    386           else  
     352            debug("dbset CALLTRACE/$k to $cidnum", 3); 
     353          } 
     354          else 
    387355          { 
    388356            debug("Failed to DbSet CALLTRACE/$k to $cidnum ({$rc['result']})", 1); 
    389357          } 
    390         }  
    391         else  
     358        } 
     359        else 
    392360        { 
    393361          // We don't care about retval, this key may not exist 
     
    402370    } 
    403371  } 
    404 } // endforeach 
    405  
    406 $dshunt =''; 
    407 $loops=0; 
    408 $myhuntmember=""; 
    409 if (($rgmethod == "hunt") || ($rgmethod == "memoryhunt"))  
    410 
    411   if ($cidnum)  
     372} // end foreach ( $ext as $k ) 
     373 
     374$dshunt   = ''; 
     375$loops    = 0; 
     376$myhuntmember = ""; 
     377 
     378if (($rgmethod == "hunt") || ($rgmethod == "memoryhunt")) 
     379
     380  if ($cidnum) 
    412381    $AGI->set_variable(CALLTRACE_HUNT,$cidnum); 
    413382     
    414383  foreach ($extarray as $k ) 
    415   {  
     384  { 
    416385    // we loop through the original array to get the extensions in order of importance 
    417     if ($ext_hunt[$k])  
     386    if ($ext_hunt[$k]) 
    418387    { 
    419388      //If the original array is included in the extension hash then set variables 
    420389      $myhuntmember="HuntMember"."$loops"; 
    421       if ($rgmethod == "hunt")  
    422       { 
     390      if ($rgmethod == "hunt") 
    423391        $AGI->set_variable($myhuntmember,$ext_hunt[$k]); 
    424       }  
    425392      elseif ($rgmethod == "memoryhunt")  
    426393      { 
    427394        if ($loops==0)  
    428         { 
    429395          $dshunt =$ext_hunt[$k]; 
    430         }  
    431         else  
    432         { 
     396        else 
    433397          $dshunt .='&'.$ext_hunt[$k]; 
    434         } 
    435398        $AGI->set_variable($myhuntmember,$dshunt); 
    436399      } 
     
    440403} 
    441404 
    442 // chop $ds if length($ds); - removes trailing "&" 
    443405$ds = chop($ds," &"); 
    444406 
    445 if (!strlen($ds))  
     407if (!strlen($ds)) 
    446408{ 
    447409  $AGI->noop(''); 
     
    456418    $AGI->set_variable("HuntMembers",$loops); 
    457419    $AGI->set_priority(20); // dial command is at priority 20 where dialplan handles calling a ringgroup with strategy of "hunt" or "MemoryHunt" 
    458   }  
     420  } 
    459421  else 
    460422  { 
     
    464426      $ds .= $timer; 
    465427      if (trim($use_confirmation) != "FALSE") 
    466       { 
    467428        $AGI->set_variable('__RT',$timer); 
    468       } 
    469429    } 
    470430    $ds .= '|' . $dialopts; // pound to transfer, provide ringing 
    471431    if (trim($use_confirmation) != "FALSE") 
    472     { 
    473432      $AGI->set_variable('__RG_IDX',$ringgroup_index); 
    474     } 
    475433    $AGI->set_variable('ds',$ds); 
    476434    $AGI->set_priority(10); // dial command is at priority 10 
     
    481439exit( 0 ); 
    482440 
    483  
    484441// helper functions 
    485  
    486442function get_var( $agi, $value) 
    487443{ 
     
    501457  $dialstring = ''; 
    502458   
    503 //  if ($extnum =~ s/#//) 
    504   if (strpos($extnum,'#') != 0) 
    505   {                        
     459  if (strpos($extnum,'#') != 0) 
     460  { 
    506461    // "#" used to identify external numbers in forwards and callgourps 
    507462    // If using call confirmation, need to put the # back into the new dialstring 
     
    517472      $dialstring = 'Local/RG-'.$ringgroup_index.'-'.$extnum.'#@grps'; 
    518473    debug("Built External dialstring component for $extnum: $dialstring", 4); 
    519   }  
    520   else  
     474  } 
     475  else 
    521476  { 
    522477    $device_str = sprintf("%s/device", $extnum); 
     
    556511 
    557512function is_ext_avail( $extnum ) 
    558 {   
     513{ 
    559514  global $config; 
    560515     
     
    579534  $matches = array(); 
    580535  $matchpattern = '/^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/'; 
    581   foreach ($file as $line)  
     536  foreach ($file as $line) 
    582537  { 
    583538    if (preg_match($matchpattern, $line, $matches))