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,
35note=: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 )
39VALUES( :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();
72 $addresses = $this->GetProperties(
'ADR');
73 $qry =
new AwlQuery();
76 $in_transaction = ($qry->TransactionState() == 1);
77 if ( ! $in_transaction ) $qry->Begin();
79 $params = array(
':dav_id' => $dav_id );
80 $qry->QDo(
'DELETE FROM addressbook_address_adr WHERE dav_id = :dav_id', $params );
83 foreach( $addresses AS $adr ) {
84 $type = $adr->GetParameterValue(
'TYPE');
85 if ( is_array($type) ) $type = implode(
'~|~',$type);
87 $params[
':type'] = $type;
93 @$params[
':box_no'] = $address[0];
94 @$params[
':unit_no'] = $address[1];
95 @$params[
':street_address'] = $address[2];
96 @$params[
':locality'] = $address[3];
97 @$params[
':region'] = $address[4];
98 @$params[
':postcode'] = $address[5];
99 @$params[
':country'] = $address[6];
100 $params[
':property'] = $adr->Render();
101 $params[
':count'] = $count++;
103 $qry->QDo(
'INSERT INTO addressbook_address_adr (dav_id, count, type, box_no, unit_no, street_address, locality, region, postcode, country, property)
104VALUES ( :dav_id, :count, :type, :box_no, :unit_no, :street_address, :locality, :region, :postcode, :country, :property)', $params );
106 if ( ! $in_transaction ) $qry->Commit();
114 $telephones = $this->GetProperties(
'TEL');
115 $qry =
new AwlQuery();
118 $in_transaction = ($qry->TransactionState() == 1);
119 if ( ! $in_transaction ) $qry->Begin();
121 $params = array(
':dav_id' => $dav_id );
122 $qry->QDo(
'DELETE FROM addressbook_address_tel WHERE dav_id = :dav_id', $params );
125 foreach( $telephones AS $tel ) {
126 $type = $tel->GetParameterValue(
'TYPE');
127 if ( is_array($type) ) $type = implode(
'~|~',$type);
129 $params[
':type'] = $type;
130 if ( ! isset($params[
':type']) ) $params[
':type'] =
'voice';
132 $params[
':tel'] = $tel->Value();
133 $params[
':property'] = $tel->Render();
134 $params[
':count'] = $count++;
136 $qry->QDo(
'INSERT INTO addressbook_address_tel (dav_id, count, type, tel, property) VALUES ( :dav_id, :count, :type, :tel, :property)', $params );
138 if ( ! $in_transaction ) $qry->Commit();
151 $emails = $this->GetProperties(
'EMAIL');
152 $qry =
new AwlQuery();
155 $in_transaction = ($qry->TransactionState() == 1);
156 if ( ! $in_transaction ) $qry->Begin();
158 $params = array(
':dav_id' => $dav_id );
159 $qry->QDo(
'DELETE FROM addressbook_address_email WHERE dav_id = :dav_id', $params );
162 foreach( $emails AS $email ) {
163 $type = $email->GetParameterValue(
'TYPE');
164 if ( is_array($type) ) $type = implode(
'~|~',$type);
166 $params[
':type'] = $type;
167 $params[
':email'] = $email->Value();
168 $params[
':property'] = $email->Render();
169 $params[
':count'] = $count++;
171 $qry->QDo(
'INSERT INTO addressbook_address_email (dav_id, count, type, email, property) VALUES ( :dav_id, :count, :type, :email, :property)', $params );
173 if ( ! $in_transaction ) $qry->Commit();