2023-06-02 18:50:27 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class Labels_model extends CI_Model {
|
|
|
|
|
function addLabel() {
|
|
|
|
|
$data = array(
|
|
|
|
|
'user_id' => $this->session->userdata('user_id'),
|
2026-06-08 11:17:28 +02:00
|
|
|
'label_name' => $this->input->post('label_name', true),
|
|
|
|
|
'paper_type_id' => $this->input->post('paper_type_id', true),
|
|
|
|
|
'metric' => $this->input->post('measurementType', true),
|
|
|
|
|
'marginleft' => str_replace(',', '.',( $this->input->post('marginLeft', true))),
|
|
|
|
|
'margintop' => str_replace(',', '.',( $this->input->post('marginTop', true))),
|
|
|
|
|
'nx' => $this->input->post('NX', true),
|
|
|
|
|
'ny' => $this->input->post('NY', true),
|
|
|
|
|
'spacex' => str_replace(',', '.', ($this->input->post('SpaceX', true))),
|
|
|
|
|
'spacey' => str_replace(',', '.', ($this->input->post('SpaceY', true))),
|
|
|
|
|
'width' => str_replace(',', '.', ($this->input->post('width', true))),
|
|
|
|
|
'height' => str_replace(',', '.', ($this->input->post('height', true))),
|
|
|
|
|
'font_size' => $this->input->post('font_size', true),
|
|
|
|
|
'qsos' => $this->input->post('label_qsos', true),
|
|
|
|
|
'font' => $this->input->post('font', true),
|
2023-06-02 18:50:27 +02:00
|
|
|
'last_modified' => date('Y-m-d H:i:s'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->db->insert('label_types', $data);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-01 18:55:42 +02:00
|
|
|
function addPaper() {
|
|
|
|
|
$data = array(
|
|
|
|
|
'user_id' => $this->session->userdata('user_id'),
|
2026-06-08 11:17:28 +02:00
|
|
|
'paper_name' => $this->input->post('paper_name', true),
|
|
|
|
|
'metric' => $this->input->post('measurementType', true),
|
|
|
|
|
'width' => str_replace(',', '.', ($this->input->post('width', true))),
|
|
|
|
|
'height' => str_replace(',', '.', ($this->input->post('height', true))),
|
|
|
|
|
'orientation' => $this->input->post('orientation', true),
|
2023-08-01 18:55:42 +02:00
|
|
|
'last_modified' => date('Y-m-d H:i:s'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->db->insert('paper_types', $data);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 06:53:22 +00:00
|
|
|
function getLabel($id,$user_id) {
|
2026-06-08 11:17:28 +02:00
|
|
|
$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 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=?;";
|
2023-08-03 06:53:22 +00:00
|
|
|
$query=$this->db->query($sql,array($user_id,$id));
|
|
|
|
|
$result=$query->result();
|
|
|
|
|
return $result[0];
|
|
|
|
|
}
|
2023-08-01 18:55:42 +02:00
|
|
|
|
2023-06-03 08:46:52 +02:00
|
|
|
|
|
|
|
|
function updateLabel($id) {
|
|
|
|
|
$data = array(
|
|
|
|
|
'user_id' => $this->session->userdata('user_id'),
|
2026-06-08 11:17:28 +02:00
|
|
|
'label_name' => $this->input->post('label_name', true),
|
|
|
|
|
'paper_type_id' => $this->input->post('paper_type_id', true),
|
|
|
|
|
'metric' => $this->input->post('measurementType', true),
|
|
|
|
|
'marginleft' => str_replace(',', '.', ($this->input->post('marginLeft', true))),
|
|
|
|
|
'margintop' => str_replace(',', '.', ($this->input->post('marginTop', true))),
|
|
|
|
|
'nx' => $this->input->post('NX', true),
|
|
|
|
|
'ny' => $this->input->post('NY', true),
|
|
|
|
|
'spacex' => str_replace(',', '.', ($this->input->post('SpaceX', true))),
|
|
|
|
|
'spacey' => str_replace(',', '.', ($this->input->post('SpaceY', true))),
|
|
|
|
|
'width' => str_replace(',', '.', ($this->input->post('width', true))),
|
|
|
|
|
'height' => str_replace(',', '.', ($this->input->post('height', true))),
|
|
|
|
|
'font_size' => $this->input->post('font_size', true),
|
|
|
|
|
'qsos' => $this->input->post('label_qsos', true),
|
|
|
|
|
'font' => $this->input->post('font', true),
|
2023-06-03 08:46:52 +02:00
|
|
|
'last_modified' => date('Y-m-d H:i:s'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cleanid = $this->security->xss_clean($id);
|
|
|
|
|
|
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
|
|
|
$this->db->where('id', $cleanid);
|
|
|
|
|
$this->db->update('label_types', $data);
|
2023-06-02 18:50:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteLabel($id) {
|
|
|
|
|
$cleanid = xss_clean($id);
|
|
|
|
|
|
2023-08-01 18:55:42 +02:00
|
|
|
$this->db->delete('label_types', array('id' => $cleanid, 'user_id' => $this->session->userdata('user_id')));
|
2023-06-02 18:50:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fetchLabels($user_id) {
|
2026-06-08 11:17:28 +02:00
|
|
|
$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 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,array($user_id));
|
2023-06-02 18:50:27 +02:00
|
|
|
return $query->result();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 10:05:24 +02:00
|
|
|
function fetchPapertypes($user_id) {
|
2026-05-26 19:50:40 +02:00
|
|
|
$sql="SELECT p.paper_id,p.user_id,p.paper_name,p.metric,p.width,p.height,p.last_modified, p.orientation,COUNT(DISTINCT l.id) AS lbl_cnt
|
|
|
|
|
FROM paper_types p
|
2026-06-08 11:17:28 +02:00
|
|
|
LEFT OUTER JOIN label_types l ON (p.paper_id = l.paper_type_id AND p.user_id=l.user_id)
|
2026-05-26 19:50:40 +02:00
|
|
|
WHERE p.user_id = ? group by p.paper_id, p.user_id, p.paper_name, p.metric, p.width, p.height, p.last_modified, p.orientation;";
|
2026-06-08 11:17:28 +02:00
|
|
|
$query = $this->db->query($sql, array($this->session->userdata('user_id')));
|
2023-08-03 06:15:51 +00:00
|
|
|
return $query->result();
|
2023-08-02 10:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-02 18:50:27 +02:00
|
|
|
function fetchQsos($user_id) {
|
2026-06-08 11:17:28 +02:00
|
|
|
$table_name = $this->config->item('table_name');
|
|
|
|
|
$qsl = "SELECT count(*) count, station_profile.station_profile_name, station_profile.station_callsign, station_profile.station_id, station_profile.station_gridsquare
|
|
|
|
|
FROM {$table_name} as l
|
|
|
|
|
JOIN station_profile ON l.station_id = station_profile.station_id
|
|
|
|
|
WHERE l.COL_QSL_SENT IN ('R', 'Q')
|
|
|
|
|
AND station_profile.user_id = ?
|
|
|
|
|
GROUP BY station_profile.station_profile_name, station_profile.station_callsign, station_profile.station_id, station_profile.station_gridsquare
|
|
|
|
|
ORDER BY station_profile.station_callsign";
|
2023-06-02 18:50:27 +02:00
|
|
|
|
2026-06-08 11:17:28 +02:00
|
|
|
$query = $this->db->query($qsl, array($user_id));
|
2023-06-02 18:50:27 +02:00
|
|
|
|
|
|
|
|
return $query->result();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getDefaultLabel() {
|
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
|
|
|
$this->db->where('useforprint', '1');
|
|
|
|
|
$query = $this->db->get('label_types');
|
2023-08-01 18:55:42 +02:00
|
|
|
|
2023-06-02 18:50:27 +02:00
|
|
|
return $query->row();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 04:37:25 +00:00
|
|
|
function getPaperType($ptype_id) {
|
2023-08-02 09:34:32 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2023-08-03 04:37:25 +00:00
|
|
|
$this->db->where('paper_id',$ptype_id);
|
2023-08-02 09:34:32 +00:00
|
|
|
$query = $this->db->get('paper_types');
|
|
|
|
|
|
|
|
|
|
return $query->row();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 18:50:27 +02:00
|
|
|
function saveDefaultLabel($id) {
|
2026-06-08 11:17:28 +02:00
|
|
|
$uid = $this->session->userdata('user_id');
|
|
|
|
|
$sql = 'update label_types set useforprint = 0 where user_id = ?';
|
|
|
|
|
$this->db->query($sql, array($uid));
|
2023-06-02 18:50:27 +02:00
|
|
|
|
|
|
|
|
$cleanid = xss_clean($id);
|
2026-06-08 11:17:28 +02:00
|
|
|
$sql = 'update label_types set useforprint = 1 where user_id = ? and id = ?';
|
|
|
|
|
$this->db->query($sql, array($uid, $cleanid));
|
2023-06-02 18:50:27 +02:00
|
|
|
}
|
2023-06-14 16:28:12 +02:00
|
|
|
|
|
|
|
|
function export_printrequested($station_id = NULL) {
|
|
|
|
|
$this->load->model('stations');
|
|
|
|
|
$active_station_id = $this->stations->find_active();
|
|
|
|
|
|
2026-01-14 06:58:25 +00:00
|
|
|
$table_name = $this->config->item('table_name');
|
|
|
|
|
$user_id = $this->session->userdata('user_id');
|
|
|
|
|
|
2026-06-08 11:17:28 +02:00
|
|
|
$sql = "SELECT {$table_name}.*, station_profile.*, dxcc_entities.name as station_country
|
|
|
|
|
FROM {$table_name}
|
|
|
|
|
JOIN station_profile ON station_profile.station_id = {$table_name}.station_id
|
2026-01-14 06:58:25 +00:00
|
|
|
JOIN dxcc_entities ON station_profile.station_dxcc = dxcc_entities.adif
|
2026-06-08 11:17:28 +02:00
|
|
|
JOIN dxcc_entities dxc2 ON {$table_name}.COL_DXCC = dxc2.adif
|
2026-01-14 06:58:25 +00:00
|
|
|
WHERE station_profile.user_id = ?
|
|
|
|
|
AND COL_QSL_SENT IN ('R', 'Q')";
|
|
|
|
|
|
|
|
|
|
$binding = array($user_id);
|
|
|
|
|
|
|
|
|
|
if ($station_id == NULL) {
|
|
|
|
|
$sql .= " AND " . $table_name . ".station_id = ?";
|
|
|
|
|
$binding[] = $active_station_id;
|
|
|
|
|
} else if ($station_id != 'All') {
|
|
|
|
|
$sql .= " AND " . $table_name . ".station_id = ?";
|
|
|
|
|
$binding[] = $station_id;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 07:23:30 +00:00
|
|
|
$sql .= " ORDER BY dxc2.prefix ASC, COL_CALL ASC, COL_SAT_NAME ASC, COL_SAT_MODE ASC, COL_BAND_RX ASC, COL_TIME_ON ASC, COL_MODE ASC";
|
2026-01-14 06:58:25 +00:00
|
|
|
|
|
|
|
|
$query = $this->db->query($sql, $binding);
|
2023-06-14 16:28:12 +02:00
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
2023-06-27 15:03:12 +02:00
|
|
|
|
|
|
|
|
function export_printrequestedids($ids) {
|
2026-01-14 06:58:25 +00:00
|
|
|
$table_name = $this->config->item('table_name');
|
|
|
|
|
$user_id = $this->session->userdata('user_id');
|
|
|
|
|
|
2026-06-08 11:17:28 +02:00
|
|
|
$sql = "SELECT {$table_name}.*, station_profile.*, dxcc_entities.name as station_country
|
|
|
|
|
FROM {$table_name}
|
|
|
|
|
JOIN station_profile ON station_profile.station_id = {$table_name}.station_id
|
2026-01-14 06:58:25 +00:00
|
|
|
JOIN dxcc_entities ON station_profile.station_dxcc = dxcc_entities.adif
|
2026-06-08 11:17:28 +02:00
|
|
|
JOIN dxcc_entities dxc2 ON {$table_name}.COL_DXCC = dxc2.adif
|
2026-01-14 06:58:25 +00:00
|
|
|
WHERE station_profile.user_id = ?
|
|
|
|
|
AND COL_PRIMARY_KEY IN (";
|
|
|
|
|
|
|
|
|
|
$binding = array($user_id);
|
|
|
|
|
|
|
|
|
|
$placeholders = array_fill(0, count($ids), '?');
|
|
|
|
|
$sql .= implode(',', $placeholders);
|
2026-01-14 07:23:30 +00:00
|
|
|
$sql .= ") ORDER BY dxc2.prefix ASC, COL_CALL ASC, COL_SAT_NAME ASC, COL_SAT_MODE ASC, COL_BAND_RX ASC, COL_TIME_ON ASC, COL_MODE ASC";
|
2026-01-14 06:58:25 +00:00
|
|
|
|
|
|
|
|
$binding = array_merge($binding, $ids);
|
|
|
|
|
|
|
|
|
|
$query = $this->db->query($sql, $binding);
|
2023-06-27 15:03:12 +02:00
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
2023-08-02 10:05:24 +02:00
|
|
|
|
|
|
|
|
function updatePaper($id) {
|
|
|
|
|
$data = array(
|
|
|
|
|
'user_id' => $this->session->userdata('user_id'),
|
|
|
|
|
'paper_name' => xss_clean($this->input->post('paper_name', true)),
|
|
|
|
|
'metric' => xss_clean($this->input->post('measurementType', true)),
|
2024-10-06 12:31:36 +00:00
|
|
|
'width' => str_replace(',', '.', (xss_clean($this->input->post('width', true)))),
|
|
|
|
|
'height' => str_replace(',', '.', (xss_clean($this->input->post('height', true)))),
|
2023-08-02 10:35:12 +00:00
|
|
|
'orientation' => xss_clean($this->input->post('orientation', true)),
|
2023-08-02 10:05:24 +02:00
|
|
|
'last_modified' => date('Y-m-d H:i:s'),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cleanid = $this->security->xss_clean($id);
|
|
|
|
|
|
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2023-08-03 04:37:25 +00:00
|
|
|
$this->db->where('paper_id', $cleanid);
|
2023-08-02 10:05:24 +02:00
|
|
|
$this->db->update('paper_types', $data);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-03 06:15:51 +00:00
|
|
|
function label_cnt_with_paper($paper_id) {
|
2026-06-08 11:17:28 +02:00
|
|
|
$clean_paper_id = xss_clean($paper_id);
|
|
|
|
|
$uid = $this->session->userdata('user_id');
|
|
|
|
|
$sql="SELECT count(distinct l.id) as CNT
|
|
|
|
|
FROM label_types l
|
|
|
|
|
INNER JOIN paper_types p
|
|
|
|
|
ON (p.paper_id=l.paper_type_id)
|
|
|
|
|
WHERE l.user_id=?
|
|
|
|
|
AND p.user_id=?
|
|
|
|
|
AND l.paper_type_id=?";
|
|
|
|
|
$query = $this->db->query($sql, array($uid, $uid, $clean_paper_id));
|
2023-08-03 06:15:51 +00:00
|
|
|
$row = $query->row();
|
|
|
|
|
if (isset($row)) {
|
|
|
|
|
return($row->CNT);
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 10:05:24 +02:00
|
|
|
function deletePaper($id) {
|
|
|
|
|
$cleanid = xss_clean($id);
|
|
|
|
|
|
2023-08-03 04:37:25 +00:00
|
|
|
$this->db->delete('paper_types', array('paper_id' => $cleanid, 'user_id' => $this->session->userdata('user_id')));
|
2023-08-02 10:05:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPaper($id) {
|
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2023-08-03 04:37:25 +00:00
|
|
|
$this->db->where('paper_id', $id);
|
2023-08-02 10:05:24 +02:00
|
|
|
$query = $this->db->get('paper_types');
|
|
|
|
|
|
|
|
|
|
return $query->row();
|
|
|
|
|
}
|
2023-07-28 08:21:37 +00:00
|
|
|
}
|