<?php

// dummy check
if (empty($q) || empty($CFG)) {
    die;
}
if (Context == 'ponente') {
    preg_match('#^speaker/proposals/(\\d+)/files/delete/(\\d+)/?.*$#', $q, $matches);
    $proposal_id = !empty($matches) ? (int) $matches[1] : 0;
    $file_id = !empty($matches) ? (int) $matches[2] : 0;
    //Check proposal owner
    $proposal = get_proposal($proposal_id, $USER->id);
    if (!empty($proposal)) {
        //get file
        $file = get_record('prop_files', 'id', $file_id, 'id_propuesta', $proposal->id);
        $return_url = get_url('speaker/proposals/' . $proposal->id . '/files');
    } else {
        $return_url = get_url('speaker/proposals');
    }
}
$submit = optional_param('submit');
//can't delete files from accepted/canceled/deleted/programmed proposals
if (!empty($proposal) && !empty($file) && $proposal->id_status < 5) {
    ?>

<h1><?php 
    echo __('Eliminar archivo');
    ?>
</h1>

<?php 
<?php

// dummy check
if (empty($q) || empty($CFG)) {
    die;
}
if (Context == 'ponente') {
    preg_match('#^speaker/proposals/(\\d+)/delete$#', $q, $matches);
    $proposal_id = !empty($matches) ? (int) $matches[1] : 0;
    //Check proposal owner
    $proposal = get_proposal($proposal_id, $USER->id);
} elseif (Context == 'admin') {
    preg_match('#^admin/proposals/(\\d+)/delete#', $q, $matches);
    $proposal_id = !empty($matches) ? (int) $matches[1] : 0;
    $proposal = get_proposal($proposal_id);
}
$submit = optional_param('submit');
//check owner and status, dont delete acepted, scheduled or deleted¿?
// can delete canceled proposal
if (!empty($proposal) && ($proposal->id_status < 5 || ($proposal->id_status = 6))) {
    ?>

<h1><?php 
    echo __('Eliminar propuesta');
    ?>
</h1>

<?php 
    if (empty($submit)) {
        // confirm delete
        ?>
<?php

if (!defined('Context') || Context != 'admin') {
    header('Location: ' . get_url());
}
preg_match('#^admin/events/(\\d+)/cancel#', $q, $matches);
$event_id = !empty($matches) ? (int) $matches[1] : 0;
if (!empty($event_id)) {
    $event = get_record('evento', 'id', $event_id);
    $proposal = get_proposal($event->id_propuesta);
}
$submit = optional_param('submit');
?>

<h1><?php 
echo __('Cancelar evento');
?>
</h1>

<p class="error center"><?php 
echo __('Esta acción liberará el espacio ocupado en el programa por este evento
y le asignará el status de <em>Cancelada</em>. Las inscripciones de los asistentes que pudieran
tener este evento serán eliminadas.');
?>
</p>

<?php 
// process submit
if (Action == 'cancelevent' && !empty($submit) && !empty($event) && !empty($proposal)) {
    // messages holder
    $errmsg = array();
    require $CFG->admdir . 'event_optional_params_check.php';
    if (!empty($errmsg)) {
        show_error($errmsg);
    } else {
        // insert or update propuesta
        require $CFG->admdir . 'event_update_info.php';
        ?>

<p class="error center"><?php 
        echo __('Evento organización agregado.');
        ?>
</p>

<?php 
        // refresh proposal
        $proposal = get_proposal($proposal->id);
        $prop_noshow_resume = true;
        // show proposal updated details
        include $CFG->comdir . 'prop_display_info.php';
        do_submit_cancel('', __('Continuar'), $return_url);
    }
}
if (empty($submit) || !empty($errmsg)) {
    ?>
 

<form method="POST" action="">

    <p class="center"><em><?php 
    echo __('Los campos marcados con asterisco(*) son obligatorios');
    ?>
<?php

if (empty($CFG) || empty($q)) {
    die;
}
if (Context == 'asistente') {
    preg_match('#^person/workshops/(\\d+)/(.+)#', $q, $matches);
    $workshop_id = (int) $matches[1];
    $action = $matches[2];
    $userid = $USER->id;
    $workshop = get_proposal($workshop_id);
    $return = get_url('person/workshops');
    $limit = count_records('inscribe', 'id_asistente', $userid);
} else {
    $return = get_url();
}
// check if wid is a workshop or limit of subscribed workshop
// TODO: move to config limit of workshops
if ($workshop->id_prop_tipo < 50 || $workshop->id_prop_tipo >= 100 || $action == 'subscribe' && $limit > $CFG->max_inscripcionTA) {
    // clear workshop
    unset($workshop);
}
// update reg flag status
if (!empty($workshop) && !empty($workshop->id_evento) && !empty($action)) {
    if ($action == 'subscribe') {
        $query = 'INSERT INTO ' . $CFG->prefix . 'inscribe(id_asistente,id_evento,reg_time) VALUES(%d,%d,%s)';
        $time = strftime('%Y%m%d%H%M%S');
        // build query
        $query = sprintf($query, $userid, $workshop->id_evento, $time);
        $rs = execute_sql($query, false);
    } elseif ($action == 'unsubscribe') {