PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/boxes/box_clients.php

https://github.com/asterix14/dolibarr
PHP | 135 lines | 79 code | 27 blank | 29 comment | 13 complexity | dcfd1efd06c85d75dd30f27ebb4c6d37 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 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_clients.php
  21. * \ingroup societes
  22. * \brief Module de generation de l'affichage de la box clients
  23. */
  24. include_once(DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php");
  25. class box_clients extends ModeleBoxes {
  26. var $boxcode="lastcustomers";
  27. var $boximg="object_company";
  28. var $boxlabel;
  29. var $depends = array("societe");
  30. var $db;
  31. var $param;
  32. var $info_box_head = array();
  33. var $info_box_contents = array();
  34. /**
  35. * \brief Constructeur de la classe
  36. */
  37. function box_clients()
  38. {
  39. global $langs;
  40. $langs->load("boxes");
  41. $this->boxlabel=$langs->trans("BoxLastCustomers");
  42. }
  43. /**
  44. * Load data of box into memory for a future usage
  45. * @param $max Maximum number of records to show
  46. */
  47. function loadBox($max=5)
  48. {
  49. global $user, $langs, $db, $conf;
  50. $langs->load("boxes");
  51. $this->max=$max;
  52. include_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  53. $thirdpartystatic=new Societe($db);
  54. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers",$max));
  55. if ($user->rights->societe->lire)
  56. {
  57. $sql = "SELECT s.nom, s.rowid as socid, s.datec, s.tms, s.status";
  58. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  59. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  60. $sql.= " WHERE s.client IN (1, 3)";
  61. $sql.= " AND s.entity = ".$conf->entity;
  62. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  63. if ($user->societe_id) $sql.= " AND s.rowid = $user->societe_id";
  64. $sql.= " ORDER BY s.tms DESC";
  65. $sql.= $db->plimit($max, 0);
  66. $result = $db->query($sql);
  67. if ($result)
  68. {
  69. $num = $db->num_rows($result);
  70. if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $url= DOL_URL_ROOT."/comm/fiche.php?socid=";
  71. else $url= DOL_URL_ROOT."/societe/soc.php?socid=";
  72. $i = 0;
  73. while ($i < $num)
  74. {
  75. $objp = $db->fetch_object($result);
  76. $datec=$db->jdate($objp->datec);
  77. $datem=$db->jdate($objp->tms);
  78. $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"',
  79. 'logo' => $this->boximg,
  80. 'url' => $url.$objp->socid);
  81. $this->info_box_contents[$i][1] = array('td' => 'align="left"',
  82. 'text' => $objp->nom,
  83. 'url' => $url.$objp->socid);
  84. $this->info_box_contents[$i][2] = array('td' => 'align="right"',
  85. 'text' => dol_print_date($datem, "day"));
  86. $this->info_box_contents[$i][3] = array('td' => 'align="right" width="18"',
  87. 'text' => $thirdpartystatic->LibStatut($objp->status,3));
  88. $i++;
  89. }
  90. if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedCustomers"));
  91. }
  92. else {
  93. $this->info_box_contents[0][0] = array( 'td' => 'align="left"',
  94. 'maxlength'=>500,
  95. 'text' => ($db->error().' sql='.$sql));
  96. }
  97. }
  98. else {
  99. $this->info_box_contents[0][0] = array('align' => 'left',
  100. 'text' => $langs->trans("ReadPermissionNotAllowed"));
  101. }
  102. }
  103. function showBox($head = null, $contents = null)
  104. {
  105. parent::showBox($this->info_box_head, $this->info_box_contents);
  106. }
  107. }
  108. ?>