Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Mathieu Loiseau
GameOfWords
Commits
68fb99d0
Commit
68fb99d0
authored
Apr 29, 2017
by
Mathieu Loiseau
Browse files
register with new scoring and stats
parent
45e15c44
Changes
5
Hide whitespace changes
Inline
Side-by-side
GoW.sql
View file @
68fb99d0
...
...
@@ -153,13 +153,13 @@ CREATE TABLE IF NOT EXISTS `sanctionCarte` (
-- Structure de la table `score`
--
CREATE
TABLE
IF
NOT
EXISTS
`score`
(
`scoreID`
int
(
11
)
NOT
NULL
AUTO_INCREMENT
,
CREATE
TABLE
`score`
(
`scoreID`
int
(
11
)
NOT
NULL
,
`userid`
int
(
11
)
NOT
NULL
,
`scoreGlobal`
int
(
11
)
NOT
NULL
,
`scoreOracle`
int
(
11
)
NOT
NULL
,
`scoreDruide`
int
(
11
)
NOT
NULL
,
`scoreDevin`
int
(
11
)
NOT
NULL
,
`scoreGlobal`
int
(
11
)
NOT
NULL
DEFAULT
'0'
,
`scoreOracle`
int
(
11
)
NOT
NULL
DEFAULT
'0'
,
`scoreDruide`
int
(
11
)
NOT
NULL
DEFAULT
'0'
,
`scoreDevin`
int
(
11
)
NOT
NULL
DEFAULT
'0'
,
`langue`
varchar
(
20
)
CHARACTER
SET
utf8
COLLATE
utf8_unicode_ci
NOT
NULL
,
`first_game_time`
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
PRIMARY
KEY
(
`scoreID`
)
...
...
@@ -286,6 +286,9 @@ INSERT INTO `user_niveau` (`id`, `userid`, `spoken_lang`, `niveau`) VALUES
(
1
,
1
,
'Français;'
,
'Natif;'
);
INSERT
INTO
`score`
(
`scoreID`
,
`userid`
,
`scoreGlobal`
,
`scoreOracle`
,
`scoreDruide`
,
`scoreDevin`
,
`langue`
,
`first_game_time`
)
VALUES
(
1
,
1
,
0
,
0
,
0
,
0
,
'Français'
,
CURRENT_TIMESTAMP
);
INSERT
INTO
`stats_devin`
(
`userid`
,
`langue`
,
`nbEnregistrements`
,
`nbMotsTrouves`
,
`score`
)
VALUES
(
'1'
,
'Français'
,
'0'
,
'0'
,
'0'
);
INSERT
INTO
`stats_druide`
(
`userid`
,
`langue`
,
`nbCartes`
,
`nbArbitrages`
,
`nbErrArbitrage`
,
`score`
)
VALUES
(
'1'
,
'Français'
,
'0'
,
'0'
,
'0'
,
'0'
);
INSERT
INTO
`stats_oracle`
(
`userid`
,
`langue`
,
`nbJeux`
,
`nbAbandons`
,
`nbEnregistrements`
,
`nbErreurs`
,
`nbLectures`
,
`nbSucces`
,
`score`
)
VALUES
(
'1'
,
'Français'
,
'0'
,
'0'
,
'0'
,
'0'
,
'0'
,
'0'
,
'0'
);
-- --------------------------------------------------------
...
...
controllers/register.class.php
View file @
68fb99d0
...
...
@@ -2,211 +2,194 @@
class
register
{
private
$submit
=
false
;
private
$username
=
''
;
private
$useremail
=
''
;
private
$password
=
''
;
private
$password_confirm
=
''
;
private
$photo
=
''
;
private
$userlang
=
''
;
private
$errors
=
array
();
private
$spoken_lang
=
''
;
private
$points_initiaux
=
0
;
private
$userid
=
0
;
private
$niveau
=
''
;
private
$GameLvl
=
''
;
private
$userlang_game
=
''
;
private
$mode
=
''
;
public
function
set_mode
(
$mode
)
{
$this
->
mode
=
$mode
;
}
public
function
process
()
{
if
(
$this
->
init
()
)
{
$this
->
check
();
$this
->
validate
();
return
$this
->
display
();
}
return
false
;
}
private
function
init
(){
require_once
(
'./sys/load_iso.php'
);
$lang_iso
=
new
IsoLang
();
$this
->
submit
=
isset
(
$_POST
[
'submit_form'
]);
if
(
$this
->
submit
)
{
include
(
'./sys/upload.php'
);
$this
->
photo
=
''
;
$upload
=
upload
(
$_POST
[
"profilphot"
],
'profil/'
,
3000000
,
array
(
'png'
,
'gif'
,
'jpg'
,
'jpeg'
),
$_POST
[
'username'
]
);
if
(
is_array
(
$upload
)){
$this
->
errors
=
$upload
;
}
else
{
$this
->
photo
=
$upload
;
}
$this
->
username
=
isset
(
$_POST
[
'username'
])
?
trim
(
$_POST
[
'username'
])
:
''
;
$this
->
useremail
=
isset
(
$_POST
[
'useremail'
])
?
trim
(
$_POST
[
'useremail'
])
:
''
;
$this
->
password
=
isset
(
$_POST
[
'userpass'
])
?
trim
(
$_POST
[
'userpass'
])
:
''
;
$this
->
password_confirm
=
isset
(
$_POST
[
'password_confirm'
])
?
trim
(
$_POST
[
'password_confirm'
])
:
''
;
$this
->
userlang
=
isset
(
$_POST
[
'userlang'
])
?
trim
(
$_POST
[
'userlang'
])
:
''
;
$this
->
GameLvl
=
isset
(
$_POST
[
'userlvl'
])
?
trim
(
$_POST
[
'userlvl'
])
:
''
;
$this
->
spoken_lang
=
''
;
for
(
$i
=
1
;
$i
<=
10
;
$i
++
)
{
private
$submit
=
false
;
private
$username
=
''
;
private
$useremail
=
''
;
private
$password
=
''
;
private
$password_confirm
=
''
;
private
$photo
=
''
;
private
$userlang
=
''
;
private
$errors
=
array
();
private
$spoken_lang
=
''
;
private
$userid
=
0
;
private
$niveau
=
''
;
private
$GameLvl
=
''
;
private
$userlang_game
=
''
;
private
$mode
=
''
;
public
function
set_mode
(
$mode
)
{
$this
->
mode
=
$mode
;
}
public
function
process
()
{
if
(
$this
->
init
()
)
{
$this
->
check
();
$this
->
validate
();
return
$this
->
display
();
}
return
false
;
}
private
function
init
(){
require_once
(
'./sys/load_iso.php'
);
$lang_iso
=
new
IsoLang
();
$this
->
submit
=
isset
(
$_POST
[
'submit_form'
]);
if
(
$this
->
submit
)
{
include
(
'./sys/upload.php'
);
$this
->
photo
=
''
;
$upload
=
upload
(
$_POST
[
"profilphot"
],
'profil/'
,
3000000
,
array
(
'png'
,
'gif'
,
'jpg'
,
'jpeg'
),
$_POST
[
'username'
]
);
if
(
is_array
(
$upload
)){
$this
->
errors
=
$upload
;
}
else
{
$this
->
photo
=
$upload
;
}
$this
->
username
=
isset
(
$_POST
[
'username'
])
?
trim
(
$_POST
[
'username'
])
:
''
;
$this
->
useremail
=
isset
(
$_POST
[
'useremail'
])
?
trim
(
$_POST
[
'useremail'
])
:
''
;
$this
->
password
=
isset
(
$_POST
[
'userpass'
])
?
trim
(
$_POST
[
'userpass'
])
:
''
;
$this
->
password_confirm
=
isset
(
$_POST
[
'password_confirm'
])
?
trim
(
$_POST
[
'password_confirm'
])
:
''
;
$this
->
userlang
=
isset
(
$_POST
[
'userlang'
])
?
trim
(
$_POST
[
'userlang'
])
:
''
;
$this
->
GameLvl
=
isset
(
$_POST
[
'userlvl'
])
?
trim
(
$_POST
[
'userlvl'
])
:
''
;
$this
->
spoken_lang
=
''
;
for
(
$i
=
1
;
$i
<=
10
;
$i
++
)
{
for
(
$j
=
$i
+
1
;
$j
<=
10
;
$j
++
){
if
(
isset
(
$_POST
[
'choix_langs_'
.
$i
])
&&
isset
(
$_POST
[
'choix_langs_'
.
$j
])
&&
$_POST
[
'choix_langs_'
.
$i
]
==
$_POST
[
'choix_langs_'
.
$j
]){
array_push
(
$this
->
errors
,
'same_lang'
);
break
;
}
}
if
(
isset
(
$_POST
[
'choix_langs_'
.
$i
])
&&
isset
(
$_POST
[
'choix_langs_'
.
$j
])
&&
$_POST
[
'choix_langs_'
.
$i
]
==
$_POST
[
'choix_langs_'
.
$j
]){
array_push
(
$this
->
errors
,
'same_lang'
);
break
;
}
}
$this
->
spoken_lang
.
=
isset
(
$_POST
[
'choix_langs_'
.
$i
])
?
trim
(
$_POST
[
'choix_langs_'
.
$i
])
.
';'
:
''
;
//$this->spoken_lang .= isset($_POST['choix_niveau_'.$i]) ? trim($_POST['choix_niveau_'.$i]).';' : '';
$this
->
niveau
.
=
isset
(
$_POST
[
'choix_niveau_'
.
$i
])
?
trim
(
$_POST
[
'choix_niveau_'
.
$i
])
.
';'
:
''
;
if
(
!
isset
(
$_POST
[
'choix_niveau_'
.
$i
]))
{
break
;
}
}
$this
->
userlang_game
=
isset
(
$_POST
[
'lang_game'
])
?
$lang_iso
->
language_code_for
(
trim
(
$_POST
[
'lang_game'
]))
:
''
;
}
return
true
;
}
private
function
check
()
{
$db
=
db
::
getInstance
();
if
(
!
$this
->
submit
)
{
return
false
;
}
if
(
empty
(
$this
->
username
)
)
{
array_push
(
$this
->
errors
,
'user_name'
);
}
if
(
empty
(
$this
->
useremail
)
)
{
array_push
(
$this
->
errors
,
'email'
);
}
if
(
empty
(
$this
->
password
)
)
{
array_push
(
$this
->
errors
,
'password'
);
}
if
(
empty
(
$this
->
password_confirm
)
)
{
array_push
(
$this
->
errors
,
'password_confirm'
);
}
if
(
empty
(
$this
->
userlang
)
)
{
array_push
(
$this
->
errors
,
'choose_lang'
);
}
// Vérification de l'unicité
if
(
!
$this
->
errors
)
{
$mailvalid
=
true
;
if
(
!
filter_var
(
$this
->
useremail
,
FILTER_VALIDATE_EMAIL
)
)
{
array_push
(
$this
->
errors
,
'invalid_email'
);
$mailvalid
=
false
;
}
if
(
$this
->
password
!=
$this
->
password_confirm
)
{
array_push
(
$this
->
errors
,
'invalid_password'
);
}
$sql
=
'SELECT *
FROM user
WHERE username = '
.
$db
->
escape
((
string
)
$this
->
username
)
.
(
!
$mailvalid
?
''
:
'
OR useremail = '
.
$db
->
escape
((
string
)
$this
->
useremail
)
);
$result
=
$db
->
query
(
$sql
);
$row
=
$result
->
fetch_assoc
();
$result
->
free
();
if
(
$row
)
{
array_push
(
$this
->
errors
,
'username_exist'
);
}
}
}
private
function
validate
()
{
$db
=
db
::
getInstance
();
}
$this
->
userlang_game
=
isset
(
$_POST
[
'lang_game'
])
?
$lang_iso
->
language_code_for
(
trim
(
$_POST
[
'lang_game'
]))
:
''
;
}
return
true
;
}
private
function
check
()
{
$db
=
db
::
getInstance
();
if
(
!
$this
->
submit
)
{
return
false
;
}
if
(
empty
(
$this
->
username
)
)
{
array_push
(
$this
->
errors
,
'user_name'
);
}
if
(
empty
(
$this
->
useremail
)
)
{
array_push
(
$this
->
errors
,
'email'
);
}
if
(
empty
(
$this
->
password
)
)
{
array_push
(
$this
->
errors
,
'password'
);
}
if
(
empty
(
$this
->
password_confirm
)
)
{
array_push
(
$this
->
errors
,
'password_confirm'
);
}
if
(
empty
(
$this
->
userlang
)
)
{
array_push
(
$this
->
errors
,
'choose_lang'
);
}
// Vérification de l'unicité
if
(
!
$this
->
errors
)
{
$mailvalid
=
true
;
if
(
!
filter_var
(
$this
->
useremail
,
FILTER_VALIDATE_EMAIL
)
)
{
array_push
(
$this
->
errors
,
'invalid_email'
);
$mailvalid
=
false
;
}
if
(
$this
->
password
!=
$this
->
password_confirm
)
{
array_push
(
$this
->
errors
,
'invalid_password'
);
}
$sql
=
'SELECT *
FROM user
WHERE username = '
.
$db
->
escape
((
string
)
$this
->
username
)
.
(
!
$mailvalid
?
''
:
'
OR useremail = '
.
$db
->
escape
((
string
)
$this
->
useremail
)
);
$result
=
$db
->
query
(
$sql
);
$row
=
$result
->
fetch_assoc
();
$result
->
free
();
if
(
$row
)
{
array_push
(
$this
->
errors
,
'username_exist'
);
}
}
}
private
function
validate
(){
$db
=
db
::
getInstance
();
// Mise à jour de la bdd
if
(
!
$this
->
submit
||
$this
->
errors
)
{
return
false
;
}
$sql
=
'INSERT INTO user
(username, useremail, userpass, userlang, userlang_game, photo, userlvl)
VALUES('
.
$db
->
escape
((
string
)
$this
->
username
)
.
', '
.
$db
->
escape
((
string
)
$this
->
useremail
)
.
', '
.
$db
->
escape
((
string
)
md5
(
$this
->
password
))
.
', '
.
//spoken_lang = ' . $db->escape((string) $this->spoken_lang) . ',
$db
->
escape
((
string
)
$this
->
userlang
)
.
','
.
$db
->
escape
((
string
)
$this
->
userlang_game
)
.
','
.
$db
->
escape
((
string
)
$this
->
photo
)
.
','
.
$db
->
escape
((
string
)
$this
->
GameLvl
)
.
')'
;
$db
->
query
(
$sql
);
// ajout d'une ligne correspondante dans la table score
//selection de l'id de l'utilisateur
$sql
=
'SELECT userid
FROM user WHERE username="'
.
$this
->
username
.
'"'
;
$result
=
$db
->
query
(
$sql
);
$res
=
mysqli_fetch_assoc
(
$result
);
$this
->
userid
=
$res
[
'userid'
];
//ajout des langues parlées dans la table user_niveau
$sql
=
'INSERT INTO user_niveau
(userid, spoken_lang, niveau)
VALUES('
.
$db
->
escape
((
string
)
$this
->
userid
)
.
', '
.
$db
->
escape
((
string
)
$this
->
spoken_lang
)
.
', '
.
$db
->
escape
((
string
)
$this
->
niveau
)
.
')'
;
$db
->
query
(
$sql
);
//insertion dans la table score
$spoken_langg
=
explode
(
';'
,
$this
->
spoken_lang
);
foreach
(
$spoken_langg
as
$key
){
if
(
$key
!=
""
){
$sql
=
'INSERT INTO score
(userid, scoreGlobal, scoreOracle, scoreDruide, scoreDevin, langue)
VALUES('
.
$db
->
escape
((
string
)
$this
->
userid
)
.
', '
.
$db
->
escape
((
string
)
$this
->
points_initiaux
)
.
', '
.
$db
->
escape
((
string
)
$this
->
points_initiaux
)
.
', '
.
$db
->
escape
((
string
)
$this
->
points_initiaux
)
.
', '
.
$db
->
escape
((
string
)
$this
->
points_initiaux
)
.
', '
.
$db
->
escape
((
string
)
$key
)
.
')'
;
$db
->
query
(
$sql
);
}
}
redirect
(
''
);
}
private
function
display
()
{
include
(
'./views/register.form.html'
);
return
true
;
}
if
(
!
$this
->
submit
||
$this
->
errors
){
return
false
;
}
$sql
=
array
();
array_push
(
$sql
,
'INSERT INTO user (username, useremail, userpass, userlang, userlang_game, photo, userlvl)
VALUES('
.
$db
->
escape
((
string
)
$this
->
username
)
.
', '
.
$db
->
escape
((
string
)
$this
->
useremail
)
.
', '
.
$db
->
escape
((
string
)
md5
(
$this
->
password
))
.
', '
.
$db
->
escape
((
string
)
$this
->
userlang
)
.
','
.
$db
->
escape
((
string
)
$this
->
userlang_game
)
.
','
.
$db
->
escape
((
string
)
$this
->
photo
)
.
','
.
$db
->
escape
((
string
)
$this
->
GameLvl
)
.
');'
);
array_push
(
$sql
,
"SET @USER_ID = LAST_INSERT_ID();"
);
//ajout des langues parlées dans la table user_niveau
array_push
(
$sql
,
"INSERT INTO user_niveau (userid, spoken_lang, niveau)
VALUES(@USER_ID, "
.
$db
->
escape
((
string
)
$this
->
spoken_lang
)
.
", "
.
$db
->
escape
((
string
)
$this
->
niveau
)
.
");"
);
//insertion pour les scores et stats
$spoken_langg
=
explode
(
';'
,
$this
->
spoken_lang
);
foreach
(
$spoken_langg
as
$key
){
if
(
$key
!=
""
){
array_push
(
$sql
,
'INSERT INTO `score` (`userid`, `langue`)'
.
"VALUES(@USER_ID,"
.
$db
->
escape
((
string
)
$key
)
.
");"
);
array_push
(
$sql
,
"INSERT INTO `stats_devin` (`userid`, `langue`)
VALUES(@USER_ID,"
.
$db
->
escape
((
string
)
$key
)
.
");"
);
array_push
(
$sql
,
"INSERT INTO `stats_druide` (`userid`, `langue`)
VALUES(@USER_ID,"
.
$db
->
escape
((
string
)
$key
)
.
");"
);
array_push
(
$sql
,
"INSERT INTO `stats_oracle` (`userid`, `langue`)
VALUES(@USER_ID,"
.
$db
->
escape
((
string
)
$key
)
.
");"
);
}
}
array_push
(
$sql
,
"SELECT @USER_ID as `id`;"
);
try
{
if
(
$db
->
transaction
(
$sql
)){
$this
->
userid
=
$db
->
fetch_object
()
->
id
;
redirect
(
''
);
}
}
catch
(
Exception
$e
){
echo
$e
;
return
false
;
}
}
private
function
display
()
{
include
(
'./views/register.form.html'
);
return
true
;
}
}
?>
models/recording.class.php
View file @
68fb99d0
...
...
@@ -19,10 +19,10 @@ class Recording
public
function
__construct
(
$rec_id
){
$this
->
db
=
db
::
getInstance
();
$this
->
id
=
$rec_id
;
$this
->
db
->
query
(
"SELECT `idOracle`,`
O
racleLang`,`nivpartie`,`nivcarte`,`carteID` FROM `enregistrement` WHERE `enregistrementID`='
$this->id
';"
);
$this
->
db
->
query
(
"SELECT `idOracle`,`
o
racleLang`,`nivpartie`,`nivcarte`,`carteID` FROM `enregistrement` WHERE `enregistrementID`='
$this->id
';"
);
if
(
$this
->
db
->
affected_rows
()
==
1
){
$tmpObj
=
$this
->
db
->
fetch_object
();
$this
->
lang
=
$tmpObj
->
O
racleLang
;
$this
->
lang
=
$tmpObj
->
o
racleLang
;
$this
->
level
=
$tmpObj
->
nivpartie
;
$this
->
card_level
=
$tmpObj
->
nivcarte
;
$this
->
oracle_id
=
$tmpObj
->
idOracle
;
...
...
save.php
View file @
68fb99d0
...
...
@@ -60,8 +60,9 @@ foreach(array('audio') as $type) {
$mp3_file
=
new
MP3File
(
"./enregistrements/
$fileName
"
);
$duration
=
$mp3_file
->
getDuration
();
}
//TODO update d'après structure BD (et l'enregistrement au début du recording → UPDATE)
$sql
=
'INSERT INTO enregistrement
(`cheminEnregistrement`,`idOracle`,`
O
racleLang`,`carteID`,`nivcarte`,`duration`,`nivpartie`)
(`cheminEnregistrement`,`idOracle`,`
o
racleLang`,`carteID`,`nivcarte`,`duration`,`nivpartie`)
VALUES('
.
$db
->
escape
(
$fileName
)
.
','
.
$_GET
[
"userid"
]
.
','
.
$_GET
[
"gamelang"
]
.
','
.
...
...
sys/db.class.php
View file @
68fb99d0
...
...
@@ -58,6 +58,22 @@ class db
return
$this
->
result
;
}
public
function
transaction
(
$query_array
){
$this
->
handler
->
begin_transaction
();
$i
=
1
;
foreach
(
$query_array
as
$query
)
{
$this
->
query
(
$query
);
if
(
!
$this
->
result
){
$commit
=
false
;
$this
->
handler
->
rollback
();
throw
new
Exception
(
"Error “"
.
$this
->
handler
->
error
.
"” in “"
.
$query
.
"” (query #"
.
$i
.
")."
);
}
$i
++
;
}
$this
->
handler
->
commit
();
return
$this
->
result
;
}
public
function
fetch_object
(){
if
(
$this
->
result
){
return
$this
->
result
->
fetch_object
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment