Skip to content

Commit

Permalink
updater and admin space
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoc4 committed Dec 29, 2022
1 parent 715f4db commit 4feacbf
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 3 deletions.
61 changes: 61 additions & 0 deletions admin/music.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@
break;
case 've':
$pdo->exec("UPDATE `version` SET `name` = '".addslashes($_GET['name'])."', `number` = '".$_GET['number']."' WHERE `id_version` = '".$_GET['id_version']."';");
if(isset($_GET["soprano"])){
$pdo->exec("UPDATE `version` SET `soprano` = '1' WHERE `id_version` = ". $_GET['id_version']);
}else{
$pdo->exec("UPDATE `version` SET `soprano` = '0' WHERE `id_version` = ". $_GET['id_version']);
}
if(isset($_GET["alto"])){
$pdo->exec("UPDATE `version` SET `alto` = '1' WHERE `id_version` = ". $_GET['id_version']);
}else{
$pdo->exec("UPDATE `version` SET `alto` = '0' WHERE `id_version` = ". $_GET['id_version']);
}
if(isset($_GET["tenor"])){
$pdo->exec("UPDATE `version` SET `tenor` = '1' WHERE `id_version` = ". $_GET['id_version']);
}else{
$pdo->exec("UPDATE `version` SET `tenor` = '0' WHERE `id_version` = ". $_GET['id_version']);
}
if(isset($_GET["basse"])){
$pdo->exec("UPDATE `version` SET `basse` = '1' WHERE `id_version` = ". $_GET['id_version']);
}else{
$pdo->exec("UPDATE `version` SET `basse` = '0' WHERE `id_version` = ". $_GET['id_version']);
}
if(isset($_GET["tutti"])){
$pdo->exec("UPDATE `version` SET `tutti` = '1' WHERE `id_version` = ". $_GET['id_version']);
}else{
$pdo->exec("UPDATE `version` SET `tutti` = '0' WHERE `id_version` = ". $_GET['id_version']);
}
break;
case 'vd':
$version = $pdo->query("SELECT * FROM version WHERE `id_version` = '".$_GET['id_version']."' ")->fetch(PDO::FETCH_ASSOC);
Expand All @@ -58,6 +83,22 @@
}
if(move_uploaded_file($_FILES["version"]["tmp_name"], $target)){
$pdo->exec("INSERT INTO `version` (`name`, `id_music`, `url`, `number`) VALUES ('".addslashes($_POST['name'])."', '".$_GET['id']."', '".$music['directory'] . "/" . $_POST['name'] . ".mp3"."', '".$_POST['number']."');");
$id = $pdo->lastInsertId();
if(str_contains($_POST["name"], "SOPRANO")){
$pdo->exec("UPDATE `version` SET `soprano` = '1' WHERE `id_version` = ". $id);
}
if(str_contains($_POST["name"], "ALTO")){
$pdo->exec("UPDATE `version` SET `alto` = '1' WHERE `id_version` = ". $id);
}
if(str_contains($_POST["name"], "TENOR")){
$pdo->exec("UPDATE `version` SET `tenor` = '1' WHERE `id_version` = ". $id);
}
if(str_contains($_POST["name"], "BASSE")){
$pdo->exec("UPDATE `version` SET `basse` = '1' WHERE `id_version` = ". $id);
}
if(str_contains($_POST["name"], "TUTTI")){
$pdo->exec("UPDATE `version` SET `tutti` = '1' WHERE `id_version` = ". $id);
}
}else{
echo "Error";
}
Expand Down Expand Up @@ -132,6 +173,26 @@
<input type="hidden" value="<?php echo $version['id_version'] ?>" name="id_version">
<input type="text" required class="form-control" style="width: auto; display: inline;" name="name" value="<?php echo $version['name'] ?>" placeholder="Nom">
<input type="number" required class="form-control" style="width: auto; display: inline;" name="number" value="<?php echo $version['number'] ?>" placeholder="Ordre">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="soprano" name="soprano" <?php echo $version['soprano'] == 1 ? "checked" : "" ?>>
<label class="form-check-label" for="soprano">Soprano</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="alto" name="alto" <?php echo $version['alto'] == 1 ? "checked" : "" ?>>
<label class="form-check-label" for="alto">Alto</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="tenor" name="tenor" <?php echo $version['tenor'] == 1 ? "checked" : "" ?>>
<label class="form-check-label" for="tenor">Tenor</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="basse" name="basse" <?php echo $version['basse'] == 1 ? "checked" : "" ?>>
<label class="form-check-label" for="basse">Basse</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="tutti" name="tutti" <?php echo $version['tutti'] == 1 ? "checked" : "" ?>>
<label class="form-check-label" for="tutti">Tutti</label>
</div>
<input type="submit" class="btn btn-primary" value="Éditer">
<audio controls style="width: auto; display: inline; padding: .375rem .75rem;">
<source src="/files/<?php echo $version['url'] ?>" type="audio/mpeg">
Expand Down
2 changes: 1 addition & 1 deletion config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
echo 'Connexion échouée : ' . $e->getMessage();
}

$VERSION = 1;
$VERSION = 2;
if(!needsUpdate($pdo, $VERSION)){
$config = $pdo->query("SELECT * FROM config")->fetchAll(PDO::FETCH_ASSOC);

Expand Down
4 changes: 2 additions & 2 deletions updater/v1.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
echo "Updating DB";
echo "Updating DB<br>";
$pdo->exec(file_get_contents('v1.sql'));

echo "Updating file structure";
echo "Updating file structure<br>";
//create folders
$musics = $pdo->query("SELECT * FROM music")->fetchAll(PDO::FETCH_ASSOC);
foreach($musics as $music){
Expand Down
36 changes: 36 additions & 0 deletions updater/v2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
echo "Updating DB Structure<br>";
$pdo->exec(file_get_contents('v2.sql'));

echo "updating exsisting versions";
$orphean = array();
foreach($pdo->query("SELECT * FROM version")->fetchAll(PDO::FETCH_ASSOC) as $v){
$found=false;
if(str_contains($v["name"], "SOPRANO")){
$pdo->exec("UPDATE `version` SET `soprano` = '1' WHERE `id_version` = ". $v["id_version"]);
$found=true;
}
if(str_contains($v["name"], "ALTO")){
$pdo->exec("UPDATE `version` SET `alto` = '1' WHERE `id_version` = ". $v["id_version"]);
$found=true;
}
if(str_contains($v["name"], "TENOR")){
$pdo->exec("UPDATE `version` SET `tenor` = '1' WHERE `id_version` = ". $v["id_version"]);
$found=true;
}
if(str_contains($v["name"], "BASSE")){
$pdo->exec("UPDATE `version` SET `basse` = '1' WHERE `id_version` = ". $v["id_version"]);
$found=true;
}
if(str_contains($v["name"], "TUTTI")){
$pdo->exec("UPDATE `version` SET `tutti` = '1' WHERE `id_version` = ". $v["id_version"]);
$found=true;
}
if(!$found){
$orphean[] = $v["id_version"];
}
}
echo "<br><br>id not assigned:<pre>";
print_r($orphean);
echo "</pre>";

8 changes: 8 additions & 0 deletions updater/v2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE `version`
ADD `soprano` tinyint unsigned NOT NULL DEFAULT '0',
ADD `alto` tinyint unsigned NOT NULL DEFAULT '0' AFTER `soprano`,
ADD `tenor` tinyint unsigned NOT NULL DEFAULT '0' AFTER `alto`,
ADD `basse` tinyint unsigned NOT NULL DEFAULT '0' AFTER `tenor`,
ADD `tutti` tinyint unsigned NOT NULL DEFAULT '0' AFTER `basse`;

UPDATE `config` SET `value` = '2' WHERE `id_cfg` = '4';

0 comments on commit 4feacbf

Please sign in to comment.