6 require_once(
'AwlQuery.php');
7 require_once(
'vComponent.php');
9 class VCard extends vComponent {
26 function Write( $dav_id, $exists =
true ) {
27 $qry =
new AwlQuery();
30 $in_transaction = ($qry->TransactionState() == 1);
31 if ( ! $in_transaction ) $qry->Begin();
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';
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 )';
42 $params = array(
':dav_id' => $dav_id );
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;
52 foreach( $properties AS $k => $v ) {
53 $pname =
':' . strtolower($v->Name());
54 if ( $pname ==
':n' ) $pname =
':name';
55 if ( !isset($params[$pname]) ) $params[$pname] = $v->Value();
58 $qry->QDo( $sql, $params );
64 if ( ! $in_transaction ) $qry->Commit();
83 $addresses = $this->GetProperties(
'ADR');
84 $qry =
new AwlQuery();
87 $in_transaction = ($qry->TransactionState() == 1);
88 if ( ! $in_transaction ) $qry->Begin();
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;
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 );
112 if ( ! $in_transaction ) $qry->Commit();
125 $telephones = $this->GetProperties(
'TEL');
126 $qry =
new AwlQuery();
129 $in_transaction = ($qry->TransactionState() == 1);
130 if ( ! $in_transaction ) $qry->Begin();
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 );
143 if ( ! $in_transaction ) $qry->Commit();
156 $emails = $this->GetProperties(
'EMAIL');
157 $qry =
new AwlQuery();
160 $in_transaction = ($qry->TransactionState() == 1);
161 if ( ! $in_transaction ) $qry->Begin();
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 );
173 if ( ! $in_transaction ) $qry->Commit();