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 1875863..1b5c525 100644 Binary files a/db/ggdworkshop.db and b/db/ggdworkshop.db differ 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 @@
-