api.astral.php 154 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677
  1. <?php
  2. /**
  3. * Returns web form element id
  4. *
  5. * @return string
  6. */
  7. function wf_InputId() {
  8. // I know it looks really funny.
  9. // You can also get a truly random values​by throwing dice ;)
  10. $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
  11. $result = "";
  12. for ($p = 0; $p < 8; $p++) {
  13. $result .= $characters[mt_rand(0, (strlen($characters) - 1))];
  14. }
  15. return ($result);
  16. }
  17. /**
  18. * Return web form body
  19. *
  20. * @param string $action action URL
  21. * @param string $method method: POST or GET
  22. * @param string $inputs inputs string to include
  23. * @param string $class class for form
  24. * @param string $legend form legend
  25. * @param string $CtrlID
  26. * @param string $target
  27. * @param string $opts
  28. *
  29. * @return string
  30. *
  31. */
  32. function wf_Form($action, $method, $inputs, $class = '', $legend = '', $CtrlID = '', $target = '', $opts = '') {
  33. $FrmID = ((empty($CtrlID)) ? 'Form_' . wf_InputId() : $CtrlID);
  34. if ($class != '') {
  35. $form_class = ' class="' . $class . '" ';
  36. } else {
  37. $form_class = '';
  38. }
  39. if ($legend != '') {
  40. $form_legend = '<legend>' . __($legend) . '</legend> <br>';
  41. } else {
  42. $form_legend = '';
  43. }
  44. if ($target != '') {
  45. $target = ' target="' . $target . '" ';
  46. } else {
  47. $target = '';
  48. }
  49. $form = '
  50. <form action="' . $action . '" method="' . $method . '" ' . $form_class . ' id="' . $FrmID . '" ' . $target . ' ' . $opts . '>
  51. ' . $form_legend . '
  52. ' . $inputs . '
  53. </form>
  54. <div style="clear:both;"></div>
  55. ';
  56. return ($form);
  57. }
  58. /**
  59. * Return text input Web From element
  60. *
  61. * @param string $name name of element
  62. * @param string $label text label for input
  63. * @param string $value current value
  64. * @param bool $br append new line
  65. * @param string $size input size
  66. * @param string $pattern input check pattern. Avaible: geo, mobile, finance, ip, net-cidr, digits, email, alpha, alphanumeric,mac,float,login,url,sigint
  67. * @param string $class class of the element
  68. * @param string $ctrlID id of the element
  69. * @param string $options
  70. * @param bool $labelLeftSide
  71. * @param string $labelOpts
  72. *
  73. * @return string
  74. *
  75. */
  76. function wf_TextInput($name, $label = '', $value = '', $br = false, $size = '', $pattern = '', $class = '', $ctrlID = '', $options = '', $labelLeftSide = false, $labelOpts = '') {
  77. $inputid = (empty($ctrlID)) ? wf_InputId() : $ctrlID;
  78. $opts = (empty($options)) ? '' : $options;
  79. //set size
  80. if ($size != '') {
  81. $input_size = 'size="' . $size . '"';
  82. } else {
  83. $input_size = '';
  84. }
  85. if ($br) {
  86. $newline = '<br>';
  87. } else {
  88. $newline = '';
  89. }
  90. // We will verify that we correctly enter data by input type
  91. $pattern = ($pattern == 'alpha') ? 'pattern="[a-zA-Z]+" placeholder="aZ" title="' . __('This field can only contain Latin letters') . '"' : $pattern;
  92. $pattern = ($pattern == 'alphanumeric') ? 'pattern="[a-zA-Z0-9]+" placeholder="aZ09" title="' . __('This field can only contain Latin letters and numbers') . '"' : $pattern;
  93. $pattern = ($pattern == 'digits') ? 'pattern="^\d+$" placeholder="0" title="' . __('This field can only contain digits') . '"' : $pattern;
  94. $pattern = ($pattern == 'finance') ? 'pattern="\d+(\.\d+)?" placeholder="0(.00)" title="' . __('The financial input format can be') . ': 1 ; 4.01 ; 2 ; 0.001"' : $pattern;
  95. $pattern = ($pattern == 'float') ? 'pattern="\d+(\.\d+)?" placeholder="0.00" title="' . __('This field can only contain digits') . ': 1 ; 4.01 ; 2 ; 0.001"' : $pattern;
  96. $pattern = ($pattern == 'sigint') ? 'pattern="^-?\d+$" placeholder="0" title="' . __('This field can only contain digits') . ' ' . __('and') . ' - "' : $pattern;
  97. // For this pattern IP adress also can be 0.0.0.0
  98. $pattern = ($pattern == 'ip') ? 'pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$" placeholder="0.0.0.0" title="' . __('The IP address format can be') . ': 192.1.1.1"' : $pattern;
  99. // For this pattern exclude cidr /31
  100. $pattern = ($pattern == 'net-cidr') ? 'pattern="^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\/([0-9]|[1-2][0-9]|30|32)$" placeholder="0.0.0.0/0" title="' . __('The format of IP address with mask can be') . ': 192.1.1.1/32 ' . __('and the mask can not be /31') . '"' : $pattern;
  101. $pattern = ($pattern == 'email') ? 'pattern="^([\w\._-]+)@([\w\._-]+)\.([a-z]{2,6}\.?)$" placeholder="bobrik@bobrik.com" title="' . __('This field can only contain email address') . '"' : $pattern;
  102. $pattern = ($pattern == 'login') ? 'pattern="[a-zA-Z0-9_]+" placeholder="aZ09_" title="' . __('This field can only contain Latin letters and numbers') . ' ' . __('and') . ' _' . '"' : $pattern;
  103. $pattern = ($pattern == 'mac') ? 'pattern="^[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}:[a-fA-F0-9]{2}$|^[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}-[a-fA-F0-9]{2}$" placeholder="00:02:02:34:72:a5" title="' . __('This MAC have wrong format') . '"' : $pattern;
  104. $pattern = ($pattern == 'url') ? 'pattern="https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)" placeholder="http://ubilling.net.ua/" title="' . __('URL') . ': http://host.domain/ ' . __('or') . ' https://host.domain/ ' . __('or') . ' http://host.domain:port"' : $pattern;
  105. $pattern = ($pattern == 'geo') ? 'pattern="-?\d{1,2}(\.\d+)\s?,\s?-?\d{1,3}(\.\d+)" placeholder="0.00000,0.00000" title="' . __('The format of geographic data can be') . ': 40.7143528,-74.0059731 ; 41.40338, 2.17403 ; -14.235004 , 51.92528"' : $pattern;
  106. $pattern = ($pattern == 'mobile') ? 'pattern="\+?(\d{1,3})?\d{2,3}\d{7}" placeholder="(+)(38)0500000000" title="' . __('The mobile number format can be') . ': +380800100102, 0506430501, 375295431122"' : $pattern;
  107. $result = '<input type="text" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '" class="' . $class . '" ' . $opts . ' ' . $pattern . '>' . "\n";
  108. if ($label != '') {
  109. $labelOpts = (empty($labelOpts) ? '' : $labelOpts);
  110. $labelStr = '<label for="' . $inputid . '" ' . $labelOpts . '>' . __($label) . '</label>';
  111. if ($labelLeftSide) {
  112. $result = $labelStr . ' ' . $result . "\n";
  113. } else {
  114. $result .= ' ' . $labelStr . "\n";
  115. }
  116. }
  117. $result .= $newline . "\n";
  118. return ($result);
  119. }
  120. /**
  121. * Return password input Web From element (legacy)
  122. *
  123. * @param string $name name of element
  124. * @param string $label text label for input
  125. * @param string $value current value
  126. * @param bool $br append new line
  127. * @param string $size input size
  128. * @return string
  129. *
  130. */
  131. function wf_PasswordInputRaw($name, $label = '', $value = '', $br = false, $size = '') {
  132. $inputid = wf_InputId();
  133. //set size
  134. if ($size != '') {
  135. $input_size = 'size="' . $size . '"';
  136. } else {
  137. $input_size = '';
  138. }
  139. if ($br) {
  140. $newline = '<br>';
  141. } else {
  142. $newline = '';
  143. }
  144. $result = '<input type="password" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
  145. if ($label != '') {
  146. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  147. }
  148. $result .= $newline . "\n";
  149. return ($result);
  150. }
  151. /**
  152. * Return password input Web From element with show/hide controls
  153. *
  154. * @param string $name name of element
  155. * @param string $label text label for input
  156. * @param string $value current value
  157. * @param bool $br append new line
  158. * @param string $size input size
  159. * @param bool $showHideInput show or not show/hide password control
  160. *
  161. * @return string
  162. *
  163. */
  164. function wf_PasswordInput($name, $label = '', $value = '', $br = false, $size = '', $showHideInput = true) {
  165. $result = '';
  166. $inputid = wf_InputId();
  167. //set size
  168. if ($size != '') {
  169. $input_size = 'size="' . $size . '"';
  170. } else {
  171. $input_size = '';
  172. }
  173. if ($br) {
  174. $newline = '<br>';
  175. } else {
  176. $newline = '';
  177. }
  178. if ($showHideInput) {
  179. $result .= '<style> .passfieldhide { filter: grayscale(1); .passfieldshow { filter: grayscale(0); } } </style>';
  180. }
  181. //password input here
  182. $result .= '<input type="password" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
  183. if ($showHideInput) {
  184. $result .= '<span class="toggle-password' . $inputid . '"><img src="skins/icon_lock.png" width="12" title=' . __('Show') . '/' . __('Hide') . '></span>';
  185. $result .= "
  186. <script>
  187. $('.toggle-password" . $inputid . "').click(function(){
  188. $(this).children().toggleClass('passfieldhide passfieldshow');
  189. let input = $(this).prev();
  190. input.attr('type', input.attr('type') === 'password' ? 'text' : 'password');
  191. });
  192. </script>";
  193. }
  194. if ($label != '') {
  195. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  196. }
  197. $result .= $newline . "\n";
  198. return ($result);
  199. }
  200. /**
  201. * Return link form element
  202. *
  203. * @param string $url needed URL
  204. * @param string $title text title of URL
  205. * @param bool $br append new line
  206. * @param string $class class for link
  207. * @param string $options for link
  208. * @return string
  209. *
  210. */
  211. function wf_Link($url, $title, $br = false, $class = '', $options = '') {
  212. if ($class != '') {
  213. $link_class = 'class="' . $class . '"';
  214. } else {
  215. $link_class = '';
  216. }
  217. if ($br) {
  218. $newline = '<br>';
  219. } else {
  220. $newline = '';
  221. }
  222. $opts = (empty($options)) ? '' : ' ' . $options;
  223. $result = '<a href="' . $url . '" ' . $link_class . $opts . '>' . __($title) . '</a>' . "\n";
  224. $result .= $newline . "\n";
  225. return ($result);
  226. }
  227. /**
  228. * Return ajax loader compatible link
  229. *
  230. * @param string $url needed URL
  231. * @param string $title text title of URL
  232. * @param string $container output container for ajax content
  233. * @param bool $br append new line
  234. * @param string $class class for link
  235. * @return string
  236. */
  237. function wf_AjaxLink($url, $title, $container, $br = false, $class = '') {
  238. if ($class != '') {
  239. $link_class = 'class="' . $class . '"';
  240. } else {
  241. $link_class = '';
  242. }
  243. if ($br) {
  244. $newline = '<br>';
  245. } else {
  246. $newline = '';
  247. }
  248. $result = '<a href="#" onclick="goajax(\'' . $url . '\',\'' . $container . '\');" ' . $link_class . '>' . $title . '</a>' . "\n";
  249. $result .= $newline . "\n";
  250. return ($result);
  251. }
  252. /**
  253. * Return Radio box Web From element
  254. *
  255. * @param string $name name of element
  256. * @param string $label text label for input
  257. * @param string $value current value
  258. * @param bool $br append new line
  259. * @param bool $checked is checked?
  260. * @param string $ctrlID id of the element
  261. *
  262. * @return string
  263. *
  264. */
  265. function wf_RadioInput($name, $label = '', $value = '', $br = false, $checked = false, $ctrlID = '') {
  266. $inputid = (empty($ctrlID)) ? wf_InputId() : $ctrlID;
  267. if ($br) {
  268. $newline = '<br>';
  269. } else {
  270. $newline = '';
  271. }
  272. if ($checked) {
  273. $check = 'checked=""';
  274. } else {
  275. $check = '';
  276. }
  277. $result = '<input type="radio" name="' . $name . '" value="' . $value . '" id="' . $inputid . '" ' . $check . '>' . "\n";
  278. if ($label != '') {
  279. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  280. }
  281. $result .= $newline . "\n";
  282. return ($result);
  283. }
  284. /**
  285. * Return check box Web From element
  286. *
  287. * @param string $name name of element
  288. * @param string $label text label for input
  289. * @param bool $br append new line
  290. * @param bool $checked is checked?
  291. * @param string $CtrlID
  292. * @param string $CtrlClass
  293. *
  294. * @return string
  295. *
  296. */
  297. function wf_CheckInput($name, $label = '', $br = false, $checked = false, $CtrlID = '', $CtrlClass = '', $options = '', $labelOptions = '') {
  298. $inputid = ((empty($CtrlID)) ? 'ChkBox_' . wf_InputId() : $CtrlID);
  299. $inputClass = ((empty($CtrlClass)) ? '' : ' class="' . $CtrlClass . '" ');
  300. if ($br) {
  301. $newline = '<br>';
  302. } else {
  303. $newline = '';
  304. }
  305. if ($checked) {
  306. $check = 'checked=""';
  307. } else {
  308. $check = '';
  309. }
  310. $result = '<input type="checkbox" id="' . $inputid . '" ' . $inputClass . 'name="' . $name . '" ' . $check . ' ' . $options . ' />';
  311. if ($label != '') {
  312. $result .= ' <label for="' . $inputid . '" ' . $labelOptions . '>' . __($label) . '</label>' . "\n";
  313. }
  314. $result .= $newline . "\n";
  315. return ($result);
  316. }
  317. /**
  318. * Return textarea Web form element
  319. *
  320. * @param string $name name of element
  321. * @param string $label text label for input
  322. * @param string $value value for element
  323. * @param bool $br append new line - bool
  324. * @param string $size size in format "20x10"
  325. * @param string $inputId custom inputId
  326. *
  327. * @return string
  328. *
  329. */
  330. function wf_TextArea($name, $label = '', $value = '', $br = false, $size = '', $inputId = '') {
  331. $elementInputId = ($inputId) ? $inputId : wf_InputId();
  332. //set columns and rows count
  333. if ($size != '') {
  334. $sizexplode = explode('x', $size);
  335. $input_size = 'cols="' . $sizexplode[0] . '" rows="' . $sizexplode[1] . '" ';
  336. } else {
  337. $input_size = '';
  338. }
  339. if ($br) {
  340. $newline = '<br>';
  341. } else {
  342. $newline = '';
  343. }
  344. $result = '<textarea name="' . $name . '" ' . $input_size . ' id="' . $elementInputId . '">' . $value . '</textarea>' . "\n";
  345. if ($label != '') {
  346. $result .= ' <label for="' . $elementInputId . '">' . __($label) . '</label>' . "\n";
  347. }
  348. $result .= $newline . "\n";
  349. return ($result);
  350. }
  351. /**
  352. * Return hidden input web form element
  353. *
  354. * @param string $name name of element
  355. * @param string $value value for input
  356. * @param string $CtrlID
  357. * @param string $CtrlClass
  358. *
  359. * @return string
  360. *
  361. */
  362. function wf_HiddenInput($name, $value = '', $CtrlID = '', $CtrlClass = '') {
  363. $HiddenID = ((empty($CtrlID)) ? 'Hidden_' . wf_InputId() : $CtrlID);
  364. $Hiddenclass = ((empty($CtrlClass)) ? '' : ' class="' . $CtrlClass . '" ');
  365. /**
  366. * Call me by my astral name
  367. * Breeding fear through wordless tounge
  368. * Heavenly thirst - unspeakable pain
  369. * Emptied from all human motion
  370. * Confront the faceless wrath
  371. */
  372. $result = '<input type="hidden" name="' . $name . '" value="' . $value . '" id="' . $HiddenID . '"' . $Hiddenclass . '>';
  373. return ($result);
  374. }
  375. /**
  376. * Return submit web form element
  377. *
  378. * @param string $value text label for button
  379. * @param string $CtrlID
  380. * @param string $options
  381. *
  382. * @return string
  383. *
  384. */
  385. function wf_Submit($value, $CtrlID = '', $options = '') {
  386. $SubmitID = ((empty($CtrlID)) ? 'Submit_' . wf_InputId() : $CtrlID);
  387. $result = '<input type="submit" value="' . __($value) . '" id="' . $SubmitID . '" ' . $options . '>';
  388. return ($result);
  389. }
  390. /**
  391. * Return submit web form element for which you can specify class and other options
  392. *
  393. * @param $value
  394. * @param string $class
  395. * @param string $name
  396. * @param string $caption
  397. * @param string $CtrlID
  398. *
  399. * @return string
  400. */
  401. function wf_SubmitClassed($value, $class = '', $name = '', $caption = '', $CtrlID = '', $options = '') {
  402. $SubmitID = ((empty($CtrlID)) ? 'Submit_' . wf_InputId() : $CtrlID);
  403. $result = '<button type="submit" value="' . $value . '" name="' . $name . '" class= "' . $class . '" id="' . $SubmitID . '" ' . $options . '>';
  404. $result .= $caption;
  405. $result .= '</button>';
  406. return ($result);
  407. }
  408. /**
  409. * Return Trigger select web form input
  410. *
  411. * @param string $name name of element
  412. * @param string $label text label for input
  413. * @param string $state selected $value for trigger
  414. * @param bool $br append new line
  415. * @return string
  416. *
  417. */
  418. function wf_Trigger($name, $label = '', $state = '', $br = false) {
  419. $inputid = wf_InputId();
  420. if (!$state) {
  421. $noflag = 'SELECTED';
  422. } else {
  423. $noflag = '';
  424. }
  425. if ($br) {
  426. $newline = '<br>';
  427. } else {
  428. $newline = '';
  429. }
  430. $result = '
  431. <select name="' . $name . '" id="' . $inputid . '">
  432. <option value="1">' . __('Yes') . '</option>
  433. <option value="0" ' . $noflag . '>' . __('No') . '</option>
  434. </select>
  435. ' . "\n";
  436. if ($label != '') {
  437. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  438. }
  439. $result .= $newline . "\n";
  440. return ($result);
  441. }
  442. /**
  443. * Return select Web From element
  444. *
  445. * @param string $name name of element
  446. * @param array $params array of elements $value=>$option
  447. * @param string $label text label for input
  448. * @param string $selected selected $value for selector
  449. * @param bool $br append new line
  450. * @param bool $sort alphabetical sorting of params array by value
  451. * @param string $CtrlID id of the element
  452. * @param string $CtrlClass
  453. * @param string $options
  454. * @param bool $labelLeftSide
  455. * @param string $labelOpts
  456. *
  457. * @return string
  458. *
  459. */
  460. function wf_Selector($name, $params, $label, $selected = '', $br = false, $sort = false, $CtrlID = '', $CtrlClass = '', $options = '', $labelLeftSide = false, $labelOpts = '') {
  461. $inputid = (empty($CtrlID)) ? wf_InputId() : $CtrlID;
  462. $inputclass = (empty($CtrlClass)) ? '' : ' class="' . $CtrlClass . '"';
  463. $opts = (empty($options)) ? '' : ' ' . $options . ' ';
  464. if ($br) {
  465. $newline = '<br>';
  466. } else {
  467. $newline = '';
  468. }
  469. $result = '<select name="' . $name . '" id="' . $inputid . '"' . $inputclass . $options . '>';
  470. if (!empty($params)) {
  471. ($sort) ? asort($params) : $params;
  472. foreach ($params as $value => $eachparam) {
  473. $flag_selected = (($selected == $value) and ($selected != '')) ? 'SELECTED' : ''; // !='' because 0 values possible
  474. $result .= '<option value="' . $value . '" ' . $flag_selected . '>' . $eachparam . '</option>' . "\n";
  475. }
  476. }
  477. $result .= '</select>' . "\n";
  478. if ($label != '') {
  479. $labelOpts = (empty($labelOpts) ? '' : $labelOpts);
  480. $labelStr = '<label for="' . $inputid . '" ' . $labelOpts . '>' . __($label) . '</label>';
  481. if ($labelLeftSide) {
  482. $result = $labelStr . ' ' . $result . "\n";
  483. } else {
  484. $result .= ' ' . $labelStr . "\n";
  485. }
  486. }
  487. $result .= $newline . "\n";
  488. return ($result);
  489. }
  490. /**
  491. * Return select Web From element
  492. *
  493. * @param string $name
  494. * @param array $params
  495. * @param string $label
  496. * @param string $selected
  497. * @param bool $br
  498. * @param string $class
  499. * @return string
  500. */
  501. function wf_SelectorClassed($name, $params, $label, $selected = '', $br = false, $class = '') {
  502. $inputid = wf_InputId();
  503. if ($br) {
  504. $newline = '<br>';
  505. } else {
  506. $newline = '';
  507. }
  508. $result = '<select name="' . $name . '" id="' . $inputid . '" class="' . $class . '">';
  509. if (!empty($params)) {
  510. foreach ($params as $value => $eachparam) {
  511. $sel_flag = '';
  512. if ($selected != '') {
  513. if ($selected == $value) {
  514. $sel_flag = 'SELECTED';
  515. }
  516. }
  517. $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
  518. }
  519. }
  520. $result .= '</select>' . "\n";
  521. if ($label != '') {
  522. $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  523. }
  524. $result .= $newline . "\n";
  525. return ($result);
  526. }
  527. /**
  528. * Return select Web From element with auto click option
  529. *
  530. * @param string $name name of element
  531. * @param array $params array of elements $value=>$option
  532. * @param string $label text label for input
  533. * @param string $selected selected $value for selector
  534. * @param bool $br append new line
  535. * @return string
  536. *
  537. */
  538. function wf_SelectorAC($name, $params, $label, $selected = '', $br = false) {
  539. $inputid = wf_InputId();
  540. if ($br) {
  541. $newline = '<br>';
  542. } else {
  543. $newline = '';
  544. }
  545. $result = '<select name="' . $name . '" id="' . $inputid . '" onChange="this.form.submit();">';
  546. if (!empty($params)) {
  547. foreach ($params as $value => $eachparam) {
  548. $sel_flag = '';
  549. if ($selected != '') {
  550. if ($selected == $value) {
  551. $sel_flag = 'SELECTED';
  552. }
  553. }
  554. $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
  555. }
  556. }
  557. $result .= '</select>' . "\n";
  558. if ($label != '') {
  559. $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  560. }
  561. $result .= $newline . "\n";
  562. return ($result);
  563. }
  564. /**
  565. * Return select Web From element with auto click option into ajax container
  566. *
  567. * @param string $container name of container element
  568. * @param array $params array of elements $url=>$option
  569. * @param string $label text label for input
  570. * @param string $selected selected $value for selector
  571. * @param bool $br append new line
  572. * @param string $options some raw custom options
  573. *
  574. * @return string
  575. *
  576. */
  577. function wf_AjaxSelectorAC($container, $params, $label, $selected = '', $br = false, $options = '') {
  578. $inputid = wf_InputId();
  579. if ($br) {
  580. $newline = '<br>';
  581. } else {
  582. $newline = '';
  583. }
  584. $result = '<select name="' . $inputid . '" id="' . $inputid . '" onChange="this.options[this.selectedIndex].onclick();" ' . $options . '>';
  585. if (!empty($params)) {
  586. foreach ($params as $value => $eachparam) {
  587. $sel_flag = '';
  588. if ($selected != '') {
  589. if ($selected == $value) {
  590. $sel_flag = 'SELECTED';
  591. }
  592. }
  593. $result .= '<option value="' . $value . '" ' . $sel_flag . ' onclick="goajax(\'' . $value . '\',\'' . $container . '\');">' . $eachparam . '</option>' . "\n";
  594. }
  595. }
  596. $result .= '</select>' . "\n";
  597. if ($label != '') {
  598. $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  599. }
  600. $result .= $newline . "\n";
  601. return ($result);
  602. }
  603. /**
  604. * Return Month select Web From element
  605. *
  606. * @param string $name name of element
  607. * @param string $label text label for input
  608. * @param string $selected selected $value for selector
  609. * @param bool $br append new line
  610. * @param bool $allTime appends month '1488' to the end of selector
  611. *
  612. * @return string
  613. */
  614. function wf_MonthSelector($name, $label, $selected = '', $br = false, $allTime = false) {
  615. $allmonth = months_array();
  616. $params = array();
  617. //localize months
  618. foreach ($allmonth as $monthnum => $monthname) {
  619. $params[$monthnum] = rcms_date_localise($monthname);
  620. }
  621. $inputid = wf_InputId();
  622. if ($br) {
  623. $newline = '<br>';
  624. } else {
  625. $newline = '';
  626. }
  627. $result = '<select name="' . $name . '" id="' . $inputid . '">';
  628. if (!empty($params)) {
  629. foreach ($params as $value => $eachparam) {
  630. $sel_flag = '';
  631. if ($selected != '') {
  632. if ($selected == $value) {
  633. $sel_flag = 'SELECTED';
  634. }
  635. }
  636. $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
  637. }
  638. }
  639. if ($allTime) {
  640. $selectedM = ($selected == '1488') ? 'SELECTED' : ''; // yep, this required to passing vf() checks and empty() checks.
  641. $result .= '<option value="1488" ' . $selectedM . '>' . __('All time') . '</option>';
  642. }
  643. $result .= '</select>' . "\n";
  644. if ($label != '') {
  645. $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  646. }
  647. $result .= $newline . "\n";
  648. return ($result);
  649. }
  650. /**
  651. * Return Year select Web From element
  652. *
  653. * @param string $name name of element
  654. * @param string $label text label for input
  655. * @param bool $br append new line
  656. * @return string
  657. *
  658. */
  659. function wf_YearSelector($name, $label = '', $br = false) {
  660. $curyear = curyear();
  661. $inputid = wf_InputId();
  662. $count = (date("Y") - 2007);
  663. if ($br) {
  664. $newline = '<br>';
  665. } else {
  666. $newline = '';
  667. }
  668. $selector = '<select name="' . $name . '" id="' . $inputid . '">';
  669. for ($i = 0; $i < $count; $i++) {
  670. $selector .= '<option value="' . ($curyear - $i) . '">' . ($curyear - $i) . '</option>';
  671. }
  672. $selector .= '</select>';
  673. if ($label != '') {
  674. $selector .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  675. }
  676. $selector .= $newline;
  677. return ($selector);
  678. }
  679. /**
  680. * Return Year select Web From element
  681. *
  682. * @param string $name name of element
  683. * @param string $label text label for input
  684. * @param bool $br append new line
  685. * @param int $year selected year
  686. * @param int $allTime as last year equal 1488
  687. *
  688. * @return string
  689. *
  690. */
  691. function wf_YearSelectorPreset($name, $label = '', $br = false, $year = '', $allTime = false) {
  692. $curyear = curyear();
  693. $inputid = wf_InputId();
  694. $count = (date("Y") - 2007);
  695. $selected = '';
  696. if ($br) {
  697. $newline = '<br>';
  698. } else {
  699. $newline = '';
  700. }
  701. $selector = '<select name="' . $name . '" id="' . $inputid . '">';
  702. for ($i = 0; $i < $count; $i++) {
  703. $selected = (($curyear - $i) == $year) ? 'SELECTED' : '';
  704. $selector .= '<option value="' . ($curyear - $i) . '" ' . $selected . '>' . ($curyear - $i) . '</option>';
  705. }
  706. if ($allTime) {
  707. $selected = ($year == '1488') ? 'SELECTED' : ''; // yep, this required to passing vf() checks and empty() checks.
  708. $selector .= '<option value="1488" ' . $selected . '>' . __('All time') . '</option>';
  709. }
  710. $selector .= '</select>';
  711. if ($label != '') {
  712. $selector .= '<label for="' . $inputid . '">' . __($label) . '</label>';
  713. }
  714. $selector .= $newline;
  715. return ($selector);
  716. }
  717. /**
  718. * Check for POST have needed variables
  719. *
  720. * @param array $params array of POST variables to check
  721. * @return bool
  722. *
  723. */
  724. function wf_CheckPost($params) {
  725. $result = true;
  726. if (!empty($params)) {
  727. foreach ($params as $eachparam) {
  728. if (isset($_POST[$eachparam])) {
  729. if (empty($_POST[$eachparam])) {
  730. $result = false;
  731. }
  732. } else {
  733. $result = false;
  734. }
  735. }
  736. }
  737. return ($result);
  738. }
  739. /**
  740. * Check for GET have needed variables
  741. *
  742. * @param array $params array of GET variables to check
  743. * @return bool
  744. *
  745. */
  746. function wf_CheckGet($params) {
  747. $result = true;
  748. if (!empty($params)) {
  749. foreach ($params as $eachparam) {
  750. if (isset($_GET[$eachparam])) {
  751. if (empty($_GET[$eachparam])) {
  752. $result = false;
  753. }
  754. } else {
  755. $result = false;
  756. }
  757. }
  758. }
  759. return ($result);
  760. }
  761. /**
  762. * Returns boolean representation of variable like boolval() in PHP 5.5+
  763. * but also can check if variable contains strings 'true' and 'false'
  764. * and return appropriate value
  765. *
  766. * @param mixed $Variable
  767. * @param bool $CheckAsTrueFalseStr
  768. *
  769. * @return bool
  770. */
  771. function wf_getBoolFromVar($Variable, $CheckAsTrueFalseStr = false) {
  772. if (isset($Variable)) {
  773. if (empty($Variable)) {
  774. return false;
  775. }
  776. } else {
  777. return false;
  778. }
  779. if ($CheckAsTrueFalseStr) {
  780. if (strtolower($Variable) === 'true' || strtolower($Variable) === '1') {
  781. return true;
  782. }
  783. if (strtolower($Variable) === 'false' || strtolower($Variable) === '0') {
  784. return false;
  785. }
  786. } else {
  787. return !!$Variable;
  788. }
  789. }
  790. /**
  791. * Returns true if $value is empty() or null but not equals to 0 or '0'
  792. *
  793. * @param string $value
  794. *
  795. * @return bool
  796. */
  797. function wf_emptyNonZero($value = '') {
  798. return ((empty($value) and $value !== 0 and $value !== '0') ? true : false);
  799. }
  800. /**
  801. * Construct HTML table row element
  802. *
  803. * @param string $cells table row cells
  804. * @param string $class table row class
  805. * @return string
  806. *
  807. */
  808. function wf_TableRow($cells, $class = '') {
  809. if ($class != '') {
  810. $rowclass = 'class="' . $class . '"';
  811. } else {
  812. $rowclass = '';
  813. }
  814. $result = '<tr ' . $rowclass . '>' . $cells . '</tr>' . "\n";
  815. return ($result);
  816. }
  817. /**
  818. * Construct HTML table row element with style inside
  819. *
  820. * @param string $cells table row cells
  821. * @param string $class table row class
  822. * @return string
  823. *
  824. */
  825. function wf_TableRowStyled($cells, $class = '', $style = '') {
  826. if ($class != '') {
  827. $rowclass = 'class="' . $class . '"';
  828. } else {
  829. $rowclass = '';
  830. }
  831. $result = '<tr style="' . $style . '" ' . $rowclass . '>' . $cells . '</tr>' . "\n";
  832. return ($result);
  833. }
  834. /**
  835. * Construct HTML table cell element
  836. *
  837. * @param string $data table cell data
  838. * @param string $width width of cell element
  839. * @param string $class table cell class
  840. * @param string $customkey table cell custom param
  841. * @return string
  842. *
  843. */
  844. function wf_TableCell($data, $width = '', $class = '', $customkey = '', $colspan = '', $rowspan = '') {
  845. if ($width != '') {
  846. $cellwidth = 'width="' . $width . '"';
  847. } else {
  848. $cellwidth = '';
  849. }
  850. if ($class != '') {
  851. $cellclass = 'class="' . $class . '"';
  852. } else {
  853. $cellclass = '';
  854. }
  855. if ($customkey != '') {
  856. $customkey = $customkey;
  857. } else {
  858. $customkey = '';
  859. }
  860. $colspan = (empty($colspan)) ? '' : 'colspan="' . $colspan . '"';
  861. $rowspan = (empty($rowspan)) ? '' : 'rowspan="' . $rowspan . '"';
  862. $result = '<td ' . $cellwidth . ' ' . $cellclass . ' ' . $customkey . ' ' . $colspan . ' ' . $rowspan . '>' . $data . '</td>' . "\n";
  863. return ($result);
  864. }
  865. /**
  866. * Construct HTML table body
  867. *
  868. * @param string $rows table rows data
  869. * @param string $width width of cell element
  870. * @param string $border table border width
  871. * @param string $class table cell class
  872. * @param string $options table additional options
  873. * @return string
  874. *
  875. */
  876. function wf_TableBody($rows, $width = '', $border = '0', $class = '', $options = '') {
  877. if ($width != '') {
  878. $tablewidth = 'width="' . $width . '"';
  879. } else {
  880. $tablewidth = '';
  881. }
  882. if ($class != '') {
  883. $tableclass = 'class="' . $class . '"';
  884. } else {
  885. $tableclass = '';
  886. }
  887. if ($border != '') {
  888. $tableborder = 'border="' . $border . '"';
  889. } else {
  890. $tableborder = '';
  891. }
  892. $result = '
  893. <table ' . $tablewidth . ' ' . $tableborder . ' ' . $tableclass . ' ' . $options . ' >
  894. ' . $rows . '
  895. </table>
  896. ';
  897. return ($result);
  898. }
  899. /**
  900. * Returns JS confirmation url
  901. *
  902. * @param string $url URL if confirmed
  903. * @param string $title link title
  904. * @param string $alerttext alert text
  905. * @param string $functiontorun function name with parameters which must exist on a page
  906. * @param string $class link class
  907. *
  908. * @return string
  909. *
  910. */
  911. function wf_JSAlert($url, $title, $alerttext, $functiontorun = '', $class = '') {
  912. $class = (empty($class)) ? '' : 'class="' . $class . '"';
  913. if (empty($functiontorun)) {
  914. $result = '<a ' . $class . ' onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;}" href="' . $url . '">' . $title . '</a>';
  915. } else {
  916. $result = '<a ' . $class . ' onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;} else { ' . $functiontorun . '; return false; }" href="' . $url . '">' . $title . '</a>';
  917. }
  918. return ($result);
  919. }
  920. /**
  921. * Returns JS confirmation url with some applied class
  922. *
  923. * @param string $url URL if confirmed
  924. * @param string $title link title
  925. * @param string $alerttext alert text
  926. * @param string $functiontorun function name with parameters which must exist on a page
  927. *
  928. * @return string
  929. *
  930. */
  931. function wf_JSAlertStyled($url, $title, $alerttext, $class = '', $functiontorun = '') {
  932. $class = (!empty($class)) ? 'class="' . $class . '"' : '';
  933. if (empty($functiontorun)) {
  934. $result = '<a onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;}" href="' . $url . '" ' . $class . '>' . $title . '</a>';
  935. } else {
  936. $result = '<a onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;} else { ' . $functiontorun . '; }" href="' . $url . '" ' . $class . '>' . $title . '</a>';
  937. }
  938. return ($result);
  939. }
  940. /**
  941. * Returns standard paginator widget
  942. *
  943. * @param int $total Total items count
  944. * @param int $perpage Per page items count
  945. * @param int $current current page
  946. * @param string $link module link which use paginator
  947. * @param string $class page links class
  948. * @param int $maxAmount maximun amount of pages to render
  949. *
  950. * @return string
  951. */
  952. function wf_pagination($total, $perpage, $current, $link, $class = '', $maxAmount = 0) {
  953. if ($class != '') {
  954. $pageclass = 'class="' . $class . '"';
  955. } else {
  956. $pageclass = '';
  957. }
  958. $return = '';
  959. $link = preg_replace("/((&amp;|&)page=(\d*))/", '', $link);
  960. if (!empty($perpage)) {
  961. $pages = ceil($total / $perpage);
  962. if ($pages != 1) {
  963. $c = 1;
  964. while ($c <= $pages) {
  965. $renderPageLink = true;
  966. if (!empty($maxAmount)) {
  967. if ($pages > $maxAmount) {
  968. if ($c > $maxAmount) {
  969. $renderPageLink = false;
  970. if ($c == $pages) {
  971. //last page
  972. $return .= '...';
  973. $renderPageLink = true;
  974. }
  975. if (($current) >= ($maxAmount)) {
  976. if ($c == ($current + 1)) {
  977. $renderPageLink = true;
  978. }
  979. if ($c == ($current - 1) or ($c == ($current))) {
  980. $renderPageLink = true;
  981. }
  982. }
  983. }
  984. }
  985. }
  986. if ($renderPageLink) {
  987. if ($c != $current) {
  988. $return .= ' ' . '<a href="' . $link . '&amp;page=' . $c . '" ' . $pageclass . '>' . $c . '</a> ';
  989. } else {
  990. $return .= ' ' . '<a href="#" ' . $pageclass . ' style="color: #ff0000;">' . $c . '</a> ';
  991. }
  992. if ($c == $maxAmount) {
  993. $return .= '...';
  994. }
  995. }
  996. $c++;
  997. }
  998. }
  999. }
  1000. return ($return);
  1001. }
  1002. /**
  1003. * Returns image body
  1004. *
  1005. * @param string $url image url
  1006. * @param string $title image title
  1007. * @param string $style image custom styling
  1008. *
  1009. * @return string
  1010. */
  1011. function wf_img($url, $title = '', $style = '') {
  1012. if ($title != '') {
  1013. $imgtitle = 'title="' . $title . '"';
  1014. } else {
  1015. $imgtitle = '';
  1016. }
  1017. $imgstyle = (empty($style)) ? '' : ' style="' . $style . '" ';
  1018. $result = '<img src="' . $url . '" ' . $imgtitle . $imgstyle . ' border="0">';
  1019. return ($result);
  1020. }
  1021. /**
  1022. * Returns image body with some dimensions
  1023. *
  1024. * @param string $url image url
  1025. * @param string $title title attribure for image
  1026. * @param string $width image width
  1027. * @param string $height image height
  1028. * @param string $style image custom styling
  1029. *
  1030. * @return string
  1031. */
  1032. function wf_img_sized($url, $title = '', $width = '', $height = '', $style = '') {
  1033. $imgtitle = ($title != '') ? 'title="' . $title . '"' : '';
  1034. $imgwidth = ($width != '') ? 'width="' . $width . '"' : '';
  1035. $imgheight = ($height != '') ? 'height="' . $height . '"' : '';
  1036. $imgstyle = (empty($style)) ? '' : ' style="' . $style . '" ';
  1037. $result = '<img src="' . $url . '" ' . $imgtitle . ' ' . $imgwidth . ' ' . $imgheight . $imgstyle . ' border="0">';
  1038. return ($result);
  1039. }
  1040. /**
  1041. * Returns link that calls new modal window
  1042. *
  1043. * @param string $link link text
  1044. * @param string $title modal window title
  1045. * @param string $content modal window content
  1046. * @param string $linkclass link class
  1047. * @param string $width modal window width
  1048. * @param string $height modal window height
  1049. *
  1050. * @return string
  1051. */
  1052. function wf_modal($link, $title, $content, $linkclass = '', $width = '', $height = '') {
  1053. $wid = wf_inputid();
  1054. //setting link class
  1055. if ($linkclass != '') {
  1056. $link_class = 'class="' . $linkclass . '"';
  1057. } else {
  1058. $link_class = '';
  1059. }
  1060. //setting auto width if not specified
  1061. if ($width == '') {
  1062. $width = '600';
  1063. }
  1064. //setting auto height if not specified
  1065. if ($height == '') {
  1066. $height = '400';
  1067. }
  1068. $dialog = '
  1069. <script type="text/javascript">
  1070. $(function() {
  1071. $( "#dialog-modal_' . $wid . '" ).dialog({
  1072. autoOpen: false,
  1073. width: ' . $width . ',
  1074. height: ' . $height . ',
  1075. modal: true,
  1076. show: "drop",
  1077. hide: "fold"
  1078. });
  1079. $( "#opener_' . $wid . '" ).click(function() {
  1080. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  1081. return false;
  1082. });
  1083. });
  1084. </script>
  1085. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  1086. <p>
  1087. ' . $content . '
  1088. </p>
  1089. </div>
  1090. <a href="#" id="opener_' . $wid . '" ' . $link_class . '>' . $link . '</a>
  1091. ';
  1092. return ($dialog);
  1093. }
  1094. /**
  1095. * Returns link that calls new modal window with automatic dimensions by inside content
  1096. *
  1097. * @param string $link link text
  1098. * @param string $title modal window title
  1099. * @param string $content modal window content
  1100. * @param string $linkclass link class
  1101. * @param string $windowID
  1102. *
  1103. * @return string
  1104. *
  1105. */
  1106. function wf_modalAuto($link, $title, $content, $linkclass = '', $windowID = '') {
  1107. $wid = (empty($windowID) ? 'dialog-modal_' . wf_inputid() : $windowID);
  1108. //setting link class
  1109. if ($linkclass != '') {
  1110. $link_class = 'class="' . $linkclass . '"';
  1111. } else {
  1112. $link_class = '';
  1113. }
  1114. $width = "'auto'";
  1115. $height = "'auto'";
  1116. $dialog = '
  1117. <script type="text/javascript">
  1118. $(function() {
  1119. $( "#' . $wid . '" ).dialog({
  1120. autoOpen: false,
  1121. width: \'auto\',
  1122. height: \'auto\',
  1123. modal: true,
  1124. show: "drop",
  1125. hide: "fold"
  1126. });
  1127. $( "#opener_' . $wid . '" ).click(function() {
  1128. $( "#' . $wid . '" ).dialog( "open" );
  1129. return false;
  1130. });
  1131. });
  1132. </script>
  1133. <div id="' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  1134. <p>
  1135. ' . $content . '
  1136. </p>
  1137. </div>
  1138. <a href="#" id="opener_' . $wid . '" ' . $link_class . '>' . $link . '</a>
  1139. ';
  1140. return ($dialog);
  1141. }
  1142. /**
  1143. * Returns link that calls new modal window with automatic dimensions by inner content and without "opener" object
  1144. *
  1145. * @param string $Title
  1146. * @param string $Content
  1147. * @param string $WindowID
  1148. * @param string $WindowBodyID
  1149. * @param bool $DestroyOnClose
  1150. * @param string $AutoOpen
  1151. * @param string $Width
  1152. * @param string $Height
  1153. *
  1154. * @return string
  1155. */
  1156. function wf_modalAutoForm($Title, $Content, $WindowID = '', $WindowBodyID = '', $DestroyOnClose = false, $AutoOpen = 'false', $Width = '', $Height = '') {
  1157. $WID = (empty($WindowID)) ? 'dialog-modal_' . wf_inputid() : $WindowID;
  1158. $WBID = (empty($WindowBodyID)) ? 'body_dialog-modal_' . wf_inputid() : $WindowBodyID;
  1159. if (empty($Width)) {
  1160. $Width = "'auto'";
  1161. }
  1162. if (empty($Height)) {
  1163. $Height = "'auto'";
  1164. }
  1165. $DestroyParams = '';
  1166. if ($DestroyOnClose) {
  1167. $DestroyParams = ',
  1168. close: function(event, ui) {
  1169. $(\'#' . $WID . '\').dialog("destroy");
  1170. $(\'#' . $WID . '\').remove();
  1171. $(\'#script_' . $WID . '\').remove();
  1172. }
  1173. ';
  1174. }
  1175. $Dialog = wf_tag('script', false, '', 'type="text/javascript" id="script_' . $WID . '"');
  1176. $Dialog .= '
  1177. $(function() {
  1178. $(\'#' . $WID . '\').dialog({
  1179. autoOpen: ' . $AutoOpen . ',
  1180. width: ' . $Width . ',
  1181. height: ' . $Height . ',
  1182. modal: true,
  1183. show: "drop",
  1184. hide: "fold"' . $DestroyParams . '
  1185. });
  1186. });
  1187. ';
  1188. $Dialog .= wf_tag('script', true);
  1189. $Dialog .= '
  1190. <div id="' . $WID . '" title="' . $Title . '" style="display:none; width:1px; height:1px;">
  1191. <p id="' . $WBID . '">' . $Content . '</p>
  1192. </div>
  1193. ';
  1194. return $Dialog;
  1195. }
  1196. /**
  1197. * Returns calendar widget
  1198. *
  1199. * @param string $field field name to insert calendar
  1200. * @param bool $extControls extended year and month controls
  1201. *
  1202. * @return string
  1203. *
  1204. */
  1205. function wf_DatePicker($field, $extControls = false) {
  1206. $inputid = wf_InputId();
  1207. $curlang = curlang();
  1208. if ($extControls) {
  1209. $extControls = ',
  1210. changeMonth: true,
  1211. yearRange: "-100:+100",
  1212. changeYear: true';
  1213. } else {
  1214. $extControls = '';
  1215. }
  1216. $result = '<script>
  1217. $(function() {
  1218. $( "#' . $inputid . '" ).datepicker({
  1219. showOn: "both",
  1220. buttonImage: "skins/icon_calendar.gif",
  1221. buttonImageOnly: true,
  1222. dateFormat: "yy-mm-dd",
  1223. showAnim: "slideDown"' . $extControls . '
  1224. });
  1225. $.datepicker.regional[\'en\'] = {
  1226. closeText: \'Done\',
  1227. prevText: \'Prev\',
  1228. nextText: \'Next\',
  1229. currentText: \'Today\',
  1230. monthNames: [\'January\',\'February\',\'March\',\'April\',\'May\',\'June\',
  1231. \'July\',\'August\',\'September\',\'October\',\'November\',\'December\'],
  1232. monthNamesShort: [\'Jan\', \'Feb\', \'Mar\', \'Apr\', \'May\', \'Jun\',
  1233. \'Jul\', \'Aug\', \'Sep\', \'Oct\', \'Nov\', \'Dec\'],
  1234. dayNames: [\'Sunday\', \'Monday\', \'Tuesday\', \'Wednesday\', \'Thursday\', \'Friday\', \'Saturday\'],
  1235. dayNamesShort: [\'Sun\', \'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\', \'Sat\'],
  1236. dayNamesMin: [\'Su\',\'Mo\',\'Tu\',\'We\',\'Th\',\'Fr\',\'Sa\'],
  1237. weekHeader: \'Wk\',
  1238. dateFormat: \'dd/mm/yy\',
  1239. firstDay: 1,
  1240. isRTL: false,
  1241. showMonthAfterYear: false,
  1242. yearSuffix: \'\'};
  1243. $.datepicker.regional[\'ru\'] = {
  1244. closeText: \'Закрыть\',
  1245. prevText: \'&#x3c;Пред\',
  1246. nextText: \'След&#x3e;\',
  1247. currentText: \'Сегодня\',
  1248. monthNames: [\'Январь\',\'Февраль\',\'Март\',\'Апрель\',\'Май\',\'Июнь\',
  1249. \'Июль\',\'Август\',\'Сентябрь\',\'Октябрь\',\'Ноябрь\',\'Декабрь\'],
  1250. monthNamesShort: [\'Янв\',\'Фев\',\'Мар\',\'Апр\',\'Май\',\'Июн\',
  1251. \'Июл\',\'Авг\',\'Сен\',\'Окт\',\'Ноя\',\'Дек\'],
  1252. dayNames: [\'воскресенье\',\'понедельник\',\'вторник\',\'среда\',\'четверг\',\'пятница\',\'суббота\'],
  1253. dayNamesShort: [\'вск\',\'пнд\',\'втр\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
  1254. dayNamesMin: [\'Вс\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
  1255. weekHeader: \'Нед\',
  1256. dateFormat: \'dd.mm.yy\',
  1257. firstDay: 1,
  1258. isRTL: false,
  1259. showMonthAfterYear: false,
  1260. yearSuffix: \'\'};
  1261. $.datepicker.regional[\'uk\'] = {
  1262. closeText: \'Закрити\',
  1263. prevText: \'&#x3c;\',
  1264. nextText: \'&#x3e;\',
  1265. currentText: \'Сьогодні\',
  1266. monthNames: [\'Січень\',\'Лютий\',\'Березень\',\'Квітень\',\'Травень\',\'Червень\',
  1267. \'Липень\',\'Серпень\',\'Вересень\',\'Жовтень\',\'Листопад\',\'Грудень\'],
  1268. monthNamesShort: [\'Січ\',\'Лют\',\'Бер\',\'Кві\',\'Тра\',\'Чер\',
  1269. \'Лип\',\'Сер\',\'Вер\',\'Жов\',\'Лис\',\'Гру\'],
  1270. dayNames: [\'неділя\',\'понеділок\',\'вівторок\',\'середа\',\'четвер\',\'п’ятниця\',\'субота\'],
  1271. dayNamesShort: [\'нед\',\'пнд\',\'вів\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
  1272. dayNamesMin: [\'Нд\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
  1273. weekHeader: \'Тиж\',
  1274. dateFormat: \'dd/mm/yy\',
  1275. firstDay: 1,
  1276. isRTL: false,
  1277. showMonthAfterYear: false,
  1278. yearSuffix: \'\'};
  1279. $.datepicker.setDefaults($.datepicker.regional[\'' . $curlang . '\']);
  1280. });
  1281. </script>
  1282. <input type="text" id="' . $inputid . '" name="' . $field . '" size="10">
  1283. ';
  1284. return ($result);
  1285. }
  1286. /**
  1287. * Returns calendar widget with preset date
  1288. *
  1289. * @param string $field field name to insert calendar
  1290. * @param string $date to set the calendar's value to
  1291. * @param bool $extControls extended year and month controls
  1292. * @param string $CtrlID
  1293. *
  1294. * @return string
  1295. *
  1296. */
  1297. function wf_DatePickerPreset($field, $date, $extControls = false, $CtrlID = '', $ctrlClass = '') {
  1298. $inputid = (empty($CtrlID)) ? wf_InputId() : $CtrlID;
  1299. $class = (empty($ctrlClass)) ? '' : ' class="' . $ctrlClass . '" ';
  1300. $curlang = curlang();
  1301. if ($extControls) {
  1302. $extControls = ',
  1303. changeMonth: true,
  1304. yearRange: "-100:+100",
  1305. changeYear: true';
  1306. } else {
  1307. $extControls = '';
  1308. }
  1309. $result = '<script>
  1310. $(function() {
  1311. $( "#' . $inputid . '" ).datepicker({
  1312. showOn: "both",
  1313. buttonImage: "skins/icon_calendar.gif",
  1314. buttonImageOnly: true,
  1315. dateFormat: "yy-mm-dd",
  1316. showAnim: "slideDown"' . $extControls . '
  1317. });
  1318. $.datepicker.regional[\'en\'] = {
  1319. closeText: \'Done\',
  1320. prevText: \'Prev\',
  1321. nextText: \'Next\',
  1322. currentText: \'Today\',
  1323. monthNames: [\'January\',\'February\',\'March\',\'April\',\'May\',\'June\',
  1324. \'July\',\'August\',\'September\',\'October\',\'November\',\'December\'],
  1325. monthNamesShort: [\'Jan\', \'Feb\', \'Mar\', \'Apr\', \'May\', \'Jun\',
  1326. \'Jul\', \'Aug\', \'Sep\', \'Oct\', \'Nov\', \'Dec\'],
  1327. dayNames: [\'Sunday\', \'Monday\', \'Tuesday\', \'Wednesday\', \'Thursday\', \'Friday\', \'Saturday\'],
  1328. dayNamesShort: [\'Sun\', \'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\', \'Sat\'],
  1329. dayNamesMin: [\'Su\',\'Mo\',\'Tu\',\'We\',\'Th\',\'Fr\',\'Sa\'],
  1330. weekHeader: \'Wk\',
  1331. dateFormat: \'dd/mm/yy\',
  1332. firstDay: 1,
  1333. isRTL: false,
  1334. showMonthAfterYear: false,
  1335. yearSuffix: \'\'};
  1336. $.datepicker.regional[\'ru\'] = {
  1337. closeText: \'Закрыть\',
  1338. prevText: \'&#x3c;Пред\',
  1339. nextText: \'След&#x3e;\',
  1340. currentText: \'Сегодня\',
  1341. monthNames: [\'Январь\',\'Февраль\',\'Март\',\'Апрель\',\'Май\',\'Июнь\',
  1342. \'Июль\',\'Август\',\'Сентябрь\',\'Октябрь\',\'Ноябрь\',\'Декабрь\'],
  1343. monthNamesShort: [\'Янв\',\'Фев\',\'Мар\',\'Апр\',\'Май\',\'Июн\',
  1344. \'Июл\',\'Авг\',\'Сен\',\'Окт\',\'Ноя\',\'Дек\'],
  1345. dayNames: [\'воскресенье\',\'понедельник\',\'вторник\',\'среда\',\'четверг\',\'пятница\',\'суббота\'],
  1346. dayNamesShort: [\'вск\',\'пнд\',\'втр\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
  1347. dayNamesMin: [\'Вс\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
  1348. weekHeader: \'Нед\',
  1349. dateFormat: \'dd.mm.yy\',
  1350. firstDay: 1,
  1351. isRTL: false,
  1352. showMonthAfterYear: false,
  1353. yearSuffix: \'\'};
  1354. $.datepicker.regional[\'uk\'] = {
  1355. closeText: \'Закрити\',
  1356. prevText: \'&#x3c;\',
  1357. nextText: \'&#x3e;\',
  1358. currentText: \'Сьогодні\',
  1359. monthNames: [\'Січень\',\'Лютий\',\'Березень\',\'Квітень\',\'Травень\',\'Червень\',
  1360. \'Липень\',\'Серпень\',\'Вересень\',\'Жовтень\',\'Листопад\',\'Грудень\'],
  1361. monthNamesShort: [\'Січ\',\'Лют\',\'Бер\',\'Кві\',\'Тра\',\'Чер\',
  1362. \'Лип\',\'Сер\',\'Вер\',\'Жов\',\'Лис\',\'Гру\'],
  1363. dayNames: [\'неділя\',\'понеділок\',\'вівторок\',\'середа\',\'четвер\',\'п’ятниця\',\'субота\'],
  1364. dayNamesShort: [\'нед\',\'пнд\',\'вів\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
  1365. dayNamesMin: [\'Нд\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
  1366. weekHeader: \'Тиж\',
  1367. dateFormat: \'dd/mm/yy\',
  1368. firstDay: 1,
  1369. isRTL: false,
  1370. showMonthAfterYear: false,
  1371. yearSuffix: \'\'};
  1372. $.datepicker.setDefaults($.datepicker.regional[\'' . $curlang . '\']);
  1373. });
  1374. </script>
  1375. <input type="text" id="' . $inputid . '" name="' . $field . '" value="' . $date . '" size="10" ' . $class . '>
  1376. ';
  1377. return ($result);
  1378. }
  1379. /**
  1380. * Returns FullCalendar widget
  1381. *
  1382. * @param string $data prepeared data to show
  1383. * @param string $options
  1384. * @param bool $useHTMLInTitle
  1385. * @param bool $useHTMLListViewOnly
  1386. * @param string $ajaxURLForDnD
  1387. * @param bool $saveViewState
  1388. *
  1389. * @return string
  1390. */
  1391. function wf_FullCalendar($data, $options = '', $useHTMLInTitle = false, $useHTMLListViewOnly = false, $ajaxURLForDnD = '', $saveViewState = false) {
  1392. global $ubillingConfig;
  1393. $elementid = wf_InputId();
  1394. $dragdropON = ($ubillingConfig->getAlterParam('CALENDAR_DRAG_AND_DROP_ON') and !empty($ajaxURLForDnD));
  1395. $dndConfirmON = $ubillingConfig->getAlterParam('CALENDAR_DRAG_AND_DROP_CONFIRM_ON');
  1396. $titlesSearchON = $ubillingConfig->getAlterParam('CALENDAR_TITLES_SEARCH_ON');
  1397. $viewLoad = '';
  1398. $viewSetup = '';
  1399. $viewSave = '';
  1400. if ($saveViewState) {
  1401. $viewLoad = "var savedView = localStorage.getItem('calendarView') || 'month';";
  1402. $viewSetup = "defaultView: savedView,";
  1403. $viewSave = ",viewRender: function(view) {
  1404. localStorage.setItem('calendarView', view.name);
  1405. }";
  1406. }
  1407. if ($useHTMLInTitle) {
  1408. if ($useHTMLListViewOnly) {
  1409. $htmlInTitle = " eventRender: function(event, element, view) {
  1410. if (view.type.indexOf('list') >= 0) {
  1411. var link = element.find('[class*=-title] a');
  1412. var title = element.find('[class*=-title]');
  1413. link.html(title.text());
  1414. title.html( link );
  1415. } else {
  1416. var title = element.find('[class*=-title]');
  1417. // some hack to remove HTML from text
  1418. var doc = new DOMParser().parseFromString(title.text(), 'text/html');
  1419. var titleText = (doc.body.textContent || \"\");
  1420. title.html( titleText );
  1421. }
  1422. }, ";
  1423. } else {
  1424. $htmlInTitle = " eventRender: function(event, element, view) {
  1425. if (view.type.indexOf('list') >= 0) {
  1426. var link = element.find('[class*=-title] a');
  1427. var title = element.find('[class*=-title]');
  1428. link.html(title.text());
  1429. title.html( link );
  1430. } else {
  1431. var title = element.find('[class*=-title]');
  1432. title.html( title.text() );
  1433. }
  1434. }, ";
  1435. }
  1436. } else {
  1437. $htmlInTitle = '';
  1438. }
  1439. $calendar = "<script type='text/javascript'>
  1440. $(document).ready(function() {
  1441. var date = new Date();
  1442. var d = date.getDate();
  1443. var m = date.getMonth();
  1444. var y = date.getFullYear();
  1445. " . $viewLoad . "
  1446. $('#" . $elementid . "').fullCalendar({
  1447. header: {
  1448. left: 'prev,next today',
  1449. center: 'title',
  1450. right: 'month,basicWeek,basicDay,listMonth'
  1451. },
  1452. editable: " . ($dragdropON ? "true" : "false") . ",
  1453. " . $htmlInTitle . "
  1454. theme: true,
  1455. weekends: true,
  1456. timeFormat: 'H(:mm)',
  1457. displayEventTime: false,
  1458. height: 'auto',
  1459. contentHeight: 'auto',
  1460. " . $viewSetup . "
  1461. " . $options . "
  1462. monthNamesShort: [
  1463. '" . rcms_date_localise('Jan') . "',
  1464. '" . rcms_date_localise('Feb') . "',
  1465. '" . rcms_date_localise('Mar') . "',
  1466. '" . rcms_date_localise('Apr') . "',
  1467. '" . rcms_date_localise('May') . "',
  1468. '" . rcms_date_localise('Jun') . "',
  1469. '" . rcms_date_localise('Jul') . "',
  1470. '" . rcms_date_localise('Aug') . "',
  1471. '" . rcms_date_localise('Sep') . "',
  1472. '" . rcms_date_localise('Oct') . "',
  1473. '" . rcms_date_localise('Nov') . "',
  1474. '" . rcms_date_localise('Dec') . "'
  1475. ],
  1476. monthNames: [
  1477. '" . rcms_date_localise('January') . "',
  1478. '" . rcms_date_localise('February') . "',
  1479. '" . rcms_date_localise('March') . "',
  1480. '" . rcms_date_localise('April') . "',
  1481. '" . rcms_date_localise('May') . "',
  1482. '" . rcms_date_localise('June') . "',
  1483. '" . rcms_date_localise('July') . "',
  1484. '" . rcms_date_localise('August') . "',
  1485. '" . rcms_date_localise('September') . "',
  1486. '" . rcms_date_localise('October') . "',
  1487. '" . rcms_date_localise('November') . "',
  1488. '" . rcms_date_localise('December') . "'
  1489. ],
  1490. dayNamesShort: [
  1491. '" . rcms_date_localise('Sun') . "',
  1492. '" . rcms_date_localise('Mon') . "',
  1493. '" . rcms_date_localise('Tue') . "',
  1494. '" . rcms_date_localise('Wed') . "',
  1495. '" . rcms_date_localise('Thu') . "',
  1496. '" . rcms_date_localise('Fri') . "',
  1497. '" . rcms_date_localise('Sat') . "'
  1498. ],
  1499. dayNames: [
  1500. '" . rcms_date_localise('Sunday') . "',
  1501. '" . rcms_date_localise('Monday') . "',
  1502. '" . rcms_date_localise('Tuesday') . "',
  1503. '" . rcms_date_localise('Wednesday') . "',
  1504. '" . rcms_date_localise('Thursday') . "',
  1505. '" . rcms_date_localise('Friday') . "',
  1506. '" . rcms_date_localise('Saturday') . "'
  1507. ],
  1508. buttonText: {
  1509. today: '" . __('Today') . "',
  1510. month: '" . __('Month') . "',
  1511. week: '" . __('Week') . "',
  1512. day: '" . __('Day') . "',
  1513. list: '" . __('List') . "'
  1514. },
  1515. events: [
  1516. " . $data . "
  1517. ]
  1518. " . $viewSave . "
  1519. });
  1520. });
  1521. </script>
  1522. <div id='" . $elementid . "'></div>
  1523. ";
  1524. $jsCalendarDnD = '';
  1525. $jsCalendarSrchFill = '';
  1526. $jsCalendarSearch = '';
  1527. $appendJS = '';
  1528. if ($dragdropON) {
  1529. $jsCalendarDnDCancel = " event.start = eventPrevStartDT;
  1530. $('#" . $elementid . "').fullCalendar('updateEvent', event);
  1531. console.log(objID + ' Start time change canceled');
  1532. ";
  1533. $jsCalendarDnDMain = " // need to convert to local time to prevent adding timezone offset hours adding after drop
  1534. var mm = moment(event.start);
  1535. mm.local();
  1536. event.start = mm;
  1537. var newStartDT = event.start.format('YYYY-MM-DD HH:mm:ss');
  1538. $.ajax({
  1539. type: \"POST\",
  1540. url: \"" . $ajaxURLForDnD . "\",
  1541. data: {object_id: objID, new_start_time: newStartDT},
  1542. success: function(reqResult) {
  1543. // 'SUCCESS' must be returned as a result of the request
  1544. // to indicate that event datetime was actually changed
  1545. // otherwise DnD operation will be reverted
  1546. if (reqResult == 'SUCCESS') {
  1547. console.log(objID + ' Start time changed');
  1548. } else {
  1549. " . $jsCalendarDnDCancel . "
  1550. }
  1551. }
  1552. });
  1553. ";
  1554. if ($dndConfirmON) {
  1555. $jsCalendarDnD = "
  1556. calendar.on('eventDrop', function(event, delta, revertFunc, jsEvent, ui, view) {
  1557. var objID = event.id;
  1558. if (empty(objID)) {
  1559. " . $jsCalendarDnDCancel . "
  1560. return false;
  1561. }
  1562. if (confirm('" . __('Do you confirm the movement of this event?') . "')) {
  1563. " . $jsCalendarDnDMain . "
  1564. } else {
  1565. " . $jsCalendarDnDCancel . "
  1566. }
  1567. });
  1568. ";
  1569. } else {
  1570. $jsCalendarDnD = "
  1571. calendar.on('eventDrop', function(event, delta, revertFunc, jsEvent, ui, view) {
  1572. var objID = event.id;
  1573. if (empty(objID)) {
  1574. " . $jsCalendarDnDCancel . "
  1575. return false;
  1576. }
  1577. " . $jsCalendarDnDMain . "
  1578. });
  1579. ";
  1580. }
  1581. }
  1582. if ($titlesSearchON) {
  1583. $jsCalendarSrchFill = "$('#calendarSource').val(JSON.stringify(calendar.clientEvents(), ['id', 'title', 'start', 'end', 'url', 'className', 'allDay']));";
  1584. $jsCalendarSearch = "
  1585. $('#calendarSearchInput').on('change keyup', function() {
  1586. var searchWords = this.value.toLowerCase().split(' ');
  1587. var source = JSON.parse($('#calendarSource').val());
  1588. var newSource = source.filter(elem => {
  1589. var titleStr = elem.title.toLowerCase();
  1590. return searchWords.every(item => titleStr.includes(item));
  1591. });
  1592. // converting UTC datetime back to our timezone
  1593. newSource.forEach(item => {
  1594. var dtStart = item.start;
  1595. item.start = new Date(dtStart);
  1596. });
  1597. refreshCalendar(newSource);
  1598. });
  1599. function refreshCalendar(newSource) {
  1600. $('#" . $elementid . "').fullCalendar('removeEvents');
  1601. $('#" . $elementid . "').fullCalendar('addEventSource', newSource);
  1602. $('#" . $elementid . "').fullCalendar('refetchEvents');
  1603. }
  1604. ";
  1605. }
  1606. if ($titlesSearchON or $dragdropON) {
  1607. $appendJS = "
  1608. <script type='text/javascript'>
  1609. // global scope var to save the event's initial start datetime on DragNDrop operation start
  1610. // to be used for DnD cancelation if confirmation is ON
  1611. var eventPrevStartDT = '';
  1612. $(function() {
  1613. var calendar = $('#" . $elementid . "').fullCalendar('getCalendar');
  1614. " . $jsCalendarSrchFill . "
  1615. calendar.on('eventDragStart', function(event, jsEvent, ui, view) {
  1616. eventPrevStartDT = event.start.format();
  1617. });
  1618. " . $jsCalendarDnD . "
  1619. });
  1620. " . $jsCalendarSearch . "
  1621. " . wf_JSEmptyFunc() . "
  1622. </script>
  1623. ";
  1624. $calendar .= $appendJS;
  1625. }
  1626. if ($titlesSearchON) {
  1627. $calendar .= "\n" . wf_HiddenInput('calendarsource', '', 'calendarSource');
  1628. $calendar = wf_TextInput('searchcalendar', __('Calendar events titles filter') . ':' . wf_nbsp(2), '', true, '', '', 'glamour', 'calendarSearchInput', 'style="width: 70%; float: none !important"', true, 'style="font-size: 1.1em; margin-left: 5px; font-weight: bold;"')
  1629. . wf_delimiter() . $calendar;
  1630. }
  1631. return ($calendar);
  1632. }
  1633. /**
  1634. * Returns div plate with some content
  1635. *
  1636. * @param string $content Data to include into plate widget
  1637. * @param string $width Widget width
  1638. * @param string $height Widget height
  1639. * @param string $class Widget class to assign
  1640. * @param string $opts Widget style options. Do not include style="..."
  1641. *
  1642. * @return string
  1643. */
  1644. function wf_Plate($content, $width = '', $height = '', $class = '', $opts = '') {
  1645. if ($width != '') {
  1646. $width = 'width: ' . $width . ';';
  1647. }
  1648. if ($height != '') {
  1649. $height = 'height: ' . $height . ';';
  1650. }
  1651. if ($class != '') {
  1652. $class = 'class="' . $class . '"';
  1653. }
  1654. $result = '
  1655. <div style="' . $width . ' ' . $height . ' float: left; ' . $opts . ' " ' . $class . '>
  1656. ' . $content . '
  1657. </div>
  1658. ';
  1659. return ($result);
  1660. }
  1661. /**
  1662. * Returns some count of delimiters
  1663. *
  1664. * @param int $count count of delimited rows
  1665. * @return string
  1666. *
  1667. */
  1668. function wf_delimiter($count = 1) {
  1669. $result = '';
  1670. for ($i = 0; $i <= $count; $i++) {
  1671. $result .= '<br />';
  1672. }
  1673. return ($result);
  1674. }
  1675. /**
  1676. * Returns some html styled tag
  1677. *
  1678. * @param int $tag HTML tag entity
  1679. * @param bool $closed tag is closing?
  1680. * @param string $class tag styling class
  1681. * @param string $options tag extra options
  1682. * @return string
  1683. *
  1684. */
  1685. function wf_tag($tag, $closed = false, $class = '', $options = '') {
  1686. if (!empty($class)) {
  1687. $tagclass = ' class="' . $class . '"';
  1688. } else {
  1689. $tagclass = '';
  1690. }
  1691. if ($closed) {
  1692. $tagclose = '/';
  1693. } else {
  1694. $tagclose = '';
  1695. }
  1696. if ($options != '') {
  1697. $tagoptions = $options;
  1698. } else {
  1699. $tagoptions = '';
  1700. }
  1701. $result = '<' . $tagclose . $tag . $tagclass . ' ' . $tagoptions . '>';
  1702. return ($result);
  1703. }
  1704. /**
  1705. * Constructs and returns default AJAX loader
  1706. *
  1707. * @param bool $noAnimation
  1708. *
  1709. * @return string
  1710. */
  1711. function wf_AjaxLoader($noAnimation = false) {
  1712. if ($noAnimation) {
  1713. $animationCode = '';
  1714. } else {
  1715. $animationCode = 'contentElem.innerHTML = \'<img src="skins/ajaxloader.gif" id="ubajaxloaderanim">\';';
  1716. }
  1717. $result = '
  1718. <script type="text/javascript">
  1719. function getXmlHttp()
  1720. {
  1721. var xmlhttp;
  1722. try
  1723. {
  1724. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  1725. }
  1726. catch (e)
  1727. {
  1728. try
  1729. {
  1730. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  1731. }
  1732. catch (E)
  1733. {
  1734. xmlhttp = false;
  1735. }
  1736. }
  1737. if(!xmlhttp && typeof XMLHttpRequest!=\'undefined\')
  1738. {
  1739. xmlhttp = new XMLHttpRequest();
  1740. }
  1741. return xmlhttp;
  1742. }
  1743. function goajax(link,container)
  1744. {
  1745. var myrequest = getXmlHttp()
  1746. var docum = link;
  1747. var contentElem = document.getElementById(container);
  1748. myrequest.open(\'POST\', docum, true);
  1749. myrequest.setRequestHeader(\'Content-Type\', \'application/x-www-form-urlencoded\');
  1750. ' . $animationCode . '
  1751. myrequest.onreadystatechange = function()
  1752. {
  1753. if (myrequest.readyState == 4)
  1754. {
  1755. if(myrequest.status == 200)
  1756. {
  1757. var resText = myrequest.responseText;
  1758. var ua = navigator.userAgent.toLowerCase();
  1759. if (ua.indexOf(\'gecko\') != -1)
  1760. {
  1761. var range = contentElem.ownerDocument.createRange();
  1762. range.selectNodeContents(contentElem);
  1763. range.deleteContents();
  1764. var fragment = range.createContextualFragment(resText);
  1765. contentElem.appendChild(fragment);
  1766. }
  1767. else
  1768. {
  1769. contentElem.innerHTML = resText;
  1770. }
  1771. }
  1772. else
  1773. {
  1774. contentElem.innerHTML = \'' . __('Error') . '\';
  1775. }
  1776. }
  1777. }
  1778. myrequest.send();
  1779. }
  1780. </script>
  1781. ';
  1782. return ($result);
  1783. }
  1784. /**
  1785. * Returns default ajax container div element
  1786. *
  1787. * @param string $containerName container name aka ID
  1788. * @param string $options misc options like size/display if required
  1789. * @param string $content default container content
  1790. *
  1791. * @return string
  1792. */
  1793. function wf_AjaxContainer($containerName, $options = '', $content = '') {
  1794. $result = wf_tag('div', false, '', 'id="' . $containerName . '" ' . $options . ' ') . $content . wf_tag('div', true);
  1795. return ($result);
  1796. }
  1797. /**
  1798. * Returns default ajax container span element
  1799. *
  1800. * @param string $containerName container name aka ID
  1801. * @param string $options misc options like size/display if required
  1802. * @param srring $content default container content
  1803. *
  1804. * @return string
  1805. */
  1806. function wf_AjaxContainerSpan($containerName, $options = '', $content = '') {
  1807. $result = wf_tag('span', false, '', 'id="' . $containerName . '" ' . $options . ' ') . $content . wf_tag('span', true);
  1808. return ($result);
  1809. }
  1810. /**
  1811. * Returns new opened modal window with some content
  1812. *
  1813. * @param string $title modal window title
  1814. * @param string $content modal window content
  1815. * @param string $width modal window width
  1816. * @param string $height modal window height
  1817. * @return string
  1818. *
  1819. */
  1820. function wf_modalOpened($title, $content, $width = '', $height = '') {
  1821. $wid = wf_inputid();
  1822. //setting auto width if not specified
  1823. if ($width == '') {
  1824. $width = '600';
  1825. }
  1826. //setting auto width if not specified
  1827. if ($height == '') {
  1828. $height = '400';
  1829. }
  1830. $dialog = '
  1831. <script type="text/javascript">
  1832. $(function() {
  1833. $( "#dialog-modal_' . $wid . '" ).dialog({
  1834. autoOpen: true,
  1835. width: ' . $width . ',
  1836. height: ' . $height . ',
  1837. modal: true,
  1838. show: "drop",
  1839. hide: "fold"
  1840. });
  1841. $( "#opener_' . $wid . '" ).click(function() {
  1842. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  1843. return false;
  1844. });
  1845. });
  1846. </script>
  1847. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  1848. <p>
  1849. ' . $content . '
  1850. </p>
  1851. </div>
  1852. ';
  1853. return ($dialog);
  1854. }
  1855. /**
  1856. * Returns new opened modal window with some content and automatic sizes
  1857. *
  1858. * @param string $title modal window title
  1859. * @param string $content modal window content
  1860. *
  1861. * @return string
  1862. */
  1863. function wf_modalOpenedAuto($title, $content) {
  1864. $wid = wf_inputid();
  1865. $width = "'auto'";
  1866. $height = "'auto'";
  1867. $dialog = '
  1868. <script type="text/javascript">
  1869. $(function() {
  1870. $( "#dialog-modal_' . $wid . '" ).dialog({
  1871. autoOpen: true,
  1872. width: ' . $width . ',
  1873. height: ' . $height . ',
  1874. modal: true,
  1875. show: "drop",
  1876. hide: "fold"
  1877. });
  1878. $( "#opener_' . $wid . '" ).click(function() {
  1879. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  1880. return false;
  1881. });
  1882. });
  1883. </script>
  1884. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  1885. <p>
  1886. ' . $content . '
  1887. </p>
  1888. </div>
  1889. ';
  1890. return ($dialog);
  1891. }
  1892. /**
  1893. * Returns Chart source
  1894. *
  1895. * @param string $data - CSV formatted data
  1896. * @param string $widht - graph width in pixels
  1897. * @param string $height - graph height in pixels
  1898. * @param bool $errorbars - display error bars around data series
  1899. *
  1900. * @return string
  1901. */
  1902. function wf_Graph($data, $width = '500', $height = '300', $errorbars = false, $GraphTitle = '', $XLabel = '', $YLabel = '', $RangeSelector = false) {
  1903. $randomId = wf_InputId();
  1904. $objectId = 'graph_' . $randomId;
  1905. $data = trim($data);
  1906. $data = explodeRows($data);
  1907. $cleandata = '';
  1908. if ($errorbars) {
  1909. $errorbars = 'true';
  1910. } else {
  1911. $errorbars = 'false';
  1912. }
  1913. if (!empty($data)) {
  1914. foreach ($data as $eachrow) {
  1915. $cleandata .= '"' . trim($eachrow) . '\n" +' . "\n";
  1916. }
  1917. $cleandata = mb_substr($cleandata, 0, -2, 'utf-8');
  1918. }
  1919. //style="width: 98%; "
  1920. $result = wf_tag('div', false, '', 'id="' . $randomId . '" style="width:' . $width . 'px; height:' . $height . 'px;"') . wf_tag('div', true);
  1921. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  1922. $result .= $objectId . ' = new Dygraph(';
  1923. $result .= 'document.getElementById("' . $randomId . '"),' . "\n";
  1924. $result .= $cleandata;
  1925. $result .= ', { errorBars: ' . $errorbars;
  1926. $result .= (!empty($GraphTitle)) ? ', title: \'' . $GraphTitle . '\'' : '';
  1927. $result .= (!empty($XLabel)) ? ', xlabel: \'' . $XLabel . '\'' : '';
  1928. $result .= (!empty($YLabel)) ? ', ylabel: \'' . $YLabel . '\'' : '';
  1929. $result .= (!empty($RangeSelector)) ? ', showRangeSelector: true' : '';
  1930. $result .= ' }' . "\n";
  1931. $result .= ');';
  1932. $result .= wf_tag('script', true);
  1933. return ($result);
  1934. }
  1935. /**
  1936. * Returns Chart source by data loaded from the file - acceptable for huge data sets
  1937. *
  1938. * @param string $datafile - existing CSV file path
  1939. * @param string $widht - graph width in pixels
  1940. * @param string $height - graph height in pixels
  1941. * @param bool $errorbars - display error bars around data series
  1942. *
  1943. * @return string
  1944. */
  1945. function wf_GraphCSV($datafile, $width = '500', $height = '300', $errorbars = false, $GraphTitle = '', $XLabel = '', $YLabel = '', $RangeSelector = false) {
  1946. $randomId = wf_InputId();
  1947. $objectId = 'graph_' . $randomId;
  1948. if ($errorbars) {
  1949. $errorbars = 'true';
  1950. } else {
  1951. $errorbars = 'false';
  1952. }
  1953. $result = wf_tag('div', false, '', 'id="' . $randomId . '" style="width:' . $width . 'px; height:' . $height . 'px;"') . wf_tag('div', true);
  1954. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  1955. $result .= $objectId . ' = new Dygraph(';
  1956. $result .= 'document.getElementById("' . $randomId . '"), "' . $datafile . '" ' . "\n";
  1957. $result .= ', { errorBars: ' . $errorbars;
  1958. $result .= (!empty($GraphTitle)) ? ', title: \'' . $GraphTitle . '\'' : '';
  1959. $result .= (!empty($XLabel)) ? ', xlabel: \'' . $XLabel . '\'' : '';
  1960. $result .= (!empty($YLabel)) ? ', ylabel: \'' . $YLabel . '\'' : '';
  1961. $result .= (!empty($RangeSelector)) ? ', showRangeSelector: true' : '';
  1962. $result .= ' }' . "\n";
  1963. $result .= ');';
  1964. $result .= wf_tag('script', true);
  1965. return ($result);
  1966. }
  1967. /**
  1968. * Returns color picker dialog
  1969. *
  1970. * @param string $name input name
  1971. * @param string $label input text label
  1972. * @param string $value input pre setted data
  1973. * @param bool $br add line break after input?
  1974. * @param string $size size of element
  1975. * @param string $changeCtrlColorID ID of the control which color will be changed to selected color
  1976. * @param string $changeCtrlColorCSSProp the CSS3 color-property which will be assigned to selected color
  1977. * (like: background-color, border-color, etc)
  1978. *
  1979. * @return string
  1980. */
  1981. function wf_ColPicker($name, $label = '', $value = '', $br = false, $size = '', $changeCtrlColorID = '', $changeCtrlColorCSSProp = '') {
  1982. $id = wf_InputId();
  1983. if (!empty($changeCtrlColorID) and !empty($changeCtrlColorCSSProp)) {
  1984. $changeCtrlColorJS = ' $(\'#' . $changeCtrlColorID . '\').css("' . $changeCtrlColorCSSProp . '", "#" + hex_str);';
  1985. } else {
  1986. $changeCtrlColorJS = '';
  1987. }
  1988. $css = '
  1989. <link rel="stylesheet" href="modules/jsc/colpick/colpick.css" type="text/css"/>';
  1990. $js = '
  1991. <script src="modules/jsc/colpick/colpick.js" type="text/javascript"></script>
  1992. <script type="text/javascript">
  1993. $(document).ready(function() {
  1994. $("#' . $id . '").colpick({
  1995. colorScheme: "light",
  1996. layout: "hex",
  1997. submit: true,
  1998. color: "' . (!empty($value) ? $value : "#f57601") . '",
  1999. onSubmit: function(hsb,hex,rgb,el) {
  2000. var colpickID = $(el).colpick().data("colpickId");
  2001. var hex_str = $("#" + colpickID + " div.colpick_hex_field > input").val();
  2002. $(el).val("#" + hex_str);
  2003. $(el).colpickHide();
  2004. $(el).focus();
  2005. ' . $changeCtrlColorJS . '
  2006. },
  2007. onChange: function(hsb,hex,rgb,el) {
  2008. var hex_str = hex;
  2009. ' . $changeCtrlColorJS . '
  2010. }
  2011. });
  2012. });
  2013. </script>
  2014. ';
  2015. if (!empty($changeCtrlColorJS)) {
  2016. $tmpJS = '
  2017. $(document).ready(function() {
  2018. var colpickID = $("#' . $id . '").colpick().data("colpickId");
  2019. var hex_str = $("#" + colpickID + " div.colpick_hex_field > input").val();
  2020. ' . $changeCtrlColorJS . '
  2021. });
  2022. ';
  2023. $js .= wf_EncloseWithJSTags($tmpJS);
  2024. }
  2025. $size = (!empty($size)) ? 'size="' . $size . '"' : null;
  2026. $result = '<input type="text" name="' . $name . '" value="' . $value . '" id="' . $id . '" ' . $size . '>' . "\n";
  2027. $result .= (!empty($label)) ? '<label for="' . $id . '">' . __($label) . '</label>' : null;
  2028. $result .= (!empty($br)) ? '<br>' : null;
  2029. $result .= "\n";
  2030. return $css . $js . $result;
  2031. }
  2032. /**
  2033. * Return Jquery UI selectable combobox
  2034. *
  2035. * @param string $name name of element
  2036. * @param array $params array of elements $value=>$option
  2037. * @param string $label text label for input
  2038. * @param string $selected selected $value for selector (now ignored)
  2039. * @param bool $br append new line
  2040. * @return string
  2041. *
  2042. */
  2043. function wf_JuiComboBox($name, $params, $label, $selected = '', $br = false) {
  2044. $id = wf_InputId();
  2045. $select = '';
  2046. if (!empty($params)) {
  2047. foreach ($params as $io => $each) {
  2048. $flag_selected = (!empty($selected) and $selected == $io) ? 'SELECTED' : '';
  2049. $select .= '<option value="' . $io . '" ' . $flag_selected . '>' . $each . '</option>' . "\n";
  2050. }
  2051. }
  2052. $result = '
  2053. <style>
  2054. .custom-combobox_' . $id . ' {
  2055. position: relative;
  2056. display: inline-block;
  2057. }
  2058. .custom-combobox-toggle_' . $id . ' {
  2059. position: absolute;
  2060. top: 0;
  2061. bottom: 0;
  2062. margin-left: -1px;
  2063. padding: 0;
  2064. }
  2065. .custom-combobox-input_' . $id . ' {
  2066. margin: 0;
  2067. padding: 5px 10px;
  2068. }
  2069. .ui-autocomplete {
  2070. max-height: 400px;
  2071. overflow-y: auto; /* prevent horizontal scrollbar */
  2072. overflow-x: hidden; /* add padding to account for vertical scrollbar */
  2073. z-index:1000 !important;
  2074. }
  2075. </style>
  2076. <script>
  2077. (function( $ ) {
  2078. $.widget( "custom.combobox_' . $id . '", {
  2079. _create: function() {
  2080. this.wrapper = $( "<span>" )
  2081. .addClass( "custom-combobox_' . $id . '" )
  2082. .insertAfter( this.element );
  2083. this.element.hide();
  2084. this._createAutocomplete();
  2085. this._createShowAllButton();
  2086. },
  2087. _createAutocomplete: function() {
  2088. var selected = this.element.children( ":selected" ),
  2089. value = selected.val() ? selected.text() : "";
  2090. this.input = $( "<input>" )
  2091. .appendTo( this.wrapper )
  2092. .val( value )
  2093. .attr( "title", "" )
  2094. .addClass( "custom-combobox-input_' . $id . ' ui-widget_' . $id . ' ui-widget-content ui-state-default ui-corner-left" )
  2095. .autocomplete({
  2096. delay: 0,
  2097. minLength: 0,
  2098. source: $.proxy( this, "_source" )
  2099. })
  2100. .tooltip({
  2101. tooltipClass: "ui-state-highlight"
  2102. });
  2103. this._on( this.input, {
  2104. autocompleteselect: function( event, ui ) {
  2105. ui.item.option.selected = true;
  2106. this._trigger( "select", event, {
  2107. item: ui.item.option
  2108. });
  2109. },
  2110. autocompletechange: "_removeIfInvalid"
  2111. });
  2112. },
  2113. _createShowAllButton: function() {
  2114. var input = this.input,
  2115. wasOpen = false;
  2116. $( "<a>" )
  2117. .attr( "tabIndex", -1 )
  2118. .attr( "title", "' . __('Show all') . '" )
  2119. .tooltip()
  2120. .appendTo( this.wrapper )
  2121. .button({
  2122. icons: {
  2123. primary: "ui-icon-triangle-1-s"
  2124. },
  2125. text: false
  2126. })
  2127. .removeClass( "ui-corner-all" )
  2128. .addClass( "custom-combobox-toggle_' . $id . ' ui-corner-right" )
  2129. .mousedown(function() {
  2130. wasOpen = input.autocomplete( "widget" ).is( ":visible" );
  2131. })
  2132. .click(function() {
  2133. input.focus();
  2134. // Close if already visible
  2135. if ( wasOpen ) {
  2136. return;
  2137. }
  2138. // Pass empty string as value to search for, displaying all results
  2139. input.autocomplete( "search", "" );
  2140. });
  2141. },
  2142. _source: function( request, response ) {
  2143. var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
  2144. response( this.element.children( "option" ).map(function() {
  2145. var text = $( this ).text();
  2146. if ( this.value && ( !request.term || matcher.test(text) ) )
  2147. return {
  2148. label: text,
  2149. value: text,
  2150. option: this
  2151. };
  2152. }) );
  2153. },
  2154. _removeIfInvalid: function( event, ui ) {
  2155. // Selected an item, nothing to do
  2156. if ( ui.item ) {
  2157. return;
  2158. }
  2159. // Search for a match (case-insensitive)
  2160. var value = this.input.val(),
  2161. valueLowerCase = value.toLowerCase(),
  2162. valid = false;
  2163. this.element.children( "option" ).each(function() {
  2164. if ( $( this ).text().toLowerCase() === valueLowerCase ) {
  2165. this.selected = valid = true;
  2166. return false;
  2167. }
  2168. });
  2169. // Found a match, nothing to do
  2170. if ( valid ) {
  2171. return;
  2172. }
  2173. this.input.autocomplete( "instance" ).term = "";
  2174. },
  2175. _destroy: function() {
  2176. this.wrapper.remove();
  2177. this.element.show();
  2178. }
  2179. });
  2180. })( jQuery );
  2181. $(function() {
  2182. $( "#combobox_' . $id . '" ).combobox_' . $id . '();
  2183. });
  2184. </script>
  2185. <div class="ui-widget_' . $id . '">
  2186. <label for="combobox_' . $id . '">' . $label . '</label>
  2187. <select id="combobox_' . $id . '" name=' . $name . '>
  2188. ' . $select . '
  2189. </select>
  2190. </div>
  2191. ';
  2192. if ($br) {
  2193. $result .= wf_tag('br');
  2194. }
  2195. return ($result);
  2196. }
  2197. /**
  2198. * Returns auto complete text input element
  2199. *
  2200. * @param string $name name of element
  2201. * @param array $data data array for autocomplete box
  2202. * @param string $label text label for input
  2203. * @param string $value current value
  2204. * @param bool $br append new line - bool
  2205. * @param string $size input size
  2206. * @return string
  2207. *
  2208. */
  2209. function wf_AutocompleteTextInput($name, $data = array(), $label = '', $value = '', $br = false, $size = '') {
  2210. $inputid = wf_InputId();
  2211. //set size
  2212. if ($size != '') {
  2213. $input_size = 'size="' . $size . '"';
  2214. } else {
  2215. $input_size = '';
  2216. }
  2217. if ($br) {
  2218. $newline = '<br>';
  2219. } else {
  2220. $newline = '';
  2221. }
  2222. $acData = '';
  2223. $autocomplete = '<script>
  2224. $(function() {
  2225. var availableOpts_' . $inputid . ' = [
  2226. ';
  2227. if (!empty($data)) {
  2228. foreach ($data as $io => $each) {
  2229. $each = str_replace('"', '`', $each);
  2230. $acData .= '"' . $each . '",';
  2231. }
  2232. }
  2233. //removing ending coma
  2234. $acData = mb_substr($acData, 0, -1, 'UTF-8');
  2235. $autocomplete .= $acData;
  2236. $autocomplete .= '
  2237. ];
  2238. $( "#' . $name . '_autocomplete" ).autocomplete({
  2239. source: availableOpts_' . $inputid . '
  2240. });
  2241. });
  2242. </script>';
  2243. $result = $autocomplete;
  2244. $result .= '<input type="text" id="' . $name . '_autocomplete" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
  2245. if ($label != '') {
  2246. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  2247. }
  2248. $result .= $newline . "\n";
  2249. return ($result);
  2250. }
  2251. /**
  2252. * Returns calendar widget with preset time
  2253. * Based on Jon Thornton's jquery timepicker: http://jonthornton.github.io/jquery-timepicker
  2254. *
  2255. * @param string $field field name to insert time select widget
  2256. * @param string $time default value time for widget
  2257. * @param string $DisabledTimeRanges string which represents time ranges unavailable to pick up, like: "['11:00', '14:05'], ['20:30', '21:00']" and so on
  2258. * @param string $label label of widget
  2259. * @param bool $br add break after the widget body?
  2260. * @return string
  2261. */
  2262. function wf_TimePickerPreset($field, $time = '', $label = '', $br = false, $DisabledTimeRanges = '') {
  2263. $inputId = wf_InputId();
  2264. if (isset($DisabledTimeRanges)) {
  2265. $DisabledTimeRanges = ',\'disableTimeRanges\': [ ' . $DisabledTimeRanges . ']';
  2266. }
  2267. $result = wf_tag('input', false, '', 'type="text" value="' . $time . '" name="' . $field . '" size="5" id="' . $inputId . '"');
  2268. $result .= wf_tag('script');
  2269. $result .= '$(\'#' . $inputId . '\').timepicker({\'scrollDefault\': \'' . $time . '\', \'timeFormat\': \'H:i\'' . $DisabledTimeRanges . ' });';
  2270. $result .= wf_tag('script', true);
  2271. //clickable icon and label
  2272. if (!empty($label)) {
  2273. $label = ' ' . __($label);
  2274. }
  2275. $result .= wf_tag('label', false, '', 'for="' . $inputId . '"') . wf_img('skins/icon_time_small.png', __('Time')) . $label . wf_tag('label', true);
  2276. //break at end
  2277. if ($br) {
  2278. $result .= wf_tag('br');
  2279. }
  2280. return ($result);
  2281. }
  2282. /**
  2283. * Returns calendar widget with preset time
  2284. * Based on Jon Thornton's jquery timepicker: http://jonthornton.github.io/jquery-timepicker
  2285. *
  2286. * @param string $field field name to insert time select widget
  2287. * @param string $time default value time for widget
  2288. * @param string $DisabledTimeRanges string which represents time ranges unavailable to pick up, like: "['11:00', '14:05'], ['20:30', '21:00']" and so on
  2289. * @param string $label label of widget
  2290. * @param bool $br add break after the widget body?
  2291. * @return string
  2292. */
  2293. function wf_TimePickerPresetSeconds($field, $time = '', $label = '', $br = false, $DisabledTimeRanges = '') {
  2294. $inputId = wf_InputId();
  2295. if (isset($DisabledTimeRanges)) {
  2296. $DisabledTimeRanges = ',\'disableTimeRanges\': [ ' . $DisabledTimeRanges . ']';
  2297. }
  2298. $result = wf_tag('input', false, '', 'type="text" value="' . $time . '" name="' . $field . '" size="8" id="' . $inputId . '"');
  2299. $result .= wf_tag('script');
  2300. $result .= '$(\'#' . $inputId . '\').timepicker({\'scrollDefault\': \'' . $time . '\', \'timeFormat\': \'H:i:s\'' . $DisabledTimeRanges . ' });';
  2301. $result .= wf_tag('script', true);
  2302. //clickable icon and label
  2303. if (!empty($label)) {
  2304. $label = ' ' . __($label);
  2305. }
  2306. $result .= wf_tag('label', false, '', 'for="' . $inputId . '"') . wf_img('skins/icon_time_small.png', __('Time')) . $label . wf_tag('label', true);
  2307. //break at end
  2308. if ($br) {
  2309. $result .= wf_tag('br');
  2310. }
  2311. return ($result);
  2312. }
  2313. /**
  2314. * Returns div with styles cleanup
  2315. *
  2316. * @return string
  2317. */
  2318. function wf_CleanDiv() {
  2319. $result = wf_tag('div', false, '', 'style="clear:both;"') . wf_tag('div', true);
  2320. return ($result);
  2321. }
  2322. /**
  2323. * Renders JQuery Data Table with some embedded data
  2324. *
  2325. * @param array $columns columns names array
  2326. * @param string $data data array to render
  2327. * @param bool $saveState grid state saving - conflicts with default sort order
  2328. * @param string $objects object names
  2329. * @param int $rowsCount rows count to default display
  2330. * @param string $opts additional options like:
  2331. * "order": [[ 0, "desc" ]]
  2332. * or
  2333. * dom: \'Bfrtipsl\', buttons: [\'copy\', \'csv\', \'excel\', \'pdf\', \'print\']
  2334. * or "dom": \'<"F"lfB>rti<"F"ps>\', buttons: [\'csv\', \'excel\', \'pdf\', \'print\']
  2335. * @param bool $addFooter
  2336. * @param string $footerOpts
  2337. * @param string $footerTHOpts
  2338. *
  2339. * @return string
  2340. */
  2341. function wf_JqDtEmbed($columns, $dataArr, $saveState = false, $objects = 'users', $rowsCount = 100, $opts = '', $addFooter = false, $footerOpts = '', $footerTHOpts = '') {
  2342. $jsArr = array();
  2343. $jsArr = json_encode($dataArr);
  2344. $tableId = 'jqdte_' . wf_InputId();
  2345. $result = '';
  2346. $saveState = ($saveState) ? 'true' : 'false';
  2347. $opts = (!empty($opts)) ? $opts . ',' : '';
  2348. $lenMenu = '[[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "' . __('All') . '"]]';
  2349. $jq_dt = wf_tag('script', false, '', ' type="text/javascript" charset="utf-8"');
  2350. $jq_dt .= '
  2351. $(document).ready(function() {
  2352. var data=' . $jsArr . '
  2353. var table=$(\'#' . $tableId . '\').dataTable( {
  2354. "oLanguage": {
  2355. "sLengthMenu": "' . __('Show') . ' _MENU_",
  2356. "sZeroRecords": "' . __('Nothing found') . '",
  2357. "sInfo": "' . __('Showing') . ' _START_ ' . __('to') . ' _END_ ' . __('of') . ' _TOTAL_ ' . __($objects) . '",
  2358. "sInfoEmpty": "' . __('Showing') . ' 0 ' . __('to') . ' 0 ' . __('of') . ' 0 ' . __($objects) . '",
  2359. "sInfoFiltered": "(' . __('Filtered') . ' ' . __('from') . ' _MAX_ ' . __('Total') . ')",
  2360. "sSearch": "' . __('Search') . '",
  2361. "sProcessing": "' . __('Processing') . '...",
  2362. "oPaginate": {
  2363. "sFirst": "' . __('First') . '",
  2364. "sPrevious": "' . __('Previous') . '",
  2365. "sNext": "' . __('Next') . '",
  2366. "sLast": "' . __('Last') . '"
  2367. },
  2368. },
  2369. "bPaginate": true,
  2370. "bLengthChange": true,
  2371. "bFilter": true,
  2372. "bSort": true,
  2373. "bInfo": true,
  2374. "bAutoWidth": false,
  2375. "bProcessing": true,
  2376. "bStateSave": ' . $saveState . ',
  2377. "iDisplayLength": ' . $rowsCount . ',
  2378. "data": data,
  2379. "bDeferRender": true,
  2380. "lengthMenu": ' . $lenMenu . ',
  2381. ' . $opts . '
  2382. "bJQueryUI": true
  2383. } );
  2384. } );
  2385. ';
  2386. $jq_dt .= wf_tag('script', true);
  2387. $result = $jq_dt;
  2388. $result .= wf_tag('table', false, 'display compact', 'id="' . $tableId . '"');
  2389. $result .= wf_tag('thead', false);
  2390. $tablecells = '';
  2391. $footerCells = '<tfoot ' . $footerOpts . '><tr>';
  2392. foreach ($columns as $io => $eachColumn) {
  2393. $tablecells .= wf_TableCell(__($eachColumn));
  2394. if ($addFooter) {
  2395. $footerCells .= '<th ' . $footerTHOpts . '></th>';
  2396. }
  2397. }
  2398. $result .= wf_TableRow($tablecells);
  2399. $result .= wf_tag('thead', true);
  2400. if ($addFooter) {
  2401. $result .= $footerCells . '</tr></tfoot>';
  2402. }
  2403. $result .= wf_tag('table', true);
  2404. return ($result);
  2405. }
  2406. /**
  2407. * Renders JQuery Data Tables container
  2408. *
  2409. * @param array $columns columns names array
  2410. * @param string $ajaxUrl URL to fetch JSON data
  2411. * @param bool $saveState grid state saving - conflicts with default sort order
  2412. * @param string $objects object names
  2413. * @param int $rowsCount rows count to default display
  2414. * @param string $opts additional options like:
  2415. * "order": [[ 0, "desc" ]]
  2416. * or
  2417. * dom: \'Bfrtipsl\', buttons: [\'copy\', \'csv\', \'excel\', \'pdf\', \'print\']
  2418. * or "dom": \'<"F"lfB>rti<"F"ps>\', buttons: [\'csv\', \'excel\', \'pdf\', \'print\']
  2419. * @param bool $addFooter
  2420. * @param string $footerOpts
  2421. * @param string $footerTHOpts
  2422. * @param bool $serverSide Use server-side processing?
  2423. *
  2424. * @return string
  2425. */
  2426. function wf_JqDtLoader($columns, $ajaxUrl, $saveState = false, $objects = 'users', $rowsCount = 100, $opts = '', $addFooter = false, $footerOpts = '', $footerTHOpts = '', $serverSide = false) {
  2427. $tableId = 'jqdt_' . md5($ajaxUrl);
  2428. $result = '';
  2429. $saveState = ($saveState) ? 'true' : 'false';
  2430. $opts = (!empty($opts)) ? $opts . ',' : '';
  2431. $sside = ($serverSide) ? '"serverSide": true,' : '';
  2432. $lenMenu = ($serverSide) ? '[[10, 25, 50, 100, 200], [10, 25, 50, 100, 200]]' : '[[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "' . __('All') . '"]]';
  2433. $jq_dt = wf_tag('script', false, '', ' type="text/javascript" charset="utf-8"');
  2434. $jq_dt .= '
  2435. $(document).ready(function() {
  2436. var table=$(\'#' . $tableId . '\').dataTable( {
  2437. "oLanguage": {
  2438. "sLengthMenu": "' . __('Show') . ' _MENU_",
  2439. "sZeroRecords": "' . __('Nothing found') . '",
  2440. "sInfo": "' . __('Showing') . ' _START_ ' . __('to') . ' _END_ ' . __('of') . ' _TOTAL_ ' . __($objects) . '",
  2441. "sInfoEmpty": "' . __('Showing') . ' 0 ' . __('to') . ' 0 ' . __('of') . ' 0 ' . __($objects) . '",
  2442. "sInfoFiltered": "(' . __('Filtered') . ' ' . __('from') . ' _MAX_ ' . __('Total') . ')",
  2443. "sSearch": "' . __('Search') . '",
  2444. "sProcessing": "' . __('Processing') . '...",
  2445. "oPaginate": {
  2446. "sFirst": "' . __('First') . '",
  2447. "sPrevious": "' . __('Previous') . '",
  2448. "sNext": "' . __('Next') . '",
  2449. "sLast": "' . __('Last') . '"
  2450. },
  2451. },
  2452. "bPaginate": true,
  2453. "bLengthChange": true,
  2454. "bFilter": true,
  2455. "bSort": true,
  2456. "bInfo": true,
  2457. "bAutoWidth": false,
  2458. "bProcessing": true,
  2459. "bStateSave": ' . $saveState . ',
  2460. "iDisplayLength": ' . $rowsCount . ',
  2461. "sAjaxSource": \'' . $ajaxUrl . '\',
  2462. "bDeferRender": true,
  2463. ' . $sside . '
  2464. "lengthMenu": ' . $lenMenu . ',
  2465. ' . $opts . '
  2466. "bJQueryUI": true
  2467. } );
  2468. } );
  2469. ';
  2470. $jq_dt .= wf_tag('script', true);
  2471. $result = $jq_dt;
  2472. $result .= wf_tag('table', false, 'display compact', 'id="' . $tableId . '"');
  2473. $result .= wf_tag('thead', false);
  2474. $tablecells = '';
  2475. $footerCells = '<tfoot ' . $footerOpts . '><tr>';
  2476. foreach ($columns as $io => $eachColumn) {
  2477. $tablecells .= wf_TableCell(__($eachColumn));
  2478. if ($addFooter) {
  2479. $footerCells .= '<th ' . $footerTHOpts . '></th>';
  2480. }
  2481. }
  2482. $result .= wf_TableRow($tablecells);
  2483. $result .= wf_tag('thead', true);
  2484. if ($addFooter) {
  2485. $result .= $footerCells . '</tr></tfoot>';
  2486. }
  2487. $result .= wf_tag('table', true);
  2488. return ($result);
  2489. }
  2490. /**
  2491. * Returns a JS snippet to control the visibility of JQDT column
  2492. *
  2493. * @param string $CallerObjID
  2494. * @param string $CallerObjEvent
  2495. * @param string $JQDTID
  2496. * @param int $ColIndex
  2497. *
  2498. * @return string
  2499. */
  2500. function wf_JQDTColumnHideShow($CallerObjID, $CallerObjEvent, $JQDTID, $ColIndex) {
  2501. $JSCode = '$(\'#' . $CallerObjID . '\').on("' . $CallerObjEvent . '", function() {
  2502. // Get the column API object
  2503. var column = $(\'#' . $JQDTID . '\').DataTable().column(' . $ColIndex . ');
  2504. // Toggle the visibility
  2505. column.visible( !column.visible() );
  2506. });
  2507. ';
  2508. return $JSCode;
  2509. }
  2510. /**
  2511. * Returns a JS snippet for .row().show() plugin
  2512. *
  2513. * @return string
  2514. */
  2515. function wf_JQDTRowShowPluginJS() {
  2516. $jsCode = '
  2517. $.fn.dataTable.Api.register(\'row().show()\', function() {
  2518. var page_info = this.table().page.info();
  2519. // Get row index
  2520. var new_row_index = this.index();
  2521. // Row position
  2522. var row_position = this.table()
  2523. .rows({ search: \'applied\' })[0]
  2524. .indexOf(new_row_index);
  2525. // Already on right page ?
  2526. if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) {
  2527. // Return row object
  2528. return this;
  2529. }
  2530. // Find page number
  2531. var page_to_display = Math.floor(row_position / this.table().page.len());
  2532. // Go to that page
  2533. this.table().page(page_to_display);
  2534. // Return row object
  2535. return this;
  2536. });
  2537. ';
  2538. return ($jsCode);
  2539. }
  2540. /**
  2541. * Returns a JS snippet for column footer sum() plugin
  2542. *
  2543. * @return string
  2544. */
  2545. function wf_JQDTColumnTotalSumJS() {
  2546. $jsCode = '
  2547. jQuery.fn.dataTable.Api.register( \'sum()\', function ( ) {
  2548. return this.flatten().reduce( function ( a, b ) {
  2549. if ( typeof a === \'string\' ) {
  2550. a = a.replace(/[^\d.-]/g, \'\') * 1;
  2551. }
  2552. if ( typeof b === \'string\' ) {
  2553. b = b.replace(/[^\d.-]/g, \'\') * 1;
  2554. }
  2555. return a + b;
  2556. }, 0 );
  2557. } );
  2558. ';
  2559. return ($jsCode);
  2560. }
  2561. /**
  2562. * Returns a JS snippet for markdown the row with searched value
  2563. *
  2564. * @param string|int $columnNum
  2565. * @param string $searchVal
  2566. * @param string $truncateURL
  2567. * @param string $truncateParam
  2568. *
  2569. * @return string
  2570. */
  2571. function wf_JQDTMarkRowJS($columnNum, $searchVal, $truncateURL = '', $truncateParam = '') {
  2572. $truncateJSCode = '';
  2573. if (!empty($truncateURL) and !empty($truncateParam)) {
  2574. $truncateJSCode = '
  2575. //var urlParamsObject = new URLSearchParams(\'' . $truncateURL . '\');
  2576. var urlParamsObject = new URLSearchParams(window.location.search);
  2577. if (urlParamsObject.has(\'' . $truncateParam . '\')) {
  2578. urlParamsObject.delete(\'' . $truncateParam . '\');
  2579. var truncatedURL = window.location.origin + window.location.pathname + "?" + urlParamsObject.toString();
  2580. window.history.replaceState({}, document.title, truncatedURL);
  2581. }
  2582. ';
  2583. }
  2584. $result = '
  2585. $(document).ready( function () {
  2586. var table = $(\'[id ^= "jqdt_"][role = "grid"]\').DataTable();
  2587. table.on( \'init\', function () {
  2588. var row = table.row(function ( idx, data, node ) {
  2589. return data[' . $columnNum . '] == \'' . $searchVal . '\';
  2590. });
  2591. if (row.length > 0) {
  2592. row.select().show().draw(false);
  2593. }
  2594. });
  2595. ' . $truncateJSCode . '
  2596. });
  2597. ';
  2598. return ($result);
  2599. }
  2600. /**
  2601. * Retruns a JS snippet for processing JQDT "details" functional
  2602. *
  2603. * @param $ajaxURL - URL to retrive data into "details" DIV
  2604. * @param $colIndex - above-level JQDT column index to get the AJAX data from
  2605. * @param $jqdtID - above-level JQDT DOM ID
  2606. * @param string $ajaxMethod
  2607. * @param string $jsFuncName - JS function name which will be called on processing the "details click"
  2608. * @param string $divContainerCSS - some CSS for "details" DIV
  2609. *
  2610. * @return string
  2611. */
  2612. function wf_JQDTDetailsClickProcessingJS($ajaxURL, $colIndex, $jqdtID, $ajaxMethod = 'POST', $jsFuncName = 'showDetailsData', $divContainerCSS = '') {
  2613. $divCSS = (empty($divContainerCSS) ? '{"margin-top":"5px", "margin-left":"10px", "margin-bottom":"10px"}' : $divContainerCSS);
  2614. $result = '
  2615. $(document).ready(function() {
  2616. $(\'#' . $jqdtID . ' tbody\').on(\'click\', \'td.details-control\', function (evt) {
  2617. evt.stopPropagation();
  2618. var table = $(\'#' . $jqdtID . '\').DataTable();
  2619. var tr = $(this).closest(\'tr\');
  2620. var row = table.row( tr );
  2621. var rowIdx = row.index();
  2622. var ajaxData = table.cell(rowIdx, ' . $colIndex . ').data();
  2623. if ( row.child.isShown() ) {
  2624. row.child.hide();
  2625. tr.removeClass(\'shown\');
  2626. }
  2627. else {
  2628. row.child( ' . $jsFuncName . '(row.data(), ajaxData, \'' . $ajaxURL . '\', \'' . $ajaxMethod . '\') ).show();
  2629. tr.addClass(\'shown\');
  2630. }
  2631. } );
  2632. function ' . $jsFuncName . ' ( rowData, ajaxData, ajaxURL, ajaxMethod ) {
  2633. var div = $(\'<div/>\')
  2634. .addClass( \'detailsLoading\' )
  2635. .text( \'Loading...\' );
  2636. $.ajax( {
  2637. type: ajaxMethod,
  2638. url: ajaxURL,
  2639. data: ajaxData,
  2640. success: function ( reqResult ) {
  2641. div.html( reqResult ).removeClass( \'loading\' );
  2642. div.css(' . $divCSS . ');
  2643. }
  2644. } );
  2645. return div;
  2646. }
  2647. } );
  2648. ';
  2649. return ($result);
  2650. }
  2651. /**
  2652. * Returns simple JQDT refresh link with JS snippet
  2653. *
  2654. * @param string $jqdtID
  2655. * @param string $jqdtIDSelector
  2656. * @param string $class
  2657. * @param string $opts
  2658. *
  2659. * @return string
  2660. */
  2661. function wf_JQDTRefreshButton($jqdtID = '', $jqdtIDSelector = '', $class = '', $opts = '') {
  2662. $result = '';
  2663. if (!empty($jqdtID) or !empty($jqdtIDSelector)) {
  2664. $class = (empty($class) ? 'ubButtonInline' : $class);
  2665. $tmpInpID = wf_InputId();
  2666. $result = wf_Link('#', wf_img('skins/refresh.gif', __('Refresh table data'), 'vertical-align: bottom'), false, $class, 'id="' . $tmpInpID . '" ' . $opts);
  2667. $tmpScript = '
  2668. $(\'#' . $tmpInpID . '\').click(function(evt) {
  2669. $(\'img\', this).addClass("image_rotate");
  2670. ';
  2671. if (empty($jqdtID)) {
  2672. $tmpScript .= '$(\'#\'+' . $jqdtIDSelector . ').DataTable().ajax.reload();';
  2673. } else {
  2674. $tmpScript .= '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();';
  2675. }
  2676. $tmpScript .= '
  2677. $(\'img\', this).removeClass("image_rotate");
  2678. evt.preventDefault();
  2679. return false;
  2680. });
  2681. ';
  2682. $result .= wf_EncloseWithJSTags($tmpScript);
  2683. }
  2684. return ($result);
  2685. }
  2686. /**
  2687. * Outputs a hex color based text string without # at begin, like an ac1c09
  2688. *
  2689. * @param $text String of text
  2690. * @param $palette Integer between 0 and 100
  2691. *
  2692. * @return string
  2693. */
  2694. function wf_genColorCodeFromText($text, $palette = '') {
  2695. $hash = md5($palette . $text); // modify input to get a different palette
  2696. $result = '';
  2697. $result = substr($hash, 0, 2) . substr($hash, 2, 2) . substr($hash, 4, 2);
  2698. return ($result);
  2699. }
  2700. /**
  2701. * Renders Google 3d pie chart
  2702. *
  2703. * @param array $params data in format like string=>count
  2704. * @param string $title chart title
  2705. * @param string $width chart width in px or %, 500px default
  2706. * @param string $height chart height in px or %, 500px default
  2707. * @param string $options google charts options, useful examples see below<br>
  2708. * pieSliceText: percentage/value/label/none OR pieSliceText: 'value-and-percentage'<br>
  2709. * is3D: true/false <br>
  2710. * backgroundColor: '#666', <br>
  2711. * legend : {position: 'bottom', textStyle: {color: 'red', fontSize: 12 }}, <br>
  2712. * chartArea: { width: '90%', height: '90%' }, <br>
  2713. * @param string $fixedColors use fixed auto-generated colors based on text labels with pallette<br>
  2714. *
  2715. * @return string
  2716. */
  2717. function wf_gcharts3DPie($params, $title = '', $width = '', $height = '', $options = '', $fixedColors = '') {
  2718. global $ubillingConfig;
  2719. $altCfg = $ubillingConfig->getAlter();
  2720. $containerId = wf_InputId();
  2721. $width = ($width) ? $width : '500px';
  2722. $height = ($height) ? $height : '500px';
  2723. $result = '';
  2724. $chartData = '';
  2725. $enableFlag = true;
  2726. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2727. $enableFlag = true;
  2728. } else {
  2729. if ($altCfg['GCHARTS_ENABLED']) {
  2730. $enableFlag = true;
  2731. } else {
  2732. $enableFlag = false;
  2733. }
  2734. }
  2735. if ($enableFlag) {
  2736. $colors = '';
  2737. if ($fixedColors) {
  2738. $palette = (is_bool($fixedColors)) ? '' : $fixedColors; //use string parameter as palette
  2739. $colors .= 'var colors = { ';
  2740. }
  2741. if (!empty($params)) {
  2742. foreach ($params as $io => $each) {
  2743. $chartData .= '[\'' . $io . '\',' . $each . '],';
  2744. if ($fixedColors) {
  2745. $colors .= " '" . $io . "': '" . wf_genColorCodeFromText($io, $palette) . "',";
  2746. }
  2747. }
  2748. $chartData = substr($chartData, 0, -1);
  2749. }
  2750. if ($fixedColors) {
  2751. $colors = rtrim($colors, ',');
  2752. $colors .= '};';
  2753. }
  2754. if ($fixedColors) {
  2755. $colors .= ' var slices = [];
  2756. for (var i = 0; i < data.getNumberOfRows(); i++) {
  2757. slices.push({
  2758. color: colors[data.getValue(i, 0)]
  2759. });
  2760. }';
  2761. $slicesInject = 'slices: slices,';
  2762. } else {
  2763. $slicesInject = '';
  2764. }
  2765. //legend.scrollArrows.activeColor
  2766. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.google.com/jsapi"') . wf_tag('script', true);
  2767. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2768. $result .= '
  2769. google.load("visualization", "1", {packages:["corechart"]});
  2770. google.setOnLoadCallback(drawChart);
  2771. function drawChart() {
  2772. var data = google.visualization.arrayToDataTable([
  2773. [\'X\', \'Y\'],
  2774. ' . $chartData . '
  2775. ]);
  2776. ' . $colors . '
  2777. var options = {
  2778. title: \'' . $title . '\',
  2779. ' . $slicesInject . '
  2780. is3D: true,
  2781. ' . $options . '
  2782. \'tooltip\' : {
  2783. trigger: \'none\'
  2784. }
  2785. };
  2786. var chart = new google.visualization.PieChart(document.getElementById(\'' . $containerId . '\'));
  2787. chart.draw(data, options);
  2788. }
  2789. ';
  2790. $result .= wf_tag('script', true);
  2791. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2792. }
  2793. return ($result);
  2794. }
  2795. /**
  2796. * Renders Google line chart
  2797. *
  2798. * @param array $params data in format like
  2799. * $params=array(
  2800. * 0=>array('month','total','active','inactive'),
  2801. * 1=>array('Февраль',200,150,50),
  2802. * 2=>array('Сентябрь',200,160,40)
  2803. * );
  2804. * @param string $title chart title
  2805. * @param string $width chart width in px or %, 500px default
  2806. * @param string $height chart height in px or %, 500px default
  2807. * @param string $options google charts options
  2808. *
  2809. * @return string
  2810. */
  2811. function wf_gchartsLine($params, $title = '', $width = '', $height = '', $options = '') {
  2812. global $ubillingConfig;
  2813. $altCfg = $ubillingConfig->getAlter();
  2814. $containerId = wf_InputId();
  2815. $width = ($width) ? $width : '500px';
  2816. $height = ($height) ? $height : '500px';
  2817. $result = '';
  2818. $chartData = '';
  2819. $enableFlag = true;
  2820. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2821. $enableFlag = true;
  2822. } else {
  2823. if ($altCfg['GCHARTS_ENABLED']) {
  2824. $enableFlag = true;
  2825. } else {
  2826. $enableFlag = false;
  2827. }
  2828. }
  2829. if ($enableFlag) {
  2830. if (!empty($params)) {
  2831. $chartData = json_encode($params, JSON_NUMERIC_CHECK);
  2832. }
  2833. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  2834. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2835. $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
  2836. google.charts.setOnLoadCallback(drawChart);
  2837. function drawChart() {
  2838. var data = google.visualization.arrayToDataTable(
  2839. ' . $chartData . '
  2840. );
  2841. var options = {
  2842. title: \'' . $title . '\',
  2843. curveType: \'function\',
  2844. ' . $options . '
  2845. };
  2846. var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
  2847. chart.draw(data, options);
  2848. }
  2849. ';
  2850. $result .= wf_tag('script', true);
  2851. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2852. }
  2853. return ($result);
  2854. }
  2855. /**
  2856. * Renders Google line chart
  2857. *
  2858. * @param array $params data in format like
  2859. * $params=array(
  2860. * 0=>array('month','total','active','inactive'),
  2861. * 1=>array('Февраль',200,150,50),
  2862. * 2=>array('Сентябрь',200,160,40)
  2863. * );
  2864. * @param string $title chart title
  2865. * @param string $width chart width in px or %, 500px default
  2866. * @param string $height chart height in px or %, 500px default
  2867. * @param string $options google charts options
  2868. *
  2869. * @return string
  2870. */
  2871. function wf_gchartsLineZeroIsBad($params, $title = '', $width = '', $height = '', $options = '') {
  2872. global $ubillingConfig;
  2873. $altCfg = $ubillingConfig->getAlter();
  2874. $containerId = wf_InputId();
  2875. $width = ($width) ? $width : '500px';
  2876. $height = ($height) ? $height : '500px';
  2877. $result = '';
  2878. $chartData = '';
  2879. $enableFlag = true;
  2880. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2881. $enableFlag = true;
  2882. } else {
  2883. if ($altCfg['GCHARTS_ENABLED']) {
  2884. $enableFlag = true;
  2885. } else {
  2886. $enableFlag = false;
  2887. }
  2888. }
  2889. if ($enableFlag) {
  2890. if (!empty($params)) {
  2891. $chartData = json_encode($params, JSON_NUMERIC_CHECK);
  2892. }
  2893. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  2894. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2895. $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
  2896. google.charts.setOnLoadCallback(drawChart);
  2897. function drawChart() {
  2898. var data = google.visualization.arrayToDataTable(
  2899. ' . $chartData . '
  2900. );
  2901. var options = {
  2902. title: \'' . $title . '\',
  2903. curveType: \'function\',
  2904. ' . $options . '
  2905. legend: { position: \'bottom\' }
  2906. };
  2907. var dataView = new google.visualization.DataView(data);
  2908. dataView.setColumns([
  2909. // reference existing columns by index
  2910. 0, 1,
  2911. // add function for line color
  2912. {
  2913. calc: function(data, row) {
  2914. var colorDown = "#FF0000";
  2915. var colorUp = "#0d8a00";
  2916. if ((data.getValue(row, 1) < 0)) {
  2917. return colorDown;
  2918. } else {
  2919. //return colorUp;
  2920. }
  2921. },
  2922. type: "string",
  2923. role: "style"
  2924. }
  2925. ]);
  2926. var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
  2927. chart.draw(dataView, options);
  2928. }
  2929. ';
  2930. $result .= wf_tag('script', true);
  2931. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2932. }
  2933. return ($result);
  2934. }
  2935. /**
  2936. * Returns default back control
  2937. *
  2938. * @param string $url Link URL
  2939. * @param string $title Link title
  2940. * @param bool $br Line break line after link
  2941. * @param string $class Link class name
  2942. * @param string $opts Link style or attributes
  2943. *
  2944. * @return string
  2945. */
  2946. function wf_BackLink($url, $title = '', $br = false, $class = 'ubButton', $opts = '') {
  2947. $title = (empty($title)) ? __('Back') : __($title);
  2948. $result = wf_Link($url, wf_img('skins/back.png') . ' ' . $title, $br, $class, $opts);
  2949. return ($result);
  2950. }
  2951. /**
  2952. * Returns form disabler JS code, for preventing duplicating POST requests
  2953. *
  2954. * @return string
  2955. */
  2956. function wf_FormDisabler() {
  2957. $result = wf_tag('script', false, '', 'type="text/javascript" language="javascript" src="modules/jsc/form-disabler.js"') . wf_tag('script', true);
  2958. return ($result);
  2959. }
  2960. /**
  2961. * Returns spoiler control with specified options
  2962. *
  2963. * @param string $Content
  2964. * @param string $Title
  2965. * @param bool $Closed
  2966. * @param string $SpoilerID
  2967. * @param string $OuterDivClass
  2968. * @param string $OuterDivOptions
  2969. * @param string $InnerDivClass
  2970. * @param string $InnerDivOptions
  2971. *
  2972. * @return string
  2973. */
  2974. function wf_Spoiler($Content, $Title = '', $Closed = false, $SpoilerID = '', $OuterDivClass = '', $OuterDivOptions = '', $InnerDivClass = '', $InnerDivOptions = '') {
  2975. if (empty($SpoilerID)) {
  2976. $SpoilerID = 'spoiler_' . wf_InputId();
  2977. }
  2978. $SpoilerLnkID = 'lnk_' . wf_InputId();
  2979. $SpoilerBodyID = 'spbody_' . wf_InputId();
  2980. $SpoilerStateID = 'spstate_' . wf_InputId();
  2981. $SpoilerState = ($Closed) ? '▼' : '▲';
  2982. //$ubngStrPos = strpos(CUR_SKIN_PATH, 'ubng');
  2983. $OuterDivClass = 'spoiler clearfix ' . $OuterDivClass;
  2984. $OuterDivOptions = ' id="' . $SpoilerID . '" ' . $OuterDivOptions;
  2985. $InnerDivClass = 'spoiler_body ' . $InnerDivClass;
  2986. $InnerDivOptions = ' id="' . $SpoilerBodyID . '" ' . $InnerDivOptions;
  2987. $Result = wf_tag('div', false, $OuterDivClass, $OuterDivOptions);
  2988. $Result .= wf_tag('div', false, 'spoiler_title clearfix');
  2989. //$Result .= '<a id="' . $SpoilerLnkID . '" class="spoiler_link" href="#">';
  2990. $Result .= '<span id="' . $SpoilerLnkID . '" class="spoiler_link">';
  2991. $Result .= wf_tag('h3', false, '', '');
  2992. $Result .= $Title;
  2993. $Result .= wf_tag('h3', true);
  2994. //$Result .= $SpoilerState . '</a>' . "\n";
  2995. $Result .= '<span id="' . $SpoilerStateID . '">' . $SpoilerState . '</span>';
  2996. $Result .= '</span>' . "\n";
  2997. $Result .= wf_tag('div', true);
  2998. $Result .= wf_tag('div', false, $InnerDivClass, $InnerDivOptions);
  2999. $Result .= $Content;
  3000. $Result .= wf_tag('div', true);
  3001. $Result .= wf_tag('div', true);
  3002. $Result .= wf_tag('script', false, '', 'type="text/javascript"');
  3003. $Result .= '$(\'#' . $SpoilerLnkID . '\').click(function() {
  3004. $(\'#' . $SpoilerBodyID . '\').toggleClass("spoiler_closed");
  3005. if ( $(\'#' . $SpoilerBodyID . '\').hasClass("spoiler_closed") ) {
  3006. $(\'#' . $SpoilerBodyID . '\').slideUp(\'50\');
  3007. $(\'#' . $SpoilerStateID . '\').html(\'▼\');
  3008. } else {
  3009. $(\'#' . $SpoilerBodyID . '\').slideDown(\'50\');
  3010. $(\'#' . $SpoilerStateID . '\').html(\'▲\');
  3011. }
  3012. return false;
  3013. });';
  3014. //$Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').css("display", "none").toggleClass("spoiler_closed");' : '';
  3015. $Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').slideUp(\'50\').toggleClass("spoiler_closed");' : '';
  3016. $Result .= wf_tag('script', true);
  3017. return $Result;
  3018. }
  3019. /**
  3020. * Returns JS for a control which will be responsible for opening dynamic modal windows via ajax call to a specific URL
  3021. *
  3022. * @param $ajaxURL
  3023. * @param $dataArray
  3024. * @param string $controlId
  3025. * @param bool $wrapWithJSScriptTag
  3026. * @param string $queryType
  3027. * @param string $jsEvent
  3028. * @param bool $noPreventDefault
  3029. * @param bool $noReturnFalse
  3030. * @param bool $updNestedJQDT
  3031. * @param string $nestedJQDTSelector
  3032. *
  3033. * @return string
  3034. */
  3035. function wf_JSAjaxModalOpener($ajaxURL, $dataArray, $controlId = '', $wrapWithJSScriptTag = false, $queryType = 'GET', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
  3036. $inputId = (empty($controlId)) ? wf_InputId() : $controlId;
  3037. $modalWindowId = 'modalWindowId:"dialog-modal_' . $inputId . '", ';
  3038. $modalWindowBodyId = 'modalWindowBodyId:"body_dialog-modal_' . $inputId . '"';
  3039. $preventDefault = ($noPreventDefault) ? "" : "\nevt.preventDefault();";
  3040. $returnFalse = ($noReturnFalse) ? "" : "\nreturn false;";
  3041. $ajaxData = '';
  3042. foreach ($dataArray as $io => $each) {
  3043. if (is_array($each)) {
  3044. $ajaxData .= $io . ':' . json_encode($each) . ', ';
  3045. } else {
  3046. $ajaxData .= $io . ':"' . $each . '", ';
  3047. }
  3048. }
  3049. if ($updNestedJQDT) {
  3050. $findJQDTToUpdate = (empty($nestedJQDTSelector) ? 'var closestJQDTID = $(this).parent().parent().next("tr").find(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");' : 'var closestJQDTID = ' . $nestedJQDTSelector);
  3051. } else {
  3052. $findJQDTToUpdate = 'var closestJQDTID = $(this).closest(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");';
  3053. }
  3054. $result = '$(\'#' . $inputId . '\').' . $jsEvent . '(function(evt) {
  3055. ' . $findJQDTToUpdate . '
  3056. $.ajax({
  3057. type: "' . $queryType . '",
  3058. url: "' . $ajaxURL . '",
  3059. data: {' . $ajaxData
  3060. . $modalWindowId
  3061. . $modalWindowBodyId
  3062. . '},
  3063. success: function(ajaxresult) {
  3064. $(document.body).append(ajaxresult);
  3065. $(\'#dialog-modal_' . $inputId . '\').append(\'<input type="hidden" name="closestJQDT" value="\' + closestJQDTID + \'" id="closestJQDTID">\');
  3066. $(\'#dialog-modal_' . $inputId . '\').dialog("open");
  3067. }
  3068. });'
  3069. . $preventDefault
  3070. . $returnFalse
  3071. . '});
  3072. ';
  3073. if ($wrapWithJSScriptTag) {
  3074. $result = wf_tag('script', false, '', 'type="text/javascript"')
  3075. . $result
  3076. . wf_tag('script', true);
  3077. }
  3078. return ($result);
  3079. }
  3080. /**
  3081. * Returns JS for a link which will be responsible for opening an assigned modal window
  3082. *
  3083. * @param $ajaxURL
  3084. * @param $ajaxDataArr
  3085. * @param string $title
  3086. * @param string $icon
  3087. * @param string $linkCSSClass
  3088. * @param string $queryType
  3089. * @param string $jsEvent
  3090. * @param bool $noPreventDefault
  3091. * @param bool $noReturnFalse
  3092. * @param bool $updNestedJQDT
  3093. * @param string $nestedJQDTSelector
  3094. *
  3095. * @return string
  3096. */
  3097. function wf_jsAjaxDynamicWindowButton($ajaxURL, $ajaxDataArr, $title = 'Button', $icon = '', $linkCSSClass = '', $queryType = 'POST', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
  3098. $linkID = wf_InputId();
  3099. $dynamicOpener = wf_Link('#', $icon . ' ' . $title, false, $linkCSSClass, 'id="' . $linkID . '"')
  3100. . wf_JSAjaxModalOpener($ajaxURL, $ajaxDataArr, $linkID, true, $queryType, $jsEvent, $noPreventDefault, $noReturnFalse, $updNestedJQDT, $nestedJQDTSelector);
  3101. return ($dynamicOpener);
  3102. }
  3103. /**
  3104. * Inserts JS-code to process submitting of multiple dynamically or statically created MODAL FORMS via AJAX call
  3105. * To work properly, requires wf_JSEmptyFunc() and wf_JSElemInsertedCatcherFunc() routines to be inserted on a page beforehand.
  3106. * Also it's better to pass a JQUERY DataTable ID to be able to update a certain JQDT records
  3107. *
  3108. * @param string $submitFormClasses (need to be passed with leading dot, several classes may be passed )
  3109. * @param string $submitFormIDCtrlClass (need to be passed with leading dot)
  3110. * @param string $jqdtID
  3111. * @param string $emptyValueCheckClasses (need to be passed with leading dot)
  3112. * @param string $errorFormIDParamName
  3113. *
  3114. * @return string
  3115. */
  3116. function wf_jsAjaxFormSubmit($submitFormClasses, $submitFormIDCtrlClass, $jqdtID = '', $emptyValueCheckClasses = '', $errorFormIDParamName = '') {
  3117. $result = '';
  3118. $emptyValueCheckClasses = (empty($emptyValueCheckClasses) ? '__EmptyCheckControl' : $emptyValueCheckClasses);
  3119. $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
  3120. $errorModalWindowId = wf_InputId();
  3121. $result .= '
  3122. function checkEmptyVal(ctrlClassName) {
  3123. $(document).on("focus keydown", ctrlClassName, function(evt) {
  3124. $(document).find(ctrlClassName).each(function(indx, element){
  3125. if ( $(element).hasClass(\'__MandatoryEmpty\') ) {
  3126. $(element).val("");
  3127. $(element).css("border-color", "");
  3128. $(element).css("color", "");
  3129. $(element).toggleClass(\'__MandatoryEmpty\');
  3130. }
  3131. });
  3132. });
  3133. }
  3134. // for already inserted elements on page load
  3135. checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
  3136. // for newly inserted elements after page load
  3137. onElementInserted(\'body\', \'' . $emptyValueCheckClasses . '\', function(element) {
  3138. checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
  3139. });
  3140. $(document).on("submit", "' . $submitFormClasses . '", function(evt) {
  3141. evt.preventDefault();
  3142. var emptyCheckClass = \'' . $emptyValueCheckClasses . '\';
  3143. var mandatoryFldsEmpty = false;
  3144. $(this).find(emptyCheckClass).each(function(indx, element){
  3145. if ( empty($(element).val()) ) {
  3146. $(element).css("border-color", "red");
  3147. $(element).css("color", "grey");
  3148. $(element).val("' . __('Mandatory field') . '");
  3149. $(element).toggleClass(\'__MandatoryEmpty\');
  3150. mandatoryFldsEmpty = true
  3151. }
  3152. });
  3153. if (!mandatoryFldsEmpty) {
  3154. var FrmAction = $(this).attr("action");
  3155. var FrmData = $(this).serialize() + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\';
  3156. $.ajax({
  3157. type: "POST",
  3158. url: FrmAction,
  3159. data: FrmData,
  3160. success: function(result) {
  3161. if ( !empty(result) ) {
  3162. $(document.body).append(result);
  3163. $( \'#' . $errorModalWindowId . '\' ).dialog("open");
  3164. } else {
  3165. var customJQDTToReload = $(\'#closestJQDTID\').val();
  3166. if (!empty(customJQDTToReload)) {
  3167. $(\'#\' + customJQDTToReload).DataTable().ajax.reload();
  3168. } else {
  3169. ' . (empty($jqdtID) ? ' ' : '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();') . '
  3170. }
  3171. $( \'#\' + $("' . $submitFormIDCtrlClass . '").val() ).dialog("close");
  3172. }
  3173. }
  3174. });
  3175. }
  3176. });
  3177. ';
  3178. return ($result);
  3179. }
  3180. /**
  3181. * Returns a simple wrapper for a JS function with ajax request which can be used later for multiple "callers"
  3182. * e.g. - to delete record from DB or whatever
  3183. *
  3184. * @param $funcName
  3185. * @param string $jqdtID
  3186. * @param string $jqdtIDSelector
  3187. * @param string $errorFormIDParamName
  3188. * @param string $queryType
  3189. * @param bool $jqdtClearBeforePaste
  3190. *
  3191. * @return string
  3192. */
  3193. function wf_jsAjaxCustomFunc($funcName, $jqdtID = '', $jqdtIDSelector = '', $errorFormIDParamName = '', $queryType = 'POST', $jqdtClearBeforePaste = false) {
  3194. $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
  3195. $errorModalWindowId = wf_InputId();
  3196. $jqdtReloadScript = '';
  3197. $jqdtSelector = '';
  3198. $result = '';
  3199. if (!empty($jqdtID)) {
  3200. $jqdtSelector = '$(\'#' . $jqdtID . '\')';
  3201. } elseif (!empty($jqdtIDSelector)) {
  3202. $jqdtSelector = '$(\'#\'+' . $jqdtIDSelector . ')';
  3203. }
  3204. if (!empty($jqdtSelector)) {
  3205. if ($jqdtClearBeforePaste) {
  3206. $jqdtReloadScript = '
  3207. if ( !empty(reqResult) ) {
  3208. var json = jQuery.parseJSON(reqResult);
  3209. var table = ' . $jqdtSelector . '.DataTable();
  3210. table.clear(); //clear the current data
  3211. table.rows.add(json[\'aaData\']).draw();
  3212. }
  3213. ';
  3214. } else {
  3215. $jqdtReloadScript = '
  3216. if ( !empty(reqResult) ) {
  3217. $(document.body).append(reqResult);
  3218. if ($(\'#' . $errorFormIDParamName . '\')) {
  3219. $(\'#' . $errorFormIDParamName . '\').dialog("open");
  3220. }
  3221. }
  3222. ' . $jqdtSelector . '.DataTable().ajax.reload();
  3223. ';
  3224. }
  3225. }
  3226. $result .= '
  3227. function ' . $funcName . '(ajaxURL, ajaxData) {
  3228. var ajaxData = ajaxData + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\'
  3229. $.ajax({
  3230. type: "' . $queryType . '",
  3231. url: ajaxURL,
  3232. data: ajaxData,
  3233. success: function(reqResult) {
  3234. '
  3235. . $jqdtReloadScript .
  3236. '}
  3237. });
  3238. }
  3239. ';
  3240. return ($result);
  3241. }
  3242. /**
  3243. * JS snippet for a filtering form for JQDT. Needs a bit of specific handling
  3244. *
  3245. * @param $ajaxURLStr
  3246. * @param $formID
  3247. * @param $jqdtID
  3248. *
  3249. * @return string
  3250. */
  3251. function wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID) {
  3252. $result = '
  3253. $(\'#' . $formID . '\').submit(function(evt) {
  3254. evt.preventDefault();
  3255. $.ajax({
  3256. url: "' . $ajaxURLStr . '",
  3257. type: "POST",
  3258. data: $(\'#' . $formID . '\').serialize(),
  3259. success: function(reqResult) {
  3260. var json = jQuery.parseJSON(reqResult);
  3261. var table = $(\'#' . $jqdtID . '\').DataTable();
  3262. table.clear(); //clear the current data
  3263. table.rows.add(json[\'aaData\']).draw();
  3264. }
  3265. });
  3266. });
  3267. ';
  3268. return ($result);
  3269. }
  3270. /**
  3271. * Returns a JS-snippet for a regular selector-control cascade filtering by pre-prepared data
  3272. * The point is:
  3273. * we have a hidden input with a predefined data, like:
  3274. * valueInAboveLevelSelector1 => correspondingValueInChildSelector1
  3275. * valueInAboveLevelSelector1 => correspondingValueInChildSelector2
  3276. * valueInAboveLevelSelector1 => correspondingValueInChildSelector3
  3277. * valueInAboveLevelSelector2 => correspondingValueInChildSelector1
  3278. * valueInAboveLevelSelector2 => correspondingValueInChildSelector2
  3279. * valueInAboveLevelSelector2 => correspondingValueInChildSelector3
  3280. * valueInAboveLevelSelector2 => correspondingValueInChildSelector4
  3281. * valueInAboveLevelSelectorN => correspondingValueInChildSelectorNN
  3282. * ..................................................................
  3283. *
  3284. * When a user selects a value in AboveLevelSelector we take that array from hidden input and walk through it -
  3285. * when we find a key equal to selected in AboveLevelSelector value - we take that element in a variable
  3286. * to build a new contents for a child selector. And the same for each key which equals to selected from AboveLevelSelector value
  3287. *
  3288. *
  3289. * @param string $webSelectorID
  3290. * @param string $webSelectorIDToFilter
  3291. * @param string $filterDataElemID
  3292. * @param string $filterFuncName
  3293. * @param bool $blankFirstRow
  3294. * @param string $blankFirstRowVal
  3295. * @param string $blankFirstRowDispVal
  3296. *
  3297. * @return string
  3298. */
  3299. /* function wf_jsWebSelectorFilter($webSelectorID, $webSelectorIDToFilter, $filterDataElemID,
  3300. $webSelChangeFuncName = '', $filterFuncName = '',
  3301. $blankFirstRow = false, $blankFirstRowVal = '0', $blankFirstRowDispVal = '----') {
  3302. $webSelChangeFuncName = (empty($webSelChangeFuncName) ? 'funcChange_' . $webSelectorIDToFilter : $webSelChangeFuncName);
  3303. $filterFuncName = (empty($filterFuncName) ? 'funcFilter_' . $webSelectorIDToFilter : $filterFuncName);
  3304. $webSelectRunChange = (empty($webSelectorIDToFilter) ? "" : "$('#" . $webSelectorIDToFilter . "').change();");
  3305. $firstRowBlank = ($blankFirstRow ? "var newselect = '<option value=\"" . $blankFirstRowVal . "\">" . $blankFirstRowDispVal . "</option>';" : "");
  3306. */
  3307. function wf_jsWebSelectorFilter() {
  3308. $result = '
  3309. function filterWebDropdown(search_keyword, filterListVals, webSelectRun2ChangeID,
  3310. firstRowBlank = true, blankRowVal = "0", blankRowDispVal = "----") {
  3311. if ( !empty(filterListVals.length) ) {
  3312. var search_array = JSON.parse(atob(filterListVals));
  3313. } else {
  3314. return;
  3315. }
  3316. var newselect = "";
  3317. if (firstRowBlank) {
  3318. newselect = \'<option value="\' + blankRowVal + \'">\' + blankRowDispVal + \'</option>\';
  3319. }
  3320. if (search_keyword.length > 0 && search_keyword.trim() !== blankRowDispVal) {
  3321. for (var key in search_array) {
  3322. if ( key.trim() !== "" && key.toLowerCase() == search_keyword.toLowerCase() ) {
  3323. var foundVal = search_array[key];
  3324. for (var foundKey in foundVal) {
  3325. var foundKeyVal = foundVal[foundKey];
  3326. for (var dbID in foundKeyVal) {
  3327. newselect = newselect + \'<option value="\' + dbID + \'">\' + foundKeyVal[dbID] + \'</option>\';
  3328. }
  3329. }
  3330. }
  3331. }
  3332. }
  3333. $(\'#\' + webSelectRun2ChangeID).html(newselect);
  3334. $(\'#\' + webSelectRun2ChangeID).change();
  3335. }
  3336. ';
  3337. return ($result);
  3338. }
  3339. /**
  3340. * Simply encloses a JS snippet with a 'script' open/close tags
  3341. *
  3342. * @param string $content
  3343. *
  3344. * @return string
  3345. */
  3346. function wf_EncloseWithJSTags($content) {
  3347. $result = wf_tag('script', false, '', 'type="text/javascript"');
  3348. $result .= $content;
  3349. $result .= wf_tag('script', true);
  3350. return ($result);
  3351. }
  3352. /**
  3353. * Generates tabbed UI for almost any data.
  3354. *
  3355. * @param $tabsDivID - ID of the main tab div
  3356. * @param $tabsList - array of: tab ID => array('tab_options' => 'options',
  3357. * 'tab_caption' => 'caption,
  3358. * 'additional_data' => 'anything')
  3359. * which represents the tabs itself.
  3360. * Additional data can be anything, like some JS script or comments or whatever.
  3361. * @param $tabsBody - array of: div ID => array('div_options' => 'options',
  3362. * 'tab_body_data' => 'data'
  3363. * 'additional_data' => 'anything')
  3364. * which represents the divs with tabs data.
  3365. * Additional data can be anything, like some JS script or comments or whatever.
  3366. * @param string $mainDivOpts
  3367. * @param string $ulOpts
  3368. * @param bool $tabsCarouselOn
  3369. *
  3370. * @return string
  3371. */
  3372. function wf_TabsGen($tabsDivID, $tabsList, $tabsBody, $mainDivOpts = '', $ulOpts = '', $tabsCarouselOn = false) {
  3373. $result = '';
  3374. if (!empty($tabsDivID) and !empty($tabsList) and !empty($tabsBody)) {
  3375. $divOps = 'id="' . $tabsDivID . '" ' . $mainDivOpts;
  3376. $initTabsJSStr = '$( "#' . $tabsDivID . '" ).tabs();';
  3377. if ($tabsCarouselOn) {
  3378. $initTabsJSStr = '$("#' . $tabsDivID . '").scrollTabs({
  3379. scrollOptions: {
  3380. showFirstLastArrows: false,
  3381. closable: false
  3382. }
  3383. });
  3384. // dirty hack for scrollTabsPlugin to select the very first tab
  3385. $( "#' . $tabsDivID . '" ).scrollTabs("option", "active", 0);
  3386. // another hack for Firefox
  3387. $(".ui-scroll-tabs-view").css("margin-bottom", "0");
  3388. ';
  3389. }
  3390. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  3391. $result .= ' $( function() { ' .
  3392. $initTabsJSStr .
  3393. ' } );
  3394. ';
  3395. $result .= wf_tag('script', true);
  3396. $result .= wf_tag('div', false, '', $divOps);
  3397. $result .= wf_tag('ul', false, '', $ulOpts);
  3398. foreach ($tabsList as $tabhref => $tabData) {
  3399. $result .= wf_tag('li') .
  3400. wf_tag('a', false, '', 'href="#' . $tabhref . '" ' . $tabData['options']) .
  3401. $tabData['caption'] .
  3402. wf_tag('a', true) .
  3403. wf_tag('li', true) .
  3404. $tabData['additional_data'];
  3405. }
  3406. $result .= wf_tag('ul', true);
  3407. foreach ($tabsBody as $bodyID => $bodyData) {
  3408. $result .= wf_tag('div', false, '', 'id="' . $bodyID . '" ' . $bodyData['options']) .
  3409. $bodyData['body'] .
  3410. wf_tag('div', true) .
  3411. $bodyData['additional_data'];
  3412. }
  3413. $result .= wf_tag('div', true);
  3414. }
  3415. return ($result);
  3416. }
  3417. /**
  3418. * Returns scripts and CSS links for tabs carousel plugin.
  3419. * Be sure to add this once to a page if you planning to use wf_TabsGen function with tabsCarouselOn
  3420. */
  3421. function wf_TabsCarouselInitLinking() {
  3422. $result = '<link rel="stylesheet" href="modules/jsc/JQUI_ScrollTabs/style.css" type="text/css">';
  3423. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ba-throttle-debounce.min.js"></script>';
  3424. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.mousewheel.min.js"></script>';
  3425. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.touchSwipe.min.js"></script>';
  3426. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ui.scrolltabs.js"></script>';
  3427. return ($result);
  3428. }
  3429. /**
  3430. * Returns plain JS-code of 'empty' function to use for checking an empty value in JS code
  3431. *
  3432. * @return string
  3433. */
  3434. function wf_JSEmptyFunc() {
  3435. $Result = '
  3436. function empty (mixed_var) {
  3437. // version: 909.322
  3438. // discuss at: http://phpjs.org/functions/empty
  3439. var key;
  3440. if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === \'null\' || mixed_var === false || mixed_var === undefined || mixed_var === \'undefined\' ) {
  3441. return true;
  3442. }
  3443. if (typeof mixed_var == \'object\') {
  3444. for (key in mixed_var) {
  3445. return false;
  3446. }
  3447. return true;
  3448. }
  3449. return false;
  3450. }
  3451. ';
  3452. return ($Result);
  3453. }
  3454. /**
  3455. * Returns some count of non-breaking space symbols
  3456. *
  3457. * @param int $count
  3458. *
  3459. * @return string
  3460. */
  3461. function wf_nbsp($count = 1) {
  3462. $result = '';
  3463. for ($i = 0; $i < $count; $i++) {
  3464. $result .= '&nbsp;';
  3465. }
  3466. return ($result);
  3467. }
  3468. /**
  3469. * Returns JS onElementInserted() func which allow to make any actions for
  3470. * dynamically created objects right after the moment of it's creation
  3471. * elementSelector MUST be a 'class' or 'id' selector, like '.SomeMyClass' or '#SomeMyID'
  3472. *
  3473. * This code and it's function call must exist on a page BEFORE dynamic elements loaded
  3474. * The 'class' or 'id' selectors which will be used in dynamically loaded content
  3475. * must be known BEFORE the content loaded - so avoid of generating some random IDs on-the-fly,
  3476. * just when that content is loaded or in any other way
  3477. *
  3478. * DO NOT include this code or it's function call(like any other JS code)
  3479. * to a dynamically loaded content - as it WON'T WORK that way
  3480. *
  3481. * Source code: https://stackoverflow.com/a/38517525
  3482. *
  3483. * @return string
  3484. */
  3485. function wf_JSElemInsertedCatcherFunc() {
  3486. $Result = '
  3487. function onElementInserted(containerSelector, elementSelector, callback) {
  3488. var onMutationsObserved = function(mutations) {
  3489. mutations.forEach(function(mutation) {
  3490. if (mutation.addedNodes.length) {
  3491. var foundElements = $(mutation.addedNodes).find(elementSelector);
  3492. if (foundElements.length <= 0) {
  3493. foundElements = $(mutation.addedNodes).closest(elementSelector);
  3494. }
  3495. for (var i = 0, len = foundElements.length; i < len; i++) {
  3496. callback(foundElements[i]);
  3497. }
  3498. }
  3499. if (mutation.type === \'attributes\' && ( (\'.\' + $(mutation.target).attr(\'class\') == elementSelector)
  3500. || (\'#\' + $(mutation.target).attr(\'id\') == elementSelector) )) {
  3501. callback(mutation.target);
  3502. }
  3503. });
  3504. };
  3505. var target = $(containerSelector)[0];
  3506. var config = { childList: true, subtree: true, attributes: true, attributeFilter: ["id", "class"]};
  3507. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  3508. var observer = new MutationObserver(onMutationsObserved);
  3509. observer.observe(target, config);
  3510. }
  3511. ';
  3512. return $Result;
  3513. }
  3514. /**
  3515. * Renders default steps-meter progressbar
  3516. *
  3517. * @param array $params as stepname=>decription
  3518. * @param int $current
  3519. *
  3520. * @return type
  3521. */
  3522. function wf_StepsMeter($params, $current) {
  3523. $style = wf_tag('style');
  3524. $style .= "
  3525. .steps{
  3526. min-height:90px;
  3527. padding:30px 30px 0 30px;
  3528. position:relative
  3529. }
  3530. .steps .steps-container{
  3531. background:#DDD;
  3532. height:10px;
  3533. width:95%;
  3534. border-radius:10px ;
  3535. -moz-border-radius:10px ;
  3536. -webkit-border-radius:10px ;
  3537. -ms-border-radius:10px ;
  3538. margin:0;
  3539. list-style:none
  3540. }
  3541. .steps .steps-container li{
  3542. text-align:center;
  3543. list-style:none;
  3544. float:left
  3545. }
  3546. .steps .steps-container li .step{
  3547. padding:0 50px
  3548. }
  3549. .steps .steps-container li .step .step-image{
  3550. margin:-14px 0 0 0
  3551. }
  3552. .steps .steps-container li .step .step-image span{
  3553. background-color:#DDD;
  3554. display:block;
  3555. width:37px;
  3556. height:37px;
  3557. margin:0 auto;
  3558. border-radius:37px ;
  3559. -moz-border-radius:37px ;
  3560. -webkit-border-radius:37px ;
  3561. -ms-border-radius:37px
  3562. }
  3563. .steps .steps-container li .step .step-current{
  3564. font-size:11px;
  3565. font-style:italic;
  3566. color:#999;
  3567. margin:8px 0 0 0
  3568. }
  3569. .steps .steps-container li .step .step-description{
  3570. font-size:13px;
  3571. font-style:italic;
  3572. color:#538897
  3573. }
  3574. .steps .steps-container li.activated .step .step-image span{
  3575. background-color:#5DC177
  3576. }
  3577. .steps .steps-container li.activated .step .step-image span:after{
  3578. background-color:#FFF;
  3579. display:block;
  3580. content:'';
  3581. position:absolute;
  3582. z-index:1;
  3583. width:27px;
  3584. height:27px;
  3585. margin:5px;
  3586. border-radius:27px ;
  3587. -moz-border-radius:27px ;
  3588. -webkit-border-radius:27px ;
  3589. -ms-border-radius:27px ;
  3590. box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
  3591. -moz-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
  3592. -webkit-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15)
  3593. }
  3594. .steps .step-bar{
  3595. background-color:#5DC177;
  3596. height:10px;
  3597. position:absolute;
  3598. top:30px;
  3599. border-radius:10px 0 0 10px;
  3600. -moz-border-radius:10px 0 0 10px;
  3601. -webkit-border-radius:10px 0 0 10px;
  3602. -ms-border-radius:10px 0 0 10px
  3603. }
  3604. .steps .step-bar.last{
  3605. border-radius:10px ;
  3606. -moz-border-radius:10px ;
  3607. -webkit-border-radius:10px ;
  3608. -ms-border-radius:10px
  3609. }
  3610. ";
  3611. $style .= wf_tag('style', true);
  3612. $count = 1;
  3613. $paramsCount = sizeof($params);
  3614. if (!empty($params)) {
  3615. $width = round(100 / $paramsCount) - 1;
  3616. $code = wf_tag('div', false, 'steps');
  3617. $code .= wf_tag('ul', false, 'steps-container');
  3618. foreach ($params as $io => $each) {
  3619. $currentClass = ($count <= $current) ? 'activated' : '';
  3620. $code .= wf_tag('li', false, $currentClass, 'style="width:' . $width . '%;"');
  3621. $code .= wf_tag('div', false, 'step');
  3622. $code .= wf_tag('div', false, 'step-image') . wf_tag('span') . wf_tag('span', true) . wf_tag('div', true);
  3623. $code .= wf_tag('div', false, 'step-current') . $io . wf_tag('div', true);
  3624. $code .= wf_tag('div', false, 'step-description') . $each . wf_tag('div', true);
  3625. $code .= wf_tag('div', true);
  3626. $code .= wf_tag('li', true);
  3627. $count++;
  3628. }
  3629. $code .= wf_tag('ul', true);
  3630. $widthBar = $width * $current;
  3631. $code .= wf_tag('div', false, 'step-bar', 'style="width: ' . $widthBar . '%;"') . wf_tag('div', true);
  3632. $code .= wf_tag('div', true);
  3633. $code .= wf_CleanDiv();
  3634. $result = $style . $code;
  3635. }
  3636. return ($result);
  3637. }
  3638. /**
  3639. * Returns confirmation dialog to navigate to some URL
  3640. *
  3641. * @param string $url
  3642. * @param string $title
  3643. * @param string $alerttext
  3644. * @param string $class
  3645. * @param string $cancelUrl
  3646. * @param string $customDialogTitle
  3647. *
  3648. * @return string
  3649. */
  3650. function wf_ConfirmDialog($url, $title, $alerttext, $class = '', $cancelUrl = '', $customWindowTitle = '') {
  3651. $result = '';
  3652. $dialog = __($alerttext);
  3653. $dialog .= wf_tag('br');
  3654. $dialog .= wf_tag('center', false);
  3655. $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree');
  3656. if ($cancelUrl) {
  3657. $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel');
  3658. }
  3659. $dialog .= wf_tag('center', true);
  3660. $cleanTitle = strip_tags($title);
  3661. if ($customWindowTitle) {
  3662. $cleanTitle = $customWindowTitle;
  3663. }
  3664. $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class);
  3665. return ($result);
  3666. }
  3667. /**
  3668. * Returns confirmation dialog to navigate to some URL
  3669. *
  3670. * @param string $url
  3671. * @param string $title
  3672. * @param string $alerttext
  3673. * @param string $class
  3674. * @param string $cancelUrl
  3675. * @param string $funcRunAgree
  3676. * @param string $funcRunCancel
  3677. * @param string $modalWinID
  3678. *
  3679. * @return string
  3680. */
  3681. function wf_ConfirmDialogJS($url, $title, $alerttext, $class = '', $cancelUrl = '', $funcRunAgree = '', $funcRunCancel = '', $modalWinID = '') {
  3682. $result = '';
  3683. $modalWinID = (empty($modalWinID) ? 'dialog-modal_' . wf_InputId() : $modalWinID);
  3684. $funcRunAgree = (empty($funcRunAgree) ? '' : ' onclick="' . $funcRunAgree . '; return false; "');
  3685. $funcRunCancel = (empty($funcRunCancel) ? '' : ' onclick="' . $funcRunCancel . '; return false; "');
  3686. $dialog = __($alerttext);
  3687. $dialog .= wf_tag('br');
  3688. $dialog .= wf_tag('center', false);
  3689. $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree', $funcRunAgree);
  3690. if (!empty($cancelUrl) or !empty($funcRunCancel)) {
  3691. $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel', $funcRunCancel);
  3692. }
  3693. $dialog .= wf_tag('center', true);
  3694. $cleanTitle = strip_tags($title);
  3695. $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class, $modalWinID);
  3696. return ($result);
  3697. }
  3698. /**
  3699. * Returns code that plays some sound from existing audio file
  3700. *
  3701. * @param string $url
  3702. *
  3703. * @return string
  3704. */
  3705. function wf_doSound($url) {
  3706. $result = wf_tag('script') . "var audio = new Audio('" . $url . "'); audio.play();" . wf_tag('script', true);
  3707. return ($result);
  3708. }
  3709. /**
  3710. * Renders temperature gauge
  3711. *
  3712. * @param float $temperature
  3713. * @param string $title
  3714. * @param string $options
  3715. *
  3716. * @return string
  3717. */
  3718. function wf_renderTemperature($temperature, $title = '', $options = '') {
  3719. $result = '';
  3720. if (empty($options)) {
  3721. $options = ' max: 100,
  3722. min: 0,
  3723. width: 280, height: 280,
  3724. greenFrom: 10, greenTo: 60,
  3725. yellowFrom:60, yellowTo: 70,
  3726. redFrom: 70, redTo: 100,
  3727. minorTicks: 5';
  3728. }
  3729. $result = wf_renderGauge($temperature, $title, '°C', $options);
  3730. return ($result);
  3731. }
  3732. /**
  3733. * Renders generic gauge
  3734. *
  3735. * @param float $value
  3736. * @param string $title
  3737. * @param string $units
  3738. * @param string $options
  3739. * @param int $size
  3740. *
  3741. * @return string
  3742. */
  3743. function wf_renderGauge($value, $title = '', $units = '', $options = '', $size = 300) {
  3744. $result = '';
  3745. $gaugeId = wf_InputId();
  3746. $sizeContainer = $size;
  3747. $sizeContent = $sizeContainer - 20;
  3748. if (empty($options)) {
  3749. $options = ' max: 100,
  3750. min: 0,
  3751. width: ' . $sizeContent . ', height: ' . $sizeContent . ',
  3752. greenFrom: 10, greenTo: 60,
  3753. yellowFrom:60, yellowTo: 70,
  3754. redFrom: 70, redTo: 100,
  3755. minorTicks: 5';
  3756. }
  3757. $containerStyle = 'width: ' . $sizeContainer . 'px; height: ' . $sizeContainer . 'px; float:left; ';
  3758. $result .= wf_tag('div', false, '', 'style="' . $containerStyle . '"');
  3759. $result .= wf_tag('div', false, '', 'id="gengauge_div' . $gaugeId . '"');
  3760. $result .= wf_tag('div', true);
  3761. $result .= wf_tag('center') . wf_tag('b') . $title . wf_tag('b', true) . wf_tag('center', true);
  3762. $result .= wf_tag('div', true);
  3763. $result .= wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  3764. $result .= wf_tag('script');
  3765. $result .= 'google.charts.load(\'current\', {\'packages\':[\'gauge\']});
  3766. google.charts.setOnLoadCallback(drawChart);
  3767. function drawChart() {
  3768. var data = google.visualization.arrayToDataTable([
  3769. [\'Label\', \'Value\'],
  3770. [\'' . $units . '\', ' . $value . ']
  3771. ]);
  3772. var options = {
  3773. ' . $options . '
  3774. };
  3775. var chart = new google.visualization.Gauge(document.getElementById(\'gengauge_div' . $gaugeId . '\'));
  3776. chart.draw(data, options);
  3777. } ';
  3778. $result .= wf_tag('script', true);
  3779. return ($result);
  3780. }
  3781. /**
  3782. * Returns simple pre-formatted date-or-time range picker.
  3783. * For example - for filtering form.
  3784. *
  3785. * @param bool $inTable
  3786. * @param bool $tableCellsOnly
  3787. * @param bool $tableRowsOnly
  3788. * @param bool $vertical
  3789. * @param bool $dateIsON
  3790. * @param bool $timeIsON
  3791. * @param string $dateStart
  3792. * @param string $dateEnd
  3793. * @param string $dpStartInpName
  3794. * @param string $dpEndInpName
  3795. * @param string $timeStart
  3796. * @param string $timeEnd
  3797. * @param string $tpStartInpName
  3798. * @param string $tpEndInpName
  3799. *
  3800. * @return string
  3801. */
  3802. function wf_DatesTimesRangeFilter(
  3803. $inTable = true,
  3804. $tableCellsOnly = false,
  3805. $tableRowsOnly = false,
  3806. $vertical = false,
  3807. $dateIsON = true,
  3808. $timeIsON = false,
  3809. $dateStart = '',
  3810. $dateEnd = '',
  3811. $dpStartInpName = '',
  3812. $dpEndInpName = '',
  3813. $timeStart = '',
  3814. $timeEnd = '',
  3815. $tpStartInpName = '',
  3816. $tpEndInpName = ''
  3817. ) {
  3818. $inputs = '';
  3819. $cells = '';
  3820. $rows = '';
  3821. $datepickerStart = '';
  3822. $datepickerEnd = '';
  3823. $datepickerStartCapt = '';
  3824. $datepickerEndCapt = '';
  3825. $timepickerStart = '';
  3826. $timepickerEnd = '';
  3827. $timepickerStartCapt = '';
  3828. $timepickerEndCapt = '';
  3829. if ($dateIsON) {
  3830. $dpStartInpName = (empty($dpStartInpName) ? 'datestartfilter' : $dpStartInpName);
  3831. $dpEndInpName = (empty($dpEndInpName) ? 'dateendfilter' : $dpEndInpName);
  3832. $datepickerStart = wf_DatePickerPreset($dpStartInpName, $dateStart, true);
  3833. $datepickerEnd = wf_DatePickerPreset($dpEndInpName, $dateEnd, true);
  3834. $datepickerStartCapt = __('Date from') . ':';
  3835. $datepickerEndCapt = __('Date to') . ':';
  3836. }
  3837. if ($timeIsON) {
  3838. $tpStartInpName = (empty($tpStartInpName) ? 'timestartfilter' : $tpStartInpName);
  3839. $tpEndInpName = (empty($tpEndInpName) ? 'timeendfilter' : $tpEndInpName);
  3840. $timepickerStart = wf_TimePickerPreset($tpStartInpName, $timeStart);
  3841. $timepickerEnd = wf_TimePickerPreset($tpEndInpName, $timeEnd);
  3842. $timepickerStartCapt = __('Time from') . ':';
  3843. $timepickerEndCapt = __('Time to') . ':';
  3844. }
  3845. if ($inTable) {
  3846. if ($dateIsON) {
  3847. $cells .= wf_TableCell($datepickerStartCapt);
  3848. $cells .= wf_TableCell($datepickerStart);
  3849. }
  3850. if ($timeIsON) {
  3851. if ($dateIsON) {
  3852. $cells .= wf_nbsp(4);
  3853. }
  3854. $cells .= wf_TableCell($timepickerStartCapt);
  3855. $cells .= wf_TableCell($timepickerStart);
  3856. }
  3857. if ($vertical) {
  3858. $rows = wf_TableRow($cells);
  3859. $cells = '';
  3860. } else {
  3861. $cells .= wf_TableCell(wf_nbsp(2));
  3862. }
  3863. if ($dateIsON) {
  3864. $cells .= wf_TableCell($datepickerEndCapt);
  3865. $cells .= wf_TableCell($datepickerEnd);
  3866. }
  3867. if ($timeIsON) {
  3868. if ($dateIsON) {
  3869. $cells .= wf_nbsp(4);
  3870. }
  3871. $cells .= wf_TableCell($timepickerEndCapt);
  3872. $cells .= wf_TableCell($timepickerEnd);
  3873. }
  3874. if ($tableCellsOnly) {
  3875. $inputs = $cells;
  3876. } elseif ($tableRowsOnly) {
  3877. $rows .= wf_TableRow($cells);
  3878. $inputs = $rows;
  3879. } else {
  3880. $rows .= wf_TableRow($cells);
  3881. $inputs = wf_TableBody($rows, 'auto', '0', '', '');
  3882. }
  3883. } else {
  3884. if ($dateIsON) {
  3885. $inputs .= $datepickerStartCapt . wf_nbsp(2) . $datepickerStart;
  3886. }
  3887. if ($timeIsON) {
  3888. if ($dateIsON) {
  3889. $inputs .= wf_nbsp(4);
  3890. }
  3891. $inputs .= $timepickerStartCapt . wf_nbsp(2) . $timepickerStart;
  3892. }
  3893. if ($vertical) {
  3894. $inputs .= wf_delimiter();
  3895. } else {
  3896. $inputs .= wf_nbsp(8);
  3897. }
  3898. if ($dateIsON) {
  3899. $inputs .= $datepickerEndCapt . wf_nbsp(2) . $datepickerEnd;
  3900. }
  3901. if ($timeIsON) {
  3902. if ($dateIsON) {
  3903. $inputs .= wf_nbsp(4);
  3904. }
  3905. $inputs .= $timepickerEndCapt . wf_nbsp(2) . $timepickerEnd;
  3906. }
  3907. }
  3908. return ($inputs);
  3909. }
  3910. /**
  3911. * Returns select2 searchable input widget
  3912. *
  3913. * @param string $name
  3914. * @param array $params
  3915. * @param string $label
  3916. * @param string $selected
  3917. * @param bool $br
  3918. * @param string $options
  3919. *
  3920. * @return string
  3921. */
  3922. function wf_SelectorSearchable($name, $params, $label, $selected = '', $br = false, $options = '') {
  3923. $result = '';
  3924. $inputId = wf_InputId();
  3925. $ctrlClass = 'select2_' . $inputId;
  3926. $curLang = curlang();
  3927. $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
  3928. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
  3929. $initCode .= wf_tag('script', true);
  3930. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
  3931. $initCode .= wf_tag('script', true);
  3932. $initCode .= wf_tag('script');
  3933. $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
  3934. $initCode .= wf_tag('script', true);
  3935. $result .= $initCode;
  3936. $result .= wf_Selector($name, $params, $label, $selected, $br, false, '', $ctrlClass, $options);
  3937. return ($result);
  3938. }
  3939. /**
  3940. * Returns select2 searchable input widget with auto-submit function
  3941. *
  3942. * @param string $name
  3943. * @param array $params
  3944. * @param string $label
  3945. * @param string $selected
  3946. * @param bool $br
  3947. * @param string $options
  3948. *
  3949. * @return string
  3950. */
  3951. function wf_SelectorSearchableAC($name, $params, $label, $selected = '', $br = false) {
  3952. $options = 'onChange="this.form.submit();"';
  3953. $result = wf_SelectorSearchable($name, $params, $label, $selected, $br, $options);
  3954. return ($result);
  3955. }
  3956. /**
  3957. * Return select2 Web From element with auto click option into ajax container
  3958. *
  3959. * @param string $container name of container element
  3960. * @param array $params array of elements $url=>$option
  3961. * @param string $label text label for input
  3962. * @param string $selected selected $value for selector
  3963. * @param bool $br append new line
  3964. * @param string $options some raw custom options
  3965. *
  3966. * @return string
  3967. *
  3968. */
  3969. function wf_AjaxSelectorSearchableAC($container, $params, $label, $selected = '', $br = false, $options = '') {
  3970. $inputid = wf_InputId();
  3971. $result = '';
  3972. $inputId = wf_InputId();
  3973. $ctrlClass = 'select2_' . $inputId;
  3974. $curLang = curlang();
  3975. $newline = ($br) ? wf_tag('br') : '';
  3976. $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
  3977. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
  3978. $initCode .= wf_tag('script', true);
  3979. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
  3980. $initCode .= wf_tag('script', true);
  3981. $initCode .= wf_tag('script');
  3982. $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
  3983. $initCode .= wf_tag('script', true);
  3984. $result .= $initCode;
  3985. $selectorOptions = 'name="' . $inputid . '" id="' . $inputid . '" onChange="this.options[this.selectedIndex].onclick();" ' . $options;
  3986. $result .= wf_tag('select', false, $ctrlClass, $selectorOptions);
  3987. if (!empty($params)) {
  3988. foreach ($params as $value => $eachparam) {
  3989. $sel_flag = ($selected == $value) ? 'SELECTED' : '';
  3990. $optionSpec = 'value="' . $value . '" ' . $sel_flag . ' onclick="goajax(\'' . $value . '\',\'' . $container . '\');"';
  3991. $result .= wf_tag('option', false, '', $optionSpec) . $eachparam . wf_tag('option', true);
  3992. }
  3993. }
  3994. $result .= wf_tag('select', true);
  3995. if (!empty($label)) {
  3996. $result .= wf_tag('label', false, '', 'for="' . $inputid . '"');
  3997. $result .= __($label);
  3998. $result .= wf_tag('label', true);
  3999. }
  4000. $result .= $newline;
  4001. return ($result);
  4002. }
  4003. /**
  4004. * Generates HTML and JavaScript for a show/hide toggle functionality.
  4005. *
  4006. * This function creates a clickable element that toggles the visibility of a content section.
  4007. * It uses jQuery for the toggle effect and updates the clickable element's label based on the visibility state.
  4008. *
  4009. * @param string $content The content to be shown or hidden.
  4010. * @param string $title The title to be displayed on the toggle element. Default is an empty string.
  4011. * @param string $class Additional CSS class to be applied to the outer span. Default is an empty string.
  4012. *
  4013. * @return string
  4014. */
  4015. function wf_ShowHide($content, $title = '', $class = '') {
  4016. $result = '';
  4017. $inputId = 'showhide' . wf_InputId();
  4018. $contentId = 'content' . wf_InputId();
  4019. $labelShow = wf_img_sized('skins/icon_visible.png', $title, 12) . ' ' . __($title) . ' ';
  4020. $labelHide = wf_img_sized('skins/icon_hidden.png', '', 12) . ' ';
  4021. $result .= wf_tag('span', false, $class);
  4022. $result .= wf_tag('span', false, '', 'id="' . $inputId . '"');
  4023. $result .= $labelShow;
  4024. $result .= wf_tag('span', true);
  4025. $result .= wf_tag('span', false, '', 'id="' . $contentId . '" style="display:none;"');
  4026. $result .= $content;
  4027. $result .= wf_tag('span', true);
  4028. $result .= wf_tag('span', true);
  4029. $result .= wf_tag('script');
  4030. $result .= '
  4031. $( "#' . $inputId . '" ).on( "click", function() {
  4032. $( "#' . $contentId . '" ).toggle( "fast", function() {
  4033. $("#' . $inputId . '").html(\'' . $labelHide . '\');
  4034. });
  4035. });
  4036. $( "#' . $contentId . '" ).on( "click", function() {
  4037. $( "#' . $contentId . '" ).toggle( "fast", function() {
  4038. $("#' . $inputId . '").html(\'' . $labelShow . '\');
  4039. });
  4040. });
  4041. ';
  4042. $result .= wf_tag('script', true);
  4043. return ($result);
  4044. }
  4045. /**
  4046. * JQuery Data Tables JSON formatting class
  4047. */
  4048. class wf_JqDtHelper {
  4049. /**
  4050. * Contains raw array of added grid elements
  4051. *
  4052. * @var array
  4053. */
  4054. protected $allRows = array();
  4055. /**
  4056. * Total available records count
  4057. *
  4058. * @var int
  4059. */
  4060. protected $rowsTotalCount = 0;
  4061. /**
  4062. * Filtered rows count
  4063. *
  4064. * @var int
  4065. */
  4066. protected $rowsFilteredCount = 0;
  4067. /**
  4068. * The draw counter that this object is a response to
  4069. *
  4070. * @var int
  4071. */
  4072. protected $draw = 0;
  4073. /**
  4074. * Server side processing flag
  4075. *
  4076. * @var bool
  4077. */
  4078. protected $sSideFlag = true;
  4079. public function __construct($serverSideProcessing = false) {
  4080. $this->setServerSideProcessing($serverSideProcessing);
  4081. }
  4082. /**
  4083. * Sets the server-side processing state.
  4084. *
  4085. * @param bool $state
  4086. *
  4087. * @return void
  4088. */
  4089. public function setServerSideProcessing($state = false) {
  4090. $this->sSideFlag = $state;
  4091. }
  4092. /**
  4093. * Adds new row to elements array, dont forget unset() data in your loop, after adding new row.
  4094. *
  4095. * @param array $data
  4096. *
  4097. * @return void
  4098. */
  4099. public function addRow($data) {
  4100. if (!empty($data)) {
  4101. $jsonItem = array();
  4102. foreach ($data as $io => $each) {
  4103. $jsonItem[] = $each;
  4104. }
  4105. $this->allRows[] = $jsonItem;
  4106. }
  4107. }
  4108. /**
  4109. * Returns JSON acceptible for jquery data tables
  4110. *
  4111. * @return string
  4112. */
  4113. protected function renderJson() {
  4114. $result = array();
  4115. if ($this->sSideFlag) {
  4116. $result += array(
  4117. 'draw' => 0,
  4118. 'recordsTotal' => $this->rowsTotalCount,
  4119. 'recordsFiltered' => $this->rowsFilteredCount
  4120. );
  4121. }
  4122. $result += array("aaData" => $this->allRows);
  4123. $result = json_encode($result);
  4124. return ($result);
  4125. }
  4126. /**
  4127. * Sets total rows count
  4128. *
  4129. * @param int $count
  4130. *
  4131. * @return void
  4132. */
  4133. public function setTotalRowsCount($count) {
  4134. $this->rowsTotalCount = $count;
  4135. }
  4136. /**
  4137. * Sets filtered rows count
  4138. *
  4139. * @param int $count
  4140. *
  4141. * @return void
  4142. */
  4143. public function setFilteredRowsCount($count) {
  4144. $this->rowsFilteredCount = $count;
  4145. }
  4146. /**
  4147. * Renders empty page JSON data for background ajax requests
  4148. *
  4149. * @return void
  4150. */
  4151. public function getJson() {
  4152. header('Content-Type: application/json');
  4153. die($this->renderJson());
  4154. }
  4155. /**
  4156. * Extracts rendered JSON data from object
  4157. *
  4158. * @return string
  4159. */
  4160. public function extractJson() {
  4161. return ($this->renderJson());
  4162. }
  4163. /**
  4164. * Flushes current object instance elements array
  4165. *
  4166. * @return void
  4167. */
  4168. public function flushData() {
  4169. $this->allRows = array();
  4170. }
  4171. }