Example #1
0
function deletePlotter($plotterId)
{
    $obj->successful = true;
    $obj->method = 'deletePlotter';
    // If plotter to delete is already cutted we need to restablish mts to the rolls
    // (i'm doing a restore plotter just to reuse code, it will be deleted later anywise)
    $query = "SELECT * FROM plotters WHERE id = '{$plotterId}'";
    $result = mysql_query($query);
    $rows = fetch_array($result);
    // unique result
    if ($rows[0]['cutted'] == true || $rows[0]['cutted'] == '1') {
        $plotter = new stdClass();
        $plotter->id = $plotterId;
        $plotter->cuts = array();
        $query = "SELECT * FROM plottercuts WHERE plotterId = '{$plotterId}'";
        $result = mysql_query($query);
        $cutsrows = fetch_array($result);
        foreach ($cutsrows as $row) {
            $cut = new stdClass();
            $cut->mtsCutted = $row['mtsCutted'];
            $cut->rollId = $row['rollId'];
            array_push($plotter->cuts, $cut);
        }
        restorePlotter($plotter);
    }
    // insert in removed plotters
    $query = "INSERT INTO removedplotters SELECT *, now() FROM plotters WHERE id = '{$plotterId}'";
    if (!mysql_query($query)) {
        $obj->successful = false;
        $obj->query = $query;
    }
    // delete plotter
    $query = "DELETE FROM plotters WHERE id = '" . $plotterId . "'";
    if (!mysql_query($query)) {
        $obj->successful = false;
        $obj->query = $query;
    }
    // delete assigned cuts (Note: plotter cuts assigned but not cutted are not reduced from roll mts so no need to restore nothing here)
    $query = "DELETE FROM plottercuts WHERE plotterId = '{$plotterId}'";
    if (!mysql_query($query)) {
        $obj->successful = false;
        $obj->query = $query;
    }
    // TODO possible after removing a plotter the prevision get in allCutted state -> include info in response
    $prevision = checkAllClothsCutted($rows[0]['previsionId']);
    $obj->allCutted = $prevision['allCutted'];
    $obj->plotterId = $plotterId;
    $obj->row0 = $rows[0];
    return $obj;
}
Example #2
0
db_connect();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $request_payload = file_get_contents('php://input');
    //var_dump($request_payload);
    $json = json_decode($request_payload);
    if (isset($_GET['saveCut'])) {
        $value = savePlotterCut($json);
    } else {
        if (isset($_GET['cutted'])) {
            $value = finishPlotter($json);
        } else {
            if (isset($_GET['manualPlotter'])) {
                $value = saveManualPlotter($json);
            } else {
                if (isset($_GET['restore'])) {
                    $value = restorePlotter($json);
                } else {
                    if (isset($_GET['toDesign'])) {
                        $value = toDesignPlotter($json);
                    } else {
                        if (isset($_GET['edit'])) {
                            $value = editPlotter($json, $_GET['field']);
                        } else {
                            if (isset($_GET['editPlotterPrevision'])) {
                                $value = editPlotterPrevision($json, $_GET['field']);
                            }
                        }
                    }
                }
            }
        }