box_ficheinter.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  3. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  4. * Copyright (C) 2015 Frederic France <frederic.france@free.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 3 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 <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/boxes/box_ficheinter.php
  21. * \ingroup ficheinter
  22. * \brief Box to show last interventions
  23. */
  24. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  25. /**
  26. * Class to manage the box to show last interventions
  27. */
  28. class box_ficheinter extends ModeleBoxes
  29. {
  30. public $boxcode = "ficheinter";
  31. public $boximg = "object_intervention";
  32. public $boxlabel = "BoxFicheInter";
  33. public $depends = array("ficheinter"); // conf->contrat->enabled
  34. /**
  35. * @var DoliDB Database handler.
  36. */
  37. public $db;
  38. public $param;
  39. public $info_box_head = array();
  40. public $info_box_contents = array();
  41. /**
  42. * Constructor
  43. *
  44. * @param DoliDB $db Database handler
  45. * @param string $param More parameters
  46. */
  47. public function __construct($db, $param)
  48. {
  49. global $user;
  50. $this->db = $db;
  51. $this->hidden = empty($user->rights->ficheinter->lire);
  52. }
  53. /**
  54. * Load data for box to show them later
  55. *
  56. * @param int $max Maximum number of records to load
  57. * @return void
  58. */
  59. public function loadBox($max = 10)
  60. {
  61. global $user, $langs, $conf;
  62. $this->max = $max;
  63. include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  64. $ficheinterstatic = new Fichinter($this->db);
  65. $thirdpartystatic = new Societe($this->db);
  66. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastFicheInter", $max));
  67. if (!empty($user->rights->ficheinter->lire)) {
  68. $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
  69. $sql .= ", f.datec";
  70. $sql .= ", f.date_valid as datev";
  71. $sql .= ", f.tms as datem";
  72. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  73. $sql .= ", s.code_client, s.code_compta, s.client";
  74. $sql .= ", s.logo, s.email, s.entity";
  75. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  76. if (empty($user->rights->societe->client->voir)) {
  77. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  78. }
  79. $sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
  80. $sql .= " WHERE f.fk_soc = s.rowid ";
  81. $sql .= " AND f.entity = ".$conf->entity;
  82. if (empty($user->rights->societe->client->voir) && !$user->socid) {
  83. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  84. }
  85. if ($user->socid) {
  86. $sql .= " AND s.rowid = ".((int) $user->socid);
  87. }
  88. $sql .= " ORDER BY f.tms DESC";
  89. $sql .= $this->db->plimit($max, 0);
  90. dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
  91. $resql = $this->db->query($sql);
  92. if ($resql) {
  93. $num = $this->db->num_rows($resql);
  94. $now = dol_now();
  95. $i = 0;
  96. while ($i < $num) {
  97. $objp = $this->db->fetch_object($resql);
  98. $datec = $this->db->jdate($objp->datec);
  99. $datem = $this->db->jdate($objp->datem);
  100. $ficheinterstatic->statut = $objp->status;
  101. $ficheinterstatic->status = $objp->status;
  102. $ficheinterstatic->id = $objp->rowid;
  103. $ficheinterstatic->ref = $objp->ref;
  104. $thirdpartystatic->id = $objp->socid;
  105. $thirdpartystatic->name = $objp->name;
  106. //$thirdpartystatic->name_alias = $objp->name_alias;
  107. $thirdpartystatic->code_client = $objp->code_client;
  108. $thirdpartystatic->code_compta = $objp->code_compta;
  109. $thirdpartystatic->client = $objp->client;
  110. $thirdpartystatic->logo = $objp->logo;
  111. $thirdpartystatic->email = $objp->email;
  112. $thirdpartystatic->entity = $objp->entity;
  113. $this->info_box_contents[$i][] = array(
  114. 'td' => 'class="nowraponall"',
  115. 'text' => $ficheinterstatic->getNomUrl(1),
  116. 'asis' => 1,
  117. );
  118. $this->info_box_contents[$i][] = array(
  119. 'td' => 'class="tdoverflowmax150"',
  120. 'text' => $thirdpartystatic->getNomUrl(1),
  121. 'asis' => 1,
  122. );
  123. $this->info_box_contents[$i][] = array(
  124. 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
  125. 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
  126. );
  127. $this->info_box_contents[$i][] = array(
  128. 'td' => 'class="nowrap right"',
  129. 'text' => $ficheinterstatic->getLibStatut(3),
  130. 'asis' => 1,
  131. );
  132. $i++;
  133. }
  134. if ($num == 0) {
  135. $this->info_box_contents[$i][0] = array(
  136. 'td' => 'class="center opacitymedium"',
  137. 'text'=>$langs->trans("NoRecordedInterventions")
  138. );
  139. }
  140. $this->db->free($resql);
  141. } else {
  142. $this->info_box_contents[0][0] = array(
  143. 'td' => '',
  144. 'maxlength'=>500,
  145. 'text' => ($this->db->error().' sql='.$sql),
  146. );
  147. }
  148. } else {
  149. $this->info_box_contents[0][0] = array(
  150. 'td' => 'class="nohover opacitymedium left"',
  151. 'text' => $langs->trans("ReadPermissionNotAllowed")
  152. );
  153. }
  154. }
  155. /**
  156. * Method to show box
  157. *
  158. * @param array $head Array with properties of box title
  159. * @param array $contents Array with properties of box lines
  160. * @param int $nooutput No print, only return string
  161. * @return string
  162. */
  163. public function showBox($head = null, $contents = null, $nooutput = 0)
  164. {
  165. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  166. }
  167. }