dolibarr 24.0.0-beta
document.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012 Florian Henry <florian.henry@open-concept.pro>
5 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
8 * Copyright (C) 2025 Incent Maury TimGroup <vmaury@timgroup.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
40require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
45
46// Load translation files required by the page
47$langs->loadLangs(array('projects', 'other'));
48
49$action = GETPOST('action', 'aZ09');
50$confirm = GETPOST('confirm', 'alpha');
51$mine = GETPOST('mode') == 'mine' ? 1 : 0;
52$id = GETPOSTINT('id');
53$ref = GETPOST('ref', 'alpha');
54$withproject = GETPOSTINT('withproject');
55$project_ref = GETPOST('project_ref', 'alpha');
56
57// Get parameters
58$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
59$sortfield = GETPOST('sortfield', 'aZ09comma');
60$sortorder = GETPOST('sortorder', 'aZ09comma');
61$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
62if (empty($page) || $page == -1) {
63 $page = 0;
64} // If $page is not defined, or '' or -1
65$offset = $limit * $page;
66$pageprev = $page - 1;
67$pagenext = $page + 1;
68if (!$sortorder) {
69 $sortorder = "ASC";
70}
71if (!$sortfield) {
72 $sortfield = "name";
73}
74
75$hookmanager->initHooks(array('projecttaskdocument', 'globalcard'));
76
77$object = new Task($db);
78$projectstatic = new Project($db);
79
80$upload_dir = null;
81if ($id > 0 || $ref) {
82 $object->fetch($id, $ref);
83}
84
85// Security check
86$socid = 0;
87
88restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
89
90$permissiontoadd = $user->hasRight('projet', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
91
92
93/*
94 * Actions
95 */
96
97$parameters = array('projectid' => $object->fk_project);
98$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
99if ($reshook < 0) {
100 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
101}
102
103if (empty($reshook)) {
104 // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
105 if (!empty($project_ref) && !empty($withproject)) {
106 if ($projectstatic->fetch(0, $project_ref) > 0) {
107 $tasksarray = $object->getTasksArray(null, null, $projectstatic->id, $socid, 0);
108 if (count($tasksarray) > 0) {
109 $id = $tasksarray[0]->id;
110 $object->fetch($id);
111 } else {
112 header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
113 exit;
114 }
115 }
116 }
117
118 if ($id > 0 || !empty($ref)) {
119 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_TASK') && empty($object->comments)) {
120 $object->fetchComments();
121 }
122 $projectstatic->fetch($object->fk_project);
123 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
124 $projectstatic->fetchComments();
125 }
126
127 if (!empty($projectstatic->socid)) {
128 $projectstatic->fetch_thirdparty();
129 }
130
131 $object->project = clone $projectstatic;
132
133 $upload_dir = $conf->project->multidir_output[$projectstatic->entity].'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
134 }
135
136 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
137}
138
139
140/*
141 * View
142 */
143
144$form = new Form($db);
145
146$title = $object->ref . ' - ' . $langs->trans("Documents");
147if (!empty($withproject)) {
148 $title .= ' | ' . $langs->trans("Project") . (!empty($projectstatic->ref) ? ': '.$projectstatic->ref : '') ;
149}
150$help_url = '';
151
152llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project project-tasks page-task_document');
153
154if ($object->id > 0 && $upload_dir !== null) {
155 $projectstatic->fetch_thirdparty();
156
157 $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
158
159 if (!empty($withproject)) {
160 // Tabs for project
161 $tab = 'tasks';
162 $head = project_prepare_head($projectstatic);
163
164 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
165
166 $param = (isset($mode) && $mode == 'mine' ? '&mode=mine' : '');
167
168 // Project card
169
170 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
171
172 $morehtmlref = '<div class="refidno">';
173 // Title
174 $morehtmlref .= $projectstatic->title;
175 // Thirdparty
176 if (isset($projectstatic->thirdparty->id) && $projectstatic->thirdparty->id > 0) {
177 $morehtmlref .= '<br>'.$projectstatic->thirdparty->getNomUrl(1, 'project');
178 }
179 $morehtmlref .= '</div>';
180
181 // Define a complementary filter for search of next/prev ref.
182 if (!$user->hasRight('projet', 'all', 'lire')) {
183 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
184 $projectstatic->next_prev_filter = "rowid:IN:".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0');
185 }
186
187 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
188
189 print '<div class="fichecenter">';
190 print '<div class="fichehalfleft">';
191 print '<div class="underbanner clearboth"></div>';
192
193 print '<table class="border tableforfield centpercent">';
194
195 // Usage
196 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
197 print '<tr><td class="tdtop">';
198 print $langs->trans("Usage");
199 print '</td>';
200 print '<td>';
201 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
202 print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
203 $htmltext = $langs->trans("ProjectFollowOpportunity");
204 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
205 print '<br>';
206 }
207 if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
208 print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
209 $htmltext = $langs->trans("ProjectFollowTasks");
210 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
211 print '<br>';
212 }
213 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
214 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"' : '')).'"> ';
215 $htmltext = $langs->trans("ProjectBillTimeDescription");
216 print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
217 print '<br>';
218 }
219 if (isModEnabled('eventorganization')) {
220 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"' : '')).'"> ';
221 $htmltext = $langs->trans("EventOrganizationDescriptionLong");
222 print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
223 }
224 print '</td></tr>';
225 }
226
227 // Budget
228 print '<tr><td>'.$langs->trans("Budget").'</td><td>';
229 if (isset($projectstatic->budget_amount) && strcmp($projectstatic->budget_amount, '')) {
230 print price($projectstatic->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
231 }
232 print '</td></tr>';
233
234 // Date start - end project
235 print '<tr><td>'.$langs->trans("Dates").'</td><td>';
236 $start = dol_print_date($projectstatic->date_start, 'day');
237 print($start ? $start : '?');
238 $end = dol_print_date($projectstatic->date_end, 'day');
239 print ' - ';
240 print($end ? $end : '?');
241 if ($projectstatic->hasDelay()) {
242 print img_warning("Late");
243 }
244 print '</td></tr>';
245
246 // Visibility
247 print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
248 if ($projectstatic->public) {
249 print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
250 print $langs->trans('SharedProject');
251 } else {
252 print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
253 print $langs->trans('PrivateProject');
254 }
255 print '</td></tr>';
256
257 // Other attributes
258 $cols = 2;
259 $savobject = $object;
260 $object = $projectstatic;
261 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
262 $object = $savobject;
263
264 print '</table>';
265
266 print '</div>';
267 print '<div class="fichehalfright">';
268 print '<div class="underbanner clearboth"></div>';
269
270 print '<table class="border tableforfield centpercent">';
271
272 // Categories
273 if (isModEnabled('category')) {
274 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
275 print $form->showCategories($projectstatic->id, 'project', 1);
276 print "</td></tr>";
277 }
278
279 // Description
280 print '<tr><td class="titlefield'.($projectstatic->description ? ' noborderbottom' : '').'" colspan="2">'.$langs->trans("Description").'</td></tr>';
281 if ($projectstatic->description) {
282 print '<tr><td class="nottitleforfield" colspan="2">';
283 print '<div class="longmessagecut">';
284 print dolPrintHTML($projectstatic->description);
285 print '</div>';
286 print '</td></tr>';
287 }
288
289 print '</table>';
290
291 print '</div>';
292 print '</div>';
293
294 print '<div class="clearboth"></div>';
295
296 print dol_get_fiche_end();
297
298 print '<br>';
299 }
300
301 $head = task_prepare_head($object);
302 print dol_get_fiche_head($head, 'task_document', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
303
304 // Files list constructor
305 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
306 $totalsize = 0;
307 foreach ($filearray as $key => $file) {
308 $totalsize += $file['size'];
309 }
310
311 $param = (GETPOST('withproject') ? '&withproject=1' : '');
312 $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
313
314 if (!GETPOST('withproject') || empty($projectstatic->id)) {
315 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
316 $object->next_prev_filter = "fk_projet:IN:".$db->sanitize($projectsListId);
317 } else {
318 $object->next_prev_filter = "fk_projet:=:".((int) $projectstatic->id);
319 }
320
321 $morehtmlref = '';
322
323 // Project
324 if (empty($withproject)) {
325 $morehtmlref .= '<div class="refidno">';
326 $morehtmlref .= $langs->trans("Project").': ';
327 $morehtmlref .= $projectstatic->getNomUrl(1);
328 $morehtmlref .= '<br>';
329
330 // Third party
331 $morehtmlref .= $langs->trans("ThirdParty").': ';
332 if (is_object($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
333 $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
334 }
335 $morehtmlref .= '</div>';
336 }
337
338 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
339
340 print '<div class="fichecenter">';
341
342 print '<div class="underbanner clearboth"></div>';
343 print '<table class="border tableforfield centpercent">';
344
345 // Files infos
346 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
347 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
348
349 print "</table>\n";
350
351 print '</div>';
352
353 print dol_get_fiche_end();
354
355 print '<br>';
356
357 $param = '';
358 if ($withproject) {
359 $param .= '&withproject=1';
360 }
361 $modulepart = 'project_task';
362 $permissiontoadd = $user->hasRight('projet', 'creer');
363 $permtoedit = $user->hasRight('projet', 'creer');
364 $relativepathwithnofile = dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/';
365 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
366} else {
367 header('Location: index.php');
368 exit;
369}
370
371// End of page
372llxFooter();
373$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 generation of HTML components Only common components must be 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_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:64
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.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintHTML($s, $allowiframe=0, $moreallowedtags=array())
Return a string (that can be on several lines) ready to be output on a HTML page.
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.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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)
Return value of a param into GET or POST supervariable.
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, $mode=0)
Check permissions of a user to show a page and an object.