[3733] | 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 | $params[':type'] = $adr->GetParameterValue('TYPE'); |
---|
| 94 | $address = explode(';',$adr->Value()); |
---|
| 95 | |
---|
| 96 | // We use @ to suppress the warnings here, because the NULL in the database suits us well. |
---|
| 97 | @$params[':box_no'] = $address[0]; |
---|
| 98 | @$params[':unit_no'] = $address[1]; |
---|
| 99 | @$params[':street_address'] = $address[2]; |
---|
| 100 | @$params[':locality'] = $address[3]; |
---|
| 101 | @$params[':region'] = $address[4]; |
---|
| 102 | @$params[':postcode'] = $address[5]; |
---|
| 103 | @$params[':country'] = $address[6]; |
---|
| 104 | $params[':property'] = $adr->Render(); |
---|
| 105 | $qry->QDo( 'INSERT INTO addressbook_address_adr (dav_id, type, box_no, unit_no, street_address, locality, region, postcode, country, property) |
---|
| 106 | VALUES( :dav_id, :type, :box_no, :unit_no, :street_address, :locality, :region, :postcode, :country, :property)', $params ); |
---|
| 107 | } |
---|
| 108 | if ( ! $in_transaction ) $qry->Commit(); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | /** |
---|
| 113 | CREATE TABLE addressbook_address_tel ( |
---|
| 114 | dav_id INT8 NOT NULL REFERENCES caldav_data(dav_id) ON UPDATE CASCADE ON DELETE CASCADE, |
---|
| 115 | type TEXT, |
---|
| 116 | tel TEXT, |
---|
| 117 | property TEXT -- The full text of the property |
---|
| 118 | ); |
---|
| 119 | */ |
---|
| 120 | function WritePhones( $dav_id ) { |
---|
| 121 | $telephones = $this->GetProperties('TEL'); |
---|
| 122 | $qry = new AwlQuery(); |
---|
| 123 | |
---|
| 124 | // Only run a local transaction if we're not in one already. |
---|
| 125 | $in_transaction = ($qry->TransactionState() == 1); |
---|
| 126 | if ( ! $in_transaction ) $qry->Begin(); |
---|
| 127 | |
---|
| 128 | $params = array( ':dav_id' => $dav_id ); |
---|
| 129 | $qry->QDo('DELETE FROM addressbook_address_tel WHERE dav_id = :dav_id', $params ); |
---|
| 130 | foreach( $telephones AS $tel ) { |
---|
| 131 | $params[':type'] = $tel->GetParameterValue('TYPE'); |
---|
| 132 | if ( ! isset($params[':type']) ) $params[':type'] = 'voice'; |
---|
| 133 | $params[':tel'] = $tel->Value(); |
---|
| 134 | $params[':property'] = $tel->Render(); |
---|
| 135 | $qry->QDo( 'INSERT INTO addressbook_address_tel (dav_id, type, tel, property) VALUES( :dav_id, :type, :tel, :property)', $params ); |
---|
| 136 | } |
---|
| 137 | if ( ! $in_transaction ) $qry->Commit(); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | /** |
---|
| 142 | CREATE TABLE addressbook_address_email ( |
---|
| 143 | dav_id INT8 NOT NULL REFERENCES caldav_data(dav_id) ON UPDATE CASCADE ON DELETE CASCADE, |
---|
| 144 | type TEXT, |
---|
| 145 | email TEXT, |
---|
| 146 | property TEXT -- The full text of the property |
---|
| 147 | ); |
---|
| 148 | */ |
---|
| 149 | function WriteEmails( $dav_id ) { |
---|
| 150 | $emails = $this->GetProperties('EMAIL'); |
---|
| 151 | $qry = new AwlQuery(); |
---|
| 152 | |
---|
| 153 | // Only run a local transaction if we're not in one already. |
---|
| 154 | $in_transaction = ($qry->TransactionState() == 1); |
---|
| 155 | if ( ! $in_transaction ) $qry->Begin(); |
---|
| 156 | |
---|
| 157 | $params = array( ':dav_id' => $dav_id ); |
---|
| 158 | $qry->QDo('DELETE FROM addressbook_address_email WHERE dav_id = :dav_id', $params ); |
---|
| 159 | foreach( $emails AS $email ) { |
---|
| 160 | $params[':type'] = $email->GetParameterValue('TYPE'); |
---|
| 161 | $params[':email'] = $email->Value(); |
---|
| 162 | $params[':property'] = $email->Render(); |
---|
| 163 | $qry->QDo( 'INSERT INTO addressbook_address_email (dav_id, type, email, property) VALUES( :dav_id, :type, :email, :property)', $params ); |
---|
| 164 | } |
---|
| 165 | if ( ! $in_transaction ) $qry->Commit(); |
---|
| 166 | } |
---|
| 167 | /**************** Incluido para funcionar com expresso ***************** |
---|
| 168 | ************************************************************************ |
---|
| 169 | ***********************************************************************/ |
---|
| 170 | |
---|
| 171 | function Write_expresso( $uidnumber, $exists = true ) { |
---|
| 172 | |
---|
| 173 | // Only run a local transaction if we're not in one already. |
---|
| 174 | $uid_value = $this->GetProperties('UID'); |
---|
| 175 | foreach($uid_value AS $G => $H) |
---|
| 176 | { |
---|
| 177 | $uid = preg_split('/@/', $H->Value()); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | $qry = new AwlQuery( "select id_contact from phpgw_cc_contact where id_contact= :id AND id_owner = :owner ", array(':id' => $uid[0],':owner' => $uidnumber)); |
---|
| 181 | if( $qry->Exec() && $qry->rows() > 0 ) |
---|
| 182 | { |
---|
| 183 | $response_code = 200; |
---|
| 184 | $params = array(':id_contact' => $uid[0]); |
---|
| 185 | $sql = 'UPDATE phpgw_cc_contact SET photo=:photo, alias=:nickname, family_names =:ft, given_names=:name, |
---|
| 186 | names_ordered =:fn, birthdate =:bday, notes=:note WHERE id_contact=:id_contact'; |
---|
| 187 | } |
---|
| 188 | else |
---|
| 189 | { |
---|
| 190 | $response_code = 204; |
---|
| 191 | $qry = new AwlQuery( "select max(id_contact) from phpgw_cc_contact"); |
---|
| 192 | $qry->Exec(); |
---|
| 193 | $cont=$qry->fetch(); |
---|
| 194 | $params = array(':id_contact' => $cont->max + 1); |
---|
| 195 | $sql = 'INSERT INTO phpgw_cc_contact ( id_contact, id_owner, photo, alias, given_names, family_names, names_ordered, birthdate, notes ) |
---|
| 196 | VALUES ( :id_contact, :id_owner, :photo, :nickname, :name , :ft, :fn , :bday, :note)'; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | $params[':id_owner']=$uidnumber; |
---|
| 200 | $wanted = array('PHOTO' => true,'NICKNAME' => true, 'FN' => true, 'N' => true, |
---|
| 201 | 'NOTE'=> true, 'BDAY' => true); |
---|
| 202 | $properties = $this->GetProperties( $wanted ); |
---|
| 203 | |
---|
| 204 | foreach( $wanted AS $k => $v ) { |
---|
| 205 | $pname = ':' . strtolower($k); |
---|
| 206 | if ( $pname == ':n' ) $pname = ':name'; |
---|
| 207 | $params[$pname] = null; |
---|
| 208 | } |
---|
| 209 | foreach( $properties AS $k => $v ) { |
---|
| 210 | $pname = ':' . strtolower($v->Name()); |
---|
| 211 | if ( $pname == ':n' ) $pname = ':name'; |
---|
| 212 | if ( $pname == ':name' ){ |
---|
| 213 | $nome=preg_split('/;/', $v->Value()); |
---|
| 214 | $params[':name']=$nome[1]; |
---|
| 215 | $params[':ft']=$nome[0]; |
---|
| 216 | continue; |
---|
| 217 | } |
---|
| 218 | if ( !isset($params[$pname]) /** @TODO: or this is one is in the user's language */ ) $params[$pname] = $v->Value(); |
---|
| 219 | } |
---|
| 220 | $qry = new AwlQuery( $sql, $params ); |
---|
| 221 | $qry->Exec(); |
---|
| 222 | if ( $response_code == 200) |
---|
| 223 | $id_contactt = $uid[0]; |
---|
| 224 | else |
---|
| 225 | $id_contactt = $cont->max + 1; |
---|
| 226 | $emails = $this->GetProperties('EMAIL'); |
---|
| 227 | |
---|
| 228 | $tels = $this->GetProperties('TEL'); |
---|
| 229 | if ( isset($emails) || isset($tels)) |
---|
| 230 | { |
---|
| 231 | $qry = new AwlQuery("select id_connection from phpgw_cc_contact_conns where id_contact= :id", array(':id' => $id_contactt )); |
---|
| 232 | if ($qry->Exec() && $qry->rows() > 0) |
---|
| 233 | { |
---|
| 234 | while( $idconns = $qry->Fetch() ) { |
---|
| 235 | $qryy = new AwlQuery("DELETE from phpgw_cc_contact_conns where id_contact= :id AND id_connection = :id_connection", array(':id' => $id_contactt ,':id_connection' => $idconns->id_connection)); |
---|
| 236 | $qryy->Exec(); |
---|
| 237 | $qryy = new AwlQuery("DELETE from phpgw_cc_connections where id_connection = :id_connection", array(':id_connection' => $idconns->id_connection)); |
---|
| 238 | $qryy->Exec(); |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | if (isset($emails)) |
---|
| 242 | { |
---|
| 243 | foreach( $emails AS $email ) { |
---|
| 244 | $params[':type'] = $email->GetParameterValue('TYPE'); |
---|
| 245 | $params[':email'] = $email->Value(); |
---|
| 246 | $qry = new AwlQuery( "select max(id_connection) from phpgw_cc_connections"); |
---|
| 247 | $qry->Exec(); |
---|
| 248 | $cont=$qry->fetch(); |
---|
| 249 | if ( strtoupper($params[':type']) == 'WORK' ) |
---|
| 250 | {$params[':type'] = "Principal"; |
---|
| 251 | $params[':default'] = true; |
---|
| 252 | } |
---|
| 253 | else if ( $params[':type'] == 'pref' ) |
---|
| 254 | {$params[':type'] = "Principal"; |
---|
| 255 | $params[':default'] = true; |
---|
| 256 | } |
---|
| 257 | else |
---|
| 258 | { |
---|
| 259 | $params[':default'] = false; |
---|
| 260 | $params[':type'] = "Alternativo"; |
---|
| 261 | } |
---|
| 262 | $params[':id_conns'] = $cont->max + 1; |
---|
| 263 | dbg_log_array( "PUTTTTTT", 'EMAILSSSS', $params, true ); |
---|
| 264 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_connections (id_connection, connection_name, connection_value, connection_is_default) VALUES( :id_conns, :type, :email, :default )', $params ); |
---|
| 265 | $qry->Exec(); |
---|
| 266 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_contact_conns (id_contact, id_connection, id_typeof_contact_connection) VALUES( :id_contact, :id_conns, 1)', array(':id_contact' => $id_contactt , ':id_conns' => $cont->max + 1)); |
---|
| 267 | $qry->Exec(); |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | if (isset($tels)) |
---|
| 271 | { |
---|
| 272 | foreach( $tels AS $tel ) { |
---|
| 273 | $params[':type'] = $tel->GetParameterValue('TYPE'); |
---|
| 274 | if ( ! isset($params[':type']) ) $params[':type'] = 'voice'; |
---|
| 275 | $params[':tel'] = $tel->Value(); |
---|
| 276 | $params[':property'] = $tel->Render(); |
---|
| 277 | $qry = new AwlQuery( "select max(id_connection) from phpgw_cc_connections"); |
---|
| 278 | $qry->Exec(); |
---|
| 279 | $cont=$qry->fetch(); |
---|
| 280 | if ( strtoupper($params[':type']) == 'WORK') |
---|
| 281 | {$params[':type'] = "Trabalho"; |
---|
| 282 | $params[':default'] = true; |
---|
| 283 | } |
---|
| 284 | else if ( $params[':type'] == 'pref') |
---|
| 285 | {$params[':type'] = "Celular"; |
---|
| 286 | $params[':default'] = true; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | else if ( strtoupper($params[':type']) == 'HOME') |
---|
| 290 | { |
---|
| 291 | $params[':default'] = false; |
---|
| 292 | $params[':type'] = "Casa"; |
---|
| 293 | } |
---|
| 294 | else if ( strtoupper($params[':type']) == 'CELL') |
---|
| 295 | { |
---|
| 296 | $params[':default'] = false; |
---|
| 297 | $params[':type'] = "Celular"; |
---|
| 298 | } |
---|
| 299 | else if ( strtoupper($params[':type']) == 'FAX') |
---|
| 300 | { |
---|
| 301 | $params[':default'] = false; |
---|
| 302 | $params[':type'] = "Fax"; |
---|
| 303 | } |
---|
| 304 | $params[':id_conns'] = $cont->max + 1; |
---|
| 305 | dbg_log_array( "PUTTTTTT", 'TELSSSSSSSSS', $params, true ); |
---|
| 306 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_connections (id_connection, connection_name, connection_value, connection_is_default) VALUES( :id_conns, :type, :tel, :default )', $params ); |
---|
| 307 | $qry->Exec(); |
---|
| 308 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_contact_conns (id_contact, id_connection, id_typeof_contact_connection) VALUES( :id_contact, :id_conns, 2)', array(':id_contact' => $id_contactt , ':id_conns' => $cont->max + 1)); |
---|
| 309 | $qry->Exec(); |
---|
| 310 | |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | } |
---|
| 315 | |
---|
| 316 | } |
---|
| 317 | else |
---|
| 318 | { |
---|
| 319 | if (isset($emails)) |
---|
| 320 | { |
---|
| 321 | foreach( $emails AS $email ) { |
---|
| 322 | $params[':type'] = $email->GetParameterValue('TYPE'); |
---|
| 323 | $params[':email'] = $email->Value(); |
---|
| 324 | $qry = new AwlQuery( "select max(id_connection) from phpgw_cc_connections"); |
---|
| 325 | $qry->Exec(); |
---|
| 326 | $cont=$qry->fetch(); |
---|
| 327 | if ( strtoupper($params[':type']) == 'WORK') |
---|
| 328 | {$params[':type'] = "Principal"; |
---|
| 329 | $params[':default'] = true; |
---|
| 330 | } |
---|
| 331 | else if ( $params[':type'] == 'pref') |
---|
| 332 | {$params[':type'] = "Principal"; |
---|
| 333 | $params[':default'] = true; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | else |
---|
| 337 | { |
---|
| 338 | $params[':default'] = false; |
---|
| 339 | $params[':type'] = "Alternativo"; |
---|
| 340 | } |
---|
| 341 | $params[':id_conns'] = $cont->max + 1; |
---|
| 342 | dbg_log_array( "PUTTTTTT", 'EMAILSSSS INSERT', $params, true ); |
---|
| 343 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_connections (id_connection, connection_name, connection_value, connection_is_default) VALUES( :id_conns, :type, :email, :default )', $params ); |
---|
| 344 | $qry->Exec(); |
---|
| 345 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_contact_conns (id_contact, id_connection, id_typeof_contact_connection) VALUES( :id_contact, :id_conns, 1)', array(':id_contact' => $id_contactt , ':id_conns' => $cont->max + 1)); |
---|
| 346 | $qry->Exec(); |
---|
| 347 | } |
---|
| 348 | } |
---|
| 349 | if (isset($tels)) |
---|
| 350 | { |
---|
| 351 | foreach( $tels AS $tel ) { |
---|
| 352 | $params[':type'] = $tel->GetParameterValue('TYPE'); |
---|
| 353 | if ( ! isset($params[':type']) ) $params[':type'] = 'voice'; |
---|
| 354 | $params[':tel'] = $tel->Value(); |
---|
| 355 | $params[':property'] = $tel->Render(); |
---|
| 356 | $qry = new AwlQuery( "select max(id_connection) from phpgw_cc_connections"); |
---|
| 357 | $qry->Exec(); |
---|
| 358 | $cont=$qry->fetch(); |
---|
| 359 | if ( strtoupper($params[':type']) == 'WORK') |
---|
| 360 | {$params[':type'] = "Trabalho"; |
---|
| 361 | $params[':default'] = true; |
---|
| 362 | } |
---|
| 363 | else if ( $params[':type'] == 'pref') |
---|
| 364 | {$params[':type'] = "Celular"; |
---|
| 365 | $params[':default'] = true; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | else if ( strtoupper($params[':type']) == 'HOME') |
---|
| 369 | { |
---|
| 370 | $params[':default'] = false; |
---|
| 371 | $params[':type'] = "Casa"; |
---|
| 372 | } |
---|
| 373 | else if ( strtoupper($params[':type']) == 'CELL') |
---|
| 374 | { |
---|
| 375 | $params[':default'] = false; |
---|
| 376 | $params[':type'] = "Celular"; |
---|
| 377 | } |
---|
| 378 | else if ( strtoupper($params[':type']) == 'FAX') |
---|
| 379 | { |
---|
| 380 | $params[':default'] = false; |
---|
| 381 | $params[':type'] = "Fax"; |
---|
| 382 | } |
---|
| 383 | $params[':id_conns'] = $cont->max + 1; |
---|
| 384 | dbg_log_array( "PUTTTTTT", 'TELSSSSS INSERT', $params, true ); |
---|
| 385 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_connections (id_connection, connection_name, connection_value, connection_is_default) VALUES( :id_conns, :type, :tel, :default )', $params ); |
---|
| 386 | $qry->Exec(); |
---|
| 387 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_contact_conns (id_contact, id_connection, id_typeof_contact_connection) VALUES( :id_contact, :id_conns, 2)', array(':id_contact' => $id_contactt , ':id_conns' => $cont->max + 1)); |
---|
| 388 | $qry->Exec(); |
---|
| 389 | |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | |
---|
| 393 | |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | $addresses = $this->GetProperties('ADR'); |
---|
| 398 | if ( isset($addresses)) |
---|
| 399 | { |
---|
| 400 | $qry = new AwlQuery("select id_address from phpgw_cc_contact_addrs where id_contact= :id", array(':id' => $id_contactt)); |
---|
| 401 | if ($qry->Exec() && $qry->rows() > 0) |
---|
| 402 | { |
---|
| 403 | while( $idconns = $qry->Fetch() ) { |
---|
| 404 | $qryy = new AwlQuery("DELETE from phpgw_cc_contact_addrs where id_contact= :id AND id_address = :id_connection", array(':id' => $id_contactt ,':id_connection' => $idconns->id_address)); |
---|
| 405 | $qryy->Exec(); |
---|
| 406 | $qryy = new AwlQuery("DELETE from phpgw_cc_addresses where id_address = :id_connection", array(':id_connection' => $idconns->id_address)); |
---|
| 407 | $qryy->Exec(); |
---|
| 408 | |
---|
| 409 | } |
---|
| 410 | foreach( $addresses AS $adr ) { |
---|
| 411 | $params[':type'] = $adr->GetParameterValue('TYPE'); |
---|
| 412 | $address = explode(';',$adr->Value()); |
---|
| 413 | |
---|
| 414 | // We use @ to suppress the warnings here, because the NULL in the database suits us well. |
---|
| 415 | @$params[':box_no'] = $address[0]; |
---|
| 416 | @$params[':unit_no'] = $address[1]; |
---|
| 417 | @$params[':street_address'] = $address[2]; |
---|
| 418 | @$params[':locality'] = $address[3]; |
---|
| 419 | @$params[':region'] = $address[4]; |
---|
| 420 | @$params[':postcode'] = $address[5]; |
---|
| 421 | @$params[':country'] = substr($address[6],0,2); |
---|
| 422 | $qry = new AwlQuery( "select max(id_address) from phpgw_cc_addresses"); |
---|
| 423 | $qry->Exec(); |
---|
| 424 | $cont=$qry->fetch(); |
---|
| 425 | if ( strtoupper($params[':type']) == 'WORK') |
---|
| 426 | {$params[':type'] = 2; |
---|
| 427 | $params[':default'] = true; |
---|
| 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
| 431 | $params[':default'] = false; |
---|
| 432 | $params[':type'] = 1; |
---|
| 433 | } |
---|
| 434 | $params[':id_conns'] = $cont->max + 1; |
---|
| 435 | $qry = new AwlQuery( "select id_city from phpgw_cc_city where city_name = :idcity", array(':idcity' => $address[3])); |
---|
| 436 | if ( @$qry->Exec() && $qry->rows() > 0 ) |
---|
| 437 | { $city=$qry->fetch(); |
---|
| 438 | $params[':locality'] = $city->id_city; |
---|
| 439 | } |
---|
| 440 | else |
---|
| 441 | $params[':locality'] = ""; |
---|
| 442 | $qry = new AwlQuery( "select id_state from phpgw_cc_state where state_name = :idstate OR state_symbol = :idstate ", array(':idstate' => $address[4])); |
---|
| 443 | if ( @$qry->Exec() && $qry->rows() > 0 ) |
---|
| 444 | { $state=$qry->fetch(); |
---|
| 445 | $params[':region'] = $state->id_state; |
---|
| 446 | } |
---|
| 447 | else |
---|
| 448 | $params[':region'] = ""; |
---|
| 449 | dbg_log_array( "PUTTTTTT", 'ADDRESSSSSSS', $params, true ); |
---|
| 450 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_addresses ( id_address,id_city,id_state,id_country,address1,postal_code,address_is_default) VALUES( :id_conns, :locality, :region, :country, :street_address, :postcode, :default )', $params ); |
---|
| 451 | $qry->Exec(); |
---|
| 452 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_contact_addrs (id_contact, id_address, id_typeof_contact_address ) VALUES( :id_contact, :id_conns, :type)', array(':id_contact' => $id_contactt , ':id_conns' => $cont->max + 1,':type' => $params[':type'])); |
---|
| 453 | $qry->Exec(); |
---|
| 454 | } |
---|
| 455 | |
---|
| 456 | } |
---|
| 457 | else |
---|
| 458 | { |
---|
| 459 | foreach( $addresses AS $adr ) { |
---|
| 460 | $params[':type'] = $adr->GetParameterValue('TYPE'); |
---|
| 461 | $address = explode(';',$adr->Value()); |
---|
| 462 | |
---|
| 463 | // We use @ to suppress the warnings here, because the NULL in the database suits us well. |
---|
| 464 | @$params[':box_no'] = $address[0]; |
---|
| 465 | @$params[':unit_no'] = $address[1]; |
---|
| 466 | @$params[':street_address'] = $address[2]; |
---|
| 467 | @$params[':locality'] = $address[3]; |
---|
| 468 | @$params[':region'] = $address[4]; |
---|
| 469 | @$params[':postcode'] = $address[5]; |
---|
| 470 | @$params[':country'] = substr($address[6],0,2); |
---|
| 471 | $qry = new AwlQuery( "select max(id_address) from phpgw_cc_addresses"); |
---|
| 472 | $qry->Exec(); |
---|
| 473 | $cont=$qry->fetch(); |
---|
| 474 | if ( strtoupper($params[':type']) == 'WORK') |
---|
| 475 | {$params[':type'] = 2; |
---|
| 476 | $params[':default'] = true; |
---|
| 477 | } |
---|
| 478 | else |
---|
| 479 | { |
---|
| 480 | $params[':default'] = false; |
---|
| 481 | $params[':type'] = 1; |
---|
| 482 | } |
---|
| 483 | $params[':id_conns'] = $cont->max + 1; |
---|
| 484 | $qry = new AwlQuery( "select id_city from phpgw_cc_city where city_name = :idcity", array(':idcity' => $address[3])); |
---|
| 485 | if ( @$qry->Exec() && $qry->rows() > 0 ) |
---|
| 486 | { $city=$qry->fetch(); |
---|
| 487 | $params[':locality'] = $city->id_city; |
---|
| 488 | } |
---|
| 489 | else |
---|
| 490 | $params[':locality'] = ""; |
---|
| 491 | $qry = new AwlQuery( "select id_state from phpgw_cc_state where state_name = :idstate OR state_symbol = :idstate ", array(':idstate' => $address[4])); |
---|
| 492 | if ( @$qry->Exec() && $qry->rows() > 0 ) |
---|
| 493 | { $state=$qry->fetch(); |
---|
| 494 | $params[':region'] = $state->id_state; |
---|
| 495 | } |
---|
| 496 | else |
---|
| 497 | $params[':region'] = ""; |
---|
| 498 | dbg_log_array( "PUTTTTTT", 'ADDRESSSSSSSSSS INSERT', $params, true ); |
---|
| 499 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_addresses ( id_address,id_city,id_state,id_country,address1,postal_code,address_is_default) VALUES( :id_conns, :locality, :region, :country, :street_address, :postcode, :default )', $params ); |
---|
| 500 | $qry->Exec(); |
---|
| 501 | $qry = new AwlQuery( 'INSERT INTO phpgw_cc_contact_addrs (id_contact, id_address, id_typeof_contact_address ) VALUES( :id_contact, :id_conns, :type)', array(':id_contact' => $id_contactt , ':id_conns' => $cont->max + 1,':type' => $params[':type'])); |
---|
| 502 | $qry->Exec(); |
---|
| 503 | } |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | return $response_code; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | |
---|
| 511 | |
---|
| 512 | } |
---|