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