From 536fac81d8d24b2899d31864d3bb8aeebbfb52e1 Mon Sep 17 00:00:00 2001 From: rob Date: Mon, 13 Jan 2003 15:55:33 +0000 Subject: [PATCH] Added basic file upload functions --- lib/documentmanagement/documentModify.inc | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 16 deletions(-) diff --git a/lib/documentmanagement/documentModify.inc b/lib/documentmanagement/documentModify.inc index 2d0a939..75e874a 100644 --- a/lib/documentmanagement/documentModify.inc +++ b/lib/documentmanagement/documentModify.inc @@ -10,9 +10,84 @@ * @date 13 January 2003 */ +require_once ("$default->owl_root_url/lib/owl.lib.php"); + class DocumentModify { /** + * Upload and store a new document + * + * @param $aUserDocument An array containing uploaded file information generated by calling + * uploadCompat($varname) in owl.lib.php + * @param $iFolderID Folder in which to store document + * + * @return true on successful upload and storage, false otherwise and set $_SESSION["errorMessage"] + * + * @todo add URL functionality + */ + + function uploadDocument($aUserDocument, $iFolderID) { + global $lang_fileexists, $lang_err_upload; + //check if the user has folder write permissions + if ($this->hasFolderWritePermissions($iFolderID) || $this->hasWriteRoleForFolder($iFolderID) || $this->isInGroup("System Administrators")) { + //if the user is within his quota after uploading the file + if (isWithinQuote($aUserDocument["size"])) { + $sNewPath = $this->generatePath($iFolderID); + //if the file already exists, return false and display an error + if(file_exists($sNewPath . $aUserDocument["name"])) { + $_SESSION["errorMessage"] = $lang_fileexists + return false; + } + copy($userfile["tmp_name"], $sNewPath); + unlink($userfile["tmp_name"]); + if(!file_exists($sNewPath)) { + if ($default->debug == true) { + $_SESSION["errorMessage"] = $lang_err_upload . "," .$sNewPath; + return false; + } else { + $_SESSION["errorMessage"] = $lang_err_upload; + return false; + } + } + } + + } + + /** + * Generate the path for the current folder by recursing up the tree to its parents + * + * @return path + */ + function generatePath($iFolderID) { + return ""; + + } + + /** + * Checks whether the user will be within his/her current quota if a new file is uploaded + * + * @param $iNewFileSize Size of new file + * + * @return true if the user is within quota, false otherwise and sets $_SESSION["errorMessage"] + */ + + function isWithinQuota($iNewFileSize) { + return true; + } + + /** + * Generates a path for a folder + * + * @param $sFolderName Name of folder to generate path for + * + * @returns generated path + */ + + function generatePath($sFolderName) { + + } + + /** * Checks if the current user has write permission for a specific folder * * @param $iFolderID Primary key of folder to check @@ -26,27 +101,31 @@ class DocumentModify { /** * Check is the user is assigned a specific role that has write permission for a folder - * * - * @param $sRoleName Name of role to check + * * @param $iFolderID Primary key of folder to check * * @return true is the user has the role assigned, false otherwise and set $_SESSION["errorMessage"] */ - function hasWriteRoleForFolder($sRoleName, $iFolderID) { - global $default; - $iRoleID = $this->getRoleID($sRoleName); - if (!($iRoleID === false)) { - $sql = new Owl_DB(); - $sql->query("SELECT * FROM " . $default->owl_folders_user_links_table . " AS FURL INNER JOIN " . $default->owl_role_table . " AS R ON FURL.role_id = R.id WHERE role_id = " . $iRoleID . " AND folder_id = " . $iFolderID . " AND user_id = " . $_SESSION["user_id"] . " AND R.can_write = 1"); - if ($sql->next_record()) { - return true; - } - $_SESSION["errorMessage"] = $lang_err_user_role; - return false; + function hasWriteRoleForFolder($iFolderID) { + global $default; + $sql = new Owl_DB(); + $sql->query("SELECT * FROM " . $default->owl_folders_user_links_table . " AS FURL INNER JOIN " . $default->owl_role_table . " AS R ON FURL.role_id = R.id WHERE folder_id = " . $iFolderID . " AND user_id = " . $_SESSION["user_id"] . " AND R.can_write = 1"); + if ($sql->next_record()) { + return true; } - //error message is set in $this->getRoleID($sRoleName); - return false; - + $_SESSION["errorMessage"] = $lang_err_user_role; + return false; + } + + /** + * Checks if the current user is in a given role + * + * @param $sRoleName Name of role to check + * + * @return true if the user is in the role, false otherwise and sets $_SESSION["errorMessage"] + */ + function isInGroup($sGroupName) { + return true; } /** -- libgit2 0.21.4