api.ukvsystem.php 198 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755
  1. <?php
  2. /**
  3. * UKV cable TV accounting implementation
  4. */
  5. class UkvSystem {
  6. /**
  7. * Available tariffs as id=>data
  8. *
  9. * @var array
  10. */
  11. protected $tariffs = array();
  12. /**
  13. * Available users and therir data as id=>data
  14. *
  15. * @var array
  16. */
  17. protected $users = array();
  18. /**
  19. * Available cities from directory
  20. *
  21. * @var array
  22. */
  23. protected $cities = array('' => '-');
  24. /**
  25. * Available streets from directory
  26. *
  27. * @var array
  28. */
  29. protected $streets = array('' => '-');
  30. /**
  31. * Available system cashtypes
  32. *
  33. * @var array
  34. */
  35. protected $cashtypes = array();
  36. /**
  37. * Default month array with localized names
  38. *
  39. * @var array
  40. */
  41. protected $month = array();
  42. /**
  43. * Currently assigned users contracts as contract=>userid
  44. *
  45. * @var array
  46. */
  47. protected $contracts = array();
  48. /**
  49. * Preprocessed banksta records
  50. *
  51. * @var array
  52. */
  53. protected $bankstarecords = array();
  54. /**
  55. * Some magic goes here
  56. *
  57. * @var array
  58. */
  59. protected $bankstafoundusers = array();
  60. /**
  61. * Contains all available tagtypes as id=>data
  62. *
  63. * @var array
  64. */
  65. protected $allTagtypes = array();
  66. /**
  67. * Contains all available user tags
  68. *
  69. * @var array
  70. */
  71. protected $allUserTags = array();
  72. /**
  73. * System alter.ini config represented as key=>value
  74. *
  75. * @var array
  76. */
  77. protected $altCfg = array();
  78. /**
  79. * System message helper object placeholder
  80. *
  81. * @var object
  82. */
  83. protected $messages = '';
  84. /**
  85. * UbillingConfig object placeholder
  86. *
  87. * @var null
  88. */
  89. protected $ubConfig = null;
  90. //static routing URLs
  91. const URL_TARIFFS_MGMT = '?module=ukv&tariffs=true'; //tariffs management
  92. const URL_USERS_MGMT = '?module=ukv&users=true'; //users management
  93. const URL_USERS_LIST = '?module=ukv&users=true&userslist=true'; //users list route
  94. const URL_USERS_PROFILE = '?module=ukv&users=true&showuser='; //user profile
  95. const URL_USERS_LIFESTORY = '?module=ukv&users=true&lifestory=true&showuser='; //user lifestory
  96. const URL_USERS_REGISTER = '?module=ukv&users=true&register=true'; //users registration route
  97. const URL_USERS_AJAX_SOURCE = '?module=ukv&ajax=true'; //ajax datasource for JQuery data tables
  98. const URL_INET_USER_PROFILE = '?module=userprofile&username='; //internet user profile
  99. const URTL_USERS_ANIHILATION = '?module=ukv&users=true&deleteuser='; // user extermination form
  100. const URL_BANKSTA_MGMT = '?module=ukv&banksta=true'; //bank statements processing url
  101. const URL_BANKSTA_PROCESSING = '?module=ukv&banksta=true&showhash='; // bank statement processing url
  102. const URL_BANKSTA_DETAILED = '?module=ukv&banksta=true&showdetailed='; //detailed banksta row display url
  103. const URL_REPORTS_LIST = '?module=ukv&reports=true&showreport=reportList'; //reports listing link
  104. const URL_REPORTS_MGMT = '?module=ukv&reports=true&showreport='; //reports listing link
  105. const URL_PHOTOSTORAGE = '?module=photostorage&scope=UKVUSERPROFILE&mode=list&itemid='; //photostorage link
  106. //registration options
  107. const REG_ACT = 1;
  108. const REG_CASH = 0;
  109. //misc options
  110. protected $debtLimit = 2; //debt limit in month count
  111. //bank statements options (Oschadbank)
  112. const BANKSTA_IN_CHARSET = 'cp866';
  113. const BANKSTA_OUT_CHARSET = 'utf-8';
  114. const BANKSTA_PATH = 'content/documents/ukv_banksta/';
  115. const BANKSTA_CONTRACT = 'ABCOUNT';
  116. const BANKSTA_ADDRESS = 'ADDR';
  117. const BANKSTA_REALNAME = 'FIO';
  118. const BANKSTA_SUMM = 'SUMM';
  119. const BANKSTA_NOTES = 'NAME_PLAT';
  120. const BANKSTA_TIME = 'PTIME';
  121. const BANKSTA_DATE = 'PDATE';
  122. //bank statements options (Oschadbank terminals)
  123. const OT_BANKSTA_CONTRACT = 'ABCOUNTT';
  124. const OT_BANKSTA_ADDRESS = 'ADDRT';
  125. const OT_BANKSTA_REALNAME = 'FIOTDT';
  126. const OT_BANKSTA_SUMM = 'SUMMT';
  127. const OT_BANKSTA_NOTES = 'NAME_PLAT';
  128. const OT_BANKSTA_TIME = 'PTIMETT';
  129. const OT_BANKSTA_DATE = 'PDATETT';
  130. //bank statements options (PrivatBank dbf)
  131. const PB_BANKSTA_CONTRACT = 'N_DOGOV';
  132. const PB_BANKSTA_ADDRESS = 'ADR_TEL';
  133. const PB_BANKSTA_REALNAME = 'FIO_PLAT';
  134. const PB_BANKSTA_SUMM = 'SUMMA';
  135. const PB_BANKSTA_NOTES = 'N_DOKUM';
  136. const PB_BANKSTA_TIME = 'NOPE';
  137. const PB_BANKSTA_DATE = 'OPERDEN';
  138. //finance coloring options
  139. const COLOR_FEE = 'a90000';
  140. const COLOR_PAYMENT = '005304';
  141. const COLOR_CORRECTING = 'ff6600';
  142. const COLOR_MOCK = '006699';
  143. //some exeptions
  144. const EX_TARIFF_FIELDS_EMPTY = 'EMPTY_TARIFF_OPTS_RECEIVED';
  145. const EX_USER_NOT_EXISTS = 'NO_EXISTING_UKV_USER';
  146. const EX_USER_NOT_SET = 'NO_VALID_USERID_RECEIVED';
  147. const EX_USER_NO_TARIFF_SET = 'NO_TARIFF_SET';
  148. const EX_USER_NOT_ACTIVE = 'USER_NOT_ACTIVE';
  149. const EX_BANKSTA_PREPROCESS_EMPTY = 'BANK_STATEMENT_INPUT_INVALID';
  150. /**
  151. * Creates new UKV instance
  152. */
  153. public function __construct() {
  154. $this->loadConfigs();
  155. $this->loadTariffs();
  156. $this->loadUsers();
  157. $this->loadCities();
  158. $this->loadStreets();
  159. $this->loadMonth();
  160. $this->loadDebtLimit();
  161. $this->loadTagtypes();
  162. $this->loadUsertags();
  163. $this->initMessages();
  164. }
  165. /**
  166. * Loads needed system configs into private data property
  167. *
  168. * @global object $ubillingConfig
  169. *
  170. * @return void
  171. */
  172. protected function loadConfigs() {
  173. global $ubillingConfig;
  174. $this->ubConfig = $ubillingConfig;
  175. $this->altCfg = $ubillingConfig->getAlter();
  176. }
  177. /**
  178. * loads all tariffs into private tariffs prop
  179. *
  180. * @return void
  181. */
  182. protected function loadTariffs() {
  183. $query = "SELECT * from `ukv_tariffs` ORDER by `tariffname` ASC;";
  184. $alltariffs = simple_queryall($query);
  185. if (!empty($alltariffs)) {
  186. foreach ($alltariffs as $io => $each) {
  187. $this->tariffs[$each['id']] = $each;
  188. }
  189. }
  190. }
  191. /**
  192. * loads all existing cities into private cities prop
  193. *
  194. * @return void
  195. */
  196. protected function loadCities() {
  197. $query = "SELECT * from `city` ORDER BY `id` ASC;";
  198. $allcities = simple_queryall($query);
  199. if (!empty($allcities)) {
  200. foreach ($allcities as $io => $each) {
  201. $this->cities[$each['cityname']] = $each['cityname'];
  202. }
  203. }
  204. }
  205. /**
  206. * loads all existing streets into private streets prop
  207. *
  208. * @return void
  209. */
  210. protected function loadStreets() {
  211. $query = "SELECT DISTINCT `streetname` from `street` ORDER BY `streetname` ASC;";
  212. $allstreets = simple_queryall($query);
  213. if (!empty($allstreets)) {
  214. foreach ($allstreets as $io => $each) {
  215. $this->streets[$each['streetname']] = $each['streetname'];
  216. }
  217. }
  218. }
  219. /**
  220. * load all existing cashtypes into private cashtypes prop
  221. *
  222. * @return void
  223. */
  224. protected function loadCashtypes() {
  225. $query = "SELECT `id`,`cashtype` from `cashtype` ORDER BY `id` ASC;";
  226. $all = simple_queryall($query);
  227. if (!empty($all)) {
  228. foreach ($all as $io => $each) {
  229. $this->cashtypes[$each['id']] = __($each['cashtype']);
  230. }
  231. }
  232. }
  233. /**
  234. * loads current month data into private props
  235. *
  236. * @return void
  237. */
  238. protected function loadMonth() {
  239. $monthArr = months_array();
  240. $this->month['currentmonth'] = date("m");
  241. $this->month['currentyear'] = date("Y");;
  242. foreach ($monthArr as $num => $each) {
  243. $this->month['names'][$num] = rcms_date_localise($each);
  244. }
  245. }
  246. /**
  247. * loads current debt limit from global config
  248. *
  249. * @return void
  250. */
  251. protected function loadDebtLimit() {
  252. global $ubillingConfig;
  253. $altCfg = $ubillingConfig->getAlter();
  254. $this->debtLimit = $altCfg['UKV_MONTH_DEBTLIMIT'];
  255. }
  256. /**
  257. * Loads all available tagstypes
  258. *
  259. * @return void
  260. */
  261. protected function loadTagtypes() {
  262. $query = "SELECT * from `tagtypes`";
  263. $all = simple_queryall($query);
  264. if (!empty($all)) {
  265. foreach ($all as $io => $each) {
  266. $this->allTagtypes[$each['id']] = $each;
  267. }
  268. }
  269. }
  270. /**
  271. * Loads all available usertags
  272. *
  273. * @return void
  274. */
  275. protected function loadUsertags() {
  276. $query = "SELECT * from `ukv_tags`";
  277. $all = simple_queryall($query);
  278. if (!empty($all)) {
  279. foreach ($all as $io => $each) {
  280. $this->allUserTags[$each['id']] = $each;
  281. }
  282. }
  283. }
  284. /**
  285. * Inits message helper object for further usage
  286. *
  287. * @return void
  288. */
  289. protected function initMessages() {
  290. $this->messages = new UbillingMessageHelper();
  291. }
  292. /**
  293. * creates new tariff into database
  294. *
  295. * @param string $name tariff name
  296. * @param float $price tariff price
  297. *
  298. * @return void
  299. */
  300. public function tariffCreate($name, $price) {
  301. $name = mysql_real_escape_string($name);
  302. $name = trim($name);
  303. $price = mysql_real_escape_string($price);
  304. $price = trim($price);
  305. if (!empty($name)) {
  306. $price = (empty($price)) ? 0 : $price;
  307. $query = "INSERT INTO `ukv_tariffs` (`id`, `tariffname`, `price`) VALUES (NULL, '" . $name . "', '" . $price . "');";
  308. nr_query($query);
  309. log_register("UKV TARIFF CREATE `" . $name . "` WITH PRICE `" . $price . "`");
  310. } else {
  311. throw new Exception(self::EX_TARIFF_FIELDS_EMPTY);
  312. }
  313. }
  314. /**
  315. * check is tariff protected/used by some users
  316. *
  317. * @param int $tariffid existing tariff ID
  318. *
  319. * @return bool
  320. */
  321. protected function tariffIsProtected($tariffid) {
  322. $tariffid = vf($tariffid, 3);
  323. $query = "SELECT `id` from `ukv_users` WHERE `tariffid`='" . $tariffid . "';";
  324. $data = simple_query($query);
  325. if (empty($data)) {
  326. return (false);
  327. } else {
  328. return (true);
  329. }
  330. }
  331. /**
  332. * deletes some existing tariff from database
  333. *
  334. * @param int $tariffid existing tariff ID
  335. *
  336. * @return void
  337. */
  338. public function tariffDelete($tariffid) {
  339. $tariffid = vf($tariffid, 3);
  340. //check - is tariff used by anyone?
  341. if (!$this->tariffIsProtected($tariffid)) {
  342. $tariffName = $this->tariffs[$tariffid]['tariffname'];
  343. $query = "DELETE from `ukv_tariffs` WHERE `id`='" . $tariffid . "'";
  344. nr_query($query);
  345. log_register("UKV TARIFF DELETE `" . $tariffName . "` [" . $tariffid . "]");
  346. } else {
  347. log_register("UKV TARIFF DELETE PROTECTED TRY [" . $tariffid . "]");
  348. }
  349. }
  350. /**
  351. * saves some tariff params into database
  352. *
  353. * @param int $tariffid existing tariff ID
  354. * @param string $tariffname new name of the tariff
  355. * @param float $price new tariff price
  356. */
  357. public function tariffSave($tariffid, $tariffname, $price) {
  358. $tariffid = vf($tariffid, 3);
  359. $tariffname = mysql_real_escape_string($tariffname);
  360. $tariffname = trim($tariffname);
  361. $price = mysql_real_escape_string($price);
  362. $price = trim($price);
  363. if (!empty($tariffname)) {
  364. $price = (empty($price)) ? 0 : $price;
  365. $query = "UPDATE `ukv_tariffs` SET `tariffname` = '" . $tariffname . "', `price` = '" . $price . "' WHERE `id` = '" . $tariffid . "';";
  366. nr_query($query);
  367. log_register("UKV TARIFF CHANGE `" . $tariffname . "` WITH PRICE `" . $price . "` [" . $tariffid . "]");
  368. } else {
  369. throw new Exception(self::EX_TARIFF_FIELDS_EMPTY);
  370. }
  371. }
  372. /**
  373. * returns tariff edit form
  374. *
  375. * @param int $tariffid existing tariff id
  376. *
  377. * @rerturn string
  378. */
  379. protected function tariffEditForm($tariffid) {
  380. $tariffid = vf($tariffid, 3);
  381. $inputs = wf_HiddenInput('edittariff', $tariffid);
  382. $inputs .= wf_TextInput('edittariffname', __('Tariff name'), $this->tariffs[$tariffid]['tariffname'], true, '20');
  383. $inputs .= wf_TextInput('edittariffprice', __('Tariff Fee'), $this->tariffs[$tariffid]['price'], true, '5');
  384. $inputs .= wf_Submit(__('Save'));
  385. $result = wf_Form('', 'POST', $inputs, 'glamour');
  386. return ($result);
  387. }
  388. /**
  389. * returns tariff creation form
  390. *
  391. * @return string
  392. */
  393. protected function tariffCreateForm() {
  394. $inputs = wf_HiddenInput('createtariff', 'true');
  395. $inputs .= wf_TextInput('createtariffname', __('Tariff name'), '', true, '20');
  396. $inputs .= wf_TextInput('createtariffprice', __('Tariff Fee'), '', true, '5');
  397. $inputs .= wf_Submit(__('Create new tariff'));
  398. $result = wf_Form('', 'POST', $inputs, 'glamour');
  399. return ($result);
  400. }
  401. /**
  402. * renders CaTV tariffs list with some controls
  403. *
  404. * @return void
  405. */
  406. public function renderTariffs() {
  407. $cells = wf_TableCell(__('ID'));
  408. $cells .= wf_TableCell(__('Tariff name'));
  409. $cells .= wf_TableCell(__('Tariff Fee'));
  410. $cells .= wf_TableCell(__('Actions'));
  411. $rows = wf_TableRow($cells, 'row1');
  412. if (!empty($this->tariffs)) {
  413. foreach ($this->tariffs as $io => $each) {
  414. $cells = wf_TableCell($each['id']);
  415. $cells .= wf_TableCell($each['tariffname']);
  416. $cells .= wf_TableCell($each['price']);
  417. $actlinks = wf_JSAlert(self::URL_TARIFFS_MGMT . '&tariffdelete=' . $each['id'], web_delete_icon(), __('Removing this may lead to irreparable results'));
  418. $actlinks .= wf_modal(web_edit_icon(), __('Edit') . ' ' . $each['tariffname'], $this->tariffEditForm($each['id']), '', '400', '200');
  419. $cells .= wf_TableCell($actlinks, '', '', $customkey = 'sorttable_customkey="0"'); //need this to keep table sortable
  420. $rows .= wf_TableRow($cells, 'row5');
  421. }
  422. }
  423. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  424. $result .= wf_modal(wf_img('skins/plus.png', __('Create new tariff')), __('Create new tariff'), $this->tariffCreateForm(), '', '400', '200');
  425. return ($result);
  426. }
  427. /**
  428. * returns module control panel
  429. *
  430. * @return string
  431. */
  432. public function panel() {
  433. $result = '';
  434. if (cfr('UKV')) {
  435. $result .= wf_Link(self::URL_USERS_LIST, wf_img('skins/ukv/users.png') . ' ' . __('Users'), false, 'ubButton');
  436. }
  437. if (cfr('UKVREG')) {
  438. $result .= wf_Link(self::URL_USERS_REGISTER, wf_img('skins/ukv/add.png') . ' ' . __('Users registration'), false, 'ubButton');
  439. }
  440. if (cfr('UKVTAR')) {
  441. $result .= wf_Link(self::URL_TARIFFS_MGMT, wf_img('skins/ukv/dollar.png') . ' ' . __('Tariffs'), false, 'ubButton');
  442. }
  443. if (cfr('UKVBST')) {
  444. $result .= wf_Link(self::URL_BANKSTA_MGMT, wf_img('skins/ukv/bank.png') . ' ' . __('Bank statements'), false, 'ubButton');
  445. }
  446. if (cfr('UKVREP')) {
  447. $result .= wf_Link(self::URL_REPORTS_LIST, wf_img('skins/ukv/report.png') . ' ' . __('Reports'), false, 'ubButton');
  448. }
  449. return ($result);
  450. }
  451. /**
  452. * loads all users from database to private prop users
  453. *
  454. * @return void
  455. */
  456. protected function loadUsers() {
  457. $query = "SELECT * from `ukv_users`";
  458. $allusers = simple_queryall($query);
  459. if (!empty($allusers)) {
  460. foreach ($allusers as $io => $each) {
  461. $this->users[$each['id']] = $each;
  462. $this->contracts[$each['contract']] = $each['id'];
  463. }
  464. }
  465. }
  466. /**
  467. * just sets user balance to specified value
  468. *
  469. * @param int $userid existing user id
  470. * @param float $cash cash value to set
  471. *
  472. * @return void
  473. */
  474. protected function userSetCash($userid, $cash) {
  475. if (isset($this->users[$userid])) {
  476. simple_update_field('ukv_users', 'cash', $cash, "WHERE `id`='" . $userid . "';");
  477. }
  478. }
  479. /**
  480. * logs payment to database
  481. *
  482. *
  483. * @param int $userid
  484. * @param float $summ
  485. * @param bool $visible
  486. * @param int $cashtypeid
  487. * @param string $notes
  488. *
  489. * @return void
  490. */
  491. public function logPayment($userid, $summ, $visible = true, $cashtypeid = 1, $notes = '') {
  492. $userid = vf($userid, 3);
  493. $summ = mysql_real_escape_string($summ);
  494. $date = date("Y-m-d H:i:s");
  495. $admin = whoami();
  496. $currentBalance = $this->users[$userid]['cash'];
  497. $visible = ($visible) ? 1 : 0;
  498. $cashtypeid = vf($cashtypeid, 3);
  499. $notes = mysql_real_escape_string($notes);
  500. $query = "INSERT INTO `ukv_payments` (`id` , `userid` , `date` , `admin` , `balance` , `summ` , `visible` , `cashtypeid` , `note`)
  501. VALUES (NULL , '" . $userid . "', '" . $date . "', '" . $admin . "', '" . $currentBalance . "', '" . $summ . "', '" . $visible . "', '" . $cashtypeid . "', '" . $notes . "');";
  502. nr_query($query);
  503. }
  504. /**
  505. * External interface for private setCash method used in manual finance ops
  506. *
  507. * @param int $userid
  508. * @param float $summ
  509. * @param bool $visible
  510. * @param int $cashtypeid
  511. * @param string $notes
  512. *
  513. * @return void
  514. */
  515. public function userAddCash($userid, $summ, $visible = true, $cashtypeid = 1, $notes = '') {
  516. $userid = vf($userid, 3);
  517. $summ = mysql_real_escape_string($summ);
  518. $currentBalance = $this->users[$userid]['cash'];
  519. //create transaction record
  520. $this->logPayment($userid, $summ, $visible, $cashtypeid, $notes);
  521. //push payment to user
  522. $newCashValue = $currentBalance + $summ;
  523. $this->userSetCash($userid, $newCashValue);
  524. $this->users[$userid]['cash'] = $newCashValue;
  525. log_register('UKV BALANCEADD ((' . $userid . ')) ON ' . $summ);
  526. }
  527. /**
  528. * checks is input number valid money format or not?
  529. *
  530. * @param float $number an string to check
  531. *
  532. * @return bool
  533. */
  534. public function isMoney($number) {
  535. return preg_match("/^-?[0-9]+(?:\.[0-9]{1,2})?$/", $number);
  536. }
  537. /**
  538. * charges month fee for some user
  539. *
  540. * @param int $userid existing user ID
  541. *
  542. * @return void
  543. */
  544. protected function feeCharge($userid) {
  545. $userid = vf($userid, 3);
  546. if ($this->users[$userid]['tariffid']) {
  547. $tariffId = $this->users[$userid]['tariffid'];
  548. $tariffName = $this->tariffs[$tariffId]['tariffname'];
  549. $tariffPrice = $this->tariffs[$tariffId]['price'];
  550. $montlyFee = abs($tariffPrice);
  551. $currentBalance = $this->users[$userid]['cash'];
  552. $newCash = $currentBalance - $montlyFee;
  553. $currentMonth = $this->month['currentmonth'];
  554. $currentMonthName = $this->month['names'][$currentMonth];
  555. $currentYear = $this->month['currentyear'];
  556. if ($this->users[$userid]['active']) {
  557. $notes = 'UKVFEE:' . $tariffName . ' ' . $currentMonthName . ' ' . $currentYear;
  558. $this->logPayment($userid, ('-' . $montlyFee), false, 1, $notes);
  559. $this->userSetCash($userid, $newCash);
  560. } else {
  561. $notes = 'UKVFEE: ' . self::EX_USER_NOT_ACTIVE;
  562. $this->logPayment($userid, 0, false, 1, $notes);
  563. }
  564. } else {
  565. //no tariff set - skipping
  566. $this->logPayment($userid, 0, false, 1, 'UKVFEE: ' . self::EX_USER_NO_TARIFF_SET);
  567. }
  568. }
  569. /**
  570. * logs fee charge fact to database
  571. *
  572. * @return void
  573. */
  574. protected function feeChargeLog() {
  575. $curyearmonth = date("Y-m");
  576. $query = "INSERT INTO `ukv_fees` (`id`, `yearmonth`) VALUES (NULL, '" . $curyearmonth . "');";
  577. nr_query($query);
  578. }
  579. /**
  580. * Changes all users tariffs and reloads users data if required
  581. *
  582. * @return void
  583. */
  584. protected function tariffsMoveAll() {
  585. if (!empty($this->users)) {
  586. foreach ($this->users as $io => $each) {
  587. if (!empty($each['tariffnmid'])) {
  588. $newTariffId = $each['tariffnmid'];
  589. if (isset($this->tariffs[$newTariffId])) {
  590. $userId = $each['id'];
  591. $where = "WHERE `id`='" . $userId . "'";
  592. //change tariff in database
  593. simple_update_field('ukv_users', 'tariffid', $newTariffId, $where);
  594. //update tariffs state in current instance
  595. $this->users[$userId]['tariffid'] = $newTariffId;
  596. $this->users[$userId]['tariffnmid'] = '';
  597. //drop tariffnm
  598. simple_update_field('ukv_users', 'tariffnmid', '', $where);
  599. }
  600. }
  601. }
  602. }
  603. }
  604. /**
  605. * charges fee for all users and controls per month validity
  606. *
  607. * @return int
  608. */
  609. public function feeChargeAll() {
  610. $curyearmonth = date("Y-m");
  611. $query_check = "SELECT `id` from `ukv_fees` WHERE `yearmonth`='" . $curyearmonth . "'";
  612. $feesProcessed = simple_query($query_check);
  613. $chargeCounter = 0;
  614. if (!$feesProcessed) {
  615. if (!empty($this->users)) {
  616. //previously moving tariffs if required
  617. $this->tariffsMoveAll();
  618. foreach ($this->users as $io => $each) {
  619. $this->feeCharge($each['id']);
  620. $chargeCounter++;
  621. }
  622. }
  623. log_register('UKV FEE CHARGED FOR ' . $chargeCounter . ' USERS');
  624. $this->feeChargeLog();
  625. } else {
  626. log_register('UKV FEE CHARGE DOUBLE TRY');
  627. }
  628. return ($chargeCounter);
  629. }
  630. /**
  631. * public interface view for manual payments processing
  632. *
  633. * @param int $userid - existing user ID
  634. *
  635. * @return string
  636. */
  637. public function userManualPaymentsForm($userid) {
  638. $userid = vf($userid, 3);
  639. $this->loadCashtypes();
  640. $inputs = '';
  641. $inputs .= wf_HiddenInput('manualpaymentprocessing', $userid);
  642. $inputs .= wf_TextInput('paymentsumm', __('New cash'), '', true, '5', '', '', 'UkvPaymSum');
  643. $inputs .= wf_RadioInput('paymenttype', __('Add cash'), 'add', false, true);
  644. $inputs .= wf_RadioInput('paymenttype', __('Correct saldo'), 'correct', false, false);
  645. $inputs .= wf_RadioInput('paymenttype', __('Mock payment'), 'mock', true, false);
  646. $inputs .= wf_Selector('paymentcashtype', $this->cashtypes, __('Cash type'), '', true);
  647. $inputs .= wf_TextInput('paymentnotes', __('Payment notes'), '', true, '40');
  648. $inputs .= wf_delimiter(0);
  649. if ($this->ubConfig->getAlterParam('DREAMKAS_ENABLED')) {
  650. $DreamKas = new DreamKas();
  651. $inputs .= $DreamKas->web_FiscalizePaymentCtrls('ukv');
  652. $inputs .= wf_tag('script', false, '', 'type="text/javascript"');
  653. $inputs .= '$(document).ready(function() {
  654. // dirty hack with setTimeout() to work in Chrome
  655. setTimeout(function(){
  656. $(\'#UkvPaymSum\').focus();
  657. }, 100);
  658. });
  659. ';
  660. $inputs .= wf_tag('script', true);
  661. $inputs .= wf_delimiter(0);
  662. }
  663. $inputs .= wf_Submit(__('Payment'));
  664. $result = wf_Form('', 'POST', $inputs, 'glamour');
  665. return ($result);
  666. }
  667. /**
  668. * returns user full address if this one exists
  669. *
  670. * @param int $userid existing user id
  671. *
  672. * @return string
  673. */
  674. public function userGetFullAddress($userid) {
  675. if (isset($this->users[$userid])) {
  676. global $ubillingConfig;
  677. $altcfg = $ubillingConfig->getAlter();
  678. //zero apt numbers as private builds
  679. if ($altcfg['ZERO_TOLERANCE']) {
  680. $apt = ($this->users[$userid]['apt'] == '0') ? '' : '/' . $this->users[$userid]['apt'];
  681. } else {
  682. $apt = '/' . $this->users[$userid]['apt'];
  683. }
  684. //city display
  685. if ($altcfg['CITY_DISPLAY']) {
  686. $city = $this->users[$userid]['city'] . ' ';
  687. } else {
  688. $city = '';
  689. }
  690. $result = $city . $this->users[$userid]['street'] . ' ' . $this->users[$userid]['build'] . $apt;
  691. } else {
  692. $result = '';
  693. }
  694. return ($result);
  695. }
  696. /**
  697. * Returns real name field for some user
  698. *
  699. * @param int $userid
  700. *
  701. * @return string
  702. */
  703. public function userGetRealName($userid) {
  704. $result = '';
  705. if (isset($this->users[$userid])) {
  706. $result = $this->users[$userid]['realname'];
  707. }
  708. return ($result);
  709. }
  710. /**
  711. * Returns existing tariff name by tariffid
  712. *
  713. * @param int $tariffid
  714. *
  715. * @return string
  716. */
  717. public function tariffGetName($tariffid) {
  718. if ($this->tariffs[$tariffid]['tariffname']) {
  719. $result = $this->tariffs[$tariffid]['tariffname'];
  720. } else {
  721. $result = '';
  722. }
  723. return ($result);
  724. }
  725. /**
  726. * user deletion form
  727. *
  728. * @param int $userid existing user ID
  729. *
  730. * @return string
  731. */
  732. public function userDeletionForm($userid) {
  733. $userid = vf($userid, 3);
  734. $inputs = __('Be careful, this module permanently deletes user and all data associated with it. Opportunities to raise from the dead no longer.') . ' <br>
  735. ' . __('To ensure that we have seen the seriousness of your intentions to enter the word сonfirm the field below.');
  736. $inputs .= wf_HiddenInput('userdeleteprocessing', $userid);
  737. $inputs .= wf_delimiter();
  738. $inputs .= wf_tag('input', false, '', 'type="text" name="deleteconfirmation" autocomplete="off"');
  739. $inputs .= wf_tag('br');
  740. $inputs .= wf_Submit(__('I really want to stop suffering User'));
  741. $result = wf_Form('', 'POST', $inputs, 'glamour');
  742. return ($result);
  743. }
  744. /**
  745. * deletes some user from database
  746. *
  747. * @param int $userid
  748. *
  749. * @return void
  750. */
  751. public function userDelete($userid) {
  752. $userid = vf($userid, 3);
  753. if (isset($this->users[$userid])) {
  754. $query = "DELETE from `ukv_users` WHERE `id`='" . $userid . "';";
  755. nr_query($query);
  756. log_register('UKV USER DELETED ((' . $userid . '))');
  757. } else {
  758. throw new Exception(self::EX_USER_NOT_EXISTS);
  759. }
  760. }
  761. /**
  762. * Returns user registration form
  763. *
  764. * @return string
  765. */
  766. public function userRegisterForm() {
  767. $aptsel = '';
  768. $currentStep = 0;
  769. $registerSteps = array(
  770. __('Step') . ' 1' => __('Select city'),
  771. __('Step') . ' 2' => __('Select street'),
  772. __('Step') . ' 3' => __('Select build'),
  773. __('Success') => __('Confirm'),
  774. );
  775. if (!isset($_POST['citysel'])) {
  776. $citysel = web_CitySelectorAc(); // onChange="this.form.submit();
  777. $streetsel = '';
  778. } else {
  779. $citydata = zb_AddressGetCityData($_POST['citysel']);
  780. $citysel = $citydata['cityname'] . wf_HiddenInput('citysel', $citydata['id']);
  781. $streetsel = web_StreetSelectorAc($citydata['id']);
  782. $currentStep = 1;
  783. }
  784. if (isset($_POST['streetsel'])) {
  785. $streetdata = zb_AddressGetStreetData($_POST['streetsel']);
  786. $streetsel = $streetdata['streetname'] . wf_HiddenInput('streetsel', $streetdata['id']);
  787. $buildsel = web_BuildSelectorAc($_POST['streetsel']);
  788. $currentStep = 2;
  789. } else {
  790. $buildsel = '';
  791. }
  792. if (isset($_POST['buildsel'])) {
  793. $submit_btn = '';
  794. $builddata = zb_AddressGetBuildData($_POST['buildsel']);
  795. $buildsel = $builddata['buildnum'] . wf_HiddenInput('buildsel', $builddata['id']);
  796. $aptsel = wf_TextInput('uregapt', __('Apartment'), '', true, '4');
  797. $submit_btn .= wf_HiddenInput('userregisterprocessing', 'true');
  798. $submit_btn .= wf_tag('tr', false, 'row3');
  799. $submit_btn .= wf_tag('td', false);
  800. $submit_btn .= wf_Submit(__('Let register that user'));
  801. $submit_btn .= wf_tag('td', true);
  802. $submit_btn .= wf_tag('td', false);
  803. $submit_btn .= wf_tag('td', true);
  804. $submit_btn .= wf_tag('tr', true);
  805. $currentStep = 3;
  806. } else {
  807. $submit_btn = '';
  808. }
  809. $formInputs = wf_tag('tr', false, 'row3');
  810. $formInputs .= wf_tag('td', false, '', 'width="50%"') . $citysel . wf_tag('td', true);
  811. $formInputs .= wf_tag('td', false) . __('City') . wf_tag('td', true);
  812. $formInputs .= wf_tag('tr', true);
  813. $formInputs .= wf_tag('tr', false, 'row3');
  814. $formInputs .= wf_tag('td', false) . $streetsel . wf_tag('td', true);
  815. $formInputs .= wf_tag('td', false) . __('Street') . wf_tag('td', true);
  816. $formInputs .= wf_tag('tr', true);
  817. $formInputs .= wf_tag('tr', false, 'row3');
  818. $formInputs .= wf_tag('td', false) . $buildsel . wf_tag('td', true);
  819. $formInputs .= wf_tag('td', false) . __('Build') . wf_tag('td', true);
  820. $formInputs .= wf_tag('tr', true);
  821. $formInputs .= wf_tag('tr', false, 'row3');
  822. $formInputs .= wf_tag('td', false) . $aptsel . wf_tag('td', true);
  823. $formInputs .= wf_tag('td', false) . __('Apartment') . wf_tag('td', true);
  824. $formInputs .= wf_tag('tr', true);
  825. $formInputs .= $submit_btn;
  826. $formData = wf_Form('', 'POST', $formInputs);
  827. $form = wf_TableBody($formData, '100%', '0', 'glamour');
  828. $form .= wf_tag('div', false, '', 'style="clear:both;"') . wf_tag('div', true);
  829. $form .= wf_StepsMeter($registerSteps, $currentStep);
  830. return ($form);
  831. }
  832. /**
  833. * registers new users into database and returns new user ID
  834. *
  835. * @return int
  836. */
  837. public function userCreate() {
  838. $curdate = date("Y-m-d H:i:s");
  839. $query = "
  840. INSERT INTO `ukv_users` (
  841. `id` ,
  842. `contract` ,
  843. `tariffid` ,
  844. `tariffnmid` ,
  845. `cash` ,
  846. `active` ,
  847. `realname` ,
  848. `passnum` ,
  849. `passwho` ,
  850. `passdate` ,
  851. `paddr`,
  852. `ssn` ,
  853. `phone` ,
  854. `mobile` ,
  855. `regdate` ,
  856. `city` ,
  857. `street` ,
  858. `build` ,
  859. `apt` ,
  860. `inetlogin` ,
  861. `notes`
  862. )
  863. VALUES (
  864. NULL ,
  865. NULL ,
  866. NULL ,
  867. NULL ,
  868. '" . self::REG_CASH . "',
  869. '" . self::REG_ACT . "',
  870. NULL ,
  871. NULL ,
  872. NULL ,
  873. NULL ,
  874. NULL ,
  875. NULL ,
  876. NULL ,
  877. NULL ,
  878. '" . $curdate . "',
  879. NULL ,
  880. NULL ,
  881. NULL ,
  882. NULL ,
  883. NULL ,
  884. NULL
  885. ); ";
  886. nr_query($query);
  887. $newUserId = simple_get_lastid('ukv_users');
  888. $result = $newUserId;
  889. log_register("UKV REGISTER USER ((" . $newUserId . "))");
  890. //saving post registration data
  891. $this->userPostRegSave($newUserId);
  892. return ($result);
  893. }
  894. /**
  895. * Returns cable seal edit form
  896. *
  897. * @param int $userid Existing user ID
  898. * @return string
  899. */
  900. protected function userCableSealForm($userid) {
  901. $userid = vf($userid, 3);
  902. $result = '';
  903. if (isset($this->users[$userid])) {
  904. $currentSeal = $this->users[$userid]['cableseal'];
  905. $inputs = wf_TextInput('ueditcableseal', __('Cable seal'), $currentSeal, true, 20);
  906. $inputs .= wf_HiddenInput('usercablesealprocessing', $userid);
  907. $inputs .= wf_Submit(__('Save'));
  908. $result = wf_Form('', 'POST', $inputs, 'glamour');
  909. }
  910. return ($result);
  911. }
  912. /**
  913. * returns user edit form for some userid
  914. *
  915. * @param int $userid existing user ID
  916. *
  917. * @return string
  918. */
  919. protected function userEditForm($userid) {
  920. $userid = vf($userid, 3);
  921. if (isset($this->users[$userid])) {
  922. $userData = $this->users[$userid];
  923. $switchArr = array('1' => __('Yes'), '0' => __('No'));
  924. $tariffArr = array();
  925. $tariffnmArr = array('' => '-');
  926. if (!empty($this->tariffs)) {
  927. foreach ($this->tariffs as $io => $each) {
  928. $tariffArr[$each['id']] = $each['tariffname'];
  929. }
  930. }
  931. if (!empty($this->tariffs)) {
  932. foreach ($this->tariffs as $io => $each) {
  933. //excluding current tariff
  934. if ($userData['tariffid'] != $each['id']) {
  935. $tariffnmArr[$each['id']] = $each['tariffname'];
  936. }
  937. }
  938. }
  939. $inputs = '';
  940. $inputs = wf_tag('tr', false);
  941. $inputs .= wf_tag('td', false, '', 'valign="top"');
  942. $inputs .= wf_HiddenInput('usereditprocessing', $userid);
  943. $inputs .= wf_tag('div', false, 'floatpanelswide');
  944. $inputs .= wf_tag('h3') . __('Full address') . wf_tag('h3', true);
  945. $inputs .= wf_Selector('ueditcity', $this->cities, __('City'), $userData['city'], true);
  946. $inputs .= wf_Selector('ueditstreet', $this->streets, __('Street'), $userData['street'], true);
  947. $inputs .= wf_TextInput('ueditbuild', __('Build'), $userData['build'], false, '5');
  948. $inputs .= wf_TextInput('ueditapt', __('Apartment'), $userData['apt'], true, '4');
  949. $inputs .= wf_tag('div', true);
  950. $inputs .= wf_tag('td', true);
  951. $inputs .= wf_tag('td', false, '', 'valign="top"');
  952. $inputs .= wf_tag('div', false, 'floatpanelswide');
  953. $inputs .= wf_tag('h3') . __('Contact info') . wf_tag('h3', true);
  954. $inputs .= wf_TextInput('ueditrealname', __('Real Name'), $userData['realname'], true, '30');
  955. $inputs .= wf_TextInput('ueditphone', __('Phone'), $userData['phone'], true, '20');
  956. $inputs .= wf_TextInput('ueditmobile', __('Mobile'), $userData['mobile'], true, '20');
  957. $inputs .= wf_tag('div', true);
  958. $inputs .= wf_tag('td', true);
  959. $inputs .= wf_tag('tr', true);
  960. $inputs .= wf_tag('td', false, '', 'valign="top"');
  961. $inputs .= wf_tag('div', false, 'floatpanelswide');
  962. $inputs .= wf_tag('h3') . __('Services') . wf_tag('h3', true);
  963. $inputs .= wf_TextInput('ueditcontract', __('Contract'), $userData['contract'], true, '10');
  964. $inputs .= wf_Selector('uedittariff', $tariffArr, __('Tariff'), $userData['tariffid'], true);
  965. $inputs .= wf_Selector('uedittariffnm', $tariffnmArr, __('Next month'), $userData['tariffnmid'], true);
  966. $inputs .= wf_Selector('ueditactive', $switchArr, __('Connected'), $userData['active'], true);
  967. $inputs .= wf_TextInput('ueditregdate', __('Contract date'), $userData['regdate'], true, '20');
  968. $inputs .= wf_TextInput('ueditinetlogin', __('Login'), $userData['inetlogin'], true, '20');
  969. $inputs .= wf_tag('div', true);
  970. $inputs .= wf_tag('td', true);
  971. $inputs .= wf_tag('td', false, '', 'valign="top"');
  972. $inputs .= wf_tag('div', false, 'floatpanelswide');
  973. $inputs .= wf_tag('h3') . __('Passport data') . wf_tag('h3', true);
  974. $inputs .= wf_TextInput('ueditpassnum', __('Passport number'), $userData['passnum'], true, '20');
  975. $inputs .= wf_TextInput('ueditpasswho', __('Issuing authority'), $userData['passwho'], true, '20');
  976. $inputs .= wf_DatePickerPreset('ueditpassdate', $userData['passdate'], true) . __('Date of issue') . wf_tag('br');
  977. $inputs .= wf_TextInput('ueditssn', __('SSN'), $userData['ssn'], true, '20');
  978. $inputs .= wf_TextInput('ueditpaddr', __('Registration address'), $userData['paddr'], true, '20');
  979. $inputs .= wf_tag('div', true);
  980. $inputs .= wf_tag('td', true);
  981. $inputs .= wf_tag('tr', true);
  982. $inputs .= wf_tag('tr', false);
  983. $inputs .= wf_tag('td', false, '', 'colspan="2" valign="top"');
  984. $inputs .= wf_tag('div', false, 'floatpanelswide');
  985. $inputs .= wf_TextInput('ueditnotes', __('Notes'), $userData['notes'], false, '60');
  986. $inputs .= wf_tag('div', true);
  987. $inputs .= wf_tag('td', true);
  988. $inputs .= wf_tag('tr', true);
  989. $inputs .= wf_tag('tr', false);
  990. $inputs .= wf_tag('td', false, '', 'colspan="2" valign="top"');
  991. $inputs .= wf_Submit(__('Save'));
  992. $inputs .= wf_tag('td', true);
  993. $inputs .= wf_tag('tr', true);
  994. $inputs = wf_TableBody($inputs, '800', 0, '');
  995. $result = wf_Form('', 'POST', $inputs, 'ukvusereditform');
  996. return ($result);
  997. }
  998. }
  999. /**
  1000. * returns user lifestory strict parsed from system log
  1001. *
  1002. * @param int $userid existing user id
  1003. *
  1004. * @return string
  1005. */
  1006. public function userLifeStoryForm($userid) {
  1007. $userid = vf($userid, 3);
  1008. $query = "SELECT * from `weblogs` WHERE `event` LIKE '%((" . $userid . "))%' ORDER BY `id` DESC;";
  1009. $all = simple_queryall($query);
  1010. $cells = wf_TableCell(__('ID'));
  1011. $cells .= wf_TableCell(__('Who?'));
  1012. $cells .= wf_TableCell(__('When?'));
  1013. $cells .= wf_TableCell(__('What happen?'));
  1014. $rows = wf_TableRow($cells, 'row1');
  1015. if (!empty($all)) {
  1016. foreach ($all as $io => $each) {
  1017. $cells = wf_TableCell($each['id']);
  1018. $cells .= wf_TableCell($each['admin']);
  1019. $cells .= wf_TableCell($each['date']);
  1020. $cells .= wf_TableCell($each['event']);
  1021. $rows .= wf_TableRow($cells, 'row5');
  1022. }
  1023. }
  1024. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  1025. return ($result);
  1026. }
  1027. /**
  1028. * checks is user contract unique
  1029. *
  1030. * @param string $contract - contract number to check
  1031. *
  1032. * @return bool
  1033. */
  1034. protected function checkContract($contract) {
  1035. if (isset($this->contracts[$contract])) {
  1036. $result = false;
  1037. } else {
  1038. $result = true;
  1039. }
  1040. return ($result);
  1041. }
  1042. /**
  1043. * Saves new cable seal value into database
  1044. *
  1045. * @throws Exception
  1046. * @return void
  1047. */
  1048. public function userCableSealSave() {
  1049. if (wf_CheckPost(array('usercablesealprocessing'))) {
  1050. $userId = vf($_POST['usercablesealprocessing']);
  1051. $where = "WHERE `id`='" . $userId . "';";
  1052. $tablename = 'ukv_users';
  1053. $newSeal = vf($_POST['ueditcableseal']);
  1054. if ($this->users[$userId]['cableseal'] != $newSeal) {
  1055. simple_update_field($tablename, 'cableseal', $newSeal, $where);
  1056. log_register('UKV USER ((' . $userId . ')) CHANGE CABLESEAL `' . $newSeal . '`');
  1057. }
  1058. } else {
  1059. throw new Exception(self::EX_USER_NOT_SET);
  1060. }
  1061. }
  1062. /**
  1063. * saves some user params into database
  1064. *
  1065. * @return void
  1066. */
  1067. public function userSave() {
  1068. if (wf_CheckPost(array('usereditprocessing'))) {
  1069. $userId = ubRouting::post('usereditprocessing', 'int');
  1070. $where = "WHERE `id`='" . $userId . "';";
  1071. $tablename = 'ukv_users';
  1072. //saving city
  1073. if ($this->users[$userId]['city'] != $_POST['ueditcity']) {
  1074. simple_update_field($tablename, 'city', $_POST['ueditcity'], $where);
  1075. log_register('UKV USER ((' . $userId . ')) CHANGE CITY `' . $_POST['ueditcity'] . '`');
  1076. }
  1077. //saving street
  1078. if ($this->users[$userId]['street'] != $_POST['ueditstreet']) {
  1079. simple_update_field($tablename, 'street', $_POST['ueditstreet'], $where);
  1080. log_register('UKV USER ((' . $userId . ')) CHANGE STREET `' . $_POST['ueditstreet'] . '`');
  1081. }
  1082. //saving build
  1083. if ($this->users[$userId]['build'] != $_POST['ueditbuild']) {
  1084. $newBuild = $this->filterStringData($_POST['ueditbuild']);
  1085. simple_update_field($tablename, 'build', $newBuild, $where);
  1086. log_register('UKV USER ((' . $userId . ')) CHANGE BUILD `' . $newBuild . '`');
  1087. }
  1088. //saving apartment
  1089. if ($this->users[$userId]['apt'] != $_POST['ueditapt']) {
  1090. $newApt = $this->filterStringData($_POST['ueditapt']);
  1091. simple_update_field($tablename, 'apt', $newApt, $where);
  1092. log_register('UKV USER ((' . $userId . ')) CHANGE APT `' . $newApt . '`');
  1093. }
  1094. //saving realname
  1095. if ($this->users[$userId]['realname'] != $_POST['ueditrealname']) {
  1096. $newRealname = $this->filterStringData($_POST['ueditrealname']);
  1097. simple_update_field($tablename, 'realname', $newRealname, $where);
  1098. log_register('UKV USER ((' . $userId . ')) CHANGE REALNAME `' . $newRealname . '`');
  1099. }
  1100. //saving phone
  1101. if ($this->users[$userId]['phone'] != $_POST['ueditphone']) {
  1102. simple_update_field($tablename, 'phone', $_POST['ueditphone'], $where);
  1103. log_register('UKV USER ((' . $userId . ')) CHANGE PHONE `' . $_POST['ueditphone'] . '`');
  1104. }
  1105. //saving mobile number
  1106. if ($this->users[$userId]['mobile'] != $_POST['ueditmobile']) {
  1107. simple_update_field($tablename, 'mobile', $_POST['ueditmobile'], $where);
  1108. log_register('UKV USER ((' . $userId . ')) CHANGE MOBILE `' . $_POST['ueditmobile'] . '`');
  1109. }
  1110. //saving contract
  1111. if ($this->users[$userId]['contract'] != $_POST['ueditcontract']) {
  1112. $newContract = trim($_POST['ueditcontract']);
  1113. if ($this->checkContract($newContract)) {
  1114. simple_update_field($tablename, 'contract', $newContract, $where);
  1115. log_register('UKV USER ((' . $userId . ')) CHANGE CONTRACT `' . $newContract . '`');
  1116. } else {
  1117. log_register('UKV USER ((' . $userId . ')) CHANGE FAIL CONTRACT `' . $newContract . '` DUPLICATE');
  1118. }
  1119. }
  1120. //saving tariff
  1121. if ($this->users[$userId]['tariffid'] != ubRouting::post('uedittariff', 'int')) {
  1122. simple_update_field($tablename, 'tariffid', ubRouting::post('uedittariff', 'int'), $where);
  1123. log_register('UKV USER ((' . $userId . ')) CHANGE TARIFF [' . $_POST['uedittariff'] . ']');
  1124. }
  1125. //saving next month tariff
  1126. if ($this->users[$userId]['tariffnmid'] != ubRouting::post('uedittariffnm', 'int')) {
  1127. simple_update_field($tablename, 'tariffnmid', ubRouting::post('uedittariffnm', 'int'), $where);
  1128. log_register('UKV USER ((' . $userId . ')) CHANGE TARIFFNM [' . $_POST['uedittariffnm'] . ']');
  1129. }
  1130. //saving user activity
  1131. if ($this->users[$userId]['active'] != $_POST['ueditactive']) {
  1132. simple_update_field($tablename, 'active', $_POST['ueditactive'], $where);
  1133. log_register('UKV USER ((' . $userId . ')) CHANGE ACTIVE `' . $_POST['ueditactive'] . '`');
  1134. }
  1135. //saving registration date
  1136. if ($this->users[$userId]['regdate'] != $_POST['ueditregdate']) {
  1137. simple_update_field($tablename, 'regdate', $_POST['ueditregdate'], $where);
  1138. log_register('UKV USER ((' . $userId . ')) CHANGE REGDATE `' . $_POST['ueditregdate'] . '`');
  1139. }
  1140. //saving user internet backlinking
  1141. if ($this->users[$userId]['inetlogin'] != $_POST['ueditinetlogin']) {
  1142. simple_update_field($tablename, 'inetlogin', $_POST['ueditinetlogin'], $where);
  1143. log_register('UKV USER ((' . $userId . ')) CHANGE INETLOGIN (' . $_POST['ueditinetlogin'] . ')');
  1144. }
  1145. //saving passport number
  1146. if ($this->users[$userId]['passnum'] != $_POST['ueditpassnum']) {
  1147. simple_update_field($tablename, 'passnum', $_POST['ueditpassnum'], $where);
  1148. log_register('UKV USER ((' . $userId . ')) CHANGE PASSPORTNUM `' . $_POST['ueditpassnum'] . '`');
  1149. }
  1150. //saving passport issuing authority
  1151. if ($this->users[$userId]['passwho'] != $_POST['ueditpasswho']) {
  1152. simple_update_field($tablename, 'passwho', $_POST['ueditpasswho'], $where);
  1153. log_register('UKV USER ((' . $userId . ')) CHANGE PASSPORTWHO `' . $_POST['ueditpasswho'] . '`');
  1154. }
  1155. //saving passport issue date
  1156. if ($this->users[$userId]['passdate'] != $_POST['ueditpassdate']) {
  1157. simple_update_field($tablename, 'passdate', $_POST['ueditpassdate'], $where);
  1158. log_register('UKV USER ((' . $userId . ')) CHANGE PASSPORTDATE `' . $_POST['ueditpassdate'] . '`');
  1159. }
  1160. //saving user SSN
  1161. if ($this->users[$userId]['ssn'] != $_POST['ueditssn']) {
  1162. simple_update_field($tablename, 'ssn', $_POST['ueditssn'], $where);
  1163. log_register('UKV USER ((' . $userId . ')) CHANGE SSN `' . $_POST['ueditssn'] . '`');
  1164. }
  1165. //saving user registration address
  1166. if ($this->users[$userId]['paddr'] != $_POST['ueditpaddr']) {
  1167. simple_update_field($tablename, 'paddr', $_POST['ueditpaddr'], $where);
  1168. log_register('UKV USER ((' . $userId . ')) CHANGE PASSADDRESS`' . $_POST['ueditpaddr'] . '`');
  1169. }
  1170. //saving user notes
  1171. if ($this->users[$userId]['notes'] != $_POST['ueditnotes']) {
  1172. simple_update_field($tablename, 'notes', $_POST['ueditnotes'], $where);
  1173. log_register('UKV USER ((' . $userId . ')) CHANGE NOTES `' . $_POST['ueditnotes'] . '`');
  1174. }
  1175. } else {
  1176. throw new Exception(self::EX_USER_NOT_SET);
  1177. }
  1178. }
  1179. /**
  1180. * protected method using to save address data for newly registered user
  1181. *
  1182. * @param int $userId - existin new user ID
  1183. *
  1184. * @return void
  1185. */
  1186. protected function userPostRegSave($userId) {
  1187. $citydata = zb_AddressGetCityData($_POST['citysel']);
  1188. $streetdata = zb_AddressGetStreetData($_POST['streetsel']);
  1189. $builddata = zb_AddressGetBuildData($_POST['buildsel']);
  1190. $whereReg = "WHERE `id` = '" . $userId . "';";
  1191. simple_update_field('ukv_users', 'city', $citydata['cityname'], $whereReg);
  1192. log_register('UKV USER ((' . $userId . ')) CHANGE CITY `' . $citydata['cityname'] . '`');
  1193. simple_update_field('ukv_users', 'street', $streetdata['streetname'], $whereReg);
  1194. log_register('UKV USER ((' . $userId . ')) CHANGE STREET `' . $streetdata['streetname'] . '`');
  1195. $newBuild = $this->filterStringData($builddata['buildnum']);
  1196. simple_update_field('ukv_users', 'build', $newBuild, $whereReg);
  1197. log_register('UKV USER ((' . $userId . ')) CHANGE BUILD `' . $builddata['buildnum'] . '`');
  1198. $newApt = (!empty($_POST['uregapt'])) ? $_POST['uregapt'] : 0;
  1199. $newApt = $this->filterStringData($newApt);
  1200. simple_update_field('ukv_users', 'apt', $newApt, $whereReg);
  1201. log_register('UKV USER ((' . $userId . ')) CHANGE APT `' . $newApt . '`');
  1202. }
  1203. /**
  1204. * Returns tags edit interface for some user
  1205. *
  1206. * @param int $userid
  1207. *
  1208. * @return string
  1209. */
  1210. protected function profileTagsEditForm($userid) {
  1211. $userid = vf($userid, 3);
  1212. $result = '';
  1213. $paramsTmp = array();
  1214. if (!empty($this->allTagtypes)) {
  1215. foreach ($this->allTagtypes as $io => $each) {
  1216. $paramsTmp[$each['id']] = $each['tagname'];
  1217. }
  1218. }
  1219. $inputs = wf_Selector('newtagtypeid', $paramsTmp, __('Add tag'), '', false) . ' ';
  1220. $inputs .= wf_HiddenInput('newtaguserid', $userid);
  1221. $inputs .= wf_Submit(__('Save'));
  1222. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  1223. $result .= wf_CleanDiv();
  1224. $result .= wf_delimiter();
  1225. $paramsDelTmp = array();
  1226. if (!empty($this->allUserTags)) {
  1227. foreach ($this->allUserTags as $io => $eachtag) {
  1228. if ($eachtag['userid'] == $userid) {
  1229. if (isset($this->allTagtypes[$eachtag['tagtypeid']])) {
  1230. $paramsDelTmp[$eachtag['id']] = $this->allTagtypes[$eachtag['tagtypeid']]['tagname'];
  1231. } else {
  1232. $paramsDelTmp[$eachtag['id']] = __('Deleted') . ': ' . $eachtag['tagtypeid'];
  1233. }
  1234. }
  1235. }
  1236. }
  1237. if (!empty($paramsDelTmp)) {
  1238. $inputs = wf_Selector('deltagid', $paramsDelTmp, __('Delete tag'), '', false);
  1239. $inputs .= wf_HiddenInput('deltaguserid', $userid);
  1240. $inputs .= wf_Submit(__('Delete'));
  1241. $result .= wf_Form('', 'POST', $inputs, 'glamour');
  1242. $result .= wf_CleanDiv();
  1243. }
  1244. return ($result);
  1245. }
  1246. /**
  1247. * Catches and performs if required tagg adding/deletion for some user
  1248. *
  1249. * @return void
  1250. */
  1251. protected function catchTagChangeRequest() {
  1252. if (wf_CheckPost(array('newtagtypeid', 'newtaguserid'))) {
  1253. $tagTypeId = vf($_POST['newtagtypeid'], 3);
  1254. $userId = vf($_POST['newtaguserid'], 3);
  1255. $query = "INSERT INTO `ukv_tags` (`id`,`tagtypeid`,`userid`) VALUES ";
  1256. $query .= "(NULL,'" . $tagTypeId . "','" . $userId . "');";
  1257. nr_query($query);
  1258. log_register('UKV TAG ADD ((' . $userId . ')) TYPE [' . $tagTypeId . ']');
  1259. rcms_redirect(self::URL_USERS_PROFILE . $userId);
  1260. }
  1261. if (wf_CheckPost(array('deltagid', 'deltaguserid'))) {
  1262. $delTagId = vf($_POST['deltagid'], 3);
  1263. $userId = vf($_POST['deltaguserid'], 3);
  1264. $query = "DELETE from `ukv_tags` WHERE `id`='" . $delTagId . "';";
  1265. nr_query($query);
  1266. log_register('UKV TAG DEL ((' . $userId . ')) TAGID [' . $delTagId . ']');
  1267. rcms_redirect(self::URL_USERS_PROFILE . $userId);
  1268. }
  1269. }
  1270. /**
  1271. * Returns tagtype data
  1272. *
  1273. * @param int $tagtypeid
  1274. *
  1275. * @return array
  1276. */
  1277. protected function getTagParams($tagtypeid) {
  1278. $tagtypeid = vf($tagtypeid, 3);
  1279. $result = array();
  1280. if (isset($this->allTagtypes[$tagtypeid])) {
  1281. $result = $this->allTagtypes[$tagtypeid];
  1282. }
  1283. return ($result);
  1284. }
  1285. /**
  1286. * Returns array of available UKV tariffs
  1287. *
  1288. * @return array
  1289. */
  1290. public function getTariffs() {
  1291. $result = $this->tariffs;
  1292. return ($result);
  1293. }
  1294. /**
  1295. * Returns array of available UKV users
  1296. *
  1297. * @return array
  1298. */
  1299. public function getUsers() {
  1300. $result = $this->users;
  1301. return ($result);
  1302. }
  1303. /**
  1304. * Returns array with all user data for a certain UKV userID
  1305. *
  1306. * @return array
  1307. */
  1308. public function getUserData($userid) {
  1309. $result = (isset($this->users[$userid])) ? $this->users[$userid] : array();
  1310. return ($result);
  1311. }
  1312. /**
  1313. * Returns tag html preprocessed body
  1314. *
  1315. * @param int $id
  1316. * @param bool $power
  1317. *
  1318. * @return string
  1319. */
  1320. protected function getTagBody($id, $power = false) {
  1321. $powerTmp = array();
  1322. $result = '';
  1323. if ($power) {
  1324. foreach ($this->allUserTags as $io => $each) {
  1325. if (isset($powerTmp[$each['tagtypeid']])) {
  1326. $powerTmp[$each['tagtypeid']]++;
  1327. } else {
  1328. $powerTmp[$each['tagtypeid']] = 1;
  1329. }
  1330. }
  1331. $tagPower = (isset($powerTmp[$id])) ? $powerTmp[$id] : 0;
  1332. $powerSup = wf_tag('sup', false) . $tagPower . wf_tag('sup', true);
  1333. } else {
  1334. $powerSup = '';
  1335. }
  1336. $tagbody = $this->getTagParams($id);
  1337. if (!empty($tagbody)) {
  1338. $renderPower = ($power) ? $tagPower : $tagbody['tagsize'];
  1339. $result = wf_tag('font', false, '', 'color="' . $tagbody['tagcolor'] . '" size="' . $renderPower . '"');
  1340. $result .= wf_tag('a', false, '', 'href="' . self::URL_REPORTS_MGMT . 'reportTagcloud&tagid=' . $id . '" style="color: ' . $tagbody['tagcolor'] . ';"') . $tagbody['tagname'] . $powerSup . wf_tag('a', true);
  1341. $result .= wf_tag('font', true);
  1342. $result .= '&nbsp;';
  1343. } else {
  1344. $result .= __('Deleted') . ': ' . $id . '&nbsp;';
  1345. }
  1346. return ($result);
  1347. }
  1348. /**
  1349. * Returns user applied tags as browsable html
  1350. *
  1351. * @param int $userid
  1352. * @return string
  1353. */
  1354. protected function renderUserTags($userid) {
  1355. $result = '';
  1356. if (!empty($this->allUserTags)) {
  1357. foreach ($this->allUserTags as $io => $eachtag) {
  1358. if ($eachtag['userid'] == $userid) {
  1359. $result .= $this->getTagBody($eachtag['tagtypeid']);
  1360. }
  1361. }
  1362. }
  1363. return ($result);
  1364. }
  1365. /**
  1366. * Renders profile plugin container
  1367. *
  1368. * @param string $right
  1369. * @param string $data
  1370. *
  1371. * @return string
  1372. */
  1373. protected function renderPluginContainer($right, $data) {
  1374. $result = '';
  1375. if (cfr($right)) {
  1376. $result .= wf_tag('div', false, 'dashtask', 'style="height:75px; width:75px;"');
  1377. $result .= $data;
  1378. $result .= wf_tag('div', true);
  1379. }
  1380. return ($result);
  1381. }
  1382. /**
  1383. * returns some existing user profile
  1384. *
  1385. * @param int $userid existing user`s ID
  1386. *
  1387. * @return string
  1388. */
  1389. public function userProfile($userid) {
  1390. global $ubillingConfig;
  1391. $userid = vf($userid, 3);
  1392. if (isset($this->users[$userid])) {
  1393. $userData = $this->users[$userid];
  1394. $rows = '';
  1395. //zero apt numbers as private builds
  1396. if ($this->altCfg['ZERO_TOLERANCE']) {
  1397. $apt = ($userData['apt'] == '0') ? '' : '/' . $userData['apt'];
  1398. } else {
  1399. $apt = '/' . $userData['apt'];
  1400. }
  1401. //photostorage integration
  1402. if ($this->altCfg['PHOTOSTORAGE_ENABLED']) {
  1403. $photoControl = wf_Link(self::URL_PHOTOSTORAGE . $userid, wf_img_sized('skins/photostorage.png', __('Upload images'), '10'), false);
  1404. } else {
  1405. $photoControl = '';
  1406. }
  1407. //additional user comments
  1408. if ($this->altCfg['ADCOMMENTS_ENABLED']) {
  1409. $adcomments = new ADcomments('UKVUSERPROFILE');
  1410. }
  1411. //task creation control
  1412. if ($this->altCfg['CREATETASK_IN_PROFILE']) {
  1413. $customData = '';
  1414. if ($this->altCfg['CONDET_ENABLED']) {
  1415. if (!empty($userData['cableseal'])) {
  1416. $userCableSeal = __('Cable seal') . ': ' . $userData['cableseal'] . '\r\n';
  1417. $customData = wf_HiddenInput('unifiedformtelegramappend', $userCableSeal);
  1418. }
  1419. }
  1420. $shortAddress = $userData['street'] . ' ' . $userData['build'] . $apt;
  1421. $taskForm = ts_TaskCreateFormUnified($shortAddress, $userData['mobile'], $userData['phone'], '', $customData);
  1422. $taskControl = wf_modal(wf_img('skins/createtask.gif', __('Create task')), __('Create task'), $taskForm, '', '420', '500');
  1423. } else {
  1424. $taskControl = '';
  1425. }
  1426. $cells = wf_TableCell(__('Full address') . ' ' . $taskControl, '20%', 'row2');
  1427. $cells .= wf_TableCell($userData['city'] . ' ' . $userData['street'] . ' ' . $userData['build'] . $apt);
  1428. $rows .= wf_TableRow($cells, 'row3');
  1429. $cells = wf_TableCell(__('Real Name') . ' ' . $photoControl, '20%', 'row2');
  1430. $cells .= wf_TableCell($userData['realname']);
  1431. $rows .= wf_TableRow($cells, 'row3');
  1432. $cells = wf_TableCell(__('Phone'), '30%', 'row2');
  1433. $cells .= wf_TableCell($userData['phone']);
  1434. $rows .= wf_TableRow($cells, 'row3');
  1435. $cells = wf_TableCell(__('Mobile'), '30%', 'row2');
  1436. $cells .= wf_TableCell($userData['mobile']);
  1437. $rows .= wf_TableRow($cells, 'row3');
  1438. $cells = wf_TableCell(wf_tag('b') . __('Contract') . wf_tag('b', true), '20%', 'row2');
  1439. $cells .= wf_TableCell(wf_tag('b') . $userData['contract'] . wf_tag('b', true));
  1440. $rows .= wf_TableRow($cells, 'row3');
  1441. $cells = wf_TableCell(__('Tariff'), '30%', 'row2');
  1442. $cells .= wf_TableCell(@$this->tariffs[$userData['tariffid']]['tariffname']);
  1443. $rows .= wf_TableRow($cells, 'row3');
  1444. $cells = wf_TableCell(__('Planned tariff change'), '30%', 'row2');
  1445. $cells .= wf_TableCell(@$this->tariffs[$userData['tariffnmid']]['tariffname']);
  1446. $rows .= wf_TableRow($cells, 'row3');
  1447. $cells = wf_TableCell(wf_tag('b') . __('Cash') . wf_tag('b', true), '30%', 'row2');
  1448. $cells .= wf_TableCell(wf_tag('b') . $userData['cash'] . wf_tag('b', true));
  1449. $rows .= wf_TableRow($cells, 'row3');
  1450. $cells = wf_TableCell(__('Connected'), '30%', 'row2');
  1451. $cells .= wf_TableCell(web_bool_led($userData['active']));
  1452. $rows .= wf_TableRow($cells, 'row3');
  1453. $cells = wf_TableCell(__('User contract date'), '30%', 'row2');
  1454. $cells .= wf_TableCell($userData['regdate']);
  1455. $rows .= wf_TableRow($cells, 'row3');
  1456. $cells = wf_TableCell(__('Internet account'), '30%', 'row2');
  1457. $inetLink = (!empty($userData['inetlogin'])) ? wf_Link(self::URL_INET_USER_PROFILE . $userData['inetlogin'], web_profile_icon() . ' ' . $userData['inetlogin'], false, '') : '';
  1458. $cells .= wf_TableCell($inetLink);
  1459. $rows .= wf_TableRow($cells, 'row3');
  1460. $cells = wf_TableCell(__('Cable seal'), '30%', 'row2');
  1461. $cells .= wf_TableCell($userData['cableseal']);
  1462. $rows .= wf_TableRow($cells, 'row3');
  1463. $cells = wf_TableCell(__('Notes'), '30%', 'row2');
  1464. $cells .= wf_TableCell($userData['notes']);
  1465. $rows .= wf_TableRow($cells, 'row3');
  1466. $profileData = wf_TableBody($rows, '100%', 0, '');
  1467. //tags area
  1468. if (!empty($this->allTagtypes)) {
  1469. $this->catchTagChangeRequest();
  1470. $tagsArea = wf_modalAuto(web_add_icon(__('Add tag')), __('Add tag'), $this->profileTagsEditForm($userid));
  1471. $tagsArea .= $this->renderUserTags($userid);
  1472. } else {
  1473. $tagsArea = '';
  1474. }
  1475. $lifeStoryUrl = self::URL_USERS_LIFESTORY . $userid;
  1476. $profilePlugins = '';
  1477. $profilePlugins .= $this->renderPluginContainer('UKV', wf_Link($lifeStoryUrl, wf_img('skins/icon_orb_big.gif', __('User lifestory'))) . __('Details'));
  1478. $profilePlugins .= $this->renderPluginContainer('UKVCASH', wf_modalAuto(wf_img('skins/ukv/money.png', __('Cash')), __('Finance operations'), $this->userManualPaymentsForm($userid), '', '600', '250') . __('Cash'));
  1479. $profilePlugins .= $this->renderPluginContainer('UKVUED', wf_modalAuto(wf_img('skins/ukv/useredit.png', __('Edit user')), __('Edit user'), $this->userEditForm($userid), '') . __('Edit'));
  1480. $profilePlugins .= $this->renderPluginContainer('UKVSEAL', wf_modalAuto(wf_img('skins/ukv/cableseal.png', __('Cable seal')), __('Cable seal'), $this->userCableSealForm($userid), '') . __('Cable seal'));
  1481. $profilePlugins .= $this->renderPluginContainer('EMPLOYEE', wf_Link('?module=prevtasks&address=' . $shortAddress . '&ukvuserid=' . $userid, wf_img('skins/worker.png', __('Jobs'))) . __('Jobs'));
  1482. $profilePlugins .= $this->renderPluginContainer('UKVDEL', wf_modal(wf_img('skins/annihilation.gif', __('Deleting user')), __('Deleting user'), $this->userDeletionForm($userid), '', '800', '300') . __('Delete'));
  1483. if ($ubillingConfig->getAlterParam('PRINT_RECEIPTS_ENABLED') and $ubillingConfig->getAlterParam('PRINT_RECEIPTS_IN_PROFILE') and cfr('PRINTRECEIPTS')) {
  1484. $receiptsPrinter = new PrintReceipt();
  1485. $profilePlugins .= wf_tag('div', false, 'dashtask', 'style="height:75px; width:75px;"');
  1486. $profilePlugins .= $receiptsPrinter->renderWebFormForProfile($userid, 'ctvsrv', __('Cable television'), $userData['cash'], $userData['street'], $userData['build']);
  1487. $profilePlugins .= wf_tag('br');
  1488. $profilePlugins .= __('Print receipt');
  1489. $profilePlugins .= wf_tag('div', true);
  1490. }
  1491. //main view construction
  1492. $profilecells = wf_tag('td', false, '', 'valign="top"') . $profileData . wf_tag('td', true);
  1493. $profilerows = wf_TableRow($profilecells);
  1494. $profilecells = wf_tag('td', false, '', 'valign="top"') . $tagsArea . wf_tag('td', true);
  1495. $profilerows .= wf_TableRow($profilecells);
  1496. $profilecells = wf_tag('td', false, '', ' valign="top"') . $profilePlugins . wf_tag('td', true);
  1497. $profilerows .= wf_TableRow($profilecells);
  1498. $result = wf_TableBody($profilerows, '100%', '0');
  1499. $result .= $this->userPaymentsRender($userid);
  1500. //additional user comments
  1501. if ($this->altCfg['ADCOMMENTS_ENABLED']) {
  1502. $result .= wf_tag('h3') . __('Additional comments') . wf_tag('h3', true);
  1503. $result .= $adcomments->renderComments($userid);
  1504. }
  1505. return ($result);
  1506. } else {
  1507. throw new Exception(self::EX_USER_NOT_EXISTS);
  1508. }
  1509. }
  1510. /**
  1511. * Filter for quotes etc
  1512. *
  1513. * @param string $data
  1514. * @return string
  1515. */
  1516. protected function filterStringData($data) {
  1517. $result = str_replace('"', '`', $data);
  1518. $result = str_replace("'", '`', $result);
  1519. return ($result);
  1520. }
  1521. /**
  1522. * renders full user list with some ajax data
  1523. *
  1524. * @return string
  1525. */
  1526. public function renderUsers() {
  1527. global $ubillingConfig;
  1528. $altcfg = $ubillingConfig->getAlter();
  1529. $columns = array('Full address', 'Real Name', 'Contract', 'Tariff', 'Connected');
  1530. if ($altcfg['UKV_SHOW_REG_DATA']) {
  1531. $columns[] = 'User contract date';
  1532. }
  1533. $columns[] = 'Cash';
  1534. $result = wf_JqDtLoader($columns, self::URL_USERS_AJAX_SOURCE, false, 'users', 50);
  1535. return ($result);
  1536. }
  1537. /**
  1538. * Extracts ajax data for JQuery data tables
  1539. *
  1540. * @return void
  1541. */
  1542. public function ajaxUsers() {
  1543. global $ubillingConfig;
  1544. $altcfg = $ubillingConfig->getAlter();
  1545. $json = new wf_JqDtHelper();
  1546. if (!empty($this->users)) {
  1547. foreach ($this->users as $io => $each) {
  1548. //zero apt numbers as private builds
  1549. if ($altcfg['ZERO_TOLERANCE']) {
  1550. $apt = ($each['apt'] == '0') ? '' : '/' . $each['apt'];
  1551. } else {
  1552. $apt = '/' . $each['apt'];
  1553. }
  1554. //city display
  1555. if ($altcfg['CITY_DISPLAY']) {
  1556. $city = $each['city'] . ' ';
  1557. } else {
  1558. $city = '';
  1559. }
  1560. //activity flag
  1561. $activity = ($each['active']) ? web_bool_led($each['active']) . ' ' . __('Yes') : web_bool_led($each['active']) . ' ' . __('No');
  1562. $activity = str_replace('"', '', $activity);
  1563. //profile link
  1564. $profileLink = wf_Link(self::URL_USERS_PROFILE . $each['id'], web_profile_icon(), false) . ' ';
  1565. //building data array
  1566. $data[] = $profileLink . $city . $each['street'] . ' ' . $each['build'] . $apt;
  1567. $data[] = $each['realname'];
  1568. $data[] = $each['contract'];
  1569. $data[] = @$this->tariffs[$each['tariffid']]['tariffname'];
  1570. $data[] = $activity;
  1571. if ($altcfg['UKV_SHOW_REG_DATA']) {
  1572. $data[] = $each['regdate'];
  1573. }
  1574. $data[] = $each['cash'];
  1575. $json->addRow($data);
  1576. unset($data);
  1577. }
  1578. }
  1579. $json->getJson();
  1580. }
  1581. /**
  1582. * translates payment note for catv users
  1583. *
  1584. * @param string $paynote some payment note to translate
  1585. *
  1586. * @return string
  1587. */
  1588. protected function translatePaymentNote($paynote) {
  1589. if ($paynote == '') {
  1590. $paynote = __('CaTV');
  1591. }
  1592. if (ispos($paynote, 'BANKSTA:')) {
  1593. $paynote = str_replace('BANKSTA:', __('Bank statement') . ' ', $paynote);
  1594. }
  1595. if (ispos($paynote, 'ASCONTRACT')) {
  1596. $paynote = str_replace('ASCONTRACT', __('by users contract') . ' ', $paynote);
  1597. }
  1598. if (ispos($paynote, 'MOCK:')) {
  1599. $paynote = str_replace('MOCK:', __('Mock payment') . ' ', $paynote);
  1600. }
  1601. if (ispos($paynote, 'UKVFEE:')) {
  1602. $paynote = str_replace('UKVFEE:', __('Fee') . '. ', $paynote);
  1603. }
  1604. if (ispos($paynote, self::EX_USER_NO_TARIFF_SET)) {
  1605. $paynote = str_replace(self::EX_USER_NO_TARIFF_SET, __('Any tariff not set. Fee charge skipped.') . ' ', $paynote);
  1606. }
  1607. if (ispos($paynote, self::EX_USER_NOT_ACTIVE)) {
  1608. $paynote = str_replace(self::EX_USER_NOT_ACTIVE, __('User not connected. Fee charge skipped.'), $paynote);
  1609. }
  1610. return ($paynote);
  1611. }
  1612. /**
  1613. * renders all of user payments from database
  1614. *
  1615. * @param string $userid existing user ID
  1616. *
  1617. * @return string
  1618. */
  1619. public function userPaymentsRender($userid) {
  1620. global $ubillingConfig;
  1621. $altcfg = $ubillingConfig->getAlter();
  1622. $userid = vf($userid, 3);
  1623. $curdate = curdate();
  1624. $currentAdminLogin = whoami();
  1625. //extract delete admin logins
  1626. if (!empty($this->altCfg['CAN_DELETE_PAYMENTS'])) {
  1627. $deletingAdmins = explode(',', $this->altCfg['CAN_DELETE_PAYMENTS']);
  1628. $deletingAdmins = array_flip($deletingAdmins);
  1629. }
  1630. $iCanDeletePayments = (isset($deletingAdmins[$currentAdminLogin])) ? true : false;
  1631. if (isset($this->users[$userid])) {
  1632. if (empty($this->cashtypes)) {
  1633. $this->loadCashtypes();
  1634. }
  1635. $query = "SELECT * from `ukv_payments` WHERE `userid`='" . $userid . "' ORDER BY `id` DESC;";
  1636. $all = simple_queryall($query);
  1637. $cells = wf_TableCell(__('ID'));
  1638. $cells .= wf_TableCell(__('Date'));
  1639. $cells .= wf_TableCell(__('Cash'));
  1640. $cells .= wf_TableCell(__('From'));
  1641. $cells .= wf_TableCell(__('To'));
  1642. $cells .= wf_TableCell(__('Operation'));
  1643. $cells .= wf_TableCell(__('Cash type'));
  1644. $cells .= wf_TableCell(__('Notes'));
  1645. $cells .= wf_TableCell(__('Admin'));
  1646. if ($iCanDeletePayments) {
  1647. $cells .= wf_TableCell(__('Actions'));
  1648. }
  1649. $rows = wf_TableRow($cells, 'row1');
  1650. if (!empty($all)) {
  1651. foreach ($all as $io => $eachpayment) {
  1652. $normalPayment = true;
  1653. $paymentCashtype = @$this->cashtypes[$eachpayment['cashtypeid']];
  1654. if ($eachpayment['visible']) {
  1655. if (!ispos($eachpayment['note'], 'MOCK:')) {
  1656. $operation = __('Payment');
  1657. $rowColor = '#' . self::COLOR_PAYMENT;
  1658. } else {
  1659. $operation = __('Mock payment');
  1660. $rowColor = '#' . self::COLOR_MOCK;
  1661. $normalPayment = false;
  1662. }
  1663. } else {
  1664. if (!ispos($eachpayment['note'], 'UKVFEE:')) {
  1665. $operation = __('Correcting');
  1666. $rowColor = '#' . self::COLOR_CORRECTING;
  1667. } else {
  1668. $operation = __('Fee');
  1669. $rowColor = '#' . self::COLOR_FEE;
  1670. $paymentCashtype = __('Fee');
  1671. }
  1672. }
  1673. $colorStart = wf_tag('font', false, '', 'color="' . $rowColor . '"');
  1674. $colorEnd = wf_tag('font', true);
  1675. if ($normalPayment) {
  1676. $newBalance = $eachpayment['balance'] + $eachpayment['summ'];
  1677. } else {
  1678. $newBalance = $eachpayment['balance'];
  1679. }
  1680. //payment notes translation
  1681. if ($altcfg['TRANSLATE_PAYMENTS_NOTES']) {
  1682. $notes = $this->translatePaymentNote($eachpayment['note']);
  1683. } else {
  1684. $notes = $eachpayment['note'];
  1685. }
  1686. //today payments highlight
  1687. $rowClass = 'row3';
  1688. if (ispos($eachpayment['date'], $curdate)) {
  1689. $rowClass = 'paytoday';
  1690. }
  1691. $cells = wf_TableCell($eachpayment['id']);
  1692. $cells .= wf_TableCell($eachpayment['date']);
  1693. $cells .= wf_TableCell($eachpayment['summ']);
  1694. $cells .= wf_TableCell($eachpayment['balance']);
  1695. $cells .= wf_TableCell($newBalance);
  1696. $cells .= wf_TableCell($colorStart . $operation . $colorEnd);
  1697. $cells .= wf_TableCell($paymentCashtype);
  1698. $cells .= wf_TableCell($notes);
  1699. $cells .= wf_TableCell($eachpayment['admin']);
  1700. if ($iCanDeletePayments) {
  1701. $deletionRoute = self::URL_USERS_PROFILE . $userid . '&deletepaymentid=' . $eachpayment['id'];
  1702. $deleteControls = wf_JSAlert($deletionRoute, wf_img('skins/delete_small.png', __('Delete')), $this->messages->getDeleteAlert());
  1703. $cells .= wf_TableCell($deleteControls);
  1704. }
  1705. $rows .= wf_TableRow($cells, $rowClass);
  1706. }
  1707. }
  1708. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  1709. return ($result);
  1710. } else {
  1711. throw new Exception(self::EX_USER_NOT_EXISTS);
  1712. }
  1713. }
  1714. /**
  1715. * Deletes some existing payment from database
  1716. *
  1717. * @param int $paymentId
  1718. * @param int $userId
  1719. *
  1720. * @return void
  1721. */
  1722. public function paymentDelete($paymentId, $userId) {
  1723. $paymentId = vf($paymentId, 3);
  1724. $userId = vf($userId, 3);
  1725. if (!empty($paymentId) and !empty($userId)) {
  1726. $currentAdminLogin = whoami();
  1727. //extract delete admin logins
  1728. if (!empty($this->altCfg['CAN_DELETE_PAYMENTS'])) {
  1729. $deletingAdmins = explode(',', $this->altCfg['CAN_DELETE_PAYMENTS']);
  1730. $deletingAdmins = array_flip($deletingAdmins);
  1731. }
  1732. $iCanDeletePayments = (isset($deletingAdmins[$currentAdminLogin])) ? true : false;
  1733. if ($iCanDeletePayments) {
  1734. $payments = new NyanORM('ukv_payments');
  1735. $payments->where('id', '=', $paymentId);
  1736. $payments->where('userid', '=', $userId);
  1737. $payments->delete();
  1738. log_register("UKV PAYMENT DELETE [" . $paymentId . "] ((" . $userId . "))");
  1739. } else {
  1740. log_register("UKV PAYMENT UNAUTH DELETION ATTEMPT [" . $paymentId . "] ((" . $userId . "))");
  1741. }
  1742. }
  1743. }
  1744. /*
  1745. * Bank statements processing
  1746. */
  1747. /**
  1748. * returns bank statement upload form
  1749. *
  1750. * @return string
  1751. */
  1752. public function bankstaLoadForm() {
  1753. $uploadinputs = wf_HiddenInput('uploadukvbanksta', 'true');
  1754. $uploadinputs .= __('Bank statement') . wf_tag('br');
  1755. $uploadinputs .= wf_tag('input', false, '', 'id="fileselector" type="file" name="ukvbanksta"') . wf_tag('br');
  1756. $uploadinputs .= __('Bankstatement type');
  1757. $uploadinputs .= wf_RadioInput('ukvbankstatype', __('Oschadbank'), 'oschad', false, true);
  1758. $uploadinputs .= wf_RadioInput('ukvbankstatype', __('Oschadbank terminal'), 'oschadterm', false, false);
  1759. $uploadinputs .= wf_RadioInput('ukvbankstatype', __('PrivatBank'), 'privatbankdbf', true, false);
  1760. $uploadinputs .= wf_Submit('Upload');
  1761. $uploadform = bs_UploadFormBody('', 'POST', $uploadinputs, 'glamour');
  1762. return ($uploadform);
  1763. }
  1764. /**
  1765. * checks is banksta hash unique?
  1766. *
  1767. * @param string $hash bank statement raw content hash
  1768. *
  1769. * @return bool
  1770. */
  1771. protected function bankstaCheckHash($hash) {
  1772. $query = "SELECT `id` from `ukv_banksta` WHERE `hash`='" . $hash . "';";
  1773. $data = simple_query($query);
  1774. if (empty($data)) {
  1775. return (true);
  1776. } else {
  1777. return (false);
  1778. }
  1779. }
  1780. /**
  1781. * process of uploading of bank statement
  1782. *
  1783. * @return array
  1784. */
  1785. public function bankstaDoUpload() {
  1786. $uploaddir = self::BANKSTA_PATH;
  1787. $allowedExtensions = array("dbf");
  1788. $result = array();
  1789. $extCheck = true;
  1790. //check file type
  1791. foreach ($_FILES as $file) {
  1792. if ($file['tmp_name'] > '') {
  1793. if (@!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) {
  1794. $extCheck = false;
  1795. }
  1796. }
  1797. }
  1798. if ($extCheck) {
  1799. $filename = zb_rand_string(8) . '.dbf';
  1800. $uploadfile = $uploaddir . $filename;
  1801. if (move_uploaded_file($_FILES['ukvbanksta']['tmp_name'], $uploadfile)) {
  1802. $fileContent = file_get_contents(self::BANKSTA_PATH . $filename);
  1803. $fileHash = md5($fileContent);
  1804. $fileContent = ''; //free some memory
  1805. if ($this->bankstaCheckHash($fileHash)) {
  1806. $result = array(
  1807. 'filename' => $_FILES['ukvbanksta']['name'],
  1808. 'savedname' => $filename,
  1809. 'hash' => $fileHash
  1810. );
  1811. } else {
  1812. log_register('UKV BANKSTA DUPLICATE TRY ' . $fileHash);
  1813. show_error(__('Same bank statement already exists'));
  1814. }
  1815. } else {
  1816. show_error(__('Cant upload file to') . ' ' . self::BANKSTA_PATH);
  1817. }
  1818. } else {
  1819. show_error(__('Wrong file type'));
  1820. log_register('UKV BANKSTA WRONG FILETYPE');
  1821. }
  1822. return ($result);
  1823. }
  1824. /**
  1825. * Creates new banksta row in Database
  1826. *
  1827. * @param string $newDate
  1828. * @param string $newHash
  1829. * @param string $newFilename
  1830. * @param string $newAdmin
  1831. * @param string $newContract
  1832. * @param string $newSumm
  1833. * @param string $newAddress
  1834. * @param string $newRealname
  1835. * @param string $newNotes
  1836. * @param string $newPate
  1837. * @param string $newPtime
  1838. * @param int $payId
  1839. *
  1840. * @return void
  1841. */
  1842. protected function bankstaCreateRow($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm, $newAddress, $newRealname, $newNotes, $newPdate, $newPtime, $payId) {
  1843. $query = "INSERT INTO `ukv_banksta` (`id`, `date`, `hash`, `filename`, `admin`, `contract`, `summ`, `address`, `realname`, `notes`, `pdate`, `ptime`, `processed`, `payid`)
  1844. VALUES (
  1845. NULL ,
  1846. '" . $newDate . "',
  1847. '" . $newHash . "',
  1848. '" . $newFilename . "',
  1849. '" . $newAdmin . "',
  1850. '" . $newContract . "',
  1851. '" . $newSumm . "',
  1852. '" . $newAddress . "',
  1853. '" . $newRealname . "',
  1854. '" . $newNotes . "',
  1855. '" . $newPdate . "',
  1856. '" . $newPtime . "',
  1857. '0',
  1858. '" . $payId . "'
  1859. );
  1860. ";
  1861. nr_query($query);
  1862. }
  1863. /**
  1864. * new banksta store in database bankstaDoUpload() method and returns preprocessed
  1865. * bank statement hash for further usage
  1866. *
  1867. * @param $bankstadata array returned from
  1868. *
  1869. * @return string
  1870. */
  1871. public function bankstaPreprocessing($bankstadata) {
  1872. $result = '';
  1873. if (!empty($bankstadata)) {
  1874. if (file_exists(self::BANKSTA_PATH . $bankstadata['savedname'])) {
  1875. //processing raw data
  1876. $newHash = $bankstadata['hash'];
  1877. $result = $newHash;
  1878. $newFilename = $bankstadata['filename'];
  1879. $newAdmin = whoami();
  1880. $payId = vf($this->altCfg['UKV_BS_PAYID'], 3);
  1881. $dbf = new dbf_class(self::BANKSTA_PATH . $bankstadata['savedname']);
  1882. $num_rec = $dbf->dbf_num_rec;
  1883. $importCounter = 0;
  1884. for ($i = 0; $i <= $num_rec; $i++) {
  1885. $eachRow = $dbf->getRowAssoc($i);
  1886. if (!empty($eachRow)) {
  1887. if (@$eachRow[self::BANKSTA_CONTRACT] != '') {
  1888. $newDate = date("Y-m-d H:i:s");
  1889. $newContract = trim($eachRow[self::BANKSTA_CONTRACT]);
  1890. $newContract = mysql_real_escape_string($newContract);
  1891. $newSumm = trim($eachRow[self::BANKSTA_SUMM]);
  1892. $newSumm = mysql_real_escape_string($newSumm);
  1893. $newAddress = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::BANKSTA_ADDRESS]);
  1894. $newAddress = mysql_real_escape_string($newAddress);
  1895. $newRealname = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::BANKSTA_REALNAME]);
  1896. $newRealname = mysql_real_escape_string($newRealname);
  1897. $newNotes = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::BANKSTA_NOTES]);
  1898. $newNotes = mysql_real_escape_string($newNotes);
  1899. $newPdate = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::BANKSTA_DATE]);
  1900. $newPdate = mysql_real_escape_string($newPdate);
  1901. $newPtime = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::BANKSTA_TIME]);
  1902. $newPtime = mysql_real_escape_string($newPtime);
  1903. $this->bankstaCreateRow($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm, $newAddress, $newRealname, $newNotes, $newPdate, $newPtime, $payId);
  1904. $importCounter++;
  1905. }
  1906. }
  1907. }
  1908. log_register('UKV BANKSTA IMPORTED ' . $importCounter . ' ROWS');
  1909. } else {
  1910. show_error(__('Strange exeption'));
  1911. }
  1912. } else {
  1913. throw new Exception(self::EX_BANKSTA_PREPROCESS_EMPTY);
  1914. }
  1915. return ($result);
  1916. }
  1917. /**
  1918. * new banksta store in database bankstaDoUpload() method and returns preprocessed
  1919. * bank statement hash for further usage
  1920. *
  1921. * @param string $bankstadata array returned from
  1922. *
  1923. * @return string
  1924. */
  1925. public function bankstaPreprocessingTerminal($bankstadata) {
  1926. $result = '';
  1927. if (!empty($bankstadata)) {
  1928. if (file_exists(self::BANKSTA_PATH . $bankstadata['savedname'])) {
  1929. //processing raw data
  1930. $newHash = $bankstadata['hash'];
  1931. $result = $newHash;
  1932. $newFilename = $bankstadata['filename'];
  1933. $newAdmin = whoami();
  1934. $payId = vf($this->altCfg['UKV_BS_PAYID'], 3);
  1935. $dbf = new dbf_class(self::BANKSTA_PATH . $bankstadata['savedname']);
  1936. $num_rec = $dbf->dbf_num_rec;
  1937. $importCounter = 0;
  1938. for ($i = 0; $i <= $num_rec; $i++) {
  1939. $eachRow = $dbf->getRowAssoc($i);
  1940. if (!empty($eachRow)) {
  1941. if (!empty($eachRow[self::OT_BANKSTA_CONTRACT])) {
  1942. $newDate = date("Y-m-d H:i:s");
  1943. $newContract = trim($eachRow[self::OT_BANKSTA_CONTRACT]);
  1944. $newContract = mysql_real_escape_string($newContract);
  1945. $newSumm = trim($eachRow[self::OT_BANKSTA_SUMM]);
  1946. $newSumm = mysql_real_escape_string($newSumm);
  1947. $newAddress = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::OT_BANKSTA_ADDRESS]);
  1948. $newAddress = mysql_real_escape_string($newAddress);
  1949. $newRealname = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::OT_BANKSTA_REALNAME]);
  1950. $newRealname = mysql_real_escape_string($newRealname);
  1951. $newNotes = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::OT_BANKSTA_NOTES]);
  1952. $newNotes = mysql_real_escape_string($newNotes);
  1953. $newPdate = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::OT_BANKSTA_DATE]);
  1954. $newPdate = mysql_real_escape_string($newPdate);
  1955. $newPtime = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::OT_BANKSTA_TIME]);
  1956. $newPtime = mysql_real_escape_string($newPtime);
  1957. $this->bankstaCreateRow($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm, $newAddress, $newRealname, $newNotes, $newPdate, $newPtime, $payId);
  1958. $importCounter++;
  1959. }
  1960. }
  1961. }
  1962. log_register('UKV BANKSTA IMPORTED ' . $importCounter . ' ROWS');
  1963. } else {
  1964. show_error(__('Strange exeption'));
  1965. }
  1966. } else {
  1967. throw new Exception(self::EX_BANKSTA_PREPROCESS_EMPTY);
  1968. }
  1969. return ($result);
  1970. }
  1971. /**
  1972. * new banksta store in database bankstaDoUpload() method and returns preprocessed
  1973. * bank statement hash for further usage
  1974. *
  1975. * @param string $bankstadata array returned from
  1976. *
  1977. * @return string
  1978. */
  1979. public function bankstaPreprocessingPrivatDbf($bankstadata) {
  1980. $result = '';
  1981. if (!empty($bankstadata)) {
  1982. if (file_exists(self::BANKSTA_PATH . $bankstadata['savedname'])) {
  1983. //processing raw data
  1984. $newHash = $bankstadata['hash'];
  1985. $result = $newHash;
  1986. $newFilename = $bankstadata['filename'];
  1987. $newAdmin = whoami();
  1988. $payId = vf($this->altCfg['UKV_BSPB_PAYID'], 3);
  1989. $dbf = new dbf_class(self::BANKSTA_PATH . $bankstadata['savedname']);
  1990. $num_rec = $dbf->dbf_num_rec;
  1991. $importCounter = 0;
  1992. for ($i = 0; $i <= $num_rec; $i++) {
  1993. $eachRow = $dbf->getRowAssoc($i);
  1994. if (!empty($eachRow)) {
  1995. if (@$eachRow[self::PB_BANKSTA_CONTRACT] != '') {
  1996. $newDate = date("Y-m-d H:i:s");
  1997. $newContract = trim($eachRow[self::PB_BANKSTA_CONTRACT]);
  1998. $newContract = mysql_real_escape_string($newContract);
  1999. $newSumm = trim($eachRow[self::PB_BANKSTA_SUMM]);
  2000. $newSumm = mysql_real_escape_string($newSumm);
  2001. $newAddress = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::PB_BANKSTA_ADDRESS]);
  2002. $newAddress = mysql_real_escape_string($newAddress);
  2003. $newRealname = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::PB_BANKSTA_REALNAME]);
  2004. $newRealname = mysql_real_escape_string($newRealname);
  2005. $newNotes = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $eachRow[self::PB_BANKSTA_NOTES]);
  2006. $newNotes = mysql_real_escape_string($newNotes);
  2007. $pbDate = $eachRow[self::PB_BANKSTA_DATE];
  2008. $pbDate = strtotime($pbDate);
  2009. $pbDate = date("Y-m-d", $pbDate);
  2010. $newPdate = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, $pbDate);
  2011. $newPdate = mysql_real_escape_string($newPdate);
  2012. $newPtime = iconv(self::BANKSTA_IN_CHARSET, self::BANKSTA_OUT_CHARSET, curtime());
  2013. $newPtime = mysql_real_escape_string($newPtime);
  2014. $this->bankstaCreateRow($newDate, $newHash, $newFilename, $newAdmin, $newContract, $newSumm, $newAddress, $newRealname, $newNotes, $newPdate, $newPtime, $payId);
  2015. $importCounter++;
  2016. }
  2017. }
  2018. }
  2019. log_register('UKV BANKSTA IMPORTED ' . $importCounter . ' ROWS');
  2020. } else {
  2021. show_error(__('Strange exeption'));
  2022. }
  2023. } else {
  2024. throw new Exception(self::EX_BANKSTA_PREPROCESS_EMPTY);
  2025. }
  2026. return ($result);
  2027. }
  2028. /**
  2029. * returns banksta processing form for some hash
  2030. *
  2031. * @param string $hash existing preprocessing bank statement hash
  2032. *
  2033. * @return string
  2034. */
  2035. public function bankstaProcessingForm($hash) {
  2036. $hash = mysql_real_escape_string($hash);
  2037. $query = "SELECT * from `ukv_banksta` WHERE `hash`='" . $hash . "' ORDER BY `id` ASC;";
  2038. $all = simple_queryall($query);
  2039. $cashPairs = array();
  2040. $totalSumm = 0;
  2041. $rowsCount = 0;
  2042. $cells = wf_TableCell(__('ID'));
  2043. $cells .= wf_TableCell(__('Address'));
  2044. $cells .= wf_TableCell(__('Real Name'));
  2045. $cells .= wf_TableCell(__('Contract'));
  2046. $cells .= wf_TableCell(__('Cash'));
  2047. $cells .= wf_TableCell(__('Processed'));
  2048. $cells .= wf_TableCell(__('Contract'));
  2049. $cells .= wf_TableCell(__('Real Name'));
  2050. $cells .= wf_TableCell(__('Address'));
  2051. $cells .= wf_TableCell(__('Tariff'));
  2052. $rows = wf_TableRow($cells, 'row1');
  2053. if (!empty($all)) {
  2054. foreach ($all as $io => $each) {
  2055. $AddInfoControl = wf_Link(self::URL_BANKSTA_DETAILED . $each['id'], $each['id'], false, '');
  2056. $processed = ($each['processed']) ? true : false;
  2057. $cells = wf_TableCell($AddInfoControl);
  2058. $cells .= wf_TableCell($each['address']);
  2059. $cells .= wf_TableCell($each['realname']);
  2060. if (!$processed) {
  2061. $editInputs = wf_TextInput('newbankcontr', '', $each['contract'], false, '6');
  2062. $editInputs .= wf_CheckInput('lockbankstarow', __('Lock'), false, false);
  2063. $editInputs .= wf_HiddenInput('bankstacontractedit', $each['id']);
  2064. $editInputs .= wf_Submit(__('Save'));
  2065. $editForm = wf_Form('', 'POST', $editInputs);
  2066. } else {
  2067. $editForm = $each['contract'];
  2068. }
  2069. $cells .= wf_TableCell($editForm);
  2070. $cells .= wf_TableCell($each['summ']);
  2071. $cells .= wf_TableCell(web_bool_led($processed));
  2072. //user detection
  2073. if (isset($this->contracts[$each['contract']])) {
  2074. $detectedUser = $this->users[$this->contracts[$each['contract']]];
  2075. $detectedContract = wf_Link(self::URL_USERS_PROFILE . $detectedUser['id'], web_profile_icon() . ' ' . $detectedUser['contract'], false, '');
  2076. $detectedAddress = $detectedUser['street'] . ' ' . $detectedUser['build'] . '/' . $detectedUser['apt'];
  2077. $detectedRealName = $detectedUser['realname'];
  2078. $detectedTariff = $detectedUser['tariffid'];
  2079. $detectedTariff = $this->tariffs[$detectedTariff]['tariffname'];
  2080. if (!$processed) {
  2081. $cashPairs[$each['id']]['bankstaid'] = $each['id'];
  2082. $cashPairs[$each['id']]['userid'] = $detectedUser['id'];
  2083. $cashPairs[$each['id']]['usercontract'] = $detectedUser['contract'];
  2084. $cashPairs[$each['id']]['summ'] = $each['summ'];
  2085. $cashPairs[$each['id']]['payid'] = $each['payid'];
  2086. }
  2087. $rowClass = 'row3';
  2088. //try to highlight multiple payments
  2089. if (!isset($this->bankstafoundusers[$each['contract']])) {
  2090. $this->bankstafoundusers[$each['contract']] = $detectedUser['id'];
  2091. } else {
  2092. $rowClass = 'ukvbankstadup';
  2093. }
  2094. } else {
  2095. $detectedContract = '';
  2096. $detectedAddress = '';
  2097. $detectedRealName = '';
  2098. $detectedTariff = '';
  2099. if ($each['processed'] == 1) {
  2100. $rowClass = 'row2';
  2101. } else {
  2102. $rowClass = 'undone';
  2103. }
  2104. }
  2105. $cells .= wf_TableCell($detectedContract);
  2106. $cells .= wf_TableCell($detectedRealName);
  2107. $cells .= wf_TableCell($detectedAddress);
  2108. $cells .= wf_TableCell($detectedTariff);
  2109. $rows .= wf_TableRow($cells, $rowClass);
  2110. $totalSumm = $totalSumm + $each['summ'];
  2111. $rowsCount++;
  2112. }
  2113. }
  2114. //summary here
  2115. $cells = wf_TableCell('');
  2116. $cells .= wf_TableCell(__('Total'));
  2117. $cells .= wf_TableCell($rowsCount);
  2118. $cells .= wf_TableCell('');
  2119. $cells .= wf_TableCell($totalSumm);
  2120. $cells .= wf_TableCell('');
  2121. $cells .= wf_TableCell('');
  2122. $cells .= wf_TableCell('');
  2123. $cells .= wf_TableCell('');
  2124. $cells .= wf_TableCell('');
  2125. $rows .= wf_TableRow($cells, 'row2');
  2126. $result = wf_TableBody($rows, '100%', '0', '');
  2127. if (!empty($cashPairs)) {
  2128. $cashPairs = serialize($cashPairs);
  2129. $cashPairs = base64_encode($cashPairs);
  2130. $cashInputs = wf_HiddenInput('bankstaneedpaymentspush', $cashPairs);
  2131. $cashInputs .= wf_Submit(__('Bank statement processing'));
  2132. $result .= wf_FormDisabler();
  2133. $result .= wf_Form('', 'POST', $cashInputs, 'glamour');
  2134. }
  2135. return ($result);
  2136. }
  2137. /**
  2138. * returns detailed banksta row info
  2139. *
  2140. * @param int $id existing banksta ID
  2141. *
  2142. * @return string
  2143. */
  2144. public function bankstaGetDetailedRowInfo($id) {
  2145. $id = vf($id, 3);
  2146. $query = "SELECT * from `ukv_banksta` WHERE `id`='" . $id . "'";
  2147. $dataRaw = simple_query($query);
  2148. $result = '';
  2149. $result .= wf_BackLink(self::URL_BANKSTA_PROCESSING . $dataRaw['hash']);
  2150. $result .= wf_delimiter();
  2151. if (!empty($dataRaw)) {
  2152. $result .= wf_tag('pre', false, 'floatpanelswide', '') . print_r($dataRaw, true) . wf_tag('pre', true);
  2153. $result .= wf_CleanDiv();
  2154. }
  2155. return ($result);
  2156. }
  2157. /**
  2158. * loads all of banksta rows to further checks to private prop
  2159. *
  2160. * @return void
  2161. */
  2162. protected function loadBankstaAll() {
  2163. $query = "SELECT * from `ukv_banksta`";
  2164. $all = simple_queryall($query);
  2165. if (!empty($all)) {
  2166. foreach ($all as $io => $each) {
  2167. $this->bankstarecords[$each['id']] = $each;
  2168. }
  2169. }
  2170. }
  2171. /**
  2172. * checks is banksta row ID unprocessed?
  2173. *
  2174. * @param int $bankstaid existing banksta row ID
  2175. *
  2176. * @return bool
  2177. */
  2178. protected function bankstaIsUnprocessed($bankstaid) {
  2179. $result = false;
  2180. if (isset($this->bankstarecords[$bankstaid])) {
  2181. if ($this->bankstarecords[$bankstaid]['processed'] == 0) {
  2182. $result = true;
  2183. } else {
  2184. $result = false;
  2185. }
  2186. }
  2187. return ($result);
  2188. }
  2189. /**
  2190. * sets banksta row as processed
  2191. *
  2192. * @param int $bankstaid existing bank statement ID
  2193. *
  2194. * @return void
  2195. */
  2196. public function bankstaSetProcessed($bankstaid) {
  2197. $bankstaid = vf($bankstaid, 3);
  2198. simple_update_field('ukv_banksta', 'processed', 1, "WHERE `id`='" . $bankstaid . "'");
  2199. }
  2200. /**
  2201. * push payments to some user accounts via bank statements
  2202. *
  2203. * @return void
  2204. */
  2205. public function bankstaPushPayments() {
  2206. if (wf_CheckPost(array('bankstaneedpaymentspush'))) {
  2207. $rawData = base64_decode($_POST['bankstaneedpaymentspush']);
  2208. $rawData = unserialize($rawData);
  2209. if (!empty($rawData)) {
  2210. if (empty($this->bankstarecords)) {
  2211. $this->loadBankstaAll();
  2212. }
  2213. foreach ($rawData as $io => $eachstatement) {
  2214. if ($this->bankstaIsUnprocessed($eachstatement['bankstaid'])) {
  2215. //all good is with this row
  2216. // push payment and mark banksta as processed
  2217. $payid = (!empty($eachstatement['payid'])) ? vf($eachstatement['payid'], 3) : 1; //default cash
  2218. $this->userAddCash($eachstatement['userid'], $eachstatement['summ'], 1, $payid, 'BANKSTA: [' . $eachstatement['bankstaid'] . '] ASCONTRACT ' . $eachstatement['usercontract']);
  2219. $this->bankstaSetProcessed($eachstatement['bankstaid']);
  2220. } else {
  2221. //duplicate payment try
  2222. log_register('UKV BANKSTA TRY DUPLICATE [' . $eachstatement['bankstaid'] . '] PAYMENT PUSH');
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. /**
  2229. * Renders bank statements list datatables json datasource
  2230. *
  2231. * @return void
  2232. */
  2233. public function bankstaRenderAjaxList() {
  2234. $query = "SELECT `filename`,`hash`,`date`,`admin`,`payid`,COUNT(`id`) AS `rowcount` FROM `ukv_banksta` GROUP BY `hash` ORDER BY `date` DESC;";
  2235. $all = simple_queryall($query);
  2236. $this->loadCashtypes();
  2237. $jsonAAData = array();
  2238. if (!empty($all)) {
  2239. foreach ($all as $io => $each) {
  2240. $jsonItem = array();
  2241. $jsonItem[] = $each['date'];
  2242. $jsonItem[] = $each['filename'];
  2243. $jsonItem[] = @$this->cashtypes[$each['payid']];
  2244. $jsonItem[] = $each['rowcount'];
  2245. $jsonItem[] = $each['admin'];
  2246. $actLinks = wf_Link(self::URL_BANKSTA_PROCESSING . $each['hash'], wf_img('skins/icon_search_small.gif', __('Show')), false, '');
  2247. $jsonItem[] = $actLinks;
  2248. $jsonAAData[] = $jsonItem;
  2249. }
  2250. }
  2251. $result = array("aaData" => $jsonAAData);
  2252. die(json_encode($result));
  2253. }
  2254. /**
  2255. * Renders bank statements list container
  2256. *
  2257. * @return type
  2258. */
  2259. public function bankstaRenderList() {
  2260. $result = '';
  2261. $columns = array(__('Date'), __('Filename'), __('Type'), __('Rows'), __('Admin'), __('Actions'));
  2262. $opts = '"order": [[ 0, "desc" ]]';
  2263. $result .= wf_JqDtLoader($columns, self::URL_BANKSTA_MGMT . '&ajbslist=true', false, __('Bank statement'), 50, $opts);
  2264. return ($result);
  2265. }
  2266. /**
  2267. * cnahges banksta contract number for some existing row
  2268. *
  2269. * @param int $bankstaid existing bank statement transaction ID
  2270. * @param string $contract new contract number for this row
  2271. */
  2272. public function bankstaSetContract($bankstaid, $contract) {
  2273. $bankstaid = vf($bankstaid, 3);
  2274. $contract = mysql_real_escape_string($contract);
  2275. $contract = trim($contract);
  2276. if (empty($this->bankstarecords)) {
  2277. $this->loadBankstaAll();
  2278. }
  2279. if (isset($this->bankstarecords[$bankstaid])) {
  2280. $oldContract = $this->bankstarecords[$bankstaid]['contract'];
  2281. simple_update_field('ukv_banksta', 'contract', $contract, "WHERE `id`='" . $bankstaid . "';");
  2282. log_register('UKV BANKSTA [' . $bankstaid . '] CONTRACT `' . $oldContract . '` CHANGED ON `' . $contract . '`');
  2283. } else {
  2284. log_register('UKV BANKSTA NONEXIST [' . $bankstaid . '] CONTRACT CHANGE TRY');
  2285. }
  2286. }
  2287. /*
  2288. * and there is some reports for UKV subsystem
  2289. */
  2290. /**
  2291. * returns report icon and link
  2292. *
  2293. * @return string
  2294. */
  2295. protected function buildReportTask($link, $icon, $text) {
  2296. $icon_path = 'skins/ukv/';
  2297. $task_link = $link;
  2298. $task_icon = $icon_path . $icon;
  2299. $task_text = $text;
  2300. if (isset($_COOKIE['tb_iconsize'])) {
  2301. $tbiconsize = vf($_COOKIE['tb_iconsize'], 3);
  2302. } else {
  2303. $tbiconsize = '128';
  2304. }
  2305. $template = wf_tag('div', false, 'dashtask', 'style="height:' . ($tbiconsize + 30) . 'px; width:' . ($tbiconsize + 30) . 'px;"');
  2306. $template .= wf_tag('a', false, '', 'href="' . $task_link . '"');
  2307. $template .= wf_tag('img', false, '', 'src="' . $task_icon . '" border="0" width="' . $tbiconsize . '" height="' . $tbiconsize . '" alt="' . $task_text . '" title="' . $task_text . '"');
  2308. $template .= wf_tag('a', true);
  2309. $template .= wf_tag('br');
  2310. $template .= wf_tag('br');
  2311. $template .= $task_text;
  2312. $template .= wf_tag('div', true);
  2313. return ($template);
  2314. }
  2315. /**
  2316. * renders report list
  2317. *
  2318. * @return void
  2319. */
  2320. public function reportList() {
  2321. $reports = '';
  2322. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportDebtors', 'debtors.png', __('Debtors'));
  2323. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportAntiDebtors', 'antidebtors.png', __('AntiDebtors'));
  2324. if (cfr('UKVCASH')) {
  2325. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportTariffs', 'tariffsreport.jpg', __('Tariffs report'));
  2326. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportFinance', 'financereport.jpg', __('Finance report'));
  2327. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportFees', 'feesreport.png', __('Money fees'));
  2328. }
  2329. if (cfr('UKVREG')) {
  2330. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportSignup', 'signupreport.jpg', __('Signup report'));
  2331. }
  2332. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportStreets', 'streetsreport.png', __('Streets report'));
  2333. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportDebtAddr', 'debtaddr.png', __('Current debtors for delivery by address'));
  2334. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportDebtStreets', 'debtstreets.png', __('Current debtors for delivery by streets'));
  2335. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportTagcloud', 'tagcloud.jpg', __('Tag cloud'));
  2336. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportIntegrity', 'integrity.png', __('Integrity control'));
  2337. if ($this->altCfg['COMPLEX_ENABLED']) {
  2338. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportComplexAssign', 'reportcomplexassign.png', __('Users with complex services'));
  2339. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportShouldbeComplex', 'shouldbecomplex.png', __('Users which should be complex in UKV'));
  2340. $reports .= $this->buildReportTask(self::URL_REPORTS_MGMT . 'reportShouldNotbeComplex', 'shouldbecomplex.png', __('Users which should not be complex in UKV'));
  2341. }
  2342. if ($this->altCfg['CONDET_ENABLED']) {
  2343. $reports .= $this->buildReportTask('?module=report_condet&ukv=true', 'report_condet.png', __('Connection details report'));
  2344. }
  2345. $reports .= wf_CleanDiv();
  2346. show_window(__('Reports'), $reports);
  2347. }
  2348. /**
  2349. * shows printable report content
  2350. *
  2351. * @param $title report title
  2352. * @param $data report data to printable transform
  2353. *
  2354. * @return void
  2355. */
  2356. protected function reportPrintable($title, $data) {
  2357. $style = file_get_contents(CONFIG_PATH . "ukvprintable.css");
  2358. $header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2359. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
  2360. <head>
  2361. <title>' . $title . '</title>
  2362. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  2363. <style type="text/css">
  2364. ' . $style . '
  2365. </style>
  2366. <script src="modules/jsc/sorttable.js" language="javascript"></script>
  2367. </head>
  2368. <body>
  2369. ';
  2370. $footer = '</body> </html>';
  2371. $title = (!empty($title)) ? wf_tag('h2') . $title . wf_tag('h2', true) : '';
  2372. $data = $header . $title . $data . $footer;
  2373. $profileIconMask = web_profile_icon();
  2374. $connectedMask = web_bool_led(1, true);
  2375. $disconnectedMask = web_bool_led(0, true);
  2376. $frozenMask = wf_img('skins/icon_passive.gif');
  2377. $data = str_replace($profileIconMask, '', $data);
  2378. $data = str_replace($connectedMask, __('Connected'), $data);
  2379. $data = str_replace($frozenMask, __('Freezed'), $data);
  2380. $data = str_replace($disconnectedMask, wf_tag('b') . __('Disconnected') . wf_tag('b', true), $data);
  2381. die($data);
  2382. }
  2383. /**
  2384. * Renders debtors notifications by address selection
  2385. *
  2386. *
  2387. * @return void
  2388. */
  2389. public function reportDebtAddr() {
  2390. if (wf_CheckGet(array('aj_rdabuildsel'))) {
  2391. if (!empty($_GET['aj_rdabuildsel'])) {
  2392. $streetId = base64_decode($_GET['aj_rdabuildsel']);
  2393. if ($streetId != '-') {
  2394. $buildParams = array();
  2395. if (!empty($this->users)) {
  2396. foreach ($this->users as $io => $each) {
  2397. if ($each['street'] == $streetId) {
  2398. $buildParams[$each['build']] = $each['build'];
  2399. }
  2400. }
  2401. natsort($buildParams);
  2402. }
  2403. $buildInputs = wf_Selector('buildsel', $buildParams, __('Build'), '', true);
  2404. $buildInputs .= wf_HiddenInput('streetsel', $streetId);
  2405. $buildInputs .= wf_TextInput('debtcash', __('The threshold at which the money considered user debtor'), '0', true, 4);
  2406. $buildInputs .= wf_Submit(__('Print'));
  2407. die($buildInputs);
  2408. } else {
  2409. die('');
  2410. }
  2411. }
  2412. }
  2413. if (!wf_CheckPost(array('buildsel', 'streetsel'))) {
  2414. $streetData = array();
  2415. if (!empty($this->streets)) {
  2416. foreach ($this->streets as $streetId => $eachStreetName) {
  2417. $streetId = base64_encode($eachStreetName);
  2418. $streetData[self::URL_REPORTS_MGMT . 'reportDebtAddr' . '&aj_rdabuildsel=' . $streetId] = $eachStreetName;
  2419. }
  2420. }
  2421. $inputs = wf_AjaxLoader();
  2422. $inputs .= wf_AjaxSelectorAC('aj_buildcontainer', $streetData, __('Street'), '', false);
  2423. $inputs .= wf_AjaxContainer('aj_buildcontainer');
  2424. $form = wf_Form('', 'POST', $inputs, 'glamour');
  2425. show_window(__('Current debtors for delivery by address'), $form);
  2426. } else {
  2427. $searchBuild = mysql_real_escape_string($_POST['buildsel']);
  2428. $searchStreet = mysql_real_escape_string($_POST['streetsel']);
  2429. $debtCash = (wf_CheckPost(array('debtcash'))) ? ('-' . vf($_POST['debtcash'], 3)) : 0;
  2430. $query = "SELECT * from `ukv_users` WHERE `cash`<'" . $debtCash . "' AND `street`='" . $searchStreet . "' AND `build`='" . $searchBuild . "' AND `active`='1' ORDER BY `street`";
  2431. $allDebtors = simple_queryall($query);
  2432. $rawTemplate = file_get_contents(CONFIG_PATH . "catv_debtors.tpl");
  2433. $printableTemplate = '';
  2434. if (!empty($allDebtors)) {
  2435. foreach ($allDebtors as $io => $each) {
  2436. $rowtemplate = $rawTemplate;
  2437. $rowtemplate = str_ireplace('{REALNAME}', $each['realname'], $rowtemplate);
  2438. $rowtemplate = str_ireplace('{STREET}', $each['street'], $rowtemplate);
  2439. $rowtemplate = str_ireplace('{BUILD}', $each['build'], $rowtemplate);
  2440. $rowtemplate = str_ireplace('{APT}', $each['apt'], $rowtemplate);
  2441. $rowtemplate = str_ireplace('{DEBT}', $each['cash'], $rowtemplate);
  2442. $rowtemplate = str_ireplace('{CURDATE}', curdate(), $rowtemplate);
  2443. $rowtemplate = str_ireplace('{PAYDAY}', (date("Y-m-") . '01'), $rowtemplate);
  2444. $printableTemplate .= $rowtemplate;
  2445. }
  2446. $printableTemplate = wf_TableBody($printableTemplate, '100%', 0, 'sortable');
  2447. $printableTemplate = $this->reportPrintable(__('Current debtors for delivery by address'), $printableTemplate);
  2448. } else {
  2449. show_window('', $this->messages->getStyledMessage(__('Nothing found'), 'info'));
  2450. }
  2451. }
  2452. }
  2453. /**
  2454. * Renders debtors notifications by address selection
  2455. *
  2456. *
  2457. * @return void
  2458. */
  2459. public function reportDebtStreets() {
  2460. if (wf_CheckGet(array('aj_rdabuildsel'))) {
  2461. if (!empty($_GET['aj_rdabuildsel'])) {
  2462. $streetId = base64_decode($_GET['aj_rdabuildsel']);
  2463. $buildInputs = wf_HiddenInput('streetsel', $streetId);
  2464. $buildInputs .= wf_TextInput('debtcash', __('The threshold at which the money considered user debtor'), '0', true, 4);
  2465. $buildInputs .= wf_Submit(__('Print'));
  2466. die($buildInputs);
  2467. } else {
  2468. die('');
  2469. }
  2470. }
  2471. if (!wf_CheckPost(array('streetsel'))) {
  2472. $streetData = array();
  2473. if (!empty($this->streets)) {
  2474. foreach ($this->streets as $streetId => $eachStreetName) {
  2475. $streetId = base64_encode($eachStreetName);
  2476. $streetData[self::URL_REPORTS_MGMT . 'reportDebtStreets' . '&aj_rdabuildsel=' . $streetId] = $eachStreetName;
  2477. }
  2478. }
  2479. $inputs = wf_AjaxLoader();
  2480. $inputs .= wf_AjaxSelectorAC('aj_buildcontainer', $streetData, __('Street'), '', false);
  2481. $inputs .= wf_AjaxContainer('aj_buildcontainer');
  2482. $form = wf_Form('', 'POST', $inputs, 'glamour');
  2483. show_window(__('Current debtors for delivery by streets'), $form);
  2484. } else {
  2485. $searchStreet = mysql_real_escape_string($_POST['streetsel']);
  2486. $debtCash = (wf_CheckPost(array('debtcash'))) ? ('-' . vf($_POST['debtcash'], 3)) : 0;
  2487. $query = "SELECT * from `ukv_users` WHERE `cash`<'" . $debtCash . "' AND `street`='" . $searchStreet . "' AND `active`='1' ORDER BY `build`";
  2488. $allDebtors = simple_queryall($query);
  2489. $rawTemplate = file_get_contents(CONFIG_PATH . "catv_debtors.tpl");
  2490. $printableTemplate = '';
  2491. if (!empty($allDebtors)) {
  2492. foreach ($allDebtors as $io => $each) {
  2493. $rowtemplate = $rawTemplate;
  2494. $rowtemplate = str_ireplace('{REALNAME}', $each['realname'], $rowtemplate);
  2495. $rowtemplate = str_ireplace('{STREET}', $each['street'], $rowtemplate);
  2496. $rowtemplate = str_ireplace('{BUILD}', $each['build'], $rowtemplate);
  2497. $rowtemplate = str_ireplace('{APT}', $each['apt'], $rowtemplate);
  2498. $rowtemplate = str_ireplace('{DEBT}', $each['cash'], $rowtemplate);
  2499. $rowtemplate = str_ireplace('{CURDATE}', curdate(), $rowtemplate);
  2500. $rowtemplate = str_ireplace('{PAYDAY}', (date("Y-m-") . '01'), $rowtemplate);
  2501. $printableTemplate .= $rowtemplate;
  2502. }
  2503. $printableTemplate = wf_TableBody($printableTemplate, '100%', 0, 'sortable');
  2504. $printableTemplate = $this->reportPrintable(__('Current debtors for delivery by streets'), $printableTemplate);
  2505. } else {
  2506. show_window('', $this->messages->getStyledMessage(__('Nothing found'), 'info'));
  2507. }
  2508. }
  2509. }
  2510. /**
  2511. * Returns UKV user id by contract
  2512. *
  2513. * @param string $contract
  2514. *
  2515. * @return int
  2516. */
  2517. protected function userGetByContract($contract) {
  2518. $result = '';
  2519. if (!empty($this->users)) {
  2520. foreach ($this->users as $io => $each) {
  2521. if ($each['contract'] == $contract) {
  2522. $result = $each['id'];
  2523. break;
  2524. }
  2525. }
  2526. }
  2527. return ($result);
  2528. }
  2529. /**
  2530. * Returns array of available debtors
  2531. *
  2532. * @return array
  2533. */
  2534. public function getDebtors() {
  2535. $result = array();
  2536. $debtorsArr = array();
  2537. $counter = 0;
  2538. $summDebt = 0;
  2539. if ($this->altCfg['COMPLEX_ENABLED']) {
  2540. $complexFlag = true;
  2541. $inetAddress = zb_AddressGetFulladdresslistCached();
  2542. $inetRealnames = zb_UserGetAllRealnames();
  2543. $complexCfIds = $this->altCfg['COMPLEX_CFIDS'];
  2544. $complexCfIds = explode(',', $complexCfIds);
  2545. $complexContractCf = $complexCfIds[0];
  2546. $complexActiveCf = $complexCfIds[1];
  2547. $complexMasksTmp = $this->altCfg['COMPLEX_MASKS'];
  2548. $complexMasksTmp = explode(',', $complexMasksTmp);
  2549. $complexContracts = array();
  2550. $complexActive = array();
  2551. $inetCableseals = array();
  2552. if (!empty($complexMasksTmp)) {
  2553. foreach ($complexMasksTmp as $io => $each) {
  2554. $complexMasks[$each] = $each;
  2555. }
  2556. }
  2557. $allComplexUsers = array(); //login=>userdata
  2558. if (!empty($complexMasks)) {
  2559. $allUsersRaw = zb_UserGetAllStargazerDataAssoc();
  2560. if (!empty($allUsersRaw)) {
  2561. foreach ($allUsersRaw as $userLogin => $eachUser) {
  2562. foreach ($complexMasks as $ia => $eachComplexMask) {
  2563. if (ispos($eachUser['Tariff'], $eachComplexMask)) {
  2564. $allComplexUsers[$userLogin] = $eachUser;
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. //getting complex active and contract fields
  2571. $query_complex = "SELECT * from `cfitems`";
  2572. $cfRaw = simple_queryall($query_complex);
  2573. if (!empty($cfRaw)) {
  2574. foreach ($cfRaw as $io => $eachCf) {
  2575. if ($eachCf['typeid'] == $complexContractCf) {
  2576. $complexContracts[$eachCf['login']] = $eachCf['content'];
  2577. }
  2578. if ($eachCf['typeid'] == $complexActiveCf) {
  2579. $complexActive[$eachCf['login']] = $eachCf['content'];
  2580. }
  2581. }
  2582. }
  2583. } else {
  2584. $complexFlag = false;
  2585. }
  2586. if (!empty($this->users)) {
  2587. foreach ($this->users as $ix => $eachUser) {
  2588. $userTariff = $eachUser['tariffid'];
  2589. $tariffPrice = (isset($this->tariffs[$userTariff]['price'])) ? $this->tariffs[$userTariff]['price'] : 0;
  2590. $debtMaxLimit = '-' . ($tariffPrice * $this->debtLimit);
  2591. if (($eachUser['cash'] <= $debtMaxLimit) and ($eachUser['active'] == 1) and ($tariffPrice != 0)) {
  2592. $debtorsArr[$eachUser['street']][$eachUser['id']] = $eachUser;
  2593. $debtorsArr[$eachUser['street']][$eachUser['id']]['usertype'] = 'ukv';
  2594. $counter++;
  2595. }
  2596. }
  2597. }
  2598. //complex processing
  2599. if ($complexFlag) {
  2600. $userStreets = zb_AddressGetStreetUsers();
  2601. if (!empty($allComplexUsers)) {
  2602. foreach ($allComplexUsers as $io => $eachComplexUser) {
  2603. if (($eachComplexUser['Cash'] < -$eachComplexUser['Credit']) and (@$complexActive[$eachComplexUser['login']])) {
  2604. if (isset($complexContracts[$eachComplexUser['login']])) {
  2605. $ukvUserId = $this->userGetByContract($complexContracts[$eachComplexUser['login']]);
  2606. if (isset($this->users[$ukvUserId])) {
  2607. $userStreet = (isset($userStreets[$eachComplexUser['login']])) ? $userStreets[$eachComplexUser['login']] : __('Unknown');
  2608. $ukvUserData = $this->users[$ukvUserId];
  2609. $debtorsArr[$userStreet][$ukvUserId] = $ukvUserData;
  2610. $debtorsArr[$userStreet][$ukvUserId]['usertype'] = 'inet';
  2611. $debtorsArr[$userStreet][$ukvUserId]['cash'] = $eachComplexUser['Cash'];
  2612. }
  2613. }
  2614. }
  2615. }
  2616. }
  2617. }
  2618. if (!empty($debtorsArr)) {
  2619. foreach ($debtorsArr as $streetName => $eachDebtorStreet) {
  2620. if (!empty($eachDebtorStreet)) {
  2621. foreach ($eachDebtorStreet as $ia => $eachDebtor) {
  2622. $result[$eachDebtor['id']] = $eachDebtor['id'];
  2623. }
  2624. }
  2625. }
  2626. }
  2627. return ($result);
  2628. }
  2629. /**
  2630. * renders debtors report
  2631. *
  2632. * @return void
  2633. */
  2634. public function reportDebtors() {
  2635. $debtorsArr = array();
  2636. $result = '';
  2637. $counter = 0;
  2638. $summDebt = 0;
  2639. if ($this->altCfg['COMPLEX_ENABLED']) {
  2640. $complexFlag = true;
  2641. $inetAddress = zb_AddressGetFulladdresslistCached();
  2642. $inetRealnames = zb_UserGetAllRealnames();
  2643. $complexCfIds = $this->altCfg['COMPLEX_CFIDS'];
  2644. $complexCfIds = explode(',', $complexCfIds);
  2645. $complexContractCf = $complexCfIds[0];
  2646. $complexActiveCf = $complexCfIds[1];
  2647. $complexMasksTmp = $this->altCfg['COMPLEX_MASKS'];
  2648. $complexMasksTmp = explode(',', $complexMasksTmp);
  2649. $complexContracts = array();
  2650. $complexActive = array();
  2651. $inetCableseals = array();
  2652. if (!empty($complexMasksTmp)) {
  2653. foreach ($complexMasksTmp as $io => $each) {
  2654. $complexMasks[$each] = $each;
  2655. }
  2656. }
  2657. $allComplexUsers = array(); //login=>userdata
  2658. if (!empty($complexMasks)) {
  2659. $allUsersRaw = zb_UserGetAllStargazerDataAssoc();
  2660. if (!empty($allUsersRaw)) {
  2661. foreach ($allUsersRaw as $userLogin => $eachUser) {
  2662. foreach ($complexMasks as $ia => $eachComplexMask) {
  2663. if (ispos($eachUser['Tariff'], $eachComplexMask)) {
  2664. $allComplexUsers[$userLogin] = $eachUser;
  2665. }
  2666. }
  2667. }
  2668. }
  2669. }
  2670. //getting complex active and contract fields
  2671. $query_complex = "SELECT * from `cfitems`";
  2672. $cfRaw = simple_queryall($query_complex);
  2673. if (!empty($cfRaw)) {
  2674. foreach ($cfRaw as $io => $eachCf) {
  2675. if ($eachCf['typeid'] == $complexContractCf) {
  2676. $complexContracts[$eachCf['login']] = $eachCf['content'];
  2677. }
  2678. if ($eachCf['typeid'] == $complexActiveCf) {
  2679. $complexActive[$eachCf['login']] = $eachCf['content'];
  2680. }
  2681. }
  2682. }
  2683. } else {
  2684. $complexFlag = false;
  2685. }
  2686. if (!empty($this->users)) {
  2687. foreach ($this->users as $ix => $eachUser) {
  2688. $userTariff = $eachUser['tariffid'];
  2689. $tariffPrice = (isset($this->tariffs[$userTariff]['price'])) ? $this->tariffs[$userTariff]['price'] : 0;
  2690. $debtMaxLimit = '-' . ($tariffPrice * $this->debtLimit);
  2691. if (($eachUser['cash'] <= $debtMaxLimit) and ($eachUser['active'] == 1) and ($tariffPrice != 0)) {
  2692. $debtorsArr[$eachUser['street']][$eachUser['id']] = $eachUser;
  2693. $debtorsArr[$eachUser['street']][$eachUser['id']]['usertype'] = 'ukv';
  2694. $debtorsArr[$eachUser['street']][$eachUser['id']]['dsc'] = '';
  2695. $counter++;
  2696. $summDebt = $summDebt + $eachUser['cash'];
  2697. }
  2698. }
  2699. }
  2700. //complex processing
  2701. if ($complexFlag) {
  2702. $userStreets = zb_AddressGetStreetUsers();
  2703. if (!empty($allComplexUsers)) {
  2704. foreach ($allComplexUsers as $io => $eachComplexUser) {
  2705. if (
  2706. (($eachComplexUser['Cash'] < -$eachComplexUser['Credit']) and (@$complexActive[$eachComplexUser['login']]))
  2707. or (($eachComplexUser['Passive'] == 1) and (@$complexActive[$eachComplexUser['login']]))
  2708. ) {
  2709. if (isset($complexContracts[$eachComplexUser['login']])) {
  2710. $ukvUserId = $this->userGetByContract($complexContracts[$eachComplexUser['login']]);
  2711. if (isset($this->users[$ukvUserId])) {
  2712. $userStreet = (isset($userStreets[$eachComplexUser['login']])) ? $userStreets[$eachComplexUser['login']] : __('Unknown');
  2713. $ukvUserData = $this->users[$ukvUserId];
  2714. $debtorsArr[$userStreet][$ukvUserId] = $ukvUserData;
  2715. $debtorsArr[$userStreet][$ukvUserId]['usertype'] = 'inet';
  2716. $debtorsArr[$userStreet][$ukvUserId]['cash'] = $eachComplexUser['Cash'];
  2717. $debtorsArr[$userStreet][$ukvUserId]['active'] = @$complexActive[$eachComplexUser['login']];
  2718. $debtorsArr[$userStreet][$ukvUserId]['dsc'] = ($eachComplexUser['Passive']) ? ' ' . wf_img('skins/icon_passive.gif') : '';
  2719. $summDebt = $summDebt + $eachComplexUser['Cash'];
  2720. $counter++;
  2721. }
  2722. } else {
  2723. $result .= $this->messages->getStyledMessage(__('Missing registered UKV user with complex tariff') . ': ' . $eachComplexUser['login'], 'error');
  2724. }
  2725. }
  2726. }
  2727. }
  2728. }
  2729. //append report counter
  2730. $result .= wf_tag('h4', false, 'row3') . __('Total') . ': ' . $counter . ' / ' . __('Debt') . ': ' . $summDebt . wf_tag('h4', true);
  2731. if (!empty($debtorsArr)) {
  2732. foreach ($debtorsArr as $streetName => $eachDebtorStreet) {
  2733. if (!empty($eachDebtorStreet)) {
  2734. $result .= wf_tag('h3') . $streetName . wf_tag('h3', true);
  2735. $cells = wf_TableCell(__('Contract'), '10%');
  2736. $cells .= wf_TableCell(__('Full address'), '31%');
  2737. $cells .= wf_TableCell(__('Real Name'), '30%');
  2738. $cells .= wf_TableCell(__('Tariff'), '15%');
  2739. $cells .= wf_TableCell(__('Cash'), '7%');
  2740. $cells .= wf_TableCell(__('Seal'));
  2741. $cells .= wf_TableCell(__('Status'), '7%');
  2742. $rows = wf_TableRow($cells, 'row1');
  2743. foreach ($eachDebtorStreet as $ia => $eachDebtor) {
  2744. $debtorAddress = $this->userGetFullAddress($eachDebtor['id']);
  2745. $debtorLink = wf_Link(self::URL_USERS_PROFILE . $eachDebtor['id'], web_profile_icon() . ' ', false);
  2746. $userCash = $eachDebtor['cash'];
  2747. $cableSeal = $eachDebtor['cableseal'];
  2748. $userTariff = $this->tariffs[$eachDebtor['tariffid']]['tariffname'];
  2749. $activeLed = web_bool_led($eachDebtor['active'], true);
  2750. $userRealname = $eachDebtor['realname'];
  2751. $userContract = $eachDebtor['contract'];
  2752. $cells = wf_TableCell($userContract);
  2753. $cells .= wf_TableCell($debtorLink . $debtorAddress);
  2754. $cells .= wf_TableCell($userRealname);
  2755. $cells .= wf_TableCell($userTariff);
  2756. $cells .= wf_TableCell($userCash);
  2757. $cells .= wf_TableCell($cableSeal);
  2758. $cells .= wf_TableCell($activeLed . $eachDebtor['dsc']);
  2759. $rows .= wf_TableRow($cells, 'row3');
  2760. }
  2761. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  2762. }
  2763. }
  2764. }
  2765. $printableControl = wf_Link(self::URL_REPORTS_MGMT . 'reportDebtors&printable=true', wf_img('skins/icon_print.png', __('Print')));
  2766. if (wf_CheckGet(array('printable'))) {
  2767. $this->reportPrintable(__('Debtors'), $result);
  2768. } else {
  2769. show_window(__('Debtors') . ' ' . $printableControl, $result);
  2770. }
  2771. }
  2772. /**
  2773. * renders anti-debtors report
  2774. *
  2775. * @return void
  2776. */
  2777. public function reportAntiDebtors() {
  2778. $debtorsArr = array();
  2779. $result = '';
  2780. $counter = 0;
  2781. if ($this->altCfg['COMPLEX_ENABLED']) {
  2782. $complexFlag = true;
  2783. $inetAddress = zb_AddressGetFulladdresslistCached();
  2784. $inetRealnames = zb_UserGetAllRealnames();
  2785. $complexCfIds = $this->altCfg['COMPLEX_CFIDS'];
  2786. $complexCfIds = explode(',', $complexCfIds);
  2787. $complexContractCf = $complexCfIds[0];
  2788. $complexActiveCf = $complexCfIds[1];
  2789. $complexMasksTmp = $this->altCfg['COMPLEX_MASKS'];
  2790. $complexMasksTmp = explode(',', $complexMasksTmp);
  2791. $complexContracts = array();
  2792. $complexActive = array();
  2793. $inetCableseals = array();
  2794. if (!empty($complexMasksTmp)) {
  2795. foreach ($complexMasksTmp as $io => $each) {
  2796. $complexMasks[$each] = $each;
  2797. }
  2798. }
  2799. $allComplexUsers = array(); //login=>userdata
  2800. if (!empty($complexMasks)) {
  2801. $allUsersRaw = zb_UserGetAllStargazerDataAssoc();
  2802. if (!empty($allUsersRaw)) {
  2803. foreach ($allUsersRaw as $userLogin => $eachUser) {
  2804. foreach ($complexMasks as $ia => $eachComplexMask) {
  2805. if (ispos($eachUser['Tariff'], $eachComplexMask)) {
  2806. $allComplexUsers[$userLogin] = $eachUser;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. //getting complex active and contract fields
  2813. $query_complex = "SELECT * from `cfitems`";
  2814. $cfRaw = simple_queryall($query_complex);
  2815. if (!empty($cfRaw)) {
  2816. foreach ($cfRaw as $io => $eachCf) {
  2817. if ($eachCf['typeid'] == $complexContractCf) {
  2818. $complexContracts[$eachCf['login']] = $eachCf['content'];
  2819. }
  2820. if ($eachCf['typeid'] == $complexActiveCf) {
  2821. $complexActive[$eachCf['login']] = $eachCf['content'];
  2822. }
  2823. }
  2824. }
  2825. } else {
  2826. $complexFlag = false;
  2827. }
  2828. if (!empty($this->users)) {
  2829. foreach ($this->users as $ix => $eachUser) {
  2830. $userTariff = $eachUser['tariffid'];
  2831. $tariffPrice = (isset($this->tariffs[$userTariff]['price'])) ? $this->tariffs[$userTariff]['price'] : 0;
  2832. if (($eachUser['cash'] >= 0) and ($eachUser['active'] == 0) and ($tariffPrice != 0)) {
  2833. $debtorsArr[$eachUser['street']][$eachUser['id']] = $eachUser;
  2834. $counter++;
  2835. }
  2836. }
  2837. }
  2838. //complex processing
  2839. if ($complexFlag) {
  2840. $userStreets = zb_AddressGetStreetUsers();
  2841. if (!empty($allComplexUsers)) {
  2842. foreach ($allComplexUsers as $io => $eachComplexUser) {
  2843. if (($eachComplexUser['Cash'] >= -$eachComplexUser['Credit']) and (!@$complexActive[$eachComplexUser['login']])) {
  2844. if (isset($complexContracts[$eachComplexUser['login']])) {
  2845. $ukvUserId = $this->userGetByContract($complexContracts[$eachComplexUser['login']]);
  2846. if (isset($this->users[$ukvUserId])) {
  2847. if (!@$eachComplexUser['Passive']) { //user is not frozen
  2848. $userStreet = (isset($userStreets[$eachComplexUser['login']])) ? $userStreets[$eachComplexUser['login']] : __('Unknown');
  2849. $ukvUserData = $this->users[$ukvUserId];
  2850. $debtorsArr[$userStreet][$ukvUserId] = $ukvUserData;
  2851. $debtorsArr[$userStreet][$ukvUserId]['usertype'] = 'inet';
  2852. $debtorsArr[$userStreet][$ukvUserId]['cash'] = $eachComplexUser['Cash'];
  2853. $debtorsArr[$userStreet][$ukvUserId]['active'] = @$complexActive[$eachComplexUser['login']];
  2854. $counter++;
  2855. }
  2856. }
  2857. } else {
  2858. $result .= $this->messages->getStyledMessage(__('Missing registered UKV user with complex tariff') . ': ' . $eachComplexUser['login'], 'error');
  2859. }
  2860. }
  2861. }
  2862. }
  2863. }
  2864. //append report counter
  2865. $result .= wf_tag('h4', false, 'row3') . __('Total') . ': ' . $counter . wf_tag('h4', true);
  2866. if (!empty($debtorsArr)) {
  2867. foreach ($debtorsArr as $streetName => $eachDebtorStreet) {
  2868. if (!empty($eachDebtorStreet)) {
  2869. $result .= wf_tag('h3') . $streetName . wf_tag('h3', true);
  2870. $cells = wf_TableCell(__('Contract'), '10%');
  2871. $cells .= wf_TableCell(__('Full address'), '31%');
  2872. $cells .= wf_TableCell(__('Real Name'), '30%');
  2873. $cells .= wf_TableCell(__('Tariff'), '15%');
  2874. $cells .= wf_TableCell(__('Cash'), '7%');
  2875. $cells .= wf_TableCell(__('Seal'));
  2876. $cells .= wf_TableCell(__('Status'), '7%');
  2877. $rows = wf_TableRow($cells, 'row1');
  2878. foreach ($eachDebtorStreet as $ia => $eachDebtor) {
  2879. $cells = wf_TableCell($eachDebtor['contract']);
  2880. $debtorAddress = $this->userGetFullAddress($eachDebtor['id']);
  2881. $debtorLink = wf_Link(self::URL_USERS_PROFILE . $eachDebtor['id'], web_profile_icon() . ' ', false);
  2882. $cells .= wf_TableCell($debtorLink . $debtorAddress);
  2883. $cells .= wf_TableCell($eachDebtor['realname']);
  2884. $cells .= wf_TableCell($this->tariffs[$eachDebtor['tariffid']]['tariffname']);
  2885. $cells .= wf_TableCell($eachDebtor['cash']);
  2886. $cells .= wf_TableCell($eachDebtor['cableseal']);
  2887. $cells .= wf_TableCell(web_bool_led($eachDebtor['active'], true));
  2888. $rows .= wf_TableRow($cells, 'row3');
  2889. }
  2890. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  2891. }
  2892. }
  2893. }
  2894. $printableControl = wf_Link(self::URL_REPORTS_MGMT . 'reportAntiDebtors&printable=true', wf_img('skins/icon_print.png', __('Print')));
  2895. if (wf_CheckGet(array('printable'))) {
  2896. $this->reportPrintable(__('AntiDebtors'), $result);
  2897. } else {
  2898. show_window(__('AntiDebtors') . ' ' . $printableControl, $result);
  2899. }
  2900. }
  2901. /**
  2902. * renders tariffs popularity report
  2903. *
  2904. * @return void
  2905. */
  2906. public function reportTariffs() {
  2907. $tariffArr = array();
  2908. $tariffUsers = array();
  2909. $tariffCounter = array();
  2910. $tariffMoves = array();
  2911. $userTotalCount = sizeof($this->users);
  2912. $result = '';
  2913. if (!empty($this->tariffs)) {
  2914. foreach ($this->tariffs as $io => $each) {
  2915. $tariffArr[$each['id']] = $each['tariffname'];
  2916. $tariffCounter[$each['id']]['all'] = 0;
  2917. $tariffCounter[$each['id']]['alive'] = 0;
  2918. }
  2919. }
  2920. if ((!empty($tariffArr)) and (!empty($this->users))) {
  2921. foreach ($this->users as $io => $eachUser) {
  2922. if (!empty($eachUser['tariffid'])) {
  2923. $tariffUsers[$eachUser['tariffid']][] = $eachUser;
  2924. $tariffCounter[$eachUser['tariffid']]['all'] = $tariffCounter[$eachUser['tariffid']]['all'] + 1;
  2925. if ($eachUser['active']) {
  2926. $tariffCounter[$eachUser['tariffid']]['alive'] = $tariffCounter[$eachUser['tariffid']]['alive'] + 1;
  2927. }
  2928. //next month movements
  2929. if ($eachUser['tariffnmid']) {
  2930. $tariffMoves[$eachUser['id']]['from'] = $eachUser['tariffid'];
  2931. $tariffMoves[$eachUser['id']]['to'] = $eachUser['tariffnmid'];
  2932. }
  2933. }
  2934. }
  2935. }
  2936. //tariff summary grid
  2937. $cells = wf_TableCell(__('Tariff'));
  2938. $cells .= wf_TableCell(__('Total'));
  2939. $cells .= wf_TableCell(__('Visual'));
  2940. $cells .= wf_TableCell(__('Active'));
  2941. $rows = wf_TableRow($cells, 'row1');
  2942. foreach ($tariffArr as $tariffId => $tariffName) {
  2943. $tariffLink = wf_Link(self::URL_REPORTS_MGMT . 'reportTariffs&showtariffusers=' . $tariffId, $tariffName);
  2944. $cells = wf_TableCell($tariffLink);
  2945. $cells .= wf_TableCell($tariffCounter[$tariffId]['all']);
  2946. $cells .= wf_TableCell(web_bar($tariffCounter[$tariffId]['all'], $userTotalCount));
  2947. $cells .= wf_TableCell(web_barTariffs($tariffCounter[$tariffId]['alive'], ($tariffCounter[$tariffId]['all'] - $tariffCounter[$tariffId]['alive'])));
  2948. $rows .= wf_TableRow($cells, 'row5');
  2949. }
  2950. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  2951. $result .= wf_tag('b') . __('Total') . ': ' . $userTotalCount . wf_tag('b', true);
  2952. //tariff move summary
  2953. if (!empty($tariffMoves)) {
  2954. if (!wf_CheckGet(array('showtariffusers'))) {
  2955. $result .= wf_tag('br');
  2956. $result .= wf_tag('h3') . __('Planned tariff changes') . wf_tag('h3', true);
  2957. $cells = wf_TableCell(__('User'));
  2958. $cells .= wf_TableCell(__('Real Name'));
  2959. $cells .= wf_TableCell(__('Tariff'));
  2960. $cells .= wf_TableCell(__('Next month'));
  2961. $rows = wf_TableRow($cells, 'row1');
  2962. foreach ($tariffMoves as $moveUserId => $moveData) {
  2963. $cells = wf_TableCell(wf_Link(self::URL_USERS_PROFILE . $moveUserId, web_profile_icon() . ' ' . $this->userGetFullAddress($moveUserId)));
  2964. $cells .= wf_TableCell($this->userGetRealName($moveUserId));
  2965. $cells .= wf_TableCell($this->tariffGetName($moveData['from']));
  2966. $cells .= wf_TableCell($this->tariffGetName($moveData['to']));
  2967. $rows .= wf_TableRow($cells, 'row3');
  2968. }
  2969. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  2970. $result .= wf_tag('b') . __('Total') . ': ' . sizeof($tariffMoves) . wf_tag('b', true);
  2971. }
  2972. }
  2973. //show per tariff users
  2974. if (wf_CheckGet(array('showtariffusers'))) {
  2975. $tariffSearch = vf($_GET['showtariffusers'], 3);
  2976. if (isset($tariffUsers[$tariffSearch])) {
  2977. if (!empty($tariffUsers[$tariffSearch])) {
  2978. $result .= wf_delimiter();
  2979. $result .= wf_tag('h2') . __('Tariff') . ': ' . $tariffArr[$tariffSearch] . wf_tag('h2', true);
  2980. $cells = wf_TableCell(__('Contract'), '10%');
  2981. $cells .= wf_TableCell(__('Full address'), '31%');
  2982. $cells .= wf_TableCell(__('Real Name'), '25%');
  2983. $cells .= wf_TableCell(__('Tariff'), '15%');
  2984. $cells .= wf_TableCell(__('Cash'), '7%');
  2985. $cells .= wf_TableCell(__('Seal'), '5%');
  2986. $cells .= wf_TableCell(__('Status'), '7%');
  2987. $rows = wf_TableRow($cells, 'row1');
  2988. foreach ($tariffUsers[$_GET['showtariffusers']] as $io => $eachUser) {
  2989. $cells = wf_TableCell($eachUser['contract']);
  2990. $fullAddress = $this->userGetFullAddress($eachUser['id']);
  2991. $profileLink = wf_Link(self::URL_USERS_PROFILE . $eachUser['id'], web_profile_icon() . ' ', false, '');
  2992. $cells .= wf_TableCell($profileLink . $fullAddress);
  2993. $cells .= wf_TableCell($eachUser['realname']);
  2994. $cells .= wf_TableCell($this->tariffs[$eachUser['tariffid']]['tariffname']);
  2995. $cells .= wf_TableCell($eachUser['cash']);
  2996. $cells .= wf_tablecell($eachUser['cableseal']);
  2997. $cells .= wf_TableCell(web_bool_led($eachUser['active'], true));
  2998. $rows .= wf_TableRow($cells, 'row3');
  2999. }
  3000. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  3001. }
  3002. }
  3003. $printableControl = wf_Link(self::URL_REPORTS_MGMT . 'reportTariffs&showtariffusers=' . $tariffSearch . '&printable=true', wf_img('skins/icon_print.png', __('Print')));
  3004. } else {
  3005. $printableControl = wf_Link(self::URL_REPORTS_MGMT . 'reportTariffs&printable=true', wf_img('skins/icon_print.png', __('Print')));
  3006. }
  3007. if (!wf_CheckGet(array('printable'))) {
  3008. show_window(__('Tariffs report') . ' ' . $printableControl, $result);
  3009. } else {
  3010. $this->reportPrintable(__('Tariffs report'), $result);
  3011. }
  3012. }
  3013. /**
  3014. * returns payments year summ by selected year
  3015. *
  3016. * @param string $year year to show
  3017. *
  3018. * @return string
  3019. */
  3020. protected function paymentsGetYearSumm($year) {
  3021. $year = vf($year);
  3022. $query = "SELECT SUM(`summ`) from `ukv_payments` WHERE `date` LIKE '" . $year . "-%' AND `summ` > 0 AND `visible`='1'";
  3023. $result = simple_query($query);
  3024. return ($result['SUM(`summ`)']);
  3025. }
  3026. /**
  3027. * returns month payments summ by some year and month
  3028. *
  3029. * @param string $year year to select
  3030. * @param string $month month to select
  3031. *
  3032. * @return string
  3033. */
  3034. protected function paymentsGetMonthSumm($year, $month) {
  3035. $year = vf($year);
  3036. $query = "SELECT SUM(`summ`) from `ukv_payments` WHERE `date` LIKE '" . $year . "-" . $month . "%' AND `summ` > 0 AND `visible`='1'";
  3037. $result = simple_query($query);
  3038. return ($result['SUM(`summ`)']);
  3039. }
  3040. /**
  3041. * returns month payments count by some year and month
  3042. *
  3043. * @param $year year to select
  3044. * @param $month month to select
  3045. *
  3046. * @return string
  3047. */
  3048. protected function paymentsGetMonthCount($year, $month) {
  3049. $year = vf($year);
  3050. $query = "SELECT COUNT(`id`) from `ukv_payments` WHERE `date` LIKE '" . $year . "-" . $month . "%' AND `summ` > 0 AND `visible`='1'";
  3051. $result = simple_query($query);
  3052. return ($result['COUNT(`id`)']);
  3053. }
  3054. /**
  3055. * shows payments graph for some year
  3056. *
  3057. * @param string $year year to show
  3058. *
  3059. * @return void
  3060. */
  3061. protected function paymentsShowGraph($year) {
  3062. $months = months_array();
  3063. $year_summ = $this->paymentsGetYearSumm($year);
  3064. $curtime = time();
  3065. $yearPayData = array();
  3066. $cacheTime = 3600; //sec intervall to cache
  3067. $cache = new UbillingCache();
  3068. $cells = wf_TableCell('');
  3069. $cells .= wf_TableCell(__('Month'));
  3070. $cells .= wf_TableCell(__('Payments count'));
  3071. $cells .= wf_TableCell(__('ARPU'));
  3072. $cells .= wf_TableCell(__('Cash'));
  3073. $cells .= wf_TableCell(__('Visual'), '50%');
  3074. $rows = wf_TableRow($cells, 'row1');
  3075. //caching subroutine
  3076. $renewTime = $cache->get('UKVYPD_LAST', $cacheTime);
  3077. if (empty($renewTime)) {
  3078. //first usage
  3079. $renewTime = $curtime;
  3080. $cache->set('UKVYPD_LAST', $renewTime, $cacheTime);
  3081. $updateCache = true;
  3082. } else {
  3083. //cache time already set
  3084. $timeShift = $curtime - $renewTime;
  3085. if ($timeShift > $cacheTime) {
  3086. //cache update needed
  3087. $updateCache = true;
  3088. } else {
  3089. //load data from cache or init new cache
  3090. $yearPayData_raw = $cache->get('UKVYPD_CACHE', $cacheTime);
  3091. if (empty($yearPayData_raw)) {
  3092. //first usage
  3093. $emptyCache = array();
  3094. $emptyCache = serialize($emptyCache);
  3095. $emptyCache = base64_encode($emptyCache);
  3096. $cache->set('UKVYPD_CACHE', $emptyCache, $cacheTime);
  3097. $updateCache = true;
  3098. } else {
  3099. // data loaded from cache
  3100. $yearPayData = base64_decode($yearPayData_raw);
  3101. $yearPayData = unserialize($yearPayData);
  3102. $updateCache = false;
  3103. //check is current year already cached?
  3104. if (!isset($yearPayData[$year]['graphs'])) {
  3105. $updateCache = true;
  3106. }
  3107. //check is manual cache refresh is needed?
  3108. if (wf_CheckGet(array('forcecache'))) {
  3109. $updateCache = true;
  3110. rcms_redirect(self::URL_REPORTS_MGMT . 'reportFinance');
  3111. }
  3112. }
  3113. }
  3114. }
  3115. if ($updateCache) {
  3116. foreach ($months as $eachmonth => $monthname) {
  3117. $month_summ = $this->paymentsGetMonthSumm($year, $eachmonth);
  3118. $paycount = $this->paymentsGetMonthCount($year, $eachmonth);
  3119. $monthArpu = (empty($paycount)) ? 0 : @round($month_summ / $paycount, 2);
  3120. if (is_nan($monthArpu)) {
  3121. $monthArpu = 0;
  3122. }
  3123. $cells = wf_TableCell($eachmonth);
  3124. $cells .= wf_TableCell(wf_Link(self::URL_REPORTS_MGMT . 'reportFinance&month=' . $year . '-' . $eachmonth, rcms_date_localise($monthname)));
  3125. $cells .= wf_TableCell($paycount);
  3126. $cells .= wf_TableCell($monthArpu);
  3127. $cells .= wf_TableCell(zb_CashBigValueFormat($month_summ), '', '', 'align="right"');
  3128. $cells .= wf_TableCell(web_bar($month_summ, $year_summ));
  3129. $rows .= wf_TableRow($cells, 'row3');
  3130. }
  3131. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  3132. $yearPayData[$year]['graphs'] = $result;
  3133. //write to cache
  3134. $cache->set('UKVYPD_LAST', $curtime, $cacheTime);
  3135. $newCache = serialize($yearPayData);
  3136. $newCache = base64_encode($newCache);
  3137. $cache->set('UKVYPD_CACHE', $newCache, $cacheTime);
  3138. } else {
  3139. //take data from cache
  3140. if (isset($yearPayData[$year]['graphs'])) {
  3141. $result = $yearPayData[$year]['graphs'];
  3142. $result .= __('Cache state at time') . ': ' . date("Y-m-d H:i:s", ($renewTime)) . ' ';
  3143. $result .= wf_Link(self::URL_REPORTS_MGMT . 'reportFinance&forcecache=true', wf_img('skins/icon_cleanup.png', __('Renew')), false, '');
  3144. } else {
  3145. $result = __('Strange exeption');
  3146. }
  3147. }
  3148. show_window(__('Payments by') . ' ' . $year, $result);
  3149. }
  3150. /**
  3151. * returns UKV payments by some query
  3152. *
  3153. * @param string $query raw SQL query to select data
  3154. *
  3155. * @return string
  3156. */
  3157. protected function paymentsShow($query) {
  3158. if (empty($this->cashtypes)) {
  3159. $this->loadCashtypes();
  3160. }
  3161. $alltypes = $this->cashtypes;
  3162. $allapayments = simple_queryall($query);
  3163. $cashTypesStats = array();
  3164. $total = 0;
  3165. $totalPaycount = 0;
  3166. $cells = wf_TableCell(__('ID'));
  3167. $cells .= wf_TableCell(__('Date'));
  3168. $cells .= wf_TableCell(__('Cash'));
  3169. //optional contract display
  3170. if ($this->altCfg['FINREP_CONTRACT']) {
  3171. $cells .= wf_TableCell(__('Contract'));
  3172. }
  3173. $cells .= wf_TableCell(__('Full address'));
  3174. $cells .= wf_TableCell(__('Real Name'));
  3175. $cells .= wf_TableCell(__('Cash type'));
  3176. $cells .= wf_TableCell(__('Notes'));
  3177. $cells .= wf_TableCell(__('Admin'));
  3178. $rows = wf_TableRow($cells, 'row1');
  3179. if (!empty($allapayments)) {
  3180. foreach ($allapayments as $io => $eachpayment) {
  3181. @$userData = $this->users[$eachpayment['userid']];
  3182. if ($this->altCfg['TRANSLATE_PAYMENTS_NOTES']) {
  3183. $eachpayment['note'] = $this->translatePaymentNote($eachpayment['note']);
  3184. }
  3185. $cells = wf_TableCell($eachpayment['id']);
  3186. $cells .= wf_TableCell($eachpayment['date']);
  3187. $cells .= wf_TableCell($eachpayment['summ']);
  3188. //optional contract display
  3189. if ($this->altCfg['FINREP_CONTRACT']) {
  3190. $cells .= wf_TableCell(@$userData['contract']);
  3191. }
  3192. $userLink = wf_Link(self::URL_USERS_PROFILE . $eachpayment['userid'], web_profile_icon());
  3193. $cells .= wf_TableCell($userLink . ' ' . $this->userGetFullAddress($eachpayment['userid']));
  3194. $cells .= wf_TableCell(@$userData['realname']);
  3195. $cells .= wf_TableCell(@__($alltypes[$eachpayment['cashtypeid']]));
  3196. $cells .= wf_TableCell($eachpayment['note']);
  3197. $cells .= wf_TableCell($eachpayment['admin']);
  3198. $rows .= wf_TableRow($cells, 'row3');
  3199. if ($eachpayment['summ'] > 0) {
  3200. $total = $total + $eachpayment['summ'];
  3201. $totalPaycount++;
  3202. //per cashtype tiny stats
  3203. if (isset($cashTypesStats[$eachpayment['cashtypeid']])) {
  3204. $cashTypesStats[$eachpayment['cashtypeid']]['count']++;
  3205. $cashTypesStats[$eachpayment['cashtypeid']]['summ'] += $eachpayment['summ'];
  3206. } else {
  3207. $cashTypesStats[$eachpayment['cashtypeid']]['count'] = 1;
  3208. $cashTypesStats[$eachpayment['cashtypeid']]['summ'] = $eachpayment['summ'];
  3209. }
  3210. }
  3211. }
  3212. }
  3213. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  3214. $result .= wf_tag('strong') . __('Cash') . ': ' . $total . wf_tag('strong', true) . wf_tag('br');
  3215. $result .= wf_tag('strong') . __('Payments count') . ': ' . $totalPaycount . wf_tag('strong', true);
  3216. //render cashtype stats
  3217. if (!empty($cashTypesStats)) {
  3218. $cells = wf_TableCell(__('Cash type'));
  3219. $cells .= wf_TableCell(__('Count'));
  3220. $cells .= wf_TableCell(__('Cash'));
  3221. $rows = wf_TableRow($cells, 'row1');
  3222. foreach ($cashTypesStats as $cashtypeid => $eachct) {
  3223. $cells = wf_TableCell(@$this->cashtypes[$cashtypeid]);
  3224. $cells .= wf_TableCell($eachct['count']);
  3225. $cells .= wf_TableCell($eachct['summ']);
  3226. $rows .= wf_TableRow($cells, 'row3');
  3227. }
  3228. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  3229. }
  3230. return ($result);
  3231. }
  3232. /**
  3233. * Renders tagcloud report
  3234. *
  3235. * @return void
  3236. */
  3237. public function reportTagcloud() {
  3238. $result = '';
  3239. $reportTmp = array();
  3240. if (!empty($this->allTagtypes)) {
  3241. if (!empty($this->allUserTags)) {
  3242. foreach ($this->allUserTags as $io => $each) {
  3243. if (!isset($reportTmp[$each['tagtypeid']])) {
  3244. $result .= $this->getTagBody($each['tagtypeid'], true);
  3245. $reportTmp[$each['tagtypeid']] = $each['tagtypeid'];
  3246. }
  3247. }
  3248. }
  3249. if (wf_CheckGet(array('tagid'))) {
  3250. $showTagid = vf($_GET['tagid'], 3);
  3251. $result .= wf_delimiter();
  3252. $result .= wf_tag('h2') . __('Tag') . ': ' . @$this->allTagtypes[$showTagid]['tagname'] . wf_tag('h2', true);
  3253. $cells = wf_TableCell(__('Contract'), '10%');
  3254. $cells .= wf_TableCell(__('Full address'), '31%');
  3255. $cells .= wf_TableCell(__('Real Name'), '25%');
  3256. $cells .= wf_TableCell(__('Tariff'), '15%');
  3257. $cells .= wf_TableCell(__('Cash'), '7%');
  3258. $cells .= wf_TableCell(__('Seal'), '5%');
  3259. $cells .= wf_TableCell(__('Status'), '7%');
  3260. $rows = wf_TableRow($cells, 'row1');
  3261. foreach ($this->allUserTags as $io => $eachtag) {
  3262. if ($eachtag['tagtypeid'] == $showTagid) {
  3263. $eachUser = @$this->users[$eachtag['userid']];
  3264. if (!empty($eachUser)) {
  3265. $cells = wf_TableCell($eachUser['contract']);
  3266. $fullAddress = $this->userGetFullAddress($eachUser['id']);
  3267. $profileLink = wf_Link(self::URL_USERS_PROFILE . $eachUser['id'], web_profile_icon() . ' ', false, '');
  3268. $cells .= wf_TableCell($profileLink . $fullAddress);
  3269. $cells .= wf_TableCell($eachUser['realname']);
  3270. $cells .= wf_TableCell($this->tariffs[$eachUser['tariffid']]['tariffname']);
  3271. $cells .= wf_TableCell($eachUser['cash']);
  3272. $cells .= wf_tablecell($eachUser['cableseal']);
  3273. $cells .= wf_TableCell(web_bool_led($eachUser['active'], true));
  3274. $rows .= wf_TableRow($cells, 'row3');
  3275. }
  3276. }
  3277. }
  3278. $result .= wf_TableBody($rows, '100%', '0', 'sortable');
  3279. ////////////////
  3280. }
  3281. show_window(__('Tag cloud'), $result);
  3282. } else {
  3283. show_window(__('Tag cloud'), $this->messages->getStyledMessage(__('Nothing found'), 'warning'));
  3284. }
  3285. }
  3286. /**
  3287. * renders finance report
  3288. *
  3289. * @return void
  3290. */
  3291. public function reportFinance() {
  3292. $show_year = (!wf_CheckPost(array('yearsel'))) ? curyear() : $_POST['yearsel'];
  3293. $dateSelectorPreset = (wf_CheckPost(array('showdatepayments'))) ? $_POST['showdatepayments'] : curdate();
  3294. $dateinputs = wf_DatePickerPreset('showdatepayments', $dateSelectorPreset);
  3295. $dateinputs .= wf_Submit(__('Show'));
  3296. $dateform = wf_Form(self::URL_REPORTS_MGMT . 'reportFinance', 'POST', $dateinputs, 'glamour');
  3297. $yearinputs = wf_YearSelector('yearsel');
  3298. $yearinputs .= wf_Submit(__('Show'));
  3299. $yearform = wf_Form(self::URL_REPORTS_MGMT . 'reportFinance', 'POST', $yearinputs, 'glamour');
  3300. $controlcells = wf_TableCell(wf_tag('h3', false, 'title') . __('Year') . wf_tag('h3', true));
  3301. $controlcells .= wf_TableCell(wf_tag('h3', false, 'title') . __('Payments by date') . wf_tag('h3', true));
  3302. $controlcells .= wf_TableCell(wf_tag('h3', false, 'title') . __('Debt') . wf_tag('h3', true));
  3303. $controlrows = wf_TableRow($controlcells);
  3304. $controlcells = wf_TableCell($yearform);
  3305. $controlcells .= wf_TableCell($dateform);
  3306. //extract total debt summ
  3307. $debt_q = "SELECT SUM(`cash`) as `totaldebt`, COUNT(`id`) as `debtcount` from `ukv_users` WHERE `cash`<0";
  3308. $totalDebt = simple_query($debt_q);
  3309. $debtData = __('Cash') . ': ' . wf_tag('b') . $totalDebt['totaldebt'] . wf_tag('b', true) . wf_tag('br');
  3310. $debtData .= __('Count') . ': ' . wf_tag('b') . $totalDebt['debtcount'] . wf_tag('b', true);
  3311. $controlcells .= wf_TableCell($debtData);
  3312. $controlrows .= wf_TableRow($controlcells);
  3313. $controlgrid = wf_TableBody($controlrows, '100%', 0, '');
  3314. show_window('', $controlgrid);
  3315. //show per month report
  3316. $this->paymentsShowGraph($show_year);
  3317. if (!isset($_GET['month'])) {
  3318. // payments by somedate
  3319. if (isset($_POST['showdatepayments'])) {
  3320. $paydate = mysql_real_escape_string($_POST['showdatepayments']);
  3321. $paydate = (!empty($paydate)) ? $paydate : curdate();
  3322. show_window(__('Payments by date') . ' ' . $paydate, $this->paymentsShow("SELECT * from `ukv_payments` WHERE `date` LIKE '" . $paydate . "%' AND `visible`='1' ORDER by `date` DESC;"));
  3323. } else {
  3324. // today payments
  3325. $today = curdate();
  3326. show_window(__('Today payments'), $this->paymentsShow("SELECT * from `ukv_payments` WHERE `date` LIKE '" . $today . "%' AND `visible`='1' ORDER by `date` DESC;"));
  3327. }
  3328. } else {
  3329. // show monthly payments
  3330. $paymonth = mysql_real_escape_string($_GET['month']);
  3331. show_window(__('Month payments'), $this->paymentsShow("SELECT * from `ukv_payments` WHERE `date` LIKE '" . $paymonth . "%' AND `visible`='1' ORDER by `date` DESC;"));
  3332. }
  3333. }
  3334. /**
  3335. * renders users signup report
  3336. *
  3337. * @return void
  3338. */
  3339. public function reportSignup() {
  3340. $regdates = array();
  3341. $months = months_array();
  3342. $monthCount = array();
  3343. $showYear = (wf_CheckPost(array('showyear'))) ? vf($_POST['showyear'], 3) : curyear();
  3344. $showMonth = (wf_CheckGet(array('month'))) ? mysql_real_escape_string($_GET['month']) : curmonth();
  3345. $yearCount = 0;
  3346. $displayCount = 0;
  3347. $displayTmp = array();
  3348. if (!empty($this->users)) {
  3349. foreach ($this->users as $io => $each) {
  3350. if (!empty($each['regdate'])) {
  3351. $dateTime = explode(' ', $each['regdate']);
  3352. $regdates[$dateTime[0]][] = $each['id'];
  3353. }
  3354. }
  3355. }
  3356. // show year selector
  3357. $yearInputs = wf_YearSelector('showyear', ' ', false);
  3358. $yearInputs .= wf_Submit(__('Show'));
  3359. $yearForm = wf_Form('', 'POST', $yearInputs, 'glamour');
  3360. show_window(__('Year'), $yearForm);
  3361. //extract year signup count data
  3362. foreach ($months as $eachMonth => $monthName) {
  3363. $sigcount = 0;
  3364. if (!empty($regdates)) {
  3365. foreach ($regdates as $eachRegDate => $userIds) {
  3366. $dateMark = $showYear . '-' . $eachMonth;
  3367. if (ispos($eachRegDate, $dateMark)) {
  3368. $sigcount = $sigcount + count($regdates[$eachRegDate]);
  3369. }
  3370. $monthCount[$eachMonth] = $sigcount;
  3371. }
  3372. $yearCount = $yearCount + $sigcount;
  3373. }
  3374. }
  3375. //render per year grid
  3376. $cells = wf_TableCell('');
  3377. $cells .= wf_TableCell(__('Month'));
  3378. $cells .= wf_TableCell(__('Signups'));
  3379. $cells .= wf_TableCell(__('Visual'));
  3380. $rows = wf_TableRow($cells, 'row1');
  3381. foreach ($months as $eachMonth => $monthName) {
  3382. $cells = wf_TableCell($eachMonth);
  3383. $monthLink = wf_Link(self::URL_REPORTS_MGMT . 'reportSignup&month=' . $showYear . '-' . $eachMonth, rcms_date_localise($monthName), false);
  3384. $cells .= wf_TableCell($monthLink);
  3385. $cells .= wf_TableCell($monthCount[$eachMonth]);
  3386. $cells .= wf_TableCell(web_bar($monthCount[$eachMonth], $yearCount));
  3387. $rows .= wf_TableRow($cells, 'row3');
  3388. }
  3389. $result = wf_TableBody($rows, '100%', 0, 'sortable');
  3390. $result .= __('Total') . ': ' . $yearCount;
  3391. show_window(__('User signups by year') . ' ' . $showYear, $result);
  3392. //render per month registrations
  3393. $cells = wf_TableCell(__('ID'));
  3394. $cells .= wf_TableCell(__('Date'));
  3395. $cells .= wf_TableCell(__('Full address'));
  3396. $cells .= wf_TableCell(__('Real Name'));
  3397. $cells .= wf_TableCell(__('Tariff'));
  3398. $rows = wf_TableRow($cells, 'row1');
  3399. if (!empty($regdates)) {
  3400. foreach ($regdates as $eachRegDate => $eachRegUsers) {
  3401. if (ispos($eachRegDate, $showMonth)) {
  3402. foreach ($eachRegUsers as $ix => $eachUserId) {
  3403. $displayTmp[] = $eachUserId;
  3404. }
  3405. }
  3406. }
  3407. }
  3408. if (!empty($displayTmp)) {
  3409. rsort($displayTmp);
  3410. foreach ($displayTmp as $ix => $eachUserId) {
  3411. $cells = wf_TableCell($eachUserId);
  3412. $cells .= wf_TableCell($this->users[$eachUserId]['regdate']);
  3413. $userLink = wf_Link(self::URL_USERS_PROFILE . $eachUserId, web_profile_icon() . ' ', false);
  3414. $cells .= wf_TableCell($userLink . $this->userGetFullAddress($eachUserId));
  3415. $cells .= wf_TableCell($this->users[$eachUserId]['realname']);
  3416. $cells .= wf_TableCell(@$this->tariffs[$this->users[$eachUserId]['tariffid']]['tariffname']);
  3417. $rows .= wf_TableRow($cells, 'row3');
  3418. $displayCount++;
  3419. }
  3420. }
  3421. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  3422. $result .= __('Total') . ': ' . $displayCount;
  3423. if ($showMonth == curmonth()) {
  3424. $monthTitle = __('Current month user signups');
  3425. } else {
  3426. $monthTitle = __('User signups by month') . ' ' . $showMonth;
  3427. }
  3428. show_window($monthTitle, $result);
  3429. }
  3430. /**
  3431. * renders fees report by selected month
  3432. *
  3433. * @return void
  3434. */
  3435. public function reportFees() {
  3436. $allFeesDates_q = "SELECT * from `ukv_fees` ORDER BY `id` DESC;";
  3437. $allFeesDates = simple_queryall($allFeesDates_q);
  3438. $result = '';
  3439. $csvData = '';
  3440. //existing report download
  3441. if (wf_CheckGet(array('downloadfeereport'))) {
  3442. $filenameToDownload = base64_decode($_GET['downloadfeereport']);
  3443. zb_DownloadFile('exports/' . $filenameToDownload, 'docx');
  3444. }
  3445. //render fees list
  3446. $cells = wf_TableCell(__('Month'));
  3447. $rows = wf_TableRow($cells, 'row1');
  3448. if (!empty($allFeesDates)) {
  3449. foreach ($allFeesDates as $ia => $eachFee) {
  3450. $feeLink = wf_Link(self::URL_REPORTS_MGMT . 'reportFees&showfees=' . $eachFee['yearmonth'], $eachFee['yearmonth'], false);
  3451. $cells = wf_TableCell($feeLink);
  3452. $rows .= wf_TableRow($cells, 'row3');
  3453. }
  3454. }
  3455. $result .= wf_TableBody($rows, '30%', '0', 'sortable');
  3456. show_window(__('By date'), $result);
  3457. //render fees by selected month
  3458. if (wf_CheckGet(array('showfees'))) {
  3459. $feesSumm = 0;
  3460. $feesCount = 0;
  3461. $searchFees = mysql_real_escape_string($_GET['showfees']);
  3462. $payments_q = "SELECT * from `ukv_payments` WHERE `date` LIKE '" . $searchFees . "%' AND `note` LIKE 'UKVFEE:%' ORDER BY `id` DESC";
  3463. $allPayments = simple_queryall($payments_q);
  3464. if (!empty($allPayments)) {
  3465. $cells = wf_TableCell(__('ID'));
  3466. $cells .= wf_TableCell(__('Date'));
  3467. $cells .= wf_TableCell(__('Cash'));
  3468. $cells .= wf_TableCell(__('Full address'));
  3469. $cells .= wf_TableCell(__('Real Name'));
  3470. $rowsf = wf_TableRow($cells, 'row1');
  3471. foreach ($allPayments as $io => $eachPayment) {
  3472. if ($eachPayment['summ'] < 0) {
  3473. $userLink = wf_Link(self::URL_USERS_PROFILE . $eachPayment['userid'], web_profile_icon() . ' ', false);
  3474. $userAddress = $this->userGetFullAddress($eachPayment['userid']);
  3475. $userRealName = (empty($this->users[$eachPayment['userid']])) ? $eachPayment['userid'] . ' - ' . __('Unknown user') : $this->users[$eachPayment['userid']]['realname'];
  3476. $cells = wf_TableCell($eachPayment['id']);
  3477. $cells .= wf_TableCell($eachPayment['date']);
  3478. $cells .= wf_TableCell($eachPayment['summ']);
  3479. $cells .= wf_TableCell($userLink . $userAddress);
  3480. $cells .= wf_TableCell($userRealName);
  3481. $rowsf .= wf_TableRow($cells, 'row3');
  3482. $feesCount++;
  3483. $feesSumm = $feesSumm + $eachPayment['summ'];
  3484. $csvData .= $eachPayment['id'] . ';' . $eachPayment['date'] . ';' . $eachPayment['summ'] . ';' . $userAddress . ';' . $userRealName . "\r" . "\n";
  3485. }
  3486. }
  3487. //saving downloadable report
  3488. $csvSaveName = $searchFees . '_ukvfeesreport.csv';
  3489. $csvData = iconv('utf-8', 'windows-1251', $csvData);
  3490. file_put_contents('exports/' . $csvSaveName, $csvData);
  3491. $downloadLink = wf_Link(self::URL_REPORTS_MGMT . 'reportFees&downloadfeereport=' . base64_encode($csvSaveName), wf_img('skins/excel.gif', __('Download')), false);
  3492. $result = wf_tag('strong') . __('Count') . ': ' . $feesCount;
  3493. $result .= wf_tag('br');
  3494. $result .= __('Money') . ': ' . $feesSumm;
  3495. $result .= wf_tag('strong', true);
  3496. $result .= wf_TableBody($rowsf, '100%', '0', 'sortable');
  3497. show_window(__('Money fees') . ' ' . $searchFees . ' ' . $downloadLink, $result);
  3498. }
  3499. }
  3500. }
  3501. /**
  3502. * renders streets report
  3503. *
  3504. * @return void
  3505. */
  3506. public function reportStreets() {
  3507. global $ubillingConfig;
  3508. $withAddress = $ubillingConfig->getAlterParam('UKV_STREET_REP_BUILD_SEL');
  3509. $ukvCities = array();
  3510. $ukvStreets = array();
  3511. $ukvBuilds = array('' => '-');
  3512. //loads cities, streets and builds occupied by UKV users
  3513. $ukvCities_q = "SELECT DISTINCT `city` from `ukv_users` ORDER BY `city` ASC";
  3514. $ukvCitiesRaw = simple_queryall($ukvCities_q);
  3515. if (!empty($ukvCitiesRaw)) {
  3516. foreach ($ukvCitiesRaw as $ieuc => $euc) {
  3517. $ukvCities[$euc['city']] = $euc['city'];
  3518. }
  3519. }
  3520. $ukvStreets_q = "SELECT DISTINCT `street` from `ukv_users` ORDER BY `street` ASC";
  3521. $ukvStreetsRaw = simple_queryall($ukvStreets_q);
  3522. if (!empty($ukvStreetsRaw)) {
  3523. foreach ($ukvStreetsRaw as $ieus => $eus) {
  3524. $ukvStreets[$eus['street']] = $eus['street'];
  3525. }
  3526. }
  3527. if ($withAddress) {
  3528. $ukvBuilds_q = "SELECT `street`.`streetname`, `build`.`buildnum` FROM `street` RIGHT JOIN `build` ON `build`.`streetid` = `street`.`id` ORDER BY `buildnum`;";
  3529. $ukvBuildsRaw = simple_queryall($ukvBuilds_q);
  3530. if (!empty($ukvBuildsRaw)) {
  3531. foreach ($ukvBuildsRaw as $io => $each) {
  3532. $ukvBuilds[trim($each['streetname']) . trim($each['buildnum'])] = trim($each['buildnum']);
  3533. }
  3534. }
  3535. }
  3536. //main codepart
  3537. $citySelected = (wf_CheckPost(array('streetreportcity'))) ? $_POST['streetreportcity'] : '';
  3538. $streetSelected = (wf_CheckPost(array('streetreportstreet'))) ? $_POST['streetreportstreet'] : '';
  3539. $buildSelected = (wf_CheckPost(array('streetreportbuild'))) ? $_POST['streetreportbuild'] : '';
  3540. $inputs = wf_Selector('streetreportcity', $ukvCities, __('City'), $citySelected, false);
  3541. $inputs .= wf_Selector('streetreportstreet', $ukvStreets, __('Street'), $streetSelected, false, '', 'ReportStreetsSel');
  3542. if ($withAddress) {
  3543. $inputs .= wf_Selector('streetreportbuild', $ukvBuilds, __('Build'), $buildSelected, false, '', 'ReportBuildsSel');
  3544. $inputs .= wf_HiddenInput('printthemall', base64_encode(json_encode($ukvBuilds)), 'TmpBuildsAll');
  3545. $inputs .= wf_tag('script', false, '', 'type="text/javascript"');
  3546. $inputs .= '$(document).ready(function() {
  3547. $(\'#ReportStreetsSel\').change(function(evt) {
  3548. var keyword = $(this).val();
  3549. var source = JSON.parse(atob($(\'#TmpBuildsAll\').val()));
  3550. filterBuildsSelect(keyword, source);
  3551. });
  3552. function filterBuildsSelect(search_keyword, search_array) {
  3553. var newselect = $("<select id=\"ReportBuildsSel\" name=\"streetreportbuild\" />");
  3554. $("<option />", {value: \'\', text: \'-\'}).appendTo(newselect);
  3555. if (search_keyword.length > 0 && search_keyword.trim() !== "-") {
  3556. for (var key in search_array) {
  3557. if ( key.toLowerCase() == search_keyword.toLowerCase() + search_array[key] && key.trim() !== "" ) {
  3558. $("<option />", {value: key, text: search_array[key]}).appendTo(newselect);
  3559. }
  3560. }
  3561. }
  3562. $(\'#ReportBuildsSel\').replaceWith(newselect);
  3563. }
  3564. var buildSelected = $(\'#ReportBuildsSel\').val()
  3565. var keyword = $(\'#ReportStreetsSel\').val();
  3566. var source = JSON.parse(atob($(\'#TmpBuildsAll\').val()));
  3567. filterBuildsSelect(keyword, source);
  3568. $(\'#ReportBuildsSel\').val(buildSelected);
  3569. });
  3570. ';
  3571. $inputs .= wf_tag('script', true);
  3572. }
  3573. $inputs .= wf_Submit(__('Show'));
  3574. $form = wf_Form('', 'POST', $inputs, 'glamour');
  3575. show_window(__('Streets report'), $form);
  3576. if ((wf_CheckPost(array('streetreportcity', 'streetreportstreet'))) or (wf_CheckGet(array('rc', 'rs')))) {
  3577. //set form data
  3578. if (wf_CheckPost(array('streetreportcity', 'streetreportstreet'))) {
  3579. $citySearch = $_POST['streetreportcity'];
  3580. $streetSearch = $_POST['streetreportstreet'];
  3581. $buildSearch = (wf_CheckPost(array('streetreportbuild'))) ? str_ireplace($streetSearch, '', $_POST['streetreportbuild']) : '';
  3582. }
  3583. //or printable report
  3584. if (wf_CheckGet(array('rc', 'rs'))) {
  3585. $citySearch = $_GET['rc'];
  3586. $streetSearch = $_GET['rs'];
  3587. $buildSearch = (wf_CheckGet(array('rb'))) ? $_GET['rb'] : '';
  3588. }
  3589. if (!empty($this->users)) {
  3590. $counter = 0;
  3591. $cells = wf_TableCell(__('Contract'), '10%');
  3592. $cells .= wf_TableCell(__('Full address'), '31%');
  3593. $cells .= wf_TableCell(__('Real Name'), '25%');
  3594. $cells .= wf_TableCell(__('Tariff'), '15%');
  3595. $cells .= wf_TableCell(__('Cash'), '7%');
  3596. $cells .= wf_TableCell(__('Seal'), '5%');
  3597. $cells .= wf_TableCell(__('Status'), '7%');
  3598. $rows = wf_TableRow($cells, 'row1');
  3599. foreach ($this->users as $io => $eachUser) {
  3600. if (($eachUser['city'] == $citySearch) and ($eachUser['street'] == $streetSearch) and (empty($buildSearch) ? true : $eachUser['build'] == $buildSearch)) {
  3601. $cells = wf_TableCell($eachUser['contract']);
  3602. $fullAddress = $this->userGetFullAddress($eachUser['id']);
  3603. $profileLink = wf_Link(self::URL_USERS_PROFILE . $eachUser['id'], web_profile_icon() . ' ', false, '');
  3604. $cells .= wf_TableCell($profileLink . $fullAddress);
  3605. $cells .= wf_TableCell($eachUser['realname']);
  3606. $cells .= wf_TableCell($this->tariffs[$eachUser['tariffid']]['tariffname']);
  3607. $cells .= wf_TableCell($eachUser['cash']);
  3608. $cells .= wf_TableCell($eachUser['cableseal']);
  3609. $cells .= wf_TableCell(web_bool_led($eachUser['active'], true));
  3610. $rows .= wf_TableRow($cells, 'row3');
  3611. $counter++;
  3612. }
  3613. }
  3614. $result = wf_TableBody($rows, '100%', '0', 'sortable');
  3615. $result .= __('Total') . ': ' . $counter;
  3616. $buildLinkPart = empty($buildSearch) ? '' : '&rb=' . $buildSearch;
  3617. $buildCaptPart = empty($buildSearch) ? ' ' : ' / ' . $buildSearch . ' ';
  3618. if (wf_CheckGet(array('printable'))) {
  3619. $this->reportPrintable($citySearch . ' / ' . $streetSearch . $buildCaptPart, $result);
  3620. } else {
  3621. $printlink = wf_Link(self::URL_REPORTS_MGMT . 'reportStreets&rc=' . $citySearch . '&rs=' . $streetSearch . $buildLinkPart . '&printable=true', wf_img('skins/icon_print.png', __('Print')), false);
  3622. show_window($citySearch . ' / ' . $streetSearch . $buildCaptPart . $printlink, $result);
  3623. }
  3624. } else {
  3625. show_window(__('Result'), __('Any users found'));
  3626. }
  3627. }
  3628. }
  3629. /**
  3630. * Renders users stats with assigned internet account
  3631. *
  3632. * @return string
  3633. */
  3634. protected function renderInetAssignStats() {
  3635. $result = '';
  3636. $count = 0;
  3637. if (!empty($this->users)) {
  3638. foreach ($this->users as $io => $each) {
  3639. if (!empty($each['inetlogin'])) {
  3640. $count++;
  3641. }
  3642. }
  3643. }
  3644. $result = $this->messages->getStyledMessage(__('Users which already have associated internet account') . ': ' . wf_tag('b') . $count . wf_tag('b', true), 'info');
  3645. return ($result);
  3646. }
  3647. /**
  3648. * Renders complex users assign forms or something like that.
  3649. *
  3650. * @return void
  3651. */
  3652. public function reportComplexAssign() {
  3653. $nologinUsers = array();
  3654. $ukvContracts = array();
  3655. $inetContracts = array();
  3656. $contractCfId = '';
  3657. $result = '';
  3658. //updating inet login if required
  3659. if (wf_CheckPost(array('assignComplexLogin', 'assignComplexUkvId'))) {
  3660. $updateUserId = vf($_POST['assignComplexUkvId'], 3);
  3661. $updateInetLogin = $_POST['assignComplexLogin'];
  3662. if ($this->users[$updateUserId]['inetlogin'] != $updateInetLogin) {
  3663. simple_update_field('ukv_users', 'inetlogin', $updateInetLogin, "WHERE `id`='" . $updateUserId . "';");
  3664. log_register('UKV USER ((' . $updateUserId . ')) ASSIGN INETLOGIN (' . $updateInetLogin . ')');
  3665. rcms_redirect(self::URL_REPORTS_MGMT . 'reportComplexAssign');
  3666. }
  3667. }
  3668. $allInetUsers = zb_UserGetAllStargazerDataAssoc();
  3669. $allAddress = zb_AddressGetFulladdresslistCached();
  3670. $allRealNames = zb_UserGetAllRealnames();
  3671. //preparing ukv users
  3672. if (!empty($this->users)) {
  3673. foreach ($this->users as $io => $each) {
  3674. if (empty($each['inetlogin'])) {
  3675. $nologinUsers[$each['id']] = $each;
  3676. $ukvContracts[$each['contract']] = $each['id'];
  3677. }
  3678. }
  3679. }
  3680. //getting complex contract CF id
  3681. if (!empty($this->altCfg['COMPLEX_CFIDS'])) {
  3682. $cfDataRaw = $this->altCfg['COMPLEX_CFIDS'];
  3683. $cfData = explode(',', $cfDataRaw);
  3684. $contractCfId = (isset($cfData[0])) ? vf($cfData[0], 3) : '';
  3685. }
  3686. //prepare cf logins=>contract pairs
  3687. if (!empty($contractCfId)) {
  3688. $query = "SELECT `login`,`content` from `cfitems` WHERE `typeid`='" . $contractCfId . "' AND `content` IS NOT NULL;";
  3689. $rawCfs = simple_queryall($query);
  3690. if (!empty($rawCfs)) {
  3691. foreach ($rawCfs as $io => $each) {
  3692. $inetContracts[$each['login']] = $each['content'];
  3693. }
  3694. }
  3695. }
  3696. //rendering main form
  3697. if (!empty($inetContracts)) {
  3698. $cells = wf_TableCell(__('Full address'));
  3699. $cells .= wf_TableCell(__('Real Name'));
  3700. $cells .= wf_TableCell(__('Tariff'));
  3701. $cells .= wf_TableCell(__('Contract'));
  3702. $cells .= wf_TableCell(__('Login'));
  3703. $cells .= wf_TableCell(__('Full address'));
  3704. $cells .= wf_TableCell(__('Real Name'));
  3705. $cells .= wf_TableCell(__('Actions'));
  3706. $rows = wf_TableRow($cells, 'row1');
  3707. foreach ($inetContracts as $login => $contract) {
  3708. if (isset($allInetUsers[$login])) {
  3709. if (!empty($contract)) {
  3710. @$ukvUserId = $ukvContracts[$contract];
  3711. if (!empty($ukvUserId)) {
  3712. if (isset($nologinUsers[$ukvUserId])) {
  3713. $ukvRealname = @$this->users[$ukvUserId]['realname'];
  3714. $inetRealname = @$allRealNames[$login];
  3715. $ukvAddress = $this->userGetFullAddress($ukvUserId);
  3716. $inetAddress = @$allAddress[$login];
  3717. $catvLink = wf_link(self::URL_USERS_PROFILE . $ukvUserId, web_profile_icon() . ' ' . $ukvAddress);
  3718. $cells = wf_TableCell($catvLink);
  3719. $cells .= wf_TableCell($ukvRealname);
  3720. $cells .= wf_TableCell(@$this->tariffs[$this->users[$ukvUserId]['tariffid']]['tariffname']);
  3721. $cells .= wf_TableCell($contract);
  3722. $profileLink = wf_Link('?module=userprofile&username=' . $login, web_profile_icon() . ' ' . $login, false);
  3723. $cells .= wf_TableCell($profileLink);
  3724. $cells .= wf_TableCell($inetAddress);
  3725. $cells .= wf_TableCell($inetRealname);
  3726. $assignInputs = wf_HiddenInput('assignComplexLogin', $login);
  3727. $assignInputs .= wf_HiddenInput('assignComplexUkvId', $ukvUserId);
  3728. $assignInputs .= wf_Submit(__('Assign'));
  3729. $assignContols = wf_Form('', 'POST', $assignInputs, '');
  3730. $cells .= wf_TableCell($assignContols);
  3731. $rowclass = 'row3';
  3732. //coloring results
  3733. if ((!empty($ukvRealname)) and (!empty($inetRealname))) {
  3734. $ukvNameTmp = explode(' ', $ukvRealname);
  3735. $inetNameTmp = explode(' ', $inetRealname);
  3736. if (@$ukvNameTmp[0] == @$inetNameTmp[0]) {
  3737. $rowclass = 'ukvassignnamerow';
  3738. }
  3739. if ((!empty($inetAddress)) and (!empty($ukvAddress))) {
  3740. if (($inetAddress == $ukvAddress) and (@$ukvNameTmp[0] == @$inetNameTmp[0])) {
  3741. $rowclass = 'ukvassignaddrrow';
  3742. }
  3743. }
  3744. }
  3745. $rows .= wf_TableRow($cells, $rowclass);
  3746. }
  3747. }
  3748. }
  3749. }
  3750. }
  3751. $result .= $this->renderInetAssignStats() . wf_tag('br');
  3752. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  3753. show_window(__('Assign UKV users to complex profiles'), $result);
  3754. }
  3755. }
  3756. /**
  3757. * Renders report that should be complex users
  3758. *
  3759. * @return void
  3760. */
  3761. public function reportShouldbeComplex() {
  3762. $complexCFids = $this->altCfg['COMPLEX_CFIDS'];
  3763. $complexTariffs = array();
  3764. $complexEnabledService = array();
  3765. $userTariffs = array();
  3766. $result = array();
  3767. $reportData = '';
  3768. if (!empty($complexCFids)) {
  3769. $complexCFids = explode(',', $complexCFids);
  3770. $cfitemTypeId = $complexCFids[0];
  3771. $cfitemComplexEnabled = $complexCFids[1];
  3772. $complexTariffId = $this->altCfg['UKV_COMPLEX_TARIFFID'];
  3773. $complexTariffMasks = $this->altCfg['COMPLEX_MASKS'];
  3774. if (!empty($complexTariffMasks)) {
  3775. $complexTariffMasks = explode(',', $complexTariffMasks);
  3776. if (!empty($complexTariffMasks)) {
  3777. foreach ($complexTariffMasks as $io => $eachmask) {
  3778. $eachmask = trim($eachmask);
  3779. if (!empty($eachmask)) {
  3780. $complexTariffs[$eachmask] = $eachmask;
  3781. }
  3782. }
  3783. }
  3784. $tariff_q = "SELECT `login`,`Tariff`,`TariffChange` from `users`";
  3785. $loginsRaw = simple_queryall($tariff_q);
  3786. $allLogins = array();
  3787. if (!empty($loginsRaw)) {
  3788. foreach ($loginsRaw as $io => $each) {
  3789. foreach ($complexTariffs as $ia => $eachComplexTariff) {
  3790. if ((ispos($each['Tariff'], $eachComplexTariff)) or (ispos($each['TariffChange'], $eachComplexTariff))) {
  3791. $allLogins[$each['login']] = $io;
  3792. $userTariffs[$each['login']] = $each['Tariff'];
  3793. }
  3794. }
  3795. }
  3796. }
  3797. //getting contracts
  3798. $cf_q = "SELECT * from `cfitems` WHERE `typeid`='" . $cfitemTypeId . "' AND `content` != ''";
  3799. $allCfs = simple_queryall($cf_q);
  3800. $allContracts = array();
  3801. if (!empty($allCfs)) {
  3802. foreach ($allCfs as $io => $each) {
  3803. if (isset($allLogins[$each['login']])) {
  3804. $allContracts[$each['content']] = $each['login'];
  3805. }
  3806. }
  3807. }
  3808. //getting complex service enabled flag
  3809. $cf_q = "SELECT * from `cfitems` WHERE `typeid`='" . $cfitemComplexEnabled . "' AND `content` != ''";
  3810. $allCfs = simple_queryall($cf_q);
  3811. if (!empty($allCfs)) {
  3812. foreach ($allCfs as $io => $each) {
  3813. if (isset($allLogins[$each['login']])) {
  3814. $complexEnabledService[$each['login']] = $each['content'];
  3815. }
  3816. }
  3817. }
  3818. $allUkvUsers = array();
  3819. if (!empty($this->users)) {
  3820. foreach ($this->users as $userid => $userdata) {
  3821. if ($userdata['tariffid'] != $complexTariffId) {
  3822. $allUkvUsers[$userdata['contract']] = $userdata;
  3823. }
  3824. }
  3825. }
  3826. if (!empty($allContracts)) {
  3827. foreach ($allContracts as $io => $each) {
  3828. if (isset($allUkvUsers[$io])) {
  3829. $result[$io] = $allUkvUsers[$io]['id'];
  3830. }
  3831. }
  3832. }
  3833. if (!empty($result)) {
  3834. $cells = wf_TableCell(__('Contract'));
  3835. $cells .= wf_TableCell(__('Internet') . ' ' . __('tariff'));
  3836. $cells .= wf_TableCell(__('Complex') . ' ' . __('Active'));
  3837. $cells .= wf_TableCell(__('Full address'));
  3838. $cells .= wf_TableCell(__('Real Name'));
  3839. $cells .= wf_TableCell(__('Tariff') . ' ' . __('UKV'));
  3840. $cells .= wf_TableCell(__('Cash'));
  3841. $cells .= wf_TableCell(__('Status'));
  3842. $rows = wf_TableRow($cells, 'row1');
  3843. foreach ($result as $userContract => $userId) {
  3844. $userLogin = (isset($allContracts[$userContract])) ? $allContracts[$userContract] : '';
  3845. $userTariff = (isset($userTariffs[$userLogin])) ? $userTariffs[$userLogin] : __('No');
  3846. if (!empty($userLogin)) {
  3847. if (isset($complexEnabledService[$userLogin])) {
  3848. if ($complexEnabledService[$userLogin]) {
  3849. $complexFlag = true;
  3850. } else {
  3851. $complexFlag = false;
  3852. }
  3853. } else {
  3854. $complexFlag = false;
  3855. }
  3856. }
  3857. if (($this->users[$userId]['active']) or ($complexFlag)) {
  3858. $cells = wf_TableCell(wf_Link(self::URL_USERS_PROFILE . $userId, web_profile_icon(__('Profile') . ' ' . __('UKV'))) . ' ' . $userContract);
  3859. $cells .= wf_TableCell($userTariff);
  3860. $cells .= wf_TableCell(web_bool_led($complexFlag));
  3861. $cells .= wf_TableCell(wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon(__('Profile') . ' ' . __('Internet'))) . ' ' . $this->userGetFullAddress($userId));
  3862. $cells .= wf_TableCell($this->users[$userId]['realname']);
  3863. $cells .= wf_TableCell($this->tariffs[$this->users[$userId]['tariffid']]['tariffname']);
  3864. $cells .= wf_TableCell($this->users[$userid]['cash']);
  3865. $cells .= wf_TableCell(web_bool_led($this->users[$userId]['active']));
  3866. $rows .= wf_TableRow($cells, 'row3');
  3867. }
  3868. }
  3869. $reportData = wf_TableBody($rows, '100%', 0, 'sortable');
  3870. show_window(__('Users which should be complex in UKV'), $reportData);
  3871. } else {
  3872. show_info(__('Nothing found'));
  3873. }
  3874. }
  3875. } else {
  3876. show_error(__('You missed an important option'));
  3877. }
  3878. }
  3879. /**
  3880. * Renders report that should not be complex users
  3881. *
  3882. * @return void
  3883. */
  3884. public function reportShouldNotbeComplex() {
  3885. $complexCFids = $this->altCfg['COMPLEX_CFIDS'];
  3886. $complexTariffs = array();
  3887. $complexEnabledService = array();
  3888. $userTariffs = array();
  3889. $result = array();
  3890. $reportData = '';
  3891. if (!empty($complexCFids)) {
  3892. $complexCFids = explode(',', $complexCFids);
  3893. $cfitemTypeId = $complexCFids[0];
  3894. $cfitemComplexEnabled = $complexCFids[1];
  3895. $complexTariffId = $this->altCfg['UKV_COMPLEX_TARIFFID'];
  3896. $complexTariffMasks = $this->altCfg['COMPLEX_MASKS'];
  3897. if (!empty($complexTariffMasks)) {
  3898. $complexTariffMasks = explode(',', $complexTariffMasks);
  3899. if (!empty($complexTariffMasks)) {
  3900. foreach ($complexTariffMasks as $io => $eachmask) {
  3901. $eachmask = trim($eachmask);
  3902. if (!empty($eachmask)) {
  3903. $complexTariffs[$eachmask] = $eachmask;
  3904. }
  3905. }
  3906. }
  3907. $tariff_q = "SELECT `login`,`Tariff`,`TariffChange` from `users`";
  3908. $loginsRaw = simple_queryall($tariff_q);
  3909. $allLogins = array();
  3910. if (!empty($loginsRaw)) {
  3911. foreach ($loginsRaw as $ix => $each) {
  3912. $allLogins[$each['login']] = $each;
  3913. $userTariffs[$each['login']] = $each['Tariff'];
  3914. }
  3915. }
  3916. if (!empty($allLogins)) {
  3917. foreach ($allLogins as $io => $each) {
  3918. foreach ($complexTariffs as $ia => $eachComplexTariff) {
  3919. if ((ispos($each['Tariff'], $eachComplexTariff)) or (ispos($each['TariffChange'], $eachComplexTariff))) {
  3920. unset($allLogins[$each['login']]);
  3921. }
  3922. }
  3923. }
  3924. }
  3925. //getting contracts
  3926. $cf_q = "SELECT * from `cfitems` WHERE `typeid`='" . $cfitemTypeId . "' AND `content` != ''";
  3927. $allCfs = simple_queryall($cf_q);
  3928. $allContracts = array();
  3929. if (!empty($allCfs)) {
  3930. foreach ($allCfs as $io => $each) {
  3931. if (isset($allLogins[$each['login']])) {
  3932. $allContracts[$each['content']] = $each['login'];
  3933. }
  3934. }
  3935. }
  3936. //getting complex service enabled flag
  3937. $cf_q = "SELECT * from `cfitems` WHERE `typeid`='" . $cfitemComplexEnabled . "' AND `content` != ''";
  3938. $allCfs = simple_queryall($cf_q);
  3939. if (!empty($allCfs)) {
  3940. foreach ($allCfs as $io => $each) {
  3941. if (isset($allLogins[$each['login']])) {
  3942. $complexEnabledService[$each['login']] = $each['content'];
  3943. }
  3944. }
  3945. }
  3946. $allUkvUsers = array();
  3947. if (!empty($this->users)) {
  3948. foreach ($this->users as $userid => $userdata) {
  3949. if ($userdata['tariffid'] == $complexTariffId) {
  3950. $allUkvUsers[$userdata['contract']] = $userdata;
  3951. }
  3952. }
  3953. }
  3954. if (!empty($allContracts)) {
  3955. foreach ($allContracts as $io => $each) {
  3956. if (isset($allUkvUsers[$io])) {
  3957. if (isset($allLogins[$each])) {
  3958. $result[$io] = $allUkvUsers[$io]['id'];
  3959. }
  3960. }
  3961. }
  3962. }
  3963. if (!empty($result)) {
  3964. $cells = wf_TableCell(__('Contract'));
  3965. $cells .= wf_TableCell(__('Internet') . ' ' . __('tariff'));
  3966. $cells .= wf_TableCell(__('Complex') . ' ' . __('Active'));
  3967. $cells .= wf_TableCell(__('Full address'));
  3968. $cells .= wf_TableCell(__('Real Name'));
  3969. $cells .= wf_TableCell(__('Tariff') . ' ' . __('UKV'));
  3970. $cells .= wf_TableCell(__('Cash'));
  3971. $cells .= wf_TableCell(__('Status'));
  3972. $rows = wf_TableRow($cells, 'row1');
  3973. foreach ($result as $userContract => $userId) {
  3974. $userLogin = (isset($allContracts[$userContract])) ? $allContracts[$userContract] : '';
  3975. $userTariff = (isset($userTariffs[$userLogin])) ? $userTariffs[$userLogin] : __('No');
  3976. if (!empty($userLogin)) {
  3977. if (isset($complexEnabledService[$userLogin])) {
  3978. if ($complexEnabledService[$userLogin]) {
  3979. $complexFlag = true;
  3980. } else {
  3981. $complexFlag = false;
  3982. }
  3983. } else {
  3984. $complexFlag = false;
  3985. }
  3986. }
  3987. $cells = wf_TableCell(wf_Link(self::URL_USERS_PROFILE . $userId, web_profile_icon(__('Profile') . ' ' . __('UKV'))) . ' ' . $userContract);
  3988. $cells .= wf_TableCell($userTariff);
  3989. $cells .= wf_TableCell(web_bool_led($complexFlag));
  3990. $cells .= wf_TableCell(wf_Link('?module=userprofile&username=' . $userLogin, web_profile_icon(__('Profile') . ' ' . __('Internet'))) . ' ' . $this->userGetFullAddress($userId));
  3991. $cells .= wf_TableCell($this->users[$userId]['realname']);
  3992. $cells .= wf_TableCell($this->tariffs[$this->users[$userId]['tariffid']]['tariffname']);
  3993. $cells .= wf_TableCell($this->users[$userid]['cash']);
  3994. $cells .= wf_TableCell(web_bool_led($this->users[$userId]['active']));
  3995. $rows .= wf_TableRow($cells, 'row3');
  3996. }
  3997. $reportData = wf_TableBody($rows, '100%', 0, 'sortable');
  3998. show_window(__('Users which should not be complex in UKV'), $reportData);
  3999. } else {
  4000. show_info(__('Nothing found'));
  4001. }
  4002. }
  4003. } else {
  4004. show_error(__('You missed an important option'));
  4005. }
  4006. }
  4007. /**
  4008. * Renders UKV users integrity report
  4009. *
  4010. * @return void
  4011. */
  4012. public function reportIntegrity() {
  4013. $result = '';
  4014. $addressTmp = array();
  4015. $contractsTmp = array();
  4016. $problemUsers = array();
  4017. $problemComplex = array();
  4018. $problemTypes = array(
  4019. 'addressdup' => __('Address duplicate'),
  4020. 'contractdup' => __('Contract duplicate'),
  4021. 'addressempty' => __('Empty address'),
  4022. 'contractempty' => __('Empty contract'),
  4023. 'notariff' => __('No tariff'),
  4024. 'noukvuser' => __('Missing registered UKV user with complex tariff'),
  4025. 'activediff' => __('Account activity is different')
  4026. );
  4027. if (!empty($this->users)) {
  4028. if ($this->altCfg['COMPLEX_ENABLED']) {
  4029. $complexFlag = true;
  4030. $inetAddress = zb_AddressGetFulladdresslistCached();
  4031. $inetRealnames = zb_UserGetAllRealnames();
  4032. $complexCfIds = $this->altCfg['COMPLEX_CFIDS'];
  4033. $complexCfIds = explode(',', $complexCfIds);
  4034. $complexContractCf = $complexCfIds[0];
  4035. $complexActiveCf = $complexCfIds[1];
  4036. $complexMasksTmp = $this->altCfg['COMPLEX_MASKS'];
  4037. $complexMasksTmp = explode(',', $complexMasksTmp);
  4038. $complexContracts = array();
  4039. $complexActive = array();
  4040. $inetCableseals = array();
  4041. $contractsActivity = array();
  4042. if (!empty($complexMasksTmp)) {
  4043. foreach ($complexMasksTmp as $io => $each) {
  4044. $complexMasks[$each] = $each;
  4045. }
  4046. }
  4047. $allComplexUsers = array(); //login=>userdata
  4048. if (!empty($complexMasks)) {
  4049. $allUsersRaw = zb_UserGetAllStargazerDataAssoc();
  4050. if (!empty($allUsersRaw)) {
  4051. foreach ($allUsersRaw as $userLogin => $eachUser) {
  4052. foreach ($complexMasks as $ia => $eachComplexMask) {
  4053. if (ispos($eachUser['Tariff'], $eachComplexMask)) {
  4054. $allComplexUsers[$userLogin] = $eachUser;
  4055. }
  4056. }
  4057. }
  4058. }
  4059. }
  4060. //getting complex active and contract fields
  4061. $query_complex = "SELECT * from `cfitems`";
  4062. $cfRaw = simple_queryall($query_complex);
  4063. if (!empty($cfRaw)) {
  4064. foreach ($cfRaw as $io => $eachCf) {
  4065. if ($eachCf['typeid'] == $complexContractCf) {
  4066. $complexContracts[$eachCf['login']] = $eachCf['content'];
  4067. }
  4068. if ($eachCf['typeid'] == $complexActiveCf) {
  4069. $complexActive[$eachCf['login']] = $eachCf['content'];
  4070. }
  4071. }
  4072. }
  4073. } else {
  4074. $complexFlag = false;
  4075. }
  4076. foreach ($this->users as $io => $eachUser) {
  4077. //unique address
  4078. $userAddress = $this->userGetFullAddress($eachUser['id']);
  4079. if (!empty($userAddress)) {
  4080. if (isset($addressTmp[$userAddress])) {
  4081. $problemUsers[$eachUser['id']] = $eachUser;
  4082. $problemUsers[$eachUser['id']]['type'] = 'addressdup';
  4083. //first occurence
  4084. $firstUserId = $addressTmp[$userAddress];
  4085. $problemUsers[$firstUserId] = $this->users[$firstUserId];
  4086. $problemUsers[$firstUserId]['type'] = 'addressdup';
  4087. } else {
  4088. $addressTmp[$userAddress] = $eachUser['id'];
  4089. }
  4090. }
  4091. //unique contracts
  4092. if (!empty($eachUser['contract'])) {
  4093. if (isset($contractsTmp[$eachUser['contract']])) {
  4094. $problemUsers[$eachUser['id']] = $eachUser;
  4095. $problemUsers[$eachUser['id']]['type'] = 'contractdup';
  4096. //first occurence
  4097. $firstUserId = $contractsTmp[$eachUser['contract']];
  4098. $problemUsers[$firstUserId] = $this->users[$firstUserId];
  4099. $problemUsers[$firstUserId]['type'] = 'contractdup';
  4100. } else {
  4101. $contractsTmp[$eachUser['contract']] = $eachUser['id'];
  4102. }
  4103. }
  4104. //empty contract
  4105. if (empty($userAddress)) {
  4106. $problemUsers[$eachUser['id']] = $eachUser;
  4107. $problemUsers[$eachUser['id']]['type'] = 'addressempty';
  4108. }
  4109. //empty contract
  4110. if (empty($eachUser['contract'])) {
  4111. $problemUsers[$eachUser['id']] = $eachUser;
  4112. $problemUsers[$eachUser['id']]['type'] = 'contractempty';
  4113. }
  4114. //empty tariff
  4115. if (empty($eachUser['tariffid'])) {
  4116. $problemUsers[$eachUser['id']] = $eachUser;
  4117. $problemUsers[$eachUser['id']]['type'] = 'notariff';
  4118. }
  4119. //contracts actitivy temp fill
  4120. if (!empty($eachUser['contract'])) {
  4121. $contractsActivity[$eachUser['contract']] = $eachUser['active'];
  4122. }
  4123. }
  4124. //complex processing
  4125. if ($complexFlag) {
  4126. $userStreets = zb_AddressGetStreetUsers();
  4127. if (!empty($allComplexUsers)) {
  4128. //No UKV user detected
  4129. foreach ($allComplexUsers as $io => $eachComplexUser) {
  4130. if (!isset($complexContracts[$eachComplexUser['login']])) {
  4131. $problemComplex[$eachComplexUser['login']]['login'] = $eachComplexUser['login'];
  4132. $problemComplex[$eachComplexUser['login']]['type'] = 'noukvuser';
  4133. }
  4134. }
  4135. //Activity state is different
  4136. foreach ($allComplexUsers as $io => $eachComplexUser) {
  4137. if (isset($complexContracts[$eachComplexUser['login']])) {
  4138. if (isset($complexActive[$eachComplexUser['login']])) {
  4139. $cpActFlag = $complexActive[$eachComplexUser['login']];
  4140. } else {
  4141. $cpActFlag = 0;
  4142. }
  4143. if (isset($contractsActivity[$complexContracts[$eachComplexUser['login']]])) {
  4144. $ukActFlag = $contractsActivity[$complexContracts[$eachComplexUser['login']]];
  4145. } else {
  4146. $ukActFlag = 0;
  4147. }
  4148. if ($cpActFlag != $ukActFlag) {
  4149. $problemComplex[$eachComplexUser['login']]['login'] = $eachComplexUser['login'];
  4150. $problemComplex[$eachComplexUser['login']]['type'] = 'activediff';
  4151. }
  4152. }
  4153. }
  4154. //UKV user contract missing
  4155. foreach ($allComplexUsers as $io => $eachComplexUser) {
  4156. if (!isset($this->contracts[@$complexContracts[$eachComplexUser['login']]])) {
  4157. $problemComplex[$eachComplexUser['login']]['login'] = $eachComplexUser['login'];
  4158. $problemComplex[$eachComplexUser['login']]['type'] = 'noukvuser';
  4159. }
  4160. }
  4161. }
  4162. }
  4163. if (!empty($problemUsers)) {
  4164. $cells = wf_TableCell(__('ID'));
  4165. $cells .= wf_TableCell(__('Contract'));
  4166. $cells .= wf_TableCell(__('Full address'));
  4167. $cells .= wf_TableCell(__('Real Name'));
  4168. $cells .= wf_TableCell(__('Tariff'));
  4169. $cells .= wf_TableCell(__('Cash'));
  4170. $cells .= wf_TableCell(__('Active'));
  4171. $cells .= wf_TableCell(__('Type'));
  4172. $rows = wf_TableRow($cells, 'row1');
  4173. foreach ($problemUsers as $io => $each) {
  4174. $cells = wf_TableCell(wf_Link(self::URL_USERS_PROFILE . $each['id'], web_profile_icon() . ' ' . $each['id']));
  4175. $cells .= wf_TableCell($each['contract']);
  4176. $cells .= wf_TableCell($this->userGetFullAddress($each['id']));
  4177. $cells .= wf_TableCell($each['realname']);
  4178. $cells .= wf_TableCell(@$this->tariffs[$each['tariffid']]['tariffname']);
  4179. $cells .= wf_TableCell($each['cash']);
  4180. $cells .= wf_TableCell(web_bool_led($each['active']));
  4181. $cells .= wf_TableCell(@$problemTypes[$each['type']]);
  4182. $rows .= wf_TableRow($cells, 'row3');
  4183. }
  4184. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  4185. } else {
  4186. $result .= $this->messages->getStyledMessage(__('Nothing found'), 'success');
  4187. }
  4188. if ($complexFlag) {
  4189. if (!empty($problemComplex)) {
  4190. $cells = wf_TableCell(__('Login'));
  4191. $cells .= wf_TableCell(__('Full address'));
  4192. $cells .= wf_TableCell(__('Real Name'));
  4193. $cells .= wf_TableCell(__('Tariff'));
  4194. $cells .= wf_TableCell(__('Cash'));
  4195. $cells .= wf_TableCell(__('Active'));
  4196. $cells .= wf_TableCell(__('Type'));
  4197. $rows = wf_TableRow($cells, 'row1');
  4198. foreach ($problemComplex as $io => $each) {
  4199. $cells = wf_TableCell(wf_Link(self::URL_INET_USER_PROFILE . $each['login'], web_profile_icon() . ' ' . $each['login']));
  4200. $cells .= wf_TableCell(@$inetAddress[$each['login']]);
  4201. $cells .= wf_TableCell(@$inetRealnames[$each['login']]);
  4202. $cells .= wf_TableCell(@$allUsersRaw[$each['login']]['Tariff']);
  4203. $cells .= wf_TableCell(@$allUsersRaw[$each['login']]['Cash']);
  4204. $activityLabel = web_bool_led(@$complexActive[$each['login']]);
  4205. if (@isset($contractsActivity[$complexContracts[$each['login']]])) {
  4206. $activityLabel .= ' ' . web_bool_led(@$contractsActivity[$complexContracts[$each['login']]]);
  4207. }
  4208. $cells .= wf_TableCell($activityLabel);
  4209. $cells .= wf_TableCell(@$problemTypes[$each['type']]);
  4210. $rows .= wf_TableRow($cells, 'row3');
  4211. }
  4212. $result .= wf_tag('br');
  4213. $result .= wf_TableBody($rows, '100%', 0, 'sortable');
  4214. }
  4215. }
  4216. } else {
  4217. $result .= $this->messages->getStyledMessage(__('Any users found'), 'warning');
  4218. }
  4219. show_window(__('Integrity control'), $result);
  4220. }
  4221. public function getUbMessagesInstance() {
  4222. return ($this->messages);
  4223. }
  4224. }