FolderManager.inc
4.15 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
<?php
/**
* Class FolderManager
*
* Contains static functions concerned with the insert, update and deletion of folders in
* the database.
*
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @date 15 January 2003
*/
class FolderManager {
/**
* Insert a new folder into the database
*
* @param $sName Folder name
* @param $sDescription Short description of folder
* @param $iParentID Primary key of parent folder
* @param $iCreatorID ID of user who created the folder
* @param $iDocumentTypeID Document type this folder will store
* @param $iUnitID Unit to which the folder belongs
* @param $bIsPublic Is the folder public (default = false);
*
* @return true on sucessful insertion, false otherwise and set $_SESSION["errorMessage"]
*/
function createFolder($sName, $sDescription, $iParentID, $iCreatorID, $iDocumentTypeID, $iUnitID, $bIsPublic = false) {
$sName = addslashes($sName);
$sDescription = addslashes($sDescription);
global $default, $lang_err_database;
//if the folder doesn't exist
if (!(FolderManager::folderExistsName($sName, $iParentID))) {
$sql = new Owl_DB();
$result = $sql->query("INSERT INTO " . $default->owl_folders_table . " (name, description, parent_id, creator_id, document_type_id, unit_id, is_public) " .
"VALUES ('" . $sName . "', '" . $sDescription . "', " . $iParentID . ", " . $iCreatorID . ", " . $iDocumentTypeID . ", " . $iUnitID . ", " . $bIsPublic . ")");
if (!$result) {
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
return true;
}
//error message set in folderExistsName
return false;
}
/**
* Delete and existing folder
*
* $iFolderID Primary key of folder to delete
*
* @return true on successfuly deletion, false otherwise and set $_SESSION["errorMessage"]
*/
function deleteFolder($iFolderID) {
global $default,$lang_err_folder_not_exist;
//if the folder exists
if (FolderManager::folderExistsID($iFolderID)) {
$sql = new Owl_DB();
$result = $sql->query("DELETE FROM " . $default->owl_folders_table . " WHERE id = " . $iFolderID);
if (!$result) {
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
return true;
}
$_SESSION["errorMessage"] = $lang_err_folder_not_exist . "id " . $iFolderID;
return false;
}
/**
* Checks if a given folder already exists using the folder name
*
* @param $sName Name of folder
* @param $iParentID Primary key of parent folder
*
* @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
*/
function folderExistsName($sName, $iParentID) {
$sName = addslashes($sName);
global $default, $lang_err_folder_exist;
$sql = new Owl_DB();
$sql->query("SELECT * FROM " . $default->owl_folders_table . " WHERE name = '" . $sName . "' AND parent_id = " . $iParentID);
if ($sql->next_record()) {
return true;
}
$_SESSION["errorMessage"] = $lang_err_folder_exist . $sName . " parent_id " . $iParentID;
return false;
}
/**
* Checks if a given folder already exists using the folder name
*
* @param $iFolderID Primary key of folder
*
* @return true if the folder exists, false otherwise and set $_SESSION["errorMessage"]
*/
function folderExistsID($iFolderID) {
global $default, $lang_err_folder_exist;
$sql = new Owl_DB();
$sql->query("SELECT * FROM " . $default->owl_folders_table . " WHERE id = " . $iFolderID);
if ($sql->next_record()) {
return true;
}
$_SESSION["errorMessage"] =$lang_err_folder_exist . "id " . $iFolderID;
return false;
}
/**
* Get a folder's primary key using the folder name and the parent id
*
* @param $sName Name of folder
* @param $iParentID Primary key of parent folder
*
* @return id integer on successful lookup, false otherwise and set $_SESSION["errorMessage"]
*
*/
function getFolderID($sName, $iParentID) {
$sName = addslashes($sName);
global $default, $lang_err_folder_exist;
$sql = new Owl_DB();
$sql->query("SELECT id FROM " . $default->owl_folders_table . " WHERE name = '" . $sName . "' AND parent_id = " . $iParentID);
if ($sql->next_record()) {
return $sql->f("id");
}
$_SESSION["errorMessage"] = $lang_err_folder_exist . $sName;
return false;
}
}
?>