source: contrib/z-push/backend/BackendCalendarExpresso.php @ 4000

Revision 4000, 39.7 KB checked in by emersonfaria, 13 years ago (diff)

Ticket #1746 - Criada autenticacao dos Backends no LDAP e corrigido bug de login alfanumerico

  • Property svn:executable set to *
Line 
1<?php
2/***********************************************
3 * File      :   BackendCalendarExpresso.php
4 * Project   :   Z-Push
5 * Descr     :   This Calendar Backend is for Expresso Groupware.
6 *
7 * Created   :   06.12.2010 - emerson-faria.nobre@serpro.gov.br
8 *
9 * ï¿œ Zarafa Deutschland GmbH, www.zarafaserver.de
10 * This file is distributed under GPL v2.
11 * Consult LICENSE file for details
12 ************************************************/
13require_once("diffbackend.php");
14require_once("include/z_RTF.php");
15require_once("include/dbconnect.php");
16require_once("include/authldap.php");
17
18class BackendCalendarExpresso extends BackendDiff {
19        var $db;
20        var $_uidnumber;
21
22        function __construct()
23        {
24                $this->db = dbconnect();
25
26                if (!$this->db) {
27                        echo "Erro de conexao com o banco.\n";
28                        exit;
29                }
30        }
31
32        function Logon($username, $domain, $password) {
33                $this->_uidnumber = $this->authUser($this->parseUser($username), $password);
34                if(! $this->_uidnumber) return false;
35                else return true;
36        }
37
38        function Setup($user, $devid, $protocolversion) {
39                $this->_user = $user;
40                $this->_devid = $devid;
41                $this->_protocolversion = $protocolversion;
42                return true;
43        }
44
45        function SendMail($rfc822, $forward = false, $reply = false, $parent = false) {
46                return false;
47        }
48
49        function GetWasteBasket() {
50                return false;
51        }
52
53        function GetMessageList($folderid, $cutoffdate) {
54                debugLog('CalendarExpresso::GetMessageList('.$this->_uidnumber.')');
55                if ($folderid != "calendar") return false;
56
57                $messages = array();
58                try {
59                        $result = pg_query($this->db,"BEGIN;");
60                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
61                        if ($cutoffdate == 0) $result = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference = 0;");
62                        else $result = pg_query($this->db, "select c.cal_id, c.last_update, c.datetime, c.cal_type from phpgw_cal c join phpgw_cal_user u on (c.cal_id = u.cal_id) where u.cal_login ='" . $this->_uidnumber . "'and c.reference = 0 and c.edatetime > " . $cutoffdate . ";");
63                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
64                        while ($row = pg_fetch_row($result)) {
65                                $result_recur = pg_query($this->db,"select recur_enddate from phpgw_cal_repeats where cal_id = " . $row[0] . ";");
66                                if ($result_recur == FALSE) throw new Exception(pg_last_error($this->db));
67                                if ($row[3] == 'M') {
68                                        if ($recur_enddate = pg_fetch_result($result_recur, 0, 0)) {
69                                                if ($recur_enddate < $row[2]) continue; // Nao sincroniza este evento, porque a data final da recorrencia eh menor que a data inicial do evento. Eh o BD do Expresso que esta inconsistente.
70                                        }
71                                }
72                                $LatestUpdate = $row[1];
73                                $message = array();
74                                $message["id"] = $row[0];
75                                $message["mod"] = substr($LatestUpdate, 0, strlen($LatestUpdate)-3);
76                                $message["flags"] = 1; // always 'read'
77                                $messages[] = $message;
78                        }
79                        $result = pg_query($this->db,"COMMIT;");
80                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
81                } catch (Exception $e) {
82                        pg_query($this->db,"ROLLBACK;");
83                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine());
84                }
85                return $messages;
86        }
87
88        function GetFolderList() {
89                debugLog('CalendarExpresso::GetFolderList()');
90                $folder = $this->StatFolder("calendar");
91                return $folder;
92        }
93
94        function GetFolder($id) {
95                debugLog('CalendarExpresso::GetFolder('.$id.')');
96                if($id == "calendar") {
97                        $folder = new SyncFolder();
98                        $folder->serverid = $id;
99                        $folder->parentid = "0";
100                        $folder->displayname = "Calendario";
101                        $folder->type = SYNC_FOLDER_TYPE_APPOINTMENT;
102                        return $folder;
103                } else return false;
104        }
105
106        function StatFolder($id) {
107                debugLog('CalendarExpresso::StatFolder('.$id.')');
108                $folder = $this->GetFolder($id);
109                $stat = array();
110                $stat["id"] = $id;
111                $stat["parent"] = $folder->parentid;
112                $stat["mod"] = $folder->displayname;
113                return $stat;
114        }
115
116        function GetAttachmentData($attname) {
117                return false;
118        }
119
120        function StatMessage($folderid, $id) {
121                debugLog('CalendarExpresso::StatMessage('.$folderid.', '.$id.')');
122                if($folderid != "calendar") return false;
123                try {
124                 $result = pg_query($this->db,"BEGIN;");
125                 if ($result == FALSE) throw new Exception(pg_last_error($this->db));
126                 $result_calendar = pg_query($this->db, "select last_update from phpgw_cal where cal_id = " . $id . ";");
127                 if ($result_calendar == FALSE) throw new Exception(pg_last_error($this->db));
128                 while ($row_calendar = pg_fetch_row($result_calendar)) {
129                        if(isset($row_calendar[0])) {
130                                $message = array();
131                                $message["mod"] = substr($row_calendar[0], 0, strlen($row_calendar[0])-3);
132                                $message["id"] = $id;
133                                $message["flags"] = 1;
134                                return $message;
135                        }
136                 }
137                 $result = pg_query($this->db,"COMMIT;");
138                 if ($result == FALSE) throw new Exception(pg_last_error($this->db));
139                } catch (Exception $e) {
140                        pg_query($this->db,"ROLLBACK;");
141                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine());
142                }
143                return false;
144        }
145
146        function GetMessageDAO($id) {
147                debugLog('CalendarExpresso::GetMessageDAO('.$id.', ..)');
148                if(trim($id == "")) return false;
149                $message = new SyncAppointment();
150                try {
151                        $has_parent_event = false;
152                        $result = pg_query($this->db,"BEGIN;");
153                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
154                        //Evento
155                        $result = pg_query($this->db,"select config_value from phpgw_config WHERE config_name = 'hostname' AND config_app = 'phpgwapi';");
156                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
157                        $uid = "-@" . pg_fetch_result($result, 0, 0) . "-" . $id;
158                        $result = pg_query($this->db, "select cal_id, title, location, mdatetime, datetime, edatetime, description, reference, is_public, category from phpgw_cal where cal_id = " . $id . ";");
159                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
160                        if ($row = pg_fetch_row($result)) {
161                                if ($row[7] != 0) $has_parent_event = true;
162                                else $has_parent_event = false;
163                                if (!$has_parent_event) {
164                                        $message->fileas = $id;
165                                        $message->uid = utf8_encode($uid);
166                                        if(isset($row[3])) {
167                                                $tz = date_default_timezone_get();
168                                                date_default_timezone_set('UTC');
169                                                $message->dtstamp = $row[3]; // phpgw_cal.mdatetime
170                                                date_default_timezone_set($tz);
171                                        }
172                                        if(isset($row[4])) {
173                                                $tz = date_default_timezone_get();
174                                                date_default_timezone_set('UTC');
175                                                $message->starttime =  $row[4]; // phpgw_cal.datetime
176                                                date_default_timezone_set($tz);
177                                        }
178                                        if(isset($row[5])) {
179                                                $tz = date_default_timezone_get();
180                                                date_default_timezone_set('UTC');
181                                                $message->endtime = $row[5]; // phpgw_cal.edatetime
182                                                date_default_timezone_set($tz);
183                                        }
184                                }
185                                if ($has_parent_event) {
186                                        $message->exceptionstarttime = $row[4];
187                                        $message->deleted = 0;
188                                }
189                                if(isset($row[1])) {
190                                        $message->subject = utf8_encode($row[1]); // phpgw_cal.title
191                                }
192                                if(isset($row[2])) {
193                                        $message->location = utf8_encode($row[2]); // phpgw_cal.location
194                                }
195                                if(isset($row[6]) and $row[6] != "") {
196                                        $message->body = utf8_encode(str_replace('\\n', chr(13) . chr(10), $this->escape($row[6]))); // phpgw_cal.description
197                                        $message->bodysize = strlen($message->body);
198                                        $message->bodytruncated = 0;
199                                }
200                                if (isset($row[8]) and $row[8] == 1) $message->sensitivity = 0; // 0 - Normal
201                                else $message->sensitivity = 2; // 2 - Privado
202                                if (isset($row[9]) and $row[9] != "") {
203                                        $result = pg_query($this->db,"select cat_name from phpgw_categories WHERE cat_id in(" . $row[9] . ");");
204                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
205                                        while ($cat_name = pg_fetch_row($result)) {
206                                                if (!isset($message->categories)) $message->categories = array();
207                                                array_push($message->categories, utf8_encode($cat_name[0]));
208                                        }
209                                }
210                                $message->alldayevent = 0; // (0 - Não(default), 1- Sim)
211                                $message->busystatus = 2; // 2 - Ocupado
212                                //TODO: Tratar $message - timezone
213                                //$tz = $this->_getGMTTZ();
214                                $tz = array("bias" => 180, "stdbias" => 0, "dstbias" => -60, "dstendyear" => 0, "dstendmonth" => 2, "dstendday" => 0, "dstendweek" => 2, "dstendhour" => 2, "dstendminute" => 0, "dstendsecond" => 0, "dstendmillis" => 0,
215                                                      "dststartyear" => 0, "dststartmonth" =>10, "dststartday" =>0, "dststartweek" => 3, "dststarthour" => 2, "dststartminute" => 0, "dststartsecond" => 0, "dststartmillis" => 0);
216                                $message->timezone = base64_encode($this->_getSyncBlobFromTZ($tz));
217                                //TODO: Se necessario, tratar $message - meetingstatus
218                                //TODO: Se necessario, tratar AppointmentReplyTime e ResponseType
219                        }
220
221                        //Alarme do Evento - O alarme nao sera sincronizado por enquanto.
222                        /* Esse exemplo sincroniza o alarme mais distante do evento com o dispositivo movel
223                        * $result = pg_query("select data from phpgw_async where id like 'cal:" . $id . ":%' and data like '%enabled%' order by next desc;");
224                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
225                        if ($data = pg_fetch_result($result, 0, 0)) {
226                        $array_data = unserialize($data);
227                        $offset = $array_data["offset"];
228                        if (isset($array_data["offset"])) {
229                        if ($offset >= 60) $message->reminder = intval($offset / 60);
230                        else $message->reminder = 0;
231                        }
232                        }*/
233                        if (!$has_parent_event) {
234                                //Recorrencia do evento
235                                //TODO: Implementar recorrencia mensal por dia e anual por dia, recur - type 3 e 6 respectivamente. O Expresso ainda nao suporta isso. :(
236                                $result = pg_query($this->db,"select recur_type, recur_use_end, recur_enddate, recur_interval, recur_data, recur_exception from phpgw_cal_repeats where cal_id = " . $id . "and recur_type in (1,2,3,5);");
237                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
238                                if ($row = pg_fetch_row($result)){
239                                        $recur = new SyncRecurrence();
240                                        // Converte os tipos do Expresso para os tipos do Protocolo ActiveSync
241                                        switch ($row[0]) {
242                                                case 1: //repeticao diaria
243                                                        $recur->type = 0;
244                                                        break;
245                                                case 2: //repeticao semanal
246                                                        $recur->type = 1;
247                                                        break;
248                                                case 3: //repeticao mensal por data
249                                                        $recur->type = 2;
250                                                        break;
251                                                case 5: //repeticao anual por data
252                                                        $recur->type = 5;
253                                                        break;
254                                        }
255                                        if (isset($row[2])) {
256                                                $tz = date_default_timezone_get();
257                                                date_default_timezone_set('UTC');
258                                                $recur->until = $row[2];
259                                                date_default_timezone_set($tz);
260                                        }
261                                        if (isset($row[3]) and $row[3] != 0) $recur->interval = $row[3];
262                                        else $recur->interval = 1;
263                                        //TODO: Se o Expresso estiver utilizando o campo phpgw_cal_repeats.recur_use_end, implementar.
264                                        if ($recur->type == 1 or $recur->type == 3 or $recur->type == 6) {
265                                                if (isset($row[4])) $recur->dayofweek = $row[4];
266                                        }
267                                        if ($recur->type == 2 or $recur->type == 5) {
268                                                $tz = date_default_timezone_get();
269                                                date_default_timezone_set('UTC');
270                                                $array_startdatetime    = getdate($message->starttime);
271                                                $recur->dayofmonth = $array_startdatetime['mday'];
272                                                date_default_timezone_set($tz);
273
274                                        }
275                                        if ($recur->type == 5 or $recur->type == 6) {
276                                                $tz = date_default_timezone_get();
277                                                date_default_timezone_set('UTC');
278                                                $array_startdatetime    = getdate($message->starttime);
279                                                $recur->monthofyear = $array_startdatetime['mon'];
280                                                date_default_timezone_set($tz);
281
282                                        }
283                                        $message->recurrence = $recur;
284                                }
285
286                                //Eventos Unicos da Recorrencia Editados
287                                $result = pg_query($this->db, "select cal_id from phpgw_cal where reference = " . $id . ";");
288                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
289                                while ($row_recur_exception = pg_fetch_row($result)) {
290                                        $recur_exception = $this->GetMessageDAO($row_recur_exception[0]);
291                                        if ($recur_exception instanceof SyncAppointment) {
292                                                if (!isset($message->exceptions)) $message->exceptions = array();
293                                                array_push($message->exceptions, $recur_exception);
294                                        }
295                                }
296
297                                //Eventos Unicos da Recorrencia Deletados
298                                if (isset($row[5]) and $row[5] != "") {
299                                        $array_timestamps_recur_deleted = explode(",",$row[5]);
300                                        foreach ($array_timestamps_recur_deleted as $timestamp_recur_deleted) {
301                                                $recur_deleted = new SyncAppointment();
302                                                $recur_deleted->deleted = '1';
303                                                $recur_deleted->exceptionstarttime = (integer)$timestamp_recur_deleted;
304                                                if (!isset($message->exceptions)) $message->exceptions = array();
305                                                array_push($message->exceptions, $recur_deleted);
306                                        }
307                                }
308                                //TODO: Tratar Participantes do Evento
309                        }
310                        $result = pg_query($this->db,"COMMIT;");
311                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
312                } catch (Exception $e) {
313                        pg_query($this->db,"ROLLBACK;");
314                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine());
315                        return;
316                }
317                return $message;
318        }
319
320        function GetMessage($folderid, $id, $truncsize, $mimesupport = 0) {
321                debugLog('CalendarExpresso::GetMessage('.$folderid.', '.$id.', ..)');
322                if($folderid != "calendar")     return;
323                if(trim($id == "")) return;
324                $message = $this->GetMessageDAO($id);
325                return $message;
326        }
327
328        function DeleteMessage($folderid, $id) {
329                debugLog('CalendarExpresso::DeleteMessage('.$folderid.', '.$id.', ..)');
330                if (!isset($id)) return false;
331                $result = pg_query($this->db, "select owner from phpgw_cal where cal_id = " . $id . ";");
332                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
333                if ($this->_uidnumber != pg_fetch_result($result, 0, 0)) return false;
334                try {
335                        $result = pg_query($this->db,"BEGIN;");
336                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
337                        $result = pg_delete($this->db, "phpgw_cal_user", array('cal_id' => $id));
338                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
339                        $result = pg_delete($this->db, "phpgw_cal", array('reference' => $id));
340                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
341                        $result = pg_delete($this->db, "phpgw_cal_repeats", array('cal_id' => $id));
342                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
343                        $result = pg_query("delete from phpgw_async where id like 'cal:" . $id . "%';");
344                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
345                        $result = pg_delete($this->db, "phpgw_cal_extra", array('cal_id' => $id));
346                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
347                        $result = pg_delete($this->db, "phpgw_cal", array('cal_id' => $id));
348                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
349                        $result = pg_query($this->db,"COMMIT;");
350                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
351                } catch (Exception $e) {
352                        pg_query($this->db,"ROLLBACK;");
353                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine());
354                        return false;
355                }
356                return true;
357        }
358
359        function SetReadFlag($folderid, $id, $flags) {
360                return false;
361        }
362
363        function ChangeMessageDAO($id, $message) {
364                debugLog('CalendarExpresso::ChangeMessageDAO('.$id.', ..)');
365                try {
366                        $result = pg_query($this->db,"BEGIN;");
367                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
368                        $found_cal_id = false;
369                        $found_cal_user = false;
370                        $found_cal_repeats = false;
371                        if ($id != false) {
372                                $result = pg_query($this->db, "select cal_id, cal_type, owner, description from phpgw_cal where cal_id = " . $id . ";");
373                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
374                                // tenta localizar cal_id para fazer Update
375                                while ($row = pg_fetch_row($result)) {
376                                        if(isset($row[0])) {
377                                                if ($this->_uidnumber != $row[2]) return false; // Nao atualiza evento de outro proprietario
378                                                $cal_id = $row[0];
379                                                $cal_type_from_DB = $row[1];
380                                                $description_from_DB = $row[3];
381                                                $found_cal_id = true;
382                                        }
383                                }
384                                // Verifica se ja existe o registro do evento na tabela phpgw_cal_user
385                                $result = pg_query($this->db, "select cal_id, cal_login from phpgw_cal_user where cal_id = " . $cal_id . " and cal_login = '" . $this->_uidnumber . "';");
386                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
387                                if ($row = pg_fetch_row($result)) {
388                                        if(isset($row[0])) {
389                                                $found_cal_user = true;
390                                        }
391                                }
392                                // Verifica se ja existe o registro de recorrencia do evento na tabela phpgw_cal_repeats
393                                $result = pg_query($this->db, "select cal_id from phpgw_cal_repeats where cal_id = " . $cal_id . ";");
394                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
395                                if ($row = pg_fetch_row($result)) {
396                                        if(isset($row[0])) {
397                                                $found_cal_repeats = true;
398                                        }
399                                }
400                        }
401
402                        //Insere/Atualiza tabela phpgw_cal
403                        if(isset($message->uid)) {
404                                $arrayCal["uid"] = $this->truncateString(utf8_decode($message->uid),255);
405                        }
406                        if(isset($message->subject)) {
407                                $arrayCal["title"] = $this->truncateString(utf8_decode($message->subject),299);
408                        }
409                        if(isset($message->location)) {
410                                $arrayCal["location"] = $this->truncateString(utf8_decode($message->location),255);
411                        }
412                        if(isset($message->dtstamp)) {
413                                $arrayCal["mdatetime"] = $message->dtstamp;
414                        }
415                        if(isset($message->starttime)) {
416                                $arrayCal["datetime"] = $message->starttime;
417                        }
418                        if(isset($message->endtime)) {
419                                $arrayCal["edatetime"] = $message->endtime;
420                        }
421                        if(isset($message->sensitivity) and $message->sensitivity == 0) {
422                                $arrayCal["is_public"] = 1; // 1 - Normal
423                        } else $arrayCal["is_public"] = 0; // 0 - Privado
424
425                        if(isset($message->rtf)) {
426                                $rtf_to_ascii = new rtf();
427                                $rtf_to_ascii->output("ascii");
428                                $result_loadrtf = $rtf_to_ascii->loadrtf(base64_decode($message->rtf));
429                                if ($result_loadrtf == true) $rtf_to_ascii->parse();
430                                $arrayCal["description"] = $rtf_to_ascii->out;
431                                //                      } else {
432                                //                              $arrayCal["description"] = '';
433                        }
434                        $arrayCal["category"] = '';
435                        if (isset($message->categories)) {
436                                foreach ($message->categories as $category) {
437                                        $cat_id = $this->addCategory($category);
438                                        if ($cat_id != false) {
439                                                if ($arrayCal["category"] == '') {
440                                                        $arrayCal["category"] = $cat_id;
441                                                } else {
442                                                        $arrayCal["category"] .= ',' . $cat_id;
443                                                }
444                                        }
445                                }
446                        }
447                        $tz_CEL = $this->_getTZFromSyncBlob(base64_decode($message->timezone));
448                        //TODO: Atribuir valores para ex_participants
449                        $arrayCal["ex_participants"] = '';
450                        //TODO: Converter eventos que sao alldayevent para iniciar as 0:00hs e terminar as 23:59hs. Isso porque o Expresso nao suporta alldayevents
451                        //               if(isset($message->alldayevent)) {
452                        //                      $arrayCal["alldayevent"] = $this->truncateString(utf8_decode($message->alldayevent),30);
453                        //               }
454                        if (!$found_cal_id){
455                                $result = pg_query("select nextval('seq_phpgw_cal');");
456                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
457                                $cal_id = pg_fetch_result($result, 0, 0);
458                                $arrayCal["cal_id"] = $cal_id;
459                                $arrayCal["owner"] = $this->_uidnumber;
460                                if (isset($message->recurrence)) $arrayCal["cal_type"] = 'M';
461                                else $arrayCal["cal_type"] = 'E';
462                                $result = pg_insert($this->db, 'phpgw_cal', $arrayCal);
463                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
464                        } else {
465                                if (isset($cal_type_from_DB)) {
466                                        if (isset($message->recurrence)) $arrayCal["cal_type"] = 'M';
467                                        else if ($cal_type_from_DB == 'M') $arrayCal["cal_type"] = 'E';
468                                }
469                                $result = pg_update($this->db, 'phpgw_cal', $arrayCal, array('cal_id' => $cal_id));
470                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
471                        }
472
473                        // Insere/Atualiza tabela phpgw_cal_user
474                        $arrayCalUser["cal_type"] = 'u';
475                        if (!$found_cal_user){
476                                $arrayCalUser["cal_id"] = $cal_id;
477                                $arrayCalUser["cal_login"] = $this->_uidnumber;
478                                //TODO: Tratar os outros valores de cal_status
479                                $arrayCalUser["cal_status"] = 'A';
480                                $result = pg_insert($this->db, 'phpgw_cal_user', $arrayCalUser);
481                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
482                        } else {
483                                $result = pg_update($this->db, 'phpgw_cal_user', $arrayCalUser, array('cal_id' => $cal_id, 'cal_login' => $this->_uidnumber));
484                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
485                        }
486                        if (!$id) {
487                                $id = $cal_id;
488                        }
489
490                        //TODO: Implementar para os tipos 3 e 6. O Expresso ainda nao suporta esses tipos :-(
491                        if (isset($message->recurrence) and ($message->recurrence->type == 0 or $message->recurrence->type == 1 or $message->recurrence->type == 2 or $message->recurrence->type == 5)) {
492                                switch ($message->recurrence->type) {
493                                        case 0: //repeticao diaria
494                                                $arrayRecur["recur_type"] = 1;
495                                                $type_name = "day";
496                                                break;
497                                        case 1: //repeticao semanal
498                                                $arrayRecur["recur_type"] = 2;
499                                                $type_name = "week";
500                                                break;
501                                        case 2: //repeticao mensal por data
502                                                $arrayRecur["recur_type"] = 3;
503                                                $type_name = "month";
504                                                break;
505                                        case 5: //repeticao anual por data
506                                                $arrayRecur["recur_type"] = 5;
507                                                $type_name = "year";
508                                                break;
509                                }
510                                if (isset($message->recurrence->interval)) {
511                                        $arrayRecur["recur_interval"] = $message->recurrence->interval;
512                                }
513                                if ($message->recurrence->type == 1 or $message->recurrence->type == 3 or $message->recurrence->type == 6) {
514                                        if (isset($message->recurrence->dayofweek)) {
515                                                $arrayRecur["recur_data"] = $message->recurrence->dayofweek;
516                                                /*$day = $message->recurrence->dayofweek;
517                                                 $day_of_week_counter = 0;
518                                                 if (($day & 1) > 0) $day_of_week_counter++;
519                                                 if (($day & 2) > 0) $day_of_week_counter++;
520                                                 if (($day & 4) > 0) $day_of_week_counter++;
521                                                 if (($day & 8) > 0) $day_of_week_counter++;
522                                                 if (($day & 16) > 0) $day_of_week_counter++;
523                                                 if (($day & 32) > 0) $day_of_week_counter++;
524                                                 if (($day & 64) > 0) $day_of_week_counter++;*/
525                                        }
526                                }
527                                //TODO: Converter ocurrences para until.
528                                /*if (!isset($message->recurrence->until) and (isset($message->recurrence->occurrences))) {
529                                $tz = date_default_timezone_get();
530                                date_default_timezone_set('UTC');
531                                $message->recurrence->until = strtotime(date("Y-m-d H:i:s", $message->starttime) . " +" . $message->recurrence->occurrences * $message->recurrence->interval . " " . $type_name);
532                                unset($message->recurrence->occurrences);
533                                date_default_timezone_set($tz);
534                                }*/
535                                if (isset($message->recurrence->until)){
536                                        $defaultTZ = new DateTimeZone(date_default_timezone_get());
537                                        $gmtTZ = new DateTimeZone('GMT');
538                                        $gmtDate = new DateTime("now", $gmtTZ);
539                                        $GMT_EX = $defaultTZ->getOffset($gmtDate);
540                                        $GMT_CEL = -(($tz_CEL["bias"] + $tz_CEL["dstbias"]) * 60);
541
542                                        $tz = date_default_timezone_get();
543                                        date_default_timezone_set('UTC');
544                                        $day_CEL = date("d", $message->starttime +  $GMT_CEL);
545                                        $day_EX = date("d", $message->starttime +  $GMT_EX);
546
547                                        if ($day_EX > $day_CEL) $arrayRecur["recur_enddate"] = $message->recurrence->until + $GMT_CEL - $GMT_EX + 86400;
548                                        else if ($day_EX < $day_CEL) $arrayRecur["recur_enddate"] = $message->recurrence->until + $GMT_CEL - $GMT_EX - 86400;
549                                        else $arrayRecur["recur_enddate"] = $message->recurrence->until;
550                                        date_default_timezone_set($tz);
551                                        /*$arrayRecur["recur_enddate"] = $message->recurrence->until - $offsetTZ;
552                                         $hour = date("G", $message->starttime - (($tz["bias"] - $tz["dstbias"]) * 60));
553                                         $min = date("i", $message->starttime - (($tz["bias"] - $tz["dstbias"]) * 60));
554                                         $sec = date("s", $message->starttime - (($tz["bias"] - $tz["dstbias"]) * 60));
555                                               
556                                         $arrayRecur["recur_enddate"] = $message->recurrence->until + ($hour * 3600) + ($min * 60) + $sec + $offsetTZ + (($tz["bias"] - $tz["dstbias"]) * 60);*/
557                                } else {
558                                        $arrayRecur["recur_enddate"] = 1893283200; // Se nao tem data de termino seta para 30/12/2029
559                                }
560
561                                // Trata excecoes da recorrencia
562                                if (isset($message->exceptions)){
563                                        // Tem Excecoes de recorrencia do tipo Edicao
564                                        // Verifica se ja existe o registro do evento de excecao de recorrencia na tabela phpgw_cal
565                                        $recur_exception_changed_ids = "";
566                                        $recur_exception_deleted_starttimes = "";
567                                        foreach ($message->exceptions as $recur_exception) {
568                                                if ($recur_exception->deleted == 0){ //Tem Excecoes do Tipo Edicao
569                                                        $found_recur_exception_changed = true;
570                                                        if (isset($arrayExceptCal)) unset($arrayExceptCal);
571                                                        if (isset($arrayExceptCalUser)) unset($arrayExceptCalUser);
572                                                        if (isset($except_cal_id)) unset($except_cal_id);
573                                                        if (isset($except_cal_type_from_DB)) unset($except_cal_type_from_DB);
574                                                        if (isset($except_description_from_DB)) unset($except_description_from_DB);
575                                                        $found_except_cal_id = false;
576                                                        $found_except_cal_user = false;
577                                                        $result = pg_query($this->db, "select cal_id, cal_type, description from phpgw_cal where reference = " . $id . " and datetime = " . $recur_exception->exceptionstarttime . ";");
578                                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
579                                                        // tenta localizar cal_id para fazer Update
580                                                        while ($row = pg_fetch_row($result)) {
581                                                                if(isset($row[0])) {
582                                                                        $except_cal_id = $row[0];
583                                                                        $except_cal_type_from_DB = $row[1];
584                                                                        $except_description_from_DB = $row[2];
585                                                                        $found_except_cal_id = true;
586                                                                }
587                                                        }
588                                                        // Verifica se ja existe o registro do evento de excecao de recorrencia na tabela phpgw_cal_user
589                                                        if (isset($except_cal_id)) {
590                                                                $result = pg_query($this->db, "select cal_id, cal_login from phpgw_cal_user where cal_id = " . $except_cal_id . " and cal_login = '" . $this->_uidnumber . "';");
591                                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
592                                                                if ($row = pg_fetch_row($result)) {
593                                                                        if(isset($row[0])) {
594                                                                                $found_except_cal_user = true;
595                                                                        }
596                                                                }
597                                                        }
598                                                        //Insere/Atualiza tabela phpgw_cal
599                                                        $arrayExceptCal["reference"] = $cal_id;
600                                                        if(isset($message->uid)) {
601                                                                $arrayExceptCal["uid"] = $this->truncateString(utf8_decode($message->uid),255);
602                                                        }
603                                                        if(isset($recur_exception->subject)) {
604                                                                $arrayExceptCal["title"] = $this->truncateString(utf8_decode($recur_exception->subject),299);
605                                                        } elseif(isset($message->subject)) {
606                                                                $arrayExceptCal["title"] = $this->truncateString(utf8_decode($message->subject),299);
607                                                        }
608                                                        if(isset($recur_exception->location)) {
609                                                                $arrayExceptCal["location"] = $this->truncateString(utf8_decode($recur_exception->location),255);
610                                                        } else if(isset($message->location)) {
611                                                                $arrayExceptCal["location"] = $this->truncateString(utf8_decode($message->location),255);
612                                                        }
613                                                        if(isset($recur_exception->dtstamp)) {
614                                                                $arrayExceptCal["mdatetime"] = $recur_exception->dtstamp;
615                                                        } elseif(isset($message->dtstamp)) {
616                                                                $arrayExceptCal["mdatetime"] = $message->dtstamp;
617                                                        }
618                                                        if(isset($recur_exception->starttime)) {
619                                                                $arrayExceptCal["datetime"] = $recur_exception->starttime;
620                                                        } else if(isset($message->starttime)) {
621                                                                $arrayExceptCal["datetime"] = $message->starttime;
622                                                        }
623                                                        if(isset($recur_exception->endtime)) {
624                                                                $arrayExceptCal["edatetime"] = $recur_exception->endtime;
625                                                        }elseif(isset($message->endtime)) {
626                                                                $arrayExceptCal["edatetime"] = $message->endtime;
627                                                        }
628                                                        if(isset($recur_exception->sensitivity) and $recur_exception->sensitivity == 0) {
629                                                                $arrayExceptCal["is_public"] = 1; // 1 - Normal
630                                                        }elseif (isset($recur_exception->sensitivity) and $recur_exception->sensitivity == 1){
631                                                                $arrayExceptCal["is_public"] = 0; // 0 - Privado
632                                                        }elseif(isset($message->sensitivity) and $message->sensitivity == 0) {
633                                                                $arrayExceptCal["is_public"] = 1; // 1 - Normal
634                                                        }else $arrayExceptCal["is_public"] = 0; // 0 - Privado
635                                                        if (isset($recur_exception->body)) {
636                                                                $arrayExceptCal["description"] = utf8_decode($recur_exception->body);
637                                                        } elseif (!isset($except_description_from_DB)) {
638                                                                if (isset($message->rtf)) {
639                                                                        $rtf_to_ascii = new rtf();
640                                                                        $rtf_to_ascii->output("ascii");
641                                                                        $result_loadrtf = $rtf_to_ascii->loadrtf(base64_decode($message->rtf));
642                                                                        if ($result_loadrtf == true) $rtf_to_ascii->parse();
643                                                                        $arrayExceptCal["description"] = $rtf_to_ascii->out;
644                                                                } elseif (isset($description_from_DB)) {
645                                                                        $arrayExceptCal["description"] = utf8_decode($description_from_DB);
646                                                                }
647                                                        }
648                                                        $arrayExceptCal["category"] = '';
649                                                        if (isset($recur_exception->categories)) {
650                                                                foreach ($recur_exception->categories as $category) {
651                                                                        $cat_id = $this->addCategory($category);
652                                                                        if ($cat_id != false) {
653                                                                                if ($arrayExceptCal["category"] == '') {
654                                                                                        $arrayExceptCal["category"] = $cat_id;
655                                                                                } else {
656                                                                                        $arrayExceptCal["category"] .= ',' . $cat_id;
657                                                                                }
658                                                                        }
659                                                                }
660                                                        }elseif (isset($message->categories)) {
661                                                                foreach ($message->categories as $category) {
662                                                                        $cat_id = $this->addCategory($category);
663                                                                        if ($cat_id != false) {
664                                                                                if ($arrayExceptCal["category"] == '') {
665                                                                                        $arrayExceptCal["category"] = $cat_id;
666                                                                                } else {
667                                                                                        $arrayExceptCal["category"] .= ',' . $cat_id;
668                                                                                }
669                                                                        }
670                                                                }
671                                                        }
672                                                        //TODO: Converter eventos que sao alldayevent para iniciar as 0:00hs e terminar as 23:59hs. Isso porque o Expresso nao suporta alldayevents
673                                                        //               if(isset($message->alldayevent)) {
674                                                        //                      $arrayCal["alldayevent"] = $this->truncateString(utf8_decode($message->alldayevent),30);
675                                                        //               }
676                                                        if (!$found_except_cal_id){
677                                                                $result = pg_query("select nextval('seq_phpgw_cal');");
678                                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
679                                                                $except_cal_id = pg_fetch_result($result, 0, 0);
680                                                                $arrayExceptCal["cal_id"] = $except_cal_id;
681                                                                $arrayExceptCal["owner"] = $this->_uidnumber;
682                                                                $arrayExceptCal["cal_type"] = 'E';
683                                                                $result = pg_insert($this->db, 'phpgw_cal', $arrayExceptCal);
684                                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
685                                                        } else {
686                                                                $result = pg_update($this->db, 'phpgw_cal', $arrayExceptCal, array('cal_id' => $except_cal_id));
687                                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
688                                                        }
689
690                                                        // Insere/Atualiza Excecoes de Recorrencia na tabela phpgw_cal_user
691                                                        $arrayExceptCalUser["cal_type"] = 'u';
692                                                        if (!$found_except_cal_user){
693                                                                $arrayExceptCalUser["cal_id"] = $except_cal_id;
694                                                                $arrayExceptCalUser["cal_login"] = $this->_uidnumber;
695                                                                //TODO: Tratar os outros valores de cal_status
696                                                                $arrayExceptCalUser["cal_status"] = 'A';
697                                                                $result = pg_insert($this->db, 'phpgw_cal_user', $arrayExceptCalUser);
698                                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
699                                                        } else {
700                                                                $result = pg_update($this->db, 'phpgw_cal_user', $arrayExceptCalUser, array('cal_id' => $except_cal_id, 'cal_login' => $this->_uidnumber));
701                                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
702                                                        }
703                                                        if ($recur_exception_changed_ids == "") {
704                                                                $recur_exception_changed_ids = $except_cal_id;
705                                                        } else {
706                                                                $recur_exception_changed_ids .= "," . $except_cal_id;
707                                                        }
708                                                } else {
709                                                        if ($recur_exception_deleted_starttimes == "") {
710                                                                $recur_exception_deleted_starttimes = $recur_exception->exceptionstarttime;
711                                                        } else {
712                                                                $recur_exception_deleted_starttimes .= "," . $recur_exception->exceptionstarttime;
713                                                        }
714                                                }
715                                        }
716                                        if ($recur_exception_deleted_starttimes != "") {
717                                                //Tem Excecoes de recorrencia do tipo Exclusao
718                                                $arrayRecur["recur_exception"] = $recur_exception_deleted_starttimes;
719                                        } else {
720                                                $arrayRecur["recur_exception"] = "";
721                                        }
722                                        if ($recur_exception_changed_ids == "") {
723                                                // Se nao tem excecoes de recorrencia do tipo edicao, entao deleta as excecoes da recorrencia
724                                                $result = pg_query($this->db, "delete from phpgw_cal_user where cal_id in (select cal_id from phpgw_cal where reference = " . $cal_id . ");");
725                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
726                                                $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . ";");
727                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
728                                        } else {
729                                                //Deleta as excecoes da recorrencia, exceto as inseridas/atualizadas acima
730                                                $result = pg_query($this->db, "delete from phpgw_cal_user where cal_id in (select cal_id from phpgw_cal where reference = " . $cal_id . " and cal_id not in (" . $recur_exception_changed_ids . "));");
731                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
732                                                $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . " and cal_id not in (" . $recur_exception_changed_ids . ");");
733                                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
734                                        }
735                                } else {
736                                        // Se nao tem excecoes da recorrencia entao
737                                        $arrayRecur["recur_exception"] = "";
738                                        $result = pg_query($this->db, "delete from phpgw_cal_user where cal_id in (select cal_id from phpgw_cal where reference = " . $cal_id . ");");
739                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
740                                        $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . ";");
741                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
742
743                                }
744                                if (!$found_cal_repeats){
745                                        $arrayRecur["cal_id"] = $cal_id;
746                                        $result = pg_insert($this->db, 'phpgw_cal_repeats', $arrayRecur);
747                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
748                                } else {
749                                        $result = pg_update($this->db, 'phpgw_cal_repeats', $arrayRecur, array('cal_id' => $cal_id));
750                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
751                                }
752                        } elseif ($found_cal_id) {
753                                // Se nao tem recorrencia entao
754                                $result = pg_query($this->db, "delete from phpgw_cal_user where cal_id in (select cal_id from phpgw_cal where reference = " . $cal_id . ");");
755                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
756                                $result = pg_query($this->db, "delete from phpgw_cal where reference = " . $cal_id . ";");
757                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
758                                $result = pg_query($this->db, "delete from phpgw_cal_repeats where cal_id = " . $cal_id . ";");
759                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
760                        }
761                        $result = pg_query($this->db,"COMMIT;");
762                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
763                        //TODO: Implementar Participantes
764                } catch (Exception $e) {
765                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine());
766                        pg_query($this->db,"ROLLBACK;");
767                        return false;
768                }
769                return $id;
770        }
771
772        function ChangeMessage($folderid, $id, $message) {
773                debugLog('CalendarExpresso::ChangeMessage('.$folderid.', '.$id.', ..)');
774                $id = $this->ChangeMessageDAO($id, $message);
775                if ($id != false) return $this->StatMessage($folderid, $id);
776                else return false;
777        }
778
779        function MoveMessage($folderid, $id, $newfolderid) {
780                return false;
781        }
782
783        function addCategory($category) {
784                $cat_id = false;
785                try {
786                        $result = pg_query($this->db,"BEGIN;");
787                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
788                        $result = pg_query("SELECT cat_id from phpgw_categories WHERE cat_owner = -1 AND cat_appname = 'calendar' AND LOWER(to_ASCII(cat_name)) = '" . trim(strtolower($this->removeAccents(utf8_decode($category)))) . "';");
789                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
790                        if (!($cat_id = pg_fetch_result($result, 0, 0))){
791                                $result = pg_query("SELECT cat_id from phpgw_categories WHERE cat_owner = " . $this->_uidnumber . " AND cat_appname = 'calendar' AND LOWER(to_ASCII(cat_name)) = '" . trim(strtolower($this->removeAccents(utf8_decode($category)))) . "';");
792                                if ($result == FALSE) throw new Exception(pg_last_error($this->db));
793                                if (!($cat_id = pg_fetch_result($result, 0, 0))){
794                                        $result = pg_query("select nextval('seq_phpgw_categories');");
795                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
796                                        $cat_id = pg_fetch_result($result, 0, 0);
797                                        $arrayCat["cat_id"] = $cat_id;
798                                        $arrayCat["cat_owner"] = $this->_uidnumber;
799                                        $arrayCat["cat_access"] = 'public';
800                                        $arrayCat["cat_appname"] = 'calendar';
801                                        $arrayCat["cat_name"] = utf8_decode($category);
802                                        $arrayCat["cat_description"] = '';
803                                        $arrayCat["cat_data"] = 'N;';
804                                        $arrayCat["last_mod"] = time();
805                                        $result = pg_insert($this->db, 'phpgw_categories', $arrayCat);
806                                        if ($result == FALSE) throw new Exception(pg_last_error($this->db));
807                                }
808                        }
809                } catch (Exception $e) {
810                        pg_query($this->db,"ROLLBACK;");
811                        debugLog("exception -> " . $e->getMessage() . " - ARQUIVO: " . $e->getFile() . " - LINHA: " . $e->getLine());
812                        return false;
813                }
814                return $cat_id;
815        }
816
817        // -----------------------------------
818
819        function escape($data){
820                if (is_array($data)) {
821                        foreach ($data as $key => $val) {
822                                $data[$key] = $this->escape($val);
823                        }
824                        return $data;
825                }
826                $data = str_replace("\r\n", "\n", $data);
827                $data = str_replace("\r", "\n", $data);
828                $data = str_replace(array('\\', ';', ',', "\n"), array('\\\\', '\\;', '\\,', '\\n'), $data);
829                return $data;
830        }
831
832        function unescape($data){
833                $data = str_replace(array('\\\\', '\\;', '\\,', '\\n','\\N'),array('\\', ';', ',', "\n", "\n"),$data);
834                return $data;
835        }
836
837        function  removeAccents($data){
838                $data = strtr($data,"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÚÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùüúþÿ","aaaaaaaceeeeiiii noooooxouuutbaaaaaaaceeeeiiii nooooo/ouuuty");
839                return $data;
840        }
841
842        function truncateString($string, $size)
843        {
844                if(strlen($string) <= $size) return $string;
845                else return substr($string, 0, $size - 1);
846        }
847
848        function parseUser($id_user)
849        {
850                $pos = strripos($id_user, '\\');
851                if ($pos === false) {
852                        if (strlen($id_user) < 1) return false;
853                        else return $id_user;
854                } else {
855                        if (strlen($id_user) <= $pos + 1) {
856                                return false;
857                        } else {
858                                return substr(substr($id_user, $pos + 1), 0, strlen(substr($id_user, $pos + 1)));
859                        }
860                }
861        }
862
863        function _getGMTTZ() {
864                //$tz = array("bias" => 0, "stdbias" => 0, "dstbias" => 0, "dstendyear" => 0, "dstendmonth" => 2, "dstendday" => 0, "dstendweek" => 2, "dstendhour" => 2, "dstendminute" => 0, "dstendsecond" => 0, "dstendmillis" => 0,
865                //                              "dststartyear" => 0, "dststartmonth" =>10, "dststartday" =>0, "dststartweek" => 3, "dststarthour" => 2, "dststartminute" => 0, "dststartsecond" => 0, "dststartmillis" => 0);
866                $tz = array("bias" => 120, "stdbias" => 0, "dstbias" => -60, "dstendyear" => 0, "dstendmonth" => 2, "dstendday" => 0, "dstendweek" => 2, "dstendhour" => 2, "dstendminute" => 0, "dstendsecond" => 0, "dstendmillis" => 0,
867                                                      "dststartyear" => 0, "dststartmonth" =>10, "dststartday" =>0, "dststartweek" => 3, "dststarthour" => 2, "dststartminute" => 0, "dststartsecond" => 0, "dststartmillis" => 0);
868                return $tz;
869        }
870
871        // Unpack timezone info from Sync
872        function _getTZFromSyncBlob($data) {
873                $tz = unpack(    "lbias/a64name/vdstendyear/vdstendmonth/vdstendday/vdstendweek/vdstendhour/vdstendminute/vdstendsecond/vdstendmillis/" .
874                        "lstdbias/a64name/vdststartyear/vdststartmonth/vdststartday/vdststartweek/vdststarthour/vdststartminute/vdststartsecond/vdststartmillis/" .
875                        "ldstbias", $data);
876
877                // Make the structure compatible with class.recurrence.php
878                $tz["timezone"] = $tz["bias"];
879                $tz["timezonedst"] = $tz["dstbias"];
880
881                return $tz;
882        }
883
884        // Pack timezone info for Sync
885        function _getSyncBlobFromTZ($tz) {
886                $packed = pack("la64vvvvvvvv" . "la64vvvvvvvv" . "l",
887                $tz["bias"], "", 0, $tz["dstendmonth"], $tz["dstendday"], $tz["dstendweek"], $tz["dstendhour"], $tz["dstendminute"], $tz["dstendsecond"], $tz["dstendmillis"],
888                $tz["stdbias"], "", 0, $tz["dststartmonth"], $tz["dststartday"], $tz["dststartweek"], $tz["dststarthour"], $tz["dststartminute"], $tz["dststartsecond"], $tz["dststartmillis"],
889                $tz["dstbias"]);
890
891                return $packed;
892        }
893
894        // Authenticate user and return UIDNumber attribute on success
895        function authUser($user, $pwd) {
896                $ldap = new AuthLDAP();
897                $uid_number = ($ldap->bind($user,$pwd));
898                $ldap->disconnect();
899                unset($ldap);
900                if (! $uid_number) return false;
901                return $uid_number;
902        }
903};
904?>
Note: See TracBrowser for help on using the repository browser.