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) {
86 $sql .=
' LEFT OUTER JOIN '.MAIN_DB_PREFIX.
'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.((int) $this->
user->id).
')
87 LEFT JOIN '.MAIN_DB_PREFIX.
'societe AS s ON (s.rowid = sc.fk_soc)
88 LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact)
89 LEFT JOIN '.MAIN_DB_PREFIX.
'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
91 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'societe AS s ON (s.rowid = a.fk_soc)
92 LEFT JOIN '.MAIN_DB_PREFIX.
'socpeople AS sp ON (sp.rowid = a.fk_contact)
93 LEFT JOIN '.MAIN_DB_PREFIX.
'actioncomm_cdav AS ac ON (a.id = ac.fk_object)';
96 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as co ON co.rowid = sp.fk_pays
97 LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as cos ON cos.rowid = s.fk_pays
98 WHERE a.id IN (SELECT ar.fk_actioncomm FROM '.MAIN_DB_PREFIX.
'actioncomm_resources ar WHERE ar.element_type=\'user\' AND ar.fk_element='.((int) $calid).
')
99 AND a.code IN (SELECT cac.code FROM '.MAIN_DB_PREFIX.
'c_actioncomm cac WHERE cac.type<>\'systemauto\')
100 AND a.entity IN ('.
getEntity(
'societe', 1).
')';
101 if ($oid !==
false) {
102 if ($ouri ===
false) {
103 $sql .=
' AND a.id = '.intval($oid);
105 $sql .=
' AND (a.id = '.intval($oid).
' OR ac.uuidext = \''.$this->
db->escape($ouri).
'\')
';
119 public function toVCalendar($calid, $obj)
124 $nick[] = $obj->soc_code_client;
125 $categ[] = $this->langs->transnoentitiesnoconv('Customer
');
128 $location = $obj->location;
131 if (empty($location) && !empty($obj->address)) {
132 $location = trim(str_replace(array("\r", "\t", "\n"), ' ', $obj->address));
133 $location = trim($location.',
'.$obj->zip);
134 $location = trim($location.' '.$obj->town);
135 $location = trim($location.',
'.$obj->country_label);
139 if (empty($location) && !empty($obj->soc_address)) {
140 $location = trim(str_replace(array("\r", "\t", "\n"), ' ', $obj->soc_address));
141 $location = trim($location.',
'.$obj->soc_zip);
142 $location = trim($location.' '.$obj->soc_town);
143 $location = trim($location.',
'.$obj->soc_country_label);
147 $address = explode("\n", $obj->address, 2);
148 foreach ($address as $kAddr => $vAddr) {
149 $address[$kAddr] = trim(str_replace(array("\r", "\t"), ' ', str_replace("\n", ' |
', trim($vAddr))));
155 if ($obj->percent == -1 && trim($obj->datep) != '') {
161 $timezone = date_default_timezone_get();
163 $caldata = "BEGIN:VCALENDAR\n";
164 $caldata .= "VERSION:2.0\n";
165 $caldata .= "METHOD:PUBLISH\n";
166 $caldata .= "PRODID:-//Dolibarr CDav//FR\n";
167 $caldata .= "BEGIN:".$type."\n";
168 $caldata .= "CREATED:".gmdate('Ymd\THis
', strtotime($obj->datec))."Z\n";
169 $caldata .= "LAST-MODIFIED:".gmdate('Ymd\THis
', strtotime($obj->lastupd))."Z\n";
170 $caldata .= "DTSTAMP:".gmdate('Ymd\THis
', strtotime($obj->lastupd))."Z\n";
171 if ($obj->sourceuid == '') {
172 $caldata .= "UID:".$obj->id.'-ev-
'.$calid.'-cal-
'.constant('CDAV_URI_KEY
')."\n";
174 $caldata .= "UID:".$obj->sourceuid."\n";
176 $caldata .= "SUMMARY:".$obj->label."\n";
177 $caldata .= "LOCATION:".$location."\n";
178 $caldata .= "PRIORITY:".$obj->priority."\n";
179 if ($obj->fulldayevent) {
180 $caldata .= "DTSTART;VALUE=DATE:".date('Ymd
', strtotime($obj->datep))."\n";
181 if ($type == 'VEVENT
') {
182 if (trim($obj->datep2) != '') {
183 $caldata .= "DTEND;VALUE=DATE:".date('Ymd
', strtotime($obj->datep2) + 1)."\n";
185 $caldata .= "DTEND;VALUE=DATE:".date('Ymd
', strtotime($obj->datep) + (25 * 3600))."\n";
187 } elseif (trim($obj->datep2) != '') {
188 $caldata .= "DUE;VALUE=DATE:".date('Ymd
', strtotime($obj->datep2) + 1)."\n";
191 $caldata .= "DTSTART;TZID=".$timezone.":".strtr($obj->datep, array(" "=>"T", ":"=>"", "-"=>""))."\n";
192 if ($type == 'VEVENT
') {
193 if (trim($obj->datep2) != '') {
194 $caldata .= "DTEND;TZID=".$timezone.":".strtr($obj->datep2, array(" "=>"T", ":"=>"", "-"=>""))."\n";
196 $caldata .= "DTEND;TZID=".$timezone.":".strtr($obj->datep, array(" "=>"T", ":"=>"", "-"=>""))."\n";
198 } elseif (trim($obj->datep2) != '') {
199 $caldata .= "DUE;TZID=".$timezone.":".strtr($obj->datep2, array(" "=>"T", ":"=>"", "-"=>""))."\n";
202 $caldata .= "CLASS:PUBLIC\n";
203 if ($obj->transparency == 1) {
204 $caldata .= "TRANSP:TRANSPARENT\n";
206 $caldata .= "TRANSP:OPAQUE\n";
209 if ($type == 'VEVENT
') {
210 $caldata .= "STATUS:CONFIRMED\n";
211 } elseif ($obj->percent == 0) {
212 $caldata .= "STATUS:NEEDS-ACTION\n";
213 } elseif ($obj->percent == 100) {
214 $caldata .= "STATUS:COMPLETED\n";
216 $caldata .= "STATUS:IN-PROCESS\n";
217 $caldata .= "PERCENT-COMPLETE:".$obj->percent."\n";
220 $caldata .= "DESCRIPTION:";
221 $caldata .= strtr($obj->note, array("\n"=>"\\n", "\r"=>""));
222 if (!empty($obj->soc_nom)) {
223 $caldata .= "\\n*DOLIBARR-SOC: ".$obj->soc_nom;
225 if (!empty($obj->soc_phone)) {
226 $caldata .= "\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone;
228 if (!empty($obj->firstname) || !empty($obj->lastname)) {
229 $caldata .= "\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname);
231 if (!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile)) {
232 $caldata .= "\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile);
234 if (strpos($obj->other_users, ',
')) { // several
235 $caldata .= "\\n*DOLIBARR-USR: ".$obj->other_users;
239 $caldata .= "END:".$type."\n";
240 $caldata .= "END:VCALENDAR\n";
252 public function getFullCalendarObjects($calendarId, $bCalendarData)
254 $calid = (int) $calendarId;
255 $calevents = array();
257 if (!$this->user->rights->agenda->myactions->read) {
261 if ($calid != $this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read)) {
265 $sql = $this->getSqlCalEvents($calid);
267 $result = $this->db->query($sql);
270 while ($obj = $this->db->fetch_object($result)) {
271 $calendardata = $this->toVCalendar($calid, $obj);
273 if ($bCalendarData) {
274 $calevents[] = array(
275 'calendardata
' => $calendardata,
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
',
284 $calevents[] = array(
285 // 'calendardata
' => $calendardata, not necessary because etag+size are present
286 'uri
' => $obj->id.'-ev-
'.constant('CDAV_URI_KEY
'),
287 'lastmodified
' => strtotime($obj->lastupd),
288 'etag
' => '"'.md5($calendardata).'"',
289 'calendarid
' => $calendarId,
290 'size
' => strlen($calendardata),
291 'component
' => strpos($calendardata, 'BEGIN:VEVENT
') > 0 ? 'vevent
' : 'vtodo
',
Define Common function to access calendar items and format it in vCalendar.
getSqlCalEvents($calid, $oid=false, $ouri=false)
Base sql request for calendar events.
__construct($user, $db, $langs)
Constructor.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
$conf db
API class for accounts.