<?php
global $bp, $wpdb;

    if ($_POST['Actualizar']) {
        
        $data = array(
                    'name'           => $_POST['event-name'],
                    'etype'          => $_POST['event-etype'],
                    'description'    => $_POST['event-desc'],
                    'placedaddress'  => $_POST['event-placedaddress'],
                    'placednote'     => $_POST['event-web'],
                    'edtsd'          => $_POST['event-edtsd'],
                    'edted'          => $_POST['event-edted'],
                    'edtsth'         => $_POST['event-edtsth'],
                    'edteth'         => $_POST['event-edteth'],
                    'edtstm'         => $_POST['event-edtstm'],
                    'edtetm'         => $_POST['event-edtetm'],
                    'edtsdunix'      => strtotime(str_replace('/', '-', $_POST['event-edtsd'])),
                    'edtedunix'      => strtotime(str_replace('/', '-', $_POST['event-edted'])),
                    'grouplink'      => $_POST['event-grouplink']
                    );
        $where = array(
                    'id' => $_POST['eventid'],
                    'slug' => $_GET['view']
                        );
        
        $result = $wpdb->update( 'wp_jet_events', $data, $where );
        
        if ( is_wp_error( $result ) ) {
            $error_string = $result->get_error_message();
            echo '<div id="message" class="error"><p>' . $error_string . '</p></div>';
        }
    }

    $eventData = $wpdb->get_row('select * from wp_jet_events where slug = "' . $_GET['view'] . '"');
    
?>
<script type="text/javascript" src="wp-content/themes/cvp-irontec/events/custom/js/scripts.js"></script>
<link rel="stylesheet" href="wp-content/themes/cvp-irontec/_inc/css/jquery-ui.css" />
<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 class="selected" 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 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=details'; ?>" name="event-settings-form" id="event-settings-form" class="standard-form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="event-a" value="true">
            
            <div id="custom-event-name">
                <label for="event-name">
                    <?php _e('* Event Name', 'buddypress') ?>
                </label>
                <input type="text" name="event-name" id="event-name" size ="26" <?php echo $required; ?> value="<?php echo $eventData->name ?>" />
            </div>
    
            <div id="custom-event-classification">
                <label for="event-etype">
                    <?php _e('* Event classification', 'buddypress') ?>
                </label>
                
                <select name="event-etype" id="event-etype" size = "1">
                    <option value="Reuniones" <?php echo ($eventData->etype == 'Reuniones') ? 'selected="selected"' : '' ?> >
                        <?php _e('Reuniones', 'buddypress'); ?>
                    </option> 
                    <option value="Espectáculos y Conciertos" <?php echo ($eventData->etype == 'Espectáculos y Conciertos') ? 'selected="selected"' : '' ?> >
                        <?php _e('Espectáculos y Conciertos', 'buddypress'); ?>
                    </option>
                    <option value="Fiestas" <?php echo ($eventData->etype == 'Fiestas') ? 'selected="selected"' : '' ?> >
                        <?php _e('Fiestas', 'buddypress'); ?>
                    </option>
                    <option value="Escapadas" <?php echo ($eventData->etype == 'Escapadas') ? 'selected="selected""' : '' ?> >
                        <?php _e('Escapadas', 'buddypress'); ?>
                    </option>
                    <option value="Congreso" <?php echo ($eventData->etype == 'Congreso') ? 'selected="selected"' : '' ?> >
                        <?php _e('Congreso', 'buddypress'); ?>
                    </option>
                    <option value="Feria" <?php echo ($eventData->etype == 'Feria') ? 'selected="selected"' : '' ?>>
                        <?php _e('Feria', 'buddypress'); ?>
                    </option>
                    <option value="Ponencia" <?php echo ($eventData->etype == 'Ponencia') ? 'selected="selected"' : '' ?>>
                        <?php _e('Ponencia', 'buddypress'); ?>
                    </option>
                    <option value="Otros" <?php echo ($eventData->etype == 'Otros') ? 'selected="selected"' : '' ?>>
                        <?php _e('Otros', 'buddypress'); ?>
                    </option >
                </select>
            </div>
            
            <div id="custom-event-desc">
                <label for="event-desc">
                    <?php _e('* Event Description', 'buddypress') ?>
                </label>
                <textarea name="event-desc" id="event-desc" <?php echo $required; ?> ><?php echo $eventData->description ?></textarea>
            </div>
            
            <div id="custom-event-placedcity">
                <label for="event-placedcity">
                    <?php _e('* Dirección web del evento', 'buddypress') ?>
                </label>
                <input type="text" name="event-web" id="event-web" size="35" maxlength="70" <?php echo $required; ?> value="<?php echo $eventData->placednote ?>" />
            </div>
            
            <div id="custom-event-placedaddress">
                <label for="event-placedaddress">
                    <?php _e('* Event address', 'buddypress') ?>
                </label>
                <input type="text" name="event-placedaddress" id="event-placedaddress" size="35" maxlength="70" <?php echo $required; ?> value="<?php echo $eventData->placedaddress ?>" />
            </div>
            
            <h4 id="custom-event-date-title">
                <?php _e('* Event Date', 'buddypress') ?>
            </h4>
            
            <div id="custom-event-date-start">
                <label for="event-edtsd">
                    <?php _e('* Event Start date', 'buddypress') ?>
                </label>
            
                <input type="text" readonly name="event-edtsd" id="event-edtsd" size="12" maxlength="20" value="<?php echo $eventData->edtsd ?>" />
            
                <select name="event-edtsth" id="event-edtsth" size=1>
                <?php
                    for ($i=0; $i<24; $i++) { ?>
                    <?php if ($i<10)
                        { $codei = '0'.$i; }
                            else
                        { $codei = $i; } ?>
                        <option value="<?php echo $codei;?>" <?php echo ($codei == $eventData->edtsth) ? 'selected="selected"' : ''?> ><?php echo $codei; ?></option>
                <?php } ?>
                </select>
            
                <?php _e(' hours', 'buddypress'); ?>
                <select name="event-edtstm" id="event-edtstm" size=1>
                <?php for ($i=0;$i<60;$i=$i+5)
                    { ?>
                    <?php if ($i<10)
                        { $codei = '0'.$i; }
                            else
                        { $codei = $i; } ?>
                <option value="<?php echo $codei; ?>" <?php echo ($codei == $eventData->edtstm) ? 'selected="selected"' : ''?> ><?php echo $codei; ?></option>
                <?php } ?>
                </select>
                <?php _e(' minutes', 'buddypress'); ?>
            </div>
            
            <div id="custom-event-date-end">
                <label for="event-edted">
                    <?php _e('* Event End date', 'buddypress') ?>
                </label>
                
                <input type="text" readonly name="event-edted" id="event-edted" size="12" maxlength="20" value="<?php echo $eventData->edted ?>" />
                        
                <select name="event-edteth" id="event-edteth" size=1>
                <?php
                    for ($i=0; $i<24; $i++) { ?>
                    <?php if ($i<10)
                        { $codei = '0'.$i; }
                            else
                        { $codei = $i; } ?>
                        <option value="<?php echo $codei;?>" <?php echo ($codei == $eventData->edteth) ? 'selected="selected"' : ''?> ><?php echo $codei; ?></option>
                <?php } ?>
                </select>
                
                <?php _e(' hours', 'buddypress'); ?>
                
                <select name="event-edtetm" id="event-edtetm" size=1>
                <?php for ($i=0;$i<60;$i=$i+5)
                    { ?>
                    <?php if ($i<10)
                        { $codei = '0'.$i; }
                            else
                        { $codei = $i; } ?>
                <option value="<?php echo $codei; ?>" <?php echo ($codei == $eventData->edtetm) ? 'selected="selected"' : ''?> ><?php echo $codei; ?></option>
                <?php } ?>
                </select><?php _e(' minutes', 'buddypress'); ?>
            </div>
<?php
/*            
            <div id="custom-event-group">
                <h4>
                    <?php _e( 'Group/Forum link options', 'buddypress'); ?>
                </h4>
                <label><?php _e('Select the group you want to contact the event:', 'buddypress'); ?></label>
                <?php jes_event_groups_dropdown( $eventData->grouplink ) ?>
            </div>
*/
?>
            <input type="hidden" name="eventid" id="event-id" value="<?php echo $eventData->id; ?>">
            <input type="submit" name="Actualizar" value="<?php _e('Actualizar', 'buddypress')?>" />
        </form><!-- #event-settings-form -->                        
        </div><!-- #item-body -->
        
        </div><!-- #content-middle-add -->
        
    </div><!-- #content-middle -->
    
    <div id="content-bottom"></div>
    
</div><!-- .padder -->

<script>
(function($) {
    $( "#event-edtsd" ).datepicker({
        dayNames:      [ "Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado" ],
        dayNamesMin:   [ "Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa" ],
        monthNames:    [ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Augosto", "Septimbre", "Octbre", "Novimbre", "Dicimbre" ],
        firstDay: 1,
        dateFormat: "dd/mm/yy"
    });
    $( "#event-edtsd" ).datepicker( "option", "showAnim", 'blind' );
    $( "#event-edted" ).datepicker({
        dayNames:      [ "Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado" ],
        dayNamesMin:   [ "Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa" ],
        monthNames:    [ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Augosto", "Septimbre", "Octbre", "Novimbre", "Dicimbre" ],
        firstDay: 1,
        dateFormat: "dd/mm/yy"
    });
    $( "#event-edted" ).datepicker( "option", "showAnim", 'blind' );
})(jQuery);
</script>
