index.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. if(cfr('MASSSEND')) {
  3. $alter_conf= rcms_parse_ini_file(CONFIG_PATH."alter.ini");
  4. set_time_limit(0);
  5. function ms_SendMessage($login,$message) {
  6. $globconf=parse_ini_file('config/billing.ini');
  7. $SGCONF=$globconf['SGCONF'];
  8. $STG_HOST=$globconf['STG_HOST'];
  9. $STG_PORT=$globconf['STG_PORT'];
  10. $STG_LOGIN=$globconf['STG_LOGIN'];
  11. $STG_PASSWD=$globconf['STG_PASSWD'];
  12. $configurator='LANG=ru_UA.utf8 '.$SGCONF.' set -s '.$STG_HOST.' -p '.$STG_PORT.' -a'.$STG_LOGIN.' -w'.$STG_PASSWD.' -u '.$login.' -m "'.$message.'"';
  13. shell_exec($configurator);
  14. }
  15. function ms_TicketCreate($from,$to,$text,$replyto='NULL',$admin='') {
  16. $from=mysql_real_escape_string($from);
  17. $to=mysql_real_escape_string($to);
  18. $admin=mysql_real_escape_string($admin);
  19. $text=mysql_real_escape_string(strip_tags($text));
  20. $date=curdatetime();
  21. $replyto=vf($replyto);
  22. $query="
  23. INSERT INTO `ticketing` (
  24. `id` ,
  25. `date` ,
  26. `replyid` ,
  27. `status` ,
  28. `from` ,
  29. `to` ,
  30. `text`,
  31. `admin`
  32. )
  33. VALUES (
  34. NULL ,
  35. '".$date."',
  36. ".$replyto.",
  37. '0',
  38. '".$from."',
  39. '".$to."',
  40. '".$text."',
  41. '".$admin."'
  42. );
  43. ";
  44. nr_query($query);
  45. }
  46. function ms_TicketSetDone($ticketid) {
  47. $ticketid=vf($ticketid);
  48. simple_update_field('ticketing', 'status', '1', "WHERE `id`='".$ticketid."'");
  49. }
  50. function ms_MassSendMessage($users_arr,$message) {
  51. global $alter_conf;
  52. if (!empty($users_arr)) {
  53. foreach ($users_arr as $eachuser) {
  54. if (!$alter_conf['MASSSEND_SAFE']) {
  55. ms_SendMessage($eachuser, $message);
  56. } else {
  57. ms_TicketCreate('NULL', $eachuser, $message,'NULL',whoami());
  58. $newid=simple_get_lastid('ticketing');
  59. ms_TicketSetDone($newid);
  60. }
  61. }
  62. log_register("MASSEND (".sizeof($users_arr).")");
  63. }
  64. }
  65. function ms_ShowForm() {
  66. $inputs=__('Message').'<br>';
  67. $inputs.=wf_TextArea('message', '', '', true, '60x6');
  68. $inputs.=wf_TextInput('exactuserlogins', 'Exact users, comma delimiter', '', true, '30');
  69. $inputs.=wf_RadioInput('sendtype', 'Exact users', 'exactusers', true,true);
  70. $inputs.=wf_RadioInput('sendtype', 'Debtors', 'debtors', true);
  71. $inputs.=wf_RadioInput('sendtype', 'All users', 'allusers', true);
  72. $inputs.=wf_Submit('Send');
  73. $form= wf_Form('', 'POST', $inputs, 'glamour');
  74. show_window(__('Masssender'),$form);
  75. }
  76. function ms_GetDebtors() {
  77. $query="SELECT `login` from `users` WHERE `Cash`<0";
  78. $result=array();
  79. $alldebtors= simple_queryall($query);
  80. if (!empty($alldebtors)) {
  81. foreach ($alldebtors as $io=>$eachdebtor) {
  82. $result[]=$eachdebtor['login'];
  83. }
  84. }
  85. return($result);
  86. }
  87. function ms_GetAllusers() {
  88. $query="SELECT `login` from `users`";
  89. $result=array();
  90. $allusers= simple_queryall($query);
  91. if (!empty($allusers)) {
  92. foreach ($allusers as $io=>$eachuser) {
  93. $result[]=$eachuser['login'];
  94. }
  95. }
  96. return($result);
  97. }
  98. function ms_GetExactUsers() {
  99. $result=array();
  100. if (wf_CheckPost(array('exactuserlogins'))) {
  101. $usersplit=explode(',',$_POST['exactuserlogins']);
  102. if (!empty($usersplit)) {
  103. foreach ($usersplit as $eachlogin) {
  104. $result[]=trim($eachlogin);
  105. }
  106. }
  107. }
  108. return($result);
  109. }
  110. if ($alter_conf['MASSSEND_ENABLED']) {
  111. //show form
  112. ms_ShowForm();
  113. //send messages if need
  114. if (wf_CheckPost(array('sendtype'))) {
  115. $sendtype=$_POST['sendtype'];
  116. if ($sendtype=='debtors') {
  117. $users_arr= ms_GetDebtors();
  118. }
  119. if ($sendtype=='allusers') {
  120. $users_arr= ms_GetAllusers();
  121. }
  122. if ($sendtype=='exactusers') {
  123. $users_arr= ms_GetExactUsers();
  124. }
  125. if (wf_CheckPost(array('message'))) {
  126. ms_MassSendMessage($users_arr, $_POST['message']);
  127. }
  128. }
  129. } else {
  130. show_error(__('Disabled'));
  131. }
  132. } else {
  133. show_error(__('Access denied'));
  134. }
  135. ?>