diff --git a/2016/event-edit.php b/2016/event-edit.php index 6b0cc80..4b4743b 100644 --- a/2016/event-edit.php +++ b/2016/event-edit.php @@ -1,545 +1,614 @@ . require 'load.php'; // inherit the Conference or specify one $conference_uid = CURRENT_CONFERENCE_UID; if( isset( $_REQUEST['conference'] ) ) { $conference_uid = $_REQUEST['conference']; } // check if the Conference exists $conference = FullConference::factoryFromUID( $conference_uid ) ->queryRow(); if( !$conference ) { die_with_404(); } // retrieve the Event (if existing) $event = null; if( isset( $_GET['uid'] ) ) { $event = FullEvent::queryByConferenceAndUID( $conference->getConferenceID(), $_GET['uid'] ); if( !$event ) { die_with_404(); } if( !$event->isEventEditable() ) { error_die("Can't edit event"); } } else { // check if there are permissions to add event if( !has_permission( 'add-event' ) ) { die( 'missing permissions' ); } } +$warning = null; + if( $_POST ) { 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::ABSTRACT, $_POST['abstract'], 'snull' ); $data[] = new DBCol( Event::DESCRIPTION, $_POST['description'], 'snull' ); $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' ); foreach( $data as $row ) { $row->promoteNULL(); } if( $event ) { // update the existing Event Event::factory() ->whereInt( Event::ID, $event->getEventID() ) ->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 (temporary redirect) - http_redirect( $event->getFullEventEditURL(), 302 ); + // POST-redirect-GET + http_redirect( $event->getFullEventEditURL(), 303 ); + } + + /** + * Change the Image + */ + if( $event && is_action( 'change-image' ) ) { + + // prepare the image uploader + $image = new FileUploader( 'image', [ + 'category' => 'image', + 'override-filename' => $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 ) { - EventUser::delete($event->getEventID(), $user->getUserID()); + EventUser::delete( $event->getEventID(), $user->getUserID() ); insert_row('event_user', [ new DBCol( Event::ID, $event->getEventID(), 'd' ), new DBCol( User::ID, $user->getUserID(), '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( 'event', [ 'title' => sprintf( __("Modifica %s: %s"), $event->getChapterName(), $event->getEventTitle() ), 'url' => $event->getEventURL() ] ); } else { Header::spawn( 'event', [ 'title' => sprintf( __( "Aggiungi %s" ), __( "Evento" ) ), ] ); } ?> + +
+ +

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

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'] ); } ?> />

getEventAbstractHTML() ?>

getEventDescriptionHTML() ?>
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" ) ) ) ?>

. /** * Class able to query a FullEvent. */ class QueryEvent extends Query { + /** + * Univoque Event ID column name + * + * @var + */ + protected $EVENT_ID = 'event.event_ID'; + /** * Univoque Chapter ID column name * * @var */ protected $CHAPTER_ID = 'event.chapter_ID'; /** * Univoque location ID column name (useful with conference joins) */ protected $LOCATION_ID = 'conference.location_ID'; /** * Constructor */ public function __construct() { parent::__construct(); $this->from( Event::T ); $this->defaultClass( FullEvent::class ); } + /** + * Where the Event is... + * + * @return self + */ + public function whereEvent( $event ) { + return $this->whereEventID( $event->getEventID() ); + } + + /** + * Where the Event ID is... + * + * @param int $id Event ID + * @return self + */ + public function whereEventID( $id ) { + return $this->whereInt( $this->EVENT_ID, $id ); + } + /** * Limit to a certain User * * @param $user User * @return self */ public function whereUser( $user ) { return $this->joinEventUser() ->whereInt( EventUser::USER_, $user->getUserID() ); } /** * Limit to a specific Conference * * @param $conference Conference * @return self */ public function whereConference( $conference ) { return $this->joinConference() ->whereInt( Event::CONFERENCE_, $conference->getConferenceID() ); } /** * Exclude a specific Conference * * @param $conference Conference * @return self */ public function whereConferenceNot( $conference ) { $id = $conference->getConferenceID(); return $this->joinConference() ->whereInt( Event::CONFERENCE_, $id, '<>' ); } /** * Join Events to their Conference * * You can call it multiple time safely. * * @return self */ public function joinConference() { if( empty( $this->joinedConference ) ) { $this->from( Conference::T ); $this->equals( Conference::ID_, Event::CONFERENCE_ ); $this->joinedConference = true; } return $this; } /** * Join a table with the Chapter table * * @return self */ public function joinChapter() { return $this->joinOn( 'INNER', 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID ); } /** * Join Events to their Location (and Conference. asd) * * You can call it multiple time safely. * * @TODO: move this method into QueryConference, and extends QueryEvent * @return self */ public function joinLocation() { if( empty( $this->joinedLocation ) ) { $this->joinOn( 'INNER', Location::T, $this->LOCATION_ID, 'location.location_ID' ); } return $this; } /** * Join Events to User IDs * * You can call it multiple time safely. * * @return self */ public function joinEventUser() { if( empty( $this->joinedEventUser ) ) { $this->from( EventUser::T ); $this->equals( EventUser::EVENT_, Event::ID_ ); $this->joinedEventUser = true; } return $this; } /** * Join Events and their Track, Chapter and Room (can be NULL). * * You can call it multiple time safely. * * @return self */ public function joinTrackChapterRoom() { if( empty( $this->joinedTrackChapterRoom ) ) { $this->from( Room::T ) ->equals( Room::ID_, Event::ROOM_ ); $this->from( Track::T ) ->equals( Track::ID_, Event::TRACK_ ); $this->from( Chapter::T ) ->equals( Chapter::ID_, Event::CHAPTER_ ); $this->joinedTrackChapterRoom = true; } return $this; } }