dolibarr  13.0.2
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 <https://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', 'bills'));
37 
38 $id = GETPOST('id', 'int');
39 $ref = GETPOST('ref', 'alpha');
40 $action = GETPOST('action', 'aZ09');
41 
42 // Security check
43 if ($user->socid) $socid = $user->socid;
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  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
60  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
61  }
62 
63  if ($result >= 0)
64  {
65  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
66  exit;
67  } else {
68  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
69  {
70  $langs->load("errors");
71  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
72  } else {
73  setEventMessages($object->error, $object->errors, 'errors');
74  }
75  }
76 }
77 
78 // bascule du statut d'un contact
79 elseif ($action == 'swapstatut' && $user->rights->commande->creer)
80 {
81  if ($object->fetch($id))
82  {
83  $result = $object->swapContactStatus(GETPOST('ligne'));
84  } else {
85  dol_print_error($db);
86  }
87 }
88 
89 // Efface un contact
90 elseif ($action == 'deletecontact' && $user->rights->commande->creer)
91 {
92  $object->fetch($id);
93  $result = $object->delete_contact($_GET["lineid"]);
94 
95  if ($result >= 0)
96  {
97  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
98  exit;
99  } else {
100  dol_print_error($db);
101  }
102 }
103 /*
104 elseif ($action == 'setaddress' && $user->rights->commande->creer)
105 {
106  $object->fetch($id);
107  $result=$object->setDeliveryAddress($_POST['fk_address']);
108  if ($result < 0) dol_print_error($db,$object->error);
109 }*/
110 
111 
112 /*
113  * View
114  */
115 
116 llxHeader('', $langs->trans('Order'), 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes');
117 
118 $form = new Form($db);
119 $formcompany = new FormCompany($db);
120 $formother = new FormOther($db);
121 $contactstatic = new Contact($db);
122 $userstatic = new User($db);
123 
124 
125 /* *************************************************************************** */
126 /* */
127 /* Mode vue et edition */
128 /* */
129 /* *************************************************************************** */
130 
131 if ($id > 0 || !empty($ref))
132 {
133  $langs->trans("OrderCard");
134 
135  if ($object->fetch($id, $ref) > 0)
136  {
137  $object->fetch_thirdparty();
138 
139  $head = commande_prepare_head($object);
140  print dol_get_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order');
141 
142 
143  // Order card
144 
145  $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
146 
147 
148  $morehtmlref = '<div class="refidno">';
149  // Ref customer
150  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
151  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
152  // Thirdparty
153  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
154  // Project
155  if (!empty($conf->projet->enabled))
156  {
157  $langs->load("projects");
158  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
159  if ($user->rights->commande->creer)
160  {
161  if ($action != 'classify') {
162  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
163  $morehtmlref .= ' : ';
164  }
165  if ($action == 'classify') {
166  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
167  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
168  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
169  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
170  $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
171  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
172  $morehtmlref .= '</form>';
173  } else {
174  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
175  }
176  } else {
177  if (!empty($object->fk_project)) {
178  $proj = new Project($db);
179  $proj->fetch($object->fk_project);
180  $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
181  $morehtmlref .= $proj->ref;
182  $morehtmlref .= '</a>';
183  } else {
184  $morehtmlref .= '';
185  }
186  }
187  }
188  $morehtmlref .= '</div>';
189 
190  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
191 
193 
194  print '<br>';
195 
196  // Contacts lines (modules that overwrite templates must declare this into descriptor)
197  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
198  foreach ($dirtpls as $reldir)
199  {
200  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
201  if ($res) break;
202  }
203  } else {
204  // Contact not found
205  print "ErrorRecordNotFound";
206  }
207 }
208 
209 
210 // End of page
211 llxFooter();
212 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
Class to manage projects.
Class to manage customers orders.
Classe permettant la generation de composants html autre Only common components are here...
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.
commande_prepare_head(Commande $object)
Prepare array with list of tabs.
Definition: order.lib.php:34
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
llxFooter()
Empty footer.
Definition: wrapper.php:59