diff --git a/SeedDMS_Core/Core/inc.ClassDocument.php b/SeedDMS_Core/Core/inc.ClassDocument.php index 963b4a980..0e71c9054 100644 --- a/SeedDMS_Core/Core/inc.ClassDocument.php +++ b/SeedDMS_Core/Core/inc.ClassDocument.php @@ -2219,20 +2219,39 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */ function addDocumentLink($targetID, $userID, $public) { /* {{{ */ $db = $this->_dms->getDB(); - $public = ($public) ? "1" : "0"; + $public = ($public) ? 1 : 0; - $queryStr = "INSERT INTO `tblDocumentLinks` (`document`, `target`, `userID`, `public`) VALUES (".$this->_id.", ".(int)$targetID.", ".(int)$userID.", ".(int)$public.")"; + if (!is_numeric($targetID) || $targetID < 1) + return false; + + if ($targetID == $this->_id) + return false; + + if (!is_numeric($userID) || $userID < 1) + return false; + + if(!($target = $this->_dms->getDocument($targetID))) + return false; + + if(!($user = $this->_dms->getUser($userID))) + return false; + + $queryStr = "INSERT INTO `tblDocumentLinks` (`document`, `target`, `userID`, `public`) VALUES (".$this->_id.", ".(int)$targetID.", ".(int)$userID.", ".$public.")"; if (!$db->getResult($queryStr)) return false; unset($this->_documentLinks); - return true; + + $id = $db->getInsertID('tblDocumentLinks'); + $link = new SeedDMS_Core_DocumentLink($id, $this, $target, $user->getId(), $public); + return $link; } /* }}} */ function removeDocumentLink($linkID) { /* {{{ */ $db = $this->_dms->getDB(); - if (!is_numeric($linkID)) return false; + if (!is_numeric($linkID) || $linkID < 1) + return false; $queryStr = "DELETE FROM `tblDocumentLinks` WHERE `document` = " . $this->_id ." AND `id` = " . (int) $linkID; if (!$db->getResult($queryStr)) return false;