diff --git a/api.php b/api.php index 0cc14ce..c485174 100644 --- a/api.php +++ b/api.php @@ -40,11 +40,6 @@ switch ($_SERVER['REQUEST_METHOD']) { header("HTTP/1.0 404 Not Found"); } else { - // extend stored data with newId - // this point has to be fixed at it would not work with encrypted json - $newData = json_decode($data); - $newData->poll->id = $requested_id; - // set http header header("HTTP/1.0 200 OK"); @@ -55,7 +50,7 @@ switch ($_SERVER['REQUEST_METHOD']) { header('Content-Type: application/x-json-encrypted; charset=utf-8'); // send data back - echo json_encode($newData); + echo $data; } break; @@ -98,17 +93,15 @@ switch ($_SERVER['REQUEST_METHOD']) { // set content-type and charset header('Content-Type: application/x-json-encrypted; charset=utf-8'); - // extend given data with newId - // this point has to be fixed at it would not work with encrypted json - $newData = json_decode($data); - switch ($type) { case "polls": - $newData->poll->id = $newId; + $newData = $datahandler->get($newId); break; case "users": + $newData = json_decode($data); $newData->user->id = $newId; + $newData = json_encode($newData); break; default: @@ -117,7 +110,7 @@ switch ($_SERVER['REQUEST_METHOD']) { } // send back data - echo json_encode($newData); + echo $newData; } break; diff --git a/classes/datahandler.php b/classes/datahandler.php index 0af3541..ab32c33 100644 --- a/classes/datahandler.php +++ b/classes/datahandler.php @@ -61,6 +61,15 @@ class datahandler { $poll_data_json = file_get_contents($poll_file); $poll_data = json_decode($poll_data_json); + + // set id to poll + $poll_data->poll->id = $poll_id; + + // set id to option + foreach ($poll_data->poll->options as $k => $v) { + $poll_data->poll->options[$k]->id = $poll_id + $k; + } + $poll_data->poll->users = array(); // check for existing user diff --git a/index.html b/index.html index c5027b4..29200bf 100644 --- a/index.html +++ b/index.html @@ -103,12 +103,12 @@