dolibarr 18.0.6
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 = GETPOST('dellinkid', 'int');
30$addlink = GETPOST('addlink', 'alpha');
31$addlinkid = GETPOST('idtolinkto', 'int');
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) && !empty($conf->global->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'])) unset($_POST['reftolinkto']);
55 } elseif ($ret < 0) {
56 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
57 } else {
58 $langs->load('errors');
59 setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors');
60 }
61 }
62}
63
64// Delete link in table llx_element_element
65if ($action == 'dellink' && !empty($permissiondellink) && !$cancellink && $dellinkid > 0) {
66 $result = $object->deleteObjectLinked(0, '', 0, '', $dellinkid);
67 if ($result < 0) {
68 setEventMessages($object->error, $object->errors, 'errors');
69 }
70}
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
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.
getElementProperties($element_type)
Get an array with properties of an element.