index.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <?php
  2. if (cfr('REPORTCOMPLEX')) {
  3. class ReportComplex {
  4. protected $data = array();
  5. protected $masks = array();
  6. protected $cfields = array();
  7. protected $contracts = array();
  8. protected $actives = array();
  9. protected $altCfg = array();
  10. protected $ukvCableSeals = array();
  11. const CPL_SETTINGS_EX = 'NO_SETTINGS_DEFINED';
  12. const CPL_EMPTY_EX = 'EMPTY_SETTINGS_RECEIVED';
  13. const CPL_COUNT_EX = 'WRONG_PARAM_COUNT';
  14. public function __construct() {
  15. //loads report specific options
  16. try {
  17. $this->loadConfig();
  18. } catch(Exception $err) {
  19. show_error($err->getMessage());
  20. }
  21. //load actual data by users with complex services
  22. $this->loadData();
  23. }
  24. /*
  25. * loads report specific options from alter config to private props masks & cfields
  26. *
  27. * @return void
  28. */
  29. private function loadConfig() {
  30. global $ubillingConfig;
  31. $altercfg = $ubillingConfig->getAlter();
  32. $this->altCfg = $altercfg;
  33. if ((isset($altercfg['COMPLEX_MASKS'])) AND ( isset($altercfg['COMPLEX_CFIDS']))) {
  34. //loads tariff masks
  35. if (!empty($altercfg['COMPLEX_MASKS'])) {
  36. $masksRaw = explode(",", $altercfg['COMPLEX_MASKS']);
  37. if (!empty($masksRaw)) {
  38. foreach ($masksRaw as $eachmask) {
  39. $this->masks[] = "'" . trim($eachmask) . "%'";
  40. }
  41. }
  42. } else {
  43. throw new Exception(self::CPL_EMPTY_EX);
  44. }
  45. //loads contract and enabled flags CFIDs
  46. if (!empty($altercfg['COMPLEX_CFIDS'])) {
  47. if (!empty($altercfg['COMPLEX_CFIDS'])) {
  48. $cfieldsRaw = explode(',', $altercfg['COMPLEX_CFIDS']);
  49. if (sizeof($cfieldsRaw) == 2) {
  50. $this->cfields['contract'] = trim($cfieldsRaw[0]);
  51. $this->cfields['active'] = trim($cfieldsRaw[1]);
  52. } else {
  53. throw new Exception(self::CPL_COUNT_EX);
  54. }
  55. }
  56. } else {
  57. throw new Exception(self::CPL_EMPTY_EX);
  58. }
  59. } else {
  60. throw new Exception(self::CPL_SETTINGS_EX);
  61. }
  62. }
  63. /*
  64. * get all users with complex service tariffs
  65. *
  66. * @return void
  67. */
  68. protected function loadData() {
  69. $tariffLikes = '';
  70. if (!empty($this->masks)) {
  71. $tariffLikes = implode(' OR `Tariff` LIKE ', $this->masks);
  72. }
  73. $query = "SELECT * from `users` WHERE `Tariff` LIKE " . $tariffLikes . ";";
  74. $alldata = simple_queryall($query);
  75. if (!empty($alldata)) {
  76. $this->data = $alldata;
  77. }
  78. if ( !empty($this->cfields) ) {
  79. //loading complex service contracts
  80. $queryContracts = "SELECT `login`,`content` from `cfitems` WHERE `typeid`='" . $this->cfields['contract'] . "'";
  81. $allContracts = simple_queryall($queryContracts);
  82. if (!empty($allContracts)) {
  83. foreach ($allContracts as $ia => $eachContract) {
  84. $this->contracts[$eachContract['login']] = $eachContract['content'];
  85. }
  86. }
  87. //loading complex services activity flags
  88. $queryActive = "SELECT `login`,`content` from `cfitems` WHERE `typeid`='" . $this->cfields['active'] . "'";
  89. $allActive = simple_queryall($queryActive);
  90. if (!empty($allActive)) {
  91. foreach ($allActive as $ib => $eachActive) {
  92. $this->actives[$eachActive['login']] = $eachActive['content'];
  93. }
  94. }
  95. }
  96. //extracting ukv cable seals if required
  97. if ($this->altCfg['UKV_ENABLED']) {
  98. $sealQuery = "SELECT `cableseal`,`inetlogin` from `ukv_users`";
  99. $rawSeals = simple_queryall($sealQuery);
  100. if (!empty($rawSeals)) {
  101. foreach ($rawSeals as $io => $each) {
  102. $this->ukvCableSeals[$each['inetlogin']] = $each['cableseal'];
  103. }
  104. }
  105. }
  106. }
  107. /*
  108. * returns private propert data
  109. *
  110. * @return array
  111. */
  112. public function getData() {
  113. $result = $this->data;
  114. return ($result);
  115. }
  116. public function printable($data) {
  117. $style = file_get_contents(CONFIG_PATH . "ukvprintable.css");
  118. $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  119. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
  120. <head>
  121. <title></title>
  122. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  123. <style type="text/css">
  124. ' . $style . '
  125. </style>
  126. <script src="modules/jsc/sorttable.js" language="javascript"></script>
  127. </head>
  128. <body>
  129. ';
  130. $footer = '</body> </html>';
  131. $result = $header . $data . $footer;
  132. return ($result);
  133. }
  134. /*
  135. * renders all users report by existing private data props
  136. *
  137. * @param $cutdata - bool cutting profile links and leds, for printing
  138. *
  139. * @return string
  140. */
  141. public function renderAll($cutdata = false) {
  142. $alladdress = zb_AddressGetFulladdresslistCached();
  143. $allrealnames = zb_UserGetAllRealnames();
  144. $userCounter = 0;
  145. $cells = '';
  146. if (!$cutdata) {
  147. $cells.= wf_TableCell(__('Login'));
  148. }
  149. $cells.= wf_TableCell(__('Address'));
  150. $cells.= wf_TableCell(__('Real Name'));
  151. if ($this->altCfg['UKV_ENABLED']) {
  152. $cells.= wf_TableCell(__('Cable seal'));
  153. } else {
  154. $cells.= wf_TableCell(__('IP'));
  155. }
  156. $cells.= wf_TableCell(__('Tariff'));
  157. $cells.= wf_TableCell(__('Cash'));
  158. $cells.= wf_TableCell(__('Credit'));
  159. $cells.= wf_TableCell(__('Contract'));
  160. $cells.= wf_TableCell(__('Service active'));
  161. $rows = wf_TableRow($cells, 'row1');
  162. if (!empty($this->data)) {
  163. foreach ($this->data as $io => $each) {
  164. $cells = '';
  165. if (!$cutdata) {
  166. $profileLink = wf_Link('?module=userprofile&username=' . $each['login'], web_profile_icon() . ' ' . $each['login'], false, '');
  167. $cells = wf_TableCell($profileLink);
  168. }
  169. $cells.= wf_TableCell(@$alladdress[$each['login']]);
  170. $cells.= wf_TableCell(@$allrealnames[$each['login']]);
  171. if ($this->altCfg['UKV_ENABLED']) {
  172. $cells.=wf_TableCell(@$this->ukvCableSeals[$each['login']]);
  173. } else {
  174. $cells.= wf_TableCell($each['IP']);
  175. }
  176. $cells.= wf_TableCell($each['Tariff']);
  177. $cells.= wf_TableCell($each['Cash']);
  178. $cells.= wf_TableCell($each['Credit']);
  179. $cells.= wf_TableCell(@$this->contracts[$each['login']]);
  180. $actFlag = web_bool_led(@$this->actives[$each['login']], true);
  181. if ($cutdata) {
  182. $actFlag = strip_tags($actFlag);
  183. }
  184. $cells.= wf_TableCell($actFlag, '', '', 'sorttable_customkey="' . @$this->actives[$each['login']] . '"');
  185. $rows.= wf_TableRow($cells, 'row3');
  186. $userCounter++;
  187. }
  188. }
  189. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  190. $result.= __('Total') . ': ' . $userCounter;
  191. return ($result);
  192. }
  193. /*
  194. * renders debtors users report by existing private data props
  195. *
  196. * @param $cutdata - bool cutting profile links and leds, for printing
  197. *
  198. * @return string
  199. */
  200. public function renderDebtors($cutdata = false) {
  201. $alladdress = zb_AddressGetFulladdresslistCached();
  202. $allrealnames = zb_UserGetAllRealnames();
  203. $userCounter = 0;
  204. $cells = '';
  205. if (!$cutdata) {
  206. $cells.= wf_TableCell(__('Login'));
  207. }
  208. $cells.= wf_TableCell(__('Address'));
  209. $cells.= wf_TableCell(__('Real Name'));
  210. if ($this->altCfg['UKV_ENABLED']) {
  211. $cells.= wf_TableCell(__('Cable seal'));
  212. } else {
  213. $cells.= wf_TableCell(__('IP'));
  214. }
  215. $cells.= wf_TableCell(__('Tariff'));
  216. $cells.= wf_TableCell(__('Cash'));
  217. $cells.= wf_TableCell(__('Credit'));
  218. $cells.= wf_TableCell(__('Contract'));
  219. $cells.= wf_TableCell(__('Service active'));
  220. $rows = wf_TableRow($cells, 'row1');
  221. if (!empty($this->data)) {
  222. foreach ($this->data as $io => $each) {
  223. if ((($each['Cash'] < ('-' . $each['Credit'])) AND ( @$this->actives[$each['login']] == 1)) OR ( ($each['Passive'] == '1') AND ( @$this->actives[$each['login']] == 1))) {
  224. $cells = '';
  225. if (!$cutdata) {
  226. $profileLink = wf_Link('?module=userprofile&username=' . $each['login'], web_profile_icon() . ' ' . $each['login'], false, '');
  227. $cells = wf_TableCell($profileLink);
  228. }
  229. $cells.= wf_TableCell(@$alladdress[$each['login']]);
  230. $cells.= wf_TableCell(@$allrealnames[$each['login']]);
  231. if ($this->altCfg['UKV_ENABLED']) {
  232. $cells.= wf_TableCell(@$this->ukvCableSeals[$each['login']]);
  233. } else {
  234. $cells.= wf_TableCell($each['IP']);
  235. }
  236. $cells.= wf_TableCell($each['Tariff']);
  237. $cells.= wf_TableCell($each['Cash']);
  238. $cells.= wf_TableCell($each['Credit']);
  239. $cells.= wf_TableCell(@$this->contracts[$each['login']]);
  240. $actFlag = web_bool_led(@$this->actives[$each['login']], true);
  241. if ($cutdata) {
  242. $actFlag = strip_tags($actFlag);
  243. }
  244. $cells.= wf_TableCell($actFlag, '', '', 'sorttable_customkey="' . @$this->actives[$each['login']] . '"');
  245. $rows.= wf_TableRow($cells, 'row3');
  246. $userCounter++;
  247. }
  248. }
  249. }
  250. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  251. $result.= __('Total') . ': ' . $userCounter;
  252. return ($result);
  253. }
  254. /*
  255. * renders anti-debtors users report by existing private data props
  256. *
  257. * @param $cutdata - bool cutting profile links and leds, for printing
  258. *
  259. * @return string
  260. */
  261. public function renderAntiDebtors($cutdata = false) {
  262. $alladdress = zb_AddressGetFulladdresslistCached();
  263. $allrealnames = zb_UserGetAllRealnames();
  264. $userCounter = 0;
  265. $cells = '';
  266. if (!$cutdata) {
  267. $cells.= wf_TableCell(__('Login'));
  268. }
  269. $cells.= wf_TableCell(__('Address'));
  270. $cells.= wf_TableCell(__('Real Name'));
  271. if ($this->altCfg['UKV_ENABLED']) {
  272. $cells.=wf_TableCell(__('Cable seal'));
  273. } else {
  274. $cells.= wf_TableCell(__('IP'));
  275. }
  276. $cells.= wf_TableCell(__('Tariff'));
  277. $cells.= wf_TableCell(__('Cash'));
  278. $cells.= wf_TableCell(__('Credit'));
  279. $cells.= wf_TableCell(__('Contract'));
  280. $cells.= wf_TableCell(__('Service active'));
  281. $rows = wf_TableRow($cells, 'row1');
  282. if (!empty($this->data)) {
  283. foreach ($this->data as $io => $each) {
  284. if (($each['Cash'] >= ('-' . $each['Credit'])) AND ( @$this->actives[$each['login']] != 1) AND ( $each['Passive'] != 1)) {
  285. $cells = '';
  286. if (!$cutdata) {
  287. $profileLink = wf_Link('?module=userprofile&username=' . $each['login'], web_profile_icon() . ' ' . $each['login'], false, '');
  288. $cells = wf_TableCell($profileLink);
  289. }
  290. $cells.= wf_TableCell(@$alladdress[$each['login']]);
  291. $cells.= wf_TableCell(@$allrealnames[$each['login']]);
  292. if ($this->altCfg['UKV_ENABLED']) {
  293. $cells.=wf_TableCell(@$this->ukvCableSeals[$each['login']]);
  294. } else {
  295. $cells.= wf_TableCell($each['IP']);
  296. }
  297. $cells.= wf_TableCell($each['Tariff']);
  298. $cells.= wf_TableCell($each['Cash']);
  299. $cells.= wf_TableCell($each['Credit']);
  300. $cells.= wf_TableCell(@$this->contracts[$each['login']]);
  301. $actFlag = web_bool_led(@$this->actives[$each['login']], true);
  302. if ($cutdata) {
  303. $actFlag = strip_tags($actFlag);
  304. }
  305. $cells.= wf_TableCell($actFlag, '', '', 'sorttable_customkey="' . @$this->actives[$each['login']] . '"');
  306. $rows.= wf_TableRow($cells, 'row3');
  307. $userCounter++;
  308. }
  309. }
  310. }
  311. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  312. $result.= __('Total') . ': ' . $userCounter;
  313. return ($result);
  314. }
  315. /*
  316. * Shows navigation panel for reports
  317. *
  318. */
  319. public function panel() {
  320. $controls = wf_Link('?module=report_complex', __('All users'), false, 'ubButton');
  321. $controls.= wf_Link('?module=report_complex&show=debtors', __('Debtors'), false, 'ubButton');
  322. $controls.= wf_Link('?module=report_complex&show=antidebtors', __('AntiDebtors'), false, 'ubButton');
  323. $controls.= wf_Link('?module=report_complex&show=nmcomplex', __('Complex service next month'), false, 'ubButton');
  324. return ($controls);
  325. }
  326. }
  327. class ReportComplexNM extends ReportComplex {
  328. /*
  329. * get all users with with complex services from the next month
  330. *
  331. * @return void
  332. */
  333. protected function loadData() {
  334. $tariffLikes = '';
  335. if (!empty($this->masks)) {
  336. $tariffLikes = implode(' OR `TariffChange` LIKE ', $this->masks);
  337. }
  338. $query = "SELECT * from `users` WHERE `TariffChange` LIKE " . $tariffLikes . ";";
  339. $alldata = simple_queryall($query);
  340. if (!empty($alldata)) {
  341. $this->data = $alldata;
  342. }
  343. if ( !empty($this->cfields) ) {
  344. //loading complex service contracts
  345. $queryContracts = "SELECT `login`,`content` from `cfitems` WHERE `typeid`='" . $this->cfields['contract'] . "'";
  346. $allContracts = simple_queryall($queryContracts);
  347. if (!empty($allContracts)) {
  348. foreach ($allContracts as $ia => $eachContract) {
  349. $this->contracts[$eachContract['login']] = $eachContract['content'];
  350. }
  351. }
  352. //loading complex services activity flags
  353. $queryActive = "SELECT `login`,`content` from `cfitems` WHERE `typeid`='" . $this->cfields['active'] . "'";
  354. $allActive = simple_queryall($queryActive);
  355. if (!empty($allActive)) {
  356. foreach ($allActive as $ib => $eachActive) {
  357. $this->actives[$eachActive['login']] = $eachActive['content'];
  358. }
  359. }
  360. }
  361. }
  362. /*
  363. * renders all users report by existing private data props
  364. *
  365. * @param $cutdata - bool cutting profile links and leds, for printing
  366. *
  367. * @return string
  368. */
  369. public function renderAll($cutdata = false) {
  370. $alladdress = zb_AddressGetFulladdresslist();
  371. $allrealnames = zb_UserGetAllRealnames();
  372. $userCounter = 0;
  373. $cells = '';
  374. if (!$cutdata) {
  375. $cells.= wf_TableCell(__('Login'));
  376. }
  377. $cells.= wf_TableCell(__('Address'));
  378. $cells.= wf_TableCell(__('Real Name'));
  379. $cells.= wf_TableCell(__('IP'));
  380. $cells.= wf_TableCell(__('Tariff'));
  381. $cells.= wf_TableCell(__('Next month'));
  382. $cells.= wf_TableCell(__('Cash'));
  383. $cells.= wf_TableCell(__('Credit'));
  384. $cells.= wf_TableCell(__('Contract'));
  385. $cells.= wf_TableCell(__('Service active'));
  386. $rows = wf_TableRow($cells, 'row1');
  387. if (!empty($this->data)) {
  388. foreach ($this->data as $io => $each) {
  389. $cells = '';
  390. if (!$cutdata) {
  391. $profileLink = wf_Link('?module=userprofile&username=' . $each['login'], web_profile_icon() . ' ' . $each['login'], false, '');
  392. $cells = wf_TableCell($profileLink);
  393. }
  394. $cells.= wf_TableCell(@$alladdress[$each['login']]);
  395. $cells.= wf_TableCell(@$allrealnames[$each['login']]);
  396. $cells.= wf_TableCell($each['IP']);
  397. $cells.= wf_TableCell($each['Tariff']);
  398. $cells.= wf_TableCell($each['TariffChange']);
  399. $cells.= wf_TableCell($each['Cash']);
  400. $cells.= wf_TableCell($each['Credit']);
  401. $cells.= wf_TableCell(@$this->contracts[$each['login']]);
  402. $actFlag = web_bool_led(@$this->actives[$each['login']], true);
  403. if ($cutdata) {
  404. $actFlag = strip_tags($actFlag);
  405. }
  406. $cells.= wf_TableCell($actFlag, '', '', 'sorttable_customkey="' . @$this->actives[$each['login']] . '"');
  407. $rows.= wf_TableRow($cells, 'row3');
  408. $userCounter++;
  409. }
  410. }
  411. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  412. $result.= __('Total') . ': ' . $userCounter;
  413. return ($result);
  414. }
  415. }
  416. /**
  417. * controller and view section
  418. */
  419. $altercfg = rcms_parse_ini_file(CONFIG_PATH . "alter.ini");
  420. if (isset($altercfg['COMPLEX_ENABLED'])) {
  421. if ($altercfg['COMPLEX_ENABLED']) {
  422. $complexReport = new ReportComplex();
  423. //showing navigation
  424. show_window(__('Users with complex services'), $complexReport->panel());
  425. if (!wf_CheckGet(array('show'))) {
  426. //show all users by default
  427. $reportHeader = __('All users with complex services');
  428. if (!wf_CheckGet(array('printable'))) {
  429. $reportHeader.=' ' . wf_Link('?module=report_complex&printable=true', wf_img('skins/printer_small.gif', __('Print')), false, '');
  430. show_window($reportHeader, $complexReport->renderAll());
  431. } else {
  432. $reportData = wf_tag('h2') . $reportHeader . wf_tag('h2', true);
  433. $reportData.= $complexReport->renderAll(true);
  434. $reportData = $complexReport->printable($reportData);
  435. die($reportData);
  436. }
  437. } else {
  438. $action = trim($_GET['show']);
  439. if ($action == 'debtors') {
  440. $reportHeader = __('Debtors who need disabling additional service');
  441. if (!wf_CheckGet(array('printable'))) {
  442. //normal render
  443. $reportHeader.=' ' . wf_Link('?module=report_complex&show=debtors&printable=true', wf_img('skins/printer_small.gif', __('Print')), false, '');
  444. $reportData = $complexReport->renderDebtors();
  445. show_window($reportHeader, $reportData);
  446. } else {
  447. //printable mode
  448. $reportData = wf_tag('h2') . $reportHeader . wf_tag('h2', true);
  449. $reportData.= $complexReport->renderDebtors(true);
  450. $reportData = $complexReport->printable($reportData);
  451. die($reportData);
  452. }
  453. }
  454. if ($action == 'antidebtors') {
  455. $reportHeader = __('AntiDebtors who need enabling additional service');
  456. if (!wf_CheckGet(array('printable'))) {
  457. //normal render
  458. $reportHeader.=' ' . wf_Link('?module=report_complex&show=antidebtors&printable=true', wf_img('skins/printer_small.gif', __('Print')), false, '');
  459. $reportData = $complexReport->renderAntiDebtors();
  460. show_window($reportHeader, $reportData);
  461. } else {
  462. //printable mode
  463. $reportData = wf_tag('h2') . $reportHeader . wf_tag('h2', true);
  464. $reportData.= $complexReport->renderAntiDebtors(true);
  465. $reportData = $complexReport->printable($reportData);
  466. die($reportData);
  467. }
  468. }
  469. if ($action == 'nmcomplex') {
  470. $nmComplexReport = new ReportComplexNM();
  471. $reportHeader = __('Complex service next month');
  472. if (!wf_CheckGet(array('printable'))) {
  473. //normal render
  474. $reportHeader.=' ' . wf_Link('?module=report_complex&show=nmcomplex&printable=true', wf_img('skins/printer_small.gif', __('Print')), false, '');
  475. $reportData = $nmComplexReport->renderAll();
  476. show_window($reportHeader, $reportData);
  477. } else {
  478. //printable mode
  479. $reportData = wf_tag('h2') . $reportHeader . wf_tag('h2', true);
  480. $reportData.= $nmComplexReport->renderAll(true);
  481. $reportData = $nmComplexReport->printable($reportData);
  482. die($reportData);
  483. }
  484. }
  485. }
  486. } else {
  487. show_error(__('This module is disabled'));
  488. }
  489. }
  490. } else {
  491. show_error(__('You cant control this module'));
  492. }
  493. ?>