api.opdenied.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * OpenPayz access management implementation
  4. */
  5. class OpDenied {
  6. /**
  7. * Contains all of preloaded users which will be denied for OpenPayz transactions as login=>id
  8. *
  9. * @var array
  10. */
  11. protected $allDenied = array();
  12. /**
  13. * Database layer placeholder
  14. *
  15. * @var object
  16. */
  17. protected $deniedDb = '';
  18. /**
  19. * Contains default data table
  20. */
  21. const DATA_TABLE = 'op_denied';
  22. /**
  23. * Predefined routing etc..
  24. */
  25. const PROUTE_DENY_LOGIN = 'opdenieduserlogin';
  26. const PROUTE_DENY_FLAG = 'opdeniedflag';
  27. public function __construct() {
  28. $this->initDb();
  29. $this->loadDenied();
  30. }
  31. /**
  32. * Inits database abstraction layer instance
  33. *
  34. * @return void
  35. */
  36. protected function initDb() {
  37. $this->deniedDb = new NyanORM(self::DATA_TABLE);
  38. }
  39. /**
  40. * Loads all available denied users from database in local prop
  41. *
  42. * @return void
  43. */
  44. protected function loadDenied() {
  45. $this->allDenied = $this->deniedDb->getAll('login');
  46. }
  47. /**
  48. * Renders deny-state modification form for some user login
  49. *
  50. * @param string $login
  51. *
  52. * @return string
  53. */
  54. public function renderModifyForm($login) {
  55. $result = '';
  56. if (!empty($login)) {
  57. $isNowDenied = (isset($this->allDenied[$login])) ? true : false;
  58. $inputs = wf_HiddenInput(self::PROUTE_DENY_LOGIN, $login);
  59. $inputs .= wf_CheckInput(self::PROUTE_DENY_FLAG, __('Deny online payments for this user'), true, $isNowDenied);
  60. $inputs .= wf_Submit(__('Save'));
  61. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  62. }
  63. return($result);
  64. }
  65. /**
  66. * Switches user denied state if required
  67. *
  68. * @param string $login
  69. * @param bool $newDenyState
  70. *
  71. * @return void
  72. */
  73. public function setUserDenyState($login, $newDenyState) {
  74. $loginF = ubRouting::filters($login, 'mres');
  75. //user already denied
  76. if (isset($this->allDenied[$login])) {
  77. if (!$newDenyState) {
  78. //deleting deny record
  79. $this->deniedDb->where('login', '=', $loginF);
  80. $this->deniedDb->delete();
  81. log_register('ZBSMAN OPALLOWED (' . $login . ')');
  82. }
  83. } else {
  84. //user is not denied now
  85. if ($newDenyState) {
  86. //creating new deny record
  87. $this->deniedDb->data('login', $loginF);
  88. $this->deniedDb->create();
  89. log_register('ZBSMAN OPDENIED (' . $login . ')');
  90. }
  91. }
  92. }
  93. /**
  94. * Returns array of currently denied users as login=>login
  95. *
  96. * @return array
  97. */
  98. public function getAllDenied() {
  99. $result = array();
  100. if (!empty($this->allDenied)) {
  101. foreach ($this->allDenied as $io => $each) {
  102. $result[$io] = $io;
  103. }
  104. }
  105. return($result);
  106. }
  107. }