PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/commande/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 227 lines | 142 code | 39 blank | 46 comment | 36 complexity | dbd3f1d573e5fbcf5558f3fb451c8bf5 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 * Copyright (C) 2011-2012 Philippe Grand       <philippe.grand@atoo-net.com>
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License as published by
  9 * the Free Software Foundation; either version 3 of the License, or
 10 * (at your option) any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21/**
 22 *     \file       htdocs/commande/contact.php
 23 *     \ingroup    commande
 24 *     \brief      Onglet de gestion des contacts de commande
 25 */
 26
 27require '../main.inc.php';
 28require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
 29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
 31require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
 32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
 33
 34$langs->load("orders");
 35$langs->load("sendings");
 36$langs->load("companies");
 37
 38$id=GETPOST('id','int');
 39$ref=GETPOST('ref','alpha');
 40$action=GETPOST('action','alpha');
 41
 42// Security check
 43if ($user->societe_id) $socid=$user->societe_id;
 44$result = restrictedArea($user, 'commande', $id,'');
 45
 46$object = new Commande($db);
 47
 48/*
 49 * Ajout d'un nouveau contact
 50 */
 51
 52if ($action == 'addcontact' && $user->rights->commande->creer)
 53{
 54	$result = $object->fetch($id);
 55
 56    if ($result > 0 && $id > 0)
 57    {
 58    	$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
 59  		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
 60    }
 61
 62	if ($result >= 0)
 63	{
 64		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 65		exit;
 66	}
 67	else
 68	{
 69		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 70		{
 71			$langs->load("errors");
 72			$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 73		}
 74		else
 75		{
 76			$mesg = '<div class="error">'.$object->error.'</div>';
 77		}
 78	}
 79}
 80
 81// bascule du statut d'un contact
 82else if ($action == 'swapstatut' && $user->rights->commande->creer)
 83{
 84	if ($object->fetch($id))
 85	{
 86	    $result=$object->swapContactStatus(GETPOST('ligne'));
 87	}
 88	else
 89	{
 90		dol_print_error($db);
 91	}
 92}
 93
 94// Efface un contact
 95else if ($action == 'deletecontact' && $user->rights->commande->creer)
 96{
 97	$object->fetch($id);
 98	$result = $object->delete_contact($_GET["lineid"]);
 99
100	if ($result >= 0)
101	{
102		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
103		exit;
104	}
105	else {
106		dol_print_error($db);
107	}
108}
109
110else if ($action == 'setaddress' && $user->rights->commande->creer)
111{
112	$object->fetch($id);
113	$result=$object->setDeliveryAddress($_POST['fk_address']);
114	if ($result < 0) dol_print_error($db,$object->error);
115}
116
117/*
118 * View
119 */
120
121llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
122
123$form = new Form($db);
124$formcompany = new FormCompany($db);
125$formother = new FormOther($db);
126$contactstatic=new Contact($db);
127$userstatic=new User($db);
128
129
130/* *************************************************************************** */
131/*                                                                             */
132/* Mode vue et edition                                                         */
133/*                                                                             */
134/* *************************************************************************** */
135dol_htmloutput_mesg($mesg);
136
137if ($id > 0 || ! empty($ref))
138{
139	$langs->trans("OrderCard");
140
141	if ($object->fetch($id, $ref) > 0)
142	{
143		$soc = new Societe($db);
144		$soc->fetch($object->socid);
145
146
147		$head = commande_prepare_head($object);
148		dol_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), 0, 'order');
149
150
151	   /*
152		*   Facture synthese pour rappel
153		*/
154		print '<table class="border" width="100%">';
155
156		$linkback = '<a href="'.DOL_URL_ROOT.'/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
157
158		// Ref
159		print '<tr><td width="18%">'.$langs->trans("Ref").'</td><td colspan="3">';
160		print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
161		print "</td></tr>";
162
163		// Ref commande client
164		print '<tr><td>';
165        print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
166		print $langs->trans('RefCustomer').'</td><td align="left">';
167        print '</td>';
168        print '</tr></table>';
169        print '</td><td colspan="3">';
170		print $object->ref_client;
171		print '</td>';
172		print '</tr>';
173
174		// Customer
175		if (is_null($object->client))	$object->fetch_thirdparty();
176
177		print "<tr><td>".$langs->trans("Company")."</td>";
178		print '<td colspan="3">'.$object->client->getNomUrl(1).'</td></tr>';
179
180		// Delivery address
181		if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
182		{
183			print '<tr><td>';
184			print '<table class="nobordernopadding" width="100%"><tr><td>';
185			print $langs->trans('DeliveryAddress');
186			print '</td>';
187
188			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>';
189			print '</tr></table>';
190			print '</td><td colspan="3">';
191
192			if ($action == 'editdelivery_address')
193			{
194				$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,GETPOST('socid','int'),'fk_address','commande',$object->id);
195			}
196			else
197			{
198				$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,GETPOST('socid','int'),'none','commande',$object->id);
199			}
200			print '</td></tr>';
201		}
202
203		print "</table>";
204
205		print '</div>';
206
207		print '<br>';
208
209		// Contacts lines (modules that overwrite templates must declare this into descriptor)
210		$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
211		foreach($dirtpls as $reldir)
212		{
213		    $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
214		    if ($res) break;
215		}
216	}
217	else
218	{
219		// Contrat non trouve
220		print "ErrorRecordNotFound";
221	}
222}
223
224
225$db->close();
226llxFooter();
227?>