Commit e2499b70 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

oracle traces → OK

parent 5664004c
......@@ -80,9 +80,8 @@ CREATE TABLE `enregistrement` (
`nbTentatives` smallint(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Combien de fois l''enregistrement a été passé à un devin',
`mise` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'La mise calculée en fonction du niveau de la carte du joueur et de la difficulté choisie',
PRIMARY KEY (`enregistrementID`),
UNIQUE KEY `cheminEnregistrement` (`cheminEnregistrement`),
KEY `idOracle` (`idOracle`),
KEY `carteID` (`carteID`)
UNIQUE KEY `no_replay` (`OracleLang`,`carteID`),
KEY `cheminEnregistrement` (`cheminEnregistrement`) USING BTREE;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
......
......@@ -6,6 +6,7 @@ require_once('./models/card.class.php');
require_once('./sys/load_iso.php');
require_once('./models/userlvl.class.php');
/**/require_once("./controllers/update_score_coeff.php");/**///transition to new scoreHandler
/**/require_once("./debug.php");
class ScoreHandler2{
private $db;
......@@ -47,10 +48,9 @@ class ScoreHandler2{
$gameLevel."','given up', '".
$this->gh->get_stake($gameLevel, $card->get_level(), $user_level).
"');";
//ICITE j'en suis là et il faudrait que je fasse 1/3 de la somme des stakes de ceux qui sont given-up ou mieux…
if(!$this->db->query($query)){
$res = false;
throw new Exception("“$query” could not be performed.");
throw new Exception("“".$query."” could not be performed.\n".$this->db->get_error());
}
else{
$res = true;
......@@ -58,5 +58,31 @@ class ScoreHandler2{
return $res;
}
public function post_record($cardId, $rec_path, $rec_length){
$query = "UPDATE `enregistrement` SET `cheminEnregistrement` = '$rec_path', `duration`='$rec_length', `tpsEnregistrement`=CURRENT_TIMESTAMP, `validation` = 'limbo' WHERE `enregistrement`.`idOracle` = ".$this->user->id." AND `enregistrement`.`carteID`='$cardId'; ";
if(!$this->db->query($query)){
$res = false;
throw new Exception("“".$query."” could not be performed.\n".$this->db->get_error());
}
else{
$res = true;
}
return $res;
}
public function abort_record($recording_path){
$query = "UPDATE `enregistrement` SET `validation` = 'given up', `tpsEnregistrement`=CURRENT_TIMESTAMP WHERE `enregistrement`.`cheminEnregistrement` = '$recording_path'; ";
if(!$this->db->query($query)){
$res = false;
throw new Exception("“".$query."” could not be performed.\n".$this->db->get_error());
}
elseif ($this->db->affected_rows != 1) {
$res = false;
throw new Exception("“".$query."” affected ".$this->db->affected_rows.".\nDatabase consistence jeopardized");
}
else{
$res = true;
}
return $res;
}
}?>
......@@ -143,7 +143,7 @@ var gamelevel = $("#level").attr("data-gamelevel");
var levelcard = $("#level").attr("data-levelcard");
// POST the Blob using XHR2
xhr('save.php?userid="'+userid+'"&userlang="'+userlang+'"&gamelang="'+gamelang+'"&cardid="'+cardid+'"&levelcard="'+levelcard+'"'+'&gamelevel="'+gamelevel+'"', formData, progress, percentage, function(fileURL) {
xhr('save.php?cardid='+cardid, formData, progress, percentage, function(fileURL) {
var href = location.href.substr(0, location.href.lastIndexOf('/') + 1);
progress.parentNode.removeChild(progress);
strong.parentNode.removeChild(strong);
......
<?php
require('./sys/config.php');
require_once('./sys/db.class.php');
require_once("./controllers/score.handler.class.php");
$ext = ".mp3";
//script pour supprimer le fichier sur le serveur
if (isset($_POST['delete-file'])) {
$fileName = 'enregistrements/'.$_POST['delete-file'];
if($conversion!==false){
//#format
if(!unlink($fileName.'.mp3')) {
echo $fileName;
echo(' problem deleting files.');
}
else {
echo(' both wav/webm files deleted successfully.');
}
//script pour supprimer le fichier sur le serveur
if (isset($_POST['delete-file'])) {
$fileName = 'enregistrements/'.$_POST['delete-file'];
if($conversion!==false){
//#format
if(!unlink($fileName.'.mp3')) {
echo $fileName;
echo(' problem deleting files.');
}
else{
$ext = ".ogg";
if(!unlink($fileName.'.ogg')) {
echo $fileName;
echo(' problem deleting files.');
}
else {
echo(' both wav/webm files deleted successfully.');
}
else {
$full_name = $_POST['delete-file'].".mp3";
echo(' both wav/webm files deleted successfully.');
}
//connexion à la BD et suppression de la ligne de l'enregistrement
$db=db::getInstance();
$sql = 'DELETE FROM enregistrement
WHERE (cheminEnregistrement=\''.$_POST['delete-file'].$ext.'\')';
$db->query($sql);
//suppression du fichier dans la serveur
}
else{
$ext = ".ogg";
if(!unlink($fileName.'.ogg')) {
echo $fileName;
echo(' problem deleting files.');
}
else {
$full_name = $_POST['delete-file'].".ogg";
echo(' both wav/webm files deleted successfully.');
}
}
$sh = new ScoreHandler2();
$sh->abort_record($full_name);
}
?>
<?php
session_start();
require_once('./sys/config.php');
require_once('./sys/db.class.php');
require_once("./controllers/score.handler.class.php");
function audio_convert($file, $filename){
$commandeConv = str_replace(array("%source%", "%target%"), array("./enregistrements/".$filename.".ogg","./enregistrements/".$filename.".mp3"), $file);
return $commandeConv;
}
$fileName = '';
$ext = ".ogg";
$db=db::getInstance();
foreach(array('audio') as $type) {
if (isset($_FILES["audio-blob"])) {
......@@ -18,32 +24,21 @@ foreach(array('audio') as $type) {
// récupère dans un tableau de hachage le nom du fichier sans l'extension, l'extension et le chemin
$file = pathinfo('./enregistrements/'.$fileName);
// convertit en mp3
if($conversion!==false){
//#format
if($conversion=="mp3"){
$conversion = "avconv -i %source% -acodec libmp3lame -q:a 2 -ac 1 %target%";
}
$commande = audio_convert($conversion, $file['filename']);
exec($commande);
// Supression du fichier.wav du serveur.
exec("rm ./enregistrements/".$file['filename'].".ogg");
$ext = ".mp3";
echo $file['filename'].$ext;
echo $commande;
}
else{
echo $file['filename'].$ext;
}
if($conversion!==false){
//#format
if($conversion=="mp3"){
$conversion = "avconv -i %source% -acodec libmp3lame -q:a 2 -ac 1 %target%";
}
$commande = audio_convert($conversion, $file['filename']);
exec($commande);
// Supression du fichier.wav du serveur.
exec("rm ./enregistrements/".$file['filename'].".ogg");
$ext = ".mp3";
}
// ajout 15/02
//$_SESSION['userid']=$userid;
//enregistrement dans la BD de la partie de l'oracle
if($fileName!='')
//$userid = $_POST["filename"];
......@@ -60,23 +55,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`,`oracleLang`,`carteID`,`nivcarte`,`duration`,`nivpartie`)
VALUES('.$db->escape($fileName).','.
$_GET["userid"]. ','.
$_GET["gamelang"]. ','.
$_GET["cardid"]. ','.
$_GET["levelcard"].','.
$duration.','.
$_GET['gamelevel'].')';
$db->query($sql);
$sh = new ScoreHandler2();
$sh->post_record($_GET["cardid"], $fileName, $duration);
echo $fileName;
}
}
function audio_convert($file, $filename){
$commandeConv = str_replace(array("%source%", "%target%"), array("./enregistrements/".$filename.".ogg","./enregistrements/".$filename.".mp3"), $file);
return $commandeConv;
}
?>
......@@ -32,14 +32,19 @@ else{
$msg.="see_card";
}
break;
default ;
case "post_record":
//not done through here (see ./save.php)
case "abort_record":
//not done through here (see ./delete.php)
default :
$msg = $lang["AJAX_noquery"];
}
}
echo json_encode(array(
"status" => $res,
"msg" => $msg
));
if(!isset($_GET["noAJAX"])){
echo json_encode(array(
"status" => $res,
"msg" => $msg
));
}
?>
......@@ -118,6 +118,10 @@ class db
return $this->result;
}
public function get_error(){
return $this->handler->error;
}
public function escape($str)
{
return is_string($str) ? '\'' . $this->handler->real_escape_string($str) . '\'' : intval($str);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment