6
* Copyright (c) 2002-2006 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
4
* functions to operate on calendar data files.
13
* $Id: calendar_data.php,v 1.7.2.10 2006/02/03 22:27:52 jervfors Exp $
6
* @copyright © 2002-2006 The SquirrelMail Project Team
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8
* @version $Id: calendar_data.php,v 1.7.2.11 2006/05/06 07:52:18 tokul Exp $
10
* @subpackage calendar
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);
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,reminder);
19
18
$calendardata = array();
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
21
* Reads multilined calendar data
23
* Plugin stores multiline texts converted to single line with PHP nl2br().
24
* Function undoes nl2br() conversion and html encoding of ASCII vertical bar.
26
* Older plugin versions sanitized data with htmlspecialchars. Since 1.5.1 calendar
27
* data is not sanitized. Output functions must make sure that data is correctly
28
* encoded and sanitized.
29
* @param string $string calendar string
30
* @return string calendar string converted to multiline text
32
* @since 1.5.1 and 1.4.7
34
function calendar_readmultiline($string) {
36
* replace html line breaks with ASCII line feeds
37
* replace htmlencoded | with ASCII vertical bar
39
$string = str_replace(array('<br />','<br>','|'),array("\n","\n",'|'),$string);
44
* Callback function used to sanitize calendar data before saving it to file
45
* @param string $sValue array value
46
* @param string $sKey array key
48
* @since 1.5.1 and 1.4.7
50
function calendar_encodedata(&$sValue, $sKey) {
52
* add html line breaks
53
* remove original ASCII line feeds and carriage returns
54
* replace ASCII vertical bar with html code in order to sanitize field delimiter
56
$sValue = str_replace(array("\n","\r",'|'),array('','','|'),nl2br($sValue));
60
* read events into array
62
* data is | delimited, just like addressbook
63
* files are structured like this:
64
* date|time|length|priority|title|message
65
* files are divided by year for performance increase
26
67
function readcalendardata() {
27
68
global $calendardata, $username, $data_dir, $year;
35
76
while ($fdata = fgetcsv ($fp, 4096, '|')) {
36
$calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
37
'priority' => $fdata[3],
38
'title' => htmlspecialchars($fdata[4],ENT_NOQUOTES),
39
'message' => htmlspecialchars($fdata[5],ENT_NOQUOTES),
40
'reminder' => $fdata[6] );
77
$calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
78
'priority' => $fdata[3],
79
'title' => str_replace("\n",' ',calendar_readmultiline($fdata[4])),
80
'message' => calendar_readmultiline($fdata[5]),
81
'reminder' => $fdata[6] );
43
84
// this is to sort the events within a day on starttime
62
107
while ( $calfoo = each ($calendardata)) {
63
108
while ( $calbar = each ($calfoo['value'])) {
64
109
$calfoobar = $calendardata[$calfoo['key']][$calbar['key']];
110
array_walk($calfoobar,'calendar_encodedata');
112
* Make sure that reminder field is set. Calendar forms don't implement it,
113
* but it is still used for calendar data. Backwards compatibility.
115
if (!isset($calfoobar['reminder'])) $calfoobar['reminder']='';
65
117
$calstr = "$calfoo[key]|$calbar[key]|$calfoobar[length]|$calfoobar[priority]|$calfoobar[title]|$calfoobar[message]|$calfoobar[reminder]\n";
66
118
if(sq_fwrite($fp, $calstr, 4096) === FALSE) {
67
error_box(_("Could not write calendar file %s", "$username.$year.cal.tmp"), $color);
119
error_box(_("Could not write calendar file %s", "$username.$year.cal.tmp"), $color);
85
141
while ($fdata = fgetcsv ($fp, 4096, "|")) {
86
142
if (($fdata[0]==$date) && ($fdata[1]==$time)){
89
$calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
145
$calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
90
146
'priority' => $fdata[3],
92
'message' => $fdata[5],
147
'title' => $fdata[4],
148
'message' => $fdata[5],
93
149
'reminder' => $fdata[6] );
98
154
writecalendardata();
102
// same as delete but not saves calendar
103
// saving is done inside event_edit.php
158
* same as delete but does not save calendar
159
* saving is done inside event_edit.php
104
164
function update_event($date, $time) {
105
165
global $calendardata, $username, $data_dir, $year;