box_project.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /* Copyright (C) 2012-2014 Charles-François BENKE <charles.fr@benke.fr>
  3. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  4. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  5. * Copyright (C) 2016 Juan José Menent <jmenent@2byte.es>
  6. * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/core/boxes/box_project.php
  23. * \ingroup projet
  24. * \brief Module to show Projet activity of the current Year
  25. */
  26. include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  27. /**
  28. * Class to manage the box to show last projet
  29. */
  30. class box_project extends ModeleBoxes
  31. {
  32. public $boxcode = "project";
  33. public $boximg = "object_projectpub";
  34. public $boxlabel;
  35. //var $depends = array("projet");
  36. /**
  37. * @var DoliDB Database handler.
  38. */
  39. public $db;
  40. public $param;
  41. public $info_box_head = array();
  42. public $info_box_contents = array();
  43. /**
  44. * Constructor
  45. *
  46. * @param DoliDB $db Database handler
  47. * @param string $param More parameters
  48. */
  49. public function __construct($db, $param = '')
  50. {
  51. global $user, $langs;
  52. // Load translation files required by the page
  53. $langs->loadLangs(array('boxes', 'projects'));
  54. $this->db = $db;
  55. $this->boxlabel = "OpenedProjects";
  56. $this->hidden = empty($user->rights->projet->lire);
  57. }
  58. /**
  59. * Load data for box to show them later
  60. *
  61. * @param int $max Maximum number of records to load
  62. * @return void
  63. */
  64. public function loadBox($max = 5)
  65. {
  66. global $conf, $user, $langs;
  67. $this->max = $max;
  68. $totalMnt = 0;
  69. $totalnb = 0;
  70. $totalnbTask = 0;
  71. $textHead = $langs->trans("OpenedProjects");
  72. $this->info_box_head = array('text' => $textHead, 'limit'=> dol_strlen($textHead));
  73. $i = 0;
  74. // list the summary of the orders
  75. if ($user->rights->projet->lire) {
  76. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  77. $projectstatic = new Project($this->db);
  78. $socid = 0;
  79. //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  80. // Get list of project id allowed to user (in a string list separated by coma)
  81. $projectsListId = '';
  82. if (empty($user->rights->projet->all->lire)) {
  83. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
  84. }
  85. $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut as status, p.public";
  86. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
  87. $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
  88. $sql .= " AND p.fk_statut = 1"; // Only open projects
  89. if (empty($user->rights->projet->all->lire)) {
  90. $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
  91. }
  92. $sql .= " ORDER BY p.datec DESC";
  93. //$sql.= $this->db->plimit($max, 0);
  94. $result = $this->db->query($sql);
  95. if ($result) {
  96. $num = $this->db->num_rows($result);
  97. while ($i < min($num, $max)) {
  98. $objp = $this->db->fetch_object($result);
  99. $projectstatic->id = $objp->rowid;
  100. $projectstatic->ref = $objp->ref;
  101. $projectstatic->title = $objp->title;
  102. $projectstatic->public = $objp->public;
  103. $projectstatic->statut = $objp->status;
  104. $this->info_box_contents[$i][] = array(
  105. 'td' => 'class="nowraponall"',
  106. 'text' => $projectstatic->getNomUrl(1),
  107. 'asis' => 1
  108. );
  109. $this->info_box_contents[$i][] = array(
  110. 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
  111. 'text' => $objp->title,
  112. );
  113. $sql = "SELECT count(*) as nb, sum(progress) as totprogress";
  114. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
  115. $sql .= " WHERE p.entity IN (".getEntity('project').')';
  116. $sql .= " AND p.rowid = ".((int) $objp->rowid);
  117. $resultTask = $this->db->query($sql);
  118. if ($resultTask) {
  119. $objTask = $this->db->fetch_object($resultTask);
  120. $this->info_box_contents[$i][] = array(
  121. 'td' => 'class="right"',
  122. 'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
  123. );
  124. if ($objTask->nb > 0) {
  125. $this->info_box_contents[$i][] = array(
  126. 'td' => 'class="right"',
  127. 'text' => round($objTask->totprogress / $objTask->nb, 0)."%",
  128. );
  129. } else {
  130. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
  131. }
  132. $totalnbTask += $objTask->nb;
  133. } else {
  134. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
  135. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
  136. }
  137. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
  138. $i++;
  139. }
  140. if ($max < $num) {
  141. $this->info_box_contents[$i][] = array('td' => 'colspan="5"', 'text' => '...');
  142. $i++;
  143. }
  144. }
  145. }
  146. // Add the sum à the bottom of the boxes
  147. $this->info_box_contents[$i][] = array(
  148. 'td' => 'class="liste_total"',
  149. 'text' => $langs->trans("Total")."&nbsp;".$textHead,
  150. 'text' => "&nbsp;",
  151. );
  152. $this->info_box_contents[$i][] = array(
  153. 'td' => 'class="right liste_total" ',
  154. 'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
  155. );
  156. $this->info_box_contents[$i][] = array(
  157. 'td' => 'class="right liste_total" ',
  158. 'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
  159. );
  160. $this->info_box_contents[$i][] = array(
  161. 'td' => 'class="liste_total"',
  162. 'text' => "&nbsp;",
  163. );
  164. $this->info_box_contents[$i][] = array(
  165. 'td' => 'class="liste_total"',
  166. 'text' => "&nbsp;",
  167. );
  168. }
  169. /**
  170. * Method to show box
  171. *
  172. * @param array $head Array with properties of box title
  173. * @param array $contents Array with properties of box lines
  174. * @param int $nooutput No print, only return string
  175. * @return string
  176. */
  177. public function showBox($head = null, $contents = null, $nooutput = 0)
  178. {
  179. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  180. }
  181. }