123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796 |
- <?php
- # 此类很大,以后优化,放到Database目录中,拆分为工厂模式
- # 必须要优化了...当时为了快速实现直接扔这一个里面了,近期优化
- namespace Manage\Src;
- use Dever;
- use Manage\Src\Lib\Input as Html;
- use Manage\Src\Lib\Log;
- class Database
- {
- /**
- * project
- *
- * @var string
- */
- private $project;
- /**
- * table
- *
- * @var string
- */
- private $table;
- /**
- * param
- *
- * @var array
- */
- private $param = array();
- /**
- * parent
- *
- * @var array
- */
- private $parent = array();
- /**
- * menu
- *
- * @var string
- */
- private $menu;
- /**
- * menu_id
- *
- * @var string
- */
- private $menu_id;
- /**
- * id
- *
- * @var string
- */
- private $id;
- /**
- * config
- *
- * @var array
- */
- private $config;
- /**
- * search
- *
- * @var bool
- */
- private $search = false;
- /**
- * chart
- *
- * @var array
- */
- private $chart = false;
- /**
- * manage_button
- *
- * @var array
- */
- private $manage_button = false;
- /**
- * info
- *
- * @var array
- */
- private $info = array();
- /**
- * state
- *
- * @var array
- */
- private $state = false;
- /**
- * lang_set
- *
- * @var array
- */
- private $lang_set = false;
- /**
- * __construct
- *
- * @return mixed
- */
- public function __construct()
- {
- $this->setting();
- $this->top = Dever::input('top');
- if ($this->top) {
- Dever::load('manage/top.update_action', $this->top);
- }
- $this->lang_set = Dever::config('base')->lang_set && count(Dever::config('base')->lang_set) > 1;
- }
- public function setting()
- {
- $this->project = Dever::input('project');
- $this->table = Dever::input('table');
- $this->menu = Dever::input('menu');
- $this->menu_id = Dever::input('menu_id');
- $this->id = Dever::input('update_where_id', Dever::input('where_id'));
- $this->name = $this->project . '/' . $this->table;
- #alias=goods_marea
- $alias = Dever::input('alias');
- if ($alias) {
- $temp = explode('_', $alias);
- $alias = Dever::config('base', $temp[0])->alias;
- if ($alias && isset($alias[$this->project])) {
- Dever::setAlias($this->project, $temp[1]);
- }
- } else {
- $alias = Dever::config('base', $this->project)->alias;
- if ($alias) {
- Dever::config('base')->alias = $alias;
- }
- }
- return $this;
- }
- /**
- * 提供给异步获取数据的接口
- *
- * @return array
- */
- public function getAjax($data)
- {
- $key = Dever::input('key');
- $value = Dever::input('value');
- $source = Dever::input('source');
-
- $config = Dever::db($source)->config['struct'][$key];
- $config['value'] = $value;
- $config['option'] = $data;
- return $this->create_update_html($key, $config);
- }
- /**
- * url
- *
- * @return array
- */
- public function url($key = false, $id = 0, $table = false, $suffix = '', $project = '', $param = array())
- {
- $table = $table ? $table : $this->table;
- $project = $project ? $project : $this->project;
- if (strpos($table, 'http://') !== false || strpos($table, 'javascript') !== false) {
- return $table;
- }
- if ($id) {
- $id = '&where_id=' . $id;
- }
- $config = array
- (
- 'project' => 'project/database?project=' . $project,
- 'list' => 'project/database/list?{param}',
- 'search' => 'project/database/list?{param}',
- 'add' => 'project/database/update?{param}',
- 'update' => 'project/database/update?{param}' . $id,
- # 增加快捷更新
- 'edit' => 'project/database/update?{param}' . $id,
- 'updateAction' => 'database.update_action_commit',
- 'url' => '',
- 'delete' => 'database.delete_action?{param}' . $id,
- 'recovery' => 'database.recovery_action?{param}' . $id,
- 'stat' => 'project/database/stat?{param}',
- 'excel' => 'database.list_excel?{param}',
- 'stat_excel' => 'database.stat_excel?{param}',
- 'reset' => 'project/database/list?project=' . $project . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id,
- 'diy' => 'list?{param}',
- );
- $state = $this->getState();
- if ($key == 'delete' && $state == 2) {
- $key = 'recovery';
- }
- if (strpos($key, 'list') !== false) {
- $config[$key] = $config['list'];
- } elseif (strpos($key, 'add') !== false) {
- $config[$key] = $config['add'];
- } elseif (strpos($key, 'edit') !== false) {
- $config[$key] = $config['edit'];
- }
- if (isset($config[$key])) {
- if (strpos($config[$key], '{param}')) {
- $param = $this->getUrlParam($key, $table, $suffix, $state, $project, $param);
- $config[$key] = str_replace('{param}', $param, $config[$key]);
- }
- return Dever::url($config[$key]);
- }
- return $config;
- }
- /**
- * 获取url需要的参数
- *
- * @return string
- */
- private function getUrlParam($key, $table, $suffix, $state, $project = '', $input = array())
- {
- $this->param = array();
- if (!$this->param) {
- if ($key != 'listParent') {
- if ($where = Dever::preInput('search_', $input)) {
- unset($where['search_option_state']);
- $this->param += $where;
- }
- }
- /*
- if ($where = Dever::preInput('oper_', $input)) {
- $this->param += $where;
- }
- */
- if ($where = Dever::preInput('set_', $input)) {
- $this->param += $where;
- }
- /*
- if ($search_limit = Dever::input('search_limit')) {
- $this->param['search_limit'] = $search_limit;
- }*/
- if ($page_type = Dever::input('page_type')) {
- $this->param['page_type'] = $page_type;
- }
- if ($state) {
- $this->param['search_option_state'] = $state;
- }
- $alias = Dever::input('alias');
- if ($alias) {
- $this->param['alias'] = $alias;
- }
- $this->param['menu'] = $this->menu;
- $this->param['menu_id'] = $this->menu_id;
- $this->parent();
- }
- $param = $this->param;
- if ($this->parent) {
- if ($key == 'listParent') {
- $parent = $this->parent['parent'];
- if ($this->parent['project']) {
- $project = $this->parent['project'];
- }
- $table = $this->parent['table'];
- } else {
- $parent = $this->parent['link'];
- }
- if (strstr($parent, '=')) {
- parse_str($parent, $array);
- $param = array_merge($this->param, $array);
- } else {
- $param['parent'] = $parent;
- }
- }
- $param['project'] = $project;
- $param['table'] = $table;
- if (strstr($table, '&')) {
- $temp = explode('&', $table, 2);
- $param['table'] = $temp[0];
- parse_str($temp[1], $array);
- $param = array_merge($param, $array);
- }
- if ($suffix) {
- parse_str($suffix, $array);
- $param = array_merge($param, $array);
- }
-
- return urldecode(http_build_query($param));
- }
- private function parent()
- {
- $this->parent = array();
- $parent = Dever::input('parent');
- if ($parent) {
- $this->parent['project'] = '';
- $this->parent['link'] = $parent;
- $parent = explode('.', $parent);
- $cur = array_pop($parent);
- if ($cur && strstr($cur, '/')) {
- $temp = explode('/', $cur);
- $cur = $temp[1];
- $this->parent['project'] = $temp[0];
- }
- $this->parent['parent'] = implode('.', $parent);
- $this->parent['table'] = $cur;
- } else {
- # 此处为了兼容旧版本的一些设置 这里后续废弃
- $parent = Dever::input('oper_table', Dever::input('oper_parent'));
- if ($parent) {
- $link = '';
- $this->parent['link'] = 'oper_table=' . $parent;
- $this->parent['table'] = $parent;
- $this->parent['project'] = Dever::input('oper_project');
- $top = Dever::preInput('top_');
- if ($top) {
- $top_query = http_build_query($top);
- $this->parent['link'] .= '&' . $top_query;
- if (strstr($top_query, '.')) {
- foreach ($top as $k => $v) {
- $temp = explode('.', $v);
- $k = str_replace('top_', '', $k);
- $link .= '&oper_' . $k . '=' . $temp[0];
- if (isset($temp[1])) {
- $link .= '&top_' . $k . '=' . $temp[1];
- }
- }
- } else {
- $link .= '&' . str_replace('top_', 'oper_', $top_query);
- }
- }
- $this->parent['parent'] = $link;
- }
- }
- }
- /**
- * 获得refer
- *
- * @return string
- */
- private function refer($type = 'project')
- {
- return '';
- switch ($type) {
- case 'project':
- $name = '数据库操作';
- break;
- case 'list':
- $name = '数据列表';
- break;
- case 'url':
- $name = '项目列表';
- break;
- }
- $name = '返回上一级';
- $url = $this->url($type);
- $refer = '-[<a href="' . $url . '">' . $name . '</a>]';
- return $refer;
- }
- /**
- * getAdminInfo
- *
- * @return array
- */
- private function getAdminInfo($data)
- {
- $admin = Dever::load('manage/auth.info');
- $data['my_admin_id'] = $admin['id'];
- $data['my_role_id'] = $admin['role'];
- return $data;
- }
- /**
- * cookie 处理cookie
- *
- * @return array
- */
- public function cookie()
- {
- $cookie = $_COOKIE;
- $array = array();
- # 判断手机版
- $mobile = Dever::mobile();
- if ((isset($cookie['left_menu']) && $cookie['left_menu'] == 'close') || $mobile) {
- $array['wrapper'] = 'enlarged forced';
- } else {
- $array['wrapper'] = 'forced';
- }
- return $array;
- }
- /**
- * listStyle
- *
- * @return array
- */
- public function listStyle()
- {
- $mobile = Dever::mobile();
- if ($mobile) {
- $style = '.container_list .panel-heading .form-control,#mul .form-control,#page .form-control
- {
- width:70%;
- }
- .row
- {
- margin-right: -15px;
- margin-left: -15px;
- }
- #dever_modal_body img
- {
- max-width:300px;
- }
- ';
- } else {
- $style = '#dever_modal_body img
- {
- max-width:300px;
- }';
- }
- return $style;
- }
- /**
- * info 处理一些基本的信息,供模板使用
- *
- * @return array
- */
- public function info()
- {
- if ($this->info) {
- return $this->info;
- }
- $config = $this->config();
- $menu = isset($config['lang']) ? $config['lang'] : $this->project . '-' . $this->table;
- if (isset($config['state']) && $config['state'] == 2) {
- $menu .= '[回收站]';
- }
- $top = Dever::load('manage/top.get');
- //print_r($top);die;
- $this->info = array
- (
- 'action' => $this->url('updateAction'),
- 'list' => $this->url('list'),
- 'search' => $this->url('search'),
- 'mul' => $this->url('list'),
- //'add' => 'location.href=\'' . $this->url('add') . '\'',
- 'add' => $this->url('add'),
- 'state' => $this->getState(),
- 'l' => 'project/database/list',
- 'project' => $this->project,
- 'table' => $this->table,
- 'menu' => $this->menu,
- 'menu_id' => $this->menu_id,
- 'id' => $this->id,
- 'main' => '数据管理' . $this->refer('url'),
- 'list_header' => $menu,
- 'list_desc' => '数据列表',
- 'project_name' => Dever::load('manage/project.name', $this->project),
- 'update_header' => $menu,
- 'update_desc' => '更新数据',
- 'updateMul' => (!$this->id && isset($config['manage']['updateMul']) && $config['manage']['updateMul']) ? '增加一条' : false,
- 'updateDesc' => isset($config['manage']['desc']) ? $config['manage']['desc'] : '',
- 'listInfo' => isset($config['info']) ? $config['info'] : '',
- 'listDesc' => isset($config['desc']) ? $config['desc'] : '',
- 'struct' => isset($config['manage']['struct']) ? $config['manage']['struct'] : '',
- 'stat_desc' => '主动统计',
- 'search_param' => '',
- 'parent' => '',
- 'parent_value' => Dever::input('parent'),
- 'alias' => Dever::input('alias'),
- 'mul_ids' => Dever::input('mul_ids'),
- 'mul_load' => Dever::input('mul_load'),
- );
- if ($this->parent) {
- $this->info['parent'] = $this->url(Dever::input('parent_link', 'listParent'));
- }
- $this->info['submit'] = $this->info['parent'] ? $this->info['parent'] : $this->info['list'];
-
- # 保存页面
- $this->info['save'] = Dever::input('oper_save_table', Dever::input('oper_save_jump'));
- if ($this->info['save']) {
- $this->info['save_project'] = Dever::input('oper_save_project');
- $this->info['list'] = $this->url(Dever::input('oper_index', 'list'), 0, $this->info['save'], '', $this->info['save_project']);
- }
- $search = Dever::preInput('search_');
- if ($search) {
- $this->info['mul'] .= '&' . http_build_query($search);
- if (layadmin()) {
- foreach ($search as $k => $v) {
- if (!strstr($k, 'search_option_')) {
- if (is_array($v)) {
- $v = implode(',', $v);
- }
- $this->info['search_param'] .= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
- }
- }
- }
- }
- $search = Dever::preInput('set_');
- if ($search) {
- $this->info['mul'] .= '&' . http_build_query($search);
- if (layadmin()) {
- foreach ($search as $k => $v) {
- if (is_array($v)) {
- $v = implode(',', $v);
- }
- $this->info['search_param'] .= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
- }
- }
- }
- if ($this->id) {
- $this->info['update_header'] = $menu . '-更新数据' . $this->refer('list');
- }
- return $this->info;
- }
- /**
- * 获取表名
- *
- * @return array
- */
- public function getTableName($project, $table)
- {
- if ($project == 'other') {
- return '无数据表';
- }
- $path = Dever::load('manage/project.path', $project);
- $config = $this->config($project, $path, $table);
- $data = isset($config['lang']) ? $config['lang'] : $project;
- return $data;
- }
- private function getState()
- {
- return Dever::input('search_option_state', 1);
- }
- /**
- * config
- *
- * @return array
- */
- public function config($project = false, $path = false, $table = false)
- {
- if (!$project) {
- $project = $this->project;
- $table = $this->table;
- }
- if (!$project) {
- return array();
- }
- Dever::$global['manage']['project'] = $project;
- $config = Dever::load('manage/project.config', $project);
- if (!is_array($config)) {
- Dever::alert($project . ' error');
- }
- $project = $config['name'];
- if (!$path) {
- if (isset($config['base']) && isset($config['rel'])) {
- $path = DEVER_INCLUDE_PATH . $config['rel'];
- } else {
- $path = $config['path'];
- }
- }
- if ($project && $path && empty($this->config[$path])) {
- $this->config[$path] = array();
- $dir = $path . 'database/';
- if (is_dir($dir)) {
- $database = scandir($dir);
- foreach ($database as $k => $v) {
- if (strpos($v, '.php') !== false) {
- $k = str_replace('.php', '', $v);
- $this->config[$path][$k] = $this->struct($dir . $v, $project);
- }
- }
- }
- }
- if (isset($this->config[$path][$table])) {
- return $this->config[$path][$table];
- }
- return $this->config[$path];
- }
- # 得到重写的配置
- public function getConfig()
- {
- $config = $this->config();
- if (!isset($config['info'])) {
- $config['info'] = '';
- }
- if (!isset($config['desc'])) {
- $config['desc'] = '';
- }
- $manage = Dever::config('base')->manage;
- if ($manage) {
- if (isset($manage['info'])) {
- $config['info'] = $manage['info'];
- }
- if (isset($manage['desc'])) {
- $config['desc'] = $manage['desc'];
- }
- }
- return $config;
- }
- /**
- * 对database配置文件进行解析
- *
- * @return array
- */
- private function struct($file, $project = false)
- {
- $config = include $file;
- if (isset($config['struct']) && is_array($config['struct']['id'])) {
- $config['update'] = false;
- $config['manage']['struct'] = '<table border=1 width=100% height=100%>';
- $config['level'] = 1;
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['level'])) {
- $config['level'] = 3;
- }
- if (isset($v['search_parent'])) {
- $config['manage']['search_parent'][$v['search_parent']] = $k;
- $config['manage']['search_child'][$k] = $v['search_parent'];
- }
- if (!isset($config['search'])) {
- if (isset($v['search_name'])) {
- $v['name'] = $v['search_name'];
- }
- if (isset($v['search']) && is_string($v['search'])) {
- if ($v['search'] == 'sday') {
- $config['manage']['search']['sday'][$k]['key'] = $v['search'];
- $config['manage']['search']['sday'][$k]['lang'] = $v['name'];
- } elseif ($v['search'] == 'sdate') {
- $config['manage']['search']['sdate'][$k]['key'] = $v['search'];
- $config['manage']['search']['sdate'][$k]['lang'] = $v['name'];
- } elseif (strpos($v['search'], 'time') !== false || strpos($v['search'], 'day') !== false) {
- $config['manage']['search']['day'][$k]['key'] = $v['search'];
- $config['manage']['search']['day'][$k]['lang'] = $v['name'];
- } elseif (strpos($v['search'], 'date') !== false) {
- $config['manage']['search']['date'][$k]['key'] = $v['search'];
- $config['manage']['search']['date'][$k]['lang'] = $v['name'];
- } elseif (strpos($v['search'], 'year') !== false) {
- $config['manage']['search']['year'][$k]['key'] = $v['search'];
- $config['manage']['search']['year'][$k]['lang'] = $v['name'];
- } elseif (strpos($v['search'], 'month') !== false) {
- $config['manage']['search']['month'][$k]['key'] = $v['search'];
- $config['manage']['search']['month'][$k]['lang'] = $v['name'];
- }
- if (strpos($v['search'], 'exp') !== false) {
- $config['manage']['search']['exp'][$k] = $v['name'];
- }
- if (strpos($v['search'], 'ins') !== false) {
- $config['manage']['search']['ins'][$k] = $v['name'];
- }
- if (strpos($v['search'], 'fulltext') !== false) {
- $config['manage']['search']['fulltext'][$k] = $v['name'];
- isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like_score');
- } elseif (strpos($v['search'], 'text') !== false) {
- $config['manage']['search']['text'][$k] = $v['name'];
- } elseif (strpos($v['search'], 'hidden') !== false) {
- $config['manage']['search']['hidden'][$k] = $v['name'];
- }
- if (isset($v['exist']) && strpos($v['search'], 'exist') !== false) {
- $config['manage']['search']['exist'][$k]['option'] = $v['exist'];
- $config['manage']['search']['exist'][$k]['lang'] = $v['name'];
- }
- if (isset($v['option']) && strpos($v['search'], 'selects') !== false) {
- $config['manage']['search']['selects'][$k]['option'] = $v['option'];
- $config['manage']['search']['selects'][$k]['lang'] = $v['name'];
- if (isset($v['default'])) {
- $config['manage']['search']['selects'][$k]['default'] = $v['default'];
- }
- } elseif (isset($v['option']) && strpos($v['search'], 'select') !== false) {
- $config['manage']['search']['select'][$k]['option'] = $v['option'];
- $config['manage']['search']['select'][$k]['lang'] = $v['name'];
- if (isset($v['default'])) {
- $config['manage']['search']['select'][$k]['default'] = $v['default'];
- }
- }
- if (isset($v['option']) && strpos($v['search'], 'group') !== false) {
- $config['manage']['search']['group'][$k]['option'] = $v['option'];
- $config['manage']['search']['group'][$k]['lang'] = $v['name'];
- if (isset($v['default'])) {
- $config['manage']['search']['group'][$k]['default'] = $v['default'];
- }
- }
- if (isset($v['option']) && strpos($v['search'], 'linkage') !== false) {
- $config['manage']['search']['linkage'][$k]['option'] = $v['option'];
- $config['manage']['search']['linkage'][$k]['lang'] = $v['name'];
- if (isset($v['default'])) {
- $config['manage']['search']['linkage'][$k]['default'] = $v['default'];
- }
- }
- } elseif (isset($v['search']) && is_array($v['search'])) {
- if (isset($v['search']['api'])) {
- $config['manage']['search']['api'][$k] = $v['search'];
- $config['manage']['search']['api'][$k]['lang'] = $v['name'];
- }
- }
- if (isset($v['search_button'])) {
- $config['manage']['search']['button'][$k] = $v['search_button'];
- }
- }
- /*
- if (isset($v['table']) && !isset($config['end'])) {
- $config['end']['insert'] = $v['value'];
- }
- */
-
- if (isset($v['update'])) {
- if (!isset($config['manage']['insert'])) {
- $config['manage']['insert'] = true;
- }
- $config['update'] = true;
- }
- if (isset($v['type'])) {
- $config['manage']['struct'] .= Dever::tbody(array($k, $v['type'], $v['name']));
- }
- }
- $config['manage']['struct'] .= '</table>';
- $config['manage']['_list'] = array
- (
- 'col' => 'manage',
- 'name' => '管理',
- 'value' => array(),
- );
- if (!isset($config['manage']['edit']) || (isset($config['manage']['edit']) && $config['manage']['edit'] == true)) {
- if (!isset($config['manage']['list_button']['update'])) {
- $config['manage']['_list']['value']['update'] = '编辑';
- }
- }
-
- if (isset($config['manage']['list'][0]) && is_array($config['manage']['list'][0])) {
- $config['manage']['_list']['value'] += $config['manage']['list'][0];
- unset($config['manage']['list'][0]);
- } elseif (isset($config['manage']['list_button']) && $config['manage']['list_button']) {
- $config['manage']['_list']['value'] += $config['manage']['list_button'];
- }
- if (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] == true)) {
- if (!isset($config['manage']['list_button']['delete'])) {
- $config['manage']['_list']['value']['delete'] = '删除';
- }
- }
- if (!$config['manage']['_list']['value']) {
- unset($config['manage']['_list']);
- }
- if (isset($config['manage']['list_type'])) {
- $config['manage']['list_table'] = 'html';
- }
- # 新增排序
- $l = isset($_GET['l']) ? $_GET['l'] : '';
- if ($l == 'project/database/list' || $l == 'database.list_excel') {
- $list_order = array();
- $i = 0;
- foreach ($config['struct'] as $ki => $vi) {
- if (isset($vi['list_order'])) {
- $list_order[] = $vi['list_order'];
- } else {
- $config['struct'][$ki]['list_order'] = $i;
- $list_order[] = $i;
- }
- $i++;
- }
- if ($list_order) {
- array_multisort($list_order, SORT_ASC, SORT_NUMERIC, $config['struct']);
- }
- }
- } else {
- echo $file;die;
- }
- $config['state'] = $this->getState();
- $config['project'] = $project;
- return $config;
- }
- public function submit()
- {
- $data = Dever::submit();
- return $data;
- }
- /**
- * 自定义列表页面
- *
- * @return array
- */
- public function page($key = 'list')
- {
- $key = Dever::input('page_value', $key);
- $type = Dever::input('page_type', 1);
- $config = $this->config();
- $result = array();
- $result['s1'] = 'display:none';
- $result['s2'] = 'display:';
- $result['content'] = '';
- $key = 'page_' . $key;
- if (isset($config['manage'][$key]) && $type == 1) {
- if ($config['manage'][$key] == 'photo' && isset($config['manage']['photo'])) {
- $result['content'] = Dever::view('list/photo', false, 'manage');
- } else {
- $result['content'] = Dever::view($config['manage'][$key], 'manage', $this->project);
- }
-
- //echo $result['content'];die;
- if ($result['content']) {
- Dever::setInput('page_content', 1);
- $result['s1'] = 'display:';
- $result['s2'] = 'display:none';
- # 添加底部
- if ($key != 'page_list_table') {
- $result['content'] .= Dever::view('inc/foot', false, 'manage');
- }
- }
- } elseif (strstr($key, 'list_table')) {
- Dever::setInput('page_type', 2);
- }
- return $result;
- }
- /**
- * 自定义列表页面
- *
- * @return array
- */
- public function page_list()
- {
- return $this->page('list');
- }
- /**
- * 自定义列表页面 只接管table部分,同时必须传值page_type=1
- *
- * @return array
- */
- public function page_list_table()
- {
- $type = Dever::input('page_type', 2);
- if ($type == 1) {
- return $this->page('list_table');
- } else {
- return $this->page('list_table_default');
- }
- }
- /**
- * 自定义列表页面
- *
- * @return array
- */
- public function page_update()
- {
- return $this->page('update');
- }
- /**
- * 载入自定义资源
- *
- * @return array
- */
- public function res()
- {
- $result = array
- (
- 'js' => '',
- 'css' => '',
- );
- if (!$this->project) {
- return $result;
- }
- $config = $this->config();
- if (isset($config['manage']['res'])) {
- foreach ($config['manage']['res'] as $k => $v) {
- $result[$k] = $this->getRes($k, $v);
- }
- }
- return $result;
- }
- /**
- * 载入默认样式
- *
- * @return array
- */
- public function css()
- {
- $css = '';
- $fast = Dever::input('fast');
- if ($fast == 1) {
- $css = '.layui-input,.xm-select-parent
- {
- width: 100%;
- }';
- } else {
- $css = '.layui-input,.xm-select-parent,.layui-form-select
- {
- width: 50%;
- }
- .layui-form-select .layui-input {
- width:100%;
- }
- @media screen and (max-width: 1024px) {
- .layui-input,.xm-select-parent
- {
- width: 90%;
- }
- }';
- }
- return $css;
- }
- /**
- * getRes
- *
- * @return string
- */
- protected function getRes($path, $value)
- {
- if (is_array($value)) {
- $res = '';
- foreach ($value as $k => $v) {
- $res .= $this->getRes($path, $v);
- }
- return $res;
- } else {
- if ($this->project != 'manage') {
- $base = str_replace('assets/', 'assets/manage/', Dever::config('host', $this->project)->$path);
- } else {
- $base = Dever::config('host', $this->project)->$path;
- }
-
- $file = $base . $value . '.' . $path;
- if ($path == 'js') {
- $res = '<script type="text/javascript" src="'.$file.'"></script>';
- } else {
- $res = '<link rel="stylesheet" type="text/css" href="'.$file.'">
- ';
- }
-
- return $res;
- }
- }
- /**
- * 头部banner
- *
- * @return array
- */
- public function banner()
- {
- if (!$this->project) {
- return '';
- }
- $config = $this->config();
- $result = '';
- if (isset($config['manage']['banner'])) {
- foreach ($config['manage']['banner'] as $k => $v) {
- $config['manage']['banner'][$k] = $this->value($v, 'yes');
- }
- if (empty($config['manage']['banner']['link'])) {
- $config['manage']['banner']['link'] = '#';
- $config['manage']['banner']['target'] = '_self';
- }
- if (empty($config['manage']['banner']['target'])) {
- $config['manage']['banner']['target'] = '_blank';
- }
- $result = '<a target="' . $config['manage']['banner']['target'] . '" href="' . $config['manage']['banner']['link'] . '"><img src="' . $config['manage']['banner']['img'] . '"></a>
- <span>' . $config['manage']['banner']['name'] . '</span>';
- }
- return $result;
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_select(&$result, $search, $name, $lang, $option, $default = false, $bind = array(), $parent = '', $mul = false)
- {
- $value = array();
- if (strpos($lang, '-')) {
- $temp = explode('-', $lang);
- $lang = $temp[0];
- }
- $value['name'] = $name;
- $value['lang'] = $lang;
- $value['option'] = $option;
- if (isset($search[$name])) {
- $value['value'] = $search[$name];
- }
- if ($default) {
- //$value['default'] = $default;
- }
- if ($bind) {
- $value['bind'] = $bind;
- }
- $value['parent'] = $parent;
- if ($mul) {
- $value['update'] = 'selects';
- $value['match'] = 'option';
- }
- $result .= Html::select($value, false);
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_group(&$result, $search, $name, $lang, $option, $default = false)
- {
- $value = array();
- $value['name'] = $name;
- $value['lang'] = $lang;
- $value['option'] = $option;
- if (isset($search[$name])) {
- $value['value'] = $search[$name];
- }
- if ($default) {
- //$value['default'] = $default;
- }
- $result .= Html::group($value, false);
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_linkage(&$result, $search, $name, $lang, $option, $default = false)
- {
- $value = array();
- $value['name'] = $name;
- $value['lang'] = $lang;
- $value['option'] = $option;
- $value['search_state'] = true;
- if (isset($search[$name])) {
- $value['value'] = $search[$name];
- }
- if ($default) {
- //$value['default'] = $default;
- }
- $result .= Html::linkage($value, 'span');
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search_time(&$result, $search, $prefix, $key, $config, $type = 'time')
- {
- $start = $end = true;
- $eq = $eqs = false;
- if (is_array($config)) {
- $lang = $config['lang'];
- $search_key = $config['key'];
- if (strstr($search_key, '_')) {
- $temp = explode('_', $search_key);
- $start = $end = false;
- if (isset($temp[1])) {
- if ($temp[1] == 'start') {
- $start = true;
- } elseif ($temp[1] == 'end') {
- $end = true;
- } elseif ($temp[1] == 'eq') {
- $eq = true;
- } elseif ($temp[1] == 'eqs') {
- $eqs = true;
- }
- }
- }
- } else {
- $lang = $config;
- }
- if ($eqs) {
- $value = array();
- $value['name'] = $prefix . 'option_' . $key;
- Dever::setInput($value['name'], '', 'search_');
- $value['lang'] = $lang;
- if (isset($search[$value['name']]) && $search[$value['name']]) {
- $value['value'] = Dever::maketime($search[$value['name']]);
- $start_value = $end_value = $value['value'];
- if ($type == 'time' || $type == 'day' || $type == 'date') {
- $start_value = Dever::maketime($search[$value['name']] . ' 00:00:00');
- $end_value = Dever::maketime($search[$value['name']] . ' 23:59:59');
- } elseif ($type == 'month') {
- $start_value = Dever::maketime($search[$value['name']] . '-01 00:00:00');
- $end_value = date('t', $start_value);
- $end_value = Dever::maketime($search[$value['name']] . '-'.$end_value.' 23:59:59');
- } elseif ($type == 'year') {
- $start_value = Dever::maketime($search[$value['name']] . '-01-01 00:00:00');
- $end_value = date('12-t', $start_value);
- $end_value = Dever::maketime($search[$value['name']] . '-'.$end_value.' 23:59:59');
- }
-
- Dever::setInput($prefix . 'option_start_' . $key, $start_value, 'search_');
- Dever::setInput($prefix . 'option_end_' . $key, $end_value, 'search_');
- }
- $result .= Html::$type($value, false);
- } elseif ($eq) {
- $value = array();
- $value['name'] = $prefix . 'option_' . $key;
- $value['lang'] = $lang;
- if (isset($search[$value['name']]) && $search[$value['name']]) {
- $value['value'] = Dever::maketime($search[$value['name']]);
- Dever::setInput($value['name'], $value['value'], 'search_');
- }
- $result .= Html::$type($value, false);
- } else {
- if ($start) {
- $value = array();
- $value['name'] = $prefix . 'option_start_' . $key;
- $value['lang'] = '>=' . $lang;
- if (isset($search[$value['name']]) && $search[$value['name']]) {
- $value['value'] = Dever::maketime($search[$value['name']]);
- Dever::setInput($value['name'], $value['value'], 'search_');
- }
- $result .= Html::$type($value, false);
- }
-
- if ($end) {
- $value = array();
- $value['name'] = $prefix . 'option_end_' . $key;
- $value['lang'] = '<=' . $lang;
- if (isset($search[$value['name']]) && $search[$value['name']]) {
- $value['value'] = Dever::maketime($search[$value['name']]);
- Dever::setInput($value['name'], $value['value'], 'search_');
- }
- $result .= Html::$type($value, false);
- }
- }
- }
- /**
- * 列表页头部按钮
- *
- * @return array
- */
- public function list_button()
- {
- /*
- if (Dever::load('manage/auth.oper', 2) == false) {
- return '';
- }
- */
- $button = array();
- $config = $this->config();
- $result = '';
- $suffix = '';
- if (isset($config['manage']['link'])) {
- $suffix = $config['manage']['link'];
- }
- # 增加返回上一页按钮
- $info = $this->info();
- if ($info['parent']) {
- $parent_name = '返回上一页';
- $parent_show = false;
- if (isset($config['manage']['parent']) && $config['manage']['parent']) {
- if (is_string($config['manage']['parent'])) {
- $parent_name = $config['manage']['parent'];
- }
- $parent_show = true;
- } elseif (!isset($config['manage']['parent'])) {
- $parent_show = true;
- }
- if ($parent_show) {
- $button[$parent_name] = $info['parent'];
- }
- }
- if ($info['add']) {
- $add_name = '新增';
- $add_show = false;
- if (isset($config['manage']['insert']) && $config['manage']['insert']) {
- if (is_string($config['manage']['insert'])) {
- $add_name = $config['manage']['insert'];
- }
- $add_show = true;
- } elseif (!isset($config['manage']['insert'])) {
- $add_show = true;
- }
- $insert_state = Dever::load('manage/auth.oper', 4);
- if ($insert_state) {
- if ($add_show) {
- $button[$add_name] = $info['add'] . '&' . $suffix;
- }
- } elseif (isset($config['manage']['button']['新增'])) {
- unset($config['manage']['button']['新增']);
- }
- }
- # 增加主动统计按钮
- if ($this->state && isset($config['manage']['stat'])) {
- $name = '数据统计';
- if (is_string($config['manage']['stat'])) {
- $name = $config['manage']['stat'];
- }
- $button[$name] = $this->url('stat', false, false, $suffix);
- }
- if (isset($config['manage']['button']) && $config['manage']['button']) {
- $button += $config['manage']['button'];
- }
- # 增加下载报表按钮
- if ($this->state && isset($config['manage']['excel']) && $config['manage']['excel']) {
- $url = $this->url('excel');
- if (is_array($config['manage']['excel'])) {
- foreach ($config['manage']['excel'] as $k => $v) {
- if (is_array($v)) {
- $name = $v[0];
- $u = $url . '&excel_name='.$v[1].'&excel_load=' . $v[2];
- $button[$name] = 'onclick="jump(\''.$u.'\', \'#form1\')"';
- } else {
- $name = $v;
- $button[$name] = 'onclick="jump(\''.$url.'\', \'#form1\')"';
- }
- }
- } else {
- $name = '导出数据';
- if (is_string($config['manage']['excel']) && !strstr($config['manage']['excel'], '.')) {
- $name = $config['manage']['excel'];
- }
- $button[$name] = 'onclick="jump(\''.$url.'\', \'#form1\')"';
- }
- }
-
- # 增加回收站
- if (Dever::load('manage/auth.oper', 5) != false && isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] && isset($config['manage']['_list']['value']['delete'])))) {
- if ($config['state'] == 2) {
- $button['返回数据列表'] = $this->url('list', 0, false, 'search_option_state=1', $this->project);
- } else {
- $button['回收站'] = $this->url('list', 0, false, 'search_option_state=2', $this->project);
- }
- }
- # 列表页按钮
- if ($button) {
- $result .= $this->list_button_show($button, $suffix, $config);
- }
- /*
- if (Dever::load('manage/auth.oper', 6) != false && isset($config['manage']['button'])) {
- $result .= $this->list_button_show($config['manage']['button']);
- }*/
- return $result;
- }
- /**
- * 更新页按钮
- *
- * @return array
- */
- public function update_button()
- {
- # 新增权限
- /*
- if (Dever::load('manage/auth.oper', 2) == false) {
- Dever::alert('你没有权限');
- }
- */
- $info = $this->info();
- $config = $this->config();
- $result = '';
- $save_name = '提交保存';
- if (isset($config['manage']['update_save']) && !$config['manage']['update_save']) {
- $save_name = '';
- }
- if ($save_name) {
- $result .= '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> '.$save_name.'</button>';
- }
- $close_name = '放弃保存';
- if (isset($config['manage']['update_close']) && !$config['manage']['update_close']) {
- $close_name = '';
- }
- if ($close_name) {
- $result .= '<a href="' . $info['submit'] . '" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclicks="msg({status:1,msg:\'yes\'})">'.$close_name.'</a>';
- }
- if (isset($config['manage']['update_button']) && $config['manage']['update_button']) {
- $result = '';
- foreach ($config['manage']['update_button'] as $k => $v) {
- if ($v == 'save-data') {
- $result .= '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> ' . $k . '</button>';
- } elseif ($v == 'copy-data') {
- $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="set_update(\'#copy_num\', 1);set_update(\'#update_where_id\', 0);submit_action();">' . $k . '</a>';
- } elseif ($v == 'copy-datas') {
- $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="copy_data($(this))">' . $k . '</a>';
- } else {
- $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="' . $v . '">' . $k . '</a>';
- }
- }
- }
- return $result;
- }
- private function list_button_show($button, $suffix = '', $config = array())
- {
- $result = '';
- $refer = Dever::input('refer');
- if ($refer) {
- $button['返回上一页'] = array('location', Dever::decode($refer));
- }
- # 不显示哪个按钮
- $manage = Dever::config('base')->manage;
- foreach ($button as $k => $v) {
- if ($manage && isset($manage['deleteButton']) && in_array($k, $manage['deleteButton'])) {
- continue;
- }
- # 增加细分权限
- if ($config && isset($config['manage']['auth']) && $config['manage']['auth'] && !Dever::load('manage/auth.check', $config['lang'] . '-' . $k, $this->menu_id)) {
- continue;
- }
- if (is_array($v)) {
- if ($v[0] == 'location') {
- if ($v[1] == 'add') {
- $url = $this->url('add', false, false, $suffix);
- } elseif ($v[1] == 'list') {
- $url = $this->url('list', false, false, $suffix);
- } else {
- $url = Dever::url($v[1]);
- }
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="location.href=\''.$url.'\'">' . $k . '</a>';
- } elseif ($v[0] == 'import') {
- $result .= ' <a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $v[1] . '\')">' . $k . '</a>';
- } elseif ($v[0] == 'excel' || $v[0] == 'search') {
- $url = Dever::url($v[1]);
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="jump(\''.$url.'\', \'#form1\')">' . $k . '</a>';
- } elseif ($v[0] == 'oper') {
- $url = Dever::url($v[1]);
- $content = '';
- if (isset($v[2])) {
- $content = $v[2];
- }
- $title = '';
- if (isset($v[3])) {
- $title = $v[3];
- }
- $url .= '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $k;
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list layui-btn-danger" href="javascript:;" onclick="load(\'' . $url . '\', \'' . $content . '\', \'' . $title . '\')">' . $k . '</a>';
- } elseif ($v[0] == 'oper_mul') {
- if (isset($v[2])) {
- $url = $this->url($v[1], false, false, $suffix);
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$url.'\',\''.$k.'\', \''.$v[2].'\', false, false, 1, \''.$v[3].'\')">' . $k . '</a>';
- //$result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list layui-btn-danger" href="javascript:;" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list', false, false, $suffix) . '\');list_mul($(this), 1, \''.$url.'\')">' . $k . '</a>';
- } else {
- $url = Dever::url($v[1]);
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list layui-btn-danger" href="javascript:;" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list', false, false, $suffix) . '\');list_mul($(this), 1, \''.$url.'\')">' . $k . '</a>';
- }
-
- } elseif ($v[0] == 'show') {
- $url = Dever::url($v[1]);
- $submit = '';
- if (isset($v[2])) {
- $submit = Dever::url($v[2]);
- }
-
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="loadPage(\''.$url.'\', \''.$k.'\',\''.$submit.'\')">' . $k . '</a>';
- } elseif ($v[0] == 'fast') {
- if (isset($v[2]) && $v[2]) {
- $url = $this->url('add', $v[1], $v[2], $suffix);
- } elseif (isset($v[1]) && $v[1]) {
- $url = Dever::url($v[1], false, false, $suffix);
- } else {
- $url = $this->url('add', false, false, $suffix);
- }
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$url.'\',\''.$k.'\', \'\')">' . $k . '</a>';
- } elseif ($v[0] == 'fasts') {
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$this->url('add', false, false, $suffix).'\',\''.$k.'\', \'\', 1)">' . $k . '</a>';
- } elseif ($v[0] == 'onclick') {
- $result .= ' <a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" onclick="' . $v[1] . '">' . $k . '</a>';
- } else {
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . $this->url($v[0], false, $v[1], $suffix) . '">' . $k . '</a>';
- }
-
- } elseif (strpos($v, 'modal|') !== false) {
- $t = explode('modal|', $v);
- $result .= ' <a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $t[1] . '\')">' . $k . '</a>';
- } elseif (strpos($v, '|') !== false) {
- $t = explode('|', $v);
- $result .= $t[0] . ' <a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $t[1] . '>' . $k . '</a>';
- } elseif (strpos($v, 'onclick') !== false) {
- $result .= ' <a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $v . '>' . $k . '</a>';
- } elseif (strpos($v, 'http://') !== false || strpos($v, 'https://') !== false) {
- //$result .= ' <a href="javascript:;" class="btn btn-default" onclick="jump(\''.Dever::url($v).'\')">'.$k.'</a>';
- $result .= ' <a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . Dever::url($v) . '">' . $k . '</a>';
- } else {
- $result .= ' <a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="load(\'' . Dever::url($v) . '\')">' . $k . '</a>';
- }
- }
- $result = ltrim($result, ' ');
- return $result;
- }
- /**
- * 列表页搜索
- *
- * @return array
- */
- public function list_search()
- {
- if (Dever::load('manage/auth.oper', 2) == false) {
- return '';
- }
- # 将以下判断合并
- # 权限验证
- /*
- if (!Dever::load('manage/auth.check', '搜索', $this->menu_id)) {
- return '';
- }
- */
- /*
- # 新增权限
- if (Dever::load('manage/auth.oper', 2) == false) {
- return '';
- }
- if (!Dever::load('manage/auth.checkFunc', $this->menu_id, false, '搜索')) {
- return '';
- }
- */
- $config = $this->config();
- # 增加细分权限
- /*
- if ($config && isset($config['manage']['auth']) && $config['manage']['auth'] && !Dever::load('manage/auth.check', $config['lang'] . '-' . '搜索', $this->menu_id)) {
- return '';
- }*/
- $result = '';
- $top_result = '';
- # 搜索
- if (isset($config['struct']) && isset($config['manage']['search']) && $config['manage']['search']) {
- $search = Dever::preInput('search_');
- $set = Dever::preInput('set_');
- $node = Html::node(array(' style="margin-top:0px;"', ''));
- $btn = '<div class="layui-inline"><input type="hidden" value="2" name="excel" id="excel">';
- if (isset($config['manage']['search']['button'])) {
- foreach ($config['manage']['search']['button'] as $k => $v) {
- $i = 0;
- foreach ($v['option'] as $k1 => $v1) {
- $value = $k . '~' . $v['sum'] . '~' . $k1;
- if (isset($v['group'])) {
- $value .= '~' . $v['group'];
- }
- if (!isset($search['search_button']) && $i == 0) {
- $search['search_button'] = $value;
- }
- if (isset($search['search_button']) && $search['search_button'] == $value) {
- $class = 'layui-btn-normal';
- } else {
- $class = 'layui-btn-primary';
- }
- $url = $this->url('list', 0, false, 'search_button=' . $value);
- $btn .= '<a class="btn btn-primary layui-btn layuiadmin-btn-list '.$class.'" href="'.$url.'" type="button" style="height: 38px;margin-left:0px;margin-top:-2px;">'.$v1.'</a> ';
- }
- }
- }
- $btn .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list" id="search_button" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('search') . '\');list_search($(this))" type="button" style="height: 38px;margin-left:0px;margin-top:-2px;">搜索</button><a class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary" href=" '. $this->url('reset') . '" type="button" style="height: 38px;margin-right:5px;margin-top:-2px;display:none;">重置</a></div>';
- //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
- $prefix = 'search_';
-
- $result .= $node[0];
- if (isset($config['manage']['search']['linkage'])) {
- foreach ($config['manage']['search']['linkage'] as $k => $v) {
- $this->list_search_linkage($result, $search, $prefix . 'linkage_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
- if (!layadmin()) {
- $result .= '<br />';
- }
- }
- }
- if (isset($config['manage']['search']['selects'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['selects'] as $k => $v) {
- $bind = array();
- $parent = '';
- $option = $this->option($v['option']);
- if (isset($config['manage']['search_parent'][$k])) {
- $bind = array
- (
- 'onchange',
- 'setOption',
- 'search_option_' . $config['manage']['search_parent'][$k]
- );
- }
- elseif (isset($config['manage']['search_child'][$k])) {
- $parent = $config['manage']['search_child'][$k];
- }
- $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent, true);
- }
- }
- if (isset($config['manage']['search']['select'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['select'] as $k => $v) {
- $bind = array();
- $parent = '';
- $option = $this->option($v['option']);
- if (isset($config['manage']['search_parent'][$k])) {
- $bind = array
- (
- 'onchange',
- 'setOption',
- 'search_option_' . $config['manage']['search_parent'][$k]
- );
- }
- elseif (isset($config['manage']['search_child'][$k])) {
- $parent = $config['manage']['search_child'][$k];
- }
- $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
- }
- }
- if (isset($config['manage']['search']['exist'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['exist'] as $k => $v) {
- $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
- }
- }
- if (isset($config['manage']['search']['group'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['group'] as $k => $v) {
- $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
- }
- }
- if (isset($config['manage']['search']['api'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['api'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'api_' . $k;
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v['lang'], '-') !== false) {
- $t = explode('-', $v['lang']);
- $v['lang'] = $t[0];
- }
- $value['placeholder'] = $v['lang'];
- if (isset($v['option']) && $v['option']) {
- $value['option'] = $this->option($v['option']);
- $value['lang'] = $v['lang'];
- if (isset($v['top']) && $v['top']) {
- $top_result .= Html::select($value, false);
- } else {
- $result .= Html::select($value, false);
- }
- } else {
- $result .= Html::text($value, false);
- }
-
- }
- }
- if (isset($config['manage']['search']['text'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['text'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'option_' . $k;
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v, '-') !== false) {
- $t = explode('-', $v);
- $v = $t[0];
- }
- $value['placeholder'] = $v;
- $result .= Html::text($value, false);
- }
- }
- if (isset($config['manage']['search']['hidden'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['hidden'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'option_' . $k;
- $value['class'] = 'form-control';
- if (isset($set[$value['name']])) {
- $value['name'] = 'set_option_' . $k;
- $value['value'] = $set[$value['name']];
- } elseif (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v, '-') !== false) {
- $t = explode('-', $v);
- $v = $t[0];
- }
- $value['placeholder'] = $v;
- $value['type'] = 'hidden';
- $result .= Html::hidden($value, false);
- }
- }
- if (isset($config['manage']['search']['ins'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['ins'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'option_' . $k;
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v, '-') !== false) {
- $t = explode('-', $v);
- $v = $t[0];
- }
- $value['placeholder'] = $v;
- $result .= Html::text($value, false);
- }
- }
- if (isset($config['manage']['search']['fulltext'])) {
- $this->list_search_br($result);
- foreach ($config['manage']['search']['fulltext'] as $k => $v) {
- $value = array();
- $value['name'] = $prefix . 'fulltext_' . $k;
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- if (strpos($v, '-') !== false) {
- $t = explode('-', $v);
- $v = $t[0];
- }
- $value['placeholder'] = $v;
- $result .= Html::text($value, false);
- }
- }
- if (isset($config['manage']['search']['exp'])) {
- $result .= '<br />';
- $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
- $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
- (
- 3 => '大于',
- 4 => '大于等于',
- 5 => '小于',
- 6 => '小于等于',
- ), 1);
- $value = array();
- $value['name'] = $prefix . 'exp_value';
- $value['class'] = 'form-control';
- if (isset($search[$value['name']])) {
- $value['value'] = $search[$value['name']];
- }
- $value['placeholder'] = '填写值';
- $result .= Html::text($value, false);
- }
- if (isset($config['manage']['search']['day'])) {
- foreach ($config['manage']['search']['day'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v, 'day');
- }
- }
- if (isset($config['manage']['search']['date'])) {
- foreach ($config['manage']['search']['date'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
- }
- }
- if (isset($config['manage']['search']['year'])) {
- foreach ($config['manage']['search']['year'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v, 'year');
- }
- }
- if (isset($config['manage']['search']['month'])) {
- foreach ($config['manage']['search']['month'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v, 'month');
- }
- }
- if (isset($config['manage']['search']['sday'])) {
- $result .= '<br />';
- foreach ($config['manage']['search']['sday'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v, 'sday');
- }
- $sday = Dever::input('search_option_sday');
- $s1 = $s2 = $s3 = '';
- if ($sday == 7) {
- $s2 = 'sday_button_border';
- } elseif ($sday == 30) {
- $s3 = 'sday_button_border';
- } elseif ($sday) {
- $s1 = 'sday_button_border';
- }
- $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sday_button '.$s1.'" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;" onclick="setDay($(this), 0)">今日</button>';
- $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sday_button '.$s2.'" onclick="setDay($(this), 7)" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;">7日</button>';
- $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sday_button '.$s3.'" onclick="setDay($(this), 30)" type="button" style="height: 38px;margin-right:20px;margin-top:-4px;">30日</button><style>.sday_button_border{border-color: #009688;}</style>';
- $result .= '<input type="hidden" name="search_option_sday" id="search_option_sday" value="0">';
- } elseif (isset($config['manage']['search']['sdate'])) {
- $result .= '<br />';
- foreach ($config['manage']['search']['sdate'] as $k => $v) {
- $this->list_search_time($result, $search, $prefix, $k, $v, 'sdate');
- }
- $sdate = Dever::input('search_option_sdate');
- $s1 = $s2 = $s3 = '';
- if ($sdate == 7) {
- $s2 = 'sdate_button_border';
- } elseif ($sdate == 30) {
- $s3 = 'sdate_button_border';
- } elseif ($sdate) {
- $s1 = 'sdate_button_border';
- }
- $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sdate_button '.$s1.'" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;" onclick="setDate($(this), 0)">今日</button>';
- $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sdate_button '.$s2.'" onclick="setDate($(this), 7)" type="button" style="height: 38px;margin-right:5px;margin-top:-4px;">7日</button>';
- $result .= '<button class="btn btn-primary layui-btn layuiadmin-btn-list layui-btn-primary sdate_button '.$s3.'" onclick="setDate($(this), 30)" type="button" style="height: 38px;margin-right:20px;margin-top:-4px;">30日</button><style>.sdate_button_border{border-color: #009688;}</style>';
- $result .= '<input type="hidden" name="search_option_sdate" id="search_option_sdate" value="0">';
- }
- # 列表页按钮
- if (isset($config['manage']['search_button'])) {
- $btn .= $this->list_button_show($config['manage']['search_button'], '', $config);
- }
- $result .= $btn . $node[1];
- //$result .= '</form>';
- # 增加每页显示条数
- $config['manage']['num'] = $this->getNumConfig($config);
-
- /*
- if ($config['manage']['num']) {
- $result = $this->num($result, $config['manage']['num']);
- }
- */
- }
- $oper = Dever::preInput('oper_');
- if ($oper) {
- foreach ($oper as $k => $v) {
- $result .= '<input type="hidden" value="'.$v.'" name="'.$k.'" id="'.$k.'" />';
- }
- }
- $top = Dever::input('top_parent');
- if ($top) {
- $result .= '<input type="hidden" value="'.$top.'" name="top_parent" id="top_parent" />';
- }
- $page_type = Dever::input('page_type');
- if ($page_type) {
- $result .= '<input type="hidden" value="'.$page_type.'" name="page_type" id="page_type" />';
- }
- if ($top_result) {
- $result = $top_result . $result;
- }
- return $result;
- }
- private function list_search_br(&$result)
- {
- if (strpos($result, ' ') && !strpos($result, '<br />')) {
- $result .= '<br />';
- }
- }
- /**
- * 获取条数配置
- *
- * @return array
- */
- private function getNumConfig($config)
- {
- if (isset($config['manage']['list_type'])) {
- return false;
- }
- if (isset($config['manage']['num']) && $config['manage']['num'] == false) {
- return false;
- }
- if (!isset($config['manage']['num'])) {
- $config['manage']['num'] = array(20,30,40,50,60,70,80,90,100);
- }
- Dever::config('base')->page_num = $config['manage']['num'];
- return $config['manage']['num'];
- }
- /**
- * 生成条数的html
- *
- * @return string
- */
- private function num($result, $config)
- {
- return $result;
- $limit = '';
- $cur = Dever::input('search_limit', 0);
- foreach($config as $k => $v) {
- if ($cur == $k) {
- $btn = 'success';
- } else {
- $btn = 'default';
- }
- $url = $this->url('list', 0, false, 'search_limit=' . $k);
- $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.' layui-btn layui-btn-radius layui-btn-primary">'.$v.'</a> ';
- }
-
- $num = '<div class="form-group layui-inline"><div style="padding-top:10px;margin-bottom: -10px;"><label style="color:#bababa;margin-left:8px;margin-right:10px;font-size:14px;font-weight:bold;">每页显示条数:</label>'.$limit.'</div></div>';
- /*
- if (layadmin()) {
- $num = '';
- }*/
- $result .= $num;
- return $result;
- }
- /**
- * 列表页表格头
- *
- * @return array
- */
- public function list_thead($type = false)
- {
- if (Dever::load('manage/auth.oper', 1) == false) {
- Dever::alert('你没有权限');
- }
- $config = $this->config();
- if ($type == 'layui') {
- if (!isset($config['manage']['list_table']) || (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'html')) {
- return false;
- }
- } else {
- if (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'js') {
- return '';
- }
- }
- $result = array();
- /*
- $tbody = Dever::load('manage/database.list_tbody');
- if (!$tbody) {
- return $result;
- }
- */
- if (isset($config['struct'])) {
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
- if (isset($config['top']) && is_string($config['top'])) {
- $top = Dever::load('manage/auth.getTop', array($config['top']));
- if ($top) {
- $url = $this->url('update', $top['value']);
- }
- } else {
- $url = $this->url('update', Dever::input('where_id', 1));
- }
- return Dever::location($url);
- } else {
- if (isset($config['manage']['mul']) && $config['manage']['mul']) {
- if ($type == 'layui') {
- $layui = array
- (
- 'field' => 'checkbox',
- 'title' => '<input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list" lay-ignore/>',
- //'fixed' => 'left',
- );
- $result[] = $layui;
- } else {
- $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
- }
- }
- $data = array();
- $data = $this->getAdminInfo($data);
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['list']) && $v['list']) {
- # 处理权限
- if (isset($v['auth'])) {
- $auth = $this->value($v['auth'], $data);
- if (!$auth) {
- continue;
- }
- }
- if (isset($v['list_name'])) {
- $v['name'] = $v['list_name'];
- } else {
- $temp = Html::cue(array('name' => $v['name']));
- $v['name'] = $temp['name'];
- }
- if (!isset($v['level'])) {
- $v['level'] = $config['level'];
- }
- if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
- $link = Dever::url();
- $order = 'search_order_' . $k . '';
- if (strpos($link, $order) !== false) {
- $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
- } else {
- $link .= '{order}';
- }
- $search = Dever::input($order);
- $cancel = '';
- if ($search) {
- $asc = $search;
- $cancel = ' <a class="glyphicon glyphicon-remove-sign layui-icon layui-icon-close" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
- } else {
- $asc = 'desc';
- if (!isset($v['order']) && $k != 'id') {
- //$cancel = ' <a class="glyphicon glyphicon-circle-arrow-down layui-icon layui-icon-up" style="color:black;" href="' . str_replace('{order}', '&' . $order . '=desc', $link) . '" title="降序"></a>';
- }
- }
- if ($asc == 'asc') {
- $asc = 'desc';
- $icon = 'down';
- $text = '降序';
- } else {
- $asc = 'asc';
- $icon = 'up';
- $text = '升序';
- }
- $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
- if ($type == 'layui') {
- $layui = array
- (
- 'field' => $k,
- 'title' => '<a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . ' <span class="layui-icon layui-icon-' . $icon . '" style="font-size:12px"></span></a>',
- );
- $result[] = $layui;
-
- } else {
- $result[] = '<th data-priority="'.$v['level'].'"><a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . ' <span class="glyphicon glyphicon-circle-arrow-' . $icon . ' layui-icon layui-icon-' . $icon . '"></span></a>' . $cancel . '</th>';
- }
-
- } else {
-
- if ($type == 'layui') {
- if ($k == 'id' || isset($v['fixed'])) {
- $layui = array
- (
- 'field' => $k,
- 'title' => $v['name'],
- //'fixed' => 'left',
- );
- } else {
- $layui = array
- (
- 'field' => $k,
- 'title' => $v['name'],
- );
- }
- if (isset($v['list_header']) && $v['list_header']) {
- $layui += $v['list_header'];
- }
- $result[] = $layui;
- } else {
- $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
- }
- }
- }
- }
- //if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
- if (isset($config['manage']['_list']['value']) && $this->manage_button) {
- if ($type == 'layui') {
- $layui = array
- (
- 'field' => $config['manage']['_list']['col'],
- 'title' => $config['manage']['_list']['name'],
- //'fixed' => 'right',
- );
- $result[] = $layui;
- } else {
- $result[] = '<th data-priority="1" class="dever-manage">' . $config['manage']['_list']['name'] . '</th>';
- }
- }
- }
- }
- return $result;
- }
- # layui表头
- /*
- public function list_thead_layui()
- {
- $html = 'config.table = {};config.table.cols = [];';
- $data = $this->list_thead('layui');
- if ($data) {
- $data = array($data);
- $data = Dever::json_encode($data);
- $html .= 'config.table.cols = ' . $data;
- return $html;
- } else {
- $html .= 'config.table.cols = []';
- return $html;
- }
-
- }
- # layui表的数据 没有使用其异步方式
- public function list_tbody_layui()
- {
- $html = 'config.table.data = [];';
- $data = $this->list_tbody(false, 'layui');
- $data = Dever::json_encode($data);
- $html .= 'config.table.data = ' . $data;
- return $html;
- }
- */
- /**
- * 导出列表
- *
- * @return array
- */
- public function list_excel_api()
- {
- Dever::$global['base']['excel'] = 1;
- $this->list_search();
- $data = $this->list_tbody(true);
-
- if ($data) {
- $config = $this->config();
- if (isset($config['manage']['excel']) && $config['manage']['excel']) {
- $method = 'excel';
- $info = $this->info();
- $load = Dever::input('excel_load');
- if ($load) {
- return Dever::load($load, $data);
- } elseif (is_string($config['manage']['excel']) && strstr($config['manage']['excel'], '.')) {
- return Dever::load($config['manage']['excel'], $data);
- } else {
- $data = $this->getAdminInfo($data);
- return $this->excel($info, $data, $config);
- }
- }
- } else {
- Dever::alert('无导出数据');
- }
- //print_r($data);die;
- }
- private function excel($info, $data, $config)
- {
- $file = Dever::input('excel_name');
- if (!$file) {
- $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
- }
- $header = $body = array();
- $i = 0;
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['list']) && $v['list']) {
- # 处理权限
- if (isset($v['auth'])) {
- $auth = $this->value($v['auth'], $data);
- if (!$auth) {
- continue;
- }
- }
- //$v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
- if (isset($v['list_name']) && $v['list_name']) {
- $v['name'] = $v['list_name'];
- }
- $header[$i] = $v['name'];
- $j = 0;
- foreach ($data as $ki => $vi) {
- if (is_array($vi)) {
- if (isset($data[$ki][$k])) {
- $data[$ki]['cur_value'] = $data[$ki][$k];
- }
- $body[$j][$i] = '';
- //if (isset($vi[$k])) {
- # 处理同步
- # 兼容旧版,之后去掉
- if (isset($v['sync']) && isset($v['sync'][0]) && (strstr($k, '-') || strstr($k, '.'))) {
- $temp = explode('-', $k);
- if ($vi[$v['sync'][0]] > 0) {
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $v['sync'][1] => $vi[$v['sync'][0]]));
- } else {
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $v['sync'][3] => $vi[$v['sync'][2]], 'option_' . $v['sync'][4] => $vi[$v['sync'][0]]));
- }
-
- if (isset($temp[2])) {
- $data[$ki][$k] = $vi[$k] = isset($load[$temp[2]]) ? $load[$temp[2]] : $v['default'];
- }
- } elseif (isset($v['sync']) && (strstr($k, '-') || strstr($k, '.'))) {
- $v['sync']['dever-read'] = $vi;
- $data[$ki][$k] = Dever::load($k, $v['sync']);
- }
- if (true) {
- $value = $vi[$k];
- if (is_string($v['list'])) {
- $value = $this->value($v['list'], $data[$ki], $config['struct']);
- }
- if (isset($v['option'])) {
- $value = $this->getOptionValue($value, $v);
- }
- //$value = mb_convert_encoding($value,'gb2312','utf-8');
- $body[$j][$i] = $value;
- $j++;
- }
- }
- }
- $i++;
- }
- }
- return Dever::excelExport($body, $header, $file);
- }
- private function getOptionValue($value, $v)
- {
- # 验证option是否是匿名函数
- $v['option'] = $this->option($v['option']);
- # 位运算
- if (isset($v['bit'])) {
- $ts = array();
- foreach ($v['option'] as $tm => $tv) {
- if (isset($v['bit'][$tm]) && ($value & $tm) > 0) {
- $ts[] = $tv;
- }
- }
- $value = implode(',', $ts);
- }
- if ((isset($v['child_name']) || (isset($v['show']) && is_string($v['show'])))) {
- if (isset($v['option'][$value]) && is_array($v['option'][$value])) {
- $value = $v['option'][$value]['name'];
- } else {
- $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
- }
- } else {
- if (strstr($value, ',')) {
- $temp = explode(',', $value);
- $t = array();
- foreach ($temp as $vv) {
- if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
- $t[] = $v['option'][$vv]['name'];
- } elseif(isset($v['option'][$vv])) {
- $t[] = $v['option'][$vv];
- } else {
- $t[] = $vv;
- }
- }
- $value = implode("\r\n", $t);
- } elseif (isset($v['option'][$value]) && is_array($v['option'][$value])) {
- $value = $v['option'][$value]['name'];
- } else {
- $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
- }
- }
- return $value;
- }
- private function _getChr($start, $num)
- {
- $num = $start + $num;
- $max = floor($num / 91);
- if ($max > 0) {
- $num = $num - (91 * $max) + $start;
- $num = chr($start) . chr($num);
- } else {
- $num = chr($num);
- }
- return $num;
- }
- /**
- * 列表页数据列表 检索
- *
- * @return array
- */
- private function list_tbody_search($config, $param, $high, $search)
- {
- # 根据api的数据检索到id
- $api = Dever::preInput('search_api_');
- if ($api) {
- foreach ($api as $k => $v) {
- if ($v) {
- unset($search[$k]);
- $k = str_replace('search_api_', '', $k);
- # 设定检索高亮
- $high[$k] = $v;
- if (isset($config['manage']['search']['api'][$k]['api'])) {
- $col = $config['manage']['search']['api'][$k]['col'];
- $v = ltrim($v);
- $v = rtrim($v);
- if ($v == 'no') {
- $param['option_no'] = $config['manage']['search']['api'][$k]['no'];
- } else {
- $option = array($col => $v, 'clear_top' => true);
- # 此处可以增加关联关系
- $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
- $result = $config['manage']['search']['api'][$k]['result'];
- if ($v && is_array($v)) {
- if (isset($v[$result])) {
- $v = $v[$result];
- } else {
- if ($result == 'id') {
- $v = array_keys($v);
- } else {
- $t = array();
- foreach ($v as $k1 => $v1) {
- $t[] = $v1[$result];
- }
- $v = $t;
- }
- if (isset($config['manage']['search']['api'][$k]['search'])) {
- $param['option'][$config['manage']['search']['api'][$k]['search']] = array('yes', 'in');
- } else {
- $param['option'][$k] = array('yes', 'in');
- }
- }
- } else {
- $v = '-100';
- }
- }
- }
- if (!isset($param['option_no'])) {
- if (isset($config['manage']['search']['api'][$k]['search'])) {
- $param['option_' . $config['manage']['search']['api'][$k]['search']] = $v;
- } else {
- $param['option_' . $k] = $v;
- }
- }
- }
- }
- }
- # 检索有无值
- $exist = Dever::preInput('search_exist_');
- if ($exist) {
- foreach ($exist as $k => $v) {
- if ($v) {
- $v = ltrim(rtrim($v));
- unset($search[$k]);
- $k = str_replace('search_exist_', '', $k);
- if ($v == 'yes') {
- # 有值
- $param['option'][$k] = array('yes', '!=');
- //$param['option_' . $k] = 'null';
- } elseif ($v == 'no') {
- # 无值
- $param['option'][$k] = array('yes', '=');
- //$param['option_' . $k] = 'null';
- } elseif (strpos($v, '|')) {
- # 有无值或者自定义的值
- $temp = explode('|', $v);
- $param['option_' . $k] = $temp[1];
- if ($temp[0] == 'yes') {
- $param['option'][$k] = array('yes', '!=');
- $param['option'][$k . '_t1'] = array('yes-' . $k, '!=');
- } else {
- $param['option'][$k] = array('yes', '=', 'and(');
- $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
- }
- //$param['option_' . $k . '_t1'] = 'null';
- } else {
- # 自定义的值
- $param['option_' . $k] = $v;
- }
- }
- }
- }
- # 检索in
- $in = Dever::preInput('search_in_');
- if ($in) {
- $in_state = false;
- foreach ($in as $k => $v) {
- if ($v) {
- $v = ltrim(rtrim($v));
- unset($search[$k]);
- $k = str_replace('search_in_', '', $k);
- $param['option'][$k] = array('yes', 'in');
- $param['option_' . $k] = $v;
- # 设定检索高亮
- //$high[$k] = $v;
- $in_state = true;
- }
- }
- $this->search = true;
- }
- $fulltext = Dever::preInput('search_fulltext_');
- if ($fulltext) {
- $fulltext_state = false;
- foreach ($fulltext as $k => $v) {
- if ($v) {
- $v = ltrim(rtrim($v));
- unset($search[$k]);
- $k = str_replace('search_fulltext_', '', $k);
- $param['option_' . $k] = $v;
- # 设定检索高亮
- $high[$k] = $v;
- $fulltext_state = true;
- }
- }
- $this->search = true;
- }
- $linkage = Dever::preInput('search_linkage_');
- if ($linkage) {
- foreach ($linkage as $k => $v) {
- if ($v && $v != -1) {
- unset($search[$k]);
- $k = str_replace('search_linkage_', '', $k);
- if (isset($config['struct'][$k]['search_col'])) {
- $temp = explode(',', $config['struct'][$k]['search_col']);
- if (!is_array($v)) {
- $v = explode(',', $v);
- }
- foreach ($temp as $k1 => $v1) {
- if (isset($v[$k1]) && $v[$k1] != -1) {
- $param['option_' . $v1] = $v[$k1];
- }
- }
- } else {
- if (is_array($v)) {
- $v = implode(',', $v);
- }
-
- if ($v != -1) {
- $v = Dever::defaultValue($v);
- $param['option_' . $k] = $v;
- # 设定检索高亮
- $high[$k] = $v;
- }
- }
- }
- }
- $this->search = true;
- }
- $exp = Dever::preInput('search_exp_');
- if ($exp) {
- $k = $search['search_exp_col'];
- $v = $search['search_exp_value'];
- $v = ltrim(rtrim($v));
- $param['option_' . $k] = $v;
- $param['search_type'] = $search['search_exp_type'];
- $this->search = true;
- }
- $order = Dever::preInput('search_order_');
- if ($order) {
- foreach ($order as $k => $v) {
- $v = ltrim(rtrim($v));
- $k = str_replace('search_order_', '', $k);
- $param['order'][0][$k] = $v;
- unset($search[$k]);
- }
- }
- $set = Dever::preInput('set_');
- if ($set) {
- foreach ($set as $k => $v) {
- $v = ltrim(rtrim($v));
- $k = str_replace('set_', '', $k);
- $param[$k] = $v;
- }
- }
- foreach ($search as $k => $v) {
- if ($v) {
- if (is_string($v)) {
- $v = ltrim(rtrim($v));
- }
- if (strstr($k, '-') || strstr($k, '.')) {
- $k = str_replace('search_option_', '', $k);
- $struct = $config['struct'][$k];
- if (isset($struct['search_col']) && $struct['search_col']) {
- $param[$struct['search_col']] = $v;
- } elseif (isset($struct['sync']) && isset($struct['sync'][0])) {
- # 兼容旧版,之后去掉
- $temp = explode('-', $k);
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $struct['sync'][1] => $v));
- /*
- if ($v[$vi['sync'][0]] > 0) {
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
- } else {
- $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
- }*/
-
- if (isset($temp[2])) {
- $v = isset($load[$temp[2]]) ? $load[$temp[2]] : $struct['default'];
- $param[str_replace('search_', '', $k)] = $v;
- }
- }elseif (isset($struct['sync'])) {
- $struct['sync']['dever-read']['id'] = $v;
- $v = Dever::load($k, $struct['sync']);
- if (!$v) {
- $v = $struct['default'];
- }
- $param[str_replace('search_', '', $k)] = $v;
- }
- } elseif (strpos($k, 'dever_') !== false) {
- continue;
- } elseif (strpos($k, 'option_') !== false) {
- //Dever::setInput(str_replace('search_', '', $k), $v);
- if (is_array($v)) {
- if ($v[0] == 0) {
- continue;
- }
- $v = str_replace(',0', '', implode(',', $v));
- $t = explode(',', $v);
- $parent = end($t);
- $v .= '%';
- }
- $param[str_replace('search_', '', $k)] = $v;
- $this->search = true;
- } elseif ($k == 'search_limit') {
- $num = $this->getNumConfig($config);
- if ($num) {
- $param['page'][0] = $num[$v];
- }
- }
- }
- }
- return array($param, $high);
- }
- private function list_tbody_mul($config, $send)
- {
- $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
- $method = Dever::input('method');
- if (strstr($method, 'mul') && $mul && $mul['mul_type'] > 0) {
- if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
- Dever::alert('您还未选择任何数据条目');
- }
-
- Dever::config('base')->mul_type = $mul['mul_type'];
- unset($mul['mul_type']);
- $param = $send;
- if (isset($param['page'])) {
- unset($param['page']);
- }
- foreach ($mul as $k => $v) {
- if ($v) {
- if (is_array($v)) {
- $v = implode(',', $v);
- }
- $param[str_replace('mul_', '', $k)] = $v;
- if (strstr($k, 'mul_set_')) {
- $k = str_replace('mul_set_', '', $k);
- if (isset($config['struct'][$k]) && isset($config['struct'][$k]['mul_where'])) {
- $param = array_merge(Dever::prefix($config['struct'][$k]['mul_where'], 'option_'), $param);
- }
- }
- }
- }
- //print_r($param);die;
- if (isset($param)) {
- $data = Dever::db($this->project . '/' . $this->table)->getmul($param);
- if ($data) {
- Dever::config('base')->mul_data = array_keys($data);
- if (strstr($method, 'mul.')) {
- $url = str_replace('mul.', '', $method);
- if ($url) {
- $send = array();
- foreach ($param as $k => $v) {
- $send['search_' . $k] = $v;
- }
- $send['search_ids'] = implode(',', Dever::config('base')->mul_data);
- if (strstr($url, '?')) {
- $url .= '&' . http_build_query($send);
- } else {
- $url .= '?' . http_build_query($send);
- }
-
- Dever::alert($url, 2);
- }
- }
- $method = $this->project . '/' . $this->table . '-updatemul';
- $state = Dever::load($method, $param);
- }
- }
- Dever::alert('reload');
- }
- }
- /**
- * 列表页数据列表:图片形式
- *
- * @return array
- */
- public function list_photo()
- {
- $config = $this->config();
- $result = array();
- if (isset($config['manage']['photo'])) {
- $high = array();
-
- $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
- $param = array();
- $parent = 0;
- if ($search) {
- list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
- }
- if (empty($param['page'])) {
- $num = $this->getNumConfig($config);
- if ($num) {
- $param['page'][0] = $num[0];
- }
- }
- $method = $this->project . '/' . $this->table . '-list';
- $result = Dever::load($method, $param);
- if ($result) {
- foreach ($result as $k => $v) {
- $result[$k] = Dever::load($config['manage']['photo'], $v);
- $result[$k]['button'] = $this->list_tbody_button($config, $v, 'div');
- }
- }
- }
- return $result;
- }
- /**
- * 列表页数据列表:表格形式
- *
- * @return array
- */
- public function list_tbody($excel = false, $type = false)
- {
- $this->state = false;
- # 新增权限
- if (Dever::load('manage/auth.oper', 1) == false) {
- Dever::alert('你没有权限');
- }
- if (Dever::input('page_content') == 1) {
- return '';
- }
- $config = $this->config();
- $high = array();
-
- $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
- $param = array();
- $parent = 0;
- if ($search) {
- list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
- }
- $num = $this->getNumConfig($config);
- if (empty($param['page']) && $num) {
- $param['page'][0] = $num[0];
- }
- # 批量更新
- $this->list_tbody_mul($config, $param);
- $result = $return = array();
- if (isset($config['top_option']) && $config['top_option']) {
- if (isset($config['top_option'][0])) {
- foreach ($config['top_option'] as $k => $v) {
- if (isset($v['join'])) {
- $param['join'][] = $v['join'];
- $col = 't_2.' . $v['col'];
- $param['option']['state'] = 'yes-t_1.state';
- } else {
- $col = $v['col'];
- }
- if ($v['value']) {
- $param['option'][$v['col']] = array('yes-' . $col, 'in');
- $param[$v['col']] = $v['value'];
- }
- }
- } else {
- $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
- }
- }
- if (isset($config['manage']['company']) && is_array($config['manage']['company']) && isset($config['manage']['company']['join'])) {
- $param['join'][] = $config['manage']['company']['join'];
- }
- if ($excel == true) {
- $method = $this->project . '/' . $this->table . '-list';//all
- } else {
- $method = $this->project . '/' . $this->table . '-list';
- }
- //print_r($param);
- $data = Dever::load($method, $param);
- //print_r(Dever::sql());die;
- if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
- $parent = array();
- $child = array();
- foreach ($data as $k => $v) {
- if ($v[$config['name'] . '_id'] <= 0) {
- $parent[$k] = $v;
- } else {
- $v['name'] = '|-----' . $v['name'];
- $child[$v[$config['name'] . '_id']][$k] = $v;
- }
- }
- if ($parent) {
- $data = array();
- foreach ($parent as $k => $v) {
- $data[$v['id']] = $v;
- if (isset($child[$v['id']])) {
- foreach ($child[$v['id']] as $i => $j) {
- $data[$j['id']] = $j;
- }
- }
- }
- }
- } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
- $data = $this->tree($data, $config, -1);
- }
- if ($excel == true) {
- return $data;
- }
- if (Dever::input('page_type') == 1) {
- Dever::$global['manage']['list_data'] = $data;
- return;
- }
- //print_r($data);die;
- //print_r(Helper::page("current"));die;
- $this->manage_button = false;
- if ($data && isset($config['struct'])) {
- $i = 0;
- $pg = Dever::input('pg', 1);
- $cur = Dever::input('search_limit', 0);
-
- foreach ($data as $k => $v) {
- $data[$k] = $this->getAdminInfo($data[$k]);
- $data[$k]['i'] = $i;
- $ii = isset($num[$cur]) ? intval($num[$cur])*($pg-1) : 0;
- $data[$k]['r'] = $i+1+$ii;
- $result[$k] = '<tr>';
- $return[$i] = array();
- if (isset($config['manage']['mul']) && $config['manage']['mul']) {
- $mul_state = false;
- if ($config['manage']['mul'] && is_string($config['manage']['mul'])) {
- $mul_state = $this->value($config['manage']['mul'], $data[$k]);
- } else {
- $mul_state = true;
- }
- if ($mul_state) {
- $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="' . $v['id'] . '"/>';
- } else {
- $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="-1" disabled/>';
- }
- $result[$k] .= '<td>'.$checkbox.'</td>';
- $return[$i]['checkbox'] = $checkbox;
- }
- foreach ($config['struct'] as $ki => $vi) {
- if (isset($data[$k][$ki])) {
- $data[$k]['cur_value'] = $data[$k][$ki];
- }
-
- # 处理同步
- # 兼容处理,之后删除
- if (isset($vi['sync']) && (isset($vi['sync'][0]) && strpos($ki, '-'))) {
- $temp = explode('-', $ki);
- if ($v[$vi['sync'][0]] > 0) {
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
- } else {
- $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
- }
-
- if (isset($temp[2])) {
- $data[$k][$ki] = $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
- }
- } elseif (isset($vi['sync']) && (strstr($ki, '-') || strstr($ki, '.'))) {
- $vi['sync']['dever-read'] = $v;
- $v[$ki] = Dever::load($ki, $vi['sync']);
- if (!$v[$ki]) {
- $v[$ki] = $vi['default'];
- }
- $data[$k][$ki] = $v[$ki];
- }
- if (isset($vi['list']) && $vi['list']) {
- if (empty($v[$ki])) {
- $v[$ki] = isset($vi['default']) ? $vi['default'] : '';
- }
- # 处理权限
- if (isset($vi['auth'])) {
- $auth = $this->value($vi['auth'], $data[$k]);
- if (!$auth) {
- continue;
- }
- }
- $show = $v[$ki];
- if (is_string($vi['list'])) {
- $show = $this->value($vi['list'], $data[$k], $config['struct']);
- }
- if (isset($vi['key']) && $vi['update'] != 'editor') {
- $show = Dever::upload($show);
- }
- if (isset($vi['modal'])) {
- $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
- } elseif (isset($vi['option']) && !is_string($vi['list'])) {
- # 验证option是否是匿名函数
- if ((isset($vi['edit']) && $vi['edit'])) {
- $vi['option'] = $this->option($vi['option'], $vi['edit']);
- } else {
- $vi['option'] = $this->option($vi['option']);
- }
- # 位运算
- if (isset($vi['bit'])) {
- $ts = array();
- foreach ($vi['option'] as $tm => $tv) {
- if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
- $ts[] = $tv;
- }
- }
- $show = implode(',', $ts);
- }
- if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
- if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
- $show = $vi['option'][$show]['name'];
- } else {
- $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
- }
- }
- //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
- elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
- {
- $vi['name'] = 'up_col_' . $ki;
- $vi['value'] = $v[$ki];
- $m = 'select';
- if (isset($vi['update']) && $vi['update'] == 'group') {
- $m = 'group';
- }
- $show_edit = $this->value($vi['edit'], $data[$k], $config['struct']);
- if ($show_edit) {
- $show = Html::$m($vi, 'form-list', '', 'style="min-width: 100px;" data-old="'.$show.'" onchange="update($(this), \'' . $v['id'] . '\', \'' . $this->project . '\', \'' . $this->table . '\', \'\', \'' . $this->menu_id . '\')"');
- } else {
- if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
- $show = $vi['option'][$show]['name'];
- } else {
- $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
- }
- //$show = '';
- }
- } else {
- if (strstr($show, ',')) {
- $temp = explode(',', $show);
- $t = array();
- foreach ($temp as $vv) {
- if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
- $t[] = $vi['option'][$vv]['name'];
- } elseif(isset($vi['option'][$vv])) {
- $t[] = $vi['option'][$vv];
- } else {
- $t[] = $vv;
- }
- }
- $show = implode('<br />', $t);
- } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
- if (isset($vi['option'][$show]['style'])) {
- $vi['option'][$show]['name'] = '<font style="'.$vi['option'][$show]['style'].'">' . $vi['option'][$show]['name'] . '</font>';
- }
- $show = $vi['option'][$show]['name'];
-
- } else {
- $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
- }
- }
- }
- $text = $show;
- if ($high && isset($high[$ki])) {
- if (isset($v['s_' . $ki])) {
- $text = $v['s_' . $ki];
- $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
- $text = str_replace('</em>', '</font>', $text);
- } elseif (strlen($high[$ki]) > 1) {
- $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text, 1);
- }
- }
- if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
- //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
- $url = $this->url('updateAction');
- $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
- $text = '<span class="edit" data-col="' . $ki . '" data-url="' . $url . '" data-id="' . $v['id'] . '" data-project="' . $this->project . '" data-table="' . $this->table . '" data-content="' . $show . '" data-type="' . $vi['edit'] . '">'.$text.'</span>';
- $result[$k] .= '<td >' . $text . '</td>';
- if (isset($return[$i][$ki])) {
- $text = $return[$i][$ki] . $text;
- }
- $return[$i][$ki] = $text;
- } else {
- $result[$k] .= '<td>' . $text . '</td>';
- if (isset($return[$i][$ki])) {
- $text = $return[$i][$ki] . $text;
- }
- $return[$i][$ki] = $text;
- }
- if (isset($config['manage']['chart'])) {
- $this->chart($config['manage']['chart'], $ki, $return[$i][$ki], $vi);
- }
- }
- }
- $button = $this->list_tbody_button($config, $data[$k]);
- if ($button == '<td></td>') {
- $button = str_replace('<td></td>', '<td> </td>', $button);
- }
- $result[$k] .= $button;
- $return[$i]['manage'] = str_replace(array('<td>', '</td>'), '', $button);
- $result[$k] .= '</tr>';
- $i++;
- }
- }
- if ($result) {
- $this->state = true;
- $result = implode('', $result);
- if (!$this->manage_button) {
- $result = str_replace('<td> </td>', '', $result);
- }
- } else {
- $result = '';
- }
- if ($type) {
- return $return;
- }
- return $result;
- }
- private function list_tbody_button($config, $data, $type = 'td')
- {
- if (isset($data['cur_value'])) {
- unset($data['cur_value']);
- }
- $result = '';
- $auth = Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false;
- if (isset($config['manage']['_list']['value']['list']) && isset($config['manage']['_list']['value']['list'][0]) && $config['manage']['_list']['value']['list'][0] == '查看详情') {
- $auth = true;
- }
- if ($auth && isset($config['manage']['_list']['value'])) {
- //if (isset($config['manage']['_list']['value'])) {
- $result = '<'.$type.'>';
- if ($config['state'] == 2) {
- if (isset($config['manage']['_list']['value']['update'])) {
- unset($config['manage']['_list']['value']['update']);
- }
- if (isset($config['manage']['_list']['value']['delete'])) {
- $config['manage']['_list']['value']['delete'] = '恢复';
- }
- }
- $suffix = '';
- if (isset($config['manage']['link'])) {
- $suffix = $config['manage']['link'];
- }
- foreach ($config['manage']['_list']['value'] as $kj => $vj) {
-
- $pj = false;
- $h = '<span class="am-icon-pencil-square-o"></span>';
- if (strstr($kj, 'new') || strstr($kj, 'location') || strstr($kj, 'list')) {
- $oper = true;
- } elseif ($kj == 'delete') {
- $oper = Dever::load('manage/auth.oper', 5);
- $h = '<span class="am-icon-trash-o"></span>';
- } else {
- $oper = Dever::load('manage/auth.oper', 3);
- }
- if (is_array($vj) && isset($vj[1])) {
- if (isset($vj[2])) {
- $oper = $this->value($vj[2], $data);
- }
- if ($oper && strpos($vj[1], 'modal|') === false) {
- $pj = $this->value($vj[1], $data);
- $vjn = $vj[0];
- }
- } else {
- $vjn = $vj;
- }
- # 增加细分权限
- if ($config && isset($config['manage']['auth']) && $config['manage']['auth'] && !Dever::load('manage/auth.check', $config['lang'] . '-' . $vjn, $this->menu_id)) {
- continue;
- }
- if ($oper == true) {
- $this->manage_button = true;
- if ($kj == 'delete') {
- $class = 'layui-btn layui-btn-danger';
- } else {
- $class = 'layui-btn';
- }
- if (layadmin()) {
- $class .= ' layui-btn-xs';
- }
- if (strpos($kj, 'fast_list') !== false) {
- if (!isset($vj[3])) {
- $vj[3] = '';
- }
-
- $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('list', $data['id'], $pj, $suffix) . '\', \''.$vj[0].'\', \''.$vj[3].'\', 1, 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'fast_add') !== false) {
- if (!isset($vj[3])) {
- $vj[3] = '';
- }
-
- $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('update', false, $pj, $suffix) . '\', \''.$vj[0].'\', \''.$vj[3].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'fast') !== false) {
- if (!isset($vj[3])) {
- $vj[3] = '';
- }
-
- $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('update', $data['id'], $pj, $suffix) . '\', \''.$vj[0].'\', \''.$vj[3].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'edits') !== false) {
- if (!isset($vj[1])) {
- $vj[1] = '';
- }
- $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url($kj, $data['id'], false, $suffix) . '\', \''.$vj[0].'\', \''.$vj[1].'\', 1)"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'copy') !== false) {
- $vj[1] = $this->value($vj[1], $data);
- $vj[1] = Dever::load($vj[1]);
- $result .= '<a style="cursor:pointer" data-clipboard-text="'.$vj[1].'" class="clipboard"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'edit') !== false) {
- if (!isset($vj[1])) {
- $vj[1] = '';
- }
- if (strstr($vj[1], 'http')) {
- $url = $vj[1] . '&id=' . $data['id'];
- } else {
- $url = $this->url($kj, $data['id'], false, $suffix);
- }
- $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $url . '\', \''.$vj[0].'\', \''.$vj[1].'\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'location') !== false) {
- if (!isset($vj[1])) {
- $vj[1] = '';
- }
- if (strstr($vj[1], 'http')) {
- $url = $vj[1] . '&id=' . $data['id'];
- } else {
- $url = $this->url($kj, $data['id'], false, $suffix);
- }
- $result .= '<a href="'.$url.'"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'oper') !== false) {
- $content = '';
- $title = '';
- if (isset($vj[3])) {
- $content = $this->value($vj[3], $data);
- }
- if (isset($vj[4])) {
- $title = $vj[4];
- }
- $url = Dever::url($pj) . '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $vj[0];
- $result .= '<a href="javascript:;" onclick="load(\'' . $url . '\', \'' . $content . '\', \'' . $title . '\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $vj[0] . '</button></a> ';
- } elseif (strpos($kj, 'new') !== false) {
- if (!isset($vj[1])) {
- $vj[1] = '';
- }
- if (!isset($vj[2])) {
- $vj[2] = '';
- }
- if (strstr($vj[1], 'http')) {
- $url = $vj[1] . '&id=' . $data['id'];
- } elseif($vj[2]) {
- $url = Dever::url($this->value($vj[1], $data), $vj[2]);
- } else {
- $url = $this->url($kj, $data['id'], false, $suffix);
- }
- $result .= '<a href="' . $url . '" target="_blank" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $h . $vjn . '</button></a> ';
- } elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
- $t = explode('|', $vj[1]);
- $result .= '<a href="#dever_modal" data-toggle="modal" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'" onclick=' . $t[1] . ' msg-send="' . $this->value($t[2], $data) . '">' . $vj[0] . '</a> ';
- } elseif (isset($vj[1]) || $kj == 'delete') {
- $result .= '<a href="' . $this->url($kj, $data['id'], $pj, $suffix) . '" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $h . $vjn . '</button></a> ';
- } elseif ($vj) {
- $result .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
- }
- }
- }
- $result .= '</'.$type.'>';
- }
- return $result;
- }
- /**
- * 多级分类
- *
- * @return array
- */
- private function tree($data, $config, $parent = 0)
- {
- $key = $config['name'] . '_id';
- $result = array();
- $this->treeData($data, $result, $key, $parent);
- return $result;
- }
- private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
- {
- if (empty($array)) {
- return;
- }
- $level++;
- foreach ($array as $k => $v) {
- if ((isset($v[$key]) && $v[$key] == $parent_id) || (isset($v['parent_id']) && $v['parent_id'] == $parent_id)) {
- $v['level'] = $level;
- $v['name'] = $this->treeName($v['name'], $level);
- $result[] = $v;
- unset($array[$k]);
- $this->treeData($array, $result, $key, $v['id'], $level);
- }
- }
- }
- private function treeName($name, $level = 1)
- {
- $string = '';
- if ($level > 1) {
- /*
- $num = 4;
- $string = '-';
- //STR_PAD_LEFT
- $string = str_pad('|', $level * $num, $string);
- */
- $string = str_repeat(' ',$level-1);
- $string .= '|—';
- }
- return $string . $name;
- }
- /**
- * 列表页批量管理
- *
- * @return array
- */
- public function list_mul()
- {
- # 新增权限:更新权限
- if (Dever::load('manage/auth.oper', 3) == false) {
- return '';
- }
- $config = $this->config();
- $result = '';
- if ($this->state && isset($config['struct']) && isset($config['manage']['mul']) && $config['manage']['mul']) {
- $mul = Dever::preInput('mul_');
- $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
- $btn = '<button class="btn btn-danger layui-btn layui-btn-danger" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list') . '\');list_mul($(this), 1)" type="button" style="height: 38px;margin-left:10px;">批量操作</button>';
- $prefix = 'mul_';
- $result .= $node[0];
- $default = 0;
- $option = array
- (
- 1 => '本页选中的数据',
- );
- # 只有当有搜索条件时才会出现
- if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
- $option[2] = '所有页面的数据';
- $default = 2;
- }
- $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择要批量操作的数据', $option, $default);
- $state = false;
- foreach ($config['struct'] as $k => $v) {
- if ($k == 'state' && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
- $v['option'] = Dever::config('base')->state;
- if ($this->getState() == 2) {
- unset($v['option'][2]);
- } else {
- unset($v['option'][1]);
- }
-
- $v['edit'] = true;
- }
- $select = false;
- if (isset($v['mul'])) {
- $select = $v['mul'];
- $state = true;
- } elseif (isset($v['edit'])) {
- $select = $v['edit'];
- }
- if ($select) {
- if (isset($v['mul_option']) && (is_array($v['mul_option']) || is_object($v['mul_option']))) {
- $result .= ' ';
- $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['mul_option'], $select), $v['default']);
- } elseif (isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
- $result .= ' ';
- $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option'], $select), $v['default']);
- }
- }
- }
- if ($state) {
- $result .= $btn . $node[1];
- } else {
- $result = '';
- }
- }
- //print_r($result);die;
- return $result;
- }
- private function value($value, $data, $struct = array())
- {
- if (!$data) {
- return $value;
- }
- if (isset($data['cur_value'])) {
- if ($value == 'time') {
- return $data['cur_value'] ? date('Y-m-d H:i', $data['cur_value']) : '-';
- } elseif (!strstr($value, 'Dever') && !strstr($value, '&') && !strstr($value, '<br />') && !strstr($value, '{') && (strstr($value, '/') || strstr($value, '.'))) {
- return $data['cur_value'] ? Dever::load($value, $data['cur_value']) : '-';
- }
- }
-
- if (strstr($value, '={') && !strstr($value, '"')) {
- $value = '"' . $value . '"';
- }
- if (is_string($data)) {
- $eval = '$value = ' . $value . ';';
- eval($eval);
- return $value;
- }
- if ($value == 'table' && $struct) {
- $result = $this->struct_data($struct, $data);
- $value = Dever::table($result);
- } elseif (strpos($value, '{') !== false && strpos($value, '{"') === false) {
- # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
- //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
- $func = function ($r) use ($data) {
- if (isset($data[$r[1]])) {
- return $data[$r[1]];
- }
- return false;
- };
- $value = preg_replace_callback('/{(.*?)}/', $func, $value);
- if (strstr($value, '<script>')) {
- $value = str_replace('<script>', '<script>$(document).ready(function(){', $value);
- $value = str_replace('</script>', '});</script>', $value);
- }
- $eval = '$value = ' . $value . ';';
- eval($eval);
- }
- return $value;
- }
- /**
- * update
- *
- * @return array
- */
- public function update()
- {
- $config = $this->config();
- $data = array();
- if ($this->id) {
- # 新增权限
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- $auth = 1;
- } else {
- $auth = 3;
- }
- if (Dever::load('manage/auth.oper', $auth) == false) {
- Dever::alert('你没有权限');
- }
- $data = $this->load('one', $this->id);
- } else {
- # 新增权限
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- $auth = 1;
- } else {
- $auth = 4;
- }
- if (Dever::load('manage/auth.oper', $auth) == false) {
- Dever::alert('你没有权限');
- }
- }
- $data = $this->getAdminInfo($data);
- $col = Dever::input('col');
- $result = $this->update_struct($config, $col, $data);
- //print_r($result);die;
- return $result;
- }
- public function update_content()
- {
- $config = $this->config();
- $data = array();
- if ($this->id) {
- # 新增权限
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- $auth = 1;
- } else {
- $auth = 3;
- }
- if (Dever::load('manage/auth.oper', $auth) == false) {
- Dever::alert('你没有权限');
- }
- $data = $this->load('one', $this->id);
- } else {
- # 新增权限
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- $auth = 1;
- } else {
- $auth = 4;
- }
- if (Dever::load('manage/auth.oper', $auth) == false) {
- Dever::alert('你没有权限');
- }
- }
- $data = $this->getAdminInfo($data);
- $col = Dever::input('col');
- Dever::setInput('ajax', 1);
- $result = '<div class="layui-col-md12"><div class="layui-card" {style}><div class="layui-card-body">';
- $desc = Dever::load('manage/database.info#updateDesc');
- if ($desc) {
- if (is_object($desc)) {
- $function = $desc;
- $desc = $function();
- }
- $result .= $desc;
- }
- if (isset($config['manage']['lang']) && $this->lang_set) {
- $result .= '<div class="layui-tab layui-tab-card"><ul class="layui-tab-title">';
- $tab = '<div class="layui-tab-content">';
- $i = 0;
- if ($col) {
- $col = explode(',', $col);
- $config['manage']['lang'] = explode(',', $config['manage']['lang']);
- $config['manage']['lang'] = array_intersect($config['manage']['lang'], $col);
- $config['manage']['lang'] = implode(',', $config['manage']['lang']);
- $col = implode(',', $col);
- }
- foreach (Dever::config('base')->lang_set as $k => $v) {
- if ($i == 0) {
- $prefix = '';
- } else {
- $prefix = $k;
- $col = $config['manage']['lang'];
- //$prefix = 'l-l' . $k . 'l-l';
- //$data = $this->load('one', $this->id, $this->table . '__' . $k);
- }
- if (isset($config['manage']['tab']) && $config['manage']['tab']) {
- $content = '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
- $tab_content = '<div class="layui-tab-content">';
- $j = 0;
- foreach ($config['manage']['tab'] as $k1 => $v1) {
- $html = $this->update_struct($config, $col, $data, $k1, $prefix);
- if ($html) {
- $class_0 = $class_1 = '';
- if ($j == 0) {
- $class_0 = 'layui-this';
- $class_1 = 'layui-show';
- }
- $content .= '<li class="'.$class_0.'">'.$v1.'</li>';
- $tab_content .= '<div class="layui-tab-item '.$class_1.'">'.$html.'</div>';
- $j++;
- }
- }
- $tab_content .= '</div>';
- $content .= '</ul>' . $tab_content . '</div>';
- if ($content) {
- $class_0 = $class_1 = '';
- if ($i == 0) {
- $class_0 = 'layui-this';
- $class_1 = 'layui-show';
- }
- $result .= '<li class="'.$class_0.'">'.$v.'</li>';
- $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
- $i++;
- }
- } else {
- $content = $this->update_struct($config, $col, $data, -1, $prefix);
- if ($content) {
- $class_0 = $class_1 = '';
- if ($i == 0) {
- $class_0 = 'layui-this';
- $class_1 = 'layui-show';
- }
- $result .= '<li class="'.$class_0.'">'.$v.'</li>';
- $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
- $i++;
- }
- }
- }
- $tab .= '</div>';
- $result .= '</ul>' . $tab . '</div>';
- } elseif (isset($config['manage']['tab']) && $config['manage']['tab']) {
- $result .= '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
- $tab = '<div class="layui-tab-content">';
- $i = 0;
- foreach ($config['manage']['tab'] as $k => $v) {
- $content = $this->update_struct($config, $col, $data, $k);
- if ($content) {
- $class_0 = $class_1 = '';
- if ($i == 0) {
- $class_0 = 'layui-this';
- $class_1 = 'layui-show';
- }
- $result .= '<li class="'.$class_0.'">'.$v.'</li>';
- $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
- $i++;
- }
- }
- $tab .= '</div>';
- $result .= '</ul>' . $tab . '</div>';
- } else {
- $result .= $this->update_struct($config, $col, $data);
- }
- if (isset($this->card) && $this->card) {
- $result = str_replace('{style}', 'style="display:none"', $result);
- }
- $button = '';
- if (Dever::input('fast') != 1) {
- $button = '<div class="layui-card-body" id="update_button"><div class="layui-form-item">' . $this->update_button() . '</div></div>';
- } else {
- if (isset($config['manage']['update_save']) && !$config['manage']['update_save']) {
- $button = '<div class="dever_no_save" style="display:none;"></div>';
- }
- }
- $result .= '</div>'.$button.'</div></div>';
- //print_r($result);die;
- return $result;
- }
- public function update_struct($config, $col, $data, $tab = -1, $prefix = '', $layadmin = false, $show = true)
- {
- if (!$layadmin) {
- $layadmin = layadmin();
- }
- $result = array();
- $upload_call = '';
- if (isset($config['manage']['upload'])) {
- $upload_call = $this->value($config['manage']['upload'], $data);
- }
- foreach ($config['struct'] as $k => $v) {
- if (isset($config['manage']['lang']) && $this->lang_set && isset($v['sync']) && (strstr($k, '-') || strstr($k, '.'))) {
- continue;
- }
- $state = false;
- if ($tab == 0) {
- if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
- $state = true;
- }
- } elseif ($tab > 0) {
- if (isset($v['tab']) && $v['tab'] == $tab) {
- $state = true;
- }
- } else {
- $state = true;
- }
- if (isset($v['update']) && $v['update'] && $state) {
- if ($col && !strstr(',' . $col . ',', ',' . $k . ',')) {
- continue;
- }
- //处理权限
- if (isset($v['auth'])) {
- $auth = $this->value($v['auth'], $data);
- if (!$auth) {
- continue;
- }
- }
- $index = $k;
- if ($prefix && !strstr($k, '-')) {
- $k = $prefix . '_' . $k;
- }
- # 处理show模式下的class
- $class = $this->update_class($k, $v, '', $data);
- $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
- $style = '';
- if ($col && $v['update'] == 'hidden') {
- $style = 'style="display:none"';
- }
- if ($v['update'] == 'sku') {
- $class = $class . ' layui-tab-card';
- $style = 'style="padding: 10px;"';
- }
- if ($layadmin) {
- $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div classs="layui-col-lg6">';
- if (is_array($v['update'])) {
- $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div class="layui-tab layui-tab-card">';
- }
- }
- if (!$show) {
- $result[$k] = '<div classs="layui-col-lg6">';
- }
- if ($upload_call) {
- $v['upload_call'] = $upload_call . '&key=' . $k;
- }
- if (isset($config['manage']['sku']) && $v['update'] == 'sku') {
- $v['sku'] = $config['manage']['sku'];
- $v['data'] = $data;
- }
- $result[$k] .= $this->create_update_html($k, $v, $data, false, $prefix);
- if (!$show) {
- $result[$k] .= '</div>';
- } else {
- $result[$k] .= '</div></div>';
- }
- } elseif (!$col && isset($v['class'])) {
- # 分割线
- $v['name'] = $this->value($v['name'], array('test' => 1));
- if (isset($v['right'])) {
- $this->card_right = true;
- }
- $this->card = true;
- $result[$k] = Html::hr($v);
- }
- }
- if (Dever::input('ajax') == 1) {
- return implode('', $result);
- }
- return $result;
- }
- public function card()
- {
- if (isset($this->card_right)) {
- return 'layui-col-md6';
- }
- return 'layui-col-md12';
- }
- public function layui_card()
- {
- if (isset($this->card)) {
- return false;
- }
- return true;
- }
- /**
- * update_class
- *
- * @return string
- */
- public function update_class($name, $param, $prefix = '', $data = array())
- {
- $class = '';
- $key = 'show';
- if (isset($param[$key]) && $param[$key]) {
- $parent = array();
- $child = array();
- if (is_string($param[$key])) {
- parse_str($param[$key], $param[$key]);
- }
- if (is_array($param[$key])) {
- foreach ($param[$key] as $k => $v) {
- if ($k == 'no') {
- $child[$k . '_' . $v] = $key . '_no';
- } elseif (strstr($v, '/')) {
- $parent[$k] = $key . '_' . $k;
- $k = $k . '_ajax';
- $value = '';
- if (isset($data[$name])) {
- $value = $data[$name];
- }
- $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
- $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
- } else {
- if (strpos($v, ',')) {
- $temp = explode(',', $v);
- foreach ($temp as $v1) {
- $show = $k . '_' . $v1;
- if ($prefix) {
- $k = str_replace($name, $k, $prefix);
- $show = str_replace($name, $show, $prefix);
- }
- $parent[$k] = $key . '_' . $k;
- $child[$show] = $key . '_' . $show;
- }
- } else {
- $show = $k . '_' . $v;
- if ($prefix) {
- $k = str_replace($name, $k, $prefix);
- $show = str_replace($name, $show, $prefix);
- }
- $parent[$k] = $key . '_' . $k;
- $child[$show] = $key . '_' . $show;
- }
- }
- }
- }
- $class = implode(' ', $parent) . ' ' . implode(' ', $child);
- }
- if (isset($param['control'])) {
- $class .= ' ' . $key . '_input';
- }
- if (isset($param['control_url'])) {
- $class .= ' control_url';
- }
- return $class;
- }
- /**
- * update_html
- *
- * @return string
- */
- public function create_update_html($key, $value, $data = array(), $index = false, $prefix = '')
- {
- $result = '';
- $this->update_key($key, $value);
- $value['ext'] = $value['col'] = $key;
- $value['update'] = $value['update'] ? $value['update'] : 'text';
- if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
- $value['value'] = $value['update'];
- $value['update'] = 'hidden';
- }
- if (!$index) {
- $index = $key;
- }
- $this->update_html($value, $key, $index, $data, $result, $prefix);
- return $result;
- }
- private function update_key(&$key, &$value)
- {
- $value['source_key'] = $key;
- if (strstr($key, '/')) {
- if (strstr($key, '-')) {
- $temp = explode('-', $key);
- $value['api'] = $temp[0];
- $value['method'] = $temp[1];
- } else {
- $value['api'] = $key;
- }
- $key = str_replace('/', '--', $key);
- }
- }
- /**
- * update_html
- *
- * @return string
- */
- public function update_html($param, $key, $index, $data, &$result, $prefix = '', $ext = 'update')
- {
- if (isset($param['match']) && $param['match'] != 'option') {
- if (is_string($param['match']) && strpos($param['match'], '/') !== false) {
- if (strstr($param['match'], 'option||')) {
- $param['valid'] = 'validate[custom[' . $key . ']]';
- } else {
- $param['valid'] = 'validate[required,custom[' . $key . ']]';
- }
- } else {
- $param['valid'] = 'validate[required]';
- }
- }
-
- if (isset($param['name']) && $param['name'] && isset($param['update']) && $param['update'] != 'hidden' && $param['update'] != 'load') {
- $result .= Html::pageLeft($param);
- }
- if ($param['update']) {
- $order = true;
- # 名称带前缀
- $param['name'] = $ext . '_' . $param['ext'];
- $param['index'] = $index;
- //$param['value'] = '';
- # 得到当前的值
- //if (isset($data[$index]) && !isset($param['value'])) {
- if (isset($data[$index])) {
- $param['value'] = $data[$index];
- }
- # 得到下级的值
- if (isset($param['child_value']) && isset($data['id'])) {
- $param['child_value'] = $this->value($param['child_value'], $data);
- }
- # 验证option是否是匿名函数
- if (isset($param['option'])) {
- $param['option'] = $this->option($param['option']);
- }
- if (isset($data[$index]) && !isset($param['value']) && isset($param['key']) && $param['update'] != 'editor') {
- $param['value'] = Dever::upload($data[$index]);
- }
- # 处理下级字段
- if (isset($param['child'])) {
- $param['child'] = $this->option($param['child']);
- if (isset($data[$key . '_parent'])) {
- $param['parent_value'] = $data[$key . '_parent'];
- }
- }
- # 设置默认值
- if (isset($param['default'])) {
- $param['default'] = $this->option($param['default']);
- }
- # 处理关联数据 兼容处理,以后删除
- if (isset($param['sync']) && isset($param['sync'][0]) && strpos($key, '-') && $param['update'] != 'load') {
- $temp = explode('-', $key);
- if (isset($data[$param['sync'][0]])) {
- if (isset($temp[2])) {
- $m = 'one';
- } else {
- $m = 'select';
- }
- if ($data[$param['sync'][0]] > 0) {
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-' . $m, array('option_' . $param['sync'][1] => $data[$param['sync'][0]], 'orders' => array('id' => 'asc')));
- } else {
- $load = Dever::load($temp[0] . '/' . $temp[1] . '-' . $m, array('option_' . $param['sync'][3] => $data[$param['sync'][2]], 'option_' . $param['sync'][4] => $data[$param['sync'][0]], 'orders' => array('id' => 'asc')));
- }
- if ($m == 'one') {
- $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
- } else {
- $param['value'] = $load;
- }
- }
- if (!isset($temp[2]) && is_array($param['update'])) {
- $order = false;
- if (isset($param['update'][0]) && is_string($param['update'][0]) && strstr($param['update'][0], '.')) {
- if (isset($param['update'][1]) && $param['update'][1]) {
- $param['update_load'] = $param['update'][0];
- $param['update'] = 'load';
- } else {
- $param['update'] = Dever::load($param['update'][0]);
- }
- } else {
- $config = Dever::db($temp[0] . '/' . $temp[1])->config;
- $param['update'] = $config['struct'];
- }
-
- if (isset($config['manage']['tab'])) {
- $param['prefix'] = $prefix;
- $param['tab_config'] = $config['manage']['tab'];
- if (isset($config['manage']['lang'])) {
- $param['lang'] = $config['manage']['lang'];
- }
- }
- //$param['value'] = Dever::db($temp[0] . '/' . $temp[1]);
- }
- } elseif (isset($param['sync']) && isset($param['api']) && $param['update'] != 'load') {
- $param['sync']['dever-read'] = $data;
- if (is_array($param['update'])) {
- $param['value'] = Dever::load($param['api'], $param['sync']);
- $order = false;
- if (isset($param['update'][0]) && is_string($param['update'][0]) && strstr($param['update'][0], '.')) {
- if (isset($param['update'][1]) && $param['update'][1]) {
- $param['update_load'] = $param['update'][0];
- $param['update'] = 'load';
- } else {
- $param['update'] = Dever::load($param['update'][0]);
- }
- } else {
- $config = Dever::db($param['api'])->config;
- $param['update'] = $config['struct'];
- }
-
- if (isset($config['manage']['tab'])) {
- $param['prefix'] = $prefix;
- $param['tab_config'] = $config['manage']['tab'];
- if (isset($config['manage']['lang'])) {
- $param['lang'] = $config['manage']['lang'];
- }
- }
- } elseif (strstr($param['api'], '.')) {
- $param['value'] = Dever::load($param['api'], $param['sync']);
- } elseif (isset($param['method'])) {
- $param['value'] = Dever::load($param['api'] . '-' . $param['method'], $param['sync']);
- }
- }
- $method = $param['update'];
- if (is_array($method)) {
- $c = '';
- if (layadmin()) {
- $c = 'layui-tab-title';
- }
- $delete = true;
- if (isset($param['update_type']) && $param['update_type'] == 2) {
- $table = '<style>.layui-table .layui-input, .layui-table .xm-select-parent{width:100%}</style>';
- $table .= '<table class="layui-table">';
- $table_header = '<thead><tr>';
- $table_body = '<tbody>';
- $table_key = '';
- if (isset($param['option'])) {
- $param['value'] = $param['value'] + $param['option'];
- $table_key = '1';
- if (isset($param['value']) && $param['value']) {
- $table_body .= '<tr class="table_copy" style="display:none;">';
- $table_up = 'dever_up';
- } else {
- $table_body .= '<tr>';
- $table_up = 'update';
- }
- } else {
- $table_body .= '<tr class="table_copy" style="display:none;">';
- $table_key = '-1';
- $table_up = 'dever_up';
- }
- if ($table_key) {
- foreach ($param['update'] as $hk => $hv) {
- if (isset($hv['col'])) {
- $hk = $hv['col'];
- }
- $this->update_key($hk, $hv);
- if ($this->id && $hk === 'id') {
- $hv['update'] = 'hidden';
- }
- if (isset($hv['update']) && $hv['update'] && (!isset($hv['tab']) || (isset($hv['tab']) && $hv['tab'] <= 0))) {
- $n = $hv['name'];
- unset($hv['name']);
- $s = '';
- $hv['ext'] = $param['name'] . '_c_'.$table_key.'_i_' . $hk;
- if ($hv['update'] == 'linkage') {
- $hv['update_width'] = '30%';
- }
- $this->update_html($hv, $hk, $hk, array(), $s, '', $table_up);
- if ($hv['update'] == 'hidden') {
- $table_header .= '<td style="display:none;">'.$n.'</td>';
- $table_body .= '<td style="display:none;">'.$s.'</td>';
- } else {
- $table_header .= '<td>'.$n.'</td>';
- $table_body .= '<td>'.$s.'</td>';
- }
- }
- }
- if ($table_key == '-1') {
- $table_header .= '<td>操作</td>';
- $table_body .= '<td><a href="javascript:;" onclick="var self = $(this);var index = layer.confirm(\'确定进行此项操作吗?\', function(i, l){self.parent().parent().remove();layer.close(index);});" class="layui-btn layui-btn-xs">删除</a></td>';
- }
- $table_body .= '</tr>';
- }
-
- $total = array();
- if (isset($param['value']) && $param['value']) {
- if (!is_array($param['value'])) {
- $param['value'] = Dever::json_decode($param['value']);
- }
- foreach ($param['value'] as $bk => $bv) {
- $table_body .= '<tr id="'.$param['name'] . '_c_'.$bk.'">';
- foreach ($param['update'] as $hk => $hv) {
- if (isset($hv['col'])) {
- $hk = $hv['col'];
- }
- $this->update_key($hk, $hv);
- if ($this->id && $hk === 'id') {
- $hv['update'] = 'hidden';
- }
- if (isset($hv['update']) && $hv['update'] && (!isset($hv['tab']) || (isset($hv['tab']) && $hv['tab'] <= 0))) {
- unset($hv['name']);
- $s = '';
- $hv['ext'] = $param['name'] . '_c_' . $bk . '_i_' . $hk;
- if ($hv['update'] == 'linkage') {
- $hv['update_width'] = '30%';
- }
- $hv = $this->update_html($hv, $hk, $hk, $bv, $s);
- if (isset($param['update_show']) && $param['update_show'] && is_array($param['update_show'])) {
- if (isset($param['update_show'][$hv['source_key']])) {
- if (!isset($total[$hv['source_key']])) {
- $total[$hv['source_key']] = array($hv['desc'], $param['update_show'][$hv['source_key']], 0);
- }
- $total[$hv['source_key']][2] += $hv['value'];
- }
- }
- if ($hv['update'] == 'hidden') {
- $table_body .= '<td style="display:none;">'.$s.'</td>';
- } else {
- $table_body .= '<td>'.$s.'</td>';
- }
- }
- }
- if ($table_key == '-1') {
- if (isset($param['api'])) {
- $del_table = $param['api'];
- $del_id = Dever::encode($bv['id']);
- $table_body .= '<td><a href="javascript:;" onclick="var self = $(this);var index = layer.confirm(\'确定进行此项操作吗?\', function(i, l){var p = self.parent().parent();var url=config.host+\'api.del\';$.post(url, {table:\''.$del_table.'\', id:\''.$del_id.'\'});p.remove();layer.close(index);});" class="layui-btn layui-btn-xs">删除</a></td>';
- } else {
- $table_body .= '<td><a href="javascript:;" onclick="var self = $(this);var index = layer.confirm(\'确定进行此项操作吗?\', function(i, l){var p = self.parent().parent();p.remove();layer.close(index);});" class="layui-btn layui-btn-xs">删除</a></td>';
- }
-
- }
- $table_body .= '</tr>';
- }
- } else {
- if (isset($param['update_show']) && $param['update_show'] && is_array($param['update_show'])) {
- foreach ($param['update_show'] as $uk => $uv) {
- if (isset($param['update'][$uk])) {
- if (!isset($total[$uk])) {
- $total[$uk] = array($param['update'][$uk]['desc'], $uv, 0);
- }
- }
- }
- }
- }
- $table_body .= '</tbody>';
- $table_header .= '</tr></thead>';
- $table .= $table_body . $table_header;
- $table .= '</table>';
- $result .= $table;
- if ($total) {
- $result .= '<section class="border-b" style="padding: 10px;display: inline-block;">';
- foreach ($total as $k => $v) {
- $result .= '<span>'.$v[0].':<span id="'.$v[1].'">'.$v[2].'</span></span> ';
- }
- $result .= '</section>';
- }
- } elseif (isset($param['update_type']) && $param['update_type'] == 3) {
- $table = '<style>.layui-table .layui-input, .layui-table .xm-select-parent{width:100%}</style>';
- $table .= '<table class="layui-table">';
- $table_header = '<thead><tr>';
- $table_body = '<tbody>';
- $table_body .= '<tr class="table_copy" style="display:none;">';
- foreach ($param['update'] as $hk => $hv) {
- if (isset($hv['col'])) {
- $hk = $hv['col'];
- }
- $this->update_key($hk, $hv);
- if ($this->id && $hk === 'id') {
- $hv['update'] = 'hidden';
- }
- if (isset($hv['update']) && $hv['update'] && (!isset($hv['tab']) || (isset($hv['tab']) && $hv['tab'] <= 0))) {
- $n = $hv['name'];
- unset($hv['name']);
- $s = '';
- $hv['ext'] = $param['name'] . '_c_-1_i_' . $hk;
- if ($hv['update'] == 'linkage') {
- $hv['update_width'] = '30%';
- }
- $this->update_html($hv, $hk, $hk, array(), $s, '', 'dever_up');
- if ($hv['update'] == 'hidden') {
- $table_header .= '<td style="display:none;">'.$n.'</td>';
- $table_body .= '<td style="display:none;">'.$s.'</td>';
- } else {
- $table_header .= '<td>'.$n.'</td>';
- $table_body .= '<td>'.$s.'</td>';
- }
- }
- }
- $table_body .= '</tr>';
- if (isset($param['value']) && $param['value']) {
- if (!is_array($param['value'])) {
- $param['value'] = Dever::json_decode($param['value']);
- }
- foreach ($param['value'] as $bk => $bv) {
- $table_body .= '<tr>';
- foreach ($param['update'] as $hk => $hv) {
- if (isset($hv['col'])) {
- $hk = $hv['col'];
- }
- $this->update_key($hk, $hv);
- if ($this->id && $hk === 'id') {
- $hv['update'] = 'hidden';
- }
- if (isset($hv['update']) && $hv['update'] && (!isset($hv['tab']) || (isset($hv['tab']) && $hv['tab'] <= 0))) {
- unset($hv['name']);
- $s = '';
- $hv['ext'] = $param['name'] . '_c_' . $bk . '_i_' . $hk;
- if ($hv['update'] == 'linkage') {
- $hv['update_width'] = '30%';
- }
- if ($hv['update'] != 'hidden') {
- $hv['update_type'] = $hv['update'];
- $hv['update'] = 'show';
- }
- $this->update_html($hv, $hk, $hk, $bv, $s);
- if ($hv['update'] == 'hidden') {
- $table_body .= '<td style="display:none;">'.$s.'</td>';
- } else {
- $table_body .= '<td>'.$s.'</td>';
- }
- }
- }
- $table_body .= '</tr>';
- }
- }
- $table_body .= '</tbody>';
- $table_header .= '</tr></thead>';
- $table .= $table_body . $table_header;
- $table .= '</table>';
- $result .= $table;
- } else {
- if (isset($param['option'])) {
- $delete = false;
- $result .= '<ul class="nav nav-tabs '.$c.'" style="height:100%;">{tab}</ul>';
- $order = array
- (
- 'col' => $key,
- 'name' => $param['desc'],
- 'default' => '1',
- 'desc' => $param['desc'],
- 'match' => 'is_string',
- 'update' => 'hidden',
- 'option' => $param['option']
- );
- array_unshift($method, $order);
- if (isset($param['value']) && $param['value']) {
- $value = $param['value'];
- if (!is_array($value)) {
- $value = Dever::json_decode($value);
- }
- $param['value'] = array();
- if (!$value) {
- foreach ($param['option'] as $k => $v) {
- if (isset($v['name'])) {
- $v = $v['name'];
- }
- $param['value'][$v]['main_' . $key] = $k;
- }
- } else {
- foreach ($param['option'] as $k => $v) {
- if (isset($v['name'])) {
- $v = $v['name'];
- }
- foreach ($value[$k] as $k1 => $v1) {
- $param['value'][$v][$k1] = $v1;
- }
- /*
- foreach ($value[$k-1] as $k1 => $v1) {
- $param['value'][$v][$k1] = $v1;
- }*/
- }
- }
-
-
- } else {
- $param['value'] = array();
- foreach ($param['option'] as $k => $v) {
- if (isset($v['name'])) {
- $v = $v['name'];
- }
- $param['value'][$v]['main_' . $key] = $k;
- }
- }
- } else {
- $result .= '<ul class="nav nav-tabs '.$c.'" style="height:100%;">{tab}<li style="margin:0px;padding:0 15px;"><a href="javascript:;" class="dever_form_add" toggle_key="' . $key . '">增加一条</a></li></ul>';
- if ($order) {
- $order = array
- (
- 'col' => 'order',
- 'name' => '排序-按照数字正序排列',
- 'default' => '1',
- 'desc' => '排序',
- 'match' => 'is_string',
- 'update' => 'text',
- );
- array_unshift($method, $order);
- }
- }
- $tab = '';
- $this->update_child(array(), $method, $key, $result, -1, $param, $delete);
- if (isset($param['value']) && $param['value']) {
- if (!is_array($param['value'])) {
- $param['value'] = Dever::array_decode($param['value']);
- }
- //print_r($param['value']);die;
- if (is_array($param['value'])) {
- $i = 0;
- foreach ($param['value'] as $k => $v) {
- $n = $k;
- if (is_string($k)) {
- $k = $i;
- }
- $this->update_child($v, $method, $key, $result, $k, $param, $delete);
- $active = '';
- if ($k == 0) {
- $active = 'active';
- }
- if (layadmin() && $active) {
- $active .= ' layui-this';
- }
- $k = $k + 1;
- if (!is_string($n)) {
- $n = '第' . $k . '条';
- }
- if (isset($param['option']) && count($param['option']) <= 1) {
- } else {
- $tab .= '<li class="' . $active . '" style="margin:0px;padding:0 15px;"><a href="javascript:;" id="tab-' . $key . '-child-' . $k . '" toggle_key="' . $key . '" toggle_id="' . $k . '" toggle_child=".dever_' . $key . '_child" toggle="#' . $key . '-child-' . $k . '" onclick="showToggle($(this))">'.$n.'</a></li>';
- $i++;
- }
-
- }
- }
-
- } else {
- $this->update_child(array(), $method, $key, $result, 0, $param, $delete);
- $tab = '<li class="active layui-this" style="margin:0px;padding:0 15px;"><a href="javascript:;" id="tab-' . $key . '-child-1" toggle_key="' . $key . '" toggle_id="1" toggle_child=".dever_' . $param['col'] . '_child" toggle="#' . $key . '-child-1" onclick="showToggle($(this))">第1条</a></li>';
- }
- if ($tab) {
- $result = str_replace('{tab}', $tab, $result);
- } else {
- $result = str_replace('<ul class="nav nav-tabs layui-tab-title" style="height:100%;">{tab}</ul>', '', $result);
- }
- }
-
- } else {
- if (isset($param['update_input']) && isset($data[$index . '_input'])) {
- $param['update_input_data'] = explode(',', $data[$index . '_input']);
- }
- $param['project'] = $this->project;
- $param['table'] = $this->table;
- if (isset($param['upload_search'])) {
- $param['upload_search'] = $this->value($param['upload_search'], $data + $param);
- }
- if (isset($param['upload_search_value'])) {
- $param['upload_search_value'] = $this->value($param['upload_search_value'], $data + $param);
- }
- if (isset($param['update_search_value'])) {
- $param['update_search_value'] = $this->value($param['update_search_value'], $data + $param);
- }
- $param['where_id'] = $this->id;
- $result .= Html::$method($param);
- }
- if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
- $result .= Html::desc($param['desc']);
- }
- }
- return $param;
- }
- /**
- * update_action
- *
- * @return array
- */
- private function update_child($data, $param, $key, &$result, $index, $config, $delete = true)
- {
- if (isset($config['tab_config']) && $config['tab_config']) {
- if ($index != 0) {
- $style = 'display:none;';
- } else {
- $style = '';
- }
- $result .= '<div class="layui-tab layui-tab-brief dever_' . $key . '_child dever_form_add_child" lay-filter="component-tabs-brief" style="'.$style.'" id="' . $key . '-child-' . ($index + 1) . '">';
- if ($delete) {
- $result .= '<div class="dever_form_delete" style="cursor:pointer">[删除]</div><ul class="layui-tab-title" style="width:50%">';
- } else {
- $result .= '<ul class="layui-tab-title">';
- }
-
- $tab = '<div class="layui-tab-content">';
- $i = 0;
- foreach ($config['tab_config'] as $k => $v) {
- $content = $this->update_child_data($data, $param, $key, $index, $k, $config);
- if ($content) {
- $class_0 = $class_1 = '';
- if ($i == 0) {
- $class_0 = 'layui-this';
- $class_1 = 'layui-show';
- }
- $result .= '<li class="'.$class_0.'">'.$v.'</li>';
- $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
- $i++;
- }
- }
- $tab .= '</div>';
- $result .= '</ul>' . $tab . '</div>';
- } else {
- $style = 'margin:10px;';
- if ($index != 0) {
- $style = 'display:none;margin:10px;';
- }
- $result .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" style="' . $style . '">';
- if ($delete) {
- $result .= '<div class="dever_form_delete" style="cursor:pointer">[删除]</div>';
- }
- $result .= $content = $this->update_child_data($data, $param, $key, $index, 0, $config);
- $result .= '</div>';
- }
- }
- private function update_child_data($data, $param, $key, $index, $tab = -1, $config = array())
- {
- $result = '';
- foreach ($param as $k => $v) {
- if (is_string($k)) {
- $v['col'] = $k;
- }
- if ($this->id && $v['col'] == 'id') {
- $v['update'] = 'hidden';
- }
- if (!isset($v['update'])) {
- continue;
- }
-
- if (isset($config['prefix']) && $config['prefix']) {
- if (isset($config['lang']) && $config['lang'] && !in_array($v['col'], $config['lang'])) {
- continue;
- }
- $v['col'] = $config['prefix'] . '_' . $v['col'];
- }
- $state = false;
- if ($tab == 0) {
- if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
- $state = true;
- }
- } elseif ($tab > 0) {
- if (isset($v['tab']) && $v['tab'] == $tab) {
- $state = true;
- }
- } else {
- $state = true;
- }
- if (isset($v['update']) && $v['update'] && $state) {
-
- $v['type'] = $v['update'];
- $prefix = '';
- if ($index < 0) {
- $v['ext'] = $key . '_c_' . $v['col'];
- $prefix = $v['ext'];
- } else {
- $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
- $prefix = $v['ext'];
- }
- if ($v['col'] == 'order') {
- $v['default'] = $index+1;
- }
- $class = $this->update_class($v['col'], $v, $prefix);
- if ($v['update'] == 'hidden') {
- $result .= '<div class="form-group ' . $class . '" style="display:none">';
- $this->update_html($v, $key, $v['col'], $data, $result);
- $result .= '</div>';
- } else {
- $result .= '<div class="form-group ' . $class . '" style="margin-top:10px">';
- $this->update_html($v, $key, $v['col'], $data, $result);
- $result .= '</div>';
- }
- }
- }
- return $result;
- }
- /**
- * update_action
- *
- * @return array
- */
- public function update_action_commit_api()
- {
- $mul_ids = Dever::input('mul_ids');
- $key = Dever::input('dever_submit_key');
- $col = Dever::input('col');
- $value = Dever::input('value');
- if ($key) {
- Dever::submit_check($key, false, true);
- }
- $method = false;
- $config = $this->config();
- $input = Dever::preInput('update_');
- $info = array();
- if ($this->id) {
- # 新增权限
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- $auth = 1;
- } else {
- $auth = 3;
- }
- if (Dever::load('manage/auth.oper', $auth) == false) {
- Dever::alert('你没有权限');
- }
- Dever::setInput('where_id', $this->id);
- //Dever::setInput('update_where_id', $this->id);
- $info = $this->load('one', $this->id);
- if ($info) {
- $method = 'update';
- if ($col && $value) {
- $method = 'update_' . $col;
- //Dever::setInput('set_' . $col, $value);
- //Dever::setInput('update_' . $col, $value);
- $param['where_id'] = $this->id;
- $param['set_' . $col] = $value;
- $this->load($method, $param);
- $struct = $this->struct_data($config['struct'], array($col => $value));
- Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $this->id);
- Dever::out('yes');
- return;
- }
- $prefix = 'set';
- } else {
- $method = 'insert';
- $prefix = 'add';
- }
- }
- if (!$method) {
- # 新增权限
- if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
- $auth = 1;
- } else {
- $auth = 4;
- }
- if (Dever::load('manage/auth.oper', $auth) == false) {
- Dever::alert('你没有权限');
- }
- $method = 'insert';
- $prefix = 'add';
- }
- if ($method && $input) {
- $update = $order = $update_other = array();
- $i = 0;
- $c = array();
- foreach ($input as $k => $v) {
- if ($v === '') {
- $v = 'null';
- }
- if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
- $temp = str_replace('copy.', '', $v);
- if (isset($input['update_' . $temp])) {
- $v = $input['update_' . $temp];
- }
- }
- if (strpos($k, '_c_') !== false) {
- if (strstr($k, 'update_update_')) {
- $k = str_replace('update_update_', 'update_', $k);
- }
- if ($v == 'null') {
- $v = '';
- }
- $temp = explode('_c_', $k);
- $h = $temp[0];
- $k = str_replace('update_', $prefix . '_', $h);
- if (!isset($c[$k])) {
- $c[$k] = array();
- }
- if (strpos($temp[1], '_i_') !== false) {
- $temp = explode('_i_', $temp[1]);
- if (!isset($c[$k][$temp[1]])) {
- $c[$k][$temp[1]] = 0;
- } else {
- $c[$k][$temp[1]]++;
- }
- $num = $c[$k][$temp[1]];
- if (strpos($h, '-')) {
- $h = str_replace('update_', '', $h);
- $h = str_replace('--', '/', $h);
- # 兼容处理 之后删除
- if (isset($config['struct'][$h]) && isset($config['struct'][$h]['sync']) && isset($config['struct'][$h]['sync'][0])) {
- $s_col = $config['struct'][$h]['sync'][0];
- $m_col = $config['struct'][$h]['sync'][1];
- if ($s_col == 'id') {
- $s_value = $this->id;
- } elseif (isset($info[$s_col])) {
- $s_value = $info[$s_col];
- } else {
- $s_value = $input['update_' . $s_col];
- }
- $t = explode('-', $h);
- $index = $t[0] . '/' . $t[1];
- if (Dever::zero($v)) {
- $v = (string) $v;
- } elseif (!$v) {
- $v = 'null';
- }
- $update_col[$i][$index] = $m_col;
- $update_set[$i][$index][$num]['set_' . $temp[1]] = $v;
- $update_add[$i][$index][$num]['add_' . $temp[1]] = $v;
- $update_add[$i][$index][$num]['add_' . $m_col] = $s_value;
- $update_deletes[$i][$index][$m_col] = $s_value;
- $update_id[$i][$index][$num][$m_col] = $s_value;
- if ($this->id && $temp[1] == 'id') {
- $update_id[$i][$index][$num]['id'] = $v;
- }
- } elseif (isset($config['struct'][$h]) && isset($config['struct'][$h]['sync'])) {
- $t = explode('-', $h);
- $index = $t[0];
- if (Dever::zero($v)) {
- $v = (string) $v;
- } elseif (!$v) {
- $v = 'null';
- }
- $update_set[$i][$index][$num]['set_' . $temp[1]] = $v;
- $update_add[$i][$index][$num]['add_' . $temp[1]] = $v;
- if ($this->id && $temp[1] == 'id') {
- $update_id[$i][$index][$num]['id'] = $v;
- }
- foreach ($config['struct'][$h]['sync'] as $ks => $vs) {
- if ($vs == 'id') {
- $vs = $this->id;
- $update_col[$i][$index] = $ks;
- } elseif (isset($info[$vs])) {
- $vs = $info[$vs];
- } elseif (isset($input['update_' . $vs])) {
- $vs = $input['update_' . $vs];
- }
- $update_add[$i][$index][$num]['add_' . $ks] = $vs;
- $update_deletes[$i][$index][$ks] = $vs;
- $update_id[$i][$index][$num][$ks] = $vs;
- }
- }
- } else {
- $update[$i][$k][$num][$temp[1]] = $v;
- if ($temp[1] == 'order') {
- $order[$i][$k][$num] = $v;
- }
- }
- } else {
- //$update[$i][$k][$c][$temp[1]] = $v;
- }
- } elseif (strpos($k, '__') !== false) {
- $temp1 = explode('__', $k);
- $temp2 = explode('_', $temp1[0]);
- $i = $temp2[1] - 1;
- if (strpos($k, 'where_id') !== false) {
- //$update[$i]['where_id'] = $v;
- } else {
- $update[$i]['add_' . $temp1[1]] = $v;
- }
- } else {
- $ki = str_replace('update_', $prefix . '_', $k);
- if (strpos($ki, 'where_id') !== false) {
- if ($method != 'insert') {
- $update[$i]['where_id'] = $v;
- }
- } else {
- if (strpos($k, 'l-l')) {
- $temp = explode('l-l', $k);
- $k = str_replace('_', '', $temp[2]);
- $update_other[$i][$temp[1]][$k] = $v;
- } elseif (strpos($k, '-') && isset($config['struct'][$k]['sync'][0])) {
- # 兼容处理,之后删除
- $k = str_replace('update_', '', $k);
- if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
- $s_col = $config['struct'][$k]['sync'][0];
- $m_col = $config['struct'][$k]['sync'][1];
- if ($s_col == 'id') {
- $s_value = $this->id;
- } elseif (isset($info[$s_col])) {
- $s_value = $info[$s_col];
- } else {
- $s_value = $input['update_' . $s_col];
- }
- $temp = explode('-', $k);
- $index = $temp[0] . '/' . $temp[1];
- if (isset($temp[2])) {
- $update_col[$i][$index] = $m_col;
- $update_set[$i][$index][0]['set_' . $temp[2]] = $v;
- //$update_set[$i][$index][0]['set_' . $m_col] = $s_value;
- $update_add[$i][$index][0]['add_' . $temp[2]] = $v;
- $update_add[$i][$index][0]['add_' . $m_col] = $s_value;
- $update_id[$i][$index][0][$m_col] = $s_value;
- }
- } else {
- $temp = explode('-', $k);
- if (isset($temp[2])) {
- $k = $temp[0] . '-' . $temp[1];
- if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
- $s_col = $config['struct'][$k]['sync'][0];
- $m_col = $config['struct'][$k]['sync'][1];
- if ($s_col == 'id') {
- $s_value = $this->id;
- } elseif (isset($info[$s_col])) {
- $s_value = $info[$s_col];
- } else {
- $s_value = $input['update_' . $s_col];
- }
- $index = $temp[0] . '/' . $temp[1];
- $temp[2] = ltrim($temp[2], '_');
- $temp = explode('_', $temp[2]);
- $update_col[$i][$index] = $m_col;
- $up = array();
- $up['add_' . $temp[0] . '_id'] = $temp[1];
- $up['add_' . $temp[0] . '_value'] = $v;
- $up['add_' . $m_col] = $s_value;
- $update_add[$i][$index][] = $up;
- $update_delete[$i][$index][][$m_col] = $s_value;
- }
- }
- }
- } elseif (strpos($k, '#')) {
- $k = str_replace('update_', '', $k);
- $k = str_replace('--', '/', $k);
- # 此处需要改造 ---
- if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
- $temp = explode('-', $k);
- $index = $temp[0];
- $temp = explode('#', $temp[1]);
- $c_col = $temp[1];
- $update_set[$i][$index][0]['set_' . $c_col] = $v;
- $update_add[$i][$index][0]['add_' . $c_col] = $v;
- foreach ($config['struct'][$k]['sync'] as $ks => $vs) {
- if ($vs == 'id') {
- $vs = $this->id;
- $update_col[$i][$index] = $ks;
- } elseif (isset($info[$vs])) {
- $vs = $info[$vs];
- } elseif (isset($input['update_' . $vs])) {
- $vs = $input['update_' . $vs];
- }
- $update_add[$i][$index][0]['add_' . $ks] = $vs;
- $update_id[$i][$index][0][$ks] = $vs;
- }
- } else {
- $temp = explode('-', $k);
- $k = $index = $temp[0];
- $temp = explode('#', $temp[1]);
- $c_col = $temp[1];
- if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
- $c_col = ltrim($c_col, '_');
- $temp = explode('_', $c_col);
- $up = array();
- $up['add_' . $temp[0] . '_id'] = $temp[1];
- $up['add_' . $temp[0] . '_value'] = $v;
-
- foreach ($config['struct'][$k]['sync'] as $ks => $vs) {
- if ($vs == 'id') {
- $vs = $this->id;
- $update_col[$i][$index] = $ks;
- } elseif (isset($info[$vs])) {
- $vs = $info[$vs];
- } elseif (isset($input['update_' . $vs])) {
- $vs = $input['update_' . $vs];
- }
- $up['add_' . $ks] = $vs;
- $update_delete[$i][$index][][$ks] = $vs;
- }
- $update_add[$i][$index][] = $up;
- }
- }
- } else {
- if (is_array($v)) {
- $k = str_replace('update_', '', $k);
- $kd = $k . '_id';
- if (isset($config['struct'][$kd])) {
- foreach ($v as $vk => $vt) {
- if ($vt == -1) {
- if ($vk != 0) {
- unset($v[$vk]);
- }
- }
- }
- if ($v) {
- $vd = end($v);
- $kdi = $prefix . '_' . $kd;
- $update[$i][$kdi] = $vd;
- }
- }
- if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
- $v = end($v);
- }
- }
- $update[$i][$ki] = $v;
- }
- }
- }
- }
- //print_r($update_col);
- //print_r($update_set);
- //print_r($update_id);
- //print_r($update_add);die;
- //print_r($input);
- //print_r($update_other);die;
- //print_r($config['struct']);die;
- if ($mul_ids) {
- $mul_load = Dever::input('mul_load');
- if ($mul_load) {
- Dever::load($mul_load, $mul_ids, '', $update[0]);
- }
- Dever::out('yes');
- return;
- }
- $this->checkSpec($config);
- # 增加复制的数量
- $copy_num = Dever::input('copy_num');
- if ($copy_num > 0) {
- $update[0]['where_id'] = 0;
- for ($i = 1; $i < $copy_num; $i++) {
- $update[$i] = $update[0];
- # 缓存处理
- $update[$i]['rank'] = $i;
- }
- }
- if ($this->id && !$info) {
- $update[0]['add_id'] = $this->id;
- }
- //print_r($update);die;
- $fast = Dever::input('fast');
- foreach ($update as $k => $v) {
- $method = 'insert';
- $old = array();
- if (isset($v['where_id']) && $v['where_id']) {
- $method = 'update';
- $old = $this->load('one', $v['where_id']);
- }
- if ($method == 'insert' && isset($config['manage']['insert_check'])) {
- $insert_check = explode(',', $config['manage']['insert_check']);
- foreach ($insert_check as $k1 => $v1) {
- if (strstr($v1, '-')) {
- $t = explode('-', $v1);
- $v1 = $t[0] . '/' . $t[1];
- }
- if (isset($config['struct'][$v1])) {
- if (strstr($v1, '/') && !isset($update_id[$k][$v1])) {
- Dever::alert($config['struct'][$v1]['name'] . '不能为空');
- } elseif (isset($v['add_' . $v1]) && is_string($v['add_' . $v1]) && (!$v['add_' . $v1] || $v['add_' . $v1] == 'null')) {
- Dever::alert($config['struct'][$v1]['name'] . '不能为空');
- }
- }
- }
- }
- if ($method == 'update' && isset($config['manage']['update_check'])) {
- $update_check = explode(',', $config['manage']['update_check']);
- foreach ($update_check as $k1 => $v1) {
- if (strstr($v1, '-')) {
- $t = explode('-', $v1);
- $v1 = $t[0] . '/' . $t[1];
- }
- if (isset($config['struct'][$v1])) {
- if (strstr($v1, '/') && !isset($update_id[$k][$v1])) {
- Dever::alert($config['struct'][$v1]['name'] . '不能为空');
- } elseif (isset($v['set_' . $v1]) && is_string($v['set_' . $v1]) && (!$v['set_' . $v1] || $v['set_' . $v1] == 'null')) {
- Dever::alert($config['struct'][$v1]['name'] . '不能为空');
- }
- }
- }
- }
- if (isset($order[$k])) {
- foreach ($order[$k] as $i => $j) {
- array_multisort($j, SORT_ASC, $v[$i]);
- }
- }
- if (isset($v['set_password']) && (!$v['set_password'] || $v['set_password'] == 'null')) {
- unset($v['set_password']);
- }
- $id = $this->load($method, $v);
- if ($id) {
- $struct = $this->struct_data($config['struct'], $v, $old);
- Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $id ? $id : $this->id);
- if ($update_other && isset($update_other[$k])) {
- foreach ($update_other[$k] as $k1 => $v1) {
- $v1['id'] = $id;
- $this->load($method, $v1, $this->table . '__' . $k1);
- }
- }
- if (isset($update_add[$k]) && $update_add[$k]) {
- if (isset($update_deletes[$k]) && $update_deletes[$k]) {
- foreach ($update_deletes[$k] as $k1 => $v1) {
- $v1['set_state'] = 2;
- Dever::load($k1 . '-updates', $v1);
- }
- }
- foreach ($update_add[$k] as $k1 => $v1) {
- $col = isset($update_col[$k][$k1]) ? $update_col[$k][$k1] : false;
- foreach ($v1 as $k2 => $v2) {
- if ($col) {
- if (isset($update_set[$k][$k1][$k2]['set_' . $col])) {
- $update_set[$k][$k1][$k2]['set_' . $col] = $id;
- }
- if (isset($v2['add_' . $col])) {
- $v2['add_' . $col] = $id;
- }
- }
- $check = false;
- if (isset($update_id[$k][$k1][$k2])) {
- if ($col && isset($update_id[$k][$k1][$k2][$col])) {
- $update_id[$k][$k1][$k2][$col] = $id;
- }
- $check = Dever::load($k1 . '-one', $update_id[$k][$k1][$k2]);
- } elseif (isset($update_delete[$k][$k1][$k2])) {
- # 清理
- Dever::load($k1 . '-delete', $update_delete[$k][$k1][$k2]);
- }
-
- if ($check) {
- unset($update_set[$k][$k1][$k2]['set_id']);
- $update_set[$k][$k1][$k2]['where_id'] = $check['id'];
- $update_set[$k][$k1][$k2]['set_state'] = 1;
- Dever::load($k1 . '-update', $update_set[$k][$k1][$k2]);
- } else {
- Dever::load($k1 . '-insert', $v2);
- }
- }
- }
- }
- $this->spec($id, $config);
- if ($method == 'insert' && isset($config['manage']['insert_end'])) {
- Dever::load($config['manage']['insert_end'], $id);
- }
- if ($method == 'update' && isset($config['manage']['update_end'])) {
- Dever::load($config['manage']['update_end'], $id);
- }
- }
- }
- }
- Dever::out('yes');
- }
- private function checkSpec($config)
- {
- $type = Dever::input('update_type');
- if ($type && isset($type[0]) && $type[0] > 10) {
- //Dever::setInput('update_spec_type', -1);
- return;
- }
- $spec_type = Dever::input('update_spec_type');
- if ($spec_type == 1) {
- $sku = Dever::input('skus');
- if (!isset($sku[-1])) {
- Dever::alert('规格设置不能为空');
- }
- if (!$sku[-1]['code']) {
- Dever::alert('规格设置不能为空');
- }
- } elseif ($spec_type == 2) {
- $spec = Dever::input('spec');
- if (!$spec) {
- Dever::alert('规格设置不能为空');
- }
- }
- }
- private function spec($id, $config)
- {
- $spec_type = Dever::input('update_spec_type');
- if ($spec_type && $spec_type > 0) {
- if (isset($config['manage']['sku'])) {
- $spec_table = $config['manage']['sku']['spec'];
- $sku_table = $config['manage']['sku']['sku'];
- }
- if (!isset($sku_table)) {
- $sku_table = 'info_sku';
- }
- $sku_table = $this->project . '/' . $sku_table;
- if ($spec_type == 2) {
- $spec = Dever::input('spec');
- $sku = Dever::input('skus');
- if ($spec && $sku) {
- if (!isset($spec_table)) {
- $spec_table = 'info_spec';
- }
- $spec_table = $this->project . '/' . $spec_table;
- $spec_value_table = $spec_table . '_value';
- $spec = Dever::json_decode($spec);
- if ($spec) {
- $sku_id = array();
- Dever::db($spec_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
- Dever::db($spec_value_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
- foreach ($spec as $k1 => $v1) {
- $order = $k1 + 1;
- if (is_numeric($v1['id'])) {
- $spec_id = Dever::db($spec_table)->update(array('where_id' => $v1['id'], 'set_state' => 1, 'set_reorder' => $order));
- } else {
- $spec_id = Dever::db($spec_table)->insert(array('name' => $v1['title'], 'info_id' => $id, 'reorder' => $order));
- }
- foreach ($v1['child'] as $k2 => $v2) {
- $v2['checked'] = $v2['checked'] ? 1 : 2;
- if (is_numeric($v2['id'])) {
- Dever::db($spec_value_table)->update(array('where_id' => $v2['id'], 'set_state' => 1, 'set_is_checked' => $v2['checked']));
- } else {
- $sku_id[$v2['id']] = Dever::db($spec_value_table)->insert(array('value' => $v2['title'], 'is_checked' => $v2['checked'], 'info_id' => $id, 'spec_id' => $spec_id));
- }
- }
- }
- Dever::db($spec_table)->delete(array('info_id' => $id, 'state' => 2));
- Dever::db($spec_value_table)->delete(array('info_id' => $id, 'state' => 2));
- $this->sku($id, $sku_table, $sku, $sku_id);
- }
- }
- } else {
- $sku = Dever::input('skus');
- if ($sku) {
- $this->sku($id, $sku_table, $sku);
- //Dever::db($spec_table)->delete(array('info_id' => $id));
- //Dever::db($spec_value_table)->delete(array('info_id' => $id));
- }
- }
- }
-
- }
- private function sku($id, $sku_table, $sku, $sku_id = false)
- {
- Dever::db($sku_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
- foreach ($sku as $k1 => $v1) {
- if ($sku_id) {
- foreach ($sku_id as $k2 => $v2) {
- $k1 = str_replace($k2, $v2, $k1);
- }
- }
- $sku_data = array();
- $sku_data['info_id'] = $id;
- $sku_data['key'] = $k1;
- $sku_info = Dever::db($sku_table)->one($sku_data);
- foreach ($v1 as $k3 => $v3) {
- $sku_data[$k3] = $v3;
- }
- if ($sku_info) {
- $sku_data['where_id'] = $sku_info['id'];
- $sku_data['state'] = 1;
- Dever::db($sku_table)->update($sku_data);
- } else {
- Dever::db($sku_table)->insert($sku_data);
- }
- }
- Dever::db($sku_table)->delete(array('info_id' => $id, 'state' => 2));
- }
- public function struct_data($struct, $data, $old = array())
- {
- $log = $tlog = array();
- foreach ($struct as $i => $j) {
- if (isset($data[$i])) {
- $data['cur_value'] = $data[$i];
- }
- /*
- if ($i == 'reorder' || $i == 'id') {
- continue;
- }
- */
- if (isset($j['list_name'])) {
- $j['name'] = $j['list_name'];
- } elseif (strpos($j['name'], '-')) {
- $temp = explode('-', $j['name']);
- $j['name'] = $temp[0];
- }
- if (isset($j['list_table'])) {
- $j['list'] = $j['list_table'];
- if ($j['list'] == false) {
- $data[$i] = false;
- }
- }
- $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
- $update = true;
- if ($old && isset($j['update'])) {
- $update = (is_string($j['update']) && $j['update'] != 'linkage');
- }
- if (isset($data['where_' . $i]) && $data['where_' . $i]) {
- $log[$j['name']] = $data['where_' . $i];
- } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
- $log[$j['name']] = $data['set_' . $i];
- } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
- $log[$j['name']] = $data['add_' . $i];
- } elseif (isset($data[$i]) && $data[$i]) {
- if ($i == 'id') {
- $log[$j['name']] = $data[$i];
- } else {
- $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
- }
- }
- if (isset($log[$j['name']])) {
- $tlog[$j['name']] = $log[$j['name']];
- if (is_array($tlog[$j['name']])) {
- if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
- $tlog[$j['name']] = json_encode($tlog[$j['name']]);
- if (isset($old[$i]) && is_array($old[$i])) {
- $old[$i] = json_encode($old[$i]);
- }
- } elseif (isset($tlog[$j['name']][0])) {
- $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
- if (isset($old[$i]) && is_array($old[$i])) {
- $old[$i] = implode(',', $old[$i]);
- }
- }
- } elseif (strpos($log[$j['name']], 'http://wx.qlogo.cn/') !== false || strpos($log[$j['name']], '.jpg') !== false || strpos($log[$j['name']], '.gif') !== false || strpos($log[$j['name']], '.png') !== false) {
- $log[$j['name']] = '<img layer-src="' . $log[$j['name']] . '" src="' . $log[$j['name']] . '" width="150">';
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = Dever::pic($old[$i]);
- $old[$i] = '<img layer-src="' . $old[$i] . '" src="' . $old[$i] . '" width="150">';
- }
- } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
- if (!strstr($log[$j['name']], '-')) {
- $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
- }
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = date("Y-m-d H:i:s", $old[$i]);
- }
- } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'day') !== false)) {
- if (!strstr($log[$j['name']], '-')) {
- $log[$j['name']] = date("Y-m-d", $log[$j['name']]);
- }
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = date("Y-m-d", $old[$i]);
- }
- } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'month') !== false)) {
- if (!strstr($log[$j['name']], '-')) {
- $log[$j['name']] = date("Y-m", $log[$j['name']]);
- }
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = date("Y-m", $old[$i]);
- }
- } elseif (isset($j['decode'])) {
- $log[$j['name']] = Dever::array_decode($log[$j['name']]);
- if (isset($old[$i]) && $old[$i]) {
- $old[$i] = Dever::array_decode($old[$i]);
- }
- }
-
- if (isset($j['option']) && !$list && $update) {
- $name = array();
- $old_name = array();
- $option = $this->option($j['option']);
- if (is_array($option)) {
- foreach ($option as $a => $b) {
- if (!is_array($log[$j['name']])) {
- if ($a == $log[$j['name']]) {
- $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
- }
- } elseif (in_array($a, $log[$j['name']])) {
- $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
- }
- if ($old && isset($old[$i])) {
- if (!is_array($old[$i])) {
- if ($a == $old[$i]) {
- $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
- }
- } elseif (in_array($a, $old[$i])) {
- $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
- }
- }
- }
- }
-
- $log[$j['name']] = implode(',', $name);
- if ($old_name) {
- $old[$i] = implode(',', $old_name);
- }
- }
- if ($log[$j['name']] == 'null') {
- unset($log[$j['name']]);
- }
- if ($old && strstr($i, 'area')) {
- $old[$i] = Dever::load('area/api')->string($old[$i]);
- if (isset($log[$j['name']]) && $log[$j['name']]) {
- $log[$j['name']] = Dever::load('area/api')->string($log[$j['name']]);
- }
- }
- if (isset($log[$j['name']]) && isset($old[$i]) && $old[$i] != $tlog[$j['name']] && $old[$i] != $log[$j['name']]) {
- $log[$j['name']] = array('更新前' => $old[$i], '更新后' => $log[$j['name']]);
- } elseif ($old) {
- //unset($log[$j['name']]);
- }
- }
- }
- return $log;
- }
- /**
- * delete_action
- *
- * @return array
- */
- public function delete_action_api()
- {
- if (Dever::load('manage/auth.oper', 5) == false) {
- Dever::alert('您没有权限');
- }
- $config = $this->config();
- if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
- $name = '逻辑删除';
- $this->load('update', array('where_id' => $this->id, 'state' => 2));
- } else {
- $name = '物理删除';
- $this->load('delete', $this->id);
- }
- Log::add($this->project, $this->table, $this->menu_id, '', 3, array('ID' => $this->id, '方式' => $name), $this->id);
- return 'reload';
- return 'reloaderror';
- }
- /**
- * recovery_action
- *
- * @return array
- */
- public function recovery_action_api()
- {
- if (Dever::load('manage/auth.oper', 5) == false) {
- Dever::alert('您没有权限');
- }
- $this->load('update', array('where_id' => $this->id, 'state' => 1));
- Log::add($this->project, $this->table, $this->menu_id, '', 4, array('ID' => $this->id, '方式' => '逻辑恢复'), $this->id);
- return 'reload';
- }
- /**
- * list_data
- *
- * @return array
- */
- public function list_data()
- {
- $config = $this->config();
- $data = array();
- if (isset($config['manage']['data']) && $config['manage']['data']) {
- $num = count($config['manage']['data']);
- if ($num <= 4) {
- $xs = '3';
- } else {
- $xs = '1';
- }
- foreach ($config['manage']['data'] as $k => $v) {
- if (is_object($v[1])) {
- $function = $v[1];
- $v[1] = $function();
- }
- $link = '';
- if (isset($v[2]) && $v[2]) {
- $link = 'project/database/list?project=' . $this->project . '&table=' . $this->table . '&' . $v[2];
- $link = 'href="' . Dever::url($link, 'manage') . '"';
- }
- $data[] = '<li class="layui-col-xs'.$xs.'" style="min-width: 12%;">
- <a class="layadmin-backlog-body" '.$link.'><h3>'.$v[0].'</h3>
- <p><cite>'.$v[1].'</cite></p></a></li>';
- }
- }
-
- return $data;
- }
- /**
- * list_data
- *
- * @return array
- */
- public function list_data_show()
- {
- $config = $this->config();
- if (isset($config['manage']['data']) && $config['manage']['data']) {
- return 'display:block';
- }
-
- return 'display:none';
- }
- /**
- * chart
- *
- * @return array
- */
- public function chart($config, $key, $data, $struct)
- {
- if (!$this->chart) {
- $this->chart = array();
- $this->chart['x'] = array();
- $this->chart['data'] = array();
- }
- if ($config['x'] == $key) {
- $this->chart['x'][] = $data;
- } elseif (in_array($key, $config['data'])) {
- if (!isset($this->chart['data'][$key])) {
- $this->chart['data'][$key] = array
- (
- 'name' => $struct['name'],
- 'type' => 'line',
- 'stack' => 'Total',
- 'data' => array(),
- );
- }
- $this->chart['data'][$key]['data'][] = $data;
- }
- }
- /**
- * chart_data
- *
- * @return array
- */
- public function list_chart()
- {
- $config = $this->config();
- $chart = '';
- if (isset($config['manage']['chart']) && $this->chart) {
- $this->chart['x'] = array_reverse($this->chart['x']);
- $x = Dever::json_encode($this->chart['x']);
- $this->chart['data'] = array_values($this->chart['data']);
- foreach ($this->chart['data'] as $k => $v) {
- $this->chart['data'][$k]['data'] = array_reverse($this->chart['data'][$k]['data']);
- }
- $data = Dever::json_encode($this->chart['data']);
- $echarts = Dever::assets('lib/echarts/echarts.common.min.js', 'script');
- $chart = '<script type="text/javascript" src="'.$echarts.'"></script><script>var chartDom = document.getElementById("chart");var myChart = echarts.init(chartDom);';
- $chart .= "var option = {
- tooltip: {
- trigger: 'axis'
- },
-
- toolbox: {
- feature: {
- saveAsImage: {}
- }
- },
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: ".$x."
- },
- yAxis: {
- type: 'value'
- },
- series: ".$data."
- };option && myChart.setOption(option);</script>";
- }
-
- return $chart;
- }
- /**
- * chart_data
- *
- * @return array
- */
- public function list_chart_show()
- {
- $config = $this->config();
- if (isset($config['manage']['chart'])) {
- return 'display:block';
- }
-
- return 'display:none';
- }
- /**
- * stat 为主动统计提供相关数据
- *
- * @return array
- */
- public function stat()
- {
- //bundle 包依赖工具
- $config = $this->config();
- if (empty($config['manage']['stat'])) {
- Dever::alert('该项目主动统计功能未开放');
- }
- $data = $config['manage'];
- $data['table'] = '';
- $method = $this->project . '/' . $this->table . '-all';
- $gp = Dever::input('gp', 'month,day');
- $col = is_string($gp) ? explode(',', $gp) : $gp;
- $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
- foreach ($col as $k => $v) {
- $this->stat_data($data, $config['struct'], $v, $method);
- }
- return $data;
- }
- /**
- * stat 为主动统计提供导出数据 后续优化
- *
- * @return array
- */
- public function stat_excel()
- {
- Dever::$global['base']['excel'] = 1;
- //print_r($data['thead']);die;
- $data = $this->stat();
- if ($data && isset($data['list'])) {
- $xls = new \PHPExcel();
- $xls->getProperties()->setCreator("Maze Stat Excel")
- ->setLastModifiedBy("Maze Stat Excel")
- ->setTitle("Office 2007 XLSX Maze Document")
- ->setSubject("Office 2007 XLSX Maze Document")
- ->setDescription("Dever Stat Excel")
- ->setKeywords("Dever Stat Excel")
- ->setCategory("Dever Stat Excel");
- $info = $this->info();
- $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
- $start = 65;
- $s = 0;
- foreach ($data['thead'] as $k => $v) {
- if ($s > 0) {
- $xls->createSheet();
- }
- $act = $xls->setActiveSheetIndex($s);
- $act->setTitle($v[0]);
- $s++;
- $i = 0;
- foreach ($v as $kj => $vj) {
- $num = 1;
- $cell = $this->_getChr($start, $i);
- $act->setCellValue($cell . '' . $num, $vj);
- $act->getColumnDimension($cell)->setWidth(20);
- $i++;
- if (isset($data['list'][$k])) {
- foreach ($data['list'][$k] as $ki => $vi) {
- if (isset($vi[$kj])) {
- $num += 1;
- $act->setCellValue($cell . $num, $vi[$kj]);
- }
- }
- }
- }
- }
- //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
- //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
- $xls->setActiveSheetIndex(0);
- $filename = $name . '.xlsx';
- header('Pragma: public');
- header('Expires: 0');
- header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
- header('Content-Type:application/force-download');
- header('Content-Type:application/vnd.ms-execl');
- header('Content-Type:application/octet-stream');
- header('Content-Type:application/download');
- header("Content-Disposition:attachment;filename='" . $filename . "'");
- header('Content-Transfer-Encoding:binary');
- $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
- $write->save('php://output');
- }
- }
- /**
- * stat_search
- *
- * @return mixed
- */
- private function stat_search($struct, $col, $stat, $search)
- {
- unset($struct['id']);
- unset($struct['cdate']);
- if ($stat) {
- $stat = explode(',', $stat);
- foreach ($stat as $k => $v) {
- if (isset($struct[$v])) {
- unset($struct[$v]);
- }
- }
- }
- $struct['day']['name'] = '天';
- $struct['month']['name'] = '月';
- $struct['year']['name'] = '年';
- $param['update'] = 'checkbox';
- $param['name'] = 'gp';
- $param['value'] = $col;
- $param['option'] = $struct;
- $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
- $html .= '<div class="form-group">';
- $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
- $html .= Html::radio($param);
- $html .= '</div>';
- $input = Dever::preInput('search_');
- if (isset($search['date'])) {
- foreach ($search['date'] as $k => $v) {
- $html .= '<div class="form-group">';
- $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
- $html .= '</div>';
- }
- $input = Dever::preInput('search_');
- if ($input) {
- foreach ($input as $k => $v) {
- if ($v && strpos($k, 'option_') !== false) {
- Dever::setInput(str_replace('search_', '', $k), $v);
- }
- }
- }
- }
- if (isset($search['fulltext'])) {
- $html .= '<div class="form-group">';
- $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
- $this->list_search_select($html, $input, 'search_fulltext_type', '', array
- (
- 1 => '精确匹配',
- 2 => '模糊匹配',
- 3 => '大于',
- 4 => '大于等于',
- 5 => '小于',
- 6 => '小于等于',
- ), 1);
- $value = array();
- $value['name'] = 'search_fulltext_value';
- $value['class'] = 'form-control';
- if (isset($input[$value['name']])) {
- $value['value'] = $input[$value['name']];
- $fix = '';
- if ($input['search_fulltext_type'] == 2) {
- $fix = '%';
- }
- Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
- //print_r(Dever::input('option_name'));die;
- }
- $html .= Html::text($value, false);
- $html .= '</div>';
- }
- $html .= '<input type="hidden" name="excel" id="excel" value="2"><a href="javascript:;" class="btn btn-primary" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat') . '\').submit();">确定</a>';
- $html .= ' <a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
- $html .= '</form>';
- return $html;
- }
- /**
- * stat_data
- *
- * @return mixed
- */
- private function stat_data(&$data, $struct, $col, $method)
- {
- Dever::setInput('group', $col);
- switch ($col) {
- case 'year':
- $name = '按年统计';
- break;
- case 'month':
- $name = '按月统计';
- break;
- case 'day':
- $name = '按天统计';
- break;
- default:
- $name = $struct[$col]['name'];
- break;
- }
- $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
- $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
- $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
- $data['thead'][$col] = array($name, '统计数字');
- if ($list) {
- $data['table'] .= '<tbody>';
- $total = 0;
- foreach ($list as $k => $v) {
- if (isset($v[$col])) {
- if (isset($struct[$col]['option'])) {
- $option = $this->option($struct[$col]['option']);
- if (isset($option[$v[$col]])) {
- $v[$col] = $option[$v[$col]];
- if (is_array($v[$col])) {
- $v[$col] = $v[$col]['name'];
- }
- }
- }
- $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
- $total += $v['total'];
- $data['list'][$col][] = array($v[$col], $v['total']);
- }
- }
- $data['table'] .= '</tbody>';
- if ($total > 0 && $k > 0) {
- $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
- $data['list'][$col][] = array('汇总', $total);
- }
- }
- $data['table'] .= '</table></div>';
- }
- /**
- * load
- *
- * @return mixed
- */
- private function load($method = 'one', $param = array(), $table = false)
- {
- if (!$table) {
- $table = $this->table;
- }
- return Dever::load($this->project . '/' . $table . '-' . $method, $param);
- }
- /**
- * __call
- *
- * @return object
- */
- public function __call($method, $param)
- {
- if (strpos($method, 'html_') !== false) {
- return Html::text($param);
- }
- return $this;
- }
- /**
- * option
- *
- * @return string
- */
- private function option($option, $value = false)
- {
- if (is_object($option)) {
- $function = $option;
- $option = $function();
- }
- if ($value && is_array($value)) {
- $state = false;
- foreach ($value as $k => $v) {
- if ($v === true) {
- $state = true;
- break;
- }
- }
- if ($state) {
- $option = array_intersect_key($option, $value);
- } else {
- $option = $value;
- }
- }
- return $option;
- }
- /**
- * option
- *
- * @return string
- */
- public function manage()
- {
- $config = $this->config();
- return $config;
- }
- /**
- * valid
- *
- * @return string
- */
- public function valid()
- {
- //http://placehold.it/350x150
- $config = $this->config();
- if (isset($config['struct'])) {
- $rule = array();
- $rule['required']['regex'] = 'none';
- $rule['required']['alertText'] = '此项不能为空';
- $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
- $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
- $rule['required']['alertTextDateRange'] = '日期范围不可空白';
- foreach ($config['struct'] as $k => $v) {
- if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
- if (strstr($v['match'], 'option||')) {
- $v['match'] = str_replace('option||', '', $v['match']);
- }
- $rule[$k]['regex'] = $v['match'];
- $rule[$k]['alertText'] = $v['desc'];
- }
- }
- }
- $script = '<script>';
- //参考https://blog.csdn.net/wangzl1163/article/details/51071826
- //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
- $script .= '(function($){
- $.fn.validationEngineLanguage = function(){
- };
- $.validationEngineLanguage = {
- newLang: function(){
- $.validationEngineLanguage.allRules = ';
- //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
- $script .= str_replace(array('\\\\', '\\/', '"/', '/"', '/u"', '/g"', '/i"', '\x{4e00}-\x{9fa5}', '\x'), array('\\', '/', '/', '/', '/u', '/g', '/i', '\u4e00-\u9fa5', '\u'), json_encode($rule)) . ';';
- $script .= '}
- };
- $.validationEngineLanguage.newLang();
- })(jQuery);';
- $script .= '$(document).ready(function(){
- $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){showAlertFlag = false;submit();}});
- });';
- $script .= '</script>';
- //print_r($script);die;
- return $script;
- }
- /**
- * save
- *
- * @return string
- */
- public function save()
- {
- $config = $this->config();
- if (isset($config['manage']['save'])) {
- return 'yes';
- }
- return 'no';
- }
- }
|