Typo
[squirrelmail.git] / plugins / calendar / calendar_data.php
1 <?php
2 /*
3 * calendar_data.php
4 *
5 * Copyright (c) 2001 Michal Szczotka <michal@tuxy.org>
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * functions to operate on calendar data files.
9 *
10 * $Id$
11 */
12
13 // this is array that contains all events
14 // it is three dimensional array with fallowing structure
15 // $calendardata[date][time] = array(length,priority,title,message);
16 $calendardata = array();
17
18 //read events into array
19 //data is | delimited, just like addresbook
20 //files are structured like this:
21 //date|time|length|priority|title|message);
22 //files are divide by year for performance increase
23 function readcalendardata() {
24 global $calendardata, $username, $data_dir, $year;
25
26 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
27
28 if (file_exists($filename)){
29 $fp = fopen ($filename,'r');
30 }
31 if ($fp){
32 while ($fdata = fgetcsv ($fp, 4096, '|')) {
33 $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
34 'priority' => $fdata[3],
35 'title' => $fdata[4],
36 'message' => $fdata[5],
37 'reminder' => $fdata[6] );
38 }
39 fclose ($fp);
40 }
41 }
42
43 //makes events persistant
44 function writecalendardata() {
45 global $calendardata, $username, $data_dir, $year;
46
47 $filetmp = getHashedFile($username, $data_dir, "$username.$year.cal.tmp");
48 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
49 $fp = fopen ($filetmp,"w");
50 if ($fp) {
51 while ( $calfoo = each ($calendardata)) {
52 while ( $calbar = each ($calfoo[value])) {
53 $calfoobar = $calendardata[$calfoo[key]][$calbar[key]];
54 $calstr = "$calfoo[key]|$calbar[key]|$calfoobar[length]|$calfoobar[priority]|$calfoobar[title]|$calfoobar[message]|$calfoobar[reminder]\n";
55 fwrite($fp, $calstr, 4096);
56 }
57
58 }
59 fclose ($fp);
60 rename($filetmp,$filename);
61 }
62 }
63
64 //deletes event from file
65 function delete_event($date, $time) {
66 global $calendardata, $username, $data_dir, $year;
67
68 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
69 $fp = fopen ($filename,'r');
70 if ($fp){
71 while ($fdata = fgetcsv ($fp, 4096, "|")) {
72 if (($fdata[0]==$date) && ($fdata[1]==$time)){
73 // do nothing
74 } else {
75 $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
76 'priority' => $fdata[3],
77 'title' => $fdata[4],
78 'message' => $fdata[5],
79 'reminder' => $fdata[6] );
80 }
81 }
82 fclose ($fp);
83 }
84 writecalendardata();
85
86 }
87
88 // same as delete but not saves calendar
89 // saving is done inside event_edit.php
90 function update_event($date, $time) {
91 global $calendardata, $username, $data_dir, $year;
92
93 $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
94 $fp = fopen ($filename,'r');
95 if ($fp){
96 while ($fdata = fgetcsv ($fp, 4096, '|')) {
97 if (($fdata[0]==$date) && ($fdata[1]==$time)){
98 // do nothing
99 } else {
100 $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
101 'priority' => $fdata[3],
102 'title' => $fdata[4],
103 'message' => $fdata[5],
104 'reminder' => $fdata[6] );
105 }
106 }
107 fclose ($fp);
108 }
109 }
110
111
112 ?>