dolibarr 21.0.0-beta
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
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
38$langs->load("companies");
39
40
41/*
42 * View
43 */
44
45llxHeader();
46
47// Security check
48if ($user->socid > 0) {
49 $action = '';
50 $socid = $user->socid;
51}
52
53$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
54$sortfield = GETPOST('sortfield', 'aZ09comma');
55$sortorder = GETPOST('sortorder', 'aZ09comma');
56$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
57if (empty($page) || $page == -1) {
58 $page = 0;
59} // If $page is not defined, or '' or -1
60$offset = $limit * $page;
61$pageprev = $page - 1;
62$pagenext = $page + 1;
63if (!$sortorder) {
64 $sortorder = "ASC";
65}
66if (!$sortfield) {
67 $sortfield = "p.name";
68}
69$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
70
71
72/*
73 * List mode
74 */
75
76$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";
77if (!$user->hasRight("societe", "client", "voir") && !$socid) {
78 $sql .= ", sc.fk_soc, sc.fk_user ";
79}
80$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."socpeople as p, ".MAIN_DB_PREFIX."c_stcomm as st";
81if (!$user->hasRight("societe", "client", "voir") && !$socid) {
82 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
83}
84$sql .= " WHERE s.fk_stcomm = st.id";
85$sql .= " AND s.fournisseur = 1";
86$sql .= " AND s.rowid = p.fk_soc";
87$sql .= " AND s.entity IN (".getEntity('societe').")";
88if (!$user->hasRight("societe", "client", "voir") && !$socid) {
89 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
90}
91
92if (dol_strlen($stcomm)) {
93 $sql .= " AND s.fk_stcomm=$stcomm";
94}
95
96if (dol_strlen($begin)) {
97 $sql .= " AND p.name LIKE '$begin%'";
98}
99
100if ($contactname) {
101 $sql .= " AND p.name LIKE '%".strtolower($contactname)."%'";
102 $sortfield = "p.name";
103 $sortorder = "ASC";
104}
105
106if ($socid) {
107 $sql .= " AND s.rowid = ".((int) $socid);
108}
109
110$sql .= " ORDER BY $sortfield $sortorder ";
111$sql .= $db->plimit($limit, $offset);
112
113$result = $db->query($sql);
114if ($result) {
115 $num = $db->num_rows($result);
116
117 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
118 print_barre_liste($title." (".$langs->trans("Suppliers").")", $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num);
119
120 print '<table class="liste centpercent">';
121 print '<tr class="liste_titre">';
122 print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, "", "", $sortfield, $sortorder);
123 print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, "", "", $sortfield, $sortorder);
124 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, "", "", $sortfield, $sortorder);
127 print "</tr>\n";
128
129 $i = 0;
130 while ($i < min($num, $limit)) {
131 $obj = $db->fetch_object($result);
132
133 print '<tr class="oddeven">';
134
135 print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'">'.img_object($langs->trans("ShowContact"), "contact").' '.$obj->lastname.'</a></td>';
136 print '<td>'.$obj->firstname.'</td>';
137 print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
138 print '<td>'.$obj->email.'</td>';
139 print '<td>'.$obj->phone.'</td>';
140
141 print "</tr>\n";
142 $i++;
143 }
144 print "</table>";
145 $db->free($result);
146} else {
147 dol_print_error($db);
148}
149
150// End of page
151llxFooter();
152$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.
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.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79