A start for a new change_password master plugin. This is not finished
[squirrelmail.git] / plugins / calendar / calendar_data.php
index 8bf3d65e448f1701c5d66f555413d49370e1a603..705e8a7168adce2782369bc4e57eae664a4ee470 100644 (file)
@@ -1,25 +1,32 @@
 <?php
-/*
- *  calendar_data.php
+
+/**
+ * calendar_data.php
+ *
+ * Copyright (c) 2002-2003 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
- *  Copyright (c) 2001 Michal Szczotka <michal@tuxy.org>
- *  Licensed under the GNU GPL. For full terms see the file COPYING.
+ * Originally contrubuted by Michal Szczotka <michal@tuxy.org>
  *
- *  functions to operate on calendar data files.
+ * functions to operate on calendar data files.
  *
  * $Id$
+ * @package plugins
+ * @subpackage calendar
  */
 
-// this is array that contains all events
-// it is three dimensional array with fallowing structure
-// $calendardata[date][time] = array(length,priority,title,message);
+/** this is array that contains all events
+ *  it is three dimensional array with fallowing structure
+ *  $calendardata[date][time] = array(length,priority,title,message); */
 $calendardata = array();
 
-//read events into array
-//data is | delimited, just like addresbook
-//files are structured like this:
-//date|time|length|priority|title|message);
-//files are divide by year for performance increase
+/**
+ * read events into array
+ *
+ * data is | delimited, just like addressbook
+ * files are structured like this:
+ * date|time|length|priority|title|message
+ * files are divided by year for performance increase */
 function readcalendardata() {
     global $calendardata, $username, $data_dir, $year;
 
@@ -27,16 +34,24 @@ function readcalendardata() {
 
     if (file_exists($filename)){
         $fp = fopen ($filename,'r');
-    }
-    if ($fp){
-        while ($fdata = fgetcsv ($fp, 4096, '|')) {
-            $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
-                                                         'priority' => $fdata[3],
-                                                         'title' => $fdata[4],
-                                                         'message' => $fdata[5],
-                                                         'reminder' => $fdata[6] );
+
+        if ($fp){
+            while ($fdata = fgetcsv ($fp, 4096, '|')) {
+                $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
+                                                            'priority' => $fdata[3],
+                                                            'title' => htmlspecialchars($fdata[4],ENT_NOQUOTES),
+                                                            'message' => htmlspecialchars($fdata[5],ENT_NOQUOTES),
+                                                            'reminder' => $fdata[6] );
+            }
+            fclose ($fp);
+            // this is to sort the events within a day on starttime
+            $new_calendardata = array();
+           foreach($calendardata as $day => $data) {
+                ksort($data, SORT_NUMERIC);
+                $new_calendardata[$day] = $data;
+            }
+           $calendardata = $new_calendardata;
         }
-        fclose ($fp);
     }
 }
 
@@ -49,14 +64,15 @@ function writecalendardata() {
     $fp = fopen ($filetmp,"w");
     if ($fp) {
         while ( $calfoo = each ($calendardata)) {
-            while ( $calbar = each ($calfoo[value])) {
-                $calfoobar = $calendardata[$calfoo[key]][$calbar[key]];
+            while ( $calbar = each ($calfoo['value'])) {
+                $calfoobar = $calendardata[$calfoo['key']][$calbar['key']];
                 $calstr = "$calfoo[key]|$calbar[key]|$calfoobar[length]|$calfoobar[priority]|$calfoobar[title]|$calfoobar[message]|$calfoobar[reminder]\n";
                 fwrite($fp, $calstr, 4096);
             }
 
         }
         fclose ($fp);
+        @unlink($filename);
         rename($filetmp,$filename);
     }
 }
@@ -109,4 +125,4 @@ function update_event($date, $time) {
 }
 
 
-?>
\ No newline at end of file
+?>