Overview

Packages

  • awl
    • caldav-client-v2
    • RRule
  • davical
    • authentication
      • drivers
    • caldav
    • DAViCalSession
    • DAVTicket
    • external-bind
    • feed
    • HTTPAuthSession
    • iSchedule
    • iSchedule-POST
    • logging
    • metrics
    • Principal
    • propfind
    • PublicSession
    • Request
    • Resource
    • tzservice
  • None
  • PHP

Classes

  • CalDAVClient
  • CheckResult
  • setupFakeSession
  • VCard
  • VTimezone

Functions

  • access_ticket_browser
  • binding_row_editor
  • bindings_to_other_browser
  • bindings_to_us_browser
  • build_dependencies_table
  • build_privileges_html
  • build_site_statistics
  • BuildSqlFilter
  • calquery_apply_filter
  • cardquery_apply_filter
  • catch_setup_errors
  • check_awl_version
  • check_calendar
  • check_curl
  • check_database_connection
  • check_datetime
  • check_davical_version
  • check_gettext
  • check_iconv
  • check_ldap
  • check_magic_quotes_gpc
  • check_magic_quotes_runtime
  • check_pdo
  • check_pdo_pgsql
  • check_pgsql
  • check_real_php
  • check_schema_version
  • check_string
  • check_suhosin_server_strip
  • check_xml
  • collection_privilege_format_function
  • confirm_delete_bind_in
  • confirm_delete_binding
  • confirm_delete_collection
  • confirm_delete_principal
  • confirm_delete_ticket
  • do_error
  • edit_binding_row
  • edit_grant_row_collection
  • edit_grant_row_principal
  • edit_group_row
  • edit_ticket_row
  • errorResponse
  • expand_properties
  • fetch_external
  • get_address_properties
  • get_freebusy
  • get_href_containers
  • get_phpinfo
  • grant_row_editor
  • group_members_browser
  • group_memberships_browser
  • group_row_editor
  • handle_subaction
  • i18n
  • ischedule_get
  • log_setup_error
  • make_help_link
  • principal_collection_browser
  • principal_editor
  • principal_grants_browser
  • principal_privilege_format_function
  • send_page_header
  • SqlFilterCardDAV
  • SqlFilterFragment
  • ticket_row_editor
  • unicodeToUtf8
  • update_external
  • utf8ToUnicode
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3: * Extend the vComponent to specifically handle VCARD resources
  4: */
  5: 
  6: require_once('AwlQuery.php');
  7: require_once('vComponent.php');
  8: 
  9: class VCard extends vComponent {
 10: 
 11:   /**
 12: CREATE TABLE addressbook_resource (
 13:   dav_id INT8 NOT NULL REFERENCES caldav_data(dav_id) ON UPDATE CASCADE ON DELETE CASCADE PRIMARY KEY,
 14:   version TEXT,
 15:   uid TEXT,
 16:   nickname TEXT,
 17:   fn TEXT, -- fullname
 18:   n TEXT, -- Name Surname;First names
 19:   note TEXT,
 20:   org TEXT,
 21:   url TEXT,
 22:   fburl TEXT,
 23:   caluri TEXT
 24: );
 25:   */
 26:   function Write( $dav_id, $exists = true ) {
 27:     $qry = new AwlQuery();
 28: 
 29:     // Only run a local transaction if we're not in one already.
 30:     $in_transaction = ($qry->TransactionState() == 1);
 31:     if ( ! $in_transaction ) $qry->Begin();
 32: 
 33:     if ( $exists ) {
 34:       $sql = 'UPDATE addressbook_resource SET version=:version, uid=:uid, nickname=:nickname, fn=:fn, n=:name,
 35: note=:note, org=:org, url=:url, fburl=:fburl, caladruri=:caladruri, caluri=:caluri WHERE dav_id=:dav_id';
 36:     }
 37:     else {
 38:       $sql = 'INSERT INTO addressbook_resource ( dav_id, version, uid, nickname, fn, n, note, org, url, fburl, caladruri, caluri )
 39: VALUES( :dav_id, :version, :uid, :nickname, :fn, :name, :note, :org, :url, :fburl, :caladruri, :caluri )';
 40:     }
 41: 
 42:     $params = array( ':dav_id' => $dav_id );
 43: 
 44:     $wanted = array('VERSION' => true, 'UID' => true, 'NICKNAME' => true, 'FN' => true, 'N' => true,
 45:                     'NOTE'=> true, 'ORG' => true, 'URL' => true, 'FBURL' => true, 'CALADRURI' => true, 'CALURI' => true);
 46:     $properties = $this->GetProperties( $wanted );
 47:     foreach( $wanted AS $k => $v ) {
 48:       $pname = ':' . strtolower($k);
 49:       if ( $pname == ':n' ) $pname = ':name';
 50:       $params[$pname] = null;
 51:     }
 52:     foreach( $properties AS $k => $v ) {
 53:       $pname = ':' . strtolower($v->Name());
 54:       if ( $pname == ':n' ) $pname = ':name';
 55:       if ( !isset($params[$pname]) /** @todo or this is one is in the user's language */ ) $params[$pname] = $v->Value();
 56:     }
 57: 
 58:     $qry->QDo( $sql, $params );
 59: 
 60:     $this->WriteAddresses($dav_id);
 61:     $this->WritePhones($dav_id);
 62:     $this->WriteEmails($dav_id);
 63: 
 64:     if ( ! $in_transaction ) $qry->Commit();
 65:   }
 66: 
 67: 
 68:   /**
 69: CREATE TABLE addressbook_address_adr (
 70:   dav_id INT8 NOT NULL REFERENCES caldav_data(dav_id) ON UPDATE CASCADE ON DELETE CASCADE,
 71:   type TEXT,
 72:   box_no TEXT,
 73:   unit_no TEXT,
 74:   street_address TEXT,
 75:   locality TEXT,
 76:   region TEXT,
 77:   postcode TEXT,
 78:   country TEXT,
 79:   property TEXT -- The full text of the property
 80: );
 81:   */
 82:   function WriteAddresses( $dav_id ) {
 83:     $addresses = $this->GetProperties('ADR');
 84:     $qry = new AwlQuery();
 85: 
 86:     // Only run a local transaction if we're not in one already.
 87:     $in_transaction = ($qry->TransactionState() == 1);
 88:     if ( ! $in_transaction ) $qry->Begin();
 89: 
 90:     $params = array( ':dav_id' => $dav_id );
 91:     $qry->QDo('DELETE FROM addressbook_address_adr WHERE dav_id = :dav_id', $params );
 92:     foreach( $addresses AS $adr ) {
 93:       $type = $adr->GetParameterValue('TYPE');
 94:       if ( is_array($type) ) $type = implode('~|~',$type);
 95:       $params[':type'] = $type;
 96:       //explode on ; that is not preceeded by an \
 97:       $address = preg_split( '{(?<!\\\\);}', $adr->Value());
 98:       //$address = explode(';',$adr->Value());
 99: 
100:       // We use @ to suppress the warnings here, because the NULL in the database suits us well.
101:       @$params[':box_no']   = $address[0];
102:       @$params[':unit_no']  = $address[1];
103:       @$params[':street_address'] = $address[2];
104:       @$params[':locality'] = $address[3];
105:       @$params[':region']   = $address[4];
106:       @$params[':postcode'] = $address[5];
107:       @$params[':country']  = $address[6];
108:       $params[':property'] = $adr->Render();
109:       $qry->QDo( 'INSERT INTO addressbook_address_adr (dav_id, type, box_no, unit_no, street_address, locality, region, postcode, country, property)
110: VALUES( :dav_id, :type, :box_no, :unit_no, :street_address, :locality, :region, :postcode, :country, :property)', $params );
111:     }
112:     if ( ! $in_transaction ) $qry->Commit();
113:   }
114: 
115: 
116:   /**
117: CREATE TABLE addressbook_address_tel (
118:   dav_id INT8 NOT NULL REFERENCES caldav_data(dav_id) ON UPDATE CASCADE ON DELETE CASCADE,
119:   type TEXT,
120:   tel TEXT,
121:   property TEXT -- The full text of the property
122: );
123:   */
124:   function WritePhones( $dav_id ) {
125:     $telephones = $this->GetProperties('TEL');
126:     $qry = new AwlQuery();
127: 
128:     // Only run a local transaction if we're not in one already.
129:     $in_transaction = ($qry->TransactionState() == 1);
130:     if ( ! $in_transaction ) $qry->Begin();
131: 
132:     $params = array( ':dav_id' => $dav_id );
133:     $qry->QDo('DELETE FROM addressbook_address_tel WHERE dav_id = :dav_id', $params );
134:     foreach( $telephones AS $tel ) {
135:       $type = $tel->GetParameterValue('TYPE');
136:       if ( is_array($type) ) $type = implode('~|~',$type);
137:       $params[':type'] = $type;
138:       if ( ! isset($params[':type']) ) $params[':type'] = 'voice';
139:       $params[':tel'] = $tel->Value();
140:       $params[':property'] = $tel->Render();
141:       $qry->QDo( 'INSERT INTO addressbook_address_tel (dav_id, type, tel, property) VALUES( :dav_id, :type, :tel, :property)', $params );
142:     }
143:     if ( ! $in_transaction ) $qry->Commit();
144:   }
145: 
146: 
147:   /**
148: CREATE TABLE addressbook_address_email (
149:   dav_id INT8 NOT NULL REFERENCES caldav_data(dav_id) ON UPDATE CASCADE ON DELETE CASCADE,
150:   type TEXT,
151:   email TEXT,
152:   property TEXT -- The full text of the property
153: );
154:   */
155:   function WriteEmails( $dav_id ) {
156:     $emails = $this->GetProperties('EMAIL');
157:     $qry = new AwlQuery();
158: 
159:     // Only run a local transaction if we're not in one already.
160:     $in_transaction = ($qry->TransactionState() == 1);
161:     if ( ! $in_transaction ) $qry->Begin();
162: 
163:     $params = array( ':dav_id' => $dav_id );
164:     $qry->QDo('DELETE FROM addressbook_address_email WHERE dav_id = :dav_id', $params );
165:     foreach( $emails AS $email ) {
166:       $type = $email->GetParameterValue('TYPE');
167:       if ( is_array($type) ) $type = implode('~|~',$type);
168:       $params[':type'] = $type;
169:       $params[':email'] = $email->Value();
170:       $params[':property'] = $email->Render();
171:       $qry->QDo( 'INSERT INTO addressbook_address_email (dav_id, type, email, property) VALUES( :dav_id, :type, :email, :property)', $params );
172:     }
173:     if ( ! $in_transaction ) $qry->Commit();
174:   }
175: 
176: }
DAViCal API documentation generated by ApiGen 2.8.0