48 $this->langs = $langs;
70 co.label country_label,
75 s.address soc_address,
78 cos.label soc_country_label,
81 (SELECT GROUP_CONCAT(u.login) FROM '.MAIN_DB_PREFIX.
'actioncomm_resources ar
82 LEFT OUTER JOIN '.MAIN_DB_PREFIX.
'user AS u ON (u.rowid=fk_element)
83 WHERE ar.element_type=\'user\' AND fk_actioncomm=a.id) AS other_users
84 FROM '.MAIN_DB_PREFIX.
'actioncomm AS a';
85 if (!$this->
user->rights->societe->client->voir)
87 $sql .=
' LEFT OUTER JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->
user->id.
')
88 LEFT JOIN '.MAIN_DB_PREFIX.
'societe AS s ON (s.rowid = sc.fk_soc)
89 LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact)
90 LEFT JOIN '.MAIN_DB_PREFIX.
'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
92 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe AS s ON (s.rowid = a.fk_soc)
93 LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople AS sp ON (sp.rowid = a.fk_contact)
94 LEFT JOIN '.MAIN_DB_PREFIX.
'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
97 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON co.rowid = sp.fk_pays
98 LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as cos ON cos.rowid = s.fk_pays
99 WHERE a.id IN (SELECT ar.fk_actioncomm FROM '.MAIN_DB_PREFIX.
'actioncomm_resources ar WHERE ar.element_type=\'user\' AND ar.fk_element='.intval($calid).
')
100 AND a.code IN (SELECT cac.code FROM '.MAIN_DB_PREFIX.
'c_actioncomm cac WHERE cac.type<>\'systemauto\')
101 AND a.entity IN ('.
getEntity(
'societe', 1).
')';
102 if ($oid !==
false) {
105 $sql .=
' AND a.id = '.intval($oid);
107 $sql .=
' AND (a.id = '.intval($oid).
' OR ac.uuidext = \''.$this->
db->escape($ouri).
'\')
';
121 public function toVCalendar($calid, $obj)
126 $nick[] = $obj->soc_code_client;
127 $categ[] = $this->langs->transnoentitiesnoconv('Customer
');
130 $location = $obj->location;
133 if (empty($location) && !empty($obj->address))
135 $location = trim(str_replace(array("\r", "\t", "\n"), ' ', $obj->address));
136 $location = trim($location.',
'.$obj->zip);
137 $location = trim($location.' '.$obj->town);
138 $location = trim($location.',
'.$obj->country_label);
142 if (empty($location) && !empty($obj->soc_address))
144 $location = trim(str_replace(array("\r", "\t", "\n"), ' ', $obj->soc_address));
145 $location = trim($location.',
'.$obj->soc_zip);
146 $location = trim($location.' '.$obj->soc_town);
147 $location = trim($location.',
'.$obj->soc_country_label);
150 $address = explode("\n", $obj->address, 2);
151 foreach ($address as $kAddr => $vAddr)
153 $address[$kAddr] = trim(str_replace(array("\r", "\t"), ' ', str_replace("\n", ' |
', trim($vAddr))));
158 if ($obj->percent == -1 && trim($obj->datep) != '')
160 else $type = 'VTODO
';
162 $timezone = date_default_timezone_get();
164 $caldata = "BEGIN:VCALENDAR\n";
165 $caldata .= "VERSION:2.0\n";
166 $caldata .= "METHOD:PUBLISH\n";
167 $caldata .= "PRODID:-//Dolibarr CDav//FR\n";
168 $caldata .= "BEGIN:".$type."\n";
169 $caldata .= "CREATED:".gmdate('Ymd\THis
', strtotime($obj->datec))."Z\n";
170 $caldata .= "LAST-MODIFIED:".gmdate('Ymd\THis
', strtotime($obj->lastupd))."Z\n";
171 $caldata .= "DTSTAMP:".gmdate('Ymd\THis
', strtotime($obj->lastupd))."Z\n";
172 if ($obj->sourceuid == '')
173 $caldata .= "UID:".$obj->id.'-ev-
'.$calid.'-cal-
'.constant('CDAV_URI_KEY
')."\n";
174 else $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)
180 $caldata .= "DTSTART;VALUE=DATE:".date('Ymd
', strtotime($obj->datep))."\n";
181 if ($type == 'VEVENT
')
183 if (trim($obj->datep2) != '')
184 $caldata .= "DTEND;VALUE=DATE:".date('Ymd
', strtotime($obj->datep2) + 1)."\n";
185 else $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";
189 $caldata .= "DTSTART;TZID=".$timezone.":".strtr($obj->datep, array(" "=>"T", ":"=>"", "-"=>""))."\n";
190 if ($type == 'VEVENT
')
192 if (trim($obj->datep2) != '')
193 $caldata .= "DTEND;TZID=".$timezone.":".strtr($obj->datep2, array(" "=>"T", ":"=>"", "-"=>""))."\n";
194 else $caldata .= "DTEND;TZID=".$timezone.":".strtr($obj->datep, array(" "=>"T", ":"=>"", "-"=>""))."\n";
195 } elseif (trim($obj->datep2) != '')
196 $caldata .= "DUE;TZID=".$timezone.":".strtr($obj->datep2, array(" "=>"T", ":"=>"", "-"=>""))."\n";
198 $caldata .= "CLASS:PUBLIC\n";
199 if ($obj->transparency == 1)
200 $caldata .= "TRANSP:TRANSPARENT\n";
201 else $caldata .= "TRANSP:OPAQUE\n";
203 if ($type == 'VEVENT
')
204 $caldata .= "STATUS:CONFIRMED\n";
205 elseif ($obj->percent == 0)
206 $caldata .= "STATUS:NEEDS-ACTION\n";
207 elseif ($obj->percent == 100)
208 $caldata .= "STATUS:COMPLETED\n";
210 $caldata .= "STATUS:IN-PROCESS\n";
211 $caldata .= "PERCENT-COMPLETE:".$obj->percent."\n";
214 $caldata .= "DESCRIPTION:";
215 $caldata .= strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
216 if (!empty($obj->soc_nom))
217 $caldata .= "\\n*DOLIBARR-SOC: ".$obj->soc_nom;
218 if (!empty($obj->soc_phone))
219 $caldata .= "\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
220 if (!empty($obj->firstname) || !empty($obj->lastname))
221 $caldata .= "\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
222 if (!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile))
223 $caldata .= "\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
224 if (strpos($obj->other_users, ',
')) // several
225 $caldata .= "\\n*DOLIBARR-USR: ".$obj->other_users;
228 $caldata .= "END:".$type."\n";
229 $caldata .= "END:VCALENDAR\n";
241 public function getFullCalendarObjects($calendarId, $bCalendarData)
243 $calid = ($calendarId * 1);
244 $calevents = array();
246 if (!$this->user->rights->agenda->myactions->read)
249 if ($calid != $this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read))
252 $sql = $this->getSqlCalEvents($calid);
254 $result = $this->db->query($sql);
258 while ($obj = $this->db->fetch_object($result))
260 $calendardata = $this->toVCalendar($calid, $obj);
264 $calevents[] = array(
265 'calendardata
' => $calendardata,
266 'uri
' => $obj->id.'-ev-
'.constant('CDAV_URI_KEY
'),
267 'lastmodified
' => strtotime($obj->lastupd),
268 'etag
' => '"'.md5($calendardata).'"',
269 'calendarid
' => $calendarId,
270 'size
' => strlen($calendardata),
271 'component
' => strpos($calendardata, 'BEGIN:VEVENT
') > 0 ? 'vevent
' : 'vtodo
',
274 $calevents[] = array(
275 // 'calendardata
' => $calendardata, not necessary because etag+size are present
276 'uri
' => $obj->id.'-ev-
'.constant('CDAV_URI_KEY
'),
277 'lastmodified
' => strtotime($obj->lastupd),
278 'etag
' => '"'.md5($calendardata).'"',
279 'calendarid
' => $calendarId,
280 'size
' => strlen($calendardata),
281 'component
' => strpos($calendardata, 'BEGIN:VEVENT
') > 0 ? 'vevent
' : 'vtodo
',
__construct($user, $db, $langs)
Constructor.
$conf db
API class for accounts.
Define Common function to access calendar items and format it in vCalendar.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
getSqlCalEvents($calid, $oid=false, $ouri=false)
Base sql request for calendar events.