dolibarr 21.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 Frédéric France <frederic.france@free.fr>
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
28// Load Dolibarr environment
29require '../../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
31require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
32require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array('projects', 'other'));
47
48$action = GETPOST('action', 'aZ09');
49$confirm = GETPOST('confirm', 'alpha');
50$mine = GETPOST('mode') == 'mine' ? 1 : 0;
51//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
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$object = new Task($db);
76$projectstatic = new Project($db);
77
78if ($id > 0 || $ref) {
79 $object->fetch($id, $ref);
80}
81
82// Security check
83$socid = 0;
84
85restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
86
87$permissiontoadd = $user->hasRight('projet', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
88
89
90/*
91 * Actions
92 */
93
94// Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
95if (!empty($project_ref) && !empty($withproject)) {
96 if ($projectstatic->fetch(0, $project_ref) > 0) {
97 $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
98 if (count($tasksarray) > 0) {
99 $id = $tasksarray[0]->id;
100 $object->fetch($id);
101 } else {
102 header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
103 exit;
104 }
105 }
106}
107
108if ($id > 0 || !empty($ref)) {
109 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_TASK') && method_exists($object, 'fetchComments') && empty($object->comments)) {
110 $object->fetchComments();
111 }
112 $projectstatic->fetch($object->fk_project);
113 if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
114 $projectstatic->fetchComments();
115 }
116
117 if (!empty($projectstatic->socid)) {
118 $projectstatic->fetch_thirdparty();
119 }
120
121 $object->project = clone $projectstatic;
122
123 $upload_dir = $conf->project->multidir_output[$projectstatic->entity].'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
124}
125
126include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
127
128
129/*
130 * View
131 */
132$form = new Form($db);
133
134$title = $object->ref . ' - ' . $langs->trans("Documents");
135if (!empty($withproject)) {
136 $title .= ' | ' . $langs->trans("Project") . (!empty($projectstatic->ref) ? ': '.$projectstatic->ref : '') ;
137}
138$help_url = '';
139
140llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-project project-tasks page-task_document');
141
142if ($object->id > 0) {
143 $projectstatic->fetch_thirdparty();
144
145 $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
146
147 if (!empty($withproject)) {
148 // Tabs for project
149 $tab = 'tasks';
150 $head = project_prepare_head($projectstatic);
151
152 print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
153
154 $param = (isset($mode) && $mode == 'mine' ? '&mode=mine' : '');
155
156 // Project card
157
158 $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
159
160 $morehtmlref = '<div class="refidno">';
161 // Title
162 $morehtmlref .= $projectstatic->title;
163 // Thirdparty
164 if (isset($projectstatic->thirdparty->id) && $projectstatic->thirdparty->id > 0) {
165 $morehtmlref .= '<br>'.$projectstatic->thirdparty->getNomUrl(1, 'project');
166 }
167 $morehtmlref .= '</div>';
168
169 // Define a complementary filter for search of next/prev ref.
170 if (!$user->hasRight('projet', 'all', 'lire')) {
171 $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
172 $projectstatic->next_prev_filter = "rowid:IN:(".$db->sanitize(count($objectsListId) ? implode(',', array_keys($objectsListId)) : '0').")";
173 }
174
175 dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
176
177 print '<div class="fichecenter">';
178 print '<div class="fichehalfleft">';
179 print '<div class="underbanner clearboth"></div>';
180
181 print '<table class="border tableforfield centpercent">';
182
183 // Usage
184 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES') || !getDolGlobalString('PROJECT_HIDE_TASKS') || isModEnabled('eventorganization')) {
185 print '<tr><td class="tdtop">';
186 print $langs->trans("Usage");
187 print '</td>';
188 print '<td>';
189 if (getDolGlobalString('PROJECT_USE_OPPORTUNITIES')) {
190 print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
191 $htmltext = $langs->trans("ProjectFollowOpportunity");
192 print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
193 print '<br>';
194 }
195 if (!getDolGlobalString('PROJECT_HIDE_TASKS')) {
196 print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
197 $htmltext = $langs->trans("ProjectFollowTasks");
198 print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
199 print '<br>';
200 }
201 if (!getDolGlobalString('PROJECT_HIDE_TASKS') && getDolGlobalString('PROJECT_BILL_TIME_SPENT')) {
202 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"' : '')).'"> ';
203 $htmltext = $langs->trans("ProjectBillTimeDescription");
204 print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
205 print '<br>';
206 }
207 if (isModEnabled('eventorganization')) {
208 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"' : '')).'"> ';
209 $htmltext = $langs->trans("EventOrganizationDescriptionLong");
210 print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
211 }
212 print '</td></tr>';
213 }
214
215 // Visibility
216 print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
217 if ($projectstatic->public) {
218 print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
219 print $langs->trans('SharedProject');
220 } else {
221 print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
222 print $langs->trans('PrivateProject');
223 }
224 print '</td></tr>';
225
226 // Budget
227 print '<tr><td>'.$langs->trans("Budget").'</td><td>';
228 if (isset($projectstatic->budget_amount) && strcmp($projectstatic->budget_amount, '')) {
229 print price($projectstatic->budget_amount, 0, $langs, 1, 0, 0, $conf->currency);
230 }
231 print '</td></tr>';
232
233 // Date start - end project
234 print '<tr><td>'.$langs->trans("Dates").'</td><td>';
235 $start = dol_print_date($projectstatic->date_start, 'day');
236 print($start ? $start : '?');
237 $end = dol_print_date($projectstatic->date_end, 'day');
238 print ' - ';
239 print($end ? $end : '?');
240 if ($projectstatic->hasDelay()) {
241 print img_warning("Late");
242 }
243 print '</td></tr>';
244
245 // Other attributes
246 $cols = 2;
247 //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
248
249 print '</table>';
250
251 print '</div>';
252 print '<div class="fichehalfright">';
253 print '<div class="underbanner clearboth"></div>';
254
255 print '<table class="border tableforfield centpercent">';
256
257 // Description
258 print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
259 print nl2br($projectstatic->description);
260 print '</td></tr>';
261
262 // Categories
263 if (isModEnabled('category')) {
264 print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
265 print $form->showCategories($projectstatic->id, 'project', 1);
266 print "</td></tr>";
267 }
268
269 print '</table>';
270
271 print '</div>';
272 print '</div>';
273
274 print '<div class="clearboth"></div>';
275
276 print dol_get_fiche_end();
277
278 print '<br>';
279 }
280
281 $head = task_prepare_head($object);
282 print dol_get_fiche_head($head, 'task_document', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
283
284 // Files list constructor
285 $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ? SORT_DESC : SORT_ASC), 1);
286 $totalsize = 0;
287 foreach ($filearray as $key => $file) {
288 $totalsize += $file['size'];
289 }
290
291 $param = (GETPOST('withproject') ? '&withproject=1' : '');
292 $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
293
294 if (!GETPOST('withproject') || empty($projectstatic->id)) {
295 $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
296 $object->next_prev_filter = "fk_projet:IN:(".$db->sanitize($projectsListId).")";
297 } else {
298 $object->next_prev_filter = "fk_projet:=:".((int) $projectstatic->id);
299 }
300
301 $morehtmlref = '';
302
303 // Project
304 if (empty($withproject)) {
305 $morehtmlref .= '<div class="refidno">';
306 $morehtmlref .= $langs->trans("Project").': ';
307 $morehtmlref .= $projectstatic->getNomUrl(1);
308 $morehtmlref .= '<br>';
309
310 // Third party
311 $morehtmlref .= $langs->trans("ThirdParty").': ';
312 if (is_object($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
313 $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
314 }
315 $morehtmlref .= '</div>';
316 }
317
318 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
319
320 print '<div class="fichecenter">';
321
322 print '<div class="underbanner clearboth"></div>';
323 print '<table class="border tableforfield centpercent">';
324
325 // Files infos
326 print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
327 print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
328
329 print "</table>\n";
330
331 print '</div>';
332
333 print dol_get_fiche_end();
334
335 print '<br>';
336
337 $param = '';
338 if ($withproject) {
339 $param .= '&withproject=1';
340 }
341 $modulepart = 'project_task';
342 $permissiontoadd = $user->hasRight('projet', 'creer');
343 $permtoedit = $user->hasRight('projet', 'creer');
344 $relativepathwithnofile = dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/';
345 include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
346} else {
347 header('Location: index.php');
348 exit;
349}
350
351// End of page
352llxFooter();
353$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
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:71
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage tasks.
llxFooter()
Footer empty.
Definition document.php:107
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_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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)
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.
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)
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.