PageRenderTime 53ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/product/popuprop.php

https://bitbucket.org/speedealing/speedealing
PHP | 167 lines | 107 code | 30 blank | 30 comment | 26 complexity | 27ae0fb60bb585eff2a88e92fdbc26f5 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  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. /**
  21. * \file htdocs/product/popuprop.php
  22. * \ingroup propal, produit
  23. * \brief Liste des produits/services par popularite
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  27. //Required to translate NbOfProposals
  28. $langs->load('propal');
  29. $type=GETPOST("type","int");
  30. // Security check
  31. if (! empty($user->societe_id)) $socid=$user->societe_id;
  32. $result=restrictedArea($user,'produit|service');
  33. $sortfield = GETPOST("sortfield",'alpha');
  34. $sortorder = GETPOST("sortorder",'alpha');
  35. $page = GETPOST("page",'int');
  36. if ($page < 0) $page = 0;
  37. if (! $sortfield) $sortfield="c";
  38. if (! $sortorder) $sortorder="DESC";
  39. if ($page == -1) $page = 0;
  40. $limit = $conf->liste_limit;
  41. $offset = $limit * $page ;
  42. $staticproduct=new Product($db);
  43. /*
  44. * View
  45. */
  46. $helpurl='';
  47. if ($type == 0)
  48. {
  49. $helpurl='EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  50. }
  51. else if ($type == 1)
  52. {
  53. $helpurl='EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  54. }
  55. llxHeader('','',$helpurl);
  56. //On n'affiche le lien page suivante que s'il y a une page suivante ...
  57. $sql = "SELECT count(*) as c";
  58. $sql.= " FROM ".MAIN_DB_PREFIX."product";
  59. $sql.= ' WHERE entity IN ('.getEntity('product', 1).')';
  60. if (isset($type)) $sql.= " AND fk_product_type = ".$type;
  61. $result=$db->query($sql);
  62. if ($result)
  63. {
  64. $obj = $db->fetch_object($result);
  65. $num = $obj->c;
  66. }
  67. $param = '';
  68. $title = $langs->trans("ListProductServiceByPopularity");
  69. if (isset($type))
  70. {
  71. $param = '&amp;type='.$type;
  72. $title = $langs->trans("ListProductByPopularity");
  73. if ($type == 1) $title = $langs->trans("ListServiceByPopularity");
  74. }
  75. print_barre_liste($title, $page, "popuprop.php",$param,"","","",$num);
  76. print '<table class="noborder" width="100%">';
  77. print "<tr class=\"liste_titre\">";
  78. print_liste_field_titre($langs->trans('Ref'), 'popuprop.php', 'p.ref', '', '', '', $sortfield, $sortorder);
  79. print_liste_field_titre($langs->trans('Type'), 'popuprop.php', 'p.type', '', '', '', $sortfield, $sortorder);
  80. print_liste_field_titre($langs->trans('Label'), 'popuprop.php', 'p.label', '', '', '', $sortfield, $sortorder);
  81. print_liste_field_titre($langs->trans('NbOfProposals'), 'popuprop.php', 'c', '', '', 'align="right"', $sortfield, $sortorder);
  82. print "</tr>\n";
  83. $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type as type, count(*) as c";
  84. $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as pd";
  85. $sql.= ", ".MAIN_DB_PREFIX."product as p";
  86. $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
  87. $sql.= " AND p.rowid = pd.fk_product";
  88. if (isset($type)) $sql.= " AND fk_product_type = ".$type;
  89. $sql.= " GROUP BY (p.rowid)";
  90. $sql.= $db->order($sortfield,$sortorder);
  91. $sql.= $db->plimit($limit, $offset);
  92. $result=$db->query($sql);
  93. if ($result)
  94. {
  95. $num = $db->num_rows($result);
  96. $i = 0;
  97. $var=True;
  98. while ($i < $num)
  99. {
  100. $objp = $db->fetch_object($result);
  101. // Multilangs
  102. if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active
  103. {
  104. $sql = "SELECT label";
  105. $sql.= " FROM ".MAIN_DB_PREFIX."product_lang";
  106. $sql.= " WHERE fk_product=".$objp->rowid;
  107. $sql.= " AND lang='". $langs->getDefaultLang() ."'";
  108. $sql.= " LIMIT 1";
  109. $resultp = $db->query($sql);
  110. if ($resultp)
  111. {
  112. $objtp = $db->fetch_object($resultp);
  113. if (! empty($objtp->label)) $objp->label = $objtp->label;
  114. }
  115. }
  116. $var=!$var;
  117. print "<tr $bc[$var]>";
  118. print '<td><a href="'.DOL_URL_ROOT.'/product/stats/fiche.php?id='.$objp->rowid.'">';
  119. if ($objp->type==1) print img_object($langs->trans("ShowService"),"service");
  120. else print img_object($langs->trans("ShowProduct"),"product");
  121. print " ";
  122. print $objp->ref.'</a></td>';
  123. print '<td>';
  124. if ($objp->type==1) print $langs->trans("ShowService");
  125. else print $langs->trans("ShowProduct");
  126. print '</td>';
  127. print '<td>'.$objp->label.'</td>';
  128. print '<td align="right">'.$objp->c.'</td>';
  129. print "</tr>\n";
  130. $i++;
  131. }
  132. $db->free();
  133. }
  134. print "</table>";
  135. llxFooter();
  136. $db->close();
  137. ?>