Web Interface For Lite Argus Control modules
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

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. // Saves the settings window of a module (getModuleSettings.php -> saveSettings()).
  3. require_once('../ajax_asm.php');
  4. if( $CUser->Data['id'] > 1 ){
  5. $Data = array();
  6. $Data['success'] = false;
  7. $Data['msg'] = 'Module Not Selected!';
  8. $MID = isset( $_POST['MID'] ) ? intval( $_POST['MID'] ) : 0;
  9. if( $MID > 0 ){
  10. $Data['msg'] = 'Module Does Not Exists!';
  11. $RR = $DATABASE->Query( "SELECT * FROM `modules` WHERE `id`={$MID}", false );
  12. if( count( $RR ) ){
  13. $CMD = $RR[0];
  14. $AUX = intval( $CMD['aux_id'] );
  15. // clamp a numeric POST field to [min,max], $def when it is missing
  16. $pInt = function( $Name, $Min, $Max, $Def ){
  17. if( !isset( $_POST[$Name] ) || $_POST[$Name] === '' ) return $Def;
  18. return max( $Min, min( $Max, intval( $_POST[$Name] ) ) );
  19. };
  20. $pFloat = function( $Name, $Min, $Max, $Def ){
  21. if( !isset( $_POST[$Name] ) || $_POST[$Name] === '' ) return $Def;
  22. return max( $Min, min( $Max, floatval( $_POST[$Name] ) ) );
  23. };
  24. $pBool = function( $Name ){
  25. if( !isset( $_POST[$Name] ) ) return 0;
  26. $V = strtolower( strval( $_POST[$Name] ) );
  27. return ( $V === 'true' || $V === '1' || $V === 'on' ) ? 1 : 0;
  28. };
  29. // OpenCV line types la_mojo accepts (0 and 1 are old values: 8 / 4 connected)
  30. $pLine = function( $Name ){
  31. $V = isset( $_POST[$Name] ) ? intval( $_POST[$Name] ) : 8;
  32. return in_array( $V, array( 0, 1, 4, 8, 16 ) ) ? $V : 8;
  33. };
  34. switch( intval( $CMD['type'] ) ){
  35. case 8:{ // Embed Video Encoder (module_eve)
  36. $SiW = array( 320, 640, 800, 1280, 1024, 1920 );
  37. $SiH = array( 240, 480, 600, 720, 768, 1080 );
  38. $SIZE = $pInt( 'SIZE', 0, count( $SiW ) - 1, 3 );
  39. $W = $SiW[$SIZE];
  40. $H = $SiH[$SIZE];
  41. $F = array(
  42. 'web_port' => $pInt( 'PORT', 1, 65535, 8972 ),
  43. 'width' => $W,
  44. 'height' => $H,
  45. 'compression_quality' => $pInt( 'COMPRESSION', 0, 100, 70 ),
  46. 'show_ts' => $pBool( 'SHOW1' ),
  47. 'show_label' => $pBool( 'SHOW2' ),
  48. 'show_logo' => $pBool( 'SHOW3' ),
  49. // positions in pixels, negative values are measured from the right / bottom edge
  50. 'ts_x' => $pInt( 'TS_POSX', -$W, $W, 5 ),
  51. 'ts_y' => $pInt( 'TS_POSY', -$H, $H, 5 ),
  52. 'ts_transperant' => $pBool( 'TS_TRANS' ),
  53. 'ts_font_face' => $pInt( 'TS_FONT', 0, 7, 1 ),
  54. 'ts_font_scale' => $pFloat( 'TS_FONT_SCALE', 0.1, 4.0, 1.0 ),
  55. 'ts_font_thickness' => $pInt( 'TS_FONT_THICK', 1, 8, 1 ),
  56. 'ts_line_type' => $pLine( 'TS_LINE' ),
  57. 'label_x' => $pInt( 'LBL_POSX', -$W, $W, 5 ),
  58. 'label_y' => $pInt( 'LBL_POSY', -$H, $H, -10 ),
  59. 'label_transperant' => $pBool( 'LBL_TRANS' ),
  60. 'label_font_face' => $pInt( 'LBL_FONT', 0, 7, 1 ),
  61. 'label_font_scale' => $pFloat( 'LBL_FONT_SCALE', 0.1, 4.0, 1.0 ),
  62. 'label_font_thickness' => $pInt( 'LBL_FONT_THICK', 1, 8, 1 ),
  63. 'label_line_type' => $pLine( 'LBL_LINE' ),
  64. 'logo_x' => $pInt( 'LOG_POSX', -$W, $W, 0 ),
  65. 'logo_y' => $pInt( 'LOG_POSY', -$H, $H, 0 ),
  66. 'logo_w' => $pInt( 'LOG_W', 0, $W, 0 ),
  67. 'logo_h' => $pInt( 'LOG_H', 0, $H, 0 )
  68. );
  69. $SET = array();
  70. foreach( $F as $K => $V ) $SET[] = "`{$K}`=".( is_float( $V ) ? sprintf( '%.3F', $V ) : intval( $V ) );
  71. // exec() reports a failure instead of die() in Query()
  72. if( $DATABASE->DBLink->exec( "UPDATE `module_eve` SET ".implode( ', ', $SET )." WHERE `id`={$AUX}" ) ){
  73. $Data['success'] = true;
  74. $Data['msg'] = '';
  75. } else {
  76. $Data['msg'] = 'Unable to save the settings!';
  77. };
  78. break;
  79. };
  80. default:
  81. $Data['msg'] = 'Saving the settings of this module type is not supported!';
  82. break;
  83. };
  84. };
  85. };
  86. echo json_encode( $Data );
  87. exit();
  88. };
  89. header( 'location: /');
  90. ?>