diff --git a/calendar/js/calendar.js b/calendar/js/calendar.js index 887712e..30ca7dc 100644 --- a/calendar/js/calendar.js +++ b/calendar/js/calendar.js @@ -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 ) { diff --git a/calendar/redirect.php b/calendar/redirect.php new file mode 100644 index 0000000..2f7b7b2 --- /dev/null +++ b/calendar/redirect.php @@ -0,0 +1,80 @@ + $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; +?>