From d5dd8200b9463188f3a258902188b39a8ccbcd11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 4 Nov 2015 15:48:54 +0000 Subject: [PATCH] added foreign key to database --- html/messagetable.php | 6 +++--- html/safechat.js | 11 ++++++++++- html/usertable.php | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/html/messagetable.php b/html/messagetable.php index 15159de..49aeb24 100644 --- a/html/messagetable.php +++ b/html/messagetable.php @@ -12,9 +12,9 @@ - + - +
Table: message
Colum NameSQL TypeDescription
idintIncrementing message id starting at 1.
idint, primary keyIncrementing message id starting at 1.
timetimestampTime when message has been stored in the database.
uservarchar(50)The sender's user name (pseudonym).
uservarchar(50), references \ref usertable "user (name)"The sender's user name (pseudonym).
msglongtextThe encryped and armored message text.
*/ @@ -23,7 +23,7 @@ require_once("opendb.php"); try { - $db->query('create table if not exists message (id int primary key not null auto_increment, time timestamp default current_timestamp, user varchar(50) not null, msg longtext not null);'); + $db->query('create table if not exists message (id int primary key not null auto_increment, time timestamp default current_timestamp, user varchar(50) not null, msg longtext not null, foreign key (user) references user(name) on delete cascade on update cascade) character set utf8 engine=innodb;'); $db->query('set global max_allowed_packet=1000000000'); $db->query('set global net_buffer_length=1000000'); } catch (Exception $e) { diff --git a/html/safechat.js b/html/safechat.js index 5640964..3ea08c1 100644 --- a/html/safechat.js +++ b/html/safechat.js @@ -686,4 +686,13 @@ function start() { } /// On Load, Call @ref start -$(start); +$( + window.onbeforeunload = function() { + return "Are you sure you want to navigate away?"; + } + window.onunload = function () { // you probably don't want to leave now... + alert('You are trying to leave.'); + return false; + } + start(); +); diff --git a/html/usertable.php b/html/usertable.php index 25c89c7..b106044 100644 --- a/html/usertable.php +++ b/html/usertable.php @@ -14,7 +14,7 @@ - +
Table: user
Colum NameSQL TypeDescription
namevarchar(50)The user's name (pseudonym).
namevarchar(50), primary keyThe user's name (pseudonym).
pubkeytextThe user's public key.
@@ -24,7 +24,7 @@ require_once("opendb.php"); try { - $db->query('create table if not exists user (name varchar(50) not null unique key, pubkey text not null);'); + $db->query('create table if not exists user (name varchar(50) not null primary key, pubkey text not null) character set utf8 engine=innodb;'); } catch (Exception $e) { error('database error on server'); }