diff --git a/2016/event-translate.php b/2016/event-translate.php index 8468de8..5a18a60 100644 --- a/2016/event-translate.php +++ b/2016/event-translate.php @@ -1,119 +1,134 @@ . // load the framework require 'load.php'; // only allow translators // read the Event ID $id = isset( $_GET['id'] ) ? (int) $_GET['id'] : null; // require the Event ID if( !$id ) { die_with_404(); } // query the Event $event = ( new QueryEvent() ) ->whereEventID( $id ) ->joinConference() ->joinTrack() ->queryRow(); // no Event no party if( !$event ) { die_with_404(); } // no permissions no party if( !$event->isEventEditable() && !has_permission( 'translate' ) ) { error_die( 'not enough permissions' ); } $DEFAULT_LANGUAGE = RegisterLanguage::instance()->getDefault(); // register form action if( is_action( 'translate-event' ) ) { $tosave = []; // for each language save the fields foreach( all_languages() as $lang ) { - // do not allow to edit the default language - if( $lang === $DEFAULT_LANGUAGE ) { + // do not allow to edit the default language if you are not the Event owner + if( $lang === $DEFAULT_LANGUAGE && !$event->isEventEditable() ) { continue; } - foreach( Event::fields_i18n() as $i18n_column => $label ) { + // for each translatable fields + foreach( Event::fields_i18n() as $i18n_column ) { + // generic column name in this language $field = $i18n_column . '_' . $lang->getISO(); // sent column value - $value = $_POST[ $field ] ?? null; + $value = isset( $_POST[ $field ] ) + ? $_POST[ $field ] + : null; + + // set empty strings as null + if( !$value ) { + $value = null; + } - // prepare to be saved + // sanitize the value before update (allow string and null) $tosave[] = new DBCol( $field, $value, 'snull' ); } } // update the fields ( new QueryEvent() ) ->whereEvent( $event ) ->update( $tosave ); + + // POST -> redirect -> GET + http_redirect( $_SERVER[ 'REQUEST_URI' ], 303 ); } // print the site header Header::spawn( null, [ 'title' => $event->getEventTitle(), ] ); ?>
-

-

- -
- - -
- -
+ + + + $event, + 'field' => Event::ABSTRACT, + 'label' => __( "Abstract" ) + ] ) ?> + + + $event, + 'field' => Event::DESCRIPTION, + 'label' => __( "Descrizione" ) + ] ) ?> + + + $event, + 'field' => Event::NOTE, + 'label' => __( "Note" ) + ] ) ?>
. /** * A recursive function to generate a menu tree. * * @param string $uid The menu identifier * @param int $level Level of the menu, used internally. Default 0. * @param array $args Arguments */ function print_menu($uid = null, $level = 0, $args = [] ) { $args = array_replace( [ 'max-level' => 99, 'main-ul-intag' => 'class="collection"' ], $args ); if( $level > $args['max-level'] ) { return; } $menuEntries = get_children_menu_entries($uid); if( ! $menuEntries ) { return; } ?> >
  • url ), $menuEntry->name, $menuEntry->get('title') ) ?> uid, $level + 1, $args ) ?>
  • $icon"; } function die_with_404() { new Header('404', [ 'title' => __("È un 404! Pagina non trovata :("), 'not-found' => true ] ); error( __("Nott foond! A.k.a. erroro quattrociantoquatto (N.B. eseguire coi permessi di root non risolve la situazione!)") ); new Footer(); exit; } + +/** + * Require a certain page from the template directory + * + * @param $name string page name (to be sanitized) + * @param $args mixed arguments to be passed to the page scope + */ +function template( $template, $template_args = [] ) { + extract( $template_args, EXTR_SKIP ); + require CURRENT_CONFERENCE_ABSPATH . __ . 'template' . __ . $template . '.php'; +}