<?php
global $bp, $wpdb;

$eventData = $wpdb->get_row('select * from wp_jet_events where slug = "' . $_GET['view'] . '"');

    if ($_POST['delete-event-button'] and $_POST['delete-event-understand'] == '1') {
        
        $deleteEvent = 'delete from wp_jet_events where id = "' . $_POST['event-id'] . '" and slug = "' . $_GET['view'] . '"';
        $deleteUsers = 'delete from wp_jet_events_members where event_id = "' . $_POST['event-id'] . '"';
        $deleteNotif = 'delete from wp_bp_notifications where component_action = "jes_event_invite" and item_id ="' . $_POST['event-id'] . '"';
        
        $wpdb->query($deleteEvent);
        $wpdb->query($deleteUsers);
        $wpdb->query($deleteNotif);
        
        wp_redirect( bp_get_root_domain() . '/eventos/' );
    }
?>
<script type="text/javascript" src="wp-content/themes/cvp-irontec/events/custom/js/scripts.js"></script>
<style>
li.iron-encabezado-li a.selected {
    background: whiteSmoke;
    color: #444;
    padding: 5px 7px;
}

li.iron-encabezado-li a:HOVER {
    text-decoration: none;
}
</style>
<div id="iron-encabezado-container">
    <h2 class="iron-encabezado-seccion"><?php echo __('Eventos','buddypress'); ?></h2>

    <ul class="iron-encabezado-ul">
        <li class="iron-encabezado-li">
            <a href="<?php bp_root_domain() ?>/eventos/">
                <?php _e ( 'Todos', 'buddypress' ); ?>
            </a>
        </li>
        </li>
        <li class="iron-encabezado-li">&middot;&nbsp;
            <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view']; ?>">
                <?php _e ( 'Volver al evento', 'buddypress' ) ; ?>
            </a>
        </li>
        <li class="iron-encabezado-li">&middot;&nbsp;
            <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] . '&Admin=details'; ?>">
                <?php _e ( 'Administración', 'buddypress' ) ; ?>
            </a>
        </li>
    </ul>
</div>

<div class="padder" id="jes-padder">
    
    <div id="content-top"></div>

    <div id="content-middle">
    
    <div id="content-middle-add">

        <div id="item-body">

        <div id="iron-encabezado-container-sub">
            <ul class="iron-encabezado-ul">
                <li class="iron-encabezado-li">
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=details' ?>">
                        <?php _e('Editar', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=avatar' ?>">
                        <?php _e('Avatar', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=members' ?>">
                            <?php _e('Miembros', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=sendInvites' ?>">
                        <?php _e('Enviar invitaciones', 'buddypress'); ?>
                    </a>
                </li>
                <li class="iron-encabezado-li">&nbsp;
                    <a class="selected" href="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=delete' ?>">
                        <?php _e('Delete', 'buddypress'); ?>
                    </a>
                </li>
            </ul>
        </div>
        
        <form action="<?php echo bp_get_root_domain() . '/eventos/?view=' . $_GET['view'] .'&Admin=delete' ?>" name="event-settings-form" id="event-settings-form" class="standard-form" method="POST" enctype="multipart/form-data">
        
            <div id="message" class="info">
                <p>
                    <?php _e('ATENCIÓN: Borrando este evento, borrarás completamente TODOS los contenidos asociados a este. No hay vuelta atrás, por favor, piensa bien lo que haces.', 'buddypress'); ?>
                </p>
            </div>
        
            <input type="checkbox" name="delete-event-understand" id="delete-event-understand" value="1" onclick="if(this.checked) { document.getElementById('delete-event-button').disabled = ''; } else { document.getElementById('delete-event-button').disabled = 'disabled'; }">
            <?php _e('Entiendo las consecuencias de Borrar este Evento.', 'buddypress'); ?>
            
            <div class="submit">
                <input type="submit" disabled="disabled" value="<?php _e('Eliminar Evento', 'buddypress' )?> →" id="delete-event-button" name="delete-event-button">
            </div>
        
            <input type="hidden" name="event-id" id="event-id" value="<?php echo $eventData->id?>">
        
        </form>
        
        </div><!-- #item-body -->
            
    </div>
    
    </div><!-- #content-middle -->
    
    <div id="content-bottom"></div>
    
</div><!-- .padder -->
    
