box_project.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 project
  24. * \brief Module to show Project 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 project
  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->hasRight('projet', 'lire')) {
  76. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  77. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  78. $projectstatic = new Project($this->db);
  79. $companystatic = new Societe($this->db);
  80. $socid = 0;
  81. //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.
  82. // Get list of project id allowed to user (in a string list separated by coma)
  83. $projectsListId = '';
  84. if (!$user->hasRight('projet', 'all', 'lire')) {
  85. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
  86. }
  87. $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut as status, p.public, p.fk_soc,";
  88. $sql .= " s.nom as name, s.name_alias";
  89. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
  90. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid";
  91. $sql .= " WHERE p.entity IN (".getEntity('project').")"; // Only current entity or severals if permission ok
  92. $sql .= " AND p.fk_statut = ".((int) $projectstatic::STATUS_VALIDATED); // Only open projects
  93. if (!$user->hasRight('projet', 'all', 'lire')) {
  94. $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
  95. }
  96. $sql .= " ORDER BY p.datec DESC";
  97. //$sql.= $this->db->plimit($max, 0);
  98. $result = $this->db->query($sql);
  99. if ($result) {
  100. $num = $this->db->num_rows($result);
  101. while ($i < min($num, $max)) {
  102. $objp = $this->db->fetch_object($result);
  103. $projectstatic->id = $objp->rowid;
  104. $projectstatic->ref = $objp->ref;
  105. $projectstatic->title = $objp->title;
  106. $projectstatic->public = $objp->public;
  107. $projectstatic->statut = $objp->status;
  108. $companystatic->id = $objp->fk_soc;
  109. $companystatic->name = $objp->name;
  110. $companystatic->name_alias = $objp->name_alias;
  111. $this->info_box_contents[$i][] = array(
  112. 'td' => 'class="nowraponall"',
  113. 'text' => $projectstatic->getNomUrl(1),
  114. 'asis' => 1
  115. );
  116. $this->info_box_contents[$i][] = array(
  117. 'td' => 'class="tdoverflowmax150 maxwidth200onsmartphone"',
  118. 'text' => $objp->title,
  119. );
  120. $this->info_box_contents[$i][] = array(
  121. 'td' => 'class="tdoverflowmax100"',
  122. 'text' => ($objp->fk_soc > 0 ? $companystatic->getNomUrl(1) : ''),
  123. 'asis' => 1
  124. );
  125. $sql = "SELECT count(*) as nb, sum(progress) as totprogress";
  126. $sql .= " FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid";
  127. $sql .= " WHERE p.entity IN (".getEntity('project').')';
  128. $sql .= " AND p.rowid = ".((int) $objp->rowid);
  129. $resultTask = $this->db->query($sql);
  130. if ($resultTask) {
  131. $objTask = $this->db->fetch_object($resultTask);
  132. $this->info_box_contents[$i][] = array(
  133. 'td' => 'class="right"',
  134. 'text' => $objTask->nb."&nbsp;".$langs->trans("Tasks"),
  135. );
  136. if ($objTask->nb > 0) {
  137. $this->info_box_contents[$i][] = array(
  138. 'td' => 'class="right"',
  139. 'text' => round($objTask->totprogress / $objTask->nb, 0)."%",
  140. );
  141. } else {
  142. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
  143. }
  144. $totalnbTask += $objTask->nb;
  145. } else {
  146. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => round(0));
  147. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => "N/A&nbsp;");
  148. }
  149. $this->info_box_contents[$i][] = array('td' => 'class="right"', 'text' => $projectstatic->getLibStatut(3));
  150. $i++;
  151. }
  152. if ($max < $num) {
  153. $this->info_box_contents[$i][] = array('td' => 'colspan="6"', 'text' => '...');
  154. $i++;
  155. }
  156. }
  157. }
  158. // Add the sum à the bottom of the boxes
  159. $this->info_box_contents[$i][] = array(
  160. 'tr' => 'class="liste_total_wrap"',
  161. 'td' => 'class="liste_total"',
  162. 'text' => $langs->trans("Total")."&nbsp;".$textHead,
  163. );
  164. $this->info_box_contents[$i][] = array(
  165. 'td' => 'class="right liste_total" ',
  166. 'text' => round($num, 0)."&nbsp;".$langs->trans("Projects"),
  167. );
  168. $this->info_box_contents[$i][] = array(
  169. 'td' => 'class="right liste_total" ',
  170. 'text' => (($max < $num) ? '' : (round($totalnbTask, 0)."&nbsp;".$langs->trans("Tasks"))),
  171. );
  172. $this->info_box_contents[$i][] = array(
  173. 'td' => 'class="liste_total"',
  174. 'text' => "&nbsp;",
  175. );
  176. $this->info_box_contents[$i][] = array(
  177. 'td' => 'class="liste_total"',
  178. 'text' => "&nbsp;",
  179. );
  180. $this->info_box_contents[$i][] = array(
  181. 'td' => 'class="liste_total"',
  182. 'text' => "&nbsp;",
  183. );
  184. }
  185. /**
  186. * Method to show box
  187. *
  188. * @param array $head Array with properties of box title
  189. * @param array $contents Array with properties of box lines
  190. * @param int $nooutput No print, only return string
  191. * @return string
  192. */
  193. public function showBox($head = null, $contents = null, $nooutput = 0)
  194. {
  195. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  196. }
  197. }