box_task.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. /* Copyright (C) 2012-2018 Charlene BENKE <charlie@patas-monkey.com>
  3. * Copyright (C) 2015-2021 Frederic France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/core/boxes/box_task.php
  20. * \ingroup Projet
  21. * \brief Module to Task activity of the current year
  22. */
  23. include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  24. require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
  25. /**
  26. * Class to manage the box to show last task
  27. */
  28. class box_task extends ModeleBoxes
  29. {
  30. public $boxcode = "projettask";
  31. public $boximg = "object_projecttask";
  32. public $boxlabel;
  33. public $depends = array("projet");
  34. /**
  35. * @var DoliDB Database handler.
  36. */
  37. public $db;
  38. public $param;
  39. public $enabled = 1; // enable because fixed ;-).
  40. public $info_box_head = array();
  41. public $info_box_contents = array();
  42. /**
  43. * Constructor
  44. *
  45. * @param DoliDB $db Database handler
  46. * @param string $param More parameters
  47. */
  48. public function __construct($db, $param = '')
  49. {
  50. global $conf, $user, $langs;
  51. // Load translation files required by the page
  52. $langs->loadLangs(array('boxes', 'projects'));
  53. $this->boxlabel = "Tasks";
  54. $this->db = $db;
  55. $this->hidden = (!empty($conf->global->PROJECT_HIDE_TASKS) || empty($user->rights->projet->lire));
  56. }
  57. /**
  58. * Load data for box to show them later
  59. *
  60. * @param int $max Maximum number of records to load
  61. * @return void
  62. */
  63. public function loadBox($max = 5)
  64. {
  65. global $conf, $user, $langs;
  66. $this->max = $max;
  67. include_once DOL_DOCUMENT_ROOT."/projet/class/task.class.php";
  68. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  69. require_once DOL_DOCUMENT_ROOT."/core/lib/project.lib.php";
  70. $projectstatic = new Project($this->db);
  71. $taskstatic = new Task($this->db);
  72. $form = new Form($this->db);
  73. $cookie_name = 'DOLUSERCOOKIE_boxfilter_task';
  74. $boxcontent = '';
  75. $socid = $user->socid;
  76. $textHead = $langs->trans("CurentlyOpenedTasks");
  77. $filterValue = 'all';
  78. if (in_array(GETPOST($cookie_name), array('all', 'im_project_contact', 'im_task_contact'))) {
  79. $filterValue = GETPOST($cookie_name);
  80. } elseif (!empty($_COOKIE[$cookie_name])) {
  81. $filterValue = preg_replace('/[^a-z_]/', '', $_COOKIE[$cookie_name]); // Clean cookie from evil data
  82. }
  83. if ($filterValue == 'im_task_contact') {
  84. $textHead .= ' : '.$langs->trans("WhichIamLinkedTo");
  85. } elseif ($filterValue == 'im_project_contact') {
  86. $textHead .= ' : '.$langs->trans("WhichIamLinkedToProject");
  87. }
  88. $this->info_box_head = array(
  89. 'text' => $textHead,
  90. 'limit'=> dol_strlen($textHead),
  91. 'sublink'=>'',
  92. 'subtext'=>$langs->trans("Filter"),
  93. 'subpicto'=>'filter.png',
  94. 'subclass'=>'linkobject boxfilter',
  95. 'target'=>'none' // Set '' to get target="_blank"
  96. );
  97. // list the summary of the orders
  98. if ($user->rights->projet->lire) {
  99. $boxcontent .= '<div id="ancor-idfilter'.$this->boxcode.'" style="display: block; position: absolute; margin-top: -100px"></div>'."\n";
  100. $boxcontent .= '<div id="idfilter'.$this->boxcode.'" class="center" >'."\n";
  101. $boxcontent .= '<form class="flat " method="POST" action="'.$_SERVER["PHP_SELF"].'#ancor-idfilter'.$this->boxcode.'">'."\n";
  102. $boxcontent .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
  103. $selectArray = array('all' => $langs->trans("NoFilter"), 'im_task_contact' => $langs->trans("WhichIamLinkedTo"), 'im_project_contact' => $langs->trans("WhichIamLinkedToProject"));
  104. $boxcontent .= $form->selectArray($cookie_name, $selectArray, $filterValue);
  105. $boxcontent .= '<button type="submit" class="button buttongen button-save">'.$langs->trans("Refresh").'</button>';
  106. $boxcontent .= '</form>'."\n";
  107. $boxcontent .= '</div>'."\n";
  108. if (!empty($conf->use_javascript_ajax)) {
  109. $boxcontent .= '<script type="text/javascript">
  110. jQuery(document).ready(function() {
  111. jQuery("#idsubimg'.$this->boxcode.'").click(function() {
  112. jQuery(".showiffilter'.$this->boxcode.'").toggle();
  113. });
  114. });
  115. </script>';
  116. // set cookie by js
  117. $boxcontent .= '<script>date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "'.$cookie_name.'='.$filterValue.'; expires= " + date.toGMTString() + "; path=/ "; </script>';
  118. }
  119. $this->info_box_contents[0][] = array(
  120. 'tr' => 'class="nohover showiffilter'.$this->boxcode.' hideobject"',
  121. 'td' => 'class="nohover"',
  122. 'textnoformat' => $boxcontent,
  123. );
  124. // Get list of project id allowed to user (in a string list separated by coma)
  125. $projectsListId = '';
  126. if (empty($user->rights->projet->all->lire)) {
  127. $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
  128. }
  129. $sql = "SELECT pt.rowid, pt.ref, pt.fk_projet, pt.fk_task_parent, pt.datec, pt.dateo, pt.datee, pt.datev, pt.label, pt.description, pt.duration_effective, pt.planned_workload, pt.progress";
  130. $sql .= ", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
  131. $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
  132. $sql .= " JOIN ".MAIN_DB_PREFIX."projet as p ON (pt.fk_projet = p.rowid)";
  133. if ($filterValue === 'im_task_contact') {
  134. $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = pt.rowid AND ec.fk_socpeople = ".((int) $user->id).")";
  135. $sql .= " JOIN ".MAIN_DB_PREFIX."c_type_contact as tc ON (ec.fk_c_type_contact = tc.rowid AND tc.element = 'project_task' AND tc.source = 'internal' )";
  136. } elseif ($filterValue === 'im_project_contact') {
  137. $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $user->id).")";
  138. $sql .= " JOIN ".MAIN_DB_PREFIX."c_type_contact as tc ON (ec.fk_c_type_contact = tc.rowid AND tc.element = 'project' AND tc.source = 'internal' )";
  139. }
  140. $sql .= " WHERE ";
  141. $sql .= " pt.entity = ".$conf->entity;
  142. $sql .= " AND p.fk_statut = ".Project::STATUS_VALIDATED;
  143. $sql .= " AND (pt.progress < 100 OR pt.progress IS NULL ) "; // 100% is done and not displayed
  144. $sql .= " AND p.usage_task = 1 ";
  145. if (empty($user->rights->projet->all->lire)) {
  146. $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
  147. }
  148. $sql .= " ORDER BY pt.datee ASC, pt.dateo ASC";
  149. $sql .= $this->db->plimit($max, 0);
  150. $result = $this->db->query($sql);
  151. $i = 1;
  152. if ($result) {
  153. $num = $this->db->num_rows($result);
  154. while ($objp = $this->db->fetch_object($result)) {
  155. $taskstatic->id = $objp->rowid;
  156. $taskstatic->ref = $objp->ref;
  157. $taskstatic->label = $objp->label;
  158. $taskstatic->progress = $objp->progress;
  159. $taskstatic->fk_statut = $objp->fk_statut;
  160. $taskstatic->date_end = $this->db->jdate($objp->datee);
  161. $taskstatic->planned_workload = $objp->planned_workload;
  162. $taskstatic->duration_effective = $objp->duration_effective;
  163. $projectstatic->id = $objp->project_id;
  164. $projectstatic->ref = $objp->project_ref;
  165. $projectstatic->title = $objp->project_title;
  166. $label = $projectstatic->getNomUrl(1).' &nbsp; '.$taskstatic->getNomUrl(1).' '.dol_htmlentities($taskstatic->label);
  167. $boxcontent = getTaskProgressView($taskstatic, $label, true, false, false);
  168. $this->info_box_contents[$i][] = array(
  169. 'td' => '',
  170. 'text' => $boxcontent,
  171. );
  172. $i++;
  173. }
  174. } else {
  175. dol_print_error($this->db);
  176. }
  177. }
  178. }
  179. /**
  180. * Method to show box
  181. *
  182. * @param array $head Array with properties of box title
  183. * @param array $contents Array with properties of box lines
  184. * @param int $nooutput No print, only return string
  185. * @return string
  186. */
  187. public function showBox($head = null, $contents = null, $nooutput = 0)
  188. {
  189. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  190. }
  191. }