dolibarr  16.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  *
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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('projects', 'other'));
37 
38 $action = GETPOST('action', 'aZ09');
39 $confirm = GETPOST('confirm', 'alpha');
40 $mine = GETPOST('mode') == 'mine' ? 1 : 0;
41 //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
42 $id = GETPOST('id', 'int');
43 $ref = GETPOST('ref', 'alpha');
44 $withproject = GETPOST('withproject', 'int');
45 $project_ref = GETPOST('project_ref', 'alpha');
46 
47 // Get parameters
48 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortorder) {
59  $sortorder = "ASC";
60 }
61 if (!$sortfield) {
62  $sortfield = "name";
63 }
64 
65 $object = new Task($db);
66 $projectstatic = new Project($db);
67 
68 if ($id > 0 || $ref) {
69  $object->fetch($id, $ref);
70 }
71 
72 // Security check
73 $socid = 0;
74 
75 restrictedArea($user, 'projet', $object->fk_project, 'projet&project');
76 
77 $permissiontoadd = $user->rights->projet->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_linkedfiles.inc.php
78 
79 
80 /*
81  * Actions
82  */
83 
84 // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
85 if (!empty($project_ref) && !empty($withproject)) {
86  if ($projectstatic->fetch(0, $project_ref) > 0) {
87  $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
88  if (count($tasksarray) > 0) {
89  $id = $tasksarray[0]->id;
90  $object->fetch($id);
91  } else {
92  header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
93  exit;
94  }
95  }
96 }
97 
98 if ($id > 0 || !empty($ref)) {
99  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) {
100  $object->fetchComments();
101  }
102  $projectstatic->fetch($object->fk_project);
103  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) {
104  $projectstatic->fetchComments();
105  }
106 
107  if (!empty($projectstatic->socid)) {
108  $projectstatic->fetch_thirdparty();
109  }
110 
111  $object->project = clone $projectstatic;
112 
113  $upload_dir = $conf->project->multidir_output[$projectstatic->entity].'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
114 }
115 
116 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
117 
118 
119 /*
120  * View
121  */
122 
123 $form = new Form($db);
124 
125 llxHeader('', $langs->trans('Task'));
126 
127 if ($object->id > 0) {
128  $projectstatic->fetch_thirdparty();
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 
137  print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
138 
139  $param = ($mode == 'mine' ? '&mode=mine' : '');
140 
141  // Project card
142 
143  $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
144 
145  $morehtmlref = '<div class="refidno">';
146  // Title
147  $morehtmlref .= $projectstatic->title;
148  // Thirdparty
149  if ($projectstatic->thirdparty->id > 0) {
150  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
151  }
152  $morehtmlref .= '</div>';
153 
154  // Define a complementary filter for search of next/prev ref.
155  if (empty($user->rights->projet->all->lire)) {
156  $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
157  $projectstatic->next_prev_filter = " rowid IN (".$db->sanitize(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
158  }
159 
160  dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
161 
162  print '<div class="fichecenter">';
163  print '<div class="fichehalfleft">';
164  print '<div class="underbanner clearboth"></div>';
165 
166  print '<table class="border tableforfield centpercent">';
167 
168  // Usage
169  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) || empty($conf->global->PROJECT_HIDE_TASKS) || !empty($conf->eventorganization->enabled)) {
170  print '<tr><td class="tdtop">';
171  print $langs->trans("Usage");
172  print '</td>';
173  print '<td>';
174  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
175  print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
176  $htmltext = $langs->trans("ProjectFollowOpportunity");
177  print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
178  print '<br>';
179  }
180  if (empty($conf->global->PROJECT_HIDE_TASKS)) {
181  print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
182  $htmltext = $langs->trans("ProjectFollowTasks");
183  print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
184  print '<br>';
185  }
186  if (empty($conf->global->PROJECT_HIDE_TASKS) && !empty($conf->global->PROJECT_BILL_TIME_SPENT)) {
187  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"' : '')).'"> ';
188  $htmltext = $langs->trans("ProjectBillTimeDescription");
189  print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
190  print '<br>';
191  }
192  if (!empty($conf->eventorganization->enabled)) {
193  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"' : '')).'"> ';
194  $htmltext = $langs->trans("EventOrganizationDescriptionLong");
195  print $form->textwithpicto($langs->trans("ManageOrganizeEvent"), $htmltext);
196  }
197  print '</td></tr>';
198  }
199 
200  // Visibility
201  print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
202  if ($projectstatic->public) {
203  print img_picto($langs->trans('SharedProject'), 'world', 'class="paddingrightonly"');
204  print $langs->trans('SharedProject');
205  } else {
206  print img_picto($langs->trans('PrivateProject'), 'private', 'class="paddingrightonly"');
207  print $langs->trans('PrivateProject');
208  }
209  print '</td></tr>';
210 
211  // Date start - end
212  print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
213  $start = dol_print_date($projectstatic->date_start, 'day');
214  print ($start ? $start : '?');
215  $end = dol_print_date($projectstatic->date_end, 'day');
216  print ' - ';
217  print ($end ? $end : '?');
218  if ($projectstatic->hasDelay()) {
219  print img_warning("Late");
220  }
221  print '</td></tr>';
222 
223  // Budget
224  print '<tr><td>'.$langs->trans("Budget").'</td><td>';
225  if (strcmp($projectstatic->budget_amount, '')) {
226  print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
227  }
228  print '</td></tr>';
229 
230  // Other attributes
231  $cols = 2;
232  //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
233 
234  print '</table>';
235 
236  print '</div>';
237  print '<div class="fichehalfright">';
238  print '<div class="underbanner clearboth"></div>';
239 
240  print '<table class="border tableforfield centpercent">';
241 
242  // Description
243  print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
244  print nl2br($projectstatic->description);
245  print '</td></tr>';
246 
247  // Categories
248  if (isModEnabled('categorie')) {
249  print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
250  print $form->showCategories($projectstatic->id, 'project', 1);
251  print "</td></tr>";
252  }
253 
254  print '</table>';
255 
256  print '</div>';
257  print '</div>';
258 
259  print '<div class="clearboth"></div>';
260 
261  print dol_get_fiche_end();
262 
263  print '<br>';
264  }
265 
266  $head = task_prepare_head($object);
267  print dol_get_fiche_head($head, 'task_document', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
268 
269  // Files list constructor
270  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
271  $totalsize = 0;
272  foreach ($filearray as $key => $file) {
273  $totalsize += $file['size'];
274  }
275 
276  $param = (GETPOST('withproject') ? '&withproject=1' : '');
277  $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
278 
279  if (!GETPOST('withproject') || empty($projectstatic->id)) {
280  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
281  $object->next_prev_filter = " fk_projet IN (".$db->sanitize($projectsListId).")";
282  } else {
283  $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
284  }
285 
286  $morehtmlref = '';
287 
288  // Project
289  if (empty($withproject)) {
290  $morehtmlref .= '<div class="refidno">';
291  $morehtmlref .= $langs->trans("Project").': ';
292  $morehtmlref .= $projectstatic->getNomUrl(1);
293  $morehtmlref .= '<br>';
294 
295  // Third party
296  $morehtmlref .= $langs->trans("ThirdParty").': ';
297  if (is_object($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
298  $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
299  }
300  $morehtmlref .= '</div>';
301  }
302 
303  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
304 
305  print '<div class="fichecenter">';
306 
307  print '<div class="underbanner clearboth"></div>';
308  print '<table class="border tableforfield centpercent">';
309 
310  // Files infos
311  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
312  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
313 
314  print "</table>\n";
315 
316  print '</div>';
317 
318  print dol_get_fiche_end();
319 
320  print '<br>';
321 
322  $param = '';
323  if ($withproject) {
324  $param .= '&withproject=1';
325  }
326  $modulepart = 'project_task';
327  $permissiontoadd = $user->rights->projet->creer;
328  $permtoedit = $user->rights->projet->creer;
329  $relativepathwithnofile = dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/';
330  include DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
331 } else {
332  header('Location: index.php');
333  exit;
334 }
335 
336 // End of page
337 llxFooter();
338 $db->close();
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1226
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
llxFooter
llxFooter()
Footer empty.
Definition: document.php:89
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
Task
Class to manage tasks.
Definition: task.class.php:37
project_prepare_head
project_prepare_head(Project $project, $moreparam='')
Prepare array with list of tabs.
Definition: project.lib.php:38
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:60
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2046
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(isset($_GET["hashp"]) &&!defined("NOLOGIN")) if((isset($_GET["modulepart"]) && $_GET["modulepart"]=='medias')) llxHeader()
Header empty.
Definition: document.php:80
task_prepare_head
task_prepare_head($object)
Prepare array with list of tabs.
Definition: project.lib.php:335
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
price
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.
Definition: functions.lib.php:5541