dolibarr 20.0.0
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 * 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
29require '../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
32require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34if (isModEnabled('project')) {
35 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
36}
37
38// Load translation files required by the page
39$langs->loadLangs(array('contracts', 'companies'));
40
41$action = GETPOST('action', 'aZ09');
42$confirm = GETPOST('confirm', 'alpha');
43$socid = GETPOSTINT('socid');
44$id = GETPOSTINT('id');
45$ref = GETPOST('ref', 'alpha');
46
47// Security check
48if ($user->socid) {
49 $socid = $user->socid;
50}
51
52$object = new Contrat($db);
53
54// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
55$hookmanager->initHooks(array('contractcontactcard', 'globalcard'));
56
57$permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
58
59$result = restrictedArea($user, 'contrat', $object->id);
60
61
62/*
63 * Actions
64 */
65
66$parameters = array('id'=>$id);
67$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
68if ($reshook < 0) {
69 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
70}
71
72if (empty($reshook)) {
73 // Add new contact
74 if ($action == 'addcontact' && $user->hasRight('contrat', 'creer')) {
75 $result = $object->fetch($id);
76
77 if ($result > 0 && $id > 0) {
78 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
79 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
80 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
81 }
82
83 if ($result >= 0) {
84 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
85 exit;
86 } else {
87 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
88 $langs->load("errors");
89 $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
90 } else {
91 $mesg = $object->error;
92 }
93
94 setEventMessages($mesg, null, 'errors');
95 }
96 }
97
98 // Toggle the status of a contact
99 if ($action == 'swapstatut' && $user->hasRight('contrat', 'creer')) {
100 if ($object->fetch($id)) {
101 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
102 } else {
103 dol_print_error($db, $object->error);
104 }
105 }
106
107 // Delete contact
108 if ($action == 'deletecontact' && $user->hasRight('contrat', 'creer')) {
109 $object->fetch($id);
110 $result = $object->delete_contact(GETPOSTINT("lineid"));
111
112 if ($result >= 0) {
113 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
114 exit;
115 }
116 }
117}
118
119/*
120 * View
121 */
122
123$title = $langs->trans("Contract");
124$help_url = 'EN:Module_Contracts|FR:Module_Contrat';
125
126llxHeader('', $title, $help_url);
127
128$form = new Form($db);
129$formcompany = new FormCompany($db);
130$contactstatic = new Contact($db);
131$userstatic = new User($db);
132
133/* *************************************************************************** */
134/* */
135/* Card view and edit mode */
136/* */
137/* *************************************************************************** */
138
139if ($id > 0 || !empty($ref)) {
140 if ($object->fetch($id, $ref) > 0) {
141 $object->fetch_thirdparty();
142
143 $head = contract_prepare_head($object);
144
145 $hselected = 1;
146
147 print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
148
149 // Contract card
150
151 $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
152
153
154 $morehtmlref = '';
155 //if (!empty($modCodeContract->code_auto)) {
156 $morehtmlref .= $object->ref;
157 /*} else {
158 $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
159 $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
160 }*/
161
162 $morehtmlref .= '<div class="refidno">';
163 // Ref customer
164 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
165 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
166 // Ref supplier
167 $morehtmlref .= '<br>';
168 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
169 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
170 // Thirdparty
171 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
172 // Project
173 if (isModEnabled('project')) {
174 $langs->load("projects");
175 $morehtmlref .= '<br>';
176 if (0) {
177 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
178 if ($action != 'classify') {
179 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
180 }
181 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
182 } else {
183 if (!empty($object->fk_project)) {
184 $proj = new Project($db);
185 $proj->fetch($object->fk_project);
186 $morehtmlref .= $proj->getNomUrl(1);
187 if ($proj->title) {
188 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
189 }
190 }
191 }
192 }
193 $morehtmlref .= '</div>';
194
195
196 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
197
198
199 print '<div class="fichecenter">';
200 print '<div class="underbanner clearboth"></div>';
201
202 print '<table class="border tableforfield" width="100%">';
203
204
205 // Ligne info remises tiers
206 print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
207 if ($object->thirdparty->remise_percent) {
208 print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);
209 } else {
210 print $langs->trans("CompanyHasNoRelativeDiscount");
211 }
212 $absolute_discount = $object->thirdparty->getAvailableDiscounts();
213 print '. ';
214 if ($absolute_discount) {
215 print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));
216 } else {
217 print $langs->trans("CompanyHasNoAbsoluteDiscount");
218 }
219 print '.';
220 print '</td></tr>';
221
222 // Date
223 print '<tr>';
224 print '<td class="titlefield">';
225 print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);
226 print '</td><td>';
227 print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');
228 print '</td>';
229 print '</tr>';
230
231 print "</table>";
232
233 print '</div>';
234
235 print dol_get_fiche_end();
236
237 print '<br>';
238
239 // Contacts lines
240 include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
241 } else {
242 print "ErrorRecordNotFound";
243 }
244}
245
246
247llxFooter();
248$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage contact/addresses.
Class to manage contracts.
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.
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.