dolibarr 21.0.0-beta
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
40// Load translation files required by the page
41$langs->load("companies");
42
43$sortfield = GETPOST('sortfield', 'aZ09comma');
44$sortorder = GETPOST('sortorder', 'aZ09comma');
45$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
46if (!$sortorder) {
47 $sortorder = "ASC";
48}
49if (!$sortfield) {
50 $sortfield = "p.lastname";
51}
52if ($page < 0) {
53 $page = 0;
54}
55$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
56$offset = $limit * $page;
57
58$type = GETPOST('type', 'alpha');
59$search_lastname = GETPOST('search_nom') ? GETPOST('search_nom') : GETPOST('search_lastname'); // For backward compatibility
60$search_firstname = GETPOST('search_firstname') ? GETPOST('search_firstname') : GETPOST('search_firstname'); // For backward compatibility
61$search_company = GETPOST('search_societe') ? GETPOST('search_societe') : GETPOST('search_company'); // For backward compatibility
62$contactname = GETPOST('contactname');
63$begin = GETPOST('begin', 'alpha');
64
65// Security check
66$socid = GETPOSTINT('socid');
67if ($user->socid) {
68 $action = '';
69 $socid = $user->socid;
70}
71
72$hookmanager->initHooks(array('contactlist'));
73$result = restrictedArea($user, 'societe', $socid, '');
74
75
76/*
77 * View
78 */
79
80llxHeader('', $langs->trans("Contacts"));
81
82$urlfiche = null;
83
84if ($type == "c" || $type == "p") {
85 $label = $langs->trans("Customers");
86 $urlfiche = "card.php";
87}
88if ($type == "f") {
89 $label = $langs->trans("Suppliers");
90 $urlfiche = "card.php";
91}
92
93/*
94 * List mode
95 */
96
97$sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm,";
98$sql .= " p.rowid as cidp, p.lastname, p.firstname, p.email, p.phone";
99$sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
100$sql .= " ".MAIN_DB_PREFIX."socpeople as p";
101$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
102$sql .= " WHERE s.fk_stcomm = st.id";
103$sql .= " AND p.entity IN (".getEntity('contact').")";
104if ($type == "c") {
105 $sql .= " AND s.client IN (1, 3)";
106}
107if ($type == "p") {
108 $sql .= " AND s.client IN (2, 3)";
109}
110if ($type == "f") {
111 $sql .= " AND s.fournisseur = 1";
112}
113if (!empty($search_lastname)) {
114 $sql .= " AND p.lastname LIKE '%".$db->escape($search_lastname)."%'";
115}
116if (!empty($search_firstname)) {
117 $sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
118}
119if (!empty($search_company)) {
120 $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
121}
122if (!empty($contactname)) { // access a partir du module de recherche
123 $sql .= " AND (p.lastname LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
124 $sortfield = "p.lastname";
125 $sortorder = "ASC";
126}
127// If the internal user must only see his customers, force searching by him
128$search_sale = 0;
129if (!$user->hasRight('societe', 'client', 'voir')) {
130 $search_sale = $user->id;
131}
132// Search on sale representative
133if ($search_sale && $search_sale != '-1') {
134 if ($search_sale == -2) {
135 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
136 } elseif ($search_sale > 0) {
137 $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).")";
138 }
139}
140// Search on socid
141if ($socid) {
142 $sql .= " AND p.fk_soc = ".((int) $socid);
143}
144
145$sql .= $db->order($sortfield, $sortorder);
146$sql .= $db->plimit($limit + 1, $offset);
147
148$resql = $db->query($sql);
149if ($resql) {
150 $num = $db->num_rows($resql);
151
152 $param = "&type=".$type;
153
154 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
155 print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
156
157 print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
158
159 print '<table class="liste centpercent">';
160 print '<tr class="liste_titre">';
161 print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, "", $sortfield, $sortorder);
162 print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
163 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
166 print "</tr>\n";
167
168 print '<tr class="liste_titre">';
169 print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
170 print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
171 print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
172 print '<td class="liste_titre">&nbsp;</td>';
173 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>';
174 print "</tr>\n";
175
176 $i = 0;
177 while ($i < min($num, $limit)) {
178 $obj = $db->fetch_object($resql);
179
180 print '<tr class="oddeven">';
181 print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
182 print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
183 print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
184
185 print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a>&nbsp;';
186 print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
187
188 print '<td>'.dol_print_email($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
189
190 print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').'&nbsp;</td>';
191
192 print "</tr>\n";
193 $i++;
194 }
195 print "</table>";
196
197 print '</form>';
198
199 $db->free($resql);
200} else {
201 dol_print_error($db);
202}
203
204// End of page
205llxFooter();
206$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:71
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.