我试图制作一些东西,但它没有用。
我有一个有变化的数据库
(Shift, Location, Start Time, End Time,...).
我已经创建了一个页面来搜索这些班次并显示它们。
这会给出一个包含班次的表格和3个指向edit, delete, or book them
的链接。
预订它们应该将它们添加到我的Google日历中。 Book链接将ID发送到Add_Event.php Google总是试图让我一次又一次地登录而不发送任何内容。我绝望了。它昨天工作。现在它停止了工作。
的search.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Zoeken</title>
</head>
<body>
<form action="" method="post">
<div>
<strong>Dienst: </strong> <input type="text" name="Dienst" value="<?php echo $Dienst; ?>" /><br/>
<input type="submit" name="zoeken" value="Zoeken">
</div>
</form>
<?php
if (isset($_POST['zoeken']))
{
include('connect-db.php');
$id = $_POST['id'];
$Locatie = $_POST['Locatie'];
$Periode = $_POST['Periode'];
$Dag = $_POST['Dag'];
$Dienst = $_POST['Dienst'];
// get results from database
$result = mysql_query("SELECT * FROM WMC_DeLijn WHERE Dienst='$Dienst' ")
or die(mysql_error());
// display data in table
echo "<p><b>Alles</b> | <a href='search_paginated.php?page=1'>Pagina</a></p>";
echo "<h2>Resultaten:</h2><p>";
echo "<table border='1' cellpadding='10'>";
echo "<table><tr><th>ID</th><th>Locatie</th><th>Periode</th><th>Dag</th> <th>Dienst</th><th>Delen</th><th>Geleed</th><th>Start 1</th><th>Eind 1</th> <th>Start 2</th><th>Eind 2</th><th>Lijnen</th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td align="center">' . $row['id'] . '</td>';
echo '<td align="center">' . $row['Locatie'] . '</td>';
echo '<td align="center">' . $row['Periode'] . '</td>';
echo '<td align="center">' . $row['Dag'] . '</td>';
echo '<td align="center">' . $row['Dienst'] . '</td>';
echo '<td align="center">' . $row['Delen'] . '</td>';
echo '<td align="center">' . $row['Geleed'] . '</td>';
echo '<td align="center">' . $row['Start1'] . '</td>';
echo '<td align="center">' . $row['Eind1'] . '</td>';
echo '<td align="center">' . $row['Start2'] . '</td>';
echo '<td align="center">' . $row['Eind2'] . '</td>';
echo '<td align="center">' . $row['Lijnen'] . '</td>';
echo '<td align="center"><a href="edit.php?id=' . $row['id'] . '">Bewerken</a></td>';
echo '<td align="center"><a href="delete.php?id=' . $row['id'] . '">Verwijderen</a></td>';
echo '<td align="center"><a href="Add_Event.php?id=' . $row['id'] . '">Afspraak maken</a></td>';
echo "</tr>";
} }
// close table>
echo "</table>";
?>
<p><a href="new.php">Toevoegen</a> | <a href="search.php">Zoeken</a> | <a href="search_lijnen.php">Zoeken op lijnnummer</a></p>
Add_Event.php
<?php
error_reporting(E_ALL);
// connect to the database
include('connect-db.php');
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
{
// query db
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM WMC_DeLijn WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$Locatie = $row['Locatie'];
$Periode = $row['Periode'];
$Dag = $row['Dag'];
$Dienst = $row['Dienst'];
$Delen = $row['Delen'];
$Geleed = $row['Geleed'];
$Start1 = $row['Start1'];
$Eind1 = $row['Eind1'];
$Start2 = $row['Start2'];
$Eind2 = $row['Eind2'];
$Lijnen = $row['Lijnen'];
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error!';
}
require_once '/customers/0/c/6/wmc-corner.be/httpd.www/DeLijn/google-api-php-client/src/Google_Client.php';
require_once '/customers/0/c/6/wmc-corner.be/httpd.www/DeLijn/google-api-php-client/src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Diensten Boeken");
$client->setClientId('xxx.apps.googleusercontent.com');
$client->setClientSecret('xxxx');
$client->setRedirectUri('http://www.xxx.be/xxx/search.php');
$client->setDeveloperKey('AIzaSyCyEC7cIu7yJS6ao73yaFMszKwvsWGkvFc');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout']))
{
unset($_SESSION['token']);
}
if (isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken())
{
$calList = $cal->calendarList->listCalendarList();
// print_r(get_declared_classes()); //This will dump the data of all declared classes so you can see what you have to work with
//print "<br/><br/>";
if(isset($_POST['action']))
{
$action = $_POST['action'];
if($action == "addCalEvent")
{
//Text Variables
$tBus="Bus: ";
$tLijnen="Lijnen: ";
$tDienst="Dienst ";
$tDienst1="/1";
$tDienst2="/2";
$plus="T";
$title1 = $tDienst.$fDienst.$tDienst1;
$title2 = $tDienst.$fDienst.$tDienst2;
$timezone= ".000+02:00";
//Post Variables
$title =$_POST["title"] ;
$desc = $_POST["desc"];
$calID = $_POST["calID"];
$locat = $_POST["locat"];
$ffrom = $_POST["from"];
$funtil = $_POST["until"];
$fPeriode = $_POST["Periode"];
$fDelen = $_POST["Delen"];
$fDienst = $_POST["Dienst"];
$fGeleed = $_POST["Geleed"];
$fStart1 = $_POST["Start1"];
$fEind1 = $_POST["Eind1"];
$fStart2 = $_POST["Start2"];
$fEind2 = $_POST["Eind2"];
$fDag = $_POST["Dag"];
$fLijnen = $_POST["Lijnen"];
//Time Variables
$from= $ffrom.$plus.$fStart1.$timezone;
$until= $funtil.$plus.$fEind1.$timezone;
$from1= $ffrom.$plus.$fStart2.$timezone;
$until1= $funtil.$plus.$fEind2.$timezone;
if($fDelen ='1')
{
//Set the Event data
$event = new Google_Event(); //note in the API examples it calls Event(). Apparently, they changed it and didn't update examples.
$event->setSummary($title);
$event->setDescription($desc);
$event->setLocation($locat);
$start = new Google_EventDateTime();
$start->setDateTime($from);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($until);
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('addenteeEmail');
// ...
//$attendees = array(dewit.lesley@gmail.com);
//$event->attendees = $attendees;
$createdEvent = $cal->events->insert('u4slarv7t1qn1fsblvfkdoct4c@group.calendar.google.com', $event);
// echo $createdEvent->getId();
}
else
{
$event = new Google_Event(); //note in the API examples it calls Event(). Apparently, they changed it and didn't update examples.
$event->setSummary($title1);
$event->setDescription($desc);
$event->setLocation($locat);
$start = new Google_EventDateTime();
$start->setDateTime($from);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($until);
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('addenteeEmail');
$event1 = new Google_Event(); //note in the API examples it calls Event(). Apparently, they changed it and didn't update examples.
$event1->setSummary($title2);
$event1->setDescription($desc);
$event1->setLocation($locat);
$start = new Google_EventDateTime();
$start->setDateTime($from1);
$event1->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($until1);
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('addenteeEmail');
$createdEvent = $cal->events->insert('xxx@group.calendar.google.com', $event);
// echo $createdEvent->getId();
}
}
}
// This is the form
print "<div style='width:100%;height:100%;'><div style='width:550px;height:550px;text-align:center;margin:200px auto;background-color:#f0ffff;border:1px solid black;'><div style='padding:50px;'><table>";
print "<form action='Add_Event.php' method='POST'>";
print "<tr><td>Title: </td><td><input type='text' name='title'value=' Dienst: $Dienst' id='title'></td></tr>";
print "<tr><td>Omschrijving: </td><td><input type='text' name='desc'value=' Geleed: $Geleed Lijnen: $Lijnen' id='title'></td></tr>";
print "<tr><td>Dag: </td><td><input type='text' name='locat'value='Stelplaats : $Locatie' id='desc'></td></tr>";
print "<tr><td>Periode: </td><td><input type='text' name='Periode' value='$Periode' id='locat'></td></tr>";
print "<tr><td>Dag: </td><td><input type='text' name='Dag'value='$Dag' id='desc'></td></tr>";
print "<tr><td>Dienst: </td><td><input type='text' name='Dienst' value='$Dienst' id='locat'></td></tr>";
print "<tr><td>Delen: </td><td><input type='text' name='Delen' value='$Delen' id='locat'></td></tr>";
print "<tr><td>Start1: </td><td><input type='text' name='Start1' value='$Start1' id='Start1'></td></tr>";
print "<tr><td>Eind1: </td><td><input type='text' name='Eind1' value='$Eind1' id='Eind1'></td></tr>";
print "<tr><td>Start2: </td><td><input type='text' name='Start2' value='$Start2' id='Eind1'></td></tr>";
print "<tr><td>Eind2: </td><td><input type='text' name='Eind2' value='$Eind2' id='Eind1'></td></tr>";
print "<tr><td>Geleed: </td><td><input type='text' name='Geleed'value='$Geleed' id='desc'></td></tr>";
print "<tr><td>Lijnen: </td><td><input type='text' name='Lijnen'value='$Lijnen' id='desc'></td></tr>";
print "<tr><td colspan='2'>Datum Formaat: JJJJ-MM-DDTHH</td></tr>";
print "<tr><td>From: </td><td><input type='text' name='from' id='from'></td></tr>";
print "<tr><td>To: </td><td><input type='text' name='until' id='until'></td></tr>";
print "<input type='hidden' name='action' value='addCalEvent'>";
print "<tr><td colspan='2'><div style='text-align:right;'><input type='submit' value='Submit'></div></td></tr>";
print "</form>";
print "</table></div></div></div>";
//Dumps Calendar Data so you can see what you're working with
//print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
$_SESSION['token'] = $client->getAccessToken();
}
else
{
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Verbind met Google!</a>";
}
?>
答案 0 :(得分:0)
我能够做我需要做的事情。我重新编写代码,我正在使用我的Google服务帐户。这解决了我现在的问题。