12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487 |
- <?php
- /**
- * Returns web form element id
- *
- * @return string
- */
- function wf_InputId() {
- // I know it looks really funny.
- // You can also get a truly random valuesby throwing dice ;)
- $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
- $result = "";
- for ($p = 0; $p < 8; $p++) {
- $result .= $characters[mt_rand(0, (strlen($characters) - 1))];
- }
- return ($result);
- }
- /**
- * Return web form body
- *
- * @param string $action action URL
- * @param string $method method: POST or GET
- * @param string $inputs inputs string to include
- * @param string $class class for form
- * @param string $legend form legend
- * @param string $CtrlID
- * @param string $target
- * @param string $opts
- *
- * @return string
- *
- */
- function wf_Form($action, $method, $inputs, $class = '', $legend = '', $CtrlID = '', $target = '', $opts = '') {
- $FrmID = ((empty($CtrlID)) ? 'Form_' . wf_InputId() : $CtrlID);
- if ($class != '') {
- $form_class = ' class="' . $class . '" ';
- } else {
- $form_class = '';
- }
- if ($legend != '') {
- $form_legend = '<legend>' . __($legend) . '</legend> <br>';
- } else {
- $form_legend = '';
- }
- if ($target != '') {
- $target = ' target="' . $target . '" ';
- } else {
- $target = '';
- }
- $form = '
- <form action="' . $action . '" method="' . $method . '" ' . $form_class . ' id="' . $FrmID . '" ' . $target . ' ' . $opts . '>
- ' . $form_legend . '
- ' . $inputs . '
- </form>
- <div style="clear:both;"></div>
- ';
- return ($form);
- }
- /**
- * Return text input Web From element
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param string $value current value
- * @param bool $br append new line
- * @param string $size input size
- * @param string $pattern input check pattern. Avaible: geo, mobile, finance, ip, net-cidr, digits, email, alpha, alphanumeric,mac,float,login,url,sigint
- * @param string $class class of the element
- * @param string $ctrlID id of the element
- * @param string $options
- * @param bool $labelLeftSide
- * @param string $labelOpts
- *
- * @return string
- *
- */
- function wf_TextInput($name, $label = '', $value = '', $br = false, $size = '', $pattern = '', $class = '', $ctrlID = '', $options = '', $labelLeftSide = false, $labelOpts = '') {
- $inputid = (empty($ctrlID)) ? wf_InputId() : $ctrlID;
- $opts = (empty($options)) ? '' : $options;
- //set size
- if ($size != '') {
- $input_size = 'size="' . $size . '"';
- } else {
- $input_size = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- // We will verify that we correctly enter data by input type
- $pattern = ($pattern == 'alpha') ? 'pattern="[a-zA-Z]+" placeholder="aZ" title="' . __('This field can only contain Latin letters') . '"' : $pattern;
- $pattern = ($pattern == 'alphanumeric') ? 'pattern="[a-zA-Z0-9]+" placeholder="aZ09" title="' . __('This field can only contain Latin letters and numbers') . '"' : $pattern;
- $pattern = ($pattern == 'digits') ? 'pattern="^\d+$" placeholder="0" title="' . __('This field can only contain digits') . '"' : $pattern;
- $pattern = ($pattern == 'finance') ? 'pattern="\d+(\.\d+)?" placeholder="0(.00)" title="' . __('The financial input format can be') . ': 1 ; 4.01 ; 2 ; 0.001"' : $pattern;
- $pattern = ($pattern == 'float') ? 'pattern="\d+(\.\d+)?" placeholder="0.00" title="' . __('This field can only contain digits') . ': 1 ; 4.01 ; 2 ; 0.001"' : $pattern;
- $pattern = ($pattern == 'sigint') ? 'pattern="^-?\d+$" placeholder="0" title="' . __('This field can only contain digits') . ' ' . __('and') . ' - "' : $pattern;
- // For this pattern IP adress also can be 0.0.0.0
- $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;
- // For this pattern exclude cidr /31
- $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;
- $pattern = ($pattern == 'email') ? 'pattern="^([\w\._-]+)@([\w\._-]+)\.([a-z]{2,6}\.?)$" placeholder="bobrik@bobrik.com" title="' . __('This field can only contain email address') . '"' : $pattern;
- $pattern = ($pattern == 'login') ? 'pattern="[a-zA-Z0-9_]+" placeholder="aZ09_" title="' . __('This field can only contain Latin letters and numbers') . ' ' . __('and') . ' _' . '"' : $pattern;
- $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;
- $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;
- $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;
- $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;
- $result = '<input type="text" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '" class="' . $class . '" ' . $opts . ' ' . $pattern . '>' . "\n";
- if ($label != '') {
- $labelOpts = (empty($labelOpts) ? '' : $labelOpts);
- $labelStr = '<label for="' . $inputid . '" ' . $labelOpts . '>' . __($label) . '</label>';
- if ($labelLeftSide) {
- $result = $labelStr . ' ' . $result . "\n";
- } else {
- $result .= ' ' . $labelStr . "\n";
- }
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return password input Web From element (legacy)
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param string $value current value
- * @param bool $br append new line
- * @param string $size input size
- * @return string
- *
- */
- function wf_PasswordInputRaw($name, $label = '', $value = '', $br = false, $size = '') {
- $inputid = wf_InputId();
- //set size
- if ($size != '') {
- $input_size = 'size="' . $size . '"';
- } else {
- $input_size = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<input type="password" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
- if ($label != '') {
- $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return password input Web From element with show/hide controls
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param string $value current value
- * @param bool $br append new line
- * @param string $size input size
- * @param bool $showHideInput show or not show/hide password control
- *
- * @return string
- *
- */
- function wf_PasswordInput($name, $label = '', $value = '', $br = false, $size = '', $showHideInput = true) {
- $result = '';
- $inputid = wf_InputId();
- //set size
- if ($size != '') {
- $input_size = 'size="' . $size . '"';
- } else {
- $input_size = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- if ($showHideInput) {
- $result .= '<style> .passfieldhide { filter: grayscale(1); .passfieldshow { filter: grayscale(0); } } </style>';
- }
- //password input here
- $result .= '<input type="password" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
- if ($showHideInput) {
- $result .= '<span class="toggle-password' . $inputid . '"><img src="skins/icon_lock.png" width="12" title=' . __('Show') . '/' . __('Hide') . '></span>';
- $result .= "
- <script>
- $('.toggle-password" . $inputid . "').click(function(){
- $(this).children().toggleClass('passfieldhide passfieldshow');
- let input = $(this).prev();
- input.attr('type', input.attr('type') === 'password' ? 'text' : 'password');
- });
- </script>";
- }
- if ($label != '') {
- $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return link form element
- *
- * @param string $url needed URL
- * @param string $title text title of URL
- * @param bool $br append new line
- * @param string $class class for link
- * @param string $options for link
- * @return string
- *
- */
- function wf_Link($url, $title, $br = false, $class = '', $options = '') {
- if ($class != '') {
- $link_class = 'class="' . $class . '"';
- } else {
- $link_class = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $opts = (empty($options)) ? '' : ' ' . $options;
- $result = '<a href="' . $url . '" ' . $link_class . $opts . '>' . __($title) . '</a>' . "\n";
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return ajax loader compatible link
- *
- * @param string $url needed URL
- * @param string $title text title of URL
- * @param string $container output container for ajax content
- * @param bool $br append new line
- * @param string $class class for link
- * @return string
- */
- function wf_AjaxLink($url, $title, $container, $br = false, $class = '') {
- if ($class != '') {
- $link_class = 'class="' . $class . '"';
- } else {
- $link_class = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<a href="#" onclick="goajax(\'' . $url . '\',\'' . $container . '\');" ' . $link_class . '>' . $title . '</a>' . "\n";
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return Radio box Web From element
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param string $value current value
- * @param bool $br append new line
- * @param bool $checked is checked?
- * @param string $ctrlID id of the element
- *
- * @return string
- *
- */
- function wf_RadioInput($name, $label = '', $value = '', $br = false, $checked = false, $ctrlID = '') {
- $inputid = (empty($ctrlID)) ? wf_InputId() : $ctrlID;
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- if ($checked) {
- $check = 'checked=""';
- } else {
- $check = '';
- }
- $result = '<input type="radio" name="' . $name . '" value="' . $value . '" id="' . $inputid . '" ' . $check . '>' . "\n";
- if ($label != '') {
- $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return check box Web From element
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param bool $br append new line
- * @param bool $checked is checked?
- * @param string $CtrlID
- * @param string $CtrlClass
- *
- * @return string
- *
- */
- function wf_CheckInput($name, $label = '', $br = false, $checked = false, $CtrlID = '', $CtrlClass = '', $options = '', $labelOptions = '') {
- $inputid = ((empty($CtrlID)) ? 'ChkBox_' . wf_InputId() : $CtrlID);
- $inputClass = ((empty($CtrlClass)) ? '' : ' class="' . $CtrlClass . '" ');
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- if ($checked) {
- $check = 'checked=""';
- } else {
- $check = '';
- }
- $result = '<input type="checkbox" id="' . $inputid . '" ' . $inputClass . 'name="' . $name . '" ' . $check . ' ' . $options . ' />';
- if ($label != '') {
- $result .= ' <label for="' . $inputid . '" ' . $labelOptions . '>' . __($label) . '</label>' . "\n";
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return textarea Web form element
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param string $value value for element
- * @param bool $br append new line - bool
- * @param string $size size in format "20x10"
- * @param string $inputId custom inputId
- *
- * @return string
- *
- */
- function wf_TextArea($name, $label = '', $value = '', $br = false, $size = '', $inputId = '') {
- $elementInputId = ($inputId) ? $inputId : wf_InputId();
- //set columns and rows count
- if ($size != '') {
- $sizexplode = explode('x', $size);
- $input_size = 'cols="' . $sizexplode[0] . '" rows="' . $sizexplode[1] . '" ';
- } else {
- $input_size = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<textarea name="' . $name . '" ' . $input_size . ' id="' . $elementInputId . '">' . $value . '</textarea>' . "\n";
- if ($label != '') {
- $result .= ' <label for="' . $elementInputId . '">' . __($label) . '</label>' . "\n";
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return hidden input web form element
- *
- * @param string $name name of element
- * @param string $value value for input
- * @param string $CtrlID
- * @param string $CtrlClass
- *
- * @return string
- *
- */
- function wf_HiddenInput($name, $value = '', $CtrlID = '', $CtrlClass = '') {
- $HiddenID = ((empty($CtrlID)) ? 'Hidden_' . wf_InputId() : $CtrlID);
- $Hiddenclass = ((empty($CtrlClass)) ? '' : ' class="' . $CtrlClass . '" ');
- /**
- * Call me by my astral name
- * Breeding fear through wordless tounge
- * Heavenly thirst - unspeakable pain
- * Emptied from all human motion
- * Confront the faceless wrath
- */
- $result = '<input type="hidden" name="' . $name . '" value="' . $value . '" id="' . $HiddenID . '"' . $Hiddenclass . '>';
- return ($result);
- }
- /**
- * Return submit web form element
- *
- * @param string $value text label for button
- * @param string $CtrlID
- * @param string $options
- *
- * @return string
- *
- */
- function wf_Submit($value, $CtrlID = '', $options = '') {
- $SubmitID = ((empty($CtrlID)) ? 'Submit_' . wf_InputId() : $CtrlID);
- $result = '<input type="submit" value="' . __($value) . '" id="' . $SubmitID . '" ' . $options . '>';
- return ($result);
- }
- /**
- * Return submit web form element for which you can specify class and other options
- *
- * @param $value
- * @param string $class
- * @param string $name
- * @param string $caption
- * @param string $CtrlID
- *
- * @return string
- */
- function wf_SubmitClassed($value, $class = '', $name = '', $caption = '', $CtrlID = '', $options = '') {
- $SubmitID = ((empty($CtrlID)) ? 'Submit_' . wf_InputId() : $CtrlID);
- $result = '<button type="submit" value="' . $value . '" name="' . $name . '" class= "' . $class . '" id="' . $SubmitID . '" ' . $options . '>';
- $result .= $caption;
- $result .= '</button>';
- return ($result);
- }
- /**
- * Return Trigger select web form input
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param string $state selected $value for trigger
- * @param bool $br append new line
- * @return string
- *
- */
- function wf_Trigger($name, $label = '', $state = '', $br = false) {
- $inputid = wf_InputId();
- if (!$state) {
- $noflag = 'SELECTED';
- } else {
- $noflag = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '
- <select name="' . $name . '" id="' . $inputid . '">
- <option value="1">' . __('Yes') . '</option>
- <option value="0" ' . $noflag . '>' . __('No') . '</option>
- </select>
- ' . "\n";
- if ($label != '') {
- $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return select Web From element
- *
- * @param string $name name of element
- * @param array $params array of elements $value=>$option
- * @param string $label text label for input
- * @param string $selected selected $value for selector
- * @param bool $br append new line
- * @param bool $sort alphabetical sorting of params array by value
- * @param string $CtrlID id of the element
- * @param string $CtrlClass
- * @param string $options
- * @param bool $labelLeftSide
- * @param string $labelOpts
- *
- * @return string
- *
- */
- function wf_Selector($name, $params, $label, $selected = '', $br = false, $sort = false, $CtrlID = '', $CtrlClass = '', $options = '', $labelLeftSide = false, $labelOpts = '') {
- $inputid = (empty($CtrlID)) ? wf_InputId() : $CtrlID;
- $inputclass = (empty($CtrlClass)) ? '' : ' class="' . $CtrlClass . '"';
- $opts = (empty($options)) ? '' : ' ' . $options . ' ';
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<select name="' . $name . '" id="' . $inputid . '"' . $inputclass . $options . '>';
- if (!empty($params)) {
- ($sort) ? asort($params) : $params;
- foreach ($params as $value => $eachparam) {
- $flag_selected = (($selected == $value) and ($selected != '')) ? 'SELECTED' : ''; // !='' because 0 values possible
- $result .= '<option value="' . $value . '" ' . $flag_selected . '>' . $eachparam . '</option>' . "\n";
- }
- }
- $result .= '</select>' . "\n";
- if ($label != '') {
- $labelOpts = (empty($labelOpts) ? '' : $labelOpts);
- $labelStr = '<label for="' . $inputid . '" ' . $labelOpts . '>' . __($label) . '</label>';
- if ($labelLeftSide) {
- $result = $labelStr . ' ' . $result . "\n";
- } else {
- $result .= ' ' . $labelStr . "\n";
- }
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return select Web From element
- *
- * @param string $name
- * @param array $params
- * @param string $label
- * @param string $selected
- * @param bool $br
- * @param string $class
- * @return string
- */
- function wf_SelectorClassed($name, $params, $label, $selected = '', $br = false, $class = '') {
- $inputid = wf_InputId();
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<select name="' . $name . '" id="' . $inputid . '" class="' . $class . '">';
- if (!empty($params)) {
- foreach ($params as $value => $eachparam) {
- $sel_flag = '';
- if ($selected != '') {
- if ($selected == $value) {
- $sel_flag = 'SELECTED';
- }
- }
- $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
- }
- }
- $result .= '</select>' . "\n";
- if ($label != '') {
- $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return select Web From element with auto click option
- *
- * @param string $name name of element
- * @param array $params array of elements $value=>$option
- * @param string $label text label for input
- * @param string $selected selected $value for selector
- * @param bool $br append new line
- * @return string
- *
- */
- function wf_SelectorAC($name, $params, $label, $selected = '', $br = false) {
- $inputid = wf_InputId();
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<select name="' . $name . '" id="' . $inputid . '" onChange="this.form.submit();">';
- if (!empty($params)) {
- foreach ($params as $value => $eachparam) {
- $sel_flag = '';
- if ($selected != '') {
- if ($selected == $value) {
- $sel_flag = 'SELECTED';
- }
- }
- $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
- }
- }
- $result .= '</select>' . "\n";
- if ($label != '') {
- $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return select Web From element with auto click option into ajax container
- *
- * @param string $container name of container element
- * @param array $params array of elements $url=>$option
- * @param string $label text label for input
- * @param string $selected selected $value for selector
- * @param bool $br append new line
- * @param string $options some raw custom options
- *
- * @return string
- *
- */
- function wf_AjaxSelectorAC($container, $params, $label, $selected = '', $br = false, $options = '') {
- $inputid = wf_InputId();
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<select name="' . $inputid . '" id="' . $inputid . '" onChange="this.options[this.selectedIndex].onclick();" ' . $options . '>';
- if (!empty($params)) {
- foreach ($params as $value => $eachparam) {
- $sel_flag = '';
- if ($selected != '') {
- if ($selected == $value) {
- $sel_flag = 'SELECTED';
- }
- }
- $result .= '<option value="' . $value . '" ' . $sel_flag . ' onclick="goajax(\'' . $value . '\',\'' . $container . '\');">' . $eachparam . '</option>' . "\n";
- }
- }
- $result .= '</select>' . "\n";
- if ($label != '') {
- $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return Month select Web From element
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param string $selected selected $value for selector
- * @param bool $br append new line
- * @param bool $allTime appends month '1488' to the end of selector
- *
- * @return string
- */
- function wf_MonthSelector($name, $label, $selected = '', $br = false, $allTime = false) {
- $allmonth = months_array();
- $params = array();
- //localize months
- foreach ($allmonth as $monthnum => $monthname) {
- $params[$monthnum] = rcms_date_localise($monthname);
- }
- $inputid = wf_InputId();
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $result = '<select name="' . $name . '" id="' . $inputid . '">';
- if (!empty($params)) {
- foreach ($params as $value => $eachparam) {
- $sel_flag = '';
- if ($selected != '') {
- if ($selected == $value) {
- $sel_flag = 'SELECTED';
- }
- }
- $result .= '<option value="' . $value . '" ' . $sel_flag . '>' . $eachparam . '</option>' . "\n";
- }
- }
- if ($allTime) {
- $selectedM = ($selected == '1488') ? 'SELECTED' : ''; // yep, this required to passing vf() checks and empty() checks.
- $result .= '<option value="1488" ' . $selectedM . '>' . __('All time') . '</option>';
- }
- $result .= '</select>' . "\n";
- if ($label != '') {
- $result .= '<label for="' . $inputid . '">' . __($label) . '</label>';
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Return Year select Web From element
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param bool $br append new line
- * @return string
- *
- */
- function wf_YearSelector($name, $label = '', $br = false) {
- $curyear = curyear();
- $inputid = wf_InputId();
- $count = (date("Y") - 2007);
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $selector = '<select name="' . $name . '" id="' . $inputid . '">';
- for ($i = 0; $i < $count; $i++) {
- $selector .= '<option value="' . ($curyear - $i) . '">' . ($curyear - $i) . '</option>';
- }
- $selector .= '</select>';
- if ($label != '') {
- $selector .= '<label for="' . $inputid . '">' . __($label) . '</label>';
- }
- $selector .= $newline;
- return ($selector);
- }
- /**
- * Return Year select Web From element
- *
- * @param string $name name of element
- * @param string $label text label for input
- * @param bool $br append new line
- * @param int $year selected year
- * @param int $allTime as last year equal 1488
- *
- * @return string
- *
- */
- function wf_YearSelectorPreset($name, $label = '', $br = false, $year = '', $allTime = false) {
- $curyear = curyear();
- $inputid = wf_InputId();
- $count = (date("Y") - 2007);
- $selected = '';
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $selector = '<select name="' . $name . '" id="' . $inputid . '">';
- for ($i = 0; $i < $count; $i++) {
- $selected = (($curyear - $i) == $year) ? 'SELECTED' : '';
- $selector .= '<option value="' . ($curyear - $i) . '" ' . $selected . '>' . ($curyear - $i) . '</option>';
- }
- if ($allTime) {
- $selected = ($year == '1488') ? 'SELECTED' : ''; // yep, this required to passing vf() checks and empty() checks.
- $selector .= '<option value="1488" ' . $selected . '>' . __('All time') . '</option>';
- }
- $selector .= '</select>';
- if ($label != '') {
- $selector .= '<label for="' . $inputid . '">' . __($label) . '</label>';
- }
- $selector .= $newline;
- return ($selector);
- }
- /**
- * Check for POST have needed variables
- *
- * @param array $params array of POST variables to check
- * @return bool
- *
- */
- function wf_CheckPost($params) {
- $result = true;
- if (!empty($params)) {
- foreach ($params as $eachparam) {
- if (isset($_POST[$eachparam])) {
- if (empty($_POST[$eachparam])) {
- $result = false;
- }
- } else {
- $result = false;
- }
- }
- }
- return ($result);
- }
- /**
- * Check for GET have needed variables
- *
- * @param array $params array of GET variables to check
- * @return bool
- *
- */
- function wf_CheckGet($params) {
- $result = true;
- if (!empty($params)) {
- foreach ($params as $eachparam) {
- if (isset($_GET[$eachparam])) {
- if (empty($_GET[$eachparam])) {
- $result = false;
- }
- } else {
- $result = false;
- }
- }
- }
- return ($result);
- }
- /**
- * Returns boolean representation of variable like boolval() in PHP 5.5+
- * but also can check if variable contains strings 'true' and 'false'
- * and return appropriate value
- *
- * @param mixed $Variable
- * @param bool $CheckAsTrueFalseStr
- *
- * @return bool
- */
- function wf_getBoolFromVar($Variable, $CheckAsTrueFalseStr = false) {
- if (isset($Variable)) {
- if (empty($Variable)) {
- return false;
- }
- } else {
- return false;
- }
- if ($CheckAsTrueFalseStr) {
- if (strtolower($Variable) === 'true' || strtolower($Variable) === '1') {
- return true;
- }
- if (strtolower($Variable) === 'false' || strtolower($Variable) === '0') {
- return false;
- }
- } else {
- return !!$Variable;
- }
- }
- /**
- * Returns true if $value is empty() or null but not equals to 0 or '0'
- *
- * @param string $value
- *
- * @return bool
- */
- function wf_emptyNonZero($value = '') {
- return ((empty($value) and $value !== 0 and $value !== '0') ? true : false);
- }
- /**
- * Construct HTML table row element
- *
- * @param string $cells table row cells
- * @param string $class table row class
- * @return string
- *
- */
- function wf_TableRow($cells, $class = '') {
- if ($class != '') {
- $rowclass = 'class="' . $class . '"';
- } else {
- $rowclass = '';
- }
- $result = '<tr ' . $rowclass . '>' . $cells . '</tr>' . "\n";
- return ($result);
- }
- /**
- * Construct HTML table row element with style inside
- *
- * @param string $cells table row cells
- * @param string $class table row class
- * @return string
- *
- */
- function wf_TableRowStyled($cells, $class = '', $style = '') {
- if ($class != '') {
- $rowclass = 'class="' . $class . '"';
- } else {
- $rowclass = '';
- }
- $result = '<tr style="' . $style . '" ' . $rowclass . '>' . $cells . '</tr>' . "\n";
- return ($result);
- }
- /**
- * Construct HTML table cell element
- *
- * @param string $data table cell data
- * @param string $width width of cell element
- * @param string $class table cell class
- * @param string $customkey table cell custom param
- * @return string
- *
- */
- function wf_TableCell($data, $width = '', $class = '', $customkey = '', $colspan = '', $rowspan = '') {
- if ($width != '') {
- $cellwidth = 'width="' . $width . '"';
- } else {
- $cellwidth = '';
- }
- if ($class != '') {
- $cellclass = 'class="' . $class . '"';
- } else {
- $cellclass = '';
- }
- if ($customkey != '') {
- $customkey = $customkey;
- } else {
- $customkey = '';
- }
- $colspan = (empty($colspan)) ? '' : 'colspan="' . $colspan . '"';
- $rowspan = (empty($rowspan)) ? '' : 'rowspan="' . $rowspan . '"';
- $result = '<td ' . $cellwidth . ' ' . $cellclass . ' ' . $customkey . ' ' . $colspan . ' ' . $rowspan . '>' . $data . '</td>' . "\n";
- return ($result);
- }
- /**
- * Construct HTML table body
- *
- * @param string $rows table rows data
- * @param string $width width of cell element
- * @param string $border table border width
- * @param string $class table cell class
- * @param string $options table additional options
- * @return string
- *
- */
- function wf_TableBody($rows, $width = '', $border = '0', $class = '', $options = '') {
- if ($width != '') {
- $tablewidth = 'width="' . $width . '"';
- } else {
- $tablewidth = '';
- }
- if ($class != '') {
- $tableclass = 'class="' . $class . '"';
- } else {
- $tableclass = '';
- }
- if ($border != '') {
- $tableborder = 'border="' . $border . '"';
- } else {
- $tableborder = '';
- }
- $result = '
- <table ' . $tablewidth . ' ' . $tableborder . ' ' . $tableclass . ' ' . $options . ' >
- ' . $rows . '
- </table>
- ';
- return ($result);
- }
- /**
- * Returns JS confirmation url
- *
- * @param string $url URL if confirmed
- * @param string $title link title
- * @param string $alerttext alert text
- * @param string $functiontorun function name with parameters which must exist on a page
- * @param string $class link class
- *
- * @return string
- *
- */
- function wf_JSAlert($url, $title, $alerttext, $functiontorun = '', $class = '') {
- $class = (empty($class)) ? '' : 'class="' . $class . '"';
- if (empty($functiontorun)) {
- $result = '<a ' . $class . ' onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;}" href="' . $url . '">' . $title . '</a>';
- } else {
- $result = '<a ' . $class . ' onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;} else { ' . $functiontorun . '; return false; }" href="' . $url . '">' . $title . '</a>';
- }
- return ($result);
- }
- /**
- * Returns JS confirmation url with some applied class
- *
- * @param string $url URL if confirmed
- * @param string $title link title
- * @param string $alerttext alert text
- * @param string $functiontorun function name with parameters which must exist on a page
- *
- * @return string
- *
- */
- function wf_JSAlertStyled($url, $title, $alerttext, $class = '', $functiontorun = '') {
- $class = (!empty($class)) ? 'class="' . $class . '"' : '';
- if (empty($functiontorun)) {
- $result = '<a onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;}" href="' . $url . '" ' . $class . '>' . $title . '</a>';
- } else {
- $result = '<a onclick="if(!confirm(\'' . __($alerttext) . '\')) { return false;} else { ' . $functiontorun . '; }" href="' . $url . '" ' . $class . '>' . $title . '</a>';
- }
- return ($result);
- }
- /**
- * Returns standard paginator widget
- *
- * @param int $total Total items count
- * @param int $perpage Per page items count
- * @param int $current current page
- * @param string $link module link which use paginator
- * @param string $class page links class
- * @param int $maxAmount maximun amount of pages to render
- *
- * @return string
- */
- function wf_pagination($total, $perpage, $current, $link, $class = '', $maxAmount = 0) {
- if ($class != '') {
- $pageclass = 'class="' . $class . '"';
- } else {
- $pageclass = '';
- }
- $return = '';
- $link = preg_replace("/((&|&)page=(\d*))/", '', $link);
- if (!empty($perpage)) {
- $pages = ceil($total / $perpage);
- if ($pages != 1) {
- $c = 1;
- while ($c <= $pages) {
- $renderPageLink = true;
- if (!empty($maxAmount)) {
- if ($pages > $maxAmount) {
- if ($c > $maxAmount) {
- $renderPageLink = false;
- if ($c == $pages) {
- //last page
- $return .= '...';
- $renderPageLink = true;
- }
- if (($current) >= ($maxAmount)) {
- if ($c == ($current + 1)) {
- $renderPageLink = true;
- }
- if ($c == ($current - 1) or ($c == ($current))) {
- $renderPageLink = true;
- }
- }
- }
- }
- }
- if ($renderPageLink) {
- if ($c != $current) {
- $return .= ' ' . '<a href="' . $link . '&page=' . $c . '" ' . $pageclass . '>' . $c . '</a> ';
- } else {
- $return .= ' ' . '<a href="#" ' . $pageclass . ' style="color: #ff0000;">' . $c . '</a> ';
- }
- if ($c == $maxAmount) {
- $return .= '...';
- }
- }
- $c++;
- }
- }
- }
- return ($return);
- }
- /**
- * Returns image body
- *
- * @param string $url image url
- * @param string $title image title
- * @param string $style image custom styling
- *
- * @return string
- */
- function wf_img($url, $title = '', $style = '') {
- if ($title != '') {
- $imgtitle = 'title="' . $title . '"';
- } else {
- $imgtitle = '';
- }
- $imgstyle = (empty($style)) ? '' : ' style="' . $style . '" ';
- $result = '<img src="' . $url . '" ' . $imgtitle . $imgstyle . ' border="0">';
- return ($result);
- }
- /**
- * Returns image body with some dimensions
- *
- * @param string $url image url
- * @param string $title title attribure for image
- * @param string $width image width
- * @param string $height image height
- * @param string $style image custom styling
- *
- * @return string
- */
- function wf_img_sized($url, $title = '', $width = '', $height = '', $style = '') {
- $imgtitle = ($title != '') ? 'title="' . $title . '"' : '';
- $imgwidth = ($width != '') ? 'width="' . $width . '"' : '';
- $imgheight = ($height != '') ? 'height="' . $height . '"' : '';
- $imgstyle = (empty($style)) ? '' : ' style="' . $style . '" ';
- $result = '<img src="' . $url . '" ' . $imgtitle . ' ' . $imgwidth . ' ' . $imgheight . $imgstyle . ' border="0">';
- return ($result);
- }
- /**
- * Returns link that calls new modal window
- *
- * @param string $link link text
- * @param string $title modal window title
- * @param string $content modal window content
- * @param string $linkclass link class
- * @param string $width modal window width
- * @param string $height modal window height
- *
- * @return string
- */
- function wf_modal($link, $title, $content, $linkclass = '', $width = '', $height = '') {
- $wid = wf_inputid();
- //setting link class
- if ($linkclass != '') {
- $link_class = 'class="' . $linkclass . '"';
- } else {
- $link_class = '';
- }
- //setting auto width if not specified
- if ($width == '') {
- $width = '600';
- }
- //setting auto height if not specified
- if ($height == '') {
- $height = '400';
- }
- $dialog = '
- <script type="text/javascript">
- $(function() {
- $( "#dialog-modal_' . $wid . '" ).dialog({
- autoOpen: false,
- width: ' . $width . ',
- height: ' . $height . ',
- modal: true,
- show: "drop",
- hide: "fold"
- });
- $( "#opener_' . $wid . '" ).click(function() {
- $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
- return false;
- });
- });
- </script>
- <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
- <p>
- ' . $content . '
- </p>
- </div>
- <a href="#" id="opener_' . $wid . '" ' . $link_class . '>' . $link . '</a>
- ';
- return ($dialog);
- }
- /**
- * Returns link that calls new modal window with automatic dimensions by inside content
- *
- * @param string $link link text
- * @param string $title modal window title
- * @param string $content modal window content
- * @param string $linkclass link class
- * @param string $windowID
- *
- * @return string
- *
- */
- function wf_modalAuto($link, $title, $content, $linkclass = '', $windowID = '') {
- $wid = (empty($windowID) ? 'dialog-modal_' . wf_inputid() : $windowID);
- //setting link class
- if ($linkclass != '') {
- $link_class = 'class="' . $linkclass . '"';
- } else {
- $link_class = '';
- }
- $width = "'auto'";
- $height = "'auto'";
- $dialog = '
- <script type="text/javascript">
- $(function() {
- $( "#' . $wid . '" ).dialog({
- autoOpen: false,
- width: \'auto\',
- height: \'auto\',
- modal: true,
- show: "drop",
- hide: "fold"
- });
- $( "#opener_' . $wid . '" ).click(function() {
- $( "#' . $wid . '" ).dialog( "open" );
- return false;
- });
- });
- </script>
- <div id="' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
- <p>
- ' . $content . '
- </p>
- </div>
- <a href="#" id="opener_' . $wid . '" ' . $link_class . '>' . $link . '</a>
- ';
- return ($dialog);
- }
- /**
- * Returns link that calls new modal window with automatic dimensions by inner content and without "opener" object
- *
- * @param string $Title
- * @param string $Content
- * @param string $WindowID
- * @param string $WindowBodyID
- * @param bool $DestroyOnClose
- * @param string $AutoOpen
- * @param string $Width
- * @param string $Height
- *
- * @return string
- */
- function wf_modalAutoForm($Title, $Content, $WindowID = '', $WindowBodyID = '', $DestroyOnClose = false, $AutoOpen = 'false', $Width = '', $Height = '') {
- $WID = (empty($WindowID)) ? 'dialog-modal_' . wf_inputid() : $WindowID;
- $WBID = (empty($WindowBodyID)) ? 'body_dialog-modal_' . wf_inputid() : $WindowBodyID;
- if (empty($Width)) {
- $Width = "'auto'";
- }
- if (empty($Height)) {
- $Height = "'auto'";
- }
- $DestroyParams = '';
- if ($DestroyOnClose) {
- $DestroyParams = ',
- close: function(event, ui) {
- $(\'#' . $WID . '\').dialog("destroy");
- $(\'#' . $WID . '\').remove();
- $(\'#script_' . $WID . '\').remove();
- }
- ';
- }
- $Dialog = wf_tag('script', false, '', 'type="text/javascript" id="script_' . $WID . '"');
- $Dialog .= '
- $(function() {
- $(\'#' . $WID . '\').dialog({
- autoOpen: ' . $AutoOpen . ',
- width: ' . $Width . ',
- height: ' . $Height . ',
- modal: true,
- show: "drop",
- hide: "fold"' . $DestroyParams . '
- });
- });
- ';
- $Dialog .= wf_tag('script', true);
- $Dialog .= '
- <div id="' . $WID . '" title="' . $Title . '" style="display:none; width:1px; height:1px;">
- <p id="' . $WBID . '">' . $Content . '</p>
- </div>
- ';
- return $Dialog;
- }
- /**
- * Returns calendar widget
- *
- * @param string $field field name to insert calendar
- * @param bool $extControls extended year and month controls
- *
- * @return string
- *
- */
- function wf_DatePicker($field, $extControls = false) {
- $inputid = wf_InputId();
- $curlang = curlang();
- if ($extControls) {
- $extControls = ',
- changeMonth: true,
- yearRange: "-100:+100",
- changeYear: true';
- } else {
- $extControls = '';
- }
- $result = '<script>
- $(function() {
- $( "#' . $inputid . '" ).datepicker({
- showOn: "both",
- buttonImage: "skins/icon_calendar.gif",
- buttonImageOnly: true,
- dateFormat: "yy-mm-dd",
- showAnim: "slideDown"' . $extControls . '
- });
-
-
- $.datepicker.regional[\'en\'] = {
- closeText: \'Done\',
- prevText: \'Prev\',
- nextText: \'Next\',
- currentText: \'Today\',
- monthNames: [\'January\',\'February\',\'March\',\'April\',\'May\',\'June\',
- \'July\',\'August\',\'September\',\'October\',\'November\',\'December\'],
- monthNamesShort: [\'Jan\', \'Feb\', \'Mar\', \'Apr\', \'May\', \'Jun\',
- \'Jul\', \'Aug\', \'Sep\', \'Oct\', \'Nov\', \'Dec\'],
- dayNames: [\'Sunday\', \'Monday\', \'Tuesday\', \'Wednesday\', \'Thursday\', \'Friday\', \'Saturday\'],
- dayNamesShort: [\'Sun\', \'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\', \'Sat\'],
- dayNamesMin: [\'Su\',\'Mo\',\'Tu\',\'We\',\'Th\',\'Fr\',\'Sa\'],
- weekHeader: \'Wk\',
- dateFormat: \'dd/mm/yy\',
- firstDay: 1,
- isRTL: false,
- showMonthAfterYear: false,
- yearSuffix: \'\'};
-
- $.datepicker.regional[\'ru\'] = {
- closeText: \'Закрыть\',
- prevText: \'<Пред\',
- nextText: \'След>\',
- currentText: \'Сегодня\',
- monthNames: [\'Январь\',\'Февраль\',\'Март\',\'Апрель\',\'Май\',\'Июнь\',
- \'Июль\',\'Август\',\'Сентябрь\',\'Октябрь\',\'Ноябрь\',\'Декабрь\'],
- monthNamesShort: [\'Янв\',\'Фев\',\'Мар\',\'Апр\',\'Май\',\'Июн\',
- \'Июл\',\'Авг\',\'Сен\',\'Окт\',\'Ноя\',\'Дек\'],
- dayNames: [\'воскресенье\',\'понедельник\',\'вторник\',\'среда\',\'четверг\',\'пятница\',\'суббота\'],
- dayNamesShort: [\'вск\',\'пнд\',\'втр\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
- dayNamesMin: [\'Вс\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
- weekHeader: \'Нед\',
- dateFormat: \'dd.mm.yy\',
- firstDay: 1,
- isRTL: false,
- showMonthAfterYear: false,
- yearSuffix: \'\'};
-
- $.datepicker.regional[\'uk\'] = {
- closeText: \'Закрити\',
- prevText: \'<\',
- nextText: \'>\',
- currentText: \'Сьогодні\',
- monthNames: [\'Січень\',\'Лютий\',\'Березень\',\'Квітень\',\'Травень\',\'Червень\',
- \'Липень\',\'Серпень\',\'Вересень\',\'Жовтень\',\'Листопад\',\'Грудень\'],
- monthNamesShort: [\'Січ\',\'Лют\',\'Бер\',\'Кві\',\'Тра\',\'Чер\',
- \'Лип\',\'Сер\',\'Вер\',\'Жов\',\'Лис\',\'Гру\'],
- dayNames: [\'неділя\',\'понеділок\',\'вівторок\',\'середа\',\'четвер\',\'п’ятниця\',\'субота\'],
- dayNamesShort: [\'нед\',\'пнд\',\'вів\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
- dayNamesMin: [\'Нд\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
- weekHeader: \'Тиж\',
- dateFormat: \'dd/mm/yy\',
- firstDay: 1,
- isRTL: false,
- showMonthAfterYear: false,
- yearSuffix: \'\'};
-
- $.datepicker.setDefaults($.datepicker.regional[\'' . $curlang . '\']);
-
- });
- </script>
-
- <input type="text" id="' . $inputid . '" name="' . $field . '" size="10">
- ';
- return ($result);
- }
- /**
- * Returns calendar widget with preset date
- *
- * @param string $field field name to insert calendar
- * @param string $date to set the calendar's value to
- * @param bool $extControls extended year and month controls
- * @param string $CtrlID
- *
- * @return string
- *
- */
- function wf_DatePickerPreset($field, $date, $extControls = false, $CtrlID = '', $ctrlClass = '') {
- $inputid = (empty($CtrlID)) ? wf_InputId() : $CtrlID;
- $class = (empty($ctrlClass)) ? '' : ' class="' . $ctrlClass . '" ';
- $curlang = curlang();
- if ($extControls) {
- $extControls = ',
- changeMonth: true,
- yearRange: "-100:+100",
- changeYear: true';
- } else {
- $extControls = '';
- }
- $result = '<script>
- $(function() {
- $( "#' . $inputid . '" ).datepicker({
- showOn: "both",
- buttonImage: "skins/icon_calendar.gif",
- buttonImageOnly: true,
- dateFormat: "yy-mm-dd",
- showAnim: "slideDown"' . $extControls . '
- });
-
-
- $.datepicker.regional[\'en\'] = {
- closeText: \'Done\',
- prevText: \'Prev\',
- nextText: \'Next\',
- currentText: \'Today\',
- monthNames: [\'January\',\'February\',\'March\',\'April\',\'May\',\'June\',
- \'July\',\'August\',\'September\',\'October\',\'November\',\'December\'],
- monthNamesShort: [\'Jan\', \'Feb\', \'Mar\', \'Apr\', \'May\', \'Jun\',
- \'Jul\', \'Aug\', \'Sep\', \'Oct\', \'Nov\', \'Dec\'],
- dayNames: [\'Sunday\', \'Monday\', \'Tuesday\', \'Wednesday\', \'Thursday\', \'Friday\', \'Saturday\'],
- dayNamesShort: [\'Sun\', \'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\', \'Sat\'],
- dayNamesMin: [\'Su\',\'Mo\',\'Tu\',\'We\',\'Th\',\'Fr\',\'Sa\'],
- weekHeader: \'Wk\',
- dateFormat: \'dd/mm/yy\',
- firstDay: 1,
- isRTL: false,
- showMonthAfterYear: false,
- yearSuffix: \'\'};
-
- $.datepicker.regional[\'ru\'] = {
- closeText: \'Закрыть\',
- prevText: \'<Пред\',
- nextText: \'След>\',
- currentText: \'Сегодня\',
- monthNames: [\'Январь\',\'Февраль\',\'Март\',\'Апрель\',\'Май\',\'Июнь\',
- \'Июль\',\'Август\',\'Сентябрь\',\'Октябрь\',\'Ноябрь\',\'Декабрь\'],
- monthNamesShort: [\'Янв\',\'Фев\',\'Мар\',\'Апр\',\'Май\',\'Июн\',
- \'Июл\',\'Авг\',\'Сен\',\'Окт\',\'Ноя\',\'Дек\'],
- dayNames: [\'воскресенье\',\'понедельник\',\'вторник\',\'среда\',\'четверг\',\'пятница\',\'суббота\'],
- dayNamesShort: [\'вск\',\'пнд\',\'втр\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
- dayNamesMin: [\'Вс\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
- weekHeader: \'Нед\',
- dateFormat: \'dd.mm.yy\',
- firstDay: 1,
- isRTL: false,
- showMonthAfterYear: false,
- yearSuffix: \'\'};
-
- $.datepicker.regional[\'uk\'] = {
- closeText: \'Закрити\',
- prevText: \'<\',
- nextText: \'>\',
- currentText: \'Сьогодні\',
- monthNames: [\'Січень\',\'Лютий\',\'Березень\',\'Квітень\',\'Травень\',\'Червень\',
- \'Липень\',\'Серпень\',\'Вересень\',\'Жовтень\',\'Листопад\',\'Грудень\'],
- monthNamesShort: [\'Січ\',\'Лют\',\'Бер\',\'Кві\',\'Тра\',\'Чер\',
- \'Лип\',\'Сер\',\'Вер\',\'Жов\',\'Лис\',\'Гру\'],
- dayNames: [\'неділя\',\'понеділок\',\'вівторок\',\'середа\',\'четвер\',\'п’ятниця\',\'субота\'],
- dayNamesShort: [\'нед\',\'пнд\',\'вів\',\'срд\',\'чтв\',\'птн\',\'сбт\'],
- dayNamesMin: [\'Нд\',\'Пн\',\'Вт\',\'Ср\',\'Чт\',\'Пт\',\'Сб\'],
- weekHeader: \'Тиж\',
- dateFormat: \'dd/mm/yy\',
- firstDay: 1,
- isRTL: false,
- showMonthAfterYear: false,
- yearSuffix: \'\'};
-
- $.datepicker.setDefaults($.datepicker.regional[\'' . $curlang . '\']);
-
- });
- </script>
-
- <input type="text" id="' . $inputid . '" name="' . $field . '" value="' . $date . '" size="10" ' . $class . '>
- ';
- return ($result);
- }
- /**
- * Returns FullCalendar widget
- *
- * @param string $data prepeared data to show
- * @param string $options
- * @param bool $useHTMLInTitle
- * @param bool $useHTMLListViewOnly
- * @param string $ajaxURLForDnD
- *
- * @return string
- */
- function wf_FullCalendar($data, $options = '', $useHTMLInTitle = false, $useHTMLListViewOnly = false, $ajaxURLForDnD = '') {
- global $ubillingConfig;
- $elementid = wf_InputId();
- $dragdropON = ($ubillingConfig->getAlterParam('CALENDAR_DRAG_AND_DROP_ON') and !empty($ajaxURLForDnD));
- $dndConfirmON = $ubillingConfig->getAlterParam('CALENDAR_DRAG_AND_DROP_CONFIRM_ON');
- $titlesSearchON = $ubillingConfig->getAlterParam('CALENDAR_TITLES_SEARCH_ON');
- if ($useHTMLInTitle) {
- if ($useHTMLListViewOnly) {
- $htmlInTitle = " eventRender: function(event, element, view) {
- if (view.type.indexOf('list') >= 0) {
- var link = element.find('[class*=-title] a');
- var title = element.find('[class*=-title]');
- link.html(title.text());
- title.html( link );
- } else {
- var title = element.find('[class*=-title]');
- // some hack to remove HTML from text
- var doc = new DOMParser().parseFromString(title.text(), 'text/html');
- var titleText = (doc.body.textContent || \"\");
- title.html( titleText );
- }
- }, ";
- } else {
- $htmlInTitle = " eventRender: function(event, element, view) {
- if (view.type.indexOf('list') >= 0) {
- var link = element.find('[class*=-title] a');
- var title = element.find('[class*=-title]');
- link.html(title.text());
- title.html( link );
- } else {
- var title = element.find('[class*=-title]');
- title.html( title.text() );
- }
- }, ";
- }
- } else {
- $htmlInTitle = '';
- }
- $calendar = "<script type='text/javascript'>
- $(document).ready(function() {
-
- var date = new Date();
- var d = date.getDate();
- var m = date.getMonth();
- var y = date.getFullYear();
-
- $('#" . $elementid . "').fullCalendar({
- header: {
- left: 'prev,next today',
- center: 'title',
- right: 'month,basicWeek,basicDay,listMonth'
- },
-
- editable: " . ($dragdropON ? "true" : "false") . ",
- " . $htmlInTitle . "
- theme: true,
- weekends: true,
- timeFormat: 'H(:mm)',
- displayEventTime: false,
- height: 'auto',
- contentHeight: 'auto',
- " . $options . "
- monthNamesShort: [
- '" . rcms_date_localise('Jan') . "',
- '" . rcms_date_localise('Feb') . "',
- '" . rcms_date_localise('Mar') . "',
- '" . rcms_date_localise('Apr') . "',
- '" . rcms_date_localise('May') . "',
- '" . rcms_date_localise('Jun') . "',
- '" . rcms_date_localise('Jul') . "',
- '" . rcms_date_localise('Aug') . "',
- '" . rcms_date_localise('Sep') . "',
- '" . rcms_date_localise('Oct') . "',
- '" . rcms_date_localise('Nov') . "',
- '" . rcms_date_localise('Dec') . "'
- ],
- monthNames: [
- '" . rcms_date_localise('January') . "',
- '" . rcms_date_localise('February') . "',
- '" . rcms_date_localise('March') . "',
- '" . rcms_date_localise('April') . "',
- '" . rcms_date_localise('May') . "',
- '" . rcms_date_localise('June') . "',
- '" . rcms_date_localise('July') . "',
- '" . rcms_date_localise('August') . "',
- '" . rcms_date_localise('September') . "',
- '" . rcms_date_localise('October') . "',
- '" . rcms_date_localise('November') . "',
- '" . rcms_date_localise('December') . "'
- ],
-
- dayNamesShort: [
- '" . rcms_date_localise('Sun') . "',
- '" . rcms_date_localise('Mon') . "',
- '" . rcms_date_localise('Tue') . "',
- '" . rcms_date_localise('Wed') . "',
- '" . rcms_date_localise('Thu') . "',
- '" . rcms_date_localise('Fri') . "',
- '" . rcms_date_localise('Sat') . "'
- ],
-
- dayNames: [
- '" . rcms_date_localise('Sunday') . "',
- '" . rcms_date_localise('Monday') . "',
- '" . rcms_date_localise('Tuesday') . "',
- '" . rcms_date_localise('Wednesday') . "',
- '" . rcms_date_localise('Thursday') . "',
- '" . rcms_date_localise('Friday') . "',
- '" . rcms_date_localise('Saturday') . "'
- ],
-
- buttonText: {
- today: '" . __('Today') . "',
- month: '" . __('Month') . "',
- week: '" . __('Week') . "',
- day: '" . __('Day') . "',
- list: '" . __('List') . "'
- },
-
-
- events: [
- " . $data . "
-
- ]
-
- });
-
- });
-
- </script>
- <div id='" . $elementid . "'></div>
- ";
- $jsCalendarDnD = '';
- $jsCalendarSrchFill = '';
- $jsCalendarSearch = '';
- $appendJS = '';
- if ($dragdropON) {
- $jsCalendarDnDCancel = " event.start = eventPrevStartDT;
- $('#" . $elementid . "').fullCalendar('updateEvent', event);
- console.log(objID + ' Start time change canceled');
- ";
- $jsCalendarDnDMain = " // need to convert to local time to prevent adding timezone offset hours adding after drop
- var mm = moment(event.start);
- mm.local();
- event.start = mm;
- var newStartDT = event.start.format('YYYY-MM-DD HH:mm:ss');
-
- $.ajax({
- type: \"POST\",
- url: \"" . $ajaxURLForDnD . "\",
- data: {object_id: objID, new_start_time: newStartDT},
- success: function(reqResult) {
- // 'SUCCESS' must be returned as a result of the request
- // to indicate that event datetime was actually changed
- // otherwise DnD operation will be reverted
- if (reqResult == 'SUCCESS') {
- console.log(objID + ' Start time changed');
- } else {
- " . $jsCalendarDnDCancel . "
- }
- }
- });
- ";
- if ($dndConfirmON) {
- $jsCalendarDnD = "
- calendar.on('eventDrop', function(event, delta, revertFunc, jsEvent, ui, view) {
- var objID = event.id;
- if (empty(objID)) {
- " . $jsCalendarDnDCancel . "
- return false;
- }
-
- if (confirm('" . __('Do you confirm the movement of this event?') . "')) {
- " . $jsCalendarDnDMain . "
- } else {
- " . $jsCalendarDnDCancel . "
- }
- });
-
- ";
- } else {
- $jsCalendarDnD = "
- calendar.on('eventDrop', function(event, delta, revertFunc, jsEvent, ui, view) {
- var objID = event.id;
- if (empty(objID)) {
- " . $jsCalendarDnDCancel . "
- return false;
- }
-
- " . $jsCalendarDnDMain . "
- });
-
- ";
- }
- }
- if ($titlesSearchON) {
- $jsCalendarSrchFill = "$('#calendarSource').val(JSON.stringify(calendar.clientEvents(), ['id', 'title', 'start', 'end', 'url', 'className', 'allDay']));";
- $jsCalendarSearch = "
- $('#calendarSearchInput').on('change keyup', function() {
- var searchWords = this.value.toLowerCase().split(' ');
- var source = JSON.parse($('#calendarSource').val());
- var newSource = source.filter(elem => {
- var titleStr = elem.title.toLowerCase();
- return searchWords.every(item => titleStr.includes(item));
- });
-
- // converting UTC datetime back to our timezone
- newSource.forEach(item => {
- var dtStart = item.start;
- item.start = new Date(dtStart);
- });
- refreshCalendar(newSource);
- });
-
- function refreshCalendar(newSource) {
- $('#" . $elementid . "').fullCalendar('removeEvents');
- $('#" . $elementid . "').fullCalendar('addEventSource', newSource);
- $('#" . $elementid . "').fullCalendar('refetchEvents');
- }
-
- ";
- }
- if ($titlesSearchON or $dragdropON) {
- $appendJS = "
- <script type='text/javascript'>
- // global scope var to save the event's initial start datetime on DragNDrop operation start
- // to be used for DnD cancelation if confirmation is ON
- var eventPrevStartDT = '';
-
- $(function() {
- var calendar = $('#" . $elementid . "').fullCalendar('getCalendar');
- " . $jsCalendarSrchFill . "
-
- calendar.on('eventDragStart', function(event, jsEvent, ui, view) {
- eventPrevStartDT = event.start.format();
- });
-
- " . $jsCalendarDnD . "
- });
-
- " . $jsCalendarSearch . "
- " . wf_JSEmptyFunc() . "
- </script>
-
- ";
- $calendar .= $appendJS;
- }
- if ($titlesSearchON) {
- $calendar .= "\n" . wf_HiddenInput('calendarsource', '', 'calendarSource');
- $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;"')
- . wf_delimiter() . $calendar;
- }
- return ($calendar);
- }
- /**
- * Returns div plate with some content
- *
- * @param string $content Data to include into plate widget
- * @param string $width Widget width
- * @param string $height Widget height
- * @param string $class Widget class to assign
- * @param string $opts Widget style options. Do not include style="..."
- *
- * @return string
- */
- function wf_Plate($content, $width = '', $height = '', $class = '', $opts = '') {
- if ($width != '') {
- $width = 'width: ' . $width . ';';
- }
- if ($height != '') {
- $height = 'height: ' . $height . ';';
- }
- if ($class != '') {
- $class = 'class="' . $class . '"';
- }
- $result = '
- <div style="' . $width . ' ' . $height . ' float: left; ' . $opts . ' " ' . $class . '>
- ' . $content . '
- </div>
- ';
- return ($result);
- }
- /**
- * Returns some count of delimiters
- *
- * @param int $count count of delimited rows
- * @return string
- *
- */
- function wf_delimiter($count = 1) {
- $result = '';
- for ($i = 0; $i <= $count; $i++) {
- $result .= '<br />';
- }
- return ($result);
- }
- /**
- * Returns some html styled tag
- *
- * @param int $tag HTML tag entity
- * @param bool $closed tag is closing?
- * @param string $class tag styling class
- * @param string $options tag extra options
- * @return string
- *
- */
- function wf_tag($tag, $closed = false, $class = '', $options = '') {
- if (!empty($class)) {
- $tagclass = ' class="' . $class . '"';
- } else {
- $tagclass = '';
- }
- if ($closed) {
- $tagclose = '/';
- } else {
- $tagclose = '';
- }
- if ($options != '') {
- $tagoptions = $options;
- } else {
- $tagoptions = '';
- }
- $result = '<' . $tagclose . $tag . $tagclass . ' ' . $tagoptions . '>';
- return ($result);
- }
- /**
- * Constructs and returns default AJAX loader
- *
- * @param bool $noAnimation
- *
- * @return string
- */
- function wf_AjaxLoader($noAnimation = false) {
- if ($noAnimation) {
- $animationCode = '';
- } else {
- $animationCode = 'contentElem.innerHTML = \'<img src="skins/ajaxloader.gif" id="ubajaxloaderanim">\';';
- }
- $result = '
- <script type="text/javascript">
- function getXmlHttp()
- {
- var xmlhttp;
- try
- {
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- }
- catch (e)
- {
- try
- {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch (E)
- {
- xmlhttp = false;
- }
- }
-
- if(!xmlhttp && typeof XMLHttpRequest!=\'undefined\')
- {
- xmlhttp = new XMLHttpRequest();
- }
- return xmlhttp;
- }
-
- function goajax(link,container)
- {
- var myrequest = getXmlHttp()
- var docum = link;
- var contentElem = document.getElementById(container);
- myrequest.open(\'POST\', docum, true);
- myrequest.setRequestHeader(\'Content-Type\', \'application/x-www-form-urlencoded\');
- ' . $animationCode . '
- myrequest.onreadystatechange = function()
- {
- if (myrequest.readyState == 4)
- {
- if(myrequest.status == 200)
- {
- var resText = myrequest.responseText;
- var ua = navigator.userAgent.toLowerCase();
-
- if (ua.indexOf(\'gecko\') != -1)
- {
- var range = contentElem.ownerDocument.createRange();
- range.selectNodeContents(contentElem);
- range.deleteContents();
- var fragment = range.createContextualFragment(resText);
- contentElem.appendChild(fragment);
- }
- else
- {
- contentElem.innerHTML = resText;
- }
- }
- else
- {
- contentElem.innerHTML = \'' . __('Error') . '\';
- }
- }
-
- }
- myrequest.send();
- }
- </script>
- ';
- return ($result);
- }
- /**
- * Returns default ajax container div element
- *
- * @param string $containerName container name aka ID
- * @param string $options misc options like size/display if required
- * @param string $content default container content
- *
- * @return string
- */
- function wf_AjaxContainer($containerName, $options = '', $content = '') {
- $result = wf_tag('div', false, '', 'id="' . $containerName . '" ' . $options . ' ') . $content . wf_tag('div', true);
- return ($result);
- }
- /**
- * Returns default ajax container span element
- *
- * @param string $containerName container name aka ID
- * @param string $options misc options like size/display if required
- * @param srring $content default container content
- *
- * @return string
- */
- function wf_AjaxContainerSpan($containerName, $options = '', $content = '') {
- $result = wf_tag('span', false, '', 'id="' . $containerName . '" ' . $options . ' ') . $content . wf_tag('span', true);
- return ($result);
- }
- /**
- * Returns new opened modal window with some content
- *
- * @param string $title modal window title
- * @param string $content modal window content
- * @param string $width modal window width
- * @param string $height modal window height
- * @return string
- *
- */
- function wf_modalOpened($title, $content, $width = '', $height = '') {
- $wid = wf_inputid();
- //setting auto width if not specified
- if ($width == '') {
- $width = '600';
- }
- //setting auto width if not specified
- if ($height == '') {
- $height = '400';
- }
- $dialog = '
- <script type="text/javascript">
- $(function() {
- $( "#dialog-modal_' . $wid . '" ).dialog({
- autoOpen: true,
- width: ' . $width . ',
- height: ' . $height . ',
- modal: true,
- show: "drop",
- hide: "fold"
- });
- $( "#opener_' . $wid . '" ).click(function() {
- $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
- return false;
- });
- });
- </script>
- <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
- <p>
- ' . $content . '
- </p>
- </div>
- ';
- return ($dialog);
- }
- /**
- * Returns new opened modal window with some content and automatic sizes
- *
- * @param string $title modal window title
- * @param string $content modal window content
- *
- * @return string
- */
- function wf_modalOpenedAuto($title, $content) {
- $wid = wf_inputid();
- $width = "'auto'";
- $height = "'auto'";
- $dialog = '
- <script type="text/javascript">
- $(function() {
- $( "#dialog-modal_' . $wid . '" ).dialog({
- autoOpen: true,
- width: ' . $width . ',
- height: ' . $height . ',
- modal: true,
- show: "drop",
- hide: "fold"
- });
- $( "#opener_' . $wid . '" ).click(function() {
- $( "#dialog-modal_' . $wid . '" ).dialog( "open" );
- return false;
- });
- });
- </script>
- <div id="dialog-modal_' . $wid . '" title="' . $title . '" style="display:none; width:1px; height:1px;">
- <p>
- ' . $content . '
- </p>
- </div>
- ';
- return ($dialog);
- }
- /**
- * Returns Chart source
- *
- * @param string $data - CSV formatted data
- * @param string $widht - graph width in pixels
- * @param string $height - graph height in pixels
- * @param bool $errorbars - display error bars around data series
- *
- * @return string
- */
- function wf_Graph($data, $width = '500', $height = '300', $errorbars = false, $GraphTitle = '', $XLabel = '', $YLabel = '', $RangeSelector = false) {
- $randomId = wf_InputId();
- $objectId = 'graph_' . $randomId;
- $data = trim($data);
- $data = explodeRows($data);
- $cleandata = '';
- if ($errorbars) {
- $errorbars = 'true';
- } else {
- $errorbars = 'false';
- }
- if (!empty($data)) {
- foreach ($data as $eachrow) {
- $cleandata .= '"' . trim($eachrow) . '\n" +' . "\n";
- }
- $cleandata = mb_substr($cleandata, 0, -2, 'utf-8');
- }
- //style="width: 98%; "
- $result = wf_tag('div', false, '', 'id="' . $randomId . '" style="width:' . $width . 'px; height:' . $height . 'px;"') . wf_tag('div', true);
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= $objectId . ' = new Dygraph(';
- $result .= 'document.getElementById("' . $randomId . '"),' . "\n";
- $result .= $cleandata;
- $result .= ', { errorBars: ' . $errorbars;
- $result .= (!empty($GraphTitle)) ? ', title: \'' . $GraphTitle . '\'' : '';
- $result .= (!empty($XLabel)) ? ', xlabel: \'' . $XLabel . '\'' : '';
- $result .= (!empty($YLabel)) ? ', ylabel: \'' . $YLabel . '\'' : '';
- $result .= (!empty($RangeSelector)) ? ', showRangeSelector: true' : '';
- $result .= ' }' . "\n";
- $result .= ');';
- $result .= wf_tag('script', true);
- return ($result);
- }
- /**
- * Returns Chart source by data loaded from the file - acceptable for huge data sets
- *
- * @param string $datafile - existing CSV file path
- * @param string $widht - graph width in pixels
- * @param string $height - graph height in pixels
- * @param bool $errorbars - display error bars around data series
- *
- * @return string
- */
- function wf_GraphCSV($datafile, $width = '500', $height = '300', $errorbars = false, $GraphTitle = '', $XLabel = '', $YLabel = '', $RangeSelector = false) {
- $randomId = wf_InputId();
- $objectId = 'graph_' . $randomId;
- if ($errorbars) {
- $errorbars = 'true';
- } else {
- $errorbars = 'false';
- }
- $result = wf_tag('div', false, '', 'id="' . $randomId . '" style="width:' . $width . 'px; height:' . $height . 'px;"') . wf_tag('div', true);
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= $objectId . ' = new Dygraph(';
- $result .= 'document.getElementById("' . $randomId . '"), "' . $datafile . '" ' . "\n";
- $result .= ', { errorBars: ' . $errorbars;
- $result .= (!empty($GraphTitle)) ? ', title: \'' . $GraphTitle . '\'' : '';
- $result .= (!empty($XLabel)) ? ', xlabel: \'' . $XLabel . '\'' : '';
- $result .= (!empty($YLabel)) ? ', ylabel: \'' . $YLabel . '\'' : '';
- $result .= (!empty($RangeSelector)) ? ', showRangeSelector: true' : '';
- $result .= ' }' . "\n";
- $result .= ');';
- $result .= wf_tag('script', true);
- return ($result);
- }
- /**
- * Returns color picker dialog
- *
- * @param string $name input name
- * @param string $label input text label
- * @param string $value input pre setted data
- * @param bool $br add line break after input?
- * @param string $size size of element
- * @param string $changeCtrlColorID ID of the control which color will be changed to selected color
- * @param string $changeCtrlColorCSSProp the CSS3 color-property which will be assigned to selected color
- * (like: background-color, border-color, etc)
- *
- * @return string
- */
- function wf_ColPicker($name, $label = '', $value = '', $br = false, $size = '', $changeCtrlColorID = '', $changeCtrlColorCSSProp = '') {
- $id = wf_InputId();
- if (!empty($changeCtrlColorID) and !empty($changeCtrlColorCSSProp)) {
- $changeCtrlColorJS = ' $(\'#' . $changeCtrlColorID . '\').css("' . $changeCtrlColorCSSProp . '", "#" + hex_str);';
- } else {
- $changeCtrlColorJS = '';
- }
- $css = '
- <link rel="stylesheet" href="modules/jsc/colpick/colpick.css" type="text/css"/>';
- $js = '
- <script src="modules/jsc/colpick/colpick.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $("#' . $id . '").colpick({
- colorScheme: "light",
- layout: "hex",
- submit: true,
- color: "' . (!empty($value) ? $value : "#f57601") . '",
- onSubmit: function(hsb,hex,rgb,el) {
- var colpickID = $(el).colpick().data("colpickId");
- var hex_str = $("#" + colpickID + " div.colpick_hex_field > input").val();
-
- $(el).val("#" + hex_str);
- $(el).colpickHide();
- $(el).focus();
- ' . $changeCtrlColorJS . '
- },
- onChange: function(hsb,hex,rgb,el) {
- var hex_str = hex;
- ' . $changeCtrlColorJS . '
- }
- });
- });
- </script>
- ';
- if (!empty($changeCtrlColorJS)) {
- $tmpJS = '
- $(document).ready(function() {
- var colpickID = $("#' . $id . '").colpick().data("colpickId");
- var hex_str = $("#" + colpickID + " div.colpick_hex_field > input").val();
- ' . $changeCtrlColorJS . '
- });
- ';
- $js .= wf_EncloseWithJSTags($tmpJS);
- }
- $size = (!empty($size)) ? 'size="' . $size . '"' : null;
- $result = '<input type="text" name="' . $name . '" value="' . $value . '" id="' . $id . '" ' . $size . '>' . "\n";
- $result .= (!empty($label)) ? '<label for="' . $id . '">' . __($label) . '</label>' : null;
- $result .= (!empty($br)) ? '<br>' : null;
- $result .= "\n";
- return $css . $js . $result;
- }
- /**
- * Return Jquery UI selectable combobox
- *
- * @param string $name name of element
- * @param array $params array of elements $value=>$option
- * @param string $label text label for input
- * @param string $selected selected $value for selector (now ignored)
- * @param bool $br append new line
- * @return string
- *
- */
- function wf_JuiComboBox($name, $params, $label, $selected = '', $br = false) {
- $id = wf_InputId();
- $select = '';
- if (!empty($params)) {
- foreach ($params as $io => $each) {
- $flag_selected = (!empty($selected) and $selected == $io) ? 'SELECTED' : '';
- $select .= '<option value="' . $io . '" ' . $flag_selected . '>' . $each . '</option>' . "\n";
- }
- }
- $result = '
- <style>
- .custom-combobox_' . $id . ' {
- position: relative;
- display: inline-block;
- }
- .custom-combobox-toggle_' . $id . ' {
- position: absolute;
- top: 0;
- bottom: 0;
- margin-left: -1px;
- padding: 0;
- }
- .custom-combobox-input_' . $id . ' {
- margin: 0;
- padding: 5px 10px;
- }
- .ui-autocomplete {
- max-height: 400px;
- overflow-y: auto; /* prevent horizontal scrollbar */
- overflow-x: hidden; /* add padding to account for vertical scrollbar */
- z-index:1000 !important;
- }
- </style>
- <script>
- (function( $ ) {
- $.widget( "custom.combobox_' . $id . '", {
- _create: function() {
- this.wrapper = $( "<span>" )
- .addClass( "custom-combobox_' . $id . '" )
- .insertAfter( this.element );
- this.element.hide();
- this._createAutocomplete();
- this._createShowAllButton();
- },
- _createAutocomplete: function() {
- var selected = this.element.children( ":selected" ),
- value = selected.val() ? selected.text() : "";
- this.input = $( "<input>" )
- .appendTo( this.wrapper )
- .val( value )
- .attr( "title", "" )
- .addClass( "custom-combobox-input_' . $id . ' ui-widget_' . $id . ' ui-widget-content ui-state-default ui-corner-left" )
- .autocomplete({
- delay: 0,
- minLength: 0,
- source: $.proxy( this, "_source" )
- })
- .tooltip({
- tooltipClass: "ui-state-highlight"
- });
- this._on( this.input, {
- autocompleteselect: function( event, ui ) {
- ui.item.option.selected = true;
- this._trigger( "select", event, {
- item: ui.item.option
- });
- },
- autocompletechange: "_removeIfInvalid"
- });
- },
- _createShowAllButton: function() {
- var input = this.input,
- wasOpen = false;
- $( "<a>" )
- .attr( "tabIndex", -1 )
- .attr( "title", "' . __('Show all') . '" )
- .tooltip()
- .appendTo( this.wrapper )
- .button({
- icons: {
- primary: "ui-icon-triangle-1-s"
- },
- text: false
- })
- .removeClass( "ui-corner-all" )
- .addClass( "custom-combobox-toggle_' . $id . ' ui-corner-right" )
- .mousedown(function() {
- wasOpen = input.autocomplete( "widget" ).is( ":visible" );
- })
- .click(function() {
- input.focus();
- // Close if already visible
- if ( wasOpen ) {
- return;
- }
- // Pass empty string as value to search for, displaying all results
- input.autocomplete( "search", "" );
- });
- },
- _source: function( request, response ) {
- var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
- response( this.element.children( "option" ).map(function() {
- var text = $( this ).text();
- if ( this.value && ( !request.term || matcher.test(text) ) )
- return {
- label: text,
- value: text,
- option: this
- };
- }) );
- },
- _removeIfInvalid: function( event, ui ) {
- // Selected an item, nothing to do
- if ( ui.item ) {
- return;
- }
- // Search for a match (case-insensitive)
- var value = this.input.val(),
- valueLowerCase = value.toLowerCase(),
- valid = false;
- this.element.children( "option" ).each(function() {
- if ( $( this ).text().toLowerCase() === valueLowerCase ) {
- this.selected = valid = true;
- return false;
- }
- });
- // Found a match, nothing to do
- if ( valid ) {
- return;
- }
- this.input.autocomplete( "instance" ).term = "";
- },
- _destroy: function() {
- this.wrapper.remove();
- this.element.show();
- }
- });
- })( jQuery );
- $(function() {
- $( "#combobox_' . $id . '" ).combobox_' . $id . '();
- });
- </script>
- <div class="ui-widget_' . $id . '">
- <label for="combobox_' . $id . '">' . $label . '</label>
- <select id="combobox_' . $id . '" name=' . $name . '>
- ' . $select . '
- </select>
- </div>
- ';
- if ($br) {
- $result .= wf_tag('br');
- }
- return ($result);
- }
- /**
- * Returns auto complete text input element
- *
- * @param string $name name of element
- * @param array $data data array for autocomplete box
- * @param string $label text label for input
- * @param string $value current value
- * @param bool $br append new line - bool
- * @param string $size input size
- * @return string
- *
- */
- function wf_AutocompleteTextInput($name, $data = array(), $label = '', $value = '', $br = false, $size = '') {
- $inputid = wf_InputId();
- //set size
- if ($size != '') {
- $input_size = 'size="' . $size . '"';
- } else {
- $input_size = '';
- }
- if ($br) {
- $newline = '<br>';
- } else {
- $newline = '';
- }
- $acData = '';
- $autocomplete = '<script>
- $(function() {
- var availableOpts_' . $inputid . ' = [
- ';
- if (!empty($data)) {
- foreach ($data as $io => $each) {
- $each = str_replace('"', '`', $each);
- $acData .= '"' . $each . '",';
- }
- }
- //removing ending coma
- $acData = mb_substr($acData, 0, -1, 'UTF-8');
- $autocomplete .= $acData;
- $autocomplete .= '
- ];
- $( "#' . $name . '_autocomplete" ).autocomplete({
- source: availableOpts_' . $inputid . '
- });
- });
- </script>';
- $result = $autocomplete;
- $result .= '<input type="text" id="' . $name . '_autocomplete" name="' . $name . '" value="' . $value . '" ' . $input_size . ' id="' . $inputid . '">' . "\n";
- if ($label != '') {
- $result .= ' <label for="' . $inputid . '">' . __($label) . '</label>' . "\n";
- }
- $result .= $newline . "\n";
- return ($result);
- }
- /**
- * Returns calendar widget with preset time
- * Based on Jon Thornton's jquery timepicker: http://jonthornton.github.io/jquery-timepicker
- *
- * @param string $field field name to insert time select widget
- * @param string $time default value time for widget
- * @param string $DisabledTimeRanges string which represents time ranges unavailable to pick up, like: "['11:00', '14:05'], ['20:30', '21:00']" and so on
- * @param string $label label of widget
- * @param bool $br add break after the widget body?
- * @return string
- */
- function wf_TimePickerPreset($field, $time = '', $label = '', $br = false, $DisabledTimeRanges = '') {
- $inputId = wf_InputId();
- if (isset($DisabledTimeRanges)) {
- $DisabledTimeRanges = ',\'disableTimeRanges\': [ ' . $DisabledTimeRanges . ']';
- }
- $result = wf_tag('input', false, '', 'type="text" value="' . $time . '" name="' . $field . '" size="5" id="' . $inputId . '"');
- $result .= wf_tag('script');
- $result .= '$(\'#' . $inputId . '\').timepicker({\'scrollDefault\': \'' . $time . '\', \'timeFormat\': \'H:i\'' . $DisabledTimeRanges . ' });';
- $result .= wf_tag('script', true);
- //clickable icon and label
- if (!empty($label)) {
- $label = ' ' . __($label);
- }
- $result .= wf_tag('label', false, '', 'for="' . $inputId . '"') . wf_img('skins/icon_time_small.png', __('Time')) . $label . wf_tag('label', true);
- //break at end
- if ($br) {
- $result .= wf_tag('br');
- }
- return ($result);
- }
- /**
- * Returns calendar widget with preset time
- * Based on Jon Thornton's jquery timepicker: http://jonthornton.github.io/jquery-timepicker
- *
- * @param string $field field name to insert time select widget
- * @param string $time default value time for widget
- * @param string $DisabledTimeRanges string which represents time ranges unavailable to pick up, like: "['11:00', '14:05'], ['20:30', '21:00']" and so on
- * @param string $label label of widget
- * @param bool $br add break after the widget body?
- * @return string
- */
- function wf_TimePickerPresetSeconds($field, $time = '', $label = '', $br = false, $DisabledTimeRanges = '') {
- $inputId = wf_InputId();
- if (isset($DisabledTimeRanges)) {
- $DisabledTimeRanges = ',\'disableTimeRanges\': [ ' . $DisabledTimeRanges . ']';
- }
- $result = wf_tag('input', false, '', 'type="text" value="' . $time . '" name="' . $field . '" size="8" id="' . $inputId . '"');
- $result .= wf_tag('script');
- $result .= '$(\'#' . $inputId . '\').timepicker({\'scrollDefault\': \'' . $time . '\', \'timeFormat\': \'H:i:s\'' . $DisabledTimeRanges . ' });';
- $result .= wf_tag('script', true);
- //clickable icon and label
- if (!empty($label)) {
- $label = ' ' . __($label);
- }
- $result .= wf_tag('label', false, '', 'for="' . $inputId . '"') . wf_img('skins/icon_time_small.png', __('Time')) . $label . wf_tag('label', true);
- //break at end
- if ($br) {
- $result .= wf_tag('br');
- }
- return ($result);
- }
- /**
- * Returns div with styles cleanup
- *
- * @return string
- */
- function wf_CleanDiv() {
- $result = wf_tag('div', false, '', 'style="clear:both;"') . wf_tag('div', true);
- return ($result);
- }
- /**
- * Renders JQuery Data Tables container
- *
- * @param array $columns columns names array
- * @param string $ajaxUrl URL to fetch JSON data
- * @param bool $saveState grid state saving - conflicts with default sort order
- * @param string $objects object names
- * @param int $rowsCount rows count to default display
- * @param string $opts additional options like:
- * "order": [[ 0, "desc" ]]
- * or
- * dom: \'Bfrtipsl\', buttons: [\'copy\', \'csv\', \'excel\', \'pdf\', \'print\']
- * or "dom": \'<"F"lfB>rti<"F"ps>\', buttons: [\'csv\', \'excel\', \'pdf\', \'print\']
- * @param bool $addFooter
- * @param string $footerOpts
- * @param string $footerTHOpts
- *
- * @return string
- */
- function wf_JqDtLoader($columns, $ajaxUrl, $saveState = false, $objects = 'users', $rowsCount = 100, $opts = '', $addFooter = false, $footerOpts = '', $footerTHOpts = '') {
- $tableId = 'jqdt_' . md5($ajaxUrl);
- $result = '';
- $saveState = ($saveState) ? 'true' : 'false';
- $opts = (!empty($opts)) ? $opts . ',' : '';
- $jq_dt = wf_tag('script', false, '', ' type="text/javascript" charset="utf-8"');
- $jq_dt .= '
- $(document).ready(function() {
-
- var table=$(\'#' . $tableId . '\').dataTable( {
- "oLanguage": {
- "sLengthMenu": "' . __('Show') . ' _MENU_",
- "sZeroRecords": "' . __('Nothing found') . '",
- "sInfo": "' . __('Showing') . ' _START_ ' . __('to') . ' _END_ ' . __('of') . ' _TOTAL_ ' . __($objects) . '",
- "sInfoEmpty": "' . __('Showing') . ' 0 ' . __('to') . ' 0 ' . __('of') . ' 0 ' . __($objects) . '",
- "sInfoFiltered": "(' . __('Filtered') . ' ' . __('from') . ' _MAX_ ' . __('Total') . ')",
- "sSearch": "' . __('Search') . '",
- "sProcessing": "' . __('Processing') . '...",
- "oPaginate": {
- "sFirst": "' . __('First') . '",
- "sPrevious": "' . __('Previous') . '",
- "sNext": "' . __('Next') . '",
- "sLast": "' . __('Last') . '"
- },
- },
-
- "bPaginate": true,
- "bLengthChange": true,
- "bFilter": true,
- "bSort": true,
- "bInfo": true,
- "bAutoWidth": false,
- "bProcessing": true,
- "bStateSave": ' . $saveState . ',
- "iDisplayLength": ' . $rowsCount . ',
- "sAjaxSource": \'' . $ajaxUrl . '\',
- "bDeferRender": true,
- "lengthMenu": [[10, 25, 50, 100, 200, -1], [10, 25, 50, 100, 200, "' . __('All') . '"]],
- ' . $opts . '
- "bJQueryUI": true
- } );
-
-
-
- } );
-
-
- ';
- $jq_dt .= wf_tag('script', true);
- $result = $jq_dt;
- $result .= wf_tag('table', false, 'display compact', 'id="' . $tableId . '"');
- $result .= wf_tag('thead', false);
- $tablecells = '';
- $footerCells = '<tfoot ' . $footerOpts . '><tr>';
- foreach ($columns as $io => $eachColumn) {
- $tablecells .= wf_TableCell(__($eachColumn));
- if ($addFooter) {
- $footerCells .= '<th ' . $footerTHOpts . '></th>';
- }
- }
- $result .= wf_TableRow($tablecells);
- $result .= wf_tag('thead', true);
- if ($addFooter) {
- $result .= $footerCells . '</tr></tfoot>';
- }
- $result .= wf_tag('table', true);
- return ($result);
- }
- /**
- * Returns a JS snippet to control the visibility of JQDT column
- *
- * @param string $CallerObjID
- * @param string $CallerObjEvent
- * @param string $JQDTID
- * @param int $ColIndex
- *
- * @return string
- */
- function wf_JQDTColumnHideShow($CallerObjID, $CallerObjEvent, $JQDTID, $ColIndex) {
- $JSCode = '$(\'#' . $CallerObjID . '\').on("' . $CallerObjEvent . '", function() {
- // Get the column API object
- var column = $(\'#' . $JQDTID . '\').DataTable().column(' . $ColIndex . ');
- // Toggle the visibility
- column.visible( !column.visible() );
- });
- ';
- return $JSCode;
- }
- /**
- * Returns a JS snippet for .row().show() plugin
- *
- * @return string
- */
- function wf_JQDTRowShowPluginJS() {
- $jsCode = '
- $.fn.dataTable.Api.register(\'row().show()\', function() {
- var page_info = this.table().page.info();
- // Get row index
- var new_row_index = this.index();
- // Row position
- var row_position = this.table()
- .rows({ search: \'applied\' })[0]
- .indexOf(new_row_index);
- // Already on right page ?
- if ((row_position >= page_info.start && row_position < page_info.end) || row_position < 0) {
- // Return row object
- return this;
- }
- // Find page number
- var page_to_display = Math.floor(row_position / this.table().page.len());
- // Go to that page
- this.table().page(page_to_display);
- // Return row object
- return this;
- });
-
- ';
- return ($jsCode);
- }
- /**
- * Returns a JS snippet for column footer sum() plugin
- *
- * @return string
- */
- function wf_JQDTColumnTotalSumJS() {
- $jsCode = '
- jQuery.fn.dataTable.Api.register( \'sum()\', function ( ) {
- return this.flatten().reduce( function ( a, b ) {
- if ( typeof a === \'string\' ) {
- a = a.replace(/[^\d.-]/g, \'\') * 1;
- }
- if ( typeof b === \'string\' ) {
- b = b.replace(/[^\d.-]/g, \'\') * 1;
- }
-
- return a + b;
- }, 0 );
- } );
-
- ';
- return ($jsCode);
- }
- /**
- * Returns a JS snippet for markdown the row with searched value
- *
- * @param string|int $columnNum
- * @param string $searchVal
- * @param string $truncateURL
- * @param string $truncateParam
- *
- * @return string
- */
- function wf_JQDTMarkRowJS($columnNum, $searchVal, $truncateURL = '', $truncateParam = '') {
- $truncateJSCode = '';
- if (!empty($truncateURL) and !empty($truncateParam)) {
- $truncateJSCode = '
- //var urlParamsObject = new URLSearchParams(\'' . $truncateURL . '\');
- var urlParamsObject = new URLSearchParams(window.location.search);
-
- if (urlParamsObject.has(\'' . $truncateParam . '\')) {
- urlParamsObject.delete(\'' . $truncateParam . '\');
- var truncatedURL = window.location.origin + window.location.pathname + "?" + urlParamsObject.toString();
- window.history.replaceState({}, document.title, truncatedURL);
- }
- ';
- }
- $result = '
- $(document).ready( function () {
- var table = $(\'[id ^= "jqdt_"][role = "grid"]\').DataTable();
- table.on( \'init\', function () {
- var row = table.row(function ( idx, data, node ) {
- return data[' . $columnNum . '] == \'' . $searchVal . '\';
- });
-
- if (row.length > 0) {
- row.select().show().draw(false);
- }
- });
- ' . $truncateJSCode . '
- });
- ';
- return ($result);
- }
- /**
- * Retruns a JS snippet for processing JQDT "details" functional
- *
- * @param $ajaxURL - URL to retrive data into "details" DIV
- * @param $colIndex - above-level JQDT column index to get the AJAX data from
- * @param $jqdtID - above-level JQDT DOM ID
- * @param string $ajaxMethod
- * @param string $jsFuncName - JS function name which will be called on processing the "details click"
- * @param string $divContainerCSS - some CSS for "details" DIV
- *
- * @return string
- */
- function wf_JQDTDetailsClickProcessingJS($ajaxURL, $colIndex, $jqdtID, $ajaxMethod = 'POST', $jsFuncName = 'showDetailsData', $divContainerCSS = '') {
- $divCSS = (empty($divContainerCSS) ? '{"margin-top":"5px", "margin-left":"10px", "margin-bottom":"10px"}' : $divContainerCSS);
- $result = '
- $(document).ready(function() {
- $(\'#' . $jqdtID . ' tbody\').on(\'click\', \'td.details-control\', function (evt) {
- evt.stopPropagation();
- var table = $(\'#' . $jqdtID . '\').DataTable();
- var tr = $(this).closest(\'tr\');
- var row = table.row( tr );
- var rowIdx = row.index();
- var ajaxData = table.cell(rowIdx, ' . $colIndex . ').data();
-
- if ( row.child.isShown() ) {
- row.child.hide();
- tr.removeClass(\'shown\');
- }
- else {
- row.child( ' . $jsFuncName . '(row.data(), ajaxData, \'' . $ajaxURL . '\', \'' . $ajaxMethod . '\') ).show();
- tr.addClass(\'shown\');
- }
- } );
-
- function ' . $jsFuncName . ' ( rowData, ajaxData, ajaxURL, ajaxMethod ) {
- var div = $(\'<div/>\')
- .addClass( \'detailsLoading\' )
- .text( \'Loading...\' );
-
- $.ajax( {
- type: ajaxMethod,
- url: ajaxURL,
- data: ajaxData,
- success: function ( reqResult ) {
- div.html( reqResult ).removeClass( \'loading\' );
- div.css(' . $divCSS . ');
- }
- } );
-
- return div;
- }
- } );
- ';
- return ($result);
- }
- /**
- * Returns simple JQDT refresh link with JS snippet
- *
- * @param string $jqdtID
- * @param string $jqdtIDSelector
- * @param string $class
- * @param string $opts
- *
- * @return string
- */
- function wf_JQDTRefreshButton($jqdtID = '', $jqdtIDSelector = '', $class = '', $opts = '') {
- $result = '';
- if (!empty($jqdtID) or !empty($jqdtIDSelector)) {
- $class = (empty($class) ? 'ubButtonInline' : $class);
- $tmpInpID = wf_InputId();
- $result = wf_Link('#', wf_img('skins/refresh.gif', __('Refresh table data'), 'vertical-align: bottom'), false, $class, 'id="' . $tmpInpID . '" ' . $opts);
- $tmpScript = '
- $(\'#' . $tmpInpID . '\').click(function(evt) {
- $(\'img\', this).addClass("image_rotate");
- ';
- if (empty($jqdtID)) {
- $tmpScript .= '$(\'#\'+' . $jqdtIDSelector . ').DataTable().ajax.reload();';
- } else {
- $tmpScript .= '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();';
- }
- $tmpScript .= '
-
- $(\'img\', this).removeClass("image_rotate");
- evt.preventDefault();
- return false;
- });
-
- ';
- $result .= wf_EncloseWithJSTags($tmpScript);
- }
- return ($result);
- }
- /**
- * Outputs a hex color based text string without # at begin, like an ac1c09
- *
- * @param $text String of text
- * @param $palette Integer between 0 and 100
- *
- * @return string
- */
- function wf_genColorCodeFromText($text, $palette = '') {
- $hash = md5($palette . $text); // modify input to get a different palette
- $result = '';
- $result = substr($hash, 0, 2) . substr($hash, 2, 2) . substr($hash, 4, 2);
- return ($result);
- }
- /**
- * Renders Google 3d pie chart
- *
- * @param array $params data in format like string=>count
- * @param string $title chart title
- * @param string $width chart width in px or %, 500px default
- * @param string $height chart height in px or %, 500px default
- * @param string $options google charts options, useful examples see below<br>
- * pieSliceText: percentage/value/label/none OR pieSliceText: 'value-and-percentage'<br>
- * is3D: true/false <br>
- * backgroundColor: '#666', <br>
- * legend : {position: 'bottom', textStyle: {color: 'red', fontSize: 12 }}, <br>
- * chartArea: { width: '90%', height: '90%' }, <br>
- * @param string $fixedColors use fixed auto-generated colors based on text labels with pallette<br>
- *
- * @return string
- */
- function wf_gcharts3DPie($params, $title = '', $width = '', $height = '', $options = '', $fixedColors = '') {
- global $ubillingConfig;
- $altCfg = $ubillingConfig->getAlter();
- $containerId = wf_InputId();
- $width = ($width) ? $width : '500px';
- $height = ($height) ? $height : '500px';
- $result = '';
- $chartData = '';
- $enableFlag = true;
- if (!isset($altCfg['GCHARTS_ENABLED'])) {
- $enableFlag = true;
- } else {
- if ($altCfg['GCHARTS_ENABLED']) {
- $enableFlag = true;
- } else {
- $enableFlag = false;
- }
- }
- if ($enableFlag) {
- $colors = '';
- if ($fixedColors) {
- $palette = (is_bool($fixedColors)) ? '' : $fixedColors; //use string parameter as palette
- $colors .= 'var colors = { ';
- }
- if (!empty($params)) {
- foreach ($params as $io => $each) {
- $chartData .= '[\'' . $io . '\',' . $each . '],';
- if ($fixedColors) {
- $colors .= " '" . $io . "': '" . wf_genColorCodeFromText($io, $palette) . "',";
- }
- }
- $chartData = substr($chartData, 0, -1);
- }
- if ($fixedColors) {
- $colors = rtrim($colors, ',');
- $colors .= '};';
- }
- if ($fixedColors) {
- $colors .= ' var slices = [];
- for (var i = 0; i < data.getNumberOfRows(); i++) {
- slices.push({
- color: colors[data.getValue(i, 0)]
- });
- }';
- $slicesInject = 'slices: slices,';
- } else {
- $slicesInject = '';
- }
- //legend.scrollArrows.activeColor
- $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.google.com/jsapi"') . wf_tag('script', true);
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= '
- google.load("visualization", "1", {packages:["corechart"]});
- google.setOnLoadCallback(drawChart);
-
- function drawChart() {
- var data = google.visualization.arrayToDataTable([
- [\'X\', \'Y\'],
- ' . $chartData . '
- ]);
-
- ' . $colors . '
-
- var options = {
- title: \'' . $title . '\',
- ' . $slicesInject . '
- is3D: true,
-
- ' . $options . '
-
- \'tooltip\' : {
- trigger: \'none\'
- }
- };
- var chart = new google.visualization.PieChart(document.getElementById(\'' . $containerId . '\'));
-
- chart.draw(data, options);
- }
- ';
- $result .= wf_tag('script', true);
- $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
- }
- return ($result);
- }
- /**
- * Renders Google line chart
- *
- * @param array $params data in format like
- * $params=array(
- * 0=>array('month','total','active','inactive'),
- * 1=>array('Февраль',200,150,50),
- * 2=>array('Сентябрь',200,160,40)
- * );
- * @param string $title chart title
- * @param string $width chart width in px or %, 500px default
- * @param string $height chart height in px or %, 500px default
- * @param string $options google charts options
- *
- * @return string
- */
- function wf_gchartsLine($params, $title = '', $width = '', $height = '', $options = '') {
- global $ubillingConfig;
- $altCfg = $ubillingConfig->getAlter();
- $containerId = wf_InputId();
- $width = ($width) ? $width : '500px';
- $height = ($height) ? $height : '500px';
- $result = '';
- $chartData = '';
- $enableFlag = true;
- if (!isset($altCfg['GCHARTS_ENABLED'])) {
- $enableFlag = true;
- } else {
- if ($altCfg['GCHARTS_ENABLED']) {
- $enableFlag = true;
- } else {
- $enableFlag = false;
- }
- }
- if ($enableFlag) {
- if (!empty($params)) {
- $chartData = json_encode($params, JSON_NUMERIC_CHECK);
- }
- $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
- google.charts.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = google.visualization.arrayToDataTable(
- ' . $chartData . '
- );
- var options = {
- title: \'' . $title . '\',
- curveType: \'function\',
- ' . $options . '
- };
- var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
- chart.draw(data, options);
- }
- ';
- $result .= wf_tag('script', true);
- $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
- }
- return ($result);
- }
- /**
- * Renders Google line chart
- *
- * @param array $params data in format like
- * $params=array(
- * 0=>array('month','total','active','inactive'),
- * 1=>array('Февраль',200,150,50),
- * 2=>array('Сентябрь',200,160,40)
- * );
- * @param string $title chart title
- * @param string $width chart width in px or %, 500px default
- * @param string $height chart height in px or %, 500px default
- * @param string $options google charts options
- *
- * @return string
- */
- function wf_gchartsLineZeroIsBad($params, $title = '', $width = '', $height = '', $options = '') {
- global $ubillingConfig;
- $altCfg = $ubillingConfig->getAlter();
- $containerId = wf_InputId();
- $width = ($width) ? $width : '500px';
- $height = ($height) ? $height : '500px';
- $result = '';
- $chartData = '';
- $enableFlag = true;
- if (!isset($altCfg['GCHARTS_ENABLED'])) {
- $enableFlag = true;
- } else {
- if ($altCfg['GCHARTS_ENABLED']) {
- $enableFlag = true;
- } else {
- $enableFlag = false;
- }
- }
- if ($enableFlag) {
- if (!empty($params)) {
- $chartData = json_encode($params, JSON_NUMERIC_CHECK);
- }
- $result = wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= 'google.charts.load(\'current\', {\'packages\':[\'corechart\']});
- google.charts.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = google.visualization.arrayToDataTable(
- ' . $chartData . '
- );
- var options = {
- title: \'' . $title . '\',
- curveType: \'function\',
- ' . $options . '
- legend: { position: \'bottom\' }
- };
-
- var dataView = new google.visualization.DataView(data);
- dataView.setColumns([
- // reference existing columns by index
- 0, 1,
- // add function for line color
- {
- calc: function(data, row) {
- var colorDown = "#FF0000";
- var colorUp = "#0d8a00";
- if ((data.getValue(row, 1) < 0)) {
- return colorDown;
- } else {
- //return colorUp;
- }
- },
- type: "string",
- role: "style"
- }
- ]);
- var chart = new google.visualization.LineChart(document.getElementById(\'' . $containerId . '\'));
- chart.draw(dataView, options);
- }
- ';
- $result .= wf_tag('script', true);
- $result .= wf_tag('div', false, '', 'id="' . $containerId . '" style="width: ' . $width . '; height: ' . $height . ';"') . wf_tag('div', true);
- }
- return ($result);
- }
- /**
- * Returns default back control
- *
- * @param string $url Link URL
- * @param string $title Link title
- * @param bool $br Line break line after link
- * @param string $class Link class name
- * @param string $opts Link style or attributes
- *
- * @return string
- */
- function wf_BackLink($url, $title = '', $br = false, $class = 'ubButton', $opts = '') {
- $title = (empty($title)) ? __('Back') : __($title);
- $result = wf_Link($url, wf_img('skins/back.png') . ' ' . $title, $br, $class, $opts);
- return ($result);
- }
- /**
- * Returns form disabler JS code, for preventing duplicating POST requests
- *
- * @return string
- */
- function wf_FormDisabler() {
- $result = wf_tag('script', false, '', 'type="text/javascript" language="javascript" src="modules/jsc/form-disabler.js"') . wf_tag('script', true);
- return ($result);
- }
- /**
- * Returns spoiler control with specified options
- *
- * @param string $Content
- * @param string $Title
- * @param bool $Closed
- * @param string $SpoilerID
- * @param string $OuterDivClass
- * @param string $OuterDivOptions
- * @param string $InnerDivClass
- * @param string $InnerDivOptions
- *
- * @return string
- */
- function wf_Spoiler($Content, $Title = '', $Closed = false, $SpoilerID = '', $OuterDivClass = '', $OuterDivOptions = '', $InnerDivClass = '', $InnerDivOptions = '') {
- if (empty($SpoilerID)) {
- $SpoilerID = 'spoiler_' . wf_InputId();
- }
- $SpoilerLnkID = 'lnk_' . wf_InputId();
- $SpoilerBodyID = 'spbody_' . wf_InputId();
- $SpoilerStateID = 'spstate_' . wf_InputId();
- $SpoilerState = ($Closed) ? '▼' : '▲';
- //$ubngStrPos = strpos(CUR_SKIN_PATH, 'ubng');
- $OuterDivClass = 'spoiler clearfix ' . $OuterDivClass;
- $OuterDivOptions = ' id="' . $SpoilerID . '" ' . $OuterDivOptions;
- $InnerDivClass = 'spoiler_body ' . $InnerDivClass;
- $InnerDivOptions = ' id="' . $SpoilerBodyID . '" ' . $InnerDivOptions;
- $Result = wf_tag('div', false, $OuterDivClass, $OuterDivOptions);
- $Result .= wf_tag('div', false, 'spoiler_title clearfix');
- //$Result .= '<a id="' . $SpoilerLnkID . '" class="spoiler_link" href="#">';
- $Result .= '<span id="' . $SpoilerLnkID . '" class="spoiler_link">';
- $Result .= wf_tag('h3', false, '', '');
- $Result .= $Title;
- $Result .= wf_tag('h3', true);
- //$Result .= $SpoilerState . '</a>' . "\n";
- $Result .= '<span id="' . $SpoilerStateID . '">' . $SpoilerState . '</span>';
- $Result .= '</span>' . "\n";
- $Result .= wf_tag('div', true);
- $Result .= wf_tag('div', false, $InnerDivClass, $InnerDivOptions);
- $Result .= $Content;
- $Result .= wf_tag('div', true);
- $Result .= wf_tag('div', true);
- $Result .= wf_tag('script', false, '', 'type="text/javascript"');
- $Result .= '$(\'#' . $SpoilerLnkID . '\').click(function() {
- $(\'#' . $SpoilerBodyID . '\').toggleClass("spoiler_closed");
-
- if ( $(\'#' . $SpoilerBodyID . '\').hasClass("spoiler_closed") ) {
- $(\'#' . $SpoilerBodyID . '\').slideUp(\'50\');
- $(\'#' . $SpoilerStateID . '\').html(\'▼\');
- } else {
- $(\'#' . $SpoilerBodyID . '\').slideDown(\'50\');
- $(\'#' . $SpoilerStateID . '\').html(\'▲\');
- }
-
- return false;
- });';
- //$Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').css("display", "none").toggleClass("spoiler_closed");' : '';
- $Result .= ($Closed) ? '$(\'#' . $SpoilerBodyID . '\').slideUp(\'50\').toggleClass("spoiler_closed");' : '';
- $Result .= wf_tag('script', true);
- return $Result;
- }
- /**
- * Returns JS for a control which will be responsible for opening dynamic modal windows via ajax call to a specific URL
- *
- * @param $ajaxURL
- * @param $dataArray
- * @param string $controlId
- * @param bool $wrapWithJSScriptTag
- * @param string $queryType
- * @param string $jsEvent
- * @param bool $noPreventDefault
- * @param bool $noReturnFalse
- * @param bool $updNestedJQDT
- * @param string $nestedJQDTSelector
- *
- * @return string
- */
- function wf_JSAjaxModalOpener($ajaxURL, $dataArray, $controlId = '', $wrapWithJSScriptTag = false, $queryType = 'GET', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
- $inputId = (empty($controlId)) ? wf_InputId() : $controlId;
- $modalWindowId = 'modalWindowId:"dialog-modal_' . $inputId . '", ';
- $modalWindowBodyId = 'modalWindowBodyId:"body_dialog-modal_' . $inputId . '"';
- $preventDefault = ($noPreventDefault) ? "" : "\nevt.preventDefault();";
- $returnFalse = ($noReturnFalse) ? "" : "\nreturn false;";
- $ajaxData = '';
- foreach ($dataArray as $io => $each) {
- if (is_array($each)) {
- $ajaxData .= $io . ':' . json_encode($each) . ', ';
- } else {
- $ajaxData .= $io . ':"' . $each . '", ';
- }
- }
- if ($updNestedJQDT) {
- $findJQDTToUpdate = (empty($nestedJQDTSelector) ? 'var closestJQDTID = $(this).parent().parent().next("tr").find(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");' : 'var closestJQDTID = ' . $nestedJQDTSelector);
- } else {
- $findJQDTToUpdate = 'var closestJQDTID = $(this).closest(\'[id ^= "jqdt_"][role = "grid"]\').attr("id");';
- }
- $result = '$(\'#' . $inputId . '\').' . $jsEvent . '(function(evt) {
- ' . $findJQDTToUpdate . '
-
- $.ajax({
- type: "' . $queryType . '",
- url: "' . $ajaxURL . '",
- data: {' . $ajaxData
- . $modalWindowId
- . $modalWindowBodyId
- . '},
- success: function(ajaxresult) {
- $(document.body).append(ajaxresult);
- $(\'#dialog-modal_' . $inputId . '\').append(\'<input type="hidden" name="closestJQDT" value="\' + closestJQDTID + \'" id="closestJQDTID">\');
-
- $(\'#dialog-modal_' . $inputId . '\').dialog("open");
- }
- });'
- . $preventDefault
- . $returnFalse
- . '});
- ';
- if ($wrapWithJSScriptTag) {
- $result = wf_tag('script', false, '', 'type="text/javascript"')
- . $result
- . wf_tag('script', true);
- }
- return ($result);
- }
- /**
- * Returns JS for a link which will be responsible for opening an assigned modal window
- *
- * @param $ajaxURL
- * @param $ajaxDataArr
- * @param string $title
- * @param string $icon
- * @param string $linkCSSClass
- * @param string $queryType
- * @param string $jsEvent
- * @param bool $noPreventDefault
- * @param bool $noReturnFalse
- * @param bool $updNestedJQDT
- * @param string $nestedJQDTSelector
- *
- * @return string
- */
- function wf_jsAjaxDynamicWindowButton($ajaxURL, $ajaxDataArr, $title = 'Button', $icon = '', $linkCSSClass = '', $queryType = 'POST', $jsEvent = 'click', $noPreventDefault = false, $noReturnFalse = false, $updNestedJQDT = false, $nestedJQDTSelector = '') {
- $linkID = wf_InputId();
- $dynamicOpener = wf_Link('#', $icon . ' ' . $title, false, $linkCSSClass, 'id="' . $linkID . '"')
- . wf_JSAjaxModalOpener($ajaxURL, $ajaxDataArr, $linkID, true, $queryType, $jsEvent, $noPreventDefault, $noReturnFalse, $updNestedJQDT, $nestedJQDTSelector);
- return ($dynamicOpener);
- }
- /**
- * Inserts JS-code to process submitting of multiple dynamically or statically created MODAL FORMS via AJAX call
- * To work properly, requires wf_JSEmptyFunc() and wf_JSElemInsertedCatcherFunc() routines to be inserted on a page beforehand.
- * Also it's better to pass a JQUERY DataTable ID to be able to update a certain JQDT records
- *
- * @param string $submitFormClasses (need to be passed with leading dot, several classes may be passed )
- * @param string $submitFormIDCtrlClass (need to be passed with leading dot)
- * @param string $jqdtID
- * @param string $emptyValueCheckClasses (need to be passed with leading dot)
- * @param string $errorFormIDParamName
- *
- * @return string
- */
- function wf_jsAjaxFormSubmit($submitFormClasses, $submitFormIDCtrlClass, $jqdtID = '', $emptyValueCheckClasses = '', $errorFormIDParamName = '') {
- $result = '';
- $emptyValueCheckClasses = (empty($emptyValueCheckClasses) ? '__EmptyCheckControl' : $emptyValueCheckClasses);
- $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
- $errorModalWindowId = wf_InputId();
- $result .= '
- function checkEmptyVal(ctrlClassName) {
- $(document).on("focus keydown", ctrlClassName, function(evt) {
- $(document).find(ctrlClassName).each(function(indx, element){
- if ( $(element).hasClass(\'__MandatoryEmpty\') ) {
- $(element).val("");
- $(element).css("border-color", "");
- $(element).css("color", "");
- $(element).toggleClass(\'__MandatoryEmpty\');
- }
- });
- });
- }
-
- // for already inserted elements on page load
- checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
-
- // for newly inserted elements after page load
- onElementInserted(\'body\', \'' . $emptyValueCheckClasses . '\', function(element) {
- checkEmptyVal(\'' . $emptyValueCheckClasses . '\');
- });
-
- $(document).on("submit", "' . $submitFormClasses . '", function(evt) {
- evt.preventDefault();
- var emptyCheckClass = \'' . $emptyValueCheckClasses . '\';
- var mandatoryFldsEmpty = false;
-
- $(this).find(emptyCheckClass).each(function(indx, element){
- if ( empty($(element).val()) ) {
- $(element).css("border-color", "red");
- $(element).css("color", "grey");
- $(element).val("' . __('Mandatory field') . '");
- $(element).toggleClass(\'__MandatoryEmpty\');
-
- mandatoryFldsEmpty = true
- }
- });
-
- if (!mandatoryFldsEmpty) {
- var FrmAction = $(this).attr("action");
- var FrmData = $(this).serialize() + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\';
-
- $.ajax({
- type: "POST",
- url: FrmAction,
- data: FrmData,
- success: function(result) {
- if ( !empty(result) ) {
- $(document.body).append(result);
- $( \'#' . $errorModalWindowId . '\' ).dialog("open");
- } else {
- var customJQDTToReload = $(\'#closestJQDTID\').val();
- if (!empty(customJQDTToReload)) {
- $(\'#\' + customJQDTToReload).DataTable().ajax.reload();
- } else {
- ' . (empty($jqdtID) ? ' ' : '$(\'#' . $jqdtID . '\').DataTable().ajax.reload();') . '
- }
- $( \'#\' + $("' . $submitFormIDCtrlClass . '").val() ).dialog("close");
- }
- }
- });
- }
- });
-
- ';
- return ($result);
- }
- /**
- * Returns a simple wrapper for a JS function with ajax request which can be used later for multiple "callers"
- * e.g. - to delete record from DB or whatever
- *
- * @param $funcName
- * @param string $jqdtID
- * @param string $jqdtIDSelector
- * @param string $errorFormIDParamName
- * @param string $queryType
- * @param bool $jqdtClearBeforePaste
- *
- * @return string
- */
- function wf_jsAjaxCustomFunc($funcName, $jqdtID = '', $jqdtIDSelector = '', $errorFormIDParamName = '', $queryType = 'POST', $jqdtClearBeforePaste = false) {
- $errorFormIDParamName = (empty($errorFormIDParamName) ? 'errfrmid' : $errorFormIDParamName);
- $errorModalWindowId = wf_InputId();
- $jqdtReloadScript = '';
- $jqdtSelector = '';
- $result = '';
- if (!empty($jqdtID)) {
- $jqdtSelector = '$(\'#' . $jqdtID . '\')';
- } elseif (!empty($jqdtIDSelector)) {
- $jqdtSelector = '$(\'#\'+' . $jqdtIDSelector . ')';
- }
- if (!empty($jqdtSelector)) {
- if ($jqdtClearBeforePaste) {
- $jqdtReloadScript = '
- if ( !empty(reqResult) ) {
- var json = jQuery.parseJSON(reqResult);
- var table = ' . $jqdtSelector . '.DataTable();
- table.clear(); //clear the current data
- table.rows.add(json[\'aaData\']).draw();
- }
- ';
- } else {
- $jqdtReloadScript = '
- if ( !empty(reqResult) ) {
- $(document.body).append(reqResult);
- if ($(\'#' . $errorFormIDParamName . '\')) {
- $(\'#' . $errorFormIDParamName . '\').dialog("open");
- }
- }
-
- ' . $jqdtSelector . '.DataTable().ajax.reload();
- ';
- }
- }
- $result .= '
- function ' . $funcName . '(ajaxURL, ajaxData) {
- var ajaxData = ajaxData + \'&' . $errorFormIDParamName . '=' . $errorModalWindowId . '\'
- $.ajax({
- type: "' . $queryType . '",
- url: ajaxURL,
- data: ajaxData,
- success: function(reqResult) {
- '
- . $jqdtReloadScript .
- '}
- });
- }
-
- ';
- return ($result);
- }
- /**
- * JS snippet for a filtering form for JQDT. Needs a bit of specific handling
- *
- * @param $ajaxURLStr
- * @param $formID
- * @param $jqdtID
- *
- * @return string
- */
- function wf_jsAjaxFilterFormSubmit($ajaxURLStr, $formID, $jqdtID) {
- $result = '
- $(\'#' . $formID . '\').submit(function(evt) {
- evt.preventDefault();
-
- $.ajax({
- url: "' . $ajaxURLStr . '",
- type: "POST",
- data: $(\'#' . $formID . '\').serialize(),
- success: function(reqResult) {
- var json = jQuery.parseJSON(reqResult);
- var table = $(\'#' . $jqdtID . '\').DataTable();
- table.clear(); //clear the current data
- table.rows.add(json[\'aaData\']).draw();
- }
- });
- });
- ';
- return ($result);
- }
- /**
- * Returns a JS-snippet for a regular selector-control cascade filtering by pre-prepared data
- * The point is:
- * we have a hidden input with a predefined data, like:
- * valueInAboveLevelSelector1 => correspondingValueInChildSelector1
- * valueInAboveLevelSelector1 => correspondingValueInChildSelector2
- * valueInAboveLevelSelector1 => correspondingValueInChildSelector3
- * valueInAboveLevelSelector2 => correspondingValueInChildSelector1
- * valueInAboveLevelSelector2 => correspondingValueInChildSelector2
- * valueInAboveLevelSelector2 => correspondingValueInChildSelector3
- * valueInAboveLevelSelector2 => correspondingValueInChildSelector4
- * valueInAboveLevelSelectorN => correspondingValueInChildSelectorNN
- * ..................................................................
- *
- * When a user selects a value in AboveLevelSelector we take that array from hidden input and walk through it -
- * when we find a key equal to selected in AboveLevelSelector value - we take that element in a variable
- * to build a new contents for a child selector. And the same for each key which equals to selected from AboveLevelSelector value
- *
- *
- * @param string $webSelectorID
- * @param string $webSelectorIDToFilter
- * @param string $filterDataElemID
- * @param string $filterFuncName
- * @param bool $blankFirstRow
- * @param string $blankFirstRowVal
- * @param string $blankFirstRowDispVal
- *
- * @return string
- */
- /* function wf_jsWebSelectorFilter($webSelectorID, $webSelectorIDToFilter, $filterDataElemID,
- $webSelChangeFuncName = '', $filterFuncName = '',
- $blankFirstRow = false, $blankFirstRowVal = '0', $blankFirstRowDispVal = '----') {
- $webSelChangeFuncName = (empty($webSelChangeFuncName) ? 'funcChange_' . $webSelectorIDToFilter : $webSelChangeFuncName);
- $filterFuncName = (empty($filterFuncName) ? 'funcFilter_' . $webSelectorIDToFilter : $filterFuncName);
- $webSelectRunChange = (empty($webSelectorIDToFilter) ? "" : "$('#" . $webSelectorIDToFilter . "').change();");
- $firstRowBlank = ($blankFirstRow ? "var newselect = '<option value=\"" . $blankFirstRowVal . "\">" . $blankFirstRowDispVal . "</option>';" : "");
- */
- function wf_jsWebSelectorFilter() {
- $result = '
-
- function filterWebDropdown(search_keyword, filterListVals, webSelectRun2ChangeID,
- firstRowBlank = true, blankRowVal = "0", blankRowDispVal = "----") {
-
- if ( !empty(filterListVals.length) ) {
- var search_array = JSON.parse(atob(filterListVals));
- } else {
- return;
- }
-
- var newselect = "";
-
- if (firstRowBlank) {
- newselect = \'<option value="\' + blankRowVal + \'">\' + blankRowDispVal + \'</option>\';
- }
-
- if (search_keyword.length > 0 && search_keyword.trim() !== blankRowDispVal) {
- for (var key in search_array) {
- if ( key.trim() !== "" && key.toLowerCase() == search_keyword.toLowerCase() ) {
- var foundVal = search_array[key];
-
- for (var foundKey in foundVal) {
- var foundKeyVal = foundVal[foundKey];
- for (var dbID in foundKeyVal) {
- newselect = newselect + \'<option value="\' + dbID + \'">\' + foundKeyVal[dbID] + \'</option>\';
- }
- }
- }
- }
- }
-
- $(\'#\' + webSelectRun2ChangeID).html(newselect);
- $(\'#\' + webSelectRun2ChangeID).change();
- }
-
- ';
- return ($result);
- }
- /**
- * Simply encloses a JS snippet with a 'script' open/close tags
- *
- * @param string $content
- *
- * @return string
- */
- function wf_EncloseWithJSTags($content) {
- $result = wf_tag('script', false, '', 'type="text/javascript"');
- $result .= $content;
- $result .= wf_tag('script', true);
- return ($result);
- }
- /**
- * Generates tabbed UI for almost any data.
- *
- * @param $tabsDivID - ID of the main tab div
- * @param $tabsList - array of: tab ID => array('tab_options' => 'options',
- * 'tab_caption' => 'caption,
- * 'additional_data' => 'anything')
- * which represents the tabs itself.
- * Additional data can be anything, like some JS script or comments or whatever.
- * @param $tabsBody - array of: div ID => array('div_options' => 'options',
- * 'tab_body_data' => 'data'
- * 'additional_data' => 'anything')
- * which represents the divs with tabs data.
- * Additional data can be anything, like some JS script or comments or whatever.
- * @param string $mainDivOpts
- * @param string $ulOpts
- * @param bool $tabsCarouselOn
- *
- * @return string
- */
- function wf_TabsGen($tabsDivID, $tabsList, $tabsBody, $mainDivOpts = '', $ulOpts = '', $tabsCarouselOn = false) {
- $result = '';
- if (!empty($tabsDivID) and !empty($tabsList) and !empty($tabsBody)) {
- $divOps = 'id="' . $tabsDivID . '" ' . $mainDivOpts;
- $initTabsJSStr = '$( "#' . $tabsDivID . '" ).tabs();';
- if ($tabsCarouselOn) {
- $initTabsJSStr = '$("#' . $tabsDivID . '").scrollTabs({
- scrollOptions: {
- showFirstLastArrows: false,
- closable: false
- }
- });
-
- // dirty hack for scrollTabsPlugin to select the very first tab
- $( "#' . $tabsDivID . '" ).scrollTabs("option", "active", 0);
- // another hack for Firefox
- $(".ui-scroll-tabs-view").css("margin-bottom", "0");
- ';
- }
- $result .= wf_tag('script', false, '', 'type="text/javascript"');
- $result .= ' $( function() { ' .
- $initTabsJSStr .
- ' } );
- ';
- $result .= wf_tag('script', true);
- $result .= wf_tag('div', false, '', $divOps);
- $result .= wf_tag('ul', false, '', $ulOpts);
- foreach ($tabsList as $tabhref => $tabData) {
- $result .= wf_tag('li') .
- wf_tag('a', false, '', 'href="#' . $tabhref . '" ' . $tabData['options']) .
- $tabData['caption'] .
- wf_tag('a', true) .
- wf_tag('li', true) .
- $tabData['additional_data'];
- }
- $result .= wf_tag('ul', true);
- foreach ($tabsBody as $bodyID => $bodyData) {
- $result .= wf_tag('div', false, '', 'id="' . $bodyID . '" ' . $bodyData['options']) .
- $bodyData['body'] .
- wf_tag('div', true) .
- $bodyData['additional_data'];
- }
- $result .= wf_tag('div', true);
- }
- return ($result);
- }
- /**
- * Returns scripts and CSS links for tabs carousel plugin.
- * Be sure to add this once to a page if you planning to use wf_TabsGen function with tabsCarouselOn
- */
- function wf_TabsCarouselInitLinking() {
- $result = '<link rel="stylesheet" href="modules/jsc/JQUI_ScrollTabs/style.css" type="text/css">';
- $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ba-throttle-debounce.min.js"></script>';
- $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.mousewheel.min.js"></script>';
- $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.touchSwipe.min.js"></script>';
- $result .= '<script type="text/javascript" src="modules/jsc/JQUI_ScrollTabs/jquery.ui.scrolltabs.js"></script>';
- return ($result);
- }
- /**
- * Returns plain JS-code of 'empty' function to use for checking an empty value in JS code
- *
- * @return string
- */
- function wf_JSEmptyFunc() {
- $Result = '
- function empty (mixed_var) {
- // version: 909.322
- // discuss at: http://phpjs.org/functions/empty
-
- var key;
- if (mixed_var === "" || mixed_var === 0 || mixed_var === "0" || mixed_var === null || mixed_var === \'null\' || mixed_var === false || mixed_var === undefined || mixed_var === \'undefined\' ) {
- return true;
- }
-
- if (typeof mixed_var == \'object\') {
- for (key in mixed_var) {
- return false;
- }
- return true;
- }
- return false;
- }
-
- ';
- return ($Result);
- }
- /**
- * Returns some count of non-breaking space symbols
- *
- * @param int $count
- *
- * @return string
- */
- function wf_nbsp($count = 1) {
- $result = '';
- for ($i = 0; $i < $count; $i++) {
- $result .= ' ';
- }
- return ($result);
- }
- /**
- * Returns JS onElementInserted() func which allow to make any actions for
- * dynamically created objects right after the moment of it's creation
- * elementSelector MUST be a 'class' or 'id' selector, like '.SomeMyClass' or '#SomeMyID'
- *
- * This code and it's function call must exist on a page BEFORE dynamic elements loaded
- * The 'class' or 'id' selectors which will be used in dynamically loaded content
- * must be known BEFORE the content loaded - so avoid of generating some random IDs on-the-fly,
- * just when that content is loaded or in any other way
- *
- * DO NOT include this code or it's function call(like any other JS code)
- * to a dynamically loaded content - as it WON'T WORK that way
- *
- * Source code: https://stackoverflow.com/a/38517525
- *
- * @return string
- */
- function wf_JSElemInsertedCatcherFunc() {
- $Result = '
- function onElementInserted(containerSelector, elementSelector, callback) {
- var onMutationsObserved = function(mutations) {
- mutations.forEach(function(mutation) {
- if (mutation.addedNodes.length) {
- var foundElements = $(mutation.addedNodes).find(elementSelector);
-
- if (foundElements.length <= 0) {
- foundElements = $(mutation.addedNodes).closest(elementSelector);
- }
-
- for (var i = 0, len = foundElements.length; i < len; i++) {
- callback(foundElements[i]);
- }
- }
-
- if (mutation.type === \'attributes\' && ( (\'.\' + $(mutation.target).attr(\'class\') == elementSelector)
- || (\'#\' + $(mutation.target).attr(\'id\') == elementSelector) )) {
-
- callback(mutation.target);
- }
- });
- };
-
- var target = $(containerSelector)[0];
- var config = { childList: true, subtree: true, attributes: true, attributeFilter: ["id", "class"]};
- var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
- var observer = new MutationObserver(onMutationsObserved);
- observer.observe(target, config);
- }
-
- ';
- return $Result;
- }
- /**
- * Renders default steps-meter progressbar
- *
- * @param array $params as stepname=>decription
- * @param int $current
- *
- * @return type
- */
- function wf_StepsMeter($params, $current) {
- $style = wf_tag('style');
- $style .= "
- .steps{
- min-height:90px;
- padding:30px 30px 0 30px;
- position:relative
- }
-
- .steps .steps-container{
- background:#DDD;
- height:10px;
- width:95%;
-
- border-radius:10px ;
- -moz-border-radius:10px ;
- -webkit-border-radius:10px ;
- -ms-border-radius:10px ;
- margin:0;
- list-style:none
- }
-
- .steps .steps-container li{
- text-align:center;
- list-style:none;
- float:left
- }
-
- .steps .steps-container li .step{
- padding:0 50px
- }
-
- .steps .steps-container li .step .step-image{
- margin:-14px 0 0 0
- }
-
- .steps .steps-container li .step .step-image span{
- background-color:#DDD;
- display:block;
- width:37px;
- height:37px;
- margin:0 auto;
- border-radius:37px ;
- -moz-border-radius:37px ;
- -webkit-border-radius:37px ;
- -ms-border-radius:37px
- }
-
- .steps .steps-container li .step .step-current{
- font-size:11px;
- font-style:italic;
- color:#999;
- margin:8px 0 0 0
- }
-
- .steps .steps-container li .step .step-description{
- font-size:13px;
- font-style:italic;
- color:#538897
- }
-
- .steps .steps-container li.activated .step .step-image span{
- background-color:#5DC177
- }
-
- .steps .steps-container li.activated .step .step-image span:after{
- background-color:#FFF;
- display:block;
- content:'';
- position:absolute;
- z-index:1;
- width:27px;
- height:27px;
- margin:5px;
- border-radius:27px ;
- -moz-border-radius:27px ;
- -webkit-border-radius:27px ;
- -ms-border-radius:27px ;
- box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
- -moz-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15) ;
- -webkit-box-shadow: 4px 4px 0px 0px rgba(0,0,0,0.15)
- }
-
- .steps .step-bar{
- background-color:#5DC177;
- height:10px;
- position:absolute;
- top:30px;
- border-radius:10px 0 0 10px;
- -moz-border-radius:10px 0 0 10px;
- -webkit-border-radius:10px 0 0 10px;
- -ms-border-radius:10px 0 0 10px
- }
-
- .steps .step-bar.last{
- border-radius:10px ;
- -moz-border-radius:10px ;
- -webkit-border-radius:10px ;
- -ms-border-radius:10px
- }
- ";
- $style .= wf_tag('style', true);
- $count = 1;
- $paramsCount = sizeof($params);
- if (!empty($params)) {
- $width = round(100 / $paramsCount) - 1;
- $code = wf_tag('div', false, 'steps');
- $code .= wf_tag('ul', false, 'steps-container');
- foreach ($params as $io => $each) {
- $currentClass = ($count <= $current) ? 'activated' : '';
- $code .= wf_tag('li', false, $currentClass, 'style="width:' . $width . '%;"');
- $code .= wf_tag('div', false, 'step');
- $code .= wf_tag('div', false, 'step-image') . wf_tag('span') . wf_tag('span', true) . wf_tag('div', true);
- $code .= wf_tag('div', false, 'step-current') . $io . wf_tag('div', true);
- $code .= wf_tag('div', false, 'step-description') . $each . wf_tag('div', true);
- $code .= wf_tag('div', true);
- $code .= wf_tag('li', true);
- $count++;
- }
- $code .= wf_tag('ul', true);
- $widthBar = $width * $current;
- $code .= wf_tag('div', false, 'step-bar', 'style="width: ' . $widthBar . '%;"') . wf_tag('div', true);
- $code .= wf_tag('div', true);
- $code .= wf_CleanDiv();
- $result = $style . $code;
- }
- return ($result);
- }
- /**
- * Returns confirmation dialog to navigate to some URL
- *
- * @param string $url
- * @param string $title
- * @param string $alerttext
- * @param string $class
- * @param string $cancelUrl
- * @param string $customDialogTitle
- *
- * @return string
- */
- function wf_ConfirmDialog($url, $title, $alerttext, $class = '', $cancelUrl = '', $customWindowTitle = '') {
- $result = '';
- $dialog = __($alerttext);
- $dialog .= wf_tag('br');
- $dialog .= wf_tag('center', false);
- $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree');
- if ($cancelUrl) {
- $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel');
- }
- $dialog .= wf_tag('center', true);
- $cleanTitle = strip_tags($title);
- if ($customWindowTitle) {
- $cleanTitle = $customWindowTitle;
- }
- $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class);
- return ($result);
- }
- /**
- * Returns confirmation dialog to navigate to some URL
- *
- * @param string $url
- * @param string $title
- * @param string $alerttext
- * @param string $class
- * @param string $cancelUrl
- * @param string $funcRunAgree
- * @param string $funcRunCancel
- * @param string $modalWinID
- *
- * @return string
- */
- function wf_ConfirmDialogJS($url, $title, $alerttext, $class = '', $cancelUrl = '', $funcRunAgree = '', $funcRunCancel = '', $modalWinID = '') {
- $result = '';
- $modalWinID = (empty($modalWinID) ? 'dialog-modal_' . wf_InputId() : $modalWinID);
- $funcRunAgree = (empty($funcRunAgree) ? '' : ' onclick="' . $funcRunAgree . '; return false; "');
- $funcRunCancel = (empty($funcRunCancel) ? '' : ' onclick="' . $funcRunCancel . '; return false; "');
- $dialog = __($alerttext);
- $dialog .= wf_tag('br');
- $dialog .= wf_tag('center', false);
- $dialog .= wf_Link($url, __('Agree'), false, 'confirmagree', $funcRunAgree);
- if (!empty($cancelUrl) or !empty($funcRunCancel)) {
- $dialog .= wf_Link($cancelUrl, __('Cancel'), false, 'confirmcancel', $funcRunCancel);
- }
- $dialog .= wf_tag('center', true);
- $cleanTitle = strip_tags($title);
- $result .= wf_modalAuto($title, __($cleanTitle), $dialog, $class, $modalWinID);
- return ($result);
- }
- /**
- * Returns code that plays some sound from existing audio file
- *
- * @param string $url
- *
- * @return string
- */
- function wf_doSound($url) {
- $result = wf_tag('script') . "var audio = new Audio('" . $url . "'); audio.play();" . wf_tag('script', true);
- return ($result);
- }
- /**
- * Renders temperature gauge
- *
- * @param float $temperature
- * @param string $title
- * @param string $options
- *
- * @return string
- */
- function wf_renderTemperature($temperature, $title = '', $options = '') {
- $result = '';
- if (empty($options)) {
- $options = ' max: 100,
- min: 0,
- width: 280, height: 280,
- greenFrom: 10, greenTo: 60,
- yellowFrom:60, yellowTo: 70,
- redFrom: 70, redTo: 100,
- minorTicks: 5';
- }
- $result = wf_renderGauge($temperature, $title, '°C', $options);
- return ($result);
- }
- /**
- * Renders generic gauge
- *
- * @param float $value
- * @param string $title
- * @param string $units
- * @param string $options
- * @param int $size
- *
- * @return string
- */
- function wf_renderGauge($value, $title = '', $units = '', $options = '', $size = 300) {
- $result = '';
- $gaugeId = wf_InputId();
- $sizeContainer = $size;
- $sizeContent = $sizeContainer - 20;
- if (empty($options)) {
- $options = ' max: 100,
- min: 0,
- width: ' . $sizeContent . ', height: ' . $sizeContent . ',
- greenFrom: 10, greenTo: 60,
- yellowFrom:60, yellowTo: 70,
- redFrom: 70, redTo: 100,
- minorTicks: 5';
- }
- $containerStyle = 'width: ' . $sizeContainer . 'px; height: ' . $sizeContainer . 'px; float:left; ';
- $result .= wf_tag('div', false, '', 'style="' . $containerStyle . '"');
- $result .= wf_tag('div', false, '', 'id="gengauge_div' . $gaugeId . '"');
- $result .= wf_tag('div', true);
- $result .= wf_tag('center') . wf_tag('b') . $title . wf_tag('b', true) . wf_tag('center', true);
- $result .= wf_tag('div', true);
- $result .= wf_tag('script', false, '', 'type="text/javascript" src="https://www.gstatic.com/charts/loader.js"') . wf_tag('script', true);
- $result .= wf_tag('script');
- $result .= 'google.charts.load(\'current\', {\'packages\':[\'gauge\']});
- google.charts.setOnLoadCallback(drawChart);
- function drawChart() {
- var data = google.visualization.arrayToDataTable([
- [\'Label\', \'Value\'],
- [\'' . $units . '\', ' . $value . ']
- ]);
- var options = {
- ' . $options . '
- };
- var chart = new google.visualization.Gauge(document.getElementById(\'gengauge_div' . $gaugeId . '\'));
- chart.draw(data, options);
-
- } ';
- $result .= wf_tag('script', true);
- return ($result);
- }
- /**
- * Returns simple pre-formatted date-or-time range picker.
- * For example - for filtering form.
- *
- * @param bool $inTable
- * @param bool $tableCellsOnly
- * @param bool $tableRowsOnly
- * @param bool $vertical
- * @param bool $dateIsON
- * @param bool $timeIsON
- * @param string $dateStart
- * @param string $dateEnd
- * @param string $dpStartInpName
- * @param string $dpEndInpName
- * @param string $timeStart
- * @param string $timeEnd
- * @param string $tpStartInpName
- * @param string $tpEndInpName
- *
- * @return string
- */
- function wf_DatesTimesRangeFilter(
- $inTable = true,
- $tableCellsOnly = false,
- $tableRowsOnly = false,
- $vertical = false,
- $dateIsON = true,
- $timeIsON = false,
- $dateStart = '',
- $dateEnd = '',
- $dpStartInpName = '',
- $dpEndInpName = '',
- $timeStart = '',
- $timeEnd = '',
- $tpStartInpName = '',
- $tpEndInpName = ''
- ) {
- $inputs = '';
- $cells = '';
- $rows = '';
- $datepickerStart = '';
- $datepickerEnd = '';
- $datepickerStartCapt = '';
- $datepickerEndCapt = '';
- $timepickerStart = '';
- $timepickerEnd = '';
- $timepickerStartCapt = '';
- $timepickerEndCapt = '';
- if ($dateIsON) {
- $dpStartInpName = (empty($dpStartInpName) ? 'datestartfilter' : $dpStartInpName);
- $dpEndInpName = (empty($dpEndInpName) ? 'dateendfilter' : $dpEndInpName);
- $datepickerStart = wf_DatePickerPreset($dpStartInpName, $dateStart, true);
- $datepickerEnd = wf_DatePickerPreset($dpEndInpName, $dateEnd, true);
- $datepickerStartCapt = __('Date from') . ':';
- $datepickerEndCapt = __('Date to') . ':';
- }
- if ($timeIsON) {
- $tpStartInpName = (empty($tpStartInpName) ? 'timestartfilter' : $tpStartInpName);
- $tpEndInpName = (empty($tpEndInpName) ? 'timeendfilter' : $tpEndInpName);
- $timepickerStart = wf_TimePickerPreset($tpStartInpName, $timeStart);
- $timepickerEnd = wf_TimePickerPreset($tpEndInpName, $timeEnd);
- $timepickerStartCapt = __('Time from') . ':';
- $timepickerEndCapt = __('Time to') . ':';
- }
- if ($inTable) {
- if ($dateIsON) {
- $cells .= wf_TableCell($datepickerStartCapt);
- $cells .= wf_TableCell($datepickerStart);
- }
- if ($timeIsON) {
- if ($dateIsON) {
- $cells .= wf_nbsp(4);
- }
- $cells .= wf_TableCell($timepickerStartCapt);
- $cells .= wf_TableCell($timepickerStart);
- }
- if ($vertical) {
- $rows = wf_TableRow($cells);
- $cells = '';
- } else {
- $cells .= wf_TableCell(wf_nbsp(2));
- }
- if ($dateIsON) {
- $cells .= wf_TableCell($datepickerEndCapt);
- $cells .= wf_TableCell($datepickerEnd);
- }
- if ($timeIsON) {
- if ($dateIsON) {
- $cells .= wf_nbsp(4);
- }
- $cells .= wf_TableCell($timepickerEndCapt);
- $cells .= wf_TableCell($timepickerEnd);
- }
- if ($tableCellsOnly) {
- $inputs = $cells;
- } elseif ($tableRowsOnly) {
- $rows .= wf_TableRow($cells);
- $inputs = $rows;
- } else {
- $rows .= wf_TableRow($cells);
- $inputs = wf_TableBody($rows, 'auto', '0', '', '');
- }
- } else {
- if ($dateIsON) {
- $inputs .= $datepickerStartCapt . wf_nbsp(2) . $datepickerStart;
- }
- if ($timeIsON) {
- if ($dateIsON) {
- $inputs .= wf_nbsp(4);
- }
- $inputs .= $timepickerStartCapt . wf_nbsp(2) . $timepickerStart;
- }
- if ($vertical) {
- $inputs .= wf_delimiter();
- } else {
- $inputs .= wf_nbsp(8);
- }
- if ($dateIsON) {
- $inputs .= $datepickerEndCapt . wf_nbsp(2) . $datepickerEnd;
- }
- if ($timeIsON) {
- if ($dateIsON) {
- $inputs .= wf_nbsp(4);
- }
- $inputs .= $timepickerEndCapt . wf_nbsp(2) . $timepickerEnd;
- }
- }
- return ($inputs);
- }
- /**
- * Returns select2 searchable input widget
- *
- * @param string $name
- * @param array $params
- * @param string $label
- * @param string $selected
- * @param bool $br
- * @param string $options
- *
- * @return string
- */
- function wf_SelectorSearchable($name, $params, $label, $selected = '', $br = false, $options = '') {
- $result = '';
- $inputId = wf_InputId();
- $ctrlClass = 'select2_' . $inputId;
- $curLang = curlang();
- $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
- $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
- $initCode .= wf_tag('script', true);
- $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
- $initCode .= wf_tag('script', true);
- $initCode .= wf_tag('script');
- $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
- $initCode .= wf_tag('script', true);
- $result .= $initCode;
- $result .= wf_Selector($name, $params, $label, $selected, $br, false, '', $ctrlClass, $options);
- return ($result);
- }
- /**
- * Returns select2 searchable input widget with auto-submit function
- *
- * @param string $name
- * @param array $params
- * @param string $label
- * @param string $selected
- * @param bool $br
- * @param string $options
- *
- * @return string
- */
- function wf_SelectorSearchableAC($name, $params, $label, $selected = '', $br = false) {
- $options = 'onChange="this.form.submit();"';
- $result = wf_SelectorSearchable($name, $params, $label, $selected, $br, $options);
- return ($result);
- }
- /**
- * Return select2 Web From element with auto click option into ajax container
- *
- * @param string $container name of container element
- * @param array $params array of elements $url=>$option
- * @param string $label text label for input
- * @param string $selected selected $value for selector
- * @param bool $br append new line
- * @param string $options some raw custom options
- *
- * @return string
- *
- */
- function wf_AjaxSelectorSearchableAC($container, $params, $label, $selected = '', $br = false, $options = '') {
- $inputid = wf_InputId();
- $result = '';
- $inputId = wf_InputId();
- $ctrlClass = 'select2_' . $inputId;
- $curLang = curlang();
- $newline = ($br) ? wf_tag('br') : '';
- $initCode = '<link href="modules/jsc/select2/css/select2.css" rel="stylesheet" />';
- $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/select2.min.js"');
- $initCode .= wf_tag('script', true);
- $initCode .= wf_tag('script', false, '', 'src="modules/jsc/select2/js/i18n/' . $curLang . '.js"');
- $initCode .= wf_tag('script', true);
- $initCode .= wf_tag('script');
- $initCode .= '$(document).ready(function() { $(".' . $ctrlClass . '").select2(); });';
- $initCode .= wf_tag('script', true);
- $result .= $initCode;
- $selectorOptions = 'name="' . $inputid . '" id="' . $inputid . '" onChange="this.options[this.selectedIndex].onclick();" ' . $options;
- $result .= wf_tag('select', false, $ctrlClass, $selectorOptions);
- if (!empty($params)) {
- foreach ($params as $value => $eachparam) {
- $sel_flag = ($selected == $value) ? 'SELECTED' : '';
- $optionSpec = 'value="' . $value . '" ' . $sel_flag . ' onclick="goajax(\'' . $value . '\',\'' . $container . '\');"';
- $result .= wf_tag('option', false, '', $optionSpec) . $eachparam . wf_tag('option', true);
- }
- }
- $result .= wf_tag('select', true);
- if (!empty($label)) {
- $result .= wf_tag('label', false, '', 'for="' . $inputid . '"');
- $result .= __($label);
- $result .= wf_tag('label', true);
- }
- $result .= $newline;
- return ($result);
- }
- /**
- * Generates HTML and JavaScript for a show/hide toggle functionality.
- *
- * This function creates a clickable element that toggles the visibility of a content section.
- * It uses jQuery for the toggle effect and updates the clickable element's label based on the visibility state.
- *
- * @param string $content The content to be shown or hidden.
- * @param string $title The title to be displayed on the toggle element. Default is an empty string.
- * @param string $class Additional CSS class to be applied to the outer span. Default is an empty string.
- *
- * @return string
- */
- function wf_ShowHide($content, $title = '', $class = '') {
- $result = '';
- $inputId = 'showhide' . wf_InputId();
- $contentId = 'content' . wf_InputId();
- $labelShow = wf_img_sized('skins/icon_visible.png', $title, 12) . ' ' . __($title) . ' ';
- $labelHide = wf_img_sized('skins/icon_hidden.png', '', 12) . ' ';
- $result .= wf_tag('span', false, $class);
- $result .= wf_tag('span', false, '', 'id="' . $inputId . '"');
- $result .= $labelShow;
- $result .= wf_tag('span', true);
- $result .= wf_tag('span', false, '', 'id="' . $contentId . '" style="display:none;"');
- $result .= $content;
- $result .= wf_tag('span', true);
- $result .= wf_tag('span', true);
- $result .= wf_tag('script');
- $result .= '
- $( "#' . $inputId . '" ).on( "click", function() {
- $( "#' . $contentId . '" ).toggle( "fast", function() {
- $("#' . $inputId . '").html(\'' . $labelHide . '\');
- });
- });
-
- $( "#' . $contentId . '" ).on( "click", function() {
- $( "#' . $contentId . '" ).toggle( "fast", function() {
- $("#' . $inputId . '").html(\'' . $labelShow . '\');
- });
- });
- ';
- $result .= wf_tag('script', true);
- return ($result);
- }
- /**
- * JQuery Data Tables JSON formatting class
- */
- class wf_JqDtHelper {
- /**
- * Contains raw array of added grid elements
- *
- * @var array
- */
- protected $allRows = array();
- /**
- * Adds new row to elements array, dont forget unset() data in your loop, after adding new row.
- *
- * @param array $data
- *
- * @return void
- */
- public function addRow($data) {
- if (!empty($data)) {
- $jsonItem = array();
- foreach ($data as $io => $each) {
- $jsonItem[] = $each;
- }
- $this->allRows[] = $jsonItem;
- }
- }
- /**
- * Returns JSON acceptible for jquery data tables
- *
- * @return string
- */
- protected function renderJson() {
- $result = array("aaData" => $this->allRows);
- $result = json_encode($result);
- return ($result);
- }
- /**
- * Renders empty page JSON data for background ajax requests
- *
- * @return void
- */
- public function getJson() {
- die($this->renderJson());
- }
- /**
- * Extracts rendered JSON data from object
- *
- * @return string
- */
- public function extractJson() {
- return ($this->renderJson());
- }
- /**
- * Flushes current object instance elements array
- *
- * @return void
- */
- public function flushData() {
- $this->allRows = array();
- }
- }
|