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