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

/htdocs/propal/contact.php

https://bitbucket.org/speedealing/speedealing
PHP | 224 lines | 149 code | 34 blank | 41 comment | 38 complexity | b2cb26c612e28ca88a4ff9937d2476bb MD5 | raw file
  1<?php
  2/* Copyright (C) 2005      Patrick Rouillon     <patrick@rouillon.net>
  3 * Copyright (C) 2005-2009 Destailleur Laurent  <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/comm/propal/contact.php
 23 *       \ingroup    propal
 24 *       \brief      Onglet de gestion des contacts de propal
 25 */
 26
 27require '../../main.inc.php';
 28require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
 29require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
 30require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.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("facture");
 35$langs->load("orders");
 36$langs->load("sendings");
 37$langs->load("companies");
 38
 39$id=GETPOST('id','int');
 40$ref= GETPOST('ref','alpha');
 41$lineid=GETPOST('lineid','int');
 42$action=GETPOST('action','alpha');
 43
 44// Security check
 45if ($user->societe_id) $socid=$user->societe_id;
 46$result = restrictedArea($user, 'propal', $id);
 47
 48$object = new Propal($db);
 49
 50// Load object
 51if ($id > 0 || ! empty($ref))
 52{
 53	$ret=$object->fetch($id, $ref);
 54	if ($ret == 0)
 55	{
 56		$langs->load("errors");
 57		setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors');
 58		$error++;
 59	}
 60	else if ($ret < 0)
 61	{
 62		setEventMessage($object->error, 'errors');
 63		$error++;
 64	}
 65}
 66if (! $error)
 67{
 68	$object->fetch_thirdparty();
 69}
 70else
 71{
 72	header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
 73	exit;
 74}
 75
 76
 77/*
 78 * Ajout d'un nouveau contact
 79 */
 80
 81if ($action == 'addcontact' && $user->rights->propale->creer)
 82{
 83    if ($object->id > 0)
 84    {
 85    	$contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
 86  		$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
 87    }
 88
 89	if ($result >= 0)
 90	{
 91		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 92		exit;
 93	}
 94	else
 95	{
 96		if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 97		{
 98			$langs->load("errors");
 99			setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
100		}
101		else
102		{
103			setEventMessage($object->error, 'errors');
104		}
105	}
106}
107
108// Bascule du statut d'un contact
109else if ($action == 'swapstatut' && $user->rights->propale->creer)
110{
111	if ($object->id > 0)
112	{
113	    $result=$object->swapContactStatus(GETPOST('ligne'));
114	}
115}
116
117// Efface un contact
118else if ($action == 'deletecontact' && $user->rights->propale->creer)
119{
120	$result = $object->delete_contact($lineid);
121
122	if ($result >= 0)
123	{
124		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
125		exit;
126	}
127	else
128	{
129		dol_print_error($db);
130	}
131}
132
133else if ($action == 'setaddress' && $user->rights->propale->creer)
134{
135	$result=$object->setDeliveryAddress($_POST['fk_address']);
136	if ($result < 0) dol_print_error($db,$object->error);
137}
138
139
140/*
141 * View
142 */
143
144llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
145
146$form = new Form($db);
147$formcompany= new FormCompany($db);
148$formother = new FormOther($db);
149
150if ($object->id > 0)
151{
152	$head = propal_prepare_head($object);
153	dol_fiche_head($head, 'contact', $langs->trans("Proposal"), 0, 'propal');
154
155	/*
156	 * Propal synthese pour rappel
157	 */
158	print '<table class="border" width="100%">';
159
160	$linkback='<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
161
162	// Ref
163	print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">';
164	print $form->showrefnav($object,'ref',$linkback,1,'ref','ref','');
165	print '</td></tr>';
166
167	// Ref client
168	print '<tr><td>';
169	print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
170	print $langs->trans('RefCustomer').'</td><td align="left">';
171	print '</td>';
172	print '</tr></table>';
173	print '</td><td colspan="3">';
174	print $object->ref_client;
175	print '</td>';
176	print '</tr>';
177
178	// Customer
179	print "<tr><td>".$langs->trans("Company")."</td>";
180	print '<td colspan="3">'.$object->client->getNomUrl(1).'</td></tr>';
181
182	// Delivery address
183	if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT))
184	{
185		print '<tr><td>';
186		print '<table class="nobordernopadding" width="100%"><tr><td>';
187		print $langs->trans('DeliveryAddress');
188		print '</td>';
189
190		if ($action != 'editdelivery_address' && ! empty($object->brouillon))
191			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>';
192		print '</tr></table>';
193		print '</td><td colspan="3">';
194
195		if ($action == 'editdelivery_address')
196		{
197			$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'fk_address','propal',$object->id);
198		}
199		else
200		{
201			$formother->form_address($_SERVER['PHP_SELF'].'?id='.$object->id,$object->fk_delivery_address,$object->socid,'none','propal',$object->id);
202		}
203		print '</td></tr>';
204	}
205
206	print "</table>";
207
208	print '</div>';
209
210	print '<br>';
211
212	// Contacts lines (modules that overwrite templates must declare this into descriptor)
213	$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
214	foreach($dirtpls as $reldir)
215	{
216		$res=@include dol_buildpath($reldir.'/contacts.tpl.php');
217		if ($res) break;
218	}
219}
220
221llxFooter();
222
223$db->close();
224?>