dolibarr 21.0.0-alpha
contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
4 * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31
32// Load translation files required by the page
33$langs->load("companies");
34
35$sortfield = GETPOST('sortfield', 'aZ09comma');
36$sortorder = GETPOST('sortorder', 'aZ09comma');
37$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
38if (!$sortorder) {
39 $sortorder = "ASC";
40}
41if (!$sortfield) {
42 $sortfield = "p.lastname";
43}
44if ($page < 0) {
45 $page = 0;
46}
47$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
48$offset = $limit * $page;
49
50$type = GETPOST('type', 'alpha');
51$search_lastname = GETPOST('search_nom') ? GETPOST('search_nom') : GETPOST('search_lastname'); // For backward compatibility
52$search_firstname = GETPOST('search_firstname') ? GETPOST('search_firstname') : GETPOST('search_firstname'); // For backward compatibility
53$search_company = GETPOST('search_societe') ? GETPOST('search_societe') : GETPOST('search_company'); // For backward compatibility
54$contactname = GETPOST('contactname');
55$begin = GETPOST('begin', 'alpha');
56
57// Security check
58$socid = GETPOSTINT('socid');
59if ($user->socid) {
60 $action = '';
61 $socid = $user->socid;
62}
63
64$hookmanager->initHooks(array('contactlist'));
65$result = restrictedArea($user, 'societe', $socid, '');
66
67
68/*
69 * View
70 */
71
72llxHeader('', $langs->trans("Contacts"));
73
74$urlfiche = null;
75
76if ($type == "c" || $type == "p") {
77 $label = $langs->trans("Customers");
78 $urlfiche = "card.php";
79}
80if ($type == "f") {
81 $label = $langs->trans("Suppliers");
82 $urlfiche = "card.php";
83}
84
85/*
86 * List mode
87 */
88
89$sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm,";
90$sql .= " p.rowid as cidp, p.lastname, p.firstname, p.email, p.phone";
91$sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
92$sql .= " ".MAIN_DB_PREFIX."socpeople as p";
93$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
94$sql .= " WHERE s.fk_stcomm = st.id";
95$sql .= " AND p.entity IN (".getEntity('contact').")";
96if ($type == "c") {
97 $sql .= " AND s.client IN (1, 3)";
98}
99if ($type == "p") {
100 $sql .= " AND s.client IN (2, 3)";
101}
102if ($type == "f") {
103 $sql .= " AND s.fournisseur = 1";
104}
105if (!empty($search_lastname)) {
106 $sql .= " AND p.lastname LIKE '%".$db->escape($search_lastname)."%'";
107}
108if (!empty($search_firstname)) {
109 $sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
110}
111if (!empty($search_company)) {
112 $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
113}
114if (!empty($contactname)) { // access a partir du module de recherche
115 $sql .= " AND (p.lastname LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
116 $sortfield = "p.lastname";
117 $sortorder = "ASC";
118}
119// If the internal user must only see his customers, force searching by him
120$search_sale = 0;
121if (!$user->hasRight('societe', 'client', 'voir')) {
122 $search_sale = $user->id;
123}
124// Search on sale representative
125if ($search_sale && $search_sale != '-1') {
126 if ($search_sale == -2) {
127 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
128 } elseif ($search_sale > 0) {
129 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
130 }
131}
132// Search on socid
133if ($socid) {
134 $sql .= " AND p.fk_soc = ".((int) $socid);
135}
136
137$sql .= $db->order($sortfield, $sortorder);
138$sql .= $db->plimit($limit + 1, $offset);
139
140$resql = $db->query($sql);
141if ($resql) {
142 $num = $db->num_rows($resql);
143
144 $param = "&type=".$type;
145
146 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
147 print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
148
149 print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
150
151 print '<table class="liste centpercent">';
152 print '<tr class="liste_titre">';
153 print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, "", $sortfield, $sortorder);
154 print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
155 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
158 print "</tr>\n";
159
160 print '<tr class="liste_titre">';
161 print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
162 print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
163 print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
164 print '<td class="liste_titre">&nbsp;</td>';
165 print '<td class="liste_titre right"><input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"), 'search.png', '', 0, 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'"></td>';
166 print "</tr>\n";
167
168 $i = 0;
169 while ($i < min($num, $limit)) {
170 $obj = $db->fetch_object($resql);
171
172 print '<tr class="oddeven">';
173 print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
174 print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
175 print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
176
177 print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a>&nbsp;';
178 print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
179
180 print '<td>'.dol_print_email($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
181
182 print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').'&nbsp;</td>';
183
184 print "</tr>\n";
185 $i++;
186 }
187 print "</table>";
188
189 print '</form>';
190
191 $db->free($resql);
192} else {
193 dol_print_error($db);
194}
195
196// End of page
197llxFooter();
198$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
llxFooter()
Footer empty.
Definition document.php:107
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.