PageRenderTime 187ms CodeModel.GetById 100ms app.highlight 20ms RepoModel.GetById 61ms app.codeStats 0ms

/htdocs/expedition/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 426 lines | 296 code | 70 blank | 60 comment | 70 complexity | 81571d0d6d6ca0b5abc6ccc89f060bd9 MD5 | raw file
  1<?php
  2/* Copyright (C) 2005      Patrick Rouillon     <patrick@rouillon.net>
  3 * Copyright (C) 2005-2011 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/expedition/contact.php
 22 *     \ingroup    expedition
 23 *     \brief      Onglet de gestion des contacts de expedition
 24 */
 25
 26require '../main.inc.php';
 27require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
 28require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
 29require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
 32
 33$langs->load("orders");
 34$langs->load("sendings");
 35$langs->load("companies");
 36
 37$id=GETPOST('id','int');
 38$ref=GETPOST('ref','alpha');
 39$action=GETPOST('action','alpha');
 40
 41// Security check
 42if ($user->societe_id) $socid=$user->societe_id;
 43$result = restrictedArea($user, 'expedition', $id,'');
 44
 45$object = new Expedition($db);
 46if ($id > 0 || ! empty($ref))
 47{
 48    $object->fetch($id, $ref);
 49
 50    if (!empty($object->origin))
 51    {
 52        $typeobject = $object->origin;
 53        $origin = $object->origin;
 54        $object->fetch_origin();
 55    }
 56
 57    // Linked documents
 58    if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
 59    {
 60        $objectsrc=new Commande($db);
 61        $objectsrc->fetch($object->$typeobject->id);
 62    }
 63    if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
 64    {
 65        $objectsrc=new Propal($db);
 66        $objectsrc->fetch($object->$typeobject->id);
 67    }
 68}
 69
 70
 71/*
 72 * Actions
 73 */
 74
 75if ($action == 'addcontact' && $user->rights->expedition->creer)
 76{
 77    if ($result > 0 && $id > 0)
 78    {
 79  		$result = $objectsrc->add_contact($_POST["contactid"], $_POST["type"], $_POST["source"]);
 80    }
 81
 82	if ($result >= 0)
 83	{
 84		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 85		exit;
 86	}
 87	else
 88	{
 89		if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 90		{
 91			$langs->load("errors");
 92			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 93		}
 94		else
 95		{
 96			$mesg = '<div class="error">'.$objectsrc->error.'</div>';
 97		}
 98	}
 99}
100
101// bascule du statut d'un contact
102else if ($action == 'swapstatut' && $user->rights->expedition->creer)
103{
104    $result=$objectsrc->swapContactStatus(GETPOST('ligne'));
105}
106
107// Efface un contact
108else if ($action == 'deleteline' && $user->rights->expedition->creer)
109{
110	$result = $objectsrc->delete_contact($_GET["lineid"]);
111
112	if ($result >= 0)
113	{
114		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
115		exit;
116	}
117	else {
118		dol_print_error($db);
119	}
120}
121
122else if ($action == 'setaddress' && $user->rights->expedition->creer)
123{
124	$object->fetch($id);
125	$result=$object->setDeliveryAddress($_POST['fk_address']);
126	if ($result < 0) dol_print_error($db,$object->error);
127}
128
129
130/*
131 * View
132 */
133
134llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
135
136$form = new Form($db);
137$formcompany = new FormCompany($db);
138$formother = new FormOther($db);
139$contactstatic=new Contact($db);
140$userstatic=new User($db);
141
142
143/* *************************************************************************** */
144/*                                                                             */
145/* Mode vue et edition                                                         */
146/*                                                                             */
147/* *************************************************************************** */
148dol_htmloutput_mesg($mesg);
149
150if ($id > 0 || ! empty($ref))
151{
152	$langs->trans("OrderCard");
153
154	$soc = new Societe($db);
155	$soc->fetch($object->socid);
156
157
158	$head = shipping_prepare_head($object);
159	dol_fiche_head($head, 'contact', $langs->trans("Sending"), 0, 'sending');
160
161	if (is_null($object->client))	$object->fetch_thirdparty();
162
163   /*
164	*   Facture synthese pour rappel
165	*/
166	print '<table class="border" width="100%">';
167
168	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/liste.php">'.$langs->trans("BackToList").'</a>';
169
170	// Ref
171	print '<tr><td width="18%">'.$langs->trans("Ref").'</td><td colspan="3">';
172	print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
173	print "</td></tr>";
174
175	// Customer
176	print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
177	print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
178	print "</tr>";
179
180	// Linked documents
181	if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
182	{
183		print '<tr><td>';
184		$objectsrc=new Commande($db);
185		$objectsrc->fetch($object->$typeobject->id);
186		print $langs->trans("RefOrder").'</td>';
187		print '<td colspan="3">';
188		print $objectsrc->getNomUrl(1,'commande');
189		print "</td>\n";
190		print '</tr>';
191	}
192	if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
193	{
194		print '<tr><td>';
195		$objectsrc=new Propal($db);
196		$objectsrc->fetch($object->$typeobject->id);
197		print $langs->trans("RefProposal").'</td>';
198		print '<td colspan="3">';
199		print $objectsrc->getNomUrl(1,'expedition');
200		print "</td>\n";
201		print '</tr>';
202	}
203
204	// Ref expedition client
205	print '<tr><td>';
206    print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
207	print $langs->trans('RefCustomer').'</td><td align="left">';
208    print '</td>';
209    print '</tr></table>';
210    print '</td><td colspan="3">';
211	print $objectsrc->ref_client;
212	print '</td>';
213	print '</tr>';
214	
215	// Delivery address
216	if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
217	{
218		print '<tr><td>';
219		print '<table class="nobordernopadding" width="100%"><tr><td>';
220		print $langs->trans('DeliveryAddress');
221		print '</td>';
222	
223		if ($action != 'editdelivery_address' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdelivery_address&amp;socid='.$object->socid.'&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryAddress'),1).'</a></td>';
224		print '</tr></table>';
225		print '</td><td colspan="3">';
226	
227		if ($action == 'editdelivery_address')
228		{
229			$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'fk_address','shipping',$object->id);
230		}
231		else
232		{
233			$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'none','shipping',$object->id);
234		}
235		print '</td></tr>';
236	}
237
238	print "</table>";
239
240	print '</div>';
241
242	// Lignes de contacts
243	echo '<br><table class="noborder" width="100%">';
244
245	/*
246	 * Ajouter une ligne de contact. Non affiche en mode modification de ligne
247	 */
248	if ($action != 'editline' && $user->rights->expedition->creer)
249	{
250		print '<tr class="liste_titre">';
251		print '<td>'.$langs->trans("Source").'</td>';
252		print '<td>'.$langs->trans("Company").'</td>';
253		print '<td>'.$langs->trans("Contacts").'</td>';
254		print '<td>'.$langs->trans("ContactType").'</td>';
255		print '<td>&nbsp;</td>';
256		print '<td colspan="2">&nbsp;</td>';
257		print "</tr>\n";
258
259		$var = false;
260
261		print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
262		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
263		print '<input type="hidden" name="action" value="addcontact">';
264		print '<input type="hidden" name="source" value="internal">';
265		print '<input type="hidden" name="id" value="'.$id.'">';
266
267		// Ligne ajout pour contact interne
268		print '<tr '.$bc[$var].'>';
269
270		print '<td nowrap="nowrap">';
271		print img_object('','user').' '.$langs->trans("Users");
272		print '</td>';
273
274		print '<td colspan="1">';
275		print $conf->global->MAIN_INFO_SOCIETE_NOM;
276		print '</td>';
277
278		print '<td colspan="1">';
279		//$userAlreadySelected = $object->getListContactId('internal');	// On ne doit pas desactiver un contact deja selectionne car on doit pouvoir le selectionner une deuxieme fois pour un autre type
280		$form->select_users($user->id,'contactid',0,$userAlreadySelected);
281		print '</td>';
282		print '<td>';
283		$formcompany->selectTypeContact($objectsrc, '', 'type','internal');
284		print '</td>';
285		print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
286		print '</tr>';
287
288		print '</form>';
289
290		print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="post">';
291		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
292		print '<input type="hidden" name="action" value="addcontact">';
293		print '<input type="hidden" name="source" value="external">';
294		print '<input type="hidden" name="id" value="'.$id.'">';
295
296		// Ligne ajout pour contact externe
297		$var=!$var;
298		print '<tr '.$bc[$var].'>';
299
300		print '<td nowrap="nowrap">';
301		print img_object('','contact').' '.$langs->trans("ThirdPartyContacts");
302		print '</td>';
303
304		print '<td colspan="1">';
305		$selectedCompany = isset($_GET["newcompany"])?$_GET["newcompany"]:$object->client->id;
306		$selectedCompany = $formcompany->selectCompaniesForNewContact($objectsrc, 'id', $selectedCompany, 'newcompany', '', $object->id);
307		print '</td>';
308
309		print '<td colspan="1">';
310		$nbofcontacts=$form->select_contacts($selectedCompany, '', 'contactid');
311		if ($nbofcontacts == 0) print $langs->trans("NoContactDefined");
312		print '</td>';
313		print '<td>';
314
315		$formcompany->selectTypeContact($objectsrc, '', 'type','external');
316		print '</td>';
317		print '<td align="right" colspan="3" ><input type="submit" class="button" value="'.$langs->trans("Add").'"';
318		if (! $nbofcontacts) print ' disabled="disabled"';
319		print '></td>';
320		print '</tr>';
321
322		print "</form>";
323
324		print '<tr><td colspan="7">&nbsp;</td></tr>';
325	}
326
327	// List of linked contacts
328	print '<tr class="liste_titre">';
329	print '<td>'.$langs->trans("Source").'</td>';
330	print '<td>'.$langs->trans("Company").'</td>';
331	print '<td>'.$langs->trans("Contacts").'</td>';
332	print '<td>'.$langs->trans("ContactType").'</td>';
333	print '<td align="center">'.$langs->trans("Status").'</td>';
334	print '<td colspan="2">&nbsp;</td>';
335	print "</tr>\n";
336
337	$companystatic=new Societe($db);
338	$var = true;
339
340	foreach(array('internal','external') as $source)
341	{
342		$tab = $objectsrc->liste_contact(-1,$source);
343		$num=count($tab);
344
345		$i = 0;
346		while ($i < $num)
347		{
348			$var = !$var;
349
350			print '<tr '.$bc[$var].' valign="top">';
351
352			// Source
353			print '<td align="left">';
354			if ($tab[$i]['source']=='internal') print $langs->trans("User");
355			if ($tab[$i]['source']=='external') print $langs->trans("ThirdPartyContact");
356			print '</td>';
357
358			// Societe
359			print '<td align="left">';
360			if ($tab[$i]['socid'] > 0)
361			{
362				$companystatic->fetch($tab[$i]['socid']);
363				print $companystatic->getNomUrl(1);
364			}
365			if ($tab[$i]['socid'] < 0)
366			{
367				print $conf->global->MAIN_INFO_SOCIETE_NOM;
368			}
369			if (! $tab[$i]['socid'])
370			{
371				print '&nbsp;';
372			}
373			print '</td>';
374
375			// Contact
376			print '<td>';
377            if ($tab[$i]['source']=='internal')
378            {
379                $userstatic->id=$tab[$i]['id'];
380                $userstatic->lastname=$tab[$i]['lastname'];
381                $userstatic->firstname=$tab[$i]['firstname'];
382                print $userstatic->getNomUrl(1);
383            }
384            if ($tab[$i]['source']=='external')
385            {
386                $contactstatic->id=$tab[$i]['id'];
387                $contactstatic->lastname=$tab[$i]['lastname'];
388                $contactstatic->firstname=$tab[$i]['firstname'];
389                print $contactstatic->getNomUrl(1);
390            }
391			print '</td>';
392
393			// Type de contact
394			print '<td>'.$tab[$i]['libelle'].'</td>';
395
396			// Statut
397			print '<td align="center">';
398			// Activation desativation du contact
399			if ($object->statut >= 0)	print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=swapstatut&amp;ligne='.$tab[$i]['rowid'].'">';
400			print $contactstatic->LibStatut($tab[$i]['status'],3);
401			if ($object->statut >= 0)	print '</a>';
402			print '</td>';
403
404			// Icon update et delete
405			print '<td align="center" nowrap="nowrap" colspan="2">';
406			if ($object->statut < 5 && $user->rights->expedition->creer)
407			{
408				print '&nbsp;';
409				print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;lineid='.$tab[$i]['rowid'].'">';
410				print img_delete();
411				print '</a>';
412			}
413			print '</td>';
414
415			print "</tr>\n";
416
417			$i ++;
418		}
419	}
420	print "</table>";
421}
422
423llxFooter();
424
425$db->close();
426?>