Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stephane Crozat
apisub
Commits
092297a1
Unverified
Commit
092297a1
authored
Nov 07, 2018
by
Rémy Huet
💻
Browse files
Separate database management from views
parent
9c4e11c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
index.php
View file @
092297a1
...
...
@@ -23,9 +23,11 @@ if (!isset($_SESSION['ticket'])) {
}
include
$_SERVER
[
'DOCUMENT_ROOT'
]
.
'/apisub/lib/db.php'
;
include
'lib/views.php'
;
$db
=
new
DB
();
$db
->
printHtmlBegin
();
$db
->
printUser
(
$_SESSION
[
'utclogin'
],
$_SESSION
[
'surname'
],
$_SESSION
[
'firstname'
]);
Views
::
printHtmlBegin
();
Views
::
printUser
(
$_SESSION
[
'utclogin'
],
$_SESSION
[
'surname'
],
$_SESSION
[
'firstname'
]);
if
(
isset
(
$_GET
[
'api'
])
&&
isset
(
$_GET
[
'utclogin'
]))
{
if
(
isset
(
$_GET
[
'action'
]))
{
...
...
@@ -38,7 +40,7 @@ if (isset($_GET['api']) && isset($_GET['utclogin'])) {
}
}
$db
->
subList
(
$_SESSION
[
'utclogin'
]);
$db
->
apiList
(
$_SESSION
[
'utclogin'
]
,
'H'
,
2019
);
Views
::
printSubList
(
$db
->
subList
(
$_SESSION
[
'utclogin'
]),
$_SESSION
[
'utclogin'
]);
Views
::
printApiList
(
$db
->
apiList
(
'H'
,
2019
),
$_SESSION
[
'utclogin'
]);
?>
lib/db.php
View file @
092297a1
...
...
@@ -13,59 +13,26 @@ class DB {
}
}
public
function
printHtmlBegin
()
{
echo
'<html>'
;
echo
'<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>'
;
echo
'<title>Api Sub</title>'
;
echo
'<link href="css/main.css" type="text/css" rel="stylesheet"/>'
;
echo
'<body>'
;
echo
'<h1>Inscriptions Api</h1>'
;
}
function
printUser
(
$utclogin
,
$surname
,
$firstname
)
{
echo
'<p><i>'
.
$firstname
.
' '
.
$surname
.
'</i> (<b>'
.
$utclogin
.
'</b>)</p>'
;
}
function
subList
(
$utclogin
)
{
function
subList
(
string
$utclogin
)
:
array
{
$sql
=
"SELECT *
FROM vsubscription
WHERE utclogin='"
.
$utclogin
.
"'"
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
();
$res
=
$st
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
if
(
$res
)
{
echo
'<h2>Vos inscriptions</h2>'
;
foreach
(
$res
as
$row
)
{
echo
'<p>'
;
echo
' <a href="index.php?action=unsub&api='
.
$row
[
'code'
]
.
'&utclogin='
.
$utclogin
.
'">[désinscription]</a> '
;
echo
$row
[
'code'
]
.
"-"
.
$row
[
'name'
]
.
" ("
.
$row
[
'semester'
]
.
$row
[
'year'
]
.
", du "
.
$row
[
'dbegin'
]
.
" au "
.
$row
[
'dend'
]
.
") [inscrit le "
.
$row
[
'subdate'
]
.
"]"
;
echo
'</p>'
;
}
}
else
{
echo
'<h2>Aucune inscription</h2>'
;
}
return
$res
;
}
function
apiList
(
$utclog
in
,
$semester
,
$year
)
{
function
apiList
(
str
in
g
$semester
,
int
$year
)
:
array
{
$sql
=
"SELECT *
FROM vApi
WHERE semester='"
.
$semester
.
"' AND year="
.
$year
;
$st
=
$this
->
conn
->
prepare
(
$sql
);
$st
->
execute
();
$res
=
$st
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
if
(
$res
)
{
echo
'<h2>Liste des Api '
.
$semester
.
$year
.
'</h2>'
;
foreach
(
$res
as
$row
)
{
echo
'<p>'
;
echo
'<a href="index.php?action=sub&api='
.
$row
[
'code'
]
.
'&utclogin='
.
$utclogin
.
'">[inscription]</a> '
;
echo
$row
[
'code'
]
.
"-"
.
$row
[
'name'
];
echo
'</p>'
;
}
}
else
{
echo
'<h2>Aucune Api</h2>'
;
}
return
$res
;
}
function
subToApi
(
$utclogin
,
$api
)
{
...
...
lib/views.php
0 → 100644
View file @
092297a1
<?php
class
Views
{
public
static
function
printHtmlBegin
()
:
void
{
echo
'<html>'
;
echo
'<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/></head>'
;
echo
'<title>Api Sub</title>'
;
echo
'<link href="css/main.css" type="text/css" rel="stylesheet"/>'
;
echo
'<body>'
;
echo
'<h1>Inscriptions Api</h1>'
;
}
public
static
function
printUser
(
string
$utclogin
,
string
$surname
,
string
$firstname
)
:
void
{
echo
'<p><i>'
.
$firstname
.
' '
.
$surname
.
'</i> (<b>'
.
$utclogin
.
'</b>)</p>'
;
}
public
static
function
printSubList
(
array
$list
,
string
$utclogin
)
:
void
{
if
(
$list
)
{
echo
'<h2>Vos inscriptions</h2>'
;
foreach
(
$list
as
$row
)
{
echo
'<p>'
;
echo
' <a href="index.php?action=unsub&api='
.
$row
[
'code'
]
.
'&utclogin='
.
$utclogin
.
'">[désinscription]</a> '
;
echo
$row
[
'code'
]
.
"-"
.
$row
[
'name'
]
.
" ("
.
$row
[
'semester'
]
.
$row
[
'year'
]
.
", du "
.
$row
[
'dbegin'
]
.
" au "
.
$row
[
'dend'
]
.
") [inscrit le "
.
$row
[
'subdate'
]
.
"]"
;
echo
'</p>'
;
}
}
else
{
echo
'<h2>Aucune inscription</h2>'
;
}
}
public
static
function
printApiList
(
array
$list
,
string
$utclogin
)
:
void
{
if
(
$list
)
{
echo
'<h2>Liste des Api '
.
$semester
.
$year
.
'</h2>'
;
foreach
(
$list
as
$row
)
{
echo
'<p>'
;
echo
'<a href="index.php?action=sub&api='
.
$row
[
'code'
]
.
'&utclogin='
.
$utclogin
.
'">[inscription]</a> '
;
echo
$row
[
'code'
]
.
"-"
.
$row
[
'name'
];
echo
'</p>'
;
}
}
else
{
echo
'<h2>Aucune Api</h2>'
;
}
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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