[kronolith] Categories for remote calendars

Justus Pendleton horde at ryoohki.net
Sun Nov 23 21:30:47 PST 2003


Hi,

I recently started playing around with Kronolith's remote calendar
support by adding a bunch of calendars from www.icalshare.com.  All
was pretty much well except for one thing, all of the events showed up
as unfiled and thus had the same color making them hard (for me, at
least) to differentiate in the calendar views.  I thought it would be
nice to allow the user to specify a category for all events in a
remote calendar.

So I tried to make a few changes toward that end.  I have attached a
patch showing what I've done.  All is pretty much well with one
caveat:

Warnings are generated by preexisting remote calendars on account
of them not having this new category defined.  This is the first time
I've ever written any PHP so I wasn't sure how to go about avoiding
that warning.

I haven't used remote calendars much so I don't know if this is a
good way to handle them or not.  But below is my patch to add this to
Kronolith.

Index: prefs.php
===================================================================
RCS file: /repository/kronolith/prefs.php,v
retrieving revision 1.30
diff -u -b -B -w -p -r1.30 prefs.php
--- prefs.php	16 Sep 2003 23:05:58 -0000	1.30
+++ prefs.php	24 Nov 2003 05:19:51 -0000
@@ -14,13 +14,15 @@ function handle_remote_cal_management($u
 
     $calName = Util::getFormData('remote_name');
     $calUrl  = Util::getFormData('remote_url');
+    $calCat  = Util::getFormData('remote_category');
     $calActionID = Util::getFormData('remote_action', 'add');
 
     if ($calActionID == 'add') {
         if (!empty($calName) && !empty($calUrl)) {
             $cals = unserialize($prefs->getValue('remote_cals'));
             $cals[] = array('name' => $calName,
-                            'url'  => $calUrl);
+                            'url'  => $calUrl,
+			    'category' => $calCat);
             $prefs->setValue('remote_cals', serialize($cals));                
             $updated = true;
             return false;
Index: lib/Kronolith.php
===================================================================
RCS file: /repository/kronolith/lib/Kronolith.php,v
retrieving revision 1.166
diff -u -b -B -w -p -r1.166 Kronolith.php
--- lib/Kronolith.php	4 Nov 2003 03:17:10 -0000	1.166
+++ lib/Kronolith.php	24 Nov 2003 05:19:54 -0000
@@ -171,7 +171,7 @@ class Kronolith {
      */
     function listRemoteEvents($url)
     {
-        global $calendar;
+        global $calendar, $prefs;
 
         if (empty($_SESSION['kronolith']['remote'])) {
             $_SESSION['kronolith']['remote'] = array();
@@ -204,6 +204,9 @@ class Kronolith {
                 $event->fromHash($vcs->toHash($i));
                 $event->remoteCal = $url;
                 $event->eventIndex = $i;
+		$remote_calendars = unserialize($prefs->getValue('remote_cals'));
+		$array_index = array_search ($url, $remote_calendars);
+		$event->category = $remote_calendars[$array_index]['category'];
                 $events[] = $event;
             }
         }
Index: templates/prefs/remote_cal_management.inc
===================================================================
RCS file: /repository/kronolith/templates/prefs/remote_cal_management.inc,v
retrieving revision 1.2
diff -u -b -B -w -p -r1.2 remote_cal_management.inc
--- templates/prefs/remote_cal_management.inc	30 Dec 2002 10:45:21 -0000	1.2
+++ templates/prefs/remote_cal_management.inc	24 Nov 2003 05:20:01 -0000
@@ -19,18 +19,28 @@ function deleteCal(id)
 
 <tr>
   <th align="left"><?php echo _("Name") ?></th>
-  <th align="left" colspan="2">
+  <th align="left" colspan="1">
     <?php echo _("URL") ?>
   </th>
+  <th align="left"><?php echo _("Category") ?></th>
 </tr>
 
 <?php
 $cals = unserialize($prefs->getValue('remote_cals'));
+
+$categories = Kronolith::listCategories();
+
+$calendar_id = $prefs->getValue('default_share');
+$_colors = Kronolith::categoryColors();
+$colors = isset($_colors[$calendar_id]) ? $_colors[$calendar_id] : array();
+
 foreach ($cals as $key => $cal):
+$color = isset($colors[$cal['category']]) ? $colors[$cal['category']] : '#ffffff';
 ?>
 <tr>
   <td><?php echo $cal['name'] ?></td>
   <td><?php echo $cal['url'] ?></td>
+  <td style="background-color:<?php echo $color ?>"><b><?php echo $categories[$cal['category']] ?></b></td>
   <td><a href='#' onclick="deleteCal('<?php echo $cal['url'] ?>'); return false;"><?php echo _("Delete") ?></a></td>
 </tr>
 <?php endforeach; ?>
@@ -57,6 +67,14 @@ foreach ($cals as $key => $cal):
         <td>
           <input size="50" type="text" name="remote_url" value="">
         </td>
+      </tr>
+      <tr>
+        <td>
+	  <?php echo _("Category") ?> &nbsp;&nbsp;
+	</td>
+	<td>
+	  <?php echo Kronolith::buildCategoryWidget('remote_category', $calendar_id) ?>
+	</td>
       </tr>
     </table>
   </td>


More information about the kronolith mailing list