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