dolibarr 21.0.0-alpha
box_task.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012-2018 Charlene BENKE <charlie@patas-monkey.com>
3 * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
26include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
27require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
28
29
33class box_task extends ModeleBoxes
34{
35 public $boxcode = "projettask";
36 public $boximg = "object_projecttask";
37 public $boxlabel;
38 public $depends = array("projet");
39
40 public $enabled = 1;
41
48 public function __construct($db, $param = '')
49 {
50 global $conf, $user, $langs;
51
52 // Load translation files required by the page
53 $langs->loadLangs(array('boxes', 'projects'));
54
55 $this->boxlabel = "Tasks";
56 $this->db = $db;
57
58 $this->hidden = (getDolGlobalString('PROJECT_HIDE_TASKS') || !$user->hasRight('projet', 'lire'));
59 }
60
67 public function loadBox($max = 5)
68 {
69 global $conf, $user, $langs;
70
71 $this->max = $max;
72 include_once DOL_DOCUMENT_ROOT."/projet/class/task.class.php";
73 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
74 require_once DOL_DOCUMENT_ROOT."/core/lib/project.lib.php";
75 $projectstatic = new Project($this->db);
76 $taskstatic = new Task($this->db);
77 $form = new Form($this->db);
78 $cookie_name = 'DOLUSER_boxfilter_task';
79 $boxcontent = '';
80 $socid = $user->socid;
81
82 $textHead = $langs->trans("CurentlyOpenedTasks");
83
84 $filterValue = 'all';
85 if (in_array(GETPOST($cookie_name), array('all', 'im_project_contact', 'im_task_contact'))) {
86 $filterValue = GETPOST($cookie_name);
87 } elseif (!empty($_COOKIE[$cookie_name])) {
88 $filterValue = preg_replace('/[^a-z_]/', '', $_COOKIE[$cookie_name]); // Clean cookie from evil data
89 }
90
91 if ($filterValue == 'im_task_contact') {
92 $textHead .= ' : '.$langs->trans("WhichIamLinkedTo");
93 } elseif ($filterValue == 'im_project_contact') {
94 $textHead .= ' : '.$langs->trans("WhichIamLinkedToProject");
95 }
96
97
98 $this->info_box_head = array(
99 'text' => $textHead,
100 'limit' => dol_strlen($textHead),
101 'sublink' => '',
102 'subtext' => $langs->trans("Filter"),
103 'subpicto' => 'filter.png',
104 'subclass' => 'linkobject boxfilter',
105 'target' => 'none' // Set '' to get target="_blank"
106 );
107
108 // list the summary of the orders
109 if ($user->hasRight('projet', 'lire')) {
110 $boxcontent .= '<div id="ancor-idfilter'.$this->boxcode.'" style="display: block; position: absolute; margin-top: -100px"></div>'."\n";
111 $boxcontent .= '<div id="idfilter'.$this->boxcode.'" class="center" >'."\n";
112 $boxcontent .= '<form class="flat " method="POST" action="'.$_SERVER["PHP_SELF"].'#ancor-idfilter'.$this->boxcode.'">'."\n";
113 $boxcontent .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
114 $selectArray = array('all' => $langs->trans("NoFilter"), 'im_task_contact' => $langs->trans("WhichIamLinkedTo"), 'im_project_contact' => $langs->trans("WhichIamLinkedToProject"));
115 $boxcontent .= $form->selectArray($cookie_name, $selectArray, $filterValue);
116 $boxcontent .= '<button type="submit" class="button buttongen button-save">'.$langs->trans("Refresh").'</button>';
117 $boxcontent .= '</form>'."\n";
118 $boxcontent .= '</div>'."\n";
119 if (!empty($conf->use_javascript_ajax)) {
120 $boxcontent .= '<script nonce="'.getNonce().'" type="text/javascript">
121 jQuery(document).ready(function() {
122 jQuery("#idsubimg'.$this->boxcode.'").click(function() {
123 jQuery(".showiffilter'.$this->boxcode.'").toggle();
124 });
125 });
126 </script>';
127 // set cookie by js
128 $boxcontent .= '<script nonce="'.getNonce().'">date = new Date(); date.setTime(date.getTime()+(30*86400000)); document.cookie = "'.$cookie_name.'='.$filterValue.'; expires= " + date.toGMTString() + "; path=/ ; SameSite=Lax"; </script>';
129 }
130 $this->info_box_contents[0][] = array(
131 'tr' => 'class="nohover showiffilter'.$this->boxcode.' hideobject"',
132 'td' => 'class="nohover"',
133 'textnoformat' => $boxcontent,
134 );
135
136
137 // Get list of project id allowed to user (in a string list separated by coma)
138 $projectsListId = '';
139 if (!$user->hasRight('projet', 'all', 'lire')) {
140 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
141 }
142
143 $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";
144 $sql .= ", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
145
146 $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
147 $sql .= " JOIN ".MAIN_DB_PREFIX."projet as p ON (pt.fk_projet = p.rowid)";
148
149 if ($filterValue === 'im_task_contact') {
150 $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = pt.rowid AND ec.fk_socpeople = ".((int) $user->id).")";
151 $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' )";
152 } elseif ($filterValue === 'im_project_contact') {
153 $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $user->id).")";
154 $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' )";
155 }
156
157 $sql .= " WHERE ";
158 $sql .= " pt.entity = ".$conf->entity;
159 $sql .= " AND p.fk_statut = ".Project::STATUS_VALIDATED;
160 $sql .= " AND (pt.progress < 100 OR pt.progress IS NULL ) "; // 100% is done and not displayed
161 $sql .= " AND p.usage_task = 1 ";
162 if (!$user->hasRight('projet', 'all', 'lire')) {
163 $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
164 }
165
166 $sql .= " ORDER BY pt.datee ASC, pt.dateo ASC";
167 $sql .= $this->db->plimit($max, 0);
168
169 $result = $this->db->query($sql);
170 $i = 1;
171 if ($result) {
172 $num = $this->db->num_rows($result);
173 while ($objp = $this->db->fetch_object($result)) {
174 $taskstatic->id = $objp->rowid;
175 $taskstatic->ref = $objp->ref;
176 $taskstatic->label = $objp->label;
177 $taskstatic->progress = $objp->progress;
178 $taskstatic->status = $objp->fk_statut;
179 $taskstatic->date_end = $this->db->jdate($objp->datee);
180 $taskstatic->planned_workload = $objp->planned_workload;
181 $taskstatic->duration_effective = $objp->duration_effective;
182
183 $projectstatic->id = $objp->project_id;
184 $projectstatic->ref = $objp->project_ref;
185 $projectstatic->title = $objp->project_title;
186
187 $label = $projectstatic->getNomUrl(1).' &nbsp; '.$taskstatic->getNomUrl(1).' '.dol_htmlentities($taskstatic->label);
188
189 $boxcontent = getTaskProgressView($taskstatic, $label, true, false, false);
190
191 $this->info_box_contents[$i][] = array(
192 'td' => '',
193 'text' => $boxcontent,
194 );
195 $i++;
196 }
197 } else {
198 dol_print_error($this->db);
199 }
200 }
201 }
202
203
204
213 public function showBox($head = null, $contents = null, $nooutput = 0)
214 {
215 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
216 }
217}
Class to manage generation of HTML components Only common components must be here.
Class ModeleBoxes.
Class to manage projects.
Class to manage tasks.
Class to manage the box to show last task.
Definition box_task.php:34
loadBox($max=5)
Load data for box to show them later.
Definition box_task.php:67
__construct($db, $param='')
Constructor.
Definition box_task.php:48
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition box_task.php:213
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_htmlentities($string, $flags=ENT_QUOTES|ENT_SUBSTITUTE, $encoding='UTF-8', $double_encode=false)
Replace htmlentities functions.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getTaskProgressView($task, $label=true, $progressNumber=true, $hideOnProgressNull=false, $spaced=false)