127 $location = $obj->location;
130 if (empty($location) && !empty($obj->address)) {
131 $location = trim(str_replace(array(
"\r",
"\t",
"\n"),
' ', $obj->address));
132 $location = trim($location.
', '.$obj->zip);
133 $location = trim($location.
' '.$obj->town);
134 $location = trim($location.
', '.$obj->country_label);
138 if (empty($location) && !empty($obj->soc_address)) {
139 $location = trim(str_replace(array(
"\r",
"\t",
"\n"),
' ', $obj->soc_address));
140 $location = trim($location.
', '.$obj->soc_zip);
141 $location = trim($location.
' '.$obj->soc_town);
142 $location = trim($location.
', '.$obj->soc_country_label);
154 if ($obj->percent == -1 && trim($obj->datep) !=
'') {
160 $timezone = date_default_timezone_get();
162 $caldata =
"BEGIN:VCALENDAR\n";
163 $caldata .=
"VERSION:2.0\n";
164 $caldata .=
"METHOD:PUBLISH\n";
165 $caldata .=
"PRODID:-//Dolibarr CDav//FR\n";
166 $caldata .=
"BEGIN:".$type.
"\n";
167 $caldata .=
"CREATED:".gmdate(
'Ymd\THis', strtotime($obj->datec)).
"Z\n";
168 $caldata .=
"LAST-MODIFIED:".gmdate(
'Ymd\THis', strtotime($obj->lastupd)).
"Z\n";
169 $caldata .=
"DTSTAMP:".gmdate(
'Ymd\THis', strtotime($obj->lastupd)).
"Z\n";
170 if ($obj->sourceuid ==
'') {
171 $caldata .=
"UID:".$obj->id.
'-ev-'.$calid.
'-cal-'.constant(
'CDAV_URI_KEY').
"\n";
173 $caldata .=
"UID:".$obj->sourceuid.
"\n";
175 $caldata .=
"SUMMARY:".$obj->label.
"\n";
176 $caldata .=
"LOCATION:".$location.
"\n";
177 $caldata .=
"PRIORITY:".$obj->priority.
"\n";
178 if ($obj->fulldayevent) {
179 $caldata .=
"DTSTART;VALUE=DATE:".date(
'Ymd', strtotime($obj->datep)).
"\n";
180 if ($type ==
'VEVENT') {
181 if (trim($obj->datep2) !=
'') {
182 $caldata .=
"DTEND;VALUE=DATE:".date(
'Ymd', strtotime($obj->datep2) + 1).
"\n";
184 $caldata .=
"DTEND;VALUE=DATE:".date(
'Ymd', strtotime($obj->datep) + (25 * 3600)).
"\n";
186 } elseif (trim($obj->datep2) !=
'') {
187 $caldata .=
"DUE;VALUE=DATE:".date(
'Ymd', strtotime($obj->datep2) + 1).
"\n";
190 $caldata .=
"DTSTART;TZID=".$timezone.
":".strtr($obj->datep, array(
" "=>
"T",
":"=>
"",
"-"=>
"")).
"\n";
191 if ($type ==
'VEVENT') {
192 if (trim($obj->datep2) !=
'') {
193 $caldata .=
"DTEND;TZID=".$timezone.
":".strtr($obj->datep2, array(
" "=>
"T",
":"=>
"",
"-"=>
"")).
"\n";
195 $caldata .=
"DTEND;TZID=".$timezone.
":".strtr($obj->datep, array(
" "=>
"T",
":"=>
"",
"-"=>
"")).
"\n";
197 } elseif (trim($obj->datep2) !=
'') {
198 $caldata .=
"DUE;TZID=".$timezone.
":".strtr($obj->datep2, array(
" "=>
"T",
":"=>
"",
"-"=>
"")).
"\n";
201 $caldata .=
"CLASS:PUBLIC\n";
202 if ($obj->transparency == 1) {
203 $caldata .=
"TRANSP:TRANSPARENT\n";
205 $caldata .=
"TRANSP:OPAQUE\n";
208 if ($type ==
'VEVENT') {
209 $caldata .=
"STATUS:CONFIRMED\n";
210 } elseif ($obj->percent == 0) {
211 $caldata .=
"STATUS:NEEDS-ACTION\n";
212 } elseif ($obj->percent == 100) {
213 $caldata .=
"STATUS:COMPLETED\n";
215 $caldata .=
"STATUS:IN-PROCESS\n";
216 $caldata .=
"PERCENT-COMPLETE:".$obj->percent.
"\n";
219 $caldata .=
"DESCRIPTION:";
220 $caldata .= strtr($obj->note, array(
"\n"=>
"\\n",
"\r"=>
""));
221 if (!empty($obj->soc_nom)) {
222 $caldata .=
"\\n*DOLIBARR-SOC: ".$obj->soc_nom;
224 if (!empty($obj->soc_phone)) {
225 $caldata .=
"\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
227 if (!empty($obj->firstname) || !empty($obj->lastname)) {
228 $caldata .=
"\\n*DOLIBARR-CTC: ".trim($obj->firstname.
' '.$obj->lastname);
230 if (!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile)) {
231 $caldata .=
"\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.
' '.$obj->phone_perso.
' '.$obj->phone_mobile);
233 if (strpos($obj->other_users,
',')) {
234 $caldata .=
"\\n*DOLIBARR-USR: ".$obj->other_users;
238 $caldata .=
"END:".$type.
"\n";
239 $caldata .=
"END:VCALENDAR\n";
253 $calid = (int) $calendarId;
254 $calevents = array();
256 if (!$this->
user->rights->agenda->myactions->read) {
260 if ($calid != $this->
user->id && (!isset($this->
user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read)) {
266 $result = $this->db->query($sql);
269 while ($obj = $this->db->fetch_object($result)) {
272 if ($bCalendarData) {
273 $calevents[] = array(
274 'calendardata' => $calendardata,
275 'uri' => $obj->id.
'-ev-'.constant(
'CDAV_URI_KEY'),
276 'lastmodified' => strtotime($obj->lastupd),
277 'etag' =>
'"'.md5($calendardata).
'"',
278 'calendarid' => $calendarId,
279 'size' => strlen($calendardata),
280 'component' => strpos($calendardata,
'BEGIN:VEVENT') > 0 ?
'vevent' :
'vtodo',
283 $calevents[] = array(
285 'uri' => $obj->id.
'-ev-'.constant(
'CDAV_URI_KEY'),
286 'lastmodified' => strtotime($obj->lastupd),
287 'etag' =>
'"'.md5($calendardata).
'"',
288 'calendarid' => $calendarId,
289 'size' => strlen($calendardata),
290 'component' => strpos($calendardata,
'BEGIN:VEVENT') > 0 ?
'vevent' :
'vtodo',