PDA

View Full Version : Calendar Event INSERT


reefland
05-11-2010, 11:49 AM
I am working on a bit of a modification/addition for my site and I am in need of some help. I am building a script that will be cronned and will insert events into the calendar every day. I have the script built and the insert query working however for some reason the even does not show in the calendar. I can access the event via the url for the eventid and it works fine, and I can edit the event and it will then show in the calendar. So I am missing something that needs to happen in addition to the INSERT into the event table.

To complicate matters, I can't find where the existing functions are for the event creation in the files. I am looked through calendar.php, class_dm_event and functions_calendar and can't find a single insert there anywhere.


$vbulletin->db->query_write("
INSERT INTO " . TABLE_PREFIX ."event (eventid, userid, event, title, allowsmilies, recurring, recuroption, calendarid, customfields, visible, dateline, utc, dst, dateline_from, dateline_to)
VALUES ('', '1', 'Open', '" . $day1post1title . "', '1', '0', '', '5', NULL, '1', '" . $day1 . "', '0.00', '0', '" . $day1 . "', '0')
");

Again, this inserts the event into the database just fine, but the event will not show on the calendar until it is edited via the UI. Thoughts?

--------------- Added 1273603886 at 1273603886 ---------------

Entering a row directly to the database does the same thing. So it must be some cache function I am missing or something.

reefland
05-12-2010, 09:46 PM
If anyone is interested in helping out, here is the code I am using. This is to be cronned as a scheduled task.


<?php

// ######################## SET PHP ENVIRONMENT ###########################
//error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################

require_once(DIR . '/includes/functions_newpost.php');
require_once(DIR . '/includes/functions_wysiwyg.php');
require_once(DIR . '/includes/functions_calendar.php');

$now = time();
$month = date('m', $now);
$day = date('d', $now);
$year = date('Y', $now);
$date = mktime(0, 0, 0, $month, $day, $year);
$day1 = $date + 604800;
$day2 = $day1 + 86400;
$day3 = $day2 + 86400;
$day4 = $day3 + 86400;
$day5 = $day4 + 86400;
$day6 = $day5 + 86400;
$day7 = $day6 + 86400;
$calendarinfo[calendarid] = 5;
echo "<html><head><title>test</title></head><body>Today is: $date and One Week from Today is: $day1 Calendarid is $calendarinfo[calendarid]</body></html>";

$day1post1title = "7am - OPEN";
$day1post2title = "10am - OPEN";
$day1post3title = "1pm - OPEN";
$day1post4title = "4pm - OPEN";
$day1post5title = "7pm - OPEN";
$day1post6title = "10pm - OPEN";

$vbulletin->db->query_write("
INSERT INTO " . TABLE_PREFIX ."event (eventid, userid, event, title, allowsmilies, recurring, recuroption, calendarid, customfields, visible, dateline, utc, dst, dateline_from, dateline_to)
VALUES ('', '1', 'Open', '" . $day1post1title . "', '1', '0', '', '5', NULL, '1', '" . $day1 . "', '0.00', '0', '" . $day1 . "', '0')
");

global $vbulletin, $vbphrase, $_CALENDAROPTIONS;

if (!$vbulletin->options['showevents'])
{
return false;
}

$storeevents = array();

// Store timestamp 48 hours before the current time and 48 hours after the showevent period
$beginday = TIMENOW - 172800;
$endday = TIMENOW + 86400 + 86400 * $vbulletin->options['showevents'];
$storeevents['date'] = gmdate('n-j-Y' , $endday);


$events = $vbulletin->db->query_read_slave("
SELECT eventid, userid, event.title, recurring, recuroption, dateline_from, dateline_to, event.calendarid, IF (dateline_to = 0, 1, 0) AS singleday, customfields,
dateline_from AS dateline_from_user, dateline_to AS dateline_to_user, utc, dst
FROM " . TABLE_PREFIX . "event AS event
INNER JOIN " . TABLE_PREFIX . "calendar AS calendar USING (calendarid)
WHERE ((dateline_to >= $beginday AND dateline_from < $endday) OR (dateline_to = 0 AND dateline_from >= $beginday AND dateline_from <= $endday ))
AND visible = 1
AND calendar.options & " . intval($_CALENDAROPTIONS['showupcoming']) . "
ORDER BY dateline_from
");

while ($event = $vbulletin->db->fetch_array($events))
{
$event['title'] = htmlspecialchars_uni($event['title']);
$storeevents["$event[eventid]"] = $event;
}

build_datastore('eventcache', serialize($storeevents), 1);

return $storeevents;

?>


This successfully inserts the event, which can then be access via calendar.php?e=xxxx&c=5 but the event is not viewable on the calendar.

reefland
05-16-2010, 03:56 PM
Still looking for help with this...

reefland
05-20-2010, 12:00 AM
^^ Still looking.

reefland
05-26-2010, 10:59 PM
Most of the times, it's the stupid things. The date from has to be midnight gmt.

Wood 20th*
12-12-2010, 02:13 AM
So Reefland

how's the progress on this? Is it showing up now?