diff --git a/admin/event-edit.php b/admin/event-edit.php index f308eb1..eb8c9b5 100644 --- a/admin/event-edit.php +++ b/admin/event-edit.php @@ -1,636 +1,636 @@ . /* * Event edit * * From this page you can create/edit an User and assign some skills/interests etc. */ // load configurations and framework require 'load.php'; // inherit the Conference or specify one $conference_uid = $_GET['conference_uid'] ?? $_POST['conference_uid'] ?? CURRENT_CONFERENCE_UID; // check if the Conference exists $conference = ( new QueryConference() ) ->whereConferenceUID( $conference_uid ) ->queryRow(); // no Conference no party if( !$conference ) { error( "missing conference with UID $conferene_uid" ); die_with_404(); } // retrieve the Event (if existing) $event = null; if( isset( $_GET['id'] ) ) { // no Event no party $event = ( new QueryEvent() ) ->whereConference( $conference ) ->joinConference() ->joinChapter( 'LEFT' ) ->whereEventID( $_GET['id'] ) ->queryRow(); // no Event no party if( !$event ) { die_with_404(); } // no editable no party if( !$event->isEventEditable() ) { missing_privileges(); } } else { // check if there are permissions to add event if( !has_permission( 'add-event' ) ) { missing_privileges(); } } $warning = null; // check if the user submitted a form // check which one if( $_POST ) { // the user is submitting the save form if( is_action( 'save-event' ) ) { $conference_ID = $conference->getConferenceID(); $data = []; $data[] = new DBCol( Event::TITLE, $_POST['title'], 's' ); $data[] = new DBCol( Event::UID, $_POST['uid'], 's' ); $data[] = new DBCol( Event::LANGUAGE, $_POST['language'], 's' ); $data[] = new DBCol( Event::SUBTITLE, $_POST['subtitle'], 's' ); $data[] = new DBCol( Event::START, $_POST['start'], 's' ); $data[] = new DBCol( Event::END, $_POST['end'], 's' ); $data[] = new DBCol( Event::IMAGE, $_POST['image'], 'snull' ); $data[] = new DBCol( Chapter::ID, $_POST['chapter'], 'd' ); $data[] = new DBCol( Room::ID, $_POST['room'], 'd' ); $data[] = new DBCol( Track::ID, $_POST['track'], 'd' ); $data[] = new DBCol( Conference::ID, $conference_ID, 'd' ); // for each language save the fields foreach( all_languages() as $lang ) { foreach( Event::fields_i18n() as $i18n_column => $label ) { // generic column name in this language $field = $i18n_column . '_' . $lang->getISO(); // sent column value $value = $_POST[ $field ] ?? null; // prepare to be saved $data[] = new DBCol( $field, $value, 'snull' ); } } // convert empty strings to NULL, if possible foreach( $data as $row ) { $row->promoteNULL(); } if( $event ) { // update the existing Event ( new QueryEvent() ) ->whereEvent( $event ) ->update( $data ); } else { // insert a new Event Event::factory() ->insertRow( $data ); } $id = $event ? $event->getEventID() : last_inserted_ID(); // get the updated Event $event = FullEvent::factory() ->whereInt( Event::ID, $id ) ->queryRow(); // POST-redirect-GET - http_redirect( $event->getFullEventEditURL(), 303 ); + http_redirect( $event->getEventEditURL(), 303 ); } /** * Change the Image */ if( $event && is_action( 'change-image' ) ) { // prepare the image uploader $image = new FileUploader( 'image', [ 'category' => 'image', 'override-filename' => "event-" . $event->getEventUID(), ] ); // prepare the image pathnames $img_url = $event->getConferenceUID() . _ . 'images'; $img_path = ABSPATH . __ . $event->getConferenceUID() . __ . 'images'; // really upload that shitty image somewhere if( $image->fileChoosed() ) { $ok = $image->uploadTo( $img_path, $status, $filename, $ext ); if( $ok ) { // now update ( new QueryEvent() ) ->whereEvent( $event ) ->update( [ 'event_img' => $img_url . "/$filename.$ext", ] ); // POST-redirect-GET http_redirect( $event->getFullEventEditURL(), 303 ); } else { $warning = $image->getErrorMessage(); } } } /* * Add the user */ if( $event && is_action( 'add-user' ) && isset( $_POST['user'] ) ) { // Add user $user = User::factoryFromUID( $_POST['user'] ) ->select( User::ID ) ->queryRow(); if( $user ) { ( new QueryEventUser() ) ->whereEvent( $event ) ->whereUser( $user ) ->delete(); ( new QueryEventUser() )->insertRow( [ new DBCol( Event::ID, $event->getEventID(), 'd' ), new DBCol( User ::ID, $user->getUserID(), 'd' ), new DBCol( EventUser::ORDER, 0, 'd' ), ] ); } } /** * Update an user order */ if( $event && is_action( 'update-user' ) && isset( $_POST['user'] ) ) { $user = User::factoryFromUID( $_POST['user'] ) ->select( User::ID ) ->queryRow(); if( $user ) { if ( !empty( $_POST['delete'] ) ) { // Delete user EventUser::delete( $event->getEventID(), $user->getUserID() ); } elseif( isset( $_POST['order'] ) ) { // change order EventUser::factory() ->whereInt( Event::ID, $event->getEventID() ) ->whereInt( User ::ID, $user->getUserID() ) ->update( [ new DBCol( EventUser::ORDER, $_POST['order'], 'd') ] ); } } } // post -> redirect -> get (no: it hide errors) // http_redirect( $_SERVER[ 'REQUEST_URI' ], 303 ); } if( $event ) { Header::spawn( null, [ 'title' => sprintf( __("Modifica %s: %s"), $event->getChapterName(), $event->getEventTitle() ), ] ); } else { Header::spawn( null, [ 'title' => sprintf( __( "Aggiungi %s" ), __( "Evento" ) ), ] ); } ?>

getConferenceURL(), esc_html( $conference->getConferenceTitle() ) . icon( 'home', 'left' ) ) ?>

hasEventPermalink() ): ?>

getEventURL(), // text __( "Vedi" ) . icon( 'account_box', 'left' ) ) ?>

get( Event::TITLE ) ); } ?> />
get( Event::UID ) ); } ?> />
get( Event::SUBTITLE ) ); } ?> />
get( Event::LANGUAGE ) ); } ?> />
getEventStart()->format( 'Y-m-d H:i:s' ) ); } elseif( isset( $_GET['start'] ) ) { echo value( $_GET['start'] ); } ?> />
getEventEnd()->format( 'Y-m-d H:i:s' ) ); } elseif( isset( $_GET['end'] ) ) { echo value( $_GET['end'] ); } ?> />
$label ): ?>

getISO() ?>
get( Event::IMAGE ) ); } ?>/ > hasEventImage() ): ?> <?= esc_attr( $event->getEventTitle() ) ?>

factoryUserByEvent() ->select( [ User::UID, EventUser::ORDER, ] ) ->defaultClass( EventUser::class ) ->orderBy( EventUser::ORDER ) ->queryGenerator(); ?> valid() ): ?>

$user ): ?>
getUserUID() ) ?> />
getEventUserOrder() ) ?>" />

getUserEditURL(), sprintf( __( "Modifica %s" ), __( "Utente" ) ) ) ?>