diff --git a/2016/user-edit.php b/2016/user-edit.php index 1b9e3a7..9e16df0 100644 --- a/2016/user-edit.php +++ b/2016/user-edit.php @@ -1,580 +1,640 @@ . 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::FACEBOOK, $_POST['facebook'], 'snull' ); $data[] = new DBCol( User::LINKEDIN, $_POST['linkedin'], 'snull' ); $data[] = new DBCol( User::GITHUB, $_POST['github'], 'snull' ); $data[] = new DBCol( User::TWITTER, $_POST['twitter'], 'snull' ); $data[] = new DBCol( User::LOVED_LICENSE, $_POST['lovelicense'], 'snull' ); // for each language save the biography 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(), 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() ); } } } +// register action to create a Skill +if( is_action( 'create-skill' ) && isset( $_POST['skill_title'], $_POST['skill_type'] ) ) { + + // generate a Skill UID + $skill_uid = generate_slug( $_POST['skill_title'], 32 ); + + // check if already exists + $skill = ( new QuerySkill() ) + ->whereSkillUID( $skill_uid ) + ->queryRow(); + + // create the Skill + if( !$skill ) { + ( new QuerySkill() ) + ->insertRow( [ + 'skill_uid' => $skill_uid, + 'skill_title' => $_POST['skill_title'], + 'skill_type' => $_POST['skill_type'], + ] ); + } + +} + +// register action to edit an existing Skill if( isset( $_POST['skill_uid'], $_POST['skill_score'] ) ) { // find existing Skill $skill = Skill::factoryFromUID( $_POST['skill_uid'] ) ->queryRow(); // eventually create the Skill if( !$skill ) { ( new QuerySkill() ) ->insertRow( [ 'skill_uid' => $_POST['skill_uid'], ] ); // retrieve last inserted Skill $skill = ( new QuerySkill() ) ->whereSkillID( last_inserted_ID() ) ->queryRow(); } // query the UserSkill $query_userskill = ( new QueryUserSkill() ) ->whereUser( $user ) ->whereSkill( $skill ); + // eventually change an existing skill if( is_action( 'change-skill' ) ) { // delete the Skill or just update? if( isset( $_POST['skill_delete'] ) ) { $query_userskill->delete(); } else { // update the score $query_userskill->update( [ 'skill_score' => (int)$_POST['skill_score'], ] ); } } + // eventually add a skill if( is_action( 'add-skill' ) ) { // eventually delete $query_userskill->delete(); - // then add + // then add the skill ( new QueryUserSkill() ) ->insertRow( [ 'user_ID' => $user->getUserID(), 'skill_ID' => $skill->getSkillID(), 'skill_score' => $_POST['skill_score'], ] ); } } // 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(), 303 ); } Header::spawn( null, [ 'title' => $user ? sprintf( __("Modifica %s"), $user->getUserFullname() ) : __( "Aggiungi Utente" ) , ] ); ?>

getUserURL(), __( "Vedi" ) . icon('account_box', 'left') ) ?>

get( User::NAME ) ) : '' ?> />
get( User::SURNAME ) ) : '' ?> />
getUserUID() ) : '' ?> />
getUserEmail() ) : '' ?> />
hasUserGravatar() ? value( $user->getUserGravatarUID() ) : '' ?> />
get( User::WEBSITE ) ) : '' ?> />
get( User::FACEBOOK ) ) : '' ?> />
get( User::TWITTER ) ) : '' ?> />
get( User::LINKEDIN ) ) : '' ?> />
get( User::GITHUB ) ) : '' ?> />
get( User::IMAGE ) ) : '' ?> />
hasUserLovelicense() ) { echo $user->getUserLovelicense()->getLink(); } ?>
getISO() ) ?>

getHuman() ) ?> getISO() === 'it' ): ?>

Legacy description translated by the community:

- -

-
-
-
-
- - -
-
- -
-
- -
-
- -
-
-
-
-
-
- - + factoryUserSkills() ->queryGenerator(); ?> valid() ): ?>

-

getSkillPhrase() ?>

+ + + + +

+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+ + + + +

+
+
+
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
. trait QuerySkillTrait { /** * Where the Skill is the specified one * * @param object $skill * @return self */ public function whereSkill( $skill ) { return $this->whereSkillID( $skill->getSkillID() ); } /** * Where the Skil ID is the specified one * * @param int $id Skill ID * @return self */ public function whereSkillID( $id ) { return $this->whereInt( $this->SKILL_ID, $id ); } + /** + * Where the Skill UID is the specified one + * + * @param string $uid Skill UID + * @return self + */ + public function whereSkillUID( $uid ) { + return $this->whereStr( 'skill_uid', $uid ); + } + } +/** + * Query a Skill + */ class QuerySkill extends Query { use QuerySkillTrait; /** * Univoque Skill ID column name */ protected $SKILL_ID = 'skill.skill_ID'; /** * Constructor * * @param DB $db Database connection */ public function __construct( $db = null ) { // set database and default result class parent::__construct( $db = null, Skill::class ); // set table FROM $this->from( Skill::T ); } }