api.astral.php 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487
  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. *
  1388. * @return string
  1389. */
  1390. function wf_FullCalendar($data, $options = '', $useHTMLInTitle = false, $useHTMLListViewOnly = false, $ajaxURLForDnD = '') {
  1391. global $ubillingConfig;
  1392. $elementid = wf_InputId();
  1393. $dragdropON = ($ubillingConfig->getAlterParam('CALENDAR_DRAG_AND_DROP_ON') and !empty($ajaxURLForDnD));
  1394. $dndConfirmON = $ubillingConfig->getAlterParam('CALENDAR_DRAG_AND_DROP_CONFIRM_ON');
  1395. $titlesSearchON = $ubillingConfig->getAlterParam('CALENDAR_TITLES_SEARCH_ON');
  1396. if ($useHTMLInTitle) {
  1397. if ($useHTMLListViewOnly) {
  1398. $htmlInTitle = " eventRender: function(event, element, view) {
  1399. if (view.type.indexOf('list') >= 0) {
  1400. var link = element.find('[class*=-title] a');
  1401. var title = element.find('[class*=-title]');
  1402. link.html(title.text());
  1403. title.html( link );
  1404. } else {
  1405. var title = element.find('[class*=-title]');
  1406. // some hack to remove HTML from text
  1407. var doc = new DOMParser().parseFromString(title.text(), 'text/html');
  1408. var titleText = (doc.body.textContent || \"\");
  1409. title.html( titleText );
  1410. }
  1411. }, ";
  1412. } else {
  1413. $htmlInTitle = " eventRender: function(event, element, view) {
  1414. if (view.type.indexOf('list') >= 0) {
  1415. var link = element.find('[class*=-title] a');
  1416. var title = element.find('[class*=-title]');
  1417. link.html(title.text());
  1418. title.html( link );
  1419. } else {
  1420. var title = element.find('[class*=-title]');
  1421. title.html( title.text() );
  1422. }
  1423. }, ";
  1424. }
  1425. } else {
  1426. $htmlInTitle = '';
  1427. }
  1428. $calendar = "<script type='text/javascript'>
  1429. $(document).ready(function() {
  1430. var date = new Date();
  1431. var d = date.getDate();
  1432. var m = date.getMonth();
  1433. var y = date.getFullYear();
  1434. $('#" . $elementid . "').fullCalendar({
  1435. header: {
  1436. left: 'prev,next today',
  1437. center: 'title',
  1438. right: 'month,basicWeek,basicDay,listMonth'
  1439. },
  1440. editable: " . ($dragdropON ? "true" : "false") . ",
  1441. " . $htmlInTitle . "
  1442. theme: true,
  1443. weekends: true,
  1444. timeFormat: 'H(:mm)',
  1445. displayEventTime: false,
  1446. height: 'auto',
  1447. contentHeight: 'auto',
  1448. " . $options . "
  1449. monthNamesShort: [
  1450. '" . rcms_date_localise('Jan') . "',
  1451. '" . rcms_date_localise('Feb') . "',
  1452. '" . rcms_date_localise('Mar') . "',
  1453. '" . rcms_date_localise('Apr') . "',
  1454. '" . rcms_date_localise('May') . "',
  1455. '" . rcms_date_localise('Jun') . "',
  1456. '" . rcms_date_localise('Jul') . "',
  1457. '" . rcms_date_localise('Aug') . "',
  1458. '" . rcms_date_localise('Sep') . "',
  1459. '" . rcms_date_localise('Oct') . "',
  1460. '" . rcms_date_localise('Nov') . "',
  1461. '" . rcms_date_localise('Dec') . "'
  1462. ],
  1463. monthNames: [
  1464. '" . rcms_date_localise('January') . "',
  1465. '" . rcms_date_localise('February') . "',
  1466. '" . rcms_date_localise('March') . "',
  1467. '" . rcms_date_localise('April') . "',
  1468. '" . rcms_date_localise('May') . "',
  1469. '" . rcms_date_localise('June') . "',
  1470. '" . rcms_date_localise('July') . "',
  1471. '" . rcms_date_localise('August') . "',
  1472. '" . rcms_date_localise('September') . "',
  1473. '" . rcms_date_localise('October') . "',
  1474. '" . rcms_date_localise('November') . "',
  1475. '" . rcms_date_localise('December') . "'
  1476. ],
  1477. dayNamesShort: [
  1478. '" . rcms_date_localise('Sun') . "',
  1479. '" . rcms_date_localise('Mon') . "',
  1480. '" . rcms_date_localise('Tue') . "',
  1481. '" . rcms_date_localise('Wed') . "',
  1482. '" . rcms_date_localise('Thu') . "',
  1483. '" . rcms_date_localise('Fri') . "',
  1484. '" . rcms_date_localise('Sat') . "'
  1485. ],
  1486. dayNames: [
  1487. '" . rcms_date_localise('Sunday') . "',
  1488. '" . rcms_date_localise('Monday') . "',
  1489. '" . rcms_date_localise('Tuesday') . "',
  1490. '" . rcms_date_localise('Wednesday') . "',
  1491. '" . rcms_date_localise('Thursday') . "',
  1492. '" . rcms_date_localise('Friday') . "',
  1493. '" . rcms_date_localise('Saturday') . "'
  1494. ],
  1495. buttonText: {
  1496. today: '" . __('Today') . "',
  1497. month: '" . __('Month') . "',
  1498. week: '" . __('Week') . "',
  1499. day: '" . __('Day') . "',
  1500. list: '" . __('List') . "'
  1501. },
  1502. events: [
  1503. " . $data . "
  1504. ]
  1505. });
  1506. });
  1507. </script>
  1508. <div id='" . $elementid . "'></div>
  1509. ";
  1510. $jsCalendarDnD = '';
  1511. $jsCalendarSrchFill = '';
  1512. $jsCalendarSearch = '';
  1513. $appendJS = '';
  1514. if ($dragdropON) {
  1515. $jsCalendarDnDCancel = " event.start = eventPrevStartDT;
  1516. $('#" . $elementid . "').fullCalendar('updateEvent', event);
  1517. console.log(objID + ' Start time change canceled');
  1518. ";
  1519. $jsCalendarDnDMain = " // need to convert to local time to prevent adding timezone offset hours adding after drop
  1520. var mm = moment(event.start);
  1521. mm.local();
  1522. event.start = mm;
  1523. var newStartDT = event.start.format('YYYY-MM-DD HH:mm:ss');
  1524. $.ajax({
  1525. type: \"POST\",
  1526. url: \"" . $ajaxURLForDnD . "\",
  1527. data: {object_id: objID, new_start_time: newStartDT},
  1528. success: function(reqResult) {
  1529. // 'SUCCESS' must be returned as a result of the request
  1530. // to indicate that event datetime was actually changed
  1531. // otherwise DnD operation will be reverted
  1532. if (reqResult == 'SUCCESS') {
  1533. console.log(objID + ' Start time changed');
  1534. } else {
  1535. " . $jsCalendarDnDCancel . "
  1536. }
  1537. }
  1538. });
  1539. ";
  1540. if ($dndConfirmON) {
  1541. $jsCalendarDnD = "
  1542. calendar.on('eventDrop', function(event, delta, revertFunc, jsEvent, ui, view) {
  1543. var objID = event.id;
  1544. if (empty(objID)) {
  1545. " . $jsCalendarDnDCancel . "
  1546. return false;
  1547. }
  1548. if (confirm('" . __('Do you confirm the movement of this event?') . "')) {
  1549. " . $jsCalendarDnDMain . "
  1550. } else {
  1551. " . $jsCalendarDnDCancel . "
  1552. }
  1553. });
  1554. ";
  1555. } else {
  1556. $jsCalendarDnD = "
  1557. calendar.on('eventDrop', function(event, delta, revertFunc, jsEvent, ui, view) {
  1558. var objID = event.id;
  1559. if (empty(objID)) {
  1560. " . $jsCalendarDnDCancel . "
  1561. return false;
  1562. }
  1563. " . $jsCalendarDnDMain . "
  1564. });
  1565. ";
  1566. }
  1567. }
  1568. if ($titlesSearchON) {
  1569. $jsCalendarSrchFill = "$('#calendarSource').val(JSON.stringify(calendar.clientEvents(), ['id', 'title', 'start', 'end', 'url', 'className', 'allDay']));";
  1570. $jsCalendarSearch = "
  1571. $('#calendarSearchInput').on('change keyup', function() {
  1572. var searchWords = this.value.toLowerCase().split(' ');
  1573. var source = JSON.parse($('#calendarSource').val());
  1574. var newSource = source.filter(elem => {
  1575. var titleStr = elem.title.toLowerCase();
  1576. return searchWords.every(item => titleStr.includes(item));
  1577. });
  1578. // converting UTC datetime back to our timezone
  1579. newSource.forEach(item => {
  1580. var dtStart = item.start;
  1581. item.start = new Date(dtStart);
  1582. });
  1583. refreshCalendar(newSource);
  1584. });
  1585. function refreshCalendar(newSource) {
  1586. $('#" . $elementid . "').fullCalendar('removeEvents');
  1587. $('#" . $elementid . "').fullCalendar('addEventSource', newSource);
  1588. $('#" . $elementid . "').fullCalendar('refetchEvents');
  1589. }
  1590. ";
  1591. }
  1592. if ($titlesSearchON or $dragdropON) {
  1593. $appendJS = "
  1594. <script type='text/javascript'>
  1595. // global scope var to save the event's initial start datetime on DragNDrop operation start
  1596. // to be used for DnD cancelation if confirmation is ON
  1597. var eventPrevStartDT = '';
  1598. $(function() {
  1599. var calendar = $('#" . $elementid . "').fullCalendar('getCalendar');
  1600. " . $jsCalendarSrchFill . "
  1601. calendar.on('eventDragStart', function(event, jsEvent, ui, view) {
  1602. eventPrevStartDT = event.start.format();
  1603. });
  1604. " . $jsCalendarDnD . "
  1605. });
  1606. " . $jsCalendarSearch . "
  1607. " . wf_JSEmptyFunc() . "
  1608. </script>
  1609. ";
  1610. $calendar .= $appendJS;
  1611. }
  1612. if ($titlesSearchON) {
  1613. $calendar .= "\n" . wf_HiddenInput('calendarsource', '', 'calendarSource');
  1614. $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;"')
  1615. . wf_delimiter() . $calendar;
  1616. }
  1617. return ($calendar);
  1618. }
  1619. /**
  1620. * Returns div plate with some content
  1621. *
  1622. * @param string $content Data to include into plate widget
  1623. * @param string $width Widget width
  1624. * @param string $height Widget height
  1625. * @param string $class Widget class to assign
  1626. * @param string $opts Widget style options. Do not include style="..."
  1627. *
  1628. * @return string
  1629. */
  1630. function wf_Plate($content, $width = '', $height = '', $class = '', $opts = '') {
  1631. if ($width != '') {
  1632. $width = 'width: ' . $width . ';';
  1633. }
  1634. if ($height != '') {
  1635. $height = 'height: ' . $height . ';';
  1636. }
  1637. if ($class != '') {
  1638. $class = 'class="' . $class . '"';
  1639. }
  1640. $result = '
  1641. <div style="' . $width . ' ' . $height . ' float: left; ' . $opts . ' " ' . $class . '>
  1642. ' . $content . '
  1643. </div>
  1644. ';
  1645. return ($result);
  1646. }
  1647. /**
  1648. * Returns some count of delimiters
  1649. *
  1650. * @param int $count count of delimited rows
  1651. * @return string
  1652. *
  1653. */
  1654. function wf_delimiter($count = 1) {
  1655. $result = '';
  1656. for ($i = 0; $i <= $count; $i++) {
  1657. $result .= '<br />';
  1658. }
  1659. return ($result);
  1660. }
  1661. /**
  1662. * Returns some html styled tag
  1663. *
  1664. * @param int $tag HTML tag entity
  1665. * @param bool $closed tag is closing?
  1666. * @param string $class tag styling class
  1667. * @param string $options tag extra options
  1668. * @return string
  1669. *
  1670. */
  1671. function wf_tag($tag, $closed = false, $class = '', $options = '') {
  1672. if (!empty($class)) {
  1673. $tagclass = ' class="' . $class . '"';
  1674. } else {
  1675. $tagclass = '';
  1676. }
  1677. if ($closed) {
  1678. $tagclose = '/';
  1679. } else {
  1680. $tagclose = '';
  1681. }
  1682. if ($options != '') {
  1683. $tagoptions = $options;
  1684. } else {
  1685. $tagoptions = '';
  1686. }
  1687. $result = '<' . $tagclose . $tag . $tagclass . ' ' . $tagoptions . '>';
  1688. return ($result);
  1689. }
  1690. /**
  1691. * Constructs and returns default AJAX loader
  1692. *
  1693. * @param bool $noAnimation
  1694. *
  1695. * @return string
  1696. */
  1697. function wf_AjaxLoader($noAnimation = false) {
  1698. if ($noAnimation) {
  1699. $animationCode = '';
  1700. } else {
  1701. $animationCode = 'contentElem.innerHTML = \'<img src="skins/ajaxloader.gif" id="ubajaxloaderanim">\';';
  1702. }
  1703. $result = '
  1704. <script type="text/javascript">
  1705. function getXmlHttp()
  1706. {
  1707. var xmlhttp;
  1708. try
  1709. {
  1710. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  1711. }
  1712. catch (e)
  1713. {
  1714. try
  1715. {
  1716. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  1717. }
  1718. catch (E)
  1719. {
  1720. xmlhttp = false;
  1721. }
  1722. }
  1723. if(!xmlhttp && typeof XMLHttpRequest!=\'undefined\')
  1724. {
  1725. xmlhttp = new XMLHttpRequest();
  1726. }
  1727. return xmlhttp;
  1728. }
  1729. function goajax(link,container)
  1730. {
  1731. var myrequest = getXmlHttp()
  1732. var docum = link;
  1733. var contentElem = document.getElementById(container);
  1734. myrequest.open(\'POST\', docum, true);
  1735. myrequest.setRequestHeader(\'Content-Type\', \'application/x-www-form-urlencoded\');
  1736. ' . $animationCode . '
  1737. myrequest.onreadystatechange = function()
  1738. {
  1739. if (myrequest.readyState == 4)
  1740. {
  1741. if(myrequest.status == 200)
  1742. {
  1743. var resText = myrequest.responseText;
  1744. var ua = navigator.userAgent.toLowerCase();
  1745. if (ua.indexOf(\'gecko\') != -1)
  1746. {
  1747. var range = contentElem.ownerDocument.createRange();
  1748. range.selectNodeContents(contentElem);
  1749. range.deleteContents();
  1750. var fragment = range.createContextualFragment(resText);
  1751. contentElem.appendChild(fragment);
  1752. }
  1753. else
  1754. {
  1755. contentElem.innerHTML = resText;
  1756. }
  1757. }
  1758. else
  1759. {
  1760. contentElem.innerHTML = \'' . __('Error') . '\';
  1761. }
  1762. }
  1763. }
  1764. myrequest.send();
  1765. }
  1766. </script>
  1767. ';
  1768. return ($result);
  1769. }
  1770. /**
  1771. * Returns default ajax container div element
  1772. *
  1773. * @param string $containerName container name aka ID
  1774. * @param string $options misc options like size/display if required
  1775. * @param string $content default container content
  1776. *
  1777. * @return string
  1778. */
  1779. function wf_AjaxContainer($containerName, $options = '', $content = '') {
  1780. $result = wf_tag('div', false, '', 'id="' . $containerName . '" ' . $options . ' ') . $content . wf_tag('div', true);
  1781. return ($result);
  1782. }
  1783. /**
  1784. * Returns default ajax container span element
  1785. *
  1786. * @param string $containerName container name aka ID
  1787. * @param string $options misc options like size/display if required
  1788. * @param srring $content default container content
  1789. *
  1790. * @return string
  1791. */
  1792. function wf_AjaxContainerSpan($containerName, $options = '', $content = '') {
  1793. $result = wf_tag('span', false, '', 'id="' . $containerName . '" ' . $options . ' ') . $content . wf_tag('span', true);
  1794. return ($result);
  1795. }
  1796. /**
  1797. * Returns new opened modal window with some content
  1798. *
  1799. * @param string $title modal window title
  1800. * @param string $content modal window content
  1801. * @param string $width modal window width
  1802. * @param string $height modal window height
  1803. * @return string
  1804. *
  1805. */
  1806. function wf_modalOpened($title, $content, $width = '', $height = '') {
  1807. $wid = wf_inputid();
  1808. //setting auto width if not specified
  1809. if ($width == '') {
  1810. $width = '600';
  1811. }
  1812. //setting auto width if not specified
  1813. if ($height == '') {
  1814. $height = '400';
  1815. }
  1816. $dialog = '
  1817. <script type="text/javascript">
  1818. $(function() {
  1819. $( "#dialog-modal_' . $wid . '" ).dialog({
  1820. autoOpen: true,
  1821. width: ' . $width . ',
  1822. height: ' . $height . ',
  1823. modal: true,
  1824. show: "drop",
  1825. hide: "fold"
  1826. });
  1827. $( "#opener_' . $wid . '" ).click(function() {
  1828. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  1829. return false;
  1830. });
  1831. });
  1832. </script>
  1833. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  1834. <p>
  1835. ' . $content . '
  1836. </p>
  1837. </div>
  1838. ';
  1839. return ($dialog);
  1840. }
  1841. /**
  1842. * Returns new opened modal window with some content and automatic sizes
  1843. *
  1844. * @param string $title modal window title
  1845. * @param string $content modal window content
  1846. *
  1847. * @return string
  1848. */
  1849. function wf_modalOpenedAuto($title, $content) {
  1850. $wid = wf_inputid();
  1851. $width = "'auto'";
  1852. $height = "'auto'";
  1853. $dialog = '
  1854. <script type="text/javascript">
  1855. $(function() {
  1856. $( "#dialog-modal_' . $wid . '" ).dialog({
  1857. autoOpen: true,
  1858. width: ' . $width . ',
  1859. height: ' . $height . ',
  1860. modal: true,
  1861. show: "drop",
  1862. hide: "fold"
  1863. });
  1864. $( "#opener_' . $wid . '" ).click(function() {
  1865. $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
  1866. return false;
  1867. });
  1868. });
  1869. </script>
  1870. <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
  1871. <p>
  1872. ' . $content . '
  1873. </p>
  1874. </div>
  1875. ';
  1876. return ($dialog);
  1877. }
  1878. /**
  1879. * Returns Chart source
  1880. *
  1881. * @param string $data - CSV formatted data
  1882. * @param string $widht - graph width in pixels
  1883. * @param string $height - graph height in pixels
  1884. * @param bool $errorbars - display error bars around data series
  1885. *
  1886. * @return string
  1887. */
  1888. function wf_Graph($data, $width = '500', $height = '300', $errorbars = false, $GraphTitle = '', $XLabel = '', $YLabel = '', $RangeSelector = false) {
  1889. $randomId = wf_InputId();
  1890. $objectId = 'graph_' . $randomId;
  1891. $data = trim($data);
  1892. $data = explodeRows($data);
  1893. $cleandata = '';
  1894. if ($errorbars) {
  1895. $errorbars = 'true';
  1896. } else {
  1897. $errorbars = 'false';
  1898. }
  1899. if (!empty($data)) {
  1900. foreach ($data as $eachrow) {
  1901. $cleandata .= '"' . trim($eachrow) . '\n" +' . "\n";
  1902. }
  1903. $cleandata = mb_substr($cleandata, 0, -2, 'utf-8');
  1904. }
  1905. //style="width: 98%; "
  1906. $result = wf_tag('div', false, '', 'id="' . $randomId . '" style="width:' . $width . 'px; height:' . $height . 'px;"') . wf_tag('div', true);
  1907. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  1908. $result .= $objectId . ' = new Dygraph(';
  1909. $result .= 'document.getElementById("' . $randomId . '"),' . "\n";
  1910. $result .= $cleandata;
  1911. $result .= ', { errorBars: ' . $errorbars;
  1912. $result .= (!empty($GraphTitle)) ? ', title: \'' . $GraphTitle . '\'' : '';
  1913. $result .= (!empty($XLabel)) ? ', xlabel: \'' . $XLabel . '\'' : '';
  1914. $result .= (!empty($YLabel)) ? ', ylabel: \'' . $YLabel . '\'' : '';
  1915. $result .= (!empty($RangeSelector)) ? ', showRangeSelector: true' : '';
  1916. $result .= ' }' . "\n";
  1917. $result .= ');';
  1918. $result .= wf_tag('script', true);
  1919. return ($result);
  1920. }
  1921. /**
  1922. * Returns Chart source by data loaded from the file - acceptable for huge data sets
  1923. *
  1924. * @param string $datafile - existing CSV file path
  1925. * @param string $widht - graph width in pixels
  1926. * @param string $height - graph height in pixels
  1927. * @param bool $errorbars - display error bars around data series
  1928. *
  1929. * @return string
  1930. */
  1931. function wf_GraphCSV($datafile, $width = '500', $height = '300', $errorbars = false, $GraphTitle = '', $XLabel = '', $YLabel = '', $RangeSelector = false) {
  1932. $randomId = wf_InputId();
  1933. $objectId = 'graph_' . $randomId;
  1934. if ($errorbars) {
  1935. $errorbars = 'true';
  1936. } else {
  1937. $errorbars = 'false';
  1938. }
  1939. $result = wf_tag('div', false, '', 'id="' . $randomId . '" style="width:' . $width . 'px; height:' . $height . 'px;"') . wf_tag('div', true);
  1940. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  1941. $result .= $objectId . ' = new Dygraph(';
  1942. $result .= 'document.getElementById("' . $randomId . '"), "' . $datafile . '" ' . "\n";
  1943. $result .= ', { errorBars: ' . $errorbars;
  1944. $result .= (!empty($GraphTitle)) ? ', title: \'' . $GraphTitle . '\'' : '';
  1945. $result .= (!empty($XLabel)) ? ', xlabel: \'' . $XLabel . '\'' : '';
  1946. $result .= (!empty($YLabel)) ? ', ylabel: \'' . $YLabel . '\'' : '';
  1947. $result .= (!empty($RangeSelector)) ? ', showRangeSelector: true' : '';
  1948. $result .= ' }' . "\n";
  1949. $result .= ');';
  1950. $result .= wf_tag('script', true);
  1951. return ($result);
  1952. }
  1953. /**
  1954. * Returns color picker dialog
  1955. *
  1956. * @param string $name input name
  1957. * @param string $label input text label
  1958. * @param string $value input pre setted data
  1959. * @param bool $br add line break after input?
  1960. * @param string $size size of element
  1961. * @param string $changeCtrlColorID ID of the control which color will be changed to selected color
  1962. * @param string $changeCtrlColorCSSProp the CSS3 color-property which will be assigned to selected color
  1963. * (like: background-color, border-color, etc)
  1964. *
  1965. * @return string
  1966. */
  1967. function wf_ColPicker($name, $label = '', $value = '', $br = false, $size = '', $changeCtrlColorID = '', $changeCtrlColorCSSProp = '') {
  1968. $id = wf_InputId();
  1969. if (!empty($changeCtrlColorID) and !empty($changeCtrlColorCSSProp)) {
  1970. $changeCtrlColorJS = ' $(\'#' . $changeCtrlColorID . '\').css("' . $changeCtrlColorCSSProp . '", "#" + hex_str);';
  1971. } else {
  1972. $changeCtrlColorJS = '';
  1973. }
  1974. $css = '
  1975. <link rel="stylesheet" href="modules/jsc/colpick/colpick.css" type="text/css"/>';
  1976. $js = '
  1977. <script src="modules/jsc/colpick/colpick.js" type="text/javascript"></script>
  1978. <script type="text/javascript">
  1979. $(document).ready(function() {
  1980. $("#' . $id . '").colpick({
  1981. colorScheme: "light",
  1982. layout: "hex",
  1983. submit: true,
  1984. color: "' . (!empty($value) ? $value : "#f57601") . '",
  1985. onSubmit: function(hsb,hex,rgb,el) {
  1986. var colpickID = $(el).colpick().data("colpickId");
  1987. var hex_str = $("#" + colpickID + " div.colpick_hex_field > input").val();
  1988. $(el).val("#" + hex_str);
  1989. $(el).colpickHide();
  1990. $(el).focus();
  1991. ' . $changeCtrlColorJS . '
  1992. },
  1993. onChange: function(hsb,hex,rgb,el) {
  1994. var hex_str = hex;
  1995. ' . $changeCtrlColorJS . '
  1996. }
  1997. });
  1998. });
  1999. </script>
  2000. ';
  2001. if (!empty($changeCtrlColorJS)) {
  2002. $tmpJS = '
  2003. $(document).ready(function() {
  2004. var colpickID = $("#' . $id . '").colpick().data("colpickId");
  2005. var hex_str = $("#" + colpickID + " div.colpick_hex_field > input").val();
  2006. ' . $changeCtrlColorJS . '
  2007. });
  2008. ';
  2009. $js .= wf_EncloseWithJSTags($tmpJS);
  2010. }
  2011. $size = (!empty($size)) ? 'size="' . $size . '"' : null;
  2012. $result = '<input type="text" name="' . $name . '" value="' . $value . '" id="' . $id . '" ' . $size . '>' . "\n";
  2013. $result .= (!empty($label)) ? '<label for="' . $id . '">' . __($label) . '</label>' : null;
  2014. $result .= (!empty($br)) ? '<br>' : null;
  2015. $result .= "\n";
  2016. return $css . $js . $result;
  2017. }
  2018. /**
  2019. * Return Jquery UI selectable combobox
  2020. *
  2021. * @param string $name name of element
  2022. * @param array $params array of elements $value=>$option
  2023. * @param string $label text label for input
  2024. * @param string $selected selected $value for selector (now ignored)
  2025. * @param bool $br append new line
  2026. * @return string
  2027. *
  2028. */
  2029. function wf_JuiComboBox($name, $params, $label, $selected = '', $br = false) {
  2030. $id = wf_InputId();
  2031. $select = '';
  2032. if (!empty($params)) {
  2033. foreach ($params as $io => $each) {
  2034. $flag_selected = (!empty($selected) and $selected == $io) ? 'SELECTED' : '';
  2035. $select .= '<option value="' . $io . '" ' . $flag_selected . '>' . $each . '</option>' . "\n";
  2036. }
  2037. }
  2038. $result = '
  2039. <style>
  2040. .custom-combobox_' . $id . ' {
  2041. position: relative;
  2042. display: inline-block;
  2043. }
  2044. .custom-combobox-toggle_' . $id . ' {
  2045. position: absolute;
  2046. top: 0;
  2047. bottom: 0;
  2048. margin-left: -1px;
  2049. padding: 0;
  2050. }
  2051. .custom-combobox-input_' . $id . ' {
  2052. margin: 0;
  2053. padding: 5px 10px;
  2054. }
  2055. .ui-autocomplete {
  2056. max-height: 400px;
  2057. overflow-y: auto; /* prevent horizontal scrollbar */
  2058. overflow-x: hidden; /* add padding to account for vertical scrollbar */
  2059. z-index:1000 !important;
  2060. }
  2061. </style>
  2062. <script>
  2063. (function( $ ) {
  2064. $.widget( "custom.combobox_' . $id . '", {
  2065. _create: function() {
  2066. this.wrapper = $( "<span>" )
  2067. .addClass( "custom-combobox_' . $id . '" )
  2068. .insertAfter( this.element );
  2069. this.element.hide();
  2070. this._createAutocomplete();
  2071. this._createShowAllButton();
  2072. },
  2073. _createAutocomplete: function() {
  2074. var selected = this.element.children( ":selected" ),
  2075. value = selected.val() ? selected.text() : "";
  2076. this.input = $( "<input>" )
  2077. .appendTo( this.wrapper )
  2078. .val( value )
  2079. .attr( "title", "" )
  2080. .addClass( "custom-combobox-input_' . $id . ' ui-widget_' . $id . ' ui-widget-content ui-state-default ui-corner-left" )
  2081. .autocomplete({
  2082. delay: 0,
  2083. minLength: 0,
  2084. source: $.proxy( this, "_source" )
  2085. })
  2086. .tooltip({
  2087. tooltipClass: "ui-state-highlight"
  2088. });
  2089. this._on( this.input, {
  2090. autocompleteselect: function( event, ui ) {
  2091. ui.item.option.selected = true;
  2092. this._trigger( "select", event, {
  2093. item: ui.item.option
  2094. });
  2095. },
  2096. autocompletechange: "_removeIfInvalid"
  2097. });
  2098. },
  2099. _createShowAllButton: function() {
  2100. var input = this.input,
  2101. wasOpen = false;
  2102. $( "<a>" )
  2103. .attr( "tabIndex", -1 )
  2104. .attr( "title", "' . __('Show all') . '" )
  2105. .tooltip()
  2106. .appendTo( this.wrapper )
  2107. .button({
  2108. icons: {
  2109. primary: "ui-icon-triangle-1-s"
  2110. },
  2111. text: false
  2112. })
  2113. .removeClass( "ui-corner-all" )
  2114. .addClass( "custom-combobox-toggle_' . $id . ' ui-corner-right" )
  2115. .mousedown(function() {
  2116. wasOpen = input.autocomplete( "widget" ).is( ":visible" );
  2117. })
  2118. .click(function() {
  2119. input.focus();
  2120. // Close if already visible
  2121. if ( wasOpen ) {
  2122. return;
  2123. }
  2124. // Pass empty string as value to search for, displaying all results
  2125. input.autocomplete( "search", "" );
  2126. });
  2127. },
  2128. _source: function( request, response ) {
  2129. var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
  2130. response( this.element.children( "option" ).map(function() {
  2131. var text = $( this ).text();
  2132. if ( this.value && ( !request.term || matcher.test(text) ) )
  2133. return {
  2134. label: text,
  2135. value: text,
  2136. option: this
  2137. };
  2138. }) );
  2139. },
  2140. _removeIfInvalid: function( event, ui ) {
  2141. // Selected an item, nothing to do
  2142. if ( ui.item ) {
  2143. return;
  2144. }
  2145. // Search for a match (case-insensitive)
  2146. var value = this.input.val(),
  2147. valueLowerCase = value.toLowerCase(),
  2148. valid = false;
  2149. this.element.children( "option" ).each(function() {
  2150. if ( $( this ).text().toLowerCase() === valueLowerCase ) {
  2151. this.selected = valid = true;
  2152. return false;
  2153. }
  2154. });
  2155. // Found a match, nothing to do
  2156. if ( valid ) {
  2157. return;
  2158. }
  2159. this.input.autocomplete( "instance" ).term = "";
  2160. },
  2161. _destroy: function() {
  2162. this.wrapper.remove();
  2163. this.element.show();
  2164. }
  2165. });
  2166. })( jQuery );
  2167. $(function() {
  2168. $( "#combobox_' . $id . '" ).combobox_' . $id . '();
  2169. });
  2170. </script>
  2171. <div class="ui-widget_' . $id . '">
  2172. <label for="combobox_' . $id . '">' . $label . '</label>
  2173. <select id="combobox_' . $id . '" name=' . $name . '>
  2174. ' . $select . '
  2175. </select>
  2176. </div>
  2177. ';
  2178. if ($br) {
  2179. $result .= wf_tag('br');
  2180. }
  2181. return ($result);
  2182. }
  2183. /**
  2184. * Returns auto complete text input element
  2185. *
  2186. * @param string $name name of element
  2187. * @param array $data data array for autocomplete box
  2188. * @param string $label text label for input
  2189. * @param string $value current value
  2190. * @param bool $br append new line - bool
  2191. * @param string $size input size
  2192. * @return string
  2193. *
  2194. */
  2195. function wf_AutocompleteTextInput($name, $data = array(), $label = '', $value = '', $br = false, $size = '') {
  2196. $inputid = wf_InputId();
  2197. //set size
  2198. if ($size != '') {
  2199. $input_size = 'size="' . $size . '"';
  2200. } else {
  2201. $input_size = '';
  2202. }
  2203. if ($br) {
  2204. $newline = '<br>';
  2205. } else {
  2206. $newline = '';
  2207. }
  2208. $acData = '';
  2209. $autocomplete = '<script>
  2210. $(function() {
  2211. var availableOpts_' . $inputid . ' = [
  2212. ';
  2213. if (!empty($data)) {
  2214. foreach ($data as $io => $each) {
  2215. $each = str_replace('"', '`', $each);
  2216. $acData .= '"' . $each . '",';
  2217. }
  2218. }
  2219. //removing ending coma
  2220. $acData = mb_substr($acData, 0, -1, 'UTF-8');
  2221. $autocomplete .= $acData;
  2222. $autocomplete .= '
  2223. ];
  2224. $( "#' . $name . '_autocomplete" ).autocomplete({
  2225. source: availableOpts_' . $inputid . '
  2226. });
  2227. });
  2228. </script>';
  2229. $result = $autocomplete;
  2230. $result .= '<input type="text" id="' . $name . '_autocomplete" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
  2231. if ($label != '') {
  2232. $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
  2233. }
  2234. $result .= $newline . "\n";
  2235. return ($result);
  2236. }
  2237. /**
  2238. * Returns calendar widget with preset time
  2239. * Based on Jon Thornton's jquery timepicker: http://jonthornton.github.io/jquery-timepicker
  2240. *
  2241. * @param string $field field name to insert time select widget
  2242. * @param string $time default value time for widget
  2243. * @param string $DisabledTimeRanges string which represents time ranges unavailable to pick up, like: "['11:00', '14:05'], ['20:30', '21:00']" and so on
  2244. * @param string $label label of widget
  2245. * @param bool $br add break after the widget body?
  2246. * @return string
  2247. */
  2248. function wf_TimePickerPreset($field, $time = '', $label = '', $br = false, $DisabledTimeRanges = '') {
  2249. $inputId = wf_InputId();
  2250. if (isset($DisabledTimeRanges)) {
  2251. $DisabledTimeRanges = ',\'disableTimeRanges\': [ ' . $DisabledTimeRanges . ']';
  2252. }
  2253. $result = wf_tag('input', false, '', 'type="text" value="' . $time . '" name="' . $field . '" size="5" id="' . $inputId . '"');
  2254. $result .= wf_tag('script');
  2255. $result .= '$(\'#' . $inputId . '\').timepicker({\'scrollDefault\': \'' . $time . '\', \'timeFormat\': \'H:i\'' . $DisabledTimeRanges . ' });';
  2256. $result .= wf_tag('script', true);
  2257. //clickable icon and label
  2258. if (!empty($label)) {
  2259. $label = ' ' . __($label);
  2260. }
  2261. $result .= wf_tag('label', false, '', 'for="' . $inputId . '"') . wf_img('skins/icon_time_small.png', __('Time')) . $label . wf_tag('label', true);
  2262. //break at end
  2263. if ($br) {
  2264. $result .= wf_tag('br');
  2265. }
  2266. return ($result);
  2267. }
  2268. /**
  2269. * Returns calendar widget with preset time
  2270. * Based on Jon Thornton's jquery timepicker: http://jonthornton.github.io/jquery-timepicker
  2271. *
  2272. * @param string $field field name to insert time select widget
  2273. * @param string $time default value time for widget
  2274. * @param string $DisabledTimeRanges string which represents time ranges unavailable to pick up, like: "['11:00', '14:05'], ['20:30', '21:00']" and so on
  2275. * @param string $label label of widget
  2276. * @param bool $br add break after the widget body?
  2277. * @return string
  2278. */
  2279. function wf_TimePickerPresetSeconds($field, $time = '', $label = '', $br = false, $DisabledTimeRanges = '') {
  2280. $inputId = wf_InputId();
  2281. if (isset($DisabledTimeRanges)) {
  2282. $DisabledTimeRanges = ',\'disableTimeRanges\': [ ' . $DisabledTimeRanges . ']';
  2283. }
  2284. $result = wf_tag('input', false, '', 'type="text" value="' . $time . '" name="' . $field . '" size="8" id="' . $inputId . '"');
  2285. $result .= wf_tag('script');
  2286. $result .= '$(\'#' . $inputId . '\').timepicker({\'scrollDefault\': \'' . $time . '\', \'timeFormat\': \'H:i:s\'' . $DisabledTimeRanges . ' });';
  2287. $result .= wf_tag('script', true);
  2288. //clickable icon and label
  2289. if (!empty($label)) {
  2290. $label = ' ' . __($label);
  2291. }
  2292. $result .= wf_tag('label', false, '', 'for="' . $inputId . '"') . wf_img('skins/icon_time_small.png', __('Time')) . $label . wf_tag('label', true);
  2293. //break at end
  2294. if ($br) {
  2295. $result .= wf_tag('br');
  2296. }
  2297. return ($result);
  2298. }
  2299. /**
  2300. * Returns div with styles cleanup
  2301. *
  2302. * @return string
  2303. */
  2304. function wf_CleanDiv() {
  2305. $result = wf_tag('div', false, '', 'style="clear:both;"') . wf_tag('div', true);
  2306. return ($result);
  2307. }
  2308. /**
  2309. * Renders JQuery Data Tables container
  2310. *
  2311. * @param array $columns columns names array
  2312. * @param string $ajaxUrl URL to fetch JSON data
  2313. * @param bool $saveState grid state saving - conflicts with default sort order
  2314. * @param string $objects object names
  2315. * @param int $rowsCount rows count to default display
  2316. * @param string $opts additional options like:
  2317. * "order": [[ 0, "desc" ]]
  2318. * or
  2319. * dom: \'Bfrtipsl\', buttons: [\'copy\', \'csv\', \'excel\', \'pdf\', \'print\']
  2320. * or "dom": \'<"F"lfB>rti<"F"ps>\', buttons: [\'csv\', \'excel\', \'pdf\', \'print\']
  2321. * @param bool $addFooter
  2322. * @param string $footerOpts
  2323. * @param string $footerTHOpts
  2324. *
  2325. * @return string
  2326. */
  2327. function wf_JqDtLoader($columns, $ajaxUrl, $saveState = false, $objects = 'users', $rowsCount = 100, $opts = '', $addFooter = false, $footerOpts = '', $footerTHOpts = '') {
  2328. $tableId = 'jqdt_' . md5($ajaxUrl);
  2329. $result = '';
  2330. $saveState = ($saveState) ? 'true' : 'false';
  2331. $opts = (!empty($opts)) ? $opts . ',' : '';
  2332. $jq_dt = wf_tag('script', false, '', ' type="text/javascript" charset="utf-8"');
  2333. $jq_dt .= '
  2334. $(document).ready(function() {
  2335. var table=$(\'#' . $tableId . '\').dataTable( {
  2336. "oLanguage": {
  2337. "sLengthMenu": "' . __('Show') . ' _MENU_",
  2338. "sZeroRecords": "' . __('Nothing found') . '",
  2339. "sInfo": "' . __('Showing') . ' _START_ ' . __('to') . ' _END_ ' . __('of') . ' _TOTAL_ ' . __($objects) . '",
  2340. "sInfoEmpty": "' . __('Showing') . ' 0 ' . __('to') . ' 0 ' . __('of') . ' 0 ' . __($objects) . '",
  2341. "sInfoFiltered": "(' . __('Filtered') . ' ' . __('from') . ' _MAX_ ' . __('Total') . ')",
  2342. "sSearch": "' . __('Search') . '",
  2343. "sProcessing": "' . __('Processing') . '...",
  2344. "oPaginate": {
  2345. "sFirst": "' . __('First') . '",
  2346. "sPrevious": "' . __('Previous') . '",
  2347. "sNext": "' . __('Next') . '",
  2348. "sLast": "' . __('Last') . '"
  2349. },
  2350. },
  2351. "bPaginate": true,
  2352. "bLengthChange": true,
  2353. "bFilter": true,
  2354. "bSort": true,
  2355. "bInfo": true,
  2356. "bAutoWidth": false,
  2357. "bProcessing": true,
  2358. "bStateSave": ' . $saveState . ',
  2359. "iDisplayLength": ' . $rowsCount . ',
  2360. "sAjaxSource": \'' . $ajaxUrl . '\',
  2361. "bDeferRender": true,
  2362. "lengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "' . __('All') . '"]],
  2363. ' . $opts . '
  2364. "bJQueryUI": true
  2365. } );
  2366. } );
  2367. ';
  2368. $jq_dt .= wf_tag('script', true);
  2369. $result = $jq_dt;
  2370. $result .= wf_tag('table', false, 'display compact', 'id="' . $tableId . '"');
  2371. $result .= wf_tag('thead', false);
  2372. $tablecells = '';
  2373. $footerCells = '<tfoot ' . $footerOpts . '><tr>';
  2374. foreach ($columns as $io => $eachColumn) {
  2375. $tablecells .= wf_TableCell(__($eachColumn));
  2376. if ($addFooter) {
  2377. $footerCells .= '<th ' . $footerTHOpts . '></th>';
  2378. }
  2379. }
  2380. $result .= wf_TableRow($tablecells);
  2381. $result .= wf_tag('thead', true);
  2382. if ($addFooter) {
  2383. $result .= $footerCells . '</tr></tfoot>';
  2384. }
  2385. $result .= wf_tag('table', true);
  2386. return ($result);
  2387. }
  2388. /**
  2389. * Returns a JS snippet to control the visibility of JQDT column
  2390. *
  2391. * @param string $CallerObjID
  2392. * @param string $CallerObjEvent
  2393. * @param string $JQDTID
  2394. * @param int $ColIndex
  2395. *
  2396. * @return string
  2397. */
  2398. function wf_JQDTColumnHideShow($CallerObjID, $CallerObjEvent, $JQDTID, $ColIndex) {
  2399. $JSCode = '$(\'#' . $CallerObjID . '\').on("' . $CallerObjEvent . '", function() {
  2400. // Get the column API object
  2401. var column = $(\'#' . $JQDTID . '\').DataTable().column(' . $ColIndex . ');
  2402. // Toggle the visibility
  2403. column.visible( !column.visible() );
  2404. });
  2405. ';
  2406. return $JSCode;
  2407. }
  2408. /**
  2409. * Returns a JS snippet for .row().show() plugin
  2410. *
  2411. * @return string
  2412. */
  2413. function wf_JQDTRowShowPluginJS() {
  2414. $jsCode = '
  2415. $.fn.dataTable.Api.register(\'row().show()\', function() {
  2416. var page_info = this.table().page.info();
  2417. // Get row index
  2418. var new_row_index = this.index();
  2419. // Row position
  2420. var row_position = this.table()
  2421. .rows({ search: \'applied\' })[0]
  2422. .indexOf(new_row_index);
  2423. // Already on right page ?
  2424. if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) {
  2425. // Return row object
  2426. return this;
  2427. }
  2428. // Find page number
  2429. var page_to_display = Math.floor(row_position / this.table().page.len());
  2430. // Go to that page
  2431. this.table().page(page_to_display);
  2432. // Return row object
  2433. return this;
  2434. });
  2435. ';
  2436. return ($jsCode);
  2437. }
  2438. /**
  2439. * Returns a JS snippet for column footer sum() plugin
  2440. *
  2441. * @return string
  2442. */
  2443. function wf_JQDTColumnTotalSumJS() {
  2444. $jsCode = '
  2445. jQuery.fn.dataTable.Api.register( \'sum()\', function ( ) {
  2446. return this.flatten().reduce( function ( a, b ) {
  2447. if ( typeof a === \'string\' ) {
  2448. a = a.replace(/[^\d.-]/g, \'\') * 1;
  2449. }
  2450. if ( typeof b === \'string\' ) {
  2451. b = b.replace(/[^\d.-]/g, \'\') * 1;
  2452. }
  2453. return a + b;
  2454. }, 0 );
  2455. } );
  2456. ';
  2457. return ($jsCode);
  2458. }
  2459. /**
  2460. * Returns a JS snippet for markdown the row with searched value
  2461. *
  2462. * @param string|int $columnNum
  2463. * @param string $searchVal
  2464. * @param string $truncateURL
  2465. * @param string $truncateParam
  2466. *
  2467. * @return string
  2468. */
  2469. function wf_JQDTMarkRowJS($columnNum, $searchVal, $truncateURL = '', $truncateParam = '') {
  2470. $truncateJSCode = '';
  2471. if (!empty($truncateURL) and !empty($truncateParam)) {
  2472. $truncateJSCode = '
  2473. //var urlParamsObject = new URLSearchParams(\'' . $truncateURL . '\');
  2474. var urlParamsObject = new URLSearchParams(window.location.search);
  2475. if (urlParamsObject.has(\'' . $truncateParam . '\')) {
  2476. urlParamsObject.delete(\'' . $truncateParam . '\');
  2477. var truncatedURL = window.location.origin + window.location.pathname + "?" + urlParamsObject.toString();
  2478. window.history.replaceState({}, document.title, truncatedURL);
  2479. }
  2480. ';
  2481. }
  2482. $result = '
  2483. $(document).ready( function () {
  2484. var table = $(\'[id ^= "jqdt_"][role = "grid"]\').DataTable();
  2485. table.on( \'init\', function () {
  2486. var row = table.row(function ( idx, data, node ) {
  2487. return data[' . $columnNum . '] == \'' . $searchVal . '\';
  2488. });
  2489. if (row.length > 0) {
  2490. row.select().show().draw(false);
  2491. }
  2492. });
  2493. ' . $truncateJSCode . '
  2494. });
  2495. ';
  2496. return ($result);
  2497. }
  2498. /**
  2499. * Retruns a JS snippet for processing JQDT "details" functional
  2500. *
  2501. * @param $ajaxURL - URL to retrive data into "details" DIV
  2502. * @param $colIndex - above-level JQDT column index to get the AJAX data from
  2503. * @param $jqdtID - above-level JQDT DOM ID
  2504. * @param string $ajaxMethod
  2505. * @param string $jsFuncName - JS function name which will be called on processing the "details click"
  2506. * @param string $divContainerCSS - some CSS for "details" DIV
  2507. *
  2508. * @return string
  2509. */
  2510. function wf_JQDTDetailsClickProcessingJS($ajaxURL, $colIndex, $jqdtID, $ajaxMethod = 'POST', $jsFuncName = 'showDetailsData', $divContainerCSS = '') {
  2511. $divCSS = (empty($divContainerCSS) ? '{"margin-top":"5px", "margin-left":"10px", "margin-bottom":"10px"}' : $divContainerCSS);
  2512. $result = '
  2513. $(document).ready(function() {
  2514. $(\'#' . $jqdtID . ' tbody\').on(\'click\', \'td.details-control\', function (evt) {
  2515. evt.stopPropagation();
  2516. var table = $(\'#' . $jqdtID . '\').DataTable();
  2517. var tr = $(this).closest(\'tr\');
  2518. var row = table.row( tr );
  2519. var rowIdx = row.index();
  2520. var ajaxData = table.cell(rowIdx, ' . $colIndex . ').data();
  2521. if ( row.child.isShown() ) {
  2522. row.child.hide();
  2523. tr.removeClass(\'shown\');
  2524. }
  2525. else {
  2526. row.child( ' . $jsFuncName . '(row.data(), ajaxData, \'' . $ajaxURL . '\', \'' . $ajaxMethod . '\') ).show();
  2527. tr.addClass(\'shown\');
  2528. }
  2529. } );
  2530. function ' . $jsFuncName . ' ( rowData, ajaxData, ajaxURL, ajaxMethod ) {
  2531. var div = $(\'<div/>\')
  2532. .addClass( \'detailsLoading\' )
  2533. .text( \'Loading...\' );
  2534. $.ajax( {
  2535. type: ajaxMethod,
  2536. url: ajaxURL,
  2537. data: ajaxData,
  2538. success: function ( reqResult ) {
  2539. div.html( reqResult ).removeClass( \'loading\' );
  2540. div.css(' . $divCSS . ');
  2541. }
  2542. } );
  2543. return div;
  2544. }
  2545. } );
  2546. ';
  2547. return ($result);
  2548. }
  2549. /**
  2550. * Returns simple JQDT refresh link with JS snippet
  2551. *
  2552. * @param string $jqdtID
  2553. * @param string $jqdtIDSelector
  2554. * @param string $class
  2555. * @param string $opts
  2556. *
  2557. * @return string
  2558. */
  2559. function wf_JQDTRefreshButton($jqdtID = '', $jqdtIDSelector = '', $class = '', $opts = '') {
  2560. $result = '';
  2561. if (!empty($jqdtID) or !empty($jqdtIDSelector)) {
  2562. $class = (empty($class) ? 'ubButtonInline' : $class);
  2563. $tmpInpID = wf_InputId();
  2564. $result = wf_Link('#', wf_img('skins/refresh.gif', __('Refresh table data'), 'vertical-align: bottom'), false, $class, 'id="' . $tmpInpID . '" ' . $opts);
  2565. $tmpScript = '
  2566. $(\'#' . $tmpInpID . '\').click(function(evt) {
  2567. $(\'img\', this).addClass("image_rotate");
  2568. ';
  2569. if (empty($jqdtID)) {
  2570. $tmpScript .= '$(\'#\'+' . $jqdtIDSelector . ').DataTable().ajax.reload();';
  2571. } else {
  2572. $tmpScript .= '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();';
  2573. }
  2574. $tmpScript .= '
  2575. $(\'img\', this).removeClass("image_rotate");
  2576. evt.preventDefault();
  2577. return false;
  2578. });
  2579. ';
  2580. $result .= wf_EncloseWithJSTags($tmpScript);
  2581. }
  2582. return ($result);
  2583. }
  2584. /**
  2585. * Outputs a hex color based text string without # at begin, like an ac1c09
  2586. *
  2587. * @param $text String of text
  2588. * @param $palette Integer between 0 and 100
  2589. *
  2590. * @return string
  2591. */
  2592. function wf_genColorCodeFromText($text, $palette = '') {
  2593. $hash = md5($palette . $text); // modify input to get a different palette
  2594. $result = '';
  2595. $result = substr($hash, 0, 2) . substr($hash, 2, 2) . substr($hash, 4, 2);
  2596. return ($result);
  2597. }
  2598. /**
  2599. * Renders Google 3d pie chart
  2600. *
  2601. * @param array $params data in format like string=>count
  2602. * @param string $title chart title
  2603. * @param string $width chart width in px or %, 500px default
  2604. * @param string $height chart height in px or %, 500px default
  2605. * @param string $options google charts options, useful examples see below<br>
  2606. * pieSliceText: percentage/value/label/none OR pieSliceText: 'value-and-percentage'<br>
  2607. * is3D: true/false <br>
  2608. * backgroundColor: '#666', <br>
  2609. * legend : {position: 'bottom', textStyle: {color: 'red', fontSize: 12 }}, <br>
  2610. * chartArea: { width: '90%', height: '90%' }, <br>
  2611. * @param string $fixedColors use fixed auto-generated colors based on text labels with pallette<br>
  2612. *
  2613. * @return string
  2614. */
  2615. function wf_gcharts3DPie($params, $title = '', $width = '', $height = '', $options = '', $fixedColors = '') {
  2616. global $ubillingConfig;
  2617. $altCfg = $ubillingConfig->getAlter();
  2618. $containerId = wf_InputId();
  2619. $width = ($width) ? $width : '500px';
  2620. $height = ($height) ? $height : '500px';
  2621. $result = '';
  2622. $chartData = '';
  2623. $enableFlag = true;
  2624. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2625. $enableFlag = true;
  2626. } else {
  2627. if ($altCfg['GCHARTS_ENABLED']) {
  2628. $enableFlag = true;
  2629. } else {
  2630. $enableFlag = false;
  2631. }
  2632. }
  2633. if ($enableFlag) {
  2634. $colors = '';
  2635. if ($fixedColors) {
  2636. $palette = (is_bool($fixedColors)) ? '' : $fixedColors; //use string parameter as palette
  2637. $colors .= 'var colors = { ';
  2638. }
  2639. if (!empty($params)) {
  2640. foreach ($params as $io => $each) {
  2641. $chartData .= '[\'' . $io . '\',' . $each . '],';
  2642. if ($fixedColors) {
  2643. $colors .= " '" . $io . "': '" . wf_genColorCodeFromText($io, $palette) . "',";
  2644. }
  2645. }
  2646. $chartData = substr($chartData, 0, -1);
  2647. }
  2648. if ($fixedColors) {
  2649. $colors = rtrim($colors, ',');
  2650. $colors .= '};';
  2651. }
  2652. if ($fixedColors) {
  2653. $colors .= ' var slices = [];
  2654. for (var i = 0; i < data.getNumberOfRows(); i++) {
  2655. slices.push({
  2656. color: colors[data.getValue(i, 0)]
  2657. });
  2658. }';
  2659. $slicesInject = 'slices: slices,';
  2660. } else {
  2661. $slicesInject = '';
  2662. }
  2663. //legend.scrollArrows.activeColor
  2664. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.google.com/jsapi"') . wf_tag('script', true);
  2665. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2666. $result .= '
  2667. google.load("visualization", "1", {packages:["corechart"]});
  2668. google.setOnLoadCallback(drawChart);
  2669. function drawChart() {
  2670. var data = google.visualization.arrayToDataTable([
  2671. [\'X\', \'Y\'],
  2672. ' . $chartData . '
  2673. ]);
  2674. ' . $colors . '
  2675. var options = {
  2676. title: \'' . $title . '\',
  2677. ' . $slicesInject . '
  2678. is3D: true,
  2679. ' . $options . '
  2680. \'tooltip\' : {
  2681. trigger: \'none\'
  2682. }
  2683. };
  2684. var chart = new google.visualization.PieChart(document.getElementById(\'' . $containerId . '\'));
  2685. chart.draw(data, options);
  2686. }
  2687. ';
  2688. $result .= wf_tag('script', true);
  2689. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2690. }
  2691. return ($result);
  2692. }
  2693. /**
  2694. * Renders Google line chart
  2695. *
  2696. * @param array $params data in format like
  2697. * $params=array(
  2698. * 0=>array('month','total','active','inactive'),
  2699. * 1=>array('Февраль',200,150,50),
  2700. * 2=>array('Сентябрь',200,160,40)
  2701. * );
  2702. * @param string $title chart title
  2703. * @param string $width chart width in px or %, 500px default
  2704. * @param string $height chart height in px or %, 500px default
  2705. * @param string $options google charts options
  2706. *
  2707. * @return string
  2708. */
  2709. function wf_gchartsLine($params, $title = '', $width = '', $height = '', $options = '') {
  2710. global $ubillingConfig;
  2711. $altCfg = $ubillingConfig->getAlter();
  2712. $containerId = wf_InputId();
  2713. $width = ($width) ? $width : '500px';
  2714. $height = ($height) ? $height : '500px';
  2715. $result = '';
  2716. $chartData = '';
  2717. $enableFlag = true;
  2718. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2719. $enableFlag = true;
  2720. } else {
  2721. if ($altCfg['GCHARTS_ENABLED']) {
  2722. $enableFlag = true;
  2723. } else {
  2724. $enableFlag = false;
  2725. }
  2726. }
  2727. if ($enableFlag) {
  2728. if (!empty($params)) {
  2729. $chartData = json_encode($params, JSON_NUMERIC_CHECK);
  2730. }
  2731. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  2732. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2733. $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
  2734. google.charts.setOnLoadCallback(drawChart);
  2735. function drawChart() {
  2736. var data = google.visualization.arrayToDataTable(
  2737. ' . $chartData . '
  2738. );
  2739. var options = {
  2740. title: \'' . $title . '\',
  2741. curveType: \'function\',
  2742. ' . $options . '
  2743. };
  2744. var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
  2745. chart.draw(data, options);
  2746. }
  2747. ';
  2748. $result .= wf_tag('script', true);
  2749. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2750. }
  2751. return ($result);
  2752. }
  2753. /**
  2754. * Renders Google line chart
  2755. *
  2756. * @param array $params data in format like
  2757. * $params=array(
  2758. * 0=>array('month','total','active','inactive'),
  2759. * 1=>array('Февраль',200,150,50),
  2760. * 2=>array('Сентябрь',200,160,40)
  2761. * );
  2762. * @param string $title chart title
  2763. * @param string $width chart width in px or %, 500px default
  2764. * @param string $height chart height in px or %, 500px default
  2765. * @param string $options google charts options
  2766. *
  2767. * @return string
  2768. */
  2769. function wf_gchartsLineZeroIsBad($params, $title = '', $width = '', $height = '', $options = '') {
  2770. global $ubillingConfig;
  2771. $altCfg = $ubillingConfig->getAlter();
  2772. $containerId = wf_InputId();
  2773. $width = ($width) ? $width : '500px';
  2774. $height = ($height) ? $height : '500px';
  2775. $result = '';
  2776. $chartData = '';
  2777. $enableFlag = true;
  2778. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2779. $enableFlag = true;
  2780. } else {
  2781. if ($altCfg['GCHARTS_ENABLED']) {
  2782. $enableFlag = true;
  2783. } else {
  2784. $enableFlag = false;
  2785. }
  2786. }
  2787. if ($enableFlag) {
  2788. if (!empty($params)) {
  2789. $chartData = json_encode($params, JSON_NUMERIC_CHECK);
  2790. }
  2791. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  2792. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2793. $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
  2794. google.charts.setOnLoadCallback(drawChart);
  2795. function drawChart() {
  2796. var data = google.visualization.arrayToDataTable(
  2797. ' . $chartData . '
  2798. );
  2799. var options = {
  2800. title: \'' . $title . '\',
  2801. curveType: \'function\',
  2802. ' . $options . '
  2803. legend: { position: \'bottom\' }
  2804. };
  2805. var dataView = new google.visualization.DataView(data);
  2806. dataView.setColumns([
  2807. // reference existing columns by index
  2808. 0, 1,
  2809. // add function for line color
  2810. {
  2811. calc: function(data, row) {
  2812. var colorDown = "#FF0000";
  2813. var colorUp = "#0d8a00";
  2814. if ((data.getValue(row, 1) < 0)) {
  2815. return colorDown;
  2816. } else {
  2817. //return colorUp;
  2818. }
  2819. },
  2820. type: "string",
  2821. role: "style"
  2822. }
  2823. ]);
  2824. var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
  2825. chart.draw(dataView, options);
  2826. }
  2827. ';
  2828. $result .= wf_tag('script', true);
  2829. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2830. }
  2831. return ($result);
  2832. }
  2833. /**
  2834. * Returns default back control
  2835. *
  2836. * @param string $url Link URL
  2837. * @param string $title Link title
  2838. * @param bool $br Line break line after link
  2839. * @param string $class Link class name
  2840. * @param string $opts Link style or attributes
  2841. *
  2842. * @return string
  2843. */
  2844. function wf_BackLink($url, $title = '', $br = false, $class = 'ubButton', $opts = '') {
  2845. $title = (empty($title)) ? __('Back') : __($title);
  2846. $result = wf_Link($url, wf_img('skins/back.png') . ' ' . $title, $br, $class, $opts);
  2847. return ($result);
  2848. }
  2849. /**
  2850. * Returns form disabler JS code, for preventing duplicating POST requests
  2851. *
  2852. * @return string
  2853. */
  2854. function wf_FormDisabler() {
  2855. $result = wf_tag('script', false, '', 'type="text/javascript" language="javascript" src="modules/jsc/form-disabler.js"') . wf_tag('script', true);
  2856. return ($result);
  2857. }
  2858. /**
  2859. * Returns spoiler control with specified options
  2860. *
  2861. * @param string $Content
  2862. * @param string $Title
  2863. * @param bool $Closed
  2864. * @param string $SpoilerID
  2865. * @param string $OuterDivClass
  2866. * @param string $OuterDivOptions
  2867. * @param string $InnerDivClass
  2868. * @param string $InnerDivOptions
  2869. *
  2870. * @return string
  2871. */
  2872. function wf_Spoiler($Content, $Title = '', $Closed = false, $SpoilerID = '', $OuterDivClass = '', $OuterDivOptions = '', $InnerDivClass = '', $InnerDivOptions = '') {
  2873. if (empty($SpoilerID)) {
  2874. $SpoilerID = 'spoiler_' . wf_InputId();
  2875. }
  2876. $SpoilerLnkID = 'lnk_' . wf_InputId();
  2877. $SpoilerBodyID = 'spbody_' . wf_InputId();
  2878. $SpoilerStateID = 'spstate_' . wf_InputId();
  2879. $SpoilerState = ($Closed) ? '▼' : '▲';
  2880. //$ubngStrPos = strpos(CUR_SKIN_PATH, 'ubng');
  2881. $OuterDivClass = 'spoiler clearfix ' . $OuterDivClass;
  2882. $OuterDivOptions = ' id="' . $SpoilerID . '" ' . $OuterDivOptions;
  2883. $InnerDivClass = 'spoiler_body ' . $InnerDivClass;
  2884. $InnerDivOptions = ' id="' . $SpoilerBodyID . '" ' . $InnerDivOptions;
  2885. $Result = wf_tag('div', false, $OuterDivClass, $OuterDivOptions);
  2886. $Result .= wf_tag('div', false, 'spoiler_title clearfix');
  2887. //$Result .= '<a id="' . $SpoilerLnkID . '" class="spoiler_link" href="#">';
  2888. $Result .= '<span id="' . $SpoilerLnkID . '" class="spoiler_link">';
  2889. $Result .= wf_tag('h3', false, '', '');
  2890. $Result .= $Title;
  2891. $Result .= wf_tag('h3', true);
  2892. //$Result .= $SpoilerState . '</a>' . "\n";
  2893. $Result .= '<span id="' . $SpoilerStateID . '">' . $SpoilerState . '</span>';
  2894. $Result .= '</span>' . "\n";
  2895. $Result .= wf_tag('div', true);
  2896. $Result .= wf_tag('div', false, $InnerDivClass, $InnerDivOptions);
  2897. $Result .= $Content;
  2898. $Result .= wf_tag('div', true);
  2899. $Result .= wf_tag('div', true);
  2900. $Result .= wf_tag('script', false, '', 'type="text/javascript"');
  2901. $Result .= '$(\'#' . $SpoilerLnkID . '\').click(function() {
  2902. $(\'#' . $SpoilerBodyID . '\').toggleClass("spoiler_closed");
  2903. if ( $(\'#' . $SpoilerBodyID . '\').hasClass("spoiler_closed") ) {
  2904. $(\'#' . $SpoilerBodyID . '\').slideUp(\'50\');
  2905. $(\'#' . $SpoilerStateID . '\').html(\'▼\');
  2906. } else {
  2907. $(\'#' . $SpoilerBodyID . '\').slideDown(\'50\');
  2908. $(\'#' . $SpoilerStateID . '\').html(\'▲\');
  2909. }
  2910. return false;
  2911. });';
  2912. //$Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').css("display", "none").toggleClass("spoiler_closed");' : '';
  2913. $Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').slideUp(\'50\').toggleClass("spoiler_closed");' : '';
  2914. $Result .= wf_tag('script', true);
  2915. return $Result;
  2916. }
  2917. /**
  2918. * Returns JS for a control which will be responsible for opening dynamic modal windows via ajax call to a specific URL
  2919. *
  2920. * @param $ajaxURL
  2921. * @param $dataArray
  2922. * @param string $controlId
  2923. * @param bool $wrapWithJSScriptTag
  2924. * @param string $queryType
  2925. * @param string $jsEvent
  2926. * @param bool $noPreventDefault
  2927. * @param bool $noReturnFalse
  2928. * @param bool $updNestedJQDT
  2929. * @param string $nestedJQDTSelector
  2930. *
  2931. * @return string
  2932. */
  2933. function wf_JSAjaxModalOpener($ajaxURL, $dataArray, $controlId = '', $wrapWithJSScriptTag = false, $queryType = 'GET', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
  2934. $inputId = (empty($controlId)) ? wf_InputId() : $controlId;
  2935. $modalWindowId = 'modalWindowId:"dialog-modal_' . $inputId . '", ';
  2936. $modalWindowBodyId = 'modalWindowBodyId:"body_dialog-modal_' . $inputId . '"';
  2937. $preventDefault = ($noPreventDefault) ? "" : "\nevt.preventDefault();";
  2938. $returnFalse = ($noReturnFalse) ? "" : "\nreturn false;";
  2939. $ajaxData = '';
  2940. foreach ($dataArray as $io => $each) {
  2941. if (is_array($each)) {
  2942. $ajaxData .= $io . ':' . json_encode($each) . ', ';
  2943. } else {
  2944. $ajaxData .= $io . ':"' . $each . '", ';
  2945. }
  2946. }
  2947. if ($updNestedJQDT) {
  2948. $findJQDTToUpdate = (empty($nestedJQDTSelector) ? 'var closestJQDTID = $(this).parent().parent().next("tr").find(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");' : 'var closestJQDTID = ' . $nestedJQDTSelector);
  2949. } else {
  2950. $findJQDTToUpdate = 'var closestJQDTID = $(this).closest(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");';
  2951. }
  2952. $result = '$(\'#' . $inputId . '\').' . $jsEvent . '(function(evt) {
  2953. ' . $findJQDTToUpdate . '
  2954. $.ajax({
  2955. type: "' . $queryType . '",
  2956. url: "' . $ajaxURL . '",
  2957. data: {' . $ajaxData
  2958. . $modalWindowId
  2959. . $modalWindowBodyId
  2960. . '},
  2961. success: function(ajaxresult) {
  2962. $(document.body).append(ajaxresult);
  2963. $(\'#dialog-modal_' . $inputId . '\').append(\'<input type="hidden" name="closestJQDT" value="\' + closestJQDTID + \'" id="closestJQDTID">\');
  2964. $(\'#dialog-modal_' . $inputId . '\').dialog("open");
  2965. }
  2966. });'
  2967. . $preventDefault
  2968. . $returnFalse
  2969. . '});
  2970. ';
  2971. if ($wrapWithJSScriptTag) {
  2972. $result = wf_tag('script', false, '', 'type="text/javascript"')
  2973. . $result
  2974. . wf_tag('script', true);
  2975. }
  2976. return ($result);
  2977. }
  2978. /**
  2979. * Returns JS for a link which will be responsible for opening an assigned modal window
  2980. *
  2981. * @param $ajaxURL
  2982. * @param $ajaxDataArr
  2983. * @param string $title
  2984. * @param string $icon
  2985. * @param string $linkCSSClass
  2986. * @param string $queryType
  2987. * @param string $jsEvent
  2988. * @param bool $noPreventDefault
  2989. * @param bool $noReturnFalse
  2990. * @param bool $updNestedJQDT
  2991. * @param string $nestedJQDTSelector
  2992. *
  2993. * @return string
  2994. */
  2995. function wf_jsAjaxDynamicWindowButton($ajaxURL, $ajaxDataArr, $title = 'Button', $icon = '', $linkCSSClass = '', $queryType = 'POST', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
  2996. $linkID = wf_InputId();
  2997. $dynamicOpener = wf_Link('#', $icon . ' ' . $title, false, $linkCSSClass, 'id="' . $linkID . '"')
  2998. . wf_JSAjaxModalOpener($ajaxURL, $ajaxDataArr, $linkID, true, $queryType, $jsEvent, $noPreventDefault, $noReturnFalse, $updNestedJQDT, $nestedJQDTSelector);
  2999. return ($dynamicOpener);
  3000. }
  3001. /**
  3002. * Inserts JS-code to process submitting of multiple dynamically or statically created MODAL FORMS via AJAX call
  3003. * To work properly, requires wf_JSEmptyFunc() and wf_JSElemInsertedCatcherFunc() routines to be inserted on a page beforehand.
  3004. * Also it's better to pass a JQUERY DataTable ID to be able to update a certain JQDT records
  3005. *
  3006. * @param string $submitFormClasses (need to be passed with leading dot, several classes may be passed )
  3007. * @param string $submitFormIDCtrlClass (need to be passed with leading dot)
  3008. * @param string $jqdtID
  3009. * @param string $emptyValueCheckClasses (need to be passed with leading dot)
  3010. * @param string $errorFormIDParamName
  3011. *
  3012. * @return string
  3013. */
  3014. function wf_jsAjaxFormSubmit($submitFormClasses, $submitFormIDCtrlClass, $jqdtID = '', $emptyValueCheckClasses = '', $errorFormIDParamName = '') {
  3015. $result = '';
  3016. $emptyValueCheckClasses = (empty($emptyValueCheckClasses) ? '__EmptyCheckControl' : $emptyValueCheckClasses);
  3017. $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
  3018. $errorModalWindowId = wf_InputId();
  3019. $result .= '
  3020. function checkEmptyVal(ctrlClassName) {
  3021. $(document).on("focus keydown", ctrlClassName, function(evt) {
  3022. $(document).find(ctrlClassName).each(function(indx, element){
  3023. if ( $(element).hasClass(\'__MandatoryEmpty\') ) {
  3024. $(element).val("");
  3025. $(element).css("border-color", "");
  3026. $(element).css("color", "");
  3027. $(element).toggleClass(\'__MandatoryEmpty\');
  3028. }
  3029. });
  3030. });
  3031. }
  3032. // for already inserted elements on page load
  3033. checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
  3034. // for newly inserted elements after page load
  3035. onElementInserted(\'body\', \'' . $emptyValueCheckClasses . '\', function(element) {
  3036. checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
  3037. });
  3038. $(document).on("submit", "' . $submitFormClasses . '", function(evt) {
  3039. evt.preventDefault();
  3040. var emptyCheckClass = \'' . $emptyValueCheckClasses . '\';
  3041. var mandatoryFldsEmpty = false;
  3042. $(this).find(emptyCheckClass).each(function(indx, element){
  3043. if ( empty($(element).val()) ) {
  3044. $(element).css("border-color", "red");
  3045. $(element).css("color", "grey");
  3046. $(element).val("' . __('Mandatory field') . '");
  3047. $(element).toggleClass(\'__MandatoryEmpty\');
  3048. mandatoryFldsEmpty = true
  3049. }
  3050. });
  3051. if (!mandatoryFldsEmpty) {
  3052. var FrmAction = $(this).attr("action");
  3053. var FrmData = $(this).serialize() + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\';
  3054. $.ajax({
  3055. type: "POST",
  3056. url: FrmAction,
  3057. data: FrmData,
  3058. success: function(result) {
  3059. if ( !empty(result) ) {
  3060. $(document.body).append(result);
  3061. $( \'#' . $errorModalWindowId . '\' ).dialog("open");
  3062. } else {
  3063. var customJQDTToReload = $(\'#closestJQDTID\').val();
  3064. if (!empty(customJQDTToReload)) {
  3065. $(\'#\' + customJQDTToReload).DataTable().ajax.reload();
  3066. } else {
  3067. ' . (empty($jqdtID) ? ' ' : '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();') . '
  3068. }
  3069. $( \'#\' + $("' . $submitFormIDCtrlClass . '").val() ).dialog("close");
  3070. }
  3071. }
  3072. });
  3073. }
  3074. });
  3075. ';
  3076. return ($result);
  3077. }
  3078. /**
  3079. * Returns a simple wrapper for a JS function with ajax request which can be used later for multiple "callers"
  3080. * e.g. - to delete record from DB or whatever
  3081. *
  3082. * @param $funcName
  3083. * @param string $jqdtID
  3084. * @param string $jqdtIDSelector
  3085. * @param string $errorFormIDParamName
  3086. * @param string $queryType
  3087. * @param bool $jqdtClearBeforePaste
  3088. *
  3089. * @return string
  3090. */
  3091. function wf_jsAjaxCustomFunc($funcName, $jqdtID = '', $jqdtIDSelector = '', $errorFormIDParamName = '', $queryType = 'POST', $jqdtClearBeforePaste = false) {
  3092. $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
  3093. $errorModalWindowId = wf_InputId();
  3094. $jqdtReloadScript = '';
  3095. $jqdtSelector = '';
  3096. $result = '';
  3097. if (!empty($jqdtID)) {
  3098. $jqdtSelector = '$(\'#' . $jqdtID . '\')';
  3099. } elseif (!empty($jqdtIDSelector)) {
  3100. $jqdtSelector = '$(\'#\'+' . $jqdtIDSelector . ')';
  3101. }
  3102. if (!empty($jqdtSelector)) {
  3103. if ($jqdtClearBeforePaste) {
  3104. $jqdtReloadScript = '
  3105. if ( !empty(reqResult) ) {
  3106. var json = jQuery.parseJSON(reqResult);
  3107. var table = ' . $jqdtSelector . '.DataTable();
  3108. table.clear(); //clear the current data
  3109. table.rows.add(json[\'aaData\']).draw();
  3110. }
  3111. ';
  3112. } else {
  3113. $jqdtReloadScript = '
  3114. if ( !empty(reqResult) ) {
  3115. $(document.body).append(reqResult);
  3116. if ($(\'#' . $errorFormIDParamName . '\')) {
  3117. $(\'#' . $errorFormIDParamName . '\').dialog("open");
  3118. }
  3119. }
  3120. ' . $jqdtSelector . '.DataTable().ajax.reload();
  3121. ';
  3122. }
  3123. }
  3124. $result .= '
  3125. function ' . $funcName . '(ajaxURL, ajaxData) {
  3126. var ajaxData = ajaxData + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\'
  3127. $.ajax({
  3128. type: "' . $queryType . '",
  3129. url: ajaxURL,
  3130. data: ajaxData,
  3131. success: function(reqResult) {
  3132. '
  3133. . $jqdtReloadScript .
  3134. '}
  3135. });
  3136. }
  3137. ';
  3138. return ($result);
  3139. }
  3140. /**
  3141. * JS snippet for a filtering form for JQDT. Needs a bit of specific handling
  3142. *
  3143. * @param $ajaxURLStr
  3144. * @param $formID
  3145. * @param $jqdtID
  3146. *
  3147. * @return string
  3148. */
  3149. function wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID) {
  3150. $result = '
  3151. $(\'#' . $formID . '\').submit(function(evt) {
  3152. evt.preventDefault();
  3153. $.ajax({
  3154. url: "' . $ajaxURLStr . '",
  3155. type: "POST",
  3156. data: $(\'#' . $formID . '\').serialize(),
  3157. success: function(reqResult) {
  3158. var json = jQuery.parseJSON(reqResult);
  3159. var table = $(\'#' . $jqdtID . '\').DataTable();
  3160. table.clear(); //clear the current data
  3161. table.rows.add(json[\'aaData\']).draw();
  3162. }
  3163. });
  3164. });
  3165. ';
  3166. return ($result);
  3167. }
  3168. /**
  3169. * Returns a JS-snippet for a regular selector-control cascade filtering by pre-prepared data
  3170. * The point is:
  3171. * we have a hidden input with a predefined data, like:
  3172. * valueInAboveLevelSelector1 => correspondingValueInChildSelector1
  3173. * valueInAboveLevelSelector1 => correspondingValueInChildSelector2
  3174. * valueInAboveLevelSelector1 => correspondingValueInChildSelector3
  3175. * valueInAboveLevelSelector2 => correspondingValueInChildSelector1
  3176. * valueInAboveLevelSelector2 => correspondingValueInChildSelector2
  3177. * valueInAboveLevelSelector2 => correspondingValueInChildSelector3
  3178. * valueInAboveLevelSelector2 => correspondingValueInChildSelector4
  3179. * valueInAboveLevelSelectorN => correspondingValueInChildSelectorNN
  3180. * ..................................................................
  3181. *
  3182. * When a user selects a value in AboveLevelSelector we take that array from hidden input and walk through it -
  3183. * when we find a key equal to selected in AboveLevelSelector value - we take that element in a variable
  3184. * to build a new contents for a child selector. And the same for each key which equals to selected from AboveLevelSelector value
  3185. *
  3186. *
  3187. * @param string $webSelectorID
  3188. * @param string $webSelectorIDToFilter
  3189. * @param string $filterDataElemID
  3190. * @param string $filterFuncName
  3191. * @param bool $blankFirstRow
  3192. * @param string $blankFirstRowVal
  3193. * @param string $blankFirstRowDispVal
  3194. *
  3195. * @return string
  3196. */
  3197. /* function wf_jsWebSelectorFilter($webSelectorID, $webSelectorIDToFilter, $filterDataElemID,
  3198. $webSelChangeFuncName = '', $filterFuncName = '',
  3199. $blankFirstRow = false, $blankFirstRowVal = '0', $blankFirstRowDispVal = '----') {
  3200. $webSelChangeFuncName = (empty($webSelChangeFuncName) ? 'funcChange_' . $webSelectorIDToFilter : $webSelChangeFuncName);
  3201. $filterFuncName = (empty($filterFuncName) ? 'funcFilter_' . $webSelectorIDToFilter : $filterFuncName);
  3202. $webSelectRunChange = (empty($webSelectorIDToFilter) ? "" : "$('#" . $webSelectorIDToFilter . "').change();");
  3203. $firstRowBlank = ($blankFirstRow ? "var newselect = '<option value=\"" . $blankFirstRowVal . "\">" . $blankFirstRowDispVal . "</option>';" : "");
  3204. */
  3205. function wf_jsWebSelectorFilter() {
  3206. $result = '
  3207. function filterWebDropdown(search_keyword, filterListVals, webSelectRun2ChangeID,
  3208. firstRowBlank = true, blankRowVal = "0", blankRowDispVal = "----") {
  3209. if ( !empty(filterListVals.length) ) {
  3210. var search_array = JSON.parse(atob(filterListVals));
  3211. } else {
  3212. return;
  3213. }
  3214. var newselect = "";
  3215. if (firstRowBlank) {
  3216. newselect = \'<option value="\' + blankRowVal + \'">\' + blankRowDispVal + \'</option>\';
  3217. }
  3218. if (search_keyword.length > 0 && search_keyword.trim() !== blankRowDispVal) {
  3219. for (var key in search_array) {
  3220. if ( key.trim() !== "" && key.toLowerCase() == search_keyword.toLowerCase() ) {
  3221. var foundVal = search_array[key];
  3222. for (var foundKey in foundVal) {
  3223. var foundKeyVal = foundVal[foundKey];
  3224. for (var dbID in foundKeyVal) {
  3225. newselect = newselect + \'<option value="\' + dbID + \'">\' + foundKeyVal[dbID] + \'</option>\';
  3226. }
  3227. }
  3228. }
  3229. }
  3230. }
  3231. $(\'#\' + webSelectRun2ChangeID).html(newselect);
  3232. $(\'#\' + webSelectRun2ChangeID).change();
  3233. }
  3234. ';
  3235. return ($result);
  3236. }
  3237. /**
  3238. * Simply encloses a JS snippet with a 'script' open/close tags
  3239. *
  3240. * @param string $content
  3241. *
  3242. * @return string
  3243. */
  3244. function wf_EncloseWithJSTags($content) {
  3245. $result = wf_tag('script', false, '', 'type="text/javascript"');
  3246. $result .= $content;
  3247. $result .= wf_tag('script', true);
  3248. return ($result);
  3249. }
  3250. /**
  3251. * Generates tabbed UI for almost any data.
  3252. *
  3253. * @param $tabsDivID - ID of the main tab div
  3254. * @param $tabsList - array of: tab ID => array('tab_options' => 'options',
  3255. * 'tab_caption' => 'caption,
  3256. * 'additional_data' => 'anything')
  3257. * which represents the tabs itself.
  3258. * Additional data can be anything, like some JS script or comments or whatever.
  3259. * @param $tabsBody - array of: div ID => array('div_options' => 'options',
  3260. * 'tab_body_data' => 'data'
  3261. * 'additional_data' => 'anything')
  3262. * which represents the divs with tabs data.
  3263. * Additional data can be anything, like some JS script or comments or whatever.
  3264. * @param string $mainDivOpts
  3265. * @param string $ulOpts
  3266. * @param bool $tabsCarouselOn
  3267. *
  3268. * @return string
  3269. */
  3270. function wf_TabsGen($tabsDivID, $tabsList, $tabsBody, $mainDivOpts = '', $ulOpts = '', $tabsCarouselOn = false) {
  3271. $result = '';
  3272. if (!empty($tabsDivID) and !empty($tabsList) and !empty($tabsBody)) {
  3273. $divOps = 'id="' . $tabsDivID . '" ' . $mainDivOpts;
  3274. $initTabsJSStr = '$( "#' . $tabsDivID . '" ).tabs();';
  3275. if ($tabsCarouselOn) {
  3276. $initTabsJSStr = '$("#' . $tabsDivID . '").scrollTabs({
  3277. scrollOptions: {
  3278. showFirstLastArrows: false,
  3279. closable: false
  3280. }
  3281. });
  3282. // dirty hack for scrollTabsPlugin to select the very first tab
  3283. $( "#' . $tabsDivID . '" ).scrollTabs("option", "active", 0);
  3284. // another hack for Firefox
  3285. $(".ui-scroll-tabs-view").css("margin-bottom", "0");
  3286. ';
  3287. }
  3288. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  3289. $result .= ' $( function() { ' .
  3290. $initTabsJSStr .
  3291. ' } );
  3292. ';
  3293. $result .= wf_tag('script', true);
  3294. $result .= wf_tag('div', false, '', $divOps);
  3295. $result .= wf_tag('ul', false, '', $ulOpts);
  3296. foreach ($tabsList as $tabhref => $tabData) {
  3297. $result .= wf_tag('li') .
  3298. wf_tag('a', false, '', 'href="#' . $tabhref . '" ' . $tabData['options']) .
  3299. $tabData['caption'] .
  3300. wf_tag('a', true) .
  3301. wf_tag('li', true) .
  3302. $tabData['additional_data'];
  3303. }
  3304. $result .= wf_tag('ul', true);
  3305. foreach ($tabsBody as $bodyID => $bodyData) {
  3306. $result .= wf_tag('div', false, '', 'id="' . $bodyID . '" ' . $bodyData['options']) .
  3307. $bodyData['body'] .
  3308. wf_tag('div', true) .
  3309. $bodyData['additional_data'];
  3310. }
  3311. $result .= wf_tag('div', true);
  3312. }
  3313. return ($result);
  3314. }
  3315. /**
  3316. * Returns scripts and CSS links for tabs carousel plugin.
  3317. * Be sure to add this once to a page if you planning to use wf_TabsGen function with tabsCarouselOn
  3318. */
  3319. function wf_TabsCarouselInitLinking() {
  3320. $result = '<link rel="stylesheet" href="modules/jsc/JQUI_ScrollTabs/style.css" type="text/css">';
  3321. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ba-throttle-debounce.min.js"></script>';
  3322. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.mousewheel.min.js"></script>';
  3323. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.touchSwipe.min.js"></script>';
  3324. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ui.scrolltabs.js"></script>';
  3325. return ($result);
  3326. }
  3327. /**
  3328. * Returns plain JS-code of 'empty' function to use for checking an empty value in JS code
  3329. *
  3330. * @return string
  3331. */
  3332. function wf_JSEmptyFunc() {
  3333. $Result = '
  3334. function empty (mixed_var) {
  3335. // version: 909.322
  3336. // discuss at: http://phpjs.org/functions/empty
  3337. var key;
  3338. if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === \'null\' || mixed_var === false || mixed_var === undefined || mixed_var === \'undefined\' ) {
  3339. return true;
  3340. }
  3341. if (typeof mixed_var == \'object\') {
  3342. for (key in mixed_var) {
  3343. return false;
  3344. }
  3345. return true;
  3346. }
  3347. return false;
  3348. }
  3349. ';
  3350. return ($Result);
  3351. }
  3352. /**
  3353. * Returns some count of non-breaking space symbols
  3354. *
  3355. * @param int $count
  3356. *
  3357. * @return string
  3358. */
  3359. function wf_nbsp($count = 1) {
  3360. $result = '';
  3361. for ($i = 0; $i < $count; $i++) {
  3362. $result .= '&nbsp;';
  3363. }
  3364. return ($result);
  3365. }
  3366. /**
  3367. * Returns JS onElementInserted() func which allow to make any actions for
  3368. * dynamically created objects right after the moment of it's creation
  3369. * elementSelector MUST be a 'class' or 'id' selector, like '.SomeMyClass' or '#SomeMyID'
  3370. *
  3371. * This code and it's function call must exist on a page BEFORE dynamic elements loaded
  3372. * The 'class' or 'id' selectors which will be used in dynamically loaded content
  3373. * must be known BEFORE the content loaded - so avoid of generating some random IDs on-the-fly,
  3374. * just when that content is loaded or in any other way
  3375. *
  3376. * DO NOT include this code or it's function call(like any other JS code)
  3377. * to a dynamically loaded content - as it WON'T WORK that way
  3378. *
  3379. * Source code: https://stackoverflow.com/a/38517525
  3380. *
  3381. * @return string
  3382. */
  3383. function wf_JSElemInsertedCatcherFunc() {
  3384. $Result = '
  3385. function onElementInserted(containerSelector, elementSelector, callback) {
  3386. var onMutationsObserved = function(mutations) {
  3387. mutations.forEach(function(mutation) {
  3388. if (mutation.addedNodes.length) {
  3389. var foundElements = $(mutation.addedNodes).find(elementSelector);
  3390. if (foundElements.length <= 0) {
  3391. foundElements = $(mutation.addedNodes).closest(elementSelector);
  3392. }
  3393. for (var i = 0, len = foundElements.length; i < len; i++) {
  3394. callback(foundElements[i]);
  3395. }
  3396. }
  3397. if (mutation.type === \'attributes\' && ( (\'.\' + $(mutation.target).attr(\'class\') == elementSelector)
  3398. || (\'#\' + $(mutation.target).attr(\'id\') == elementSelector) )) {
  3399. callback(mutation.target);
  3400. }
  3401. });
  3402. };
  3403. var target = $(containerSelector)[0];
  3404. var config = { childList: true, subtree: true, attributes: true, attributeFilter: ["id", "class"]};
  3405. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  3406. var observer = new MutationObserver(onMutationsObserved);
  3407. observer.observe(target, config);
  3408. }
  3409. ';
  3410. return $Result;
  3411. }
  3412. /**
  3413. * Renders default steps-meter progressbar
  3414. *
  3415. * @param array $params as stepname=>decription
  3416. * @param int $current
  3417. *
  3418. * @return type
  3419. */
  3420. function wf_StepsMeter($params, $current) {
  3421. $style = wf_tag('style');
  3422. $style .= "
  3423. .steps{
  3424. min-height:90px;
  3425. padding:30px 30px 0 30px;
  3426. position:relative
  3427. }
  3428. .steps .steps-container{
  3429. background:#DDD;
  3430. height:10px;
  3431. width:95%;
  3432. border-radius:10px ;
  3433. -moz-border-radius:10px ;
  3434. -webkit-border-radius:10px ;
  3435. -ms-border-radius:10px ;
  3436. margin:0;
  3437. list-style:none
  3438. }
  3439. .steps .steps-container li{
  3440. text-align:center;
  3441. list-style:none;
  3442. float:left
  3443. }
  3444. .steps .steps-container li .step{
  3445. padding:0 50px
  3446. }
  3447. .steps .steps-container li .step .step-image{
  3448. margin:-14px 0 0 0
  3449. }
  3450. .steps .steps-container li .step .step-image span{
  3451. background-color:#DDD;
  3452. display:block;
  3453. width:37px;
  3454. height:37px;
  3455. margin:0 auto;
  3456. border-radius:37px ;
  3457. -moz-border-radius:37px ;
  3458. -webkit-border-radius:37px ;
  3459. -ms-border-radius:37px
  3460. }
  3461. .steps .steps-container li .step .step-current{
  3462. font-size:11px;
  3463. font-style:italic;
  3464. color:#999;
  3465. margin:8px 0 0 0
  3466. }
  3467. .steps .steps-container li .step .step-description{
  3468. font-size:13px;
  3469. font-style:italic;
  3470. color:#538897
  3471. }
  3472. .steps .steps-container li.activated .step .step-image span{
  3473. background-color:#5DC177
  3474. }
  3475. .steps .steps-container li.activated .step .step-image span:after{
  3476. background-color:#FFF;
  3477. display:block;
  3478. content:'';
  3479. position:absolute;
  3480. z-index:1;
  3481. width:27px;
  3482. height:27px;
  3483. margin:5px;
  3484. border-radius:27px ;
  3485. -moz-border-radius:27px ;
  3486. -webkit-border-radius:27px ;
  3487. -ms-border-radius:27px ;
  3488. box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
  3489. -moz-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
  3490. -webkit-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15)
  3491. }
  3492. .steps .step-bar{
  3493. background-color:#5DC177;
  3494. height:10px;
  3495. position:absolute;
  3496. top:30px;
  3497. border-radius:10px 0 0 10px;
  3498. -moz-border-radius:10px 0 0 10px;
  3499. -webkit-border-radius:10px 0 0 10px;
  3500. -ms-border-radius:10px 0 0 10px
  3501. }
  3502. .steps .step-bar.last{
  3503. border-radius:10px ;
  3504. -moz-border-radius:10px ;
  3505. -webkit-border-radius:10px ;
  3506. -ms-border-radius:10px
  3507. }
  3508. ";
  3509. $style .= wf_tag('style', true);
  3510. $count = 1;
  3511. $paramsCount = sizeof($params);
  3512. if (!empty($params)) {
  3513. $width = round(100 / $paramsCount) - 1;
  3514. $code = wf_tag('div', false, 'steps');
  3515. $code .= wf_tag('ul', false, 'steps-container');
  3516. foreach ($params as $io => $each) {
  3517. $currentClass = ($count <= $current) ? 'activated' : '';
  3518. $code .= wf_tag('li', false, $currentClass, 'style="width:' . $width . '%;"');
  3519. $code .= wf_tag('div', false, 'step');
  3520. $code .= wf_tag('div', false, 'step-image') . wf_tag('span') . wf_tag('span', true) . wf_tag('div', true);
  3521. $code .= wf_tag('div', false, 'step-current') . $io . wf_tag('div', true);
  3522. $code .= wf_tag('div', false, 'step-description') . $each . wf_tag('div', true);
  3523. $code .= wf_tag('div', true);
  3524. $code .= wf_tag('li', true);
  3525. $count++;
  3526. }
  3527. $code .= wf_tag('ul', true);
  3528. $widthBar = $width * $current;
  3529. $code .= wf_tag('div', false, 'step-bar', 'style="width: ' . $widthBar . '%;"') . wf_tag('div', true);
  3530. $code .= wf_tag('div', true);
  3531. $code .= wf_CleanDiv();
  3532. $result = $style . $code;
  3533. }
  3534. return ($result);
  3535. }
  3536. /**
  3537. * Returns confirmation dialog to navigate to some URL
  3538. *
  3539. * @param string $url
  3540. * @param string $title
  3541. * @param string $alerttext
  3542. * @param string $class
  3543. * @param string $cancelUrl
  3544. * @param string $customDialogTitle
  3545. *
  3546. * @return string
  3547. */
  3548. function wf_ConfirmDialog($url, $title, $alerttext, $class = '', $cancelUrl = '', $customWindowTitle = '') {
  3549. $result = '';
  3550. $dialog = __($alerttext);
  3551. $dialog .= wf_tag('br');
  3552. $dialog .= wf_tag('center', false);
  3553. $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree');
  3554. if ($cancelUrl) {
  3555. $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel');
  3556. }
  3557. $dialog .= wf_tag('center', true);
  3558. $cleanTitle = strip_tags($title);
  3559. if ($customWindowTitle) {
  3560. $cleanTitle = $customWindowTitle;
  3561. }
  3562. $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class);
  3563. return ($result);
  3564. }
  3565. /**
  3566. * Returns confirmation dialog to navigate to some URL
  3567. *
  3568. * @param string $url
  3569. * @param string $title
  3570. * @param string $alerttext
  3571. * @param string $class
  3572. * @param string $cancelUrl
  3573. * @param string $funcRunAgree
  3574. * @param string $funcRunCancel
  3575. * @param string $modalWinID
  3576. *
  3577. * @return string
  3578. */
  3579. function wf_ConfirmDialogJS($url, $title, $alerttext, $class = '', $cancelUrl = '', $funcRunAgree = '', $funcRunCancel = '', $modalWinID = '') {
  3580. $result = '';
  3581. $modalWinID = (empty($modalWinID) ? 'dialog-modal_' . wf_InputId() : $modalWinID);
  3582. $funcRunAgree = (empty($funcRunAgree) ? '' : ' onclick="' . $funcRunAgree . '; return false; "');
  3583. $funcRunCancel = (empty($funcRunCancel) ? '' : ' onclick="' . $funcRunCancel . '; return false; "');
  3584. $dialog = __($alerttext);
  3585. $dialog .= wf_tag('br');
  3586. $dialog .= wf_tag('center', false);
  3587. $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree', $funcRunAgree);
  3588. if (!empty($cancelUrl) or !empty($funcRunCancel)) {
  3589. $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel', $funcRunCancel);
  3590. }
  3591. $dialog .= wf_tag('center', true);
  3592. $cleanTitle = strip_tags($title);
  3593. $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class, $modalWinID);
  3594. return ($result);
  3595. }
  3596. /**
  3597. * Returns code that plays some sound from existing audio file
  3598. *
  3599. * @param string $url
  3600. *
  3601. * @return string
  3602. */
  3603. function wf_doSound($url) {
  3604. $result = wf_tag('script') . "var audio = new Audio('" . $url . "'); audio.play();" . wf_tag('script', true);
  3605. return ($result);
  3606. }
  3607. /**
  3608. * Renders temperature gauge
  3609. *
  3610. * @param float $temperature
  3611. * @param string $title
  3612. * @param string $options
  3613. *
  3614. * @return string
  3615. */
  3616. function wf_renderTemperature($temperature, $title = '', $options = '') {
  3617. $result = '';
  3618. if (empty($options)) {
  3619. $options = ' max: 100,
  3620. min: 0,
  3621. width: 280, height: 280,
  3622. greenFrom: 10, greenTo: 60,
  3623. yellowFrom:60, yellowTo: 70,
  3624. redFrom: 70, redTo: 100,
  3625. minorTicks: 5';
  3626. }
  3627. $result = wf_renderGauge($temperature, $title, '°C', $options);
  3628. return ($result);
  3629. }
  3630. /**
  3631. * Renders generic gauge
  3632. *
  3633. * @param float $value
  3634. * @param string $title
  3635. * @param string $units
  3636. * @param string $options
  3637. * @param int $size
  3638. *
  3639. * @return string
  3640. */
  3641. function wf_renderGauge($value, $title = '', $units = '', $options = '', $size = 300) {
  3642. $result = '';
  3643. $gaugeId = wf_InputId();
  3644. $sizeContainer = $size;
  3645. $sizeContent = $sizeContainer - 20;
  3646. if (empty($options)) {
  3647. $options = ' max: 100,
  3648. min: 0,
  3649. width: ' . $sizeContent . ', height: ' . $sizeContent . ',
  3650. greenFrom: 10, greenTo: 60,
  3651. yellowFrom:60, yellowTo: 70,
  3652. redFrom: 70, redTo: 100,
  3653. minorTicks: 5';
  3654. }
  3655. $containerStyle = 'width: ' . $sizeContainer . 'px; height: ' . $sizeContainer . 'px; float:left; ';
  3656. $result .= wf_tag('div', false, '', 'style="' . $containerStyle . '"');
  3657. $result .= wf_tag('div', false, '', 'id="gengauge_div' . $gaugeId . '"');
  3658. $result .= wf_tag('div', true);
  3659. $result .= wf_tag('center') . wf_tag('b') . $title . wf_tag('b', true) . wf_tag('center', true);
  3660. $result .= wf_tag('div', true);
  3661. $result .= wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  3662. $result .= wf_tag('script');
  3663. $result .= 'google.charts.load(\'current\', {\'packages\':[\'gauge\']});
  3664. google.charts.setOnLoadCallback(drawChart);
  3665. function drawChart() {
  3666. var data = google.visualization.arrayToDataTable([
  3667. [\'Label\', \'Value\'],
  3668. [\'' . $units . '\', ' . $value . ']
  3669. ]);
  3670. var options = {
  3671. ' . $options . '
  3672. };
  3673. var chart = new google.visualization.Gauge(document.getElementById(\'gengauge_div' . $gaugeId . '\'));
  3674. chart.draw(data, options);
  3675. } ';
  3676. $result .= wf_tag('script', true);
  3677. return ($result);
  3678. }
  3679. /**
  3680. * Returns simple pre-formatted date-or-time range picker.
  3681. * For example - for filtering form.
  3682. *
  3683. * @param bool $inTable
  3684. * @param bool $tableCellsOnly
  3685. * @param bool $tableRowsOnly
  3686. * @param bool $vertical
  3687. * @param bool $dateIsON
  3688. * @param bool $timeIsON
  3689. * @param string $dateStart
  3690. * @param string $dateEnd
  3691. * @param string $dpStartInpName
  3692. * @param string $dpEndInpName
  3693. * @param string $timeStart
  3694. * @param string $timeEnd
  3695. * @param string $tpStartInpName
  3696. * @param string $tpEndInpName
  3697. *
  3698. * @return string
  3699. */
  3700. function wf_DatesTimesRangeFilter(
  3701. $inTable = true,
  3702. $tableCellsOnly = false,
  3703. $tableRowsOnly = false,
  3704. $vertical = false,
  3705. $dateIsON = true,
  3706. $timeIsON = false,
  3707. $dateStart = '',
  3708. $dateEnd = '',
  3709. $dpStartInpName = '',
  3710. $dpEndInpName = '',
  3711. $timeStart = '',
  3712. $timeEnd = '',
  3713. $tpStartInpName = '',
  3714. $tpEndInpName = ''
  3715. ) {
  3716. $inputs = '';
  3717. $cells = '';
  3718. $rows = '';
  3719. $datepickerStart = '';
  3720. $datepickerEnd = '';
  3721. $datepickerStartCapt = '';
  3722. $datepickerEndCapt = '';
  3723. $timepickerStart = '';
  3724. $timepickerEnd = '';
  3725. $timepickerStartCapt = '';
  3726. $timepickerEndCapt = '';
  3727. if ($dateIsON) {
  3728. $dpStartInpName = (empty($dpStartInpName) ? 'datestartfilter' : $dpStartInpName);
  3729. $dpEndInpName = (empty($dpEndInpName) ? 'dateendfilter' : $dpEndInpName);
  3730. $datepickerStart = wf_DatePickerPreset($dpStartInpName, $dateStart, true);
  3731. $datepickerEnd = wf_DatePickerPreset($dpEndInpName, $dateEnd, true);
  3732. $datepickerStartCapt = __('Date from') . ':';
  3733. $datepickerEndCapt = __('Date to') . ':';
  3734. }
  3735. if ($timeIsON) {
  3736. $tpStartInpName = (empty($tpStartInpName) ? 'timestartfilter' : $tpStartInpName);
  3737. $tpEndInpName = (empty($tpEndInpName) ? 'timeendfilter' : $tpEndInpName);
  3738. $timepickerStart = wf_TimePickerPreset($tpStartInpName, $timeStart);
  3739. $timepickerEnd = wf_TimePickerPreset($tpEndInpName, $timeEnd);
  3740. $timepickerStartCapt = __('Time from') . ':';
  3741. $timepickerEndCapt = __('Time to') . ':';
  3742. }
  3743. if ($inTable) {
  3744. if ($dateIsON) {
  3745. $cells .= wf_TableCell($datepickerStartCapt);
  3746. $cells .= wf_TableCell($datepickerStart);
  3747. }
  3748. if ($timeIsON) {
  3749. if ($dateIsON) {
  3750. $cells .= wf_nbsp(4);
  3751. }
  3752. $cells .= wf_TableCell($timepickerStartCapt);
  3753. $cells .= wf_TableCell($timepickerStart);
  3754. }
  3755. if ($vertical) {
  3756. $rows = wf_TableRow($cells);
  3757. $cells = '';
  3758. } else {
  3759. $cells .= wf_TableCell(wf_nbsp(2));
  3760. }
  3761. if ($dateIsON) {
  3762. $cells .= wf_TableCell($datepickerEndCapt);
  3763. $cells .= wf_TableCell($datepickerEnd);
  3764. }
  3765. if ($timeIsON) {
  3766. if ($dateIsON) {
  3767. $cells .= wf_nbsp(4);
  3768. }
  3769. $cells .= wf_TableCell($timepickerEndCapt);
  3770. $cells .= wf_TableCell($timepickerEnd);
  3771. }
  3772. if ($tableCellsOnly) {
  3773. $inputs = $cells;
  3774. } elseif ($tableRowsOnly) {
  3775. $rows .= wf_TableRow($cells);
  3776. $inputs = $rows;
  3777. } else {
  3778. $rows .= wf_TableRow($cells);
  3779. $inputs = wf_TableBody($rows, 'auto', '0', '', '');
  3780. }
  3781. } else {
  3782. if ($dateIsON) {
  3783. $inputs .= $datepickerStartCapt . wf_nbsp(2) . $datepickerStart;
  3784. }
  3785. if ($timeIsON) {
  3786. if ($dateIsON) {
  3787. $inputs .= wf_nbsp(4);
  3788. }
  3789. $inputs .= $timepickerStartCapt . wf_nbsp(2) . $timepickerStart;
  3790. }
  3791. if ($vertical) {
  3792. $inputs .= wf_delimiter();
  3793. } else {
  3794. $inputs .= wf_nbsp(8);
  3795. }
  3796. if ($dateIsON) {
  3797. $inputs .= $datepickerEndCapt . wf_nbsp(2) . $datepickerEnd;
  3798. }
  3799. if ($timeIsON) {
  3800. if ($dateIsON) {
  3801. $inputs .= wf_nbsp(4);
  3802. }
  3803. $inputs .= $timepickerEndCapt . wf_nbsp(2) . $timepickerEnd;
  3804. }
  3805. }
  3806. return ($inputs);
  3807. }
  3808. /**
  3809. * Returns select2 searchable input widget
  3810. *
  3811. * @param string $name
  3812. * @param array $params
  3813. * @param string $label
  3814. * @param string $selected
  3815. * @param bool $br
  3816. * @param string $options
  3817. *
  3818. * @return string
  3819. */
  3820. function wf_SelectorSearchable($name, $params, $label, $selected = '', $br = false, $options = '') {
  3821. $result = '';
  3822. $inputId = wf_InputId();
  3823. $ctrlClass = 'select2_' . $inputId;
  3824. $curLang = curlang();
  3825. $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
  3826. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
  3827. $initCode .= wf_tag('script', true);
  3828. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
  3829. $initCode .= wf_tag('script', true);
  3830. $initCode .= wf_tag('script');
  3831. $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
  3832. $initCode .= wf_tag('script', true);
  3833. $result .= $initCode;
  3834. $result .= wf_Selector($name, $params, $label, $selected, $br, false, '', $ctrlClass, $options);
  3835. return ($result);
  3836. }
  3837. /**
  3838. * Returns select2 searchable input widget with auto-submit function
  3839. *
  3840. * @param string $name
  3841. * @param array $params
  3842. * @param string $label
  3843. * @param string $selected
  3844. * @param bool $br
  3845. * @param string $options
  3846. *
  3847. * @return string
  3848. */
  3849. function wf_SelectorSearchableAC($name, $params, $label, $selected = '', $br = false) {
  3850. $options = 'onChange="this.form.submit();"';
  3851. $result = wf_SelectorSearchable($name, $params, $label, $selected, $br, $options);
  3852. return ($result);
  3853. }
  3854. /**
  3855. * Return select2 Web From element with auto click option into ajax container
  3856. *
  3857. * @param string $container name of container element
  3858. * @param array $params array of elements $url=>$option
  3859. * @param string $label text label for input
  3860. * @param string $selected selected $value for selector
  3861. * @param bool $br append new line
  3862. * @param string $options some raw custom options
  3863. *
  3864. * @return string
  3865. *
  3866. */
  3867. function wf_AjaxSelectorSearchableAC($container, $params, $label, $selected = '', $br = false, $options = '') {
  3868. $inputid = wf_InputId();
  3869. $result = '';
  3870. $inputId = wf_InputId();
  3871. $ctrlClass = 'select2_' . $inputId;
  3872. $curLang = curlang();
  3873. $newline = ($br) ? wf_tag('br') : '';
  3874. $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
  3875. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
  3876. $initCode .= wf_tag('script', true);
  3877. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
  3878. $initCode .= wf_tag('script', true);
  3879. $initCode .= wf_tag('script');
  3880. $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
  3881. $initCode .= wf_tag('script', true);
  3882. $result .= $initCode;
  3883. $selectorOptions = 'name="' . $inputid . '" id="' . $inputid . '" onChange="this.options[this.selectedIndex].onclick();" ' . $options;
  3884. $result .= wf_tag('select', false, $ctrlClass, $selectorOptions);
  3885. if (!empty($params)) {
  3886. foreach ($params as $value => $eachparam) {
  3887. $sel_flag = ($selected == $value) ? 'SELECTED' : '';
  3888. $optionSpec = 'value="' . $value . '" ' . $sel_flag . ' onclick="goajax(\'' . $value . '\',\'' . $container . '\');"';
  3889. $result .= wf_tag('option', false, '', $optionSpec) . $eachparam . wf_tag('option', true);
  3890. }
  3891. }
  3892. $result .= wf_tag('select', true);
  3893. if (!empty($label)) {
  3894. $result .= wf_tag('label', false, '', 'for="' . $inputid . '"');
  3895. $result .= __($label);
  3896. $result .= wf_tag('label', true);
  3897. }
  3898. $result .= $newline;
  3899. return ($result);
  3900. }
  3901. /**
  3902. * Generates HTML and JavaScript for a show/hide toggle functionality.
  3903. *
  3904. * This function creates a clickable element that toggles the visibility of a content section.
  3905. * It uses jQuery for the toggle effect and updates the clickable element's label based on the visibility state.
  3906. *
  3907. * @param string $content The content to be shown or hidden.
  3908. * @param string $title The title to be displayed on the toggle element. Default is an empty string.
  3909. * @param string $class Additional CSS class to be applied to the outer span. Default is an empty string.
  3910. *
  3911. * @return string
  3912. */
  3913. function wf_ShowHide($content, $title = '', $class = '') {
  3914. $result = '';
  3915. $inputId = 'showhide' . wf_InputId();
  3916. $contentId = 'content' . wf_InputId();
  3917. $labelShow = wf_img_sized('skins/icon_visible.png', $title, 12) . ' ' . __($title) . ' ';
  3918. $labelHide = wf_img_sized('skins/icon_hidden.png', '', 12) . ' ';
  3919. $result .= wf_tag('span', false, $class);
  3920. $result .= wf_tag('span', false, '', 'id="' . $inputId . '"');
  3921. $result .= $labelShow;
  3922. $result .= wf_tag('span', true);
  3923. $result .= wf_tag('span', false, '', 'id="' . $contentId . '" style="display:none;"');
  3924. $result .= $content;
  3925. $result .= wf_tag('span', true);
  3926. $result .= wf_tag('span', true);
  3927. $result .= wf_tag('script');
  3928. $result .= '
  3929. $( "#' . $inputId . '" ).on( "click", function() {
  3930. $( "#' . $contentId . '" ).toggle( "fast", function() {
  3931. $("#' . $inputId . '").html(\'' . $labelHide . '\');
  3932. });
  3933. });
  3934. $( "#' . $contentId . '" ).on( "click", function() {
  3935. $( "#' . $contentId . '" ).toggle( "fast", function() {
  3936. $("#' . $inputId . '").html(\'' . $labelShow . '\');
  3937. });
  3938. });
  3939. ';
  3940. $result .= wf_tag('script', true);
  3941. return ($result);
  3942. }
  3943. /**
  3944. * JQuery Data Tables JSON formatting class
  3945. */
  3946. class wf_JqDtHelper {
  3947. /**
  3948. * Contains raw array of added grid elements
  3949. *
  3950. * @var array
  3951. */
  3952. protected $allRows = array();
  3953. /**
  3954. * Adds new row to elements array, dont forget unset() data in your loop, after adding new row.
  3955. *
  3956. * @param array $data
  3957. *
  3958. * @return void
  3959. */
  3960. public function addRow($data) {
  3961. if (!empty($data)) {
  3962. $jsonItem = array();
  3963. foreach ($data as $io => $each) {
  3964. $jsonItem[] = $each;
  3965. }
  3966. $this->allRows[] = $jsonItem;
  3967. }
  3968. }
  3969. /**
  3970. * Returns JSON acceptible for jquery data tables
  3971. *
  3972. * @return string
  3973. */
  3974. protected function renderJson() {
  3975. $result = array("aaData" => $this->allRows);
  3976. $result = json_encode($result);
  3977. return ($result);
  3978. }
  3979. /**
  3980. * Renders empty page JSON data for background ajax requests
  3981. *
  3982. * @return void
  3983. */
  3984. public function getJson() {
  3985. die($this->renderJson());
  3986. }
  3987. /**
  3988. * Extracts rendered JSON data from object
  3989. *
  3990. * @return string
  3991. */
  3992. public function extractJson() {
  3993. return ($this->renderJson());
  3994. }
  3995. /**
  3996. * Flushes current object instance elements array
  3997. *
  3998. * @return void
  3999. */
  4000. public function flushData() {
  4001. $this->allRows = array();
  4002. }
  4003. }