6 * Copyright (c) 2002-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Originally contrubuted by Michal Szczotka <michal@tuxy.org>
11 * functions to operate on calendar data files.
15 * @subpackage calendar
18 /** this is array that contains all events
19 * it is three dimensional array with fallowing structure
20 * $calendardata[date][time] = array(length,priority,title,message); */
21 $calendardata = array();
24 * read events into array
26 * data is | delimited, just like addressbook
27 * files are structured like this:
28 * date|time|length|priority|title|message
29 * files are divided by year for performance increase */
30 function readcalendardata() {
31 global $calendardata, $username, $data_dir, $year;
33 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
35 if (file_exists($filename)){
36 $fp = fopen ($filename,'r');
39 while ($fdata = fgetcsv ($fp, 4096, '|')) {
40 $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
41 'priority' => $fdata[3],
42 'title' => htmlspecialchars($fdata[4],ENT_NOQUOTES
),
43 'message' => htmlspecialchars($fdata[5],ENT_NOQUOTES
),
44 'reminder' => $fdata[6] );
47 // this is to sort the events within a day on starttime
48 $new_calendardata = array();
49 foreach($calendardata as $day => $data) {
50 ksort($data, SORT_NUMERIC
);
51 $new_calendardata[$day] = $data;
53 $calendardata = $new_calendardata;
58 //makes events persistant
59 function writecalendardata() {
60 global $calendardata, $username, $data_dir, $year, $color;
62 $filetmp = getHashedFile($username, $data_dir, "$username.$year.cal.tmp");
63 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
64 $fp = fopen ($filetmp,"w");
66 while ( $calfoo = each ($calendardata)) {
67 while ( $calbar = each ($calfoo['value'])) {
68 $calfoobar = $calendardata[$calfoo['key']][$calbar['key']];
69 $calstr = "$calfoo[key]|$calbar[key]|$calfoobar[length]|$calfoobar[priority]|$calfoobar[title]|$calfoobar[message]|$calfoobar[reminder]\n";
70 if(sq_fwrite($fp, $calstr, 4096) === FALSE) {
71 error_box(_("Could not write calendar file %s", "$username.$year.cal.tmp"), $color);
78 rename($filetmp,$filename);
82 //deletes event from file
83 function delete_event($date, $time) {
84 global $calendardata, $username, $data_dir, $year;
86 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
87 $fp = fopen ($filename,'r');
89 while ($fdata = fgetcsv ($fp, 4096, "|")) {
90 if (($fdata[0]==$date) && ($fdata[1]==$time)){
93 $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
94 'priority' => $fdata[3],
96 'message' => $fdata[5],
97 'reminder' => $fdata[6] );
106 // same as delete but not saves calendar
107 // saving is done inside event_edit.php
108 function update_event($date, $time) {
109 global $calendardata, $username, $data_dir, $year;
111 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
112 $fp = fopen ($filename,'r');
114 while ($fdata = fgetcsv ($fp, 4096, '|')) {
115 if (($fdata[0]==$date) && ($fdata[1]==$time)){
118 $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
119 'priority' => $fdata[3],
120 'title' => $fdata[4],
121 'message' => $fdata[5],
122 'reminder' => $fdata[6] );