actions_dellink.inc.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. /**
  19. * \file htdocs/core/actions_dellink.inc.php
  20. * \brief Code for actions on linking and deleting link between elements
  21. */
  22. // $action must be defined
  23. // $object must be defined
  24. // $permissiondellink must be defined
  25. $dellinkid = GETPOST('dellinkid', 'int');
  26. $addlink = GETPOST('addlink', 'alpha');
  27. $addlinkid = GETPOST('idtolinkto', 'int');
  28. $addlinkref = GETPOST('reftolinkto', 'alpha');
  29. $cancellink = GETPOST('cancel', 'alpha');
  30. // Link object to another object
  31. if ($action == 'addlink' && !empty($permissiondellink) && !$cancellink && $id > 0 && $addlinkid > 0) {
  32. $object->fetch($id);
  33. $object->fetch_thirdparty();
  34. $result = $object->add_object_linked($addlink, $addlinkid);
  35. }
  36. // Link by reference
  37. if ($action == 'addlinkbyref' && !empty($permissiondellink) && !$cancellink && $id > 0 && !empty($addlinkref) && !empty($conf->global->MAIN_LINK_BY_REF_IN_LINKTO)) {
  38. $element_prop = getElementProperties($addlink);
  39. if (is_array($element_prop)) {
  40. dol_include_once('/' . $element_prop['classpath'] . '/' . $element_prop['classfile'] . '.class.php');
  41. $objecttmp = new $element_prop['classname']($db);
  42. $ret = $objecttmp->fetch(0, $addlinkref);
  43. if ($ret > 0) {
  44. $object->fetch($id);
  45. $object->fetch_thirdparty();
  46. $result = $object->add_object_linked($addlink, $objecttmp->id);
  47. if (isset($_POST['reftolinkto'])) unset($_POST['reftolinkto']);
  48. } elseif ($ret < 0) {
  49. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  50. } else {
  51. $langs->load('errors');
  52. setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors');
  53. }
  54. }
  55. }
  56. // Delete link in table llx_element_element
  57. if ($action == 'dellink' && !empty($permissiondellink) && !$cancellink && $dellinkid > 0) {
  58. $result = $object->deleteObjectLinked(0, '', 0, '', $dellinkid);
  59. if ($result < 0) {
  60. setEventMessages($object->error, $object->errors, 'errors');
  61. }
  62. }