PageRenderTime 34ms CodeModel.GetById 1ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/projet/tasks.php

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