dolibarr  16.0.1
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  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/order.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('orders', 'sendings', 'companies', 'bills'));
38 
39 $id = GETPOST('id', 'int');
40 $ref = GETPOST('ref', 'alpha');
41 $action = GETPOST('action', 'aZ09');
42 
43 // Security check
44 if ($user->socid) {
45  $socid = $user->socid;
46 }
47 $result = restrictedArea($user, 'commande', $id, '');
48 
49 $object = new Commande($db);
50 
51 /*
52  * Ajout d'un nouveau contact
53  */
54 
55 if ($action == 'addcontact' && $user->rights->commande->creer) {
56  $result = $object->fetch($id);
57 
58  if ($result > 0 && $id > 0) {
59  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
60  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
61  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
62  }
63 
64  if ($result >= 0) {
65  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
66  exit;
67  } else {
68  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
69  $langs->load("errors");
70  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
71  } else {
72  setEventMessages($object->error, $object->errors, 'errors');
73  }
74  }
75 } elseif ($action == 'swapstatut' && $user->rights->commande->creer) {
76  // bascule du statut d'un contact
77  if ($object->fetch($id)) {
78  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
79  } else {
80  dol_print_error($db);
81  }
82 } elseif ($action == 'deletecontact' && $user->rights->commande->creer) {
83  // Efface un contact
84  $object->fetch($id);
85  $result = $object->delete_contact(GETPOST("lineid", 'int'));
86 
87  if ($result >= 0) {
88  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
89  exit;
90  } else {
91  setEventMessages($object->error, $object->errors, 'errors');
92  }
93 }
94 
95 
96 /*
97  * View
98  */
99 $title = $langs->trans('Order')." - ".$langs->trans('ContactsAddresses');
100 $help_url = 'EN:Customers_Orders|FR:Commandes_Clients|ES:Pedidos de clientes|DE:Modul_Kundenaufträge';
101 llxHeader('', $title, $help_url);
102 
103 $form = new Form($db);
104 $formcompany = new FormCompany($db);
105 $formother = new FormOther($db);
106 $contactstatic = new Contact($db);
107 $userstatic = new User($db);
108 
109 
110 /* *************************************************************************** */
111 /* */
112 /* Mode vue et edition */
113 /* */
114 /* *************************************************************************** */
115 
116 if ($id > 0 || !empty($ref)) {
117  if ($object->fetch($id, $ref) > 0) {
118  $object->fetch_thirdparty();
119 
120  $head = commande_prepare_head($object);
121  print dol_get_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order');
122 
123  // Order card
124 
125  $linkback = '<a href="'.DOL_URL_ROOT.'/commande/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
126 
127  $morehtmlref = '<div class="refidno">';
128  // Ref customer
129  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
130  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
131  // Thirdparty
132  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
133  // Project
134  if (!empty($conf->project->enabled)) {
135  $langs->load("projects");
136  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
137  if ($user->rights->commande->creer) {
138  if ($action != 'classify') {
139  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
140  $morehtmlref .= ' : ';
141  }
142  if ($action == 'classify') {
143  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
144  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
145  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
146  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
147  $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
148  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
149  $morehtmlref .= '</form>';
150  } else {
151  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
152  }
153  } else {
154  if (!empty($object->fk_project)) {
155  $proj = new Project($db);
156  $proj->fetch($object->fk_project);
157  $morehtmlref .= ' : '.$proj->getNomUrl(1);
158  if ($proj->title) {
159  $morehtmlref .= ' - '.$proj->title;
160  }
161  } else {
162  $morehtmlref .= '';
163  }
164  }
165  }
166  $morehtmlref .= '</div>';
167 
168  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
169 
170  print dol_get_fiche_end();
171 
172  print '<br>';
173 
174  // Contacts lines (modules that overwrite templates must declare this into descriptor)
175  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
176  foreach ($dirtpls as $reldir) {
177  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
178  if ($res) {
179  break;
180  }
181  }
182  } else {
183  // Contact not found
184  print "ErrorRecordNotFound";
185  }
186 }
187 
188 
189 // End of page
190 llxFooter();
191 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage contact/addresses.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save"&&empty($cancel)) $help_url
View.
Definition: agenda.php:116
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, $mode=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
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
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:73