PageRenderTime 122ms CodeModel.GetById 101ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/projet/tasks.php

https://github.com/atm-maximep/dolibarr
PHP | 470 lines | 313 code | 84 blank | 73 comment | 64 complexity | 64f80d29b20629fb63d1848925e4703d MD5 | raw file
  1<?php
  2/* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2015 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
 18 */
 19
 20/**
 21 *	\file       htdocs/projet/tasks.php
 22 *	\ingroup    projet
 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';
 33
 34$langs->load("users");
 35$langs->load("projects");
 36
 37$action = GETPOST('action', 'alpha');
 38$id = GETPOST('id', 'int');
 39$ref = GETPOST('ref', 'alpha');
 40$backtopage=GETPOST('backtopage','alpha');
 41$cancel=GETPOST('cancel');
 42
 43$mode = GETPOST('mode', 'alpha');
 44$mine = ($mode == 'mine' ? 1 : 0);
 45//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
 46
 47$object = new Project($db);
 48$taskstatic = new Task($db);
 49$extrafields_project = new ExtraFields($db);
 50$extrafields_task = new ExtraFields($db);
 51
 52include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be include, not include_once
 53
 54if ($id > 0 || ! empty($ref))
 55{
 56	// fetch optionals attributes and labels
 57	$extralabels_projet=$extrafields_project->fetch_name_optionals_label($object->table_element);
 58	$extralabels_task=$extrafields_task->fetch_name_optionals_label($taskstatic->table_element);
 59}
 60
 61// Security check
 62$socid=0;
 63if ($user->societe_id > 0) $socid = $user->societe_id;
 64$result = restrictedArea($user, 'projet', $id);
 65
 66// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 67$hookmanager->initHooks(array('projecttaskcard','globalcard'));
 68
 69$progress=GETPOST('progress', 'int');
 70$label=GETPOST('label', 'alpha');
 71$description=GETPOST('description');
 72$planned_workload=GETPOST('planned_workloadhour')*3600+GETPOST('planned_workloadmin')*60;
 73
 74$userAccess=0;
 75
 76
 77
 78/*
 79 * Actions
 80 */
 81
 82if ($action == 'createtask' && $user->rights->projet->creer)
 83{
 84	$error=0;
 85
 86	$date_start = dol_mktime($_POST['dateohour'],$_POST['dateomin'],0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear'],'user');
 87	$date_end = dol_mktime($_POST['dateehour'],$_POST['dateemin'],0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear'],'user');
 88
 89	if (! $cancel)
 90	{
 91		if (empty($label))
 92		{
 93			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")), 'errors');
 94			$action='create';
 95			$error++;
 96		}
 97		else if (empty($_POST['task_parent']))
 98		{
 99			setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("ChildOfTask")), 'errors');
100			$action='create';
101			$error++;
102		}
103
104		if (! $error)
105		{
106			$tmparray=explode('_',$_POST['task_parent']);
107			$projectid=$tmparray[0];
108			if (empty($projectid)) $projectid = $id; // If projectid is ''
109			$task_parent=$tmparray[1];
110			if (empty($task_parent)) $task_parent = 0;	// If task_parent is ''
111
112			$task = new Task($db);
113
114			$task->fk_project = $projectid;
115			$task->ref = GETPOST('ref','alpha');
116			$task->label = $label;
117			$task->description = $description;
118			$task->planned_workload = $planned_workload;
119			$task->fk_task_parent = $task_parent;
120			$task->date_c = dol_now();
121			$task->date_start = $date_start;
122			$task->date_end = $date_end;
123			$task->progress = $progress;
124
125			// Fill array 'array_options' with data from add form
126			$ret = $extrafields_task->setOptionalsFromPost($extralabels_task,$task);
127
128			$taskid = $task->create($user);
129
130			if ($taskid > 0)
131			{
132				$result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
133			}
134			else
135			{
136			    setEventMessages($task->error,$task->errors,'errors');
137			}
138		}
139
140		if (! $error)
141		{
142			if (! empty($backtopage))
143			{
144				header("Location: ".$backtopage);
145				exit;
146			}
147			else if (empty($projectid))
148			{
149				header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($mode)?'':'?mode='.$mode));
150				exit;
151			}
152			$id = $projectid;
153		}
154	}
155	else
156	{
157		if (! empty($backtopage))
158		{
159			header("Location: ".$backtopage);
160			exit;
161		}
162		else if (empty($id))
163		{
164			// We go back on task list
165			header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($mode)?'':'?mode='.$mode));
166			exit;
167		}
168	}
169}
170
171
172/*
173 * View
174 */
175
176$form=new Form($db);
177$formother=new FormOther($db);
178$taskstatic = new Task($db);
179$userstatic=new User($db);
180
181$title=$langs->trans("Project").' - '.$langs->trans("Tasks").' - '.$object->ref.' '.$object->name;
182if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->ref.' '.$object->name.' - '.$langs->trans("Tasks");
183$help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
184llxHeader("",$title,$help_url);
185
186if ($id > 0 || ! empty($ref))
187{
188	$object->fetch($id, $ref);
189	$object->fetch_thirdparty();
190	$res=$object->fetch_optionals($object->id,$extralabels_projet);
191
192
193	// To verify role of users
194	//$userAccess = $object->restrictedProjectArea($user,'read');
195	$userWrite  = $object->restrictedProjectArea($user,'write');
196	//$userDelete = $object->restrictedProjectArea($user,'delete');
197	//print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
198
199
200	$tab=GETPOST('tab')?GETPOST('tab'):'tasks';
201
202	$head=project_prepare_head($object);
203	dol_fiche_head($head, $tab, $langs->trans("Project"),0,($object->public?'projectpub':'project'));
204
205	$param=($mode=='mine'?'&mode=mine':'');
206
207	print '<table class="border" width="100%">';
208
209	$linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
210
211	// Ref
212	print '<tr><td width="30%">';
213	print $langs->trans("Ref");
214	print '</td><td>';
215	// Define a complementary filter for search of next/prev ref.
216	if (! $user->rights->projet->all->lire)
217	{
218		$projectsListId = $object->getProjectsAuthorizedForUser($user,$mine,0);
219		$object->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
220	}
221	print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '', $param);
222	print '</td></tr>';
223
224	print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';
225
226	print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
227	if (! empty($object->thirdparty->id)) print $object->thirdparty->getNomUrl(1);
228	else print '&nbsp;';
229	print '</td>';
230	print '</tr>';
231
232	// Visibility
233	print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
234	if ($object->public) print $langs->trans('SharedProject');
235	else print $langs->trans('PrivateProject');
236	print '</td></tr>';
237
238	// Statut
239	print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
240
241	// Date start
242	print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
243	print dol_print_date($object->date_start,'day');
244	print '</td></tr>';
245
246	// Date end
247	print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
248	print dol_print_date($object->date_end,'day');
249	print '</td></tr>';
250
251	// Other options
252	$parameters=array();
253	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
254	if (empty($reshook) && ! empty($extrafields_project->attribute_label))
255	{
256		print $object->showOptionals($extrafields_project);
257	}
258
259	print '</table>';
260
261	dol_fiche_end();
262}
263
264
265if ($action == 'create' && $user->rights->projet->creer && (empty($object->thirdparty->id) || $userWrite > 0))
266{
267	if ($id > 0 || ! empty($ref)) print '<br>';
268
269	print_fiche_titre($langs->trans("NewTask"), '', 'title_project');
270
271	print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
272	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
273	print '<input type="hidden" name="action" value="createtask">';
274	print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
275	if (! empty($object->id)) print '<input type="hidden" name="id" value="'.$object->id.'">';
276	if (! empty($mode)) print '<input type="hidden" name="mode" value="'.$mode.'">';
277
278	dol_fiche_head('');
279
280	print '<table class="border" width="100%">';
281
282	$defaultref='';
283	$obj = empty($conf->global->PROJECT_TASK_ADDON)?'mod_task_simple':$conf->global->PROJECT_TASK_ADDON;
284	if (! empty($conf->global->PROJECT_TASK_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.".php"))
285	{
286		require_once DOL_DOCUMENT_ROOT ."/core/modules/project/task/".$conf->global->PROJECT_TASK_ADDON.'.php';
287		$modTask = new $obj;
288		$defaultref = $modTask->getNextValue($soc,$object);
289	}
290
291	if (is_numeric($defaultref) && $defaultref <= 0) $defaultref='';
292
293	// Ref
294	print '<input type="hidden" name="ref" value="'.($_POST["ref"]?$_POST["ref"]:$defaultref).'">';
295	print '<tr><td><span class="fieldrequired">'.$langs->trans("Ref").'</span></td><td>'.($_POST["ref"]?$_POST["ref"]:$defaultref).'</td></tr>';
296
297	print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
298	print '<input type="text" size="25" name="label" class="flat" value="'.$label.'">';
299	print '</td></tr>';
300
301	// List of projects
302	print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfTask").'</td><td>';
303	print $formother->selectProjectTasks(GETPOST('task_parent'),$projectid?$projectid:$object->id, 'task_parent', 0, 0, 1, 1);
304	print '</td></tr>';
305
306	print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
307	$contactsofproject=(! empty($object->id)?$object->getListContactId('internal'):'');
308	$form->select_users($user->id,'userid',0,'',0,'',$contactsofproject);
309	print '</td></tr>';
310
311	// Date start
312	print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
313	print $form->select_date(($date_start?$date_start:''),'dateo',1,1,0,'',1,1);
314	print '</td></tr>';
315
316	// Date end
317	print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
318	print $form->select_date(($date_end?$date_end:-1),'datee',1,1,0,'',1,1);
319	print '</td></tr>';
320
321	// planned workload
322	print '<tr><td>'.$langs->trans("PlannedWorkload").'</td><td>';
323	print $form->select_duration('planned_workload', $planned_workload?$planned_workload : $object->planned_workload,0,'text');
324	print '</td></tr>';
325
326	// Progress
327	print '<tr><td>'.$langs->trans("ProgressDeclared").'</td><td colspan="3">';
328	print $formother->select_percent($progress,'progress');
329	print '</td></tr>';
330
331	// Description
332	print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
333	print '<td>';
334	print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$description.'</textarea>';
335	print '</td></tr>';
336
337	// Other options
338	$parameters=array();
339	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
340	if (empty($reshook) && ! empty($extrafields_task->attribute_label))
341	{
342		print $object->showOptionals($extrafields_task,'edit');
343	}
344
345	print '</table>';
346
347	dol_fiche_end();
348
349	print '<div align="center">';
350	print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
351	print ' &nbsp; &nbsp; ';
352	print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
353	print '</div>';
354
355	print '</form>';
356
357}
358else if ($id > 0 || ! empty($ref))
359{
360	/*
361	 * Fiche projet en mode visu
362	 */
363
364	/*
365	 * Actions
366	 */
367	print '<div class="tabsAction">';
368
369	if ($user->rights->projet->all->creer || $user->rights->projet->creer)
370	{
371		if ($object->public || $userWrite > 0)
372		{
373			print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=create'.$param.'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id).'">'.$langs->trans('AddTask').'</a>';
374		}
375		else
376		{
377			print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
378		}
379	}
380	else
381	{
382		print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('AddTask').'</a>';
383	}
384
385	print '</div>';
386
387	print '<br>';
388
389
390	// Link to switch in "my task" / "all task"
391	print '<table width="100%"><tr><td align="right">';
392	if ($mode == 'mine')
393	{
394		print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("DoNotShowMyTasksOnly").'</a>';
395		//print ' - ';
396		//print $langs->trans("ShowMyTaskOnly");
397	}
398	else
399	{
400		//print $langs->trans("DoNotShowMyTaskOnly");
401		//print ' - ';
402		print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mode=mine">'.$langs->trans("ShowMyTasksOnly").'</a>';
403	}
404	print '</td></tr></table>';
405
406	// Get list of tasks in tasksarray and taskarrayfiltered
407	// 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).
408	$tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0);
409	// We load also tasks limited to a particular user
410	$tasksrole=($mode=='mine' ? $taskstatic->getUserRolesForProjectsOrTasks(0,$user,$object->id,0) : '');
411	//var_dump($tasksarray);
412	//var_dump($tasksrole);
413
414	if (! empty($conf->use_javascript_ajax))
415	{
416		include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
417	}
418
419	print '<table id="tablelines" class="noborder" width="100%">';
420	print '<tr class="liste_titre nodrag nodrop">';
421	// print '<td>'.$langs->trans("Project").'</td>';
422	print '<td width="100">'.$langs->trans("RefTask").'</td>';
423	print '<td>'.$langs->trans("LabelTask").'</td>';
424	print '<td align="center">'.$langs->trans("DateStart").'</td>';
425	print '<td align="center">'.$langs->trans("DateEnd").'</td>';
426	print '<td align="right">'.$langs->trans("PlannedWorkload").'</td>';
427	print '<td align="right">'.$langs->trans("ProgressDeclared").'</td>';
428	print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
429	print '<td align="right">'.$langs->trans("ProgressCalculated").'</td>';
430	print '<td>&nbsp;</td>';
431	print "</tr>\n";
432	if (count($tasksarray) > 0)
433	{
434		// Show all lines in taskarray (recursive function to go down on tree)
435		$j=0; $level=0;
436		$nboftaskshown=projectLinesa($j, 0, $tasksarray, $level, true, 0, $tasksrole, $id, 1);
437	}
438	else
439	{
440		print '<tr><td colspan="9">'.$langs->trans("NoTasks").'</td></tr>';
441	}
442	print "</table>";
443
444
445	// Test if database is clean. If not we clean it.
446	//print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
447	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)
448	{
449		if ($mode=='mine')
450		{
451			if ($nboftaskshown < count($tasksrole))
452			{
453				include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
454				cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
455			}
456		}
457		else
458		{
459			if ($nboftaskshown < count($tasksarray))
460			{
461				include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
462				cleanCorruptedTree($db, 'projet_task', 'fk_task_parent');
463			}
464		}
465	}
466}
467
468llxFooter();
469
470$db->close();