From 85a229932230b1380a196b98d716fa0f8ae0a67b Mon Sep 17 00:00:00 2001 From: int2001 Date: Thu, 3 Aug 2023 06:53:22 +0000 Subject: [PATCH] Added warning if no paper_type is assigned --- application/controllers/Labels.php | 2 +- application/models/Labels_model.php | 19 ++++++++----------- application/views/labels/edit.php | 6 +++--- application/views/labels/index.php | 2 +- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/application/controllers/Labels.php b/application/controllers/Labels.php index 314108ba..b1c05642 100644 --- a/application/controllers/Labels.php +++ b/application/controllers/Labels.php @@ -331,7 +331,7 @@ class Labels extends CI_Controller { $cleanid = $this->security->xss_clean($id); - $data['label'] = $this->labels_model->getLabel($cleanid); + $data['label'] = $this->labels_model->getLabel($cleanid,$this->session->userdata('user_id')); $data['papertypes'] = $this->labels_model->fetchPapertypes($this->session->userdata('user_id')); diff --git a/application/models/Labels_model.php b/application/models/Labels_model.php index dcd6d374..ad80dff3 100644 --- a/application/models/Labels_model.php +++ b/application/models/Labels_model.php @@ -40,14 +40,13 @@ class Labels_model extends CI_Model { } - function getLabel($id) { - $this->db->join('paper_types', 'paper_types.paper_id = label_types.paper_type_id'); - $this->db->where('label_types.user_id', $this->session->userdata('user_id')); - $this->db->where('label_types.id', $id); - $query = $this->db->get('label_types'); + function getLabel($id,$user_id) { + $sql="SELECT l.id, l.user_id,l.label_name, p.paper_name, p.paper_id,l.paper_type_id,l.metric, l.marginleft, l.margintop, l.nx, l.ny, l.spacex, l.spacey, l.width, l.height, l.font_size, l.font, l.qsos, l.useforprint, l.last_modified FROM cloudlog.label_types l left outer join paper_types p on (p.user_id=l.user_id and p.paper_id=l.paper_type_id) where l.user_id=? and l.id=?;"; + $query=$this->db->query($sql,array($user_id,$id)); + $result=$query->result(); + return $result[0]; + } - return $query->row(); - } function updateLabel($id) { $data = array( @@ -83,10 +82,8 @@ class Labels_model extends CI_Model { } function fetchLabels($user_id) { - $this->db->join('paper_types', 'paper_types.paper_id = label_types.paper_type_id'); - $this->db->where('label_types.user_id', $user_id); - $query = $this->db->get('label_types'); - + $sql="SELECT l.id, l.user_id,l.label_name, p.paper_name, l.metric, l.marginleft, l.margintop, l.nx, l.ny, l.spacex, l.spacey, l.width, l.height, l.font_size, l.font, l.qsos, l.useforprint, l.last_modified FROM cloudlog.label_types l left outer join paper_types p on (p.user_id=l.user_id and p.paper_id=l.paper_type_id) where l.user_id=?;"; + $query=$this->db->query($sql,$user_id); return $query->result(); } diff --git a/application/views/labels/edit.php b/application/views/labels/edit.php index 6483a63f..101fb2c2 100644 --- a/application/views/labels/edit.php +++ b/application/views/labels/edit.php @@ -30,9 +30,9 @@ diff --git a/application/views/labels/index.php b/application/views/labels/index.php index 96c60119..b6f15b18 100644 --- a/application/views/labels/index.php +++ b/application/views/labels/index.php @@ -88,7 +88,7 @@ foreach($labels as $label) { ?> label_name; ?> - paper_name; ?> + paper_name ?? 'No paper assigned' ?> metric; ?> width; ?> height; ?>