documentLib.inc
2.22 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
<?php
/**
* Class DocumentLib
*
* Contains miscellaneous static helper functions concerned with
* document management
*/
class DocumentLib {
/**
* Gets the folder id for a document
*
* @param $iDocumentID Document primary key
*
* @return int (folder id) on success, false otherwise and set $_SESSION["errorMessage"]
*/
function getDocumentFolderID($iDocumentID) {
global $lang_err_doc_no_folder;
$sql = new Owl_DB();
$sql->query("SELECT folder_id from " . $default->owl_documents_table . " WHERE id = " . $iDocumentID);
if ($sql->next_record()) {
return $sql->f("folder_id");
}
$_SESSION["errorMessage"] = $lang_err_doc_no_folder . "document id " . $iDocumentID;
return false;
}
/**
* Check if a document already exists
*
* @param $sName Name of document
* @param $sFolderID Primary key of folder to which document is assigned
*
* @return boolean true if document exists, false otherwise and set $_SESSION["errorMessage"]
*/
function documentExists($sName, $iFolderID) {
global $default, $lang_err_doc_not_exist;
$sql = new Owl_DB();
$sql->query("SELECT * FROM " . $default->owl_documents_table . " WHERE name = '" . $sName "' AND folder_id = " . $iFolderID);
if ($sql->next_record()) {
return true;
}
$_SESSION["errorMessage"] = $lang_err_doc_not_exist . "name = " . $sName . " folder_id = " . $iFolderID;
return false;
}
/**
* Create a new document type
*
* @param $sName Name of new document type
*
* @return boolean true on successful creation, false otherwise and set $default->errorMessage
*/
function createDocumentType($sName) {
//escape all the necessary characters that may affect db query
$sName = addslashes($sName);
//Get hold of the global error string
global $default;
//if the document type doesn't exist
if (!(DocumentManager::documentTypeExists($sName))) {
$sql = new Owl_DB();
$result = $sql->query("INSERT INTO " . $default->owl_document_types_table . " (name) values ('" . $sName . "')");
if (!$result) {
$_SESSION["errorMessage"] = "Database Error. Failed to insert document type " . $sName;
return false;
}
return true;
}
$_SESSION["errorMessage"] = "A document type with this name already exists";
return false;
}
}
?>