dolibarr  16.0.5
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 require '../main.inc.php';
28 
29 // Load translation files required by the page
30 $langs->load("companies");
31 
32 $sortfield = GETPOST('sortfield', 'aZ09comma');
33 $sortorder = GETPOST('sortorder', 'aZ09comma');
34 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
35 if (!$sortorder) {
36  $sortorder = "ASC";
37 }
38 if (!$sortfield) {
39  $sortfield = "p.name";
40 }
41 if ($page < 0) {
42  $page = 0;
43 }
44 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
45 $offset = $limit * $page;
46 
47 $type = GETPOST('type', 'alpha');
48 $search_lastname = GETPOST('search_nom') ?GETPOST('search_nom') : GETPOST('search_lastname'); // For backward compatibility
49 $search_firstname = GETPOST('search_firstname') ?GETPOST('search_firstname') : GETPOST('search_firstname'); // For backward compatibility
50 $search_company = GETPOST('search_societe') ?GETPOST('search_societe') : GETPOST('search_company'); // For backward compatibility
51 $contactname = GETPOST('contactname');
52 $begin = GETPOST('begin', 'alpha');
53 
54 // Security check
55 $socid = GETPOST('socid', 'int');
56 if ($user->socid) {
57  $action = '';
58  $socid = $user->socid;
59 }
60 $result = restrictedArea($user, 'societe', $socid, '');
61 
62 
63 /*
64  * View
65  */
66 
67 llxHeader('', $langs->trans("Contacts"));
68 
69 if ($type == "c" || $type == "p") {
70  $label = $langs->trans("Customers");
71  $urlfiche = "card.php";
72 }
73 if ($type == "f") {
74  $label = $langs->trans("Suppliers");
75  $urlfiche = "card.php";
76 }
77 
78 /*
79  * List mode
80  */
81 
82 $sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm";
83 $sql .= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
84 $sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
85 if (empty($user->rights->societe->client->voir) && !$socid) {
86  $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
87 }
88 $sql .= " ".MAIN_DB_PREFIX."socpeople as p";
89 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
90 $sql .= " WHERE s.fk_stcomm = st.id";
91 $sql .= " AND p.entity IN (".getEntity('contact').")";
92 if (empty($user->rights->societe->client->voir) && !$socid) {
93  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
94 }
95 if ($type == "c") {
96  $sql .= " AND s.client IN (1, 3)";
97 }
98 if ($type == "p") {
99  $sql .= " AND s.client IN (2, 3)";
100 }
101 if ($type == "f") {
102  $sql .= " AND s.fournisseur = 1";
103 }
104 if ($socid) {
105  $sql .= " AND s.rowid = ".((int) $socid);
106 }
107 if (!empty($search_lastname)) {
108  $sql .= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
109 }
110 if (!empty($search_firstname)) {
111  $sql .= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
112 }
113 if (!empty($search_company)) {
114  $sql .= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
115 }
116 if (!empty($contactname)) { // acces a partir du module de recherche
117  $sql .= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
118  $sortfield = "p.name";
119  $sortorder = "ASC";
120 }
121 
122 $sql .= $db->order($sortfield, $sortorder);
123 $sql .= $db->plimit($limit + 1, $offset);
124 
125 $resql = $db->query($sql);
126 if ($resql) {
127  $num = $db->num_rows($resql);
128 
129  $param = "&type=".$type;
130 
131  $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
132  print_barre_liste($title.($label ? " (".$label.")" : ""), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num);
133 
134  print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
135 
136  print '<table class="liste centpercent">';
137  print '<tr class="liste_titre">';
138  print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "p.name", $begin, $param, "", $sortfield, $sortorder);
139  print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, "", $sortfield, $sortorder);
140  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", $begin, $param, "", $sortfield, $sortorder);
141  print_liste_field_titre("Email");
142  print_liste_field_titre("Phone");
143  print "</tr>\n";
144 
145  print '<tr class="liste_titre">';
146  print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
147  print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
148  print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
149  print '<td class="liste_titre">&nbsp;</td>';
150  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>';
151  print "</tr>\n";
152 
153  $i = 0;
154  while ($i < min($num, $limit)) {
155  $obj = $db->fetch_object($resql);
156 
157  print '<tr class="oddeven">';
158  print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"), "contact");
159  print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
160  print '<td>'.dol_escape_htmltag($obj->firstname).'</td>';
161 
162  print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"), "company").'</a>&nbsp;';
163  print '<a href="'.$urlfiche."?socid=".$obj->rowid.'">'.$obj->name."</a></td>\n";
164 
165  print '<td>'.dol_print_phone($obj->email, $obj->cidp, $obj->rowid, 'AC_EMAIL').'</td>';
166 
167  print '<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid, 'AC_TEL').'&nbsp;</td>';
168 
169  print "</tr>\n";
170  $i++;
171  }
172  print "</table>";
173 
174  print '</form>';
175 
176  $db->free($resql);
177 } else {
178  dol_print_error($db);
179 }
180 
181 // End of page
182 llxFooter();
183 $db->close();
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
print_barre_liste
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.
Definition: functions.lib.php:5257
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59