PageRenderTime 2ms CodeModel.GetById 36ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/projet/tasks.php

https://github.com/asterix14/dolibarr
PHP | 346 lines | 222 code | 62 blank | 62 comment | 42 complexity | 6c5a686ba72c01a84ec4d832ab0d9d32 MD5 | raw file
  1<?php
  2/* Copyright (C) 2005      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2005-2010 Regis Houssin        <regis@dolibarr.fr>
  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 2 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");
 32
 33$mine = $_REQUEST['mode']=='mine' ? 1 : 0;
 34//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
 35
 36// Security check
 37$socid=0;
 38if ($user->societe_id > 0) $socid = $user->societe_id;
 39//$result = restrictedArea($user, 'projet', $projectid);
 40if (!$user->rights->projet->lire) accessforbidden();
 41
 42$langs->load("users");
 43$langs->load("projects");
 44
 45$progress=GETPOST('progress');
 46$description=GETPOST('description');
 47
 48$userAccess=0;
 49
 50
 51/*
 52 * Actions
 53 */
 54
 55if ($_POST["action"] == 'createtask' && $user->rights->projet->creer)
 56{
 57	$error=0;
 58
 59	$date_start = dol_mktime(12,0,0,$_POST['dateomonth'],$_POST['dateoday'],$_POST['dateoyear']);
 60    $date_end = dol_mktime(12,0,0,$_POST['dateemonth'],$_POST['dateeday'],$_POST['dateeyear']);
 61
 62	if (empty($_POST["cancel"]))
 63	{
 64		if (empty($_POST['label']))
 65		{
 66			$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"));
 67			$_GET["action"]='create';
 68			$error++;
 69		}
 70		else if (empty($_POST['task_parent']))
 71		{
 72			$mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("ChildOfTask"));
 73			$_GET["action"]='create';
 74			$error++;
 75		}
 76
 77		if (! $error)
 78		{
 79			$tmparray=explode('_',$_POST['task_parent']);
 80			$projectid=$tmparray[0];
 81			if (empty($projectid)) $projectid = $_POST["id"]; // If projectid is ''
 82			$task_parent=$tmparray[1];
 83			if (empty($task_parent)) $task_parent = 0;	// If task_parent is ''
 84
 85			$task = new Task($db);
 86
 87			$task->fk_project = $projectid;
 88			$task->label = $_POST["label"];
 89			$task->description = $_POST['description'];
 90			$task->fk_task_parent = $task_parent;
 91			$task->date_c = dol_now();
 92			$task->date_start = $date_start;
 93			$task->date_end = $date_end;
 94			$task->progress = $_POST['progress'];
 95
 96			$taskid = $task->create($user);
 97
 98			if ($taskid > 0)
 99			{
100				$result = $task->add_contact($_POST["userid"], 'TASKEXECUTIVE', 'internal');
101			}
102		}
103
104		if (! $error)
105		{
106			if (empty($projectid))
107			{
108				Header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($_REQUEST["mode"])?'':'?mode='.$_REQUEST["mode"]));
109				exit;
110			}
111			else
112			{
113				Header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$taskid);
114				exit;
115			}
116		}
117	}
118	else
119	{
120        if (empty($_GET["id"]) && empty($_POST["id"]))
121        {
122            // We go back on task list
123            Header("Location: ".DOL_URL_ROOT.'/projet/tasks/index.php'.(empty($_REQUEST["mode"])?'':'?mode='.$_REQUEST["mode"]));
124            exit;
125        }
126	}
127}
128
129/*
130 * View
131 */
132
133$form=new Form($db);
134$formother=new FormOther($db);
135
136$help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
137llxHeader("",$langs->trans("Tasks"),$help_url);
138
139$task = new Task($db);
140
141$id = (! empty($_GET['id']))?$_GET['id']:$_POST['id'];
142$ref= $_GET['ref'];
143if ($id > 0 || ! empty($ref))
144{
145	$project = new Project($db);
146	$project->fetch($_REQUEST["id"],$_GET["ref"]);
147	if ($project->societe->id > 0)  $result=$project->societe->fetch($project->societe->id);
148
149	// To verify role of users
150	$userAccess = $project->restrictedProjectArea($user);
151}
152
153if ($_GET["action"] == 'create' && $user->rights->projet->creer && (empty($project->societe->id) || $userAccess))
154{
155	print_fiche_titre($langs->trans("NewTask"));
156
157	dol_htmloutput_errors($mesg);
158
159	print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
160	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
161	print '<input type="hidden" name="action" value="createtask">';
162	if ($_GET['id'])   print '<input type="hidden" name="id" value="'.$_GET['id'].'">';
163	if ($_GET['mode']) print '<input type="hidden" name="mode" value="'.$_GET['mode'].'">';
164
165	print '<table class="border" width="100%">';
166
167	print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td>';
168	print '<input type="text" size="25" name="label" class="flat" value="'.$_POST["label"].'">';
169	print '</td></tr>';
170
171	// List of projects
172	print '<tr><td class="fieldrequired">'.$langs->trans("ChildOfTask").'</td><td>';
173	print $formother->selectProjectTasks('',$projectid?$projectid:$_GET["id"], 'task_parent', 0, 0, 1, 1);
174	print '</td></tr>';
175
176	print '<tr><td>'.$langs->trans("AffectedTo").'</td><td>';
177	print $form->select_users($user->id,'userid',1);
178	print '</td></tr>';
179
180	// Date start
181	print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
182	print $form->select_date(($date_start?$date_start:''),'dateo',0,0,0,'',1,1);
183	print '</td></tr>';
184
185	// Date end
186	print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
187	print $form->select_date(($date_end?$date_end:-1),'datee',0,0,0,'',1,1);
188	print '</td></tr>';
189
190	// Progress
191	print '<tr><td>'.$langs->trans("Progress").'</td><td colspan="3">';
192	print $formother->select_percent($progress,'progress');
193	print '</td></tr>';
194
195	// Description
196	print '<tr><td valign="top">'.$langs->trans("Description").'</td>';
197	print '<td>';
198	print '<textarea name="description" wrap="soft" cols="80" rows="'.ROWS_3.'">'.$description.'</textarea>';
199	print '</td></tr>';
200
201	print '</table>';
202	
203	print '<center><br>';
204	print '<input type="submit" class="button" name="add" value="'.$langs->trans("Add").'">';
205	print ' &nbsp; &nbsp; ';
206	print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
207	print '</center>';
208
209	print '</form>';
210
211}
212else
213{
214	/*
215	 * Fiche projet en mode visu
216	 */
217	$userstatic=new User($db);
218
219	$tab='tasks';
220
221	$head=project_prepare_head($project);
222	dol_fiche_head($head, $tab, $langs->trans("Project"),0,($project->public?'projectpub':'project'));
223
224	$param=($_REQUEST["mode"]=='mine'?'&mode=mine':'');
225
226	print '<table class="border" width="100%">';
227
228	// Ref
229	print '<tr><td width="30%">';
230	print $langs->trans("Ref");
231	print '</td><td>';
232	// Define a complementary filter for search of next/prev ref.
233	$projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
234	$project->next_prev_filter=" rowid in (".$projectsListId.")";
235	print $form->showrefnav($project,'ref','',1,'ref','ref','',$param);
236	print '</td></tr>';
237
238	print '<tr><td>'.$langs->trans("Label").'</td><td>'.$project->title.'</td></tr>';
239
240	print '<tr><td>'.$langs->trans("Company").'</td><td>';
241	if (! empty($project->societe->id)) print $project->societe->getNomUrl(1);
242	else print '&nbsp;';
243	print '</td>';
244	print '</tr>';
245
246	// Visibility
247	print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
248	if ($project->public) print $langs->trans('SharedProject');
249	else print $langs->trans('PrivateProject');
250	print '</td></tr>';
251
252	// Statut
253	print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
254
255	print '</table>';
256
257	print '</div>';
258
259	/*
260	 * Actions
261	 */
262	print '<div class="tabsAction">';
263
264	if ($user->rights->projet->all->creer || $user->rights->projet->creer)
265	{
266		if ($project->public || $userAccess)
267		{
268			print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$project->id.'&action=create'.$param.'">'.$langs->trans('AddTask').'</a>';
269		}
270		else
271		{
272			print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('AddTask').'</a>';
273		}
274	}
275	else
276	{
277		print '<a class="butActionRefused" href="#" title="'.$langs->trans("NoPermission").'">'.$langs->trans('AddTask').'</a>';
278	}
279
280	print '</div>';
281
282	print '<br>';
283
284
285	// Link to switch in "my task" / "all task"
286	print '<table width="100%"><tr><td align="right">';
287	if ($_REQUEST["mode"] == 'mine')
288	{
289		print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'">'.$langs->trans("DoNotShowMyTasksOnly").'</a>';
290		//print ' - ';
291		//print $langs->trans("ShowMyTaskOnly");
292	}
293	else
294	{
295		//print $langs->trans("DoNotShowMyTaskOnly");
296		//print ' - ';
297		print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$project->id.'&mode=mine">'.$langs->trans("ShowMyTasksOnly").'</a>';
298	}
299	print '</td></tr></table>';
300
301	// Get list of tasks in tasksarray and taskarrayfiltered
302	// We need all tasks (even not limited to a user because a task to user
303	// can have a parent that is not affected to him).
304	$tasksarray=$task->getTasksArray(0, 0, $project->id, $socid, 0);
305	// We load also tasks limited to a particular user
306	$tasksrole=($_REQUEST["mode"]=='mine' ? $task->getUserRolesForProjectsOrTasks(0,$user,$project->id,0) : '');
307	//var_dump($tasksarray);
308	//var_dump($tasksrole);
309
310	print '<table class="noborder" width="100%">';
311	print '<tr class="liste_titre">';
312	if ($projectstatic->id) print '<td>'.$langs->trans("Project").'</td>';
313	print '<td width="80">'.$langs->trans("RefTask").'</td>';
314	print '<td>'.$langs->trans("LabelTask").'</td>';
315	print '<td align="right">'.$langs->trans("Progress").'</td>';
316	print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
317	print "</tr>\n";
318	if (count($tasksarray) > 0)
319	{
320		// Show all lines in taskarray (recursive function to go down on tree)
321		$j=0;
322		$nboftaskshown=PLines($j, 0, $tasksarray, $level, true, 0, $tasksrole);
323	}
324	else
325	{
326		print '<tr><td colspan="'.($projectstatic->id?"5":"4").'">'.$langs->trans("NoTasks").'</td></tr>';
327	}
328	print "</table>";
329
330
331	// Test if database is clean. If not we clean it.
332	//print 'mode='.$_REQUEST["mode"].' $nboftaskshown='.$nboftaskshown.' count($tasksarray)='.count($tasksarray).' count($tasksrole)='.count($tasksrole).'<br>';
333	if ($_REQUEST["mode"]=='mine')
334	{
335		if ($nboftaskshown < count($tasksrole)) clean_orphelins($db);
336	}
337	else
338	{
339		if ($nboftaskshown < count($tasksarray)) clean_orphelins($db);
340	}
341}
342
343$db->close();
344
345llxFooter();
346?>