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