dolibarr  18.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-2016 Destailleur Laurent <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2022 Philippe Grand <philippe.grand@atoo-net.com>
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.'/comm/propal/class/propal.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
35 
36 // Load translation files required by the page
37 $langs->loadLangs(array('facture', 'propal', 'orders', 'sendings', 'companies'));
38 
39 $id = GETPOST('id', 'int');
40 $ref = GETPOST('ref', 'alpha');
41 $lineid = GETPOST('lineid', 'int');
42 $action = GETPOST('action', 'aZ09');
43 
44 $object = new Propal($db);
45 
46 // Load object
47 if ($id > 0 || !empty($ref)) {
48  $ret = $object->fetch($id, $ref);
49  if ($ret == 0) {
50  $langs->load("errors");
51  setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
52  $error++;
53  } elseif ($ret < 0) {
54  setEventMessages($object->error, $object->errors, 'errors');
55  $error++;
56  }
57 }
58 if (!$error) {
59  $object->fetch_thirdparty();
60 } else {
61  header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
62  exit;
63 }
64 
65 // Security check
66 $socid = '';
67 if (!empty($user->socid)) {
68  $socid = $user->socid;
69 }
70 restrictedArea($user, 'propal', $object->id);
71 
72 $usercancreate = $user->hasRight("propal", "creer");
73 
74 
75 /*
76  * Add a new contact
77  */
78 
79 if ($action == 'addcontact' && $user->hasRight('propal', 'creer')) {
80  if ($object->id > 0) {
81  $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
82  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
83  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
84  }
85 
86  if ($result >= 0) {
87  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
88  exit;
89  } else {
90  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
91  $langs->load("errors");
92  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
93  } else {
94  setEventMessages($object->error, $object->errors, 'errors');
95  }
96  }
97 } elseif ($action == 'swapstatut' && $user->hasRight('propal', 'creer')) {
98  // Toggle the status of a contact
99  if ($object->id > 0) {
100  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
101  }
102 } elseif ($action == 'deletecontact' && $user->hasRight('propal', 'creer')) {
103  // Deletes a contact
104  $result = $object->delete_contact($lineid);
105 
106  if ($result >= 0) {
107  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
108  exit;
109  } else {
110  dol_print_error($db);
111  }
112 }
113 
114 
115 /*
116  * View
117  */
118 $title = $object->ref." - ".$langs->trans('ContactsAddresses');
119 $help_url = "EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos";
120 
121 llxHeader('', $title, $help_url);
122 
123 $form = new Form($db);
124 $formcompany = new FormCompany($db);
125 $formother = new FormOther($db);
126 
127 if ($object->id > 0) {
128  $head = propal_prepare_head($object);
129  print dol_get_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal');
130 
131 
132  // Proposal card
133 
134  $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
135 
136 
137  $morehtmlref = '<div class="refidno">';
138  // Ref customer
139  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
140  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
141  // Thirdparty
142  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
143  // Project
144  if (isModEnabled('project')) {
145  $langs->load("projects");
146  $morehtmlref .= '<br>';
147  if (0) {
148  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
149  if ($action != 'classify') {
150  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
151  }
152  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
153  } else {
154  if (!empty($object->fk_project)) {
155  $proj = new Project($db);
156  $proj->fetch($object->fk_project);
157  $morehtmlref .= $proj->getNomUrl(1);
158  if ($proj->title) {
159  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
160  }
161  }
162  }
163  }
164  $morehtmlref .= '</div>';
165 
166  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
167 
168  print dol_get_fiche_end();
169 
170 
171  // Contacts lines (modules that overwrite templates must declare this into descriptor)
172  $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
173  foreach ($dirtpls as $reldir) {
174  $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
175  if ($res) {
176  break;
177  }
178  }
179 }
180 
181 // End of page
182 llxFooter();
183 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
Project
Class to manage projects.
Definition: project.class.php:36
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:609
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:5107
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1158
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4652
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:2205
$help_url
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
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
llxHeader
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
propal_prepare_head
propal_prepare_head($object)
Prepare array with list of tabs.
Definition: propal.lib.php:32
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
restrictedArea
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.
Definition: security.lib.php:353
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11654
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2177
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
dol_get_fiche_head
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.
Definition: functions.lib.php:1979
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
Propal
Class to manage proposals.
Definition: propal.class.php:52