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