[quote="Jasiek":3ic36f77]Copy Company Data - is a feature that allows you to create a contact by just entering the first and last name and copying values from the parent company like address, city etc. After copying the company values you can adjust them - for example company main phone number, e-mail address of the user etc. - before saving.
It is a time saving feature that pre-fills certain fields.
Update Contacts is a tool to update all contacts that are linked with that company with updated information. For example: Company ABC when created had an address 123 Main Street, Philadelphia, PA 19000. Then a number of contacts were created using "Copy Company Data" option. Now you may have several contacts with this address - 123 Main Street...
Company ABC moved to a new address - 9 Some Street, New York, NY 01000. All contacts under this company will still have old address and you would have to update them manually one-by-one. Using "Update Contacts" tool you can update all of them with just a few mouse clicks.
If you want to write your own tool look at the code: modules\CRM\Contacts\update_contact.php
and also: modules\CRM\Contacts\Contacts_0.php lines 227:
public function update_contacts_address_prompt($company, $lid) {
$html = '<br/>'.__('This action will update all contacts within this company with values copied from company record.').'<br/><br/>'.__('Please check which data would you like to copy to company contacts:');
$form = $this->init_module('Libs/QuickForm');
$data = array( /* Source ID, Target ID, Text, Checked state */
array('sid'=>'address_1', 'tid'=>'address_1', 'text'=>__('Address 1'), 'checked'=>true),
array('sid'=>'address_2', 'tid'=>'address_2', 'text'=>__('Address 2'), 'checked'=>true),
array('sid'=>'city', 'tid'=>'city', 'text'=>__('City'), 'checked'=>true),
array('sid'=>'country', 'tid'=>'country', 'text'=>__('Country'), 'checked'=>true),
array('sid'=>'zone', 'tid'=>'zone', 'text'=>__('Zone'), 'checked'=>true),
array('sid'=>'postal_code', 'tid'=>'postal_code', 'text'=>__('Postal Code'), 'checked'=>true),
array('sid'=>'phone', 'tid'=>'work_phone', 'text'=>__('Phone as Work Phone'), 'checked'=>false),
array('sid'=>'fax', 'tid'=>'fax', 'text'=>__('Fax'), 'checked'=>false),
);
foreach($data as $row) {
if (!isset($company[$row['sid']])) continue;
$form->addElement('checkbox', $row['sid'], $row['text'], ' <span style="color: gray">'.$company[$row['sid']].'</span>', $row['checked'] ? array('checked'=>'checked'): array());
}
$ok = $form->createElement('submit', 'submit', __('Confirm'), array('onclick'=>'leightbox_deactivate("'.$lid.'")'));
$cancel = $form->createElement('button', 'cancel', __('Cancel'), array('onclick'=>'leightbox_deactivate("'.$lid.'")'));
$form->addGroup(array($ok, $cancel));
if($form->validate()) {
$values = $form->exportValues();
$fields = array();
foreach($data as $row) {
if(array_key_exists($row['sid'], $values)) {
$fields[$row['tid']] = $row['sid'];
}
}
$this->update_contacts_address($company, $fields);
location(array());
}
$html .= $form->toHtml();
return $html;
}
public function update_contacts_address($company, $fields) {
$recs = CRM_ContactsCommon::get_contacts(array('company_name' => $company['id']), array('id'));
$new_data = array();
foreach($fields as $k => $v) {
$new_data[$k] = $company[$v];
}
foreach($recs as $contact) {
Utils_RecordBrowserCommon::update_record('contact', $contact['id'], $new_data);
}
}
Note that your script does not have to be as complex as we are first displaying a prompt (Leightbox Prompt) to ask what fields will be updated.[/quote:3ic36f77]
Tnx a lot for your assistance...i'll test this code.
Right now i wanna to use the default's one present in epesi installation. My problem is that in contact's mask there is the "copy data company" buttom and it is correctly function....while in the company's mask the "update contact" buttom there is not present...
Why is not present? How can i enable this buttom???
for my project is better because make me able to update a lot of contact from the same mask (the company mask) and only with one buttom...
tnx a lot