<?php

function add_sides($title,$title_ar) {
    global $con;
    $con->query("INSERT INTO `sides` VALUES (Null,'$title','$title_ar','" . date("Y-m-d H:i:s") . "')");
    return mysqli_insert_id($con);
}

function sides_count() {

    global $con;

    $query = $con->query("SELECT * FROM `sides` ORDER BY `id` ASC");

    $sides_count = mysqli_num_rows($query);

    return $sides_count;
}

function view_sides() {

    global $con;

    $query = $con->query("SELECT * FROM `sides`  ORDER BY `id` ASC");

    $x = 1;

    while ($row = mysqli_fetch_assoc($query)) {
        $id = $row['id'];
        $title_ar = $row['title_ar'];
        $title = $row['title'];
        $date = $row['date'];
        ?>
        <tr class="gradeX">
            <td><?php echo $x; ?></td>
            <td><?php echo $title; ?></td>

            <td><?php echo $title_ar; ?></td>

            <td><?php echo $date; ?></td>
            <td class="actions">
                <a href="side_edit.php?sideID=<?php echo $id; ?>" class="on-default"><i class="fa fa-pencil"></i></a>
                <a href="<?php echo $id; ?>" class="on-default remove-row"><i class="fa fa-trash-o"></i></a>
            </td>
        </tr>		
        <?php
        $x++;
    }

    return mysqli_insert_id($con);
}

if (isset($_POST['delete_sides_id'])) {

    include("../connection.php");

    $sides_id = $_POST['delete_sides_id'];
    $query = $con->query("DELETE FROM `sides` WHERE `id`='$sides_id'");

    if ($query) {
        echo get_success("Deleted Successfully");
    }
}
?>
