'; print_r($array); echo ''; } function getLabels() { global $db; $return = array(); $labels = $db->selectQuery("SELECT * FROM `labels`;"); foreach($labels as $label) { $return[] = new Label($label->id, $label->name); } return $return; } function getLabelById($labelId) { global $db; $return = array(); $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) { $return[] = new Label($label->id, $label->name); } return $return; } function getDocumentsByLabelId($labelId) { global $db; $return = array(); $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) { $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change); } 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 } } ?>