dolibarr  20.0.0-alpha
contact.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Patrick Rouillon <patrick@rouillon.net>
3  * Copyright (C) 2005-2018 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  * Copyright (C) 2023 Christian Foellmann <christian@foellmann.de>
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 // Load Dolibarr environment
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/supplier_proposal.lib.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 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array("propal", "supplier_proposal", "facture", "orders", "sendings", "companies"));
40 
41 $id = GETPOSTINT('id');
42 $ref = GETPOST('ref', 'alpha');
43 $action = GETPOST('action', 'aZ09');
44 
45 // Security check
46 if ($user->socid) {
47  $socid = $user->socid;
48 }
49 $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal', '');
50 
51 $object = new SupplierProposal($db);
52 
53 $permissiontoedit = $user->hasRight('supplier_proposal', 'creer');
54 
55 $hookmanager->initHooks(array('supplier_proposalcontactcard', 'globalcard'));
56 
57 
58 /*
59  * Actions
60  */
61 
62 $parameters = array('id'=>$id);
63 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
64 if ($reshook < 0) {
65  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
66 }
67 
68 if (empty($reshook)) {
69  /*
70  * Add a new contact
71  */
72  if ($action == 'addcontact' && $permissiontoedit) {
73  $result = $object->fetch($id);
74 
75  if ($result > 0 && $id > 0) {
76  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
77  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
78  $result = $object->add_contact($contactid, $typeid, GETPOST("source"));
79  }
80 
81  if ($result >= 0) {
82  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
83  exit;
84  } else {
85  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
86  $langs->load("errors");
87  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
88  } else {
89  setEventMessages($object->error, $object->errors, 'errors');
90  }
91  }
92  } elseif ($action == 'swapstatut' && $permissiontoedit) {
93  // Toggle the status of a contact
94  if ($object->fetch($id)) {
95  $result = $object->swapContactStatus(GETPOSTINT('ligne'));
96  } else {
97  setEventMessages($object->error, $object->errors, 'errors');
98  }
99  } elseif ($action == 'deletecontact' && $permissiontoedit) {
100  // Deleting a contact
101  $object->fetch($id);
102  $result = $object->delete_contact(GETPOSTINT("lineid"));
103 
104  if ($result >= 0) {
105  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
106  exit;
107  } else {
108  setEventMessages($object->error, $object->errors, 'errors');
109  }
110  }
111 }
112 
113 
114 /*
115  * View
116  */
117 $form = new Form($db);
118 $formcompany = new FormCompany($db);
119 $contactstatic = new Contact($db);
120 $userstatic = new User($db);
121 
122 
123 /* *************************************************************************** */
124 /* */
125 /* Card view and edit mode */
126 /* */
127 /* *************************************************************************** */
128 
129 if ($id > 0 || !empty($ref)) {
130  $langs->trans("SupplierProposal");
131 
132  if ($object->fetch($id, $ref) > 0) {
133  $object->fetch_thirdparty();
134 
135  $title = $object->ref." - ".$langs->trans('ContactsAddresses');
136  $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur';
137  llxHeader('', $title, $help_url);
138 
139  $head = supplier_proposal_prepare_head($object);
140  print dol_get_fiche_head($head, 'contact', $langs->trans("CommRequest"), -1, 'supplier_proposal');
141 
142  // Supplier order card
143 
144  $linkback = '<a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
145 
146  $morehtmlref = '<div class="refidno">';
147  // Ref supplier
148  //$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
149  //$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
150  // Thirdparty
151  $morehtmlref .= $object->thirdparty->getNomUrl(1);
152  // Project
153  if (isModEnabled('project')) {
154  $langs->load("projects");
155  $morehtmlref .= '<br>';
156  if (0) {
157  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
158  if ($action != 'classify') {
159  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
160  }
161  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (!getDolGlobalString('PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS') ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
162  } else {
163  if (!empty($object->fk_project)) {
164  $proj = new Project($db);
165  $proj->fetch($object->fk_project);
166  $morehtmlref .= $proj->getNomUrl(1);
167  if ($proj->title) {
168  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
169  }
170  }
171  }
172  }
173  $morehtmlref .= '</div>';
174 
175 
176  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
177 
178  print dol_get_fiche_end();
179 
180  // Contacts lines
181  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
182  } else {
183  // Contact not found
184  print "ErrorRecordNotFound";
185  }
186 }
187 
188 // End of page
189 llxFooter();
190 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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 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 price ask supplier.
Class to manage Dolibarr users.
Definition: user.class.php:50
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify 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.