forked from Befox/cdav
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cdavurls.php
160 lines (137 loc) · 5.67 KB
/
cdavurls.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/******************************************************************
* cdav is a Dolibarr module
* It allows caldav and carddav clients to sync with Dolibarr
* calendars and contacts.
*
* cdav is distributed under GNU/GPLv3 license
* (see COPYING file)
*
* cdav uses Sabre/dav library http://sabre.io/dav/
* Sabre/dav is distributed under use the three-clause BSD-license
*
* Author : Befox SARL http://www.befox.fr/
*
******************************************************************/
/**
* \file cdav/cdavurls.php
* \ingroup cdav
* \brief This page displays urls for carddav and caldav sync
*
*/
// Load Dolibarr environment
$res = 0;
// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { $i--; $j--; }
if (!$res && $i > 0 && @file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
if (!$res && $i > 0 && @file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
// Try main.inc.php using relative path
if (!$res && @file_exists("../main.inc.php")) $res = @include "../main.inc.php";
if (!$res && @file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
if (!$res && @file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
if (!$res) die("Include of main fails");
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
// Load traductions files requiredby by page
$langs->load("cdav");
// Get parameters
$id = GETPOST('id','int');
$action = GETPOST('action','alpha');
$backtopage = GETPOST('backtopage');
$type = GETPOST('type','CalDAV');
// Protection if external user
if ($user->societe_id > 0)
{
accessforbidden();
}
/***************************************************
* VIEW
*
* Put here all code to build page
****************************************************/
llxHeader('',$langs->trans($type.'url'),'');
echo '<H2>'.$langs->trans($type.'url').'</H2>';
if($type=='CardDAV')
{
echo '<h3>'.$langs->trans('URLGeneric').'</h3>';
echo '<PRE>';
echo dol_buildpath('cdav', 2)."\n";
echo dol_buildpath('cdav/server.php', 2)."\n";
echo dol_buildpath('cdav', 2)."/server.php/principals/".$user->login."/";
echo '</PRE>';
echo '<h3>'.$langs->trans('URLforCardDAV', 2).'</h3>';
echo '<PRE>'.dol_buildpath('cdav/server.php', 2).'/addressbooks/'.$user->login.'/default/</PRE>';
}
elseif($type=='CalDAV')
{
echo '<h3>'.$langs->trans('URLGeneric').'</h3>';
echo '<PRE>';
echo dol_buildpath('cdav', 2)."\n";
echo dol_buildpath('cdav/server.php', 2)."\n";
echo dol_buildpath('cdav', 2)."/server.php/principals/".$user->login."/";
echo '</PRE>';
echo '<h3>'.$langs->trans('URLforCalDAV').'</h3>';
if(isset($user->rights->agenda->allactions->read) && $user->rights->agenda->allactions->read)
{
if (versioncompare(versiondolibarrarray(), array(3,7,9))>0)
$fk_soc_fieldname = 'fk_soc';
else
$fk_soc_fieldname = 'fk_societe';
$sql = 'SELECT u.rowid, u.login, u.firstname, u.lastname
FROM '.MAIN_DB_PREFIX.'user u WHERE '.$fk_soc_fieldname.' IS NULL
ORDER BY login';
$result = $db->query($sql);
while($row = $db->fetch_array($result))
{
if($row['rowid'] == $user->id)
echo '<strong>';
echo $row['firstname'].' '.$row['lastname'].' :';
echo '<PRE>'.dol_buildpath('cdav/server.php', 2).'/calendars/'.$user->login.'/'.$row['rowid'].'-cal-'.$row['login'].'</PRE><br/>';
if($row['rowid'] == $user->id)
echo '</strong>';
}
}
else
{
echo '<PRE>'.dol_buildpath('cdav/server.php', 2).'/calendars/'.$user->login.'/'.$user->id.'-cal-'.$user->login.'</PRE>';
}
}
elseif($type=='ICS')
{
echo '<h3>'.$langs->trans('URLforICS').'</h3>';
if(isset($user->rights->agenda->allactions->read) && $user->rights->agenda->allactions->read)
{
if (versioncompare(versiondolibarrarray(), array(3,7,9))>0)
$fk_soc_fieldname = 'fk_soc';
else
$fk_soc_fieldname = 'fk_societe';
$sql = 'SELECT u.rowid, u.login, u.firstname, u.lastname
FROM '.MAIN_DB_PREFIX.'user u WHERE '.$fk_soc_fieldname.' IS NULL
ORDER BY login';
$result = $db->query($sql);
while($row = $db->fetch_array($result))
{
echo '<h4>'.$row['firstname'].' '.$row['lastname'].' :</h4>';
echo "<PRE>".$langs->trans('Full')." :\n".dol_buildpath('cdav/ics.php', 2).'?token='.base64url_encode(mcrypt_encrypt (MCRYPT_BLOWFISH, CDAV_URI_KEY, $row['rowid'].'+ø+full', ecb))."\n\n";
echo $langs->trans('NoLabel')." :\n".dol_buildpath('cdav/ics.php', 2).'?token='.base64url_encode(mcrypt_encrypt (MCRYPT_BLOWFISH, CDAV_URI_KEY, $row['rowid'].'+ø+nolabel', ecb)).'</PRE><br/>';
}
}
else
{
echo "<PRE>".$langs->trans('Full')." :\n".dol_buildpath('cdav/ics.php', 2).'?token='.base64url_encode(mcrypt_encrypt (MCRYPT_BLOWFISH, CDAV_URI_KEY, $user->id.'+ø+full', ecb))."\n\n";
echo $langs->trans('NoLabel')." :\n".dol_buildpath('cdav/ics.php', 2).'?token='.base64url_encode(mcrypt_encrypt (MCRYPT_BLOWFISH, CDAV_URI_KEY, $user->id.'+ø+nolabel', ecb)).'</PRE><br/>';
}
}
else
{
echo '<h3>'.$langs->trans('URLGeneric').'</h3>';
echo '<PRE>'.dol_buildpath('cdav', 2).'</PRE>';
}
// End of page
llxFooter();
$db->close();