Exemple #1
0
function publishMenu(array $data)
{
    if (!empty($data)) {
        $i = '';
        $qry = DB::prepare("UPDATE menu SET \n                    `parent_id` =:parent_id,\n                    `sort_id`   =:sort_id,\n                    `text`      =:texts,\n                    `handler`   =:handler,\n                    `published` =:checked \n                WHERE id=:id");
        $qry->bindParam(':parent_id', $data['parent'], PDO::PARAM_INT);
        $qry->bindParam(':sort_id', $data['sort_id'], PDO::PARAM_INT);
        $qry->bindParam(':texts', $data['text'], PDO::PARAM_STR);
        $qry->bindParam(':handler', $data['handler'], PDO::PARAM_STR);
        $qry->bindParam(':checked', $data['_checked'], PDO::PARAM_INT);
        $qry->bindParam(':id', $data['id'], PDO::PARAM_INT);
        try {
            $qry->execute();
        } catch (PDOException $e) {
            $i .= $e;
        }
        if (!empty($data["children"])) {
            $ci = 0;
            foreach ($data["children"] as $d) {
                $ci++;
                $d["parent"] = $data["id"];
                $d["sort_id"] = $ci;
                publishMenu($d);
            }
        }
        return $i;
    }
}
Exemple #2
0
    }
}
if ($req == "publishMenu") {
    $data = isset($_POST['data']) ? $_POST['data'] : [];
    if (empty($data)) {
        echo "Gagal";
        exit;
    }
    $arrData = json_decode($data, true);
    $i = 0;
    foreach ($arrData as $d) {
        $i++;
        $d["sort_id"] = $i;
        $d["parent"] = 0;
        $d["_checked"] = isset($d["_checked"]) ? $d["_checked"] : 0;
        $e = publishMenu($d);
    }
    echo "sukses";
}
if ($req == "deleteMenu") {
    $id = isset($_POST['id']) ? (int) $_POST['id'] : 0;
    if ($id != 0 || $id > 0) {
        $qry = DB::prepare("DELETE from menu where id=:id or parent_id = :id");
        $qry->bindParam(':id', $id, PDO::PARAM_INT);
        try {
            $qry->execute();
            echo "sukses";
        } catch (PDOException $e) {
            echo "Gagal " . $e->getMessage();
        }
    }