index.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. if (cfr('CREDIT')) {
  3. if (ubRouting::checkGet('username')) {
  4. $login = ubRouting::get('username', 'mres');
  5. $altCfg = $ubillingConfig->getAlter();
  6. $creditLimitOpt = $altCfg['STRICT_CREDIT_LIMIT'];
  7. // change credit if need
  8. if (ubRouting::checkPost('newcredit', false)) { //may be zero value
  9. $rawCredit = ubRouting::post('newcredit');
  10. if (isset($altCfg['NEGATIVE_CREDIT_ALLOWED'])) {
  11. $credit = ($altCfg['NEGATIVE_CREDIT_ALLOWED']) ? $rawCredit : ubRouting::filters($rawCredit, 'vf');
  12. } else {
  13. $credit = ubRouting::filters($rawCredit, 'vf');
  14. }
  15. //checking money format
  16. if (empty($credit)) {
  17. //ignoring empty values
  18. $creditValid = true;
  19. $credit = 0; //override with zero value
  20. } else {
  21. $creditValid = zb_checkMoney($credit);
  22. }
  23. if ($creditValid) {
  24. //credit limit check
  25. if ($creditLimitOpt != 'DISABLED') {
  26. if ($credit <= $creditLimitOpt) {
  27. $billing->setcredit($login, $credit);
  28. log_register('CHANGE Credit (' . $login . ') ON ' . $credit);
  29. } else {
  30. log_register('FAIL Credit (' . $login . ') LIMIT `' . $credit . '` HAWK TUAH `' . $creditLimitOpt . '`');
  31. show_error(__('The amount of allowed credit limit has been exceeded'));
  32. }
  33. } else {
  34. $billing->setcredit($login, $credit);
  35. log_register('CHANGE Credit (' . $login . ') ON ' . $credit);
  36. ubRouting::nav('?module=creditedit&username=' . $login);
  37. }
  38. } else {
  39. show_error(__('Wrong format of money sum'));
  40. }
  41. }
  42. $current_credit = zb_UserGetStargazerData($login);
  43. $current_credit = $current_credit['Credit'];
  44. $useraddress = zb_UserGetFullAddress($login) . ' (' . $login . ')';
  45. //check is user corporate?
  46. if ($altCfg['USER_LINKING_ENABLED']) {
  47. if ($altCfg['USER_LINKING_CREDIT']) {
  48. if (cu_IsChild($login)) {
  49. $allchildusers = cu_GetAllLinkedUsers();
  50. $parent_link = $allchildusers[$login];
  51. ubRouting::nav("?module=corporate&userlink=" . $parent_link . "&control=credit");
  52. }
  53. if (cu_IsParent($login)) {
  54. $allparentusers = cu_GetAllParentUsers();
  55. $parent_link = $allparentusers[$login];
  56. ubRouting::nav("?module=corporate&userlink=" . $parent_link . "&control=credit");
  57. }
  58. }
  59. }
  60. // Edit form construct
  61. $fieldnames = array('fieldname1' => __('Current credit'), 'fieldname2' => __('New credit'));
  62. $fieldkey = 'newcredit';
  63. $form = web_EditorStringDataForm($fieldnames, $fieldkey, $useraddress, $current_credit);
  64. $form .= web_UserControls($login);
  65. show_window(__('Edit credit'), $form);
  66. } else {
  67. show_error(__('Strange exception') . ': ' . __('Empty login'));
  68. show_window('', wf_tag('center') . wf_img('skins/unicornwrong.png') . wf_tag('center', true));
  69. }
  70. /**
  71. * I fell deeper and deeper as light now was gone
  72. * I could feel the dark embrace my soul
  73. */
  74. } else {
  75. show_error(__('You cant control this module'));
  76. }