Commit | Line | Data |
---|---|---|
9b926efe S |
1 | <?php |
2 | /** | |
3 | * @author Jan Altensen (Stricted) | |
4 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
5 | * @copyright 2015 Jan Altensen (Stricted) | |
6 | */ | |
7 | trait Phone { | |
8 | /** | |
9 | * get phone book entrys | |
10 | * | |
11 | * @return array | |
12 | */ | |
13 | public function getPhoneBookEntrys () { | |
14 | $data = $this->getData('PhoneBook'); | |
15 | $data = $this->getValues($data); | |
16 | ||
17 | if (isset($data['addbookentry'])) { | |
18 | return $data['addbookentry']; | |
19 | } | |
20 | else { | |
21 | return array(); | |
22 | } | |
23 | } | |
24 | ||
25 | /** | |
26 | * add Phone Book Entry | |
27 | * | |
28 | * @param string $name | |
29 | * @param string $firstname | |
30 | * @param string $private | |
31 | * @param string $work | |
32 | * @param string $mobile | |
33 | * @param integer $id | |
34 | * | |
35 | * @return array | |
36 | */ | |
37 | public function addPhoneBookEntry ($name, $firstname, $private, $work, $mobile, $id = -1) { | |
38 | $this->checkLogin(); | |
39 | ||
40 | $path = 'data/PhoneBook.json'; | |
e559c2bb | 41 | $fields = array('csrf_token' => $this->token, |
9b926efe S |
42 | 'id' => $id, |
43 | 'search' => '', | |
44 | 'phonebook_name' => $name, | |
45 | 'phonebook_vorname' => $firstname, | |
46 | 'phonebook_number_p' => $private, | |
47 | 'phonebook_number_a' => $work, | |
48 | 'phonebook_number_m' => $mobile | |
49 | ); | |
50 | ||
51 | $data = $this->sentRequest($path, $fields, true); | |
52 | $data = $this->getValues($data['body']); | |
53 | ||
54 | if ($data['status'] == 'ok') { | |
55 | return $data; | |
56 | } | |
57 | else { | |
58 | throw new RouterException('can not add/edit Phone Book Entry'); | |
59 | } | |
60 | } | |
61 | ||
62 | /** | |
63 | * edit Phone Book Entry | |
64 | * | |
65 | * @param integer $id | |
66 | * @param string $name | |
67 | * @param string $firstname | |
68 | * @param string $private | |
69 | * @param string $work | |
70 | * @param string $mobile | |
71 | * | |
72 | * @return array | |
73 | */ | |
74 | public function changePhoneBookEntry ($id, $name, $firstname, $private, $work, $mobile) { | |
75 | return $this->addPhoneBookEntry($name, $firstname, $private, $work, $private, $id); | |
76 | } | |
77 | ||
78 | /** | |
79 | * delete Phone Book Entry | |
80 | * | |
81 | * @param integer $id | |
82 | * | |
83 | * @return array | |
84 | */ | |
85 | public function deletePhoneBookEntry ($id) { | |
86 | $this->checkLogin(); | |
87 | ||
88 | $path = 'data/PhoneBook.json'; | |
e559c2bb | 89 | $fields = array('csrf_token' => $this->token, |
9b926efe S |
90 | 'id' => $id, |
91 | 'deleteEntry' => 'delete' | |
92 | ); | |
93 | ||
94 | $data = $this->sentRequest($path, $fields, true); | |
95 | $data = $this->getValues($data['body']); | |
96 | ||
97 | if ($data['status'] == 'ok') { | |
98 | return $data; | |
99 | } | |
100 | else { | |
101 | throw new RouterException('can not delete Phone Book Entry'); | |
102 | } | |
103 | } | |
104 | ||
105 | /** | |
106 | * get the Missed Calls from router | |
107 | * | |
108 | * @return array | |
109 | */ | |
110 | public function getMissedCalls() { | |
87492136 S |
111 | $lines = $this->exportData('1'); |
112 | $calls = array(); | |
113 | $c = count($lines) -2; | |
9b926efe | 114 | |
87492136 S |
115 | foreach ($lines as $line) { |
116 | if (empty($line) || strpos($line, 'Date') !== false) continue; | |
117 | ||
118 | $exp = explode(' ', $line); | |
119 | ||
120 | $data = array(); | |
121 | $data['id'] = $c; | |
122 | $data['missedcalls_date'] = $exp[0]; | |
123 | $data['missedcalls_time'] = $exp[1]; | |
124 | $data['missedcalls_who'] = $exp[2]; | |
125 | $c = $c -1; | |
126 | $calls[] = $data; | |
9b926efe | 127 | } |
87492136 S |
128 | |
129 | return $calls; | |
9b926efe S |
130 | } |
131 | ||
132 | /** | |
133 | * get the Taken Calls from router | |
134 | * | |
135 | * @return array | |
136 | */ | |
137 | public function getTakenCalls() { | |
87492136 S |
138 | $lines = $this->exportData('2'); |
139 | $calls = array(); | |
140 | $c = count($lines) -2; | |
9b926efe | 141 | |
87492136 S |
142 | foreach ($lines as $line) { |
143 | if (empty($line) || strpos($line, 'Date') !== false) continue; | |
144 | ||
145 | $exp = explode(' ', $line); | |
146 | ||
147 | $data = array(); | |
148 | $data['id'] = $c; | |
149 | $data['takencalls_date'] = $exp[0]; | |
150 | $data['takencalls_time'] = $exp[1]; | |
151 | $data['takencalls_who'] = $exp[2]; | |
152 | $data['takencalls_duration'] = $exp[3]; | |
153 | $c = $c -1; | |
154 | $calls[] = $data; | |
9b926efe | 155 | } |
87492136 S |
156 | |
157 | return $calls; | |
158 | ||
9b926efe S |
159 | } |
160 | ||
161 | /** | |
162 | * get the Dialed Calls from router | |
163 | * | |
164 | * @return array | |
165 | */ | |
166 | public function getDialedCalls() { | |
87492136 S |
167 | $lines = $this->exportData('3'); |
168 | $calls = array(); | |
169 | $c = count($lines) -2; | |
9b926efe | 170 | |
87492136 S |
171 | foreach ($lines as $line) { |
172 | if (empty($line) || strpos($line, 'Date') !== false) continue; | |
173 | ||
174 | $exp = explode(' ', $line); | |
175 | ||
176 | $data = array(); | |
177 | $data['id'] = $c; | |
178 | $data['dialedcalls_date'] = $exp[0]; | |
179 | $data['dialedcalls_time'] = $exp[1]; | |
180 | $data['dialedcalls_who'] = $exp[2]; | |
181 | $data['dialedcalls_duration'] = $exp[3]; | |
182 | $c = $c -1; | |
183 | $calls[] = $data; | |
9b926efe | 184 | } |
87492136 S |
185 | |
186 | return $calls; | |
187 | } | |
188 | ||
189 | /** | |
190 | * export data from router | |
191 | * | |
192 | * @return array | |
193 | */ | |
194 | private function exportData ($type) { | |
195 | $this->checkLogin(); | |
196 | ||
197 | $path = 'data/Syslog.json'; | |
198 | $fields = array('exporttype' => $type); | |
199 | $data = $this->sentRequest($path, $fields, true); | |
200 | ||
201 | return explode("\n", $data['body']); | |
9b926efe | 202 | } |
89d43347 | 203 | } |