1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
|
<?php
/**
* Kronolith_Event:: defines a generic API for events
*
* $Horde: kronolith/lib/Event.php,v 1.13.2.15 2003/05/15 22:15:49 jan Exp $
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @version $Revision: 1.13.2.15 $
* @since Kronolith 0.1
* @package kronolith
*/
class Kronolith_Event {
/**
* Flag that is set to true if this event has been created in the
* storage driver.
* @var boolean $initialized
*/
var $initialized = false;
/**
* The driver unique identifier for this event.
* @var integer $eventID
*/
var $eventID = null;
/**
* The title of this event,
* @var string $title
*/
var $title = '';
/**
* The identifier of the category this event belongs to.
* @var integer $category
*/
var $category = 0;
/**
* The location this event occurs at.
* @var string $location
*/
var $location = '';
/**
* The description for this event
* @var string $description
*/
var $description = '';
/**
* All the key words associtated with this event.
* @var array $keywords
*/
var $keywords = array();
/**
* All the exceptions for this event if this recuring.
* @var array $exceptions
*/
var $exceptions = array();
/**
* The timestamp for the start of this event.
* @var integer $startTimestamp
*/
var $startTimestamp = 0;
/**
* The timestamp for the end of this event.
* @var integer $endTimestamp
*/
var $endTimestamp = 0;
/**
* The duration of this event in minutes
* @var integer $durMin
*/
var $durMin = 0;
/**
* TODO what does this value represent?
* @var integer $alarm
*/
var $alarm = 0;
/**
* The timestamp for the end of the recurrance interval.
* @var integer $recurEndTimestamp
*/
var $recurEndTimestamp = null;
/**
* The type of recurrance this event follows. KRONOLITH_RECUR_* constant.
* @var KRONOLITH_RECUR_* $recurType
*/
var $recurType = KRONOLITH_RECUR_NONE;
/**
* TODO The length of time between recurances in seconds?
* @var integer $recurInterval
*/
var $recurInterval = null;
/**
* TODO
* @var
*/
var $recurData = null;
/**
* The identifier of the calender this event exists on.
* @var string $_calendar
*/
var $_calendar;
/**
* Constructor
*
* @param Kronolith_Driver $driver The backend driver that this
* event is stored in.
* @param Kronolith_Event $eventObject Backend specific event object
* that this will represent.
*/
function Kronolith_Event(&$driver, $eventObject = null)
{
$this->_calendar = $driver->getCalendar();
if (isset($eventObject)) {
$this->fromDriver($eventObject);
}
}
/**
* Return a reference to a driver that's valid for this event.
*
* @return Kronolith_Driver A driver that this event can use to save itself, etc.
*/
function &getDriver()
{
global $calendar;
if ($calendar->getCalendar() != $this->_calendar) {
$calendar->close();
$calendar->open($this->_calendar);
}
return $calendar;
}
/**
* Create a new event.
*/
function createEvent()
{
$this->toDriver();
$this->initialized = true;
}
/**
* Export this event in iCalendar format.
*
* param Identity $identity The Identity object of the organizer.
* param Horde_Data_iCalendar $vcs (optional) The data object to use to
* format the dates.
*
* @return @array Array of all the iCal attributes and their values.
*/
function toiCalendar($identity, $vcs = null)
{
global $prefs;
if (is_null($vcs)) {
include_once HORDE_BASE . '/lib/Data.php';
$vcs = &Horde_Data::singleton('icalendar');
}
$DTSTAMP = date("Ymd\TGis");
$UTCTIME = date("Ymd\TGis", (time() + date('Z')));
$vcal['DTSTAMP'] = $DTSTAMP;
$vcal['UID'] = $this->getGUID();
$vcal['SUMMARY'] = $this->title;
$vcal['DESCRIPTION'] = $this->description;
$vcal['DTSTART'] = $vcs->makeDate($this->start);
$vcal['DTEND'] = $vcs->makeDate($this->end);
$vcal['LOCATION'] = $this->location;
$vcal['TRANSP'] = 'OPAQUE';
$ORGANIZER = 'ORGANIZER;' . 'CN=' . $identity->getValue('fullname');
$vcal[$ORGANIZER] = 'MAILTO:' . $identity->getValue('from_addr');
return $vcal;
}
/**
* Import the values for this event from an array of values,
*
* @param array $hash Array containing all the values.
*/
function fromHash($hash)
{
if (!empty($hash['title'])) {
$this->setTitle($hash['title']);
}
if (!empty($hash['description'])) {
$this->setDescription($hash['description']);
}
if (!empty($hash['category'])) {
$this->setCategory($hash['category']);
}
if (!empty($hash['location'])) {
$this->setLocation($hash['location']);
}
if (!empty($hash['keywords'])) {
$this->setKeywords(explode(',', $hash['keywords']));
}
if (!empty($hash['start_date']) && !empty($hash['start_time'])) {
$date = explode('-', $hash['start_date']);
$time = explode(':', $hash['start_time']);
if (count($time) == 2) {
$time[2] = 0;
}
if (count($time) == 3 && count($date) == 3) {
$this->setStartTimestamp(mktime($time[0], $time[1], $time[2], $date[1], $date[2], $date[0]));
}
}
if (!empty($hash['end_date']) && !empty($hash['end_time'])) {
$date = explode('-', $hash['end_date']);
$time = explode(':', $hash['end_time']);
if (count($time) == 2) {
$time[2] = 0;
}
if (count($time) == 3 && count($date) == 3) {
$this->setEndTimestamp(mktime($time[0], $time[1], $time[2], $date[1], $date[2], $date[0]));
}
}
if (!empty($hash['alarm'])) {
$this->setAlarm($hash['alarm']);
} elseif (!empty($hash['alarm_date']) &&
!empty($hash['alarm_time'])) {
$date = explode('-', $hash['alarm_date']);
$time = explode(':', $hash['alarm_time']);
if (count($time) == 2) {
$time[2] = 0;
}
if (count($time) == 3 && count($date) == 3) {
$this->setAlarm(($this->getStartTimestamp() - mktime($time[0], $time[1], $time[2], $date[1], $date[2], $date[0])) / 60);
}
}
if (!empty($hash['recur_type'])) {
$this->setRecurType($hash['recur_type']);
if (!empty($hash['recur_end_date'])) {
$date = explode('-', $hash['recur_end_date']);
$this->setRecurEndTimestamp(mktime(0, 0, 0, $date[1], $date[2], $date[0]));
}
if (!empty($hash['recur_interval'])) {
$this->setRecurInterval($hash['recur_interval']);
}
if (!empty($hash['recur_data'])) {
$this->setRecurOnDay($hash['recur_data']);
}
}
}
/**
* Save changes to this event
*
* @return mixed True or a PEAR_Error on failure.
*/
function save()
{
if (!$this->initialized) {
return false;
}
$this->toDriver();
$driver = &$this->getDriver();
return $driver->saveEvent($this);
}
/**
* Add an exception to a recuring event.
*
* @param integer $year The year of the execption.
* @param integer $month The month of the execption.
* @param integer $mday The day of the month of the execption.
*/
function addException($year, $month, $mday)
{
$this->exceptions[] = sprintf("%04d%02d%02d", $year, $month, $mday);
}
/**
* Check if an exception exists for a given recurance of an event
*
* @param integer $year The year of the reucrance.
* @param integer $month The month of the reucrance.
* @param integer $mday The day of the month of the reucrance.
*
* @return boolean True if an exception exists for the given date.
*/
function hasException($year, $month, $mday)
{
return in_array(sprintf("%04d%02d%02d", $year, $month, $mday), $this->getExceptions());
}
/**
* Retrieve all the exceptions for this event
*
* @return array Array containing the dates of all the exceptions in
* YYYYMMDD form.
*/
function getExceptions()
{
return $this->exceptions;
}
/**
* TODO
*/
function isInitialized()
{
return $this->initialized;
}
/**
* Check if this event recurs on a given day of the week.
*
* @param integer $dayMask A mask specifying the day(s) to check.
*
* @return boolean True if this event recurs on the given day(s).
*/
function recurOnDay($dayMask)
{
return ($this->recurData & $dayMask);
}
/**
* Specify the days this event recurs on
*
* @param integer $dayMask A mask specifying the day(s) to recur on.
*/
function setRecurOnDay($dayMask)
{
$this->recurData = $dayMask;
}
/**
* Return the days this event recurs on.
*
* @return intenger A mask specifying the day(s) this event recurs on.
*/
function getRecurOnDays()
{
return $this->recurData;
}
function getRecurType()
{
return $this->recurType;
}
function hasRecurType($recurrence)
{
return ($recurrence === $this->recurType);
}
function setRecurType($recurrence)
{
$this->recurType = $recurrence;
}
/**
* Set the length of time between recurrances of this event.
*
* @param integer $interval The number of seconds between recurances.
*/
function setRecurInterval($interval)
{
$this->recurInterval = $interval;
}
/**
* Retrieve the length of time between recurrances fo this event.
*
* @return integer The number of seconds between recurances.
*/
function getRecurInterval()
{
return $this->recurInterval;
}
/**
* Retrieve the locally unique identifier for this event.
*
* @return integer The local identifier for this event.
*/
function getID()
{
return $this->eventID;
}
/**
* Set the locally unique identifier for this event.
*
* @param integer $eventID The local identifier for this event.
*/
function setID($eventID)
{
$this->eventID = $eventID;
}
/**
* Retrieve the globally unique identifier for this event.
*
* @return integer The globally identifier for this event.
*/
function getGUID()
{
return sprintf('%s-%s@%s', $this->getCalendar(), $this->getID(), $_SERVER["SERVER_NAME"]);
}
/**
* Retrieve the title of this event.
*
* @return string The title of this event.
*/
function getTitle()
{
if (isset($this->taskID)) {
return !empty($this->title) ? $this->title : _("[none]");
}
if (!$this->isInitialized()) {
return '';
}
return !empty($this->title) ? $this->title : _("[none]");
}
/**
* Set the title of this event.
*
* @param string The new title for this event.
*/
function setTitle($title)
{
$this->title = $title;
}
/**
* Retieve the description of this event.
*
* @return string The description of this event.
*/
function getDescription()
{
return $this->description;
}
/**
* Set the description of this event.
*
* @param string $description The new description for this event.
*/
function setDescription($description)
{
$this->description = $description;
}
/**
* Set the category this event belongs to.
*
* @param integer $category The identifier of the category this
* event belongs to.
*/
function setCategory($category)
{
$this->category = $category;
}
/**
* Reteieve the category this event belongs to.
*
* @return integer The identifier of the category this event belongs to.
*/
function getCategory()
{
return $this->category;
}
/**
* Set the location this event occurs at.
*
* @param string $location The new location for this event.
*/
function setLocation($location)
{
$this->location = $location;
}
/**
* Retrieve the location this event occurs at.
*
* @return string The lcoation of this event.
*/
function getLocation()
{
return $this->location;
}
/**
* Retrieve the time this event starts.
*
* @param integer $dayTimestamp (optional) The timestamp of a day a
* recurrance occurs. First recurrance
* used if not specified.
*
* @return integer The timestamp for the start of this event.
*/
function getStartTimestamp($dayTimestamp = null)
{
if (!isset($dayTimestamp)) {
return $this->startTimestamp;
}
list($year, $month, $day) = explode(':', date('Y:n:j', $dayTimestamp));
list($hour, $min, $sec) = explode(':', date('G:i:s', $this->startTimestamp));
return mktime($hour, $min, $sec, $month, $day, $year);
}
/**
* Set the time this event starts.
*
* @param integer $startTimestamp The timestamp for the start
* of this event.
*/
function setStartTimestamp($startTimestamp)
{
$this->startTimestamp = $startTimestamp;
$this->start = new stdClass();
list($this->start->mday, $this->start->month, $this->start->year,
$this->start->hour, $this->start->min, $this->start->sec) =
explode(':', date('d:m:Y:H:i:s', $startTimestamp));
}
function setKeywords($keywords)
{
$this->keywords = $keywords;
}
function getKeywords()
{
return $this->keywords;
}
function hasKeyword($keyword)
{
return in_array($keyword, $this->keywords);
}
function getStartDate($formatString, $dayTimestamp = null)
{
return date($formatString, $this->getStartTimestamp($dayTimestamp));
}
function getStartDatestamp()
{
return mktime(0, 0, 0,
$this->getStartDate('n'),
$this->getStartDate('j'),
$this->getStartDate('Y'));
}
function setEndTimestamp($endTimestamp)
{
$this->endTimestamp = $endTimestamp;
$this->end = new stdClass();
list($this->end->mday, $this->end->month, $this->end->year,
$this->end->hour, $this->end->min, $this->end->sec) =
explode(':', date('d:m:Y:H:i:s', $endTimestamp));
}
function getEndTimestamp($dayTimestamp = null)
{
if (!isset($dayTimestamp)) {
return $this->endTimestamp;
}
list($year, $month, $day) = explode(':', date('Y:n:j', $dayTimestamp));
list($hour, $min, $sec) = explode(':', date('G:i:s', $this->endTimestamp));
return mktime($hour, $min, $sec, $month, $day, $year);
}
function getEndDate($formatString, $dayTimestamp = null)
{
return date($formatString, $this->getEndTimestamp($dayTimestamp));
}
function setRecurEndTimestamp($recurTimestamp)
{
$this->recurEndTimestamp = $recurTimestamp;
}
function getRecurEndTimestamp()
{
return $this->recurEndTimestamp;
}
function hasRecurEnd()
{
return (isset($this->recurEnd) && isset($this->recurEnd->year) && $this->recurEnd->year != 9999);
}
function getRecurEndDate($formatString)
{
return date($formatString, $this->recurEndTimestamp);
}
function isAllDay()
{
return ($this->start->hour == 0 && $this->start->min == 0 && $this->start->sec == 0 &&
$this->end->hour == 0 && $this->end->min == 0 && $this->start->sec == 0 &&
($this->end->mday > $this->start->mday ||
$this->end->month > $this->start->month ||
$this->end->year > $this->start->year));
}
function setAlarm($alarm)
{
$this->alarm = $alarm;
}
function getAlarm()
{
return $this->alarm;
}
function readForm()
{
global $prefs;
// Basic fields.
$this->setTitle(Horde::getFormData('title', $this->title));
$this->setDescription(Horde::getFormData('description', $this->description));
$this->setLocation(Horde::getFormData('location', $this->location));
$this->setKeywords(Horde::getFormData('keywords', $this->keywords));
// Category.
if (Horde::getFormData('category') == '*new*') {
$category = Kronolith::addCategory(Horde::getFormData('new_category', $this->category));
} else {
$category = Horde::getFormData('category', $this->category);
}
$this->setCategory($category);
// Event start.
$start_year = Horde::getFormData('start_year');
$start_month = Horde::getFormData('start_month');
$start_day = Horde::getFormData('start_day');
$start_hour = Horde::getFormData('start_hour');
$start_min = Horde::getFormData('start_min');
$am_pm = Horde::getFormData('am_pm');
if (!$prefs->getValue('twentyFour')) {
if ($am_pm == 'PM') {
if ($start_hour != 12) {
$start_hour += 12;
}
} elseif ($start_hour == 12) {
$start_hour = 0;
}
}
if (Horde::getFormData('end_or_dur') == 1) {
if (Horde::getFormData('whole_day') == 1) {
$start_hour = 0;
$start_min = 0;
$dur_day = 0;
$dur_hour = 24;
$dur_min = 0;
} else {
$dur_day = Horde::getFormData('dur_day');
$dur_hour = Horde::getFormData('dur_hour');
$dur_min = Horde::getFormData('dur_min');
}
}
$this->setStartTimestamp(mktime($start_hour, $start_min, 0,
$start_month, $start_day,
$start_year));
if (Horde::getFormData('end_or_dur') == 1) {
// Event duration.
$this->setEndTimestamp(mktime($start_hour + $dur_hour,
$start_min + $dur_min,
0,
$start_month,
$start_day + $dur_day,
$start_year));
} else {
// Event end.
$end_year = Horde::getFormData('end_year');
$end_month = Horde::getFormData('end_month');
$end_day = Horde::getFormData('end_day');
$end_hour = Horde::getFormData('end_hour');
$end_min = Horde::getFormData('end_min');
$end_am_pm = Horde::getFormData('end_am_pm');
if (!$prefs->getValue('twentyFour')) {
if ($end_am_pm == 'PM') {
if ($end_hour != 12) {
$end_hour += 12;
}
} elseif ($end_hour == 12) {
$end_hour = 0;
}
}
$endstamp = mktime($end_hour, $end_min, 0,
$end_month, $end_day, $end_year);
if ($endstamp < $this->getStartTimestamp()) {
$endstamp = $this->getStartTimestamp();
}
$this->setEndTimestamp($endstamp);
}
// Alarm.
if (Horde::getFormData('alarm') == 1) {
$this->setAlarm(Horde::getFormData('alarm_value') * Horde::getFormData('alarm_unit'));
} else {
$this->setAlarm(0);
}
// Recurrence.
$recur = Horde::getFormData('recur');
if (!is_null($recur) && $recur !== '') {
if (Horde::getFormData('recur_enddate_type') == 'none') {
$recur_enddate_year = 9999;
$recur_enddate_month = 12;
$recur_enddate_day = 31;
} else {
$recur_enddate_year = Horde::getFormData('recur_enddate_year');
$recur_enddate_month = Horde::getFormData('recur_enddate_month');
$recur_enddate_day = Horde::getFormData('recur_enddate_day');
}
$this->setRecurEndTimestamp(@mktime(1, 1, 1,
$recur_enddate_month,
$recur_enddate_day,
$recur_enddate_year));
$this->setRecurType($recur);
switch ($recur) {
case KRONOLITH_RECUR_DAILY:
$this->setRecurInterval(Horde::getFormData('recur_daily_interval', 1));
break;
case KRONOLITH_RECUR_WEEKLY:
$weekly = Horde::getFormData('weekly');
$weekdays = 0;
if (is_array($weekly)) {
foreach ($weekly as $day) {
$weekdays |= $day;
}
}
if ($weekdays == 0) {
// date('w') starts Sunday at 0.
switch ($this->getStartDate('w')) {
case 0: $weekdays |= KRONOLITH_MASK_SUNDAY; break;
case 1: $weekdays |= KRONOLITH_MASK_MONDAY; break;
case 2: $weekdays |= KRONOLITH_MASK_TUESDAY; break;
case 3: $weekdays |= KRONOLITH_MASK_WEDNESDAY; break;
case 4: $weekdays |= KRONOLITH_MASK_THURSDAY; break;
case 5: $weekdays |= KRONOLITH_MASK_FRIDAY; break;
case 6: $weekdays |= KRONOLITH_MASK_SATURDAY; break;
}
}
$this->setRecurInterval(Horde::getFormData('recur_weekly_interval', 1));
$this->setRecurOnDay($weekdays);
break;
case KRONOLITH_RECUR_DAY_OF_MONTH:
$this->setRecurInterval(Horde::getFormData('recur_day_of_month_interval', 1));
break;
case KRONOLITH_RECUR_WEEK_OF_MONTH:
$this->setRecurInterval(Horde::getFormData('recur_week_of_month_interval', 1));
break;
case KRONOLITH_RECUR_YEARLY:
$this->setRecurInterval(Horde::getFormData('recur_yearly_interval', 1));
break;
}
}
$this->initialized = true;
}
function getDuration()
{
static $duration;
if (isset($duration)) {
return $duration;
}
if ($this->isInitialized()) {
$dur_day_match = $this->getEndDate('j') - $this->getStartDate('j');
$dur_hour_match = $this->getEndDate('G') - $this->getStartDate('G');
$dur_min_match = $this->getEndDate('i') - $this->getStartDate('i');
while ($dur_min_match < 0) {
$dur_min_match += 60;
$dur_hour_match--;
}
while ($dur_hour_match < 0) {
$dur_hour_match += 24;
$dur_day_match--;
}
if ($dur_hour_match == 0 && $dur_min_match == 0
&& ($this->getEndDate('d') - $this->getStartDate('d')) == 1) {
$dur_day_match = 0;
$dur_hour_match = 23;
$dur_min_match = 60;
$whole_day_match = true;
} else {
$whole_day_match = false;
}
} else {
$dur_day_match = 0;
$dur_hour_match = 1;
$dur_min_match = 0;
$whole_day_match = false;
}
$duration = new stdClass();
$duration->day = $dur_day_match;
$duration->hour = $dur_hour_match;
$duration->min = $dur_min_match;
$duration->wholeDay = $whole_day_match;
return $duration;
}
function html($property)
{
global $prefs, $conf;
$options = array();
$attributes = '';
$sel = false;
switch ($property) {
case 'category':
$cats = Kronolith::listCategories();
foreach ($cats as $cat) {
$options[$cat] = $cat;
}
$sel = $this->getCategory();
break;
case 'start_year':
$sel = $this->getStartDate('Y');
for ($i = -1; $i < 6; $i++) {
$yr = date('Y') + $i;
$options[$yr] = $yr;
}
$attributes = ' onchange="updateWday(\'start_wday\'); document.event.whole_day.checked = false; updateEndDate();"';
break;
case 'start_month':
$sel = $this->getStartDate('n');
for ($i = 1; $i < 13; $i++) {
$options[$i] = strftime('%b', mktime(1, 1, 1, $i, 1));
}
$attributes = ' onchange="updateWday(\'start_wday\'); document.event.whole_day.checked = false; updateEndDate();"';
break;
case 'start_day':
$sel = $this->getStartDate('j');
for ($i = 1; $i < 32; $i++) {
$options[$i] = $i;
}
$attributes = ' onchange="updateWday(\'start_wday\');document.event.whole_day.checked=false;updateEndDate();"';
break;
case 'start_hour':
$sel = $this->getStartDate(($prefs->getValue('twentyFour')) ? 'G' : 'g');
$hour_min = ($prefs->getValue('twentyFour')) ? 0 : 1;
$hour_max = ($prefs->getValue('twentyFour')) ? 24 : 13;
for ($i = $hour_min; $i < $hour_max; $i++) {
$options[$i] = $i;
}
$attributes = ' onchange="document.event.whole_day.checked = false; updateEndDate();"';
break;
case 'start_min':
$sel = $this->getStartDate('i');
for ($i = 0; $i < 12; $i++) {
$min = sprintf('%02d', $i * 5);
$options[$min] = $min;
}
$attributes = ' onchange="document.event.whole_day.checked = false; updateEndDate();"';
break;
case 'end_year':
$sel = $this->isInitialized() ? $this->getEndDate('Y') : $this->getStartDate('Y');
for ($i = -1; $i < 6; $i++) {
$yr = date('Y') + $i;
$options[$yr] = $yr;
}
$attributes = ' onchange="updateWday(\'end_wday\'); updateDuration(); document.event.end_or_dur[0].checked = true"';
break;
case 'end_month':
$sel = $this->isInitialized() ? $this->getEndDate('n') : $this->getStartDate('n');
for ($i = 1; $i < 13; $i++) {
$options[$i] = strftime('%b', mktime(1, 1, 1, $i, 1));
}
$attributes = ' onchange="updateWday(\'end_wday\'); updateDuration(); document.event.end_or_dur[0].checked = true"';
break;
case 'end_day':
$sel = $this->isInitialized() ? $this->getEndDate('j') : $this->getStartDate('j');
for ($i = 1; $i < 32; $i++) {
$options[$i] = $i;
}
$attributes = ' onchange="updateWday(\'end_wday\'); updateDuration(); document.event.end_or_dur[0].checked = true"';
break;
case 'end_hour':
$sel = $this->isInitialized() ?
$this->getEndDate(($prefs->getValue('twentyFour')) ? 'G' : 'g') :
$this->getStartDate(($prefs->getValue('twentyFour')) ? 'G' : 'g') + 1;
$hour_min = $prefs->getValue('twentyFour') ? 0 : 1;
$hour_max = $prefs->getValue('twentyFour') ? 24 : 13;
for ($i = $hour_min; $i < $hour_max; $i++) {
$options[$i] = $i;
}
$attributes = ' onchange="updateDuration(); document.event.end_or_dur[0].checked = true"';
break;
case 'end_min':
$sel = $this->isInitialized() ? $this->getEndDate('i') : $this->getStartDate('i');
for ($i = 0; $i < 12; $i++) {
$min = sprintf('%02d', $i * 5);
$options[$min] = $min;
}
$attributes = ' onchange="updateDuration(); document.event.end_or_dur[0].checked = true"';
break;
case 'dur_day':
$dur = $this->getDuration();
$sel = $dur->day;
for ($i = 0; $i < 366; $i++) {
$options[$i] = $i;
}
$attributes = ' onchange="document.event.whole_day.checked = false; updateEndDate(); document.event.end_or_dur[1].checked = true;"';
break;
case 'dur_hour':
$dur = $this->getDuration();
$sel = $dur->hour;
for ($i = 0; $i < 24; $i++) {
$options[$i] = $i;
}
$attributes = ' onchange="document.event.whole_day.checked = false; updateEndDate(); document.event.end_or_dur[1].checked = true;"';
break;
case 'dur_min':
$dur = $this->getDuration();
$sel = $dur->min;
for ($i = 0; $i < 13; $i++) {
$min = sprintf('%02d', $i * 5);
$options[$min] = $min;
}
$attributes = ' onchange="document.event.whole_day.checked = false;updateEndDate();document.event.end_or_dur[1].checked=true"';
break;
case 'recur_enddate_year':
if ($this->isInitialized()) {
$sel = $this->hasRecurEnd() ? $this->recurEnd->year : $this->end->year;
} else {
$sel = $this->getStartDate('Y');
}
for ($i = -1; $i < 6; $i++) {
$yr = date('Y') + $i;
$options[$yr] = $yr;
}
$attributes = ' onchange="updateWday(\'recur_end_wday\'); document.event.recur_enddate_type[1].checked = true;"';
break;
case 'recur_enddate_month':
if ($this->isInitialized()) {
$sel = $this->hasRecurEnd() ? $this->recurEnd->month : $this->end->month;
} else {
$sel = $this->getStartDate('m');
}
for ($i = 1; $i < 13; $i++) {
$options[$i] = strftime('%b', mktime(1, 1, 1, $i, 1));
}
$attributes = ' onchange="updateWday(\'recur_end_wday\'); document.event.recur_enddate_type[1].checked = true;"';
break;
case 'recur_enddate_day':
if ($this->isInitialized()) {
$sel = $this->hasRecurEnd() ? $this->recurEnd->mday : $this->end->mday;
} else {
$sel = $this->getStartDate('d');
}
for ($i = 1; $i < 32; $i++) {
$options[$i] = $i;
}
$attributes = ' onchange="updateWday(\'recur_end_wday\'); document.event.recur_enddate_type[1].checked = true;"';
break;
}
$html = '<select name="' . $property . '"' . $attributes . ' id="' . $property . '">';
$selset = false;
foreach ($options as $value => $display) {
if (!$selset && $value == $sel) {
$selected = ' selected="selected"';
$selset = true;
} else {
$selected = '';
}
$html .= "<option value=\"$value\"$selected>" . htmlspecialchars($display) . "</option>\n";
}
$html .= '</select>';
return $html;
}
function getLink($timestamp = 0, $icons = true)
{
global $print_view, $prefs;
$link = '';
if (isset($this->eventID)) {
$url = Kronolith::addParameter('viewevent.php', 'eventID=' . $this->eventID);
$url = Kronolith::addParameter($url, 'calendar=' . $this->getCalendar());
$url = Kronolith::addParameter($url, 'timestamp=' . $timestamp);
$link .= Horde::link(Horde::applicationUrl($url), $this->title, '', '', '', $this->description);
} elseif (isset($this->taskID)) {
$link .= Horde::link(Horde::url($GLOBALS['registry']->link('tasks/show', array('task' => $this->taskID))), $this->title);
}
$link .= @htmlspecialchars($this->getTitle());
$link .= '</a>';
if ($icons && $prefs->getValue('show_icons')) {
if ($this->alarm) {
$link .= Horde::img('alarm_small.gif', 'alt="' . sprintf(_("%s Minutes before"), $this->alarm) . '"');
}
if (!$print_view) {
if (isset($this->eventID)) {
$url = Kronolith::addParameter('delevent.php', 'eventID=' . $this->eventID);
$url = Kronolith::addParameter($url, 'calendar=' . $this->getCalendar());
$url = Kronolith::addParameter($url, 'timestamp=' . $timestamp);
$url = Kronolith::addParameter($url, 'url', Horde::selfURL(true));
$link .= ' ' . Horde::link(Horde::applicationUrl($url), sprintf(_("Delete %s"), $this->title)) . Horde::img('delete.gif', 'alt="' . sprintf(_("Delete %s"), @htmlspecialchars($this->getTitle())) . '"') . '</a>';
}
}
if (!$this->hasRecurType(KRONOLITH_RECUR_NONE)) {
$link .= Horde::img('recur.gif', 'alt="' . Kronolith::recurToString($this->recurType) . '"');
}
}
return $link;
}
function nextRecurrence($afterDate, $weekstart = KRONOLITH_SUNDAY)
{
$driver = &$this->getDriver();
return $driver->nextRecurrence($this->eventID, $afterDate, $weekstart);
}
function getCalendar()
{
return $this->_calendar;
}
}
|