PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/boxes/box_produits.php

https://github.com/asterix14/dolibarr
PHP | 164 lines | 105 code | 29 blank | 30 comment | 14 complexity | e85c384bb6baba7bd71b955568c36f6f MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/boxes/box_produits.php
  21. * \ingroup produits,services
  22. * \brief Module to generate box of last products/services
  23. */
  24. include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php");
  25. include_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  26. class box_produits extends ModeleBoxes {
  27. var $boxcode="lastproducts";
  28. var $boximg="object_product";
  29. var $boxlabel;
  30. var $depends = array("produit");
  31. var $db;
  32. var $param;
  33. var $info_box_head = array();
  34. var $info_box_contents = array();
  35. /**
  36. * \brief Constructeur de la classe
  37. */
  38. function box_produits()
  39. {
  40. global $langs;
  41. $langs->load("boxes");
  42. $this->boxlabel=$langs->trans("BoxLastProducts");
  43. }
  44. /**
  45. * \brief Charge les donnees en memoire pour affichage ulterieur
  46. * \param $max Nombre maximum d'enregistrements a charger
  47. */
  48. function loadBox($max=5)
  49. {
  50. global $user, $langs, $db, $conf;
  51. $this->max=$max;
  52. include_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  53. $productstatic=new Product($db);
  54. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastProducts",$max));
  55. if ($user->rights->produit->lire || $user->rights->service->lire)
  56. {
  57. $sql = "SELECT p.rowid, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy";
  58. $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
  59. $sql.= ' WHERE p.entity IN (0,'.(! empty($conf->entities['product']) ? $conf->entities['product'] : $conf->entity).')';
  60. if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0';
  61. if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1';
  62. $sql.= $db->order('p.datec', 'DESC');
  63. $sql.= $db->plimit($max, 0);
  64. $result = $db->query($sql);
  65. if ($result)
  66. {
  67. $num = $db->num_rows($result);
  68. $i = 0;
  69. while ($i < $num)
  70. {
  71. $objp = $db->fetch_object($result);
  72. $datem=$db->jdate($objp->tms);
  73. // Multilangs
  74. if ($conf->global->MAIN_MULTILANGS) // si l'option est active
  75. {
  76. $sqld = "SELECT label";
  77. $sqld.= " FROM ".MAIN_DB_PREFIX."product_lang";
  78. $sqld.= " WHERE fk_product=".$objp->rowid;
  79. $sqld.= " AND lang='". $langs->getDefaultLang() ."'";
  80. $sqld.= " LIMIT 1";
  81. $resultd = $db->query($sqld);
  82. if ($resultd)
  83. {
  84. $objtp = $db->fetch_object($resultd);
  85. if ($objtp->label != '') $objp->label = $objtp->label;
  86. }
  87. }
  88. $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"',
  89. 'logo' => ($objp->fk_product_type==1?'object_service':'object_product'),
  90. 'url' => DOL_URL_ROOT."/product/fiche.php?id=".$objp->rowid);
  91. $this->info_box_contents[$i][1] = array('td' => 'align="left"',
  92. 'text' => $objp->label,
  93. 'url' => DOL_URL_ROOT."/product/fiche.php?id=".$objp->rowid);
  94. if ($objp->price_base_type == 'HT')
  95. {
  96. $price=price($objp->price);
  97. $price_base_type=$langs->trans("HT");
  98. }
  99. else
  100. {
  101. $price=price($objp->price_ttc);
  102. $price_base_type=$langs->trans("TTC");
  103. }
  104. $this->info_box_contents[$i][2] = array('td' => 'align="right"',
  105. 'text' => $price);
  106. $this->info_box_contents[$i][3] = array('td' => 'align="center" width="20" nowrap="nowrap"',
  107. 'text' => $price_base_type);
  108. $this->info_box_contents[$i][4] = array('td' => 'align="right"',
  109. 'text' => dol_print_date($datem,'day'));
  110. $this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"',
  111. 'text' => $productstatic->LibStatut($objp->tosell,3,0));
  112. $this->info_box_contents[$i][6] = array('td' => 'align="right" width="18"',
  113. 'text' => $productstatic->LibStatut($objp->tobuy,3,1));
  114. $i++;
  115. }
  116. if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedProducts"));
  117. }
  118. else
  119. {
  120. $this->info_box_contents[0][0] = array( 'td' => 'align="left"',
  121. 'maxlength'=>500,
  122. 'text' => ($db->error().' sql='.$sql));
  123. }
  124. }
  125. else {
  126. $this->info_box_contents[0][0] = array('td' => 'align="left"',
  127. 'text' => $langs->trans("ReadPermissionNotAllowed"));
  128. }
  129. }
  130. function showBox($head = null, $contents = null)
  131. {
  132. parent::showBox($this->info_box_head, $this->info_box_contents);
  133. }
  134. }
  135. ?>