From 379507e346e8806e39f451cf35c7d72ccd609f1c Mon Sep 17 00:00:00 2001 From: German Correa Date: Fri, 1 Dec 2017 21:27:32 -0300 Subject: [PATCH] Crea la base de datos, Funciona el registro (sin validar si existe) Y mostar la lista de participantes --- api/register.php | 36 ++++++++++----- config.php | 10 +++++ db/db.php | 108 +++++++++++++++++++++++++++------------------ db/ggdworkshop.db | Bin 16384 -> 16384 bytes db/schema.sql | 19 ++++++++ dbconnect.php | 28 ++++++++++++ js/registerform.js | 5 +++ participants.php | 39 ++++++++++++++++ registration.php | 2 +- 9 files changed, 192 insertions(+), 55 deletions(-) create mode 100644 config.php create mode 100644 db/schema.sql create mode 100644 dbconnect.php create mode 100644 participants.php diff --git a/api/register.php b/api/register.php index 9334dbe..41cd433 100644 --- a/api/register.php +++ b/api/register.php @@ -1,4 +1,7 @@ -insert($fila); + /* registrar($fila); $mail = $data["email"]; $nombre = $data["nombre"] . " " . $data["apellido"]; @@ -116,7 +128,7 @@ else { 'Content-Type: ' . "text/plain; charset=UTF-8". "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($mail, 'Registration confirmation for GGDWorkshop', $msg, $headers); - + */ $data['message'] = "Registration Successfully!"; } diff --git a/config.php b/config.php new file mode 100644 index 0000000..7a4b2fe --- /dev/null +++ b/config.php @@ -0,0 +1,10 @@ +open('./ggdworkshop.db'); - } - function schema(){ - $sql =<<exec($sql); - if(!$ret){ - echo $this->lastErrorMsg(); - } else { - echo "Schema created successfully\n"; - } - $this->close(); - } +pdo == null){ + global $db_path; + $this->pdo = new \PDO('sqlite:'.$db_path); + $this->pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); + } + return $this->pdo; } + + public function schema($schema_file){ + $sql = file_get_contents($schema_file); + $this->pdo->exec($sql); + } + + public function insert($registro){ + $columns = implode(",", array_keys($registro)); + echo $columns; + $sql = "INSERT INTO Registro ($columns)" + .' VALUES (:nombre,:apellido,:titulo,:afiliacion,:ciudad,:pais,:email,:fechaLlegada,' + .':fechaPartida,:financiacion,:invitado,:cartaInvitacion,:roomingPref,:roommate,:fechaRegistro);'; + echo $sql; + $stmt = $this->pdo->prepare($sql); + $stmt->execute([ + ':nombre' => $registro['nombre'], + ':apellido' => $registro['apellido'], + ':titulo' => $registro['titulo'], + ':afiliacion' => $registro['afiliacion'], + ':ciudad' => $registro['ciudad'], + ':pais' => $registro['pais'], + ':email' => $registro['email'], + ':fechaLlegada' => $registro['fechaLlegada'], + ':fechaPartida' => $registro['fechaPartida'], + ':financiacion' => $registro['financiacion'], + ':invitado' => $registro['invitado'], + ':cartaInvitacion' => $registro['cartaInvitacion'], + ':roomingPref' => $registro['roomingPref'], + ':roommate' => $registro['roommate'], + ':fechaRegistro' => $registro['fechaRegistro'] + ]); + return $this->pdo->lastInsertId(); + + } + public function getAll(){ + $stmt = $this->pdo->prepare("SELECT * FROM Registro"); + $stmt -> execute(); + return $stmt->fetchAll(\PDO::FETCH_BOTH); + + } + + + + } + + $db = new DB(); + $db->connect(); + $db->schema($schema_path); + + - $db = new DB(); - if(!$db){ - echo $db->lastErrorMsg(); - }else{ - echo "Opened database successfully\n"; - } - $db->schema(); ?> diff --git a/db/ggdworkshop.db b/db/ggdworkshop.db index 1875863de272054882d2258a16ad96c6739ca2a2..1b5c52549a166ff576e0e5a286bf7726cf2f5554 100644 GIT binary patch delta 567 zcmZo@U~Fh$oFL7}JWc3<*eocZ#xt3NCy1*xijiGh zR+h1weR2wq5t9bjqJH)`B#&-y4*EYWTMnxt;25D(|TSa9{ zMMX{yPGwPJkHn&~)Jmi9#GI1UqT+y}{It~K;{2k}yv#BnKeMD#AwNyQH?uf9u_Qk) zGut;muOziBGbJ^jO92itAZ9q^!jl>Ks8yOf{7@31v^*|<)uEgS$G@z`x zuAz~xfsulNft8WDm4RWSIHMqgB*>A{=3qxk!yHMv8$*jq(@PU8A?|bVA>cls^8$)8 z%MwdcF`Z^;YGq)|#lXP8#D9i?{|x_gV2B>zx07PFWW?@!CJAP9PN>DG_VNNvVdVeB a!2bzo#tVKv9!6$a#-P;n%;J)wd?o;qyr%pB delta 196 zcmZo@U~Fh$oFL7}I8nw~n2|wG;sh`M4+dr)4hEhm{^L9x8ylx_PoBXO#MPF?$Sy7` z%h;gTQ7%gNOVRCrGk!F#rLA I%ZtJV0C37PVE_OC diff --git a/db/schema.sql b/db/schema.sql new file mode 100644 index 0000000..71e2be6 --- /dev/null +++ b/db/schema.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS Registro + ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + nombre VARCHAR(50) NOT NULL, + apellido VARCHAR(50) NOT NULL, + titulo VARCHAR(50), + afiliacion VARCHAR(50), + ciudad VARCHAR(50), + pais VARCHAR(50), + email VARCHAR(80) NOT NULL UNIQUE, + fechaLlegada DATE, + fechaPartida DATE, + financiacion BOOLEAN NOT NULL, + invitado BOOLEAN NOT NULL, + cartaInvitacion BOOLEAN NOT NULL, + roomingPref VARCHAR(50), + roommate VARCHAR(50), + fechaRegistro DATETIME NOT NULL + ); \ No newline at end of file diff --git a/dbconnect.php b/dbconnect.php new file mode 100644 index 0000000..bfbd8a7 --- /dev/null +++ b/dbconnect.php @@ -0,0 +1,28 @@ +pdo == null) { + try { + $this->pdo = new \PDO("sqlite:" . Config::PATH_TO_SQLITE_FILE); + } catch (\PDOException $e) { + // handle the exception here + } + + } + return $this->pdo; + } +} +?> \ No newline at end of file diff --git a/js/registerform.js b/js/registerform.js index 04c3ab6..4f977fe 100644 --- a/js/registerform.js +++ b/js/registerform.js @@ -72,6 +72,11 @@ $().ready(function(){ formdata.find(item => item.name === "roomtype").value = $("#roomtype").select2("data")[0].text; var parameters = $.param(formdata); console.log(parameters); + var post = $.post('api/register.php', parameters); + post.done(function(data){ + console.log(data); + }); + //console.log(parameters); }, errorElement: "em", diff --git a/participants.php b/participants.php new file mode 100644 index 0000000..d945a1b --- /dev/null +++ b/participants.php @@ -0,0 +1,39 @@ + + + +
+
+
+
+

Participants

+ + + + + + + + + + getAll() as $row){ + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + + ?> + + + +
FirstnameLastnameAffiliation
".$row['nombre']." ".$row['apellido']." ".$row['afiliacion']."
+
+ +
+
+ + + diff --git a/registration.php b/registration.php index c1161c1..d20545b 100644 --- a/registration.php +++ b/registration.php @@ -36,7 +36,7 @@
-