dolibarr 21.0.0-alpha
actions_dellink.inc.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2015-2016 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 * or see https://www.gnu.org/
18 */
19
26// $action must be defined
27// $object must be defined
28// $permissiondellink must be defined
29
30$dellinkid = GETPOSTINT('dellinkid');
31$addlink = GETPOST('addlink', 'alpha');
32$addlinkids = GETPOST('idtolinkto', 'array:int');
33$addlinkref = GETPOST('reftolinkto', 'alpha');
34$cancellink = GETPOST('cancel', 'alpha');
35
36// Link object to another object
37if ($action == 'addlink' && !empty($permissiondellink) && !$cancellink && $id > 0 && !empty($addlinkids)) {
38 $object->fetch($id);
39 $object->fetch_thirdparty();
40 foreach ($addlinkids as $addlinkid) {
41 $result = $object->add_object_linked($addlink, $addlinkid);
42 }
43}
44
45// Link by reference
46if ($action == 'addlinkbyref' && !empty($permissiondellink) && !$cancellink && $id > 0 && !empty($addlinkref) && !getDolGlobalString('MAIN_HIDE_LINK_BY_REF_IN_LINKTO')) {
47 $element_prop = getElementProperties($addlink);
48 if (is_array($element_prop)) {
49 dol_include_once('/' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
50
51 $objecttmp = new $element_prop['classname']($db);
52 '@phan-var-force CommonObject $objecttmp';
53 $ret = $objecttmp->fetch(0, $addlinkref);
54 if ($ret > 0) {
55 $object->fetch($id);
56 $object->fetch_thirdparty();
57 $result = $object->add_object_linked($addlink, $objecttmp->id);
58 if (isset($_POST['reftolinkto'])) {
59 unset($_POST['reftolinkto']);
60 }
61 } elseif ($ret < 0) {
62 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
63 } else {
64 $langs->load('errors');
65 setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors');
66 }
67 }
68}
69
70// Delete link in table llx_element_element
71if ($action == 'dellink' && !empty($permissiondellink) && !$cancellink && $dellinkid > 0) {
72 $result = $object->deleteObjectLinked(0, '', 0, '', $dellinkid);
73 if ($result < 0) {
74 setEventMessages($object->error, $object->errors, 'errors');
75 }
76}
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
getElementProperties($elementType)
Get an array with properties of an element.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.