dolibarr 21.0.0-beta
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 * Copyright (C) 2023 Christian Foellmann <christian@foellmann.de>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
32require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
34require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
37
46// Load translation files required by the page
47$langs->loadLangs(array('facture', 'propal', 'orders', 'sendings', 'companies'));
48
49$id = GETPOSTINT('id');
50$ref = GETPOST('ref', 'alpha');
51$lineid = GETPOSTINT('lineid');
52$action = GETPOST('action', 'aZ09');
53
54$object = new Propal($db);
55$error = 0;
56
57// Load object
58if ($id > 0 || !empty($ref)) {
59 $ret = $object->fetch($id, $ref);
60 if ($ret == 0) {
61 $langs->load("errors");
62 setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
63 $error++;
64 } elseif ($ret < 0) {
65 setEventMessages($object->error, $object->errors, 'errors');
66 $error++;
67 }
68}
69if (!$error) {
70 $object->fetch_thirdparty();
71} else {
72 header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
73 exit;
74}
75
76// Security check
77$socid = '';
78if (!empty($user->socid)) {
79 $socid = $user->socid;
80}
81$hookmanager->initHooks(array('proposalcontactcard', 'globalcard'));
82$result = restrictedArea($user, 'propal', $object->id);
83
84restrictedArea($user, 'propal', $object->id);
85
86$usercancreate = $user->hasRight("propal", "creer");
87
88/*
89 * Actions
90 */
91
92$parameters = array('id'=>$id);
93$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
94if ($reshook < 0) {
95 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
96}
97
98if (empty($reshook)) {
99 // Add new contact
100 if ($action == 'addcontact' && $user->hasRight('propal', 'creer')) {
101 if ($object->id > 0) {
102 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
103 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
104 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
105 }
106
107 if ($result >= 0) {
108 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
109 exit;
110 } else {
111 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
112 $langs->load("errors");
113 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
114 } else {
115 setEventMessages($object->error, $object->errors, 'errors');
116 }
117 }
118 } elseif ($action == 'swapstatut' && $user->hasRight('propal', 'creer')) {
119 // Toggle the status of a contact
120 if ($object->id > 0) {
121 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
122 }
123 } elseif ($action == 'deletecontact' && $user->hasRight('propal', 'creer')) {
124 // Delete contact
125 $result = $object->delete_contact($lineid);
126
127 if ($result >= 0) {
128 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
129 exit;
130 } else {
131 dol_print_error($db);
132 }
133 }
134}
135
136/*
137 * View
138 */
139$title = $object->ref." - ".$langs->trans('ContactsAddresses');
140$help_url = "EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos";
141
142llxHeader('', $title, $help_url);
143
144$form = new Form($db);
145$formcompany = new FormCompany($db);
146$formother = new FormOther($db);
147
148if ($object->id > 0) {
149 $head = propal_prepare_head($object);
150 print dol_get_fiche_head($head, 'contact', $langs->trans("Proposal"), -1, 'propal');
151
152
153 // Proposal card
154
155 $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
156
157
158 $morehtmlref = '<div class="refidno">';
159 // Ref customer
160 $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
161 $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
162 // Thirdparty
163 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'customer');
164 // Project
165 if (isModEnabled('project')) {
166 $langs->load("projects");
167 $morehtmlref .= '<br>';
168 if (0) {
169 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
170 if ($action != 'classify') {
171 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
172 }
173 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
174 } else {
175 if (!empty($object->fk_project)) {
176 $proj = new Project($db);
177 $proj->fetch($object->fk_project);
178 $morehtmlref .= $proj->getNomUrl(1);
179 if ($proj->title) {
180 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
181 }
182 }
183 }
184 }
185 $morehtmlref .= '</div>';
186
187 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1);
188
189 print dol_get_fiche_end();
190
191
192 // Contacts lines (modules that overwrite templates must declare this into descriptor)
193 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
194 foreach ($dirtpls as $reldir) {
195 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
196 if ($res) {
197 break;
198 }
199 }
200}
201
202// End of page
203llxFooter();
204$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
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 permettant la generation de composants html autre Only common components are here.
Class to manage projects.
Class to manage proposals.
llxFooter()
Footer empty.
Definition document.php:107
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
propal_prepare_head($object)
Prepare array with list of tabs.
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.