Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Google日历PHP和SQL中插入事件_Php_Mysql_Google Api_Google Calendar Api_Google Api Php Client - Fatal编程技术网

在Google日历PHP和SQL中插入事件

在Google日历PHP和SQL中插入事件,php,mysql,google-api,google-calendar-api,google-api-php-client,Php,Mysql,Google Api,Google Calendar Api,Google Api Php Client,我试图创造一些东西,但它不起作用 我有一个数据库,里面有班次 (Shift, Location, Start Time, End Time,...). 我已经创建了一个页面来搜索这些轮班并显示它们 这将提供一个带有shift和3个链接的表来编辑、删除或预订它们 预订它们会将它们添加到我的谷歌日历中。Book链接将ID发送到Add_Event.php Google总是尝试让我一次又一次地登录而不发送任何内容。我绝望了。昨天起作用了。现在它停止工作了 search.php Add_Event.

我试图创造一些东西,但它不起作用

我有一个数据库,里面有班次

(Shift, Location, Start Time, End Time,...).
我已经创建了一个页面来搜索这些轮班并显示它们

这将提供一个带有shift和3个链接的表来编辑、删除或预订它们

预订它们会将它们添加到我的谷歌日历中。Book链接将ID发送到Add_Event.php Google总是尝试让我一次又一次地登录而不发送任何内容。我绝望了。昨天起作用了。现在它停止工作了

search.php

Add_Event.php


我能做我需要做的事。我重新编写了代码,我正在使用我的谷歌服务帐户。这暂时解决了我的问题。

定义不工作?按照编写代码的方式,每次运行代码时都必须对其进行身份验证。您是否从插入中得到错误?在该表中,我有所有字段和3个额外字段。编辑、删除和预订日历。它被发送到Add_Event.php Add_Event.php?id=xx。它发送Id,然后我需要进行身份验证。之后,我只得到Add_Event.php?code=xxx标题栏,而不是Add_Event.php代码其余部分中使用的id。通过将id发送到Add_Event.php,我可以在谷歌日历中创建一个事件,在数据库中查找时间,以及标题和描述。如果没有serach.php中查找的Id,代码将无法工作。只需要知道如何发送Id以通过oauth2。当点击search.php表格中的结果时,这个链接的Id部分在oauth2之后消失了。你没有发现它。谷歌在它的$_GET['code']中向你发送了它。难道没有办法向第二个文件发送一个值吗?谷歌代码正在运行。正在寻找一种方法来查找数据库值开始时间、结束时间、标题和描述,并将它们添加到事件中。
<!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>
<?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>";

}

?>