api.cemetery.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <?php
  2. /**
  3. * Dead users burial implementation
  4. */
  5. class Cemetery {
  6. /**
  7. * Dead mark tag id via alter.ini: DEAD_TAGID
  8. *
  9. * @var int
  10. */
  11. protected $tagId = '';
  12. /**
  13. * All dead users log as id=>data
  14. *
  15. * @var array
  16. */
  17. protected $allDead = array();
  18. /**
  19. * All users with associated DEAD_TAGID
  20. *
  21. * @var array
  22. */
  23. protected $allTagged = array();
  24. /**
  25. * System alter.ini config - must be loaded in constructor
  26. *
  27. * @var array
  28. */
  29. protected $altCfg = array();
  30. /**
  31. * Cemetery database model placeholder
  32. *
  33. * @var object
  34. */
  35. protected $cemetery = '';
  36. /**
  37. * Tags database model placeholder
  38. *
  39. * @var object
  40. */
  41. protected $tags = '';
  42. /**
  43. * Creates new cemetery instance
  44. *
  45. * @param bool $loadDead
  46. */
  47. public function __construct($loadDead = true) {
  48. $this->loadAlter();
  49. $this->setTagId();
  50. //initalizing some database models
  51. $this->initCemetery();
  52. if ($loadDead) {
  53. $this->initTags();
  54. //loading required data
  55. $this->loadDead();
  56. $this->loadTagged();
  57. }
  58. }
  59. /**
  60. * Inits cemetery database model
  61. *
  62. * @return void
  63. */
  64. protected function initCemetery() {
  65. $this->cemetery = new NyanORM('cemetery');
  66. }
  67. /**
  68. * Inits tags database model
  69. *
  70. * @return void
  71. */
  72. protected function initTags() {
  73. $this->tags = new NyanORM('tags');
  74. }
  75. /**
  76. * Loads system alter.ini config into protected property
  77. *
  78. * @global object $ubillingConfig
  79. *
  80. * @return void
  81. */
  82. protected function loadAlter() {
  83. global $ubillingConfig;
  84. $this->altCfg = $ubillingConfig->getAlter();
  85. }
  86. /**
  87. * Sets dead mark tag id into protected property
  88. *
  89. * @return void
  90. */
  91. protected function setTagId() {
  92. if (isset($this->altCfg['DEAD_TAGID'])) {
  93. if ($this->altCfg['DEAD_TAGID']) {
  94. $this->tagId = $this->altCfg['DEAD_TAGID'];
  95. }
  96. }
  97. }
  98. /**
  99. * Loads dead users log from database
  100. *
  101. * @return void
  102. */
  103. protected function loadDead() {
  104. $this->allDead = $this->cemetery->getAll('id');
  105. }
  106. /**
  107. * Loads all tagged users with DEAD_TAGID
  108. *
  109. * @return void
  110. */
  111. protected function loadTagged() {
  112. if ($this->tagId) {
  113. $tagId = ubRouting::filters($this->tagId, 'int');
  114. $this->tags->where('tagid', '=', $tagId);
  115. $this->tags->selectable('login');
  116. $this->allTagged = $this->tags->getAll('login');
  117. $this->tags->selectable();
  118. }
  119. }
  120. /**
  121. * Fills cemetary log with some data
  122. *
  123. * @param string $login
  124. * @param int $state
  125. *
  126. * @return void
  127. */
  128. protected function logFuneral($login, $state) {
  129. $state = ubRouting::filters($state, 'int');
  130. $loginF = ubRouting::filters($login, 'mres');
  131. $date = curdatetime();
  132. $this->cemetery->data('login', $loginF);
  133. $this->cemetery->data('state', $state);
  134. $this->cemetery->data('date', $date);
  135. $this->cemetery->create();
  136. log_register('CEMETERY (' . $login . ') SET `' . $state . '`');
  137. }
  138. /**
  139. * Sets user as dead
  140. *
  141. * @param string $login
  142. *
  143. * @return void
  144. */
  145. public function setDead($login) {
  146. global $billing;
  147. $billing->setpassive($login, 1);
  148. log_register('CHANGE Passive (' . $login . ') ON 1');
  149. if ($this->tagId) {
  150. stg_add_user_tag($login, $this->tagId);
  151. }
  152. //set cash to zero flag (3)
  153. if (@$this->altCfg['CEMETERY_ENABLED'] == '3') {
  154. zb_CashAdd($login, 0, 'set', 1, 'CEMETERY');
  155. }
  156. $this->logFuneral($login, 1);
  157. }
  158. /**
  159. * Sets user as undead
  160. *
  161. * @param string $login
  162. *
  163. * @return void
  164. */
  165. public function setUndead($login) {
  166. global $billing;
  167. $billing->setpassive($login, 0);
  168. log_register('CHANGE Passive (' . $login . ') ON 0');
  169. if ($this->tagId) {
  170. stg_del_user_tagid($login, $this->tagId);
  171. }
  172. $this->logFuneral($login, 0);
  173. }
  174. /**
  175. * Checks is user currently mark as dead?
  176. *
  177. * @param string $login
  178. *
  179. * @return bool
  180. */
  181. public function isUserDead($login) {
  182. $result = false;
  183. if (isset($this->allTagged[$login])) {
  184. $result = true;
  185. }
  186. return ($result);
  187. }
  188. /**
  189. * Renders full cemetary log for some user
  190. *
  191. * @param string $login
  192. *
  193. * @return string
  194. */
  195. public function renderCemeteryLog($login) {
  196. $result = '';
  197. if (!empty($this->allDead)) {
  198. $cells = wf_TableCell(__('Date'));
  199. $cells .= wf_TableCell(__('Status'));
  200. $rows = wf_TableRow($cells, 'row1');
  201. foreach ($this->allDead as $io => $each) {
  202. if ($each['login'] == $login) {
  203. $led = ($each['state']) ? web_bool_led(0) : web_bool_led(1);
  204. $cells = wf_TableCell($each['date']);
  205. $cells .= wf_TableCell($led);
  206. $rows .= wf_TableRow($cells, 'row3');
  207. }
  208. }
  209. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  210. }
  211. /**
  212. * Ich trink Dutzende von Dosenbier und schalte meinen Fernseher an
  213. * Todesmöpse ohne Gnade, Todesmöpse greifen an
  214. * Super dicke titten, ey die wabbeln und die schwabbeln
  215. * Sowie affengeil Teil drei, die auf'm Affenfelsen rammeln
  216. * Ich komm auf deine Party und ich kotze auf's Buffet
  217. */
  218. if (cfr('NECROMANCY')) {
  219. if ($this->isUserDead($login)) {
  220. $inputs = wf_HiddenInput('cemeterysetasundead', $login);
  221. $inputs .= wf_Submit(__('Set user connected'));
  222. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  223. } else {
  224. $inputs = wf_HiddenInput('cemeterysetasdead', $login);
  225. $inputs .= wf_Submit(__('Set user disconnected'));
  226. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  227. }
  228. }
  229. return ($result);
  230. }
  231. /**
  232. * Returns array of all users with dead tag assigned
  233. *
  234. * @return array
  235. */
  236. public function getAllTagged() {
  237. return ($this->allTagged);
  238. }
  239. /**
  240. * Renders all-time funeral charts
  241. *
  242. * @return string
  243. */
  244. public function renderChart() {
  245. $result = '';
  246. $data = __('Month') . ',' . __('Subscriber is connected') . ',' . __('Subscriber is not connected') . "\n";
  247. $tmpArr = array();
  248. $totalCount = 0;
  249. $chartData = array();
  250. $chartData[] = array(__('Month'), __('Subscriber is connected'), __('Subscriber is not connected'));
  251. if (!empty($this->allDead)) {
  252. foreach ($this->allDead as $io => $each) {
  253. $time = strtotime($each['date']);
  254. $month = date("Y-m-d", $time);
  255. if (isset($tmpArr[$month])) {
  256. if ($each['state']) {
  257. $tmpArr[$month]['inactive'] ++;
  258. } else {
  259. $tmpArr[$month]['active'] ++;
  260. }
  261. $totalCount++;
  262. } else {
  263. if ($each['state']) {
  264. $tmpArr[$month]['inactive'] = 1;
  265. $tmpArr[$month]['active'] = 0;
  266. } else {
  267. $tmpArr[$month]['active'] = 1;
  268. $tmpArr[$month]['inactive'] = 0;
  269. }
  270. $totalCount++;
  271. }
  272. }
  273. }
  274. if (!empty($tmpArr)) {
  275. foreach ($tmpArr as $ia => $each) {
  276. $chartData[] = array($ia, ($totalCount - $each['active']), ($totalCount - $each['inactive']));
  277. }
  278. $chartsOptions = "
  279. 'focusTarget': 'category',
  280. 'hAxis': {
  281. 'color': 'none',
  282. 'baselineColor': 'none',
  283. },
  284. 'vAxis': {
  285. 'color': 'none',
  286. 'baselineColor': 'none',
  287. },
  288. 'curveType': 'function',
  289. 'pointSize': 5,
  290. 'crosshair': {
  291. trigger: 'none'
  292. },";
  293. $result .= wf_gchartsLine($chartData, '', '100%', '300px', $chartsOptions);
  294. }
  295. return ($result);
  296. }
  297. /**
  298. * Returns count of dead users by some date with non strict search
  299. *
  300. * @param string $date
  301. *
  302. * @return int
  303. */
  304. public function getDeadDateCount($date) {
  305. $result = 0;
  306. if (!empty($this->allDead)) {
  307. foreach ($this->allDead as $io => $each) {
  308. if (ispos($each['date'], $date)) {
  309. if ($each['state']) {
  310. $result++;
  311. } else {
  312. $result--;
  313. }
  314. }
  315. }
  316. }
  317. return ($result);
  318. }
  319. }
  320. ?>