|
@@ -2,11 +2,17 @@
|
|
|
|
|
|
|
|
// Label functions
|
|
// Label functions
|
|
|
|
|
|
|
|
|
|
+function pa($array) {
|
|
|
|
|
+ echo '<pre>';
|
|
|
|
|
+ print_r($array);
|
|
|
|
|
+ echo '</pre>';
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function getLabels() {
|
|
function getLabels() {
|
|
|
global $db;
|
|
global $db;
|
|
|
|
|
|
|
|
$return = array();
|
|
$return = array();
|
|
|
- $labels = $db->query("SELECT * FROM `labels`;");
|
|
|
|
|
|
|
+ $labels = $db->selectQuery("SELECT * FROM `labels`;");
|
|
|
|
|
|
|
|
foreach($labels as $label) {
|
|
foreach($labels as $label) {
|
|
|
$return[] = new Label($label->id, $label->name);
|
|
$return[] = new Label($label->id, $label->name);
|
|
@@ -19,7 +25,20 @@ function getLabelById($labelId) {
|
|
|
global $db;
|
|
global $db;
|
|
|
|
|
|
|
|
$return = array();
|
|
$return = array();
|
|
|
- $labels = $db->query("SELECT * FROM `labels` WHERE `id` = " . $labelId . ";");
|
|
|
|
|
|
|
+ $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `id` = " . $labelId . ";");
|
|
|
|
|
+
|
|
|
|
|
+ foreach($labels as $label) {
|
|
|
|
|
+ $return[] = new Label($label->id, $label->name);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $return;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getLabelByPath($path) {
|
|
|
|
|
+ global $db;
|
|
|
|
|
+
|
|
|
|
|
+ $return = array();
|
|
|
|
|
+ $labels = $db->selectQuery("SELECT * FROM `labels` WHERE `path` = '" . $path . "';");
|
|
|
|
|
|
|
|
foreach($labels as $label) {
|
|
foreach($labels as $label) {
|
|
|
$return[] = new Label($label->id, $label->name);
|
|
$return[] = new Label($label->id, $label->name);
|
|
@@ -32,7 +51,20 @@ function getDocumentsByLabelId($labelId) {
|
|
|
global $db;
|
|
global $db;
|
|
|
|
|
|
|
|
$return = array();
|
|
$return = array();
|
|
|
- $documents = $db->query("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";");
|
|
|
|
|
|
|
+ $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `label_id` = " . $labelId . ";");
|
|
|
|
|
+
|
|
|
|
|
+ foreach($documents as $document) {
|
|
|
|
|
+ $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $return;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function getDocumentsByPath($path) {
|
|
|
|
|
+ global $db;
|
|
|
|
|
+
|
|
|
|
|
+ $return = array();
|
|
|
|
|
+ $documents = $db->selectQuery("SELECT documents.* FROM `documents` JOIN `labels` ON labels.id = documents.label_id WHERE labels.path = '" . $path . "';");
|
|
|
|
|
|
|
|
foreach($documents as $document) {
|
|
foreach($documents as $document) {
|
|
|
$return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
|
|
$return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change);
|
|
@@ -41,4 +73,40 @@ function getDocumentsByLabelId($labelId) {
|
|
|
return $return;
|
|
return $return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange) {
|
|
|
|
|
+ global $db;
|
|
|
|
|
+ $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', " . $created . ", " . $lastChange . ");";
|
|
|
|
|
+ $db->insertQuery($query);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function searchNewFiles($scanDir) {
|
|
|
|
|
+ global $db;
|
|
|
|
|
+ global $CONFIG;
|
|
|
|
|
+
|
|
|
|
|
+ $oldDocuments = getDocumentsByPath($scanDir);
|
|
|
|
|
+ $files = scandir($CONFIG['documentPath'] . $scanDir);
|
|
|
|
|
+
|
|
|
|
|
+ foreach($files as $file) {
|
|
|
|
|
+ $existed = false;
|
|
|
|
|
+ if($file === '.' || $file === '..') {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach($oldDocuments as $oldDocument) {
|
|
|
|
|
+ if($oldDocument->getFileName() === $file) { // TODO: Check update-date, maybe removed files
|
|
|
|
|
+ $existed = true;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if($existed) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ addDocument('file', $file, '/', getLabelByPath($scanDir)[0]->getId(), '', 'NOW()', 'NOW()'); // TODO: get dates by filesystem
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
?>
|
|
?>
|