dolibarr  9.0.0
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 <http://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','alpha');
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->societe_id) $socid=$user->societe_id;
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  $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
67  }
68 
69  if ($result >= 0)
70  {
71  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
72  exit;
73  }
74  else
75  {
76  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
77  $langs->load("errors");
78  $msg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
79  } else {
80  $mesg = $object->error;
81  }
82 
83  setEventMessages($mesg, null, 'errors');
84  }
85 }
86 
87 // bascule du statut d'un contact
88 if ($action == 'swapstatut' && $user->rights->contrat->creer)
89 {
90  if ($object->fetch($id))
91  {
92  $result=$object->swapContactStatus(GETPOST('ligne'));
93  }
94  else
95  {
96  dol_print_error($db,$object->error);
97  }
98 }
99 
100 // Delete contact
101 if ($action == 'deletecontact' && $user->rights->contrat->creer)
102 {
103  $object->fetch($id);
104  $result = $object->delete_contact($_GET["lineid"]);
105 
106  if ($result >= 0)
107  {
108  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
109  exit;
110  }
111 }
112 
113 
114 /*
115  * View
116  */
117 
118 llxHeader('',$langs->trans("Contract"),"");
119 
120 $form = new Form($db);
121 $formcompany= new FormCompany($db);
122 $contactstatic=new Contact($db);
123 $userstatic=new User($db);
124 
125 /* *************************************************************************** */
126 /* */
127 /* Mode vue et edition */
128 /* */
129 /* *************************************************************************** */
130 
131 if ($id > 0 || ! empty($ref))
132 {
133  if ($object->fetch($id, $ref) > 0)
134  {
135  $object->fetch_thirdparty();
136 
137  $head = contract_prepare_head($object);
138 
139  $hselected=1;
140 
141  dol_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
142 
143  // Contract card
144 
145  $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(! empty($socid)?'&socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
146 
147 
148  $morehtmlref='';
149  //if (! empty($modCodeContract->code_auto)) {
150  $morehtmlref.=$object->ref;
151  /*} else {
152  $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,0,'string','',0,3);
153  $morehtmlref.=$form->editfieldval("",'ref',$object->ref,0,'string','',0,2);
154  }*/
155 
156  $morehtmlref.='<div class="refidno">';
157  // Ref customer
158  $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', 0, 1);
159  $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, 0, 'string', '', null, null, '', 1);
160  // Ref supplier
161  $morehtmlref.='<br>';
162  $morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1);
163  $morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1);
164  // Thirdparty
165  $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
166  // Project
167  if (! empty($conf->projet->enabled)) {
168  $langs->load("projects");
169  $morehtmlref.='<br>'.$langs->trans('Project') . ' ';
170  if ($user->rights->contrat->creer) {
171  if ($action != 'classify') {
172  //$morehtmlref.='<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
173  $morehtmlref.=' : ';
174  }
175  if ($action == 'classify') {
176  //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
177  $morehtmlref.='<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
178  $morehtmlref.='<input type="hidden" name="action" value="classin">';
179  $morehtmlref.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
180  $morehtmlref.=$formproject->select_projects($object->thirdparty->id, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
181  $morehtmlref.='<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
182  $morehtmlref.='</form>';
183  } else {
184  $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->thirdparty->id, $object->fk_project, 'none', 0, 0, 0, 1);
185  }
186  } else {
187  if (! empty($object->fk_project)) {
188  $proj = new Project($db);
189  $proj->fetch($object->fk_project);
190  $morehtmlref.='<a href="'.DOL_URL_ROOT.'/projet/card.php?id=' . $object->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
191  $morehtmlref.=$proj->ref;
192  $morehtmlref.='</a>';
193  } else {
194  $morehtmlref.='';
195  }
196  }
197  }
198  $morehtmlref.='</div>';
199 
200 
201  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
202 
203 
204  print '<div class="fichecenter">';
205  print '<div class="underbanner clearboth"></div>';
206 
207  print '<table class="border" width="100%">';
208 
209 
210  // Ligne info remises tiers
211  print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
212  if ($object->thirdparty->remise_percent) {
213  print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent);
214  } else {
215  print $langs->trans("CompanyHasNoRelativeDiscount");
216  }
217  $absolute_discount = $object->thirdparty->getAvailableDiscounts();
218  print '. ';
219  if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
220  else print $langs->trans("CompanyHasNoAbsoluteDiscount");
221  print '.';
222  print '</td></tr>';
223 
224  // Date
225  print '<tr>';
226  print '<td class="titlefield">';
227  print $form->editfieldkey("Date",'date_contrat',$object->date_contrat,$object,0);
228  print '</td><td>';
229  print $form->editfieldval("Date",'date_contrat',$object->date_contrat,$object,0,'datehourpicker');
230  print '</td>';
231  print '</tr>';
232 
233  print "</table>";
234 
235  print '</div>';
236 
237  dol_fiche_end();
238 
239  print '<br>';
240 
241  // Contacts lines
242  include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php';
243  } else {
244  print "ErrorRecordNotFound";
245  }
246 }
247 
248 
249 llxFooter();
250 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class to manage contact/addresses.
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.
Class to manage Dolibarr users.
Definition: user.class.php:41
Class to manage contracts.
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
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.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
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.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.