dolibarr  9.0.0
contact.php
Go to the documentation of this 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@inodbox.com>
5  * Copyright (C) 2011-2015 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 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34 
35 // Load translation files required by the page
36 $langs->loadLangs(array('orders', 'sendings', 'companies'));
37 
38 $id=GETPOST('id','int');
39 $ref=GETPOST('ref','alpha');
40 $action=GETPOST('action','alpha');
41 
42 // Security check
43 if ($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 
52 if ($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  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
73  }
74  else
75  {
76  setEventMessages($object->error, $object->errors, 'errors');
77  }
78  }
79 }
80 
81 // bascule du statut d'un contact
82 else 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
95 else 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 /*
110 else 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 /*
119  * View
120  */
121 
122 llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
123 
124 $form = new Form($db);
125 $formcompany = new FormCompany($db);
126 $formother = new FormOther($db);
127 $contactstatic=new Contact($db);
128 $userstatic=new User($db);
129 
130 
131 /* *************************************************************************** */
132 /* */
133 /* Mode vue et edition */
134 /* */
135 /* *************************************************************************** */
136 
137 if ($id > 0 || ! empty($ref))
138 {
139  $langs->trans("OrderCard");
140 
141  if ($object->fetch($id, $ref) > 0)
142  {
143  $object->fetch_thirdparty();
144 
145  $head = commande_prepare_head($object);
146  dol_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order');
147 
148 
149  // Order card
150 
151  $linkback = '<a href="' . DOL_URL_ROOT . '/commande/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
152 
153 
154  $morehtmlref='<div class="refidno">';
155  // Ref customer
156  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
157  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
158  // Thirdparty
159  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
160  // Project
161  if (! empty($conf->projet->enabled))
162  {
163  $langs->load("projects");
164  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
165  if ($user->rights->commande->creer)
166  {
167  if ($action != 'classify')
168  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
169  $morehtmlref.=' : ';
170  if ($action == 'classify') {
171  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
172  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
173  $morehtmlref.='<input type="hidden" name="action" value="classin">';
174  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
175  $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
176  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
177  $morehtmlref.='</form>';
178  } else {
179  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
180  }
181  } else {
182  if (! empty($object->fk_project)) {
183  $proj = new Project($db);
184  $proj->fetch($object->fk_project);
185  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
186  $morehtmlref.=$proj->ref;
187  $morehtmlref.='</a>';
188  } else {
189  $morehtmlref.='';
190  }
191  }
192  }
193  $morehtmlref.='</div>';
194 
195  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
196 
197  dol_fiche_end();
198 
199  print '<br>';
200 
201  // Contacts lines (modules that overwrite templates must declare this into descriptor)
202  $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
203  foreach($dirtpls as $reldir)
204  {
205  $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
206  if ($res) break;
207  }
208  }
209  else
210  {
211  // Contact not found
212  print "ErrorRecordNotFound";
213  }
214 }
215 
216 
217 // End of page
218 llxFooter();
219 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage contact/addresses.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to build HTML component for third parties management Only common components are here...
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
dol_fiche_end($notab=0)
Show tab footer of a card.
Class to manage customers orders.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
Definition: order.lib.php:34
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.