diff --git a/admin/sharable.php b/admin/sharable.php index 48a48d9..47f7e12 100644 --- a/admin/sharable.php +++ b/admin/sharable.php @@ -1,147 +1,168 @@ . /* * Event edit * * From this page you can create/edit an User and assign some skills/interests etc. */ // load configurations and framework require 'load.php'; // editable Sharable fields $EDITABLE_FIELDS = [ Sharable::TITLE, Sharable::TYPE, Sharable::PATH, Sharable::MIME, Sharable::LICENSE, Sharable::PARENT, ]; $sharable = null; $sharable_ID = $_GET['id'] ?? 0; $sharable_ID = (int) $sharable_ID; -$event_ID = null; - if( $sharable_ID ) { $sharable = ( new QuerySharable() ) ->whereSharableID( $sharable_ID ) + ->joinEvent() ->queryRow(); // no Sharable no party if( !$sharable ) { error( "missing sharable with ID $sharable_ID" ); die_with_404(); } } // check if it exists if( $sharable ) { - $event_ID = $sharable->getEventID(); + // the Event is inherited from the Sharable + $event = $sharable; } else { $event_ID = $_GET['event_ID'] ?? 0; $event_ID = (int) $event_ID; // no Event no party if( !$event_ID ) { - throw new Exception( "missing Event" ); + throw new Exception( "missing Event ID" ); + } + + // check if the Event exists + $event = ( new QueryEvent() ) + ->whereEventID( $event_ID ) + ->queryRow(); + + // no Event no party + if( !$event ) { + error( "missing Event with ID $event_ID" ); + die_with_404(); } } // check if the user submitted the form if( is_action( 'save-sharable' ) ) { // data to be saved $data = []; // read and sanitize POST data foreach( $EDITABLE_FIELDS as $field ) { $v = luser_input( $_POST[ $field ] ?? '', 254 ); if( !$v ) { $v = null; } $data[] = new DBCol( $field, $v, 'snull' ); } // check if already existing if( $sharable ) { // update existing ( new QuerySharable() ) ->whereSharable( $sharable ) ->update( $data ); } else { // remember the Event ID - $data[ Event::ID ] = $event_ID; + $data[ Event::ID ] = $event->getEventID(); // insert a new one ( new QuerySharable() ) ->insertRow( $data ); $sharable_ID = last_inserted_ID(); } // POST -> redirect -> POST http_redirect( Sharable::editURL( [ 'id' => $sharable_ID, ] ) ); } // print website header Header::spawn( null, [ 'title' => __( "Materiale condiviso" ), ] ); ?> +
+ getEventEditURL(), + esc_html( $event->getEventTitle() ) + ) + ) ?> +
+


get( $field ) : ( $_POST[ $field ] ?? null ) ) ?>" />