Skip to content

Commit

Permalink
Merge pull request #156 from vittodevit/master
Browse files Browse the repository at this point in the history
  • Loading branch information
vittodevit authored Jun 9, 2024
2 parents b6b620b + fc70d55 commit e19625d
Show file tree
Hide file tree
Showing 38 changed files with 25,517 additions and 485 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ project.xml
/tests/installer-*.php
unikey.txt
.devmode
node_modules
node_modules
/annuario/storage/a_*
355 changes: 181 additions & 174 deletions alunni/vis_alu.php

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions alunni/vis_alu_cla.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,33 @@
$sql = "SELECT * FROM tbl_classi ORDER BY specializzazione, sezione, anno";
$res = eseguiQuery($con, $sql);

print "<center><br><a class='btn btn-outline-secondary' href='vis_alu_ins.php'>Inserisci nuovo alunno senza classe</a></center><br/>";
print "<form method='POST' action='vis_alu.php' name='alunni'>";
print "<br><form method='POST' action='vis_alu.php' name='alunni'>";
print "<center>";
print "<div style='max-width: 300px'> <select class='form-select' name='idcla' ONCHANGE='alunni.submit()'><option value=''>&nbsp;</option></div>";
print "<div class='mb-2'>Seleziona classe: </div>";
print "<div style='max-width: 350px'> <select class='form-select' name='idcla' ONCHANGE='alunni.submit()'><option value=''>&nbsp;</option></div>";
while ($dati = mysqli_fetch_array($res))
{
//print("<tr> <td> <font size='3'> <a href='vis_alu.php?idcla=".$dati['idclasse']."'> ".$dati['anno']." ".$dati['sezione']." ".$dati['specializzazione']." </a> </font> </td> </tr>");
print("<option value='" . $dati['idclasse'] . "'> " . $dati['anno'] . " " . $dati['sezione'] . " " . $dati['specializzazione'] . " </option>");
}
print "<option value='0'>Senza classe</option>";
print "</select>";

print "</form>";

?>
<center>
<br> oppure <br> <br>
<a class='btn btn-outline-secondary mb-3' href='vis_alu_ins.php'>
<i class='bi bi-person-plus'></i>
Inserisci nuovo alunno senza classe
</a>
<a class='btn btn-outline-secondary' href='vis_alu_ricerca.php'>
<i class='bi bi-search'></i>
Ricerca alunni
</a> <br>
</center>
<br/>
<?php

mysqli_close($con);
stampa_piede_new("");

Expand Down
322 changes: 218 additions & 104 deletions alunni/vis_alu_ricerca.php

Large diffs are not rendered by default.

44 changes: 44 additions & 0 deletions annuario/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/*
Copyright (C) 2024 Vittorio Lo Mele
Questo programma è un software libero; potete redistribuirlo e/o modificarlo secondo i termini della
GNU Affero General Public License come pubblicata
dalla Free Software Foundation; sia la versione 3,
sia (a vostra scelta) ogni versione successiva.
Questo programma è distribuito nella speranza che sia utile
ma SENZA ALCUNA GARANZIA; senza anche l'implicita garanzia di
POTER ESSERE VENDUTO o di IDONEITA' A UN PROPOSITO PARTICOLARE.
Vedere la GNU Affero General Public License per ulteriori dettagli.
Dovreste aver ricevuto una copia della GNU Affero General Public License
in questo programma; se non l'avete ricevuta, vedete http://www.gnu.org/licenses/
*/

$NG_API_ABIL = "MASP";
$NG_API_JSON = true;

require_once '../lib/ng_api_init.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id'])) {
$idFoto = $con->real_escape_string($_POST['id']);
$foto = mysqli_fetch_assoc(eseguiQuery($con, "SELECT * FROM tbl_fotoannuario WHERE id_foto = $idFoto"));

if(!$foto) {
error_response(404, "Foto non trovata");
} else {
$defImgPath = './storage/a_' . $foto['hash'];
unlink($defImgPath);
eseguiQuery($con, "DELETE FROM tbl_fotoannuario WHERE id_foto = $idFoto");
json_response(200, "Foto eliminata");
}

} else {
error_response(400, "Richiesta non valida");
}
} else {
error_response(405, "Method Not Allowed");
}

mysqli_close($con);
37 changes: 37 additions & 0 deletions annuario/get_pic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/*
Copyright (C) 2024 Vittorio Lo Mele
Questo programma è un software libero; potete redistribuirlo e/o modificarlo secondo i termini della
GNU Affero General Public License come pubblicata
dalla Free Software Foundation; sia la versione 3,
sia (a vostra scelta) ogni versione successiva.
Questo programma è distribuito nella speranza che sia utile
ma SENZA ALCUNA GARANZIA; senza anche l'implicita garanzia di
POTER ESSERE VENDUTO o di IDONEITA' A UN PROPOSITO PARTICOLARE.
Vedere la GNU Affero General Public License per ulteriori dettagli.
Dovreste aver ricevuto una copia della GNU Affero General Public License
in questo programma; se non l'avete ricevuta, vedete http://www.gnu.org/licenses/
*/

$NG_API_ABIL = "SKIP";
$NG_API_JSON = true;

require_once '../lib/ng_api_init.php';

$path = "";

if (isset($_GET['hash']) && $_GET['hash'] != "") {
if (file_exists('./storage/a_' . $_GET['hash'])) {
$path = './storage/a_' . $_GET['hash'];
} else {
$path = './storage/default.webp';
}
} else {
$path = './storage/default.webp';
}

header('Content-Type: image/webp');
readfile($path);
mysqli_close($con);
2 changes: 2 additions & 0 deletions annuario/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html><title></title>

57 changes: 57 additions & 0 deletions annuario/metadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/*
Copyright (C) 2024 Vittorio Lo Mele
Questo programma è un software libero; potete redistribuirlo e/o modificarlo secondo i termini della
GNU Affero General Public License come pubblicata
dalla Free Software Foundation; sia la versione 3,
sia (a vostra scelta) ogni versione successiva.
Questo programma è distribuito nella speranza che sia utile
ma SENZA ALCUNA GARANZIA; senza anche l'implicita garanzia di
POTER ESSERE VENDUTO o di IDONEITA' A UN PROPOSITO PARTICOLARE.
Vedere la GNU Affero General Public License per ulteriori dettagli.
Dovreste aver ricevuto una copia della GNU Affero General Public License
in questo programma; se non l'avete ricevuta, vedete http://www.gnu.org/licenses/
*/

$NG_API_ABIL = "MASP";
$NG_API_JSON = true;

require_once '../lib/ng_api_init.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (
($_POST['tipoFoto'] == "alunno" ||
$_POST['tipoFoto'] == "classe") &&
isset($_POST['id'])
) {
$idFoto = 0;
if ($_POST['tipoFoto'] == "alunno") {
$idFoto = mysqli_fetch_assoc(eseguiQuery($con, "SELECT idfotoannuario FROM tbl_alunni WHERE idalunno = " . $_POST['id']))['idfotoannuario'];
} else {
$idFoto = mysqli_fetch_assoc(eseguiQuery($con, "SELECT idfotoannuario FROM tbl_classi WHERE idclasse = " . $_POST['id']))['idfotoannuario'];
}

$foto = mysqli_fetch_assoc(eseguiQuery($con, "SELECT * FROM tbl_fotoannuario WHERE id_foto = $idFoto"));

if(!$foto) {
error_response(404, "Foto non trovata");
} else {
$data = [
'id' => $foto['id_foto'],
'didascalia' => $foto['didascalia'],
'hash' => $foto['hash']
];

json_response(200, $data);
}

} else {
error_response(400, "Richiesta non valida");
}
} else {
error_response(405, "Method Not Allowed");
}

mysqli_close($con);
Binary file added annuario/storage/default.webp
Binary file not shown.
84 changes: 84 additions & 0 deletions annuario/upload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/*
Copyright (C) 2024 Vittorio Lo Mele
Questo programma è un software libero; potete redistribuirlo e/o modificarlo secondo i termini della
GNU Affero General Public License come pubblicata
dalla Free Software Foundation; sia la versione 3,
sia (a vostra scelta) ogni versione successiva.
Questo programma è distribuito nella speranza che sia utile
ma SENZA ALCUNA GARANZIA; senza anche l'implicita garanzia di
POTER ESSERE VENDUTO o di IDONEITA' A UN PROPOSITO PARTICOLARE.
Vedere la GNU Affero General Public License per ulteriori dettagli.
Dovreste aver ricevuto una copia della GNU Affero General Public License
in questo programma; se non l'avete ricevuta, vedete http://www.gnu.org/licenses/
*/

$NG_API_ABIL = "MASP";
$NG_API_JSON = true;

require_once '../lib/ng_api_init.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (
isset($_FILES['image']) &&
$_FILES['image']['error'] === UPLOAD_ERR_OK &&
isset($_POST['tipoFoto']) &&
isset($_POST['id']) &&
(
$_POST['tipoFoto'] == "alunno"
|| $_POST['tipoFoto'] == "classe"
)
){

$tmpFilePath = $_FILES['image']['tmp_name'];
$caption = $con->real_escape_string($_POST['caption']);
$hash = md5_file($tmpFilePath);
$defImgPath = './storage/a_' . $hash;

if (file_exists($defImgPath)) {
unlink($defImgPath);
}

if (!move_uploaded_file($tmpFilePath, $defImgPath)) {
error_response(500, "Errore durante il salvataggio dell'immagine");
}

$image = imagecreatefromstring(file_get_contents($defImgPath));

if ($image === false) {
unlink($defImgPath);
error_response(500, "Errore durante il caricamento dell'immagine");
}

unlink($defImgPath);

if (!imagewebp($image, $defImgPath)) {
error_response(500, "Errore durante la conversione dell'immagine");
}

// salva immagine a db
$res = eseguiQuery($con, "INSERT INTO tbl_fotoannuario (hash, didascalia) VALUES ('$hash', '$caption')");
$last_insert_id = mysqli_insert_id($con);
$id = $con->real_escape_string($_POST['id']);
if ($_POST['tipoFoto'] == "alunno") {
$res = $res && eseguiQuery($con, "UPDATE tbl_alunni SET idfotoannuario = $last_insert_id WHERE idalunno = $id");
} else {
$res = $res && eseguiQuery($con, "UPDATE tbl_classi SET idfotoannuario = $last_insert_id WHERE idclasse = $id");
}

if ($res == true) {
json_response(200, "Immagine caricata con successo");
} else {
unlink($defImgPath);
error_response(500, "Errore durante il salvataggio su database");
}
} else {
error_response(400, "Richiesta non valida");
}
} else {
error_response(405, "Method Not Allowed");
}

mysqli_close($con);
Loading

0 comments on commit e19625d

Please sign in to comment.