30require
'../main.inc.php';
33$langs->load(
"companies");
35$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
36$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
42 $sortfield =
"p.lastname";
48$offset = $limit * $page;
50$type =
GETPOST(
'type',
'alpha');
52$search_firstname =
GETPOST(
'search_firstname') ?
GETPOST(
'search_firstname') :
GETPOST(
'search_firstname');
54$contactname =
GETPOST(
'contactname');
55$begin =
GETPOST(
'begin',
'alpha');
61 $socid = $user->socid;
64$hookmanager->initHooks(array(
'contactlist'));
76if ($type ==
"c" || $type ==
"p") {
77 $label = $langs->trans(
"Customers");
78 $urlfiche =
"card.php";
81 $label = $langs->trans(
"Suppliers");
82 $urlfiche =
"card.php";
89$sql =
"SELECT s.rowid, s.nom as name, st.libelle as stcomm,";
90$sql .=
" p.rowid as cidp, p.lastname, p.firstname, p.email, p.phone";
91$sql .=
" FROM ".MAIN_DB_PREFIX.
"c_stcomm as st,";
92$sql .=
" ".MAIN_DB_PREFIX.
"socpeople as p";
93$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = p.fk_soc";
94$sql .=
" WHERE s.fk_stcomm = st.id";
95$sql .=
" AND p.entity IN (".getEntity(
'contact').
")";
97 $sql .=
" AND s.client IN (1, 3)";
100 $sql .=
" AND s.client IN (2, 3)";
103 $sql .=
" AND s.fournisseur = 1";
105if (!empty($search_lastname)) {
106 $sql .=
" AND p.lastname LIKE '%".$db->escape($search_lastname).
"%'";
108if (!empty($search_firstname)) {
109 $sql .=
" AND p.firstname LIKE '%".$db->escape($search_firstname).
"%'";
111if (!empty($search_company)) {
112 $sql .=
" AND s.nom LIKE '%".$db->escape($search_company).
"%'";
114if (!empty($contactname)) {
115 $sql .=
" AND (p.lastname LIKE '%".$db->escape($contactname).
"%' OR lower(p.firstname) LIKE '%".$db->escape($contactname).
"%') ";
116 $sortfield =
"p.lastname";
121if (!$user->hasRight(
'societe',
'client',
'voir')) {
122 $search_sale = $user->id;
125if ($search_sale && $search_sale !=
'-1') {
126 if ($search_sale == -2) {
127 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
128 } elseif ($search_sale > 0) {
129 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
134 $sql .=
" AND p.fk_soc = ".((int) $socid);
137$sql .= $db->order($sortfield, $sortorder);
138$sql .= $db->plimit($limit + 1, $offset);
140$resql = $db->query($sql);
142 $num = $db->num_rows($resql);
144 $param =
"&type=".$type;
146 $title = (
getDolGlobalString(
'SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans(
"ListOfContacts") : $langs->trans(
"ListOfContactsAddresses"));
147 print_barre_liste($title.($label ?
" (".$label.
")" :
""), $page, $_SERVER[
"PHP_SELF"], $param, $sortfield, $sortorder,
"", $num);
149 print
'<form action="'.$_SERVER[
"PHP_SELF"].
'?type='.
GETPOST(
"type",
"alpha").
'" method="GET">';
151 print
'<table class="liste centpercent">';
152 print
'<tr class="liste_titre">';
153 print_liste_field_titre(
"Lastname", $_SERVER[
"PHP_SELF"],
"p.lastname", $begin, $param,
"", $sortfield, $sortorder);
154 print_liste_field_titre(
"Firstname", $_SERVER[
"PHP_SELF"],
"p.firstname", $begin, $param,
"", $sortfield, $sortorder);
160 print
'<tr class="liste_titre">';
161 print
'<td class="liste_titre"><input class="flat" name="search_lastname" size="12" value="'.$search_lastname.
'"></td>';
162 print
'<td class="liste_titre"><input class="flat" name="search_firstname" size="12" value="'.$search_firstname.
'"></td>';
163 print
'<td class="liste_titre"><input class="flat" name="search_company" size="12" value="'.$search_company.
'"></td>';
164 print
'<td class="liste_titre"> </td>';
165 print
'<td class="liste_titre right"><input type="image" class="liste_titre" src="'.img_picto($langs->trans(
"Search"),
'search.png',
'', 0, 1).
'" value="'.
dol_escape_htmltag($langs->trans(
"Search")).
'" title="'.
dol_escape_htmltag($langs->trans(
"Search")).
'"></td>';
169 while ($i < min($num, $limit)) {
170 $obj = $db->fetch_object($resql);
172 print
'<tr class="oddeven">';
173 print
'<td><a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.$obj->cidp.
'&socid='.$obj->rowid.
'">'.
img_object($langs->trans(
"ShowContact"),
"contact");
174 print
'</a> <a href="'.DOL_URL_ROOT.
'/contact/card.php?id='.$obj->cidp.
'&socid='.$obj->rowid.
'">'.$obj->name.
'</a></td>';
175 print
'<td>'.dol_escape_htmltag($obj->firstname).
'</td>';
177 print
'<td><a href="'.$_SERVER[
"PHP_SELF"].
'?type='.$type.
'&socid='.$obj->rowid.
'">'.
img_object($langs->trans(
"ShowCompany"),
"company").
'</a> ';
178 print
'<a href="'.$urlfiche.
"?socid=".$obj->rowid.
'">'.$obj->name.
"</a></td>\n";
180 print
'<td>'.dol_print_email($obj->email, $obj->cidp, $obj->rowid,
'AC_EMAIL').
'</td>';
182 print
'<td>'.dol_print_phone($obj->phone, $obj->country_code, $obj->cidp, $obj->rowid,
'AC_TEL').
' </td>';
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.
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.
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.
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.