dolibarr 24.0.2
comment.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28require "../../main.inc.php";
29require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
30require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
38
47// Load translation files required by the page
48$langs->loadLangs(array('projects', 'companies'));
49
50$id = GETPOSTINT('id');
51$idcomment = GETPOSTINT('idcomment');
52$ref = GETPOST("ref", 'alpha', 1); // task ref
53$objectref = GETPOST("taskref", 'alpha'); // task ref
54$action = GETPOST('action', 'aZ09');
55$confirm = GETPOST('confirm', 'alpha');
56$withproject = GETPOSTINT('withproject');
57$project_ref = GETPOST('project_ref', 'alpha');
58$planned_workload = ((GETPOSTINT('planned_workloadhour') != '' || GETPOSTINT('planned_workloadmin') != '') ? (GETPOSTINT('planned_workloadhour') > 0 ? GETPOSTINT('planned_workloadhour') * 3600 : 0) + (GETPOSTINT('planned_workloadmin') > 0 ? GETPOSTINT('planned_workloadmin') * 60 : 0) : '');
59$mode = GETPOST('mode', 'alpha');
60
61// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
62$hookmanager->initHooks(array('projecttaskcommentcard', 'globalcard'));
63
64$object = new Task($db);
65$extrafields = new ExtraFields($db);
66$projectstatic = new Project($db);
67
68// fetch optionals attributes and labels
69$extrafields->fetch_name_optionals_label($object->table_element);
70
71// Security check
72$socid = 0;
73// Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
74if (!empty($project_ref) && !empty($withproject)) {
75 if ($projectstatic->fetch(0, $project_ref) > 0) {
76 $objectsarray = $object->getTasksArray(null, null, $projectstatic->id, $socid, 0);
77 if (count($objectsarray) > 0) {
78 $id = $objectsarray[0]->id;
79 } else {
80 header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode) ? '' : '&mode='.$mode));
81 }
82 }
83}
84
85
86if ($id > 0 || $ref) {
87 $object->fetch($id, $ref);
88}
89
90restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
91
92
93/*
94 * Actions
95 */
96
97// include comment actions (after security check to prevent IDOR)
98include DOL_DOCUMENT_ROOT.'/core/actions_comments.inc.php';
99
100
101/*
102 * View
103 */
104
105llxHeader('', $langs->trans("CommentPage"), '', '', 0, 0, '', '', '', 'mod-project project-tasks page-task_comment');
106
107$form = new Form($db);
108$formother = new FormOther($db);
109$formfile = new FormFile($db);
110
111if ($id > 0 || !empty($ref)) {
112 if ($object->fetch($id, $ref) > 0) {
113 $result = $object->fetch_optionals();
114
115 $result = $object->fetchComments();
116 if ($result < 0) {
117 setEventMessages($object->error, $object->errors, 'errors');
118 }
119
120 $result = $projectstatic->fetch($object->fk_project);
121 if (!empty($projectstatic->socid)) {
122 $projectstatic->fetch_thirdparty();
123 }
124 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
125 $projectstatic->fetchComments();
126 }
127
128 $object->project = clone $projectstatic;
129
130 $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
131
132 if (!empty($withproject)) {
133 // Tabs for project
134 $tab = 'tasks';
135 $head = project_prepare_head($projectstatic);
136 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
137
138 $param = ($mode == 'mine' ? '&mode=mine' : '');
139
140 // Project card
141
142 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
143
144 $morehtmlref = '<div class="refidno">';
145 // Title
146 $morehtmlref .= $projectstatic->title;
147 // Thirdparty
148 if ($projectstatic->thirdparty->id > 0) {
149 $morehtmlref .= '<br>'.$projectstatic->thirdparty->getNomUrl(1, 'project');
150 }
151 $morehtmlref .= '</div>';
152
153 // Define a complementary filter for search of next/prev ref.
154 if (!$user->hasRight('projet', 'all', 'lire')) {
155 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
156 $projectstatic->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
157 }
158
159 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
160
161 print '<div class="fichecenter">';
162 print '<div class="fichehalfleft">';
163 print '<div class="underbanner clearboth"></div>';
164
165 print '<table class="border centpercent">';
166
167 // Usage
168 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
169 print '<tr><td class="tdtop">';
170 print $langs->trans("Usage");
171 print '</td>';
172 print '<td>';
173 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
174 print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
175 $htmltext = $langs->trans("ProjectFollowOpportunity");
176 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
177 print '<br>';
178 }
179 if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
180 print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
181 $htmltext = $langs->trans("ProjectFollowTasks");
182 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
183 print '<br>';
184 }
185 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
186 print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_bill_time ? ' checked="checked"' : '')).'"> ';
187 $htmltext = $langs->trans("ProjectBillTimeDescription");
188 print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
189 print '<br>';
190 }
191 if (isModEnabled('eventorganization')) {
192 print '<input type="checkbox" disabled name="usage_organize_event"'.(GETPOSTISSET('usage_organize_event') ? (GETPOST('usage_organize_event', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_organize_event ? ' checked="checked"' : '')).'"> ';
193 $htmltext = $langs->trans("EventOrganizationDescriptionLong");
194 print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
195 }
196 print '</td></tr>';
197 }
198
199 // Visibility
200 print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
201 if ($projectstatic->public) {
202 print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
203 print $langs->trans('SharedProject');
204 } else {
205 print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
206 print $langs->trans('PrivateProject');
207 }
208 print '</td></tr>';
209
210 // Opportunities
211 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') && !empty($object->usage_opportunity)) {
212 // Opportunity status
213 print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
214 $code = dol_getIdFromCode($db, $projectstatic->opp_status, 'c_lead_status', 'rowid', 'code');
215 if ($code) {
216 print $langs->trans("OppStatus".$code);
217 }
218 print '</td></tr>';
219
220 // Opportunity percent
221 print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
222 if (strcmp($projectstatic->opp_percent, '')) {
223 print price($projectstatic->opp_percent, 0, $langs, 1, 0).' %';
224 }
225 print '</td></tr>';
226
227 // Opportunity Amount
228 print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
229 if (strcmp($projectstatic->opp_amount, '')) {
230 print price($projectstatic->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
231 if (strcmp($projectstatic->opp_percent, '')) {
232 print ' &nbsp; &nbsp; &nbsp; <span title="'.dol_escape_htmltag($langs->trans('OpportunityWeightedAmount')).'"><span class="opacitymedium">'.$langs->trans("OpportunityWeightedAmountShort").'</span>: <span class="amount">'.price($projectstatic->opp_amount * $projectstatic->opp_percent / 100, 0, $langs, 1, 0, -1, $conf->currency).'</span></span>';
233 }
234 }
235 print '</td></tr>';
236 }
237
238 // Budget
239 print '<tr><td>'.$langs->trans("Budget").'</td><td>';
240 if (strcmp($projectstatic->budget_amount, '')) {
241 print price($projectstatic->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
242 }
243 print '</td></tr>';
244
245 // Date start - end project
246 print '<tr><td>'.$langs->trans("Dates").'</td><td>';
247 $start = dol_print_date($projectstatic->date_start, 'day');
248 print($start ? $start : '?');
249 $end = dol_print_date($projectstatic->date_end, 'day');
250 print ' - ';
251 print($end ? $end : '?');
252 if ($projectstatic->hasDelay()) {
253 print img_warning("Late");
254 }
255 print '</td></tr>';
256
257 // Other attributes
258 $cols = 2;
259 //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
260
261 print '</table>';
262
263 print '</div>';
264 print '<div class="fichehalfright">';
265 print '<div class="underbanner clearboth"></div>';
266
267 print '<table class="border centpercent">';
268
269 // Description
270 print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
271 print nl2br($projectstatic->description);
272 print '</td></tr>';
273
274 // Categories
275 if (isModEnabled('category')) {
276 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
277 print $form->showCategories($projectstatic->id, 'project', 1);
278 print "</td></tr>";
279 }
280
281 print '</table>';
282
283 print '</div>';
284 print '</div>';
285
286 print '<div class="clearboth"></div>';
287
288 print dol_get_fiche_end();
289
290 print '<br>';
291 }
292
293 $head = task_prepare_head($object);
294
295 /*
296 * Fiche tache en mode visu
297 */
298 $param = ($withproject ? '&withproject=1' : '');
299 $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'&restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>' : '';
300
301 print dol_get_fiche_head($head, 'task_comment', $langs->trans("Task"), -1, 'projecttask');
302
303 if ($action == 'delete') {
304 print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".GETPOSTINT("id").'&withproject='.$withproject, $langs->trans("DeleteATask"), $langs->trans("ConfirmDeleteATask"), "confirm_delete");
305 }
306
307 if (!GETPOST('withproject') || empty($projectstatic->id)) {
308 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
309 $object->next_prev_filter = "fk_projet:IN:".$db->sanitize($projectsListId);
310 } else {
311 $object->next_prev_filter = "fk_projet:=:".((int) $projectstatic->id);
312 }
313
314 $morehtmlref = '';
315
316 // Project
317 if (empty($withproject)) {
318 $morehtmlref .= '<div class="refidno">';
319 $morehtmlref .= $langs->trans("Project").': ';
320 $morehtmlref .= $projectstatic->getNomUrl(1);
321 $morehtmlref .= '<br>';
322
323 // Third party
324 $morehtmlref .= $langs->trans("ThirdParty").': ';
325 if (!empty($projectstatic->thirdparty)) {
326 $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
327 }
328 $morehtmlref .= '</div>';
329 }
330
331 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
332
333 print '<div class="fichecenter">';
334
335 print '<div class="underbanner clearboth"></div>';
336 print '<table class="border centpercent">';
337
338 // Nb comments
339 print '<td class="titlefield">'.$langs->trans("NbComments").'</td><td>';
340 print $object->getNbComments();
341 print '</td></tr>';
342
343 // Other attributes
344 $cols = 3;
345 $parameters = array('socid' => $socid);
346 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
347
348 print '</table>';
349
350 print '</div>';
351
352 print dol_get_fiche_end();
353
354
355 // Include comment tpl view
356 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_comment.tpl.php';
357 }
358}
359
360// End of page
361llxFooter();
362$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage standard extra fields.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage projects.
Class to manage tasks.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
task_prepare_head($object)
Prepare array with list of tabs.
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.