| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- // Label functions
- function pa($array) {
- echo '<pre>';
- print_r($array);
- echo '</pre>';
- }
- 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
- }
- }
- ?>
|