<?php
include('../include/connection.php');
if(isset($_POST['delete']))
{
    switch($_POST['delete'])
    {
        case 'article_list':
            $success = 0;
            $sql = "delete from news where id=:id";
            $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            if($con->num_rows > 0)
            {
                $success = 1;                
            }
            echo json_encode(array('success'=>$success));
            break;
            
        case 'daily_energy_watch':
            $success = 0;
            $sql = "delete from daily_energy_watch where batchid=:id";
            $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            if($con->num_rows > 0)
            {
                $success = 1;
            }
            echo json_encode(array('success'=>$success));
            break;
            
        case 'gen':
                $success = 0;
                $sql = "delete from stats where batch_id=:id";
                $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
                if($con->num_rows > 0)
                {
                    $success = 1;
                }
                echo json_encode(array('success'=>$success));
                break;
            
        case 'disco_list':
            $success = 0;
            $sql = "select id from users where disco_id=:id";
            $q=$con->select_query($sql,array(':id'=>$_POST['id']));
            if(count($q) == 0)
            {
                $sql = "delete from discos where id=:id";
                $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
                if($con->num_rows > 0)
                {
                    $success = 1;
                }
            }
            echo json_encode(array('success'=>$success));
            break;
            
        case 'announcement_list':
            $success = 0;
            $sql = "delete from announcement where id=:id";
            $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            if($con->num_rows > 0)
            {
                $success = 1;
            }
            echo json_encode(array('success'=>$success));
            break;
            
        case 'event_list':
            $success = 0;
            $sql = "delete from event where id=:id";
            $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            if($con->num_rows > 0)
            {
                $success = 1;
                $sql = "delete from eventphoto where eventid=:id";
                $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            }
            echo json_encode(array('success'=>$success));
            break;
            
        case 'event_photos':
            $success = 0;
            $sql = "delete from eventphoto where id=:id";
            $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            if($con->num_rows > 0)
            {
                $success = 1;
            }
            echo json_encode(array('success'=>$success));
            break;
            
        case 'staff_birthdays':
            $success = 0;
            $sql = "delete from staff where id=:id";
            $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            if($con->num_rows > 0)
            {
                $success = 1;
            }
            echo json_encode(array('success'=>$success));
            break;
            
        case 'admins':
            $success = 0;
            $sql = "delete from users where id=:id";
            $q=$con->delete_query($sql,array(':id'=>$_POST['id']));
            if($con->num_rows > 0)
            {
                $success = 1;
            }
            echo json_encode(array('success'=>$success));
            break;
            
    }
}
?>