dolibarr  7.0.0-beta
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@capnetworks.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 <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 
29 $langs->load("companies");
30 
31 $sortfield=GETPOST('sortfield', 'alpha');
32 $sortorder=GETPOST('sortorder', 'alpha');
33 $page=GETPOST('page', 'int');
34 if (! $sortorder) $sortorder="ASC";
35 if (! $sortfield) $sortfield="p.name";
36 if ($page < 0) { $page = 0; }
37 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
38 $offset = $limit * $page ;
39 
40 $type=GETPOST('type', 'alpha');
41 $search_lastname=GETPOST('search_nom')?GETPOST('search_nom'):GETPOST('search_lastname'); // For backward compatibility
42 $search_firstname=GETPOST('search_firstname')?GETPOST('search_firstname'):GETPOST('search_firstname'); // For backward compatibility
43 $search_company=GETPOST('search_societe')?GETPOST('search_societe'):GETPOST('search_company'); // For backward compatibility
44 $contactname=GETPOST('contactname');
45 $begin=GETPOST('begin','alpha');
46 
47 // Security check
48 $socid = GETPOST('socid','int');
49 if ($user->societe_id) $socid=$user->societe_id;
50 $result = restrictedArea($user, 'societe',$socid,'');
51 
52 
53 /*
54  * View
55  */
56 
57 llxHeader('',$langs->trans("Contacts"));
58 
59 if ($type == "c" || $type == "p")
60 {
61  $label = $langs->trans("Customers");
62  $urlfiche="card.php";
63 }
64 if ($type == "f")
65 {
66  $label = $langs->trans("Suppliers");
67  $urlfiche="card.php";
68 }
69 
70 /*
71  * List mode
72  */
73 
74 $sql = "SELECT s.rowid, s.nom as name, st.libelle as stcomm";
75 $sql.= ", p.rowid as cidp, p.name, p.firstname, p.email, p.phone";
76 $sql.= " FROM ".MAIN_DB_PREFIX."c_stcomm as st,";
77 if (! $user->rights->societe->client->voir && ! $socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
78 $sql.= " ".MAIN_DB_PREFIX."socpeople as p";
79 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
80 $sql.= " WHERE s.fk_stcomm = st.id";
81 $sql.= " AND p.entity IN (".getEntity('societe').")";
82 if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
83 if ($type == "c") $sql.= " AND s.client IN (1, 3)";
84 if ($type == "p") $sql.= " AND s.client IN (2, 3)";
85 if ($type == "f") $sql.= " AND s.fournisseur = 1";
86 if ($socid) $sql.= " AND s.rowid = ".$socid;
87 
88 if (dol_strlen($stcomm))
89 {
90  $sql.= " AND s.fk_stcomm=".$db->escape($stcomm);
91 }
92 
93 if (! empty($search_lastname))
94 {
95  $sql.= " AND p.name LIKE '%".$db->escape($search_lastname)."%'";
96 }
97 
98 if (! empty($search_firstname))
99 {
100  $sql.= " AND p.firstname LIKE '%".$db->escape($search_firstname)."%'";
101 }
102 
103 if (! empty($search_company))
104 {
105  $sql.= " AND s.nom LIKE '%".$db->escape($search_company)."%'";
106 }
107 
108 if (! empty($contactname)) // acces a partir du module de recherche
109 {
110  $sql.= " AND (p.name LIKE '%".$db->escape($contactname)."%' OR lower(p.firstname) LIKE '%".$db->escape($contactname)."%') ";
111  $sortfield = "p.name";
112  $sortorder = "ASC";
113 }
114 
115 $sql.= $db->order($sortfield,$sortorder);
116 $sql.= $db->plimit($limit+1, $offset);
117 
118 $resql = $db->query($sql);
119 if ($resql)
120 {
121  $num = $db->num_rows($resql);
122 
123  $param="&type=".$type;
124 
125  $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
126  print_barre_liste($title.($label?" (".$label.")":""),$page, $_SERVER["PHP_SELF"], $param,$sortfield,$sortorder,"",$num);
127 
128  print '<form action="'.$_SERVER["PHP_SELF"].'?type='.GETPOST("type", "alpha").'" method="GET">';
129 
130  print '<table class="liste" width="100%">';
131  print '<tr class="liste_titre">';
132  print_liste_field_titre("Lastname",$_SERVER["PHP_SELF"],"p.name", $begin, $param,"",$sortfield,$sortorder);
133  print_liste_field_titre("Firstname",$_SERVER["PHP_SELF"],"p.firstname", $begin, $param,"",$sortfield,$sortorder);
134  print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom", $begin, $param,"",$sortfield,$sortorder);
135  print_liste_field_titre("Email");
136  print_liste_field_titre("Phone");
137  print "</tr>\n";
138 
139  print '<tr class="liste_titre">';
140  print '<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.'"></td>';
141  print '<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.'"></td>';
142  print '<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.'"></td>';
143  print '<td class="liste_titre">&nbsp;</td>';
144  print '<td class="liste_titre" align="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>';
145  print "</tr>\n";
146 
147  $var=True;
148  $i = 0;
149  while ($i < min($num,$limit))
150  {
151  $obj = $db->fetch_object($resql);
152 
153 
154 
155  print '<tr class="oddeven">';
156  print '<td><a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowContact"),"contact");
157  print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$obj->cidp.'&socid='.$obj->rowid.'">'.$obj->name.'</a></td>';
158  print "<td>$obj->firstname</TD>";
159 
160  print '<td><a href="'.$_SERVER["PHP_SELF"].'?type='.$type.'&socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
161  print "<a href=\"".$urlfiche."?socid=".$obj->rowid."\">$obj->name</a></td>\n";
162 
163  print '<td>'.dol_print_phone($obj->email,$obj->cidp,$obj->rowid,'AC_EMAIL').'</td>';
164 
165  print '<td>'.dol_print_phone($obj->phone,$obj->country_code,$obj->cidp,$obj->rowid,'AC_TEL').'&nbsp;</td>';
166 
167  print "</tr>\n";
168  $i++;
169  }
170  print "</table>";
171 
172  print '</form>';
173 
174  $db->free($resql);
175 }
176 else
177 {
178  dol_print_error($db);
179 }
180 
181 llxFooter();
182 
183 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
GETPOST($paramname, $check='none', $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='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
llxHeader()
Empty header.
Definition: wrapper.php:46
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.