- q("INSERT INTO %s%sjqcalendar (`uid`, `namespace`, `namespace_id`, `ical_uri`, `Subject`, `Location`, `Description`, `StartTime`, `EndTime`, `IsAllDayEvent`, `RecurringRule`, `Color`)
- VALUES (%d, %d, %d, '%s', '%s', '%s', '%s', %s, %s, %d, '%s', '%s')",
- CALDAV_SQL_DB, CALDAV_SQL_PREFIX,
- IntVal($calendar->uid), IntVal($calendarobject->namespace), IntVal($calendarobject->namespace_id), dbesc($calendarobject->uri), dbesc($summary),
- dbesc($location), dbesc(str_replace("\\n", "\n", $description)), $start_min, $end_max, IntVal($allday), dbesc($rrule), dbesc($color)
- );
-
- foreach ($vevent->components as $comp) {
- /** @var $comp calendarComponent */
- $trigger = $comp->getProperty("TRIGGER");
- $sql_field = ($trigger["relatedStart"] ? $start : $end);
- $sql_op = ($trigger["before"] ? "DATE_SUB" : "DATE_ADD");
- $num = "";
- $rel_type = "";
- $rel_value = 0;
- if (isset($trigger["second"])) {
- $num = IntVal($trigger["second"]) . " SECOND";
- $rel_type = "second";
- $rel_value = IntVal($trigger["second"]);
- }
- if (isset($trigger["minute"])) {
- $num = IntVal($trigger["minute"]) . " MINUTE";
- $rel_type = "minute";
- $rel_value = IntVal($trigger["minute"]);
- }
- if (isset($trigger["hour"])) {
- $num = IntVal($trigger["hour"]) . " HOUR";
- $rel_type = "hour";
- $rel_value = IntVal($trigger["hour"]);
- }
- if (isset($trigger["day"])) {
- $num = IntVal($trigger["day"]) . " DAY";
- $rel_type = "day";
- $rel_value = IntVal($trigger["day"]);
- }
- if (isset($trigger["week"])) {
- $num = IntVal($trigger["week"]) . " WEEK";
- $rel_type = "week";
- $rel_value = IntVal($trigger["week"]);
- }
- if (isset($trigger["month"])) {
- $num = IntVal($trigger["month"]) . " MONTH";
- $rel_type = "month";
- $rel_value = IntVal($trigger["month"]);
- }
- if (isset($trigger["year"])) {
- $num = IntVal($trigger["year"]) . " YEAR";
- $rel_type = "year";
- $rel_value = IntVal($trigger["year"]);
- }
- if ($trigger["before"]) $rel_value *= -1;
-
- if ($rel_type != "") {
- $not_date = "$sql_op($sql_field, INTERVAL $num)";
- q("INSERT INTO %s%snotifications (`uid`, `ical_uri`, `rel_type`, `rel_value`, `alert_date`, `notified`) VALUES ('%s', '%s', '%s', '%s', %s, IF(%s < NOW(), 1, 0))",
- CALDAV_SQL_DB, CALDAV_SQL_PREFIX,
- IntVal($calendar->uid), dbesc($calendarobject->uri), dbesc($rel_type), IntVal($rel_value), $not_date, $not_date);
- }
- }
- }