~ubuntu-branches/ubuntu/hardy/squirrelmail/hardy-updates

« back to all changes in this revision

Viewing changes to plugins/calendar/calendar_data.php

  • Committer: Bazaar Package Importer
  • Author(s): Sam Johnston
  • Date: 2004-02-04 01:42:12 UTC
  • Revision ID: james.westby@ubuntu.com-20040204014212-ek9533qvd2vo1wa1
Tags: upstream-1.5.0
ImportĀ upstreamĀ versionĀ 1.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * calendar_data.php
 
5
 *
 
6
 * Copyright (c) 2002-2003 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: calendar_data.php,v 1.11 2003/10/27 22:24:39 tassium Exp $
 
14
 * @package plugins
 
15
 * @subpackage calendar
 
16
 */
 
17
 
 
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();
 
22
 
 
23
/**
 
24
 * read events into array
 
25
 *
 
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;
 
32
 
 
33
    $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
 
34
 
 
35
    if (file_exists($filename)){
 
36
        $fp = fopen ($filename,'r');
 
37
 
 
38
        if ($fp){
 
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] );
 
45
            }
 
46
            fclose ($fp);
 
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;
 
52
            }
 
53
            $calendardata = $new_calendardata;
 
54
        }
 
55
    }
 
56
}
 
57
 
 
58
//makes events persistant
 
59
function writecalendardata() {
 
60
    global $calendardata, $username, $data_dir, $year;
 
61
 
 
62
    $filetmp = getHashedFile($username, $data_dir, "$username.$year.cal.tmp");
 
63
    $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
 
64
    $fp = fopen ($filetmp,"w");
 
65
    if ($fp) {
 
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
                fwrite($fp, $calstr, 4096);
 
71
            }
 
72
 
 
73
        }
 
74
        fclose ($fp);
 
75
        @unlink($filename);
 
76
        rename($filetmp,$filename);
 
77
    }
 
78
}
 
79
 
 
80
//deletes event from file
 
81
function delete_event($date, $time) {
 
82
    global $calendardata, $username, $data_dir, $year;
 
83
 
 
84
    $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
 
85
    $fp = fopen ($filename,'r');
 
86
    if ($fp){
 
87
        while ($fdata = fgetcsv ($fp, 4096, "|")) {
 
88
            if (($fdata[0]==$date) && ($fdata[1]==$time)){
 
89
            // do nothing
 
90
            } else {
 
91
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
 
92
                                                             'priority' => $fdata[3],
 
93
                                                             'title' => $fdata[4],
 
94
                                                             'message' => $fdata[5],
 
95
                                                             'reminder' => $fdata[6] );
 
96
            }
 
97
        }
 
98
        fclose ($fp);
 
99
    }
 
100
    writecalendardata();
 
101
 
 
102
}
 
103
 
 
104
// same as delete but not saves calendar
 
105
// saving is done inside event_edit.php
 
106
function update_event($date, $time) {
 
107
    global $calendardata, $username, $data_dir, $year;
 
108
 
 
109
    $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
 
110
    $fp = fopen ($filename,'r');
 
111
    if ($fp){
 
112
        while ($fdata = fgetcsv ($fp, 4096, '|')) {
 
113
            if (($fdata[0]==$date) && ($fdata[1]==$time)){
 
114
            // do nothing
 
115
            } else {
 
116
                $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
 
117
                                                             'priority' => $fdata[3],
 
118
                                                             'title' => $fdata[4],
 
119
                                                             'message' => $fdata[5],
 
120
                                                             'reminder' => $fdata[6] );
 
121
            }
 
122
        }
 
123
        fclose ($fp);
 
124
    }
 
125
}
 
126
 
 
127
 
 
128
?>