예제 #1
0
include_once "connect.php";
// --------------------------- RETRIEVE USER ID ---------------------------
// refer $conn to the global conn
global $conn;
// get email from cookie
$email = $_COOKIE['username'];
// get userID using email
$result = $conn->query("SELECT userID FROM users WHERE email ='{$email}'");
$userID = $result->fetch_assoc()['userID'];
// ------------------------------------------------------------------------
// get the event title
$title = $_POST['eventName'];
// get the start and end date/times and format them for MySQL
$formatted_start = getMySQLFormat(new DateTime($_POST['startDateTime']), -1);
$formatted_end = getMySQLFormat(new DateTime($_POST['endDateTime']), 1);
// insert the event into the database
$conn->query("INSERT INTO events (userID, eventName, startTime, endTime, locationID, repeating) values ({$userID}, '{$title}', '{$formatted_start}', '{$formatted_end}', 1, 0)");
// return to calendar page when done
header("Location:calendar.php");
/* 
   getMySQLFormat : converts DateTime object into DATETIME formatted string for MySQL

   @param DateTime $dateTime : the DateTime object to convert
   @param int      $round    : indicates if the date/time should be rounded
								-1 to round down to nearest hour
								0 to leave it as is (default)
                                1 to round up to the nearest hour
								NOTE: time is left as is if it is already at the hour (minutes is 0)
   @return string $formatstr : the formatted string for MySQL
*/
예제 #2
0
$max_time->add(date_interval_create_from_date_string("5 hours"));
// set the appropriate optional parameters
// timeMin is today
$optionalParameters = array('timeMin' => $min_time->format(DateTime::RFC3339), 'timeMax' => $max_time->format(DateTime::RFC3339), 'singleEvents' => TRUE);
// get the results
$results = $service->events->listEvents($calendarID, $optionalParameters);
// go through each one
foreach ($results->getItems() as $event) {
    // get the title
    $title = $event->summary;
    // get the start and end date/times
    $start = new DateTime($event->start->dateTime);
    $end = new DateTime($event->end->dateTime);
    // round the times and format them correctly
    $formatted_start = getMySQLFormat($start, -1);
    $formatted_end = getMySQLFormat($end, 1);
    // insert the event into the database
    $conn->query("INSERT INTO events (userID, eventName, startTime, endTime, locationID, repeating) values ({$userID}, '{$title}', '{$formatted_start}', '{$formatted_end}', 1, 1);");
}
/* 
   getMySQLFormat : converts DateTime object into DATETIME formatted string for MySQL

   @param DateTime $dateTime : the DateTime object to convert
   @param int      $round    : indicates if the date/time should be rounded
								-1 to round down to nearest hour
								0 to leave it as is (default)
                                1 to round up to the nearest hour
								NOTE: time is left as is if it is already at the hour (minutes is 0)
   @return string $formatstr : the formatted string for MySQL
*/
function getMySQLFormat($dateTime, $round = 0)