[2] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | * eGroupWare - Contacts Center * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Written by: * |
---|
| 6 | * - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net> * |
---|
| 7 | * sponsored by Thyamad - http://www.thyamad.com |
---|
| 8 | * ------------------------------------------------------------------------- * |
---|
| 9 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 10 | * under the terms of the GNU General Public License as published by the * |
---|
| 11 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 12 | * option) any later version. * |
---|
| 13 | \***************************************************************************/ |
---|
| 14 | |
---|
| 15 | include_once('class.abo_catalog.inc.php'); |
---|
| 16 | class bo_people_catalog extends abo_catalog |
---|
| 17 | { |
---|
| 18 | |
---|
| 19 | var $fields = array( |
---|
| 20 | 'id_contact' => true, |
---|
| 21 | 'status' => true, |
---|
| 22 | 'photo' => true, |
---|
| 23 | 'alias' => true, |
---|
| 24 | 'prefix' => true, |
---|
| 25 | 'given_names' => true, |
---|
| 26 | 'family_names' => true, |
---|
| 27 | 'names_ordered' => true, |
---|
| 28 | 'suffix' => true, |
---|
| 29 | 'birthdate' => true, |
---|
| 30 | 'sex' => true, |
---|
| 31 | 'pgp_key' => true, |
---|
| 32 | 'notes' => true, |
---|
| 33 | |
---|
| 34 | /* Array fields */ |
---|
| 35 | 'companies' => true, |
---|
| 36 | 'relations' => true, |
---|
| 37 | 'addresses' => true, |
---|
| 38 | 'connections' => true |
---|
| 39 | ); |
---|
| 40 | |
---|
| 41 | /*! |
---|
| 42 | |
---|
| 43 | @function bo_people_catalog |
---|
| 44 | @abstract Constructor |
---|
| 45 | @author Raphael Derosso Pereira |
---|
| 46 | |
---|
| 47 | */ |
---|
| 48 | function bo_people_catalog() |
---|
| 49 | { |
---|
| 50 | $this->init(); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /*! |
---|
| 54 | @function find |
---|
| 55 | @abstract Find function for this catalog |
---|
| 56 | @author Raphael Derosso Pereira |
---|
| 57 | |
---|
| 58 | */ |
---|
| 59 | function find($what, $rules=false, $other=false) |
---|
| 60 | { |
---|
| 61 | if (is_array($what) and count($what)) |
---|
| 62 | { |
---|
| 63 | $found = false; |
---|
| 64 | |
---|
| 65 | foreach ($what as $value) |
---|
| 66 | { |
---|
| 67 | if (strpos($value, 'contact') === 0) |
---|
| 68 | { |
---|
| 69 | $found = true; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | if (!$found) |
---|
| 74 | { |
---|
| 75 | return $this->sql_find($what, $rules, $other); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | if ($rules and is_array($rules)) |
---|
| 79 | { |
---|
| 80 | array_push($rules, array( |
---|
| 81 | 'field' => 'contact.id_owner', |
---|
| 82 | 'type' => '=', |
---|
| 83 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 84 | )); |
---|
| 85 | } |
---|
| 86 | else |
---|
| 87 | { |
---|
| 88 | $rules = array( |
---|
| 89 | 0 => array( |
---|
| 90 | 'field' => 'contact.id_owner', |
---|
| 91 | 'type' => '=', |
---|
| 92 | 'value' => $GLOBALS['phpgw_info']['user']['account_id'] |
---|
| 93 | ) |
---|
| 94 | ); |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | return $this->sql_find($what, $rules, $other); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | /*! |
---|
| 102 | |
---|
| 103 | @function get_single_entry |
---|
| 104 | @abstract Returns all information requested about one contact |
---|
| 105 | @author Raphael Derosso Pereira |
---|
| 106 | |
---|
| 107 | @param integer $id_contact The contact ID |
---|
| 108 | @param array $fields The array returned by get_fields whith true |
---|
| 109 | on the fields to be taken. |
---|
| 110 | |
---|
| 111 | */ |
---|
| 112 | function get_single_entry ( $id_contact, $fields ) |
---|
| 113 | { |
---|
| 114 | if (!is_array($fields)) |
---|
| 115 | { |
---|
| 116 | if (is_object($GLOBALS['phpgw']->log)) |
---|
| 117 | { |
---|
| 118 | $GLOBALS['phpgw']->log->message(array( |
---|
| 119 | 'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.', |
---|
| 120 | 'line' => __LINE__, |
---|
| 121 | 'file' => __FILE__)); |
---|
| 122 | |
---|
| 123 | $GLOBALS['phpgw']->log->commit(); |
---|
| 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | // Verify permissions |
---|
| 132 | $permissions = $this->security->get_permissions('entry', $id_contact); |
---|
| 133 | |
---|
| 134 | if (!$permissions['read']) |
---|
| 135 | { |
---|
| 136 | return false; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | //$contact_data = $this->fields; |
---|
| 140 | |
---|
| 141 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
| 142 | |
---|
| 143 | foreach ($fields as $field => $trueness) |
---|
| 144 | { |
---|
| 145 | if (!$trueness) |
---|
| 146 | { |
---|
| 147 | //unset($contact_data[$field]); |
---|
| 148 | continue; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | switch ($field) |
---|
| 152 | { |
---|
| 153 | case 'companies': |
---|
| 154 | $companies = $this->get_companies($id_contact,$trueness); |
---|
| 155 | |
---|
| 156 | if (is_array($companies) and count($companies)) |
---|
| 157 | { |
---|
| 158 | $contact_data['companies'] = $companies; |
---|
| 159 | } |
---|
| 160 | break; |
---|
| 161 | |
---|
| 162 | case 'relations': |
---|
| 163 | $relations = $this->get_relations($id_contact,$trueness); |
---|
| 164 | |
---|
| 165 | if (is_array($relations) and count($relations)) |
---|
| 166 | { |
---|
| 167 | $contact_data['relations'] = $relations; |
---|
| 168 | } |
---|
| 169 | break; |
---|
| 170 | |
---|
| 171 | case 'addresses': |
---|
| 172 | $addresses = $this->get_addresses($id_contact,$trueness); |
---|
| 173 | |
---|
| 174 | if (is_array($addresses) and count($addresses)) |
---|
| 175 | { |
---|
| 176 | $contact_data['addresses'] = $addresses; |
---|
| 177 | } |
---|
| 178 | break; |
---|
| 179 | |
---|
| 180 | case 'connections': |
---|
| 181 | $connections = $this->get_connections($id_contact,$trueness); |
---|
| 182 | |
---|
| 183 | if (is_array($connections) and count($connections)) |
---|
| 184 | { |
---|
| 185 | $contact_data['connections'] = $connections; |
---|
| 186 | } |
---|
| 187 | break; |
---|
| 188 | |
---|
| 189 | case 'prefix': |
---|
| 190 | $id = $contact->get_prefix(); |
---|
| 191 | if ($id) |
---|
| 192 | { |
---|
| 193 | $prefix = CreateObject('contactcenter.so_prefix', $id); |
---|
| 194 | $contact_data['id_prefix'] = $id; |
---|
| 195 | $contact_data['prefix'] = $prefix->get_prefix(); |
---|
| 196 | } |
---|
| 197 | break; |
---|
| 198 | |
---|
| 199 | case 'suffix': |
---|
| 200 | $id = $contact->get_suffix(); |
---|
| 201 | if ($id) |
---|
| 202 | { |
---|
| 203 | $suffix = CreateObject('contactcenter.so_suffix', $id); |
---|
| 204 | $contact_data['id_suffix'] = $id; |
---|
| 205 | $contact_data['suffix'] = $suffix->get_suffix(); |
---|
| 206 | } |
---|
| 207 | break; |
---|
| 208 | |
---|
| 209 | case 'status': |
---|
| 210 | $id = $contact->get_status(); |
---|
| 211 | if ($id) |
---|
| 212 | { |
---|
| 213 | $status = CreateObject('contactcenter.so_status', $id); |
---|
| 214 | $contact_data['id_status'] = $id; |
---|
| 215 | $contact_data['status'] = $status->get_status(); |
---|
| 216 | } |
---|
| 217 | break; |
---|
| 218 | |
---|
| 219 | default: |
---|
| 220 | //$func_name = 'contact->get_'.$field; |
---|
| 221 | //$contact_data[$field] = $this->$func_name(); |
---|
| 222 | $contact_data[$field] = $contact->get_field($field); |
---|
| 223 | break; |
---|
| 224 | } |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | if (!is_array($contact_data)) |
---|
| 228 | { |
---|
| 229 | return false; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | return $contact_data; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /*! |
---|
| 236 | |
---|
| 237 | @function get_multiple_entries |
---|
| 238 | @abstract Returns multiple Contacts data into one array |
---|
| 239 | @author Raphael Derosso Pereira |
---|
| 240 | |
---|
| 241 | @param array $id_contacts The Contacts IDs |
---|
| 242 | @param array $fields The Contacts fields to be retrieved |
---|
| 243 | @param array $other_data Other informations. The format is: |
---|
| 244 | $other_data = array( |
---|
| 245 | 'offset' => <offset>, |
---|
| 246 | 'limit' => <max_num_returns>, |
---|
| 247 | 'sort' => <sort>, |
---|
| 248 | 'order_by' => <order by> |
---|
| 249 | ); |
---|
| 250 | |
---|
| 251 | */ |
---|
| 252 | function get_multiple_entries ( $id_contacts, $fields, $other_data = false ) |
---|
| 253 | { |
---|
| 254 | if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data))) |
---|
| 255 | { |
---|
| 256 | if (is_object($GLOBALS['phpgw']->log)) |
---|
| 257 | { |
---|
| 258 | $GLOBALS['phpgw']->log->message(array( |
---|
| 259 | 'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.', |
---|
| 260 | 'line' => __LINE__, |
---|
| 261 | 'file' => __FILE__)); |
---|
| 262 | |
---|
| 263 | $GLOBALS['phpgw']->log->commit(); |
---|
| 264 | } |
---|
| 265 | else { |
---|
| 266 | exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>'); |
---|
| 267 | } |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | $contacts = array(); |
---|
| 271 | |
---|
| 272 | if ($other_data) |
---|
| 273 | { |
---|
| 274 | //TODO |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | foreach ($id_contacts as $id) |
---|
| 278 | { |
---|
| 279 | $contact = $this->get_single_entry($id,$fields); |
---|
| 280 | if ($contact) |
---|
| 281 | { |
---|
| 282 | $contacts[$id] = $contact; |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | return $contacts; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | /*! |
---|
| 290 | |
---|
| 291 | @function get_all_entries_ids |
---|
| 292 | @abstract Returns the IDs of all the entries in this catalog |
---|
| 293 | @author Raphael Derosso Pereira |
---|
| 294 | |
---|
| 295 | */ |
---|
| 296 | function get_all_entries_ids () |
---|
| 297 | { |
---|
| 298 | $search_fields = array('contact.id_contact', 'contact.names_ordered'); |
---|
| 299 | $search_other = array('order' => 'contact.names_ordered'); |
---|
| 300 | |
---|
| 301 | $result_i = $this->find($search_fields, null, $search_other); |
---|
| 302 | |
---|
| 303 | if (is_array($result_i) and count($result_i)) |
---|
| 304 | { |
---|
| 305 | $result = array(); |
---|
| 306 | foreach($result_i as $result_part) |
---|
| 307 | { |
---|
| 308 | $result[] = $result_part['id_contact']; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | return $result; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | return null; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | /*! |
---|
| 318 | |
---|
| 319 | @function get_relations |
---|
| 320 | @abstract Returns the IDs of all Contacts relations |
---|
| 321 | @author Raphael Derosso Pereira |
---|
| 322 | |
---|
| 323 | @param integer $id_contact The Contact ID |
---|
| 324 | |
---|
| 325 | @return The following array: |
---|
| 326 | $return = array( |
---|
| 327 | 'relation1' => array( |
---|
| 328 | 'id_relation' => <id_relation>, |
---|
| 329 | 'id_type' => <id_type>, |
---|
| 330 | 'type' => '<type_name>', |
---|
| 331 | 'is_subordinated' => <trueness> |
---|
| 332 | ), |
---|
| 333 | 'relation2' => array(...), |
---|
| 334 | ... |
---|
| 335 | ); |
---|
| 336 | |
---|
| 337 | */ |
---|
| 338 | function get_relations ($id_contact,$extra=false) |
---|
| 339 | { |
---|
| 340 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
| 341 | $relations = $contact->get_relations(); |
---|
| 342 | |
---|
| 343 | $count = 1; |
---|
| 344 | foreach($relations as $id => $type) |
---|
| 345 | { |
---|
| 346 | $relation = CreateObject('contactcenter.so_contact_relation_type', $type); |
---|
| 347 | |
---|
| 348 | if ($extra === 'subordinated' and $relation->get_is_subordinated()) |
---|
| 349 | { |
---|
| 350 | $return['relation'.$count]['id_relation'] = $id; |
---|
| 351 | $return['relation'.$count]['id_type'] = $type; |
---|
| 352 | $return['relation'.$count]['type'] = $relation->get_type_name(); |
---|
| 353 | $return['relation'.$count]['is_subordinated'] = $relation->get_is_subordinated(); |
---|
| 354 | $count++; |
---|
| 355 | } |
---|
| 356 | else if ($extra !== 'subordinated') |
---|
| 357 | { |
---|
| 358 | $return['relation'.$count]['id_relation'] = $id; |
---|
| 359 | $return['relation'.$count]['id_type'] = $type; |
---|
| 360 | $return['relation'.$count]['type'] = $relation->get_type_name(); |
---|
| 361 | $return['relation'.$count]['is_subordinated'] = $relation->get_is_subordinated(); |
---|
| 362 | $count++; |
---|
| 363 | } |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | return $return; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | /*! |
---|
| 370 | |
---|
| 371 | @function get_addresses |
---|
| 372 | @abstract Returns all Contacts Address Information |
---|
| 373 | @author Raphael Derosso Pereira |
---|
| 374 | |
---|
| 375 | @param integer $id_contact The Contact ID |
---|
| 376 | |
---|
| 377 | @return The following array: |
---|
| 378 | $return = array( |
---|
| 379 | 'address1' => array( |
---|
| 380 | 'id_address' => <id_address>, |
---|
| 381 | 'id_type' => <id_type>, |
---|
| 382 | 'type' => '<type_name>', |
---|
| 383 | 'address1' => '<address1>', |
---|
| 384 | 'address2' => '<address2>', |
---|
| 385 | 'complement' => '<complement>', |
---|
| 386 | 'address_other' => '<address_other>', |
---|
| 387 | 'postal_code' => '<postal_code>', |
---|
| 388 | 'po_box' => '<po_box>', |
---|
| 389 | 'id_city' => '<city>', |
---|
| 390 | 'city_name' => (string), |
---|
| 391 | 'city_timezone' => (int), |
---|
| 392 | 'city_geo_location' => (string), |
---|
| 393 | 'id_state' => (int), |
---|
| 394 | 'state_name' => (string), |
---|
| 395 | 'state_symbol' => (string), |
---|
| 396 | 'id_country' => (int), |
---|
| 397 | 'country_name' => (string), |
---|
| 398 | 'address_is_default' => <trueness> |
---|
| 399 | ), |
---|
| 400 | 'address2' => array(...), |
---|
| 401 | ... |
---|
| 402 | ); |
---|
| 403 | |
---|
| 404 | */ |
---|
| 405 | function get_addresses ( $id_contact,$extra=false ) |
---|
| 406 | { |
---|
| 407 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
| 408 | $addresses = $contact->get_addresses(extra); |
---|
| 409 | |
---|
| 410 | foreach($addresses as $id => $type) |
---|
| 411 | { |
---|
| 412 | $address = CreateObject('contactcenter.so_address',$id); |
---|
| 413 | $address_type = CreateObject('contactcenter.so_contact_address_type',$type); |
---|
| 414 | |
---|
| 415 | if ($extra === 'default' and $address->is_default()) |
---|
| 416 | { |
---|
| 417 | $return['address'.$type]['id_address'] = $id; |
---|
| 418 | $return['address'.$type]['id_typeof_address'] = $type; |
---|
| 419 | $return['address'.$type]['type'] = $address_type->get_type_name(); |
---|
| 420 | $return['address'.$type]['address1'] = $address->get_address1(); |
---|
| 421 | $return['address'.$type]['address2'] = $address->get_address2(); |
---|
| 422 | $return['address'.$type]['complement'] = $address->get_complement(); |
---|
| 423 | $return['address'.$type]['address_other'] = $address->get_address_other(); |
---|
| 424 | $return['address'.$type]['postal_code'] = $address->get_postal_code(); |
---|
| 425 | $return['address'.$type]['po_box'] = $address->get_po_box(); |
---|
| 426 | $return['address'.$type]['address_is_default'] = true; |
---|
| 427 | $return['address'.$type]['id_city'] = $id_city = $address->get_id_city(); |
---|
| 428 | $return['address'.$type]['id_state'] = $id_state = $address->get_id_state(); |
---|
| 429 | $return['address'.$type]['id_country'] = $id_country = $address->get_id_country(); |
---|
| 430 | |
---|
| 431 | if ($id_city) |
---|
| 432 | { |
---|
| 433 | $city = CreateObject('contactcenter.so_city',$id_city); |
---|
| 434 | $return['address'.$type]['city_name'] = $city->get_city_name(); |
---|
| 435 | $return['address'.$type]['city_timezone'] = $city->get_city_timezone(); |
---|
| 436 | $return['address'.$type]['city_geo_location'] = $city->get_city_geo_location(); |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | if ($id_state) |
---|
| 440 | { |
---|
| 441 | $state = CreateObject('contactcenter.so_state',$id_state); |
---|
| 442 | $return['address'.$type]['state_name'] = $state->get_state_name(); |
---|
| 443 | $return['address'.$type]['state_symbol'] = $state->get_state_symbol(); |
---|
| 444 | $return['address'.$type]['id_country'] = $id_country = $state->get_id_country(); |
---|
| 445 | } |
---|
| 446 | |
---|
| 447 | $country = CreateObject('contactcenter.so_country',$id_country); |
---|
| 448 | $return['address'.$type]['country_name'] = $country->get_country_name(); |
---|
| 449 | } |
---|
| 450 | else if ($extra !== 'default') |
---|
| 451 | { |
---|
| 452 | $return['address'.$type]['id_address'] = $id; |
---|
| 453 | $return['address'.$type]['id_typeof_address'] = $type; |
---|
| 454 | $return['address'.$type]['type'] = $address_type->get_type_name(); |
---|
| 455 | $return['address'.$type]['address1'] = $address->get_address1(); |
---|
| 456 | $return['address'.$type]['address2'] = $address->get_address2(); |
---|
| 457 | $return['address'.$type]['complement'] = $address->get_complement(); |
---|
| 458 | $return['address'.$type]['address_other'] = $address->get_address_other(); |
---|
| 459 | $return['address'.$type]['postal_code'] = $address->get_postal_code(); |
---|
| 460 | $return['address'.$type]['po_box'] = $address->get_po_box(); |
---|
| 461 | $return['address'.$type]['address_is_default'] = $address->is_default(); |
---|
| 462 | $return['address'.$type]['id_city'] = $id_city = $address->get_id_city(); |
---|
| 463 | $return['address'.$type]['id_state'] = $id_state = $address->get_id_state(); |
---|
| 464 | $return['address'.$type]['id_country'] = $id_country = $address->get_id_country(); |
---|
| 465 | |
---|
| 466 | if ($id_city) |
---|
| 467 | { |
---|
| 468 | $city = CreateObject('contactcenter.so_city',$id_city); |
---|
| 469 | $return['address'.$type]['city_name'] = $city->get_city_name(); |
---|
| 470 | $return['address'.$type]['city_timezone'] = $city->get_city_timezone(); |
---|
| 471 | $return['address'.$type]['city_geo_location'] = $city->get_city_geo_location(); |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | if ($id_state) |
---|
| 475 | { |
---|
| 476 | $state = CreateObject('contactcenter.so_state',$id_state); |
---|
| 477 | $return['address'.$type]['state_name'] = $state->get_state_name(); |
---|
| 478 | $return['address'.$type]['state_symbol'] = $state->get_state_symbol(); |
---|
| 479 | $return['address'.$type]['id_country'] = $id_country = $state->get_id_country(); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | $country = CreateObject('contactcenter.so_country',$id_country); |
---|
| 483 | $return['address'.$type]['country_name'] = $country->get_country_name(); |
---|
| 484 | } |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | return $return; |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | |
---|
| 491 | /*! |
---|
| 492 | |
---|
| 493 | @function get_connections |
---|
| 494 | @abstract Returns all Contacts connections information |
---|
| 495 | @author Raphael Derosso Pereira |
---|
| 496 | |
---|
| 497 | @param integer $id_contact The Contact ID |
---|
| 498 | |
---|
| 499 | @return The following array: |
---|
| 500 | $return = array( |
---|
| 501 | 'connection1' => array( |
---|
| 502 | 'id_connection' => <id_connection>, |
---|
| 503 | 'id_type' => <id_type>, |
---|
| 504 | 'type' => '<type_name>', |
---|
| 505 | 'connection_name' => '<connection_name>', |
---|
| 506 | 'connection_value' => '<connection_value>', |
---|
| 507 | 'connection_is_default' => '<connection_is_default>' |
---|
| 508 | ), |
---|
| 509 | 'connection2' => array(...), |
---|
| 510 | ... |
---|
| 511 | ); |
---|
| 512 | |
---|
| 513 | */ |
---|
| 514 | function get_connections ( $id_contact,$extra=false ) |
---|
| 515 | { |
---|
| 516 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
| 517 | $connections = $contact->get_connections($extra); |
---|
| 518 | |
---|
| 519 | $count = 1; |
---|
| 520 | foreach($connections as $id => $type) |
---|
| 521 | { |
---|
| 522 | $connection = CreateObject('contactcenter.so_connection', $id); |
---|
| 523 | |
---|
| 524 | if ($extra === 'default' and $connection->is_default()) |
---|
| 525 | { |
---|
| 526 | $connection_type = CreateObject('contactcenter.so_contact_connection_type', $type); |
---|
| 527 | $return['connection'.$count]['id_connection'] = $id; |
---|
| 528 | $return['connection'.$count]['id_type'] = $type; |
---|
| 529 | $return['connection'.$count]['type'] = $connection_type->get_type_name(); |
---|
| 530 | $return['connection'.$count]['connection_name'] = $connection->get_name(); |
---|
| 531 | $return['connection'.$count]['connection_value'] = $connection->get_value(); |
---|
| 532 | $return['connection'.$count]['connection_is_default'] = $connection->is_default(); |
---|
| 533 | $count++; |
---|
| 534 | } |
---|
| 535 | else if ($extra !== 'default') |
---|
| 536 | { |
---|
| 537 | $connection_type = CreateObject('contactcenter.so_contact_connection_type', $type); |
---|
| 538 | $return['connection'.$count]['id_connection'] = $id; |
---|
| 539 | $return['connection'.$count]['id_type'] = $type; |
---|
| 540 | $return['connection'.$count]['type'] = $connection_type->get_type_name(); |
---|
| 541 | $return['connection'.$count]['connection_name'] = $connection->get_name(); |
---|
| 542 | $return['connection'.$count]['connection_value'] = $connection->get_value(); |
---|
| 543 | $return['connection'.$count]['connection_is_default'] = $connection->is_default(); |
---|
| 544 | $count++; |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | return $return; |
---|
| 549 | } |
---|
| 550 | |
---|
| 551 | /*! |
---|
| 552 | |
---|
| 553 | @function get_companies |
---|
| 554 | @abstract Returns all Contacts companies information |
---|
| 555 | @author Raphael Derosso Pereira |
---|
| 556 | |
---|
| 557 | @param integer $id_contact The Contact ID |
---|
| 558 | |
---|
| 559 | @return The following array: |
---|
| 560 | $return = array( |
---|
| 561 | 'company1' => array( |
---|
| 562 | 'id_company' => <id_company>, |
---|
| 563 | 'company_name' => '<company_name>' |
---|
| 564 | 'title' => '<company_name>', |
---|
| 565 | 'department' => '<company_value>', |
---|
| 566 | ), |
---|
| 567 | 'company2' => array(...), |
---|
| 568 | ... |
---|
| 569 | ); |
---|
| 570 | |
---|
| 571 | */ |
---|
| 572 | function get_companies ( $id_contact,$extra=false ) |
---|
| 573 | { |
---|
| 574 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
| 575 | $companies = $contact->get_companies($extra); |
---|
| 576 | |
---|
| 577 | $count = 1; |
---|
| 578 | foreach($companies as $id => $value) |
---|
| 579 | { |
---|
| 580 | $company = CreateObject('contactcenter.so_company', $id); |
---|
| 581 | |
---|
| 582 | if ($extra === 'default' and $value['default_company']) |
---|
| 583 | { |
---|
| 584 | $return['company'.$count]['id_company'] = $id; |
---|
| 585 | $return['company'.$count]['company_name'] = $company->get_company_name(); |
---|
| 586 | $return['company'.$count]['title'] = $value['title']; |
---|
| 587 | $return['company'.$count]['department'] = $value['department']; |
---|
| 588 | $return['company'.$count]['default_company'] = $value['default_company']; |
---|
| 589 | $return['company'.$count]['default_contact'] = $value['default_contact']; |
---|
| 590 | $count++; |
---|
| 591 | } |
---|
| 592 | else if ($extra !== 'default') |
---|
| 593 | { |
---|
| 594 | $return['company'.$count]['id_company'] = $id; |
---|
| 595 | $return['company'.$count]['company_name'] = $company->get_company_name(); |
---|
| 596 | $return['company'.$count]['title'] = $value['title']; |
---|
| 597 | $return['company'.$count]['department'] = $value['department']; |
---|
| 598 | $return['company'.$count]['default_company'] = $value['default_company']; |
---|
| 599 | $return['company'.$count]['default_contact'] = $value['default_contact']; |
---|
| 600 | $count++; |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | |
---|
| 604 | return $return; |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | |
---|
| 608 | /*********************************************************************\ |
---|
| 609 | * Methods to get general fields * |
---|
| 610 | \*********************************************************************/ |
---|
| 611 | |
---|
| 612 | /*! |
---|
| 613 | |
---|
| 614 | @function get_all_prefixes |
---|
| 615 | @abstract Returns all the registered prefixes |
---|
| 616 | @author Raphael Derosso Pereira |
---|
| 617 | |
---|
| 618 | */ |
---|
| 619 | function get_all_prefixes ( ) |
---|
| 620 | { |
---|
| 621 | $fields = array('prefix.id_prefix','prefix.prefix'); |
---|
| 622 | |
---|
| 623 | $prefixes = $this->find($fields); |
---|
| 624 | |
---|
| 625 | if (!is_array($prefixes)) |
---|
| 626 | { |
---|
| 627 | return false; |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | while (list(,$prefix) = each($prefixes)) |
---|
| 631 | { |
---|
| 632 | $result[$prefix['id_prefix']] = $prefix['prefix']; |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | return $result; |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | |
---|
| 639 | /*! |
---|
| 640 | |
---|
| 641 | @function get_all_suffixes |
---|
| 642 | @abstract Returns all the registered suffixes |
---|
| 643 | @author Raphael Derosso Pereira |
---|
| 644 | @return An array as follows: |
---|
| 645 | $return = array( |
---|
| 646 | <id_suffix1> => '<suffix_name1>', |
---|
| 647 | <id_suffix2> => '<suffix_name2>', |
---|
| 648 | ... |
---|
| 649 | ); |
---|
| 650 | |
---|
| 651 | */ |
---|
| 652 | function get_all_suffixes ( ) |
---|
| 653 | { |
---|
| 654 | $fields = array('suffix.id_suffix','suffix.suffix'); |
---|
| 655 | |
---|
| 656 | $suffixes = $this->find($fields); |
---|
| 657 | |
---|
| 658 | if (!is_array($suffixes)) |
---|
| 659 | { |
---|
| 660 | return false; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | while (list(,$suffix) = each($suffixes)) |
---|
| 664 | { |
---|
| 665 | $result[$suffix['id_suffix']] = $suffix['suffix']; |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | return $result; |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | /*! |
---|
| 672 | |
---|
| 673 | @function get_all_status |
---|
| 674 | @abstract Returns all the registered status |
---|
| 675 | @author Raphael Derosso Pereira |
---|
| 676 | @return An array as follows: |
---|
| 677 | $return = array( |
---|
| 678 | <id_status1> => '<status_name1>', |
---|
| 679 | <id_status2> => '<status_name2>', |
---|
| 680 | ... |
---|
| 681 | ); |
---|
| 682 | |
---|
| 683 | */ |
---|
| 684 | function get_all_status ( ) |
---|
| 685 | { |
---|
| 686 | $fields = array('status.id_status','status.status_name'); |
---|
| 687 | |
---|
| 688 | $status = $this->find($fields); |
---|
| 689 | |
---|
| 690 | if (!is_array($status)) |
---|
| 691 | { |
---|
| 692 | return false; |
---|
| 693 | } |
---|
| 694 | |
---|
| 695 | while (list(,$status_) = each($status)) |
---|
| 696 | { |
---|
| 697 | $result[$status_['id_status']] = $status_['status_name']; |
---|
| 698 | } |
---|
| 699 | |
---|
| 700 | return $result; |
---|
| 701 | } |
---|
| 702 | |
---|
| 703 | /*! |
---|
| 704 | |
---|
| 705 | @function get_all_relations_types |
---|
| 706 | @abstract Returns all contacts relations types |
---|
| 707 | @author Raphael Derosso Pereira |
---|
| 708 | |
---|
| 709 | @return array The format of the return is: |
---|
| 710 | $return = array( |
---|
| 711 | <id_type1> => '<type1_name>', |
---|
| 712 | <id_type2> => '<type2_name>', |
---|
| 713 | ...); |
---|
| 714 | */ |
---|
| 715 | function get_all_relations_types ( ) |
---|
| 716 | { |
---|
| 717 | $fields = array('typeof_contact_relation.id_typeof_contact_relation', 'typeof_contact_relation.contact_relation_type_name'); |
---|
| 718 | |
---|
| 719 | $relation_types = $this->find($fields); |
---|
| 720 | |
---|
| 721 | if (!is_array($relation_types)) |
---|
| 722 | { |
---|
| 723 | return false; |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | while (list(,$relation_type) = each($relation_types)) |
---|
| 727 | { |
---|
| 728 | $result[$relation_type['id_typeof_contact_relation']] = $relation_type['contact_relation_type_name']; |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | return $result; |
---|
| 732 | } |
---|
| 733 | |
---|
| 734 | /*! |
---|
| 735 | |
---|
| 736 | @function get_all_addresses_types |
---|
| 737 | @abstract Returns all contacts addresses types |
---|
| 738 | @author Raphael Derosso Pereira |
---|
| 739 | |
---|
| 740 | @return array The format of the return is: |
---|
| 741 | $return = array( |
---|
| 742 | <id_type1> => '<type1_name>', |
---|
| 743 | <id_type2> => '<type2_name>', |
---|
| 744 | ...); |
---|
| 745 | */ |
---|
| 746 | function get_all_addresses_types ( ) |
---|
| 747 | { |
---|
| 748 | $fields = array('typeof_contact_address.id_typeof_contact_address', 'typeof_contact_address.contact_address_type_name'); |
---|
| 749 | |
---|
| 750 | $address_types = $this->find($fields); |
---|
| 751 | |
---|
| 752 | if (!is_array($address_types)) |
---|
| 753 | { |
---|
| 754 | return false; |
---|
| 755 | } |
---|
| 756 | |
---|
| 757 | while (list(,$address_type) = each($address_types)) |
---|
| 758 | { |
---|
| 759 | $result[$address_type['id_typeof_contact_address']] = $address_type['contact_address_type_name']; |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | return $result; |
---|
| 763 | } |
---|
| 764 | |
---|
| 765 | /*! |
---|
| 766 | |
---|
| 767 | @function get_all_connections_types |
---|
| 768 | @abstract Returns all contacts connections types |
---|
| 769 | @author Raphael Derosso Pereira |
---|
| 770 | |
---|
| 771 | @return array The format of the return is: |
---|
| 772 | $return = array( |
---|
| 773 | <id_type1> => '<type1_name>', |
---|
| 774 | <id_type2> => '<type2_name>', |
---|
| 775 | ...); |
---|
| 776 | */ |
---|
| 777 | function get_all_connections_types ( ) |
---|
| 778 | { |
---|
| 779 | $fields = array('typeof_contact_connection.id_typeof_contact_connection', 'typeof_contact_connection.contact_connection_type_name'); |
---|
| 780 | |
---|
| 781 | $connection_types = $this->find($fields); |
---|
| 782 | |
---|
| 783 | if (!is_array($connection_types)) |
---|
| 784 | { |
---|
| 785 | return false; |
---|
| 786 | } |
---|
| 787 | |
---|
| 788 | while (list(,$connection_type) = each($connection_types)) |
---|
| 789 | { |
---|
| 790 | $result[$connection_type['id_typeof_contact_connection']] = $connection_type['contact_connection_type_name']; |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | return $result; |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | /*! |
---|
| 797 | |
---|
| 798 | @function get_vcard |
---|
| 799 | @abstract Returns an URL that points to the file |
---|
| 800 | that contains a vCard of the specified Contact |
---|
| 801 | @author Raphael Derosso Pereira |
---|
| 802 | |
---|
| 803 | @param integer $id_status The Contact ID |
---|
| 804 | |
---|
| 805 | */ |
---|
| 806 | function get_vcard ( $id_contact ) |
---|
| 807 | { |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | |
---|
| 811 | /*********************************************************************\ |
---|
| 812 | * Methods to Include Data * |
---|
| 813 | \*********************************************************************/ |
---|
| 814 | |
---|
| 815 | /*! |
---|
| 816 | |
---|
| 817 | @function add_single_entry |
---|
| 818 | @abstract Insert a new Contact record in the DB |
---|
| 819 | @author Raphael Derosso Pereira |
---|
| 820 | |
---|
| 821 | @param array $data The Contact Information. |
---|
| 822 | |
---|
| 823 | Format: |
---|
| 824 | |
---|
| 825 | $data = array( |
---|
| 826 | 'id_status' => <id_status>, |
---|
| 827 | 'photo' => '<photo_bin_stream>', |
---|
| 828 | 'alias' => '<alias>', |
---|
| 829 | 'id_prefix' => <id_prefix>, |
---|
| 830 | 'given_names' => '<given_names>', |
---|
| 831 | 'family_names' => '<family_names>', |
---|
| 832 | 'names_ordered' => '<names_ordered>', |
---|
| 833 | 'id_suffix' => <id_suffix>, |
---|
| 834 | 'birthdate' => '<birthdate>', |
---|
| 835 | 'sex' => '<sex>', |
---|
| 836 | 'pgp_key' => '<pgp_key>', |
---|
| 837 | 'notes' => '<notes>', |
---|
| 838 | |
---|
| 839 | 'companies' => array( |
---|
| 840 | company1 => array( |
---|
| 841 | 'id_company' => <id_company>, |
---|
| 842 | 'company_name' => <company_name>, |
---|
| 843 | 'title' => <title>, |
---|
| 844 | 'department' => <department>, |
---|
| 845 | 'default_company' => (bool), |
---|
| 846 | 'default_contact' => (bool) |
---|
| 847 | ), |
---|
| 848 | company2 => array(...), |
---|
| 849 | ... |
---|
| 850 | ), |
---|
| 851 | |
---|
| 852 | 'relations' => array( |
---|
| 853 | 'relation1' => array( |
---|
| 854 | 'id_relation' => <id_relation>, |
---|
| 855 | 'id_typeof_relation' => <id_typeof_relation>, |
---|
| 856 | ), |
---|
| 857 | 'relation2' => array(...), |
---|
| 858 | ... |
---|
| 859 | ), |
---|
| 860 | |
---|
| 861 | 'addresses' => array( |
---|
| 862 | 'address1' => array( |
---|
| 863 | 'id_typeof_address' => <id_typeof_address>, |
---|
| 864 | 'address1' => '<address1>', |
---|
| 865 | 'address2' => '<address2>', |
---|
| 866 | 'complement' => '<complement>', |
---|
| 867 | 'address_other' => '<address_other>', |
---|
| 868 | 'postal_code' => '<postal_code>', |
---|
| 869 | 'po_box' => '<po_box>', |
---|
| 870 | 'id_city' => '<city>', |
---|
| 871 | 'address_is_default' => <trueness> |
---|
| 872 | ), |
---|
| 873 | 'address2' => array(...), |
---|
| 874 | ... |
---|
| 875 | ), |
---|
| 876 | |
---|
| 877 | 'connections' => array( |
---|
| 878 | 'connection1' => array( |
---|
| 879 | 'id_typeof_connection' => <id_typeof_connection>, |
---|
| 880 | 'connection_name' => <connection_name>, |
---|
| 881 | 'connection_value' => <connection_value>, |
---|
| 882 | 'connection_is_default' => <trueness> |
---|
| 883 | ), |
---|
| 884 | 'connection2' => array(...), |
---|
| 885 | ... |
---|
| 886 | ), |
---|
| 887 | |
---|
| 888 | ); |
---|
| 889 | |
---|
| 890 | If any of the above fields doesn't have a value, it should hold false. |
---|
| 891 | In the case of the multiple-values fields, instead of the array, there |
---|
| 892 | should be a false. |
---|
| 893 | |
---|
| 894 | @return integer $id The Contact ID |
---|
| 895 | */ |
---|
| 896 | function add_single_entry ( $data ) |
---|
| 897 | { |
---|
| 898 | $permissions = $this->security->get_permissions(); |
---|
| 899 | |
---|
| 900 | if (!$permissions['create']) |
---|
| 901 | { |
---|
| 902 | //return false; |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | $contact = CreateObject('contactcenter.so_contact'); |
---|
| 906 | $contact->reset_values(); |
---|
| 907 | |
---|
| 908 | $altered = false; |
---|
| 909 | foreach($data as $field => $value) |
---|
| 910 | { |
---|
| 911 | if ($value === false) |
---|
| 912 | { |
---|
| 913 | continue; |
---|
| 914 | } |
---|
| 915 | |
---|
| 916 | $altered = true; |
---|
| 917 | switch($field) |
---|
| 918 | { |
---|
| 919 | case 'photo': |
---|
| 920 | case 'alias': |
---|
| 921 | case 'id_prefix': |
---|
| 922 | case 'id_status': |
---|
| 923 | case 'id_suffix': |
---|
| 924 | case 'given_names': |
---|
| 925 | case 'family_names': |
---|
| 926 | case 'names_ordered': |
---|
| 927 | case 'birthdate': |
---|
| 928 | case 'sex': |
---|
| 929 | case 'pgp_key': |
---|
| 930 | case 'notes': |
---|
| 931 | $contact->set_field($field,$value); |
---|
| 932 | break; |
---|
| 933 | |
---|
| 934 | case 'companies': |
---|
| 935 | foreach($value as $company_fields) |
---|
| 936 | { |
---|
| 937 | if ($company_fields['company_name']) |
---|
| 938 | { |
---|
| 939 | $fields = array('company.id_company'); |
---|
| 940 | $restric = array( |
---|
| 941 | 0 => array( |
---|
| 942 | 'field' => 'company.company_name', |
---|
| 943 | 'type' => 'iLIKE', |
---|
| 944 | 'value' => $company_fields['company_name'] |
---|
| 945 | ) |
---|
| 946 | ); |
---|
| 947 | |
---|
| 948 | if($result = $this->find($fields,$restric)) |
---|
| 949 | { |
---|
| 950 | $id = $result[0]['id_company']; |
---|
| 951 | $company_fields['id_company'] = $id; |
---|
| 952 | } |
---|
| 953 | else |
---|
| 954 | { |
---|
| 955 | $company = CreateObject('contactcenter.so_company'); |
---|
| 956 | $company->reset_values(); |
---|
| 957 | $company->set_company_name($company_fields['company_name']); |
---|
| 958 | $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 959 | $company_fields['id_company'] = $company->commit(); |
---|
| 960 | } |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | $contact->set_company($company_fields); |
---|
| 964 | } |
---|
| 965 | break; |
---|
| 966 | |
---|
| 967 | case 'relations': |
---|
| 968 | foreach($value as $relation_fields) |
---|
| 969 | { |
---|
| 970 | $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']); |
---|
| 971 | } |
---|
| 972 | break; |
---|
| 973 | |
---|
| 974 | case 'addresses': |
---|
| 975 | foreach($value as $address_fields) |
---|
| 976 | { |
---|
| 977 | $address = CreateObject('contactcenter.so_address'); |
---|
| 978 | $address->reset_values(); |
---|
| 979 | foreach($address_fields as $a_field => $a_value) |
---|
| 980 | { |
---|
| 981 | if ($a_field !== 'id_typeof_address') |
---|
| 982 | { |
---|
| 983 | $address->set_field($a_field,$a_value); |
---|
| 984 | } |
---|
| 985 | } |
---|
| 986 | $address->commit(); |
---|
| 987 | $id_address = $address->get_id(); |
---|
| 988 | $contact->set_address($id_address, $address_fields['id_typeof_address']); |
---|
| 989 | } |
---|
| 990 | break; |
---|
| 991 | |
---|
| 992 | case 'connections': |
---|
| 993 | foreach($value as $connection_name => $connection_fields) |
---|
| 994 | { |
---|
| 995 | $connection = CreateObject('contactcenter.so_connection'); |
---|
| 996 | $connection->reset_values(); |
---|
| 997 | |
---|
| 998 | foreach($connection_fields as $a_field => $a_value) |
---|
| 999 | { |
---|
| 1000 | if ($a_field !== 'id_typeof_connection') |
---|
| 1001 | { |
---|
| 1002 | $connection->set_field($a_field,$a_value); |
---|
| 1003 | } |
---|
| 1004 | } |
---|
| 1005 | |
---|
| 1006 | $connection->commit(); |
---|
| 1007 | $id_connection = $connection->get_id(); |
---|
| 1008 | $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']); |
---|
| 1009 | } |
---|
| 1010 | break; |
---|
| 1011 | |
---|
| 1012 | default: |
---|
| 1013 | return false; |
---|
| 1014 | } |
---|
| 1015 | } |
---|
| 1016 | |
---|
| 1017 | if ($altered) |
---|
| 1018 | { |
---|
| 1019 | $contact->set_field('id_owner',$GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 1020 | return $contact->commit(); |
---|
| 1021 | } |
---|
| 1022 | |
---|
| 1023 | return false; |
---|
| 1024 | } |
---|
| 1025 | |
---|
| 1026 | /*! |
---|
| 1027 | |
---|
| 1028 | @function quick_add |
---|
| 1029 | @abstract Insert a new Contact record in the DB with just the |
---|
| 1030 | main fields |
---|
| 1031 | @author Raphael Derosso Pereira |
---|
| 1032 | |
---|
| 1033 | @param array $data The Contact Information. |
---|
| 1034 | |
---|
| 1035 | Format: |
---|
| 1036 | |
---|
| 1037 | $data = array( |
---|
| 1038 | 'alias' => '<alias>', |
---|
| 1039 | 'given_names' => '<given_names>', |
---|
| 1040 | 'family_names' => '<family_names>', |
---|
| 1041 | |
---|
| 1042 | 'connections' => array( |
---|
| 1043 | 'default_email' => array( |
---|
| 1044 | 'connection_name' => <connection_name>, |
---|
| 1045 | 'connection_value' => <connection_value> |
---|
| 1046 | ), |
---|
| 1047 | 'default_phone' => array( |
---|
| 1048 | 'connection_name' => <connection_name>, |
---|
| 1049 | 'connection_value' => <connection_value> |
---|
| 1050 | ) |
---|
| 1051 | ) |
---|
| 1052 | ); |
---|
| 1053 | */ |
---|
| 1054 | function quick_add ( $data ) |
---|
| 1055 | { |
---|
| 1056 | $permissions = $this->security->get_permissions(); |
---|
| 1057 | |
---|
| 1058 | if (!$permissions['create']) |
---|
| 1059 | { |
---|
| 1060 | return false; |
---|
| 1061 | } |
---|
| 1062 | |
---|
| 1063 | // TODO: GET THE ORDER TO PUT names_ordered FROM PREFERENCES! |
---|
| 1064 | |
---|
| 1065 | $preferences = ExecMethod('contactcenter.ui_preferences.get_preferences'); |
---|
| 1066 | |
---|
| 1067 | if (!is_array($preferences)) |
---|
| 1068 | { |
---|
| 1069 | $preferences['personCardEmail'] = 1; |
---|
| 1070 | $preferences['personCardPhone'] = 2; |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | $new_data = array( |
---|
| 1074 | 'alias' => $data['alias'], |
---|
| 1075 | 'id_status' => 1, |
---|
| 1076 | 'given_names' => $data['given_names'], |
---|
| 1077 | 'family_names' => $data['family_names'], |
---|
| 1078 | 'names_ordered' => $data['given_names'].' '.$data['family_names'], |
---|
| 1079 | ); |
---|
| 1080 | |
---|
| 1081 | $i = 1; |
---|
| 1082 | if ($data['connections']['default_email']['connection_value']) |
---|
| 1083 | { |
---|
| 1084 | $new_data['connections']['connection'.$i] = array( |
---|
| 1085 | 'id_typeof_connection' => $preferences['personCardEmail'], |
---|
| 1086 | 'connection_name' => $data['connections']['default_email']['connection_name'], |
---|
| 1087 | 'connection_value' => $data['connections']['default_email']['connection_value'], |
---|
| 1088 | 'connection_is_default' => 1, |
---|
| 1089 | ); |
---|
| 1090 | $i++; |
---|
| 1091 | } |
---|
| 1092 | |
---|
| 1093 | if ($data['connections']['default_phone']['connection_value']) |
---|
| 1094 | { |
---|
| 1095 | $new_data['connections']['connection'.$i] = array( |
---|
| 1096 | 'id_typeof_connection' => $preferences['personCardPhone'], |
---|
| 1097 | 'connection_name' => $data['connections']['default_phone']['connection_name'], |
---|
| 1098 | 'connection_value' => $data['connections']['default_phone']['connection_value'], |
---|
| 1099 | 'connection_is_default' => 1, |
---|
| 1100 | ); |
---|
| 1101 | } |
---|
| 1102 | |
---|
| 1103 | return $this->add_single_entry($new_data); |
---|
| 1104 | } |
---|
| 1105 | |
---|
| 1106 | /*! |
---|
| 1107 | |
---|
| 1108 | @function add_prefix |
---|
| 1109 | @abstract Insert a new Prefix in the DB |
---|
| 1110 | @author Raphael Derosso Pereira |
---|
| 1111 | |
---|
| 1112 | @param string $prefix The Prefix |
---|
| 1113 | @return integer The new ID |
---|
| 1114 | |
---|
| 1115 | */ |
---|
| 1116 | function add_prefix ( $prefix ) |
---|
| 1117 | { |
---|
| 1118 | $permissions = $this->security->get_type_permissions(); |
---|
| 1119 | |
---|
| 1120 | if (!$permissions['create']) |
---|
| 1121 | { |
---|
| 1122 | return false; |
---|
| 1123 | } |
---|
| 1124 | } |
---|
| 1125 | |
---|
| 1126 | /*! |
---|
| 1127 | |
---|
| 1128 | @function add_suffix |
---|
| 1129 | @abstract Insert a new suffix in the DB |
---|
| 1130 | @author Raphael Derosso Pereira |
---|
| 1131 | |
---|
| 1132 | @param string $suffix The suffix |
---|
| 1133 | @return integer The new ID |
---|
| 1134 | |
---|
| 1135 | */ |
---|
| 1136 | function add_suffix ( $suffix ) |
---|
| 1137 | { |
---|
| 1138 | $permissions = $this->security->get_type_permissions(); |
---|
| 1139 | |
---|
| 1140 | if (!$permissions['create']) |
---|
| 1141 | { |
---|
| 1142 | return false; |
---|
| 1143 | } |
---|
| 1144 | } |
---|
| 1145 | |
---|
| 1146 | /*! |
---|
| 1147 | |
---|
| 1148 | @function add_status |
---|
| 1149 | @abstract Insert a new Status in the DB |
---|
| 1150 | @author Raphael Derosso Pereira |
---|
| 1151 | |
---|
| 1152 | @param string $status The Status |
---|
| 1153 | @return integer The new ID |
---|
| 1154 | |
---|
| 1155 | */ |
---|
| 1156 | function add_status ( $status ) |
---|
| 1157 | { |
---|
| 1158 | $permissions = $this->security->get_type_permissions(); |
---|
| 1159 | |
---|
| 1160 | if (!$permissions['create']) |
---|
| 1161 | { |
---|
| 1162 | return false; |
---|
| 1163 | } |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | /*! |
---|
| 1167 | |
---|
| 1168 | @function add_relation_type |
---|
| 1169 | @abstract Insert a new Relation Type in the DB |
---|
| 1170 | @author Raphael Derosso Pereira |
---|
| 1171 | |
---|
| 1172 | @param string $type_name The Relation Type |
---|
| 1173 | @return integer The new ID |
---|
| 1174 | |
---|
| 1175 | */ |
---|
| 1176 | function add_relation_type ( $type_name ) |
---|
| 1177 | { |
---|
| 1178 | $permissions = $this->security->get_type_permissions(); |
---|
| 1179 | |
---|
| 1180 | if (!$permissions['create']) |
---|
| 1181 | { |
---|
| 1182 | return false; |
---|
| 1183 | } |
---|
| 1184 | } |
---|
| 1185 | |
---|
| 1186 | /*! |
---|
| 1187 | |
---|
| 1188 | @function add_address_type |
---|
| 1189 | @abstract Insert a new Address Type in the DB |
---|
| 1190 | @author Raphael Derosso Pereira |
---|
| 1191 | |
---|
| 1192 | @param string $type_name The Address Type |
---|
| 1193 | @return integer The new ID |
---|
| 1194 | |
---|
| 1195 | */ |
---|
| 1196 | function add_address_type ( $type_name ) |
---|
| 1197 | { |
---|
| 1198 | $permissions = $this->security->get_type_permissions(); |
---|
| 1199 | |
---|
| 1200 | if (!$permissions['create']) |
---|
| 1201 | { |
---|
| 1202 | return false; |
---|
| 1203 | } |
---|
| 1204 | } |
---|
| 1205 | |
---|
| 1206 | /*! |
---|
| 1207 | |
---|
| 1208 | @function add_connection_type |
---|
| 1209 | @abstract Insert a new Connection Type in the DB |
---|
| 1210 | @author Raphael Derosso Pereira |
---|
| 1211 | |
---|
| 1212 | @param string $type_name The Connection Type |
---|
| 1213 | @return integer The new ID |
---|
| 1214 | |
---|
| 1215 | */ |
---|
| 1216 | function add_connection_type ( $type_name ) |
---|
| 1217 | { |
---|
| 1218 | $permissions = $this->security->get_type_permissions(); |
---|
| 1219 | |
---|
| 1220 | if (!$permissions['create']) |
---|
| 1221 | { |
---|
| 1222 | return false; |
---|
| 1223 | } |
---|
| 1224 | } |
---|
| 1225 | |
---|
| 1226 | |
---|
| 1227 | |
---|
| 1228 | /*********************************************************************\ |
---|
| 1229 | * Methods to Alter Data * |
---|
| 1230 | \*********************************************************************/ |
---|
| 1231 | |
---|
| 1232 | /*! |
---|
| 1233 | |
---|
| 1234 | @function update_single_info |
---|
| 1235 | @abstract Update information of an existing Contact |
---|
| 1236 | @author Raphael Derosso Pereira |
---|
| 1237 | |
---|
| 1238 | @param integer $id_status The Contact ID |
---|
| 1239 | @param string $status The new Status value |
---|
| 1240 | |
---|
| 1241 | */ |
---|
| 1242 | function update_single_info ( $id_contact, $data ) |
---|
| 1243 | { |
---|
| 1244 | $permissions = $this->security->get_permissions($id_contact); |
---|
| 1245 | |
---|
| 1246 | if (!$permissions['write']) |
---|
| 1247 | { |
---|
| 1248 | return false; |
---|
| 1249 | } |
---|
| 1250 | |
---|
| 1251 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
| 1252 | |
---|
| 1253 | $altered = false; |
---|
| 1254 | // print_r($data); |
---|
| 1255 | foreach($data as $field => $value) |
---|
| 1256 | { |
---|
| 1257 | if ($value === false) |
---|
| 1258 | { |
---|
| 1259 | continue; |
---|
| 1260 | } |
---|
| 1261 | |
---|
| 1262 | $altered = true; |
---|
| 1263 | switch($field) |
---|
| 1264 | { |
---|
| 1265 | case 'photo': |
---|
| 1266 | case 'alias': |
---|
| 1267 | case 'id_prefix': |
---|
| 1268 | case 'id_status': |
---|
| 1269 | case 'id_suffix': |
---|
| 1270 | case 'given_names': |
---|
| 1271 | case 'family_names': |
---|
| 1272 | case 'names_ordered': |
---|
| 1273 | case 'birthdate': |
---|
| 1274 | case 'sex': |
---|
| 1275 | case 'pgp_key': |
---|
| 1276 | case 'notes': |
---|
| 1277 | $contact->set_field($field,$value); |
---|
| 1278 | break; |
---|
| 1279 | |
---|
| 1280 | case 'companies': |
---|
| 1281 | foreach($value as $company_fields) |
---|
| 1282 | { |
---|
| 1283 | if ($company_fields['company_name']) |
---|
| 1284 | { |
---|
| 1285 | $fields = array('company.id_company'); |
---|
| 1286 | $restric = array( |
---|
| 1287 | 0 => array( |
---|
| 1288 | 'field' => 'company.company_name', |
---|
| 1289 | 'type' => 'iLIKE', |
---|
| 1290 | 'value' => $company_fields['company_name'] |
---|
| 1291 | ) |
---|
| 1292 | ); |
---|
| 1293 | |
---|
| 1294 | if($result = $this->find($fields,$restric)) |
---|
| 1295 | { |
---|
| 1296 | $id = $result[0]['id_company']; |
---|
| 1297 | $company_fields['id_company'] = $id; |
---|
| 1298 | } |
---|
| 1299 | else |
---|
| 1300 | { |
---|
| 1301 | $company = CreateObject('contactcenter.so_company'); |
---|
| 1302 | $company->reset_values(); |
---|
| 1303 | $company->set_company_name($company_fields['company_name']); |
---|
| 1304 | $company->set_field('id_company_owner',$GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 1305 | $company_fields['id_company'] = $company->commit(); |
---|
| 1306 | } |
---|
| 1307 | } |
---|
| 1308 | |
---|
| 1309 | $contact->set_company($company_fields); |
---|
| 1310 | } |
---|
| 1311 | break; |
---|
| 1312 | |
---|
| 1313 | case 'relations': |
---|
| 1314 | foreach($value as $relation_fields) |
---|
| 1315 | { |
---|
| 1316 | $contact->set_relation($relation_fields['id_relation'], $relation_fields['id_typeof_relation']); |
---|
| 1317 | } |
---|
| 1318 | break; |
---|
| 1319 | |
---|
| 1320 | case 'addresses': |
---|
| 1321 | foreach($value as $address_name => $address_fields) |
---|
| 1322 | { |
---|
| 1323 | if ($address_fields['id_address'] && $address_fields['id_address'] !== '') |
---|
| 1324 | { |
---|
| 1325 | $address = CreateObject('contactcenter.so_address', $address_fields['id_address']); |
---|
| 1326 | } |
---|
| 1327 | else |
---|
| 1328 | { |
---|
| 1329 | $address = CreateObject('contactcenter.so_address'); |
---|
| 1330 | $address->reset_values(); |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | if (!isset($address_fields['id_country']) or $address_fields['id_country'] === false) |
---|
| 1334 | { |
---|
| 1335 | #var_dump($address_fields); |
---|
| 1336 | echo(serialize(array( |
---|
| 1337 | 'file' => __FILE__, |
---|
| 1338 | 'line' => __LINE__, |
---|
| 1339 | 'msg' => lang('An Address must have at least a Country'), |
---|
| 1340 | 'status' => 'aborted' |
---|
| 1341 | ))); |
---|
| 1342 | return; |
---|
| 1343 | } |
---|
| 1344 | |
---|
| 1345 | foreach ($address_fields as $f_name => $f_value) |
---|
| 1346 | { |
---|
| 1347 | if ($f_value === false) |
---|
| 1348 | { |
---|
| 1349 | $address->set_field($f_name, null); |
---|
| 1350 | } |
---|
| 1351 | elseif (isset($f_value)) |
---|
| 1352 | { |
---|
| 1353 | $address->set_field($f_name, $f_value); |
---|
| 1354 | } |
---|
| 1355 | } |
---|
| 1356 | |
---|
| 1357 | $address->commit(); |
---|
| 1358 | $id_address = $address->get_id(); |
---|
| 1359 | $contact->set_address($id_address, $address_fields['id_typeof_address']); |
---|
| 1360 | } |
---|
| 1361 | break; |
---|
| 1362 | |
---|
| 1363 | case 'connections': |
---|
| 1364 | foreach($value as $connection_name => $connection_fields) |
---|
| 1365 | { |
---|
| 1366 | if ($connection_name === 'removed_conns') |
---|
| 1367 | { |
---|
| 1368 | foreach($connection_fields as $id) |
---|
| 1369 | { |
---|
| 1370 | $connection = CreateObject('contactcenter.so_connection', $id); |
---|
| 1371 | if (!($connection->remove())) |
---|
| 1372 | { |
---|
| 1373 | return false; |
---|
| 1374 | } |
---|
| 1375 | |
---|
| 1376 | $contact->remove_connection($id); |
---|
| 1377 | } |
---|
| 1378 | |
---|
| 1379 | continue; |
---|
| 1380 | } |
---|
| 1381 | |
---|
| 1382 | $id_connection = $connection_fields['id_connection']; |
---|
| 1383 | if ($id_connection === '_NEW_' or |
---|
| 1384 | $id_connection === '') |
---|
| 1385 | { |
---|
| 1386 | $connection = CreateObject('contactcenter.so_connection'); |
---|
| 1387 | $connection->reset_values(); |
---|
| 1388 | } |
---|
| 1389 | else |
---|
| 1390 | { |
---|
| 1391 | $connection = CreateObject('contactcenter.so_connection', $id_connection); |
---|
| 1392 | } |
---|
| 1393 | |
---|
| 1394 | foreach($connection_fields as $a_field => $a_value) |
---|
| 1395 | { |
---|
| 1396 | if ($a_field !== 'id_typeof_connection') |
---|
| 1397 | { |
---|
| 1398 | $connection->set_field($a_field,$a_value); |
---|
| 1399 | } |
---|
| 1400 | } |
---|
| 1401 | |
---|
| 1402 | if (!$connection->commit()) |
---|
| 1403 | { |
---|
| 1404 | return false; |
---|
| 1405 | } |
---|
| 1406 | $id_connection = $connection->get_id(); |
---|
| 1407 | $contact->set_connection($id_connection, $connection_fields['id_typeof_connection']); |
---|
| 1408 | } |
---|
| 1409 | break; |
---|
| 1410 | |
---|
| 1411 | default: |
---|
| 1412 | echo 'Invalid Field: '.$field.'<br>Value: '.$value; |
---|
| 1413 | return false; |
---|
| 1414 | } |
---|
| 1415 | } |
---|
| 1416 | |
---|
| 1417 | if ($altered) |
---|
| 1418 | { |
---|
[285] | 1419 | $contact->set_field("last_status", 'U'); |
---|
| 1420 | $contact->set_field("last_update",time()."000"); |
---|
[2] | 1421 | return $contact->commit(); |
---|
| 1422 | } |
---|
| 1423 | |
---|
| 1424 | return false; |
---|
| 1425 | } |
---|
| 1426 | |
---|
| 1427 | /*! |
---|
| 1428 | |
---|
| 1429 | @function update_prefix |
---|
| 1430 | @abstract Update an existing Prefix |
---|
| 1431 | @author Raphael Derosso Pereira |
---|
| 1432 | |
---|
| 1433 | @param integer $id_prefix The Prefix ID |
---|
| 1434 | @param string $prefix The new Prefix value |
---|
| 1435 | |
---|
| 1436 | */ |
---|
| 1437 | function update_prefix ( $id_prefix, $prefix ) |
---|
| 1438 | { |
---|
| 1439 | $permissions = $this->security->get_type_permissions(); |
---|
| 1440 | |
---|
| 1441 | if (!$permissions['alter']) |
---|
| 1442 | { |
---|
| 1443 | return false; |
---|
| 1444 | } |
---|
| 1445 | } |
---|
| 1446 | |
---|
| 1447 | /*! |
---|
| 1448 | |
---|
| 1449 | @function update_suffix |
---|
| 1450 | @abstract Update an existing suffix |
---|
| 1451 | @author Raphael Derosso Pereira |
---|
| 1452 | |
---|
| 1453 | @param integer $id_suffix The suffix ID |
---|
| 1454 | @param string $suffix The new suffix value |
---|
| 1455 | |
---|
| 1456 | */ |
---|
| 1457 | function update_suffix ( $id_suffix, $suffix ) |
---|
| 1458 | { |
---|
| 1459 | $permissions = $this->security->get_type_permissions(); |
---|
| 1460 | |
---|
| 1461 | if (!$permissions['alter']) |
---|
| 1462 | { |
---|
| 1463 | return false; |
---|
| 1464 | } |
---|
| 1465 | } |
---|
| 1466 | |
---|
| 1467 | /*! |
---|
| 1468 | |
---|
| 1469 | @function update_status |
---|
| 1470 | @abstract Update an existing Status |
---|
| 1471 | @author Raphael Derosso Pereira |
---|
| 1472 | |
---|
| 1473 | @param integer $id_status The Status ID |
---|
| 1474 | @param string $status The new Status value |
---|
| 1475 | |
---|
| 1476 | */ |
---|
| 1477 | function update_status ( $id_status, $status ) |
---|
| 1478 | { |
---|
| 1479 | $permissions = $this->security->get_type_permissions(); |
---|
| 1480 | |
---|
| 1481 | if (!$permissions['alter']) |
---|
| 1482 | { |
---|
| 1483 | return false; |
---|
| 1484 | } |
---|
| 1485 | } |
---|
| 1486 | |
---|
| 1487 | /*! |
---|
| 1488 | |
---|
| 1489 | @function update_relation_type |
---|
| 1490 | @abstract Update an existing Relation Type |
---|
| 1491 | @author Raphael Derosso Pereira |
---|
| 1492 | |
---|
| 1493 | @param integer $id_type The Type ID |
---|
| 1494 | @param string $type The new type value |
---|
| 1495 | |
---|
| 1496 | */ |
---|
| 1497 | function update_relation_type ( $old_name, $relation_name ) |
---|
| 1498 | { |
---|
| 1499 | } |
---|
| 1500 | |
---|
| 1501 | /*! |
---|
| 1502 | |
---|
| 1503 | @function update_address_type |
---|
| 1504 | @abstract Update an existing Address Type |
---|
| 1505 | @author Raphael Derosso Pereira |
---|
| 1506 | |
---|
| 1507 | @param integer $id_uype The Type ID |
---|
| 1508 | @param string $type The new type value |
---|
| 1509 | |
---|
| 1510 | */ |
---|
| 1511 | function update_address_type ( $id_type, $type ) |
---|
| 1512 | { |
---|
| 1513 | } |
---|
| 1514 | |
---|
| 1515 | /*! |
---|
| 1516 | |
---|
| 1517 | @function update_connection_type |
---|
| 1518 | @abstract Update an existing Connection Type |
---|
| 1519 | @author Raphael Derosso Pereira |
---|
| 1520 | |
---|
| 1521 | @param integer $id_type The Type ID |
---|
| 1522 | @param string $type The new type value |
---|
| 1523 | |
---|
| 1524 | */ |
---|
| 1525 | function update_connection_type ( $id_type, $type ) |
---|
| 1526 | { |
---|
| 1527 | } |
---|
| 1528 | |
---|
| 1529 | |
---|
| 1530 | /*********************************************************************\ |
---|
| 1531 | * Methods to Remove Data * |
---|
| 1532 | \*********************************************************************/ |
---|
| 1533 | |
---|
| 1534 | /*! |
---|
| 1535 | |
---|
| 1536 | @function remove_single_entry |
---|
| 1537 | @abstract Remove one contact from the DB |
---|
| 1538 | @author Raphael Derosso Pereira |
---|
| 1539 | |
---|
| 1540 | @param integer $id_contact The Contact ID |
---|
| 1541 | |
---|
| 1542 | */ |
---|
| 1543 | function remove_single_entry ( $id_contact ) |
---|
| 1544 | { |
---|
| 1545 | $permissions = $this->security->get_permissions(); |
---|
| 1546 | |
---|
| 1547 | if (!$permissions['remove']) |
---|
| 1548 | { |
---|
| 1549 | return false; |
---|
| 1550 | } |
---|
| 1551 | |
---|
| 1552 | $contact = CreateObject('contactcenter.so_contact', $id_contact); |
---|
| 1553 | |
---|
| 1554 | if ($contact->get_state() === 'new') |
---|
| 1555 | { |
---|
| 1556 | return false; |
---|
| 1557 | } |
---|
| 1558 | |
---|
| 1559 | $addresses = $contact->get_addresses(); |
---|
| 1560 | $connections = $contact->get_connections(); |
---|
| 1561 | |
---|
| 1562 | if (!$contact->remove()) |
---|
| 1563 | { |
---|
| 1564 | return false; |
---|
| 1565 | } |
---|
| 1566 | |
---|
| 1567 | foreach ($addresses as $id => $type) |
---|
| 1568 | { |
---|
| 1569 | if (!($address = CreateObject('contactcenter.so_address', $id))) |
---|
| 1570 | { |
---|
| 1571 | return false; |
---|
| 1572 | } |
---|
| 1573 | |
---|
| 1574 | if (!($address->remove())) |
---|
| 1575 | { |
---|
| 1576 | return false; |
---|
| 1577 | } |
---|
| 1578 | |
---|
| 1579 | } |
---|
| 1580 | |
---|
| 1581 | foreach ($connections as $id => $type) |
---|
| 1582 | { |
---|
| 1583 | if (!($connection = CreateObject('contactcenter.so_connection',$id))) |
---|
| 1584 | { |
---|
| 1585 | return false; |
---|
| 1586 | } |
---|
| 1587 | |
---|
| 1588 | if (!($connection->remove())) |
---|
| 1589 | { |
---|
| 1590 | return false; |
---|
| 1591 | } |
---|
| 1592 | |
---|
| 1593 | } |
---|
| 1594 | |
---|
| 1595 | return true; |
---|
| 1596 | } |
---|
| 1597 | } |
---|
| 1598 | ?> |
---|