squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

calendar_data.php
Go to the documentation of this file.
1 <?php
2 
18 $calendardata = array();
19 
34 function calendar_readmultiline($string) {
39  $string = str_replace(array('<br />','<br>','&#124;'),array("\n","\n",'|'),$string);
40  return $string;
41 }
42 
50 function calendar_encodedata(&$sValue, $sKey) {
56  $sValue = str_replace(array("\n","\r",'|'),array('','','&#124;'),nl2br($sValue));
57 }
58 
67 function readcalendardata() {
68  global $calendardata, $username, $data_dir, $year;
69 
70  $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
71 
72  if (file_exists($filename)){
73  $fp = fopen ($filename,'r');
74 
75  if ($fp){
76  while ($fdata = fgetcsv ($fp, 4096, '|')) {
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] );
82  }
83  fclose ($fp);
84  // this is to sort the events within a day on starttime
85  $new_calendardata = array();
86  foreach($calendardata as $day => $data) {
87  ksort($data, SORT_NUMERIC);
88  $new_calendardata[$day] = $data;
89  }
90  $calendardata = $new_calendardata;
91  }
92  }
93 }
94 
100 function writecalendardata() {
101  global $calendardata, $username, $data_dir, $year, $color;
102 
103  $filetmp = getHashedFile($username, $data_dir, "$username.$year.cal.tmp");
104  $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
105  $fp = fopen ($filetmp,"w");
106  if ($fp) {
107  while ( $calfoo = each ($calendardata)) {
108  while ( $calbar = each ($calfoo['value'])) {
109  $calfoobar = $calendardata[$calfoo['key']][$calbar['key']];
110  array_walk($calfoobar,'calendar_encodedata');
115  if (!isset($calfoobar['reminder'])) $calfoobar['reminder']='';
116 
117  $calstr = "$calfoo[key]|$calbar[key]|$calfoobar[length]|$calfoobar[priority]|$calfoobar[title]|$calfoobar[message]|$calfoobar[reminder]\n";
118  if(sq_fwrite($fp, $calstr, 4096) === FALSE) {
119  error_box(_("Could not write calendar file %s", "$username.$year.cal.tmp"), $color);
120  }
121  }
122 
123  }
124  fclose ($fp);
125  @unlink($filename);
126  rename($filetmp,$filename);
127  }
128 }
129 
135 function delete_event($date, $time) {
136  global $calendardata, $username, $data_dir, $year;
137 
138  $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
139  $fp = fopen ($filename,'r');
140  if ($fp){
141  while ($fdata = fgetcsv ($fp, 4096, "|")) {
142  if (($fdata[0]==$date) && ($fdata[1]==$time)){
143  // do nothing
144  } else {
145  $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
146  'priority' => $fdata[3],
147  'title' => $fdata[4],
148  'message' => $fdata[5],
149  'reminder' => $fdata[6] );
150  }
151  }
152  fclose ($fp);
153  }
155 }
156 
164 function update_event($date, $time) {
165  global $calendardata, $username, $data_dir, $year;
166 
167  $filename = getHashedFile($username, $data_dir, "$username.$year.cal");
168  $fp = fopen ($filename,'r');
169  if ($fp){
170  while ($fdata = fgetcsv ($fp, 4096, '|')) {
171  if (($fdata[0]==$date) && ($fdata[1]==$time)){
172  // do nothing
173  } else {
174  $calendardata[$fdata[0]][$fdata[1]] = array( 'length' => $fdata[2],
175  'priority' => $fdata[3],
176  'title' => $fdata[4],
177  'message' => $fdata[5],
178  'reminder' => $fdata[6] );
179  }
180  }
181  fclose ($fp);
182  }
183 }
184 
185 ?>
writecalendardata
writecalendardata()
Definition: calendar_data.php:100
$date
$date
Definition: printer_friendly_bottom.php:61
$data_dir
$data_dir
Definition: config_default.php:499
sq_fwrite
sq_fwrite($fp, $string)
Definition: strings.php:763
$username
global $username
Definition: validate.php:55
$calendardata
$calendardata
Definition: calendar_data.php:18
update_event
update_event($date, $time)
Definition: calendar_data.php:164
delete_event
delete_event($date, $time)
Definition: calendar_data.php:135
calendar_readmultiline
calendar_readmultiline($string)
Definition: calendar_data.php:34
$filename
if(isset($override_type0)) if(isset($override_type1)) $filename
Definition: download.php:97
$data
$data
Definition: mailto.php:83
_
_($str)
Definition: gettext.php:160
readcalendardata
readcalendardata()
Definition: calendar_data.php:67
getHashedFile
getHashedFile($username, $dir, $datafile, $hash_search=true)
Definition: prefs.php:56
calendar_encodedata
calendar_encodedata(&$sValue, $sKey)
Definition: calendar_data.php:50
$color
$color
Definition: load_prefs.php:28
error_box
error_box($string, $color)
Definition: display_messages.php:116