Changeset 2763
- Timestamp:
- 10/18/06 05:58:23 (7 years ago)
- Files:
-
- freepbx/trunk/amp_conf/agi-bin/dialparties.agi (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
freepbx/trunk/amp_conf/agi-bin/dialparties.agi
r2666 r2763 1 1 #!/usr/bin/php -q 2 2 <?php 3 // 3 4 4 // Copyright (C) 2003 Zac Sprackett <zsprackett-asterisk@sprackett.com> 5 5 // … … 18 18 // info@coalescentsystems.ca 19 19 // 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 21 22 22 23 $config = parse_amportal_conf( "/etc/amportal.conf" ); … … 27 28 $debug = 4; 28 29 29 $ext ="";// Hash that will contain our list of extensions to call30 $ext_hunt ="";// Hash that will contain our list of extensions to call used by huntgroup31 $cidnum ="";// Caller ID Number for this call32 $cidname ="";// Caller ID Name for this call33 $timer ="";// Call timer for Dial command34 $dialopts ="";// options for dialing35 $rc ="";// Catch return code36 $priority ="";// Next priority37 $rgmethod ="";// If Ring Group what ringing method was chosen38 $dsarray = array();// This will hold all the dial strings, used to check for duplicate extensions30 $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 39 40 40 41 $AGI = new AGI(); 41 debug("Starting New Dialparties.agi", 0);42 debug("Starting New Dialparties.agi", 1); 42 43 43 44 $priority = get_var( $AGI, "priority" ) + 1; 44 debug( "priority is $priority" );45 debug( "priority is $priority", 1 ); 45 46 46 47 // Caller ID info is stored in $request in AGI class, passed from Asterisk … … 51 52 // From this point forward, Set KEEPCID in the channel so subsequent calls, CF, etc. retain the incoming 52 53 // CID that get sent down channel local. 53 // 54 $AGI->set_variable('_KEEPCID','TRUE'); 54 $AGI->set_variable('_KEEPCID','TRUE'); 55 55 56 56 $timer = get_var( $AGI, "ARG1" ); … … 58 58 $rgmethod = get_var( $AGI, "RingGroupMethod" ); 59 59 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" ); 62 62 63 63 if (empty($timer)) $timer = 0; … … 65 65 if (empty($rgmethod)) $rgmethod = "none"; 66 66 67 if (empty($use_confirmation)) $use_confirmation = "FALSE";67 if (empty($use_confirmation)) $use_confirmation = "FALSE"; 68 68 69 69 debug("Methodology of ring is '$rgmethod'", 1); 70 71 70 debug("USE_CONFIRMATION: '$use_confirmation'", 4); 72 71 debug("RINGGROUP_INDEX: '$ringgroup_index'", 4); … … 75 74 // master mode. 76 75 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; 76 if ($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; 89 85 } else 90 { 91 $mastermode = 0; 92 } 86 $mastermode = 0; 93 87 94 88 // call confirmation only works with ringall and ringall-prim. The javascripts in ringgroups … … 102 96 } 103 97 104 105 106 98 // Start with Arg Count set to 3 as two args are used 107 99 $arg_cnt = 3; 108 while( ($arg = get_var($AGI,"ARG". $arg_cnt)))109 { 110 if ($arg == '-') 100 while($arg = get_var($AGI,"ARG". $arg_cnt)) 101 { 102 if ($arg == '-') 111 103 { // not sure why, dialparties will get stuck in a loop if noresponse 112 104 debug("get_variable got a \"noresponse\"! Exiting",3); … … 137 129 $cf = $AGI->database_get('CF',$k); 138 130 $cf = $cf['data']; 139 if (strlen($cf)) 131 if (strlen($cf)) 140 132 { 141 133 // append a hash sign so we can send out on chan_local below. … … 151 143 debug("Primary ext is CF so disabling mastermode if it was set", 4); 152 144 } 153 } 154 else 155 { 145 } 146 else 156 147 debug("Extension $k cf is disabled", 3); 157 }158 148 $count++; 159 149 } … … 163 153 // sort of flag that says master mode DND so skip everything else below (set them all to ""). 164 154 // 165 166 155 167 156 // Hacky. … … 170 159 // Now check for DND 171 160 foreach ( $ext as $k ) 172 { 173 //if ( !preg_match($k, "/\#/", $matches) ) 161 { //if ( !preg_match($k, "/\#/", $matches) ) 174 162 if ( (strpos($k,"#")==0) ) 175 { 163 { 176 164 // no point in doing if cf is enabled 177 165 $dnd = $AGI->database_get('DND',$k); … … 191 179 } 192 180 } 193 else 194 { 181 else 195 182 debug("Extension $k do not disturb is disabled", 3); 196 }197 183 } 198 184 $count++; … … 200 186 201 187 // Main calling loop 202 203 188 $skipremaining = 0; // used to allow primary to ring but skip the rest 204 189 … … 217 202 // if dnd was set on the primary then dndprimary will already be set resulting in a completly blanked out list 218 203 // since dnd on the primary means don't bother me on any. 219 //220 //221 //222 204 223 205 // Don't bother checking these if we will be blanking the extnum anyhow 224 //225 206 if ($skipremaining == 1) 226 207 { … … 229 210 if ($dndprimary == 0) 230 211 { 212 // TODO what are these comments...? do we need to remove them...? 231 213 $extnum = $k; 232 214 $exthascw = $AGI->database_get('CW', $extnum);// ? 1 : 0; … … 251 233 // above. If CF unconditional was set, we never get here because we alread reset mastermode. If DND 252 234 // were set then we never get here becasue didprimary was set 253 254 235 if ($mastermode == 1) 255 236 { … … 275 256 // should not be effected 276 257 } 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) 283 259 else // $dndprimary == 1 so clear the extension 284 260 { 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. 285 263 $extnum = ''; 286 264 } 287 265 288 266 // if CF is not in use or $dndprimary is set so $extnum has been cleared and nothing to do 289 //290 267 if ( (strpos($k,"#")==0) || $dndprimary == 1) 291 268 { … … 306 283 $extnum = $extcfu . '#'; # same method as the normal cf, i.e. send to Local 307 284 } 308 else 285 else 309 286 { 310 287 debug("Extension $extnum has call forward on no answer set and is unavailable",1); … … 313 290 } 314 291 } 315 elseif ( ($exthascw == 0) || ($exthascfb == 1) ) 316 { 292 elseif ( ($exthascw == 0) || ($exthascfb == 1) ) 293 { 317 294 debug("Checking CW and CFB status for extension $extnum",3); 318 295 … … 326 303 $extnum = $extcfb . '#'; # same method as the normal cf, i.e. send to Local 327 304 } 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 329 312 { 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); 346 314 } 347 315 } … … 351 319 debug("ExtensionState for $extnum could not be read...assuming ok",3); 352 320 } 353 else 321 else 354 322 { 355 323 debug("Extension $extnum is available",1); … … 382 350 if ($rc['result'] == 1) 383 351 { 384 debug(" DbSet CALLTRACE/$k to $cidnum", 3);385 } 386 else 352 debug("dbset CALLTRACE/$k to $cidnum", 3); 353 } 354 else 387 355 { 388 356 debug("Failed to DbSet CALLTRACE/$k to $cidnum ({$rc['result']})", 1); 389 357 } 390 } 391 else 358 } 359 else 392 360 { 393 361 // We don't care about retval, this key may not exist … … 402 370 } 403 371 } 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 378 if (($rgmethod == "hunt") || ($rgmethod == "memoryhunt")) 379 { 380 if ($cidnum) 412 381 $AGI->set_variable(CALLTRACE_HUNT,$cidnum); 413 382 414 383 foreach ($extarray as $k ) 415 { 384 { 416 385 // we loop through the original array to get the extensions in order of importance 417 if ($ext_hunt[$k]) 386 if ($ext_hunt[$k]) 418 387 { 419 388 //If the original array is included in the extension hash then set variables 420 389 $myhuntmember="HuntMember"."$loops"; 421 if ($rgmethod == "hunt") 422 { 390 if ($rgmethod == "hunt") 423 391 $AGI->set_variable($myhuntmember,$ext_hunt[$k]); 424 }425 392 elseif ($rgmethod == "memoryhunt") 426 393 { 427 394 if ($loops==0) 428 {429 395 $dshunt =$ext_hunt[$k]; 430 } 431 else 432 { 396 else 433 397 $dshunt .='&'.$ext_hunt[$k]; 434 }435 398 $AGI->set_variable($myhuntmember,$dshunt); 436 399 } … … 440 403 } 441 404 442 // chop $ds if length($ds); - removes trailing "&"443 405 $ds = chop($ds," &"); 444 406 445 if (!strlen($ds)) 407 if (!strlen($ds)) 446 408 { 447 409 $AGI->noop(''); … … 456 418 $AGI->set_variable("HuntMembers",$loops); 457 419 $AGI->set_priority(20); // dial command is at priority 20 where dialplan handles calling a ringgroup with strategy of "hunt" or "MemoryHunt" 458 } 420 } 459 421 else 460 422 { … … 464 426 $ds .= $timer; 465 427 if (trim($use_confirmation) != "FALSE") 466 {467 428 $AGI->set_variable('__RT',$timer); 468 }469 429 } 470 430 $ds .= '|' . $dialopts; // pound to transfer, provide ringing 471 431 if (trim($use_confirmation) != "FALSE") 472 {473 432 $AGI->set_variable('__RG_IDX',$ringgroup_index); 474 }475 433 $AGI->set_variable('ds',$ds); 476 434 $AGI->set_priority(10); // dial command is at priority 10 … … 481 439 exit( 0 ); 482 440 483 484 441 // helper functions 485 486 442 function get_var( $agi, $value) 487 443 { … … 501 457 $dialstring = ''; 502 458 503 // if ($extnum =~ s/#//) 504 if (strpos($extnum,'#') != 0) 505 { 459 if (strpos($extnum,'#') != 0) 460 { 506 461 // "#" used to identify external numbers in forwards and callgourps 507 462 // If using call confirmation, need to put the # back into the new dialstring … … 517 472 $dialstring = 'Local/RG-'.$ringgroup_index.'-'.$extnum.'#@grps'; 518 473 debug("Built External dialstring component for $extnum: $dialstring", 4); 519 } 520 else 474 } 475 else 521 476 { 522 477 $device_str = sprintf("%s/device", $extnum); … … 556 511 557 512 function is_ext_avail( $extnum ) 558 { 513 { 559 514 global $config; 560 515 … … 579 534 $matches = array(); 580 535 $matchpattern = '/^\s*([a-zA-Z0-9]+)\s*=\s*(.*)\s*([;#].*)?/'; 581 foreach ($file as $line) 536 foreach ($file as $line) 582 537 { 583 538 if (preg_match($matchpattern, $line, $matches))
