dolibarr  16.0.5
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 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32 if (!empty($conf->project->enabled)) {
33  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34 }
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array("facture", "orders", "sendings", "companies"));
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, 'fournisseur', $id, 'commande_fournisseur', 'commande');
48 $hookmanager->initHooks(array('ordersuppliercardcontact'));
49 
50 $object = new CommandeFournisseur($db);
51 
52 
53 /*
54  * Add a new contact
55  */
56 
57 if ($action == 'addcontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
58  $result = $object->fetch($id);
59 
60  if ($result > 0 && $id > 0) {
61  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
62  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
63  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
64  }
65 
66  if ($result >= 0) {
67  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
68  exit;
69  } else {
70  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
71  $langs->load("errors");
72  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
73  } else {
74  setEventMessages($object->error, $object->errors, 'errors');
75  }
76  }
77 } elseif ($action == 'swapstatut' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
78  // Toggle the status of a contact
79  if ($object->fetch($id)) {
80  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
81  } else {
82  setEventMessages($object->error, $object->errors, 'errors');
83  }
84 } elseif ($action == 'deletecontact' && ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)) {
85  // Deleting a contact
86  $object->fetch($id);
87  $result = $object->delete_contact(GETPOST("lineid", 'int'));
88 
89  if ($result >= 0) {
90  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
91  exit;
92  } else {
93  setEventMessages($object->error, $object->errors, 'errors');
94  }
95 }
96 
97 
98 
99 /*
100  * View
101  */
102 $title = $langs->trans('SupplierOrder')." - ".$langs->trans('ContactsAddresses');
103 $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores';
104 llxHeader('', $title, $help_url);
105 
106 $form = new Form($db);
107 $formcompany = new FormCompany($db);
108 $contactstatic = new Contact($db);
109 $userstatic = new User($db);
110 
111 
112 /* *************************************************************************** */
113 /* */
114 /* Mode vue et edition */
115 /* */
116 /* *************************************************************************** */
117 
118 if ($id > 0 || !empty($ref)) {
119  $langs->trans("OrderCard");
120 
121  if ($object->fetch($id, $ref) > 0) {
122  $object->fetch_thirdparty();
123 
124  $head = ordersupplier_prepare_head($object);
125  print dol_get_fiche_head($head, 'contact', $langs->trans("SupplierOrder"), -1, 'order');
126 
127  // Supplier order card
128 
129  $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
130 
131  $morehtmlref = '<div class="refidno">';
132  // Ref supplier
133  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
134  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
135  // Thirdparty
136  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
137  // Project
138  if (!empty($conf->project->enabled)) {
139  $langs->load("projects");
140  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
141  if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) {
142  if ($action != 'classify') {
143  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
144  $morehtmlref .= ' : ';
145  }
146  if ($action == 'classify') {
147  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
148  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
149  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
150  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
151  $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
152  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
153  $morehtmlref .= '</form>';
154  } else {
155  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
156  }
157  } else {
158  if (!empty($object->fk_project)) {
159  $proj = new Project($db);
160  $proj->fetch($object->fk_project);
161  $morehtmlref .= ' : '.$proj->getNomUrl(1);
162  if ($proj->title) {
163  $morehtmlref .= ' - '.$proj->title;
164  }
165  } else {
166  $morehtmlref .= '';
167  }
168  }
169  }
170  $morehtmlref .= '</div>';
171 
172 
173  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
174 
175  print dol_get_fiche_end();
176 
177  // Contacts lines
178  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
179  } else {
180  // Contact not found
181  print "ErrorRecordNotFound";
182  }
183 }
184 
185 // End of page
186 llxFooter();
187 $db->close();
restrictedArea
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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
$help_url
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
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
CommandeFournisseur
Class to manage predefined suppliers products.
Definition: fournisseur.commande.class.php:47
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
ordersupplier_prepare_head
ordersupplier_prepare_head(CommandeFournisseur $object)
Prepare array with list of tabs.
Definition: fourn.lib.php:135
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
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