api.cardpay.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. /**
  3. * Creates card in database with some serial and price
  4. *
  5. * @param int $serial
  6. * @param float $cash
  7. * @param int $part
  8. * @param int $selling
  9. *
  10. * @return void
  11. */
  12. function zb_CardCreate($serial, $cash, $part, $selling_id) {
  13. $admin = whoami();
  14. $date = curdatetime();
  15. $query = "INSERT INTO `cardbank` (`id` , `serial` , `part` , `cash` , `admin` , `date` , `receipt_date` , `selling_id` , `active` , `used` , `usedate` , `usedlogin` , `usedip`) "
  16. . "VALUES (NULL , '" . $serial . "', '" . $part . "', '" . $cash . "', '" . $admin . "', '" . $date . "', '" . $date . "', '" . $selling_id . "', '1', '0', NULL , '', NULL);";
  17. nr_query($query);
  18. }
  19. /**
  20. * Generates cards in database with some price, and returns it serials
  21. *
  22. * @param array $cardCreate
  23. *
  24. * @return string
  25. */
  26. function zb_CardGenerate(array $cardCreate) {
  27. $count = vf($cardCreate['count'], 3);
  28. $price = vf($cardCreate['price']);
  29. $part = $cardCreate['part'];
  30. $selling = vf($cardCreate['selling'], 3);
  31. $messages = new UbillingMessageHelper();
  32. $result = '';
  33. $reported = '';
  34. $message_warn = '';
  35. $message_warn .= (empty($count)) ? $messages->getStyledMessage(__('Count of cards cannot be empty'), 'warning') : '';
  36. $message_warn .= (empty($price)) ? $messages->getStyledMessage(__('Price of cards cannot be empty'), 'warning') : '';
  37. // Check that we dont have warning
  38. if (empty($message_warn)) {
  39. $reported_arr = array();
  40. for ($cardcount = 0; $cardcount < $count; $cardcount++) {
  41. if ($cardCreate['length'] == 16) {
  42. $serial = mt_rand(1111, 9999) . mt_rand(1111, 9999) . mt_rand(1111, 9999) . mt_rand(1111, 9999);
  43. } elseif ($cardCreate['length'] == 14) {
  44. $serial = mt_rand(1111, 9999) . mt_rand(1111, 9999) . mt_rand(1111, 9999) . mt_rand(11, 99);
  45. } elseif ($cardCreate['length'] == 12) {
  46. $serial = mt_rand(1111, 9999) . mt_rand(1111, 9999) . mt_rand(1111, 9999);
  47. } elseif ($cardCreate['length'] == 10) {
  48. $serial = mt_rand(1111, 9999) . mt_rand(1111, 9999) . mt_rand(11, 99);
  49. } elseif ($cardCreate['length'] == 8) {
  50. $serial = mt_rand(1111, 9999) . mt_rand(1111, 9999);
  51. }
  52. $reported_arr[] = $serial;
  53. }
  54. // Delete duplicat serial number cards
  55. array_unique($reported_arr);
  56. $count = count($reported_arr);
  57. foreach ($reported_arr as $serial) {
  58. $reported .= $serial . "\n";
  59. zb_CardCreate($serial, $price, $part, $selling);
  60. }
  61. $result .= wf_tag('pre', false) . $reported . wf_tag('pre', true);
  62. log_register("CARDS CREATED `" . $count . "` PART `" . $part . "` SERIAL `" . $serial . "` PRICE `" . $price . "` SELLING_ID [" . $selling . "]");
  63. } else {
  64. $result = $message_warn;
  65. }
  66. return ($result);
  67. }
  68. /**
  69. * Returns count of available payment cards
  70. *
  71. * @return int
  72. */
  73. function zb_CardsGetCount() {
  74. $query = "SELECT COUNT(`id`) from `cardbank`";
  75. $result = simple_query($query);
  76. $result = $result['COUNT(`id`)'];
  77. return ($result);
  78. }
  79. /**
  80. * Returns available list with some controls
  81. *
  82. * @return string
  83. */
  84. function web_CardsShow() {
  85. $selling = zb_BuilderSelectSellingData();
  86. $totalcount = zb_CardsGetCount();
  87. $perpage = 100;
  88. //pagination
  89. if (!isset($_GET['page'])) {
  90. $current_page = 1;
  91. } else {
  92. $current_page = vf($_GET['page'], 3);
  93. }
  94. if ($totalcount > $perpage) {
  95. $paginator = wf_pagination($totalcount, $perpage, $current_page, "?module=cards", 'ubButton');
  96. $from = $perpage * ($current_page - 1);
  97. $to = $perpage;
  98. $query = "SELECT * from `cardbank` ORDER by `id` DESC LIMIT " . $from . "," . $to . ";";
  99. $alluhw = simple_queryall($query);
  100. } else {
  101. $paginator = '';
  102. $query = "SELECT * from `cardbank` ORDER by `id` DESC;";
  103. $alluhw = simple_queryall($query);
  104. }
  105. $allcards = simple_queryall($query);
  106. $cells = wf_TableCell(__('ID'));
  107. $cells .= wf_TableCell(__('Serial part'));
  108. $cells .= wf_TableCell(__('Serial number'));
  109. $cells .= wf_TableCell(__('Price'));
  110. $cells .= wf_TableCell(__('Admin'));
  111. $cells .= wf_TableCell(__('Date'));
  112. $cells .= wf_TableCell(__('Active'));
  113. $cells .= wf_TableCell(__('Used'));
  114. $cells .= wf_TableCell(__('Usage date'));
  115. $cells .= wf_TableCell(__('Used login'));
  116. $cells .= wf_TableCell(__('Used IP'));
  117. $cells .= wf_TableCell(__('Receipt date'));
  118. $cells .= wf_TableCell(__('Selling'));
  119. $cells .= wf_TableCell(wf_CheckInput('check', '', false, false), '', 'sorttable_nosort');
  120. $rows = wf_TableRow($cells, 'row1');
  121. if (!empty($allcards)) {
  122. foreach ($allcards as $io => $eachcard) {
  123. $nameSelling = array_key_exists($eachcard['selling_id'], $selling) ? $selling[$eachcard['selling_id']] : '';
  124. $cells = wf_TableCell($eachcard['id']);
  125. $cells .= wf_TableCell($eachcard['part']);
  126. $cells .= wf_TableCell($eachcard['serial']);
  127. $cells .= wf_TableCell($eachcard['cash']);
  128. $cells .= wf_TableCell($eachcard['admin']);
  129. $cells .= wf_TableCell($eachcard['date']);
  130. $cells .= wf_TableCell(web_bool_led($eachcard['active']));
  131. $cells .= wf_TableCell(web_bool_led($eachcard['used']));
  132. $cells .= wf_TableCell($eachcard['usedate']);
  133. if (!empty($eachcard['usedlogin'])) {
  134. $userLink = wf_Link('?module=userprofile&username=' . $eachcard['usedlogin'], web_profile_icon() . ' ' . $eachcard['usedlogin']);
  135. } else {
  136. $userLink = '';
  137. }
  138. $cells .= wf_TableCell($userLink);
  139. $cells .= wf_TableCell($eachcard['usedip']);
  140. $cells .= wf_TableCell($eachcard['receipt_date']);
  141. $cells .= wf_TableCell($nameSelling);
  142. $cells .= wf_TableCell(wf_CheckInput('_cards[' . $eachcard['id'] . ']', '', false, false));
  143. $rows .= wf_TableRow($cells, 'row3');
  144. }
  145. }
  146. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  147. $result .= $paginator . wf_delimiter();
  148. $result = web_CardActions($result);
  149. return ($result);
  150. }
  151. /**
  152. * Returns new cards generation form
  153. *
  154. * @return string
  155. */
  156. function web_CardsGenerateForm() {
  157. $cells = wf_TableCell(__('Selling'));
  158. $cells .= wf_TableCell(__('Serial part'));
  159. $cells .= wf_TableCell(__('Count'));
  160. $cells .= wf_TableCell(__('Price'));
  161. $cells .= wf_TableCell(__('Serial number length'));
  162. $rows = wf_TableRow($cells, 'row1');
  163. $cells = wf_TableCell(wf_Selector('card_create[selling]', zb_BuilderSelectSellingData(), '', '', false));
  164. $cells .= wf_TableCell(wf_TextInput('card_create[part]', '', '', false, '5'));
  165. $cells .= wf_TableCell(wf_TextInput('card_create[count]', '', '', false, '5'));
  166. $cells .= wf_TableCell(wf_TextInput('card_create[price]', '', '', false, '5', 'finance'));
  167. $cells .= wf_TableCell(wf_Selector('card_create[length]', array('16' => 16, '14' => 14, '12' => 12, '10' => 10, '8' => 8), '', ''));
  168. $rows .= wf_TableRow($cells, 'row1');
  169. $rows .= wf_TableRow(wf_TableCell(wf_Submit('Create')));
  170. $table = wf_TableBody($rows, '100%', 0);
  171. $result = wf_Form("", "POST", $table, 'glamour');
  172. return ($result);
  173. }
  174. /**
  175. * Returns cards search form
  176. *
  177. * @return string
  178. */
  179. function web_CardsSearchForm() {
  180. $cells = wf_TableCell(__('Selling'));
  181. $cells .= wf_TableCell(wf_Selector('card_search[selling]', zb_BuilderSelectSellingData(), '', '', false));
  182. $rows = wf_TableRow($cells, 'row2');
  183. $cells = wf_TableCell(__('ID'));
  184. $cells .= wf_TableCell(wf_TextInput('card_search[idfrom]', __('From'), '', false, '7') . wf_TextInput('card_search[idto]', __('To'), '', true, '7'));
  185. $rows .= wf_TableRow($cells, 'row2');
  186. $cells = wf_TableCell(__('Date'));
  187. $cells .= wf_TableCell(wf_DatePickerPreset('card_search[datefrom]', '') . ' ' . __('From') . wf_DatePickerPreset('card_search[dateto]', '') . ' ' . __('To'));
  188. $rows .= wf_TableRow($cells, 'row2');
  189. $cells = wf_TableCell(__('Not used'));
  190. $cells .= wf_TableCell(wf_CheckInput('card_search[used]', '', true));
  191. $rows .= wf_TableRow($cells, 'row2');
  192. $cells = wf_TableCell(__('Serial part'));
  193. $cells .= wf_TableCell(wf_TextInput('card_search[part]', '', '', false, '5'));
  194. $rows .= wf_TableRow($cells, 'row2');
  195. $cells = wf_TableCell(__('Serial number'));
  196. $cells .= wf_TableCell(wf_TextInput('card_search[serial]', '', '', true, '17'));
  197. $rows .= wf_TableRow($cells, 'row2');
  198. $rows .= wf_TableRow(wf_TableCell(wf_Submit('Search')));
  199. $result = wf_TableBody($rows, '', 0);
  200. $result = wf_Form("", "POST", $result, 'glamour');
  201. return ($result);
  202. }
  203. /**
  204. * Returns cards search form
  205. *
  206. * @param array $ids
  207. *
  208. * @return string
  209. */
  210. function web_CardsChangeForm(array $ids) {
  211. $inputs = wf_Selector('card_edit[selling]', zb_BuilderSelectSellingData(), __('Selling'), '', false);
  212. $inputs .= wf_TextInput('card_edit[part]', __('Serial part'), '', false, '17');
  213. foreach ($ids as $key => $id) {
  214. $inputs .= wf_HiddenInput(sprintf('card_edit[id][%s]', $key), $id);
  215. }
  216. $inputs .= wf_Submit('Update');
  217. $result = wf_Form('', 'POST', $inputs, 'glamour');
  218. return ($result);
  219. }
  220. /**
  221. * Returns card by serial search results
  222. *
  223. * @param array $search
  224. *
  225. * @return string
  226. */
  227. function web_CardsSearch(array $search) {
  228. $selling = zb_BuilderSelectSellingData();
  229. $serial = '%' . mysql_real_escape_string($search['serial']) . '%';
  230. $querySelling = '';
  231. if ($search['selling']) {
  232. $sellingId = mysql_real_escape_string($search['selling']);
  233. $querySelling = sprintf("AND `selling_id` = %s", $sellingId);
  234. }
  235. $queryUsed = '';
  236. if (key_exists('used', $search)) {
  237. $queryUsed = sprintf("AND `used` = 0");
  238. }
  239. $queryPart = '';
  240. if ($search['part']) {
  241. $part = mysql_real_escape_string($search['part']);
  242. $queryPart = sprintf("AND `part` = %s", $part);
  243. }
  244. $queryId = '';
  245. if ($search['idfrom'] || $search['idto']) {
  246. if (empty($search['idfrom'])) {
  247. $search['idfrom'] = $search['idto'];
  248. }
  249. if (empty($search['idto'])) {
  250. $search['idto'] = $search['idfrom'];
  251. }
  252. $idFrom = mysql_real_escape_string($search['idfrom']);
  253. $idTo = mysql_real_escape_string($search['idto']);
  254. $queryId = sprintf("AND `id` BETWEEN %s AND %s", $idFrom, $idTo);
  255. }
  256. $queryDate = '';
  257. if ($search['datefrom'] || $search['dateto']) {
  258. if (empty($search['datefrom'])) {
  259. $search['datefrom'] = $search['dateto'];
  260. }
  261. if (empty($search['dateto'])) {
  262. $search['dateto'] = $search['datefrom'];
  263. }
  264. $dateFrom = mysql_real_escape_string($search['datefrom']);
  265. $dateTo = mysql_real_escape_string($search['dateto']);
  266. $queryDate = sprintf("AND DATE(`receipt_date`) BETWEEN STR_TO_DATE('%s', '%s') AND STR_TO_DATE('%s', '%s')", $dateFrom, '%Y-%m-%d %H:%i:%s', $dateTo, '%Y-%m-%d %H:%i:%s');
  267. }
  268. $query = sprintf("SELECT * from `cardbank` WHERE `serial` LIKE '%s' %s %s %s %s %s", $serial, $queryUsed, $querySelling, $queryPart, $queryId, $queryDate);
  269. $allcards = simple_queryall($query);
  270. $result = __('Nothing found');
  271. if (!empty($allcards)) {
  272. $cells = wf_TableCell(__('ID'));
  273. $cells .= wf_TableCell(__('Serial part'));
  274. $cells .= wf_TableCell(__('Serial number'));
  275. $cells .= wf_TableCell(__('Price'));
  276. $cells .= wf_TableCell(__('Admin'));
  277. $cells .= wf_TableCell(__('Date'));
  278. $cells .= wf_TableCell(__('Active'));
  279. $cells .= wf_TableCell(__('Used'));
  280. $cells .= wf_TableCell(__('Usage date'));
  281. $cells .= wf_TableCell(__('Used login'));
  282. $cells .= wf_TableCell(__('Used IP'));
  283. $cells .= wf_TableCell(__('Receipt date'));
  284. $cells .= wf_TableCell(__('Selling'));
  285. $cells .= wf_TableCell(wf_CheckInput('check', '', false, false), '', 'sorttable_nosort');
  286. $rows = wf_TableRow($cells, 'row1');
  287. foreach ($allcards as $io => $eachcard) {
  288. $nameSelling = array_key_exists($eachcard['selling_id'], $selling) ? $selling[$eachcard['selling_id']] : '';
  289. $cells = wf_TableCell($eachcard['id']);
  290. $cells .= wf_TableCell($eachcard['part']);
  291. $cells .= wf_TableCell($eachcard['serial']);
  292. $cells .= wf_TableCell($eachcard['cash']);
  293. $cells .= wf_TableCell($eachcard['admin']);
  294. $cells .= wf_TableCell($eachcard['date']);
  295. $cells .= wf_TableCell(web_bool_led($eachcard['active']));
  296. $cells .= wf_TableCell(web_bool_led($eachcard['used']));
  297. $cells .= wf_TableCell($eachcard['usedate']);
  298. $cells .= wf_TableCell($eachcard['usedlogin']);
  299. $cells .= wf_TableCell($eachcard['usedip']);
  300. $cells .= wf_TableCell($eachcard['receipt_date']);
  301. $cells .= wf_TableCell($nameSelling);
  302. $cells .= wf_TableCell(wf_CheckInput('_cards[' . $eachcard['id'] . ']', '', false, false));
  303. $rows .= wf_TableRow($cells, 'row3');
  304. }
  305. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  306. }
  307. $result = web_CardActions($result);
  308. return ($result);
  309. }
  310. /**
  311. * @param $result
  312. *
  313. * @return string
  314. */
  315. function web_CardActions($result) {
  316. $cardActions = array(
  317. 'cachangepart' => __('Change'),
  318. 'caprint' => __('Print'),
  319. 'caexport' => __('Export serials'),
  320. 'caactive' => __('Mark as active'),
  321. 'cainactive' => __('Mark as inactive'),
  322. 'cadelete' => __('Delete'),
  323. );
  324. $actionSelect = wf_Selector('cardactions', $cardActions, '', '', false);
  325. $actionSelect .= wf_Submit(__('With selected'));
  326. $result .= $actionSelect . wf_delimiter();
  327. $result = wf_Form('', 'POST', $result, '');
  328. return ($result);
  329. }
  330. /**
  331. * Gets payment card data by its ID
  332. *
  333. * @param int $id
  334. * @return array
  335. */
  336. function zb_CardsGetData($id) {
  337. $id = vf($id, 3);
  338. $query = "SELECT * from `cardbank` WHERE `id`='" . $id . "'";
  339. $result = simple_query($query);
  340. return ($result);
  341. }
  342. /**
  343. * Marks payment card as inactive
  344. *
  345. * @param int $id
  346. */
  347. function zb_CardsMarkInactive($id) {
  348. $id = vf($id, 3);
  349. $query = "UPDATE `cardbank` SET `active` = '0' WHERE `id` = '" . $id . "'";
  350. nr_query($query);
  351. log_register("CARDS INACTIVE [" . $id . "]");
  352. }
  353. /**
  354. * Marks payment card as active
  355. *
  356. * @param int $id
  357. */
  358. function zb_CardsMarkActive($id) {
  359. $id = vf($id, 3);
  360. $query = "UPDATE `cardbank` SET `active` = '1' WHERE `id` = '" . $id . "'";
  361. nr_query($query);
  362. log_register("CARDS ACTIVE [" . $id . "]");
  363. }
  364. /**
  365. * Delete card from database by its ID
  366. *
  367. * @param int $id
  368. */
  369. function zb_CardsDelete($id) {
  370. $id = vf($id, 3);
  371. $query = "DELETE FROM `cardbank` WHERE `id`='" . $id . "'";
  372. nr_query($query);
  373. log_register("CARDS DELETE [" . $id . "]");
  374. }
  375. /**
  376. * Exports payment card number
  377. *
  378. * @param int $id
  379. * @return string
  380. */
  381. function zb_CardsExport($id) {
  382. $id = vf($id, 3);
  383. $carddata = zb_CardsGetData($id);
  384. $cardnum = $carddata['serial'];
  385. // i want to templatize it later
  386. $result = $cardnum;
  387. return ($result);
  388. }
  389. function zb_CardsMassactions() {
  390. if (isset($_POST['_cards'])) {
  391. $cardsArr = $_POST['_cards'];
  392. if (!empty($cardsArr)) {
  393. //cards change part
  394. if ($_POST['cardactions'] == 'cachangepart') {
  395. show_window(__('Change cards'), web_CardsChangeForm(array_keys($cardsArr)));
  396. }
  397. //cards export
  398. if ($_POST['cardactions'] == 'caexport') {
  399. $exportdata = '';
  400. foreach ($cardsArr as $cardid => $on) {
  401. $exportdata .= zb_CardsExport($cardid) . "\n";
  402. }
  403. $exportresult = wf_TextArea($exportdata, '', $exportdata, true, '80x20');
  404. show_window(__('Export'), $exportresult);
  405. }
  406. //cards activate
  407. if ($_POST['cardactions'] == 'caactive') {
  408. foreach ($cardsArr as $cardid => $on) {
  409. zb_CardsMarkActive($cardid);
  410. }
  411. }
  412. //cards deactivate
  413. if ($_POST['cardactions'] == 'cainactive') {
  414. foreach ($cardsArr as $cardid => $on) {
  415. zb_CardsMarkInactive($cardid);
  416. }
  417. }
  418. //cards delete
  419. if ($_POST['cardactions'] == 'cadelete') {
  420. foreach ($cardsArr as $cardid => $on) {
  421. zb_CardsDelete($cardid);
  422. }
  423. }
  424. } else {
  425. show_error(__('No cards selected'));
  426. }
  427. } else {
  428. show_error(__('No cards selected'));
  429. }
  430. }
  431. /**
  432. * Returns payment card brutes attempts list
  433. *
  434. * @return string
  435. */
  436. function web_CardShowBrutes() {
  437. $query = "SELECT * from `cardbrute`";
  438. $allbrutes = simple_queryall($query);
  439. $cells = wf_TableCell(__('ID'));
  440. $cells .= wf_TableCell(__('Serial part'));
  441. $cells .= wf_TableCell(__('Serial number'));
  442. $cells .= wf_TableCell(__('Date'));
  443. $cells .= wf_TableCell(__('Login'));
  444. $cells .= wf_TableCell(__('IP'));
  445. $cells .= wf_TableCell(__('Full address'));
  446. $cells .= wf_TableCell(__('Real Name'));
  447. $rows = wf_TableRow($cells, 'row1');
  448. if (!empty($allbrutes)) {
  449. $allrealnames = zb_UserGetAllRealnames();
  450. $alladdress = zb_AddressGetFulladdresslistCached();
  451. foreach ($allbrutes as $io => $eachbrute) {
  452. $cleaniplink = wf_JSAlert('?module=cards&cleanip=' . $eachbrute['ip'], web_delete_icon(__('Clean this IP')), __('Removing this may lead to irreparable results'));
  453. $cells = wf_TableCell($eachbrute['id']);
  454. $cells .= wf_TableCell(array_key_exists('part', $eachbrute) ? $eachbrute['part'] : '');
  455. $cells .= wf_TableCell($eachbrute['serial']);
  456. $cells .= wf_TableCell($eachbrute['date']);
  457. $cells .= wf_TableCell(wf_Link('?module=userprofile&username=' . $eachbrute['login'], web_profile_icon() . ' ' . $eachbrute['login']));
  458. $cells .= wf_TableCell($eachbrute['ip'] . ' ' . $cleaniplink);
  459. $cells .= wf_TableCell(@$alladdress[$eachbrute['login']]);
  460. $cells .= wf_TableCell(@$allrealnames[$eachbrute['login']]);
  461. $rows .= wf_TableRow($cells, 'row3');
  462. }
  463. }
  464. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  465. $cleanAllLink = wf_JSAlert('?module=cards&cleanallbrutes=true', wf_img('skins/icon_cleanup.png', __('Cleanup')), 'Are you serious');
  466. show_window(__('Bruteforce attempts') . ' ' . $cleanAllLink, $result);
  467. return ($result);
  468. }
  469. /**
  470. * Deletes some brute attempt by target IP
  471. *
  472. * @param string $ip
  473. * @return void
  474. */
  475. function zb_CardBruteCleanIP($ip) {
  476. $query = "DELETE from `cardbrute` where `ip`='" . $ip . "'";
  477. nr_query($query);
  478. log_register("CARDBRUTE DELETE `" . $ip . "`");
  479. }
  480. /**
  481. * Deletes all brute attempts
  482. *
  483. * @return void
  484. */
  485. function zb_CardBruteCleanupAll() {
  486. $query = "TRUNCATE TABLE `cardbrute`;";
  487. nr_query($query);
  488. log_register("CARDBRUTE CLEANUP");
  489. }
  490. /**
  491. * Update card part
  492. *
  493. * @param int $part
  494. * @param int $selling
  495. * @param array $ids
  496. */
  497. function zb_CardChange($part, $selling, $ids) {
  498. if ($part) {
  499. zb_CardChangePart($part, $ids);
  500. }
  501. if ($selling) {
  502. zb_CardChangeSelling($selling, $ids);
  503. }
  504. }
  505. /**
  506. * Update card part
  507. *
  508. * @param int $part
  509. * @param array $ids
  510. */
  511. function zb_CardChangePart($part, $ids) {
  512. foreach ($ids as $key => $id) {
  513. $ids[$key] = vf($id, 3);
  514. }
  515. $ids = implode(',', $ids);
  516. $query = sprintf("UPDATE `cardbank` SET `part` = '%s' WHERE `id` in (%s)", $part, $ids);
  517. nr_query($query);
  518. log_register(sprintf('CARDS UPDATE [%s] part %s', $ids, $part));
  519. }
  520. /**
  521. * Update card selling
  522. *
  523. * @param int $selling
  524. * @param array $ids
  525. */
  526. function zb_CardChangeSelling($selling, array $ids) {
  527. foreach ($ids as $key => $id) {
  528. $ids[$key] = vf($id, 3);
  529. }
  530. $ids = implode(',', $ids);
  531. $query = sprintf("UPDATE `cardbank` SET `selling_id` = '%s', `receipt_date` = '%s' WHERE `id` in (%s)", $selling, curdatetime(), $ids);
  532. nr_query($query);
  533. log_register(sprintf('CARDS UPDATE [%s] selling %s', $ids, $selling));
  534. }
  535. /**
  536. * Select card selling
  537. *
  538. * @param array $ids
  539. *
  540. * @return array|string
  541. */
  542. function zb_GetCardByIds(array $ids) {
  543. foreach ($ids as $key => $id) {
  544. $ids[$key] = vf($id, 3);
  545. }
  546. $ids = implode(',', $ids);
  547. $query = sprintf("SELECT * from `cardbank` WHERE `id` in (%s)", $ids);
  548. $selectCards = simple_queryall($query);
  549. return ($selectCards);
  550. }
  551. /**
  552. * Select dublicate card selling
  553. *
  554. * @return void
  555. */
  556. function zb_GetCardDublicate() {
  557. global $ubillingConfig;
  558. $altCfg = $ubillingConfig->getAlter();
  559. $result = '';
  560. switch ($altCfg['PAYMENTCARDS_UNIQUE_MODE']) {
  561. case 2:
  562. $query = "SELECT `serial` FROM `cardbank` GROUP BY `serial`,`part` having count(*)>1";
  563. break;
  564. default :
  565. $query = "SELECT `serial` FROM `cardbank` GROUP BY `serial` having count(*)>1";
  566. break;
  567. }
  568. $selectCards = simple_queryall($query);
  569. if ($selectCards) {
  570. $messages = new UbillingMessageHelper();
  571. foreach ($selectCards as $card) {
  572. $result .= $messages->getStyledMessage(__('Serial number of the card with duplicates') . __(': <b>' . $card['serial'] . '</b>'), 'error');
  573. }
  574. }
  575. return ($result);
  576. }
  577. /**
  578. * Runs cards processing in sinqle queue
  579. *
  580. * @return int
  581. */
  582. function zb_CardsQueueProcessing() {
  583. global $ubillingConfig;
  584. $altCfg = $ubillingConfig->getAlter();
  585. $count = 0;
  586. $query = "SELECT * from `cardbank` WHERE `usedlogin`!='' AND `used`='0'";
  587. $all = simple_queryall($query);
  588. $cashtypeId = (isset($altCfg['PC_CASHTYPEID'])) ? $altCfg['PC_CASHTYPEID'] : 1;
  589. if (!empty($all)) {
  590. foreach ($all as $io => $each) {
  591. $cardnumber = $each['serial'];
  592. $where = "WHERE `serial`='" . $cardnumber . "'";
  593. simple_update_field('cardbank', 'used', '1', $where);
  594. zb_CashAdd($each['usedlogin'], $each['cash'], 'add', $cashtypeId, 'CARD:' . $cardnumber);
  595. $count++;
  596. }
  597. }
  598. return ($count);
  599. }