From e0977ea3d71944d1e0384d11ed3524c34b3b9151 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 2 Aug 2023 18:25:04 +0200 Subject: [PATCH 1/3] Updated script number --- application/config/migration.php | 2 +- ...r_types_table.php => 134_create_label_paper_types_table.php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename application/migrations/{133_create_label_paper_types_table.php => 134_create_label_paper_types_table.php} (100%) diff --git a/application/config/migration.php b/application/config/migration.php index 6a1ed952..a700f85d 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 133; +$config['migration_version'] = 134; /* |-------------------------------------------------------------------------- diff --git a/application/migrations/133_create_label_paper_types_table.php b/application/migrations/134_create_label_paper_types_table.php similarity index 100% rename from application/migrations/133_create_label_paper_types_table.php rename to application/migrations/134_create_label_paper_types_table.php From d1d602a941a7d07755176d5f69b57783d87d15a6 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 2 Aug 2023 19:10:35 +0200 Subject: [PATCH 2/3] Added error message when saving or editing a paper type with duplicate name --- application/controllers/Labels.php | 16 +++++++++++++--- application/views/labels/createpaper.php | 20 ++++++++++++++++---- application/views/labels/editpaper.php | 18 ++++++++++++++++-- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index 97ca48b5..15029d49 100644 --- a/application/controllers/Labels.php +++ b/application/controllers/Labels.php @@ -118,8 +118,12 @@ class Labels extends CI_Controller { else { $this->load->model('labels_model'); - $this->labels_model->addPaper(); - + try { + $this->labels_model->addPaper(); + } catch (\Throwable $th) { + $this->session->set_flashdata('error', 'Your paper could not be saved. Remember that it can\'t have the same name as existing paper types.'); + redirect('labels/createpaper'); + } redirect('labels'); } @@ -379,7 +383,13 @@ class Labels extends CI_Controller { public function updatePaper($id) { $this->load->model('labels_model'); - $this->labels_model->updatePaper($id); + try { + $this->labels_model->updatePaper($id); + } catch (\Throwable $th) { + $this->session->set_flashdata('error', 'Your paper could not be saved. Remember that it can\'t have the same name as existing paper types.'); + $cleanid = $this->security->xss_clean($id); + redirect('labels/editpaper/'.$cleanid); + } $this->session->set_flashdata('message', 'Paper was saved.'); redirect('labels'); } diff --git a/application/views/labels/createpaper.php b/application/views/labels/createpaper.php index ee721d98..6bc3f285 100644 --- a/application/views/labels/createpaper.php +++ b/application/views/labels/createpaper.php @@ -3,8 +3,22 @@
session->flashdata('message')) { ?> -
-

session->flashdata('message'); ?>

+ + + + session->flashdata('error')) { ?> + + + + + session->flashdata('warning')) { ?> + + @@ -33,8 +47,6 @@
- -
diff --git a/application/views/labels/editpaper.php b/application/views/labels/editpaper.php index cddfb59a..f7de1553 100644 --- a/application/views/labels/editpaper.php +++ b/application/views/labels/editpaper.php @@ -3,8 +3,22 @@
session->flashdata('message')) { ?> -
-

session->flashdata('message'); ?>

+ + + + session->flashdata('error')) { ?> + + + + + session->flashdata('warning')) { ?> + + From c57c636068b24c6c8bee091c97d1eba5ae3adbf7 Mon Sep 17 00:00:00 2001 From: Andreas <6977712+AndreasK79@users.noreply.github.com> Date: Wed, 2 Aug 2023 19:14:18 +0200 Subject: [PATCH 3/3] Changed paper type templates to have user_id -1 --- .../migrations/134_create_label_paper_types_table.php | 8 ++++---- application/models/User_model.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/application/migrations/134_create_label_paper_types_table.php b/application/migrations/134_create_label_paper_types_table.php index 58d8571c..70db4bad 100644 --- a/application/migrations/134_create_label_paper_types_table.php +++ b/application/migrations/134_create_label_paper_types_table.php @@ -58,10 +58,10 @@ class Migration_create_label_paper_types_table extends CI_Migration { $this->dbforge->create_table('paper_types'); $this->db->query("CREATE UNIQUE INDEX idx_paper_types_user_id_paper_name ON paper_types (user_id, paper_name) ALGORITHM DEFAULT LOCK DEFAULT;"); - $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('1','1','A4','mm','210.000','P','297.000');"); - $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('2','1','A5','mm','148.000','P','210.000');"); - $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('3','1','letter','mm','215.900','P','279.400');"); - $this->db->query("insert ignore paper_types (user_id,paper_name,metric,width,orientation,height) SELECT u.user_id, pt.paper_name, pt.metric, pt.width, pt.orientation,pt.height FROM paper_types pt inner join users u where pt.id<4;"); + $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('1','-1','A4','mm','210.000','P','297.000');"); + $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('2','-1','A5','mm','148.000','P','210.000');"); + $this->db->query("insert into paper_types (id,user_id,paper_name,metric,width,orientation,height) values ('3','-1','letter','mm','215.900','P','279.400');"); + $this->db->query("insert ignore paper_types (user_id,paper_name,metric,width,orientation,height) SELECT u.user_id, pt.paper_name, pt.metric, pt.width, pt.orientation,pt.height FROM paper_types pt inner join users u where pt.user_id = -1;"); } } diff --git a/application/models/User_model.php b/application/models/User_model.php index ba8a1151..fe84a0c9 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -173,7 +173,7 @@ class User_Model extends CI_Model { $this->db->insert($this->config->item('auth_table'), $data); $insert_id = $this->db->insert_id(); $this->db->query("insert into bandxuser (bandid, userid, active, cq, dok, dxcc, iota, pota, sig, sota, uscounties, was, wwff, vucc) select bands.id, " . $insert_id . ", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 from bands;"); - $this->db->query("insert into paper_types (user_id,paper_name,metric,width,orientation,height) SELECT ".$insert_id.", paper_name, metric, width, orientation,height FROM paper_types where id<4;"); + $this->db->query("insert into paper_types (user_id,paper_name,metric,width,orientation,height) SELECT ".$insert_id.", paper_name, metric, width, orientation,height FROM paper_types where user_id = -1;"); return OK; } else { return EUSERNAMEEXISTS;