Commit 536fac81d8d24b2899d31864d3bb8aeebbfb52e1
1 parent
29705907
Added basic file upload functions
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@150 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
95 additions
and
16 deletions
lib/documentmanagement/documentModify.inc
| @@ -10,9 +10,84 @@ | @@ -10,9 +10,84 @@ | ||
| 10 | * @date 13 January 2003 | 10 | * @date 13 January 2003 |
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | +require_once ("$default->owl_root_url/lib/owl.lib.php"); | ||
| 14 | + | ||
| 13 | class DocumentModify { | 15 | class DocumentModify { |
| 14 | 16 | ||
| 15 | /** | 17 | /** |
| 18 | + * Upload and store a new document | ||
| 19 | + * | ||
| 20 | + * @param $aUserDocument An array containing uploaded file information generated by calling | ||
| 21 | + * uploadCompat($varname) in owl.lib.php | ||
| 22 | + * @param $iFolderID Folder in which to store document | ||
| 23 | + * | ||
| 24 | + * @return true on successful upload and storage, false otherwise and set $_SESSION["errorMessage"] | ||
| 25 | + * | ||
| 26 | + * @todo add URL functionality | ||
| 27 | + */ | ||
| 28 | + | ||
| 29 | + function uploadDocument($aUserDocument, $iFolderID) { | ||
| 30 | + global $lang_fileexists, $lang_err_upload; | ||
| 31 | + //check if the user has folder write permissions | ||
| 32 | + if ($this->hasFolderWritePermissions($iFolderID) || $this->hasWriteRoleForFolder($iFolderID) || $this->isInGroup("System Administrators")) { | ||
| 33 | + //if the user is within his quota after uploading the file | ||
| 34 | + if (isWithinQuote($aUserDocument["size"])) { | ||
| 35 | + $sNewPath = $this->generatePath($iFolderID); | ||
| 36 | + //if the file already exists, return false and display an error | ||
| 37 | + if(file_exists($sNewPath . $aUserDocument["name"])) { | ||
| 38 | + $_SESSION["errorMessage"] = $lang_fileexists | ||
| 39 | + return false; | ||
| 40 | + } | ||
| 41 | + copy($userfile["tmp_name"], $sNewPath); | ||
| 42 | + unlink($userfile["tmp_name"]); | ||
| 43 | + if(!file_exists($sNewPath)) { | ||
| 44 | + if ($default->debug == true) { | ||
| 45 | + $_SESSION["errorMessage"] = $lang_err_upload . "," .$sNewPath; | ||
| 46 | + return false; | ||
| 47 | + } else { | ||
| 48 | + $_SESSION["errorMessage"] = $lang_err_upload; | ||
| 49 | + return false; | ||
| 50 | + } | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * Generate the path for the current folder by recursing up the tree to its parents | ||
| 58 | + * | ||
| 59 | + * @return path | ||
| 60 | + */ | ||
| 61 | + function generatePath($iFolderID) { | ||
| 62 | + return ""; | ||
| 63 | + | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + /** | ||
| 67 | + * Checks whether the user will be within his/her current quota if a new file is uploaded | ||
| 68 | + * | ||
| 69 | + * @param $iNewFileSize Size of new file | ||
| 70 | + * | ||
| 71 | + * @return true if the user is within quota, false otherwise and sets $_SESSION["errorMessage"] | ||
| 72 | + */ | ||
| 73 | + | ||
| 74 | + function isWithinQuota($iNewFileSize) { | ||
| 75 | + return true; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Generates a path for a folder | ||
| 80 | + * | ||
| 81 | + * @param $sFolderName Name of folder to generate path for | ||
| 82 | + * | ||
| 83 | + * @returns generated path | ||
| 84 | + */ | ||
| 85 | + | ||
| 86 | + function generatePath($sFolderName) { | ||
| 87 | + | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 16 | * Checks if the current user has write permission for a specific folder | 91 | * Checks if the current user has write permission for a specific folder |
| 17 | * | 92 | * |
| 18 | * @param $iFolderID Primary key of folder to check | 93 | * @param $iFolderID Primary key of folder to check |
| @@ -26,27 +101,31 @@ class DocumentModify { | @@ -26,27 +101,31 @@ class DocumentModify { | ||
| 26 | 101 | ||
| 27 | /** | 102 | /** |
| 28 | * Check is the user is assigned a specific role that has write permission for a folder | 103 | * Check is the user is assigned a specific role that has write permission for a folder |
| 29 | - * * | ||
| 30 | - * @param $sRoleName Name of role to check | 104 | + * |
| 31 | * @param $iFolderID Primary key of folder to check | 105 | * @param $iFolderID Primary key of folder to check |
| 32 | * | 106 | * |
| 33 | * @return true is the user has the role assigned, false otherwise and set $_SESSION["errorMessage"] | 107 | * @return true is the user has the role assigned, false otherwise and set $_SESSION["errorMessage"] |
| 34 | */ | 108 | */ |
| 35 | - function hasWriteRoleForFolder($sRoleName, $iFolderID) { | ||
| 36 | - global $default; | ||
| 37 | - $iRoleID = $this->getRoleID($sRoleName); | ||
| 38 | - if (!($iRoleID === false)) { | ||
| 39 | - $sql = new Owl_DB(); | ||
| 40 | - $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"); | ||
| 41 | - if ($sql->next_record()) { | ||
| 42 | - return true; | ||
| 43 | - } | ||
| 44 | - $_SESSION["errorMessage"] = $lang_err_user_role; | ||
| 45 | - return false; | 109 | + function hasWriteRoleForFolder($iFolderID) { |
| 110 | + global $default; | ||
| 111 | + $sql = new Owl_DB(); | ||
| 112 | + $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"); | ||
| 113 | + if ($sql->next_record()) { | ||
| 114 | + return true; | ||
| 46 | } | 115 | } |
| 47 | - //error message is set in $this->getRoleID($sRoleName); | ||
| 48 | - return false; | ||
| 49 | - | 116 | + $_SESSION["errorMessage"] = $lang_err_user_role; |
| 117 | + return false; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * Checks if the current user is in a given role | ||
| 122 | + * | ||
| 123 | + * @param $sRoleName Name of role to check | ||
| 124 | + * | ||
| 125 | + * @return true if the user is in the role, false otherwise and sets $_SESSION["errorMessage"] | ||
| 126 | + */ | ||
| 127 | + function isInGroup($sGroupName) { | ||
| 128 | + return true; | ||
| 50 | } | 129 | } |
| 51 | 130 | ||
| 52 | /** | 131 | /** |