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