<?php

function date_create_from_format($format, $schedule, $t) {

$schedule = '31/03/2011 01:22 pm';
// %Y, %m and %d correspond to date()'s Y m and d.
// %I corresponds to H, %M to i and %p to a
$ugly = strptime($schedule, '%d/%m/%Y %I:%M %p');
$ymd = sprintf(
    // This is a format string that takes six total decimal
    // arguments, then left-pads them with zeros to either
    // 4 or 2 characters, as needed
    '%04d-%02d-%02d %02d:%02d:%02d',
    $ugly['tm_year'] + 1900,  // This will be "111", so we need to add 1900.
    $ugly['tm_mon'] + 1,      // This will be the month minus one, so we add one.
    $ugly['tm_mday'], 
    $ugly['tm_hour'], 
    $ugly['tm_min'], 
    $ugly['tm_sec']
);
echo $ymd;
$new_schedule = new DateTime($ymd);
return $new_schedule->format('Y-m-d\TH:i:sP');

}

	function checkboxValue($value)
	{
		if (!empty($value) && $value == 'on')
			return '1';
		else
			return '0';
	}

	function showAPITokenForm() {
		echo '<form action="index.php" type="GET">';
		echo '<label>Please provide an API token: </label>';
		echo '<input type="text" name="api_token" />';
		echo '<input type="submit" name="Submit" value="Submit" />';
		echo '</form>';
	}

	function getAPIToken() {
		if (session_id() == "")
			session_start();

		$api_token_session_name = 'playwire_api_token';
		$api_token = '';
		if (isset($_SESSION[$api_token_session_name]) && !empty($_SESSION[$api_token_session_name])) {
			if ($_GET['clear_token'] == 1)
				unset($_SESSION[$api_token_session_name]);
			else
				$api_token = $_SESSION[$api_token_session_name];
		} else if (isset($_GET['api_token']) && !empty($_GET['api_token'])) {
			$api_token = $_GET['api_token'];
			$_SESSION[$api_token_session_name] = $api_token;
		}

		return $api_token;
	}

	$api_token = getAPIToken();
?>
