Moritz Schmidt 10 жил өмнө
parent
commit
50873f2708

+ 7 - 0
ajax.php

@@ -322,6 +322,13 @@ switch($_REQUEST['action']) {
             "status"    => "OK"
             "status"    => "OK"
         );
         );
 
 
+        echo json_encode($return);
+        break;
+    case 'scanDocuments':
+        header("Status: 200 OK");
+
+        $return = scanDocuments($CONFIG['documentPath']);
+        $return['status'] = "OK";
         echo json_encode($return);
         echo json_encode($return);
         break;
         break;
     case 'debugTest': // for testing single methods etc.
     case 'debugTest': // for testing single methods etc.

+ 1 - 10
cron.php

@@ -13,16 +13,7 @@ include('includes/mailboxfolder.inc.php');
 $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'], $CONFIG['dbDatabase']);
 $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'], $CONFIG['dbDatabase']);
 
 
 
 
-$files = recursiveScanDir($CONFIG['documentPath']);
-$allDocuments = getObjectsAsArray(Document::getAllDocuments(), array("id", "fileName", "path", "labelId", "draft", "created", "lastChange", "type", "mailUid"));
-
-handleFile($files, $allDocuments);
-
-if(sizeof($allDocuments) > 0) { // Documents got removed
-    foreach($allDocuments as $document) {
-        Document::removeDocumentByID($document['id']);
-    }
-}
+echo json_encode(scanDocuments($CONFIG['documentPath']));
 
 
 //searchMails(); // Mails -> eigene klasse
 //searchMails(); // Mails -> eigene klasse
 
 

+ 15 - 19
includes/functions.inc.php

@@ -30,34 +30,30 @@ function getObjectsAsArray($objects, $keys) {
 	return $return;
 	return $return;
 }
 }
 
 
-function searchNewFiles($scanDir) {
+function scanDocuments($path) {
 	global $db;
 	global $db;
 	global $CONFIG;
 	global $CONFIG;
 
 
-	$oldDocuments = Document::getDocumentsByLabelPath($scanDir);
-	$files = scandir($CONFIG['documentPath'] . $scanDir);
 
 
-	foreach($files as $file) {
-		$existed = false;
-		if($file === '.' || $file === '..') {
-			continue;
-		}
-
-		foreach($oldDocuments as $oldDocument) {
-			if($oldDocument->getFileName() === $file) {
-				$existed = true;
-				break;
-			}
-		}
 
 
-		if($existed) {
-			continue;
-		}
+	$files = recursiveScanDir($path);
+	$allDocuments = getObjectsAsArray(Document::getAllDocuments(), array("id", "fileName", "path", "labelId", "draft", "created", "lastChange", "type", "mailUid"));
 
 
-		Document::addDocument('file', $file, '/', Label::getLabelByPath($scanDir)->getId(), '', 'NOW()', 'NOW()');
+	handleFile($files, $allDocuments);
 
 
+	if(sizeof($allDocuments) > 0) { // Documents got removed
+	    foreach($allDocuments as $document) {
+	        Document::removeDocumentByID($document['id']);
+	    }
 	}
 	}
 
 
+	$newDocumentsNumber = sizeof($allDocuments);
+
+	return array(
+	    "new" => $newDocumentsNumber
+	);
+
+
 }
 }
 
 
 function handleFile($filename, &$allDocuments) {
 function handleFile($filename, &$allDocuments) {

+ 20 - 0
scripts/custom.js

@@ -329,6 +329,26 @@ $(document).ready(function() {
                 }
                 }
             });
             });
         });
         });
+
+        $(document).on("click", "#refresh-documents", function(e) {
+            e.preventDefault();
+
+            $("#refresh-documents").hide();
+            addSpinner($("#document-list th:nth-child(6)"));
+
+            $.getJSON("ajax.php?action=scanDocuments", {}, function(r) {
+                if(r['status'] == "OK") {
+                    if(r['new'] > 0) {
+                        location.reload();
+                    } else {
+                        removeSpinner($("#document-list th:nth-child(6)"));
+                        $("#refresh-documents").show();
+                    }
+                } else {
+                    noty_error_retry();
+                }
+            });
+        });
     }
     }
 
 
     function reloadDraftVars() {
     function reloadDraftVars() {

+ 3 - 2
templates/documentlist.php

@@ -1,4 +1,4 @@
-<table class="table table-striped">
+<table id="document-list" class="table table-striped">
     <thead>
     <thead>
         <tr>
         <tr>
             <th>Typ</th>
             <th>Typ</th>
@@ -6,6 +6,7 @@
             <th>Vorlage</th>
             <th>Vorlage</th>
             <th>Erstellt am</th>
             <th>Erstellt am</th>
             <th>Letzte Änderung</th>
             <th>Letzte Änderung</th>
+            <th><a id="refresh-documents" href="#"><i class="fa fa-refresh"></i></a></th>
         </tr>
         </tr>
     </thead>
     </thead>
 <?php
 <?php
@@ -16,8 +17,8 @@ foreach($this->_['documents'] as $document) {
     echo '<td>' . $document->getDraft() . '</td>';
     echo '<td>' . $document->getDraft() . '</td>';
     echo '<td>' . $document->getCreated() . '</td>';
     echo '<td>' . $document->getCreated() . '</td>';
     echo '<td>' . $document->getLastChange() . '</td>';
     echo '<td>' . $document->getLastChange() . '</td>';
+    echo '<td></td>';
     echo '</tr>';
     echo '</tr>';
 }
 }
 ?>
 ?>
 </table>
 </table>
-<a id="new-document" href="ajax.php?action=getNewDocumentBox" type="button" class="btn btn-success fancybox.ajax">Neues Dokument</a>

+ 4 - 1
templates/label.php

@@ -21,7 +21,10 @@ foreach($this->_['entries'] as $entry){
                 <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
                 <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
                 <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
                 <li role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
                 <li role="presentation"><a href="#calls" aria-controls="settings" role="tab" data-toggle="tab">Calls</a></li>
                 <li role="presentation"><a href="#calls" aria-controls="settings" role="tab" data-toggle="tab">Calls</a></li>
-                <a href="ajax.php?action=getNewCallBox&labelID=<?php echo $this->_['label']->getId(); ?>" id="new-call" class="btn btn-primary pull-right" role="button">Neuer Anruf</a>
+                <div class="pull-right">
+                    <a id="new-document" href="ajax.php?action=getNewDocumentBox" type="button" class="btn btn-success">Neues Dokument</a>
+                    <a href="ajax.php?action=getNewCallBox&labelID=<?php echo $this->_['label']->getId(); ?>" id="new-call" class="btn btn-primary" role="button">Neuer Anruf</a>
+                </div>
 
 
             </ul>
             </ul>