dolibarr 20.0.2
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 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 * or see https://www.gnu.org/
17 */
18
25// $action must be defined
26// $object must be defined
27// $permissiondellink must be defined
28
29$dellinkid = GETPOSTINT('dellinkid');
30$addlink = GETPOST('addlink', 'alpha');
31$addlinkid = GETPOSTINT('idtolinkto');
32$addlinkref = GETPOST('reftolinkto', 'alpha');
33$cancellink = GETPOST('cancel', 'alpha');
34
35// Link object to another object
36if ($action == 'addlink' && !empty($permissiondellink) && !$cancellink && $id > 0 && $addlinkid > 0) {
37 $object->fetch($id);
38 $object->fetch_thirdparty();
39 $result = $object->add_object_linked($addlink, $addlinkid);
40}
41
42// Link by reference
43if ($action == 'addlinkbyref' && !empty($permissiondellink) && !$cancellink && $id > 0 && !empty($addlinkref) && getDolGlobalString('MAIN_LINK_BY_REF_IN_LINKTO')) {
44 $element_prop = getElementProperties($addlink);
45 if (is_array($element_prop)) {
46 dol_include_once('/' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
47
48 $objecttmp = new $element_prop['classname']($db);
49 $ret = $objecttmp->fetch(0, $addlinkref);
50 if ($ret > 0) {
51 $object->fetch($id);
52 $object->fetch_thirdparty();
53 $result = $object->add_object_linked($addlink, $objecttmp->id);
54 if (isset($_POST['reftolinkto'])) {
55 unset($_POST['reftolinkto']);
56 }
57 } elseif ($ret < 0) {
58 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
59 } else {
60 $langs->load('errors');
61 setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors');
62 }
63 }
64}
65
66// Delete link in table llx_element_element
67if ($action == 'dellink' && !empty($permissiondellink) && !$cancellink && $dellinkid > 0) {
68 $result = $object->deleteObjectLinked(0, '', 0, '', $dellinkid);
69 if ($result < 0) {
70 setEventMessages($object->error, $object->errors, 'errors');
71 }
72}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
setEventMessage($mesgs, $style='mesgs', $noduplicate=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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.