dolibarr 20.0.2
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../main.inc.php';
29
30// Load translation files required by the page
31$langs->load("companies");
32
33$sortfield = GETPOST('sortfield', 'aZ09comma');
34$sortorder = GETPOST('sortorder', 'aZ09comma');
35$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
36if (!$sortorder) {
37 $sortorder = "ASC";
38}
39if (!$sortfield) {
40 $sortfield = "p.name";
41}
42if ($page < 0) {
43 $page = 0;
44}
45$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
46$offset = $limit * $page;
47
48$type = GETPOST('type', 'alpha');
49$search_lastname = GETPOST('search_nom') ? GETPOST('search_nom') : GETPOST('search_lastname'); // For backward compatibility
50$search_firstname = GETPOST('search_firstname') ? GETPOST('search_firstname') : GETPOST('search_firstname'); // For backward compatibility
51$search_company = GETPOST('search_societe') ? GETPOST('search_societe') : GETPOST('search_company'); // For backward compatibility
52$contactname = GETPOST('contactname');
53$begin = GETPOST('begin', 'alpha');
54
55// Security check
56$socid = GETPOSTINT('socid');
57if ($user->socid) {
58 $action = '';
59 $socid = $user->socid;
60}
61$result = restrictedArea($user, 'societe', $socid, '');
62
63
64/*
65 * View
66 */
67
68llxHeader('', $langs->trans("Contacts"));
69
70if ($type == "c" || $type == "p") {
71 $label = $langs->trans("Customers");
72 $urlfiche = "card.php";
73}
74if ($type == "f") {
75 $label = $langs->trans("Suppliers");
76 $urlfiche = "card.php";
77}
78
79/*
80 * List mode
81 */
82
83$sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm,";
84$sql .= " p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
85$sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
86$sql .= " ".MAIN_DB_PREFIX."socpeople as p";
87$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
88$sql .= " WHERE s.fk_stcomm = st.id";
89$sql .= " AND p.entity IN (".getEntity('contact').")";
90if ($type == "c") {
91 $sql .= " AND s.client IN (1, 3)";
92}
93if ($type == "p") {
94 $sql .= " AND s.client IN (2, 3)";
95}
96if ($type == "f") {
97 $sql .= " AND s.fournisseur = 1";
98}
99if (!empty($search_lastname)) {
100 $sql .= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
101}
102if (!empty($search_firstname)) {
103 $sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
104}
105if (!empty($search_company)) {
106 $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
107}
108if (!empty($contactname)) { // access a partir du module de recherche
109 $sql .= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
110 $sortfield = "p.name";
111 $sortorder = "ASC";
112}
113// If the internal user must only see his customers, force searching by him
114$search_sale = 0;
115if (!$user->hasRight('societe', 'client', 'voir')) {
116 $search_sale = $user->id;
117}
118// Search on sale representative
119if ($search_sale && $search_sale != '-1') {
120 if ($search_sale == -2) {
121 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
122 } elseif ($search_sale > 0) {
123 $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).")";
124 }
125}
126// Search on socid
127if ($socid) {
128 $sql .= " AND p.fk_soc = ".((int) $socid);
129}
130
131$sql .= $db->order($sortfield, $sortorder);
132$sql .= $db->plimit($limit + 1, $offset);
133
134$resql = $db->query($sql);
135if ($resql) {
136 $num = $db->num_rows($resql);
137
138 $param = "&type=".$type;
139
140 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
141 print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
142
143 print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
144
145 print '<table class="liste centpercent">';
146 print '<tr class="liste_titre">';
147 print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, $param, "", $sortfield, $sortorder);
148 print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
149 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
152 print "</tr>\n";
153
154 print '<tr class="liste_titre">';
155 print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
156 print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
157 print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
158 print '<td class="liste_titre">&nbsp;</td>';
159 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>';
160 print "</tr>\n";
161
162 $i = 0;
163 while ($i < min($num, $limit)) {
164 $obj = $db->fetch_object($resql);
165
166 print '<tr class="oddeven">';
167 print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
168 print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
169 print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
170
171 print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a>&nbsp;';
172 print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
173
174 print '<td>'.dol_print_phone($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
175
176 print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').'&nbsp;</td>';
177
178 print "</tr>\n";
179 $i++;
180 }
181 print "</table>";
182
183 print '</form>';
184
185 $db->free($resql);
186} else {
187 dol_print_error($db);
188}
189
190// End of page
191llxFooter();
192$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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 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.