Quellcode durchsuchen

Fixed #93: Kontakte + Management implementiert

Moritz Schmidt vor 10 Jahren
Ursprung
Commit
f20f49e029
11 geänderte Dateien mit 937 neuen und 36 gelöschten Zeilen
  1. 77 0
      ajax.php
  2. BIN
      drafts/Brief.docx
  3. 383 0
      includes/contact.inc.php
  4. 3 0
      includes/controller.inc.php
  5. 1 1
      includes/functions.inc.php
  6. 12 11
      index.php
  7. 281 21
      scripts/custom.js
  8. 41 0
      sql_structure.sql
  9. 4 0
      styles/style.css
  10. 130 0
      templates/contactlist.php
  11. 5 3
      templates/label.php

+ 77 - 0
ajax.php

@@ -13,6 +13,7 @@ require('includes/documenthandler.inc.php');
 require('includes/call.inc.php');
 require('includes/reminder.inc.php');
 require('includes/mail.inc.php');
+require('includes/contact.inc.php');
 
 $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'], $CONFIG['dbDatabase']);
 
@@ -398,6 +399,82 @@ switch($_REQUEST['action']) {
 
         echo json_encode(array('success' => 1, 'result' => $out));
 
+        break;
+    case 'getContactByID':
+        header("Status: 200 OK");
+        $contact = getObjectsAsArray(Contact::getContactByID($_REQUEST['contactID']), array("id", "organization", "department", "title", "degree", "forename", "surname", "street", "streetNumber", "postalCode", "city"));
+
+        $communications = Contact::getCommunicationsByContactID($_REQUEST['contactID']);
+
+        $return = array(
+            "status" => "OK",
+            "contact" => $contact,
+            "communications" => $communications
+        );
+
+        echo json_encode($return);
+        break;
+    case 'updateContact':
+        header("Status: 200 OK");
+
+        $db->updateQuery("UPDATE `contacts` SET `organization` = \"" . $_REQUEST['organization'] . "\", `department` = \"" . $_REQUEST['department'] . "\", `title` =  \"" . $_REQUEST['title'] . "\", `degree` =  \"" . $_REQUEST['degree'] . "\", `forename` =  \"" . $_REQUEST['forename'] . "\", `surname` =  \"" . $_REQUEST['surname'] . "\", `street` =  \"" . $_REQUEST['street'] . "\", `street_number` =  \"" . $_REQUEST['streetNumber'] . "\", `postal_code` =  \"" . $_REQUEST['postalCode'] . "\", `city` =  \"" . $_REQUEST['city'] . "\" WHERE `id` = " . $_REQUEST['contactID'] . ";");
+
+        if($_REQUEST['communications'] && sizeof($_REQUEST['communications']) > 0) {
+            foreach($_REQUEST['communications'] as $communication) {
+                if($communication['id'] == -1) { // new entry
+                    $db->insertQuery("INSERT INTO `contacts_fields` (`contact_id`, `type`, `name`, `value`) VALUES (" . $_REQUEST['contactID'] . ", " . $communication['type'] . ", \"" . $communication['name'] . "\", \"" . $communication['value'] . "\");");
+                } else { // existing entry
+                    $db->updateQuery("UPDATE `contacts_fields` SET `name` = \"" . $communication['name'] . "\", `value` = \"" . $communication['value'] . "\" WHERE `id` = " . $communication['id'] . ";");
+                }
+            }
+        }
+
+        $return = array("status" => "OK");
+
+        echo json_encode($return);
+        break;
+    case 'addContact':
+        header("Status: 200 OK");
+
+        $db->insertQuery("INSERT INTO `contacts`(`user_id`, `forename`, `surname`) VALUES (" . $_REQUEST['userID'] . ", \"Neuer\", \"Kontakt\");");
+
+        $return = array("status" => "OK");
+
+        echo json_encode($return);
+        break;
+    case 'getContacts':
+        header("Status: 200 OK");
+
+        $contacts = getObjectsAsArray(Contact::getAllContactsByUserID($_REQUEST['userID']), array("id", "organization", "department", "title", "degree", "forename", "surname", "street", "streetNumber", "postalCode", "city"));
+
+        $return = array(
+            "status"    => "OK",
+            "contacts"  => $contacts
+        );
+
+        echo json_encode($return);
+        break;
+    case 'removeContact':
+        header("Status: 200 OK");
+
+        $db->removeQuery("DELETE FROM `contacts` WHERE `id` = " . $_REQUEST['contactID'] . ";");
+
+        $return = array(
+            "status"    => "OK"
+        );
+
+        echo json_encode($return);
+        break;
+    case 'removeCommunication':
+        header("Status: 200 OK");
+
+        $db->removeQuery("DELETE FROM `contacts_fields` WHERE `id` = " . $_REQUEST['communicationID'] . ";");
+
+        $return = array(
+            "status"    => "OK"
+        );
+
+        echo json_encode($return);
         break;
     case 'debugTest': // for testing single methods etc.
 

BIN
drafts/Brief.docx


+ 383 - 0
includes/contact.inc.php

@@ -0,0 +1,383 @@
+<?php
+
+class Contact {
+
+    private $id             = NULL;
+    private $organization   = NULL;
+    private $department     = NULL;
+    private $title          = NULL;
+    private $degree         = NULL;
+    private $forename       = NULL;
+    private $surname        = NULL;
+    private $street         = NULL;
+    private $streetNumber   = NULL;
+    private $postalCode     = NULL;
+    private $city           = NULL;
+
+    public static $FIELD_TEL  = 0;
+    public static $FIELD_MAIL = 1;
+    public static $FIELD_WEB  = 2;
+
+    public function __construct($id, $organization, $department, $title, $degree, $forename, $surname, $street, $streetNumber, $postalCode, $city) {
+        $this->id               = $id;
+        $this->organization     = $organization;
+        $this->department       = $department;
+        $this->title            = $title;
+        $this->degree           = $degree;
+        $this->forename         = $forename;
+        $this->surname          = $surname;
+        $this->street           = $street;
+        $this->streetNumber     = $streetNumber;
+        $this->postalCode       = $postalCode;
+        $this->city             = $city;
+    }
+
+    /**
+     * Get the value of Id
+     *
+     *
+     * @return int
+     *
+     */
+
+    public function getID() {
+        return $this->id;
+    }
+
+    /**
+     * Set the value of Id
+     *
+     *
+     * @param int id
+     *
+     */
+
+    public function setID($id) {
+        $this->id = $id;
+     }
+
+    /**
+     * Get the value of Organization
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getOrganization() {
+        return $this->organization;
+    }
+
+    /**
+     * Set the value of Organization
+     *
+     *
+     * @param string organization
+     *
+     */
+
+    public function setOrganization($organization) {
+        $this->organization = $organization;
+     }
+
+    /**
+     * Get the string of Department
+     *
+     *
+     * @return mixed
+     *
+     */
+
+    public function getDepartment() {
+        return $this->department;
+    }
+
+    /**
+     * Set the value of Department
+     *
+     *
+     * @param string department
+     *
+     */
+
+    public function setDepartment($department) {
+        $this->department = $department;
+     }
+
+    /**
+     * Get the value of Title
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getTitle() {
+        return $this->title;
+    }
+
+    /**
+     * Set the value of Title
+     *
+     *
+     * @param string title
+     *
+     */
+
+    public function setTitle($title) {
+        $this->title = $title;
+     }
+
+    /**
+     * Get the value of Degree
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getDegree() {
+        return $this->degree;
+    }
+
+    /**
+     * Set the value of Degree
+     *
+     *
+     * @param mixed degree
+     *
+     */
+
+    public function setDegree($degree) {
+        $this->degree = $degree;
+     }
+
+    /**
+     * Get the value of Forename
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getForename() {
+        return $this->forename;
+    }
+
+    /**
+     * Set the value of Forename
+     *
+     *
+     * @param string forename
+     *
+     */
+
+    public function setForename($forename) {
+        $this->forename = $forename;
+     }
+
+    /**
+     * Get the value of Surname
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getSurname() {
+        return $this->surname;
+    }
+
+    /**
+     * Set the value of Surname
+     *
+     *
+     * @param string surname
+     *
+     */
+
+    public function setSurname($surname) {
+        $this->surname = $surname;
+     }
+
+    /**
+     * Get the value of Street
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getStreet() {
+        return $this->street;
+    }
+
+    /**
+     * Set the value of Street
+     *
+     *
+     * @param string street
+     *
+     */
+
+    public function setStreet($street) {
+        $this->street = $street;
+     }
+
+    /**
+     * Get the value of Street Number
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getStreetNumber() {
+        return $this->streetNumber;
+    }
+
+    /**
+     * Set the value of Street Number
+     *
+     *
+     * @param string streetNumber
+     *
+     */
+
+    public function setStreetNumber($streetNumber) {
+        $this->streetNumber = $streetNumber;
+     }
+
+    /**
+     * Get the value of Postal Code
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getPostalCode() {
+        return $this->postalCode;
+    }
+
+    /**
+     * Set the value of Postal Code
+     *
+     *
+     * @param string postalCode
+     *
+     */
+
+    public function setPostalCode($postalCode) {
+        $this->postalCode = $postalCode;
+     }
+
+    /**
+     * Get the value of City
+     *
+     *
+     * @return string
+     *
+     */
+
+    public function getCity() {
+        return $this->city;
+    }
+
+    /**
+     * Set the value of City
+     *
+     *
+     * @param string city
+     *
+     */
+
+    public function setCity($city) {
+        $this->city = $city;
+     }
+
+     /**
+      * Get All Contacts by User ID
+      *
+      * @param int userID  ID of User
+      *
+      * @return Array(Contact)  Array with selected Contacts
+      *
+      */
+
+     public static function getAllContactsByUserID($userID) {
+         global $db;
+
+         $contacts = $db->selectQuery("SELECT * FROM `contacts` WHERE `user_id` = " . $userID . ";");
+
+         $return = array();
+
+         if(!$contacts) {
+             return false;
+         }
+
+         foreach($contacts as $contact) {
+             $return[] = new Contact($contact->id, $contact->organization, $contact->department, $contact->title, $contact->degree, $contact->forename, $contact->surname, $contact->street, $contact->street_number, $contact->postal_code, $contact->city);
+         }
+
+         return $return;
+
+     }
+
+     /**
+      * Get Contact by Contact ID
+      *
+      * @param int contactID  ID of Contact
+      *
+      * @return Contact  Selected Contact
+      *
+      */
+
+     public static function getContactByID($contactID) {
+         global $db;
+
+         $contacts = $db->selectQuery("SELECT * FROM `contacts` WHERE `id` = " . $contactID . ";");
+
+         $return = array();
+
+         if(!$contacts) {
+             return false;
+         }
+
+         foreach($contacts as $contact) {
+             $return[] = new Contact($contact->id, $contact->organization, $contact->department, $contact->title, $contact->degree, $contact->forename, $contact->surname, $contact->street, $contact->street_number, $contact->postal_code, $contact->city);
+         }
+
+         return $return[0];
+     }
+
+     /**
+      * Get communications by Contact ID
+      *
+      * @param int contactID  ID of Contact
+      *
+      * @return Array  Selected communications
+      *
+      */
+
+     public static function getCommunicationsByContactID($contactID) {
+         global $db;
+
+         $communications = $db->selectQuery("SELECT * FROM `contacts_fields` WHERE `contact_id` = " . $contactID . " ORDER BY `type` ASC;");
+
+         $return = array();
+
+         if(!$communications) {
+             return false;
+         }
+
+         foreach($communications as $communication) {
+             $return[] = array("id" => $communication->id, "type" => $communication->type, "name" => $communication->name, "value" => $communication->value);
+         }
+
+         return $return;
+     }
+
+}
+
+?>

+ 3 - 0
includes/controller.inc.php

@@ -59,9 +59,11 @@ class Controller {
 					$documentView 	= new View();
 					$mailView		= new View();
 					$callView		= new View();
+					$contactView	= new View();
 					$documentView->setTemplate('documentlist');
 					$mailView->setTemplate('maillist');
 					$callView->setTemplate('calllist');
+					$contactView->setTemplate('contactlist');
 					$callView->assign('calls', Call::getCallsByLabelID($this->request['labelID']));
 					$innerView->setTemplate('label');
 					$innerView->assign('label', Label::getLabelByID($this->request['labelID']));
@@ -72,6 +74,7 @@ class Controller {
 					$innerView->assign('documentlist', $documentView->loadTemplate());
 					$innerView->assign('maillist', $mailView->loadTemplate());
 					$innerView->assign('calllist', $callView->loadTemplate());
+					$innerView->assign('contactlist', $contactView->loadTemplate());
 					break;
 				case 'manage-labels':
 					$innerView->setTemplate('manage-labels');

+ 1 - 1
includes/functions.inc.php

@@ -25,7 +25,7 @@ function getObjectsAsArray($objects, $keys) {
 	} else {
 		foreach($keys as $key) {
 			$keyCall = 'get' . ucfirst($key);
-			$return[0][$key] = $object->$keyCall();
+			$return[0][$key] = $objects->$keyCall();
 		}
 	}
 

+ 12 - 11
index.php

@@ -1,19 +1,20 @@
 <?php
 session_start();
 // Includes
-include('includes/config.inc.php');
-include('includes/database.inc.php');
-include('includes/user.inc.php');
-include('includes/controller.inc.php');
-include('includes/model.inc.php');
-include('includes/view.inc.php');
-include('includes/functions.inc.php');
-include('includes/label.inc.php');
-include('includes/document.inc.php');
-include('includes/mailbox.inc.php');
-include('includes/mailboxfolder.inc.php');
+require('includes/config.inc.php');
+require('includes/database.inc.php');
+require('includes/user.inc.php');
+require('includes/controller.inc.php');
+require('includes/model.inc.php');
+require('includes/view.inc.php');
+require('includes/functions.inc.php');
+require('includes/label.inc.php');
+require('includes/document.inc.php');
+require('includes/mailbox.inc.php');
+require('includes/mailboxfolder.inc.php');
 require('includes/call.inc.php');
 require('includes/mail.inc.php');
+require('includes/contact.inc.php');
 
 $db = new Database($CONFIG['dbHost'], $CONFIG['dbUser'], $CONFIG['dbPassword'], $CONFIG['dbDatabase']);
 $user = new User(isset($_SESSION['username']) ? $_SESSION['username'] : NULL);

+ 281 - 21
scripts/custom.js

@@ -96,7 +96,7 @@ $(document).ready(function() {
     }
 
     function addSpinner(element) {
-        element.append("<div class=\"spinner\"><div class=\"bounce1\"></div><div class=\"bounce2\"></div><div class=\"bounce3\"></div></div>");
+        $(element).append("<div class=\"spinner\"><div class=\"bounce1\"></div><div class=\"bounce2\"></div><div class=\"bounce3\"></div></div>");
     }
 
     function removeSpinner(element) {
@@ -395,14 +395,14 @@ $(document).ready(function() {
         });
 
         var calendar = $("#calendar").calendar({
-                tmpl_path: "/tmpls/",
-                events_source: "ajax.php?action=getCalendarEvents",
-                first_day: 1, // Monday
-                onAfterViewLoad: function(view) {
-        			$('.btn-group button').removeClass('active');
-        			$('button[data-calendar-view="' + view + '"]').addClass('active');
-        		}
-            });
+            tmpl_path: "/tmpls/",
+            events_source: "ajax.php?action=getCalendarEvents",
+            first_day: 1, // Monday
+            onAfterViewLoad: function(view) {
+    			$('.btn-group button').removeClass('active');
+    			$('button[data-calendar-view="' + view + '"]').addClass('active');
+    		}
+        });
 
         $('.btn-group button[data-calendar-view]').each(function() {
             var $this = $(this);
@@ -410,6 +410,277 @@ $(document).ready(function() {
                 calendar.view($this.data('calendar-view'));
             });
         });
+
+        $(document).on("click", "a[data-action='loadContact']", function(e) {
+            e.preventDefault();
+
+            $("#contact-list .contact-selected").removeClass("contact-selected");
+            loadContact($(this).attr("data-contact-id"));
+            $($(this).children()[0]).addClass("contact-selected");
+
+        });
+
+        reloadContactList(true);
+
+        $(document).on("click", "a[data-action='save-contact']", function(e) {
+            e.preventDefault();
+
+            var communications = [];
+
+            $("a[data-action='save-contact']").remove();
+            addSpinner("#save-contact-wrapper > div");
+
+            $("#contact-communication > div").each(function(e) {
+
+                switch($(this).attr("data-contact-input-type")) {
+                    case 'tel':
+                        communications.push({
+                            type: 0,
+                            id: $(this).attr("data-id"),
+                            name: $(this).children(".col-xs-4").children("input").val(),
+                            value: $(this).children(".col-xs-7").children("input").val()
+                        });
+                        break;
+                    case 'email':
+                        communications.push({
+                            type: 1,
+                            id: $(this).attr("data-id"),
+                            name: '',
+                            value: $(this).children(".col-xs-11").children("input").val()
+                        });
+                        break;
+                    case 'web':
+                    communications.push({
+                        type: 2,
+                        id: $(this).attr("data-id"),
+                        name: '',
+                        value: $(this).children(".col-xs-11").children("input").val()
+                    });
+                        break;
+                }
+            });
+
+            data = {
+                contactID: $("#contact-tab").attr("data-contact-id"),
+                organization: $("#contact-organization").val(),
+                department: $("#contact-department").val(),
+                title: $("#contact-title").val(),
+                degree: $("#contact-degree").val(),
+                forename: $("#contact-forename").val(),
+                surname: $("#contact-surname").val(),
+                street: $("#contact-street").val(),
+                streetNumber: $("#contact-street-nr").val(),
+                postalCode: $("#contact-postal-code").val(),
+                city: $("#contact-city").val(),
+                communications: communications
+            };
+
+            $.getJSON("ajax.php?action=updateContact", data, function(r) {
+                if(r['status'] != "OK") {
+                    noty_error_retry();
+                    removeSpinner($("#save-contact-wrapper > div"));
+                } else {
+                    removeSpinner($("#save-contact-wrapper > div"));
+                    $("#save-contact-wrapper > div").append("<a href=\"#\" data-action=\"save-contact\"><i class=\"fa fa-floppy-o pull-right\"></i></a>");
+                    reloadContactList(false, function() {
+                        $("a[data-action='loadContact'][data-contact-id='" + $("#contact-tab").attr("data-contact-id") + "'] > div").addClass("contact-selected");
+                    });
+                }
+            });
+        });
+
+        $(document).on("click", "a[data-action='add-contact']", function(e) {
+            e.preventDefault();
+
+            data = {
+                userID: $("body").attr("data-user-id")
+            };
+
+            $.getJSON("ajax.php?action=addContact", data, function(r) {
+                if(r['status'] == "OK") {
+                    reloadContactList(false);
+                } else {
+                    noty_error_retry();
+                }
+            });
+
+        });
+
+        $(document).on("click", "a[data-action='add-phone-input']", function(e) {
+            e.preventDefault();
+
+            var html = "<div class=\"row\" data-contact-input-type=\"tel\" data-id=\"-1\">     <div class=\"col-xs-4\">         <input type=\"text\" class=\"form-control\" list=\"tel_kategorie\" placeholder=\"\" />         <datalist id=\"tel_kategorie\">             <option>Geschäftlich</option>             <option>Privat</option>             <option>Mobil</option>         </datalist>     </div>     <div class=\"col-xs-7\">         <input type=\"tel\" class=\"form-control\" placeholder=\"Telefon\">     </div>     <div class=\"col-xs-1\">         <div style=\"padding: 15%; margin-left: -15%;\">             <a href=\"#\" data-action=\"add-phone-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a>         </div>     </div> </div> <br>";
+
+            if($($(this).parent()).attr("id") == "communication-buttons") {
+                var telInputs = $("[data-contact-input-type='tel']");
+                if(telInputs.length > 0) {
+                    $(html).insertAfter($(telInputs[telInputs.length - 1]).next());
+                } else {
+                    $("#contact-communication").prepend(html);
+                }
+            } else {
+                $(html).insertAfter($(this).closest("[data-contact-input-type='tel']").next());
+            }
+
+        });
+
+        $(document).on("click", "a[data-action='add-email-input']", function(e) {
+            e.preventDefault();
+
+            var html = "<div class=\"row\" data-contact-input-type=\"email\" data-id=\"-1\">     <div class=\"col-xs-11\">         <input type=\"email\" class=\"form-control\" placeholder=\"Email\">     </div>     <div class=\"col-xs-1\">         <div style=\"padding: 15%; margin-left: -15%;\">             <a href=\"#\" data-action=\"add-email-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a>         </div>     </div> </div> <br>";
+
+            if($($(this).parent()).attr("id") == "communication-buttons") {
+                var mailInputs = $("[data-contact-input-type='email']");
+                if(mailInputs.length > 0) {
+                    $(html).insertAfter($(mailInputs[mailInputs.length - 1]).next());
+                } else {
+                    var telInputs = $("[data-contact-input-type='tel']");
+                    if(telInputs.length > 0) {
+                        $(html).insertAfter($(telInputs[telInputs.length - 1]).next());
+                    } else {
+                        $("#contact-communication").prepend(html);
+                    }
+                }
+            } else {
+                $(html).insertAfter($(this).closest("[data-contact-input-type='email']").next());
+            }
+
+        });
+
+        $(document).on("click", "a[data-action='add-web-input']", function(e) {
+            e.preventDefault();
+
+            var html = "<div class=\"row\" data-contact-input-type=\"web\" data-id=\"-1\">     <div class=\"col-xs-11\">         <input type=\"url\" class=\"form-control\" placeholder=\"Webseite\">     </div>     <div class=\"col-xs-1\">         <div style=\"padding: 15%; margin-left: -15%;\">             <a href=\"#\" data-action=\"add-web-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a>         </div>     </div> </div> <br>";
+
+            if($($(this).parent()).attr("id") == "communication-buttons") {
+                var urlInputs = $("[data-contact-input-type='web']");
+                if(urlInputs.length > 0) {
+                    $(html).insertAfter($(urlInputs[urlInputs.length - 1]).next());
+                } else {
+                    $("#contact-communication").append(html);
+                }
+            } else {
+                $(html).insertAfter($(this).closest("[data-contact-input-type='web']").next());
+            }
+
+        });
+
+        $(document).on("click", "a[data-action='remove-contact']", function(e) {
+            e.preventDefault();
+
+            data = {
+                contactID: $("#contact-tab").attr("data-contact-id")
+            };
+
+            $.getJSON("ajax.php?action=removeContact", data, function(r) {
+                if(r['status'] == "OK") {
+                    reloadContactList(true);
+                } else {
+                    noty_error_retry();
+                }
+            });
+        });
+
+        $(document).on("click", "a[data-action='remove-communication']", function(e) {
+            e.preventDefault();
+
+            var communicationID = $(this).closest(".row").attr("data-id");
+
+            if(communicationID == -1) { // just remove from DOM, not saved yet
+                $(this).closest(".row").next().remove();
+                $(this).closest(".row").remove();
+            } else { // also remove from DB
+
+                var row = $(this).closest(".row");
+
+                data = {
+                    communicationID: communicationID
+                };
+
+                $.getJSON("ajax.php?action=removeCommunication", data, function(r) {
+                    if(r['status'] == "OK") {
+                        $(row).next().remove();
+                        $(row).remove();
+                    } else {
+                        noty_error_retry();
+                    }
+                });
+            }
+        });
+    }
+
+    function loadContact(contactID) {
+        data = {
+            contactID: contactID
+        };
+
+        $.getJSON("ajax.php?action=getContactByID", data, function(r) {
+            if(r['status'] != "OK") {
+                noty_error_retry();
+            }
+
+            $("#contact-tab").attr("data-contact-id", r['contact'][0]['id']);
+            $("#contact-organization").val(r['contact'][0]['organization']);
+            $("#contact-department").val(r['contact'][0]['department']);
+            $("#contact-title").val(r['contact'][0]['title']);
+            $("#contact-degree").val(r['contact'][0]['degree']);
+            $("#contact-forename").val(r['contact'][0]['forename']);
+            $("#contact-surname").val(r['contact'][0]['surname']);
+            $("#contact-street").val(r['contact'][0]['street']);
+            $("#contact-street-nr").val(r['contact'][0]['streetNumber']);
+            $("#contact-postal-code").val(r['contact'][0]['postalCode']);
+            $("#contact-city").val(r['contact'][0]['city']);
+
+            $("#contact-communication").empty();
+
+            if(r['communications']) {
+                $.each(r['communications'], function(i) {
+                    var html;
+
+                    switch(this['type']) {
+                        case "0":
+                            html = "<div class=\"row\" data-contact-input-type=\"tel\" data-id=\"" + this['id'] + "\">     <div class=\"col-xs-4\">         <input type=\"text\" class=\"form-control\" list=\"tel_kategorie\" placeholder=\"\" value=\"" + this['name'] + "\" />         <datalist id=\"tel_kategorie\">             <option>Geschäftlich</option>             <option>Privat</option>             <option>Mobil</option>         </datalist>     </div>     <div class=\"col-xs-7\">         <input type=\"tel\" class=\"form-control\" placeholder=\"Telefon\" value=\"" + this['value'] + "\">     </div>     <div class=\"col-xs-1\">         <div style=\"padding: 15%; margin-left: -15%;\">             <a href=\"#\" data-action=\"add-phone-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a>         </div>     </div> </div> <br>";
+                            break;
+                        case "1":
+                            html = "<div class=\"row\" data-contact-input-type=\"email\" data-id=\"" + this['id'] + "\">     <div class=\"col-xs-11\">         <input type=\"email\" class=\"form-control\" placeholder=\"Email\" value=\"" + this['value'] + "\">     </div>     <div class=\"col-xs-1\">         <div style=\"padding: 15%; margin-left: -15%;\">             <a href=\"#\" data-action=\"add-email-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a>         </div>     </div> </div> <br>";
+                            break;
+                        case "2":
+                            html = "<div class=\"row\" data-contact-input-type=\"web\" data-id=\"" + this['id'] + "\">     <div class=\"col-xs-11\">         <input type=\"url\" class=\"form-control\" placeholder=\"Webseite\" value=\"" + this['value'] + "\">     </div>     <div class=\"col-xs-1\">         <div style=\"padding: 15%; margin-left: -15%;\">             <a href=\"#\" data-action=\"add-web-input\"><i class=\"fa fa-plus-circle\"></i></a><a href=\"#\" data-action=\"remove-communication\"><i class=\"fa fa-minus-circle\"></i></a>         </div>     </div> </div> <br>";
+                            break;
+                    }
+
+                    $("#contact-communication").append(html);
+
+                });
+            }
+
+        });
+    }
+
+    function reloadContactList(firstRun, callBack) {
+
+        data = {
+            userID: $("body").attr("data-user-id")
+        };
+
+        $.getJSON("ajax.php?action=getContacts", data, function(r) {
+            if(r['status'] != "OK") {
+                noty_error_retry();
+            } else {
+                $("#contact-list > div").empty();
+                $.each(r['contacts'], function(i) {
+                    $("#contact-list > div").append("<a href=\"#\" data-action=\"loadContact\" data-contact-id=\"" + this['id'] + "\"><div class=\"col-md-12\">" + this['forename'] + " " + this['surname'] + "</div></a>");
+                });
+
+                if(firstRun) {
+                    loadContact($($("a[data-action='loadContact']")[0]).attr("data-contact-id"));
+                    $($($("a[data-action='loadContact']")[0]).children()[0]).addClass("contact-selected");
+                }
+
+                callBack = typeof callBack !== 'undefined' ? callBack : function() {};
+                callBack();
+            }
+        });
     }
 
     function reloadDraftVars() {
@@ -418,7 +689,6 @@ $(document).ready(function() {
             draftVarsContainer = $("#draft-vars");
 
             if(draftVarsContainer.length > 0) {
-                console.log(draftVarsContainer);
                 draftVarsContainer.remove();
             }
 
@@ -443,7 +713,6 @@ $(document).ready(function() {
     $('.editable-element-text').editable({
         escape: false,
         success: function(response, newValue) {
-            console.log(response); // Debug output from ajax.php
             if(response.status == 'error') return response.msg; //msg will be shown in editable form
         },
         error: function (xhr, status, error) {
@@ -463,7 +732,6 @@ $(document).ready(function() {
             {value: 'pop3', text: 'POP3'}
         ],
         success: function(response, newValue) {
-            console.log(response); // Debug output from ajax.php
             if(response.status == 'error') return response.msg; //msg will be shown in editable form
         },
         error: function (xhr, status, error) {
@@ -484,7 +752,6 @@ $(document).ready(function() {
             {value: '0', text: 'Off'}
         ],
         success: function(response, newValue) {
-            console.log(response); // Debug output from ajax.php
             if(response.status == 'error') return response.msg; //msg will be shown in editable form
         },
         error: function (xhr, status, error) {
@@ -505,7 +772,6 @@ $(document).ready(function() {
             {value: '1', text: 'Off'}
         ],
         success: function(response, newValue) {
-            console.log(response); // Debug output from ajax.php
             if(response.status == 'error') return response.msg; //msg will be shown in editable form
         },
         error: function (xhr, status, error) {
@@ -527,7 +793,6 @@ $(document).ready(function() {
                 type: 'POST',
                 data: {'action': 'addDefaultMailaccount', 'user-id': uID},
                 success: function (result) {
-                    console.log(result);
                     location.reload();
                 }
             });
@@ -548,7 +813,6 @@ $(document).ready(function() {
                     //defaultValue: '0',
                     source: result,
                     success: function(response, newValue) {
-                        console.log(response); // Debug output from ajax.php
                         if(response.status == 'error') return response.msg; //msg will be shown in editable form
                     },
                     error: function (xhr, status, error) {
@@ -566,7 +830,6 @@ $(document).ready(function() {
         $('.editable-element-text').editable({
             escape: false,
             success: function(response, newValue) {
-                console.log(response); // Debug output from ajax.php
                 if(response.status == 'error') return response.msg; //msg will be shown in editable form
             },
             error: function (xhr, status, error) {
@@ -589,7 +852,6 @@ $(document).ready(function() {
                 type: 'POST',
                 data: {'action': 'removeMailaccount', 'id': id},
                 success: function (result) {
-                    console.log(result);
                     location.reload();
                 }
             });
@@ -603,7 +865,6 @@ $(document).ready(function() {
                 type: 'POST',
                 data: {'action': 'removeMailboxFolder', 'id': id},
                 success: function (result) {
-                    console.log(result);
                     location.reload();
                 }
             });
@@ -618,11 +879,10 @@ $(document).ready(function() {
                 type: 'POST',
                 data: {'action': 'addDefaultMailfolder', 'user-id': uID, 'label-id': lID},
                 success: function (result) {
-                    console.log(result);
                     location.reload();
                 },
                 error: function(result) {
-                    console.log(result);
+                    noty_error_retry();
                 }
             });
     });

+ 41 - 0
sql_structure.sql

@@ -34,6 +34,47 @@ CREATE TABLE `calls` (
 ) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
+--
+-- Table structure for table `contacts`
+--
+
+DROP TABLE IF EXISTS `contacts`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `contacts` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `user_id` int(11) NOT NULL,
+  `organization` varchar(256) COLLATE utf8_bin NOT NULL,
+  `department` varchar(256) COLLATE utf8_bin NOT NULL,
+  `title` varchar(128) COLLATE utf8_bin NOT NULL,
+  `degree` varchar(128) COLLATE utf8_bin NOT NULL,
+  `forename` varchar(64) COLLATE utf8_bin NOT NULL,
+  `surname` varchar(64) COLLATE utf8_bin NOT NULL,
+  `street` varchar(128) COLLATE utf8_bin NOT NULL,
+  `street_number` varchar(16) COLLATE utf8_bin NOT NULL,
+  `postal_code` varchar(16) COLLATE utf8_bin NOT NULL,
+  `city` varchar(128) COLLATE utf8_bin NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `contacts_fields`
+--
+
+DROP TABLE IF EXISTS `contacts_fields`;
+/*!40101 SET @saved_cs_client     = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `contacts_fields` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `contact_id` int(11) NOT NULL,
+  `type` int(11) NOT NULL,
+  `name` varchar(64) COLLATE utf8_bin NOT NULL,
+  `value` varchar(128) COLLATE utf8_bin NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
 --
 -- Table structure for table `documents`
 --

+ 4 - 0
styles/style.css

@@ -109,6 +109,10 @@ table td {
 	animation-delay: -0.16s;
 }
 
+.contact-selected {
+	background-color: rgba(0, 0, 0, 0.3);
+}
+
 @-webkit-keyframes bouncedelay {
 	0%, 80%, 100% {
 		-webkit-transform: scale(0.0)

+ 130 - 0
templates/contactlist.php

@@ -0,0 +1,130 @@
+<div id="contact-list" class="col-md-4">
+    <div class="row"></div>
+</div>
+<div class="col-md-8" id="contact-tab" data-contact-id="-1">
+    <div class="row">
+        <div class="col-xs-10">
+            <h3>Adresse</h3>
+        </div>
+        <div id="save-contact-wrapper" class="col-xs-2">
+            <div class="pull-right" style="padding: 15%; padding-right: 0;">
+                <a href="#" data-action="remove-contact"><i class="fa fa-minus-circle"></i></a>
+                <a href="#" data-action="add-contact"><i class="fa fa-plus-circle"></i></a>
+                <a href="#" data-action="save-contact"><i class="fa fa-floppy-o"></i></a>
+            </div>
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-xs-12">
+            <input type="text" id="contact-organization" class="form-control" placeholder="Organisation">
+        </div>
+    </div>
+    <br>
+    <div class="row">
+        <div class="col-xs-12">
+            <input type="text" id="contact-department" class="form-control" placeholder="Abteilung">
+        </div>
+    </div>
+    <br>
+    <div class="row">
+        <div class="col-xs-6">
+            <input type="text" id="contact-title" class="form-control" list="anreden" placeholder="(Firma)" />
+            <datalist id="anreden">
+                <option>(Firma)</option>
+                <option>Herr</option>
+                <option>Frau</option>
+                <option>Herr und Frau</option>
+                <option>Familie</option>
+            </datalist>
+        </div>
+        <div class="col-xs-6">
+            <input type="text" id="contact-degree" class="form-control" placeholder="Titel">
+        </div>
+    </div>
+    <br>
+    <div class="row">
+        <div class="col-xs-6">
+            <input type="text" id="contact-forename" class="form-control" placeholder="Vorname">
+        </div>
+        <div class="col-xs-6">
+            <input type="text" id="contact-surname" class="form-control" placeholder="Nachname">
+        </div>
+    </div>
+    <br>
+    <div class="row">
+        <div class="col-xs-10">
+            <input type="text" id="contact-street" class="form-control" placeholder="Straße">
+        </div>
+        <div class="col-xs-2">
+            <input type="text" id="contact-street-nr" class="form-control" placeholder="Hausnr">
+        </div>
+    </div>
+    <br>
+    <div class="row">
+        <div class="col-xs-3">
+            <input type="text" id="contact-postal-code" class="form-control" placeholder="Postleitzahl">
+        </div>
+        <div class="col-xs-9">
+            <input type="text" id="contact-city" class="form-control" placeholder="Ort">
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-xs-10">
+            <h3>Kommunikation</h3>
+        </div>
+        <div class="col-xs-2">
+            <div id="communication-buttons" style="padding: 15%; float: right;">
+                <a href="#" data-action="add-phone-input">
+                    <i class="fa fa-phone"></i>
+                </a>
+                <a href="#" data-action="add-email-input">
+                    <i class="fa fa-envelope-o"></i>
+                </a>
+                <a href="#" data-action="add-web-input">
+                    <i class="fa fa-globe"></i>
+                </a>
+            </div>
+        </div>
+    </div>
+    <div id="contact-communication"></div>
+    <!--<div class="row">
+        <div class="col-xs-4">
+            <input type="text" class="form-control" list="tel_kategorie" placeholder="Geschäftlich" />
+            <datalist id="tel_kategorie">
+                <option>Geschäftlich</option>
+                <option>Privat</option>
+                <option>Mobil</option>
+            </datalist>
+        </div>
+        <div class="col-xs-7">
+            <input type="tel" class="form-control" placeholder="Telefon">
+        </div>
+        <div class="col-xs-1">
+            <div style="padding: 15%; margin-left: -15%;">
+                <a href="#" id="add-phone-input"><i class="fa fa-plus-circle"></i></a>
+            </div>
+        </div>
+    </div>
+    <br>
+    <div class="row">
+        <div class="col-xs-11">
+            <input type="email" class="form-control" placeholder="Email">
+        </div>
+        <div class="col-xs-1">
+            <div style="padding: 15%; margin-left: -15%;">
+                <a href="#" id="add-email-input"><i class="fa fa-plus-circle"></i></a>
+            </div>
+        </div>
+    </div>
+    <br>
+    <div class="row">
+        <div class="col-xs-11">
+            <input type="url" class="form-control" placeholder="Webseite">
+        </div>
+        <div class="col-xs-1">
+            <div style="padding: 15%; margin-left: -15%;">
+                <a href="#" id="add-web-input"><i class="fa fa-plus-circle"></i></a>
+            </div>
+        </div>
+    </div>-->
+</div>

+ 5 - 3
templates/label.php

@@ -7,10 +7,10 @@
             <ul class="nav nav-tabs" role="tablist">
                 <li role="presentation" class="active"><a href="#mails" aria-controls="mails" role="tab" data-toggle="tab">Mails</a></li>
                 <li role="presentation"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Dokumente</a></li>
-                <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
+                <li role="presentation"><a href="#contacts" aria-controls="contacts" role="tab" data-toggle="tab">Kontakte</a></li>
                 <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
                 <li role="presentation"><a href="#calender" aria-controls="calender" role="tab" data-toggle="tab">Calender</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="calls" role="tab" data-toggle="tab">Calls</a></li>
                 <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>
@@ -25,7 +25,9 @@
                 <div role="tabpanel" class="tab-pane" id="home">
                     <?php echo $this->_['documentlist']; ?>
                 </div>
-                <div role="tabpanel" class="tab-pane" id="profile">PROFILE</div>
+                <div role="tabpanel" class="tab-pane" id="contacts">
+                    <?php echo $this->_['contactlist']; ?>
+                </div>
                 <div role="tabpanel" class="tab-pane" id="messages">MESSAGE</div>
                 <div role="tabpanel" class="tab-pane" id="calender">
                     <div class="btn-group pull-right" style="margin-top: 5px;">