Generate a nicer agenda message.
authorJan Schneider <jan@horde.org>
Thu, 11 Nov 2010 20:19:45 +0000 (21:19 +0100)
committerJan Schneider <jan@horde.org>
Thu, 11 Nov 2010 20:23:59 +0000 (21:23 +0100)
kronolith/scripts/agenda.php
kronolith/templates/agenda/notification.html.php
kronolith/themes/graphics/big_agenda.png [new file with mode: 0644]

index 305807e..29fb64d 100755 (executable)
@@ -32,7 +32,7 @@ function send_agendas()
     }
 
     if (!empty($GLOBALS['conf']['reminder']['server_name'])) {
-        $GLOBALS['conf']['server']['name'] = $GLOBALS['conf']['reminder']['server_name'];
+        $_SERVER['SERVER_NAME'] = $GLOBALS['conf']['server']['name'] = $GLOBALS['conf']['reminder']['server_name'];
     }
 
     // Retrieve a list of users associated with each calendar, and
@@ -51,11 +51,25 @@ function send_agendas()
     // Remove duplicates.
     $users = array_unique($users);
 
+    // Generate image mime part first and only once, because we need
+    // the Content-ID.
+    $background = new Horde_Themes_Image('big_agenda.png');
+    $image = new Horde_Mime_Part();
+    $image->setType('image/png');
+    $image->setContents(file_get_contents($background->fs));
+    $image->setContentId();
+    $image->setDisposition('attachment');
+
     $runtime = new Horde_Date($runtime);
     $default_timezone = date_default_timezone_get();
     $kronolith_driver = Kronolith::getDriver();
     $view = new Horde_View(array('templatePath' => KRONOLITH_TEMPLATES . '/agenda', 'encoding' => 'UTF-8'));
     new Horde_View_Helper_Text($view);
+    $view->imageId = $image->getContentId();
+    $view->date = $runtime;
+    if (!$GLOBALS['prefs']->isLocked('daily_agenda')) {
+        $view->prefsUrl = Horde::url(Horde::getServiceLink('prefs', 'kronolith'), true)->remove(session_name());
+    }
 
     // Loop through the users and generate an agenda for them
     foreach ($users as $user) {
@@ -130,15 +144,14 @@ function send_agendas()
         ksort($eventlist);
         $GLOBALS['registry']->setLanguageEnvironment($prefs->getValue('language'));
         $twentyFour = $prefs->getValue('twentyFour');
-        $dateFormat = $prefs->getValue('date_format');
 
         $view->pad = max(Horde_String::length(_("All day")) + 2, $twentyFour ? 6 : 8);
-        $view->date = $runtime->strftime($dateFormat);
+        $view->dateFormat = $prefs->getValue('date_format');
         $view->timeformat = $twentyFour  ? 'H:i' : 'h:ia';
         $view->events = $eventlist;
 
         $mime_mail = new Horde_Mime_Mail(
-            array('subject' => sprintf(_("Your daily agenda for %s"), $view->date),
+            array('subject' => sprintf(_("Your daily agenda for %s"), $runtime->strftime($view->dateFormat)),
                   'to' => $email,
                   'from' => $GLOBALS['conf']['reminder']['from_addr'],
                   'charset' => 'UTF-8'));
@@ -153,12 +166,19 @@ function send_agendas()
         $bodyText->setType('text/plain');
         $bodyText->setCharset('UTF-8');
         $bodyText->setContents($view->render('notification.plain.php'));
+        $bodyText->setDisposition('inline');
         $multipart->addPart($bodyText);
         $bodyHtml = new Horde_Mime_Part();
         $bodyHtml->setType('text/html');
         $bodyHtml->setCharset('UTF-8');
         $bodyHtml->setContents($view->render('notification.html.php'));
-        $multipart->addPart($bodyHtml);
+        $bodyHtml->setDisposition('inline');
+        $related = new Horde_Mime_Part();
+        $related->setType('multipart/related');
+        $related->setContentTypeParameter('start', $bodyHtml->setContentId());
+        $related->addPart($bodyHtml);
+        $related->addPart($image);
+        $multipart->addPart($related);
         $mime_mail->setBasePart($multipart);
 
         Horde::logMessage(sprintf('Sending daily agenda to %s', $email), 'DEBUG');
index b80afcb..fbd3ec0 100644 (file)
@@ -1,19 +1,42 @@
-<h3><?php echo $this->h(sprintf(_("Your daily agenda for %s"), $this->date)) ?></h3>
+<p><font size="4"><strong><?php echo $this->h(_("Your daily agenda")) ?></strong></font></p>
 
-<table style="border-collapse:collapse;border:1px solid #000" border="1">
-  <?php foreach ($this->events as $event): ?>
+<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>
+  <td width="140" valign="top">
+    <table width="110" border="0" cellspacing="0" cellpadding="0">
+      <tr>
+        <td height="117" align="center" valign="bottom" style="background:transparent url('cid:<?php echo $this->imageId ?>') no-repeat center center">
+          <font style="font-size:60px"><strong><?php echo $this->date->mday ?></strong></font>
+        </td>
+      </tr>
+      <tr>
+        <td align="center"><font size="4"><strong><?php echo $this->date->strftime('%B') ?></strong></font></td>
+      </tr>
+    </table>
+  </td>
+  <td valign="top">
+    <table width="100%" border="0" cellpadding="5" cellspacing="0">
+      <?php $i = 0; foreach ($this->events as $event): ?>
 
-  <tr>
-    <td>
-      <?php if ($event->isAllDay()): ?>
-      <?php echo $this->h(_("All day")) ?>
-      <?php else: ?>
-      <?php echo $this->h($event->start->format($this->timeformat)) ?>
-      <?php endif ?>
+      <tr<?php if ($i++ % 2) echo ' bgcolor="#f1f1f1"' ?>>
+        <td nowrap="nowrap" align="right">
+          <font size="2"><strong>
+            <?php if ($event->isAllDay()): ?>
+            <?php echo $this->h(_("All day")) ?>
+            <?php else: ?>
+            <?php echo $this->h($event->start->format($this->timeformat)) ?>
+            <?php endif ?>
 
-    </td>
-    <td><a href="<?php echo $event->getViewUrl(array(), true) ?>"><?php echo $this->h($event->title) ?></a></td>
-  </tr>
-  <?php endforeach ?>
+          </strong></font>
+        </td>
+        <td width="5">&nbsp;</td>
+        <td width="100%"><font size="2"><strong><a href="<?php echo $event->getViewUrl(array(), true)->remove(session_name()) ?>"><?php echo $this->h($event->title) ?></a></strong></font></td>
+      </tr>
+      <?php endforeach ?>
 
-</table>
+    </table>
+  </td>
+</tr></table>
+
+<?php if ($this->prefsUrl): ?>
+<p><font size="1"><?php printf(_("You get this message because your calendar is configured to send you a daily agenda. You can change this if you %slogin to the calendar%s and change your preferences."), '<a href="' . $this->prefsUrl . '">', '</a>') ?></font></p>
+<?php endif ?>
diff --git a/kronolith/themes/graphics/big_agenda.png b/kronolith/themes/graphics/big_agenda.png
new file mode 100644 (file)
index 0000000..88ce7d1
Binary files /dev/null and b/kronolith/themes/graphics/big_agenda.png differ