| 812 | | } |
|---|
| | 812 | |
|---|
| | 813 | /** Show all entries in the asterisk database |
|---|
| | 814 | * @return Array associative array of key=>value |
|---|
| | 815 | */ |
|---|
| | 816 | function database_show() { |
|---|
| | 817 | $r = $this->command("database show"); |
|---|
| | 818 | |
|---|
| | 819 | $data = explode("\n",$r["data"]); |
|---|
| | 820 | $db = array(); |
|---|
| | 821 | |
|---|
| | 822 | foreach ($data as $line) { |
|---|
| | 823 | $temp = explode(":",$line); |
|---|
| | 824 | $db[ trim($temp[0]) ] = trim($temp[1]); |
|---|
| | 825 | } |
|---|
| | 826 | return $db; |
|---|
| | 827 | } |
|---|
| | 828 | |
|---|
| | 829 | /** Add an entry to the asterisk database |
|---|
| | 830 | * @param string $family The family name to use |
|---|
| | 831 | * @param string $key The key name to use |
|---|
| | 832 | * @param mixed $value The value to add |
|---|
| | 833 | * @return bool True if successful |
|---|
| | 834 | */ |
|---|
| | 835 | function database_put($family, $key, $value) { |
|---|
| | 836 | $r = $this->command("database put ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)." ".$value); |
|---|
| | 837 | return (bool)strstr($r["data"], "success"); |
|---|
| | 838 | } |
|---|
| | 839 | |
|---|
| | 840 | /** Get an entry from the asterisk database |
|---|
| | 841 | * @param string $family The family name to use |
|---|
| | 842 | * @param string $key The key name to use |
|---|
| | 843 | * @return mixed Value of the key, or false if error |
|---|
| | 844 | */ |
|---|
| | 845 | function database_get($family, $key) { |
|---|
| | 846 | $r = $this->command("database get ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); |
|---|
| | 847 | if (substr($r["data"],0,6) == "Value:") { |
|---|
| | 848 | return trim(substr($r["data"],6)); |
|---|
| | 849 | } else { |
|---|
| | 850 | return false; |
|---|
| | 851 | } |
|---|
| | 852 | } |
|---|
| | 853 | |
|---|
| | 854 | /** Delete an entry from the asterisk database |
|---|
| | 855 | * @param string $family The family name to use |
|---|
| | 856 | * @param string $key The key name to use |
|---|
| | 857 | * @return bool True if successful |
|---|
| | 858 | */ |
|---|
| | 859 | function database_del($family, $key) { |
|---|
| | 860 | $r = $this->command("database del ".str_replace(" ","/",$family)." ".str_replace(" ","/",$key)); |
|---|
| | 861 | return (bool)strstr($r["data"], "removed"); |
|---|
| | 862 | } |
|---|
| | 863 | |
|---|
| | 864 | } |
|---|