function export_vcal($id) { header("Content-Type: text/x-vcalendar"); //header ( "Content-Type: text/plain" ); $res = export_get_event_entry($id); $entry_array = array(); $count = 0; while ($entry = dbi_fetch_row($res)) { $entry_array[$count++] = $entry; } dbi_free_result($res); if (count($entry_array) > 0) { echo "BEGIN:VCALENDAR\r\n"; echo "{$prodid}\r\n"; echo "VERSION:1.0\r\n"; /* Time Zone $tzdate = mktime(); $gmdate = gmmktime(); $tzdiff = ($gmdate - $tzdate) / 60 / 60; //FIXME only hours are represented $tz = sprintf("%02d", $tzdiff); echo "TZ:"; echo ($tzdiff >= 0) ? "+" : "-"; echo "$tz\r\n"; */ } while (list($key, $row) = each($entry_array)) { $uid = $row[0]; $export_uid = generate_uid(); $name = $row[1]; $priority = $row[2]; $date = $row[3]; $time = $row[4]; $status = $row[5]; $create_by = $row[6]; $access = $row[7]; $duration = $row[8]; $description = $row[9]; /* Start of event */ echo "BEGIN:VEVENT\r\n"; /* UID of the event (folded to 76 char) */ $export_uid = "UID:{$export_uid}"; $array = export_fold_lines($export_uid); while (list($key, $value) = each($array)) { echo "{$value}\r\n"; } /* SUMMARY of the event (folded to 76 char) */ $name = preg_replace("/\\\\/", "\\\\\\", $name); // ?? $name = "SUMMARY;ENCODING=QUOTED-PRINTABLE:" . $name; $array = export_fold_lines($name, "quotedprintable"); while (list($key, $value) = each($array)) { echo "{$value}\r\n"; } /* DESCRIPTION if any (folded to 76 char) */ if ($description != "") { $description = preg_replace("/\\\\/", "\\\\\\", $description); // ?? $description = "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" . $description; $array = export_fold_lines($description, "quotedprintable"); while (list($key, $value) = each($array)) { echo "{$value}\r\n"; } } //end if ($description != "") /* CLASS either "PRIVATE" or "PUBLIC" (the default) */ if ($access == "R") { echo "CLASS:PRIVATE\r\n"; } else { echo "CLASS:PUBLIC\r\n"; } // ATTENDEE of the event $attendee = export_get_attendee($row[0], "vcal"); for ($i = 0; $i < count($attendee); $i++) { $attendee[$i] = export_fold_lines($attendee[$i], "quotedprintable"); while (list($key, $value) = each($attendee[$i])) { echo "{$value}\r\n"; } } /* Time - all times are utc */ export_time($date, $duration, $time, "vcal"); export_recurrence_vcal($uid, $date); // FIXME: handle alarms export_alarm_vcal($uid, $date, $time); /* Goodbye event */ echo "END:VEVENT\n"; } //end while (list($key,$row) = each($entry_array)) if (count($entry_array) > 0) { echo "END:VCALENDAR\r\n"; } }
function export_vcal($id) { global $login; header('Content-Type: text/x-vcalendar'); // header ( "Content-Type: text/plain" ); $res = export_get_event_entry($id); $entry_array = array(); $count = 0; while ($entry = dbi_fetch_row($res)) { $entry_array[$count++] = $entry; } dbi_free_result($res); if (count($entry_array) > 0) { echo "BEGIN:VCALENDAR\r\n"; echo generate_prodid('vcs'); echo "VERSION:1.0\r\n"; } while (list($key, $row) = each($entry_array)) { $id = $row[0]; $export_uid = generate_uid(); $name = $row[1]; $priority = $row[2]; $date = $row[3]; $time = sprintf("%06d", $row[4]); $status = $row[5]; $create_by = $row[6]; $access = $row[7]; $duration = $row[8]; $description = $row[9]; $percent = $row[10]; $completed = $row[11]; $due_date = $row[12]; $due_time = $row[13]; $location = $row[14]; $url = $row[15]; $cal_type = $row[16]; // Figure out Categories $categories = get_categories_by_id($id, $login); /* Start of event/task */ if ($cal_type == 'E' || $cal_type == 'M') { echo "BEGIN:VEVENT\r\n"; } elseif ($cal_type == 'T' || $cal_type == 'N') { echo "BEGIN:VTODO\r\n"; } else { // VJOURNALS are not allowed in VCS files. continue; } /* UID of the event (folded to 76 char) */ $export_uid = "UID:{$export_uid}"; $array = export_fold_lines($export_uid); while (list($key, $value) = each($array)) { echo "{$value}\r\n"; } /* SUMMARY of the event (folded to 76 char) */ $name = preg_replace("/\\\\/", "\\\\\\", $name); // ?? $name = 'SUMMARY;ENCODING=QUOTED-PRINTABLE:' . $name; $array = export_fold_lines($name, 'quotedprintable'); while (list($key, $value) = each($array)) { echo "{$value}\r\n"; } /* DESCRIPTION if any (folded to 76 char) */ if ($description != '') { $description = preg_replace("/\\\\/", "\\\\\\", $description); // ?? $description = 'DESCRIPTION;ENCODING=QUOTED-PRINTABLE:' . $description; $array = export_fold_lines($description, 'quotedprintable'); while (list($key, $value) = each($array)) { echo "{$value}\r\n"; } } //end if ($description != '') /* CATEGORIES if any (folded to 76 char) */ if (isset($categories) && count($categories)) { $categories = 'CATEGORIES:' . implode(';', $categories); $array = export_fold_lines($categories, 'quotedprintable'); while (list($key, $value) = each($array)) { $ret .= "{$value}\r\n"; } } /* CLASS either "PRIVATE", "CONFIDENTIAL, or "PUBLIC" (the default) */ if ($access == 'R') { echo "CLASS:PRIVATE\r\n"; } else { if ($access == 'C') { echo "CLASS:CONFIDENTIAL\r\n"; } else { echo "CLASS:PUBLIC\r\n"; } } // ATTENDEE of the event // $attendee = export_get_attendee( $row[0], 'vcal' ); //$attendcnt = count ( $attendee ); //for ( $i = 0; $i < $attendcnt; $i++ ) { // $attendee[$i] = export_fold_lines ( $attendee[$i], 'quotedprintable' ); // while ( list ( $key, $value ) = each ( $attendee[$i] ) ) // echo "$value\r\n"; //} /* Time - all times are utc */ echo export_time($date, $duration, $time, 'vcal'); echo export_recurrence_vcal($id, $date); export_alarm_vcal($id, $date); /* Goodbye event/task */ if ($cal_type == 'E' || $cal_type == 'M') { echo "END:VEVENT\r\n"; } else { echo "END:VTODO\r\n"; } } //end while (list ($key,$row) = each ( $entry_array)) if (count($entry_array) > 0) { echo "END:VCALENDAR\r\n"; } }