dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load("orders");
36 $langs->load("sendings");
37 $langs->load("companies");
38 
39 $id=GETPOST('id','int');
40 $ref=GETPOST('ref','alpha');
41 $action=GETPOST('action','alpha');
42 
43 // Security check
44 if ($user->societe_id) $socid=$user->societe_id;
45 $result = restrictedArea($user, 'commande', $id,'');
46 
47 $object = new Commande($db);
48 
49 /*
50  * Ajout d'un nouveau contact
51  */
52 
53 if ($action == 'addcontact' && $user->rights->commande->creer)
54 {
55  $result = $object->fetch($id);
56 
57  if ($result > 0 && $id > 0)
58  {
59  $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int'));
60  $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
61  }
62 
63  if ($result >= 0)
64  {
65  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
66  exit;
67  }
68  else
69  {
70  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
71  {
72  $langs->load("errors");
73  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
74  }
75  else
76  {
77  setEventMessages($object->error, $object->errors, 'errors');
78  }
79  }
80 }
81 
82 // bascule du statut d'un contact
83 else if ($action == 'swapstatut' && $user->rights->commande->creer)
84 {
85  if ($object->fetch($id))
86  {
87  $result=$object->swapContactStatus(GETPOST('ligne'));
88  }
89  else
90  {
91  dol_print_error($db);
92  }
93 }
94 
95 // Efface un contact
96 else if ($action == 'deletecontact' && $user->rights->commande->creer)
97 {
98  $object->fetch($id);
99  $result = $object->delete_contact($_GET["lineid"]);
100 
101  if ($result >= 0)
102  {
103  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
104  exit;
105  }
106  else {
107  dol_print_error($db);
108  }
109 }
110 /*
111 else if ($action == 'setaddress' && $user->rights->commande->creer)
112 {
113  $object->fetch($id);
114  $result=$object->setDeliveryAddress($_POST['fk_address']);
115  if ($result < 0) dol_print_error($db,$object->error);
116 }*/
117 
118 
119 /*
120  * View
121  */
122 
123 llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
124 
125 $form = new Form($db);
126 $formcompany = new FormCompany($db);
127 $formother = new FormOther($db);
128 $contactstatic=new Contact($db);
129 $userstatic=new User($db);
130 
131 
132 /* *************************************************************************** */
133 /* */
134 /* Mode vue et edition */
135 /* */
136 /* *************************************************************************** */
137 
138 if ($id > 0 || ! empty($ref))
139 {
140  $langs->trans("OrderCard");
141 
142  if ($object->fetch($id, $ref) > 0)
143  {
144  $object->fetch_thirdparty();
145 
146  $head = commande_prepare_head($object);
147  dol_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order');
148 
149 
150  // Order card
151 
152  $linkback = '<a href="' . DOL_URL_ROOT . '/commande/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
153 
154 
155  $morehtmlref='<div class="refidno">';
156  // Ref customer
157  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
158  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
159  // Thirdparty
160  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
161  // Project
162  if (! empty($conf->projet->enabled))
163  {
164  $langs->load("projects");
165  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
166  if ($user->rights->commande->creer)
167  {
168  if ($action != 'classify')
169  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
170  $morehtmlref.=' : ';
171  if ($action == 'classify') {
172  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
173  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
174  $morehtmlref.='<input type="hidden" name="action" value="classin">';
175  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
176  $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
177  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
178  $morehtmlref.='</form>';
179  } else {
180  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
181  }
182  } else {
183  if (! empty($object->fk_project)) {
184  $proj = new Project($db);
185  $proj->fetch($object->fk_project);
186  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
187  $morehtmlref.=$proj->ref;
188  $morehtmlref.='</a>';
189  } else {
190  $morehtmlref.='';
191  }
192  }
193  }
194  $morehtmlref.='</div>';
195 
196  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
197 
198  dol_fiche_end();
199 
200  print '<br>';
201 
202  // Contacts lines (modules that overwrite templates must declare this into descriptor)
203  $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
204  foreach($dirtpls as $reldir)
205  {
206  $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
207  if ($res) break;
208  }
209  }
210  else
211  {
212  // Contact not found
213  print "ErrorRecordNotFound";
214  }
215 }
216 
217 
218 llxFooter();
219 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:46
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
Definition: order.lib.php:34
print
Draft customers invoices.
Definition: index.php:91
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.