Przeglądaj źródła

\#38: Helper-Methoden in entsprechende Klassen verschoben

Moritz Schmidt 10 lat temu
rodzic
commit
6f46b251f0

+ 5 - 10
ajax.php

@@ -87,22 +87,17 @@ switch($_REQUEST['action']) {
     case 'manageMailboxFolder':
         header("Status: 200 OK");
 
-
-        /*$boxHtml = 'Account: ';
-        $boxHtml .= getEditableLink('mailaccount', 'select', $_GET['mfId'], 'Click to change', getMailboxNameFromMailaccountId($_GET['mbId']));
-        $boxHtml .= '<br>Folder: ';
-        $boxHtml .= getEditableLink('mailfolder', 'text', $_GET['mfId'], 'Click to change', getMailboxFolderNameFromId($_GET['mfId'])); // TODO: make this select-box
-        echo $boxHtml;*/
-
         $editBox = array(
             "options"   => array(
                 array(
                     "type"  => "select",
-                    "name"  => "account"
+                    "name"  => "account",
+                    "value" => Imap::getMailboxNameFromMailaccountId($_GET['mbId'])
                 ),
                 array(
                     "type"  => "text",
-                    "name"  => "Folder"
+                    "name"  => "folder",
+                    "value" => MailboxFolder::getMailboxFolderNameFromId($_GET['mfId'])
                 )
             ),
             "title"     => "Mailkonto bearbeiten"
@@ -113,7 +108,7 @@ switch($_REQUEST['action']) {
         break;
     case 'getMailAccountsByUid':
         header("Status: 200 OK");
-        $mailboxes = getMailboxesByUserId($_REQUEST['uId'], false);
+        $mailboxes = Imap::getMailboxesByUserId($_REQUEST['uId'], false);
         $mbArray = array();
         foreach($mailboxes as $mailbox) {
             $mbArray[$mailbox->getId()] = $mailbox->getUsername();

+ 5 - 5
includes/controller.inc.php

@@ -57,7 +57,7 @@ class Controller {
 					break;
 				case 'label':
 					$innerView->setTemplate('label');
-					$innerView->assign('label', getLabelById($this->request['labelId']));
+					$innerView->assign('label', Label::getLabelById($this->request['labelId']));
 					$documentView = new View();
 					$documentView->setTemplate('documentlist');
 					$documentView->assign('labelId', $this->request['labelId']);
@@ -65,12 +65,12 @@ class Controller {
 					break;
 				case 'manage-labels':
 					$innerView->setTemplate('manage-labels');
-					$innerView->assign('labels', getLabels());
+					$innerView->assign('labels', Label::getAllLabels());
 					break;
 				case 'manage-label':
 					$innerView->setTemplate('manage-label');
-					$innerView->assign('label', getLabelById($this->request['labelId']));
-					$innerView->assign('mailboxFolders', getMailboxFolderByLabelId($this->request['labelId']));
+					$innerView->assign('label', Label::getLabelById($this->request['labelId']));
+					$innerView->assign('mailboxFolders', MailboxFolder::getMailboxFolderByLabelId($this->request['labelId']));
 					$innerView->assign('user', $user);
 					break;
 				case 'settings':
@@ -88,7 +88,7 @@ class Controller {
 			$this->view->setTemplate('matrix');
 			$this->headerView->assign('title', 'atOfficeWeb');
 			$this->headerView->assign('request', $this->request);
-			$this->headerView->assign('labels', getLabels());
+			$this->headerView->assign('labels', Label::getAllLabels());
 			$this->view->assign('blog_title', $this->headerView->loadTemplate());
 			$this->view->assign('blog_footer', $this->footerView->loadTemplate());
 			$this->view->assign('blog_content', $innerView->loadTemplate());

+ 95 - 0
includes/document.inc.php

@@ -55,6 +55,101 @@ class Document {
         return $this->mailUid;
     }
 
+    /**
+     * Get Documents by Label ID
+     *
+     *
+     * @param int $labelId  Label ID
+     *
+     * @return Array(Document)  Array with selected Document(s)
+     *
+     */
+
+    public static 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, $document->type, $document->mail_uid);
+        }
+
+        return $return;
+    }
+
+    /**
+     * Get Documents by FS-Path
+     *
+     *
+     * @param string $path  path, relative to ~/documents-folder
+     *
+     * @return Array(Document)  Array with selected Document(s)
+     *
+     */
+
+    public static 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, $document->type, $document->mail_uid);
+    	}
+
+    	return $return;
+    }
+
+    /**
+     * Get Documents by Mail-Header-Info
+     *
+     *
+     * @param int $mailAcc  ID of wanted Mailaccount
+     * @param int $mailUid  UID of wanted Mail-Document
+     * @param int $labelId  ID fo wanted Label
+     *
+     * @return Array(Document)  Selected Document(s)
+     *
+     */
+
+    public static function getDocumentsByMailInfo($mailAcc, $mailUid, $labelId) {
+        global $db;
+
+        $return = array();
+        $documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . " AND `mail_acc` = " . $mailAcc . ";");
+
+        foreach($documents as $document) {
+            $return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
+        }
+
+        return $return;
+    }
+
+    /**
+     * Insert new Document into DB
+     *
+     *
+     * @param string    $type       Type of Document
+     * @param string    $fileName   Name of File/Subject of Mail
+     * @param string    $path       Path relative to Label-Home-Folder / Mailaccount
+     * @param int       $labelId    ID of Label
+     * @param string    $draft      Name of used draft
+     * @param string(?) $created    Date of creation
+     * @param string(?) $lastChange Date of last change
+     * @param int       $mailUid    UID of mail, 0 for Files TODO: parameter = 0, default val
+     * @param int       $mailAcc    ID of MailAccount. Default: -1 (For Files)
+     *
+     * @return void  TODO: return true/false error diesdas
+     *
+     */
+
+    public static function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid, $mailAcc = -1) {
+        global $db;
+        $query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`, `mail_uid`, `mail_acc`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', " . $created . ", " . $lastChange . ", " . $mailUid . ", " . $mailAcc . ");";
+        $db->insertQuery($query);
+    }
+
 }
 
 ?>

+ 8 - 190
includes/functions.inc.php

@@ -1,7 +1,5 @@
 <?php
 
-// Label functions
-
 function pa($array) {
 	echo '<pre>';
 	print_r($array);
@@ -12,178 +10,11 @@ function error($message) {
 	echo $message;
 }
 
-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, $document->type, $document->mail_uid);
-	}
-
-	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, $document->type, $document->mail_uid);
-	}
-
-	return $return;
-}
-
-function getDocumentsByMailUidLabelIdMailAccId($mailUid, $labelId, $mailAcc) {
-	global $db;
-
-	$return = array();
-	$documents = $db->selectQuery("SELECT * FROM `documents` WHERE `mail_uid` = " . $mailUid . " AND `label_id` = " . $labelId . " AND `mail_acc` = " . $mailAcc . ";");
-
-	foreach($documents as $document) {
-		$return[] = new Document($document->id, $document->filename, $document->path, $document->label_id, $document->draft, $document->created, $document->last_change, $document->type, $document->mail_uid);
-	}
-
-	return $return;
-}
-
-function getMailboxes($connect = true) {
-	global $db;
-
-	$return = array();
-	$mailboxes = $db->selectQuery("SELECT * FROM `mailboxes`;");
-
-	foreach($mailboxes as $mailbox) {
-		$useSsl = '';
-		$noValidCert = '';
-
-		if($mailbox->use_ssl) {
-			$useSsl = '/ssl';
-		}
-
-		if(!$mailbox->valid_ssl) {
-			$noValidCert = '/novalidate-cert';
-		}
-		$return[] = new Imap($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // TODO: Encrypt password
-	}
-
-	return $return;
-}
-
-function getMailboxesByUserId($userId, $connect = true) {
-	global $db;
-
-	$return = array();
-	$mailboxes = $db->selectQuery("SELECT * FROM `mailboxes` WHERE `user_id` = " . $userId . ";");
-
-	foreach($mailboxes as $mailbox) {
-		$useSsl = '';
-		$noValidCert = '';
-
-		if($mailbox->use_ssl) {
-			$useSsl = '/ssl';
-		}
-
-		if(!$mailbox->valid_ssl) {
-			$noValidCert = '/novalidate-cert';
-		}
-		//$return[] = new Imap('{' . $mailbox->server . ':' . $mailbox->port . '/' . $mailbox->protocol . $useSsl . $noValidCert . '}', $mailbox->username, $mailbox->password); // TODO: Encrypt password
-		$return[] = new Imap($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // TODO: Encrypt password
-	}
-
-	return $return;
-}
-
-function getMailboxFolderByName($folderName) {
-	global $db;
-
-	$return = array();
-	$folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `folder_name` = '" . $folderName . "';");
-
-	if(!$folders) {
-		return false;
-	}
-
-	foreach($folders as $folder) {
-		$return[] = new MailboxFolder($folder->id, $folder->folder_name, $folder->mailbox_id, $folder->label_id);
-	}
-
-	return $return;
-
-}
-
-function getMailboxFolderByLabelId($labelId) {
-	global $db;
-
-	$return = array();
-	$folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `label_id` = '" . $labelId . "';");
-
-	if(!$folders) {
-		return false;
-	}
-
-	foreach($folders as $folder) {
-		$return[] = new MailboxFolder($folder->id, $folder->folder_name, $folder->mailbox_id, $folder->label_id);
-	}
-
-	return $return;
-
-}
-
-function addDocument($type, $fileName, $path, $labelId, $draft, $created, $lastChange, $mailUid, $mailAcc = -1) {
-	global $db;
-	$query = "INSERT INTO `documents`(`type`, `filename`, `path`, `label_id`, `draft`, `created`, `last_change`, `mail_uid`, `mail_acc`) VALUES ('" . $type . "', '" . $fileName . "', '" . $path . "', " . $labelId . ", '" . $draft . "', " . $created . ", " . $lastChange . ", " . $mailUid . ", " . $mailAcc . ");";
-	$db->insertQuery($query);
-}
-
 function searchNewFiles($scanDir) {
 	global $db;
 	global $CONFIG;
 
-	$oldDocuments = getDocumentsByPath($scanDir);
+	$oldDocuments = Document::getDocumentsByPath($scanDir);
 	$files = scandir($CONFIG['documentPath'] . $scanDir);
 
 	foreach($files as $file) {
@@ -203,7 +34,7 @@ function searchNewFiles($scanDir) {
 			continue;
 		}
 
-		addDocument('file', $file, '/', getLabelByPath($scanDir)[0]->getId(), '', 'NOW()', 'NOW()', 0); // TODO: get dates by filesystem
+		Document::addDocument('file', $file, '/', Label::getLabelByPath($scanDir)->getId(), '', 'NOW()', 'NOW()', 0); // TODO: get dates by filesystem
 
 	}
 
@@ -213,7 +44,7 @@ function searchMails() {
 	global $user;
 	//$imap = new Imap('{mail.mmnx.de:993/imap/ssl/novalidate-cert}', 'mobi@mmnx.de', 'msmoro');
 	//$imap->listFolders();
-	$mailboxes = getMailBoxes();
+	$mailboxes = Imap::getMailBoxes();
 	//pa($mailboxes);
 
 	foreach($mailboxes as $mailbox) {
@@ -223,9 +54,9 @@ function searchMails() {
 
 	foreach($mailboxes as $mailbox) {
 		foreach($mailbox->getFolders() as $folder) {
-			$mbFolder = getMailboxFolderByName($folder);
-			if($mbFolder[0] != false) {
-				$mailbox->changeFolder($mbFolder[0]->getFolderName());
+			$mbFolder = MailboxFolder::getMailboxFolderByName($folder);
+			if($mbFolder != false) {
+				$mailbox->changeFolder($mbFolder->getFolderName());
 
 				$messageCount = imap_num_msg($mailbox->getMailbox());
 
@@ -236,10 +67,10 @@ function searchMails() {
 					//echo $uid;
 					$uid = imap_uid($mailbox->getMailbox(), $i);
 
-					$documents = getDocumentsByMailUidLabelIdMailAccId($uid, $mbFolder[0]->getLabelId());
+					$documents = getDocumentsByMailInfo($mailbox->getId(), $uid, $mbFolder->getLabelId());
 
 					if(sizeof($documents) < 1) {
-						addDocument('mail', $headers->subject, $headers->from[0]->mailbox . '@' . $headers->from[0]->host, $mbFolder[0]->getLabelId(), '', '\'' . $headers->date . '\'', '\'' . $headers->date . '\'', $uid, $mailbox->getId());
+						Document::addDocument('mail', $headers->subject, $headers->from[0]->mailbox . '@' . $headers->from[0]->host, $mbFolder->getLabelId(), '', '\'' . $headers->date . '\'', '\'' . $headers->date . '\'', $uid, $mailbox->getId());
 					}
 				}
 			}
@@ -274,17 +105,4 @@ function getEditableLink($elementId, $type, $pk, $title, $value, $class = '') {
 	return $link;
 }
 
-function getMailboxNameFromMailaccountId($mId) {
-	global $db;
-
-	$mailbox = $db->selectStringQuery("SELECT `username` FROM `mailboxes` WHERE id=" . $mId);
-	return $mailbox;
-}
-
-function getMailboxFolderNameFromId($mId) {
-	global $db;
-
-	$mailbox = $db->selectStringQuery("SELECT `folder_name` FROM `mailbox-folders` WHERE id=" . $mId);
-	return $mailbox;
-}
 ?>

+ 84 - 0
includes/imap.inc.php

@@ -85,5 +85,89 @@ class Imap {
         return $this->username;
     }
 
+    /**
+     * Get all Mailboxes
+     *
+     *
+     * @param bool $connect  Whether to connect or just to store data
+     *
+     * @return Array(Mailbox)  All Mailboxes
+     *
+     */
+
+    public static function getAllMailboxes($connect = true) {
+        global $db;
+
+        $return = array();
+        $mailboxes = $db->selectQuery("SELECT * FROM `mailboxes`;");
+
+        foreach($mailboxes as $mailbox) {
+            $useSsl = '';
+            $noValidCert = '';
+
+            if($mailbox->use_ssl) {
+                $useSsl = '/ssl';
+            }
+
+            if(!$mailbox->valid_ssl) {
+                $noValidCert = '/novalidate-cert';
+            }
+            $return[] = new Imap($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // TODO: Encrypt password
+        }
+
+        return $return;
+    }
+
+    /**
+     * Get Mailboxes by User ID
+     *
+     *
+     * @param int $userId  ID of user
+     * @param bool $connect Whether to connect or just to store data
+     *
+     * @return Array(Mailbox)  Array with selected Mailboxes
+     *
+     */
+
+    public static function getMailboxesByUserId($userId, $connect = true) {
+        global $db;
+
+        $return = array();
+        $mailboxes = $db->selectQuery("SELECT * FROM `mailboxes` WHERE `user_id` = " . $userId . ";");
+
+        foreach($mailboxes as $mailbox) {
+            $useSsl = '';
+            $noValidCert = '';
+
+            if($mailbox->use_ssl) {
+                $useSsl = '/ssl';
+            }
+
+            if(!$mailbox->valid_ssl) {
+                $noValidCert = '/novalidate-cert';
+            }
+            $return[] = new Imap($mailbox->id, $mailbox->server, $mailbox->port, $mailbox->protocol, $useSsl, $noValidCert, $mailbox->username, $mailbox->password, $connect); // TODO: Encrypt password
+        }
+
+        return $return;
+    }
+
+    /**
+     * Get name of Mailbox by MailAccountID
+     *
+     *
+     * @param int $mId  MailAccount ID
+     *
+     * @return string  Name of Mailbox
+     *
+     */
+
+    public static function getMailboxNameFromMailaccountId($mId) {
+        global $db;
+
+        $mailbox = $db->selectStringQuery("SELECT `username` FROM `mailboxes` WHERE id=" . $mId);
+        return $mailbox;
+    }
+
 
 }

+ 75 - 0
includes/label.inc.php

@@ -15,6 +15,81 @@ class Label {
     public function getName() {
         return $this->name;
     }
+
+   /**
+    * Get all Labels
+    *
+    *
+    * @return Array(Label)  Array with all Labels
+    *
+    */
+
+    public static function getAllLabels() {
+        global $db;
+
+    	$return = array();
+    	$labels = $db->selectQuery("SELECT * FROM `labels`;");
+
+    	foreach($labels as $label) {
+    		$return[] = new Label($label->id, $label->name);
+    	}
+
+    	return $return;
+    }
+
+    /**
+     * Get a Label by ID
+     *
+     *
+     * @param int $labelId  Label ID
+     *
+     * @return Label  Selected Label object
+     *
+     */
+
+    public static 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);
+        }
+
+        if(sizeof($return) > 1) {
+            //TODO: Error handling!
+        }
+
+        return $return[0];
+    }
+
+    /**
+     * Get a Label by FS-path
+     *
+     *
+     * @param string $path  path, relative to ~/documents-folder
+     *
+     * @return Label  Selected Label
+     *
+     */
+
+    public static 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);
+        }
+
+        if(sizeof($return) > 1) {
+            // TODO: Error handling!
+        }
+
+        return $return[0];
+    }
 }
 
 

+ 73 - 0
includes/mailboxfolder.inc.php

@@ -29,4 +29,77 @@ class MailboxFolder {
     public function getLabelId() {
         return $this->labelId;
     }
+
+    /**
+     * Get MailboxFolder by Folder-name
+     *
+     *
+     * @param string $folderName  Name of folder
+     *
+     * @return MailboxFolder  Selected MailboxFolder
+     *
+     */
+
+     // TODO: sizeof handling
+
+    public static function getMailboxFolderByName($folderName) {
+        global $db;
+
+        $return = array();
+        $folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `folder_name` = '" . $folderName . "';");
+
+        if(!$folders) {
+            return false;
+        }
+
+        foreach($folders as $folder) {
+            $return[] = new MailboxFolder($folder->id, $folder->folder_name, $folder->mailbox_id, $folder->label_id);
+        }
+
+        return $return[0];
+    }
+
+    /**
+     * Get MailboxFolder by Label ID
+     *
+     *
+     * @param int $labelId  Label ID
+     *
+     * @return Array(MailboxFolder)  Array with selected MailboxFolder(s)
+     *
+     */
+
+    public static function getMailboxFolderByLabelId($labelId) {
+        global $db;
+
+        $return = array();
+        $folders = $db->selectQuery("SELECT * FROM `mailbox-folders` WHERE `label_id` = '" . $labelId . "';");
+
+        if(!$folders) {
+            return false;
+        }
+
+        foreach($folders as $folder) {
+            $return[] = new MailboxFolder($folder->id, $folder->folder_name, $folder->mailbox_id, $folder->label_id);
+        }
+
+        return $return;
+    }
+
+    /**
+     * Get MailboxFolder-Name by ID
+     *
+     *
+     * @param int $mId  Mailbox-Folder-ID
+     *
+     * @return string  MailboxFolder-Name
+     *
+     */
+
+    public static function getMailboxFolderNameFromId($mId) {
+        global $db;
+
+        $mailbox = $db->selectStringQuery("SELECT `folder_name` FROM `mailbox-folders` WHERE id=" . $mId);
+        return $mailbox;
+    }
 }

+ 41 - 2
scripts/custom.js

@@ -182,8 +182,47 @@ $(document).ready(function() {
         e.preventDefault();
 
         $.get($(this).attr('href'), function(r) {
-            editBox = $.parseJSON(r);
-            console.log(editBox);
+
+            try {
+                editBox = $.parseJSON(r);
+                console.log(editBox['options']); // DBG
+
+                var optionsContainer = document.createElement('div');
+
+                console.log(optionsContainer);
+
+                $.each(editBox['options'], function(i) {
+                    console.log("jo");
+                    $(optionsContainer).append(this.name + "<input type=\"" + this.type + "\" value=\"" + this.value + "\" style=\"float: right;\"/><br><br>")
+                });
+
+                console.log(optionsContainer);
+
+                $.fancybox({
+                    maxWidth	: 800,
+                    maxHeight	: 600,
+                    fitToView	: true,
+                    width		: '70%',
+                    height		: '70%',
+                    autoSize	: false,
+                    title   : "<h3>" + editBox['title'] + "</h3><hr>",
+                    content : optionsContainer.innerHTML,
+                    helpers : {
+                        title: {
+                            type    : 'inside',
+                            position: 'top'
+                        }
+                    }
+                });
+            } catch(e) {
+                console.log(e); // DBG
+                var n = noty({
+                    layout  : 'topCenter',
+                    text    : 'Irgendwas ist schief gelaufen.<br>Bitte probieren Sie es später noch einmal.',
+                    type    : 'error',
+                    timeout : 5000
+                    });
+            }
         });
     });
 

+ 1 - 1
templates/documentlist.php

@@ -1,6 +1,6 @@
 <?php
 // TODO: Make this MVC-style
-$documents = getDocumentsByLabelId($this->_['labelId']);
+$documents = Document::getDocumentsByLabelId($this->_['labelId']);
 ?>
 
 <table class="table table-striped">

+ 1 - 1
templates/label.php

@@ -10,7 +10,7 @@ foreach($this->_['entries'] as $entry){
 ?>
 
 <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
-    <h1 class="page-header"><?php echo $this->_['label'][0]->getName(); ?></h1>
+    <h1 class="page-header"><?php echo $this->_['label']->getName(); ?></h1>
 
     <div class="row">
         <div role="tabpanel">

+ 4 - 4
templates/manage-label.php

@@ -3,10 +3,10 @@
 
     <div class="row">
         <form action="" method="POST">
-            <input type="hidden" name="labelId" value="<?php echo $this->_['label'][0]->getId(); ?>">
+            <input type="hidden" name="labelId" value="<?php echo $this->_['label']->getId(); ?>">
             <div class="form-group">
                 <label for="labelName">Name</label> <!-- TODO: Make this a.editable -->
-                <input type="text" class="form-control" id="labelName" name="labelName" value="<?php echo $this->_['label'][0]->getName(); ?>">
+                <input type="text" class="form-control" id="labelName" name="labelName" value="<?php echo $this->_['label']->getName(); ?>">
             </div>
             <div class="form-group">
                 <label>Zugewiesene Mailaccounts</label>
@@ -23,7 +23,7 @@
                             foreach($this->_['mailboxFolders'] as $mailboxFolder) {
                                 echo '<tr>';
                                 echo '<td>' . $mailboxFolder->getId() . '</td>';
-                                echo '<td>' . getMailboxNameFromMailaccountId($mailboxFolder->getMailboxId()) . '</td>';
+                                echo '<td>' . Imap::getMailboxNameFromMailaccountId($mailboxFolder->getMailboxId()) . '</td>';
                                 echo '<td>' . $mailboxFolder->getFolderName() . '</td>';
                                 echo '<td><a class="manage-mailboxfolder fancybox.ajax" data-uid="' . $this->_['user']->getUserId() . '" href="ajax.php?action=manageMailboxFolder&mfId=' . $mailboxFolder->getId() . '&mbId=' . $mailboxFolder->getMailboxId() . '" data-id="' . $mailboxFolder->getId() . '"><i class="fa fa-wrench"></i></a></td>';
                                 echo '<td><a class="remove-mailboxfolder" href="#" data-id="' . $mailboxFolder->getId() . '"><i class="fa fa-minus-circle"></i></a></td>';
@@ -32,7 +32,7 @@
                         ?>
                     </thead>
                     <tr>
-                        <td><a id="add-mailboxfolder" href="#" data-uid="<?php echo $this->_['user']->getUserId(); ?>" data-lid="<?php echo $this->_['label'][0]->getId(); ?>"><i class="fa fa-plus-circle"></i></a></td>
+                        <td><a id="add-mailboxfolder" href="#" data-uid="<?php echo $this->_['user']->getUserId(); ?>" data-lid="<?php echo $this->_['label']->getId(); ?>"><i class="fa fa-plus-circle"></i></a></td>
                         <td></td>
                         <td></td>
                         <td></td>

+ 1 - 1
templates/settings.php

@@ -5,7 +5,7 @@
         <h3>Mailaccounts</h3>
         <?php
             $user = $this->_['user'];
-            $mailboxes = getMailboxesByUserId($user->getUserId()); // TODO: MVC
+            $mailboxes = Imap::getMailboxesByUserId($user->getUserId()); // TODO: MVC
         ?>
 
         <table class="table table-striped">