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