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