2025-06-23 05:06:57 +00:00
< ? php
class Usermodes extends CI_Model {
function all () {
2025-06-23 10:00:07 +00:00
$options_object = $this -> user_options_model -> get_options ( 'usermodes' , array ( 'option_name' => 'enabled_usermodes' , 'option_key' => 'json_modes' )) -> result ();
$usermodes = json_decode ( $options_object [ 0 ] -> option_value ? ? '[]' );
$this -> db -> where ( 'active' , 1 ); // Show only those which are not globally deactivated
2025-06-23 05:06:57 +00:00
$this -> db -> order_by ( 'mode' , 'ASC' );
$this -> db -> order_by ( 'submode' , 'ASC' );
2025-06-23 10:00:07 +00:00
$modes = $this -> db -> get ( 'adif_modes' );
$retmodes = [];
foreach ( $modes -> result () as $row ) {
if ( count ( $usermodes ) > 0 ) {
2025-06-25 06:21:48 +00:00
if ( in_array ( $row -> mode . '~' . ( $row -> submode ? ? '' ), $usermodes )) {
2025-06-23 10:00:07 +00:00
$row -> active = 1 ;
} else {
$row -> active = 0 ;
}
}
$retmodes [] = $row ;
}
return $retmodes ;
2025-06-23 05:06:57 +00:00
}
2025-06-23 10:40:32 +00:00
function active () {
$options_object = $this -> user_options_model -> get_options ( 'usermodes' , array ( 'option_name' => 'enabled_usermodes' , 'option_key' => 'json_modes' )) -> result ();
$usermodes = json_decode ( $options_object [ 0 ] -> option_value ? ? '[]' );
$this -> db -> where ( 'active' , 1 ); // Show only those which are not globally deactivated
$this -> db -> order_by ( 'mode' , 'ASC' );
$this -> db -> order_by ( 'submode' , 'ASC' );
$modes = $this -> db -> get ( 'adif_modes' );
$retmodes = [];
foreach ( $modes -> result () as $row ) {
2025-06-25 06:21:48 +00:00
if ( count ( $usermodes ) > 0 ) { // Something explicitly allowed, push it to array
if ( in_array ( $row -> mode . '~' . ( $row -> submode ? ? '' ), $usermodes )) {
2025-06-23 10:40:32 +00:00
$row -> active = 1 ;
$retmodes [] = $row ;
} else {
$row -> active = 0 ;
}
2025-06-25 06:21:48 +00:00
} else { // Default-Status? Nothing in array: So everything is allowed
2025-06-23 10:40:32 +00:00
$retmodes [] = $row ;
}
}
return $retmodes ;
}
2025-06-23 05:06:57 +00:00
function mode ( $id ) {
// Clean ID
$clean_id = $this -> security -> xss_clean ( $id );
$this -> db -> where ( 'id' , $clean_id );
return $this -> db -> get ( 'adif_modes' );
}
function activate ( $id ) {
$clean_id = $this -> security -> xss_clean ( $id );
2025-06-25 06:21:48 +00:00
$modes = [];
$raw_modes = $this -> all ();
foreach ( $raw_modes as $row ) {
if (( $row -> id == $clean_id ) || ( $row -> active == 1 )) {
$modes [] = $row -> mode . '~' . ( $row -> submode ? ? '' );
}
}
$this -> user_options_model -> set_option ( 'usermodes' , 'enabled_usermodes' , array ( 'json_modes' => json_encode ( $modes )));
return true ;
2025-06-23 05:06:57 +00:00
}
function deactivate ( $id ) {
$clean_id = $this -> security -> xss_clean ( $id );
2025-06-25 06:21:48 +00:00
$modes = [];
$raw_modes = $this -> all ();
foreach ( $raw_modes as $row ) {
if (( $row -> id != $clean_id ) && ( $row -> active == 1 )) {
$modes [] = $row -> mode . '~' . ( $row -> submode ? ? '' );
}
}
$this -> user_options_model -> set_option ( 'usermodes' , 'enabled_usermodes' , array ( 'json_modes' => json_encode ( $modes )));
return true ;
}
function activateAll () {
// Clean ID
$this -> user_options_model -> set_option ( 'usermodes' , 'enabled_usermodes' , array ( 'json_modes' => '[]' )); // Empty/Nothing is default (prevents migration)
return true ;
}
function deactivateAll () {
$this -> user_options_model -> set_option ( 'usermodes' , 'enabled_usermodes' , array ( 'json_modes' => '[""]' )); // Put at least one senseless element to array, to deactivate all on userlevel
2025-06-23 05:06:57 +00:00
return true ;
}
}
?>