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