dolibarr 23.0.3
contact.php
1<?php
2/* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
3 * Copyright (C) 2007-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
8
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array('products'));
47
48$id = GETPOSTINT('id');
49$ref = GETPOST('ref', 'alpha');
50$action = GETPOST('action', 'aZ09');
51
52$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
53$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
54if ($user->socid) {
55 $socid = $user->socid;
56}
57
58$object = new Product($db);
59$result = $object->fetch($id, $ref);
60if (!$result) {
61 print 'Record not found';
62 exit;
63}
64
65if ($object->id > 0) {
66 if ($object->type == $object::TYPE_PRODUCT) {
67 restrictedArea($user, 'product', $id, 'product&product', '', '');
68 }
69 if ($object->type == $object::TYPE_SERVICE) {
70 restrictedArea($user, 'service', $id, 'product&product', '', '');
71 }
72} else {
73 restrictedArea($user, 'product|service', $fieldvalue, 'product&product', '', '', $fieldtype);
74}
75
76
77$usercancreate = ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'));
78
79/*
80 * Adding a new contact
81 */
82
83if ($action == 'addcontact' && $usercancreate) {
84 if ($result > 0 && $id > 0) {
85 $contactid = (GETPOSTINT('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid'));
86 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
87 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
88 }
89
90 if ($result >= 0) {
91 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
92 exit;
93 } else {
94 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
95 $langs->load("errors");
96 $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
97 } else {
98 $mesg = $object->error;
99 }
100
101 setEventMessages($mesg, null, 'errors');
102 }
103} elseif ($action == 'swapstatut' && $usercancreate) {
104 // Toggle the status of a contact
105 $result = $object->swapContactStatus(GETPOSTINT('ligne'));
106} elseif ($action == 'deletecontact' && $usercancreate) {
107 // Deletes a contact
108 $result = $object->delete_contact(GETPOSTINT('lineid'));
109
110 if ($result >= 0) {
111 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
112 exit;
113 } else {
114 dol_print_error($db);
115 }
116}
117
118
119/*
120 * View
121 */
122
123$form = new Form($db);
124$formcompany = new FormCompany($db);
125$contactstatic = new Contact($db);
126$userstatic = new User($db);
127
128$title = $langs->trans('ProductServiceCard');
129$help_url = "";
130$shortlabel = dol_trunc($object->label, 16);
131if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
132 $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('Notes');
133 $help_url = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos|DE:Modul_Produkte';
134}
135if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
136 $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('Notes');
137 $help_url = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios|DE:Modul_Leistungen';
138}
139
140llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-product page-card_note');
141
142// Mode vue et edition
143
144if ($id > 0 || !empty($ref)) {
145 $object->fetch_thirdparty();
146
147 $head = product_prepare_head($object);
148 $titre = $langs->trans("CardProduct".$object->type);
149 $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
150
151 print dol_get_fiche_head($head, 'contact', $titre, -1, $picto);
152
153
154 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1&type='.$object->type.'">'.$langs->trans("BackToList").'</a>';
155 $object->next_prev_filter = "(te.fk_product_type:=:".((int) $object->type).")";
156
157 $shownav = 1;
158 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
159 $shownav = 0;
160 }
161
162 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
163
164 print dol_get_fiche_end();
165
166 print '<br>';
167
168 if (getDolGlobalString('PRODUCT_HIDE_ADD_CONTACT_USER')) {
169 $hideaddcontactforuser = 1;
170 }
171 if (getDolGlobalString('PRODUCT_HIDE_ADD_CONTACT_THIPARTY')) {
172 $hideaddcontactforthirdparty = 1;
173 }
174
175 // Contacts lines (modules that overwrite templates must declare this into descriptor)
176 $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
177 foreach ($dirtpls as $reldir) {
178 $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
179 if ($res) {
180 break;
181 }
182 }
183}
184
185
186llxFooter();
187$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
Class to manage contact/addresses.
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 products or services.
const TYPE_PRODUCT
Regular product.
const TYPE_SERVICE
Service.
Class to manage Dolibarr users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
product_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.