api.percity.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  1. <?php
  2. /**
  3. * Class for coloring users by tag color
  4. */
  5. Class ColorTagging {
  6. /**
  7. * Contains all tags
  8. *
  9. * @var array Tags
  10. */
  11. protected $allTags = array();
  12. /**
  13. * Contains all tag types
  14. *
  15. * @var array Types
  16. */
  17. protected $allTagTypes = array();
  18. /**
  19. * Contains alter.ini contents
  20. *
  21. * @var array Alter.ini contents
  22. */
  23. protected $altCfg = array();
  24. public function __construct() {
  25. $this->LoadAllTags();
  26. $this->LoadAllTagTypes();
  27. $this->loadAlter();
  28. }
  29. /**
  30. * Select from DB all data from table `tags` and place it to $this->allTags
  31. * in format $this->allTags[$eachLogin] = $eachTagID;
  32. *
  33. * @return void
  34. */
  35. protected function LoadAllTags() {
  36. $query = "SELECT * FROM `tags`";
  37. $allData = simple_queryall($query);
  38. if (!empty($allData)) {
  39. foreach ($allData as $eachData) {
  40. $this->allTags[$eachData['login']] = $eachData['tagid'];
  41. }
  42. }
  43. }
  44. /**
  45. * $Select from DB all data from table `tagtypes` and place it to $this->allTagTypes
  46. * in format $this->allTagTypes[$eachID] = $eachData;
  47. *
  48. * @return void
  49. */
  50. protected function LoadAllTagTypes() {
  51. $query = "SELECT * FROM `tagtypes`";
  52. $allData = simple_queryall($query);
  53. if (!empty($allData)) {
  54. foreach ($allData as $eachData) {
  55. $this->allTagTypes[$eachData['id']] = $eachData;
  56. }
  57. }
  58. }
  59. /**
  60. * Loads all alter.ini contents into $this->altCfg
  61. *
  62. * @global array $ubillingConfig
  63. *
  64. * @return void
  65. */
  66. protected function loadAlter() {
  67. global $ubillingConfig;
  68. $this->altCfg = $ubillingConfig->getAlter();
  69. }
  70. /**
  71. * Find's user's tag and it color if it exsists
  72. *
  73. * @param string $login User's login
  74. *
  75. * @return string Color in hex format (#000000)
  76. */
  77. public function GetUsersColor($login) {
  78. $color = '';
  79. $allowed = '';
  80. $equal = false;
  81. if (isset($this->allTags[$login]) and isset($this->allTagTypes[$this->allTags[$login]]['tagcolor'])) {
  82. if (isset($this->altCfg['ALLOWED_COLORS'])) {
  83. if (is_numeric($this->altCfg['ALLOWED_COLORS'])) {
  84. $allowed = $this->altCfg['ALLOWED_COLORS'];
  85. if ($this->allTagTypes[$this->allTags[$login]]['id'] == $allowed) {
  86. $equal = true;
  87. }
  88. } else {
  89. $allowed = explode(",", $this->altCfg['ALLOWED_COLORS']);
  90. foreach ($allowed as $each) {
  91. if ($this->allTagTypes[$this->allTags[$login]]['id'] == $each) {
  92. $equal = true;
  93. }
  94. }
  95. }
  96. if ($equal) {
  97. $color = $this->allTagTypes[$this->allTags[$login]]['tagcolor'];
  98. }
  99. } else {
  100. $color = $this->allTagTypes[$this->allTags[$login]]['tagcolor'];
  101. }
  102. }
  103. return($color);
  104. }
  105. }
  106. /**
  107. * Class for making some reports in range on one city
  108. */
  109. class PerCityAction {
  110. const MODULE_NAME = "?module=per_city_action";
  111. const PERMISSION_PATH = "content/documents/per_city_permission/";
  112. /**
  113. * Contains all addresses array as login=>address
  114. *
  115. * @var array
  116. */
  117. protected $allAddresses = array();
  118. /**
  119. * Contains all realnames array as login=>realname
  120. *
  121. * @var array
  122. */
  123. protected $allRealNames = array();
  124. /**
  125. * Contains array of all available cashtypes as id=>name
  126. *
  127. * @var array
  128. */
  129. protected $allCashTypes = array();
  130. /**
  131. * Contains all data for opts usersearch, debtors, payments
  132. * usersearch - query selects all users in certain city
  133. * debtors - query selects all debtors in certain city
  134. * payments - query select all payments in certain city by month (by default current month)
  135. *
  136. * @var array
  137. */
  138. protected $allData = array();
  139. /**
  140. * Contains array of available virtualservices as Service:id=>tagname
  141. *
  142. * @var array
  143. */
  144. protected $allServiceNames = array();
  145. /**
  146. * Contains all users that took credit by month
  147. *
  148. * @var aray
  149. */
  150. protected $allCredited = array();
  151. /**
  152. * Contains all contracts as array contract=>login
  153. *
  154. * @var array
  155. */
  156. protected $allContracts = array();
  157. /**
  158. * Contains all of user tariffs as login=>tariff array
  159. *
  160. * @var array
  161. */
  162. protected $allTariffs = array();
  163. /**
  164. * Contains all onus as login=>mac_onu
  165. *
  166. * @var array
  167. */
  168. protected $allOnu = array();
  169. protected $allOnuMac = array();
  170. /**
  171. * Contains all users notes as login=>note
  172. *
  173. * @var array
  174. */
  175. protected $allNotes = array();
  176. /**
  177. * Contains all users comments as login=>comment
  178. *
  179. * @var array
  180. */
  181. protected $allComments = array();
  182. /**
  183. * Contains all users phone data as
  184. * login[phone] = phone
  185. * login[mobile] = mobile
  186. *
  187. * @var array
  188. */
  189. protected $allPhoneData = array();
  190. /**
  191. * Contains all config alter.ini data
  192. *
  193. * @var array
  194. */
  195. protected $altCfg = array();
  196. /**
  197. * All active logins in selected data.
  198. * Need for sorting data
  199. *
  200. * @var array
  201. */
  202. protected $activeLogin = array();
  203. /**
  204. * Storing ONU signal cache
  205. *
  206. * @var array
  207. */
  208. protected $signalCache = array();
  209. public function __construct() {
  210. $this->LoadAddresses();
  211. $this->LoadRealNames();
  212. $this->loadAlter();
  213. }
  214. /**
  215. * Get full address list of all users and load it into $this->allAddress
  216. *
  217. * @return void
  218. */
  219. protected function LoadAddresses() {
  220. $this->allAddresses = zb_AddressGetFulladdresslist();
  221. }
  222. /**
  223. * Get all realnames of all users and load it into $this->allRealNames
  224. *
  225. * @return void
  226. */
  227. protected function LoadRealNames() {
  228. $this->allRealNames = zb_UserGetAllRealnames();
  229. }
  230. /**
  231. * Get all cash types and load it into $this->allCashTypes
  232. *
  233. * @return void
  234. */
  235. protected function LoadCashTypes() {
  236. $this->allCashTypes = zb_CashGetAllCashTypes();
  237. }
  238. /**
  239. * Get all service names and load it to $this->allServiceNames
  240. *
  241. * @return void
  242. */
  243. protected function LoadAllServiceNames() {
  244. $this->allServiceNames = zb_VservicesGetAllNamesLabeled();
  245. }
  246. /**
  247. * Get all data by date about self credited users and load it to $this->allCredited
  248. *
  249. * @param string $date
  250. *
  251. * @return void
  252. */
  253. public function LoadAllCredited($date = '') {
  254. if (empty($date)) {
  255. $date = $this->GetCurrentDate();
  256. }
  257. $query = "SELECT * FROM `zbssclog` WHERE `date` LIKE '" . $date . "%';";
  258. $allCredited = simple_queryall($query);
  259. if (!empty($allCredited)) {
  260. foreach ($allCredited as $eachCredited) {
  261. $this->allCredited[$eachCredited['login']] = $eachCredited['date'];
  262. }
  263. }
  264. }
  265. /**
  266. * Get all users contracts and load it into $this->allContracts
  267. *
  268. * @return void
  269. */
  270. protected function LoadAllContracts() {
  271. $this->allContracts = array_flip(zb_UserGetAllContracts());
  272. }
  273. /**
  274. * Get all users tariffs
  275. *
  276. * @return void
  277. */
  278. protected function LoadAllTariffs() {
  279. $this->allTariffs = zb_TariffsGetAllUsers();
  280. }
  281. /**
  282. * Get all users pon Data (mac onu, oltid) and load into $this->allOnu
  283. *
  284. * @return void
  285. */
  286. protected function LoadAllOnu() {
  287. $query = "SELECT * FROM `pononu`";
  288. $allonu = simple_queryall($query);
  289. $onu = array();
  290. if (!empty($allonu)) {
  291. foreach ($allonu as $io => $each) {
  292. $this->allOnuMac[$each['login']] = $each['mac'];
  293. $this->allOnu[$each['login']] = $each;
  294. }
  295. }
  296. }
  297. /**
  298. * Get all data from tables `notes` and `adcomments` and place it into $this->allNotes
  299. *
  300. * @return void
  301. */
  302. protected function LoadAllNotes() {
  303. $query = "SELECT * FROM `notes`";
  304. $allNotes = simple_queryall($query);
  305. if (!empty($allNotes)) {
  306. foreach ($allNotes as $ia => $eachnote) {
  307. $this->allNotes[$eachnote['login']] = $eachnote['note'];
  308. }
  309. }
  310. $query = "SELECT * FROM `adcomments`";
  311. $allComments = simple_queryall($query);
  312. if (!empty($allComments)) {
  313. foreach ($allComments as $ia => $eachcomment) {
  314. if (isset($this->allNotes[$eachcomment['item']])) {
  315. $this->allNotes[$eachcomment['item']].= " " . $eachcomment['text'];
  316. } else {
  317. $this->allNotes[$eachcomment['item']] = $eachcomment['text'];
  318. }
  319. }
  320. }
  321. }
  322. /**
  323. * Get all users phones data info $this->allPhoneData
  324. *
  325. * @return void
  326. */
  327. protected function LoadAllPhoneData() {
  328. $this->allPhoneData = zb_UserGetAllPhoneData();
  329. }
  330. /**
  331. * Load alter.ini config file info $this->altCfg
  332. *
  333. * @return void
  334. */
  335. protected function loadAlter() {
  336. $this->altCfg = rcms_parse_ini_file(CONFIG_PATH . 'alter.ini');
  337. }
  338. /**
  339. * Loads all onu signals from cache into $this->signalCache
  340. *
  341. * @return void
  342. */
  343. protected function loadSignalsCache() {
  344. $availCacheData = rcms_scandir(PONizer::SIGCACHE_PATH, '*_' . PONizer::SIGCACHE_EXT);
  345. if (!empty($availCacheData)) {
  346. foreach ($availCacheData as $io => $each) {
  347. $raw = file_get_contents(PONizer::SIGCACHE_PATH . $each);
  348. $raw = unserialize($raw);
  349. foreach ($raw as $mac => $signal) {
  350. $this->signalCache[$mac] = $signal;
  351. }
  352. }
  353. }
  354. }
  355. /**
  356. * Loading data depended from user choice in reports to $this->allData
  357. *
  358. * @param string $currentDate
  359. * @param int $cityId
  360. * @param string $type Type of report
  361. * @param string $from From date
  362. * @param string $to To date
  363. * @param string $by_day By one day
  364. *
  365. * @return void
  366. */
  367. public function LoadAllData($currentDate, $cityId, $type, $from = '', $to = '', $by_day = '') {
  368. switch ($type) {
  369. case "payments":
  370. $query = "SELECT * FROM `payments` WHERE `date` LIKE '" . $currentDate . "%' AND `login` IN (SELECT `login` FROM `address` WHERE `aptid` IN (SELECT `id` FROM `apt` WHERE `buildid` IN (SELECT `id` FROM `build` WHERE `streetid` IN (SELECT `id` FROM `street` WHERE `cityid`='" . $cityId . "'))))";
  371. $data = simple_queryall($query);
  372. if (!empty($data)) {
  373. foreach ($data as $each => $io) {
  374. $this->allData[$io['id']] = $io;
  375. }
  376. }
  377. break;
  378. case "usersearch":
  379. $query = "SELECT * FROM `users` WHERE `login` IN (SELECT `login` FROM `address` WHERE `aptid` IN (SELECT `id` FROM `apt` WHERE `buildid` IN (SELECT `id` FROM `build` WHERE `streetid` IN (SELECT `id` FROM `street` WHERE `cityid`='" . $cityId . "'))))";
  380. $data = simple_queryall($query);
  381. if (!empty($data)) {
  382. $this->allData = $data;
  383. }
  384. break;
  385. case "debtors":
  386. $query = "SELECT * FROM `users` WHERE `cash` < 0 AND `login` IN (SELECT `login` FROM `address` WHERE `aptid` IN (SELECT `id` FROM `apt` WHERE `buildid` IN (SELECT `id` FROM `build` WHERE `streetid` IN (SELECT `id` FROM `street` WHERE `cityid`='" . $cityId . "'))))";
  387. $data = simple_queryall($query);
  388. if (!empty($data)) {
  389. $this->allData = $data;
  390. }
  391. break;
  392. case "analytics":
  393. if (empty($by_day)) {
  394. $query = "SELECT * FROM `payments` WHERE `date` BETWEEN CAST('" . $from . "' AS DATE) AND CAST('" . $to . "' AS DATE) AND `login` IN (SELECT `login` FROM `address` WHERE `aptid` IN (SELECT `id` FROM `apt` WHERE `buildid` IN (SELECT `id` FROM `build` WHERE `streetid` IN (SELECT `id` FROM `street` WHERE `cityid`='" . $cityId . "'))))";
  395. } else {
  396. $query = "SELECT * FROM `payments` WHERE `date` LIKE '" . $by_day . "%' AND `login` IN (SELECT `login` FROM `address` WHERE `aptid` IN (SELECT `id` FROM `apt` WHERE `buildid` IN (SELECT `id` FROM `build` WHERE `streetid` IN (SELECT `id` FROM `street` WHERE `cityid`='" . $cityId . "'))))";
  397. }
  398. $data = simple_queryall($query);
  399. if (!empty($data)) {
  400. $this->allData = $data;
  401. }
  402. break;
  403. }
  404. }
  405. /**
  406. * Returns form for payments by city within some month (by default - current month)
  407. *
  408. * @return string
  409. */
  410. public function PaymentsShow() {
  411. $total = 0;
  412. $totalPayCount = 0;
  413. $this->LoadCashTypes();
  414. $cells = wf_TableCell(__('IDENC'));
  415. $cells.= wf_TableCell(__('Date'));
  416. $cells.= wf_TableCell(__('Cash'));
  417. if ($this->altCfg['FINREP_CONTRACT']) {
  418. $cells.= wf_TableCell(__('Contract'));
  419. $this->LoadAllContracts();
  420. }
  421. if ($this->altCfg['TRANSLATE_PAYMENTS_NOTES']) {
  422. $this->LoadAllServiceNames();
  423. }
  424. $cells.= wf_TableCell(__('Login'));
  425. $cells.= wf_TableCell(__('Full address'));
  426. $cells.= wf_TableCell(__('Real Name'));
  427. if ($this->altCfg['FINREP_TARIFF']) {
  428. $cells.=wf_TableCell(__('Tariff'));
  429. $this->LoadAllTariffs();
  430. }
  431. $cells.= wf_TableCell(__('Cash type'));
  432. $cells.= wf_TableCell(__('Was credited'));
  433. $cells.= wf_TableCell(__('Notes'));
  434. $cells.= wf_TableCell(__('Admin'));
  435. $rows = wf_TableRow($cells, 'row1');
  436. if (!empty($this->allData)) {
  437. foreach ($this->allData as $io => $eachpayment) {
  438. if ($this->altCfg['TRANSLATE_PAYMENTS_NOTES']) {
  439. $eachpayment['note'] = zb_TranslatePaymentNote($eachpayment['note'], $this->allServiceNames);
  440. }
  441. $cells = wf_TableCell(zb_NumEncode($eachpayment['id']));
  442. $cells.= wf_TableCell($eachpayment['date']);
  443. $cells.= wf_TableCell($eachpayment['summ']);
  444. if ($this->altCfg['FINREP_CONTRACT']) {
  445. $cells.= wf_TableCell(@$this->allContracts[$eachpayment['login']]);
  446. }
  447. $cells.= wf_TableCell(wf_Link('?module=userprofile&username=' . $eachpayment['login'], (web_profile_icon() . ' ' . $eachpayment['login']), false, ''));
  448. $cells.= wf_TableCell(@$this->allAddresses[$eachpayment['login']]);
  449. $cells.= wf_TableCell(@$this->allRealNames[$eachpayment['login']]);
  450. if ($this->altCfg['FINREP_TARIFF']) {
  451. $cells.= wf_TableCell(@$this->allTariffs[$eachpayment['login']]);
  452. }
  453. $cells.= wf_TableCell(@__($this->allCashTypes[$eachpayment['cashtypeid']]));
  454. $cells.= wf_TableCell(@$this->allCredited[$eachpayment['login']]);
  455. $cells.= wf_TableCell($eachpayment['note']);
  456. $cells.= wf_TableCell($eachpayment['admin']);
  457. $rows.= wf_TableRow($cells, 'row4');
  458. $total = $total + $eachpayment['summ'];
  459. $totalPayCount++;
  460. }
  461. }
  462. $result = wf_TableBody($rows, '100%', '0', 'sortable id');
  463. $result.=wf_tag('strong') . __('Cash') . ': ' . $total . wf_tag('strong', true) . wf_tag('br');
  464. $result.=wf_tag('strong') . __('Count') . ': ' . $totalPayCount . wf_tag('strong', true);
  465. return($result);
  466. }
  467. /**
  468. * Returns form for usersearch and debtors by city
  469. *
  470. * @return string
  471. */
  472. public function PerCityDataShow() {
  473. $this->LoadAllOnu();
  474. $this->LoadAllNotes();
  475. $this->LoadAllPhoneData();
  476. $this->LoadAllCredited();
  477. $this->loadSignalsCache();
  478. $addr_sort = 'address_down';
  479. $realname_sort = 'realname_down';
  480. $credited_sort = 'credited_down';
  481. $cash_sort = 'cash_down';
  482. $tariff_sort = 'tariff_down';
  483. $comment_sort = 'comment_down';
  484. $signal_sort = 'signal_down';
  485. $mac_onu_sort = 'mac_onu_down';
  486. if (isset($_GET['sort'])) {
  487. switch ($_GET['sort']) {
  488. case 'address_up':
  489. $this->sort_additional($this->allAddresses, SORT_ASC);
  490. break;
  491. case 'address_down':
  492. $this->sort_additional($this->allAddresses, SORT_DESC);
  493. break;
  494. case 'realname_up':
  495. $this->sort_additional($this->allRealNames, SORT_ASC);
  496. break;
  497. case 'realname_down':
  498. $this->sort_additional($this->allRealNames, SORT_DESC);
  499. break;
  500. case 'credited_up':
  501. $this->sort_additional($this->allCredited, SORT_ASC);
  502. break;
  503. case 'credited_down':
  504. $this->sort_additional($this->allCredited, SORT_DESC);
  505. break;
  506. case 'cash_up':
  507. $this->sort_standart('Cash', SORT_ASC);
  508. break;
  509. case 'cash_down':
  510. $this->sort_standart('Cash', SORT_DESC);
  511. break;
  512. case 'tariff_up':
  513. $this->sort_standart('Tariff', SORT_ASC);
  514. break;
  515. case 'tariff_down':
  516. $this->sort_standart('Tariff', SORT_DESC);
  517. break;
  518. case 'comment_up':
  519. $this->sort_additional($this->allNotes, SORT_ASC);
  520. break;
  521. case 'comment_down':
  522. $this->sort_additional($this->allNotes, SORT_DESC);
  523. break;
  524. case 'signal_up':
  525. $this->sort_signal($this->allOnu, $this->signalCache, SORT_ASC);
  526. break;
  527. case 'signal_down':
  528. $this->sort_signal($this->allOnu, $this->signalCache, SORT_DESC);
  529. break;
  530. case 'mac_onu_up':
  531. $this->sort_additional($this->allOnuMac, SORT_ASC);
  532. break;
  533. case 'mac_onu_down':
  534. $this->sort_additional($this->allOnuMac, SORT_DESC);
  535. break;
  536. }
  537. if ($_GET['sort'] == 'address_down') {
  538. $addr_sort = 'address_up';
  539. }
  540. if ($_GET['sort'] == 'realname_down') {
  541. $realname_sort = 'realname_up';
  542. }
  543. if ($_GET['sort'] == 'credited_down') {
  544. $credited_sort = 'credited_up';
  545. }
  546. if ($_GET['sort'] == 'cash_down') {
  547. $cash_sort = 'cash_up';
  548. }
  549. if ($_GET['sort'] == 'tariff_down') {
  550. $tariff_sort = 'tariff_up';
  551. }
  552. if ($_GET['sort'] == 'comment_down') {
  553. $comment_sort = 'comment_up';
  554. }
  555. if ($_GET['sort'] == 'signal_down') {
  556. $signal_sort = 'signal_up';
  557. }
  558. if ($_GET['sort'] == 'mac_onu_down') {
  559. $mac_onu_sort = 'mac_onu_up';
  560. }
  561. }
  562. $total = 0;
  563. $totalPayCount = 0;
  564. $colors = new ColorTagging();
  565. $cells = wf_TableCell(wf_tag('h2', false) . __('ID') . wf_tag('h2', true));
  566. $cells.= wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $addr_sort, __('Full address')) . wf_tag('h2', true));
  567. $cells.= wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $realname_sort, __('Real Name')) . wf_tag('h2', true));
  568. $cells.= wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $credited_sort, __('Was credited')) . wf_tag('h2', true));
  569. $cells.= wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $cash_sort, __('Cash')) . wf_tag('h2', true));
  570. if ($this->altCfg['FINREP_TARIFF']) {
  571. $cells.=wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $tariff_sort, __('Tariff')) . wf_tag('h2', true));
  572. $this->LoadAllTariffs();
  573. }
  574. $cells.= wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $comment_sort, __('Comment')) . wf_tag('h2', true));
  575. $cells.= wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $signal_sort, __('Signal')) . wf_tag('h2', true));
  576. $cells.= wf_TableCell(wf_tag('h2', false) . wf_Link($this->SaveGetParams('sort') . 'sort=' . $mac_onu_sort, __('MAC ONU/ONT')) . wf_tag('h2', true));
  577. $cells.= wf_TableCell(wf_tag('h2', false) . __('Login') . wf_tag('h2', true));
  578. $rows = wf_TableRow($cells, 'row1');
  579. if (!empty($this->allData)) {
  580. foreach ($this->allData as $eachdebtor) {
  581. $total = $total + $eachdebtor['Cash'];
  582. $totalPayCount++;
  583. $signal = @$this->signalCache[$this->allOnu[$eachdebtor['login']]['mac']];
  584. $sigColor = '#000000';
  585. if (!empty($signal)) {
  586. if (($signal > 0) OR ( $signal < -25)) {
  587. $sigColor = '#ab0000';
  588. } else {
  589. $sigColor = '#005502';
  590. }
  591. } else {
  592. $signal = __("No");
  593. }
  594. $userColor = $colors->GetUsersColor($eachdebtor['login']);
  595. $cell = wf_TableCell($totalPayCount);
  596. $cell.= wf_TableCell(@$this->allAddresses[$eachdebtor['login']]);
  597. $cell.= wf_TableCell(@$this->allRealNames[$eachdebtor['login']] . "&nbsp&nbsp" . @$this->allPhoneData[$eachdebtor['login']]['mobile']);
  598. $cell.= wf_TableCell(@$this->allCredited[$eachdebtor['login']]);
  599. $cell.= wf_TableCell($eachdebtor['Cash']);
  600. if ($this->altCfg['FINREP_TARIFF']) {
  601. $cell.= wf_TableCell($this->allTariffs[$eachdebtor['login']]);
  602. }
  603. $cell.= wf_TableCell(@$this->allNotes[$eachdebtor['login']]);
  604. $cell.= wf_TableCell(wf_tag('strong') . wf_tag('font color=' . $sigColor, false) . $signal . wf_tag('font', true) . wf_tag('strong', true));
  605. $cell.= wf_TableCell(@$this->allOnu[$eachdebtor['login']]['mac']);
  606. $cell.= wf_TableCell(wf_Link('?module=userprofile&username=' . $eachdebtor['login'], (web_profile_icon() . ' ' . $eachdebtor['login']), false, ''));
  607. if (!empty($userColor)) {
  608. $style = "background-color:$userColor";
  609. $rows.= wf_TableRowStyled($cell, 'row4', $style);
  610. } else {
  611. $rows.= wf_TableRow($cell, 'row4');
  612. }
  613. }
  614. }
  615. $result = wf_tag('strong') . __('Count') . ': ' . $totalPayCount . wf_tag('strong', true) . wf_tag('br');
  616. $result.=wf_tag('strong') . __('Cash') . ': ' . $total . wf_tag('strong', true) . wf_tag('br');
  617. $result.= wf_TableBody($rows, '100%', '0', '');
  618. return($result);
  619. }
  620. /**
  621. * Shows analytics form by city and date
  622. *
  623. * @return string
  624. */
  625. public function AnalyticsShow() {
  626. $total = 0;
  627. $totalPayCount = 0;
  628. $cardPays = 0;
  629. $paySystems = array();
  630. $adminPays = array();
  631. if (!empty($this->allData)) {
  632. foreach ($this->allData as $io => $eachPayment) {
  633. if ($eachPayment['admin'] != 'external' && $eachPayment['admin'] != 'openpayz' && $eachPayment['admin'] != 'guest') {
  634. if (!isset($adminPays[$eachPayment['admin']])) {
  635. $adminPays[$eachPayment['admin']] = $eachPayment['summ'];
  636. } else {
  637. if ($eachPayment['summ'] > 0) {
  638. $adminPays[$eachPayment['admin']] += $eachPayment['summ'];
  639. }
  640. }
  641. }
  642. $findPaySystems = explode(':', $eachPayment['note']);
  643. if ($findPaySystems[0] == 'OP') {
  644. if (!isset($paySystems[$findPaySystems[1]])) {
  645. $paySystems[$findPaySystems[1]] = $eachPayment['summ'];
  646. } else {
  647. $paySystems[$findPaySystems[1]] += $eachPayment['summ'];
  648. }
  649. } elseif ($findPaySystems[0] == 'CARD') {
  650. $cardPays += $eachPayment['summ'];
  651. }
  652. if ($eachPayment['summ'] > 0) {
  653. $total += $eachPayment['summ'];
  654. }
  655. $totalPayCount++;
  656. }
  657. }
  658. $cells = __('Admin');
  659. $cells.= wf_TableCell(__('Type'), '50%');
  660. $cells.= wf_TableCell(__('Cash'));
  661. $rows = wf_TableRow($cells, 'row1');
  662. foreach ($adminPays as $eachAdmin => $summ) {
  663. $cells = wf_TableCell($eachAdmin);
  664. $cells.= wf_TableCell($summ);
  665. $rows.= wf_TableRow($cells, 'row3');
  666. }
  667. $form = wf_TableBody($rows, '100%', '0', 'sortable');
  668. $cells = __('Internet');
  669. $cells.= wf_TableCell(__('Type'), '50%');
  670. $cells.= wf_TableCell(__('Cash'));
  671. $rows = wf_TableRow($cells, 'row1');
  672. foreach ($paySystems as $eachPaySystem => $summ) {
  673. $cells = wf_TableCell($eachPaySystem);
  674. $cells.= wf_TableCell($summ);
  675. $rows.= wf_TableRow($cells, 'row3');
  676. }
  677. $form.= wf_tag('br');
  678. $form.= wf_TableBody($rows, '100%', '0', 'sortable');
  679. $cells = __('Cards');
  680. $cells.= wf_TableCell(__('Type'), '50%');
  681. $cells.= wf_TableCell(__('Cash'));
  682. $rows = wf_TableRow($cells, 'row1');
  683. $cells = wf_TableCell(__("Cards"));
  684. $cells.= wf_TableCell($cardPays);
  685. $rows.= wf_TableRow($cells, 'row3');
  686. $form.= wf_tag('br');
  687. $form.= wf_TableBody($rows, '100%', '0', 'sortable');
  688. $form.=wf_tag('strong') . __('Cash') . ': ' . $total . wf_tag('strong', true) . wf_tag('br');
  689. $form.=wf_tag('strong') . __('Count') . ': ' . $totalPayCount . wf_tag('strong', true);
  690. return($form);
  691. }
  692. /**
  693. * City selector with check rights
  694. *
  695. * @param string $admin
  696. * @param string $action
  697. *
  698. * @return string
  699. */
  700. public function CitySelector($admin, $action) {
  701. $form = wf_tag('form', false, '', 'action="" method="GET"');
  702. $form.= wf_tag('table', false, '', 'width="100%" border="0"');
  703. if (!isset($_GET['citysel'])) {
  704. $cells = wf_TableCell(__('City'), '40%');
  705. $cells.= wf_HiddenInput("module", "per_city_action");
  706. $cells.= wf_HiddenInput("action", $action);
  707. if (isset($_GET['monthsel'])) {
  708. $cells.= wf_HiddenInput('monthsel', $_GET['monthsel']);
  709. }
  710. if (isset($_GET['from_date'])) {
  711. $cells.= wf_HiddenInput("from_date", $_GET['from_date']);
  712. }
  713. if (isset($_GET['to_date'])) {
  714. $cells.= wf_HiddenInput("to_date", $_GET['to_date']);
  715. }
  716. if (isset($_GET['by_day'])) {
  717. $cells.= wf_HiddenInput("by_day", $_GET['by_day']);
  718. }
  719. if (isset($_GET['year'])) {
  720. $cells.= wf_HiddenInput("year", $_GET['year']);
  721. }
  722. $cells.= wf_TableCell($this->CitySelectorPermissioned($admin));
  723. $form.= wf_TableRow($cells, 'row3');
  724. } else {
  725. $cityname = zb_AddressGetCityData($_GET['citysel']);
  726. $cityname = $cityname['cityname'];
  727. $cells = wf_TableCell(__('City'), '40%');
  728. $cells.= wf_HiddenInput("module", "per_city_action");
  729. $cells.= wf_HiddenInput("action", $action);
  730. if (isset($_GET['monthsel'])) {
  731. $cells.= wf_HiddenInput('monthsel', $_GET['monthsel']);
  732. }
  733. if (isset($_GET['from_date'])) {
  734. $cells.= wf_HiddenInput("from_date", $_GET['from_date']);
  735. }
  736. if (isset($_GET['to_date'])) {
  737. $cells.= wf_HiddenInput("to_date", $_GET['to_date']);
  738. }
  739. if (isset($_GET['by_day'])) {
  740. $cells.= wf_HiddenInput("by_day", $_GET['by_day']);
  741. }
  742. if (isset($_GET['year'])) {
  743. $cells.= wf_HiddenInput("year", $_GET['year']);
  744. }
  745. $cells.= wf_TableCell(web_ok_icon() . ' ' . $cityname . wf_HiddenInput('citysearch', $_GET['citysel']));
  746. $cells.= wf_TableCell(wf_Submit(__('Find')));
  747. $form.= wf_TableRow($cells, 'row3');
  748. }
  749. $form.=wf_tag('table', true);
  750. $form.=wf_tag('form', true);
  751. return($form);
  752. }
  753. /**
  754. * Returns auto-clicking city selector
  755. *
  756. * @return string
  757. */
  758. protected function CitySelectorPermissioned($admin) {
  759. $allcity = array();
  760. $tmpCity = zb_AddressGetCityAllData();
  761. $allcity['-'] = '-'; //placeholder
  762. if (!empty($tmpCity)) {
  763. if (file_exists(self::PERMISSION_PATH . $admin)) {
  764. $data = file_get_contents(self::PERMISSION_PATH . $admin);
  765. $eachId = explode(",", $data);
  766. foreach ($tmpCity as $io => $each) {
  767. $check = false;
  768. foreach ($eachId as $id) {
  769. if ($each['id'] == $id) {
  770. $check = true;
  771. }
  772. }
  773. if ($check) {
  774. $allcity[$each['id']] = $each['cityname'];
  775. }
  776. }
  777. } else {
  778. foreach ($tmpCity as $io => $each) {
  779. $allcity[$each['id']] = $each['cityname'];
  780. }
  781. }
  782. }
  783. $selector = wf_SelectorAC('citysel', $allcity, '', '', false);
  784. $selector.= wf_tag('a', false, '', 'href="?module=city" target="_BLANK"') . web_city_icon() . wf_tag('a', true);
  785. return ($selector);
  786. }
  787. /**
  788. * Returns check box cities selecor
  789. *
  790. * @return string
  791. */
  792. public function CityChecker($admin) {
  793. $tmpCity = zb_AddressGetCityAllData();
  794. $checker = '';
  795. $i = 0;
  796. if (!empty($tmpCity)) {
  797. if (file_exists(self::PERMISSION_PATH . $admin)) {
  798. $data = file_get_contents(self::PERMISSION_PATH . $admin);
  799. if (!empty($data)) {
  800. $eachId = explode(",", $data);
  801. foreach ($tmpCity as $io => $each) {
  802. $checked = false;
  803. foreach ($eachId as $id) {
  804. if ($each['id'] == $id) {
  805. $checked = true;
  806. }
  807. }
  808. $checker.= $this->CheckInput("city[$i]", $each['cityname'], $each['id'], true, $checked);
  809. $i++;
  810. }
  811. }
  812. } else {
  813. foreach ($tmpCity as $io => $each) {
  814. $checker.= $this->CheckInput("city[$i]", $each['cityname'], $each['id'], true, false);
  815. $i++;
  816. }
  817. }
  818. $checker.= wf_delimiter(0);
  819. $checker.= wf_Submit(__('Send'));
  820. }
  821. $form = wf_Form('', 'POST', $checker);
  822. return ($form);
  823. }
  824. /**
  825. * Returns available administrators list
  826. *
  827. * @return string
  828. */
  829. public function ListAdmins() {
  830. $alladmins = rcms_scandir(USERS_PATH);
  831. $cells = wf_TableCell(__('Admin'));
  832. $cells.= wf_TableCell(__('Actions'));
  833. $rows = wf_TableRow($cells, 'row1');
  834. if (!empty($alladmins)) {
  835. foreach ($alladmins as $eachadmin) {
  836. $actions = wf_Link(self::MODULE_NAME . '&action=permission&edit=' . $eachadmin, web_edit_icon('Rights'));
  837. $actions.= wf_Link(self::MODULE_NAME . '&action=permission&delete=' . $eachadmin, web_delete_icon());
  838. $cells = wf_TableCell($eachadmin);
  839. $cells.= wf_TableCell($actions);
  840. $rows.= wf_TableRow($cells, 'row3');
  841. }
  842. }
  843. $form = wf_TableBody($rows, '100%', '0', 'sortable');
  844. return($form);
  845. }
  846. /**
  847. * Return check box Web From element
  848. *
  849. * @param string $name name of element
  850. * @param string $label text label for input
  851. * @param bool $br append new line
  852. * @param bool $checked is checked?
  853. *
  854. * @return string
  855. */
  856. protected function CheckInput($name, $label = '', $value = '', $br = false, $checked = false) {
  857. $inputid = wf_InputId();
  858. if ($br) {
  859. $newline = '<br>';
  860. } else {
  861. $newline = '';
  862. }
  863. if ($checked) {
  864. $check = 'checked=""';
  865. } else {
  866. $check = '';
  867. }
  868. if ($value != '') {
  869. $result = '<input type="checkbox" id="' . $inputid . '" name="' . $name . '" ' . $check . ' value=' . $value . ' />';
  870. } else {
  871. $result = '<input type="checkbox" id="' . $inputid . '" name="' . $name . '" ' . $check . ' />';
  872. }
  873. if ($label != '') {
  874. $result.=' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  875. ;
  876. }
  877. $result.=$newline . "\n";
  878. return ($result);
  879. }
  880. /**
  881. * Check weather admin have enough rights to see reports by city
  882. *
  883. * @param int $cityID
  884. * @param string $admin
  885. *
  886. * @return boolean
  887. */
  888. public function CheckRigts($cityID, $admin) {
  889. $result = false;
  890. if (file_exists(self::PERMISSION_PATH . $admin)) {
  891. $data = file_get_contents(self::PERMISSION_PATH . $admin);
  892. $data = explode(",", $data);
  893. foreach ($data as $each) {
  894. if ($each == $cityID) {
  895. $result = true;
  896. }
  897. }
  898. } else {
  899. return true;
  900. }
  901. return ($result);
  902. }
  903. /**
  904. * Return web form for date picking
  905. *
  906. * @param string $action
  907. *
  908. * @return string
  909. */
  910. public function ChooseDateForm($action) {
  911. $inputs = wf_HiddenInput("module", "per_city_action");
  912. $inputs.= wf_HiddenInput("action", $action);
  913. if (isset($_GET['citysearch'])) {
  914. $inputs.= wf_HiddenInput("citysearch", $_GET['citysearch']);
  915. }
  916. if (isset($_GET['citysel'])) {
  917. $inputs.= wf_HiddenInput("citysel", $_GET['citysel']);
  918. }
  919. $inputs.= wf_DatePicker('from_date', true);
  920. $inputs.= __('From');
  921. $inputs.= wf_tag('br');
  922. $inputs.= wf_DatePicker('to_date', true);
  923. $inputs.= __('To');
  924. $inputs.= wf_delimiter();
  925. $inputs.= wf_Submit(__('Send'));
  926. $formBetween = wf_Form('', 'GET', $inputs);
  927. $cells = wf_TableCell($formBetween);
  928. $inputs = wf_HiddenInput("module", "per_city_action");
  929. $inputs.= wf_HiddenInput("action", $action);
  930. if (isset($_GET['citysearch'])) {
  931. $inputs.= wf_HiddenInput("citysearch", $_GET['citysearch']);
  932. }
  933. if (isset($_GET['citysel'])) {
  934. $inputs.= wf_HiddenInput("citysel", $_GET['citysel']);
  935. }
  936. $inputs.= wf_DatePicker(__("by day"), true);
  937. $inputs.= __('By day');
  938. $inputs.= wf_delimiter();
  939. $inputs.= wf_Submit(__('Send'));
  940. $formByDate = wf_Form('', 'GET', $inputs);
  941. $cells.= wf_TableCell($formByDate);
  942. $rows = wf_TableRow($cells);
  943. $result = wf_TableBody($rows, "100%", '0', '');
  944. return($result);
  945. }
  946. /**
  947. * By default getting current date in YYYY-MM format
  948. * or in case of some parameters returns only YYYY or MM
  949. *
  950. * @param bool $onlyMonth
  951. * @param bool $onlyYear
  952. * @return string
  953. */
  954. public function GetCurrentDate($onlyMonth = false, $onlyYear = false) {
  955. if ($onlyMonth) {
  956. return (date("m"));
  957. } elseif ($onlyYear) {
  958. return (date("o"));
  959. } else {
  960. return (date("Y-m"));
  961. }
  962. }
  963. /**
  964. * Load all logins from $this->allData to $this->activeLogin.
  965. * Need for sorting
  966. *
  967. * @return void
  968. */
  969. protected function getCurrentLogins() {
  970. foreach ($this->allData as $eachData => $eachValue) {
  971. $this->activeLogin[$eachValue['login']] = $eachValue;
  972. }
  973. }
  974. /**
  975. * Reads all current get parameters and make string from all of them except $except
  976. *
  977. * @param string $except
  978. *
  979. * @return string
  980. */
  981. protected function SaveGetParams($except) {
  982. $url = '?';
  983. foreach ($_GET as $key => $value) {
  984. if ($key != $except) {
  985. $url.= $key . '=' . $value . '&';
  986. }
  987. }
  988. return ($url);
  989. }
  990. /**
  991. * Function for sorting data in $this->allData.
  992. * Used for sorting cash and tariffs.
  993. *
  994. * @param array $sortingData
  995. * @param string $type
  996. *
  997. * @return void
  998. */
  999. protected function sort_standart($sortingData, $type) {
  1000. $sorted = array();
  1001. foreach ($this->allData as $eachKey => $eachValue) {
  1002. $sorted[][$sortingData] = $eachValue[$sortingData];
  1003. }
  1004. array_multisort($sorted, $type, $this->allData);
  1005. }
  1006. /**
  1007. * Function for sorting data in $this->allData.
  1008. * Used for sorting all data except onu singals, cash and tariffs.
  1009. *
  1010. * @param array $sortingData
  1011. * @param string $type
  1012. *
  1013. * @return void
  1014. */
  1015. protected function sort_additional($sortingData, $type) {
  1016. $this->getCurrentLogins();
  1017. $sorted = array();
  1018. foreach ($sortingData as $eachKey => $eachValue) {
  1019. if (isset($this->activeLogin[$eachKey])) {
  1020. $sorted[]['login'] = $eachValue . ';' . $eachKey;
  1021. }
  1022. }
  1023. array_multisort($sorted, $type);
  1024. $fullData = $this->allData;
  1025. $this->allData = array();
  1026. foreach ($sorted as $sortedKey => $sortedValue) {
  1027. $tmp = explode(";", $sortedValue['login']);
  1028. foreach ($fullData as $dataKey => $dataValue) {
  1029. if ($dataValue['login'] == $tmp[1]) {
  1030. $this->allData[] = $dataValue;
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. foreach ($fullData as $eachKey => $eachValue) {
  1036. $eq = false;
  1037. foreach ($this->allData as $dataKey => $dataValue) {
  1038. if ($dataValue['login'] == $eachValue['login']) {
  1039. $eq = true;
  1040. }
  1041. }
  1042. if (!$eq) {
  1043. $this->allData[] = $eachValue;
  1044. }
  1045. }
  1046. }
  1047. /**
  1048. * Function for sorting data in $this->allData.
  1049. * User onlu for sorting by onu signals.
  1050. *
  1051. * @param array $allOnu
  1052. * @param array $signalCache
  1053. * @param string $type
  1054. *
  1055. * @return void
  1056. */
  1057. protected function sort_signal($allOnu, $signalCache, $type) {
  1058. $this->getCurrentLogins();
  1059. foreach ($this->activeLogin as $eachKey => $eachValue) {
  1060. if (isset($allOnu[$eachKey])) {
  1061. if (isset($signalCache[$allOnu[$eachKey]['mac']])) {
  1062. $sorted[]['login'] = $signalCache[$allOnu[$eachKey]['mac']] . ';' . $eachKey;
  1063. }
  1064. }
  1065. }
  1066. array_multisort($sorted, $type);
  1067. $fullData = $this->allData;
  1068. $this->allData = array();
  1069. foreach ($sorted as $sortedKey => $sortedValue) {
  1070. $tmp = explode(";", $sortedValue['login']);
  1071. foreach ($fullData as $dataKey => $dataValue) {
  1072. if ($dataValue['login'] == $tmp[1]) {
  1073. $this->allData[] = $dataValue;
  1074. break;
  1075. }
  1076. }
  1077. }
  1078. foreach ($fullData as $eachKey => $eachValue) {
  1079. $eq = false;
  1080. foreach ($this->allData as $dataKey => $dataValue) {
  1081. if ($dataValue['login'] == $eachValue['login']) {
  1082. $eq = true;
  1083. }
  1084. }
  1085. if (!$eq) {
  1086. $this->allData[] = $eachValue;
  1087. }
  1088. }
  1089. }
  1090. }
  1091. function GetAllCreditedUsers() {
  1092. $date = date("Y-m");
  1093. $query = "SELECT * FROM `zbssclog` WHERE `date` LIKE '" . $date . "%';";
  1094. $allCredited = simple_queryall($query);
  1095. if (!empty($allCredited)) {
  1096. foreach ($allCredited as $eachCredited) {
  1097. $creditedUsers[$eachCredited['login']] = $eachCredited['date'];
  1098. }
  1099. return($creditedUsers);
  1100. } else {
  1101. return(false);
  1102. }
  1103. }
  1104. /**
  1105. * Get all data from tables `notes` and `adcomments` and place it into $this->allNotes
  1106. *
  1107. * @return void
  1108. */
  1109. function GetAllNotes() {
  1110. $result = '';
  1111. $query = "SELECT * FROM `notes`";
  1112. $allNotes = simple_queryall($query);
  1113. if (!empty($allNotes)) {
  1114. foreach ($allNotes as $ia => $eachnote) {
  1115. $result[$eachnote['login']] = $eachnote['note'];
  1116. }
  1117. }
  1118. $query = "SELECT * FROM `adcomments`";
  1119. $allComments = simple_queryall($query);
  1120. if (!empty($allComments)) {
  1121. foreach ($allComments as $ia => $eachcomment) {
  1122. if (isset($result[$eachcomment['item']])) {
  1123. $result[$eachcomment['item']].= " " . $eachcomment['text'];
  1124. } else {
  1125. $result[$eachcomment['item']] = $eachcomment['text'];
  1126. }
  1127. }
  1128. }
  1129. return $result;
  1130. }
  1131. /**
  1132. * Get all users pon Data (mac onu, oltid) and load into $this->allOnu
  1133. *
  1134. * @return void
  1135. */
  1136. function GetAllOnu() {
  1137. $query = "SELECT * FROM `pononu`";
  1138. $allonu = simple_queryall($query);
  1139. $result = '';
  1140. if (!empty($allonu)) {
  1141. foreach ($allonu as $io => $each) {
  1142. $result[$each['login']] = $each['mac'];
  1143. }
  1144. }
  1145. return $result;
  1146. }
  1147. function web_ReportCityShowPrintable($titles, $keys, $alldata, $address = 0, $realnames = 0, $rowcount = 0) {
  1148. $alter_conf = rcms_parse_ini_file(CONFIG_PATH . 'alter.ini');
  1149. $report_name = wf_tag('h2') . __("Debtors by city") . wf_tag('h2', true);
  1150. $allrealnames = zb_UserGetAllRealnames();
  1151. $alladdress = zb_AddressGetFulladdresslist();
  1152. if ($alter_conf['FINREP_TARIFF']) {
  1153. $alltariffs = zb_TariffsGetAllUsers();
  1154. }
  1155. $allphonedata = zb_UserGetAllPhoneData();
  1156. $allnotes = GetAllNotes();
  1157. $allonu = GetAllOnu();
  1158. $allCredited = GetAllCreditedUsers();
  1159. $i = 0;
  1160. $style = '
  1161. <script src="modules/jsc/sorttable.js" language="javascript"></script>
  1162. <style type="text/css">
  1163. table.printrm tbody {
  1164. counter-reset: sortabletablescope;
  1165. border-width: 1px;
  1166. padding: 1px;
  1167. border-style: dashed;
  1168. border-color: gray;
  1169. background-color: white;
  1170. -moz-border-radius: ;
  1171. }
  1172. table.printrm thead tr::before {
  1173. border-width: 1px;
  1174. padding: 1px;
  1175. border-style: dashed;
  1176. border-color: gray;
  1177. background-color: white;
  1178. -moz-border-radius: ;
  1179. text-align: center;
  1180. vertical-align: middle;
  1181. content: "ID";
  1182. display: table-cell;
  1183. }
  1184. table.printrm tbody tr::before {
  1185. border-width: 1px;
  1186. padding: 1px;
  1187. border-style: dashed;
  1188. border-color: gray;
  1189. background-color: white;
  1190. -moz-border-radius: ;
  1191. text-align: center;
  1192. vertical-align: middle;
  1193. content: counter(sortabletablescope);
  1194. counter-increment: sortabletablescope;
  1195. display: table-cell;
  1196. }
  1197. table.printrm {
  1198. border-width: 1px;
  1199. border-spacing: 2px;
  1200. border-style: outset;
  1201. border-color: gray;
  1202. border-collapse: separate;
  1203. background-color: white;
  1204. }
  1205. table.printrm th {
  1206. border-width: 1px;
  1207. padding: 1px;
  1208. border-style: dashed;
  1209. border-color: gray;
  1210. background-color: white;
  1211. -moz-border-radius: ;
  1212. }
  1213. table.printrm td {
  1214. border-width: 1px;
  1215. padding: 1px;
  1216. border-style: dashed;
  1217. border-color: gray;
  1218. background-color: white;
  1219. -moz-border-radius: ;
  1220. }
  1221. </style>';
  1222. $cells = '';
  1223. if ($address) {
  1224. $cells.= wf_TableCell(__('Full address'));
  1225. }
  1226. if ($realnames) {
  1227. $cells.= wf_TableCell(__('Real Name'));
  1228. }
  1229. foreach ($titles as $eachtitle) {
  1230. $cells.= wf_TableCell(__($eachtitle));
  1231. }
  1232. $rows = wf_TableRow($cells);
  1233. if (!empty($alldata)) {
  1234. foreach ($alldata as $io => $eachdata) {
  1235. $i++;
  1236. $cells = '';
  1237. if ($address) {
  1238. $cells.= wf_TableCell(@$alladdress[$eachdata['login']]);
  1239. }
  1240. if ($realnames) {
  1241. $cells.= wf_TableCell(@$allrealnames[$eachdata['login']] . "&nbsp" . @$allphonedata[$eachdata['login']]['mobile']);
  1242. }
  1243. if ($alter_conf['FINREP_TARIFF']) {
  1244. $cells.= wf_TableCell(@$alltariffs[$eachdata['login']]);
  1245. }
  1246. $cells.= wf_TableCell(@$allnotes[$eachdata['login']]);
  1247. $cells.= wf_TableCell(@$allonu[$eachdata['login']]);
  1248. $cells.= wf_TableCell(@$allCredited[$eachdata['login']]);
  1249. foreach ($keys as $eachkey) {
  1250. if (array_key_exists($eachkey, $eachdata)) {
  1251. $cells.= wf_TableCell($eachdata[$eachkey]);
  1252. }
  1253. }
  1254. $rows.=wf_TableRow($cells);
  1255. }
  1256. }
  1257. $result = wf_TableBody($rows, '100%', '0', 'sortable printrm');
  1258. if ($rowcount) {
  1259. $result.=wf_tag('strong') . __('Total') . ': ' . $i . wf_tag('strong', true);
  1260. }
  1261. print($style . $report_name . $result);
  1262. die();
  1263. }
  1264. function web_MonthSelector() {
  1265. $mcells = '';
  1266. $allmonth = months_array_localized();
  1267. foreach ($allmonth as $io => $each) {
  1268. if (isset($_GET['citysel'])) {
  1269. if (isset($_GET['year'])) {
  1270. $mcells.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $io . "&year=" . $_GET['year'] . "&citysel=" . $_GET['citysel'], $each, false, 'ubButton'));
  1271. } else {
  1272. $mcells.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $io . "&citysel=" . $_GET['citysel'], $each, false, 'ubButton'));
  1273. }
  1274. } elseif (isset($_GET['citysearch'])) {
  1275. if (isset($_GET['year'])) {
  1276. $mcells.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $io . "&year=" . $_GET['year'] . "&citysearch=" . $_GET['citysearch'], $each, false, 'ubButton'));
  1277. } else {
  1278. $mcells.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $io . "&citysearch=" . $_GET['citysearch'], $each, false, 'ubButton'));
  1279. }
  1280. } else {
  1281. if (isset($_GET['year'])) {
  1282. $mcells.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $io . "&year=" . $_GET['year'], $each, false, 'ubButton'));
  1283. } else {
  1284. $mcells.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $io, $each, false, 'ubButton'));
  1285. }
  1286. }
  1287. }
  1288. return ($mcells);
  1289. }
  1290. function web_YearSelector() {
  1291. $currentYear = date('Y');
  1292. $years = '';
  1293. for ($year = 2010; $year <= $currentYear; $year++) {
  1294. if (isset($_GET['citysel'])) {
  1295. if (isset($_GET['monthsel'])) {
  1296. $years.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $_GET['monthsel'] . "&citysel=" . $_GET['citysel'] . "&year=" . $year, $year, false, 'ubButton'));
  1297. } else {
  1298. $years.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments" . "&citysel=" . $_GET['citysel'] . "&year=" . $year, $year, false, 'ubButton'));
  1299. }
  1300. } elseif (isset($_GET['citysearch'])) {
  1301. if (isset($_GET['monthsel'])) {
  1302. $years.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $_GET['monthsel'] . "&year=" . $year . "&citysearch=" . $_GET['citysearch'], $year, false, 'ubButton'));
  1303. } else {
  1304. $years.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments" . "&year=" . $year . "&citysearch=" . $_GET['citysearch'], $year, false, 'ubButton'));
  1305. }
  1306. } else {
  1307. if (isset($_GET['monthsel'])) {
  1308. $years.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&monthsel=" . $_GET['monthsel'] . "&year=" . $year, $year, false, 'ubButton'));
  1309. } else {
  1310. $years.= wf_TableCell(wf_Link("?module=per_city_action&action=city_payments&year=" . $year, $year, false, 'ubButton'));
  1311. }
  1312. }
  1313. }
  1314. return ($years);
  1315. }
  1316. function web_ReportDebtorsShowPrintable($titles, $keys, $alldata, $address = 0, $realnames = 0, $rowcount = 0) {
  1317. $alter_conf = rcms_parse_ini_file(CONFIG_PATH . 'alter.ini');
  1318. $report_name = wf_tag('h2') . __("Debtors by city") . wf_tag('h2', true);
  1319. $allrealnames = zb_UserGetAllRealnames();
  1320. $alladdress = zb_AddressGetFulladdresslist();
  1321. if ($alter_conf['FINREP_TARIFF']) {
  1322. $alltariffs = zb_TariffsGetAllUsers();
  1323. }
  1324. $allphonedata = zb_UserGetAllPhoneData();
  1325. $allnotes = GetAllNotes();
  1326. $allonu = GetAllOnu();
  1327. $allCredited = GetAllCreditedUsers();
  1328. $i = 0;
  1329. $style = '
  1330. <script src="modules/jsc/sorttable.js" language="javascript"></script>
  1331. <style type="text/css">
  1332. table.printrm tbody {
  1333. counter-reset: sortabletablescope;
  1334. border-width: 1px;
  1335. padding: 1px;
  1336. border-style: dashed;
  1337. border-color: gray;
  1338. background-color: white;
  1339. -moz-border-radius: ;
  1340. }
  1341. table.printrm thead tr::before {
  1342. border-width: 1px;
  1343. padding: 1px;
  1344. border-style: dashed;
  1345. border-color: gray;
  1346. background-color: white;
  1347. -moz-border-radius: ;
  1348. text-align: center;
  1349. vertical-align: middle;
  1350. content: "ID";
  1351. display: table-cell;
  1352. }
  1353. table.printrm tbody tr::before {
  1354. border-width: 1px;
  1355. padding: 1px;
  1356. border-style: dashed;
  1357. border-color: gray;
  1358. background-color: white;
  1359. -moz-border-radius: ;
  1360. text-align: center;
  1361. vertical-align: middle;
  1362. content: counter(sortabletablescope);
  1363. counter-increment: sortabletablescope;
  1364. display: table-cell;
  1365. }
  1366. table.printrm {
  1367. border-width: 1px;
  1368. border-spacing: 2px;
  1369. border-style: outset;
  1370. border-color: gray;
  1371. border-collapse: separate;
  1372. background-color: white;
  1373. }
  1374. table.printrm th {
  1375. border-width: 1px;
  1376. padding: 1px;
  1377. border-style: dashed;
  1378. border-color: gray;
  1379. background-color: white;
  1380. -moz-border-radius: ;
  1381. }
  1382. table.printrm td {
  1383. border-width: 1px;
  1384. padding: 1px;
  1385. border-style: dashed;
  1386. border-color: gray;
  1387. background-color: white;
  1388. -moz-border-radius: ;
  1389. }
  1390. </style>';
  1391. $cells = '';
  1392. if ($address) {
  1393. $cells.=wf_TableCell(__('Full address'));
  1394. }
  1395. if ($realnames) {
  1396. $cells.=wf_TableCell(__('Real Name'));
  1397. }
  1398. foreach ($titles as $eachtitle) {
  1399. $cells.= wf_TableCell(__($eachtitle));
  1400. }
  1401. $rows = wf_TableRow($cells);
  1402. if (!empty($alldata)) {
  1403. foreach ($alldata as $io => $eachdata) {
  1404. $i++;
  1405. $cells = '';
  1406. if ($address) {
  1407. $cells.=wf_TableCell(@$alladdress[$eachdata['login']]);
  1408. }
  1409. if ($realnames) {
  1410. $cells.=wf_TableCell(@$allrealnames[$eachdata['login']] . "&nbsp " . @$allphonedata[$eachdata['login']]['mobile']);
  1411. }
  1412. if ($alter_conf['FINREP_TARIFF']) {
  1413. $cells.=wf_TableCell(@$alltariffs[$eachdata['login']]);
  1414. }
  1415. $cells.= wf_TableCell(@$allnotes[$eachdata['login']]);
  1416. $cells.= wf_TableCell(@$allonu[$eachdata['login']]);
  1417. $cells.= wf_TableCell(@$allCredited[$eachdata['login']]);
  1418. foreach ($keys as $eachkey) {
  1419. if (array_key_exists($eachkey, $eachdata)) {
  1420. $cells.=wf_TableCell($eachdata[$eachkey]);
  1421. }
  1422. }
  1423. $rows.=wf_TableRow($cells);
  1424. }
  1425. }
  1426. $result = wf_TableBody($rows, '100%', '0', 'sortable printrm');
  1427. if ($rowcount) {
  1428. $result.='<strong>' . __('Total') . ': ' . $i . '</strong>';
  1429. }
  1430. print($style . $report_name . $result);
  1431. die();
  1432. }