PageRenderTime 166ms CodeModel.GetById 60ms app.highlight 44ms RepoModel.GetById 57ms app.codeStats 0ms

/htdocs/projet/tasks/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 456 lines | 308 code | 76 blank | 72 comment | 56 complexity | 4f9488b8b88ea704ed2a4b05b92811d9 MD5 | raw file
  1<?php
  2/* Copyright (C) 2005		Rodolphe Quiedeville	<rodolphe@quiedeville.org>
  3 * Copyright (C) 2006-2010	Laurent Destailleur		<eldy@users.sourceforge.net>
  4 * Copyright (C) 2010-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/contact.php
 22 *	\ingroup    project
 23 *	\brief      Actors of a task
 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.'/contact/class/contact.class.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
 32
 33$langs->load("projects");
 34$langs->load("companies");
 35
 36$id=GETPOST('id','int');
 37$ref=GETPOST('ref','alpha');
 38$action=GETPOST('action','alpha');
 39$confirm=GETPOST('confirm','alpha');
 40$withproject=GETPOST('withproject','int');
 41$project_ref=GETPOST('project_ref','alpha');
 42
 43// Security check
 44$socid=0;
 45if ($user->societe_id > 0) $socid = $user->societe_id;
 46//$result = restrictedArea($user, 'projet', $id, 'projet_task');
 47if (! $user->rights->projet->lire) accessforbidden();
 48
 49$object = new Task($db);
 50$projectstatic = new Project($db);
 51
 52
 53/*
 54 * Actions
 55 */
 56
 57// Add new contact
 58if ($action == 'addcontact' && $user->rights->projet->creer)
 59{
 60	$result = $object->fetch($id);
 61
 62    if ($result > 0 && $id > 0)
 63    {
 64  		$result = $object->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
 65    }
 66
 67	if ($result >= 0)
 68	{
 69		header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject?'&withproject=1':''));
 70		exit;
 71	}
 72	else
 73	{
 74		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 75		{
 76			$langs->load("errors");
 77			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 78		}
 79		else
 80		{
 81			$mesg = '<div class="error">'.$object->error.'</div>';
 82		}
 83	}
 84}
 85
 86// bascule du statut d'un contact
 87if ($action == 'swapstatut' && $user->rights->projet->creer)
 88{
 89	if ($object->fetch($id))
 90	{
 91	    $result=$object->swapContactStatus(GETPOST('ligne'));
 92	}
 93	else
 94	{
 95		dol_print_error($db);
 96	}
 97}
 98
 99// Efface un contact
100if ($action == 'deleteline' && $user->rights->projet->creer)
101{
102	$object->fetch($id);
103	$result = $object->delete_contact($_GET["lineid"]);
104
105	if ($result >= 0)
106	{
107		header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id.($withproject?'&withproject=1':''));
108		exit;
109	}
110	else
111	{
112		dol_print_error($db);
113	}
114}
115
116// Retreive First Task ID of Project if withprojet is on to allow project prev next to work
117if (! empty($project_ref) && ! empty($withproject))
118{
119	if ($projectstatic->fetch(0,$project_ref) > 0)
120	{
121		$tasksarray=$object->getTasksArray(0, 0, $projectstatic->id, $socid, 0);
122		if (count($tasksarray) > 0)
123		{
124			$id=$tasksarray[0]->id;
125		}
126		else
127		{
128			header("Location: ".DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.($withproject?'&withproject=1':'').(empty($mode)?'':'&mode='.$mode));
129			exit;
130		}
131	}
132}
133
134/*
135 * View
136 */
137
138llxHeader('', $langs->trans("Task"));
139
140$form = new Form($db);
141$formcompany   = new FormCompany($db);
142$contactstatic = new Contact($db);
143$userstatic = new User($db);
144
145
146/* *************************************************************************** */
147/*                                                                             */
148/* Mode vue et edition                                                         */
149/*                                                                             */
150/* *************************************************************************** */
151
152if ($id > 0 || ! empty($ref))
153{
154	if ($object->fetch($id) > 0)
155	{
156		$result=$projectstatic->fetch($object->fk_project);
157		if (! empty($projectstatic->socid)) $projectstatic->societe->fetch($projectstatic->socid);
158
159		$userWrite  = $projectstatic->restrictedProjectArea($user,'write');
160
161		if ($withproject)
162		{
163    		// Tabs for project
164    		$tab='tasks';
165    		$head=project_prepare_head($projectstatic);
166    		dol_fiche_head($head, $tab, $langs->trans("Project"),0,($projectstatic->public?'projectpub':'project'));
167
168    		$param=($mode=='mine'?'&mode=mine':'');
169
170    		print '<table class="border" width="100%">';
171
172    		// Ref
173    		print '<tr><td width="30%">';
174    		print $langs->trans("Ref");
175    		print '</td><td>';
176    		// Define a complementary filter for search of next/prev ref.
177    		if (! $user->rights->projet->all->lire)
178    		{
179    		    $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,0);
180    		    $projectstatic->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
181    		}
182    		print $form->showrefnav($projectstatic,'project_ref','',1,'ref','ref','',$param.'&withproject=1');
183    		print '</td></tr>';
184
185    		print '<tr><td>'.$langs->trans("Label").'</td><td>'.$projectstatic->title.'</td></tr>';
186
187    		print '<tr><td>'.$langs->trans("Company").'</td><td>';
188    		if (! empty($projectstatic->societe->id)) print $projectstatic->societe->getNomUrl(1);
189    		else print '&nbsp;';
190    		print '</td>';
191    		print '</tr>';
192
193    		// Visibility
194    		print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
195    		if ($projectstatic->public) print $langs->trans('SharedProject');
196    		else print $langs->trans('PrivateProject');
197    		print '</td></tr>';
198
199    		// Statut
200    		print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projectstatic->getLibStatut(4).'</td></tr>';
201
202    		print '</table>';
203
204    		dol_fiche_end();
205
206    		print '<br>';
207		}
208
209		// To verify role of users
210		//$userAccess = $projectstatic->restrictedProjectArea($user); // We allow task affected to user even if a not allowed project
211		//$arrayofuseridoftask=$object->getListContactId('internal');
212
213		dol_htmloutput_mesg($mesg);
214
215		$head = task_prepare_head($object);
216		dol_fiche_head($head, 'task_contact', $langs->trans("Task"), 0, 'projecttask');
217
218
219		/*
220		 *   Projet synthese pour rappel
221		 */
222		print '<table class="border" width="100%">';
223
224		$param=(GETPOST('withproject')?'&withproject=1':'');
225		$linkback=GETPOST('withproject')?'<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$projectstatic->id.'">'.$langs->trans("BackToList").'</a>':'';
226
227		// Ref
228		print '<tr><td width="30%">'.$langs->trans('Ref').'</td><td colspan="3">';
229		if (! GETPOST('withproject') || empty($projectstatic->id))
230		{
231		    $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,$mine,1);
232		    $object->next_prev_filter=" fk_projet in (".$projectsListId.")";
233		}
234		else $object->next_prev_filter=" fk_projet = ".$projectstatic->id;
235	    print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param);
236		print '</td></tr>';
237
238		// Label
239		print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
240
241		// Project
242		if (empty($withproject))
243		{
244    		print '<tr><td>'.$langs->trans("Project").'</td><td>';
245    		print $projectstatic->getNomUrl(1);
246    		print '</td></tr>';
247
248    		// Customer
249    		print "<tr><td>".$langs->trans("Company")."</td>";
250    		print '<td colspan="3">';
251    		if ($projectstatic->societe->id > 0) print $projectstatic->societe->getNomUrl(1);
252    		else print '&nbsp;';
253    		print '</td></tr>';
254		}
255
256		print "</table>";
257
258		dol_fiche_end();
259
260		/*
261		 * Lignes de contacts
262		 */
263		print '<br><table class="noborder" width="100%">';
264
265		/*
266		 * Ajouter une ligne de contact
267		 * Non affiche en mode modification de ligne
268		 */
269		if ($action != 'editline' && $user->rights->projet->creer)
270		{
271			print '<tr class="liste_titre">';
272			print '<td>'.$langs->trans("Source").'</td>';
273			print '<td>'.$langs->trans("Company").'</td>';
274			print '<td>'.$langs->trans("ProjectContact").'</td>';
275			print '<td>'.$langs->trans("ContactType").'</td>';
276			print '<td colspan="3">&nbsp;</td>';
277			print "</tr>\n";
278
279			$var = false;
280
281			print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="POST">';
282			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
283			print '<input type="hidden" name="action" value="addcontact">';
284			print '<input type="hidden" name="source" value="internal">';
285			print '<input type="hidden" name="id" value="'.$id.'">';
286			print '<input type="hidden" name="withproject" value="'.$withproject.'">';
287
288			// Ligne ajout pour contact interne
289			print "<tr $bc[$var]>";
290
291			print '<td nowrap="nowrap">';
292			print img_object('','user').' '.$langs->trans("Users");
293			print '</td>';
294
295			print '<td colspan="1">';
296			print $conf->global->MAIN_INFO_SOCIETE_NOM;
297			print '</td>';
298
299			print '<td colspan="1">';
300			// On recupere les id des users deja selectionnes
301			$contactsofproject=$projectstatic->getListContactId('internal');
302			$form->select_users($user->id,'contactid',0,'',0,'',$contactsofproject);
303			print '</td>';
304			print '<td>';
305			$formcompany->selectTypeContact($object, '', 'type','internal','rowid');
306			print '</td>';
307			print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
308			print '</tr>';
309
310			print '</form>';
311
312			// Line to add an external contact. Only if project linked to a third party.
313			if ($projectstatic->socid)
314			{
315				print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
316				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
317				print '<input type="hidden" name="action" value="addcontact">';
318				print '<input type="hidden" name="source" value="external">';
319				print '<input type="hidden" name="id" value="'.$object->id.'">';
320
321				$var=!$var;
322				print "<tr $bc[$var]>";
323
324				print '<td nowrap="nowrap">';
325				print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
326				print '</td>';
327
328				print '<td colspan="1">';
329				$thirdpartyofproject=$projectstatic->getListContactId('thirdparty');
330				$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$projectstatic->societe->id;
331				$selectedCompany = $formcompany->selectCompaniesForNewContact($object, 'id', $selectedCompany, 'newcompany',$thirdpartyofproject);
332				print '</td>';
333
334				print '<td colspan="1">';
335				$contactofproject=$projectstatic->getListContactId('external');
336				$nbofcontacts=$form->select_contacts($selectedCompany,'','contactid',0,'',$contactofproject);
337				if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
338				print '</td>';
339				print '<td>';
340				$formcompany->selectTypeContact($object, '', 'type','external','rowid');
341				print '</td>';
342				print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
343				if (! $nbofcontacts) print ' disabled="disabled"';
344				print '></td>';
345				print '</tr>';
346
347				print "</form>";
348			}
349		}
350
351		// Liste des contacts lies
352		print '<tr class="liste_titre">';
353		print '<td>'.$langs->trans("Source").'</td>';
354		print '<td>'.$langs->trans("Company").'</td>';
355		print '<td>'.$langs->trans("ProjectContact").'</td>';
356		print '<td>'.$langs->trans("ContactType").'</td>';
357		print '<td align="center">'.$langs->trans("Status").'</td>';
358		print '<td colspan="2">&nbsp;</td>';
359		print "</tr>\n";
360
361		$companystatic = new Societe($db);
362		$var = true;
363
364		foreach(array('internal','external') as $source)
365		{
366			$tab = $object->liste_contact(-1,$source);
367			$num=count($tab);
368
369			$i = 0;
370			while ($i < $num)
371			{
372				$var = !$var;
373
374				print '<tr '.$bc[$var].' valign="top">';
375
376				// Source
377				print '<td align="left">';
378				if ($tab[$i]['source']=='internal') print $langs->trans("User");
379				if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
380				print '</td>';
381
382				// Societe
383				print '<td align="left">';
384				if ($tab[$i]['socid'] > 0)
385				{
386					$companystatic->fetch($tab[$i]['socid']);
387					print $companystatic->getNomUrl(1);
388				}
389				if ($tab[$i]['socid'] < 0)
390				{
391					print $conf->global->MAIN_INFO_SOCIETE_NOM;
392				}
393				if (! $tab[$i]['socid'])
394				{
395					print '&nbsp;';
396				}
397				print '</td>';
398
399				// Contact
400				print '<td>';
401                if ($tab[$i]['source']=='internal')
402                {
403                    $userstatic->id=$tab[$i]['id'];
404                    $userstatic->lastname=$tab[$i]['lastname'];
405                    $userstatic->firstname=$tab[$i]['firstname'];
406                    print $userstatic->getNomUrl(1);
407                }
408                if ($tab[$i]['source']=='external')
409                {
410                    $contactstatic->id=$tab[$i]['id'];
411                    $contactstatic->lastname=$tab[$i]['lastname'];
412                    $contactstatic->firstname=$tab[$i]['firstname'];
413                    print $contactstatic->getNomUrl(1);
414                }
415				print '</td>';
416
417				// Type de contact
418				print '<td>'.$tab[$i]['libelle'].'</td>';
419
420				// Statut
421				print '<td align="center">';
422				// Activation desativation du contact
423				if ($object->statut >= 0) print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=swapstatut&ligne='.$tab[$i]['rowid'].($withproject?'&withproject=1':'').'">';
424				print $contactstatic->LibStatut($tab[$i]['status'],3);
425				if ($object->statut >= 0) print '</a>';
426				print '</td>';
427
428				// Icon update et delete
429				print '<td align="center" nowrap>';
430				if ($user->rights->projet->creer)
431				{
432					print '&nbsp;';
433					print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deleteline&lineid='.$tab[$i]['rowid'].($withproject?'&withproject=1':'').'">';
434					print img_delete();
435					print '</a>';
436				}
437				print '</td>';
438
439				print "</tr>\n";
440
441				$i ++;
442			}
443		}
444		print "</table>";
445	}
446	else
447	{
448		print "ErrorRecordNotFound";
449	}
450}
451
452
453llxFooter();
454
455$db->close();
456?>