Changeset 4000 for contrib/z-push/backend/BackendCalendarExpresso.php
- Timestamp:
- 04/13/11 10:07:27 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/z-push/backend/BackendCalendarExpresso.php
r3637 r4000 11 11 * Consult LICENSE file for details 12 12 ************************************************/ 13 include_once('diffbackend.php'); 14 include_once('include/z_RTF.php'); 15 include_once "include/dbconnect.php"; 13 require_once("diffbackend.php"); 14 require_once("include/z_RTF.php"); 15 require_once("include/dbconnect.php"); 16 require_once("include/authldap.php"); 16 17 17 18 class BackendCalendarExpresso extends BackendDiff { 18 var $_user;19 var $_devid;20 var $_protocolversion;21 19 var $db; 20 var $_uidnumber; 22 21 23 22 function __construct() … … 26 25 27 26 if (!$this->db) { 28 echo " A DB connect error occured.\n";27 echo "Erro de conexao com o banco.\n"; 29 28 exit; 30 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; 31 36 } 32 37 … … 35 40 $this->_devid = $devid; 36 41 $this->_protocolversion = $protocolversion; 37 //TODO: Autenticar Usuario no LDAP38 39 42 return true; 40 43 } … … 49 52 50 53 function GetMessageList($folderid, $cutoffdate) { 51 $id_owner = $this->parseOwner($this->_user); 52 if ($id_owner == false) return false; 53 54 debugLog('CalendarExpresso::GetMessageList('.$id_owner.')'); 54 debugLog('CalendarExpresso::GetMessageList('.$this->_uidnumber.')'); 55 55 if ($folderid != "calendar") return false; 56 56 … … 59 59 $result = pg_query($this->db,"BEGIN;"); 60 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 ='" . $ id_owner . "'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 ='" . $ id_owner . "'and c.reference = 0 and c.edatetime > " . $cutoffdate . ";");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 63 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 64 64 while ($row = pg_fetch_row($result)) { … … 88 88 function GetFolderList() { 89 89 debugLog('CalendarExpresso::GetFolderList()'); 90 $calendars = array();91 90 $folder = $this->StatFolder("calendar"); 92 $calendars[] = $folder;93 //return $calendars;94 91 return $folder; 95 92 } … … 327 324 $message = $this->GetMessageDAO($id); 328 325 return $message; 329 330 //$message->????? //phpgw_cal.priority (1 - baixa, 2 - normal, 3 - alta) //Quando for criar um registro o valor será 2.331 //$message->????? //phpgw_cal.groups (Não vou atribuir nenhum valor)332 //$message->????? //phpgw_cal.cal_type (quando for criar um novo registro vou inserir R para Recursivo e E para não recursivo). Quando Alterar um registro entre de Recursivo para não Recursivo e vice-versa vou fazer o mesmo da inclusão. Quando alterar entre dois tipos não recursivos, não faço nada.333 //$message->????? //phpgw_cal.ex_participants334 //$message->????? //phpgw_cal_user.cal_status335 //$message->????? //phpgw_cal_user.cal_type336 //$message->????? //phpgw_cal_repeats.recur_interval337 //$message->????? //phpgw_cal_repeats.recur_data338 //$message->????? //phpgw_cal_repeats.recur_exception339 340 //$message->timezone //phpgw?????341 //$message->organizername //phpgw?????342 //$message->organizeremail //phpgw????343 //$message->attendees // phpgw???? (SyncAttendee array)344 345 //$syncAttendee = new SyncAttendee();346 //$syncAttendee->email //phpgw????347 //$syncAttendee->name //phpgw????348 326 } 349 327 … … 351 329 debugLog('CalendarExpresso::DeleteMessage('.$folderid.', '.$id.', ..)'); 352 330 if (!isset($id)) return false; 353 $id_owner = $this->parseOwner($this->_user);354 if ($id_owner == false) return false;355 331 $result = pg_query($this->db, "select owner from phpgw_cal where cal_id = " . $id . ";"); 356 332 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 357 if ($ id_owner != pg_fetch_result($result, 0, 0)) return false;333 if ($this->_uidnumber != pg_fetch_result($result, 0, 0)) return false; 358 334 try { 359 335 $result = pg_query($this->db,"BEGIN;"); … … 387 363 function ChangeMessageDAO($id, $message) { 388 364 debugLog('CalendarExpresso::ChangeMessageDAO('.$id.', ..)'); 389 $id_owner = $this->parseOwner($this->_user);390 if ($id_owner == false) return false;391 365 try { 392 366 $result = pg_query($this->db,"BEGIN;"); … … 396 370 $found_cal_repeats = false; 397 371 if ($id != false) { 398 $result = pg_query($this->db, "select cal_id, cal_type, owner from phpgw_cal where cal_id = " . $id . ";");372 $result = pg_query($this->db, "select cal_id, cal_type, owner, description from phpgw_cal where cal_id = " . $id . ";"); 399 373 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 400 374 // tenta localizar cal_id para fazer Update 401 375 while ($row = pg_fetch_row($result)) { 402 376 if(isset($row[0])) { 403 if ($ id_owner != $row[2]) return false; // Nao atualiza evento de outro proprietario377 if ($this->_uidnumber != $row[2]) return false; // Nao atualiza evento de outro proprietario 404 378 $cal_id = $row[0]; 405 379 $cal_type_from_DB = $row[1]; 380 $description_from_DB = $row[3]; 406 381 $found_cal_id = true; 407 382 } 408 383 } 409 384 // Verifica se ja existe o registro do evento na tabela phpgw_cal_user 410 $result = pg_query($this->db, "select cal_id, cal_login from phpgw_cal_user where cal_id = " . $cal_id . " and cal_login = '" . $ id_owner . "';");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 . "';"); 411 386 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 412 387 if ($row = pg_fetch_row($result)) { … … 430 405 } 431 406 if(isset($message->subject)) { 432 $arrayCal["title"] = $this->truncateString(utf8_decode($message->subject), 80);407 $arrayCal["title"] = $this->truncateString(utf8_decode($message->subject),299); 433 408 } 434 409 if(isset($message->location)) { … … 454 429 if ($result_loadrtf == true) $rtf_to_ascii->parse(); 455 430 $arrayCal["description"] = $rtf_to_ascii->out; 456 // } else {457 // $arrayCal["description"] = '';431 // } else { 432 // $arrayCal["description"] = ''; 458 433 } 459 434 $arrayCal["category"] = ''; … … 482 457 $cal_id = pg_fetch_result($result, 0, 0); 483 458 $arrayCal["cal_id"] = $cal_id; 484 $arrayCal["owner"] = $ id_owner;459 $arrayCal["owner"] = $this->_uidnumber; 485 460 if (isset($message->recurrence)) $arrayCal["cal_type"] = 'M'; 486 461 else $arrayCal["cal_type"] = 'E'; … … 500 475 if (!$found_cal_user){ 501 476 $arrayCalUser["cal_id"] = $cal_id; 502 $arrayCalUser["cal_login"] = $ id_owner;477 $arrayCalUser["cal_login"] = $this->_uidnumber; 503 478 //TODO: Tratar os outros valores de cal_status 504 479 $arrayCalUser["cal_status"] = 'A'; … … 506 481 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 507 482 } else { 508 $result = pg_update($this->db, 'phpgw_cal_user', $arrayCalUser, array('cal_id' => $cal_id, 'cal_login' => $ id_owner));483 $result = pg_update($this->db, 'phpgw_cal_user', $arrayCalUser, array('cal_id' => $cal_id, 'cal_login' => $this->_uidnumber)); 509 484 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 510 485 } … … 574 549 else $arrayRecur["recur_enddate"] = $message->recurrence->until; 575 550 date_default_timezone_set($tz); 576 /* //$arrayRecur["recur_enddate"] = $message->recurrence->until - $offsetTZ;551 /*$arrayRecur["recur_enddate"] = $message->recurrence->until - $offsetTZ; 577 552 $hour = date("G", $message->starttime - (($tz["bias"] - $tz["dstbias"]) * 60)); 578 553 $min = date("i", $message->starttime - (($tz["bias"] - $tz["dstbias"]) * 60)); … … 586 561 // Trata excecoes da recorrencia 587 562 if (isset($message->exceptions)){ 588 //if ($recur_exception_changed_starttimes != "") { 589 //Tem Excecoes de recorrencia do tipo Edicao 563 // Tem Excecoes de recorrencia do tipo Edicao 590 564 // Verifica se ja existe o registro do evento de excecao de recorrencia na tabela phpgw_cal 591 //foreach ($array_recur_exception_changed_starttime as $except_starttime) {592 565 $recur_exception_changed_ids = ""; 593 566 $recur_exception_deleted_starttimes = ""; … … 599 572 if (isset($except_cal_id)) unset($except_cal_id); 600 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); 601 575 $found_except_cal_id = false; 602 576 $found_except_cal_user = false; 603 $result = pg_query($this->db, "select cal_id, cal_type from phpgw_cal where reference = " . $id . " and datetime = " . $recur_exception->exceptionstarttime . ";");577 $result = pg_query($this->db, "select cal_id, cal_type, description from phpgw_cal where reference = " . $id . " and datetime = " . $recur_exception->exceptionstarttime . ";"); 604 578 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 605 579 // tenta localizar cal_id para fazer Update … … 608 582 $except_cal_id = $row[0]; 609 583 $except_cal_type_from_DB = $row[1]; 584 $except_description_from_DB = $row[2]; 610 585 $found_except_cal_id = true; 611 586 } … … 613 588 // Verifica se ja existe o registro do evento de excecao de recorrencia na tabela phpgw_cal_user 614 589 if (isset($except_cal_id)) { 615 $result = pg_query($this->db, "select cal_id, cal_login from phpgw_cal_user where cal_id = " . $except_cal_id . " and cal_login = '" . $ id_owner . "';");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 . "';"); 616 591 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 617 592 if ($row = pg_fetch_row($result)) { … … 627 602 } 628 603 if(isset($recur_exception->subject)) { 629 $arrayExceptCal["title"] = $this->truncateString(utf8_decode($recur_exception->subject), 80);604 $arrayExceptCal["title"] = $this->truncateString(utf8_decode($recur_exception->subject),299); 630 605 } elseif(isset($message->subject)) { 631 $arrayExceptCal["title"] = $this->truncateString(utf8_decode($message->subject), 80);606 $arrayExceptCal["title"] = $this->truncateString(utf8_decode($message->subject),299); 632 607 } 633 608 if(isset($recur_exception->location)) { … … 658 633 $arrayExceptCal["is_public"] = 1; // 1 - Normal 659 634 }else $arrayExceptCal["is_public"] = 0; // 0 - Privado 660 if(isset($recur_exception->rtf) or isset($message->rtf)) { 661 $rtf_to_ascii = new rtf(); 662 $rtf_to_ascii->output("ascii"); 663 if(isset($recur_exception->rtf)) $result_loadrtf = $rtf_to_ascii->loadrtf(base64_decode($recur_exception->rtf)); 664 elseif(isset($message->rtf)) $result_loadrtf = $rtf_to_ascii->loadrtf(base64_decode($message->rtf)); 665 if ($result_loadrtf == true) $rtf_to_ascii->parse(); 666 $arrayExceptCal["description"] = $rtf_to_ascii->out; 667 // } else { 668 // $arrayExceptCal["description"] = ''; 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 } 669 647 } 670 648 $arrayExceptCal["category"] = ''; … … 701 679 $except_cal_id = pg_fetch_result($result, 0, 0); 702 680 $arrayExceptCal["cal_id"] = $except_cal_id; 703 $arrayExceptCal["owner"] = $ id_owner;681 $arrayExceptCal["owner"] = $this->_uidnumber; 704 682 $arrayExceptCal["cal_type"] = 'E'; 705 683 $result = pg_insert($this->db, 'phpgw_cal', $arrayExceptCal); … … 714 692 if (!$found_except_cal_user){ 715 693 $arrayExceptCalUser["cal_id"] = $except_cal_id; 716 $arrayExceptCalUser["cal_login"] = $ id_owner;694 $arrayExceptCalUser["cal_login"] = $this->_uidnumber; 717 695 //TODO: Tratar os outros valores de cal_status 718 696 $arrayExceptCalUser["cal_status"] = 'A'; … … 720 698 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 721 699 } else { 722 $result = pg_update($this->db, 'phpgw_cal_user', $arrayExceptCalUser, array('cal_id' => $except_cal_id, 'cal_login' => $ id_owner));700 $result = pg_update($this->db, 'phpgw_cal_user', $arrayExceptCalUser, array('cal_id' => $except_cal_id, 'cal_login' => $this->_uidnumber)); 723 701 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 724 702 } … … 805 783 function addCategory($category) { 806 784 $cat_id = false; 807 $id_owner = $this->parseOwner($this->_user);808 if ($id_owner == false) return false;809 785 try { 810 786 $result = pg_query($this->db,"BEGIN;"); … … 813 789 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 814 790 if (!($cat_id = pg_fetch_result($result, 0, 0))){ 815 $result = pg_query("SELECT cat_id from phpgw_categories WHERE cat_owner = " . $ id_owner . " AND cat_appname = 'calendar' AND LOWER(to_ASCII(cat_name)) = '" . trim(strtolower($this->removeAccents(utf8_decode($category)))) . "';");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)))) . "';"); 816 792 if ($result == FALSE) throw new Exception(pg_last_error($this->db)); 817 793 if (!($cat_id = pg_fetch_result($result, 0, 0))){ … … 820 796 $cat_id = pg_fetch_result($result, 0, 0); 821 797 $arrayCat["cat_id"] = $cat_id; 822 $arrayCat["cat_owner"] = $ id_owner;798 $arrayCat["cat_owner"] = $this->_uidnumber; 823 799 $arrayCat["cat_access"] = 'public'; 824 800 $arrayCat["cat_appname"] = 'calendar'; … … 851 827 $data = str_replace("\r", "\n", $data); 852 828 $data = str_replace(array('\\', ';', ',', "\n"), array('\\\\', '\\;', '\\,', '\\n'), $data); 853 //return u2wi($data);854 829 return $data; 855 830 } … … 871 846 } 872 847 873 function parse Owner($id_owner)848 function parseUser($id_user) 874 849 { 875 $pos = strripos($id_ owner, '\\');850 $pos = strripos($id_user, '\\'); 876 851 if ($pos === false) { 877 if (strlen($id_ owner) <= 2) return false;878 else return substr($id_owner, 0, strlen($id_owner)-2);852 if (strlen($id_user) < 1) return false; 853 else return $id_user; 879 854 } else { 880 if (strlen($id_ owner) <= $pos + 3) {855 if (strlen($id_user) <= $pos + 1) { 881 856 return false; 882 857 } else { 883 return substr(substr($id_ owner, $pos + 1), 0, strlen(substr($id_owner, $pos + 1))-2);858 return substr(substr($id_user, $pos + 1), 0, strlen(substr($id_user, $pos + 1))); 884 859 } 885 860 } … … 916 891 return $packed; 917 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 } 918 903 }; 919 904 ?>
Note: See TracChangeset
for help on using the changeset viewer.