diff --git a/htdocs/product/index.php3 b/htdocs/product/index.php3
index 576fd9eda55..b706ae0bf1c 100644
--- a/htdocs/product/index.php3
+++ b/htdocs/product/index.php3
@@ -19,19 +19,9 @@
* $Source$
*
*/
-
require("./pre.inc.php3");
$db = new Db();
-if ($sortfield == "")
-{
- $sortfield="lower(p.label),p.price";
-}
-if ($sortorder == "")
-{
- $sortorder="ASC";
-}
-
if ($action == 'update')
{
@@ -39,51 +29,69 @@ if ($action == 'update')
$db->query($sql);
}
+if ($page == -1) {
+ $page = 0 ;
+}
-if ($page == -1) { $page = 0 ; }
$limit = $conf->liste_limit;
$offset = $limit * $page ;
-llxHeader();
-
-print_barre_liste("Liste des produits", $page, $PHP_SELF);
-
-print '
';
-
-print "| ";
-print_liste_field_titre("Réf",$PHP_SELF, "p.ref");
-print " | ";
-print_liste_field_titre("Libellé",$PHP_SELF, "p.label");
-print " | Prix de vente | ";
-print "
\n";
-
-print '';
-print '| |
';
+if ($sortfield == "")
+{
+ $sortfield="p.tms";
+}
+if ($sortorder == "")
+{
+ $sortorder="DESC";
+}
$sql = "SELECT p.rowid, p.label, p.price, p.ref FROM llx_product as p";
-if ($HTTP_POST_VARS["sref"])
+if ($sref)
{
- $sql .= " WHERE lower(p.ref) like '%".strtolower($HTTP_POST_VARS["sref"])."%'";
+ $sql .= " WHERE lower(p.ref) like '%".strtolower($sref)."%'";
}
-if ($HTTP_POST_VARS["snom"])
+if ($snom)
{
- $sql .= " WHERE lower(p.label) like '%".strtolower($HTTP_POST_VARS["snom"])."%'";
+ $sql .= " WHERE lower(p.label) like '%".strtolower($snom)."%'";
}
$sql .= " ORDER BY $sortfield $sortorder ";
-$sql .= $db->plimit( $limit ,$offset);
+$sql .= $db->plimit($limit + 1 ,$offset);
if ( $db->query($sql) )
{
$num = $db->num_rows();
$i = 0;
+ if ($num == 1)
+ {
+ $objp = $db->fetch_object($i);
+ Header("Location: fiche.php3?id=$objp->rowid");
+ }
+
+ llxHeader();
+
+ print_barre_liste("Liste des produits", $page, $PHP_SELF, "&sref=$sref&snom=$snom", $sortfield, $sortorder,'',$num);
+
+ print '';
+
+ print "| ";
+ print_liste_field_titre("Réf",$PHP_SELF, "p.ref");
+ print " | ";
+ print_liste_field_titre("Libellé",$PHP_SELF, "p.label");
+ print " | Prix de vente | ";
+ print "
\n";
+
+ print '';
+ print '| |
';
+
+
$var=True;
- while ($i < $num)
+ while ($i < min($num,$limit))
{
$objp = $db->fetch_object( $i);
$var=!$var;
@@ -95,8 +103,15 @@ if ( $db->query($sql) )
$i++;
}
$db->free();
+
+ print "
";
+
}
-print "
";
+else
+{
+ print $db->error();
+}
+
$db->close();