-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirectory.php
135 lines (121 loc) · 4.34 KB
/
directory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
require(__DIR__ . "/../includes/shared.php");
header("Content-type: text/xml; charset=utf-8");
?>
<?xml version="1.0" encoding="utf-8"?>
<?php
$key = get_key();
if($key === false) { // request key
?>
<CiscoIPPhoneText>
<Title>Outlook-Kontakte</Title>
<Prompt>Bitte Schlüssel in URL angeben!</Prompt>
<Text><?php echo pageroot(true); ?></Text>
</CiscoIPPhoneText>
<?php
exit;
}
$access_token = get_access_token($key);
if($access_token === false) { // request access
?>
<CiscoIPPhoneText>
<Title>Outlook-Kontakte</Title>
<Prompt>Bitte MS-Konto neu verbinden!</Prompt>
<Text><?php echo $url_oauth . "?key=" . $key; ?></Text>
</CiscoIPPhoneText>
<?php
}else{
$new_url = htmlspecialchars(current_url());
$new_url .= (strrpos($new_url, '?') !== false) ? '&' : '?'; // BUG?? htmlspecialchars should never contain ?
$new_url .= "id=";
$started = false;
$results = 0;
query_contacts($access_token, function($json, $last_page) { // TODO implement search
global $new_url;
global $started;
global $results;
if(isset($json->value)) { // multiple results / list
if(!$started) {
$started = true;
?>
<CiscoIPPhoneMenu>
<Title>Outlook-Kontakte</Title>
<?php
}
foreach($json->value as $contact) {
if(
(count($contact->homePhones) > 0 && !empty($contact->homePhones[0]))
|| (count($contact->businessPhones) > 0 && !empty($contact->businessPhones[0]))
|| !empty($contact->mobilePhone)
) {
$name = $contact->displayName;
if($name === "") $name = $contact->companyName;
?>
<MenuItem>
<Name><?php echo htmlspecialchars($name); ?></Name>
<URL><?php echo $new_url . urlencode($contact->id); ?></URL>
</MenuItem>
<?php
// "IP phones allow a maximum of 100 MenuItems"
// TODO IMPLEMENT MULTIPLE RESULT PAGES NAVIGATED USING SOFTKEYS
$results++;
if($results == 100) {
$last_page = true;
break;
}
}
}
if($last_page) {
?>
</CiscoIPPhoneMenu>
<?php
return false; // don't fetch next result page(s) (if any)
}
}else{ // single result
$name = $json->displayName;
if($name === "") $name = $json->companyName;
if(!$started) {
$started = true;
?>
<CiscoIPPhoneDirectory>
<Title>Outlook-Kontakt</Title>
<Prompt><?php echo htmlspecialchars(substr($name, 0, 33/* =max length*/)); ?></Prompt>
<?php
}
$numbers = array();
if(count($json->homePhones) == 1) {
if(!empty($json->homePhones[0])) $numbers['Privat'] = $json->homePhones[0];
}else{
for($i = 0; $i < count($json->homePhones); $i++) {
if(empty($json->homePhones[$i])) continue;
$numbers['Privat ' . ($i + 1)] = $json->homePhones[$i];
}
}
if(count($json->businessPhones) == 1) {
if(!empty($json->businessPhones[0])) $numbers['Geschäftlich'] = $json->businessPhones[0];
}else{
for($i = 0; $i < count($json->businessPhones); $i++) {
if(empty($json->businessPhones[$i])) continue;
$numbers['Geschäftlich ' . ($i + 1)] = $json->businessPhones[$i];
}
}
if(!empty($json->mobilePhone)) {
$numbers['Mobil'] = $json->mobilePhone;
}
foreach ($numbers as $label => $number) {
?>
<DirectoryEntry>
<Name><?php echo $label; ?></Name>
<Telephone><?php echo $number; ?></Telephone>
</DirectoryEntry>
<?php
}
if($last_page) {
?>
</CiscoIPPhoneDirectory>
<?php
}
}
});
}
?>