Changeset 2109
- Timestamp:
- 06/28/06 07:35:05 (7 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
freepbx/trunk/amp_conf/htdocs/admin/modules/core/functions.inc.php
r2101 r2109 16 16 foreach ($vmcontexts as $vmcontext) { 17 17 if(isset($uservm[$vmcontext][$extnum])){ 18 //$vmname = $uservm[$vmcontext][$extnum]['name'];19 //$vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>');20 $vmboxes[$extnum] = true;18 //$vmname = $uservm[$vmcontext][$extnum]['name']; 19 //$vmboxes[$extnum] = array($extnum, '"' . $vmname . '" <' . $extnum . '>'); 20 $vmboxes[$extnum] = true; 21 21 } 22 22 } … … 27 27 // core provides both users and voicemail boxes as destinations 28 28 if (isset($results)) { 29 foreach($results as $result) {30 $extens[] = array('destination' => 'ext-local,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>');31 if(isset($vmboxes[$result['0']])) {32 $extens[] = array('destination' => 'ext-local,${VM_PREFIX}'.$result['0'].',1', 'description' => 'voicemail box '.$result['0']);33 }29 foreach($results as $result) { 30 $extens[] = array('destination' => 'ext-local,'.$result['0'].',1', 'description' => $result['1'].' <'.$result['0'].'>'); 31 if(isset($vmboxes[$result['0']])) { 32 $extens[] = array('destination' => 'ext-local,${VM_PREFIX}'.$result['0'].',1', 'description' => 'voicemail box '.$result['0']); 33 } 34 34 } 35 35 } … … 516 516 else 517 517 $vmcontext = $thisUser['voicemail']; 518 518 519 //voicemail symlink 519 520 exec("rm -f /var/spool/asterisk/voicemail/device/".$id); … … 550 551 $deviceuser = $astman->database_get("DEVICE",$account."/user"); 551 552 if (isset($deviceuser) && $deviceuser != "none") { 552 // Remove the device record from the user's device list 553 $userdevices = $astman->database_get("AMPUSER",$deviceuser."/device"); 554 /*$userdevices = str_replace($account."&", "", $userdevices."&"); 555 // If there was more than one device, remove the extra "&" at the end. 556 if (substr($userdevices, -1, 1) == "&") { 557 $userdevices = substr($userdevices, 0, -1); 558 }*/ 559 $userdevicesarr = explode("&", $userdevices); 560 array_splice($userdevicesarr, array_search($account, $userdevicesarr), 1); 561 $userdevices = implode("&", $userdevicesarr); 562 if (empty($userdevices)) { 563 $astman->database_del("AMPUSER",$deviceuser."/device"); 564 } else { 565 $astman->database_put("AMPUSER",$deviceuser."/device",$userdevices); 566 } 553 // Remove the device record from the user's device list 554 $userdevices = $astman->database_get("AMPUSER",$deviceuser."/device"); 555 /*$userdevices = str_replace($account."&", "", $userdevices."&"); 556 557 // If there was more than one device, remove the extra "&" at the end. 558 if (substr($userdevices, -1, 1) == "&") { 559 $userdevices = substr($userdevices, 0, -1); 560 }*/ 561 $userdevicesarr = explode("&", $userdevices); 562 array_splice($userdevicesarr, array_search($account, $userdevicesarr), 1); 563 $userdevices = implode("&", $userdevicesarr); 564 565 if (empty($userdevices)) { 566 $astman->database_del("AMPUSER",$deviceuser."/device"); 567 } else { 568 $astman->database_put("AMPUSER",$deviceuser."/device",$userdevices); 569 } 567 570 } 568 571 $astman->database_del("DEVICE",$account."/dial"); … … 596 599 //take care of sip/iax/zap config 597 600 $funct = "core_devices_get".strtolower($results['tech']); 598 if (!empty($results['tech']) && function_exists($funct)){601 if (!empty($results['tech']) && function_exists($funct)) { 599 602 $devtech = $funct($account); 600 603 if (is_array($devtech)){ … … 617 620 //add details to astdb 618 621 $astman = new AGI_AsteriskManager(); 619 if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { 622 if ($res = $astman->connect("127.0.0.1", $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) { 620 623 $astman->database_deltree("DEVICE"); 621 624 foreach($devresults as $dev) { … … 711 714 die($result->getDebugInfo()."<br><br>".'error adding to SIP table'); 712 715 } 713 714 715 //script to write sip conf file from mysql716 //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_sip_conf_from_mysql.pl';717 //exec($wScript);718 719 716 } 720 717 … … 722 719 global $db; 723 720 global $currentFile; 724 $sql = "DELETE FROM sip WHERE id = '$account'"; 725 $result = $db->query($sql); 726 if(DB::IsError($result)) { 727 die($result->getMessage().$sql); 728 } 729 730 //script to write sip conf file from mysql 731 //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_sip_conf_from_mysql.pl'; 732 //exec($wScript); 733 //script to write op_server.cfg file from mysql 734 //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 735 //exec($wOpScript); 721 722 $sql = "DELETE FROM sip WHERE id = '$account'"; 723 $result = $db->query($sql); 724 725 if(DB::IsError($result)) { 726 die($result->getMessage().$sql); 727 } 736 728 } 737 729 … … 743 735 $results = null; 744 736 } 737 745 738 return $results; 746 739 } … … 750 743 global $db; 751 744 global $currentFile; 745 752 746 $iaxfields = array(array($account,'account',$account), 753 747 array($account,'secret',($_REQUEST['secret'])?$_REQUEST['secret']:''), … … 771 765 if(DB::IsError($result)) { 772 766 die($result->getMessage()."<br><br>error adding to IAX table"); 773 } 774 775 776 //script to write iax2 conf file from mysql 777 //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_iax_conf_from_mysql.pl'; 778 //exec($wScript); 779 //script to write op_server.cfg file from mysql 780 //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 781 //exec($wOpScript); 767 } 782 768 } 783 769 … … 785 771 global $db; 786 772 global $currentFile; 787 $sql = "DELETE FROM iax WHERE id = '$account'"; 788 $result = $db->query($sql); 789 if(DB::IsError($result)) { 790 die($result->getMessage().$sql); 791 } 792 793 //script to write iax2 conf file from mysql 794 //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_iax_conf_from_mysql.pl'; 795 //exec($wScript); 796 //script to write op_server.cfg file from mysql 797 //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 798 //exec($wOpScript); 773 774 $sql = "DELETE FROM iax WHERE id = '$account'"; 775 $result = $db->query($sql); 776 777 if(DB::IsError($result)) { 778 die($result->getMessage().$sql); 779 } 799 780 } 800 781 … … 806 787 $results = null; 807 788 } 789 808 790 return $results; 809 791 } … … 812 794 global $db; 813 795 global $currentFile; 796 814 797 $zapfields = array( 815 798 array($account,'account',$account), … … 833 816 if(DB::IsError($result)) { 834 817 die($result->getMessage()."<br><br>error adding to ZAP table"); 835 } 836 837 838 //script to write zap conf file from mysql 839 //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_zap_conf_from_mysql.pl'; 840 //exec($wScript); 841 //script to write op_server.cfg file from mysql 842 //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 843 //exec($wOpScript); 818 } 844 819 } 845 820 … … 847 822 global $db; 848 823 global $currentFile; 849 $sql = "DELETE FROM zap WHERE id = '$account'"; 850 $result = $db->query($sql); 851 if(DB::IsError($result)) { 852 die($result->getMessage().$sql); 853 } 854 855 //script to write zap conf file from mysql 856 //$wScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_zap_conf_from_mysql.pl'; 857 //exec($wScript); 858 //script to write op_server.cfg file from mysql 859 //$wOpScript = rtrim($_SERVER['SCRIPT_FILENAME'],$currentFile).'retrieve_op_conf_from_mysql.pl'; 860 //exec($wOpScript); 824 825 $sql = "DELETE FROM zap WHERE id = '$account'"; 826 $result = $db->query($sql); 827 if(DB::IsError($result)) { 828 die($result->getMessage().$sql); 829 } 861 830 } 862 831 … … 917 886 } 918 887 } 888 919 889 if (isset($extens)) { 920 890 sort($extens); … … 1044 1014 $vmoption = explode("=",$delete); 1045 1015 $vmoptions[$vmoption[0]] = $vmoption[1]; 1016 1046 1017 $uservm[$vmcontext][$extension] = array( 1047 'mailbox' => $extension, 1048 'pwd' => $vmpwd, 1049 'name' => $name, 1050 'email' => $email, 1051 'pager' => $pager, 1052 'options' => $vmoptions); 1018 'mailbox' => $extension, 1019 'pwd' => $vmpwd, 1020 'name' => $name, 1021 'email' => $email, 1022 'pager' => $pager, 1023 'options' => $vmoptions 1024 ); 1053 1025 } 1054 1026 saveVoicemail($uservm); … … 1061 1033 $results = $db->getRow($sql,DB_FETCHMODE_ASSOC); 1062 1034 if(DB::IsError($results)) { 1063 die($results->getMessage().$sql); 1064 } 1035 die($results->getMessage().$sql); 1036 } 1037 1065 1038 //explode recording vars 1066 1039 $recording = explode("|",$results['recording']); … … 1081 1054 $results = $db->query($sql); 1082 1055 if(DB::IsError($results)) { 1083 die($results->getMessage().$sql);1056 die($results->getMessage().$sql); 1084 1057 } 1085 1058 … … 1103 1076 unset($uservm[$incontext][$extension]); 1104 1077 saveVoicemail($uservm); 1078 1105 1079 /* 1106 1080 //delete the extension info from extensions table … … 1316 1290 { 1317 1291 // TODO: sqlite work arround - diego 1292 // need to reorder the trunks in PHP code 1318 1293 $unique_trunks = sql("SELECT * FROM globals WHERE variable LIKE 'OUT_%' ORDER BY variable","getAll"); 1319 1294 } … … 1673 1648 $routepriority = array_values($routepriority); // resequence our numbers 1674 1649 $counter=0; 1675 foreach ($routepriority as $tresult) 1676 { 1650 foreach ($routepriority as $tresult) { 1677 1651 $order=core_routing_setroutepriorityvalue($counter++); 1678 1652 $sql = sprintf("Update extensions set context='outrt-%s-%s' WHERE context='outrt-%s'",$order,substr($tresult[0],4), $tresult[0]); … … 1682 1656 } 1683 1657 } 1658 1684 1659 // Delete and readd the outbound-allroutes entries 1685 1660 $sql = "delete from extensions WHERE context='outbound-allroutes'"; … … 1688 1663 die($result->getMessage().$sql); 1689 1664 } 1665 1690 1666 $sql = "SELECT DISTINCT context FROM extensions WHERE context like 'outrt-%' ORDER BY context"; 1691 1667 $results = $db->getAll($sql); … … 1711 1687 } 1712 1688 } 1689 1713 1690 $sql = "SELECT DISTINCT SUBSTRING(context,7) FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context "; 1714 1691 // we SUBSTRING() to remove "outrt-" 1715 1692 $routepriority = $db->getAll($sql); 1716 if(DB::IsError($routepriority)) 1717 { 1693 if(DB::IsError($routepriority)) { 1718 1694 die($routepriority->getMessage()); 1719 1695 } … … 1751 1727 } 1752 1728 1753 if ($method=="new") 1754 { 1755 $sql="select DISTINCT context FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context"; 1756 $routepriority = $db->getAll($sql); 1757 if(DB::IsError($result)) { 1758 die($result->getMessage()); 1759 } 1760 $order=core_routing_setroutepriorityvalue(count($routepriority)); 1761 $name = sprintf ("%s-%s",$order,$name); 1729 if ($method=="new") { 1730 $sql="select DISTINCT context FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context"; 1731 $routepriority = $db->getAll($sql); 1732 if(DB::IsError($result)) { 1733 die($result->getMessage()); 1734 } 1735 $order=core_routing_setroutepriorityvalue(count($routepriority)); 1736 $name = sprintf ("%s-%s",$order,$name); 1762 1737 } 1763 1738 $trunks = array_values($trunks); // probably already done, but it's important for our dialplan … … 1765 1740 1766 1741 foreach ($patterns as $pattern) { 1767 1768 1742 if (false !== ($pos = strpos($pattern,"|"))) { 1769 1743 // we have a | meaning to not pass the digits on … … 1786 1760 // 1st priority is emergency dialing variable (if set) 1787 1761 if(!empty($emergency)) { 1788 $startpriority = 1;1789 $sql = "INSERT INTO extensions (context, extension, priority, application, args, descr) VALUES ";1790 $sql .= "('outrt-".$name."', ";1791 $sql .= "'".$pattern."', ";1792 $sql .= "'".$startpriority."', ";1793 $sql .= "'SetVar', ";1794 $sql .= "'EMERGENCYROUTE=YES', ";1795 $sql .= "'Use Emergency CID for device')";1796 $result = $db->query($sql);1797 if(DB::IsError($result)) {1798 die($result->getMessage());1799 }1762 $startpriority = 1; 1763 $sql = "INSERT INTO extensions (context, extension, priority, application, args, descr) VALUES "; 1764 $sql .= "('outrt-".$name."', "; 1765 $sql .= "'".$pattern."', "; 1766 $sql .= "'".$startpriority."', "; 1767 $sql .= "'SetVar', "; 1768 $sql .= "'EMERGENCYROUTE=YES', "; 1769 $sql .= "'Use Emergency CID for device')"; 1770 $result = $db->query($sql); 1771 if(DB::IsError($result)) { 1772 die($result->getMessage()); 1773 } 1800 1774 } else { 1801 $startpriority = 0;1775 $startpriority = 0; 1802 1776 } 1803 1777 … … 2000 1974 $password = ""; 2001 1975 } 1976 2002 1977 return $password; 2003 2004 1978 } 2005 1979 2006 1980 //get emergency state for this route 2007 1981 function core_routing_getrouteemergency($route) { 2008 global $db; 2009 $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'EMERGENCYROUTE%') "; 2010 $results = $db->getOne($sql); 2011 if(DB::IsError($results)) { 2012 die($results->getMessage()); 2013 } 2014 if (preg_match('/^.*=(.*)/', $results, $matches)) { 2015 $emergency = $matches[1]; 2016 } else { 2017 $emergency = ""; 2018 } 2019 return $emergency; 1982 global $db; 1983 $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'EMERGENCYROUTE%') "; 1984 $results = $db->getOne($sql); 1985 if(DB::IsError($results)) { 1986 die($results->getMessage()); 1987 } 1988 if (preg_match('/^.*=(.*)/', $results, $matches)) { 1989 $emergency = $matches[1]; 1990 } else { 1991 $emergency = ""; 1992 } 1993 1994 return $emergency; 2020 1995 } 2021 1996
