dolibarr 18.0.6
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') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
36if (!$sortorder) {
37 $sortorder = "ASC";
38}
39if (!$sortfield) {
40 $sortfield = "p.name";
41}
42if ($page < 0) {
43 $page = 0;
44}
45$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $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 = GETPOST('socid', 'int');
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,";
86if (empty($user->rights->societe->client->voir) && !$socid) {
87 $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
88}
89$sql .= " ".MAIN_DB_PREFIX."socpeople as p";
90$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
91$sql .= " WHERE s.fk_stcomm = st.id";
92$sql .= " AND p.entity IN (".getEntity('contact').")";
93if (empty($user->rights->societe->client->voir) && !$socid) {
94 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
95}
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 ($socid) {
106 $sql .= " AND s.rowid = ".((int) $socid);
107}
108if (!empty($search_lastname)) {
109 $sql .= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
110}
111if (!empty($search_firstname)) {
112 $sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
113}
114if (!empty($search_company)) {
115 $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
116}
117if (!empty($contactname)) { // acces a partir du module de recherche
118 $sql .= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
119 $sortfield = "p.name";
120 $sortorder = "ASC";
121}
122
123$sql .= $db->order($sortfield, $sortorder);
124$sql .= $db->plimit($limit + 1, $offset);
125
126$resql = $db->query($sql);
127if ($resql) {
128 $num = $db->num_rows($resql);
129
130 $param = "&type=".$type;
131
132 $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
133 print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
134
135 print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
136
137 print '<table class="liste centpercent">';
138 print '<tr class="liste_titre">';
139 print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, $param, "", $sortfield, $sortorder);
140 print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
141 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
144 print "</tr>\n";
145
146 print '<tr class="liste_titre">';
147 print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
148 print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
149 print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
150 print '<td class="liste_titre">&nbsp;</td>';
151 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>';
152 print "</tr>\n";
153
154 $i = 0;
155 while ($i < min($num, $limit)) {
156 $obj = $db->fetch_object($resql);
157
158 print '<tr class="oddeven">';
159 print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
160 print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
161 print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
162
163 print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a>&nbsp;';
164 print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
165
166 print '<td>'.dol_print_phone($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
167
168 print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').'&nbsp;</td>';
169
170 print "</tr>\n";
171 $i++;
172 }
173 print "</table>";
174
175 print '</form>';
176
177 $db->free($resql);
178} else {
179 dol_print_error($db);
180}
181
182// End of page
183llxFooter();
184$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
print_barre_liste($titre, $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.
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.