/** * Perform the import of the contacts */ function user_contacts_import($vcf_contacts, $user_id) { include_once 'php/contact/addressbook.php'; include_once 'php/contact/contact_query.inc'; $remember_uid = $GLOBALS['obm']['uid']; $GLOBALS['obm']['uid'] = $user_id; // some kind of sudo $user_id $addressbooks = OBM_AddressBook::search(); $addressBookByName = array(); foreach ($addressbooks as $addressbook) { if ($addressbook->name != 'public_contacts') { // I'd better filter this addressbook on search if ($addressbook->isDefault || isset($vcf_contacts[$addressbook->name])) { $addressbook->reset(); $addressBookByName[$addressbook->name] = $addressbook; } else { OBM_AddressBook::delete(array('addressbook_id' => $addressbook->id)); } } } foreach ($vcf_contacts as $addBookName => $fd) { if (isset($addressBookByName[$addBookName])) { $addressbook = $addressBookByName[$addBookName]; } else { $addressbook = OBM_AddressBook::create(array('name' => $addBookName)); } if ($fd && $addressbook->write) { $ids = run_query_vcard_insert(array('vcard_fd' => $fd), $addressbook); } } $GLOBALS['obm']['uid'] = $remember_uid; }
} } } // Form data are not valid } else { $display['msg'] = display_warn_msg($l_invalid_data . ' : ' . $err['msg']); $display['detail'] = dis_company_form($action, $params); } } elseif ($action == 'update') { /////////////////////////////////////////////////////////////////////////////// if (check_user_defined_rules() && check_company_data_form($params['company_id'], $params)) { $retour = run_query_company_update($params['company_id'], $params); if ($retour) { $addressbooks = OBM_AddressBook::search(); $contacts = $addressbooks->searchContacts("companyId:$params[company_id]"); foreach($contacts as $contact) { OBM_Contact::solrStore($contact); } OBM_IndexingService::commit('contact'); $display['msg'] .= display_ok_msg("$l_company : $l_update_ok"); } else { $display['msg'] .= display_err_msg("$l_company : $l_update_error"); } $display['detail'] = dis_company_consult($params); } else { $display['msg'] .= display_warn_msg($l_invalid_data . ' : ' . $err['msg']); $display['detail'] = dis_company_form($action, $params); }
public static function delete($contact) { global $obm, $cdg_sql, $c_use_connectors; if (!$contact->id) return false; //else $obm_q = new DB_OBM; $multidomain = sql_multidomain('contact'); $sql_id = sql_parse_id($contact->id); $comp_id = sql_parse_id($contact->company_id); run_query_global_delete_document_links($contact->id, 'contact'); $ret = of_userdata_query_delete('contact', $contact->id); //FIXME: do it better // BEGIN birthday and anniversary support run_query_contact_birthday_update('birthday', null, null, $contact->birthday_event, null, null, null); run_query_contact_birthday_update('anniversary', null, null, $contact->anniversary_event, null, null, null); // END birthday and anniversary support of_entity_delete('contact', $contact->id); $query = "DELETE FROM Contact WHERE contact_id = $sql_id $multidomain"; display_debug_msg($query, $cdg_sql, 'OBM_Contact::delete(1)'); $retour = $obm_q->query($query); OBM_AddressBook::timestamp($contact->addressbook_id); // If connectors in use if ($c_use_connectors) { $uid = sql_parse_id($obm['uid']); $query = "INSERT INTO DeletedContact ( deletedcontact_contact_id, deletedcontact_addressbook_id, deletedcontact_timestamp, deletedcontact_origin) VALUES ( $contact->id, $contact->addressbook_id, NOW(), '$GLOBALS[c_origin_web]' ) "; display_debug_msg($query, $cdg_sql, 'OBM_Contact::delete(2)'); $retour = $obm_q->query($query); } // After contact deletion to get correct number run_query_global_company_contact_number_update($comp_id); // Delete index OBM_IndexingService::delete('contact', $contact->id); return $retour; }