dolibarr  19.0.0-dev
contact.php
Go to the documentation of this 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@inodbox.com>
5  * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
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 // Load Dolibarr environment
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
33 if (isModEnabled('project')) {
34  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35 }
36 
37 // Load translation files required by the page
38 $langs->loadLangs(array("facture", "orders", "sendings", "companies"));
39 
40 $id = GETPOST('id', 'int');
41 $ref = GETPOST('ref', 'alpha');
42 $action = GETPOST('action', 'aZ09');
43 
44 // Security check
45 if ($user->socid) {
46  $socid = $user->socid;
47 }
48 $result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande');
49 $hookmanager->initHooks(array('ordersuppliercardcontact'));
50 
51 $object = new CommandeFournisseur($db);
52 
53 $usercancreate = ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"));
54 $permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php
55 
56 
57 /*
58  * Actions
59  */
60 
61 if ($action == 'addcontact' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) {
62  $result = $object->fetch($id);
63 
64  if ($result > 0 && $id > 0) {
65  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
66  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
67  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
68  }
69 
70  if ($result >= 0) {
71  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
72  exit;
73  } else {
74  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
75  $langs->load("errors");
76  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
77  } else {
78  setEventMessages($object->error, $object->errors, 'errors');
79  }
80  }
81 } elseif ($action == 'swapstatut' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) {
82  // Toggle the status of a contact
83  if ($object->fetch($id)) {
84  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
85  } else {
86  setEventMessages($object->error, $object->errors, 'errors');
87  }
88 } elseif ($action == 'deletecontact' && ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"))) {
89  // Deleting a contact
90  $object->fetch($id);
91  $result = $object->delete_contact(GETPOST("lineid", 'int'));
92 
93  if ($result >= 0) {
94  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
95  exit;
96  } else {
97  setEventMessages($object->error, $object->errors, 'errors');
98  }
99 }
100 
101 
102 
103 /*
104  * View
105  */
106 
107 $form = new Form($db);
108 $formcompany = new FormCompany($db);
109 $contactstatic = new Contact($db);
110 $userstatic = new User($db);
111 
112 
113 /* *************************************************************************** */
114 /* */
115 /* Mode vue et edition */
116 /* */
117 /* *************************************************************************** */
118 
119 if ($id > 0 || !empty($ref)) {
120  $langs->trans("OrderCard");
121 
122  if ($object->fetch($id, $ref) > 0) {
123  $object->fetch_thirdparty();
124 
125  $title = $object->ref." - ".$langs->trans('ContactsAddresses');
126  $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
127  llxHeader('', $title, $help_url);
128 
129  $head = ordersupplier_prepare_head($object);
130  print dol_get_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), -1, 'order');
131 
132  // Supplier order card
133 
134  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
135 
136  $morehtmlref = '<div class="refidno">';
137  // Ref supplier
138  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
139  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
140  // Thirdparty
141  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
142  // Project
143  if (isModEnabled('project')) {
144  $langs->load("projects");
145  $morehtmlref .= '<br>';
146  if (0) {
147  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
148  if ($action != 'classify' && $caneditproject) {
149  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
150  }
151  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
152  } else {
153  if (!empty($object->fk_project)) {
154  $proj = new Project($db);
155  $proj->fetch($object->fk_project);
156  $morehtmlref .= $proj->getNomUrl(1);
157  if ($proj->title) {
158  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
159  }
160  }
161  }
162  }
163  $morehtmlref .= '</div>';
164 
165 
166  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
167 
168  print dol_get_fiche_end();
169 
170  // Contacts lines
171  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
172  } else {
173  // Contact not found
174  print "ErrorRecordNotFound";
175  }
176 }
177 
178 // End of page
179 llxFooter();
180 $db->close();
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:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage predefined suppliers products.
Class to manage contact/addresses.
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.
Class to manage Dolibarr users.
Definition: user.class.php:48
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
Definition: fourn.lib.php:138
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
restrictedArea(User $user, $features, $object=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.