Moritz Schmidt 10 tahun lalu
induk
melakukan
ddcd1e5cbe
4 mengubah file dengan 66 tambahan dan 8 penghapusan
  1. 12 0
      ajax.php
  2. 34 8
      includes/mail.inc.php
  3. 13 0
      scripts/custom.js
  4. 7 0
      templates/maillist.php

+ 12 - 0
ajax.php

@@ -354,6 +354,18 @@ switch($_REQUEST['action']) {
         );
 
         echo json_encode($return);
+    case 'changeMailProcessed':
+        header("Status: 200 OK");
+        $mail = Mail::getMailByMailID($_REQUEST['mailID']);
+        $mail->setProcessed($_REQUEST['value']);
+        $mail->save();
+
+        $return = array(
+            "status"    => "OK"
+        );
+
+        echo json_encode($return);
+        break;
     case 'debugTest': // for testing single methods etc.
 
         break;

+ 34 - 8
includes/mail.inc.php

@@ -6,14 +6,16 @@ class Mail {
     private $subject            = NULL;
     private $mailboxFolderID    = NULL;
     private $mailUID            = NULL;
+    private $processed          = NULL;
 
 
-    public function __construct($id, $mailSender, $subject, $mailboxFolderID, $mailUID) {
+    public function __construct($id, $mailSender, $subject, $mailboxFolderID, $mailUID, $processed) {
         $this->id               = $id;
         $this->mailSender       = $mailSender;
         $this->subject          = $subject;
         $this->mailboxFolderID  = $mailboxFolderID;
         $this->mailUID          = $mailUID;
+        $this->processed        = $processed;
 
     }
 
@@ -137,6 +139,30 @@ class Mail {
         $this->mailUID = $mailUID;
      }
 
+     /**
+      * Get the value of processed
+      *
+      *
+      * @return int
+      *
+      */
+
+     public function getProcessed() {
+         return $this->processed;
+     }
+
+     /**
+      * Set the value of processed
+      *
+      *
+      * @param int mailUID
+      *
+      */
+
+     public function setProcessed($processed) {
+         $this->processed = $processed;
+      }
+
      public function getMailRecipient() {
          global $db;
 
@@ -158,11 +184,11 @@ class Mail {
              $this->setID("'NULL'");
          }
 
-         $db->insertQuery("INSERT INTO `mails` (`id`, `mail_sender`, `subject`, `mailbox_folder_id`, `mail_uid`) VALUES (" . $this->getID() . ", '" . $this->getMailSender() . "', '" . $this->getSubject() . "', " . $this->getMailboxFolderID() . ", " . $this->getMailUID() . ") ON DUPLICATE KEY UPDATE `mail_sender` = '" . $this->getMailSender() . "', `subject` = '" . $this->getSubject() . "', `mailbox_folder_id` = " . $this->getMailboxFolderID() . ", `mail_uid` = " . $this->getMailUID() . ";");
+         $db->insertQuery("INSERT INTO `mails` (`id`, `mail_sender`, `subject`, `mailbox_folder_id`, `mail_uid`, `processed`) VALUES (" . $this->getID() . ", '" . $this->getMailSender() . "', '" . $this->getSubject() . "', " . $this->getMailboxFolderID() . ", " . $this->getMailUID() . ", " . $this->getProcessed() . ") ON DUPLICATE KEY UPDATE `mail_sender` = '" . $this->getMailSender() . "', `subject` = '" . $this->getSubject() . "', `mailbox_folder_id` = " . $this->getMailboxFolderID() . ", `mail_uid` = " . $this->getMailUID() . ", `processed` = " . $this->getProcessed() . ";");
 
-         $this->setID(NULL); // get ID from DB
-
-         echo "<br><br>";
+         if($this->getID() == "'NULL'") {
+             $this->setID(NULL);
+         }
      }
 
      /**
@@ -186,7 +212,7 @@ class Mail {
          }
 
          foreach($mails as $mail) {
-             $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid);
+             $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid, $mail->processed);
          }
 
          return $return[0];
@@ -214,7 +240,7 @@ class Mail {
          }
 
          foreach($mails as $mail) {
-             $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid);
+             $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid, $mail->processed);
          }
 
          return $return[0];
@@ -241,7 +267,7 @@ class Mail {
          $return = array();
 
          foreach($mails as $mail) {
-             $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid);
+             $return[] = new Mail($mail->id, $mail->mail_sender, $mail->subject, $mail->mailbox_folder_id, $mail->mail_uid, $mail->processed);
          }
 
          return $return;

+ 13 - 0
scripts/custom.js

@@ -365,6 +365,19 @@ $(document).ready(function() {
                 window.location.href = "mailto:" + r['to'] + "?subject=" + r['subject'] + "&body=" + r['body'];
             });
         });
+
+        $(document).on("change", ".mail-processed", function(e) {
+            data = {
+                mailID: $(this).attr("id").replace("mail-processed-", ""),
+                value: $(this).is(':checked')
+            };
+
+            $.getJSON("ajax.php?action=changeMailProcessed", data, function(r) {
+                if(r['status'] != "OK") {
+                    noty_error_retry();
+                }
+            });
+        })
     }
 
     function reloadDraftVars() {

+ 7 - 0
templates/maillist.php

@@ -1,6 +1,7 @@
 <table id="mail-list" class="table table-striped">
     <thead>
         <tr>
+            <th><i class="fa fa-check"></i></th>
             <th>Absender</th>
             <th>Empfänger</th>
             <th>Betreff</th>
@@ -10,7 +11,13 @@
 <?php
 
 foreach($this->_['mails'] as $mail) {
+    $checked = "";
+    if($mail->getProcessed() == 1) {
+        $checked = "checked";
+    }
+
     echo '<tr>';
+    echo '<td><input type="checkbox" value="1" ' . $checked . ' id="mail-processed-' . $mail->getID() . '" class="mail-processed"></td>';
     echo '<td>' . $mail->getMailSender() . '</td>';
     echo '<td>' . $mail->getMailRecipient() . '</td>';
     echo '<td>' . $mail->getSubject() . '</td>';