dolibarr  16.0.5
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 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32 if (!empty($conf->project->enabled)) {
33  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34 }
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('contracts', 'companies'));
38 
39 $action = GETPOST('action', 'aZ09');
40 $confirm = GETPOST('confirm', 'alpha');
41 $socid = GETPOST('socid', 'int');
42 $id = GETPOST('id', 'int');
43 $ref = GETPOST('ref', 'alpha');
44 
45 // Security check
46 if ($user->socid) {
47  $socid = $user->socid;
48 }
49 $result = restrictedArea($user, 'contrat', $id);
50 
51 $object = new Contrat($db);
52 
53 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
54 $hookmanager->initHooks(array('contractcard', 'globalcard'));
55 
56 
57 /*
58  * Actions
59  */
60 
61 if ($action == 'addcontact' && $user->rights->contrat->creer) {
62  $result = $object->fetch($id);
63 
64  if ($result > 0 && $id > 0) {
65  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
66  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
67  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
68  }
69 
70  if ($result >= 0) {
71  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
72  exit;
73  } else {
74  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
75  $langs->load("errors");
76  $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
77  } else {
78  $mesg = $object->error;
79  }
80 
81  setEventMessages($mesg, null, 'errors');
82  }
83 }
84 
85 // bascule du statut d'un contact
86 if ($action == 'swapstatut' && $user->rights->contrat->creer) {
87  if ($object->fetch($id)) {
88  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
89  } else {
90  dol_print_error($db, $object->error);
91  }
92 }
93 
94 // Delete contact
95 if ($action == 'deletecontact' && $user->rights->contrat->creer) {
96  $object->fetch($id);
97  $result = $object->delete_contact(GETPOST("lineid", 'int'));
98 
99  if ($result >= 0) {
100  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
101  exit;
102  }
103 }
104 
105 
106 /*
107  * View
108  */
109 
110 llxHeader('', $langs->trans("Contract"), "");
111 
112 $form = new Form($db);
113 $formcompany = new FormCompany($db);
114 $contactstatic = new Contact($db);
115 $userstatic = new User($db);
116 
117 /* *************************************************************************** */
118 /* */
119 /* Mode vue et edition */
120 /* */
121 /* *************************************************************************** */
122 
123 if ($id > 0 || !empty($ref)) {
124  if ($object->fetch($id, $ref) > 0) {
125  $object->fetch_thirdparty();
126 
127  $head = contract_prepare_head($object);
128 
129  $hselected = 1;
130 
131  print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
132 
133  // Contract card
134 
135  $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
136 
137 
138  $morehtmlref = '';
139  //if (! empty($modCodeContract->code_auto)) {
140  $morehtmlref .= $object->ref;
141  /*} else {
142  $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
143  $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
144  }*/
145 
146  $morehtmlref .= '<div class="refidno">';
147  // Ref customer
148  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
149  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1, 'getFormatedCustomerRef');
150  // Ref supplier
151  $morehtmlref .= '<br>';
152  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
153  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
154  // Thirdparty
155  $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
156  // Project
157  if (!empty($conf->project->enabled)) {
158  $langs->load("projects");
159  $morehtmlref .= '<br>'.$langs->trans('Project').' ';
160  if ($user->rights->contrat->creer) {
161  if ($action != 'classify') {
162  //$morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
163  $morehtmlref .= ' : ';
164  }
165  if ($action == 'classify') {
166  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
167  $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
168  $morehtmlref .= '<input type="hidden" name="action" value="classin">';
169  $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
170  $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
171  $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
172  $morehtmlref .= '</form>';
173  } else {
174  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
175  }
176  } else {
177  if (!empty($object->fk_project)) {
178  $proj = new Project($db);
179  $proj->fetch($object->fk_project);
180  $morehtmlref .= ' : '.$proj->getNomUrl(1);
181  if ($proj->title) {
182  $morehtmlref .= ' - '.$proj->title;
183  }
184  } else {
185  $morehtmlref .= '';
186  }
187  }
188  }
189  $morehtmlref .= '</div>';
190 
191 
192  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
193 
194 
195  print '<div class="fichecenter">';
196  print '<div class="underbanner clearboth"></div>';
197 
198  print '<table class="border tableforfield" width="100%">';
199 
200 
201  // Ligne info remises tiers
202  print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
203  if ($object->thirdparty->remise_percent) {
204  print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent);
205  } else {
206  print $langs->trans("CompanyHasNoRelativeDiscount");
207  }
208  $absolute_discount = $object->thirdparty->getAvailableDiscounts();
209  print '. ';
210  if ($absolute_discount) {
211  print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency));
212  } else {
213  print $langs->trans("CompanyHasNoAbsoluteDiscount");
214  }
215  print '.';
216  print '</td></tr>';
217 
218  // Date
219  print '<tr>';
220  print '<td class="titlefield">';
221  print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, 0);
222  print '</td><td>';
223  print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, 0, 'datehourpicker');
224  print '</td>';
225  print '</tr>';
226 
227  print "</table>";
228 
229  print '</div>';
230 
231  print dol_get_fiche_end();
232 
233  print '<br>';
234 
235  // Contacts lines
236  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
237  } else {
238  print "ErrorRecordNotFound";
239  }
240 }
241 
242 
243 llxFooter();
244 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
Project
Class to manage projects.
Definition: project.class.php:35
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
dol_banner_tab
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.
Definition: functions.lib.php:2046
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
Contrat
Class to manage contracts.
Definition: contrat.class.php:43
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
contract_prepare_head
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
Definition: contract.lib.php:31
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59