42$addlink =
GETPOST(
'addlink',
'alpha');
43$addlinkids =
GETPOST(
'idtolinkto',
'array:int');
44$addlinkref =
GETPOST(
'reftolinkto',
'alpha');
45$cancellink =
GETPOST(
'cancel',
'alpha');
48if ($action ==
'addlink' && !empty($permissiondellink) && !$cancellink &&
$id > 0 && !empty($addlinkids)) {
51 foreach ($addlinkids as $addlinkid) {
52 $result =
$object->add_object_linked($addlink, $addlinkid);
54 $object->clearObjectLinkedCache();
58if ($action ==
'addlinkbyref' && !empty($permissiondellink) && !$cancellink &&
$id > 0 && !empty($addlinkref) && !
getDolGlobalString(
'MAIN_HIDE_LINK_BY_REF_IN_LINKTO')) {
60 if (is_array($element_prop)) {
61 dol_include_once(
'/' . $element_prop[
'classpath'] .
'/' . $element_prop[
'classfile'] .
'.class.php');
63 $objecttmp =
new $element_prop[
'classname']($db);
64 '@phan-var-force CommonObject $objecttmp';
66 $ret = $objecttmp->fetch(0, $addlinkref);
70 $result =
$object->add_object_linked($addlink, $objecttmp->id);
71 if (isset($_POST[
'reftolinkto'])) {
72 unset($_POST[
'reftolinkto']);
74 $object->clearObjectLinkedCache();
78 $langs->load(
'errors');
85if ($action ==
'dellink' && !empty($permissiondellink) && !$cancellink && $dellinkid > 0) {
92 $elementtypes = array_unique([
$object->getElementType(),
$object->element]);
93 $sqlelementtypes =
"'".implode(
"','", array_map([$db,
'escape'], $elementtypes)).
"'";
94 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"element_element";
95 $sql .=
" WHERE rowid = ".((int) $dellinkid);
96 $sql .=
" AND ((fk_source = ".((int)
$object->id).
" AND sourcetype IN (".$db->sanitize($sqlelementtypes, 1).
"))";
97 $sql .=
" OR (fk_target = ".((int)
$object->id).
" AND targettype IN (".$db->sanitize($sqlelementtypes, 1).
")))";
98 $resql = $db->query($sql);
99 if ($resql && $db->num_rows($resql) > 0) {
108 $result =
$object->deleteObjectLinked(0,
'', 0,
'', $dellinkid);
109 $object->clearObjectLinkedCache();
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.