| | 496 | /** check if a specific extension is being used, or get a list of all extensions that are being used |
|---|
| | 497 | * @param mixed an array of extension numbers to check against, or if boolean true then return list of all extensions |
|---|
| | 498 | * @return array returns an empty array if exten not in use, or any array with usage info, or of all usage |
|---|
| | 499 | * if exten is boolean true |
|---|
| | 500 | * @description Upon passing in an array of extension numbers, this api will query all modules to determine if any |
|---|
| | 501 | * are using those extension numbers. If so, it will return an array with the usage information |
|---|
| | 502 | * as described below, otherwise an empty array. If passed boolean true, it will return an array |
|---|
| | 503 | * of the same format with all extensions on the system that are being used. |
|---|
| | 504 | * |
|---|
| | 505 | * $exten_usage[$module][$exten]['description'] // description of the extension |
|---|
| | 506 | * ['edit_url'] // a url that could be invoked to edit extension |
|---|
| | 507 | * ['status'] // Status: INUSE, RESERVED, RESTRICTED |
|---|
| | 508 | */ |
|---|
| | 509 | function framework_check_extension_usage($exten=true) { |
|---|
| | 510 | global $active_modules; |
|---|
| | 511 | $exten_usage = array(); |
|---|
| | 512 | |
|---|
| | 513 | if (!is_array($exten) && $exten !== true) { |
|---|
| | 514 | $exten = array($exten); |
|---|
| | 515 | } |
|---|
| | 516 | foreach(array_keys($active_modules) as $mod) { |
|---|
| | 517 | $function = $mod."_check_extensions"; |
|---|
| | 518 | if (function_exists($function)) { |
|---|
| | 519 | $module_usage = $function($exten); |
|---|
| | 520 | if (!empty($module_usage)) { |
|---|
| | 521 | $exten_usage[$mod] = $module_usage; |
|---|
| | 522 | } |
|---|
| | 523 | } |
|---|
| | 524 | } |
|---|
| | 525 | if ($exten === true) { |
|---|
| | 526 | return $exten_usage; |
|---|
| | 527 | } else { |
|---|
| | 528 | foreach (array_keys($exten_usage) as $mod) { |
|---|
| | 529 | foreach ($exten as $test_exten) { |
|---|
| | 530 | if (isset($exten_usage[$mod][$test_exten])) { |
|---|
| | 531 | $exten_matches[$mod][$test_exten] = $exten_usage[$mod][$test_exten]; |
|---|
| | 532 | } |
|---|
| | 533 | } |
|---|
| | 534 | } |
|---|
| | 535 | } |
|---|
| | 536 | return $exten_matches; |
|---|
| | 537 | } |
|---|
| | 538 | |
|---|
| | 539 | /** check if a specific destination is being used, or get a list of all destinations that are being used |
|---|
| | 540 | * @param mixed an array of destinations to check against, or if boolean true then return list of all destinations in use |
|---|
| | 541 | * @return array returns an empty array if destination not in use, or any array with usage info, or of all usage |
|---|
| | 542 | * if dest is boolean true |
|---|
| | 543 | * @description Upon passing in an array of destinations, this api will query all modules to determine if any |
|---|
| | 544 | * are using that destination. If so, it will return an array with the usage information |
|---|
| | 545 | * as described below, otherwise an empty array. If passed boolean true, it will return an array |
|---|
| | 546 | * of the same format with all destinations on the system that are being used. |
|---|
| | 547 | * |
|---|
| | 548 | * $dest_usage[$module][]['dest'] // The destination being used |
|---|
| | 549 | * ['description'] // Description of who is using it |
|---|
| | 550 | * ['edit_url'] // a url that could be invoked to edit the using entity |
|---|
| | 551 | * |
|---|
| | 552 | */ |
|---|
| | 553 | function framework_check_destination_usage($dest=true) { |
|---|
| | 554 | global $active_modules; |
|---|
| | 555 | $dest_usage = array(); |
|---|
| | 556 | $dest_matches = array(); |
|---|
| | 557 | |
|---|
| | 558 | if (!is_array($dest) && $dest !== true) { |
|---|
| | 559 | $dest = array($dest); |
|---|
| | 560 | } |
|---|
| | 561 | foreach(array_keys($active_modules) as $mod) { |
|---|
| | 562 | $function = $mod."_check_destinations"; |
|---|
| | 563 | if (function_exists($function)) { |
|---|
| | 564 | $module_usage = $function($dest); |
|---|
| | 565 | if (!empty($module_usage)) { |
|---|
| | 566 | $dest_usage[$mod] = $module_usage; |
|---|
| | 567 | } |
|---|
| | 568 | } |
|---|
| | 569 | } |
|---|
| | 570 | if ($dest === true) { |
|---|
| | 571 | return $dest_usage; |
|---|
| | 572 | } else { |
|---|
| | 573 | /* |
|---|
| | 574 | $destlist[] = array( |
|---|
| | 575 | 'dest' => $thisdest, |
|---|
| | 576 | 'description' => 'Annoucement: '.$result['description'], |
|---|
| | 577 | 'edit_url' => 'config.php?display=announcement&type='.$type.'&extdisplay='.urlencode($thisid), |
|---|
| | 578 | ); |
|---|
| | 579 | */ |
|---|
| | 580 | foreach (array_keys($dest_usage) as $mod) { |
|---|
| | 581 | foreach ($dest as $test_dest) { |
|---|
| | 582 | foreach ($dest_usage[$mod] as $dest_item) { |
|---|
| | 583 | if ($dest_item['dest'] == $test_dest) { |
|---|
| | 584 | $dest_matches[$mod][] = $dest_item; |
|---|
| | 585 | } |
|---|
| | 586 | } |
|---|
| | 587 | } |
|---|
| | 588 | } |
|---|
| | 589 | } |
|---|
| | 590 | return $dest_matches; |
|---|
| | 591 | } |
|---|
| | 592 | |
|---|
| | 593 | /** provide optional alert() box and formatted url info for extension conflicts |
|---|
| | 594 | * @param array an array of extensions that are in conflict obtained from framework_check_extension_usage |
|---|
| | 595 | * @param boolean default false. True if url and descriptions should be split, false to combine (see return) |
|---|
| | 596 | * @param boolean default true. True to echo an alert() box, false to bypass the alert box |
|---|
| | 597 | * @return array returns an array of formatted URLs with descriptions. If $split is true, retuns an array |
|---|
| | 598 | * of the URLs with each element an array in the format of array('label' => 'description, 'url' => 'a url') |
|---|
| | 599 | * @description This is used upon detecting conflicting extension numbers to provide an optional alert box of the issue |
|---|
| | 600 | * by a module which should abort the attempt to create the extension. It also returns an array of |
|---|
| | 601 | * URLs that can be displayed by the module to show the conflicting extension(s) and links to edit |
|---|
| | 602 | * them or further interogate. The resulting URLs are returned in an array either formatted for immediate |
|---|
| | 603 | * display or split into a description and the raw URL to provide more fine grained control (or use with guielements). |
|---|
| | 604 | */ |
|---|
| | 605 | function framework_display_extension_usage_alert($usage_arr=array(),$split=false,$alert=true) { |
|---|
| | 606 | global $active_modules; |
|---|
| | 607 | $url = array(); |
|---|
| | 608 | if (!empty($usage_arr)) { |
|---|
| | 609 | $conflicts=0; |
|---|
| | 610 | foreach($usage_arr as $rawmodule => $properties) { |
|---|
| | 611 | //$str .= "Module: ".$active_modules[$rawmodule]['name']." "; |
|---|
| | 612 | foreach($properties as $exten => $details) { |
|---|
| | 613 | $conflicts++; |
|---|
| | 614 | if ($conflicts == 1) { |
|---|
| | 615 | switch ($details['status']) { |
|---|
| | 616 | case 'INUSE': |
|---|
| | 617 | $str = "Extension $exten not available, it is currently used by ".htmlspecialchars($details['description'])."."; |
|---|
| | 618 | if ($split) { |
|---|
| | 619 | $url[] = array('label' => "Edit: ".htmlspecialchars($details['description']), |
|---|
| | 620 | 'url' => $details['edit_url'], |
|---|
| | 621 | ); |
|---|
| | 622 | } else { |
|---|
| | 623 | $url[] = "<a href='".$details['edit_url']."'>Edit: ".htmlspecialchars($details['description'])."</a>"; |
|---|
| | 624 | } |
|---|
| | 625 | break; |
|---|
| | 626 | default: |
|---|
| | 627 | $str = "This extension is not available: ".htmlspecialchars($details['description'])."."; |
|---|
| | 628 | } |
|---|
| | 629 | } else { |
|---|
| | 630 | if ($split) { |
|---|
| | 631 | $url[] = array('label' => "Edit: ".htmlspecialchars($details['description']), |
|---|
| | 632 | 'url' => $details['edit_url'], |
|---|
| | 633 | ); |
|---|
| | 634 | } else { |
|---|
| | 635 | $url[] = "<a href='".$details['edit_url']."'>Edit: ".htmlspecialchars($details['description'])."</a>"; |
|---|
| | 636 | } |
|---|
| | 637 | } |
|---|
| | 638 | } |
|---|
| | 639 | } |
|---|
| | 640 | if ($conflicts > 1) { |
|---|
| | 641 | $str .= sprintf(" There are %s additonal conflicts not listed",$conflicts-1); |
|---|
| | 642 | } |
|---|
| | 643 | } |
|---|
| | 644 | if ($alert) { |
|---|
| | 645 | echo "<script>javascript:alert('$str')</script>"; |
|---|
| | 646 | } |
|---|
| | 647 | return($url); |
|---|
| | 648 | } |
|---|