api.astral.php 150 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561
  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. * @param bool $serverSide Use server-side processing?
  2325. *
  2326. * @return string
  2327. */
  2328. function wf_JqDtLoader($columns, $ajaxUrl, $saveState = false, $objects = 'users', $rowsCount = 100, $opts = '', $addFooter = false, $footerOpts = '', $footerTHOpts = '', $serverSide = false) {
  2329. $tableId = 'jqdt_' . md5($ajaxUrl);
  2330. $result = '';
  2331. $saveState = ($saveState) ? 'true' : 'false';
  2332. $opts = (!empty($opts)) ? $opts . ',' : '';
  2333. $sside = ($serverSide) ? '"serverSide": true,' : '';
  2334. $lenMenu=($serverSide) ? '[[10, 25, 50, 100, 200], [10, 25, 50, 100, 200]]' : '[[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "' . __('All') . '"]]';
  2335. $jq_dt = wf_tag('script', false, '', ' type="text/javascript" charset="utf-8"');
  2336. $jq_dt .= '
  2337. $(document).ready(function() {
  2338. var table=$(\'#' . $tableId . '\').dataTable( {
  2339. "oLanguage": {
  2340. "sLengthMenu": "' . __('Show') . ' _MENU_",
  2341. "sZeroRecords": "' . __('Nothing found') . '",
  2342. "sInfo": "' . __('Showing') . ' _START_ ' . __('to') . ' _END_ ' . __('of') . ' _TOTAL_ ' . __($objects) . '",
  2343. "sInfoEmpty": "' . __('Showing') . ' 0 ' . __('to') . ' 0 ' . __('of') . ' 0 ' . __($objects) . '",
  2344. "sInfoFiltered": "(' . __('Filtered') . ' ' . __('from') . ' _MAX_ ' . __('Total') . ')",
  2345. "sSearch": "' . __('Search') . '",
  2346. "sProcessing": "' . __('Processing') . '...",
  2347. "oPaginate": {
  2348. "sFirst": "' . __('First') . '",
  2349. "sPrevious": "' . __('Previous') . '",
  2350. "sNext": "' . __('Next') . '",
  2351. "sLast": "' . __('Last') . '"
  2352. },
  2353. },
  2354. "bPaginate": true,
  2355. "bLengthChange": true,
  2356. "bFilter": true,
  2357. "bSort": true,
  2358. "bInfo": true,
  2359. "bAutoWidth": false,
  2360. "bProcessing": true,
  2361. "bStateSave": ' . $saveState . ',
  2362. "iDisplayLength": ' . $rowsCount . ',
  2363. "sAjaxSource": \'' . $ajaxUrl . '\',
  2364. "bDeferRender": true,
  2365. ' . $sside . '
  2366. "lengthMenu": '.$lenMenu.',
  2367. ' . $opts . '
  2368. "bJQueryUI": true
  2369. } );
  2370. } );
  2371. ';
  2372. $jq_dt .= wf_tag('script', true);
  2373. $result = $jq_dt;
  2374. $result .= wf_tag('table', false, 'display compact', 'id="' . $tableId . '"');
  2375. $result .= wf_tag('thead', false);
  2376. $tablecells = '';
  2377. $footerCells = '<tfoot ' . $footerOpts . '><tr>';
  2378. foreach ($columns as $io => $eachColumn) {
  2379. $tablecells .= wf_TableCell(__($eachColumn));
  2380. if ($addFooter) {
  2381. $footerCells .= '<th ' . $footerTHOpts . '></th>';
  2382. }
  2383. }
  2384. $result .= wf_TableRow($tablecells);
  2385. $result .= wf_tag('thead', true);
  2386. if ($addFooter) {
  2387. $result .= $footerCells . '</tr></tfoot>';
  2388. }
  2389. $result .= wf_tag('table', true);
  2390. return ($result);
  2391. }
  2392. /**
  2393. * Returns a JS snippet to control the visibility of JQDT column
  2394. *
  2395. * @param string $CallerObjID
  2396. * @param string $CallerObjEvent
  2397. * @param string $JQDTID
  2398. * @param int $ColIndex
  2399. *
  2400. * @return string
  2401. */
  2402. function wf_JQDTColumnHideShow($CallerObjID, $CallerObjEvent, $JQDTID, $ColIndex) {
  2403. $JSCode = '$(\'#' . $CallerObjID . '\').on("' . $CallerObjEvent . '", function() {
  2404. // Get the column API object
  2405. var column = $(\'#' . $JQDTID . '\').DataTable().column(' . $ColIndex . ');
  2406. // Toggle the visibility
  2407. column.visible( !column.visible() );
  2408. });
  2409. ';
  2410. return $JSCode;
  2411. }
  2412. /**
  2413. * Returns a JS snippet for .row().show() plugin
  2414. *
  2415. * @return string
  2416. */
  2417. function wf_JQDTRowShowPluginJS() {
  2418. $jsCode = '
  2419. $.fn.dataTable.Api.register(\'row().show()\', function() {
  2420. var page_info = this.table().page.info();
  2421. // Get row index
  2422. var new_row_index = this.index();
  2423. // Row position
  2424. var row_position = this.table()
  2425. .rows({ search: \'applied\' })[0]
  2426. .indexOf(new_row_index);
  2427. // Already on right page ?
  2428. if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) {
  2429. // Return row object
  2430. return this;
  2431. }
  2432. // Find page number
  2433. var page_to_display = Math.floor(row_position / this.table().page.len());
  2434. // Go to that page
  2435. this.table().page(page_to_display);
  2436. // Return row object
  2437. return this;
  2438. });
  2439. ';
  2440. return ($jsCode);
  2441. }
  2442. /**
  2443. * Returns a JS snippet for column footer sum() plugin
  2444. *
  2445. * @return string
  2446. */
  2447. function wf_JQDTColumnTotalSumJS() {
  2448. $jsCode = '
  2449. jQuery.fn.dataTable.Api.register( \'sum()\', function ( ) {
  2450. return this.flatten().reduce( function ( a, b ) {
  2451. if ( typeof a === \'string\' ) {
  2452. a = a.replace(/[^\d.-]/g, \'\') * 1;
  2453. }
  2454. if ( typeof b === \'string\' ) {
  2455. b = b.replace(/[^\d.-]/g, \'\') * 1;
  2456. }
  2457. return a + b;
  2458. }, 0 );
  2459. } );
  2460. ';
  2461. return ($jsCode);
  2462. }
  2463. /**
  2464. * Returns a JS snippet for markdown the row with searched value
  2465. *
  2466. * @param string|int $columnNum
  2467. * @param string $searchVal
  2468. * @param string $truncateURL
  2469. * @param string $truncateParam
  2470. *
  2471. * @return string
  2472. */
  2473. function wf_JQDTMarkRowJS($columnNum, $searchVal, $truncateURL = '', $truncateParam = '') {
  2474. $truncateJSCode = '';
  2475. if (!empty($truncateURL) and !empty($truncateParam)) {
  2476. $truncateJSCode = '
  2477. //var urlParamsObject = new URLSearchParams(\'' . $truncateURL . '\');
  2478. var urlParamsObject = new URLSearchParams(window.location.search);
  2479. if (urlParamsObject.has(\'' . $truncateParam . '\')) {
  2480. urlParamsObject.delete(\'' . $truncateParam . '\');
  2481. var truncatedURL = window.location.origin + window.location.pathname + "?" + urlParamsObject.toString();
  2482. window.history.replaceState({}, document.title, truncatedURL);
  2483. }
  2484. ';
  2485. }
  2486. $result = '
  2487. $(document).ready( function () {
  2488. var table = $(\'[id ^= "jqdt_"][role = "grid"]\').DataTable();
  2489. table.on( \'init\', function () {
  2490. var row = table.row(function ( idx, data, node ) {
  2491. return data[' . $columnNum . '] == \'' . $searchVal . '\';
  2492. });
  2493. if (row.length > 0) {
  2494. row.select().show().draw(false);
  2495. }
  2496. });
  2497. ' . $truncateJSCode . '
  2498. });
  2499. ';
  2500. return ($result);
  2501. }
  2502. /**
  2503. * Retruns a JS snippet for processing JQDT "details" functional
  2504. *
  2505. * @param $ajaxURL - URL to retrive data into "details" DIV
  2506. * @param $colIndex - above-level JQDT column index to get the AJAX data from
  2507. * @param $jqdtID - above-level JQDT DOM ID
  2508. * @param string $ajaxMethod
  2509. * @param string $jsFuncName - JS function name which will be called on processing the "details click"
  2510. * @param string $divContainerCSS - some CSS for "details" DIV
  2511. *
  2512. * @return string
  2513. */
  2514. function wf_JQDTDetailsClickProcessingJS($ajaxURL, $colIndex, $jqdtID, $ajaxMethod = 'POST', $jsFuncName = 'showDetailsData', $divContainerCSS = '') {
  2515. $divCSS = (empty($divContainerCSS) ? '{"margin-top":"5px", "margin-left":"10px", "margin-bottom":"10px"}' : $divContainerCSS);
  2516. $result = '
  2517. $(document).ready(function() {
  2518. $(\'#' . $jqdtID . ' tbody\').on(\'click\', \'td.details-control\', function (evt) {
  2519. evt.stopPropagation();
  2520. var table = $(\'#' . $jqdtID . '\').DataTable();
  2521. var tr = $(this).closest(\'tr\');
  2522. var row = table.row( tr );
  2523. var rowIdx = row.index();
  2524. var ajaxData = table.cell(rowIdx, ' . $colIndex . ').data();
  2525. if ( row.child.isShown() ) {
  2526. row.child.hide();
  2527. tr.removeClass(\'shown\');
  2528. }
  2529. else {
  2530. row.child( ' . $jsFuncName . '(row.data(), ajaxData, \'' . $ajaxURL . '\', \'' . $ajaxMethod . '\') ).show();
  2531. tr.addClass(\'shown\');
  2532. }
  2533. } );
  2534. function ' . $jsFuncName . ' ( rowData, ajaxData, ajaxURL, ajaxMethod ) {
  2535. var div = $(\'<div/>\')
  2536. .addClass( \'detailsLoading\' )
  2537. .text( \'Loading...\' );
  2538. $.ajax( {
  2539. type: ajaxMethod,
  2540. url: ajaxURL,
  2541. data: ajaxData,
  2542. success: function ( reqResult ) {
  2543. div.html( reqResult ).removeClass( \'loading\' );
  2544. div.css(' . $divCSS . ');
  2545. }
  2546. } );
  2547. return div;
  2548. }
  2549. } );
  2550. ';
  2551. return ($result);
  2552. }
  2553. /**
  2554. * Returns simple JQDT refresh link with JS snippet
  2555. *
  2556. * @param string $jqdtID
  2557. * @param string $jqdtIDSelector
  2558. * @param string $class
  2559. * @param string $opts
  2560. *
  2561. * @return string
  2562. */
  2563. function wf_JQDTRefreshButton($jqdtID = '', $jqdtIDSelector = '', $class = '', $opts = '') {
  2564. $result = '';
  2565. if (!empty($jqdtID) or !empty($jqdtIDSelector)) {
  2566. $class = (empty($class) ? 'ubButtonInline' : $class);
  2567. $tmpInpID = wf_InputId();
  2568. $result = wf_Link('#', wf_img('skins/refresh.gif', __('Refresh table data'), 'vertical-align: bottom'), false, $class, 'id="' . $tmpInpID . '" ' . $opts);
  2569. $tmpScript = '
  2570. $(\'#' . $tmpInpID . '\').click(function(evt) {
  2571. $(\'img\', this).addClass("image_rotate");
  2572. ';
  2573. if (empty($jqdtID)) {
  2574. $tmpScript .= '$(\'#\'+' . $jqdtIDSelector . ').DataTable().ajax.reload();';
  2575. } else {
  2576. $tmpScript .= '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();';
  2577. }
  2578. $tmpScript .= '
  2579. $(\'img\', this).removeClass("image_rotate");
  2580. evt.preventDefault();
  2581. return false;
  2582. });
  2583. ';
  2584. $result .= wf_EncloseWithJSTags($tmpScript);
  2585. }
  2586. return ($result);
  2587. }
  2588. /**
  2589. * Outputs a hex color based text string without # at begin, like an ac1c09
  2590. *
  2591. * @param $text String of text
  2592. * @param $palette Integer between 0 and 100
  2593. *
  2594. * @return string
  2595. */
  2596. function wf_genColorCodeFromText($text, $palette = '') {
  2597. $hash = md5($palette . $text); // modify input to get a different palette
  2598. $result = '';
  2599. $result = substr($hash, 0, 2) . substr($hash, 2, 2) . substr($hash, 4, 2);
  2600. return ($result);
  2601. }
  2602. /**
  2603. * Renders Google 3d pie chart
  2604. *
  2605. * @param array $params data in format like string=>count
  2606. * @param string $title chart title
  2607. * @param string $width chart width in px or %, 500px default
  2608. * @param string $height chart height in px or %, 500px default
  2609. * @param string $options google charts options, useful examples see below<br>
  2610. * pieSliceText: percentage/value/label/none OR pieSliceText: 'value-and-percentage'<br>
  2611. * is3D: true/false <br>
  2612. * backgroundColor: '#666', <br>
  2613. * legend : {position: 'bottom', textStyle: {color: 'red', fontSize: 12 }}, <br>
  2614. * chartArea: { width: '90%', height: '90%' }, <br>
  2615. * @param string $fixedColors use fixed auto-generated colors based on text labels with pallette<br>
  2616. *
  2617. * @return string
  2618. */
  2619. function wf_gcharts3DPie($params, $title = '', $width = '', $height = '', $options = '', $fixedColors = '') {
  2620. global $ubillingConfig;
  2621. $altCfg = $ubillingConfig->getAlter();
  2622. $containerId = wf_InputId();
  2623. $width = ($width) ? $width : '500px';
  2624. $height = ($height) ? $height : '500px';
  2625. $result = '';
  2626. $chartData = '';
  2627. $enableFlag = true;
  2628. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2629. $enableFlag = true;
  2630. } else {
  2631. if ($altCfg['GCHARTS_ENABLED']) {
  2632. $enableFlag = true;
  2633. } else {
  2634. $enableFlag = false;
  2635. }
  2636. }
  2637. if ($enableFlag) {
  2638. $colors = '';
  2639. if ($fixedColors) {
  2640. $palette = (is_bool($fixedColors)) ? '' : $fixedColors; //use string parameter as palette
  2641. $colors .= 'var colors = { ';
  2642. }
  2643. if (!empty($params)) {
  2644. foreach ($params as $io => $each) {
  2645. $chartData .= '[\'' . $io . '\',' . $each . '],';
  2646. if ($fixedColors) {
  2647. $colors .= " '" . $io . "': '" . wf_genColorCodeFromText($io, $palette) . "',";
  2648. }
  2649. }
  2650. $chartData = substr($chartData, 0, -1);
  2651. }
  2652. if ($fixedColors) {
  2653. $colors = rtrim($colors, ',');
  2654. $colors .= '};';
  2655. }
  2656. if ($fixedColors) {
  2657. $colors .= ' var slices = [];
  2658. for (var i = 0; i < data.getNumberOfRows(); i++) {
  2659. slices.push({
  2660. color: colors[data.getValue(i, 0)]
  2661. });
  2662. }';
  2663. $slicesInject = 'slices: slices,';
  2664. } else {
  2665. $slicesInject = '';
  2666. }
  2667. //legend.scrollArrows.activeColor
  2668. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.google.com/jsapi"') . wf_tag('script', true);
  2669. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2670. $result .= '
  2671. google.load("visualization", "1", {packages:["corechart"]});
  2672. google.setOnLoadCallback(drawChart);
  2673. function drawChart() {
  2674. var data = google.visualization.arrayToDataTable([
  2675. [\'X\', \'Y\'],
  2676. ' . $chartData . '
  2677. ]);
  2678. ' . $colors . '
  2679. var options = {
  2680. title: \'' . $title . '\',
  2681. ' . $slicesInject . '
  2682. is3D: true,
  2683. ' . $options . '
  2684. \'tooltip\' : {
  2685. trigger: \'none\'
  2686. }
  2687. };
  2688. var chart = new google.visualization.PieChart(document.getElementById(\'' . $containerId . '\'));
  2689. chart.draw(data, options);
  2690. }
  2691. ';
  2692. $result .= wf_tag('script', true);
  2693. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2694. }
  2695. return ($result);
  2696. }
  2697. /**
  2698. * Renders Google line chart
  2699. *
  2700. * @param array $params data in format like
  2701. * $params=array(
  2702. * 0=>array('month','total','active','inactive'),
  2703. * 1=>array('Февраль',200,150,50),
  2704. * 2=>array('Сентябрь',200,160,40)
  2705. * );
  2706. * @param string $title chart title
  2707. * @param string $width chart width in px or %, 500px default
  2708. * @param string $height chart height in px or %, 500px default
  2709. * @param string $options google charts options
  2710. *
  2711. * @return string
  2712. */
  2713. function wf_gchartsLine($params, $title = '', $width = '', $height = '', $options = '') {
  2714. global $ubillingConfig;
  2715. $altCfg = $ubillingConfig->getAlter();
  2716. $containerId = wf_InputId();
  2717. $width = ($width) ? $width : '500px';
  2718. $height = ($height) ? $height : '500px';
  2719. $result = '';
  2720. $chartData = '';
  2721. $enableFlag = true;
  2722. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2723. $enableFlag = true;
  2724. } else {
  2725. if ($altCfg['GCHARTS_ENABLED']) {
  2726. $enableFlag = true;
  2727. } else {
  2728. $enableFlag = false;
  2729. }
  2730. }
  2731. if ($enableFlag) {
  2732. if (!empty($params)) {
  2733. $chartData = json_encode($params, JSON_NUMERIC_CHECK);
  2734. }
  2735. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  2736. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2737. $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
  2738. google.charts.setOnLoadCallback(drawChart);
  2739. function drawChart() {
  2740. var data = google.visualization.arrayToDataTable(
  2741. ' . $chartData . '
  2742. );
  2743. var options = {
  2744. title: \'' . $title . '\',
  2745. curveType: \'function\',
  2746. ' . $options . '
  2747. };
  2748. var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
  2749. chart.draw(data, options);
  2750. }
  2751. ';
  2752. $result .= wf_tag('script', true);
  2753. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2754. }
  2755. return ($result);
  2756. }
  2757. /**
  2758. * Renders Google line chart
  2759. *
  2760. * @param array $params data in format like
  2761. * $params=array(
  2762. * 0=>array('month','total','active','inactive'),
  2763. * 1=>array('Февраль',200,150,50),
  2764. * 2=>array('Сентябрь',200,160,40)
  2765. * );
  2766. * @param string $title chart title
  2767. * @param string $width chart width in px or %, 500px default
  2768. * @param string $height chart height in px or %, 500px default
  2769. * @param string $options google charts options
  2770. *
  2771. * @return string
  2772. */
  2773. function wf_gchartsLineZeroIsBad($params, $title = '', $width = '', $height = '', $options = '') {
  2774. global $ubillingConfig;
  2775. $altCfg = $ubillingConfig->getAlter();
  2776. $containerId = wf_InputId();
  2777. $width = ($width) ? $width : '500px';
  2778. $height = ($height) ? $height : '500px';
  2779. $result = '';
  2780. $chartData = '';
  2781. $enableFlag = true;
  2782. if (!isset($altCfg['GCHARTS_ENABLED'])) {
  2783. $enableFlag = true;
  2784. } else {
  2785. if ($altCfg['GCHARTS_ENABLED']) {
  2786. $enableFlag = true;
  2787. } else {
  2788. $enableFlag = false;
  2789. }
  2790. }
  2791. if ($enableFlag) {
  2792. if (!empty($params)) {
  2793. $chartData = json_encode($params, JSON_NUMERIC_CHECK);
  2794. }
  2795. $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  2796. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  2797. $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
  2798. google.charts.setOnLoadCallback(drawChart);
  2799. function drawChart() {
  2800. var data = google.visualization.arrayToDataTable(
  2801. ' . $chartData . '
  2802. );
  2803. var options = {
  2804. title: \'' . $title . '\',
  2805. curveType: \'function\',
  2806. ' . $options . '
  2807. legend: { position: \'bottom\' }
  2808. };
  2809. var dataView = new google.visualization.DataView(data);
  2810. dataView.setColumns([
  2811. // reference existing columns by index
  2812. 0, 1,
  2813. // add function for line color
  2814. {
  2815. calc: function(data, row) {
  2816. var colorDown = "#FF0000";
  2817. var colorUp = "#0d8a00";
  2818. if ((data.getValue(row, 1) < 0)) {
  2819. return colorDown;
  2820. } else {
  2821. //return colorUp;
  2822. }
  2823. },
  2824. type: "string",
  2825. role: "style"
  2826. }
  2827. ]);
  2828. var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
  2829. chart.draw(dataView, options);
  2830. }
  2831. ';
  2832. $result .= wf_tag('script', true);
  2833. $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
  2834. }
  2835. return ($result);
  2836. }
  2837. /**
  2838. * Returns default back control
  2839. *
  2840. * @param string $url Link URL
  2841. * @param string $title Link title
  2842. * @param bool $br Line break line after link
  2843. * @param string $class Link class name
  2844. * @param string $opts Link style or attributes
  2845. *
  2846. * @return string
  2847. */
  2848. function wf_BackLink($url, $title = '', $br = false, $class = 'ubButton', $opts = '') {
  2849. $title = (empty($title)) ? __('Back') : __($title);
  2850. $result = wf_Link($url, wf_img('skins/back.png') . ' ' . $title, $br, $class, $opts);
  2851. return ($result);
  2852. }
  2853. /**
  2854. * Returns form disabler JS code, for preventing duplicating POST requests
  2855. *
  2856. * @return string
  2857. */
  2858. function wf_FormDisabler() {
  2859. $result = wf_tag('script', false, '', 'type="text/javascript" language="javascript" src="modules/jsc/form-disabler.js"') . wf_tag('script', true);
  2860. return ($result);
  2861. }
  2862. /**
  2863. * Returns spoiler control with specified options
  2864. *
  2865. * @param string $Content
  2866. * @param string $Title
  2867. * @param bool $Closed
  2868. * @param string $SpoilerID
  2869. * @param string $OuterDivClass
  2870. * @param string $OuterDivOptions
  2871. * @param string $InnerDivClass
  2872. * @param string $InnerDivOptions
  2873. *
  2874. * @return string
  2875. */
  2876. function wf_Spoiler($Content, $Title = '', $Closed = false, $SpoilerID = '', $OuterDivClass = '', $OuterDivOptions = '', $InnerDivClass = '', $InnerDivOptions = '') {
  2877. if (empty($SpoilerID)) {
  2878. $SpoilerID = 'spoiler_' . wf_InputId();
  2879. }
  2880. $SpoilerLnkID = 'lnk_' . wf_InputId();
  2881. $SpoilerBodyID = 'spbody_' . wf_InputId();
  2882. $SpoilerStateID = 'spstate_' . wf_InputId();
  2883. $SpoilerState = ($Closed) ? '▼' : '▲';
  2884. //$ubngStrPos = strpos(CUR_SKIN_PATH, 'ubng');
  2885. $OuterDivClass = 'spoiler clearfix ' . $OuterDivClass;
  2886. $OuterDivOptions = ' id="' . $SpoilerID . '" ' . $OuterDivOptions;
  2887. $InnerDivClass = 'spoiler_body ' . $InnerDivClass;
  2888. $InnerDivOptions = ' id="' . $SpoilerBodyID . '" ' . $InnerDivOptions;
  2889. $Result = wf_tag('div', false, $OuterDivClass, $OuterDivOptions);
  2890. $Result .= wf_tag('div', false, 'spoiler_title clearfix');
  2891. //$Result .= '<a id="' . $SpoilerLnkID . '" class="spoiler_link" href="#">';
  2892. $Result .= '<span id="' . $SpoilerLnkID . '" class="spoiler_link">';
  2893. $Result .= wf_tag('h3', false, '', '');
  2894. $Result .= $Title;
  2895. $Result .= wf_tag('h3', true);
  2896. //$Result .= $SpoilerState . '</a>' . "\n";
  2897. $Result .= '<span id="' . $SpoilerStateID . '">' . $SpoilerState . '</span>';
  2898. $Result .= '</span>' . "\n";
  2899. $Result .= wf_tag('div', true);
  2900. $Result .= wf_tag('div', false, $InnerDivClass, $InnerDivOptions);
  2901. $Result .= $Content;
  2902. $Result .= wf_tag('div', true);
  2903. $Result .= wf_tag('div', true);
  2904. $Result .= wf_tag('script', false, '', 'type="text/javascript"');
  2905. $Result .= '$(\'#' . $SpoilerLnkID . '\').click(function() {
  2906. $(\'#' . $SpoilerBodyID . '\').toggleClass("spoiler_closed");
  2907. if ( $(\'#' . $SpoilerBodyID . '\').hasClass("spoiler_closed") ) {
  2908. $(\'#' . $SpoilerBodyID . '\').slideUp(\'50\');
  2909. $(\'#' . $SpoilerStateID . '\').html(\'▼\');
  2910. } else {
  2911. $(\'#' . $SpoilerBodyID . '\').slideDown(\'50\');
  2912. $(\'#' . $SpoilerStateID . '\').html(\'▲\');
  2913. }
  2914. return false;
  2915. });';
  2916. //$Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').css("display", "none").toggleClass("spoiler_closed");' : '';
  2917. $Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').slideUp(\'50\').toggleClass("spoiler_closed");' : '';
  2918. $Result .= wf_tag('script', true);
  2919. return $Result;
  2920. }
  2921. /**
  2922. * Returns JS for a control which will be responsible for opening dynamic modal windows via ajax call to a specific URL
  2923. *
  2924. * @param $ajaxURL
  2925. * @param $dataArray
  2926. * @param string $controlId
  2927. * @param bool $wrapWithJSScriptTag
  2928. * @param string $queryType
  2929. * @param string $jsEvent
  2930. * @param bool $noPreventDefault
  2931. * @param bool $noReturnFalse
  2932. * @param bool $updNestedJQDT
  2933. * @param string $nestedJQDTSelector
  2934. *
  2935. * @return string
  2936. */
  2937. function wf_JSAjaxModalOpener($ajaxURL, $dataArray, $controlId = '', $wrapWithJSScriptTag = false, $queryType = 'GET', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
  2938. $inputId = (empty($controlId)) ? wf_InputId() : $controlId;
  2939. $modalWindowId = 'modalWindowId:"dialog-modal_' . $inputId . '", ';
  2940. $modalWindowBodyId = 'modalWindowBodyId:"body_dialog-modal_' . $inputId . '"';
  2941. $preventDefault = ($noPreventDefault) ? "" : "\nevt.preventDefault();";
  2942. $returnFalse = ($noReturnFalse) ? "" : "\nreturn false;";
  2943. $ajaxData = '';
  2944. foreach ($dataArray as $io => $each) {
  2945. if (is_array($each)) {
  2946. $ajaxData .= $io . ':' . json_encode($each) . ', ';
  2947. } else {
  2948. $ajaxData .= $io . ':"' . $each . '", ';
  2949. }
  2950. }
  2951. if ($updNestedJQDT) {
  2952. $findJQDTToUpdate = (empty($nestedJQDTSelector) ? 'var closestJQDTID = $(this).parent().parent().next("tr").find(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");' : 'var closestJQDTID = ' . $nestedJQDTSelector);
  2953. } else {
  2954. $findJQDTToUpdate = 'var closestJQDTID = $(this).closest(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");';
  2955. }
  2956. $result = '$(\'#' . $inputId . '\').' . $jsEvent . '(function(evt) {
  2957. ' . $findJQDTToUpdate . '
  2958. $.ajax({
  2959. type: "' . $queryType . '",
  2960. url: "' . $ajaxURL . '",
  2961. data: {' . $ajaxData
  2962. . $modalWindowId
  2963. . $modalWindowBodyId
  2964. . '},
  2965. success: function(ajaxresult) {
  2966. $(document.body).append(ajaxresult);
  2967. $(\'#dialog-modal_' . $inputId . '\').append(\'<input type="hidden" name="closestJQDT" value="\' + closestJQDTID + \'" id="closestJQDTID">\');
  2968. $(\'#dialog-modal_' . $inputId . '\').dialog("open");
  2969. }
  2970. });'
  2971. . $preventDefault
  2972. . $returnFalse
  2973. . '});
  2974. ';
  2975. if ($wrapWithJSScriptTag) {
  2976. $result = wf_tag('script', false, '', 'type="text/javascript"')
  2977. . $result
  2978. . wf_tag('script', true);
  2979. }
  2980. return ($result);
  2981. }
  2982. /**
  2983. * Returns JS for a link which will be responsible for opening an assigned modal window
  2984. *
  2985. * @param $ajaxURL
  2986. * @param $ajaxDataArr
  2987. * @param string $title
  2988. * @param string $icon
  2989. * @param string $linkCSSClass
  2990. * @param string $queryType
  2991. * @param string $jsEvent
  2992. * @param bool $noPreventDefault
  2993. * @param bool $noReturnFalse
  2994. * @param bool $updNestedJQDT
  2995. * @param string $nestedJQDTSelector
  2996. *
  2997. * @return string
  2998. */
  2999. function wf_jsAjaxDynamicWindowButton($ajaxURL, $ajaxDataArr, $title = 'Button', $icon = '', $linkCSSClass = '', $queryType = 'POST', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
  3000. $linkID = wf_InputId();
  3001. $dynamicOpener = wf_Link('#', $icon . ' ' . $title, false, $linkCSSClass, 'id="' . $linkID . '"')
  3002. . wf_JSAjaxModalOpener($ajaxURL, $ajaxDataArr, $linkID, true, $queryType, $jsEvent, $noPreventDefault, $noReturnFalse, $updNestedJQDT, $nestedJQDTSelector);
  3003. return ($dynamicOpener);
  3004. }
  3005. /**
  3006. * Inserts JS-code to process submitting of multiple dynamically or statically created MODAL FORMS via AJAX call
  3007. * To work properly, requires wf_JSEmptyFunc() and wf_JSElemInsertedCatcherFunc() routines to be inserted on a page beforehand.
  3008. * Also it's better to pass a JQUERY DataTable ID to be able to update a certain JQDT records
  3009. *
  3010. * @param string $submitFormClasses (need to be passed with leading dot, several classes may be passed )
  3011. * @param string $submitFormIDCtrlClass (need to be passed with leading dot)
  3012. * @param string $jqdtID
  3013. * @param string $emptyValueCheckClasses (need to be passed with leading dot)
  3014. * @param string $errorFormIDParamName
  3015. *
  3016. * @return string
  3017. */
  3018. function wf_jsAjaxFormSubmit($submitFormClasses, $submitFormIDCtrlClass, $jqdtID = '', $emptyValueCheckClasses = '', $errorFormIDParamName = '') {
  3019. $result = '';
  3020. $emptyValueCheckClasses = (empty($emptyValueCheckClasses) ? '__EmptyCheckControl' : $emptyValueCheckClasses);
  3021. $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
  3022. $errorModalWindowId = wf_InputId();
  3023. $result .= '
  3024. function checkEmptyVal(ctrlClassName) {
  3025. $(document).on("focus keydown", ctrlClassName, function(evt) {
  3026. $(document).find(ctrlClassName).each(function(indx, element){
  3027. if ( $(element).hasClass(\'__MandatoryEmpty\') ) {
  3028. $(element).val("");
  3029. $(element).css("border-color", "");
  3030. $(element).css("color", "");
  3031. $(element).toggleClass(\'__MandatoryEmpty\');
  3032. }
  3033. });
  3034. });
  3035. }
  3036. // for already inserted elements on page load
  3037. checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
  3038. // for newly inserted elements after page load
  3039. onElementInserted(\'body\', \'' . $emptyValueCheckClasses . '\', function(element) {
  3040. checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
  3041. });
  3042. $(document).on("submit", "' . $submitFormClasses . '", function(evt) {
  3043. evt.preventDefault();
  3044. var emptyCheckClass = \'' . $emptyValueCheckClasses . '\';
  3045. var mandatoryFldsEmpty = false;
  3046. $(this).find(emptyCheckClass).each(function(indx, element){
  3047. if ( empty($(element).val()) ) {
  3048. $(element).css("border-color", "red");
  3049. $(element).css("color", "grey");
  3050. $(element).val("' . __('Mandatory field') . '");
  3051. $(element).toggleClass(\'__MandatoryEmpty\');
  3052. mandatoryFldsEmpty = true
  3053. }
  3054. });
  3055. if (!mandatoryFldsEmpty) {
  3056. var FrmAction = $(this).attr("action");
  3057. var FrmData = $(this).serialize() + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\';
  3058. $.ajax({
  3059. type: "POST",
  3060. url: FrmAction,
  3061. data: FrmData,
  3062. success: function(result) {
  3063. if ( !empty(result) ) {
  3064. $(document.body).append(result);
  3065. $( \'#' . $errorModalWindowId . '\' ).dialog("open");
  3066. } else {
  3067. var customJQDTToReload = $(\'#closestJQDTID\').val();
  3068. if (!empty(customJQDTToReload)) {
  3069. $(\'#\' + customJQDTToReload).DataTable().ajax.reload();
  3070. } else {
  3071. ' . (empty($jqdtID) ? ' ' : '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();') . '
  3072. }
  3073. $( \'#\' + $("' . $submitFormIDCtrlClass . '").val() ).dialog("close");
  3074. }
  3075. }
  3076. });
  3077. }
  3078. });
  3079. ';
  3080. return ($result);
  3081. }
  3082. /**
  3083. * Returns a simple wrapper for a JS function with ajax request which can be used later for multiple "callers"
  3084. * e.g. - to delete record from DB or whatever
  3085. *
  3086. * @param $funcName
  3087. * @param string $jqdtID
  3088. * @param string $jqdtIDSelector
  3089. * @param string $errorFormIDParamName
  3090. * @param string $queryType
  3091. * @param bool $jqdtClearBeforePaste
  3092. *
  3093. * @return string
  3094. */
  3095. function wf_jsAjaxCustomFunc($funcName, $jqdtID = '', $jqdtIDSelector = '', $errorFormIDParamName = '', $queryType = 'POST', $jqdtClearBeforePaste = false) {
  3096. $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
  3097. $errorModalWindowId = wf_InputId();
  3098. $jqdtReloadScript = '';
  3099. $jqdtSelector = '';
  3100. $result = '';
  3101. if (!empty($jqdtID)) {
  3102. $jqdtSelector = '$(\'#' . $jqdtID . '\')';
  3103. } elseif (!empty($jqdtIDSelector)) {
  3104. $jqdtSelector = '$(\'#\'+' . $jqdtIDSelector . ')';
  3105. }
  3106. if (!empty($jqdtSelector)) {
  3107. if ($jqdtClearBeforePaste) {
  3108. $jqdtReloadScript = '
  3109. if ( !empty(reqResult) ) {
  3110. var json = jQuery.parseJSON(reqResult);
  3111. var table = ' . $jqdtSelector . '.DataTable();
  3112. table.clear(); //clear the current data
  3113. table.rows.add(json[\'aaData\']).draw();
  3114. }
  3115. ';
  3116. } else {
  3117. $jqdtReloadScript = '
  3118. if ( !empty(reqResult) ) {
  3119. $(document.body).append(reqResult);
  3120. if ($(\'#' . $errorFormIDParamName . '\')) {
  3121. $(\'#' . $errorFormIDParamName . '\').dialog("open");
  3122. }
  3123. }
  3124. ' . $jqdtSelector . '.DataTable().ajax.reload();
  3125. ';
  3126. }
  3127. }
  3128. $result .= '
  3129. function ' . $funcName . '(ajaxURL, ajaxData) {
  3130. var ajaxData = ajaxData + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\'
  3131. $.ajax({
  3132. type: "' . $queryType . '",
  3133. url: ajaxURL,
  3134. data: ajaxData,
  3135. success: function(reqResult) {
  3136. '
  3137. . $jqdtReloadScript .
  3138. '}
  3139. });
  3140. }
  3141. ';
  3142. return ($result);
  3143. }
  3144. /**
  3145. * JS snippet for a filtering form for JQDT. Needs a bit of specific handling
  3146. *
  3147. * @param $ajaxURLStr
  3148. * @param $formID
  3149. * @param $jqdtID
  3150. *
  3151. * @return string
  3152. */
  3153. function wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID) {
  3154. $result = '
  3155. $(\'#' . $formID . '\').submit(function(evt) {
  3156. evt.preventDefault();
  3157. $.ajax({
  3158. url: "' . $ajaxURLStr . '",
  3159. type: "POST",
  3160. data: $(\'#' . $formID . '\').serialize(),
  3161. success: function(reqResult) {
  3162. var json = jQuery.parseJSON(reqResult);
  3163. var table = $(\'#' . $jqdtID . '\').DataTable();
  3164. table.clear(); //clear the current data
  3165. table.rows.add(json[\'aaData\']).draw();
  3166. }
  3167. });
  3168. });
  3169. ';
  3170. return ($result);
  3171. }
  3172. /**
  3173. * Returns a JS-snippet for a regular selector-control cascade filtering by pre-prepared data
  3174. * The point is:
  3175. * we have a hidden input with a predefined data, like:
  3176. * valueInAboveLevelSelector1 => correspondingValueInChildSelector1
  3177. * valueInAboveLevelSelector1 => correspondingValueInChildSelector2
  3178. * valueInAboveLevelSelector1 => correspondingValueInChildSelector3
  3179. * valueInAboveLevelSelector2 => correspondingValueInChildSelector1
  3180. * valueInAboveLevelSelector2 => correspondingValueInChildSelector2
  3181. * valueInAboveLevelSelector2 => correspondingValueInChildSelector3
  3182. * valueInAboveLevelSelector2 => correspondingValueInChildSelector4
  3183. * valueInAboveLevelSelectorN => correspondingValueInChildSelectorNN
  3184. * ..................................................................
  3185. *
  3186. * When a user selects a value in AboveLevelSelector we take that array from hidden input and walk through it -
  3187. * when we find a key equal to selected in AboveLevelSelector value - we take that element in a variable
  3188. * to build a new contents for a child selector. And the same for each key which equals to selected from AboveLevelSelector value
  3189. *
  3190. *
  3191. * @param string $webSelectorID
  3192. * @param string $webSelectorIDToFilter
  3193. * @param string $filterDataElemID
  3194. * @param string $filterFuncName
  3195. * @param bool $blankFirstRow
  3196. * @param string $blankFirstRowVal
  3197. * @param string $blankFirstRowDispVal
  3198. *
  3199. * @return string
  3200. */
  3201. /* function wf_jsWebSelectorFilter($webSelectorID, $webSelectorIDToFilter, $filterDataElemID,
  3202. $webSelChangeFuncName = '', $filterFuncName = '',
  3203. $blankFirstRow = false, $blankFirstRowVal = '0', $blankFirstRowDispVal = '----') {
  3204. $webSelChangeFuncName = (empty($webSelChangeFuncName) ? 'funcChange_' . $webSelectorIDToFilter : $webSelChangeFuncName);
  3205. $filterFuncName = (empty($filterFuncName) ? 'funcFilter_' . $webSelectorIDToFilter : $filterFuncName);
  3206. $webSelectRunChange = (empty($webSelectorIDToFilter) ? "" : "$('#" . $webSelectorIDToFilter . "').change();");
  3207. $firstRowBlank = ($blankFirstRow ? "var newselect = '<option value=\"" . $blankFirstRowVal . "\">" . $blankFirstRowDispVal . "</option>';" : "");
  3208. */
  3209. function wf_jsWebSelectorFilter() {
  3210. $result = '
  3211. function filterWebDropdown(search_keyword, filterListVals, webSelectRun2ChangeID,
  3212. firstRowBlank = true, blankRowVal = "0", blankRowDispVal = "----") {
  3213. if ( !empty(filterListVals.length) ) {
  3214. var search_array = JSON.parse(atob(filterListVals));
  3215. } else {
  3216. return;
  3217. }
  3218. var newselect = "";
  3219. if (firstRowBlank) {
  3220. newselect = \'<option value="\' + blankRowVal + \'">\' + blankRowDispVal + \'</option>\';
  3221. }
  3222. if (search_keyword.length > 0 && search_keyword.trim() !== blankRowDispVal) {
  3223. for (var key in search_array) {
  3224. if ( key.trim() !== "" && key.toLowerCase() == search_keyword.toLowerCase() ) {
  3225. var foundVal = search_array[key];
  3226. for (var foundKey in foundVal) {
  3227. var foundKeyVal = foundVal[foundKey];
  3228. for (var dbID in foundKeyVal) {
  3229. newselect = newselect + \'<option value="\' + dbID + \'">\' + foundKeyVal[dbID] + \'</option>\';
  3230. }
  3231. }
  3232. }
  3233. }
  3234. }
  3235. $(\'#\' + webSelectRun2ChangeID).html(newselect);
  3236. $(\'#\' + webSelectRun2ChangeID).change();
  3237. }
  3238. ';
  3239. return ($result);
  3240. }
  3241. /**
  3242. * Simply encloses a JS snippet with a 'script' open/close tags
  3243. *
  3244. * @param string $content
  3245. *
  3246. * @return string
  3247. */
  3248. function wf_EncloseWithJSTags($content) {
  3249. $result = wf_tag('script', false, '', 'type="text/javascript"');
  3250. $result .= $content;
  3251. $result .= wf_tag('script', true);
  3252. return ($result);
  3253. }
  3254. /**
  3255. * Generates tabbed UI for almost any data.
  3256. *
  3257. * @param $tabsDivID - ID of the main tab div
  3258. * @param $tabsList - array of: tab ID => array('tab_options' => 'options',
  3259. * 'tab_caption' => 'caption,
  3260. * 'additional_data' => 'anything')
  3261. * which represents the tabs itself.
  3262. * Additional data can be anything, like some JS script or comments or whatever.
  3263. * @param $tabsBody - array of: div ID => array('div_options' => 'options',
  3264. * 'tab_body_data' => 'data'
  3265. * 'additional_data' => 'anything')
  3266. * which represents the divs with tabs data.
  3267. * Additional data can be anything, like some JS script or comments or whatever.
  3268. * @param string $mainDivOpts
  3269. * @param string $ulOpts
  3270. * @param bool $tabsCarouselOn
  3271. *
  3272. * @return string
  3273. */
  3274. function wf_TabsGen($tabsDivID, $tabsList, $tabsBody, $mainDivOpts = '', $ulOpts = '', $tabsCarouselOn = false) {
  3275. $result = '';
  3276. if (!empty($tabsDivID) and !empty($tabsList) and !empty($tabsBody)) {
  3277. $divOps = 'id="' . $tabsDivID . '" ' . $mainDivOpts;
  3278. $initTabsJSStr = '$( "#' . $tabsDivID . '" ).tabs();';
  3279. if ($tabsCarouselOn) {
  3280. $initTabsJSStr = '$("#' . $tabsDivID . '").scrollTabs({
  3281. scrollOptions: {
  3282. showFirstLastArrows: false,
  3283. closable: false
  3284. }
  3285. });
  3286. // dirty hack for scrollTabsPlugin to select the very first tab
  3287. $( "#' . $tabsDivID . '" ).scrollTabs("option", "active", 0);
  3288. // another hack for Firefox
  3289. $(".ui-scroll-tabs-view").css("margin-bottom", "0");
  3290. ';
  3291. }
  3292. $result .= wf_tag('script', false, '', 'type="text/javascript"');
  3293. $result .= ' $( function() { ' .
  3294. $initTabsJSStr .
  3295. ' } );
  3296. ';
  3297. $result .= wf_tag('script', true);
  3298. $result .= wf_tag('div', false, '', $divOps);
  3299. $result .= wf_tag('ul', false, '', $ulOpts);
  3300. foreach ($tabsList as $tabhref => $tabData) {
  3301. $result .= wf_tag('li') .
  3302. wf_tag('a', false, '', 'href="#' . $tabhref . '" ' . $tabData['options']) .
  3303. $tabData['caption'] .
  3304. wf_tag('a', true) .
  3305. wf_tag('li', true) .
  3306. $tabData['additional_data'];
  3307. }
  3308. $result .= wf_tag('ul', true);
  3309. foreach ($tabsBody as $bodyID => $bodyData) {
  3310. $result .= wf_tag('div', false, '', 'id="' . $bodyID . '" ' . $bodyData['options']) .
  3311. $bodyData['body'] .
  3312. wf_tag('div', true) .
  3313. $bodyData['additional_data'];
  3314. }
  3315. $result .= wf_tag('div', true);
  3316. }
  3317. return ($result);
  3318. }
  3319. /**
  3320. * Returns scripts and CSS links for tabs carousel plugin.
  3321. * Be sure to add this once to a page if you planning to use wf_TabsGen function with tabsCarouselOn
  3322. */
  3323. function wf_TabsCarouselInitLinking() {
  3324. $result = '<link rel="stylesheet" href="modules/jsc/JQUI_ScrollTabs/style.css" type="text/css">';
  3325. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ba-throttle-debounce.min.js"></script>';
  3326. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.mousewheel.min.js"></script>';
  3327. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.touchSwipe.min.js"></script>';
  3328. $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ui.scrolltabs.js"></script>';
  3329. return ($result);
  3330. }
  3331. /**
  3332. * Returns plain JS-code of 'empty' function to use for checking an empty value in JS code
  3333. *
  3334. * @return string
  3335. */
  3336. function wf_JSEmptyFunc() {
  3337. $Result = '
  3338. function empty (mixed_var) {
  3339. // version: 909.322
  3340. // discuss at: http://phpjs.org/functions/empty
  3341. var key;
  3342. if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === \'null\' || mixed_var === false || mixed_var === undefined || mixed_var === \'undefined\' ) {
  3343. return true;
  3344. }
  3345. if (typeof mixed_var == \'object\') {
  3346. for (key in mixed_var) {
  3347. return false;
  3348. }
  3349. return true;
  3350. }
  3351. return false;
  3352. }
  3353. ';
  3354. return ($Result);
  3355. }
  3356. /**
  3357. * Returns some count of non-breaking space symbols
  3358. *
  3359. * @param int $count
  3360. *
  3361. * @return string
  3362. */
  3363. function wf_nbsp($count = 1) {
  3364. $result = '';
  3365. for ($i = 0; $i < $count; $i++) {
  3366. $result .= '&nbsp;';
  3367. }
  3368. return ($result);
  3369. }
  3370. /**
  3371. * Returns JS onElementInserted() func which allow to make any actions for
  3372. * dynamically created objects right after the moment of it's creation
  3373. * elementSelector MUST be a 'class' or 'id' selector, like '.SomeMyClass' or '#SomeMyID'
  3374. *
  3375. * This code and it's function call must exist on a page BEFORE dynamic elements loaded
  3376. * The 'class' or 'id' selectors which will be used in dynamically loaded content
  3377. * must be known BEFORE the content loaded - so avoid of generating some random IDs on-the-fly,
  3378. * just when that content is loaded or in any other way
  3379. *
  3380. * DO NOT include this code or it's function call(like any other JS code)
  3381. * to a dynamically loaded content - as it WON'T WORK that way
  3382. *
  3383. * Source code: https://stackoverflow.com/a/38517525
  3384. *
  3385. * @return string
  3386. */
  3387. function wf_JSElemInsertedCatcherFunc() {
  3388. $Result = '
  3389. function onElementInserted(containerSelector, elementSelector, callback) {
  3390. var onMutationsObserved = function(mutations) {
  3391. mutations.forEach(function(mutation) {
  3392. if (mutation.addedNodes.length) {
  3393. var foundElements = $(mutation.addedNodes).find(elementSelector);
  3394. if (foundElements.length <= 0) {
  3395. foundElements = $(mutation.addedNodes).closest(elementSelector);
  3396. }
  3397. for (var i = 0, len = foundElements.length; i < len; i++) {
  3398. callback(foundElements[i]);
  3399. }
  3400. }
  3401. if (mutation.type === \'attributes\' && ( (\'.\' + $(mutation.target).attr(\'class\') == elementSelector)
  3402. || (\'#\' + $(mutation.target).attr(\'id\') == elementSelector) )) {
  3403. callback(mutation.target);
  3404. }
  3405. });
  3406. };
  3407. var target = $(containerSelector)[0];
  3408. var config = { childList: true, subtree: true, attributes: true, attributeFilter: ["id", "class"]};
  3409. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  3410. var observer = new MutationObserver(onMutationsObserved);
  3411. observer.observe(target, config);
  3412. }
  3413. ';
  3414. return $Result;
  3415. }
  3416. /**
  3417. * Renders default steps-meter progressbar
  3418. *
  3419. * @param array $params as stepname=>decription
  3420. * @param int $current
  3421. *
  3422. * @return type
  3423. */
  3424. function wf_StepsMeter($params, $current) {
  3425. $style = wf_tag('style');
  3426. $style .= "
  3427. .steps{
  3428. min-height:90px;
  3429. padding:30px 30px 0 30px;
  3430. position:relative
  3431. }
  3432. .steps .steps-container{
  3433. background:#DDD;
  3434. height:10px;
  3435. width:95%;
  3436. border-radius:10px ;
  3437. -moz-border-radius:10px ;
  3438. -webkit-border-radius:10px ;
  3439. -ms-border-radius:10px ;
  3440. margin:0;
  3441. list-style:none
  3442. }
  3443. .steps .steps-container li{
  3444. text-align:center;
  3445. list-style:none;
  3446. float:left
  3447. }
  3448. .steps .steps-container li .step{
  3449. padding:0 50px
  3450. }
  3451. .steps .steps-container li .step .step-image{
  3452. margin:-14px 0 0 0
  3453. }
  3454. .steps .steps-container li .step .step-image span{
  3455. background-color:#DDD;
  3456. display:block;
  3457. width:37px;
  3458. height:37px;
  3459. margin:0 auto;
  3460. border-radius:37px ;
  3461. -moz-border-radius:37px ;
  3462. -webkit-border-radius:37px ;
  3463. -ms-border-radius:37px
  3464. }
  3465. .steps .steps-container li .step .step-current{
  3466. font-size:11px;
  3467. font-style:italic;
  3468. color:#999;
  3469. margin:8px 0 0 0
  3470. }
  3471. .steps .steps-container li .step .step-description{
  3472. font-size:13px;
  3473. font-style:italic;
  3474. color:#538897
  3475. }
  3476. .steps .steps-container li.activated .step .step-image span{
  3477. background-color:#5DC177
  3478. }
  3479. .steps .steps-container li.activated .step .step-image span:after{
  3480. background-color:#FFF;
  3481. display:block;
  3482. content:'';
  3483. position:absolute;
  3484. z-index:1;
  3485. width:27px;
  3486. height:27px;
  3487. margin:5px;
  3488. border-radius:27px ;
  3489. -moz-border-radius:27px ;
  3490. -webkit-border-radius:27px ;
  3491. -ms-border-radius:27px ;
  3492. box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
  3493. -moz-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
  3494. -webkit-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15)
  3495. }
  3496. .steps .step-bar{
  3497. background-color:#5DC177;
  3498. height:10px;
  3499. position:absolute;
  3500. top:30px;
  3501. border-radius:10px 0 0 10px;
  3502. -moz-border-radius:10px 0 0 10px;
  3503. -webkit-border-radius:10px 0 0 10px;
  3504. -ms-border-radius:10px 0 0 10px
  3505. }
  3506. .steps .step-bar.last{
  3507. border-radius:10px ;
  3508. -moz-border-radius:10px ;
  3509. -webkit-border-radius:10px ;
  3510. -ms-border-radius:10px
  3511. }
  3512. ";
  3513. $style .= wf_tag('style', true);
  3514. $count = 1;
  3515. $paramsCount = sizeof($params);
  3516. if (!empty($params)) {
  3517. $width = round(100 / $paramsCount) - 1;
  3518. $code = wf_tag('div', false, 'steps');
  3519. $code .= wf_tag('ul', false, 'steps-container');
  3520. foreach ($params as $io => $each) {
  3521. $currentClass = ($count <= $current) ? 'activated' : '';
  3522. $code .= wf_tag('li', false, $currentClass, 'style="width:' . $width . '%;"');
  3523. $code .= wf_tag('div', false, 'step');
  3524. $code .= wf_tag('div', false, 'step-image') . wf_tag('span') . wf_tag('span', true) . wf_tag('div', true);
  3525. $code .= wf_tag('div', false, 'step-current') . $io . wf_tag('div', true);
  3526. $code .= wf_tag('div', false, 'step-description') . $each . wf_tag('div', true);
  3527. $code .= wf_tag('div', true);
  3528. $code .= wf_tag('li', true);
  3529. $count++;
  3530. }
  3531. $code .= wf_tag('ul', true);
  3532. $widthBar = $width * $current;
  3533. $code .= wf_tag('div', false, 'step-bar', 'style="width: ' . $widthBar . '%;"') . wf_tag('div', true);
  3534. $code .= wf_tag('div', true);
  3535. $code .= wf_CleanDiv();
  3536. $result = $style . $code;
  3537. }
  3538. return ($result);
  3539. }
  3540. /**
  3541. * Returns confirmation dialog to navigate to some URL
  3542. *
  3543. * @param string $url
  3544. * @param string $title
  3545. * @param string $alerttext
  3546. * @param string $class
  3547. * @param string $cancelUrl
  3548. * @param string $customDialogTitle
  3549. *
  3550. * @return string
  3551. */
  3552. function wf_ConfirmDialog($url, $title, $alerttext, $class = '', $cancelUrl = '', $customWindowTitle = '') {
  3553. $result = '';
  3554. $dialog = __($alerttext);
  3555. $dialog .= wf_tag('br');
  3556. $dialog .= wf_tag('center', false);
  3557. $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree');
  3558. if ($cancelUrl) {
  3559. $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel');
  3560. }
  3561. $dialog .= wf_tag('center', true);
  3562. $cleanTitle = strip_tags($title);
  3563. if ($customWindowTitle) {
  3564. $cleanTitle = $customWindowTitle;
  3565. }
  3566. $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class);
  3567. return ($result);
  3568. }
  3569. /**
  3570. * Returns confirmation dialog to navigate to some URL
  3571. *
  3572. * @param string $url
  3573. * @param string $title
  3574. * @param string $alerttext
  3575. * @param string $class
  3576. * @param string $cancelUrl
  3577. * @param string $funcRunAgree
  3578. * @param string $funcRunCancel
  3579. * @param string $modalWinID
  3580. *
  3581. * @return string
  3582. */
  3583. function wf_ConfirmDialogJS($url, $title, $alerttext, $class = '', $cancelUrl = '', $funcRunAgree = '', $funcRunCancel = '', $modalWinID = '') {
  3584. $result = '';
  3585. $modalWinID = (empty($modalWinID) ? 'dialog-modal_' . wf_InputId() : $modalWinID);
  3586. $funcRunAgree = (empty($funcRunAgree) ? '' : ' onclick="' . $funcRunAgree . '; return false; "');
  3587. $funcRunCancel = (empty($funcRunCancel) ? '' : ' onclick="' . $funcRunCancel . '; return false; "');
  3588. $dialog = __($alerttext);
  3589. $dialog .= wf_tag('br');
  3590. $dialog .= wf_tag('center', false);
  3591. $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree', $funcRunAgree);
  3592. if (!empty($cancelUrl) or !empty($funcRunCancel)) {
  3593. $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel', $funcRunCancel);
  3594. }
  3595. $dialog .= wf_tag('center', true);
  3596. $cleanTitle = strip_tags($title);
  3597. $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class, $modalWinID);
  3598. return ($result);
  3599. }
  3600. /**
  3601. * Returns code that plays some sound from existing audio file
  3602. *
  3603. * @param string $url
  3604. *
  3605. * @return string
  3606. */
  3607. function wf_doSound($url) {
  3608. $result = wf_tag('script') . "var audio = new Audio('" . $url . "'); audio.play();" . wf_tag('script', true);
  3609. return ($result);
  3610. }
  3611. /**
  3612. * Renders temperature gauge
  3613. *
  3614. * @param float $temperature
  3615. * @param string $title
  3616. * @param string $options
  3617. *
  3618. * @return string
  3619. */
  3620. function wf_renderTemperature($temperature, $title = '', $options = '') {
  3621. $result = '';
  3622. if (empty($options)) {
  3623. $options = ' max: 100,
  3624. min: 0,
  3625. width: 280, height: 280,
  3626. greenFrom: 10, greenTo: 60,
  3627. yellowFrom:60, yellowTo: 70,
  3628. redFrom: 70, redTo: 100,
  3629. minorTicks: 5';
  3630. }
  3631. $result = wf_renderGauge($temperature, $title, '°C', $options);
  3632. return ($result);
  3633. }
  3634. /**
  3635. * Renders generic gauge
  3636. *
  3637. * @param float $value
  3638. * @param string $title
  3639. * @param string $units
  3640. * @param string $options
  3641. * @param int $size
  3642. *
  3643. * @return string
  3644. */
  3645. function wf_renderGauge($value, $title = '', $units = '', $options = '', $size = 300) {
  3646. $result = '';
  3647. $gaugeId = wf_InputId();
  3648. $sizeContainer = $size;
  3649. $sizeContent = $sizeContainer - 20;
  3650. if (empty($options)) {
  3651. $options = ' max: 100,
  3652. min: 0,
  3653. width: ' . $sizeContent . ', height: ' . $sizeContent . ',
  3654. greenFrom: 10, greenTo: 60,
  3655. yellowFrom:60, yellowTo: 70,
  3656. redFrom: 70, redTo: 100,
  3657. minorTicks: 5';
  3658. }
  3659. $containerStyle = 'width: ' . $sizeContainer . 'px; height: ' . $sizeContainer . 'px; float:left; ';
  3660. $result .= wf_tag('div', false, '', 'style="' . $containerStyle . '"');
  3661. $result .= wf_tag('div', false, '', 'id="gengauge_div' . $gaugeId . '"');
  3662. $result .= wf_tag('div', true);
  3663. $result .= wf_tag('center') . wf_tag('b') . $title . wf_tag('b', true) . wf_tag('center', true);
  3664. $result .= wf_tag('div', true);
  3665. $result .= wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
  3666. $result .= wf_tag('script');
  3667. $result .= 'google.charts.load(\'current\', {\'packages\':[\'gauge\']});
  3668. google.charts.setOnLoadCallback(drawChart);
  3669. function drawChart() {
  3670. var data = google.visualization.arrayToDataTable([
  3671. [\'Label\', \'Value\'],
  3672. [\'' . $units . '\', ' . $value . ']
  3673. ]);
  3674. var options = {
  3675. ' . $options . '
  3676. };
  3677. var chart = new google.visualization.Gauge(document.getElementById(\'gengauge_div' . $gaugeId . '\'));
  3678. chart.draw(data, options);
  3679. } ';
  3680. $result .= wf_tag('script', true);
  3681. return ($result);
  3682. }
  3683. /**
  3684. * Returns simple pre-formatted date-or-time range picker.
  3685. * For example - for filtering form.
  3686. *
  3687. * @param bool $inTable
  3688. * @param bool $tableCellsOnly
  3689. * @param bool $tableRowsOnly
  3690. * @param bool $vertical
  3691. * @param bool $dateIsON
  3692. * @param bool $timeIsON
  3693. * @param string $dateStart
  3694. * @param string $dateEnd
  3695. * @param string $dpStartInpName
  3696. * @param string $dpEndInpName
  3697. * @param string $timeStart
  3698. * @param string $timeEnd
  3699. * @param string $tpStartInpName
  3700. * @param string $tpEndInpName
  3701. *
  3702. * @return string
  3703. */
  3704. function wf_DatesTimesRangeFilter(
  3705. $inTable = true,
  3706. $tableCellsOnly = false,
  3707. $tableRowsOnly = false,
  3708. $vertical = false,
  3709. $dateIsON = true,
  3710. $timeIsON = false,
  3711. $dateStart = '',
  3712. $dateEnd = '',
  3713. $dpStartInpName = '',
  3714. $dpEndInpName = '',
  3715. $timeStart = '',
  3716. $timeEnd = '',
  3717. $tpStartInpName = '',
  3718. $tpEndInpName = ''
  3719. ) {
  3720. $inputs = '';
  3721. $cells = '';
  3722. $rows = '';
  3723. $datepickerStart = '';
  3724. $datepickerEnd = '';
  3725. $datepickerStartCapt = '';
  3726. $datepickerEndCapt = '';
  3727. $timepickerStart = '';
  3728. $timepickerEnd = '';
  3729. $timepickerStartCapt = '';
  3730. $timepickerEndCapt = '';
  3731. if ($dateIsON) {
  3732. $dpStartInpName = (empty($dpStartInpName) ? 'datestartfilter' : $dpStartInpName);
  3733. $dpEndInpName = (empty($dpEndInpName) ? 'dateendfilter' : $dpEndInpName);
  3734. $datepickerStart = wf_DatePickerPreset($dpStartInpName, $dateStart, true);
  3735. $datepickerEnd = wf_DatePickerPreset($dpEndInpName, $dateEnd, true);
  3736. $datepickerStartCapt = __('Date from') . ':';
  3737. $datepickerEndCapt = __('Date to') . ':';
  3738. }
  3739. if ($timeIsON) {
  3740. $tpStartInpName = (empty($tpStartInpName) ? 'timestartfilter' : $tpStartInpName);
  3741. $tpEndInpName = (empty($tpEndInpName) ? 'timeendfilter' : $tpEndInpName);
  3742. $timepickerStart = wf_TimePickerPreset($tpStartInpName, $timeStart);
  3743. $timepickerEnd = wf_TimePickerPreset($tpEndInpName, $timeEnd);
  3744. $timepickerStartCapt = __('Time from') . ':';
  3745. $timepickerEndCapt = __('Time to') . ':';
  3746. }
  3747. if ($inTable) {
  3748. if ($dateIsON) {
  3749. $cells .= wf_TableCell($datepickerStartCapt);
  3750. $cells .= wf_TableCell($datepickerStart);
  3751. }
  3752. if ($timeIsON) {
  3753. if ($dateIsON) {
  3754. $cells .= wf_nbsp(4);
  3755. }
  3756. $cells .= wf_TableCell($timepickerStartCapt);
  3757. $cells .= wf_TableCell($timepickerStart);
  3758. }
  3759. if ($vertical) {
  3760. $rows = wf_TableRow($cells);
  3761. $cells = '';
  3762. } else {
  3763. $cells .= wf_TableCell(wf_nbsp(2));
  3764. }
  3765. if ($dateIsON) {
  3766. $cells .= wf_TableCell($datepickerEndCapt);
  3767. $cells .= wf_TableCell($datepickerEnd);
  3768. }
  3769. if ($timeIsON) {
  3770. if ($dateIsON) {
  3771. $cells .= wf_nbsp(4);
  3772. }
  3773. $cells .= wf_TableCell($timepickerEndCapt);
  3774. $cells .= wf_TableCell($timepickerEnd);
  3775. }
  3776. if ($tableCellsOnly) {
  3777. $inputs = $cells;
  3778. } elseif ($tableRowsOnly) {
  3779. $rows .= wf_TableRow($cells);
  3780. $inputs = $rows;
  3781. } else {
  3782. $rows .= wf_TableRow($cells);
  3783. $inputs = wf_TableBody($rows, 'auto', '0', '', '');
  3784. }
  3785. } else {
  3786. if ($dateIsON) {
  3787. $inputs .= $datepickerStartCapt . wf_nbsp(2) . $datepickerStart;
  3788. }
  3789. if ($timeIsON) {
  3790. if ($dateIsON) {
  3791. $inputs .= wf_nbsp(4);
  3792. }
  3793. $inputs .= $timepickerStartCapt . wf_nbsp(2) . $timepickerStart;
  3794. }
  3795. if ($vertical) {
  3796. $inputs .= wf_delimiter();
  3797. } else {
  3798. $inputs .= wf_nbsp(8);
  3799. }
  3800. if ($dateIsON) {
  3801. $inputs .= $datepickerEndCapt . wf_nbsp(2) . $datepickerEnd;
  3802. }
  3803. if ($timeIsON) {
  3804. if ($dateIsON) {
  3805. $inputs .= wf_nbsp(4);
  3806. }
  3807. $inputs .= $timepickerEndCapt . wf_nbsp(2) . $timepickerEnd;
  3808. }
  3809. }
  3810. return ($inputs);
  3811. }
  3812. /**
  3813. * Returns select2 searchable input widget
  3814. *
  3815. * @param string $name
  3816. * @param array $params
  3817. * @param string $label
  3818. * @param string $selected
  3819. * @param bool $br
  3820. * @param string $options
  3821. *
  3822. * @return string
  3823. */
  3824. function wf_SelectorSearchable($name, $params, $label, $selected = '', $br = false, $options = '') {
  3825. $result = '';
  3826. $inputId = wf_InputId();
  3827. $ctrlClass = 'select2_' . $inputId;
  3828. $curLang = curlang();
  3829. $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
  3830. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
  3831. $initCode .= wf_tag('script', true);
  3832. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
  3833. $initCode .= wf_tag('script', true);
  3834. $initCode .= wf_tag('script');
  3835. $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
  3836. $initCode .= wf_tag('script', true);
  3837. $result .= $initCode;
  3838. $result .= wf_Selector($name, $params, $label, $selected, $br, false, '', $ctrlClass, $options);
  3839. return ($result);
  3840. }
  3841. /**
  3842. * Returns select2 searchable input widget with auto-submit function
  3843. *
  3844. * @param string $name
  3845. * @param array $params
  3846. * @param string $label
  3847. * @param string $selected
  3848. * @param bool $br
  3849. * @param string $options
  3850. *
  3851. * @return string
  3852. */
  3853. function wf_SelectorSearchableAC($name, $params, $label, $selected = '', $br = false) {
  3854. $options = 'onChange="this.form.submit();"';
  3855. $result = wf_SelectorSearchable($name, $params, $label, $selected, $br, $options);
  3856. return ($result);
  3857. }
  3858. /**
  3859. * Return select2 Web From element with auto click option into ajax container
  3860. *
  3861. * @param string $container name of container element
  3862. * @param array $params array of elements $url=>$option
  3863. * @param string $label text label for input
  3864. * @param string $selected selected $value for selector
  3865. * @param bool $br append new line
  3866. * @param string $options some raw custom options
  3867. *
  3868. * @return string
  3869. *
  3870. */
  3871. function wf_AjaxSelectorSearchableAC($container, $params, $label, $selected = '', $br = false, $options = '') {
  3872. $inputid = wf_InputId();
  3873. $result = '';
  3874. $inputId = wf_InputId();
  3875. $ctrlClass = 'select2_' . $inputId;
  3876. $curLang = curlang();
  3877. $newline = ($br) ? wf_tag('br') : '';
  3878. $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
  3879. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
  3880. $initCode .= wf_tag('script', true);
  3881. $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
  3882. $initCode .= wf_tag('script', true);
  3883. $initCode .= wf_tag('script');
  3884. $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
  3885. $initCode .= wf_tag('script', true);
  3886. $result .= $initCode;
  3887. $selectorOptions = 'name="' . $inputid . '" id="' . $inputid . '" onChange="this.options[this.selectedIndex].onclick();" ' . $options;
  3888. $result .= wf_tag('select', false, $ctrlClass, $selectorOptions);
  3889. if (!empty($params)) {
  3890. foreach ($params as $value => $eachparam) {
  3891. $sel_flag = ($selected == $value) ? 'SELECTED' : '';
  3892. $optionSpec = 'value="' . $value . '" ' . $sel_flag . ' onclick="goajax(\'' . $value . '\',\'' . $container . '\');"';
  3893. $result .= wf_tag('option', false, '', $optionSpec) . $eachparam . wf_tag('option', true);
  3894. }
  3895. }
  3896. $result .= wf_tag('select', true);
  3897. if (!empty($label)) {
  3898. $result .= wf_tag('label', false, '', 'for="' . $inputid . '"');
  3899. $result .= __($label);
  3900. $result .= wf_tag('label', true);
  3901. }
  3902. $result .= $newline;
  3903. return ($result);
  3904. }
  3905. /**
  3906. * Generates HTML and JavaScript for a show/hide toggle functionality.
  3907. *
  3908. * This function creates a clickable element that toggles the visibility of a content section.
  3909. * It uses jQuery for the toggle effect and updates the clickable element's label based on the visibility state.
  3910. *
  3911. * @param string $content The content to be shown or hidden.
  3912. * @param string $title The title to be displayed on the toggle element. Default is an empty string.
  3913. * @param string $class Additional CSS class to be applied to the outer span. Default is an empty string.
  3914. *
  3915. * @return string
  3916. */
  3917. function wf_ShowHide($content, $title = '', $class = '') {
  3918. $result = '';
  3919. $inputId = 'showhide' . wf_InputId();
  3920. $contentId = 'content' . wf_InputId();
  3921. $labelShow = wf_img_sized('skins/icon_visible.png', $title, 12) . ' ' . __($title) . ' ';
  3922. $labelHide = wf_img_sized('skins/icon_hidden.png', '', 12) . ' ';
  3923. $result .= wf_tag('span', false, $class);
  3924. $result .= wf_tag('span', false, '', 'id="' . $inputId . '"');
  3925. $result .= $labelShow;
  3926. $result .= wf_tag('span', true);
  3927. $result .= wf_tag('span', false, '', 'id="' . $contentId . '" style="display:none;"');
  3928. $result .= $content;
  3929. $result .= wf_tag('span', true);
  3930. $result .= wf_tag('span', true);
  3931. $result .= wf_tag('script');
  3932. $result .= '
  3933. $( "#' . $inputId . '" ).on( "click", function() {
  3934. $( "#' . $contentId . '" ).toggle( "fast", function() {
  3935. $("#' . $inputId . '").html(\'' . $labelHide . '\');
  3936. });
  3937. });
  3938. $( "#' . $contentId . '" ).on( "click", function() {
  3939. $( "#' . $contentId . '" ).toggle( "fast", function() {
  3940. $("#' . $inputId . '").html(\'' . $labelShow . '\');
  3941. });
  3942. });
  3943. ';
  3944. $result .= wf_tag('script', true);
  3945. return ($result);
  3946. }
  3947. /**
  3948. * JQuery Data Tables JSON formatting class
  3949. */
  3950. class wf_JqDtHelper {
  3951. /**
  3952. * Contains raw array of added grid elements
  3953. *
  3954. * @var array
  3955. */
  3956. protected $allRows = array();
  3957. /**
  3958. * Total available records count
  3959. *
  3960. * @var int
  3961. */
  3962. protected $rowsTotalCount = 0;
  3963. /**
  3964. * Filtered rows count
  3965. *
  3966. * @var int
  3967. */
  3968. protected $rowsFilteredCount = 0;
  3969. /**
  3970. * The draw counter that this object is a response to
  3971. *
  3972. * @var int
  3973. */
  3974. protected $draw = 0;
  3975. /**
  3976. * Server side processing flag
  3977. *
  3978. * @var bool
  3979. */
  3980. protected $sSideFlag = true;
  3981. public function __construct($serverSideProcessing = false) {
  3982. $this->setServerSideProcessing($serverSideProcessing);
  3983. }
  3984. /**
  3985. * Sets the server-side processing state.
  3986. *
  3987. * @param bool $state
  3988. *
  3989. * @return void
  3990. */
  3991. public function setServerSideProcessing($state = false) {
  3992. $this->sSideFlag = $state;
  3993. }
  3994. /**
  3995. * Adds new row to elements array, dont forget unset() data in your loop, after adding new row.
  3996. *
  3997. * @param array $data
  3998. *
  3999. * @return void
  4000. */
  4001. public function addRow($data) {
  4002. if (!empty($data)) {
  4003. $jsonItem = array();
  4004. foreach ($data as $io => $each) {
  4005. $jsonItem[] = $each;
  4006. }
  4007. $this->allRows[] = $jsonItem;
  4008. }
  4009. }
  4010. /**
  4011. * Returns JSON acceptible for jquery data tables
  4012. *
  4013. * @return string
  4014. */
  4015. protected function renderJson() {
  4016. $result = array();
  4017. if ($this->sSideFlag) {
  4018. $result += array(
  4019. 'draw' => 0,
  4020. 'recordsTotal' => $this->rowsTotalCount,
  4021. 'recordsFiltered' => $this->rowsFilteredCount
  4022. );
  4023. }
  4024. $result += array("aaData" => $this->allRows);
  4025. $result = json_encode($result);
  4026. return ($result);
  4027. }
  4028. /**
  4029. * Sets total rows count
  4030. *
  4031. * @param int $count
  4032. *
  4033. * @return void
  4034. */
  4035. public function setTotalRowsCount($count) {
  4036. $this->rowsTotalCount = $count;
  4037. }
  4038. /**
  4039. * Sets filtered rows count
  4040. *
  4041. * @param int $count
  4042. *
  4043. * @return void
  4044. */
  4045. public function setFilteredRowsCount($count) {
  4046. $this->rowsFilteredCount = $count;
  4047. }
  4048. /**
  4049. * Renders empty page JSON data for background ajax requests
  4050. *
  4051. * @return void
  4052. */
  4053. public function getJson() {
  4054. header('Content-Type: application/json');
  4055. die($this->renderJson());
  4056. }
  4057. /**
  4058. * Extracts rendered JSON data from object
  4059. *
  4060. * @return string
  4061. */
  4062. public function extractJson() {
  4063. return ($this->renderJson());
  4064. }
  4065. /**
  4066. * Flushes current object instance elements array
  4067. *
  4068. * @return void
  4069. */
  4070. public function flushData() {
  4071. $this->allRows = array();
  4072. }
  4073. }