diff --git a/2016/event-edit.php b/2016/event-edit.php
index 4b4743b..8d757e5 100644
--- a/2016/event-edit.php
+++ b/2016/event-edit.php
@@ -1,614 +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
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(),
+ '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 ) {
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" )
),
] );
}
?>
= esc_html( $warning ) ?>
= HTML::a(
$conference->getConferenceURL(),
$conference->getConferenceTitle() . icon( 'home', 'left' )
) ?>
= HTML::a(
// href
$event->getEventURL(),
// text
__( "Vedi" ) . icon( 'account_box', 'left' )
) ?>
= HTML::a(
ROOT . '/2016/user-edit.php',
sprintf(
__( "Aggiungi %s" ),
sprintf(
__( "Nuovo %s" ),
__( "Utente" )
)
)
) ?>
factoryUserByEvent()
->select( [
User::UID,
EventUser::ORDER,
] )
->defaultClass( EventUser::class )
->orderBy( EventUser::ORDER )
->queryGenerator();
?>
valid() ): ?>
.
require 'load.php';
$user = null;
if( isset( $_GET['uid'] ) ) {
$user = User::factoryFromUID( @ $_GET['uid'] )
->queryRow();
if( !$user ) {
die( "not found" );
}
if( !$user->hasPermissionToEditUser() ) {
error_die( "Can't edit user" );
}
} else {
if( !has_permission( 'edit-users' ) ) {
error_die( "Can't create user" );
}
}
// register form submit action
if( is_action( 'save-user' ) ) {
// avoid spaces
if( $_POST['email'] ) {
$_POST['email'] = luser_input( $_POST['email'], 32 );
}
// generate Gravatar
if( $_POST['email'] ) {
$_POST['gravatar'] = md5( $_POST['email'] );
}
// prepare data sent via POST
$data = [];
$data[] = new DBCol( User::NAME, $_POST['name'], 's' );
$data[] = new DBCol( User::SURNAME, $_POST['surname'], 's' );
$data[] = new DBCol( User::UID, $_POST['uid'], 's' );
$data[] = new DBCol( User::EMAIL, $_POST['email'], 'snull' );
$data[] = new DBCol( User::WEBSITE, $_POST['site'], 'snull' );
+ $data[] = new DBCol( User::IMAGE, $_POST['image'], 'snull' );
$data[] = new DBCol( User::GRAVATAR, $_POST['gravatar'], 'snull' );
$data[] = new DBCol( User::LOVED_LICENSE, $_POST['lovelicense'], 'snull' );
// for each language
foreach( all_languages() as $lang ) {
// generic column name in this language
$field = sprintf( 'user_bio_%s', $lang->getISO() );
// sent column value
$value = $_POST[ $field ] ?? null;
// prepare to be saved
$data[] = new DBCol( $field, $value, 'snull' );
}
// promote empty strings to null
foreach( $data as $row ) {
$row->promoteNULL();
}
if( $user ) {
// update existing user
User::factoryByID( $user->getUserID() )
->update( $data );
} else {
// insert a new User
User::factory()
->insertRow( $data );
}
$id = $user
? $user->getUserID()
: last_inserted_ID();
$user = User::factoryByID( $id )
->queryRow();
// POST -> redirect -> GET
- http_redirect( $user->getUserEditURL(), 302 );
+ http_redirect( $user->getUserEditURL(), 303 );
}
+/**
+ * Change the Image
+ */
+if( $user && is_action( 'change-image' ) ) {
+
+ // prepare the image uploader
+ $image = new FileUploader( 'image', [
+ 'category' => 'image',
+ 'override-filename' => "user-" . $user->getUserUID(),
+ ] );
+
+ // prepare the image pathnames
+ $img_url = LATEST_CONFERENCE_UID . _ . 'images';
+ $img_path = ABSPATH . __ . LATEST_CONFERENCE_UID . __ . 'images';
+
+ // really upload that shitty image somewhere
+ if( $image->fileChoosed() ) {
+ $ok = $image->uploadTo( $img_path, $status, $filename, $ext );
+ if( $ok ) {
+
+ // now update
+ ( new QueryUser() )
+ ->whereUser( $user )
+ ->update( [
+ 'user_image' => $img_url . "/$filename.$ext",
+ ] );
+
+ // POST-redirect-GET
+ http_redirect( $user->getUserEditURL(), 303 );
+
+ } else {
+ die( $image->getErrorMessage() );
+ }
+ }
+}
+
if( isset( $_POST['action'], $_POST['skill_uid'], $_POST['skill_score'] ) ) {
$skill = Skill::factoryFromUID( $_POST['skill_uid'] )
->queryRow();
$skill or error_die( sprintf(
"Skill '%s' not found",
esc_html( $_POST['skill_uid'] )
) );
if( is_action( 'change-skill' ) ) {
if( isset( $_POST['skill_delete'] ) ) {
// Delete skill checked
query( sprintf(
"DELETE FROM {$T('user_skill')} WHERE user_ID = %d AND skill_ID = %d",
$user->getUserID(),
$skill->getSkillID()
) );
} else {
// Update skill elsewhere
query_update('user_skill',
new DBCol('skill_score', $_POST['skill_score'], 'd' ),
sprintf(
'skill_ID = %d',
$skill->getSkillID()
)
);
}
}
if( is_action( 'add-skill' ) ) {
$skill = Skill::factoryFromUID( $_POST['skill_uid'] )
->queryRow();
// If exists, delete it
query( sprintf(
"DELETE FROM {$T('user_skill')} WHERE user_ID = %d AND skill_ID = %d",
$user->getUserID(),
$skill->getSkillID()
) );
insert_row('user_skill', [
new DBCol('user_ID', $user->getUserID(), 'd'),
new DBCol('skill_ID', $skill->getSkillID(), 'd'),
new DBCol('skill_score', $_POST['skill_score'], 'd'),
] );
}
}
// register action to delete the user
if( $user && is_action( 'delete-user' ) ) {
// delete the user from the database
User::factory()
->whereInt( 'user_ID', $user->getUserID() )
->delete();
// POST -> redirect -> GET
http_redirect( $user->getUserEditURL(), 302 );
}
Header::spawn('user', [
'title' =>
$user
? sprintf(
__("Modifica utente %s"),
$user->getUserFullname()
)
: __( "Aggiungi Utente" )
,
'url' => $user ? $user->getUserURL() : null,
] );
?>
= HTML::a(
$user->getUserURL(),
__( "Vedi" ) . icon('account_box', 'left')
) ?>
+
+
+
+
+
+
factoryUserSkills()
->queryGenerator();
?>
valid() ): ?>
.
trait QueryUserTrait {
/**
* Where the user ID is...
*
* @param int $id
* @return self
*/
public function whereUserID( $id ) {
return $this->whereInt( static::USER_ID, $id );
}
/**
* Where the user is...
*
* @param User $user User object
* @return self
*/
public function whereUser( $user ) {
$id = $user->getUserID();
- return $this->whereUserID();
+ return $this->whereUserID( $id );
}
}
/**
* Class useful to retrieve User(s)
*/
class QueryUser extends Query {
use QueryUserTrait;
/**
* Disambigued user ID column name
*/
const USER_ID = 'user.user_ID';
/**
* Constructor
*/
public function __construct( $db = null ) {
// choose database and default return class
parent::__construct( $db, User::class );
// choose database table
$this->from( User::T );
}
}