documentModify.inc
4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/***
* Class documentModify.inc
*
* Contains all functions required to upload, alter and
* delete a document.
*
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @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
*
* @return true is the user has folder write permission, false otherwise and set $_SESSION["errorMessage"]
*/
function hasFolderWritePermission($iFolderID) {
return true;
}
/**
* Check is the user is assigned a specific role that has write permission for a folder
*
* @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($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;
}
$_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;
}
/**
* Get the primary key for a role
*
* @param $sRoleName Name of role to get primary key for
*
* @return ID if role exists, false otherwise and set $_SESSION["errorMessage"]
*/
function getRoleID($sRoleName) {
global $default, $lang_database_error;
if (roleExists($sRoleName) {
$sql = new Owl_DB();
$sql->query("SELECT id FROM " . $default->owl_role_table . " WHERE name = '" . $sRoleName . "'";
sql->next_record();
return sql->f("id");
}
$_SESSION["errorMessage"] = $lang_database_error;
return false;
}
/**
* Checks if a given role exists
*
* @param $sRoleName Role to check for
*
* @return true if role exists, false otherwise and set $_SESSION["errorMessage"]
*/
function roleExists($sRoleName) {
global $default;
$sql = new Owl_DB();
$sql->query("SELECT id FROM " . $default->owl_role_table . " WHERE name = '" . $sRoleName . "'";
if (sql->next_record()) {
return true;
}
$_SESSION["errorMessage"] = $lang_err_role_not_exist . $sRoleName;
return false;
}
}
?>