2019-09-11 17:38:09 +01:00
< ? php
if ( ! defined ( 'BASEPATH' )) exit ( 'No direct script access allowed' );
/*
2021-10-07 21:42:19 +02:00
This controller contains features for contesting
2019-09-11 17:38:09 +01:00
*/
class Contesting extends CI_Controller {
2021-10-07 21:42:19 +02:00
function __construct () {
2021-01-05 16:14:50 +00:00
parent :: __construct ();
2021-02-12 23:27:08 +01:00
2021-01-05 16:14:50 +00:00
$this -> load -> model ( 'user_model' );
2025-01-02 10:22:23 +01:00
if ( ! $this -> user_model -> authorize ( 2 ) || ! clubaccess_check ( 99 )) { $this -> session -> set_flashdata ( 'error' , __ ( " You're not allowed to do that! " )); redirect ( 'dashboard' ); }
2021-01-05 16:14:50 +00:00
}
2024-04-28 14:21:00 +00:00
public function index () {
$this -> load -> model ( 'cat' );
$this -> load -> model ( 'stations' );
$this -> load -> model ( 'modes' );
2021-02-12 23:27:08 +01:00
$this -> load -> model ( 'contesting_model' );
2022-09-08 20:19:41 +02:00
$this -> load -> model ( 'bands' );
2020-11-08 10:46:08 +01:00
2024-08-06 13:12:15 +02:00
// Getting the live/post mode from GET command
// 0 = live
// 1 = post (manual)
2024-08-27 14:39:23 +02:00
$get_manual_mode = $this -> input -> get ( 'manual' , true );
2024-08-06 13:12:15 +02:00
if ( $get_manual_mode == '0' || $get_manual_mode == '1' ) {
$data [ 'manual_mode' ] = $get_manual_mode ;
} else {
show_404 ();
}
2021-10-07 21:42:19 +02:00
$data [ 'my_gridsquare' ] = $this -> stations -> find_gridsquare ();
2024-04-28 14:21:00 +00:00
$data [ 'radios' ] = $this -> cat -> radios ();
2024-08-06 00:04:59 +02:00
$data [ 'radio_last_updated' ] = $this -> cat -> last_updated () -> row ();
2024-04-28 14:21:00 +00:00
$data [ 'modes' ] = $this -> modes -> active ();
2021-02-12 23:27:08 +01:00
$data [ 'contestnames' ] = $this -> contesting_model -> getActivecontests ();
2022-09-08 20:19:41 +02:00
$data [ 'bands' ] = $this -> bands -> get_user_bands_for_qso_entry ();
2020-11-08 10:46:08 +01:00
2024-09-07 19:15:57 +02:00
$footerData = [];
$footerData [ 'scripts' ] = [
'assets/js/sections/contesting.js?' . filemtime ( realpath ( __DIR__ . " /../../assets/js/sections/contesting.js " )),
];
2021-10-07 21:42:19 +02:00
$this -> load -> library ( 'form_validation' );
2020-11-08 10:46:08 +01:00
2024-04-28 14:21:00 +00:00
$this -> form_validation -> set_rules ( 'start_date' , 'Date' , 'required' );
$this -> form_validation -> set_rules ( 'start_time' , 'Time' , 'required' );
$this -> form_validation -> set_rules ( 'callsign' , 'Callsign' , 'required' );
2020-11-08 10:46:08 +01:00
2024-06-08 11:01:59 +02:00
$data [ 'page_title' ] = __ ( " Contest Logging " );
2020-11-08 10:46:08 +01:00
2021-10-07 21:42:19 +02:00
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'contesting/index' );
2024-09-07 19:15:57 +02:00
$this -> load -> view ( 'interface_assets/footer' , $footerData );
2024-04-28 14:21:00 +00:00
}
2020-12-28 19:55:51 +01:00
2024-04-28 14:21:00 +00:00
public function getSessionQsos () {
session_write_close ();
$this -> load -> model ( 'Contesting_model' );
2020-12-28 19:55:51 +01:00
2024-08-27 14:39:23 +02:00
$qso = $this -> input -> post ( 'qso' , true );
2020-12-28 19:55:51 +01:00
2023-04-10 18:54:24 +02:00
header ( 'Content-Type: application/json' );
echo json_encode ( $this -> Contesting_model -> getSessionQsos ( $qso ));
2024-04-28 14:21:00 +00:00
}
2023-04-10 18:54:24 +02:00
2024-04-28 14:52:16 +00:00
public function getSession () {
session_write_close ();
$this -> load -> model ( 'Contesting_model' );
2023-04-10 18:54:24 +02:00
2024-04-28 14:52:16 +00:00
header ( 'Content-Type: application/json' );
echo json_encode ( $this -> Contesting_model -> getSession ());
}
2023-04-10 18:54:24 +02:00
public function deleteSession () {
2024-04-28 14:52:16 +00:00
$this -> load -> model ( 'Contesting_model' );
2023-04-10 18:54:24 +02:00
2024-08-27 14:39:23 +02:00
$qso = $this -> input -> post ( 'qso' , true );
2023-04-10 18:54:24 +02:00
2024-04-28 14:52:16 +00:00
$data = $this -> Contesting_model -> deleteSession ( $qso );
2020-12-28 19:55:51 +01:00
2024-04-28 14:52:16 +00:00
return json_encode ( $data );
}
2021-02-12 23:27:08 +01:00
2023-04-10 18:54:24 +02:00
public function setSession () {
2024-04-28 14:39:31 +00:00
$this -> load -> model ( 'Contesting_model' );
2024-04-29 05:13:11 +00:00
$this -> Contesting_model -> setSession ();
2024-07-17 18:24:44 +02:00
2024-08-27 14:39:23 +02:00
$this -> session -> set_userdata ( 'radio' , $this -> input -> post ( 'radio' , true ));
2024-04-28 14:39:31 +00:00
header ( 'Content-Type: application/json' );
echo json_encode ( $this -> Contesting_model -> getSession ());
}
2023-04-10 18:54:24 +02:00
2021-10-07 21:42:19 +02:00
public function create () {
2021-02-12 23:27:08 +01:00
$this -> load -> model ( 'Contesting_model' );
$this -> load -> library ( 'form_validation' );
$this -> form_validation -> set_rules ( 'name' , 'Contest Name' , 'required' );
2023-10-06 13:14:54 +02:00
$this -> form_validation -> set_rules ( 'adifname' , 'Adif Contest Name' , 'required' );
2021-02-12 23:27:08 +01:00
2024-04-29 05:13:11 +00:00
if ( $this -> form_validation -> run () == FALSE ) {
2021-02-12 23:27:08 +01:00
$data [ 'page_title' ] = " Create Mode " ;
$this -> load -> view ( 'contesting/create' , $data );
2024-04-29 05:13:11 +00:00
} else {
2021-02-12 23:27:08 +01:00
$this -> Contesting_model -> add ();
}
}
public function add () {
$this -> load -> model ( 'Contesting_model' );
$data [ 'contests' ] = $this -> Contesting_model -> getAllContests ();
2024-09-07 19:15:57 +02:00
$footerData = [];
$footerData [ 'scripts' ] = [
'assets/js/sections/contesting.js?' . filemtime ( realpath ( __DIR__ . " /../../assets/js/sections/contesting.js " )),
];
2021-02-12 23:27:08 +01:00
// Render Page
2024-06-06 21:32:42 +02:00
$data [ 'page_title' ] = __ ( " Contests " );
2021-02-12 23:27:08 +01:00
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'contesting/add' );
2024-09-07 19:15:57 +02:00
$this -> load -> view ( 'interface_assets/footer' , $footerData );
2021-02-12 23:27:08 +01:00
}
2021-10-07 21:42:19 +02:00
public function edit ( $id ) {
2021-02-12 23:27:08 +01:00
$this -> load -> model ( 'Contesting_model' );
2023-10-06 13:14:54 +02:00
$this -> load -> library ( 'form_validation' );
2021-02-12 23:27:08 +01:00
$item_id_clean = $this -> security -> xss_clean ( $id );
$data [ 'contest' ] = $this -> Contesting_model -> contest ( $item_id_clean );
2024-06-06 21:32:42 +02:00
$data [ 'page_title' ] = __ ( " Update Contest " );
2021-02-12 23:27:08 +01:00
2024-09-07 19:15:57 +02:00
$footerData = [];
$footerData [ 'scripts' ] = [
'assets/js/sections/contesting.js?' . filemtime ( realpath ( __DIR__ . " /../../assets/js/sections/contesting.js " )),
];
2021-02-12 23:27:08 +01:00
$this -> form_validation -> set_rules ( 'name' , 'Contest Name' , 'required' );
$this -> form_validation -> set_rules ( 'adifname' , 'Adif Contest Name' , 'required' );
if ( $this -> form_validation -> run () == FALSE )
{
$this -> load -> view ( 'interface_assets/header' , $data );
$this -> load -> view ( 'contesting/edit' );
2024-09-07 19:15:57 +02:00
$this -> load -> view ( 'interface_assets/footer' , $footerData );
2021-02-12 23:27:08 +01:00
}
else
{
$this -> Contesting_model -> edit ( $item_id_clean );
$data [ 'notice' ] = " Contest " . $this -> security -> xss_clean ( $this -> input -> post ( 'name' , true )) . " Updated " ;
redirect ( 'contesting/add' );
}
}
public function delete () {
2024-08-27 14:39:23 +02:00
$id = $this -> input -> post ( 'id' , true );
2021-02-12 23:27:08 +01:00
$this -> load -> model ( 'Contesting_model' );
$this -> Contesting_model -> delete ( $id );
}
public function activate () {
2024-08-27 14:39:23 +02:00
$id = $this -> input -> post ( 'id' , true );
2021-02-12 23:27:08 +01:00
$this -> load -> model ( 'Contesting_model' );
$this -> Contesting_model -> activate ( $id );
header ( 'Content-Type: application/json' );
echo json_encode ( array ( 'message' => 'OK' ));
return ;
}
public function deactivate () {
2024-08-27 14:39:23 +02:00
$id = $this -> input -> post ( 'id' , true );
2021-02-12 23:27:08 +01:00
$this -> load -> model ( 'Contesting_model' );
$this -> Contesting_model -> deactivate ( $id );
header ( 'Content-Type: application/json' );
echo json_encode ( array ( 'message' => 'OK' ));
return ;
}
2021-10-23 19:44:41 +02:00
public function deactivateall () {
$this -> load -> model ( 'Contesting_model' );
$this -> Contesting_model -> deactivateall ();
header ( 'Content-Type: application/json' );
echo json_encode ( array ( 'message' => 'OK' ));
return ;
}
public function activateall () {
$this -> load -> model ( 'Contesting_model' );
$this -> Contesting_model -> activateall ();
header ( 'Content-Type: application/json' );
echo json_encode ( array ( 'message' => 'OK' ));
return ;
}
2021-10-24 16:48:23 +02:00
/*
* Function is used for dupe - checking in contestinglogging
*/
public function checkIfWorkedBefore () {
2024-03-08 08:45:46 +00:00
session_write_close ();
2024-08-27 14:39:23 +02:00
$call = $this -> input -> post ( 'call' , true );
$band = $this -> input -> post ( 'band' , true );
$mode = $this -> input -> post ( 'mode' , true );
$contest = $this -> input -> post ( 'contest' , true );
2021-10-24 16:48:23 +02:00
$this -> load -> model ( 'Contesting_model' );
2023-04-10 18:54:24 +02:00
$result = $this -> Contesting_model -> checkIfWorkedBefore ( $call , $band , $mode , $contest );
2021-10-24 16:48:23 +02:00
header ( 'Content-Type: application/json' );
2023-11-09 15:11:36 +01:00
if ( $result && $result -> num_rows ()) {
2023-12-31 07:01:43 +00:00
$timeb4 = substr ( $result -> row () -> b4 , 0 , 5 );
2024-04-28 14:52:16 +00:00
$custom_date_format = $this -> session -> userdata ( 'user_date_format' );
2023-12-31 06:55:25 +00:00
$abstimeb4 = date ( $custom_date_format , strtotime ( $result -> row () -> COL_TIME_OFF )) . ' ' . date ( 'H:i' , strtotime ( $result -> row () -> COL_TIME_OFF ));
2023-12-31 07:01:43 +00:00
echo json_encode ( array ( 'message' => 'Worked at ' . $abstimeb4 . ' (' . $timeb4 . ' ago) before' ));
2021-10-24 16:48:23 +02:00
}
return ;
}
2021-02-12 23:27:08 +01:00
}