add view own mails, view all mails (admin role required)
authorMarkus Warg <mw@it-sls.de>
Wed, 7 Jul 2010 07:41:44 +0000 (09:41 +0200)
committerMarkus Warg <mw@it-sls.de>
Wed, 7 Jul 2010 07:41:44 +0000 (09:41 +0200)
add email delete

manager/.settings/org.eclipse.php.core.prefs
manager/application/controllers/MailController.php
manager/application/views/scripts/mail/delete.phtml [new file with mode: 0644]
manager/application/views/scripts/mail/full.phtml [new file with mode: 0644]
manager/application/views/scripts/mail/index.phtml
manager/public/css/mail.css
manager/public/img/delete_icon.jpg [new file with mode: 0644]
manager/public/js/mail_redirect.js [new file with mode: 0644]

index cbc9cef..d2d74b0 100644 (file)
@@ -1,4 +1,4 @@
-#Wed Mar 31 11:13:35 CEST 2010\r
+#Thu Apr 22 14:01:49 CEST 2010\r
 eclipse.preferences.version=1\r
 include_path=0;/ca-mgr (mawaunix)\u00055;org.zend.php.framework.CONTAINER\r
 phpVersion=php5\r
index 5ee84d4..1ba73e2 100644 (file)
@@ -12,11 +12,53 @@ class MailController extends Zend_Controller_Action
     public function init()
     {
         /* Initialize action controller here */
+               $session = Zend_Registry::get('session');
+       $auth = $session->authdata['authed_permissions'];
+
+       $action = $this->getRequest()->getActionName();
+
+       $this->view->leftNav('<a href="' .
+               $this->view->url(array('controller' => 'mail', 'action' => 'index'), 'default', true) .
+               '"' . (($action == 'index')?' class="active"':'') . '>' . I18n::_('View own Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 1);
+       if ($session->authdata['authed_role'] == 'Admin') {
+                       $this->view->leftNav('<a href="' .
+                       $this->view->url(array('controller' => 'mail', 'action' => 'full'), 'default', true) .
+                       '"' . (($action == 'full')?' class="active"':'') . '>' . I18n::_('View all Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 2);
+       }
     }
 
     public function indexAction()
     {
        $config = Zend_Registry::get('config');
+       $session = Zend_Registry::get('session');
+
+               $imap_config = $config->imap;
+        $imap = imapConnection::getInstance('cacert', $imap_config);
+               $imap->imapSwitchMbox('INBOX');
+
+        $ck = $imap->imapCheck();
+
+        $headers = array();
+        for ($i=0; $i < $ck->Nmsgs; $i++) {
+               $header = $imap->imapHeader($i+1);
+
+               // skip all emails that do not belong to the user
+               if ($header->toaddress != $session->authdata['authed_username'])
+                               continue;
+
+               $header->uid = $imap->imapUID($i+1);
+               $header->detailslink = $this->view->url(array('controller' => 'mail', 'action' => 'read', 'uid' => $header->uid), 'default', true);
+               $header->deletelink = $this->view->url(array('controller' => 'mail', 'action' => 'delete', 'uid' => $header->uid), 'default', true);
+               $headers[] = $header;
+        }
+
+        $this->view->headers = $headers;
+    }
+
+    public function fullAction()
+    {
+       $config = Zend_Registry::get('config');
+
                $imap_config = $config->imap;
         $imap = imapConnection::getInstance('cacert', $imap_config);
                $imap->imapSwitchMbox('INBOX');
@@ -28,6 +70,7 @@ class MailController extends Zend_Controller_Action
                $header = $imap->imapHeader($i+1);
                $header->uid = $imap->imapUID($i+1);
                $header->detailslink = $this->view->url(array('controller' => 'mail', 'action' => 'read', 'uid' => $header->uid), 'default', true);
+               $header->deletelink = $this->view->url(array('controller' => 'mail', 'action' => 'delete', 'uid' => $header->uid), 'default', true);
                $headers[] = $header;
         }
 
@@ -47,4 +90,38 @@ class MailController extends Zend_Controller_Action
 
                $this->view->mail_body = $body;
     }
+
+    /**
+     * delete message with unique id
+     */
+       public function deleteAction()
+    {
+       $config = Zend_Registry::get('config');
+               $uid = $this->getRequest()->getParam('uid', -1);
+               $this->view->returnto = $_SERVER['HTTP_REFERER'];
+
+               if ($uid == -1) {
+                       $this->view->message = I18n::_('You did not select an email for deletion');
+               }
+               elseif ($this->view->returnto == '') {
+                       $this->view->message = I18n::_('Please use the delete icons in the mail inventory to delete mails');
+               }
+               else {
+                       $imap_config = $config->imap;
+               $imap = imapConnection::getInstance('cacert', $imap_config);
+                       $imap->imapSwitchMbox('INBOX');
+
+                       $header = $imap->imapFetchOverview($uid);
+
+                       $session = Zend_Registry::get('session');
+                       if ($session->authdata['authed_role'] != 'Admin' && $header->to != $session->authdata['authed_username']) {
+                               $this->view->message = I18n::_('This message does not belong to you');
+                       }
+                       else {
+                       $imap->imapDelete($uid);
+                       $imap->imapExpunge();
+                       $this->view->message = I18n::_('Message deleted');
+                       }
+               }
+    }
 }
diff --git a/manager/application/views/scripts/mail/delete.phtml b/manager/application/views/scripts/mail/delete.phtml
new file mode 100644 (file)
index 0000000..d01cec8
--- /dev/null
@@ -0,0 +1,12 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: index.phtml 25 2009-12-02 15:43:21Z markus $\r
+ */\r
+$this->headLink()->appendStylesheet('/css/mail.css');\r
+$this->headScript()->appendFile('/js/mail_redirect.js');\r
+?>\r
+<H1><?php print I18n::_('Delete Mail'); ?></H1>\r
+<?php\r
+print $this->message;\r
+print '<input type="hidden" id="returnto" value="' . $this->returnto .  '">';\r
diff --git a/manager/application/views/scripts/mail/full.phtml b/manager/application/views/scripts/mail/full.phtml
new file mode 100644 (file)
index 0000000..ba1986b
--- /dev/null
@@ -0,0 +1,37 @@
+<?php\r
+/**\r
+ * @author markus\r
+ * $Id: index.phtml 25 2009-12-02 15:43:21Z markus $\r
+ */\r
+$this->headLink()->appendStylesheet('/css/mail.css');\r
+?>\r
+<H1><?php print I18n::_('View all Mail'); ?></H1>\r
+<?php\r
+if (count($this->headers) == 0) {\r
+       print I18n::_('You currently have no mail.');\r
+}\r
+else {\r
+?>\r
+<table>\r
+       <tr>\r
+               <th class="col1"><?php print I18n::_('From');?></th>\r
+               <th class="col2"><?php print I18n::_('To');?></th>\r
+               <th class="col3"><?php print I18n::_('Subject');?></th>\r
+               <th class="col4"><?php print I18n::_('Date');?></th>\r
+               <th class="col5"><?php print I18n::_('Size');?></th>\r
+               <th class="col6"><?php print I18n::_('Del');?></th>\r
+       </tr>\r
+<?php\r
+       foreach ($this->headers as $header) {\r
+               print "        <tr>\n";\r
+               print "            <td><a href=\"" . $header->detailslink . "\">" . $header->fromaddress . "</a></td>";\r
+               print "            <td>" . $header->toaddress . "</td>";\r
+               print "            <td>" . $header->subject . "</td>";\r
+               print "            <td>" . $header->date . "</td>";\r
+               print "            <td>" . $header->Size . "</td>";\r
+               print "            <td><a class=\"delete\" href=\"" . $header->deletelink . "\"><img src=\"/img/delete_icon.jpg\"></a></td>";\r
+               print "        </tr>\n";\r
+       }\r
+}\r
+?>\r
+</table>\r
index faf6bd4..85288e4 100644 (file)
@@ -5,24 +5,33 @@
  */\r
 $this->headLink()->appendStylesheet('/css/mail.css');\r
 ?>\r
-<H1><?php print I18n::_('Mail'); ?></H1>\r
+<H1><?php print I18n::_('View own Mail'); ?></H1>\r
+<?php\r
+if (count($this->headers) == 0) {\r
+       print I18n::_('You currently have no mail.');\r
+}\r
+else {\r
+?>\r
 <table>\r
        <tr>\r
-               <th><?php print I18n::_('From');?></th>\r
-               <th><?php print I18n::_('To');?></th>\r
-               <th><?php print I18n::_('Subject');?></th>\r
-               <th><?php print I18n::_('Date');?></th>\r
-               <th><?php print I18n::_('Size');?></th>\r
+               <th class="col1"><?php print I18n::_('From');?></th>\r
+               <th class="col2"><?php print I18n::_('To');?></th>\r
+               <th class="col3"><?php print I18n::_('Subject');?></th>\r
+               <th class="col4"><?php print I18n::_('Date');?></th>\r
+               <th class="col5"><?php print I18n::_('Size');?></th>\r
+               <th class="col6"><?php print I18n::_('Del');?></th>\r
        </tr>\r
 <?php\r
-foreach ($this->headers as $header) {\r
-       print "        <tr>\n";\r
-       print "            <td><a href=\"" . $header->detailslink . "\">" . $header->fromaddress . "</a></td>";\r
-       print "            <td>" . $header->toaddress . "</td>";\r
-       print "            <td>" . $header->subject . "</td>";\r
-       print "            <td>" . $header->date . "</td>";\r
-       print "            <td>" . $header->Size . "</td>";\r
-       print "        </tr>\n";\r
+       foreach ($this->headers as $header) {\r
+               print "        <tr>\n";\r
+               print "            <td><a href=\"" . $header->detailslink . "\">" . $header->fromaddress . "</a></td>";\r
+               print "            <td>" . $header->toaddress . "</td>";\r
+               print "            <td>" . $header->subject . "</td>";\r
+               print "            <td>" . $header->date . "</td>";\r
+               print "            <td>" . $header->Size . "</td>";\r
+               print "            <td><a class=\"delete\" href=\"" . $header->deletelink . "\"><img src=\"/img/delete_icon.jpg\"></a></td>";\r
+               print "        </tr>\n";\r
+       }\r
 }\r
 ?>\r
 </table>\r
index 6cd0274..4ce23f5 100644 (file)
        padding: 3px;\r
 }\r
 \r
+#content .col1 {\r
+       width: 170px;   \r
+}\r
+#content .col2 {\r
+       width: 170px;   \r
+}\r
+#content .col3 {\r
+       width: 165px;   \r
+}\r
+#content .col4 {\r
+       width: 170px;   \r
+}\r
+#content .col5 {\r
+       width: 50px;    \r
+}\r
+#content .col6 {\r
+       width: 30px;    \r
+}\r
+\r
 #content a {\r
        text-decoration: none;\r
        color: #000000;\r
@@ -23,3 +42,8 @@
 #content a:hover {\r
        color: #777777;\r
 }\r
+\r
+#content a.delete {\r
+       background-color: #ffffff;\r
+       color: white;\r
+}\r
diff --git a/manager/public/img/delete_icon.jpg b/manager/public/img/delete_icon.jpg
new file mode 100644 (file)
index 0000000..f6ce52e
Binary files /dev/null and b/manager/public/img/delete_icon.jpg differ
diff --git a/manager/public/js/mail_redirect.js b/manager/public/js/mail_redirect.js
new file mode 100644 (file)
index 0000000..a60e58f
--- /dev/null
@@ -0,0 +1,8 @@
+var delay = 2000;\r
+setTimeout('redirect()', delay);\r
+\r
+function redirect() {\r
+       var returnto = document.getElementById('returnto');\r
+       \r
+       window.location = returnto.value;\r
+}
\ No newline at end of file