Moved hostname to variable and added redirect.php

main
Thomas Ba. 10 years ago
parent 90f712aa3d
commit 048549d2f3

@ -2,13 +2,14 @@ var username = "root";
var appointments;
var categories;
var filter = 0;
var host = "://dhbw.t-battermann.de/calendar/rewrite.php";
function getListItems() {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
getListItemOnReadyStatusChangeEventHandler( request, filter );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=list");
request.open("GET", host + "?user="+username+"&format=json&action=list");
request.send();
}
function showCategory( id ) {
@ -17,7 +18,7 @@ function showCategory( id ) {
request.onreadystatechange = function() {
getListItemOnReadyStatusChangeEventHandler( request, id );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=list");
request.open("GET", host + "?user="+username+"&format=json&action=list");
request.send();
}
function prettyDate(from, to, allday) {
@ -239,7 +240,7 @@ function createNewCategory() {
request.onreadystatechange = function() {
createNewCategoryOnReadyStatusChangeEventHandler( request );
};
request.open("POST", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=add-category&name="+name);
request.open("POST", host + "?user="+username+"&format=json&action=add-category&name="+name);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("name="+encodeURIComponent(name));
}
@ -258,7 +259,7 @@ function getCategories() {
request.onreadystatechange = function() {
getCategoriesOnReadyStatusChangeEventHandler( request );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=list-categories");
request.open("GET", host + "?user="+username+"&format=json&action=list-categories");
request.send();
}
function getCategoriesOnReadyStatusChangeEventHandler( request ) {
@ -294,7 +295,7 @@ function deleteCategory( id ) {
request.onreadystatechange = function() {
deleteCategoryOnReadyStatusChangeEventHandler( request );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=delete-category&id=" + encodeURIComponent(id) );
request.open("GET", host + "?user="+username+"&format=json&action=delete-category&id=" + encodeURIComponent(id) );
request.send();
}
function deleteCategoryOnReadyStatusChangeEventHandler( request ) {
@ -327,7 +328,7 @@ function createNewEntry() {
request.onreadystatechange = function() {
createNewEntryOnReadyStatusChangeEventHandler( request );
};
request.open("POST", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=add" );
request.open("POST", host + "?user="+username+"&format=json&action=add" );
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var allday = f["allday"].checked;
request.send(
@ -395,7 +396,7 @@ function updateAppointment( id ) {
request.onreadystatechange = function() {
updateAppointmentOnReadyStatusChangeEventHandler( request );
};
request.open("POST", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=update" );
request.open("POST", host + "?user="+username+"&format=json&action=update" );
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var allday = f["allday"].checked;
request.send(
@ -427,7 +428,7 @@ function deleteAppointment( id ) {
request.onreadystatechange = function() {
deleteAppointmentOnReadyStatusChangeEventHandler( request );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=delete&id=" + encodeURIComponent(id) );
request.open("GET", host + "?user="+username+"&format=json&action=delete&id=" + encodeURIComponent(id) );
request.send();
}
}
@ -479,7 +480,7 @@ function uploadImage( id ) {
request.onreadystatechange = function() {
uploadImageOnReadyStatusChangeEventHandler( request );
};
request.open("POST", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=upload-image&id=" + id );
request.open("POST", host + "?user="+username+"&format=json&action=upload-image&id=" + id );
//request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var formData = new FormData();
formData.append("file", f["image"].files[0]);
@ -503,7 +504,7 @@ function deleteImage( id ) {
request.onreadystatechange = function() {
deleteImageOnReadyStatusChangeEventHandler( request, id );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=delete-image&id=" + encodeURIComponent(id) );
request.open("GET", host + "?user="+username+"&format=json&action=delete-image&id=" + encodeURIComponent(id) );
request.send();
}
}
@ -559,7 +560,7 @@ function addCategory( id ) {
request.onreadystatechange = function() {
addCategoryOnReadyStatusChangeEventHandler( request, id );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=put-category&event=" + id + "&category=" + f["category"].value );
request.open("GET", host + "?user="+username+"&format=json&action=put-category&event=" + id + "&category=" + f["category"].value );
request.send();
}
function addCategoryOnReadyStatusChangeEventHandler( request, id ) {
@ -579,7 +580,7 @@ function deleteCategoryFromEvent( eventId, categoryId ) {
request.onreadystatechange = function() {
deleteCategoryFromEventOnReadyStatusChangeEventHandler( request, eventId, categoryId );
};
request.open("GET", "http://host.bisswanger.com/dhbw/calendar.php?user="+username+"&format=json&action=remove-category&event=" + eventId + "&category=" + categoryId );
request.open("GET", host + "?user="+username+"&format=json&action=remove-category&event=" + eventId + "&category=" + categoryId );
request.send();
}
function deleteCategoryFromEventOnReadyStatusChangeEventHandler( request, eventId, categoryId ) {

@ -0,0 +1,80 @@
<?php
/**
This script redirects all calls to the real Web Service.
This is required to allow AJAX calls as cross-domain requests are normally not allowed.
*/
// URL of the target script
$url = "http://host.bisswanger.com/dhbw/calendar.php";
// Attach GET fields to URL
$get = "";
foreach ($_GET as $key => $value)
{
$key = htmlspecialchars($key);
$value = htmlspecialchars($value);
if ($get != "")
{
$get .= "&";
}
$get .= "$key=$value";
}
if ($get != "")
{
$url .= "?" . $get;
}
// Handle POST fields
$post = array();
foreach ($_POST as $key => $value)
{
$key = htmlspecialchars($key);
$value = htmlspecialchars($value);
$post[$key] = $value;
}
// Handle FILE attachments
$header = "";
foreach ($_FILES as $key => $value)
{
$header = array('Content-Type: multipart/form-data');
$post[htmlspecialchars($key)] = '@' . $value['tmp_name'] . ';type=' . $value['type'] . ';filename=' . $value['name'];
}
// Init cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if (count($post) > 0)
{
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($header != "")
{
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
// Execute request
$result = curl_exec($ch);
// Redirect content type
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
header("Content-Type: " . $contentType);
// Close connection
curl_close($ch);
// return web service result
print $result;
?>
Loading…
Cancel
Save