PageRenderTime 67ms CodeModel.GetById 13ms app.highlight 44ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/projet/tasks.php

https://github.com/atm-maxime/dolibarr
PHP | 853 lines | 628 code | 136 blank | 89 comment | 145 complexity | 852e019bb527006cad1e85d17b3041aa MD5 | raw file
  1<?php
  2/* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2019 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005-2017 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
 20/**
 21 *	\file       htdocs/projet/tasks.php
 22 *	\ingroup    project
 23 *	\brief      List all tasks of a project
 24 */
 25
 26require "../main.inc.php";
 27require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
 28require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
 29require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
 32require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
 33require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
 34if ($conf->categorie->enabled) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; }
 35
 36// Load translation files required by the page
 37$langs->loadLangs(array('projects', 'users', 'companies'));
 38
 39$action = GETPOST('action', 'alpha');
 40$massaction = GETPOST('massaction', 'alpha');
 41$show_files = GETPOST('show_files', 'int');
 42$confirm = GETPOST('confirm', 'alpha');
 43$toselect = GETPOST('toselect', 'array');
 44
 45$id = GETPOST('id', 'int');
 46$ref = GETPOST('ref', 'alpha');
 47$taskref = GETPOST('taskref', 'alpha');
 48
 49$backtopage = GETPOST('backtopage', 'alpha');
 50$cancel = GETPOST('cancel', 'alpha');
 51
 52$search_user_id = GETPOST('search_user_id', 'int');
 53$search_taskref = GETPOST('search_taskref');
 54$search_tasklabel = GETPOST('search_tasklabel');
 55$search_taskdescription = GETPOST('search_taskdescription');
 56$search_dtstartday = GETPOST('search_dtstartday');
 57$search_dtstartmonth = GETPOST('search_dtstartmonth');
 58$search_dtstartyear = GETPOST('search_dtstartyear');
 59$search_dtendday = GETPOST('search_dtendday');
 60$search_dtendmonth = GETPOST('search_dtendmonth');
 61$search_dtendyear = GETPOST('search_dtendyear');
 62$search_planedworkload = GETPOST('search_planedworkload');
 63$search_timespend = GETPOST('search_timespend');
 64$search_progresscalc = GETPOST('search_progresscalc');
 65$search_progressdeclare = GETPOST('search_progressdeclare');
 66
 67$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'projecttasklist';
 68
 69//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
 70
 71$object = new Project($db);
 72$taskstatic = new Task($db);
 73$extrafields = new ExtraFields($db);
 74
 75include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
 76if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
 77
 78if ($id > 0 || !empty($ref))
 79{
 80	// fetch optionals attributes and labels
 81	$extrafields->fetch_name_optionals_label($object->table_element);
 82}
 83$extrafields->fetch_name_optionals_label($taskstatic->table_element);
 84$search_array_options = $extrafields->getOptionalsFromPost($taskstatic->table_element, '', 'search_');
 85
 86// Security check
 87$socid = 0;
 88//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.
 89$result = restrictedArea($user, 'projet', $id, 'projet&project');
 90
 91$diroutputmassaction = $conf->projet->dir_output.'/tasks/temp/massgeneration/'.$user->id;
 92
 93// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
 94$hookmanager->initHooks(array('projecttaskscard', 'globalcard'));
 95
 96$progress = GETPOST('progress', 'int');
 97$label = GETPOST('label', 'alpha');
 98$description = GETPOST('description', 'none');
 99$planned_workloadhour = (GETPOST('planned_workloadhour', 'int') ?GETPOST('planned_workloadhour', 'int') : 0);
100$planned_workloadmin = (GETPOST('planned_workloadmin', 'int') ?GETPOST('planned_workloadmin', 'int') : 0);
101$planned_workload = $planned_workloadhour * 3600 + $planned_workloadmin * 60;
102
103// Definition of fields for list
104$arrayfields = array(
105	't.ref'=>array('label'=>$langs->trans("RefTask"), 'checked'=>1, 'position'=>1),
106	't.label'=>array('label'=>$langs->trans("LabelTask"), 'checked'=>1, 'position'=>2),
107	't.description'=>array('label'=>$langs->trans("Description"), 'checked'=>0, 'position'=>3),
108	't.dateo'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1, 'position'=>4),
109	't.datee'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1, 'position'=>5),
110	't.planned_workload'=>array('label'=>$langs->trans("PlannedWorkload"), 'checked'=>1, 'position'=>6),
111	't.duration_effective'=>array('label'=>$langs->trans("TimeSpent"), 'checked'=>1, 'position'=>7),
112	't.progress_calculated'=>array('label'=>$langs->trans("ProgressCalculated"), 'checked'=>1, 'position'=>8),
113	't.progress'=>array('label'=>$langs->trans("ProgressDeclared"), 'checked'=>1, 'position'=>9),
114	't.progress_summary'=>array('label'=>$langs->trans("TaskProgressSummary"), 'checked'=>1, 'position'=>10),
115);
116if ($object->usage_bill_time) {
117	$arrayfields['t.tobill'] = array('label'=>$langs->trans("TimeToBill"), 'checked'=>0, 'position'=>11);
118	$arrayfields['t.billed'] = array('label'=>$langs->trans("TimeBilled"), 'checked'=>0, 'position'=>12);
119}
120
121// Extra fields
122if (is_array($extrafields->attributes[$taskstatic->table_element]['label']) && count($extrafields->attributes[$taskstatic->table_element]['label']) > 0)
123{
124	foreach ($extrafields->attributes[$taskstatic->table_element]['label'] as $key => $val)
125	{
126		if (!empty($extrafields->attributes[$taskstatic->table_element]['list'][$key]))
127			$arrayfields["ef.".$key] = array('label'=>$extrafields->attributes[$taskstatic->table_element]['label'][$key], 'checked'=>(($extrafields->attributes[$taskstatic->table_element]['list'][$key] < 0) ? 0 : 1), 'position'=>$extrafields->attributes[$taskstatic->table_element]['pos'][$key], 'enabled'=>(abs($extrafields->attributes[$taskstatic->table_element]['list'][$key]) != 3 && $extrafields->attributes[$taskstatic->table_element]['perms'][$key]));
128	}
129}
130$arrayfields = dol_sort_array($arrayfields, 'position');
131
132$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
133
134
135/*
136 * Actions
137 */
138
139$parameters = array('id'=>$id);
140$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
141if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
142
143if (empty($reshook))
144{
145	// Selection of new fields
146	include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
147
148	// Purge search criteria
149	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
150	{
151		$search_user_id = "";
152		$search_taskref = '';
153		$search_tasklabel = '';
154		$search_dtstartday = '';
155		$search_dtstartmonth = '';
156		$search_dtstartyear = '';
157		$search_dtendday = '';
158		$search_dtendmonth = '';
159		$search_dtendyear = '';
160		$search_planedworkload = '';
161		$search_timespend = '';
162		$search_progresscalc = '';
163		$search_progressdeclare = '';
164		$toselect = '';
165		$search_array_options = array();
166	}
167
168	// Mass actions
169	$objectclass = 'Task';
170	$objectlabel = 'Tasks';
171	$permissiontoread = $user->rights->projet->lire;
172	$permissiontodelete = $user->rights->projet->supprimer;
173	$uploaddir = $conf->projet->dir_output.'/tasks';
174	include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
175}
176
177$morewherefilterarray = array();
178
179if (!empty($search_taskref)) {
180	$morewherefilterarray[] = natural_search('t.ref', $search_taskref, 0, 1);
181}
182
183if (!empty($search_tasklabel)) {
184	$morewherefilterarray[] = natural_search('t.label', $search_tasklabel, 0, 1);
185}
186
187$moresql = dolSqlDateFilter('t.dateo', $search_dtstartday, $search_dtstartmonth, $search_dtstartyear, 1);
188if ($moresql) $morewherefilterarray[] = $moresql;
189
190$moresql = dolSqlDateFilter('t.datee', $search_dtendday, $search_dtendmonth, $search_dtendyear, 1);
191if ($moresql) $morewherefilterarray[] = $moresql;
192
193if (!empty($search_planedworkload)) {
194	$morewherefilterarray[] = natural_search('t.planned_workload', $search_planedworkload, 1, 1);
195}
196
197if (!empty($search_timespend)) {
198	$morewherefilterarray[] = natural_search('t.duration_effective', $search_timespend, 1, 1);
199}
200
201if (!empty($search_progresscalc)) {
202	$filterprogresscalc = 'if '.natural_search('round(100 * $line->duration / $line->planned_workload,2)', $search_progresscalc, 1, 1).'{return 1;} else {return 0;}';
203} else {
204	$filterprogresscalc = '';
205}
206
207if (!empty($search_progressdeclare)) {
208	$morewherefilterarray[] = natural_search('t.progress', $search_progressdeclare, 1, 1);
209}
210
211$morewherefilter = '';
212if (count($morewherefilterarray) > 0) {
213	$morewherefilter = ' AND '.implode(' AND ', $morewherefilterarray);
214}
215
216if ($action == 'createtask' && $user->rights->projet->creer)
217{
218	$error = 0;
219
220	// If we use user timezone, we must change also view/list to use user timezone everywhere
221	//$date_start = dol_mktime($_POST['dateohour'],$_POST['dateomin'],0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear'],'user');
222	//$date_end = dol_mktime($_POST['dateehour'],$_POST['dateemin'],0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear'],'user');
223	$date_start = dol_mktime($_POST['dateohour'], $_POST['dateomin'], 0, $_POST['dateomonth'], $_POST['dateoday'], $_POST['dateoyear']);
224	$date_end = dol_mktime($_POST['dateehour'], $_POST['dateemin'], 0, $_POST['dateemonth'], $_POST['dateeday'], $_POST['dateeyear']);
225
226	if (!$cancel)
227	{
228		if (empty($taskref))
229		{
230			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Ref")), null, 'errors');
231			$action = 'create';
232			$error++;
233		}
234		if (empty($label))
235		{
236			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
237			$action = 'create';
238			$error++;
239		}
240		elseif (empty($_POST['task_parent']))
241		{
242			setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ChildOfProjectTask")), null, 'errors');
243			$action = 'create';
244			$error++;
245		}
246
247		if (!$error)
248		{
249			$tmparray = explode('_', $_POST['task_parent']);
250			$projectid = $tmparray[0];
251			if (empty($projectid)) $projectid = $id; // If projectid is ''
252			$task_parent = $tmparray[1];
253			if (empty($task_parent)) $task_parent = 0; // If task_parent is ''
254
255			$task = new Task($db);
256
257			$task->fk_project = $projectid;
258			$task->ref = $taskref;
259			$task->label = $label;
260			$task->description = $description;
261			$task->planned_workload = $planned_workload;
262			$task->fk_task_parent = $task_parent;
263			$task->date_c = dol_now();
264			$task->date_start = $date_start;
265			$task->date_end = $date_end;
266			$task->progress = $progress;
267
268			// Fill array 'array_options' with data from add form
269			$ret = $extrafields->setOptionalsFromPost(null, $task);
270
271			$taskid = $task->create($user);
272
273			if ($taskid > 0)
274			{
275				$result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
276			}
277			else
278			{
279				if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
280				{
281					$langs->load("projects");
282					setEventMessages($langs->trans('NewTaskRefSuggested'), '', 'warnings');
283					$duplicate_code_error = true;
284				}
285				else
286				{
287					setEventMessages($task->error, $task->errors, 'errors');
288				}
289				$action = 'create';
290				$error++;
291			}
292		}
293
294		if (!$error)
295		{
296			if (!empty($backtopage))
297			{
298				header("Location: ".$backtopage);
299				exit;
300			}
301			elseif (empty($projectid))
302			{
303				header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
304				exit;
305			}
306			$id = $projectid;
307		}
308	}
309	else
310	{
311		if (!empty($backtopage))
312		{
313			header("Location: ".$backtopage);
314			exit;
315		}
316		elseif (empty($id))
317		{
318			// We go back on task list
319			header("Location: ".DOL_URL_ROOT.'/projet/tasks/list.php'.(empty($mode) ? '' : '?mode='.$mode));
320			exit;
321		}
322	}
323}
324
325
326/*
327 * View
328 */
329
330$now = dol_now();
331$form = new Form($db);
332$formother = new FormOther($db);
333$socstatic = new Societe($db);
334$projectstatic = new Project($db);
335$taskstatic = new Task($db);
336$userstatic = new User($db);
337
338$title = $langs->trans("Project").' - '.$langs->trans("Tasks").' - '.$object->ref.' '.$object->name;
339if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->ref.' '.$object->name.' - '.$langs->trans("Tasks");
340$help_url = "EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
341llxHeader("", $title, $help_url);
342
343
344if ($id > 0 || !empty($ref))
345{
346	$object->fetch($id, $ref);
347	$object->fetch_thirdparty();
348	$res = $object->fetch_optionals();
349
350	// To verify role of users
351	//$userAccess = $object->restrictedProjectArea($user,'read');
352	$userWrite = $object->restrictedProjectArea($user, 'write');
353	//$userDelete = $object->restrictedProjectArea($user,'delete');
354	//print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
355
356
357	$tab = GETPOST('tab') ?GETPOST('tab') : 'tasks';
358
359	$head = project_prepare_head($object);
360	dol_fiche_head($head, $tab, $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
361
362	$param = '&id='.$object->id;
363	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
364	if ($search_user_id)                 		$param .= '&search_user_id='.urlencode($search_user_id);
365	if ($search_taskref)              		$param .= '&search_taskref='.urlencode($search_taskref);
366	if ($search_tasklabel)              		$param .= '&search_tasklabel='.urlencode($search_tasklabel);
367	if ($search_taskdescription)              		$param .= '&search_taskdescription='.urlencode($search_taskdescription);
368	if ($search_dtstartday)              		$param .= '&search_dtstartday='.urlencode($search_dtstartday);
369	if ($search_dtstartmonth)              		$param .= '&search_dtstartmonth='.urlencode($search_dtstartmonth);
370	if ($search_dtstartyear)              		$param .= '&search_dtstartyear='.urlencode($search_dtstartyear);
371	if ($search_dtendday)              		$param .= '&search_dtendday='.urlencode($search_dtendday);
372	if ($search_dtendmonth)              		$param .= '&search_dtendmonth='.urlencode($search_dtendmonth);
373	if ($search_dtendyear)              		$param .= '&search_dtendyear='.urlencode($search_dtendyear);
374	if ($search_planedworkload)              		$param .= '&search_planedworkload='.urlencode($search_planedworkload);
375	if ($search_timespend)              		$param .= '&search_timespend='.urlencode($search_timespend);
376	if ($search_progresscalc)              		$param .= '&search_progresscalc='.urlencode($search_progresscalc);
377	if ($search_progressdeclare)              		$param .= '&search_progressdeclare='.urlencode($search_progressdeclare);
378	if ($optioncss != '')           $param .= '&optioncss='.urlencode($optioncss);
379	// Add $param from extra fields
380	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
381
382	// Project card
383
384	$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
385
386	$morehtmlref = '<div class="refidno">';
387	// Title
388	$morehtmlref .= $object->title;
389	// Thirdparty
390	if ($object->thirdparty->id > 0)
391	{
392		$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'project');
393	}
394	$morehtmlref .= '</div>';
395
396	// Define a complementary filter for search of next/prev ref.
397	if (!$user->rights->projet->all->lire)
398	{
399		$objectsListId = $object->getProjectsAuthorizedForUser($user, 0, 0);
400		$object->next_prev_filter = " rowid in (".(count($objectsListId) ?join(',', array_keys($objectsListId)) : '0').")";
401	}
402
403	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
404
405	print '<div class="fichecenter">';
406	print '<div class="fichehalfleft">';
407	print '<div class="underbanner clearboth"></div>';
408
409	print '<table class="border tableforfield" width="100%">';
410
411	// Usage
412	print '<tr><td class="tdtop">';
413	print $langs->trans("Usage");
414	print '</td>';
415	print '<td>';
416	if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
417	{
418		print '<input type="checkbox" disabled name="usage_opportunity"'.(GETPOSTISSET('usage_opportunity') ? (GETPOST('usage_opportunity', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_opportunity ? ' checked="checked"' : '')).'"> ';
419		$htmltext = $langs->trans("ProjectFollowOpportunity");
420		print $form->textwithpicto($langs->trans("ProjectFollowOpportunity"), $htmltext);
421		print '<br>';
422	}
423	if (empty($conf->global->PROJECT_HIDE_TASKS))
424	{
425		print '<input type="checkbox" disabled name="usage_task"'.(GETPOSTISSET('usage_task') ? (GETPOST('usage_task', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_task ? ' checked="checked"' : '')).'"> ';
426		$htmltext = $langs->trans("ProjectFollowTasks");
427		print $form->textwithpicto($langs->trans("ProjectFollowTasks"), $htmltext);
428		print '<br>';
429	}
430	if (!empty($conf->global->PROJECT_BILL_TIME_SPENT))
431	{
432		print '<input type="checkbox" disabled name="usage_bill_time"'.(GETPOSTISSET('usage_bill_time') ? (GETPOST('usage_bill_time', 'alpha') != '' ? ' checked="checked"' : '') : ($object->usage_bill_time ? ' checked="checked"' : '')).'"> ';
433		$htmltext = $langs->trans("ProjectBillTimeDescription");
434		print $form->textwithpicto($langs->trans("BillTime"), $htmltext);
435		print '<br>';
436	}
437	print '</td></tr>';
438
439	// Visibility
440	print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
441	if ($object->public) print $langs->trans('SharedProject');
442	else print $langs->trans('PrivateProject');
443	print '</td></tr>';
444
445	// Date start - end
446	print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
447	$start = dol_print_date($object->date_start, 'day');
448	print ($start ? $start : '?');
449	$end = dol_print_date($object->date_end, 'day');
450	print ' - ';
451	print ($end ? $end : '?');
452	if ($object->hasDelay()) print img_warning("Late");
453	print '</td></tr>';
454
455	// Budget
456	print '<tr><td>'.$langs->trans("Budget").'</td><td>';
457	if (strcmp($object->budget_amount, '')) print price($object->budget_amount, '', $langs, 1, 0, 0, $conf->currency);
458	print '</td></tr>';
459
460	// Other attributes
461	$cols = 2;
462	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
463
464	print '</table>';
465
466	print '</div>';
467	print '<div class="fichehalfright">';
468	print '<div class="ficheaddleft">';
469	print '<div class="underbanner clearboth"></div>';
470
471	print '<table class="border tableforfield" width="100%">';
472
473	// Description
474	print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
475	print nl2br($object->description);
476	print '</td></tr>';
477
478	// Categories
479	if ($conf->categorie->enabled) {
480		print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td>';
481		print $form->showCategories($object->id, Categorie::TYPE_PROJECT, 1);
482		print "</td></tr>";
483	}
484
485	print '</table>';
486
487	print '</div>';
488	print '</div>';
489	print '</div>';
490
491	print '<div class="clearboth"></div>';
492
493
494	dol_fiche_end();
495}
496
497
498if ($action == 'create' && $user->rights->projet->creer && (empty($object->thirdparty->id) || $userWrite > 0))
499{
500	if ($id > 0 || !empty($ref)) print '<br>';
501
502	print load_fiche_titre($langs->trans("NewTask"), '', 'projecttask');
503
504	if ($object->statut == Project::STATUS_CLOSED)
505	{
506		print '<div class="warning">';
507		$langs->load("errors");
508		print $langs->trans("WarningProjectClosed");
509		print '</div>';
510	}
511	else
512	{
513		print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
514		print '<input type="hidden" name="token" value="'.newToken().'">';
515		print '<input type="hidden" name="action" value="createtask">';
516		print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
517		if (!empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
518
519		dol_fiche_head('');
520
521		print '<table class="border centpercent">';
522
523		$defaultref = '';
524		$obj = empty($conf->global->PROJECT_TASK_ADDON) ? 'mod_task_simple' : $conf->global->PROJECT_TASK_ADDON;
525		if (!empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
526		{
527			require_once DOL_DOCUMENT_ROOT."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
528			$modTask = new $obj;
529			$defaultref = $modTask->getNextValue($object->thirdparty, null);
530		}
531
532		if (is_numeric($defaultref) && $defaultref <= 0) $defaultref = '';
533
534		// Ref
535		print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>';
536		if (empty($duplicate_code_error))
537		{
538			print (GETPOSTISSET("ref") ?GETPOST("ref", 'alpha') : $defaultref);
539		}
540		else
541		{
542			print $defaultref;
543		}
544		print '<input type="hidden" name="taskref" value="'.($_POST["ref"] ? $_POST["ref"] : $defaultref).'">';
545		print '</td></tr>';
546
547		print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
548		print '<input type="text" name="label" autofocus class="minwidth500" value="'.$label.'">';
549		print '</td></tr>';
550
551		// List of projects
552		print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfProjectTask").'</td><td>';
553		print $formother->selectProjectTasks(GETPOST('task_parent'), $projectid ? $projectid : $object->id, 'task_parent', 0, 0, 1, 1, 0, '0,1', 'maxwidth500');
554		print '</td></tr>';
555
556		print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
557		$contactsofproject = (!empty($object->id) ? $object->getListContactId('internal') : '');
558		if (is_array($contactsofproject) && count($contactsofproject))
559		{
560			print $form->select_dolusers($user->id, 'userid', 0, '', 0, '', $contactsofproject, 0, 0, 0, '', 0, '', 'maxwidth300');
561		}
562		else
563		{
564			print $langs->trans("NoUserAssignedToTheProject");
565		}
566		print '</td></tr>';
567
568		// Date start
569		print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
570		print $form->selectDate(($date_start ? $date_start : ''), 'dateo', 1, 1, 0, '', 1, 1);
571		print '</td></tr>';
572
573		// Date end
574		print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
575		print $form->selectDate(($date_end ? $date_end : -1), 'datee', -1, 1, 0, '', 1, 1);
576		print '</td></tr>';
577
578		// Planned workload
579		print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
580		print $form->select_duration('planned_workload', $planned_workload ? $planned_workload : 0, 0, 'text');
581		print '</td></tr>';
582
583		// Progress
584		print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
585		print $formother->select_percent($progress, 'progress', 0, 5, 0, 100, 1);
586		print '</td></tr>';
587
588		// Description
589		print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
590		print '<td>';
591		print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_4.'">'.$description.'</textarea>';
592		print '</td></tr>';
593
594		// Other options
595		$parameters = array();
596		$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $taskstatic, $action); // Note that $action and $object may have been modified by hook
597		print $hookmanager->resPrint;
598
599		if (empty($reshook) && !empty($extrafields->attributes[$taskstatic->table_element]['label']))
600		{
601			print $taskstatic->showOptionals($extrafields, 'edit'); // Do not use $object here that is object of project but use $taskstatic
602		}
603
604		print '</table>';
605
606		dol_fiche_end();
607
608		print '<div class="center">';
609		print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
610		print ' &nbsp; &nbsp; ';
611		print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
612		print '</div>';
613
614		print '</form>';
615	}
616}
617elseif ($id > 0 || !empty($ref))
618{
619	$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
620
621	/*
622	 * Projet card in view mode
623	 */
624
625	print '<br>';
626
627	// Link to create task
628	$linktocreatetaskParam = array();
629	$linktocreatetaskUserRight = false;
630	if ($user->rights->projet->all->creer || $user->rights->projet->creer) {
631		if ($object->public || $userWrite > 0) {
632			$linktocreatetaskUserRight = true;
633		} else {
634			$linktocreatetaskParam['attr']['title'] = $langs->trans("NotOwnerOfProject");
635		}
636	}
637
638	$linktocreatetask = dolGetButtonTitle($langs->trans('AddTask'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/tasks.php?action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id), '', $linktocreatetaskUserRight, $linktocreatetaskParam);
639
640	print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
641	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
642	print '<input type="hidden" name="token" value="'.newToken().'">';
643	print '<input type="hidden" name="action" value="list">';
644	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
645	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
646	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
647	print '<input type="hidden" name="page" value="'.$page.'">';
648	print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
649
650	$title = $langs->trans("ListOfTasks");
651	$linktotasks = dolGetButtonTitle($langs->trans('ViewGantt'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/projet/ganttview.php?id='.$object->id.'&withproject=1', '', 1, array('morecss'=>'reposition'));
652
653	//print_barre_liste($title, 0, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, $linktotasks, $num, $totalnboflines, 'generic', 0, '', '', 0, 1);
654	print load_fiche_titre($title, $linktotasks.' &nbsp; '.$linktocreatetask, 'generic');
655
656	// Get list of tasks in tasksarray and taskarrayfiltered
657	// We need all tasks (even not limited to a user because a task to user can have a parent that is not affected to him).
658	$filteronthirdpartyid = $socid;
659	$tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $filteronthirdpartyid, 0, '', -1, $morewherefilter, 0, 0, $extrafields, 1, $search_array_options);
660	// We load also tasks limited to a particular user
661	$tmpuser = new User($db);
662	if ($search_user_id > 0) $tmpuser->fetch($search_user_id);
663
664	$tasksrole = ($tmpuser->id > 0 ? $taskstatic->getUserRolesForProjectsOrTasks(0, $tmpuser, $object->id, 0) : '');
665	//var_dump($tasksarray);
666	//var_dump($tasksrole);
667
668	if (!empty($conf->use_javascript_ajax))
669	{
670		include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
671	}
672
673	// Filter on categories
674	$moreforfilter = '';
675	if (count($tasksarray) > 0)
676	{
677		$moreforfilter .= '<div class="divsearchfield">';
678		$moreforfilter .= $langs->trans("TasksAssignedTo").': ';
679		$moreforfilter .= $form->select_dolusers($tmpuser->id > 0 ? $tmpuser->id : '', 'search_user_id', 1);
680		$moreforfilter .= '</div>';
681	}
682	if ($moreforfilter)
683	{
684		print '<div class="liste_titre liste_titre_bydiv centpercent">';
685		print $moreforfilter;
686		print '</div>';
687	}
688
689	print '<div class="div-table-responsive">';
690	print '<table id="tablelines" class="tagtable nobottom liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
691
692	// Fields title search
693	print '<tr class="liste_titre_filter">';
694
695	if (!empty($arrayfields['t.ref']['checked'])) {
696		print '<td class="liste_titre">';
697		print '<input class="flat searchstring maxwidth50" type="text" name="search_taskref" value="'.dol_escape_htmltag($search_taskref).'">';
698		print '</td>';
699	}
700
701	if (!empty($arrayfields['t.label']['checked'])) {
702		print '<td class="liste_titre">';
703		print '<input class="flat searchstring maxwidth100" type="text" name="search_tasklabel" value="'.dol_escape_htmltag($search_tasklabel).'">';
704		print '</td>';
705	}
706
707	if (!empty($arrayfields['t.description']['checked'])) {
708		print '<td class="liste_titre">';
709		print '<input class="flat searchstring maxwidth100" type="text" name="search_taskdescription" value="'.dol_escape_htmltag($search_taskdescription).'">';
710		print '</td>';
711	}
712
713	if (!empty($arrayfields['t.dateo']['checked'])) {
714		print '<td class="liste_titre center">';
715		print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtstartday" value="'.$search_dtstartday.'">';
716		print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtstartmonth" value="'.$search_dtstartmonth.'">';
717		$formother->select_year($search_dtstartyear ? $search_dtstartyear : -1, 'search_dtstartyear', 1, 20, 5);
718		print '</td>';
719	}
720
721	if (!empty($arrayfields['t.datee']['checked'])) {
722		print '<td class="liste_titre center">';
723		print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtendday" value="'.$search_dtendday.'">';
724		print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="search_dtendmonth" value="'.$search_dtendmonth.'">';
725		$formother->select_year($search_dtendyear ? $search_dtendyear : -1, 'search_dtendyear', 1, 20, 5);
726		print '</td>';
727	}
728
729	if (!empty($arrayfields['t.planned_workload']['checked'])) {
730		print '<td class="liste_titre right">';
731		print '<input class="flat" type="text" size="4" name="search_planedworkload" value="'.$search_planedworkload.'">';
732		print '</td>';
733	}
734
735	if (!empty($arrayfields['t.duration_effective']['checked'])) {
736		print '<td class="liste_titre right">';
737		print '<input class="flat" type="text" size="4" name="search_timespend" value="'.$search_timespend.'">';
738		print '</td>';
739	}
740
741	if (!empty($arrayfields['t.progress_calculated']['checked'])) {
742		print '<td class="liste_titre right">';
743		print '<input class="flat" type="text" size="4" name="search_progresscalc" value="'.$search_progresscalc.'">';
744		print '</td>';
745	}
746
747	if (!empty($arrayfields['t.progress']['checked'])) {
748		print '<td class="liste_titre right">';
749		print '<input class="flat" type="text" size="4" name="search_progressdeclare" value="'.$search_progressdeclare.'">';
750		print '</td>';
751	}
752
753	// progress resume not searchable
754	print '<td class="liste_titre right"></td>';
755
756	if ($object->usage_bill_time)
757	{
758		if (!empty($arrayfields['t.tobill']['checked'])) {
759			print '<td class="liste_titre right">';
760			print '</td>';
761		}
762
763		if (!empty($arrayfields['t.billed']['checked'])) {
764			print '<td class="liste_titre right">';
765			print '</td>';
766		}
767	}
768
769	if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print '<td class="liste_titre"></td>';
770
771	$extrafieldsobjectkey = $taskstatic->table_element;
772	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
773
774	// Action column
775	print '<td class="liste_titre maxwidthsearch">';
776	$searchpicto = $form->showFilterButtons();
777	print $searchpicto;
778	print '</td>';
779	print "</tr>\n";
780
781	print '<tr class="liste_titre nodrag nodrop">';
782	// print '<td>'.$langs->trans("Project").'</td>';
783	if (!empty($arrayfields['t.ref']['checked'])) print_liste_field_titre($arrayfields['t.ref']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, '');
784	if (!empty($arrayfields['t.label']['checked'])) print_liste_field_titre($arrayfields['t.label']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
785	if (!empty($arrayfields['t.description']['checked'])) print_liste_field_titre($arrayfields['t.description']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, '');
786	if (!empty($arrayfields['t.dateo']['checked'])) print_liste_field_titre($arrayfields['t.dateo']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
787	if (!empty($arrayfields['t.datee']['checked'])) print_liste_field_titre($arrayfields['t.datee']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
788	if (!empty($arrayfields['t.planned_workload']['checked'])) print_liste_field_titre($arrayfields['t.planned_workload']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
789	if (!empty($arrayfields['t.duration_effective']['checked'])) print_liste_field_titre($arrayfields['t.duration_effective']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
790	if (!empty($arrayfields['t.progress_calculated']['checked'])) print_liste_field_titre($arrayfields['t.progress_calculated']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
791	if (!empty($arrayfields['t.progress']['checked']))  print_liste_field_titre($arrayfields['t.progress']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
792	if (!empty($arrayfields['t.progress_summary']['checked'])) print_liste_field_titre($arrayfields['t.progress_summary']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'center ');
793	if ($object->usage_bill_time)
794	{
795		if (!empty($arrayfields['t.tobill']['checked']))  print_liste_field_titre($arrayfields['t.tobill']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
796		if (!empty($arrayfields['t.billed']['checked'])) print_liste_field_titre($arrayfields['t.billed']['label'], $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'right ');
797	}
798	if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST)) print_liste_field_titre("TaskRessourceLinks", $_SERVER["PHP_SELF"], '', '', $param, $sortfield, $sortorder);
799	// Extra fields
800	$disablesortlink = 1;
801	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
802	// Hook fields
803	$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
804	$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
805	print $hookmanager->resPrint;
806	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
807	print "</tr>\n";
808
809	if (count($tasksarray) > 0)
810	{
811		// Show all lines in taskarray (recursive function to go down on tree)
812		$j = 0; $level = 0;
813		$nboftaskshown = projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $object->id, 1, $object->id, $filterprogresscalc, ($object->usage_bill_time ? 1 : 0), $arrayfields);
814	}
815	else
816	{
817		$colspan = 10;
818		if ($object->usage_bill_time) $colspan += 2;
819		print '<tr class="oddeven nobottom"><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoTasks").'</span></td></tr>';
820	}
821
822	print "</table>";
823	print '</div>';
824
825	print '</form>';
826
827
828	// Test if database is clean. If not we clean it.
829	//print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
830	if (!empty($user->rights->projet->all->lire))	// We make test to clean only if user has permission to see all (test may report false positive otherwise)
831	{
832		if ($search_user_id == $user->id)
833		{
834			if ($nboftaskshown < count($tasksrole))
835			{
836				include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
837				cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
838			}
839		}
840		else
841		{
842			if ($nboftaskshown < count($tasksarray) && !GETPOST('search_user_id', 'int'))
843			{
844				include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
845				cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
846			}
847		}
848	}
849}
850
851// End of page
852llxFooter();
853$db->close();