dolibarr  17.0.4
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->rights->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->rights->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->rights->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->rights->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 llxHeader('', $langs->trans("Contract"), "");
114 
115 $form = new Form($db);
116 $formcompany = new FormCompany($db);
117 $contactstatic = new Contact($db);
118 $userstatic = new User($db);
119 
120 /* *************************************************************************** */
121 /* */
122 /* Mode vue et edition */
123 /* */
124 /* *************************************************************************** */
125 
126 if ($id > 0 || !empty($ref)) {
127  if ($object->fetch($id, $ref) > 0) {
128  $object->fetch_thirdparty();
129 
130  $head = contract_prepare_head($object);
131 
132  $hselected = 1;
133 
134  print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
135 
136  // Contract card
137 
138  $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
139 
140 
141  $morehtmlref = '';
142  //if (!empty($modCodeContract->code_auto)) {
143  $morehtmlref .= $object->ref;
144  /*} else {
145  $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
146  $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
147  }*/
148 
149  $morehtmlref .= '<div class="refidno">';
150  // Ref customer
151  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
152  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
153  // Ref supplier
154  $morehtmlref .= '<br>';
155  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
156  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
157  // Thirdparty
158  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
159  // Project
160  if (isModEnabled('project')) {
161  $langs->load("projects");
162  $morehtmlref .= '<br>';
163  if (0) {
164  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
165  if ($action != 'classify') {
166  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
167  }
168  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
169  } else {
170  if (!empty($object->fk_project)) {
171  $proj = new Project($db);
172  $proj->fetch($object->fk_project);
173  $morehtmlref .= $proj->getNomUrl(1);
174  if ($proj->title) {
175  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
176  }
177  }
178  }
179  }
180  $morehtmlref .= '</div>';
181 
182 
183  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
184 
185 
186  print '<div class="fichecenter">';
187  print '<div class="underbanner clearboth"></div>';
188 
189  print '<table class="border tableforfield" width="100%">';
190 
191 
192  // Ligne info remises tiers
193  print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
194  if ($object->thirdparty->remise_percent) {
195  print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);
196  } else {
197  print $langs->trans("CompanyHasNoRelativeDiscount");
198  }
199  $absolute_discount = $object->thirdparty->getAvailableDiscounts();
200  print '. ';
201  if ($absolute_discount) {
202  print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));
203  } else {
204  print $langs->trans("CompanyHasNoAbsoluteDiscount");
205  }
206  print '.';
207  print '</td></tr>';
208 
209  // Date
210  print '<tr>';
211  print '<td class="titlefield">';
212  print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);
213  print '</td><td>';
214  print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');
215  print '</td>';
216  print '</tr>';
217 
218  print "</table>";
219 
220  print '</div>';
221 
222  print dol_get_fiche_end();
223 
224  print '<br>';
225 
226  // Contacts lines
227  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
228  } else {
229  print "ErrorRecordNotFound";
230  }
231 }
232 
233 
234 llxFooter();
235 $db->close();
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:47
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='')
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
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.