<?php
if (isset($_SESSION['user_id'])) {
    if (isset($_POST["addCat"])) {
        $success = _exec(
            "INSERT INTO plan_zorilgo (name, type, tuluv ) VALUES (?, ?, ?)",
            'sii',
            [$_POST['name'], $_POST['type'], 1],
            $count
        );
        redirect('/plan/config');
    } else if (isset($_POST["addZorilt"])) {
        $success = _exec(
            "INSERT INTO plan_zorilgo (paren_id, name, zorilgo_id, tuluv) VALUES (?, ?, ?, ?)",
            'isii',
            [$_POST['name'], $_POST['type'], 1],
            $count
        );
        redirect('/plan/config');
    } else if (isset($_POST["mode"])) {
        if ($_POST["mode"] == "cat_tuluv") {
            $tuluv = $_POST['tuluv'];
            $t = 1;
            $tuluv == "true" ? $t = 1 : $t = 0;
            $success = _exec(
                "UPDATE plan_zorilgo SET tuluv = ? WHERE id = ?",
                'ii',
                [$t, $_POST['id']],
                $count
            );
            echo "Амжилттай!";
        }
    }
}
else echo "Дахин нэвтэрч орно уу!";