dolibarr 21.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-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 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
33require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
35if (isModEnabled('project')) {
36 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37}
38
39// Load translation files required by the page
40$langs->loadLangs(array('contracts', 'companies'));
41
42$action = GETPOST('action', 'aZ09');
43$confirm = GETPOST('confirm', 'alpha');
44$socid = GETPOSTINT('socid');
45$id = GETPOSTINT('id');
46$ref = GETPOST('ref', 'alpha');
47
48// Security check
49if ($user->socid) {
50 $socid = $user->socid;
51}
52
53$object = new Contrat($db);
54
55// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
56$hookmanager->initHooks(array('contractcontactcard', 'globalcard'));
57
58$permissiontoadd = $user->hasRight('contrat', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
59
60$result = restrictedArea($user, 'contrat', $object->id);
61
62
63/*
64 * Actions
65 */
66
67$parameters = array('id'=>$id);
68$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
69if ($reshook < 0) {
70 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
71}
72
73if (empty($reshook)) {
74 // Add new contact
75 if ($action == 'addcontact' && $user->hasRight('contrat', 'creer')) {
76 $result = $object->fetch($id);
77
78 if ($result > 0 && $id > 0) {
79 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
80 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
81 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
82 }
83
84 if ($result >= 0) {
85 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
86 exit;
87 } else {
88 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
89 $langs->load("errors");
90 $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
91 } else {
92 $mesg = $object->error;
93 }
94
95 setEventMessages($mesg, null, 'errors');
96 }
97 }
98
99 // Toggle the status of a contact
100 if ($action == 'swapstatut' && $user->hasRight('contrat', 'creer')) {
101 if ($object->fetch($id)) {
102 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
103 } else {
104 dol_print_error($db, $object->error);
105 }
106 }
107
108 // Delete contact
109 if ($action == 'deletecontact' && $user->hasRight('contrat', 'creer')) {
110 $object->fetch($id);
111 $result = $object->delete_contact(GETPOSTINT("lineid"));
112
113 if ($result >= 0) {
114 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
115 exit;
116 }
117 }
118}
119
120/*
121 * View
122 */
123
124$title = $langs->trans("Contract");
125$help_url = 'EN:Module_Contracts|FR:Module_Contrat|ES:Contratos_de_servicio';
126
127llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-contrat page-card_contact');
128
129$form = new Form($db);
130$formcompany = new FormCompany($db);
131$contactstatic = new Contact($db);
132$userstatic = new User($db);
133
134/* *************************************************************************** */
135/* */
136/* Card view and edit mode */
137/* */
138/* *************************************************************************** */
139
140if ($id > 0 || !empty($ref)) {
141 if ($object->fetch($id, $ref) > 0) {
142 $object->fetch_thirdparty();
143
144 $head = contract_prepare_head($object);
145
146 $hselected = 1;
147
148 print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
149
150 // Contract card
151
152 $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
153
154
155 $morehtmlref = '';
156 //if (!empty($modCodeContract->code_auto)) {
157 $morehtmlref .= $object->ref;
158 /*} else {
159 $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
160 $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
161 }*/
162
163 $morehtmlref .= '<div class="refidno">';
164 // Ref customer
165 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
166 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
167 // Ref supplier
168 $morehtmlref .= '<br>';
169 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
170 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
171 // Thirdparty
172 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
173 // Project
174 if (isModEnabled('project')) {
175 $langs->load("projects");
176 $morehtmlref .= '<br>';
177 if (0) {
178 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
179 if ($action != 'classify') {
180 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
181 }
182 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
183 } else {
184 if (!empty($object->fk_project)) {
185 $proj = new Project($db);
186 $proj->fetch($object->fk_project);
187 $morehtmlref .= $proj->getNomUrl(1);
188 if ($proj->title) {
189 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
190 }
191 }
192 }
193 }
194 $morehtmlref .= '</div>';
195
196
197 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
198
199
200 print '<div class="fichecenter">';
201 print '<div class="underbanner clearboth"></div>';
202
203 print '<table class="border tableforfield" width="100%">';
204
205
206 // Ligne info remises tiers
207 print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
208 if ($object->thirdparty->remise_percent) {
209 print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);
210 } else {
211 print $langs->trans("CompanyHasNoRelativeDiscount");
212 }
213 $absolute_discount = $object->thirdparty->getAvailableDiscounts();
214 print '. ';
215 if ($absolute_discount) {
216 print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));
217 } else {
218 print $langs->trans("CompanyHasNoAbsoluteDiscount");
219 }
220 print '.';
221 print '</td></tr>';
222
223 // Date
224 print '<tr>';
225 print '<td class="titlefield">';
226 print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);
227 print '</td><td>';
228 print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');
229 print '</td>';
230 print '</tr>';
231
232 print "</table>";
233
234 print '</div>';
235
236 print dol_get_fiche_end();
237
238 print '<br>';
239
240 // Contacts lines
241 include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
242 } else {
243 print "ErrorRecordNotFound";
244 }
245}
246
247
248llxFooter();
249$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($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
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.
llxFooter()
Footer empty.
Definition document.php:107
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.
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.