load_lang();
$Class_LinkController = new LinkController();
$db = new dbquery;
$db->connect();
$res_parent = $_REQUEST['res_id'];
if ($_REQUEST['mode'] == 'add') {
$self = false;
if ($res_child == $res_parent) {
$self = true;
} else {
$queryTest = "SELECT * FROM res_linked WHERE res_parent=".$res_parent." AND res_child=".$res_child." AND coll_id='".$_SESSION['collection_id_choice']."'";
$db->query($queryTest);
$i = 0;
while($test = $db->fetch_object()) {
$i++;
}
}
if ($i == 0 && !$self) {
$queryAddLink = "INSERT INTO res_linked (res_parent, res_child, coll_id) VALUES('" . $res_parent . "', '" . $res_child . "', '" . $_SESSION['collection_id_choice'] . "')";
$db->query($queryAddLink);
$hist2 = new history();
$hist2->add(
$_REQUEST['tableHist'],
$res_child,
"ADD",
'linkadd',
_LINKED_TO . $res_parent,
$_SESSION['config']['databasetype'],
'apps'
);
$hist3 = new history();
$hist3->add(
$_REQUEST['tableHist'],
$res_parent,
"ADD",
'linkup',
_THE_DOCUMENT_LINK . $res_child . ' ' . _NOW_LINK_WITH_THIS_ONE,
$_SESSION['config']['databasetype'],
'apps'
);
}
} elseif($_REQUEST['mode'] == 'del') {
$queryDelLink = "DELETE FROM res_linked WHERE res_parent=".$res_parent." AND res_child=".$res_child." and coll_id='".$_SESSION['collection_id_choice']."'";
$db->query($queryDelLink);
$hist2 = new history();
$hist2->add(
$_REQUEST['tableHist'],
$res_child,
"DEL",
'linkdel',
_LINK_TO_THE_DOCUMENT. ' ('.$res_parent.') ' . _LINK_DELETED,
$_SESSION['config']['databasetype'],
'apps'
);
$hist3 = new history();
$hist3->add(
$_REQUEST['tableHist'],
$res_parent,
"DEL",
'linkdel',
_THE_DOCUMENT_LINK . $res_child . ' ' . _NO_LINK_WITH_THIS_ONE,
$_SESSION['config']['databasetype'],
'apps'
);
}
$formatText = '';
$nbLinkDesc = $Class_LinkController->nbDirectLink(
$_SESSION['doc_id'],
$_SESSION['collection_id_choice'],
'desc'
);
if ($nbLinkDesc > 0) {
$formatText .= '';
$formatText .= $Class_LinkController->formatMap(
$Class_LinkController->getMap(
$_SESSION['doc_id'],
$_SESSION['collection_id_choice'],
'desc'
),
'desc'
);
$formatText .= '
';
}
$nbLinkAsc = $Class_LinkController->nbDirectLink(
$_SESSION['doc_id'],
$_SESSION['collection_id_choice'],
'asc'
);
if ($nbLinkAsc > 0) {
$formatText .= '';
$formatText .= $Class_LinkController->formatMap(
$Class_LinkController->getMap(
$_SESSION['doc_id'],
$_SESSION['collection_id_choice'],
'asc'
),
'asc'
);
$formatText .= '
';
}
if ($self) {
$formatText .= '';
}
if ($i != 0) {
$formatText .= '
';
$formatText .= '';
$formatText .= _LINK_ALREADY_EXISTS;
$formatText .= '';
$formatText .= '
';
$formatText .= '
';
}
$nb = $Class_LinkController->nbDirectLink(
$_SESSION['doc_id'],
$_SESSION['collection_id_choice'],
'all'
);
echo "{status : 0, links : '" . addslashes($formatText) . "', nb : '".$nb."'}";
exit ();
}
//header("Location: index.php?page=".$_REQUEST['pageHeader']."&dir=".$_REQUEST['dirHeader']."&id=".$res_child);
} else {
$Links .= '