<?php
include "classes/DatabaseConnection.php";

// return JSON string of the request and results for removing word_meaning
echo '{"request_type":"remove_meaning"';

if ($_GET["debug"]) {
    $debug = TRUE;
    echo ',"parm_debug":"TRUE"';
} else {
    $debug = FALSE;
}

$error = FALSE;
$error_text = "";

if ($_GET["meaning_id"]) {
    $i_meaning_id = $_GET["meaning_id"];
    echo ',"parm_meaning_id":"' . $i_meaning_id . '"';
} else {
    $error = TRUE;
    $error_text = "Mandatory parameter meaning_id not supplied";
}

if ($error) {
    echo ',"status":"Error: ' . $error_text . '"}';
    exit;
}

// get db connection
$db_conn = DatabaseConnection::getConnection();

if ($debug == TRUE) echo ',"db_status":"' . $db_conn->status . '"';

// delete meaning 
$query = "UPDATE word_meanings SET is_deleted = '1' WHERE id = $i_meaning_id";

$db_conn->connection->query($query);

if ($db_conn->connection->affected_rows == 0) {
    // not found
    echo ',"status":"Error: no word meaning found with id ' . $i_meaning_id . '"}';
    exit;
} else {
    if ($debug == TRUE) {
        echo ',"status":"OK: meaning_removed with id ' . $i_meaning_id . '"';  
    } else {
        echo ',"status":"OK: meaning_removed"';
    }
}

// close request object
echo '}';
?>