update copyright year
[GitHub/Stricted/speedport-hybrid-php-api.git] / lib / trait / Phone.class.php
CommitLineData
9b926efe
S
1<?php
2/**
3 * @author Jan Altensen (Stricted)
4 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
dd76f288 5 * @copyright 2015-2016 Jan Altensen (Stricted)
9b926efe
S
6 */
7trait 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
e94573dd 51 $data = $this->sendRequest($path, $fields, true);
9b926efe
S
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
e94573dd 94 $data = $this->sendRequest($path, $fields, true);
9b926efe
S
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() {
42533053
S
111 $data = $this->getData('PhoneCalls');
112 $data = $this->getValues($data);
9b926efe 113
42533053
S
114 if (isset($data['addmissedcalls'])) {
115 return $data['addmissedcalls'];
116 }
117 else {
118 return array();
9b926efe
S
119 }
120 }
121
122 /**
123 * get the Taken Calls from router
124 *
125 * @return array
126 */
127 public function getTakenCalls() {
42533053
S
128 $data = $this->getData('PhoneCalls');
129 $data = $this->getValues($data);
9b926efe 130
42533053
S
131 if (isset($data['addtakencalls'])) {
132 return $data['addtakencalls'];
133 }
134 else {
135 return array();
9b926efe
S
136 }
137 }
138
139 /**
140 * get the Dialed Calls from router
141 *
142 * @return array
143 */
144 public function getDialedCalls() {
42533053
S
145 $data = $this->getData('PhoneCalls');
146 $data = $this->getValues($data);
147
148 if (isset($data['adddialedcalls'])) {
149 return $data['adddialedcalls'];
150 }
151 else {
152 return array();
9b926efe
S
153 }
154 }
89d43347 155}