dolibarr 21.0.0-beta
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";
40 public $boxlabel;
41 public $depends = array("projet");
42
43 public $enabled = 1;
44
51 public function __construct($db, $param = '')
52 {
53 global $conf, $user, $langs;
54
55 // Load translation files required by the page
56 $langs->loadLangs(array('boxes', 'projects'));
57
58 $this->boxlabel = "Tasks";
59 $this->db = $db;
60
61 $this->hidden = (getDolGlobalString('PROJECT_HIDE_TASKS') || !$user->hasRight('projet', 'lire'));
62 }
63
70 public function loadBox($max = 5)
71 {
72 global $conf, $user, $langs;
73
74 $this->max = $max;
75 include_once DOL_DOCUMENT_ROOT."/projet/class/task.class.php";
76 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
77 require_once DOL_DOCUMENT_ROOT."/core/lib/project.lib.php";
78 $projectstatic = new Project($this->db);
79 $taskstatic = new Task($this->db);
80 $form = new Form($this->db);
81 $cookie_name = 'DOLUSER_boxfilter_task';
82 $boxcontent = '';
83 $socid = $user->socid;
84
85 $textHead = $langs->trans("CurentlyOpenedTasks");
86
87 $filterValue = 'all';
88 if (in_array(GETPOST($cookie_name), array('all', 'im_project_contact', 'im_task_contact'))) {
89 $filterValue = GETPOST($cookie_name);
90 } elseif (!empty($_COOKIE[$cookie_name])) {
91 $filterValue = preg_replace('/[^a-z_]/', '', $_COOKIE[$cookie_name]); // Clean cookie from evil data
92 }
93
94 if ($filterValue == 'im_task_contact') {
95 $textHead .= ' : '.$langs->trans("WhichIamLinkedTo");
96 } elseif ($filterValue == 'im_project_contact') {
97 $textHead .= ' : '.$langs->trans("WhichIamLinkedToProject");
98 }
99
100
101 $this->info_box_head = array(
102 'text' => $textHead,
103 'limit' => dol_strlen($textHead),
104 'sublink' => '',
105 'subtext' => $langs->trans("Filter"),
106 'subpicto' => 'filter.png',
107 'subclass' => 'linkobject boxfilter',
108 'target' => 'none' // Set '' to get target="_blank"
109 );
110
111 // list the summary of the orders
112 if ($user->hasRight('projet', 'lire')) {
113 $boxcontent .= '<div id="ancor-idfilter'.$this->boxcode.'" style="display: block; position: absolute; margin-top: -100px"></div>'."\n";
114 $boxcontent .= '<div id="idfilter'.$this->boxcode.'" class="center" >'."\n";
115 $boxcontent .= '<form class="flat " method="POST" action="'.$_SERVER["PHP_SELF"].'#ancor-idfilter'.$this->boxcode.'">'."\n";
116 $boxcontent .= '<input type="hidden" name="token" value="'.newToken().'">'."\n";
117 $selectArray = array('all' => $langs->trans("NoFilter"), 'im_task_contact' => $langs->trans("WhichIamLinkedTo"), 'im_project_contact' => $langs->trans("WhichIamLinkedToProject"));
118 $boxcontent .= $form->selectArray($cookie_name, $selectArray, $filterValue);
119 $boxcontent .= '<button type="submit" class="button buttongen button-save">'.$langs->trans("Refresh").'</button>';
120 $boxcontent .= '</form>'."\n";
121 $boxcontent .= '</div>'."\n";
122 if (!empty($conf->use_javascript_ajax)) {
123 $boxcontent .= '<script nonce="'.getNonce().'" type="text/javascript">
124 jQuery(document).ready(function() {
125 jQuery("#idsubimg'.$this->boxcode.'").click(function() {
126 jQuery(".showiffilter'.$this->boxcode.'").toggle();
127 });
128 });
129 </script>';
130 // set cookie by js
131 $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>';
132 }
133 $this->info_box_contents[0][] = array(
134 'tr' => 'class="nohover showiffilter'.$this->boxcode.' hideobject"',
135 'td' => 'class="nohover"',
136 'textnoformat' => $boxcontent,
137 );
138
139
140 // Get list of project id allowed to user (in a string list separated by coma)
141 $projectsListId = '';
142 if (!$user->hasRight('projet', 'all', 'lire')) {
143 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1, $socid);
144 }
145
146 $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";
147 $sql .= ", p.rowid project_id, p.ref project_ref, p.title project_title, p.fk_statut";
148
149 $sql .= " FROM ".MAIN_DB_PREFIX."projet_task as pt";
150 $sql .= " JOIN ".MAIN_DB_PREFIX."projet as p ON (pt.fk_projet = p.rowid)";
151
152 if ($filterValue === 'im_task_contact') {
153 $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = pt.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_task' AND tc.source = 'internal' )";
155 } elseif ($filterValue === 'im_project_contact') {
156 $sql .= " JOIN ".MAIN_DB_PREFIX."element_contact as ec ON (ec.element_id = p.rowid AND ec.fk_socpeople = ".((int) $user->id).")";
157 $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' )";
158 }
159
160 $sql .= " WHERE ";
161 $sql .= " pt.entity = ".$conf->entity;
162 $sql .= " AND p.fk_statut = ".Project::STATUS_VALIDATED;
163 $sql .= " AND (pt.progress < 100 OR pt.progress IS NULL ) "; // 100% is done and not displayed
164 $sql .= " AND p.usage_task = 1 ";
165 if (!$user->hasRight('projet', 'all', 'lire')) {
166 $sql .= " AND p.rowid IN (".$this->db->sanitize($projectsListId).")"; // public and assigned to, or restricted to company for external users
167 }
168
169 $sql .= " ORDER BY pt.datee ASC, pt.dateo ASC";
170 $sql .= $this->db->plimit($max, 0);
171
172 $result = $this->db->query($sql);
173 $i = 1;
174 if ($result) {
175 $num = $this->db->num_rows($result);
176 while ($objp = $this->db->fetch_object($result)) {
177 $taskstatic->id = $objp->rowid;
178 $taskstatic->ref = $objp->ref;
179 $taskstatic->label = $objp->label;
180 $taskstatic->progress = $objp->progress;
181 $taskstatic->status = $objp->fk_statut;
182 $taskstatic->date_end = $this->db->jdate($objp->datee);
183 $taskstatic->planned_workload = $objp->planned_workload;
184 $taskstatic->duration_effective = $objp->duration_effective;
185
186 $projectstatic->id = $objp->project_id;
187 $projectstatic->ref = $objp->project_ref;
188 $projectstatic->title = $objp->project_title;
189
190 $label = $projectstatic->getNomUrl(1).' &nbsp; '.$taskstatic->getNomUrl(1).' '.dol_htmlentities($taskstatic->label);
191
192 $boxcontent = getTaskProgressView($taskstatic, $label, true, false, false);
193
194 $this->info_box_contents[$i][] = array(
195 'td' => '',
196 'text' => $boxcontent,
197 );
198 $i++;
199 }
200 } else {
201 dol_print_error($this->db);
202 }
203 }
204 }
205
206
207
216 public function showBox($head = null, $contents = null, $nooutput = 0)
217 {
218 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
219 }
220}
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:70
__construct($db, $param='')
Constructor.
Definition box_task.php:51
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition box_task.php:216
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
getTaskProgressView($task, $label=true, $progressNumber=true, $hideOnProgressNull=false, $spaced=false)