dolibarr/htdocs/comm/clients.php

162 lines
6.1 KiB
PHP
Raw Normal View History

<?php
2006-12-23 15:57:19 +01:00
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
2008-03-31 05:57:05 +02:00
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
2002-05-10 14:28:10 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
2004-12-25 19:44:15 +01:00
2005-04-29 00:25:48 +02:00
/**
2005-08-21 21:09:05 +02:00
\file htdocs/comm/clients.php
\ingroup commercial, societe
\brief Liste des clients
2008-02-24 14:18:40 +01:00
\version $Id$
2004-12-25 19:44:15 +01:00
*/
2003-09-11 18:30:47 +02:00
require("./pre.inc.php");
2008-02-24 14:18:40 +01:00
// Security check
2008-02-25 17:30:43 +01:00
$socid = isset($_GET["socid"])?$_GET["socid"]:'';
2008-02-25 21:03:21 +01:00
if ($user->societe_id) $socid=$user->societe_id;
2008-03-01 02:26:41 +01:00
$result = restrictedArea($user, 'societe',$socid,'');
2003-03-23 16:53:03 +01:00
2008-03-31 05:57:05 +02:00
$sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
$sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
$page=isset($_GET["page"])?$_GET["page"]:$_POST["page"];
2003-03-23 16:53:03 +01:00
if ($page == -1) { $page = 0 ; }
2008-03-31 05:57:05 +02:00
$offset = $conf->liste_limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (! $sortorder) $sortorder="ASC";
if (! $sortfield) $sortfield="s.nom";
2002-05-10 14:28:10 +02:00
2005-08-11 20:54:59 +02:00
$search_nom=isset($_GET["search_nom"])?$_GET["search_nom"]:$_POST["search_nom"];
$search_ville=isset($_GET["search_ville"])?$_GET["search_ville"]:$_POST["search_ville"];
2007-01-23 19:13:40 +01:00
$search_code=isset($_GET["search_code"])?$_GET["search_code"]:$_POST["search_code"];
2005-08-11 20:54:59 +02:00
2006-03-08 14:51:37 +01:00
2008-03-06 18:56:12 +01:00
/*
* view
*/
llxHeader();
$sql = "SELECT s.rowid, s.nom, s.ville, ".$db->pdate("s.datec")." as datec, ".$db->pdate("s.datea")." as datea, st.libelle as stcomm, s.prefix_comm, s.code_client";
2008-03-01 02:26:41 +01:00
if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
2008-03-01 02:26:41 +01:00
if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql .= " WHERE s.fk_stcomm = st.id AND s.client=1";
2003-03-23 16:53:03 +01:00
if ($socid) $sql .= " AND s.rowid = ".$socid;
if ($user->societe_id) $sql .= " AND s.rowid = " .$user->societe_id;
2008-03-01 02:26:41 +01:00
if (!$user->rights->societe->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
2004-12-01 16:28:28 +01:00
2006-02-25 01:43:24 +01:00
if ($search_nom) $sql .= " AND s.nom like '%".addslashes(strtolower($search_nom))."%'";
if ($search_ville) $sql .= " AND s.ville like '%".addslashes(strtolower($search_ville))."%'";
if ($search_code) $sql .= " AND s.code_client like '%".addslashes(strtolower($search_code))."%'";
2003-03-23 16:53:03 +01:00
if ($socname)
{
2008-03-31 05:57:05 +02:00
$sql .= " AND s.nom like '%".addslashes(strtolower($socname))."%'";
$sortfield = "s.nom";
$sortorder = "ASC";
}
2008-03-06 18:56:12 +01:00
// Count total nb of records
$nbtotalofrecords = 0;
2008-03-06 19:12:07 +01:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
2008-03-06 18:56:12 +01:00
{
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
}
2002-05-10 14:28:10 +02:00
2008-03-06 18:56:12 +01:00
$sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit +1, $offset);
2003-03-23 16:53:03 +01:00
$result = $db->query($sql);
if ($result)
{
2006-12-23 15:57:19 +01:00
$num = $db->num_rows($result);
2007-01-23 19:32:23 +01:00
$param = "&amp;search_nom=".$search_nom."&amp;search_code=".$search_code."&amp;search_ville=".$search_ville;
2008-03-06 18:56:12 +01:00
print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
2006-12-23 15:57:19 +01:00
$i = 0;
print '<form method="get" action="clients.php">'."\n";
print '<table class="liste">'."\n";
print '<tr class="liste_titre">';
2008-03-31 05:57:05 +02:00
print_liste_field_titre($langs->trans("Company"),"clients.php","s.nom","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Town"),"clients.php","s.ville","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("CustomerCode"),"clients.php","s.code_client","",$param,"",$sortfield,$sortorder);
print_liste_field_titre($langs->trans("DateCreation"),"clients.php","datec","",$param,'align="center"',$sortfield,$sortorder);
2006-12-23 15:57:19 +01:00
print '<td class="liste_titre">&nbsp;</td>';
print "</tr>\n";
print '<tr class="liste_titre">';
print '<td class="liste_titre">';
2007-01-23 19:13:40 +01:00
print '<input type="text" class="flat" name="search_nom" value="'.$search_nom.'">';
2006-12-23 15:57:19 +01:00
print '</td><td class="liste_titre">';
print '<input type="text" class="flat" name="search_ville" value="'.$search_ville.'" size="10">';
print '</td><td class="liste_titre">';
print '<input type="text" class="flat" name="search_code" value="'.$search_code.'" size="10">';
print '</td><td class="liste_titre">&nbsp;</td>';
print '<td class="liste_titre" align="center"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'"></td>';
print "</tr>\n";
$var=True;
while ($i < min($num,$conf->liste_limit))
{
$obj = $db->fetch_object($result);
$var=!$var;
print "<tr $bc[$var]>";
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->rowid.'">';
2006-12-23 15:57:19 +01:00
print img_object($langs->trans("ShowCustomer"),"company");
print '</a>&nbsp;<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->rowid.'">'.stripslashes($obj->nom).'</a></td>';
2006-12-23 15:57:19 +01:00
print '<td>'.$obj->ville.'</td>';
print '<td>'.$obj->code_client.'</td>';
print '<td align="center">'.dolibarr_print_date($obj->datec).'</td>';
print '<td align="center">';
if (defined("MAIN_MODULE_DOSSIER") && MAIN_MODULE_DOSSIER == 1)
{
print '<a href="'.DOL_URL_ROOT.'/dossier/client/fiche.php?id='.$obj->rowid.'">';
2006-12-23 15:57:19 +01:00
print img_folder();
print '</a>';
}
else
{
2006-12-23 15:57:19 +01:00
print "&nbsp;";
}
2006-12-23 15:57:19 +01:00
print "</td></tr>\n";
$i++;
}
//print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],'',$sortfield,$sortorder,'',$num);
print "</table>\n";
print "</form>\n";
$db->free($result);
2003-03-23 16:53:03 +01:00
}
else
{
2006-12-23 15:57:19 +01:00
dolibarr_print_error($db);
2003-03-23 16:53:03 +01:00
}
2002-05-10 14:28:10 +02:00
$db->close();
2005-08-11 20:54:59 +02:00
llxFooter('$Date$ - $Revision$');
2002-05-10 14:28:10 +02:00
?>