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