dolibarr  13.0.2
comment.php
1 <?php
2 /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2006-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2010-2012 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require "../../main.inc.php";
27 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/modules/project/task/modules_task.php';
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array('projects', 'companies'));
39 
40 $id = GETPOST('id', 'int');
41 $idcomment = GETPOST('idcomment', 'int');
42 $ref = GETPOST("ref", 'alpha', 1); // task ref
43 $objectref = GETPOST("taskref", 'alpha'); // task ref
44 $action = GETPOST('action', 'aZ09');
45 $confirm = GETPOST('confirm', 'alpha');
46 $withproject = GETPOST('withproject', 'int');
47 $project_ref = GETPOST('project_ref', 'alpha');
48 $planned_workload = ((GETPOST('planned_workloadhour', 'int') != '' || GETPOST('planned_workloadmin', 'int') != '') ? (GETPOST('planned_workloadhour', 'int') > 0 ?GETPOST('planned_workloadhour', 'int') * 3600 : 0) + (GETPOST('planned_workloadmin', 'int') > 0 ?GETPOST('planned_workloadmin', 'int') * 60 : 0) : '');
49 
50 // Security check
51 $socid = 0;
52 //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.
53 if (!$user->rights->projet->lire) accessforbidden();
54 
55 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
56 $hookmanager->initHooks(array('projecttaskcommentcard', 'globalcard'));
57 
58 $object = new Task($db);
59 $extrafields = new ExtraFields($db);
60 $projectstatic = new Project($db);
61 
62 // fetch optionals attributes and labels
63 $extrafields->fetch_name_optionals_label($object->table_element);
64 
65 // include comment actions
66 include DOL_DOCUMENT_ROOT.'/core/actions_comments.inc.php';
67 
68 // Retrieve First Task ID of Project if withprojet is on to allow project prev next to work
69 if (!empty($project_ref) && !empty($withproject))
70 {
71  if ($projectstatic->fetch('', $project_ref) > 0)
72  {
73  $objectsarray = $object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
74  if (count($objectsarray) > 0)
75  {
76  $id = $objectsarray[0]->id;
77  } else {
78  header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.(empty($mode) ? '' : '&mode='.$mode));
79  }
80  }
81 }
82 
83 /*
84  * View
85 */
86 
87 
88 llxHeader('', $langs->trans("CommentPage"));
89 
90 $form = new Form($db);
91 $formother = new FormOther($db);
92 $formfile = new FormFile($db);
93 
94 if ($id > 0 || !empty($ref))
95 {
96  if ($object->fetch($id, $ref) > 0)
97  {
98  $result = $object->fetch_optionals();
99 
100  $result = $object->fetchComments();
101  if ($result < 0) {
102  setEventMessages($object->error, $object->errors, 'errors');
103  }
104 
105  $result = $projectstatic->fetch($object->fk_project);
106  if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty();
107  if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($projectstatic, 'fetchComments') && empty($projectstatic->comments)) $projectstatic->fetchComments();
108 
109  $object->project = clone $projectstatic;
110 
111  $userWrite = $projectstatic->restrictedProjectArea($user, 'write');
112 
113  if (!empty($withproject))
114  {
115  // Tabs for project
116  $tab = 'tasks';
117  $head = project_prepare_head($projectstatic);
118  print dol_get_fiche_head($head, $tab, $langs->trans("Project"), -1, ($projectstatic->public ? 'projectpub' : 'project'));
119 
120  $param = ($mode == 'mine' ? '&mode=mine' : '');
121 
122  // Project card
123 
124  $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
125 
126  $morehtmlref = '<div class="refidno">';
127  // Title
128  $morehtmlref .= $projectstatic->title;
129  // Thirdparty
130  if ($projectstatic->thirdparty->id > 0)
131  {
132  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$projectstatic->thirdparty->getNomUrl(1, 'project');
133  }
134  $morehtmlref .= '</div>';
135 
136  // Define a complementary filter for search of next/prev ref.
137  if (!$user->rights->projet->all->lire)
138  {
139  $objectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 0);
140  $projectstatic->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
141  }
142 
143  dol_banner_tab($projectstatic, 'project_ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
144 
145  print '<div class="fichecenter">';
146  print '<div class="fichehalfleft">';
147  print '<div class="underbanner clearboth"></div>';
148 
149  print '<table class="border centpercent">';
150 
151  // Usage
152  print '<tr><td class="tdtop">';
153  print $langs->trans("Usage");
154  print '</td>';
155  print '<td>';
156  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
157  {
158  print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_opportunity ? ' checked="checked"' : '')).'"> ';
159  $htmltext = $langs->trans("ProjectFollowOpportunity");
160  print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
161  print '<br>';
162  }
163  if (empty($conf->global->PROJECT_HIDE_TASKS))
164  {
165  print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($projectstatic->usage_task ? ' checked="checked"' : '')).'"> ';
166  $htmltext = $langs->trans("ProjectFollowTasks");
167  print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
168  print '<br>';
169  }
170  if (!empty($conf->global->PROJECT_BILL_TIME_SPENT))
171  {
172  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"' : '')).'"> ';
173  $htmltext = $langs->trans("ProjectBillTimeDescription");
174  print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
175  print '<br>';
176  }
177  print '</td></tr>';
178 
179  // Visibility
180  print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
181  if ($projectstatic->public) print $langs->trans('SharedProject');
182  else print $langs->trans('PrivateProject');
183  print '</td></tr>';
184 
185  // Usage
186  if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES) && !empty($object->usage_opportunity))
187  {
188  // Opportunity status
189  print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
190  $code = dol_getIdFromCode($db, $projectstatic->opp_status, 'c_lead_status', 'rowid', 'code');
191  if ($code) print $langs->trans("OppStatus".$code);
192  print '</td></tr>';
193 
194  // Opportunity percent
195  print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
196  if (strcmp($object->opp_percent, '')) print price($projectstatic->opp_percent, 0, $langs, 1, 0).' %';
197  print '</td></tr>';
198 
199  // Opportunity Amount
200  print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
201  /*if ($object->opp_status)
202  {
203  print price($obj->opp_amount, 1, $langs, 1, 0, -1, $conf->currency);
204  }*/
205  if (strcmp($projectstatic->opp_amount, '')) print price($projectstatic->opp_amount, 0, $langs, 1, 0, -1, $conf->currency);
206  print '</td></tr>';
207  }
208 
209  // Date start - end
210  print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
211  $start = dol_print_date($projectstatic->date_start, 'day');
212  print ($start ? $start : '?');
213  $end = dol_print_date($projectstatic->date_end, 'day');
214  print ' - ';
215  print ($end ? $end : '?');
216  if ($projectstatic->hasDelay()) print img_warning("Late");
217  print '</td></tr>';
218 
219  // Budget
220  print '<tr><td>'.$langs->trans("Budget").'</td><td>';
221  if (strcmp($projectstatic->budget_amount, '')) print price($projectstatic->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
222  print '</td></tr>';
223 
224  // Other attributes
225  $cols = 2;
226  //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
227 
228  print '</table>';
229 
230  print '</div>';
231  print '<div class="fichehalfright">';
232  print '<div class="ficheaddleft">';
233  print '<div class="underbanner clearboth"></div>';
234 
235  print '<table class="border centpercent">';
236 
237  // Description
238  print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
239  print nl2br($projectstatic->description);
240  print '</td></tr>';
241 
242  // Categories
243  if ($conf->categorie->enabled) {
244  print '<tr><td class="valignmiddle">'.$langs->trans("Categories").'</td><td>';
245  print $form->showCategories($projectstatic->id, 'project', 1);
246  print "</td></tr>";
247  }
248 
249  print '</table>';
250 
251  print '</div>';
252  print '</div>';
253  print '</div>';
254 
255  print '<div class="clearboth"></div>';
256 
258 
259  print '<br>';
260  }
261 
262  $head = task_prepare_head($object);
263 
264  /*
265  * Fiche tache en mode visu
266  */
267  $param = ($withproject ? '&withproject=1' : '');
268  $linkback = $withproject ? '<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'&restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>' : '';
269 
270  print dol_get_fiche_head($head, 'task_comment', $langs->trans("Task"), -1, 'projecttask');
271 
272  if ($action == 'delete')
273  {
274  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"].'&withproject='.$withproject, $langs->trans("DeleteATask"), $langs->trans("ConfirmDeleteATask"), "confirm_delete");
275  }
276 
277  if (!GETPOST('withproject') || empty($projectstatic->id))
278  {
279  $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user, 0, 1);
280  $object->next_prev_filter = " fk_projet in (".$projectsListId.")";
281  } else $object->next_prev_filter = " fk_projet = ".$projectstatic->id;
282 
283  $morehtmlref = '';
284 
285  // Project
286  if (empty($withproject))
287  {
288  $morehtmlref .= '<div class="refidno">';
289  $morehtmlref .= $langs->trans("Project").': ';
290  $morehtmlref .= $projectstatic->getNomUrl(1);
291  $morehtmlref .= '<br>';
292 
293  // Third party
294  $morehtmlref .= $langs->trans("ThirdParty").': ';
295  if (!empty($projectstatic->thirdparty)) {
296  $morehtmlref .= $projectstatic->thirdparty->getNomUrl(1);
297  }
298  $morehtmlref .= '</div>';
299  }
300 
301  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $param);
302 
303  print '<div class="fichecenter">';
304 
305  print '<div class="underbanner clearboth"></div>';
306  print '<table class="border centpercent">';
307 
308  // Nb comments
309  print '<td class="titlefield">'.$langs->trans("NbComments").'</td><td>';
310  print $object->getNbComments();
311  print '</td></tr>';
312 
313  // Other attributes
314  $cols = 3;
315  $parameters = array('socid'=>$socid);
316  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
317 
318  print '</table>';
319 
320  print '</div>';
321 
323 
324 
325  // Include comment tpl view
326  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_comment.tpl.php';
327  }
328 }
329 
330 // End of page
331 llxFooter();
332 $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 standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Classe permettant la generation de composants html autre Only common components are here...
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 ...
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
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_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.