<?php

include_once("database.php");
$postData = file_get_contents("php://input");

if (isset($postData) && !empty($postData)) {

  $request = json_decode($postData);
  $isFile = trim($request->isFile);
  if(isFile){
    $username = trim($request['file']['username']);
    $filename = trim($request['file']['filename']);
    $lang = trim($request['file']['language']);
    $path = '../users/' . $username . '/' . trim($request->path) . '/' . $filename . $lang;

    if (unlink($path)) {
      $msg = "file successfully deleted";
      echo json_encode($msg);

    }
    else{
      http_response_code(404);
    }
    exit;
  }
  $username = trim($request->username);
  $dirname = trim($request['file']['name']);
  $path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $dirname;

  if (rmdir($path)) {
    $msg = "directory successfully deleted";
    echo json_encode($msg);
  }
  else {
        http_response_code(404);
  }
}
?>
