2004-10-19 22:19:58 +02:00
|
|
|
<?php
|
2011-09-20 16:14:58 +02:00
|
|
|
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
|
|
|
* Copyright (C) 2003 Eric Seigne <erics@rycks.com>
|
|
|
|
|
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
2018-10-27 14:43:12 +02:00
|
|
|
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
|
2002-04-29 21:25:13 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2002-04-29 21:25:13 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2002-04-29 21:25:13 +02:00
|
|
|
*/
|
2004-12-25 19:44:15 +01:00
|
|
|
|
|
|
|
|
/**
|
2011-08-27 17:14:31 +02:00
|
|
|
* \file htdocs/comm/contact.php
|
|
|
|
|
* \ingroup commercial
|
|
|
|
|
* \brief Liste des contacts
|
|
|
|
|
*/
|
2004-12-25 19:44:15 +01:00
|
|
|
|
2012-08-22 23:24:21 +02:00
|
|
|
require '../main.inc.php';
|
2002-04-29 21:25:13 +02:00
|
|
|
|
2018-05-26 20:32:23 +02:00
|
|
|
// Load translation files required by the page
|
2005-08-21 21:11:54 +02:00
|
|
|
$langs->load("companies");
|
2004-02-21 02:46:26 +01:00
|
|
|
|
2020-09-18 17:13:01 +02:00
|
|
|
$sortfield = GETPOST('sortfield', 'aZ09comma');
|
2020-09-17 14:31:25 +02:00
|
|
|
$sortorder = GETPOST('sortorder', 'aZ09comma');
|
2020-03-13 13:07:11 +01:00
|
|
|
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
|
2021-02-23 18:59:19 +01:00
|
|
|
if (!$sortorder) {
|
|
|
|
|
$sortorder = "ASC";
|
|
|
|
|
}
|
|
|
|
|
if (!$sortfield) {
|
|
|
|
|
$sortfield = "p.name";
|
|
|
|
|
}
|
|
|
|
|
if ($page < 0) {
|
|
|
|
|
$page = 0;
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
|
|
|
|
|
$offset = $limit * $page;
|
2004-11-16 22:41:54 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$type = GETPOST('type', 'alpha');
|
|
|
|
|
$search_lastname = GETPOST('search_nom') ?GETPOST('search_nom') : GETPOST('search_lastname'); // For backward compatibility
|
|
|
|
|
$search_firstname = GETPOST('search_firstname') ?GETPOST('search_firstname') : GETPOST('search_firstname'); // For backward compatibility
|
|
|
|
|
$search_company = GETPOST('search_societe') ?GETPOST('search_societe') : GETPOST('search_company'); // For backward compatibility
|
|
|
|
|
$contactname = GETPOST('contactname');
|
|
|
|
|
$begin = GETPOST('begin', 'alpha');
|
2004-07-30 10:08:31 +02:00
|
|
|
|
2008-02-24 14:18:40 +01:00
|
|
|
// Security check
|
2019-01-27 11:55:16 +01:00
|
|
|
$socid = GETPOST('socid', 'int');
|
2021-02-23 18:59:19 +01:00
|
|
|
if ($user->socid) {
|
2021-03-29 22:43:39 +02:00
|
|
|
$action = '';
|
2021-02-23 18:59:19 +01:00
|
|
|
$socid = $user->socid;
|
|
|
|
|
}
|
2019-01-27 11:55:16 +01:00
|
|
|
$result = restrictedArea($user, 'societe', $socid, '');
|
2007-03-07 17:24:26 +01:00
|
|
|
|
2002-05-09 16:57:48 +02:00
|
|
|
|
2008-02-24 14:18:40 +01:00
|
|
|
/*
|
2016-01-11 22:03:26 +01:00
|
|
|
* View
|
|
|
|
|
*/
|
2008-02-24 14:18:40 +01:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
llxHeader('', $langs->trans("Contacts"));
|
2004-01-24 18:34:32 +01:00
|
|
|
|
2021-02-23 18:59:19 +01:00
|
|
|
if ($type == "c" || $type == "p") {
|
2020-10-31 14:32:18 +01:00
|
|
|
$label = $langs->trans("Customers");
|
|
|
|
|
$urlfiche = "card.php";
|
2004-02-21 02:46:26 +01:00
|
|
|
}
|
2021-02-23 18:59:19 +01:00
|
|
|
if ($type == "f") {
|
2020-10-31 14:32:18 +01:00
|
|
|
$label = $langs->trans("Suppliers");
|
|
|
|
|
$urlfiche = "card.php";
|
2004-01-24 18:34:32 +01:00
|
|
|
}
|
|
|
|
|
|
2002-04-29 21:25:13 +02:00
|
|
|
/*
|
2016-01-11 22:03:26 +01:00
|
|
|
* List mode
|
2002-04-29 21:25:13 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-10-04 17:20:17 +02:00
|
|
|
$sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm";
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
|
2021-10-22 22:15:59 +02:00
|
|
|
if (empty($user->rights->societe->client->voir) && !$socid) {
|
2021-02-23 18:59:19 +01:00
|
|
|
$sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
|
|
|
|
|
}
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= " ".MAIN_DB_PREFIX."socpeople as p";
|
|
|
|
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
|
|
|
|
|
$sql .= " WHERE s.fk_stcomm = st.id";
|
2022-03-18 12:05:59 +01:00
|
|
|
$sql .= " AND p.entity IN (".getEntity('contact').")";
|
2021-10-22 22:15:59 +02:00
|
|
|
if (empty($user->rights->societe->client->voir) && !$socid) {
|
2021-08-23 17:41:11 +02:00
|
|
|
$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
|
2021-02-23 18:59:19 +01:00
|
|
|
}
|
|
|
|
|
if ($type == "c") {
|
|
|
|
|
$sql .= " AND s.client IN (1, 3)";
|
|
|
|
|
}
|
|
|
|
|
if ($type == "p") {
|
|
|
|
|
$sql .= " AND s.client IN (2, 3)";
|
|
|
|
|
}
|
|
|
|
|
if ($type == "f") {
|
|
|
|
|
$sql .= " AND s.fournisseur = 1";
|
|
|
|
|
}
|
|
|
|
|
if ($socid) {
|
2021-03-22 13:31:06 +01:00
|
|
|
$sql .= " AND s.rowid = ".((int) $socid);
|
2021-02-23 18:59:19 +01:00
|
|
|
}
|
|
|
|
|
if (!empty($search_lastname)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$sql .= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
|
2005-01-14 18:06:26 +01:00
|
|
|
}
|
2021-02-23 18:59:19 +01:00
|
|
|
if (!empty($search_firstname)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
|
2005-01-14 18:06:26 +01:00
|
|
|
}
|
2021-02-23 18:59:19 +01:00
|
|
|
if (!empty($search_company)) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
|
2005-01-14 18:06:26 +01:00
|
|
|
}
|
2021-02-23 18:59:19 +01:00
|
|
|
if (!empty($contactname)) { // acces a partir du module de recherche
|
2020-10-31 14:32:18 +01:00
|
|
|
$sql .= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
|
|
|
|
|
$sortfield = "p.name";
|
|
|
|
|
$sortorder = "ASC";
|
2002-04-29 21:25:13 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$sql .= $db->order($sortfield, $sortorder);
|
|
|
|
|
$sql .= $db->plimit($limit + 1, $offset);
|
2002-04-29 21:25:13 +02:00
|
|
|
|
2008-11-01 01:16:34 +01:00
|
|
|
$resql = $db->query($sql);
|
2021-02-23 18:59:19 +01:00
|
|
|
if ($resql) {
|
2013-12-15 14:26:27 +01:00
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$param = "&type=".$type;
|
2013-12-15 14:26:27 +01:00
|
|
|
|
2020-04-10 10:59:32 +02:00
|
|
|
$title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
|
|
|
|
|
print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
|
2013-12-15 14:26:27 +01:00
|
|
|
|
2016-12-18 01:44:26 +01:00
|
|
|
print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
|
2017-08-02 13:31:53 +02:00
|
|
|
|
2019-11-05 21:24:41 +01:00
|
|
|
print '<table class="liste centpercent">';
|
2013-12-15 14:26:27 +01:00
|
|
|
print '<tr class="liste_titre">';
|
2019-01-27 11:55:16 +01:00
|
|
|
print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, $param, "", $sortfield, $sortorder);
|
|
|
|
|
print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
|
|
|
|
|
print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
|
2017-08-02 13:31:53 +02:00
|
|
|
print_liste_field_titre("Email");
|
|
|
|
|
print_liste_field_titre("Phone");
|
2013-12-15 14:26:27 +01:00
|
|
|
print "</tr>\n";
|
|
|
|
|
|
|
|
|
|
print '<tr class="liste_titre">';
|
|
|
|
|
print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
|
|
|
|
|
print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
|
|
|
|
|
print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
|
|
|
|
|
print '<td class="liste_titre"> </td>';
|
2019-02-04 10:37:51 +01:00
|
|
|
print '<td class="liste_titre right"><input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>';
|
2013-12-15 14:26:27 +01:00
|
|
|
print "</tr>\n";
|
|
|
|
|
|
|
|
|
|
$i = 0;
|
2021-02-23 18:59:19 +01:00
|
|
|
while ($i < min($num, $limit)) {
|
2013-12-15 14:26:27 +01:00
|
|
|
$obj = $db->fetch_object($resql);
|
|
|
|
|
|
2017-04-14 11:22:48 +02:00
|
|
|
print '<tr class="oddeven">';
|
2019-01-27 11:55:16 +01:00
|
|
|
print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
|
2014-09-18 21:18:25 +02:00
|
|
|
print '</a> <a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
|
2022-01-18 13:44:52 +01:00
|
|
|
print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
|
2013-12-15 14:26:27 +01:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a> ';
|
2022-01-18 13:44:52 +01:00
|
|
|
print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
|
2013-12-15 14:26:27 +01:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
print '<td>'.dol_print_phone($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
|
2013-12-15 14:26:27 +01:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').' </td>';
|
2013-12-15 14:26:27 +01:00
|
|
|
|
|
|
|
|
print "</tr>\n";
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
2016-12-18 01:44:26 +01:00
|
|
|
print "</table>";
|
2017-08-02 13:31:53 +02:00
|
|
|
|
2016-12-18 01:44:26 +01:00
|
|
|
print '</form>';
|
2017-08-02 13:31:53 +02:00
|
|
|
|
2013-12-15 14:26:27 +01:00
|
|
|
$db->free($resql);
|
2020-05-21 15:05:19 +02:00
|
|
|
} else {
|
2020-10-31 14:32:18 +01:00
|
|
|
dol_print_error($db);
|
2002-04-29 21:25:13 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-29 17:17:29 +02:00
|
|
|
// End of page
|
2012-02-03 19:06:37 +01:00
|
|
|
llxFooter();
|
2002-04-29 21:25:13 +02:00
|
|
|
$db->close();
|