$table->data[0][0] = print_input_text("search_text", $search_text, "", 15, 100, true, __('Search')); $params = array(); $params['input_id'] = 'id_company'; $params['input_name'] = 'id_company'; $params['input_value'] = $id_company; $params['title'] = __('Company'); $params['return'] = true; $table->data[0][1] = print_company_autocomplete_input($params); $table->data[0][2] = print_submit_button(__('Search'), "search_btn", false, 'class="sub search"', true); // Delete new lines from the string $where_clause = str_replace(array("\r", "\n"), '', $where_clause); $table->data[0][3] = print_button(__('Export to CSV'), '', false, 'window.open(\'include/export_csv.php?export_csv_contacts=1&where_clause=' . str_replace("'", "\\'", $where_clause) . '\')', 'class="sub csv"', true); echo '<form id="contact_search_form" method="post">'; print_table($table); echo '</form>'; $contacts = crm_get_all_contacts($where_clause); $contacts = print_array_pagination($contacts, "index.php?sec=customers&sec2=operation/contacts/contact_detail¶ms={$search_params}", $offset); if ($contacts !== false) { unset($table); $table->width = "99%"; $table->class = "listing"; $table->data = array(); $table->size = array(); $table->size[3] = '40px'; $table->style = array(); // $table->style[] = 'font-weight: bold'; $table->head = array(); $table->head[0] = __('Full name'); $table->head[1] = __('Company'); $table->head[2] = __('Email'); if ($section_write_permission || $section_manage_permission) {
$rows = crm_get_all_contracts(clean_output($where_clause)); if ($read && $enterprise) { $rows = crm_get_user_contracts($config['id_user'], $rows); } $filename = clean_output('contracts_export') . '-' . date("YmdHi"); if ($rows === false) { return; } } if ($export_csv_contacts) { $read = check_crm_acl('company', 'cr'); if (!$read) { exit; } $where_clause = get_parameter('where_clause'); $rows = crm_get_all_contacts(clean_output($where_clause)); $filename = clean_output('contacts_export') . '-' . date("YmdHi"); if ($rows === false) { return; } } if ($export_csv_companies) { $read = check_crm_acl('company', 'cr'); if (!$read) { exit; } $where_clause = get_parameter('where_clause'); $date = get_parameter('date'); $filename = clean_output('company_export') . '-' . date("YmdHi"); $rows = crm_get_companies_list(clean_output($where_clause), $date); if ($rows === false) {
echo "<h3 class='error'>" . __('Error adding activity. Empty activity') . "</h3>"; } } $company_name = get_db_sql("SELECT name FROM tcompany WHERE id = {$id}"); $table->width = "99%"; $table->class = "search-table-button"; $table->data = array(); $table->size = array(); $table->style = array(); $table->data[0][0] = "<h3>" . __("Add activity") . "</h3>"; $table->data[1][0] = "<textarea name='comments' style='width:98%; height: 210px'></textarea>"; $table->data[2][0] = print_submit_button(__('Add activity'), "create_btn", false, 'class="sub next"', true); echo '<form method="post" action="index.php?sec=customers&sec2=operation/companies/company_detail&id=' . $id . '&op=activities&op2=add">'; print_table($table); echo '</form>'; $contacts = crm_get_all_contacts(sprintf(" WHERE id_company = %d", $id)); $sql = "SELECT * FROM tcompany_contact CC, tcontact_activity C WHERE CC.id_company = {$id} AND CC.id = C.id_contact ORDER BY C.creation DESC"; $act_contacts = get_db_all_rows_sql($sql); $sql = "SELECT * FROM tcompany_activity WHERE id_company = {$id} ORDER BY date DESC"; $activities = get_db_all_rows_sql($sql); if ($activities == false) { $activities = array(); } if ($act_contacts !== false) { $activities = array_merge($activities, $act_contacts); } $activities = print_array_pagination($activities, "index.php?sec=customers&sec2=operation/companies/company_detail&id={$id}&op=activities"); if ($activities !== false) { $aux_activities = array(); foreach ($activities as $key => $act) { if (isset($act["date"])) {
/** * Get all the contacts relative to an inventory object. * * There are two ways to get the list. By default, all the contacts in the * company that has the inventory contract will be returned. Anyway, if the * contacts list was changed manually when updating or creating the * inventory object, then these are the contacts of the object. * * @param int Inventory id. * @param bool Whether to return only contact names (default) or all the fields. * * @return array List of contacts relative to an inventory object. */ function get_inventory_contacts($id_inventory, $only_names = false) { global $config; include_once "include/functions_crm.php"; /* First try to get only defined contacts */ $owner = get_db_value('owner', 'tinventory', 'id', $id_inventory); $owner_info = get_db_row("tusuario", "id_usuario", $owner); $all_contacts = array(); $contact = array("id" => $owner, "type" => "user", "id_company" => $owner_info["id_company"], "fullname" => $owner_info["nombre_real"], "email" => $owner_info["direccion"], "phone" => $owner_info["telefono"], "mobile" => __("N/A"), "position" => __("N/A"), "description" => $owner_info["comentarios"], "disabled" => $owner_info["disabled"]); $all_contacts[$contact["id"]] = $contact; //Get all users associated to the inventory object $inv_users = enterprise_hook('inventory_get_users', array($id_inventory, false)); if ($inv_users === ENTERPRISE_NOT_HOOK) { $inv_users = array(); } foreach ($inv_users as $user) { $contact = array("id" => $user["id_usuario"], "type" => "user", "id_company" => $user["id_company"], "fullname" => $user["nombre_real"], "email" => $user["direccion"], "phone" => $user["telefono"], "mobile" => __("N/A"), "position" => __("N/A"), "description" => $user["comentarios"], "disabled" => $user["disabled"]); $all_contacts[$contact["id"]] = $contact; } $inv_companies = enterprise_hook('inventory_get_companies', array($id_inventory, false)); if ($inv_companies === ENTERPRISE_NOT_HOOK) { $inv_companies = array(); } foreach ($inv_companies as $comp) { $where_clause = sprintf("WHERE id_company = %d", $comp["id"]); $contacts = crm_get_all_contacts($where_clause); if (!$contacts) { $contacts = array(); } foreach ($contacts as $contact) { $all_contacts[$contact['id']] = $contact; } } $contracts = get_inventory_contracts($id_inventory, false); if ($contracts === false) { return array(); } foreach ($contracts as $contract) { $company = get_company($contract['id_company']); if ($company === false) { continue; } if (!give_acl($config['id_user'], $contract['id_group'], "IR")) { continue; } $contacts = get_company_contacts($company['id'], false); foreach ($contacts as $contact) { if (isset($all_contacts[$contact['id']])) { continue; } $all_contacts[$contact['id']] = $contact; } } if (!$only_names) { return $all_contacts; } $retval = array(); foreach ($all_contacts as $contact) { $retval[$contact['id']] = $contact['fullname']; } return $retval; }