PageRenderTime 63ms CodeModel.GetById 48ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/projet/tasks.php

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