You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.8 KiB
90 lines
3.8 KiB
<?php
|
|
// Saves the settings window of a module (getModuleSettings.php -> saveSettings()).
|
|
require_once('../ajax_asm.php');
|
|
if( $CUser->Data['id'] > 1 ){
|
|
$Data = array();
|
|
$Data['success'] = false;
|
|
$Data['msg'] = 'Module Not Selected!';
|
|
$MID = isset( $_POST['MID'] ) ? intval( $_POST['MID'] ) : 0;
|
|
if( $MID > 0 ){
|
|
$Data['msg'] = 'Module Does Not Exists!';
|
|
$RR = $DATABASE->Query( "SELECT * FROM `modules` WHERE `id`={$MID}", false );
|
|
if( count( $RR ) ){
|
|
$CMD = $RR[0];
|
|
$AUX = intval( $CMD['aux_id'] );
|
|
// clamp a numeric POST field to [min,max], $def when it is missing
|
|
$pInt = function( $Name, $Min, $Max, $Def ){
|
|
if( !isset( $_POST[$Name] ) || $_POST[$Name] === '' ) return $Def;
|
|
return max( $Min, min( $Max, intval( $_POST[$Name] ) ) );
|
|
};
|
|
$pFloat = function( $Name, $Min, $Max, $Def ){
|
|
if( !isset( $_POST[$Name] ) || $_POST[$Name] === '' ) return $Def;
|
|
return max( $Min, min( $Max, floatval( $_POST[$Name] ) ) );
|
|
};
|
|
$pBool = function( $Name ){
|
|
if( !isset( $_POST[$Name] ) ) return 0;
|
|
$V = strtolower( strval( $_POST[$Name] ) );
|
|
return ( $V === 'true' || $V === '1' || $V === 'on' ) ? 1 : 0;
|
|
};
|
|
// OpenCV line types la_mojo accepts (0 and 1 are old values: 8 / 4 connected)
|
|
$pLine = function( $Name ){
|
|
$V = isset( $_POST[$Name] ) ? intval( $_POST[$Name] ) : 8;
|
|
return in_array( $V, array( 0, 1, 4, 8, 16 ) ) ? $V : 8;
|
|
};
|
|
switch( intval( $CMD['type'] ) ){
|
|
case 8:{ // Embed Video Encoder (module_eve)
|
|
$SiW = array( 320, 640, 800, 1280, 1024, 1920 );
|
|
$SiH = array( 240, 480, 600, 720, 768, 1080 );
|
|
$SIZE = $pInt( 'SIZE', 0, count( $SiW ) - 1, 3 );
|
|
$W = $SiW[$SIZE];
|
|
$H = $SiH[$SIZE];
|
|
$F = array(
|
|
'web_port' => $pInt( 'PORT', 1, 65535, 8972 ),
|
|
'width' => $W,
|
|
'height' => $H,
|
|
'compression_quality' => $pInt( 'COMPRESSION', 0, 100, 70 ),
|
|
'show_ts' => $pBool( 'SHOW1' ),
|
|
'show_label' => $pBool( 'SHOW2' ),
|
|
'show_logo' => $pBool( 'SHOW3' ),
|
|
// positions in pixels, negative values are measured from the right / bottom edge
|
|
'ts_x' => $pInt( 'TS_POSX', -$W, $W, 5 ),
|
|
'ts_y' => $pInt( 'TS_POSY', -$H, $H, 5 ),
|
|
'ts_transperant' => $pBool( 'TS_TRANS' ),
|
|
'ts_font_face' => $pInt( 'TS_FONT', 0, 7, 1 ),
|
|
'ts_font_scale' => $pFloat( 'TS_FONT_SCALE', 0.1, 4.0, 1.0 ),
|
|
'ts_font_thickness' => $pInt( 'TS_FONT_THICK', 1, 8, 1 ),
|
|
'ts_line_type' => $pLine( 'TS_LINE' ),
|
|
'label_x' => $pInt( 'LBL_POSX', -$W, $W, 5 ),
|
|
'label_y' => $pInt( 'LBL_POSY', -$H, $H, -10 ),
|
|
'label_transperant' => $pBool( 'LBL_TRANS' ),
|
|
'label_font_face' => $pInt( 'LBL_FONT', 0, 7, 1 ),
|
|
'label_font_scale' => $pFloat( 'LBL_FONT_SCALE', 0.1, 4.0, 1.0 ),
|
|
'label_font_thickness' => $pInt( 'LBL_FONT_THICK', 1, 8, 1 ),
|
|
'label_line_type' => $pLine( 'LBL_LINE' ),
|
|
'logo_x' => $pInt( 'LOG_POSX', -$W, $W, 0 ),
|
|
'logo_y' => $pInt( 'LOG_POSY', -$H, $H, 0 ),
|
|
'logo_w' => $pInt( 'LOG_W', 0, $W, 0 ),
|
|
'logo_h' => $pInt( 'LOG_H', 0, $H, 0 )
|
|
);
|
|
$SET = array();
|
|
foreach( $F as $K => $V ) $SET[] = "`{$K}`=".( is_float( $V ) ? sprintf( '%.3F', $V ) : intval( $V ) );
|
|
// exec() reports a failure instead of die() in Query()
|
|
if( $DATABASE->DBLink->exec( "UPDATE `module_eve` SET ".implode( ', ', $SET )." WHERE `id`={$AUX}" ) ){
|
|
$Data['success'] = true;
|
|
$Data['msg'] = '';
|
|
} else {
|
|
$Data['msg'] = 'Unable to save the settings!';
|
|
};
|
|
break;
|
|
};
|
|
default:
|
|
$Data['msg'] = 'Saving the settings of this module type is not supported!';
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
echo json_encode( $Data );
|
|
exit();
|
|
};
|
|
header( 'location: /');
|
|
?>
|