Split out functionality that gathers system specs
[squirrelmail.git] / plugins / calendar / calendar_data.php
index dff67331f29fa9446902bd6d67d64195a65f93de..73dc8608fefb5e56879c702f150f2fe2c58f17ae 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * calendar_data.php
  *
- * Copyright (c) 2002-2003 The SquirrelMail Project Team
+ * Copyright (c) 2002-2004 The SquirrelMail Project Team
  * 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.
  *
  * $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;
 
@@ -35,18 +39,25 @@ function readcalendardata() {
             while ($fdata = fgetcsv ($fp, 4096, '|')) {
                 $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
                                                             'priority' => $fdata[3],
-                                                            'title' => htmlentities($fdata[4],ENT_NOQUOTES),
-                                                            'message' => htmlentities($fdata[5],ENT_NOQUOTES),
+                                                            '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;
         }
     }
 }
 
 //makes events persistant
 function writecalendardata() {
-    global $calendardata, $username, $data_dir, $year;
+    global $calendardata, $username, $data_dir, $year, $color;
 
     $filetmp = getHashedFile($username, $data_dir, "$username.$year.cal.tmp");
     $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
@@ -56,11 +67,14 @@ function writecalendardata() {
             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);
+                if(sq_fwrite($fp, $calstr, 4096) === FALSE) {
+                       error_box(_("Could not write calendar file %s", "$username.$year.cal.tmp"), $color);
+               }
             }
 
         }
         fclose ($fp);
+        @unlink($filename);
         rename($filetmp,$filename);
     }
 }