dolibarr 19.0.3
contact.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2006 Regis Houssin <regis.houssin@inodbox.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
28
29$langs->load("companies");
30
31
32/*
33 * View
34 */
35
36llxHeader();
37
38// Security check
39if ($user->socid > 0) {
40 $action = '';
41 $socid = $user->socid;
42}
43
44$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
45$sortfield = GETPOST('sortfield', 'aZ09comma');
46$sortorder = GETPOST('sortorder', 'aZ09comma');
47$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
48if (empty($page) || $page == -1) {
49 $page = 0;
50} // If $page is not defined, or '' or -1
51$offset = $limit * $page;
52$pageprev = $page - 1;
53$pagenext = $page + 1;
54if (!$sortorder) {
55 $sortorder = "ASC";
56}
57if (!$sortfield) {
58 $sortfield = "p.name";
59}
60$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
61
62
63/*
64 * Mode liste
65 */
66
67$sql = "SELECT s.rowid as socid, s.nom as name, st.libelle as stcomm, p.rowid as cidp, p.lastname, p.firstname, p.email, p.phone";
68if (!$user->hasRight("societe", "client", "voir") && !$socid) {
69 $sql .= ", sc.fk_soc, sc.fk_user ";
70}
71$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
72if (!$user->hasRight("societe", "client", "voir") && !$socid) {
73 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
74}
75$sql .= " WHERE s.fk_stcomm = st.id";
76$sql .= " AND s.fournisseur = 1";
77$sql .= " AND s.rowid = p.fk_soc";
78$sql .= " AND s.entity IN (".getEntity('societe').")";
79if (!$user->hasRight("societe", "client", "voir") && !$socid) {
80 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
81}
82
83if (dol_strlen($stcomm)) {
84 $sql .= " AND s.fk_stcomm=$stcomm";
85}
86
87if (dol_strlen($begin)) {
88 $sql .= " AND p.name LIKE '$begin%'";
89}
90
91if ($contactname) {
92 $sql .= " AND p.name LIKE '%".strtolower($contactname)."%'";
93 $sortfield = "p.name";
94 $sortorder = "ASC";
95}
96
97if ($socid) {
98 $sql .= " AND s.rowid = ".((int) $socid);
99}
100
101$sql .= " ORDER BY $sortfield $sortorder ";
102$sql .= $db->plimit($limit, $offset);
103
104$result = $db->query($sql);
105if ($result) {
106 $num = $db->num_rows($result);
107
108 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
109 print_barre_liste($title." (".$langs->trans("Suppliers").")", $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
110
111 print '<table class="liste centpercent">';
112 print '<tr class="liste_titre">';
113 print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, "", "", $sortfield, $sortorder);
114 print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, "", "", $sortfield, $sortorder);
115 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, "", "", $sortfield, $sortorder);
118 print "</tr>\n";
119
120 $i = 0;
121 while ($i < min($num, $limit)) {
122 $obj = $db->fetch_object($result);
123
124 print '<tr class="oddeven">';
125
126 print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'">'.img_object($langs->trans("ShowContact"), "contact").' '.$obj->lastname.'</a></td>';
127 print '<td>'.$obj->firstname.'</td>';
128 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
129 print '<td>'.$obj->email.'</td>';
130 print '<td>'.$obj->phone.'</td>';
131
132 print "</tr>\n";
133 $i++;
134 }
135 print "</table>";
136 $db->free($result);
137} else {
138 dol_print_error($db);
139}
140
141// End of page
142llxFooter();
143$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
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)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.