dolibarr  13.0.2
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 = $_REQUEST['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 // Security check
48 $socid = 0;
49 //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignement.
50 //$result=restrictedArea($user,'projet',$id,'');
51 if (!$user->rights->projet->lire) accessforbidden();
52 
53 // Get parameters
54 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
55 $sortfield = GETPOST("sortfield", 'alpha');
56 $sortorder = GETPOST("sortorder", 'alpha');
57 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
58 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 if (!$sortorder) $sortorder = "ASC";
63 if (!$sortfield) $sortfield = "name";
64 
65 $object = new Task($db);
66 $projectstatic = new Project($db);
67 
68 /*
69  * Actions
70  */
71 
72 // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
73 if (!empty($project_ref) && !empty($withproject))
74 {
75  if ($projectstatic->fetch(0, $project_ref) > 0)
76  {
77  $tasksarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
78  if (count($tasksarray) > 0)
79  {
80  $id = $tasksarray[0]->id;
81  $object->fetch($id);
82  } else {
83  header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject ? '&withproject=1' : '').(empty($mode) ? '' : '&mode='.$mode));
84  exit;
85  }
86  }
87 }
88 
89 if ($id > 0 || !empty($ref))
90 {
91  if ($object->fetch($id, $ref) > 0)
92  {
93  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
94  $projectstatic->fetch($object->fk_project);
95  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) $projectstatic->fetchComments();
96 
97  if (!empty($projectstatic->socid)) {
98  $projectstatic->fetch_thirdparty();
99  }
100 
101  $object->project = clone $projectstatic;
102 
103  $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref);
104  } else {
105  dol_print_error($db);
106  }
107 }
108 
109 include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
110 
111 
112 /*
113  * View
114  */
115 
116 $form = new Form($db);
117 
118 llxHeader('', $langs->trans('Task'));
119 
120 if ($object->id > 0)
121 {
122  $projectstatic->fetch_thirdparty();
123 
124  $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
125 
126  if (!empty($withproject))
127  {
128  // Tabs for project
129  $tab = 'tasks';
130  $head = project_prepare_head($projectstatic);
131 
132  print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
133 
134  $param = ($mode == 'mine' ? '&mode=mine' : '');
135 
136  // Project card
137 
138  $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
139 
140  $morehtmlref = '<div class="refidno">';
141  // Title
142  $morehtmlref .= $projectstatic->title;
143  // Thirdparty
144  if ($projectstatic->thirdparty->id > 0)
145  {
146  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
147  }
148  $morehtmlref .= '</div>';
149 
150  // Define a complementary filter for search of next/prev ref.
151  if (!$user->rights->projet->all->lire)
152  {
153  $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
154  $projectstatic->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
155  }
156 
157  dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
158 
159  print '<div class="fichecenter">';
160  print '<div class="fichehalfleft">';
161  print '<div class="underbanner clearboth"></div>';
162 
163  print '<table class="border tableforfield centpercent">';
164 
165  // Usage
166  print '<tr><td class="tdtop">';
167  print $langs->trans("Usage");
168  print '</td>';
169  print '<td>';
170  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
171  {
172  print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
173  $htmltext = $langs->trans("ProjectFollowOpportunity");
174  print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
175  print '<br>';
176  }
177  if (empty($conf->global->PROJECT_HIDE_TASKS))
178  {
179  print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
180  $htmltext = $langs->trans("ProjectFollowTasks");
181  print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
182  print '<br>';
183  }
184  if (!empty($conf->global->PROJECT_BILL_TIME_SPENT))
185  {
186  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"' : '')).'"> ';
187  $htmltext = $langs->trans("ProjectBillTimeDescription");
188  print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
189  print '<br>';
190  }
191  print '</td></tr>';
192 
193  // Visibility
194  print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
195  if ($projectstatic->public) print $langs->trans('SharedProject');
196  else print $langs->trans('PrivateProject');
197  print '</td></tr>';
198 
199  // Date start - end
200  print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
201  $start = dol_print_date($projectstatic->date_start, 'day');
202  print ($start ? $start : '?');
203  $end = dol_print_date($projectstatic->date_end, 'day');
204  print ' - ';
205  print ($end ? $end : '?');
206  if ($projectstatic->hasDelay()) print img_warning("Late");
207  print '</td></tr>';
208 
209  // Budget
210  print '<tr><td>'.$langs->trans("Budget").'</td><td>';
211  if (strcmp($projectstatic->budget_amount, '')) print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
212  print '</td></tr>';
213 
214  // Other attributes
215  $cols = 2;
216  //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
217 
218  print '</table>';
219 
220  print '</div>';
221  print '<div class="fichehalfright">';
222  print '<div class="ficheaddleft">';
223  print '<div class="underbanner clearboth"></div>';
224 
225  print '<table class="border tableforfield centpercent">';
226 
227  // Description
228  print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
229  print nl2br($projectstatic->description);
230  print '</td></tr>';
231 
232  // Categories
233  if ($conf->categorie->enabled) {
234  print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
235  print $form->showCategories($projectstatic->id, 'project', 1);
236  print "</td></tr>";
237  }
238 
239  print '</table>';
240 
241  print '</div>';
242  print '</div>';
243  print '</div>';
244 
245  print '<div class="clearboth"></div>';
246 
248 
249  print '<br>';
250  }
251 
252  $head = task_prepare_head($object);
253  print dol_get_fiche_head($head, 'task_document', $langs->trans("Task"), -1, 'projecttask', 0, '', 'reposition');
254 
255  // Files list constructor
256  $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
257  $totalsize = 0;
258  foreach ($filearray as $key => $file)
259  {
260  $totalsize += $file['size'];
261  }
262 
263  $param = (GETPOST('withproject') ? '&withproject=1' : '');
264  $linkback = GETPOST('withproject') ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>' : '';
265 
266  if (!GETPOST('withproject') || empty($projectstatic->id))
267  {
268  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
269  $object->next_prev_filter = " fk_projet in (".$projectsListId.")";
270  } else $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
271 
272  $morehtmlref = '';
273 
274  // Project
275  if (empty($withproject))
276  {
277  $morehtmlref .= '<div class="refidno">';
278  $morehtmlref .= $langs->trans("Project").': ';
279  $morehtmlref .= $projectstatic->getNomUrl(1);
280  $morehtmlref .= '<br>';
281 
282  // Third party
283  $morehtmlref .= $langs->trans("ThirdParty").': ';
284  if (is_object($projectstatic->thirdparty) && $projectstatic->thirdparty->id > 0) {
285  $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
286  }
287  $morehtmlref .= '</div>';
288  }
289 
290  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
291 
292  print '<div class="fichecenter">';
293 
294  print '<div class="underbanner clearboth"></div>';
295  print '<table class="border tableforfield centpercent">';
296 
297  // Files infos
298  print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
299  print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.$totalsize.' '.$langs->trans("bytes").'</td></tr>';
300 
301  print "</table>\n";
302 
303  print '</div>';
304 
306 
307  print '<br>';
308 
309  $param = '';
310  if ($withproject) $param .= '&withproject=1';
311  $modulepart = 'project_task';
312  $permission = $user->rights->projet->creer;
313  $permtoedit = $user->rights->projet->creer;
314  $relativepathwithnofile = dol_sanitizeFileName($projectstatic->ref).'/'.dol_sanitizeFileName($object->ref).'/';
315  include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
316 } else {
317  header('Location: index.php');
318  exit;
319 }
320 
321 // End of page
322 llxFooter();
323 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage projects.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
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_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
project_prepare_head(Project $project)
Prepare array with list of tabs.
Definition: project.lib.php:36
print
Draft customers invoices.
Definition: index.php:89
Class to manage tasks.
Definition: task.class.php:35
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59
task_prepare_head($object)
Prepare array with list of tabs.