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