Database.php 190 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983
  1. <?php
  2. # 此类很大,以后优化,放到Database目录中,拆分为工厂模式
  3. # 必须要优化了...当时为了快速实现直接扔这一个里面了,近期优化
  4. namespace Manage\Src;
  5. use Dever;
  6. use Manage\Src\Lib\Input as Html;
  7. use Manage\Src\Lib\Log;
  8. class Database
  9. {
  10. /**
  11. * project
  12. *
  13. * @var string
  14. */
  15. private $project;
  16. /**
  17. * table
  18. *
  19. * @var string
  20. */
  21. private $table;
  22. /**
  23. * menu
  24. *
  25. * @var string
  26. */
  27. private $menu;
  28. /**
  29. * menu_id
  30. *
  31. * @var string
  32. */
  33. private $menu_id;
  34. /**
  35. * id
  36. *
  37. * @var string
  38. */
  39. private $id;
  40. /**
  41. * config
  42. *
  43. * @var array
  44. */
  45. private $config;
  46. /**
  47. * search
  48. *
  49. * @var bool
  50. */
  51. private $search = false;
  52. /**
  53. * chart
  54. *
  55. * @var array
  56. */
  57. private $chart = false;
  58. /**
  59. * manage_button
  60. *
  61. * @var array
  62. */
  63. private $manage_button = false;
  64. /**
  65. * info
  66. *
  67. * @var array
  68. */
  69. private $info = array();
  70. /**
  71. * state
  72. *
  73. * @var array
  74. */
  75. private $state = false;
  76. /**
  77. * __construct
  78. *
  79. * @return mixed
  80. */
  81. public function __construct()
  82. {
  83. $this->setting();
  84. $this->top = Dever::input('top');
  85. if ($this->top) {
  86. Dever::load('manage/top.update_action', $this->top);
  87. }
  88. }
  89. public function setting()
  90. {
  91. $this->project = Dever::input('project');
  92. $this->table = Dever::input('table');
  93. $this->menu = Dever::input('menu');
  94. $this->menu_id = Dever::input('menu_id');
  95. $this->id = Dever::input('update_where_id', Dever::input('where_id'));
  96. $this->name = $this->project . '/' . $this->table;
  97. return $this;
  98. }
  99. /**
  100. * 提供给异步获取数据的接口
  101. *
  102. * @return array
  103. */
  104. public function getAjax($data)
  105. {
  106. $key = Dever::input('key');
  107. $value = Dever::input('value');
  108. $source = Dever::input('source');
  109. $config = Dever::db($source)->config['struct'][$key];
  110. $config['value'] = $value;
  111. $config['option'] = $data;
  112. return $this->create_update_html($key, $config);
  113. }
  114. /**
  115. * url
  116. *
  117. * @return array
  118. */
  119. public function url($key = false, $id = 0, $table = false, $suffix = '', $project = '', $param = array())
  120. {
  121. $table = $table ? $table : $this->table;
  122. if (strpos($table, 'http://') !== false || strpos($table, 'javascript') !== false) {
  123. return $table;
  124. }
  125. $config = array
  126. (
  127. 'project' => 'project/database?project=' . $this->project,
  128. 'list' => 'project/database/list?{param}',
  129. 'search' => 'project/database/list?{param}',
  130. 'add' => 'project/database/update?{param}',
  131. 'update' => 'project/database/update?{param}&where_id=' . $id,
  132. # 增加快捷更新
  133. 'edit' => 'project/database/update?{param}&where_id=' . $id,
  134. 'updateAction' => 'database.update_action',
  135. 'url' => '',
  136. 'delete' => 'database.delete_action?{param}&where_id=' . $id,
  137. 'recovery' => 'database.recovery_action?{param}&where_id=' . $id,
  138. 'stat' => 'project/database/stat?{param}',
  139. 'excel' => 'database.list_excel?{param}',
  140. 'stat_excel' => 'database.stat_excel?{param}',
  141. 'reset' => 'project/database/list?project=' . $this->project . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id,
  142. 'diy' => 'list?{param}',
  143. );
  144. $state = $this->getState();
  145. if ($key == 'delete' && $state == 2) {
  146. $key = 'recovery';
  147. }
  148. if (strpos($key, 'list') !== false) {
  149. $config[$key] = $config['list'];
  150. } elseif (strpos($key, 'add') !== false) {
  151. $config[$key] = $config['add'];
  152. } elseif (strpos($key, 'edit') !== false) {
  153. $config[$key] = $config['edit'];
  154. }
  155. if (isset($config[$key])) {
  156. if (strpos($config[$key], '{param}')) {
  157. $param = $this->getUrlParam($key, $table, $suffix, $state, $project, $param);
  158. $config[$key] = str_replace('{param}', $param, $config[$key]);
  159. }
  160. return Dever::url($config[$key]);
  161. }
  162. return $config;
  163. }
  164. /**
  165. * 获取url需要的参数
  166. *
  167. * @return string
  168. */
  169. private function getUrlParam($key, $table, $suffix, $state, $project = '', $input = array())
  170. {
  171. $index = md5($key . '_' . $project . '_' . $table . '_' . $suffix . '_' . http_build_query($input));
  172. if (isset($this->param[$index])) {
  173. //return $this->param[$index];
  174. }
  175. $param = '';
  176. $array = array('project', 'search', 'add', 'list', 'update', 'edit');
  177. //if (in_array($key, $array) && !strstr($table, 'oper_')) {
  178. if (!strstr($table, 'oper_')) {
  179. $where = Dever::preInput('search_', $input);
  180. if ($where) {
  181. if (isset($where['where_id'])) {
  182. //unset($where['where_id']);
  183. }
  184. unset($where['search_option_state']);
  185. $param .= '&' . http_build_query($where);
  186. }
  187. $oper = Dever::preInput('send_', $input);
  188. if ($oper) {
  189. $param .= '&' . http_build_query($oper);
  190. }
  191. if ($key != 'listData') {
  192. $oper = Dever::preInput('oper_', $input);
  193. if ($oper) {
  194. $param .= '&' . http_build_query($oper);
  195. }
  196. }
  197. $top = Dever::preInput('top_', $input);
  198. if ($top) {
  199. $param .= '&' . http_build_query($top);
  200. }
  201. }
  202. if ($key == 'search' && $search_limit = Dever::input('search_limit')) {
  203. $param .= '&search_limit=' . $search_limit;
  204. }
  205. if (strpos($suffix, 'search_option_state') !== false) {
  206. $state = '';
  207. } else {
  208. $state = '&search_option_state=' . $state;
  209. }
  210. $page_type = Dever::input('page_type');
  211. if ($page_type) {
  212. $param .= '&page_type=' . $page_type . '';
  213. }
  214. /*
  215. $where_id = Dever::input('where_id');
  216. if ($where_id) {
  217. $param .= '&where_id=' . $where_id . '';
  218. }
  219. */
  220. $menu_id = Dever::input('menu_id');
  221. if ($menu_id && !strstr($param, 'menu_id')) {
  222. $param .= '&menu_id=' . $menu_id . '';
  223. }
  224. if (!$project) {
  225. if ($key == 'add' || $key == 'update' || $key == 'delete' || $key == 'recovery') {
  226. $project = $this->project;
  227. } else {
  228. $project = Dever::input('oper_project', $this->project);
  229. }
  230. }
  231. $param = 'project=' . $project . $param . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id . $state . $suffix;
  232. //echo $key . "\r\n";
  233. //echo $param ."\r\n";
  234. $this->param[$index] = $param;
  235. return $param;
  236. }
  237. /**
  238. * 获得refer
  239. *
  240. * @return string
  241. */
  242. private function refer($type = 'project')
  243. {
  244. return '';
  245. switch ($type) {
  246. case 'project':
  247. $name = '数据库操作';
  248. break;
  249. case 'list':
  250. $name = '数据列表';
  251. break;
  252. case 'url':
  253. $name = '项目列表';
  254. break;
  255. }
  256. $name = '返回上一级';
  257. $url = $this->url($type);
  258. $refer = '-[<a href="' . $url . '">' . $name . '</a>]';
  259. return $refer;
  260. }
  261. /**
  262. * getAdminInfo
  263. *
  264. * @return array
  265. */
  266. private function getAdminInfo($data)
  267. {
  268. $admin = Dever::load('manage/auth.info');
  269. $data['my_admin_id'] = $admin['id'];
  270. $data['my_role_id'] = $admin['role'];
  271. return $data;
  272. }
  273. /**
  274. * cookie 处理cookie
  275. *
  276. * @return array
  277. */
  278. public function cookie()
  279. {
  280. $cookie = $_COOKIE;
  281. $array = array();
  282. # 判断手机版
  283. $mobile = Dever::mobile();
  284. if ((isset($cookie['left_menu']) && $cookie['left_menu'] == 'close') || $mobile) {
  285. $array['wrapper'] = 'enlarged forced';
  286. } else {
  287. $array['wrapper'] = 'forced';
  288. }
  289. return $array;
  290. }
  291. /**
  292. * listStyle
  293. *
  294. * @return array
  295. */
  296. public function listStyle()
  297. {
  298. $mobile = Dever::mobile();
  299. if ($mobile) {
  300. $style = '.container_list .panel-heading .form-control,#mul .form-control,#page .form-control
  301. {
  302. width:70%;
  303. }
  304. .row
  305. {
  306. margin-right: -15px;
  307. margin-left: -15px;
  308. }
  309. #dever_modal_body img
  310. {
  311. max-width:300px;
  312. }
  313. ';
  314. } else {
  315. $style = '#dever_modal_body img
  316. {
  317. max-width:300px;
  318. }';
  319. }
  320. return $style;
  321. }
  322. /**
  323. * info 处理一些基本的信息,供模板使用
  324. *
  325. * @return array
  326. */
  327. public function info()
  328. {
  329. if ($this->info) {
  330. return $this->info;
  331. }
  332. $config = $this->config();
  333. $menu = isset($config['lang']) ? $config['lang'] : $this->project . '-' . $this->table;
  334. if (isset($config['state']) && $config['state'] == 2) {
  335. $menu .= '[回收站]';
  336. }
  337. $top = Dever::load('manage/top.get');
  338. //print_r($top);die;
  339. $this->info = array
  340. (
  341. 'action' => $this->url('updateAction'),
  342. 'list' => $this->url('list'),
  343. 'search' => $this->url('search'),
  344. 'mul' => $this->url('list'),
  345. //'add' => 'location.href=\'' . $this->url('add') . '\'',
  346. 'add' => $this->url('add'),
  347. 'state' => $this->getState(),
  348. 'l' => 'project/database/list',
  349. 'project' => $this->project,
  350. 'table' => $this->table,
  351. 'menu' => $this->menu,
  352. 'menu_id' => $this->menu_id,
  353. 'id' => $this->id,
  354. 'main' => '数据管理' . $this->refer('url'),
  355. 'list_header' => $menu,
  356. 'list_desc' => '数据列表',
  357. 'project_name' => Dever::load('manage/project.name', $this->project),
  358. 'update_header' => $menu,
  359. 'update_desc' => '更新数据',
  360. 'updateMul' => (!$this->id && isset($config['manage']['updateMul']) && $config['manage']['updateMul']) ? '增加一条' : false,
  361. 'updateDesc' => isset($config['manage']['desc']) ? $config['manage']['desc'] : '',
  362. 'listInfo' => isset($config['info']) ? $config['info'] : '',
  363. 'listDesc' => isset($config['desc']) ? $config['desc'] : '',
  364. 'struct' => isset($config['manage']['struct']) ? $config['manage']['struct'] : '',
  365. 'stat_desc' => '主动统计',
  366. 'search_param' => '',
  367. );
  368. # 此处为了兼容旧版本的一些设置
  369. $this->info['parent'] = Dever::input('oper_table', Dever::input('oper_parent'));
  370. # 返回上一页
  371. if ($this->info['parent']) {
  372. $oper = Dever::preInput('oper_');
  373. if ($oper) {
  374. $this->info['parent'] .= '&' . str_replace('oper_', '', http_build_query($oper));
  375. }
  376. $search = Dever::preInput('search_');
  377. if ($search) {
  378. $this->info['parent'] .= '&' . http_build_query($search);
  379. }
  380. $send = Dever::preInput('send_');
  381. if ($send) {
  382. $this->info['parent'] .= '&' . http_build_query($send);
  383. }
  384. $top = Dever::preInput('top_');
  385. if ($top) {
  386. $top_query = http_build_query($top);
  387. if (strstr($top_query, '.')) {
  388. foreach ($top as $k => $v) {
  389. $temp = explode('.', $v);
  390. $k = str_replace('top_', '', $k);
  391. $this->info['parent'] .= '&oper_' . $k . '=' . $temp[0];
  392. if (isset($temp[1])) {
  393. $this->info['parent'] .= '&top_' . $k . '=' . $temp[1];
  394. }
  395. }
  396. } else {
  397. $this->info['parent'] .= '&' . str_replace('top_', 'oper_', $top_query);
  398. }
  399. }
  400. $this->info['parent_project'] = Dever::input('oper_project');
  401. $this->info['parent'] = $this->url(Dever::input('oper_index', 'listData'), 0, $this->info['parent'], '', $this->info['parent_project']);
  402. }
  403. # 保存页面
  404. $this->info['save'] = Dever::input('oper_save_table', Dever::input('oper_save_jump'));
  405. if ($this->info['save']) {
  406. $this->info['save_project'] = Dever::input('oper_save_project');
  407. $this->info['list'] = $this->url(Dever::input('oper_index', 'list'), 0, $this->info['save'], '', $this->info['save_project']);
  408. }
  409. $search = Dever::preInput('search_');
  410. if ($search) {
  411. $this->info['mul'] .= '&' . http_build_query($search);
  412. if (layadmin()) {
  413. foreach ($search as $k => $v) {
  414. if (!strstr($k, 'search_option_')) {
  415. if (is_array($v)) {
  416. $v = implode(',', $v);
  417. }
  418. $this->info['search_param'] .= '<input type="hidden" name="'.$k.'" value="'.$v.'"/>';
  419. }
  420. }
  421. }
  422. }
  423. if ($this->id) {
  424. $this->info['update_header'] = $menu . '-更新数据' . $this->refer('list');
  425. }
  426. return $this->info;
  427. }
  428. /**
  429. * 获取表名
  430. *
  431. * @return array
  432. */
  433. public function getTableName($project, $table)
  434. {
  435. if ($project == 'other') {
  436. return '无数据表';
  437. }
  438. $path = Dever::load('manage/project.path', $project);
  439. $config = $this->config($project, $path, $table);
  440. $data = isset($config['lang']) ? $config['lang'] : $project;
  441. return $data;
  442. }
  443. private function getState()
  444. {
  445. return Dever::input('search_option_state', 1);
  446. }
  447. /**
  448. * config
  449. *
  450. * @return array
  451. */
  452. public function config($project = false, $path = false, $table = false)
  453. {
  454. if (!$project) {
  455. $project = $this->project;
  456. $table = $this->table;
  457. }
  458. if (!$project) {
  459. return array();
  460. }
  461. Dever::$global['manage']['project'] = $project;
  462. $config = Dever::load('manage/project.config', $project);
  463. if (!is_array($config)) {
  464. Dever::alert($project . ' error');
  465. }
  466. $project = $config['name'];
  467. if (!$path) {
  468. if (isset($config['base']) && isset($config['rel'])) {
  469. $path = DEVER_INCLUDE_PATH . $config['rel'];
  470. } else {
  471. $path = $config['path'];
  472. }
  473. }
  474. if ($project && $path && empty($this->config[$path])) {
  475. $this->config[$path] = array();
  476. $dir = $path . 'database/';
  477. if (is_dir($dir)) {
  478. $database = scandir($dir);
  479. foreach ($database as $k => $v) {
  480. if (strpos($v, '.php') !== false) {
  481. $k = str_replace('.php', '', $v);
  482. $this->config[$path][$k] = $this->struct($dir . $v, $project);
  483. }
  484. }
  485. }
  486. }
  487. if (isset($this->config[$path][$table])) {
  488. return $this->config[$path][$table];
  489. }
  490. return $this->config[$path];
  491. }
  492. # 得到重写的配置
  493. public function getConfig()
  494. {
  495. $config = $this->config();
  496. if (!isset($config['info'])) {
  497. $config['info'] = '';
  498. }
  499. if (!isset($config['desc'])) {
  500. $config['desc'] = '';
  501. }
  502. $manage = Dever::config('base')->manage;
  503. if ($manage) {
  504. if (isset($manage['info'])) {
  505. $config['info'] = $manage['info'];
  506. }
  507. if (isset($manage['desc'])) {
  508. $config['desc'] = $manage['desc'];
  509. }
  510. }
  511. return $config;
  512. }
  513. /**
  514. * 对database配置文件进行解析
  515. *
  516. * @return array
  517. */
  518. private function struct($file, $project = false)
  519. {
  520. $config = include $file;
  521. if (isset($config['struct']) && is_array($config['struct']['id'])) {
  522. $config['update'] = false;
  523. $config['manage']['struct'] = '<table border=1 width=100% height=100%>';
  524. $config['level'] = 1;
  525. foreach ($config['struct'] as $k => $v) {
  526. if (isset($v['level'])) {
  527. $config['level'] = 3;
  528. }
  529. if (isset($v['search_parent'])) {
  530. $config['manage']['search_parent'][$v['search_parent']] = $k;
  531. $config['manage']['search_child'][$k] = $v['search_parent'];
  532. }
  533. if (!isset($config['search'])) {
  534. if (isset($v['search']) && is_string($v['search'])) {
  535. if ($v['search'] == 'sday') {
  536. $config['manage']['search']['sday'][$k]['key'] = $v['search'];
  537. $config['manage']['search']['sday'][$k]['lang'] = $v['name'];
  538. } elseif ($v['search'] == 'sdate') {
  539. $config['manage']['search']['sdate'][$k]['key'] = $v['search'];
  540. $config['manage']['search']['sdate'][$k]['lang'] = $v['name'];
  541. } elseif (strpos($v['search'], 'time') !== false || strpos($v['search'], 'day') !== false) {
  542. $config['manage']['search']['day'][$k]['key'] = $v['search'];
  543. $config['manage']['search']['day'][$k]['lang'] = $v['name'];
  544. } elseif (strpos($v['search'], 'date') !== false) {
  545. $config['manage']['search']['date'][$k]['key'] = $v['search'];
  546. $config['manage']['search']['date'][$k]['lang'] = $v['name'];
  547. } elseif (strpos($v['search'], 'year') !== false) {
  548. $config['manage']['search']['year'][$k]['key'] = $v['search'];
  549. $config['manage']['search']['year'][$k]['lang'] = $v['name'];
  550. } elseif (strpos($v['search'], 'month') !== false) {
  551. $config['manage']['search']['month'][$k]['key'] = $v['search'];
  552. $config['manage']['search']['month'][$k]['lang'] = $v['name'];
  553. }
  554. if (strpos($v['search'], 'exp') !== false) {
  555. $config['manage']['search']['exp'][$k] = $v['name'];
  556. }
  557. if (strpos($v['search'], 'ins') !== false) {
  558. $config['manage']['search']['ins'][$k] = $v['name'];
  559. }
  560. if (strpos($v['search'], 'fulltext') !== false) {
  561. $config['manage']['search']['fulltext'][$k] = $v['name'];
  562. isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like_score');
  563. } elseif (strpos($v['search'], 'text') !== false) {
  564. $config['manage']['search']['text'][$k] = $v['name'];
  565. } elseif (strpos($v['search'], 'hidden') !== false) {
  566. $config['manage']['search']['hidden'][$k] = $v['name'];
  567. }
  568. if (isset($v['exist']) && strpos($v['search'], 'exist') !== false) {
  569. $config['manage']['search']['exist'][$k]['option'] = $v['exist'];
  570. $config['manage']['search']['exist'][$k]['lang'] = $v['name'];
  571. }
  572. if (isset($v['option']) && strpos($v['search'], 'selects') !== false) {
  573. $config['manage']['search']['selects'][$k]['option'] = $v['option'];
  574. $config['manage']['search']['selects'][$k]['lang'] = $v['name'];
  575. if (isset($v['default'])) {
  576. $config['manage']['search']['selects'][$k]['default'] = $v['default'];
  577. }
  578. } elseif (isset($v['option']) && strpos($v['search'], 'select') !== false) {
  579. $config['manage']['search']['select'][$k]['option'] = $v['option'];
  580. $config['manage']['search']['select'][$k]['lang'] = $v['name'];
  581. if (isset($v['default'])) {
  582. $config['manage']['search']['select'][$k]['default'] = $v['default'];
  583. }
  584. }
  585. if (isset($v['option']) && strpos($v['search'], 'group') !== false) {
  586. $config['manage']['search']['group'][$k]['option'] = $v['option'];
  587. $config['manage']['search']['group'][$k]['lang'] = $v['name'];
  588. if (isset($v['default'])) {
  589. $config['manage']['search']['group'][$k]['default'] = $v['default'];
  590. }
  591. }
  592. if (isset($v['option']) && strpos($v['search'], 'linkage') !== false) {
  593. $config['manage']['search']['linkage'][$k]['option'] = $v['option'];
  594. $config['manage']['search']['linkage'][$k]['lang'] = $v['name'];
  595. if (isset($v['default'])) {
  596. $config['manage']['search']['linkage'][$k]['default'] = $v['default'];
  597. }
  598. }
  599. } elseif (isset($v['search']) && is_array($v['search'])) {
  600. if (isset($v['search']['api'])) {
  601. $config['manage']['search']['api'][$k] = $v['search'];
  602. $config['manage']['search']['api'][$k]['lang'] = $v['name'];
  603. }
  604. }
  605. if (isset($v['search_button'])) {
  606. $config['manage']['search']['button'][$k] = $v['search_button'];
  607. }
  608. }
  609. /*
  610. if (isset($v['table']) && !isset($config['end'])) {
  611. $config['end']['insert'] = $v['value'];
  612. }
  613. */
  614. if (isset($v['update'])) {
  615. if (!isset($config['manage']['insert'])) {
  616. $config['manage']['insert'] = true;
  617. }
  618. $config['update'] = true;
  619. }
  620. if (isset($v['type'])) {
  621. $config['manage']['struct'] .= Dever::tbody(array($k, $v['type'], $v['name']));
  622. }
  623. }
  624. $config['manage']['struct'] .= '</table>';
  625. $config['manage']['_list'] = array
  626. (
  627. 'col' => 'manage',
  628. 'name' => '管理',
  629. 'value' => array(),
  630. );
  631. if (!isset($config['manage']['edit']) || (isset($config['manage']['edit']) && $config['manage']['edit'] == true)) {
  632. if (!isset($config['manage']['list_button']['update'])) {
  633. $config['manage']['_list']['value']['update'] = '编辑';
  634. }
  635. }
  636. if (isset($config['manage']['list'][0]) && is_array($config['manage']['list'][0])) {
  637. $config['manage']['_list']['value'] += $config['manage']['list'][0];
  638. unset($config['manage']['list'][0]);
  639. } elseif (isset($config['manage']['list_button'])) {
  640. $config['manage']['_list']['value'] += $config['manage']['list_button'];
  641. }
  642. if (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] == true)) {
  643. if (!isset($config['manage']['list_button']['delete'])) {
  644. $config['manage']['_list']['value']['delete'] = '删除';
  645. }
  646. }
  647. if (!$config['manage']['_list']['value']) {
  648. unset($config['manage']['_list']);
  649. }
  650. if (isset($config['manage']['list_type'])) {
  651. $config['manage']['list_table'] = 'html';
  652. }
  653. # 新增排序
  654. $l = isset($_GET['l']) ? $_GET['l'] : '';
  655. if ($l == 'project/database/list' || $l == 'database.list_excel') {
  656. $list_order = array();
  657. $i = 0;
  658. foreach ($config['struct'] as $ki => $vi) {
  659. if (isset($vi['list_order'])) {
  660. $list_order[] = $vi['list_order'];
  661. } else {
  662. $config['struct'][$ki]['list_order'] = $i;
  663. $list_order[] = $i;
  664. }
  665. $i++;
  666. }
  667. if ($list_order) {
  668. array_multisort($list_order, SORT_ASC, SORT_NUMERIC, $config['struct']);
  669. }
  670. }
  671. }
  672. $config['state'] = $this->getState();
  673. $config['project'] = $project;
  674. return $config;
  675. }
  676. /**
  677. * 自定义列表页面
  678. *
  679. * @return array
  680. */
  681. public function page($key = 'list')
  682. {
  683. $key = Dever::input('page_value', $key);
  684. $type = Dever::input('page_type', 1);
  685. $config = $this->config();
  686. $result = array();
  687. $result['s1'] = 'display:none';
  688. $result['s2'] = 'display:';
  689. $result['content'] = '';
  690. $key = 'page_' . $key;
  691. if (isset($config['manage'][$key]) && $type == 1) {
  692. if ($config['manage'][$key] == 'photo' && isset($config['manage']['photo'])) {
  693. $result['content'] = Dever::view('list/photo', false, 'manage');
  694. } else {
  695. $result['content'] = Dever::view($config['manage'][$key], 'manage', $this->project);
  696. }
  697. //echo $result['content'];die;
  698. if ($result['content']) {
  699. Dever::setInput('page_content', 1);
  700. $result['s1'] = 'display:';
  701. $result['s2'] = 'display:none';
  702. # 添加底部
  703. if ($key != 'page_list_table') {
  704. $result['content'] .= Dever::view('inc/foot', false, 'manage');
  705. }
  706. }
  707. } elseif (strstr($key, 'list_table')) {
  708. Dever::setInput('page_type', 2);
  709. }
  710. return $result;
  711. }
  712. /**
  713. * 自定义列表页面
  714. *
  715. * @return array
  716. */
  717. public function page_list()
  718. {
  719. return $this->page('list');
  720. }
  721. /**
  722. * 自定义列表页面 只接管table部分,同时必须传值page_type=1
  723. *
  724. * @return array
  725. */
  726. public function page_list_table()
  727. {
  728. $type = Dever::input('page_type', 2);
  729. if ($type == 1) {
  730. return $this->page('list_table');
  731. } else {
  732. return $this->page('list_table_default');
  733. }
  734. }
  735. /**
  736. * 自定义列表页面
  737. *
  738. * @return array
  739. */
  740. public function page_update()
  741. {
  742. return $this->page('update');
  743. }
  744. /**
  745. * 载入自定义资源
  746. *
  747. * @return array
  748. */
  749. public function res()
  750. {
  751. $result = array
  752. (
  753. 'js' => '',
  754. 'css' => '',
  755. );
  756. if (!$this->project) {
  757. return $result;
  758. }
  759. $config = $this->config();
  760. if (isset($config['manage']['res'])) {
  761. foreach ($config['manage']['res'] as $k => $v) {
  762. $result[$k] = $this->getRes($k, $v);
  763. }
  764. }
  765. return $result;
  766. }
  767. /**
  768. * getRes
  769. *
  770. * @return string
  771. */
  772. protected function getRes($path, $value)
  773. {
  774. if (is_array($value)) {
  775. $res = '';
  776. foreach ($value as $k => $v) {
  777. $res .= $this->getRes($path, $v);
  778. }
  779. return $res;
  780. } else {
  781. if ($this->project != 'manage') {
  782. $base = str_replace('assets/', 'assets/manage/', Dever::config('host', $this->project)->$path);
  783. } else {
  784. $base = Dever::config('host', $this->project)->$path;
  785. }
  786. $file = $base . $value . '.' . $path;
  787. if ($path == 'js') {
  788. $res = '<script type="text/javascript" src="'.$file.'"></script>';
  789. } else {
  790. $res = '<link rel="stylesheet" type="text/css" href="'.$file.'">
  791. ';
  792. }
  793. return $res;
  794. }
  795. }
  796. /**
  797. * 头部banner
  798. *
  799. * @return array
  800. */
  801. public function banner()
  802. {
  803. if (!$this->project) {
  804. return '';
  805. }
  806. $config = $this->config();
  807. $result = '';
  808. if (isset($config['manage']['banner'])) {
  809. foreach ($config['manage']['banner'] as $k => $v) {
  810. $config['manage']['banner'][$k] = $this->value($v, 'yes');
  811. }
  812. if (empty($config['manage']['banner']['link'])) {
  813. $config['manage']['banner']['link'] = '#';
  814. $config['manage']['banner']['target'] = '_self';
  815. }
  816. if (empty($config['manage']['banner']['target'])) {
  817. $config['manage']['banner']['target'] = '_blank';
  818. }
  819. $result = '<a target="' . $config['manage']['banner']['target'] . '" href="' . $config['manage']['banner']['link'] . '"><img src="' . $config['manage']['banner']['img'] . '"></a>
  820. <span>' . $config['manage']['banner']['name'] . '</span>';
  821. }
  822. return $result;
  823. }
  824. /**
  825. * 列表页搜索
  826. *
  827. * @return array
  828. */
  829. public function list_search_select(&$result, $search, $name, $lang, $option, $default = false, $bind = array(), $parent = '', $mul = false)
  830. {
  831. $value = array();
  832. if (strpos($lang, '-')) {
  833. $temp = explode('-', $lang);
  834. $lang = $temp[0];
  835. }
  836. $value['name'] = $name;
  837. $value['lang'] = $lang;
  838. $value['option'] = $option;
  839. if (isset($search[$name])) {
  840. $value['value'] = $search[$name];
  841. }
  842. if ($default) {
  843. //$value['default'] = $default;
  844. }
  845. if ($bind) {
  846. $value['bind'] = $bind;
  847. }
  848. $value['parent'] = $parent;
  849. if ($mul) {
  850. $value['update'] = 'selects';
  851. $value['match'] = 'option';
  852. }
  853. $result .= Html::select($value, false);
  854. }
  855. /**
  856. * 列表页搜索
  857. *
  858. * @return array
  859. */
  860. public function list_search_group(&$result, $search, $name, $lang, $option, $default = false)
  861. {
  862. $value = array();
  863. $value['name'] = $name;
  864. $value['lang'] = $lang;
  865. $value['option'] = $option;
  866. if (isset($search[$name])) {
  867. $value['value'] = $search[$name];
  868. }
  869. if ($default) {
  870. //$value['default'] = $default;
  871. }
  872. $result .= Html::group($value, false);
  873. }
  874. /**
  875. * 列表页搜索
  876. *
  877. * @return array
  878. */
  879. public function list_search_linkage(&$result, $search, $name, $lang, $option, $default = false)
  880. {
  881. $value = array();
  882. $value['name'] = $name;
  883. $value['lang'] = $lang;
  884. $value['option'] = $option;
  885. $value['search_state'] = true;
  886. if (isset($search[$name])) {
  887. $value['value'] = $search[$name];
  888. }
  889. if ($default) {
  890. //$value['default'] = $default;
  891. }
  892. $result .= Html::linkage($value, 'span');
  893. }
  894. /**
  895. * 列表页搜索
  896. *
  897. * @return array
  898. */
  899. public function list_search_time(&$result, $search, $prefix, $key, $config, $type = 'time')
  900. {
  901. $start = $end = true;
  902. $eq = false;
  903. if (is_array($config)) {
  904. $lang = $config['lang'];
  905. $search_key = $config['key'];
  906. if (strstr($search_key, '_')) {
  907. $temp = explode('_', $search_key);
  908. $start = $end = false;
  909. if (isset($temp[1])) {
  910. if ($temp[1] == 'start') {
  911. $start = true;
  912. } elseif ($temp[1] == 'end') {
  913. $end = true;
  914. } elseif ($temp[1] == 'eq') {
  915. $eq = true;
  916. }
  917. }
  918. }
  919. } else {
  920. $lang = $config;
  921. }
  922. if ($eq) {
  923. $value['name'] = $prefix . 'option_' . $key;
  924. $value['lang'] = $lang;
  925. if (isset($search[$value['name']])) {
  926. $value['value'] = Dever::maketime($search[$value['name']]);
  927. Dever::setInput($value['name'], $value['value'], 'search_');
  928. }
  929. $result .= Html::$type($value, false);
  930. }
  931. if ($start) {
  932. $value['name'] = $prefix . 'option_start_' . $key;
  933. $value['lang'] = '>=' . $lang;
  934. if (isset($search[$value['name']])) {
  935. $value['value'] = Dever::maketime($search[$value['name']]);
  936. Dever::setInput($value['name'], $value['value'], 'search_');
  937. }
  938. $result .= Html::$type($value, false);
  939. }
  940. if ($end) {
  941. $value['name'] = $prefix . 'option_end_' . $key;
  942. $value['lang'] = '<=' . $lang;
  943. if (isset($search[$value['name']])) {
  944. $value['value'] = Dever::maketime($search[$value['name']]);
  945. Dever::setInput($value['name'], $value['value'], 'search_');
  946. }
  947. $result .= Html::$type($value, false);
  948. }
  949. }
  950. /**
  951. * 列表页头部按钮
  952. *
  953. * @return array
  954. */
  955. public function list_button()
  956. {
  957. /*
  958. if (Dever::load('manage/auth.oper', 2) == false) {
  959. return '';
  960. }
  961. */
  962. $button = array();
  963. $config = $this->config();
  964. $result = '';
  965. # 增加返回上一页按钮
  966. $info = $this->info();
  967. if ($info['parent']) {
  968. $parent_name = '返回上一页';
  969. $parent_show = false;
  970. if (isset($config['manage']['parent']) && $config['manage']['parent']) {
  971. if (is_string($config['manage']['parent'])) {
  972. $parent_name = $config['manage']['parent'];
  973. }
  974. $parent_show = true;
  975. } elseif (!isset($config['manage']['parent'])) {
  976. $parent_show = true;
  977. }
  978. if ($parent_show) {
  979. $button[$parent_name] = $info['parent'];
  980. }
  981. }
  982. if ($info['add']) {
  983. $add_name = '新增';
  984. $add_show = false;
  985. if (isset($config['manage']['insert']) && $config['manage']['insert']) {
  986. if (is_string($config['manage']['insert'])) {
  987. $add_name = $config['manage']['insert'];
  988. }
  989. $add_show = true;
  990. } elseif (!isset($config['manage']['insert'])) {
  991. $add_show = true;
  992. }
  993. $insert_state = Dever::load('manage/auth.oper', 4);
  994. if ($insert_state) {
  995. if ($add_show) {
  996. $button[$add_name] = $info['add'];
  997. }
  998. } elseif (isset($config['manage']['button']['新增'])) {
  999. unset($config['manage']['button']['新增']);
  1000. }
  1001. }
  1002. # 增加主动统计按钮
  1003. if ($this->state && isset($config['manage']['stat'])) {
  1004. $name = '数据统计';
  1005. if (is_string($config['manage']['stat'])) {
  1006. $name = $config['manage']['stat'];
  1007. }
  1008. $button[$name] = $this->url('stat');
  1009. }
  1010. if (isset($config['manage']['button']) && $config['manage']['button']) {
  1011. $button += $config['manage']['button'];
  1012. }
  1013. # 增加下载报表按钮
  1014. if ($this->state && isset($config['manage']['excel']) && $config['manage']['excel']) {
  1015. $url = $this->url('excel');
  1016. if (is_array($config['manage']['excel'])) {
  1017. foreach ($config['manage']['excel'] as $k => $v) {
  1018. if (is_array($v)) {
  1019. $name = $v[0];
  1020. $u = $url . '&excel_name='.$v[1].'&excel_load=' . $v[2];
  1021. $button[$name] = 'onclick="jump(\''.$u.'\', \'#form1\')"';
  1022. } else {
  1023. $name = $v;
  1024. $button[$name] = 'onclick="jump(\''.$url.'\', \'#form1\')"';
  1025. }
  1026. }
  1027. } else {
  1028. $name = '导出数据';
  1029. if (is_string($config['manage']['excel']) && !strstr($config['manage']['excel'], '.')) {
  1030. $name = $config['manage']['excel'];
  1031. }
  1032. $button[$name] = 'onclick="jump(\''.$url.'\', \'#form1\')"';
  1033. }
  1034. }
  1035. # 增加回收站
  1036. 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'])))) {
  1037. if ($config['state'] == 2) {
  1038. $button['返回数据列表'] = $this->url('list', 0, false, '&search_option_state=1', $this->project);
  1039. } else {
  1040. $button['回收站'] = $this->url('list', 0, false, '&search_option_state=2', $this->project);
  1041. }
  1042. }
  1043. # 列表页按钮
  1044. if ($button) {
  1045. $result .= $this->list_button_show($button);
  1046. }
  1047. /*
  1048. if (Dever::load('manage/auth.oper', 6) != false && isset($config['manage']['button'])) {
  1049. $result .= $this->list_button_show($config['manage']['button']);
  1050. }*/
  1051. return $result;
  1052. }
  1053. /**
  1054. * 更新页按钮
  1055. *
  1056. * @return array
  1057. */
  1058. public function update_button()
  1059. {
  1060. # 新增权限
  1061. /*
  1062. if (Dever::load('manage/auth.oper', 2) == false) {
  1063. Dever::alert('你没有权限');
  1064. }
  1065. */
  1066. $info = $this->info();
  1067. $result = '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> 提交保存</button>
  1068. <a href="' . $info['list'] . '" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclicks="msg({status:1,msg:\'yes\'})">放弃保存</a>';
  1069. $config = $this->config();
  1070. if (isset($config['manage']['update_button']) && $config['manage']['update_button']) {
  1071. $result = '';
  1072. foreach ($config['manage']['update_button'] as $k => $v) {
  1073. if ($v == 'save-data') {
  1074. $result .= '<button type="button" class="btn btn-primary save-data layui-btn layuiadmin-btn-list"><i class="fa fa-save"></i> ' . $k . '</button>';
  1075. } elseif ($v == 'copy-data') {
  1076. $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>';
  1077. } elseif ($v == 'copy-datas') {
  1078. $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="copy_data($(this))">' . $k . '</a>';
  1079. } else {
  1080. $result .= '<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="' . $v . '">' . $k . '</a>';
  1081. }
  1082. }
  1083. }
  1084. return $result;
  1085. }
  1086. private function list_button_show($button)
  1087. {
  1088. $result = '';
  1089. $refer = Dever::input('refer');
  1090. if ($refer) {
  1091. $button['返回上一页'] = array('location', Dever::decode($refer));
  1092. }
  1093. # 不显示哪个按钮
  1094. $manage = Dever::config('base')->manage;
  1095. foreach ($button as $k => $v) {
  1096. if ($manage && isset($manage['deleteButton']) && in_array($k, $manage['deleteButton'])) {
  1097. continue;
  1098. }
  1099. # 增加细分权限
  1100. /*
  1101. if (!Dever::load('manage/auth.check', $k, $this->menu_id)) {
  1102. continue;
  1103. }
  1104. */
  1105. if (is_array($v)) {
  1106. if ($v[0] == 'location') {
  1107. if ($v[1] == 'add') {
  1108. $url = $this->url('add');
  1109. } elseif ($v[1] == 'list') {
  1110. $url = $this->url('list');
  1111. } else {
  1112. $url = Dever::url($v[1]);
  1113. }
  1114. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="location.href=\''.$url.'\'">' . $k . '</a>';
  1115. } elseif ($v[0] == 'import') {
  1116. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $v[1] . '\')">' . $k . '</a>';
  1117. } elseif ($v[0] == 'excel' || $v[0] == 'search') {
  1118. $url = Dever::url($v[1]);
  1119. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="jump(\''.$url.'\', \'#form1\')">' . $k . '</a>';
  1120. } elseif ($v[0] == 'oper') {
  1121. $url = Dever::url($v[1]);
  1122. $content = '';
  1123. if (isset($v[2])) {
  1124. $content = $v[2];
  1125. }
  1126. $title = '';
  1127. if (isset($v[3])) {
  1128. $title = $v[3];
  1129. }
  1130. $url .= '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $k;
  1131. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list layui-btn-danger" href="javascript:;"onclick="load(\'' . $url . '\', \'' . $content . '\', \'' . $title . '\')">' . $k . '</a>';
  1132. } elseif ($v[0] == 'show') {
  1133. $url = Dever::url($v[1]);
  1134. $submit = '';
  1135. if (isset($v[2])) {
  1136. $submit = Dever::url($v[2]);
  1137. }
  1138. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" onclick="loadPage(\''.$url.'\', \''.$k.'\',\''.$submit.'\')">' . $k . '</a>';
  1139. } elseif ($v[0] == 'fast') {
  1140. if (isset($v[2]) && $v[2]) {
  1141. $url = $this->url('add', $v[1], $v[2]);
  1142. } elseif (isset($v[1]) && $v[1]) {
  1143. $url = Dever::url($v[1]);
  1144. } else {
  1145. $url = $this->url('add');
  1146. }
  1147. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$url.'\',\''.$k.'\', \'\')">' . $k . '</a>';
  1148. } elseif ($v[0] == 'fasts') {
  1149. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$this->url('add').'\',\''.$k.'\', \'\', 1)">' . $k . '</a>';
  1150. } elseif ($v[0] == 'onclick') {
  1151. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" onclick="' . $v[1] . '">' . $k . '</a>';
  1152. } else {
  1153. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . $this->url($v[0], false, $v[1]) . '">' . $k . '</a>';
  1154. }
  1155. } elseif (strpos($v, 'modal|') !== false) {
  1156. $t = explode('modal|', $v);
  1157. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $t[1] . '\')">' . $k . '</a>';
  1158. } elseif (strpos($v, '|') !== false) {
  1159. $t = explode('|', $v);
  1160. $result .= $t[0] . '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $t[1] . '>' . $k . '</a>';
  1161. } elseif (strpos($v, 'onclick') !== false) {
  1162. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $v . '>' . $k . '</a>';
  1163. } elseif (strpos($v, 'http://') !== false || strpos($v, 'https://') !== false) {
  1164. //$result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default" onclick="jump(\''.Dever::url($v).'\')">'.$k.'</a>';
  1165. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . Dever::url($v) . '">' . $k . '</a>';
  1166. } else {
  1167. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-danger layui-btn layuiadmin-btn-list layui-btn-danger" onclick="load(\'' . Dever::url($v) . '\')">' . $k . '</a>';
  1168. }
  1169. }
  1170. $result = ltrim($result, '&nbsp;&nbsp;');
  1171. return $result;
  1172. }
  1173. /**
  1174. * 列表页搜索
  1175. *
  1176. * @return array
  1177. */
  1178. public function list_search()
  1179. {
  1180. if (Dever::load('manage/auth.oper', 2) == false) {
  1181. return '';
  1182. }
  1183. # 将以下判断合并
  1184. # 权限验证
  1185. /*
  1186. if (!Dever::load('manage/auth.check', '搜索', $this->menu_id)) {
  1187. return '';
  1188. }
  1189. */
  1190. /*
  1191. # 新增权限
  1192. if (Dever::load('manage/auth.oper', 2) == false) {
  1193. return '';
  1194. }
  1195. if (!Dever::load('manage/auth.checkFunc', $this->menu_id, false, '搜索')) {
  1196. return '';
  1197. }
  1198. */
  1199. $config = $this->config();
  1200. $result = '';
  1201. $top_result = '';
  1202. # 搜索
  1203. if (isset($config['struct']) && isset($config['manage']['search']) && $config['manage']['search']) {
  1204. $search = Dever::preInput('search_');
  1205. $node = Html::node(array(' style="margin-top:0px;"', ''));
  1206. $btn = '<div class="layui-inline"><input type="hidden" value="2" name="excel" id="excel">';
  1207. if (isset($config['manage']['search']['button'])) {
  1208. foreach ($config['manage']['search']['button'] as $k => $v) {
  1209. $i = 0;
  1210. foreach ($v['option'] as $k1 => $v1) {
  1211. $value = $k . '~' . $v['sum'] . '~' . $k1;
  1212. if (isset($v['group'])) {
  1213. $value .= '~' . $v['group'];
  1214. }
  1215. if (!isset($search['search_button']) && $i == 0) {
  1216. $search['search_button'] = $value;
  1217. }
  1218. if (isset($search['search_button']) && $search['search_button'] == $value) {
  1219. $class = 'layui-btn-normal';
  1220. } else {
  1221. $class = 'layui-btn-primary';
  1222. }
  1223. $url = $this->url('list', 0, false, '&search_button=' . $value);
  1224. $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>&nbsp;&nbsp;';
  1225. }
  1226. }
  1227. }
  1228. $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>';
  1229. //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
  1230. $prefix = 'search_';
  1231. $result .= $node[0];
  1232. if (isset($config['manage']['search']['linkage'])) {
  1233. foreach ($config['manage']['search']['linkage'] as $k => $v) {
  1234. $this->list_search_linkage($result, $search, $prefix . 'linkage_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  1235. if (!layadmin()) {
  1236. $result .= '<br />';
  1237. }
  1238. }
  1239. }
  1240. if (isset($config['manage']['search']['selects'])) {
  1241. $this->list_search_br($result);
  1242. foreach ($config['manage']['search']['selects'] as $k => $v) {
  1243. $bind = array();
  1244. $parent = '';
  1245. $option = $this->option($v['option']);
  1246. if (isset($config['manage']['search_parent'][$k])) {
  1247. $bind = array
  1248. (
  1249. 'onchange',
  1250. 'setOption',
  1251. 'search_option_' . $config['manage']['search_parent'][$k]
  1252. );
  1253. }
  1254. elseif (isset($config['manage']['search_child'][$k])) {
  1255. $parent = $config['manage']['search_child'][$k];
  1256. }
  1257. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent, true);
  1258. }
  1259. }
  1260. if (isset($config['manage']['search']['select'])) {
  1261. $this->list_search_br($result);
  1262. foreach ($config['manage']['search']['select'] as $k => $v) {
  1263. $bind = array();
  1264. $parent = '';
  1265. $option = $this->option($v['option']);
  1266. if (isset($config['manage']['search_parent'][$k])) {
  1267. $bind = array
  1268. (
  1269. 'onchange',
  1270. 'setOption',
  1271. 'search_option_' . $config['manage']['search_parent'][$k]
  1272. );
  1273. }
  1274. elseif (isset($config['manage']['search_child'][$k])) {
  1275. $parent = $config['manage']['search_child'][$k];
  1276. }
  1277. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
  1278. }
  1279. }
  1280. if (isset($config['manage']['search']['exist'])) {
  1281. $this->list_search_br($result);
  1282. foreach ($config['manage']['search']['exist'] as $k => $v) {
  1283. $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
  1284. }
  1285. }
  1286. if (isset($config['manage']['search']['group'])) {
  1287. $this->list_search_br($result);
  1288. foreach ($config['manage']['search']['group'] as $k => $v) {
  1289. $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  1290. }
  1291. }
  1292. if (isset($config['manage']['search']['api'])) {
  1293. $this->list_search_br($result);
  1294. foreach ($config['manage']['search']['api'] as $k => $v) {
  1295. $value = array();
  1296. $value['name'] = $prefix . 'api_' . $k;
  1297. $value['class'] = 'form-control';
  1298. if (isset($search[$value['name']])) {
  1299. $value['value'] = $search[$value['name']];
  1300. }
  1301. if (strpos($v['lang'], '-') !== false) {
  1302. $t = explode('-', $v['lang']);
  1303. $v['lang'] = $t[0];
  1304. }
  1305. $value['placeholder'] = $v['lang'];
  1306. if (isset($v['option']) && $v['option']) {
  1307. $value['option'] = $this->option($v['option']);
  1308. $value['lang'] = $v['lang'];
  1309. if (isset($v['top']) && $v['top']) {
  1310. $top_result .= Html::select($value, false);
  1311. } else {
  1312. $result .= Html::select($value, false);
  1313. }
  1314. } else {
  1315. $result .= Html::text($value, false);
  1316. }
  1317. }
  1318. }
  1319. if (isset($config['manage']['search']['text'])) {
  1320. $this->list_search_br($result);
  1321. foreach ($config['manage']['search']['text'] as $k => $v) {
  1322. $value = array();
  1323. $value['name'] = $prefix . 'option_' . $k;
  1324. $value['class'] = 'form-control';
  1325. if (isset($search[$value['name']])) {
  1326. $value['value'] = $search[$value['name']];
  1327. }
  1328. if (strpos($v, '-') !== false) {
  1329. $t = explode('-', $v);
  1330. $v = $t[0];
  1331. }
  1332. $value['placeholder'] = $v;
  1333. $result .= Html::text($value, false);
  1334. }
  1335. }
  1336. if (isset($config['manage']['search']['hidden'])) {
  1337. $this->list_search_br($result);
  1338. foreach ($config['manage']['search']['hidden'] as $k => $v) {
  1339. $value = array();
  1340. $value['name'] = $prefix . 'option_' . $k;
  1341. $value['class'] = 'form-control';
  1342. if (isset($search[$value['name']])) {
  1343. $value['value'] = $search[$value['name']];
  1344. }
  1345. if (strpos($v, '-') !== false) {
  1346. $t = explode('-', $v);
  1347. $v = $t[0];
  1348. }
  1349. $value['placeholder'] = $v;
  1350. $value['type'] = 'hidden';
  1351. $result .= Html::hidden($value, false);
  1352. }
  1353. }
  1354. if (isset($config['manage']['search']['ins'])) {
  1355. $this->list_search_br($result);
  1356. foreach ($config['manage']['search']['ins'] as $k => $v) {
  1357. $value = array();
  1358. $value['name'] = $prefix . 'option_' . $k;
  1359. $value['class'] = 'form-control';
  1360. if (isset($search[$value['name']])) {
  1361. $value['value'] = $search[$value['name']];
  1362. }
  1363. if (strpos($v, '-') !== false) {
  1364. $t = explode('-', $v);
  1365. $v = $t[0];
  1366. }
  1367. $value['placeholder'] = $v;
  1368. $result .= Html::text($value, false);
  1369. }
  1370. }
  1371. if (isset($config['manage']['search']['fulltext'])) {
  1372. $this->list_search_br($result);
  1373. foreach ($config['manage']['search']['fulltext'] as $k => $v) {
  1374. $value = array();
  1375. $value['name'] = $prefix . 'fulltext_' . $k;
  1376. $value['class'] = 'form-control';
  1377. if (isset($search[$value['name']])) {
  1378. $value['value'] = $search[$value['name']];
  1379. }
  1380. if (strpos($v, '-') !== false) {
  1381. $t = explode('-', $v);
  1382. $v = $t[0];
  1383. }
  1384. $value['placeholder'] = $v;
  1385. $result .= Html::text($value, false);
  1386. }
  1387. }
  1388. if (isset($config['manage']['search']['exp'])) {
  1389. $result .= '<br />';
  1390. $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
  1391. $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
  1392. (
  1393. 3 => '大于',
  1394. 4 => '大于等于',
  1395. 5 => '小于',
  1396. 6 => '小于等于',
  1397. ), 1);
  1398. $value = array();
  1399. $value['name'] = $prefix . 'exp_value';
  1400. $value['class'] = 'form-control';
  1401. if (isset($search[$value['name']])) {
  1402. $value['value'] = $search[$value['name']];
  1403. }
  1404. $value['placeholder'] = '填写值';
  1405. $result .= Html::text($value, false);
  1406. }
  1407. if (isset($config['manage']['search']['day'])) {
  1408. foreach ($config['manage']['search']['day'] as $k => $v) {
  1409. $this->list_search_time($result, $search, $prefix, $k, $v, 'day');
  1410. }
  1411. }
  1412. if (isset($config['manage']['search']['date'])) {
  1413. foreach ($config['manage']['search']['date'] as $k => $v) {
  1414. $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
  1415. }
  1416. }
  1417. if (isset($config['manage']['search']['year'])) {
  1418. foreach ($config['manage']['search']['year'] as $k => $v) {
  1419. $this->list_search_time($result, $search, $prefix, $k, $v, 'year');
  1420. }
  1421. }
  1422. if (isset($config['manage']['search']['month'])) {
  1423. foreach ($config['manage']['search']['month'] as $k => $v) {
  1424. $this->list_search_time($result, $search, $prefix, $k, $v, 'month');
  1425. }
  1426. }
  1427. if (isset($config['manage']['search']['sday'])) {
  1428. $result .= '<br />';
  1429. foreach ($config['manage']['search']['sday'] as $k => $v) {
  1430. $this->list_search_time($result, $search, $prefix, $k, $v, 'sday');
  1431. }
  1432. $sday = Dever::input('search_option_sday');
  1433. $s1 = $s2 = $s3 = '';
  1434. if ($sday == 7) {
  1435. $s2 = 'sday_button_border';
  1436. } elseif ($sday == 30) {
  1437. $s3 = 'sday_button_border';
  1438. } elseif ($sday) {
  1439. $s1 = 'sday_button_border';
  1440. }
  1441. $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>';
  1442. $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>';
  1443. $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>';
  1444. $result .= '<input type="hidden" name="search_option_sday" id="search_option_sday" value="0">';
  1445. } elseif (isset($config['manage']['search']['sdate'])) {
  1446. $result .= '<br />';
  1447. foreach ($config['manage']['search']['sdate'] as $k => $v) {
  1448. $this->list_search_time($result, $search, $prefix, $k, $v, 'sdate');
  1449. }
  1450. $sdate = Dever::input('search_option_sdate');
  1451. $s1 = $s2 = $s3 = '';
  1452. if ($sdate == 7) {
  1453. $s2 = 'sdate_button_border';
  1454. } elseif ($sdate == 30) {
  1455. $s3 = 'sdate_button_border';
  1456. } elseif ($sdate) {
  1457. $s1 = 'sdate_button_border';
  1458. }
  1459. $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>';
  1460. $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>';
  1461. $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>';
  1462. $result .= '<input type="hidden" name="search_option_sdate" id="search_option_sdate" value="0">';
  1463. }
  1464. # 列表页按钮
  1465. if (isset($config['manage']['search_button'])) {
  1466. $btn .= $this->list_button_show($config['manage']['search_button']);
  1467. }
  1468. $result .= $btn . $node[1];
  1469. //$result .= '</form>';
  1470. # 增加每页显示条数
  1471. $config['manage']['num'] = $this->getNumConfig($config);
  1472. /*
  1473. if ($config['manage']['num']) {
  1474. $result = $this->num($result, $config['manage']['num']);
  1475. }
  1476. */
  1477. }
  1478. $oper = Dever::preInput('oper_');
  1479. if ($oper) {
  1480. foreach ($oper as $k => $v) {
  1481. $result .= '<input type="hidden" value="'.$v.'" name="'.$k.'" id="'.$k.'" />';
  1482. }
  1483. }
  1484. $top = Dever::input('top_parent');
  1485. if ($top) {
  1486. $result .= '<input type="hidden" value="'.$top.'" name="top_parent" id="top_parent" />';
  1487. }
  1488. $page_type = Dever::input('page_type');
  1489. if ($page_type) {
  1490. $result .= '<input type="hidden" value="'.$page_type.'" name="page_type" id="page_type" />';
  1491. }
  1492. if ($top_result) {
  1493. $result = $top_result . $result;
  1494. }
  1495. return $result;
  1496. }
  1497. private function list_search_br(&$result)
  1498. {
  1499. if (strpos($result, '&nbsp;&nbsp;') && !strpos($result, '<br />')) {
  1500. $result .= '<br />';
  1501. }
  1502. }
  1503. /**
  1504. * 获取条数配置
  1505. *
  1506. * @return array
  1507. */
  1508. private function getNumConfig($config)
  1509. {
  1510. if (isset($config['manage']['list_type'])) {
  1511. return false;
  1512. }
  1513. if (isset($config['manage']['num']) && $config['manage']['num'] == false) {
  1514. return false;
  1515. }
  1516. if (!isset($config['manage']['num'])) {
  1517. $config['manage']['num'] = array(20,30,40,50,60,70,80,90,100);
  1518. }
  1519. Dever::config('base')->page_num = $config['manage']['num'];
  1520. return $config['manage']['num'];
  1521. }
  1522. /**
  1523. * 生成条数的html
  1524. *
  1525. * @return string
  1526. */
  1527. private function num($result, $config)
  1528. {
  1529. return $result;
  1530. $limit = '';
  1531. $cur = Dever::input('search_limit', 0);
  1532. foreach($config as $k => $v) {
  1533. if ($cur == $k) {
  1534. $btn = 'success';
  1535. } else {
  1536. $btn = 'default';
  1537. }
  1538. $url = $this->url('list', 0, false, '&search_limit=' . $k);
  1539. $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.' layui-btn layui-btn-radius layui-btn-primary">'.$v.'</a> ';
  1540. }
  1541. $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>';
  1542. /*
  1543. if (layadmin()) {
  1544. $num = '';
  1545. }*/
  1546. $result .= $num;
  1547. return $result;
  1548. }
  1549. /**
  1550. * 列表页表格头
  1551. *
  1552. * @return array
  1553. */
  1554. public function list_thead($type = false)
  1555. {
  1556. if (Dever::load('manage/auth.oper', 1) == false) {
  1557. Dever::alert('你没有权限');
  1558. }
  1559. $config = $this->config();
  1560. if ($type == 'layui') {
  1561. if (!isset($config['manage']['list_table']) || (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'html')) {
  1562. return false;
  1563. }
  1564. } else {
  1565. if (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'js') {
  1566. return '';
  1567. }
  1568. }
  1569. $result = array();
  1570. /*
  1571. $tbody = Dever::load('manage/database.list_tbody');
  1572. if (!$tbody) {
  1573. return $result;
  1574. }
  1575. */
  1576. if (isset($config['struct'])) {
  1577. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  1578. # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
  1579. if (isset($config['top']) && is_string($config['top'])) {
  1580. $top = Dever::load('manage/auth.getTop', array($config['top']));
  1581. if ($top) {
  1582. $url = $this->url('update', $top['value']);
  1583. }
  1584. } else {
  1585. $url = $this->url('update', Dever::input('where_id', 1));
  1586. }
  1587. return Dever::location($url);
  1588. } else {
  1589. if (isset($config['manage']['mul']) && $config['manage']['mul']) {
  1590. if ($type == 'layui') {
  1591. $layui = array
  1592. (
  1593. 'field' => 'checkbox',
  1594. 'title' => '<input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list" lay-ignore/>',
  1595. //'fixed' => 'left',
  1596. );
  1597. $result[] = $layui;
  1598. } else {
  1599. $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
  1600. }
  1601. }
  1602. $data = array();
  1603. $data = $this->getAdminInfo($data);
  1604. foreach ($config['struct'] as $k => $v) {
  1605. if (isset($v['list']) && $v['list']) {
  1606. # 处理权限
  1607. if (isset($v['auth'])) {
  1608. $auth = $this->value($v['auth'], $data);
  1609. if (!$auth) {
  1610. continue;
  1611. }
  1612. }
  1613. if (isset($v['list_name'])) {
  1614. $v['name'] = $v['list_name'];
  1615. } else {
  1616. $temp = Html::cue(array('name' => $v['name']));
  1617. $v['name'] = $temp['name'];
  1618. }
  1619. if (!isset($v['level'])) {
  1620. $v['level'] = $config['level'];
  1621. }
  1622. if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
  1623. $link = Dever::url();
  1624. $order = 'search_order_' . $k . '';
  1625. if (strpos($link, $order) !== false) {
  1626. $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
  1627. } else {
  1628. $link .= '{order}';
  1629. }
  1630. $search = Dever::input($order);
  1631. $cancel = '';
  1632. if ($search) {
  1633. $asc = $search;
  1634. $cancel = '&nbsp;<a class="glyphicon glyphicon-remove-sign layui-icon layui-icon-close" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
  1635. } else {
  1636. $asc = 'desc';
  1637. if (!isset($v['order']) && $k != 'id') {
  1638. //$cancel = '&nbsp;<a class="glyphicon glyphicon-circle-arrow-down layui-icon layui-icon-up" style="color:black;" href="' . str_replace('{order}', '&' . $order . '=desc', $link) . '" title="降序"></a>';
  1639. }
  1640. }
  1641. if ($asc == 'asc') {
  1642. $asc = 'desc';
  1643. $icon = 'down';
  1644. $text = '降序';
  1645. } else {
  1646. $asc = 'asc';
  1647. $icon = 'up';
  1648. $text = '升序';
  1649. }
  1650. $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
  1651. if ($type == 'layui') {
  1652. $layui = array
  1653. (
  1654. 'field' => $k,
  1655. 'title' => '<a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . '&nbsp;<span class="layui-icon layui-icon-' . $icon . '" style="font-size:12px"></span></a>',
  1656. );
  1657. $result[] = $layui;
  1658. } else {
  1659. $result[] = '<th data-priority="'.$v['level'].'"><a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . '&nbsp;<span class="glyphicon glyphicon-circle-arrow-' . $icon . ' layui-icon layui-icon-' . $icon . '"></span></a>' . $cancel . '</th>';
  1660. }
  1661. } else {
  1662. if ($type == 'layui') {
  1663. if ($k == 'id' || isset($v['fixed'])) {
  1664. $layui = array
  1665. (
  1666. 'field' => $k,
  1667. 'title' => $v['name'],
  1668. //'fixed' => 'left',
  1669. );
  1670. } else {
  1671. $layui = array
  1672. (
  1673. 'field' => $k,
  1674. 'title' => $v['name'],
  1675. );
  1676. }
  1677. if (isset($v['list_header']) && $v['list_header']) {
  1678. $layui += $v['list_header'];
  1679. }
  1680. $result[] = $layui;
  1681. } else {
  1682. $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
  1683. }
  1684. }
  1685. }
  1686. }
  1687. //if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
  1688. if (isset($config['manage']['_list']['value']) && $this->manage_button) {
  1689. if ($type == 'layui') {
  1690. $layui = array
  1691. (
  1692. 'field' => $config['manage']['_list']['col'],
  1693. 'title' => $config['manage']['_list']['name'],
  1694. //'fixed' => 'right',
  1695. );
  1696. $result[] = $layui;
  1697. } else {
  1698. $result[] = '<th data-priority="1" class="dever-manage">' . $config['manage']['_list']['name'] . '</th>';
  1699. }
  1700. }
  1701. }
  1702. }
  1703. return $result;
  1704. }
  1705. # layui表头
  1706. /*
  1707. public function list_thead_layui()
  1708. {
  1709. $html = 'config.table = {};config.table.cols = [];';
  1710. $data = $this->list_thead('layui');
  1711. if ($data) {
  1712. $data = array($data);
  1713. $data = Dever::json_encode($data);
  1714. $html .= 'config.table.cols = ' . $data;
  1715. return $html;
  1716. } else {
  1717. $html .= 'config.table.cols = []';
  1718. return $html;
  1719. }
  1720. }
  1721. # layui表的数据 没有使用其异步方式
  1722. public function list_tbody_layui()
  1723. {
  1724. $html = 'config.table.data = [];';
  1725. $data = $this->list_tbody(false, 'layui');
  1726. $data = Dever::json_encode($data);
  1727. $html .= 'config.table.data = ' . $data;
  1728. return $html;
  1729. }
  1730. */
  1731. /**
  1732. * 导出列表
  1733. *
  1734. * @return array
  1735. */
  1736. public function list_excel_api()
  1737. {
  1738. Dever::$global['base']['excel'] = 1;
  1739. $this->list_search();
  1740. $data = $this->list_tbody(true);
  1741. if ($data) {
  1742. $config = $this->config();
  1743. if (isset($config['manage']['excel']) && $config['manage']['excel']) {
  1744. $method = 'excel';
  1745. $info = $this->info();
  1746. $load = Dever::input('excel_load');
  1747. if ($load) {
  1748. return Dever::load($load, $data);
  1749. } elseif (is_string($config['manage']['excel']) && strstr($config['manage']['excel'], '.')) {
  1750. return Dever::load($config['manage']['excel'], $data);
  1751. } else {
  1752. $data = $this->getAdminInfo($data);
  1753. return $this->excel($info, $data, $config);
  1754. }
  1755. }
  1756. } else {
  1757. Dever::alert('无导出数据');
  1758. }
  1759. //print_r($data);die;
  1760. }
  1761. private function excel($info, $data, $config)
  1762. {
  1763. $file = Dever::input('excel_name');
  1764. if (!$file) {
  1765. $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
  1766. }
  1767. $header = $body = array();
  1768. $i = 0;
  1769. foreach ($config['struct'] as $k => $v) {
  1770. if (isset($v['list']) && $v['list']) {
  1771. # 处理权限
  1772. if (isset($v['auth'])) {
  1773. $auth = $this->value($v['auth'], $data);
  1774. if (!$auth) {
  1775. continue;
  1776. }
  1777. }
  1778. //$v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
  1779. if (isset($v['list_name']) && $v['list_name']) {
  1780. $v['name'] = $v['list_name'];
  1781. }
  1782. $header[$i] = $v['name'];
  1783. $j = 0;
  1784. foreach ($data as $ki => $vi) {
  1785. if (is_array($vi)) {
  1786. $body[$j][$i] = '';
  1787. //if (isset($vi[$k])) {
  1788. # 处理同步
  1789. if (isset($v['sync']) && strpos($k, '-')) {
  1790. $temp = explode('-', $k);
  1791. if ($vi[$v['sync'][0]] > 0) {
  1792. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $v['sync'][1] => $vi[$v['sync'][0]]));
  1793. } else {
  1794. $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]]));
  1795. }
  1796. if (isset($temp[2])) {
  1797. $data[$ki][$k] = $vi[$k] = isset($load[$temp[2]]) ? $load[$temp[2]] : $v['default'];
  1798. }
  1799. }
  1800. if (true) {
  1801. $value = $vi[$k];
  1802. if (is_string($v['list'])) {
  1803. $value = $this->value($v['list'], $data[$ki], $config['struct']);
  1804. }
  1805. if (isset($v['option'])) {
  1806. $value = $this->getOptionValue($value, $v);
  1807. }
  1808. //$value = mb_convert_encoding($value,'gb2312','utf-8');
  1809. $body[$j][$i] = $value;
  1810. $j++;
  1811. }
  1812. }
  1813. }
  1814. $i++;
  1815. }
  1816. }
  1817. return Dever::excelExport($body, $header, $file);
  1818. }
  1819. private function getOptionValue($value, $v)
  1820. {
  1821. # 验证option是否是匿名函数
  1822. $v['option'] = $this->option($v['option']);
  1823. # 位运算
  1824. if (isset($v['bit'])) {
  1825. $ts = array();
  1826. foreach ($v['option'] as $tm => $tv) {
  1827. if (isset($v['bit'][$tm]) && ($value & $tm) > 0) {
  1828. $ts[] = $tv;
  1829. }
  1830. }
  1831. $value = implode(',', $ts);
  1832. }
  1833. if ((isset($v['child_name']) || (isset($v['show']) && is_string($v['show'])))) {
  1834. if (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1835. $value = $v['option'][$value]['name'];
  1836. } else {
  1837. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1838. }
  1839. } else {
  1840. if (strstr($value, ',')) {
  1841. $temp = explode(',', $value);
  1842. $t = array();
  1843. foreach ($temp as $vv) {
  1844. if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
  1845. $t[] = $v['option'][$vv]['name'];
  1846. } elseif(isset($v['option'][$vv])) {
  1847. $t[] = $v['option'][$vv];
  1848. } else {
  1849. $t[] = $vv;
  1850. }
  1851. }
  1852. $value = implode("\r\n", $t);
  1853. } elseif (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1854. $value = $v['option'][$value]['name'];
  1855. } else {
  1856. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1857. }
  1858. }
  1859. return $value;
  1860. }
  1861. private function _getChr($start, $num)
  1862. {
  1863. $num = $start + $num;
  1864. $max = floor($num / 91);
  1865. if ($max > 0) {
  1866. $num = $num - (91 * $max) + $start;
  1867. $num = chr($start) . chr($num);
  1868. } else {
  1869. $num = chr($num);
  1870. }
  1871. return $num;
  1872. }
  1873. /**
  1874. * 列表页数据列表 检索
  1875. *
  1876. * @return array
  1877. */
  1878. private function list_tbody_search($config, $param, $high, $search)
  1879. {
  1880. # 根据api的数据检索到id
  1881. $api = Dever::preInput('search_api_');
  1882. if ($api) {
  1883. foreach ($api as $k => $v) {
  1884. if ($v) {
  1885. unset($search[$k]);
  1886. $k = str_replace('search_api_', '', $k);
  1887. # 设定检索高亮
  1888. $high[$k] = $v;
  1889. if (isset($config['manage']['search']['api'][$k]['api'])) {
  1890. $col = $config['manage']['search']['api'][$k]['col'];
  1891. $v = ltrim($v);
  1892. $v = rtrim($v);
  1893. if ($v == 'no') {
  1894. $param['option_no'] = $config['manage']['search']['api'][$k]['no'];
  1895. } else {
  1896. $option = array($col => $v, 'clear_top' => true);
  1897. # 此处可以增加关联关系
  1898. $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
  1899. $result = $config['manage']['search']['api'][$k]['result'];
  1900. if ($v && is_array($v)) {
  1901. if (isset($v[$result])) {
  1902. $v = $v[$result];
  1903. } else {
  1904. if ($result == 'id') {
  1905. $v = array_keys($v);
  1906. } else {
  1907. $t = array();
  1908. foreach ($v as $k1 => $v1) {
  1909. $t[] = $v1[$result];
  1910. }
  1911. $v = $t;
  1912. }
  1913. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1914. $param['option'][$config['manage']['search']['api'][$k]['search']] = array('yes', 'in');
  1915. } else {
  1916. $param['option'][$k] = array('yes', 'in');
  1917. }
  1918. }
  1919. } else {
  1920. $v = '-100';
  1921. }
  1922. }
  1923. }
  1924. if (!isset($param['option_no'])) {
  1925. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1926. $param['option_' . $config['manage']['search']['api'][$k]['search']] = $v;
  1927. } else {
  1928. $param['option_' . $k] = $v;
  1929. }
  1930. }
  1931. }
  1932. }
  1933. }
  1934. # 检索有无值
  1935. $exist = Dever::preInput('search_exist_');
  1936. if ($exist) {
  1937. foreach ($exist as $k => $v) {
  1938. if ($v) {
  1939. unset($search[$k]);
  1940. $k = str_replace('search_exist_', '', $k);
  1941. if ($v == 'yes') {
  1942. # 有值
  1943. $param['option'][$k] = array('yes', '!=');
  1944. $param['option_' . $k] = 'null';
  1945. } elseif ($v == 'no') {
  1946. # 无值
  1947. $param['option'][$k] = array('yes', '=');
  1948. $param['option_' . $k] = 'null';
  1949. } elseif (strpos($v, '|')) {
  1950. # 有无值或者自定义的值
  1951. $temp = explode('|', $v);
  1952. $param['option_' . $k] = $temp[1];
  1953. if ($temp[0] == 'yes') {
  1954. $param['option'][$k] = array('yes', '!=');
  1955. $param['option'][$k . '_t1'] = array('yes-' . $k, '!=');
  1956. } else {
  1957. $param['option'][$k] = array('yes', '=', 'and(');
  1958. $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
  1959. }
  1960. $param['option_' . $k . '_t1'] = 'null';
  1961. } else {
  1962. # 自定义的值
  1963. $param['option_' . $k] = $v;
  1964. }
  1965. }
  1966. }
  1967. }
  1968. # 检索in
  1969. $in = Dever::preInput('search_in_');
  1970. if ($in) {
  1971. $in_state = false;
  1972. foreach ($in as $k => $v) {
  1973. if ($v) {
  1974. unset($search[$k]);
  1975. $k = str_replace('search_in_', '', $k);
  1976. $param['option'][$k] = array('yes', 'in');
  1977. $param['option_' . $k] = $v;
  1978. # 设定检索高亮
  1979. //$high[$k] = $v;
  1980. $in_state = true;
  1981. }
  1982. }
  1983. $this->search = true;
  1984. }
  1985. $fulltext = Dever::preInput('search_fulltext_');
  1986. if ($fulltext) {
  1987. $fulltext_state = false;
  1988. foreach ($fulltext as $k => $v) {
  1989. if ($v) {
  1990. unset($search[$k]);
  1991. $k = str_replace('search_fulltext_', '', $k);
  1992. $param['option_' . $k] = $v;
  1993. # 设定检索高亮
  1994. $high[$k] = $v;
  1995. $fulltext_state = true;
  1996. }
  1997. }
  1998. $this->search = true;
  1999. }
  2000. $linkage = Dever::preInput('search_linkage_');
  2001. if ($linkage) {
  2002. foreach ($linkage as $k => $v) {
  2003. if ($v && $v != -1) {
  2004. unset($search[$k]);
  2005. $k = str_replace('search_linkage_', '', $k);
  2006. if (isset($config['struct'][$k]['search_col'])) {
  2007. $temp = explode(',', $config['struct'][$k]['search_col']);
  2008. if (!is_array($v)) {
  2009. $v = explode(',', $v);
  2010. }
  2011. foreach ($temp as $k1 => $v1) {
  2012. if (isset($v[$k1]) && $v[$k1] != -1) {
  2013. $param['option_' . $v1] = $v[$k1];
  2014. }
  2015. }
  2016. } else {
  2017. if (is_array($v)) {
  2018. $v = implode(',', $v);
  2019. }
  2020. if ($v != -1) {
  2021. $v = Dever::defaultValue($v);
  2022. $param['option_' . $k] = $v;
  2023. # 设定检索高亮
  2024. $high[$k] = $v;
  2025. }
  2026. }
  2027. }
  2028. }
  2029. $this->search = true;
  2030. }
  2031. $exp = Dever::preInput('search_exp_');
  2032. if ($exp) {
  2033. $k = $search['search_exp_col'];
  2034. $v = $search['search_exp_value'];
  2035. $param['option_' . $k] = $v;
  2036. $param['search_type'] = $search['search_exp_type'];
  2037. $this->search = true;
  2038. }
  2039. $order = Dever::preInput('search_order_');
  2040. if ($order) {
  2041. foreach ($order as $k => $v) {
  2042. $k = str_replace('search_order_', '', $k);
  2043. $param['order'][0][$k] = $v;
  2044. unset($search[$k]);
  2045. }
  2046. }
  2047. foreach ($search as $k => $v) {
  2048. if ($v) {
  2049. if (strpos($k, '-') !== false) {
  2050. $k = str_replace('search_option_', '', $k);
  2051. $temp = explode('-', $k);
  2052. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  2053. }
  2054. $struct = $config['struct'][$k];
  2055. if (isset($struct['search_col']) && $struct['search_col']) {
  2056. $param[$struct['search_col']] = $v;
  2057. } else {
  2058. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $struct['sync'][1] => $v));
  2059. /*
  2060. if ($v[$vi['sync'][0]] > 0) {
  2061. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  2062. } else {
  2063. $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
  2064. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
  2065. }*/
  2066. if (isset($temp[2])) {
  2067. $v = isset($load[$temp[2]]) ? $load[$temp[2]] : $struct['default'];
  2068. $param[str_replace('search_', '', $k)] = $v;
  2069. }
  2070. }
  2071. } elseif (strpos($k, 'dever_') !== false) {
  2072. continue;
  2073. } elseif (strpos($k, 'option_') !== false) {
  2074. //Dever::setInput(str_replace('search_', '', $k), $v);
  2075. if (is_array($v)) {
  2076. if ($v[0] == 0) {
  2077. continue;
  2078. }
  2079. $v = str_replace(',0', '', implode(',', $v));
  2080. $t = explode(',', $v);
  2081. $parent = end($t);
  2082. $v .= '%';
  2083. }
  2084. $param[str_replace('search_', '', $k)] = $v;
  2085. $this->search = true;
  2086. } elseif ($k == 'search_limit') {
  2087. $num = $this->getNumConfig($config);
  2088. if ($num) {
  2089. $param['page'][0] = $num[$v];
  2090. }
  2091. }
  2092. }
  2093. }
  2094. return array($param, $high);
  2095. }
  2096. private function list_tbody_mul($send)
  2097. {
  2098. $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
  2099. if (Dever::input('method') == 'mul' && $mul && $mul['mul_type'] > 0) {
  2100. if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
  2101. Dever::alert('您还未选择任何数据条目');
  2102. }
  2103. Dever::config('base')->mul_type = $mul['mul_type'];
  2104. /*
  2105. if (isset($param['page'])) {
  2106. unset($param['page']);
  2107. }
  2108. */
  2109. unset($mul['mul_type']);
  2110. $param = array();
  2111. foreach ($mul as $k => $v) {
  2112. if ($v) {
  2113. if (is_array($v)) {
  2114. $v = implode(',', $v);
  2115. }
  2116. $param[str_replace('mul_', '', $k)] = $v;
  2117. }
  2118. }
  2119. if (isset($param)) {
  2120. $method = $this->project . '/' . $this->table . '-updatemul';
  2121. $state = Dever::load($method, $param);
  2122. }
  2123. Dever::alert('reload');
  2124. }
  2125. }
  2126. /**
  2127. * 列表页数据列表:图片形式
  2128. *
  2129. * @return array
  2130. */
  2131. public function list_photo()
  2132. {
  2133. $config = $this->config();
  2134. $result = array();
  2135. if (isset($config['manage']['photo'])) {
  2136. $high = array();
  2137. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  2138. $param = array();
  2139. $parent = 0;
  2140. if ($search) {
  2141. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  2142. }
  2143. if (empty($param['page'])) {
  2144. $num = $this->getNumConfig($config);
  2145. if ($num) {
  2146. $param['page'][0] = $num[0];
  2147. }
  2148. }
  2149. $method = $this->project . '/' . $this->table . '-list';
  2150. $result = Dever::load($method, $param);
  2151. if ($result) {
  2152. foreach ($result as $k => $v) {
  2153. $result[$k] = Dever::load($config['manage']['photo'], $v);
  2154. $result[$k]['button'] = $this->list_tbody_button($config, $v, 'div');
  2155. }
  2156. }
  2157. }
  2158. return $result;
  2159. }
  2160. /**
  2161. * 列表页数据列表:表格形式
  2162. *
  2163. * @return array
  2164. */
  2165. public function list_tbody($excel = false, $type = false)
  2166. {
  2167. $this->state = false;
  2168. # 新增权限
  2169. if (Dever::load('manage/auth.oper', 1) == false) {
  2170. Dever::alert('你没有权限');
  2171. }
  2172. if (Dever::input('page_content') == 1) {
  2173. return '';
  2174. }
  2175. $config = $this->config();
  2176. $high = array();
  2177. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  2178. $param = array();
  2179. $parent = 0;
  2180. if ($search) {
  2181. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  2182. }
  2183. $num = $this->getNumConfig($config);
  2184. if (empty($param['page']) && $num) {
  2185. $param['page'][0] = $num[0];
  2186. }
  2187. # 批量更新
  2188. $this->list_tbody_mul($param);
  2189. $result = $return = array();
  2190. if (isset($config['top_option']) && $config['top_option']) {
  2191. if (isset($config['top_option'][0])) {
  2192. foreach ($config['top_option'] as $k => $v) {
  2193. if (isset($v['join'])) {
  2194. $param['join'][] = $v['join'];
  2195. $col = 't_2.' . $v['col'];
  2196. $param['option']['state'] = 'yes-t_1.state';
  2197. } else {
  2198. $col = $v['col'];
  2199. }
  2200. if ($v['value']) {
  2201. $param['option'][$v['col']] = array('yes-' . $col, 'in');
  2202. $param[$v['col']] = $v['value'];
  2203. }
  2204. }
  2205. } else {
  2206. $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
  2207. }
  2208. }
  2209. if (isset($config['manage']['company']) && is_array($config['manage']['company']) && isset($config['manage']['company']['join'])) {
  2210. $param['join'][] = $config['manage']['company']['join'];
  2211. }
  2212. if ($excel == true) {
  2213. $method = $this->project . '/' . $this->table . '-list';//all
  2214. } else {
  2215. $method = $this->project . '/' . $this->table . '-list';
  2216. }
  2217. //print_r($param);
  2218. $data = Dever::load($method, $param);
  2219. //print_r(Dever::sql());die;
  2220. if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
  2221. $parent = array();
  2222. $child = array();
  2223. foreach ($data as $k => $v) {
  2224. if ($v[$config['name'] . '_id'] <= 0) {
  2225. $parent[$k] = $v;
  2226. } else {
  2227. $v['name'] = '|-----' . $v['name'];
  2228. $child[$v[$config['name'] . '_id']][$k] = $v;
  2229. }
  2230. }
  2231. if ($parent) {
  2232. $data = array();
  2233. foreach ($parent as $k => $v) {
  2234. $data[$v['id']] = $v;
  2235. if (isset($child[$v['id']])) {
  2236. foreach ($child[$v['id']] as $i => $j) {
  2237. $data[$j['id']] = $j;
  2238. }
  2239. }
  2240. }
  2241. }
  2242. } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
  2243. $data = $this->tree($data, $config, -1);
  2244. }
  2245. if ($excel == true) {
  2246. return $data;
  2247. }
  2248. if (Dever::input('page_type') == 1) {
  2249. Dever::$global['manage']['list_data'] = $data;
  2250. return;
  2251. }
  2252. //print_r($data);die;
  2253. //print_r(Helper::page("current"));die;
  2254. $this->manage_button = false;
  2255. if ($data && isset($config['struct'])) {
  2256. $i = 0;
  2257. $pg = Dever::input('pg', 1);
  2258. $cur = Dever::input('search_limit', 0);
  2259. foreach ($data as $k => $v) {
  2260. $data[$k] = $this->getAdminInfo($data[$k]);
  2261. $data[$k]['i'] = $i;
  2262. $ii = isset($num[$cur]) ? intval($num[$cur])*($pg-1) : 0;
  2263. $data[$k]['r'] = $i+1+$ii;
  2264. $result[$k] = '<tr>';
  2265. $return[$i] = array();
  2266. if (isset($config['manage']['mul']) && $config['manage']['mul']) {
  2267. $mul_state = false;
  2268. if ($config['manage']['mul'] && is_string($config['manage']['mul'])) {
  2269. $mul_state = $this->value($config['manage']['mul'], $data[$k]);
  2270. } else {
  2271. $mul_state = true;
  2272. }
  2273. if ($mul_state) {
  2274. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="' . $v['id'] . '"/>';
  2275. } else {
  2276. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="-1" disabled/>';
  2277. }
  2278. $result[$k] .= '<td>'.$checkbox.'</td>';
  2279. $return[$i]['checkbox'] = $checkbox;
  2280. }
  2281. foreach ($config['struct'] as $ki => $vi) {
  2282. # 处理同步
  2283. if (isset($vi['sync']) && strpos($ki, '-')) {
  2284. $temp = explode('-', $ki);
  2285. if ($v[$vi['sync'][0]] > 0) {
  2286. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  2287. } else {
  2288. $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
  2289. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
  2290. }
  2291. if (isset($temp[2])) {
  2292. $data[$k][$ki] = $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
  2293. }
  2294. }
  2295. if (isset($vi['list']) && $vi['list']) {
  2296. if (empty($v[$ki])) {
  2297. $v[$ki] = isset($vi['default']) ? $vi['default'] : '';
  2298. }
  2299. # 处理权限
  2300. if (isset($vi['auth'])) {
  2301. $auth = $this->value($vi['auth'], $data[$k]);
  2302. if (!$auth) {
  2303. continue;
  2304. }
  2305. }
  2306. $show = $v[$ki];
  2307. if (is_string($vi['list'])) {
  2308. $show = $this->value($vi['list'], $data[$k], $config['struct']);
  2309. }
  2310. if (isset($vi['key']) && $vi['update'] != 'editor') {
  2311. $show = Dever::upload($show);
  2312. }
  2313. if (isset($vi['modal'])) {
  2314. $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
  2315. } elseif (isset($vi['option']) && !is_string($vi['list'])) {
  2316. # 验证option是否是匿名函数
  2317. if ((isset($vi['edit']) && $vi['edit'])) {
  2318. $vi['option'] = $this->option($vi['option'], $vi['edit']);
  2319. } else {
  2320. $vi['option'] = $this->option($vi['option']);
  2321. }
  2322. # 位运算
  2323. if (isset($vi['bit'])) {
  2324. $ts = array();
  2325. foreach ($vi['option'] as $tm => $tv) {
  2326. if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
  2327. $ts[] = $tv;
  2328. }
  2329. }
  2330. $show = implode(',', $ts);
  2331. }
  2332. if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
  2333. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2334. $show = $vi['option'][$show]['name'];
  2335. } else {
  2336. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2337. }
  2338. }
  2339. //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
  2340. elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
  2341. {
  2342. $vi['name'] = 'up_col_' . $ki;
  2343. $vi['value'] = $v[$ki];
  2344. $m = 'select';
  2345. if (isset($vi['update']) && $vi['update'] == 'group') {
  2346. $m = 'group';
  2347. }
  2348. $show_edit = $this->value($vi['edit'], $data[$k], $config['struct']);
  2349. if ($show_edit) {
  2350. $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 . '\')"');
  2351. } else {
  2352. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2353. $show = $vi['option'][$show]['name'];
  2354. } else {
  2355. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2356. }
  2357. $show = '';
  2358. }
  2359. } else {
  2360. if (strstr($show, ',')) {
  2361. $temp = explode(',', $show);
  2362. $t = array();
  2363. foreach ($temp as $vv) {
  2364. if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
  2365. $t[] = $vi['option'][$vv]['name'];
  2366. } elseif(isset($vi['option'][$vv])) {
  2367. $t[] = $vi['option'][$vv];
  2368. } else {
  2369. $t[] = $vv;
  2370. }
  2371. }
  2372. $show = implode('<br />', $t);
  2373. } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2374. if (isset($vi['option'][$show]['style'])) {
  2375. $vi['option'][$show]['name'] = '<font style="'.$vi['option'][$show]['style'].'">' . $vi['option'][$show]['name'] . '</font>';
  2376. }
  2377. $show = $vi['option'][$show]['name'];
  2378. } else {
  2379. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2380. }
  2381. }
  2382. }
  2383. $text = $show;
  2384. if ($high && isset($high[$ki])) {
  2385. if (isset($v['s_' . $ki])) {
  2386. $text = $v['s_' . $ki];
  2387. $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
  2388. $text = str_replace('</em>', '</font>', $text);
  2389. } elseif (strlen($high[$ki]) > 1) {
  2390. $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text, 1);
  2391. }
  2392. }
  2393. if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
  2394. //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
  2395. $url = $this->url('updateAction');
  2396. $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
  2397. $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>';
  2398. $result[$k] .= '<td >' . $text . '</td>';
  2399. if (isset($return[$i][$ki])) {
  2400. $text = $return[$i][$ki] . $text;
  2401. }
  2402. $return[$i][$ki] = $text;
  2403. } else {
  2404. $result[$k] .= '<td>' . $text . '</td>';
  2405. if (isset($return[$i][$ki])) {
  2406. $text = $return[$i][$ki] . $text;
  2407. }
  2408. $return[$i][$ki] = $text;
  2409. }
  2410. if (isset($config['manage']['chart'])) {
  2411. $this->chart($config['manage']['chart'], $ki, $return[$i][$ki], $vi);
  2412. }
  2413. }
  2414. }
  2415. $button = $this->list_tbody_button($config, $data[$k]);
  2416. if ($button == '<td></td>') {
  2417. $button = str_replace('<td></td>', '<td>&nbsp;</td>', $button);
  2418. }
  2419. $result[$k] .= $button;
  2420. $return[$i]['manage'] = str_replace(array('<td>', '</td>'), '', $button);
  2421. $result[$k] .= '</tr>';
  2422. $i++;
  2423. }
  2424. }
  2425. if ($result) {
  2426. $this->state = true;
  2427. $result = implode('', $result);
  2428. if (!$this->manage_button) {
  2429. $result = str_replace('<td>&nbsp;</td>', '', $result);
  2430. }
  2431. } else {
  2432. $result = '';
  2433. }
  2434. if ($type) {
  2435. return $return;
  2436. }
  2437. return $result;
  2438. }
  2439. private function list_tbody_button($config, $data, $type = 'td')
  2440. {
  2441. $result = '';
  2442. $auth = Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false;
  2443. if (isset($config['manage']['_list']['value']['list']) && isset($config['manage']['_list']['value']['list'][0]) && $config['manage']['_list']['value']['list'][0] == '查看详情') {
  2444. $auth = true;
  2445. }
  2446. if ($auth && isset($config['manage']['_list']['value'])) {
  2447. //if (isset($config['manage']['_list']['value'])) {
  2448. $result = '<'.$type.'>';
  2449. if ($config['state'] == 2) {
  2450. if (isset($config['manage']['_list']['value']['update'])) {
  2451. unset($config['manage']['_list']['value']['update']);
  2452. }
  2453. if (isset($config['manage']['_list']['value']['delete'])) {
  2454. $config['manage']['_list']['value']['delete'] = '恢复';
  2455. }
  2456. }
  2457. foreach ($config['manage']['_list']['value'] as $kj => $vj) {
  2458. $pj = false;
  2459. $h = '<span class="am-icon-pencil-square-o"></span>';
  2460. if (strstr($kj, 'new') || strstr($kj, 'location') || strstr($kj, 'list')) {
  2461. $oper = true;
  2462. } elseif ($kj == 'delete') {
  2463. $oper = Dever::load('manage/auth.oper', 5);
  2464. $h = '<span class="am-icon-trash-o"></span>';
  2465. } else {
  2466. $oper = Dever::load('manage/auth.oper', 3);
  2467. }
  2468. if (is_array($vj) && isset($vj[1])) {
  2469. if (isset($vj[2])) {
  2470. $oper = $this->value($vj[2], $data);
  2471. }
  2472. if ($oper && strpos($vj[1], 'modal|') === false) {
  2473. $pj = $this->value($vj[1], $data);
  2474. $vjn = $vj[0];
  2475. }
  2476. } else {
  2477. $vjn = $vj;
  2478. }
  2479. if ($oper == true) {
  2480. $this->manage_button = true;
  2481. if ($kj == 'delete') {
  2482. $class = 'layui-btn layui-btn-danger';
  2483. } else {
  2484. $class = 'layui-btn';
  2485. }
  2486. if (layadmin()) {
  2487. $class .= ' layui-btn-xs';
  2488. }
  2489. if (strpos($kj, 'fast_list') !== false) {
  2490. if (!isset($vj[3])) {
  2491. $vj[3] = '';
  2492. }
  2493. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('list', $data['id'], $pj) . '\', \''.$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>&nbsp;&nbsp;';
  2494. } elseif (strpos($kj, 'fast_add') !== false) {
  2495. if (!isset($vj[3])) {
  2496. $vj[3] = '';
  2497. }
  2498. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('update', false, $pj) . '\', \''.$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>&nbsp;&nbsp;';
  2499. } elseif (strpos($kj, 'fast') !== false) {
  2500. if (!isset($vj[3])) {
  2501. $vj[3] = '';
  2502. }
  2503. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url('update', $data['id'], $pj) . '\', \''.$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>&nbsp;&nbsp;';
  2504. } elseif (strpos($kj, 'edits') !== false) {
  2505. if (!isset($vj[1])) {
  2506. $vj[1] = '';
  2507. }
  2508. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url($kj, $data['id']) . '\', \''.$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>&nbsp;&nbsp;';
  2509. } elseif (strpos($kj, 'copy') !== false) {
  2510. $vj[1] = $this->value($vj[1], $data);
  2511. $vj[1] = Dever::load($vj[1]);
  2512. $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>&nbsp;&nbsp;';
  2513. } elseif (strpos($kj, 'edit') !== false) {
  2514. if (!isset($vj[1])) {
  2515. $vj[1] = '';
  2516. }
  2517. if (strstr($vj[1], 'http')) {
  2518. $url = $vj[1] . '&id=' . $data['id'];
  2519. } else {
  2520. $url = $this->url($kj, $data['id']);
  2521. }
  2522. $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>&nbsp;&nbsp;';
  2523. } elseif (strpos($kj, 'location') !== false) {
  2524. if (!isset($vj[1])) {
  2525. $vj[1] = '';
  2526. }
  2527. if (strstr($vj[1], 'http')) {
  2528. $url = $vj[1] . '&id=' . $data['id'];
  2529. } else {
  2530. $url = $this->url($kj, $data['id']);
  2531. }
  2532. $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>&nbsp;&nbsp;';
  2533. } elseif (strpos($kj, 'oper') !== false) {
  2534. $content = '';
  2535. $title = '';
  2536. if (isset($vj[3])) {
  2537. $content = $this->value($vj[3], $data);
  2538. }
  2539. if (isset($vj[4])) {
  2540. $title = $vj[4];
  2541. }
  2542. $url = Dever::url($pj) . '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $vj[0];
  2543. $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>&nbsp;&nbsp;';
  2544. } elseif (strpos($kj, 'new') !== false) {
  2545. if (!isset($vj[1])) {
  2546. $vj[1] = '';
  2547. }
  2548. if (!isset($vj[2])) {
  2549. $vj[2] = '';
  2550. }
  2551. if (strstr($vj[1], 'http')) {
  2552. $url = $vj[1] . '&id=' . $data['id'];
  2553. } elseif($vj[2]) {
  2554. $url = Dever::url($this->value($vj[1], $data), $vj[2]);
  2555. } else {
  2556. $url = $this->url($kj, $data['id']);
  2557. }
  2558. $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>&nbsp;&nbsp;';
  2559. } elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
  2560. $t = explode('|', $vj[1]);
  2561. $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>&nbsp;&nbsp;';
  2562. } elseif (isset($vj[1])) {
  2563. $result .= '<a href="' . $this->url($kj, $data['id'], $pj) . '" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5 '.$class.'">' . $h . $vjn . '</button></a>&nbsp;&nbsp;';
  2564. } else {
  2565. $result .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
  2566. }
  2567. }
  2568. }
  2569. $result .= '</'.$type.'>';
  2570. }
  2571. return $result;
  2572. }
  2573. /**
  2574. * 多级分类
  2575. *
  2576. * @return array
  2577. */
  2578. private function tree($data, $config, $parent = 0)
  2579. {
  2580. $key = $config['name'] . '_id';
  2581. $result = array();
  2582. $this->treeData($data, $result, $key, $parent);
  2583. return $result;
  2584. }
  2585. private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
  2586. {
  2587. if (empty($array)) {
  2588. return;
  2589. }
  2590. $level++;
  2591. foreach ($array as $k => $v) {
  2592. if ((isset($v[$key]) && $v[$key] == $parent_id) || (isset($v['parent_id']) && $v['parent_id'] == $parent_id)) {
  2593. $v['level'] = $level;
  2594. $v['name'] = $this->treeName($v['name'], $level);
  2595. $result[] = $v;
  2596. unset($array[$k]);
  2597. $this->treeData($array, $result, $key, $v['id'], $level);
  2598. }
  2599. }
  2600. }
  2601. private function treeName($name, $level = 1)
  2602. {
  2603. $string = '';
  2604. if ($level > 1) {
  2605. /*
  2606. $num = 4;
  2607. $string = '-';
  2608. //STR_PAD_LEFT
  2609. $string = str_pad('|', $level * $num, $string);
  2610. */
  2611. $string = str_repeat(' ',$level-1);
  2612. $string .= '|—';
  2613. }
  2614. return $string . $name;
  2615. }
  2616. /**
  2617. * 列表页批量管理
  2618. *
  2619. * @return array
  2620. */
  2621. public function list_mul()
  2622. {
  2623. # 新增权限:更新权限
  2624. if (Dever::load('manage/auth.oper', 3) == false) {
  2625. return '';
  2626. }
  2627. $config = $this->config();
  2628. $result = '';
  2629. if ($this->state && isset($config['struct']) && isset($config['manage']['mul']) && $config['manage']['mul']) {
  2630. $mul = Dever::preInput('mul_');
  2631. $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
  2632. $btn = '<button class="btn btn-danger layui-btn layui-btn-danger" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list') . '\');list_mul($(this))" type="button" style="height: 38px;margin-left:10px;">更新</button>';
  2633. $prefix = 'mul_';
  2634. $result .= $node[0];
  2635. $default = 0;
  2636. $option = array
  2637. (
  2638. 1 => '本页选中的数据',
  2639. );
  2640. # 只有当有搜索条件时才会出现
  2641. if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
  2642. //$option[2] = '所有页面的数据';
  2643. //$default = 2;
  2644. }
  2645. $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择要更新的数据', $option, $default);
  2646. foreach ($config['struct'] as $k => $v) {
  2647. if ($k == 'state' && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  2648. $v['option'] = Dever::config('base')->state;
  2649. if ($this->getState() == 2) {
  2650. unset($v['option'][2]);
  2651. } else {
  2652. unset($v['option'][1]);
  2653. }
  2654. $v['edit'] = true;
  2655. }
  2656. $select = false;
  2657. if (isset($v['mul'])) {
  2658. $select = $v['mul'];
  2659. } elseif (isset($v['edit'])) {
  2660. $select = $v['edit'];
  2661. }
  2662. if ($select) {
  2663. if (isset($v['mul_option']) && (is_array($v['mul_option']) || is_object($v['mul_option']))) {
  2664. $result .= '&nbsp;&nbsp;';
  2665. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['mul_option'], $select), $v['default']);
  2666. } elseif (isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
  2667. $result .= '&nbsp;&nbsp;';
  2668. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option'], $select), $v['default']);
  2669. }
  2670. }
  2671. }
  2672. $result .= $btn . $node[1];
  2673. }
  2674. //print_r($result);die;
  2675. return $result;
  2676. }
  2677. private function value($value, $data, $struct = array())
  2678. {
  2679. if (!$data) {
  2680. return $value;
  2681. }
  2682. if (strstr($value, '={') && !strstr($value, '"')) {
  2683. $value = '"' . $value . '"';
  2684. }
  2685. if (is_string($data)) {
  2686. $eval = '$value = ' . $value . ';';
  2687. eval($eval);
  2688. return $value;
  2689. }
  2690. if ($value == 'table' && $struct) {
  2691. $result = $this->struct_data($struct, $data);
  2692. $value = Dever::table($result);
  2693. } elseif (strpos($value, '{') !== false && strpos($value, '{"') === false) {
  2694. # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
  2695. //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
  2696. $func = function ($r) use ($data) {
  2697. if (isset($data[$r[1]])) {
  2698. return $data[$r[1]];
  2699. }
  2700. return false;
  2701. };
  2702. $value = preg_replace_callback('/{(.*?)}/', $func, $value);
  2703. if (strstr($value, '<script>')) {
  2704. $value = str_replace('<script>', '<script>$(document).ready(function(){', $value);
  2705. $value = str_replace('</script>', '});</script>', $value);
  2706. }
  2707. $eval = '$value = ' . $value . ';';
  2708. eval($eval);
  2709. }
  2710. return $value;
  2711. }
  2712. /**
  2713. * update
  2714. *
  2715. * @return array
  2716. */
  2717. public function update()
  2718. {
  2719. $config = $this->config();
  2720. $data = array();
  2721. if ($this->id) {
  2722. # 新增权限
  2723. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2724. $auth = 1;
  2725. } else {
  2726. $auth = 3;
  2727. }
  2728. if (Dever::load('manage/auth.oper', $auth) == false) {
  2729. Dever::alert('你没有权限');
  2730. }
  2731. $data = $this->load('one', $this->id);
  2732. } else {
  2733. # 新增权限
  2734. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2735. $auth = 1;
  2736. } else {
  2737. $auth = 4;
  2738. }
  2739. if (Dever::load('manage/auth.oper', $auth) == false) {
  2740. Dever::alert('你没有权限');
  2741. }
  2742. }
  2743. $data = $this->getAdminInfo($data);
  2744. $col = Dever::input('col');
  2745. $result = $this->update_struct($config, $col, $data);
  2746. //print_r($result);die;
  2747. return $result;
  2748. }
  2749. public function update_content()
  2750. {
  2751. $config = $this->config();
  2752. $data = array();
  2753. if ($this->id) {
  2754. # 新增权限
  2755. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2756. $auth = 1;
  2757. } else {
  2758. $auth = 3;
  2759. }
  2760. if (Dever::load('manage/auth.oper', $auth) == false) {
  2761. Dever::alert('你没有权限');
  2762. }
  2763. $data = $this->load('one', $this->id);
  2764. } else {
  2765. # 新增权限
  2766. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2767. $auth = 1;
  2768. } else {
  2769. $auth = 4;
  2770. }
  2771. if (Dever::load('manage/auth.oper', $auth) == false) {
  2772. Dever::alert('你没有权限');
  2773. }
  2774. }
  2775. $data = $this->getAdminInfo($data);
  2776. $col = Dever::input('col');
  2777. Dever::setInput('ajax', 1);
  2778. $result = '<div class="layui-col-md12"><div class="layui-card" {style}><div class="layui-card-body">';
  2779. $desc = Dever::load('manage/database.info#updateDesc');
  2780. if ($desc) {
  2781. $result .= $desc;
  2782. }
  2783. if (isset($config['manage']['lang']) && Dever::config('base')->lang_set && count(Dever::config('base')->lang_set) > 1) {
  2784. $result .= '<div class="layui-tab layui-tab-card"><ul class="layui-tab-title">';
  2785. $tab = '<div class="layui-tab-content">';
  2786. $i = 0;
  2787. if ($col) {
  2788. $col = explode(',', $col);
  2789. $config['manage']['lang'] = explode(',', $config['manage']['lang']);
  2790. $config['manage']['lang'] = array_intersect($config['manage']['lang'], $col);
  2791. $config['manage']['lang'] = implode(',', $config['manage']['lang']);
  2792. $col = implode(',', $col);
  2793. }
  2794. foreach (Dever::config('base')->lang_set as $k => $v) {
  2795. if ($i == 0) {
  2796. $prefix = '';
  2797. } else {
  2798. $prefix = $k;
  2799. $col = $config['manage']['lang'];
  2800. //$prefix = 'l-l' . $k . 'l-l';
  2801. //$data = $this->load('one', $this->id, $this->table . '__' . $k);
  2802. }
  2803. if (isset($config['manage']['tab']) && $config['manage']['tab']) {
  2804. $content = '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
  2805. $tab_content = '<div class="layui-tab-content">';
  2806. $j = 0;
  2807. foreach ($config['manage']['tab'] as $k1 => $v1) {
  2808. $html = $this->update_struct($config, $col, $data, $k1, $prefix);
  2809. if ($html) {
  2810. $class_0 = $class_1 = '';
  2811. if ($j == 0) {
  2812. $class_0 = 'layui-this';
  2813. $class_1 = 'layui-show';
  2814. }
  2815. $content .= '<li class="'.$class_0.'">'.$v1.'</li>';
  2816. $tab_content .= '<div class="layui-tab-item '.$class_1.'">'.$html.'</div>';
  2817. $j++;
  2818. }
  2819. }
  2820. $tab_content .= '</div>';
  2821. $content .= '</ul>' . $tab_content . '</div>';
  2822. if ($content) {
  2823. $class_0 = $class_1 = '';
  2824. if ($i == 0) {
  2825. $class_0 = 'layui-this';
  2826. $class_1 = 'layui-show';
  2827. }
  2828. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2829. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2830. $i++;
  2831. }
  2832. } else {
  2833. $content = $this->update_struct($config, $col, $data, -1, $prefix);
  2834. if ($content) {
  2835. $class_0 = $class_1 = '';
  2836. if ($i == 0) {
  2837. $class_0 = 'layui-this';
  2838. $class_1 = 'layui-show';
  2839. }
  2840. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2841. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2842. $i++;
  2843. }
  2844. }
  2845. }
  2846. $tab .= '</div>';
  2847. $result .= '</ul>' . $tab . '</div>';
  2848. } elseif (isset($config['manage']['tab']) && $config['manage']['tab']) {
  2849. $result .= '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
  2850. $tab = '<div class="layui-tab-content">';
  2851. $i = 0;
  2852. foreach ($config['manage']['tab'] as $k => $v) {
  2853. $content = $this->update_struct($config, $col, $data, $k);
  2854. if ($content) {
  2855. $class_0 = $class_1 = '';
  2856. if ($i == 0) {
  2857. $class_0 = 'layui-this';
  2858. $class_1 = 'layui-show';
  2859. }
  2860. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2861. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2862. $i++;
  2863. }
  2864. }
  2865. $tab .= '</div>';
  2866. $result .= '</ul>' . $tab . '</div>';
  2867. } else {
  2868. $result .= $this->update_struct($config, $col, $data);
  2869. }
  2870. if (isset($this->card) && $this->card) {
  2871. $result = str_replace('{style}', 'style="display:none"', $result);
  2872. }
  2873. $button = '';
  2874. if (Dever::input('fast') != 1) {
  2875. $button = '<div class="layui-card-body" id="update_button"><div class="layui-form-item">' . $this->update_button() . '</div></div>';
  2876. }
  2877. $result .= '</div>'.$button.'</div></div>';
  2878. //print_r($result);die;
  2879. return $result;
  2880. }
  2881. public function update_struct($config, $col, $data, $tab = -1, $prefix = '', $layadmin = false)
  2882. {
  2883. if (!$layadmin) {
  2884. $layadmin = layadmin();
  2885. }
  2886. $result = array();
  2887. $upload_call = '';
  2888. if (isset($config['manage']['upload'])) {
  2889. $upload_call = $this->value($config['manage']['upload'], $data);
  2890. }
  2891. foreach ($config['struct'] as $k => $v) {
  2892. if (isset($config['manage']['lang']) && isset($v['sync']) && strpos($k, '-')) {
  2893. continue;
  2894. }
  2895. $state = false;
  2896. if ($tab == 0) {
  2897. if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
  2898. $state = true;
  2899. }
  2900. } elseif ($tab > 0) {
  2901. if (isset($v['tab']) && $v['tab'] == $tab) {
  2902. $state = true;
  2903. }
  2904. } else {
  2905. $state = true;
  2906. }
  2907. if (isset($v['update']) && $v['update'] && $state) {
  2908. if ($col && !strstr(',' . $col . ',', ',' . $k . ',')) {
  2909. continue;
  2910. }
  2911. //处理权限
  2912. if (isset($v['auth'])) {
  2913. $auth = $this->value($v['auth'], $data);
  2914. if (!$auth) {
  2915. continue;
  2916. }
  2917. }
  2918. $index = $k;
  2919. if ($prefix && !strstr($k, '-')) {
  2920. $k = $prefix . '_' . $k;
  2921. }
  2922. # 处理show模式下的class
  2923. $class = $this->update_class($k, $v, '', $data);
  2924. $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
  2925. $style = '';
  2926. if ($v['update'] == 'hidden') {
  2927. $style = 'style="display:none"';
  2928. }
  2929. if ($layadmin) {
  2930. $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div classs="layui-col-lg6">';
  2931. if (is_array($v['update'])) {
  2932. $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div class="layui-tab layui-tab-card">';
  2933. }
  2934. }
  2935. if ($upload_call) {
  2936. $v['upload_call'] = $upload_call . '&key=' . $k;
  2937. }
  2938. if (isset($config['manage']['sku']) && $v['update'] == 'sku') {
  2939. $v['sku'] = $config['manage']['sku'];
  2940. $v['data'] = $data;
  2941. }
  2942. $result[$k] .= $this->create_update_html($k, $v, $data, false, $prefix);
  2943. $result[$k] .= '</div></div>';
  2944. } elseif (!$col && isset($v['class'])) {
  2945. # 分割线
  2946. $v['name'] = $this->value($v['name'], array('test' => 1));
  2947. if (isset($v['right'])) {
  2948. $this->card_right = true;
  2949. }
  2950. $this->card = true;
  2951. $result[$k] = Html::hr($v);
  2952. }
  2953. }
  2954. if (Dever::input('ajax') == 1) {
  2955. return implode('', $result);
  2956. }
  2957. return $result;
  2958. }
  2959. public function card()
  2960. {
  2961. if (isset($this->card_right)) {
  2962. return 'layui-col-md6';
  2963. }
  2964. return 'layui-col-md12';
  2965. }
  2966. public function layui_card()
  2967. {
  2968. if (isset($this->card)) {
  2969. return false;
  2970. }
  2971. return true;
  2972. }
  2973. /**
  2974. * update_class
  2975. *
  2976. * @return string
  2977. */
  2978. public function update_class($name, $param, $prefix = '', $data = array())
  2979. {
  2980. $class = '';
  2981. $key = 'show';
  2982. if (isset($param[$key]) && $param[$key]) {
  2983. $parent = array();
  2984. $child = array();
  2985. if (is_string($param[$key])) {
  2986. parse_str($param[$key], $param[$key]);
  2987. }
  2988. if (is_array($param[$key])) {
  2989. foreach ($param[$key] as $k => $v) {
  2990. if ($k == 'no') {
  2991. $child[$k . '_' . $v] = $key . '_no';
  2992. } elseif (strpos($v, '/')) {
  2993. $parent[$k] = $key . '_' . $k;
  2994. $k = $k . '_ajax';
  2995. $value = '';
  2996. if (isset($data[$name])) {
  2997. $value = $data[$name];
  2998. }
  2999. $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
  3000. $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
  3001. } else {
  3002. if (strpos($v, ',')) {
  3003. $temp = explode(',', $v);
  3004. foreach ($temp as $v1) {
  3005. $show = $k . '_' . $v1;
  3006. if ($prefix) {
  3007. $k = str_replace($name, $k, $prefix);
  3008. $show = str_replace($name, $show, $prefix);
  3009. }
  3010. $parent[$k] = $key . '_' . $k;
  3011. $child[$show] = $key . '_' . $show;
  3012. }
  3013. } else {
  3014. $show = $k . '_' . $v;
  3015. if ($prefix) {
  3016. $k = str_replace($name, $k, $prefix);
  3017. $show = str_replace($name, $show, $prefix);
  3018. }
  3019. $parent[$k] = $key . '_' . $k;
  3020. $child[$show] = $key . '_' . $show;
  3021. }
  3022. }
  3023. }
  3024. }
  3025. $class = implode(' ', $parent) . ' ' . implode(' ', $child);
  3026. }
  3027. if (isset($param['control'])) {
  3028. $class .= ' ' . $key . '_input';
  3029. }
  3030. return $class;
  3031. }
  3032. /**
  3033. * update_html
  3034. *
  3035. * @return string
  3036. */
  3037. public function create_update_html($key, $value, $data = array(), $index = false, $prefix = '')
  3038. {
  3039. $result = '';
  3040. $value['ext'] = $value['col'] = $key;
  3041. $value['update'] = $value['update'] ? $value['update'] : 'text';
  3042. if (isset($value['match']) && $value['match'] != 'option') {
  3043. if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
  3044. if (strstr($value['match'], 'option||')) {
  3045. $value['valid'] = 'validate[custom[' . $key . ']]';
  3046. } else {
  3047. $value['valid'] = 'validate[required,custom[' . $key . ']]';
  3048. }
  3049. } else {
  3050. $value['valid'] = 'validate[required]';
  3051. }
  3052. }
  3053. if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
  3054. $value['value'] = $value['update'];
  3055. $value['update'] = 'hidden';
  3056. }
  3057. if (!$index) {
  3058. $index = $key;
  3059. }
  3060. $this->update_html($value, $key, $index, $data, $result, $prefix);
  3061. return $result;
  3062. }
  3063. /**
  3064. * update_html
  3065. *
  3066. * @return string
  3067. */
  3068. public function update_html($param, $key, $index, $data, &$result, $prefix = '')
  3069. {
  3070. if (isset($param['name']) && isset($param['update']) && $param['update'] != 'hidden' && $param['update'] != 'load') {
  3071. $result .= Html::pageLeft($param);
  3072. }
  3073. if ($param['update']) {
  3074. $order = true;
  3075. # 名称带前缀
  3076. $param['name'] = 'update_' . $param['ext'];
  3077. $param['index'] = $index;
  3078. //$param['value'] = '';
  3079. # 得到当前的值
  3080. //if (isset($data[$index]) && !isset($param['value'])) {
  3081. if (isset($data[$index]) && $data[$index]) {
  3082. $param['value'] = $data[$index];
  3083. }
  3084. # 得到下级的值
  3085. if (isset($param['child_value']) && isset($data['id'])) {
  3086. $param['child_value'] = $this->value($param['child_value'], $data);
  3087. }
  3088. # 验证option是否是匿名函数
  3089. if (isset($param['option'])) {
  3090. $param['option'] = $this->option($param['option']);
  3091. }
  3092. if (isset($data[$index]) && !isset($param['value']) && isset($param['key']) && $param['update'] != 'editor') {
  3093. $param['value'] = Dever::upload($data[$index]);
  3094. }
  3095. # 处理下级字段
  3096. if (isset($param['child'])) {
  3097. $param['child'] = $this->option($param['child']);
  3098. if (isset($data[$key . '_parent'])) {
  3099. $param['parent_value'] = $data[$key . '_parent'];
  3100. }
  3101. }
  3102. # 设置默认值
  3103. if (isset($param['default'])) {
  3104. $param['default'] = $this->option($param['default']);
  3105. }
  3106. # 处理同步
  3107. if (isset($param['sync']) && strpos($key, '-') && $param['update'] != 'load') {
  3108. $temp = explode('-', $key);
  3109. if (isset($data[$param['sync'][0]])) {
  3110. if (isset($temp[2])) {
  3111. $m = 'one';
  3112. } else {
  3113. $m = 'select';
  3114. }
  3115. if ($data[$param['sync'][0]] > 0) {
  3116. $load = Dever::load($temp[0] . '/' . $temp[1] . '-' . $m, array('option_' . $param['sync'][1] => $data[$param['sync'][0]], 'order' => array('id' => 'asc')));
  3117. } else {
  3118. $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]], 'order' => array('id' => 'asc')));
  3119. }
  3120. if ($m == 'one') {
  3121. $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
  3122. } else {
  3123. $param['value'] = $load;
  3124. }
  3125. }
  3126. if (!isset($temp[2]) && is_array($param['update'])) {
  3127. $order = false;
  3128. if (isset($param['update'][0]) && is_string($param['update'][0]) && strstr($param['update'][0], '.')) {
  3129. if (isset($param['update'][1]) && $param['update'][1]) {
  3130. $param['update_load'] = $param['update'][0];
  3131. $param['update'] = 'load';
  3132. } else {
  3133. $param['update'] = Dever::load($param['update'][0]);
  3134. }
  3135. } else {
  3136. $config = Dever::db($temp[0] . '/' . $temp[1])->config;
  3137. $param['update'] = $config['struct'];
  3138. }
  3139. if (isset($config['manage']['tab'])) {
  3140. $param['prefix'] = $prefix;
  3141. $param['tab'] = $config['manage']['tab'];
  3142. if (isset($config['manage']['tab'])) {
  3143. $param['lang'] = $config['manage']['lang'];
  3144. }
  3145. }
  3146. //$param['value'] = Dever::db($temp[0] . '/' . $temp[1]);
  3147. }
  3148. }
  3149. $method = $param['update'];
  3150. if (is_array($method)) {
  3151. $c = '';
  3152. if (layadmin()) {
  3153. $c = 'layui-tab-title';
  3154. }
  3155. $delete = true;
  3156. if (isset($param['option'])) {
  3157. $delete = false;
  3158. $result .= '<ul class="nav nav-tabs '.$c.'" style="height:100%;">{tab}</ul>';
  3159. $order = array
  3160. (
  3161. 'col' => $key,
  3162. 'name' => $param['desc'],
  3163. 'default' => '1',
  3164. 'desc' => $param['desc'],
  3165. 'match' => 'is_string',
  3166. 'update' => 'hidden',
  3167. 'option' => $param['option']
  3168. );
  3169. array_unshift($method, $order);
  3170. if (isset($param['value']) && $param['value']) {
  3171. $value = Dever::array_decode($param['value']);
  3172. $param['value'] = array();
  3173. if (!$value) {
  3174. foreach ($param['option'] as $k => $v) {
  3175. if (isset($v['name'])) {
  3176. $v = $v['name'];
  3177. }
  3178. $param['value'][$v][$key] = $k;
  3179. }
  3180. } else {
  3181. foreach ($param['option'] as $k => $v) {
  3182. if (isset($v['name'])) {
  3183. $v = $v['name'];
  3184. }
  3185. foreach ($value[$k-1] as $k1 => $v1) {
  3186. $param['value'][$v][$k1] = $v1;
  3187. }
  3188. }
  3189. }
  3190. } else {
  3191. $param['value'] = array();
  3192. foreach ($param['option'] as $k => $v) {
  3193. if (isset($v['name'])) {
  3194. $v = $v['name'];
  3195. }
  3196. $param['value'][$v][$key] = $k;
  3197. }
  3198. }
  3199. } else {
  3200. $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>';
  3201. if ($order) {
  3202. $order = array
  3203. (
  3204. 'col' => 'order',
  3205. 'name' => '排序-按照数字正序排列',
  3206. 'default' => '1',
  3207. 'desc' => '排序',
  3208. 'match' => 'is_string',
  3209. 'update' => 'text',
  3210. );
  3211. array_unshift($method, $order);
  3212. }
  3213. }
  3214. $tab = '';
  3215. $this->update_child(array(), $method, $key, $result, -1, $param, $delete);
  3216. if (isset($param['value']) && $param['value']) {
  3217. if (!is_array($param['value'])) {
  3218. $param['value'] = Dever::array_decode($param['value']);
  3219. }
  3220. if (is_array($param['value'])) {
  3221. $i = 0;
  3222. foreach ($param['value'] as $k => $v) {
  3223. $n = $k;
  3224. if (is_string($k)) {
  3225. $k = $i;
  3226. }
  3227. $this->update_child($v, $method, $key, $result, $k, $param, $delete);
  3228. $active = '';
  3229. if ($k == 0) {
  3230. $active = 'active';
  3231. }
  3232. if (layadmin() && $active) {
  3233. $active .= ' layui-this';
  3234. }
  3235. $k = $k + 1;
  3236. if (!is_string($n)) {
  3237. $n = '第' . $k . '条';
  3238. }
  3239. if (isset($param['option']) && count($param['option']) <= 1) {
  3240. } else {
  3241. $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>';
  3242. $i++;
  3243. }
  3244. }
  3245. }
  3246. } else {
  3247. $this->update_child(array(), $method, $key, $result, 0, $param, $delete);
  3248. $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>';
  3249. }
  3250. if ($tab) {
  3251. $result = str_replace('{tab}', $tab, $result);
  3252. } else {
  3253. $result = str_replace('<ul class="nav nav-tabs layui-tab-title" style="height:100%;">{tab}</ul>', '', $result);
  3254. }
  3255. } else {
  3256. if (isset($param['update_input']) && isset($data[$index . '_input'])) {
  3257. $param['update_input_data'] = explode(',', $data[$index . '_input']);
  3258. }
  3259. $param['project'] = $this->project;
  3260. $param['table'] = $this->table;
  3261. if (isset($param['upload_search'])) {
  3262. $param['upload_search'] = $this->value($param['upload_search'], $data + $param);
  3263. }
  3264. if (isset($param['upload_search_value'])) {
  3265. $param['upload_search_value'] = $this->value($param['upload_search_value'], $data + $param);
  3266. }
  3267. $param['where_id'] = $this->id;
  3268. $result .= Html::$method($param);
  3269. }
  3270. if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
  3271. $result .= Html::desc($param['desc']);
  3272. }
  3273. }
  3274. }
  3275. /**
  3276. * update_action
  3277. *
  3278. * @return array
  3279. */
  3280. private function update_child($data, $param, $key, &$result, $index, $config, $delete = true)
  3281. {
  3282. if (isset($config['tab']) && $config['tab']) {
  3283. if ($index != 0) {
  3284. $style = 'display:none;';
  3285. } else {
  3286. $style = '';
  3287. }
  3288. $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) . '"><ul class="layui-tab-title">';
  3289. $tab = '<div class="layui-tab-content">';
  3290. $i = 0;
  3291. foreach ($config['tab'] as $k => $v) {
  3292. $content = $this->update_child_data($data, $param, $key, $index, $k, $config);
  3293. if ($content) {
  3294. $class_0 = $class_1 = '';
  3295. if ($i == 0) {
  3296. $class_0 = 'layui-this';
  3297. $class_1 = 'layui-show';
  3298. }
  3299. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  3300. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  3301. $i++;
  3302. }
  3303. }
  3304. $tab .= '</div>';
  3305. $result .= '</ul>' . $tab . '</div>';
  3306. } else {
  3307. $style = 'margin:10px;';
  3308. if ($index != 0) {
  3309. $style = 'display:none;margin:10px;';
  3310. }
  3311. $result .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" style="' . $style . '">';
  3312. if ($delete) {
  3313. $result .= '<div class="dever_form_delete" style="cursor:pointer">[删除]</div>';
  3314. }
  3315. $result .= $content = $this->update_child_data($data, $param, $key, $index, -1, $config);
  3316. $result .= '</div>';
  3317. }
  3318. }
  3319. private function update_child_data($data, $param, $key, $index, $tab = -1, $config = array())
  3320. {
  3321. $result = '';
  3322. foreach ($param as $k => $v) {
  3323. if (is_string($k)) {
  3324. $v['col'] = $k;
  3325. }
  3326. if ($this->id && $v['col'] == 'id') {
  3327. $v['update'] = 'hidden';
  3328. }
  3329. if (!isset($v['update'])) {
  3330. continue;
  3331. }
  3332. if (isset($config['prefix']) && $config['prefix']) {
  3333. if (isset($config['lang']) && $config['lang'] && !in_array($v['col'], $config['lang'])) {
  3334. continue;
  3335. }
  3336. $v['col'] = $config['prefix'] . '_' . $v['col'];
  3337. }
  3338. $state = false;
  3339. if ($tab == 0) {
  3340. if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
  3341. $state = true;
  3342. }
  3343. } elseif ($tab > 0) {
  3344. if (isset($v['tab']) && $v['tab'] == $tab) {
  3345. $state = true;
  3346. }
  3347. } else {
  3348. $state = true;
  3349. }
  3350. if (isset($v['update']) && $v['update'] && $state) {
  3351. $v['type'] = $v['update'];
  3352. $prefix = '';
  3353. if ($index < 0) {
  3354. $v['ext'] = $key . '_c_' . $v['col'];
  3355. $prefix = $v['ext'];
  3356. } else {
  3357. $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
  3358. $prefix = $v['ext'];
  3359. }
  3360. if ($v['col'] == 'order') {
  3361. $v['default'] = $index+1;
  3362. }
  3363. $class = $this->update_class($v['col'], $v, $prefix);
  3364. if ($v['update'] == 'hidden') {
  3365. $result .= '<div class="form-group ' . $class . '" style="display:none">';
  3366. $this->update_html($v, $key, $v['col'], $data, $result);
  3367. $result .= '</div>';
  3368. } else {
  3369. $result .= '<div class="form-group ' . $class . '" style="margin-top:10px">';
  3370. $this->update_html($v, $key, $v['col'], $data, $result);
  3371. $result .= '</div>';
  3372. }
  3373. }
  3374. }
  3375. return $result;
  3376. }
  3377. /**
  3378. * update_action
  3379. *
  3380. * @return array
  3381. */
  3382. public function update_action_api()
  3383. {
  3384. $method = false;
  3385. $config = $this->config();
  3386. $input = Dever::preInput('update_');
  3387. if ($this->id) {
  3388. # 新增权限
  3389. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  3390. $auth = 1;
  3391. } else {
  3392. $auth = 3;
  3393. }
  3394. if (Dever::load('manage/auth.oper', $auth) == false) {
  3395. Dever::alert('你没有权限');
  3396. }
  3397. Dever::setInput('where_id', $this->id);
  3398. //Dever::setInput('update_where_id', $this->id);
  3399. $info = $this->load('one', $this->id);
  3400. if ($info) {
  3401. $method = 'update';
  3402. $col = Dever::input('col');
  3403. $value = Dever::input('value');
  3404. if ($col && $value) {
  3405. $method = 'update_' . $col;
  3406. //Dever::setInput('set_' . $col, $value);
  3407. //Dever::setInput('update_' . $col, $value);
  3408. $param['where_id'] = $this->id;
  3409. $param['set_' . $col] = $value;
  3410. $this->load($method, $param);
  3411. $struct = $this->struct_data($config['struct'], array($col => $value));
  3412. Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $this->id);
  3413. Dever::out('yes');
  3414. return;
  3415. }
  3416. $prefix = 'set';
  3417. } else {
  3418. $method = 'insert';
  3419. $prefix = 'add';
  3420. }
  3421. }
  3422. if (!$method) {
  3423. # 新增权限
  3424. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  3425. $auth = 1;
  3426. } else {
  3427. $auth = 4;
  3428. }
  3429. if (Dever::load('manage/auth.oper', $auth) == false) {
  3430. Dever::alert('你没有权限');
  3431. }
  3432. $method = 'insert';
  3433. $prefix = 'add';
  3434. }
  3435. if ($method && $input) {
  3436. $update = $order = $update_other = array();
  3437. $i = 0;
  3438. $c = array();
  3439. foreach ($input as $k => $v) {
  3440. if ($v === '') {
  3441. $v = 'null';
  3442. }
  3443. if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
  3444. $temp = str_replace('copy.', '', $v);
  3445. if (isset($input['update_' . $temp])) {
  3446. $v = $input['update_' . $temp];
  3447. }
  3448. }
  3449. if (strpos($k, '_c_') !== false) {
  3450. if ($v == 'null') {
  3451. $v = '';
  3452. }
  3453. $temp = explode('_c_', $k);
  3454. $h = $temp[0];
  3455. $k = str_replace('update_', $prefix . '_', $h);
  3456. if (!isset($c[$k])) {
  3457. $c[$k] = array();
  3458. }
  3459. if (strpos($temp[1], '_i_') !== false) {
  3460. $temp = explode('_i_', $temp[1]);
  3461. if (!isset($c[$k][$temp[1]])) {
  3462. $c[$k][$temp[1]] = 0;
  3463. } else {
  3464. $c[$k][$temp[1]]++;
  3465. }
  3466. $num = $c[$k][$temp[1]];
  3467. if (strpos($h, '-')) {
  3468. $h = str_replace('update_', '', $h);
  3469. if (isset($config['struct'][$h]) && isset($config['struct'][$h]['sync'])) {
  3470. $s_col = $config['struct'][$h]['sync'][0];
  3471. $m_col = $config['struct'][$h]['sync'][1];
  3472. if ($s_col == 'id') {
  3473. $s_value = $this->id;
  3474. } else {
  3475. $s_one = $this->load('one', $this->id);
  3476. $s_value = $s_one[$s_col];
  3477. }
  3478. $t = explode('-', $h);
  3479. $index = $t[0] . '/' . $t[1];
  3480. $update_col[$i][$index] = $m_col;
  3481. $update_set[$i][$index][$num]['set_' . $temp[1]] = $v;
  3482. $update_add[$i][$index][$num]['add_' . $temp[1]] = $v;
  3483. $update_add[$i][$index][$num]['add_' . $m_col] = $s_value;
  3484. $update_id[$i][$index][$num][$m_col] = $s_value;
  3485. if ($this->id && $temp[1] == 'id') {
  3486. $update_id[$i][$index][$num]['id'] = $v;
  3487. }
  3488. }
  3489. } else {
  3490. $update[$i][$k][$num][$temp[1]] = $v;
  3491. if ($temp[1] == 'order') {
  3492. $order[$i][$k][$num] = $v;
  3493. }
  3494. }
  3495. } else {
  3496. //$update[$i][$k][$c][$temp[1]] = $v;
  3497. }
  3498. } elseif (strpos($k, '__') !== false) {
  3499. $temp1 = explode('__', $k);
  3500. $temp2 = explode('_', $temp1[0]);
  3501. $i = $temp2[1] - 1;
  3502. if (strpos($k, 'where_id') !== false) {
  3503. //$update[$i]['where_id'] = $v;
  3504. } else {
  3505. $update[$i]['add_' . $temp1[1]] = $v;
  3506. }
  3507. } else {
  3508. $ki = str_replace('update_', $prefix . '_', $k);
  3509. if (strpos($ki, 'where_id') !== false) {
  3510. if ($method != 'insert') {
  3511. $update[$i]['where_id'] = $v;
  3512. }
  3513. } else {
  3514. if (strpos($k, 'l-l')) {
  3515. $temp = explode('l-l', $k);
  3516. $k = str_replace('_', '', $temp[2]);
  3517. $update_other[$i][$temp[1]][$k] = $v;
  3518. } elseif (strpos($k, '-')) {
  3519. $k = str_replace('update_', '', $k);
  3520. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  3521. $s_col = $config['struct'][$k]['sync'][0];
  3522. $m_col = $config['struct'][$k]['sync'][1];
  3523. if ($s_col == 'id') {
  3524. $s_value = $this->id;
  3525. } else {
  3526. $s_one = $this->load('one', $this->id);
  3527. $s_value = $s_one[$s_col];
  3528. }
  3529. $temp = explode('-', $k);
  3530. $index = $temp[0] . '/' . $temp[1];
  3531. if (isset($temp[2])) {
  3532. $update_col[$i][$index] = $m_col;
  3533. $update_set[$i][$index][0]['set_' . $temp[2]] = $v;
  3534. //$update_set[$i][$index][0]['set_' . $m_col] = $s_value;
  3535. $update_add[$i][$index][0]['add_' . $temp[2]] = $v;
  3536. $update_add[$i][$index][0]['add_' . $m_col] = $s_value;
  3537. $update_id[$i][$index][0][$m_col] = $s_value;
  3538. }
  3539. } else {
  3540. $temp = explode('-', $k);
  3541. if (isset($temp[2])) {
  3542. $k = $temp[0] . '-' . $temp[1];
  3543. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  3544. $s_col = $config['struct'][$k]['sync'][0];
  3545. $m_col = $config['struct'][$k]['sync'][1];
  3546. if ($s_col == 'id') {
  3547. $s_value = $this->id;
  3548. } else {
  3549. $s_one = $this->load('one', $this->id);
  3550. $s_value = $s_one[$s_col];
  3551. }
  3552. $index = $temp[0] . '/' . $temp[1];
  3553. $temp[2] = ltrim($temp[2], '_');
  3554. $temp = explode('_', $temp[2]);
  3555. $update_col[$i][$index] = $m_col;
  3556. $up = array();
  3557. $up['add_' . $temp[0] . '_id'] = $temp[1];
  3558. $up['add_' . $temp[0] . '_value'] = $v;
  3559. $up['add_' . $m_col] = $s_value;
  3560. $update_add[$i][$index][] = $up;
  3561. $update_delete[$i][$index][][$m_col] = $s_value;
  3562. }
  3563. }
  3564. }
  3565. } else {
  3566. if (is_array($v)) {
  3567. $k = str_replace('update_', '', $k);
  3568. $kd = $k . '_id';
  3569. if (isset($config['struct'][$kd])) {
  3570. foreach ($v as $vk => $vt) {
  3571. if ($vt == -1) {
  3572. if ($vk != 0) {
  3573. unset($v[$vk]);
  3574. }
  3575. }
  3576. }
  3577. if ($v) {
  3578. $vd = end($v);
  3579. $kdi = $prefix . '_' . $kd;
  3580. $update[$i][$kdi] = $vd;
  3581. }
  3582. }
  3583. if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
  3584. $v = end($v);
  3585. }
  3586. }
  3587. $update[$i][$ki] = $v;
  3588. }
  3589. }
  3590. }
  3591. }
  3592. //print_r($update_set);
  3593. //print_r($update_id);
  3594. //print_r($update_add);die;
  3595. //print_r($input);
  3596. //print_r($update_other);
  3597. //print_r($config['struct']);die;
  3598. # 增加复制的数量
  3599. $copy_num = Dever::input('copy_num');
  3600. if ($copy_num > 0) {
  3601. $update[0]['where_id'] = 0;
  3602. for ($i = 1; $i < $copy_num; $i++) {
  3603. $update[$i] = $update[0];
  3604. # 缓存处理
  3605. $update[$i]['rank'] = $i;
  3606. }
  3607. }
  3608. if ($this->id && !$info) {
  3609. $update[0]['add_id'] = $this->id;
  3610. }
  3611. //print_r($update);die;
  3612. foreach ($update as $k => $v) {
  3613. $method = 'insert';
  3614. $old = array();
  3615. if (isset($v['where_id']) && $v['where_id']) {
  3616. $method = 'update';
  3617. $old = $this->load('one', $v['where_id']);
  3618. }
  3619. if (isset($order[$k])) {
  3620. foreach ($order[$k] as $i => $j) {
  3621. array_multisort($j, SORT_ASC, $v[$i]);
  3622. }
  3623. }
  3624. if (isset($v['set_password']) && (!$v['set_password'] || $v['set_password'] == 'null')) {
  3625. unset($v['set_password']);
  3626. }
  3627. $id = $this->load($method, $v);
  3628. if ($id) {
  3629. $struct = $this->struct_data($config['struct'], $v, $old);
  3630. Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $id ? $id : $this->id);
  3631. if ($update_other && isset($update_other[$k])) {
  3632. foreach ($update_other[$k] as $k1 => $v1) {
  3633. $v1['id'] = $id;
  3634. $this->load($method, $v1, $this->table . '__' . $k1);
  3635. }
  3636. }
  3637. if (isset($update_add[$k]) && $update_add[$k]) {
  3638. foreach ($update_add[$k] as $k1 => $v1) {
  3639. $col = $update_col[$k][$k1];
  3640. foreach ($v1 as $k2 => $v2) {
  3641. if (isset($update_set[$k][$k1][$k2]['set_' . $col])) {
  3642. $update_set[$k][$k1][$k2]['set_' . $col] = $id;
  3643. }
  3644. if (isset($v2['add_' . $col])) {
  3645. $v2['add_' . $col] = $id;
  3646. }
  3647. $check = false;
  3648. if (isset($update_id[$k][$k1][$k2])) {
  3649. if (isset($update_id[$k][$k1][$k2][$col])) {
  3650. $update_id[$k][$k1][$k2][$col] = $id;
  3651. }
  3652. $check = Dever::load($k1 . '-one', $update_id[$k][$k1][$k2]);
  3653. } elseif (isset($update_delete[$k][$k1][$k2])) {
  3654. # 清理
  3655. Dever::load($k1 . '-delete', $update_delete[$k][$k1][$k2]);
  3656. }
  3657. if ($check) {
  3658. unset($update_set[$k][$k1][$k2]['set_id']);
  3659. $update_set[$k][$k1][$k2]['where_id'] = $check['id'];
  3660. Dever::load($k1 . '-update', $update_set[$k][$k1][$k2]);
  3661. } else {
  3662. Dever::load($k1 . '-insert', $v2);
  3663. }
  3664. }
  3665. }
  3666. }
  3667. $this->spec($id, $config);
  3668. }
  3669. }
  3670. }
  3671. Dever::out('yes');
  3672. }
  3673. private function spec($id, $config)
  3674. {
  3675. if (isset($config['manage']['sku'])) {
  3676. $spec_table = $config['manage']['sku']['spec'];
  3677. $sku_table = $config['manage']['sku']['sku'];
  3678. }
  3679. if (!isset($sku_table)) {
  3680. $sku_table = 'info_sku';
  3681. }
  3682. $sku_table = $this->project . '/' . $sku_table;
  3683. $spec_type = Dever::input('update_spec_type');
  3684. if ($spec_type == 2) {
  3685. $spec = Dever::input('spec');
  3686. $sku = Dever::input('skus');
  3687. if ($spec && $sku) {
  3688. if (!isset($spec_table)) {
  3689. $spec_table = 'info_spec';
  3690. }
  3691. $spec_table = $this->project . '/' . $spec_table;
  3692. $spec_value_table = $spec_table . '_value';
  3693. $spec = Dever::json_decode($spec);
  3694. if ($spec) {
  3695. $sku_id = array();
  3696. Dever::db($spec_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
  3697. Dever::db($spec_value_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
  3698. foreach ($spec as $k1 => $v1) {
  3699. $order = $k1 + 1;
  3700. if (is_numeric($v1['id'])) {
  3701. $spec_id = Dever::db($spec_table)->update(array('where_id' => $v1['id'], 'set_state' => 1, 'set_reorder' => $order));
  3702. } else {
  3703. $spec_id = Dever::db($spec_table)->insert(array('name' => $v1['title'], 'info_id' => $id, 'reorder' => $order));
  3704. }
  3705. foreach ($v1['child'] as $k2 => $v2) {
  3706. $v2['checked'] = $v2['checked'] ? 1 : 2;
  3707. if (is_numeric($v2['id'])) {
  3708. Dever::db($spec_value_table)->update(array('where_id' => $v2['id'], 'set_state' => 1, 'set_is_checked' => $v2['checked']));
  3709. } else {
  3710. $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));
  3711. }
  3712. }
  3713. }
  3714. Dever::db($spec_table)->delete(array('info_id' => $id, 'state' => 2));
  3715. Dever::db($spec_value_table)->delete(array('info_id' => $id, 'state' => 2));
  3716. $this->sku($id, $sku_table, $sku, $sku_id);
  3717. }
  3718. }
  3719. } else {
  3720. $sku = Dever::input('skus');
  3721. if ($sku) {
  3722. $this->sku($id, $sku_table, $sku);
  3723. //Dever::db($spec_table)->delete(array('info_id' => $id));
  3724. //Dever::db($spec_value_table)->delete(array('info_id' => $id));
  3725. }
  3726. }
  3727. }
  3728. private function sku($id, $sku_table, $sku, $sku_id = false)
  3729. {
  3730. Dever::db($sku_table)->updates(array('option_info_id' => $id, 'set_state' => 2));
  3731. foreach ($sku as $k1 => $v1) {
  3732. if ($sku_id) {
  3733. foreach ($sku_id as $k2 => $v2) {
  3734. $k1 = str_replace($k2, $v2, $k1);
  3735. }
  3736. }
  3737. $sku_data = array();
  3738. $sku_data['info_id'] = $id;
  3739. $sku_data['key'] = $k1;
  3740. $sku_info = Dever::db($sku_table)->one($sku_data);
  3741. foreach ($v1 as $k3 => $v3) {
  3742. $sku_data[$k3] = $v3;
  3743. }
  3744. if ($sku_info) {
  3745. $sku_data['where_id'] = $sku_info['id'];
  3746. $sku_data['state'] = 1;
  3747. Dever::db($sku_table)->update($sku_data);
  3748. } else {
  3749. Dever::db($sku_table)->insert($sku_data);
  3750. }
  3751. }
  3752. Dever::db($sku_table)->delete(array('info_id' => $id, 'state' => 2));
  3753. }
  3754. public function struct_data($struct, $data, $old = array())
  3755. {
  3756. $log = $tlog = array();
  3757. foreach ($struct as $i => $j) {
  3758. /*
  3759. if ($i == 'reorder' || $i == 'id') {
  3760. continue;
  3761. }
  3762. */
  3763. if (isset($j['list_name'])) {
  3764. $j['name'] = $j['list_name'];
  3765. } elseif (strpos($j['name'], '-')) {
  3766. $temp = explode('-', $j['name']);
  3767. $j['name'] = $temp[0];
  3768. }
  3769. if (isset($j['list_table'])) {
  3770. $j['list'] = $j['list_table'];
  3771. if ($j['list'] == false) {
  3772. $data[$i] = false;
  3773. }
  3774. }
  3775. $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
  3776. $update = true;
  3777. if ($old && isset($j['update'])) {
  3778. $update = (is_string($j['update']) && $j['update'] != 'linkage');
  3779. }
  3780. if (isset($data['where_' . $i]) && $data['where_' . $i]) {
  3781. $log[$j['name']] = $data['where_' . $i];
  3782. } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
  3783. $log[$j['name']] = $data['set_' . $i];
  3784. } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
  3785. $log[$j['name']] = $data['add_' . $i];
  3786. } elseif (isset($data[$i]) && $data[$i]) {
  3787. if ($i == 'id') {
  3788. $log[$j['name']] = $data[$i];
  3789. } else {
  3790. $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
  3791. }
  3792. }
  3793. if (isset($log[$j['name']])) {
  3794. $tlog[$j['name']] = $log[$j['name']];
  3795. if (is_array($tlog[$j['name']])) {
  3796. if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
  3797. $tlog[$j['name']] = json_encode($tlog[$j['name']]);
  3798. if (isset($old[$i]) && is_array($old[$i])) {
  3799. $old[$i] = json_encode($old[$i]);
  3800. }
  3801. } elseif (isset($tlog[$j['name']][0])) {
  3802. $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
  3803. if (isset($old[$i]) && is_array($old[$i])) {
  3804. $old[$i] = implode(',', $old[$i]);
  3805. }
  3806. }
  3807. } 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) {
  3808. $log[$j['name']] = '<img layer-src="' . $log[$j['name']] . '" src="' . $log[$j['name']] . '" width="150">';
  3809. if (isset($old[$i]) && $old[$i]) {
  3810. $old[$i] = Dever::pic($old[$i]);
  3811. $old[$i] = '<img layer-src="' . $old[$i] . '" src="' . $old[$i] . '" width="150">';
  3812. }
  3813. } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
  3814. $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
  3815. if (isset($old[$i]) && $old[$i]) {
  3816. $old[$i] = date("Y-m-d H:i:s", $old[$i]);
  3817. }
  3818. } elseif (isset($j['decode'])) {
  3819. $log[$j['name']] = Dever::array_decode($log[$j['name']]);
  3820. if (isset($old[$i]) && $old[$i]) {
  3821. $old[$i] = Dever::array_decode($old[$i]);
  3822. }
  3823. }
  3824. if (isset($j['option']) && !$list && $update) {
  3825. $name = array();
  3826. $old_name = array();
  3827. $option = $this->option($j['option']);
  3828. if (is_array($option)) {
  3829. foreach ($option as $a => $b) {
  3830. if (!is_array($log[$j['name']])) {
  3831. if ($a == $log[$j['name']]) {
  3832. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3833. }
  3834. } elseif (in_array($a, $log[$j['name']])) {
  3835. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3836. }
  3837. if ($old && isset($old[$i])) {
  3838. if (!is_array($old[$i])) {
  3839. if ($a == $old[$i]) {
  3840. $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3841. }
  3842. } elseif (in_array($a, $old[$i])) {
  3843. $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3844. }
  3845. }
  3846. }
  3847. }
  3848. $log[$j['name']] = implode(',', $name);
  3849. if ($old_name) {
  3850. $old[$i] = implode(',', $old_name);
  3851. }
  3852. }
  3853. if ($log[$j['name']] == 'null') {
  3854. unset($log[$j['name']]);
  3855. }
  3856. if ($old && strstr($i, 'area')) {
  3857. $old[$i] = Dever::load('area/api')->string($old[$i]);
  3858. if (isset($log[$j['name']]) && $log[$j['name']]) {
  3859. $log[$j['name']] = Dever::load('area/api')->string($log[$j['name']]);
  3860. }
  3861. }
  3862. if (isset($log[$j['name']]) && isset($old[$i]) && $old[$i] != $tlog[$j['name']] && $old[$i] != $log[$j['name']]) {
  3863. $log[$j['name']] = array('更新前' => $old[$i], '更新后' => $log[$j['name']]);
  3864. } elseif ($old) {
  3865. //unset($log[$j['name']]);
  3866. }
  3867. }
  3868. }
  3869. return $log;
  3870. }
  3871. /**
  3872. * delete_action
  3873. *
  3874. * @return array
  3875. */
  3876. public function delete_action_api()
  3877. {
  3878. if (Dever::load('manage/auth.oper', 5) == false) {
  3879. Dever::alert('您没有权限');
  3880. }
  3881. $config = $this->config();
  3882. if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  3883. $name = '逻辑删除';
  3884. $this->load('update', array('where_id' => $this->id, 'state' => 2));
  3885. } else {
  3886. $name = '物理删除';
  3887. $this->load('delete', $this->id);
  3888. }
  3889. Log::add($this->project, $this->table, $this->menu_id, '', 3, array('ID' => $this->id, '方式' => $name), $this->id);
  3890. return 'reload';
  3891. return 'reloaderror';
  3892. }
  3893. /**
  3894. * recovery_action
  3895. *
  3896. * @return array
  3897. */
  3898. public function recovery_action_api()
  3899. {
  3900. if (Dever::load('manage/auth.oper', 5) == false) {
  3901. Dever::alert('您没有权限');
  3902. }
  3903. $this->load('update', array('where_id' => $this->id, 'state' => 1));
  3904. Log::add($this->project, $this->table, $this->menu_id, '', 4, array('ID' => $this->id, '方式' => '逻辑恢复'), $this->id);
  3905. return 'reload';
  3906. }
  3907. /**
  3908. * list_data
  3909. *
  3910. * @return array
  3911. */
  3912. public function list_data()
  3913. {
  3914. $config = $this->config();
  3915. $data = array();
  3916. if (isset($config['manage']['data']) && $config['manage']['data']) {
  3917. foreach ($config['manage']['data'] as $k => $v) {
  3918. if (is_object($v[1])) {
  3919. $function = $v[1];
  3920. $v[1] = $function();
  3921. }
  3922. $link = '';
  3923. if (isset($v[2]) && $v[2]) {
  3924. $link = 'project/database/list?project=' . $this->project . '&table=' . $this->table . '&' . $v[2];
  3925. $link = 'href="' . Dever::url($link, 'manage') . '"';
  3926. }
  3927. $data[] = '<li class="layui-col-xs3">
  3928. <a class="layadmin-backlog-body" '.$link.'><h3>'.$v[0].'</h3>
  3929. <p><cite>'.$v[1].'</cite></p></a></li>';
  3930. }
  3931. }
  3932. return $data;
  3933. }
  3934. /**
  3935. * list_data
  3936. *
  3937. * @return array
  3938. */
  3939. public function list_data_show()
  3940. {
  3941. $config = $this->config();
  3942. if (isset($config['manage']['data']) && $config['manage']['data']) {
  3943. return 'display:block';
  3944. }
  3945. return 'display:none';
  3946. }
  3947. /**
  3948. * chart
  3949. *
  3950. * @return array
  3951. */
  3952. public function chart($config, $key, $data, $struct)
  3953. {
  3954. if (!$this->chart) {
  3955. $this->chart = array();
  3956. $this->chart['x'] = array();
  3957. $this->chart['data'] = array();
  3958. }
  3959. if ($config['x'] == $key) {
  3960. $this->chart['x'][] = $data;
  3961. } elseif (in_array($key, $config['data'])) {
  3962. if (!isset($this->chart['data'][$key])) {
  3963. $this->chart['data'][$key] = array
  3964. (
  3965. 'name' => $struct['name'],
  3966. 'type' => 'line',
  3967. 'stack' => 'Total',
  3968. 'data' => array(),
  3969. );
  3970. }
  3971. $this->chart['data'][$key]['data'][] = $data;
  3972. }
  3973. }
  3974. /**
  3975. * chart_data
  3976. *
  3977. * @return array
  3978. */
  3979. public function list_chart()
  3980. {
  3981. $config = $this->config();
  3982. $chart = '';
  3983. if (isset($config['manage']['chart']) && $this->chart) {
  3984. $this->chart['x'] = array_reverse($this->chart['x']);
  3985. $x = Dever::json_encode($this->chart['x']);
  3986. $this->chart['data'] = array_values($this->chart['data']);
  3987. foreach ($this->chart['data'] as $k => $v) {
  3988. $this->chart['data'][$k]['data'] = array_reverse($this->chart['data'][$k]['data']);
  3989. }
  3990. $data = Dever::json_encode($this->chart['data']);
  3991. $echarts = Dever::assets('lib/echarts/echarts.common.min.js', 'script');
  3992. $chart = '<script type="text/javascript" src="'.$echarts.'"></script><script>var chartDom = document.getElementById("chart");var myChart = echarts.init(chartDom);';
  3993. $chart .= "var option = {
  3994. tooltip: {
  3995. trigger: 'axis'
  3996. },
  3997. toolbox: {
  3998. feature: {
  3999. saveAsImage: {}
  4000. }
  4001. },
  4002. xAxis: {
  4003. type: 'category',
  4004. boundaryGap: false,
  4005. data: ".$x."
  4006. },
  4007. yAxis: {
  4008. type: 'value'
  4009. },
  4010. series: ".$data."
  4011. };option && myChart.setOption(option);</script>";
  4012. }
  4013. return $chart;
  4014. }
  4015. /**
  4016. * chart_data
  4017. *
  4018. * @return array
  4019. */
  4020. public function list_chart_show()
  4021. {
  4022. $config = $this->config();
  4023. if (isset($config['manage']['chart'])) {
  4024. return 'display:block';
  4025. }
  4026. return 'display:none';
  4027. }
  4028. /**
  4029. * stat 为主动统计提供相关数据
  4030. *
  4031. * @return array
  4032. */
  4033. public function stat()
  4034. {
  4035. //bundle 包依赖工具
  4036. $config = $this->config();
  4037. if (empty($config['manage']['stat'])) {
  4038. Dever::alert('该项目主动统计功能未开放');
  4039. }
  4040. $data = $config['manage'];
  4041. $data['table'] = '';
  4042. $method = $this->project . '/' . $this->table . '-all';
  4043. $gp = Dever::input('gp', 'month,day');
  4044. $col = is_string($gp) ? explode(',', $gp) : $gp;
  4045. $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
  4046. foreach ($col as $k => $v) {
  4047. $this->stat_data($data, $config['struct'], $v, $method);
  4048. }
  4049. return $data;
  4050. }
  4051. /**
  4052. * stat 为主动统计提供导出数据 后续优化
  4053. *
  4054. * @return array
  4055. */
  4056. public function stat_excel()
  4057. {
  4058. Dever::$global['base']['excel'] = 1;
  4059. //print_r($data['thead']);die;
  4060. $data = $this->stat();
  4061. if ($data && isset($data['list'])) {
  4062. $xls = new \PHPExcel();
  4063. $xls->getProperties()->setCreator("Maze Stat Excel")
  4064. ->setLastModifiedBy("Maze Stat Excel")
  4065. ->setTitle("Office 2007 XLSX Maze Document")
  4066. ->setSubject("Office 2007 XLSX Maze Document")
  4067. ->setDescription("Dever Stat Excel")
  4068. ->setKeywords("Dever Stat Excel")
  4069. ->setCategory("Dever Stat Excel");
  4070. $info = $this->info();
  4071. $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
  4072. $start = 65;
  4073. $s = 0;
  4074. foreach ($data['thead'] as $k => $v) {
  4075. if ($s > 0) {
  4076. $xls->createSheet();
  4077. }
  4078. $act = $xls->setActiveSheetIndex($s);
  4079. $act->setTitle($v[0]);
  4080. $s++;
  4081. $i = 0;
  4082. foreach ($v as $kj => $vj) {
  4083. $num = 1;
  4084. $cell = $this->_getChr($start, $i);
  4085. $act->setCellValue($cell . '' . $num, $vj);
  4086. $act->getColumnDimension($cell)->setWidth(20);
  4087. $i++;
  4088. if (isset($data['list'][$k])) {
  4089. foreach ($data['list'][$k] as $ki => $vi) {
  4090. if (isset($vi[$kj])) {
  4091. $num += 1;
  4092. $act->setCellValue($cell . $num, $vi[$kj]);
  4093. }
  4094. }
  4095. }
  4096. }
  4097. }
  4098. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
  4099. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
  4100. $xls->setActiveSheetIndex(0);
  4101. $filename = $name . '.xlsx';
  4102. header('Pragma: public');
  4103. header('Expires: 0');
  4104. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  4105. header('Content-Type:application/force-download');
  4106. header('Content-Type:application/vnd.ms-execl');
  4107. header('Content-Type:application/octet-stream');
  4108. header('Content-Type:application/download');
  4109. header("Content-Disposition:attachment;filename='" . $filename . "'");
  4110. header('Content-Transfer-Encoding:binary');
  4111. $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
  4112. $write->save('php://output');
  4113. }
  4114. }
  4115. /**
  4116. * stat_search
  4117. *
  4118. * @return mixed
  4119. */
  4120. private function stat_search($struct, $col, $stat, $search)
  4121. {
  4122. unset($struct['id']);
  4123. unset($struct['cdate']);
  4124. if ($stat) {
  4125. $stat = explode(',', $stat);
  4126. foreach ($stat as $k => $v) {
  4127. if (isset($struct[$v])) {
  4128. unset($struct[$v]);
  4129. }
  4130. }
  4131. }
  4132. $struct['day']['name'] = '天';
  4133. $struct['month']['name'] = '月';
  4134. $struct['year']['name'] = '年';
  4135. $param['update'] = 'checkbox';
  4136. $param['name'] = 'gp';
  4137. $param['value'] = $col;
  4138. $param['option'] = $struct;
  4139. $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
  4140. $html .= '<div class="form-group">';
  4141. $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
  4142. $html .= Html::radio($param);
  4143. $html .= '</div>';
  4144. $input = Dever::preInput('search_');
  4145. if (isset($search['date'])) {
  4146. foreach ($search['date'] as $k => $v) {
  4147. $html .= '<div class="form-group">';
  4148. $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
  4149. $html .= '</div>';
  4150. }
  4151. $input = Dever::preInput('search_');
  4152. if ($input) {
  4153. foreach ($input as $k => $v) {
  4154. if ($v && strpos($k, 'option_') !== false) {
  4155. Dever::setInput(str_replace('search_', '', $k), $v);
  4156. }
  4157. }
  4158. }
  4159. }
  4160. if (isset($search['fulltext'])) {
  4161. $html .= '<div class="form-group">';
  4162. $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
  4163. $this->list_search_select($html, $input, 'search_fulltext_type', '', array
  4164. (
  4165. 1 => '精确匹配',
  4166. 2 => '模糊匹配',
  4167. 3 => '大于',
  4168. 4 => '大于等于',
  4169. 5 => '小于',
  4170. 6 => '小于等于',
  4171. ), 1);
  4172. $value = array();
  4173. $value['name'] = 'search_fulltext_value';
  4174. $value['class'] = 'form-control';
  4175. if (isset($input[$value['name']])) {
  4176. $value['value'] = $input[$value['name']];
  4177. $fix = '';
  4178. if ($input['search_fulltext_type'] == 2) {
  4179. $fix = '%';
  4180. }
  4181. Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
  4182. //print_r(Dever::input('option_name'));die;
  4183. }
  4184. $html .= Html::text($value, false);
  4185. $html .= '</div>';
  4186. }
  4187. $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>';
  4188. $html .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
  4189. $html .= '</form>';
  4190. return $html;
  4191. }
  4192. /**
  4193. * stat_data
  4194. *
  4195. * @return mixed
  4196. */
  4197. private function stat_data(&$data, $struct, $col, $method)
  4198. {
  4199. Dever::setInput('group', $col);
  4200. switch ($col) {
  4201. case 'year':
  4202. $name = '按年统计';
  4203. break;
  4204. case 'month':
  4205. $name = '按月统计';
  4206. break;
  4207. case 'day':
  4208. $name = '按天统计';
  4209. break;
  4210. default:
  4211. $name = $struct[$col]['name'];
  4212. break;
  4213. }
  4214. $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
  4215. $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
  4216. $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
  4217. $data['thead'][$col] = array($name, '统计数字');
  4218. if ($list) {
  4219. $data['table'] .= '<tbody>';
  4220. $total = 0;
  4221. foreach ($list as $k => $v) {
  4222. if (isset($v[$col])) {
  4223. if (isset($struct[$col]['option'])) {
  4224. $option = $this->option($struct[$col]['option']);
  4225. if (isset($option[$v[$col]])) {
  4226. $v[$col] = $option[$v[$col]];
  4227. if (is_array($v[$col])) {
  4228. $v[$col] = $v[$col]['name'];
  4229. }
  4230. }
  4231. }
  4232. $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
  4233. $total += $v['total'];
  4234. $data['list'][$col][] = array($v[$col], $v['total']);
  4235. }
  4236. }
  4237. $data['table'] .= '</tbody>';
  4238. if ($total > 0 && $k > 0) {
  4239. $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
  4240. $data['list'][$col][] = array('汇总', $total);
  4241. }
  4242. }
  4243. $data['table'] .= '</table></div>';
  4244. }
  4245. /**
  4246. * load
  4247. *
  4248. * @return mixed
  4249. */
  4250. private function load($method = 'one', $param = array(), $table = false)
  4251. {
  4252. if (!$table) {
  4253. $table = $this->table;
  4254. }
  4255. return Dever::load($this->project . '/' . $table . '-' . $method, $param);
  4256. }
  4257. /**
  4258. * __call
  4259. *
  4260. * @return object
  4261. */
  4262. public function __call($method, $param)
  4263. {
  4264. if (strpos($method, 'html_') !== false) {
  4265. return Html::text($param);
  4266. }
  4267. return $this;
  4268. }
  4269. /**
  4270. * option
  4271. *
  4272. * @return string
  4273. */
  4274. private function option($option, $value = false)
  4275. {
  4276. if (is_object($option)) {
  4277. $function = $option;
  4278. $option = $function();
  4279. }
  4280. if ($value && is_array($value)) {
  4281. $state = false;
  4282. foreach ($value as $k => $v) {
  4283. if ($v === true) {
  4284. $state = true;
  4285. break;
  4286. }
  4287. }
  4288. if ($state) {
  4289. $option = array_intersect_key($option, $value);
  4290. } else {
  4291. $option = $value;
  4292. }
  4293. }
  4294. return $option;
  4295. }
  4296. /**
  4297. * option
  4298. *
  4299. * @return string
  4300. */
  4301. public function manage()
  4302. {
  4303. $config = $this->config();
  4304. return $config;
  4305. }
  4306. /**
  4307. * valid
  4308. *
  4309. * @return string
  4310. */
  4311. public function valid()
  4312. {
  4313. //http://placehold.it/350x150
  4314. $config = $this->config();
  4315. if (isset($config['struct'])) {
  4316. $rule = array();
  4317. $rule['required']['regex'] = 'none';
  4318. $rule['required']['alertText'] = '此项不能为空';
  4319. $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
  4320. $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
  4321. $rule['required']['alertTextDateRange'] = '日期范围不可空白';
  4322. foreach ($config['struct'] as $k => $v) {
  4323. if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
  4324. if (strstr($v['match'], 'option||')) {
  4325. $v['match'] = str_replace('option||', '', $v['match']);
  4326. }
  4327. $rule[$k]['regex'] = $v['match'];
  4328. $rule[$k]['alertText'] = $v['desc'];
  4329. }
  4330. }
  4331. }
  4332. $script = '<script>';
  4333. //参考https://blog.csdn.net/wangzl1163/article/details/51071826
  4334. //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
  4335. $script .= '(function($){
  4336. $.fn.validationEngineLanguage = function(){
  4337. };
  4338. $.validationEngineLanguage = {
  4339. newLang: function(){
  4340. $.validationEngineLanguage.allRules = ';
  4341. //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
  4342. $script .= str_replace(array('\\\\', '\\/', '"/', '/"', '/u"', '/g"', '/i"', '\x{4e00}-\x{9fa5}', '\x'), array('\\', '/', '/', '/', '/u', '/g', '/i', '\u4e00-\u9fa5', '\u'), json_encode($rule)) . ';';
  4343. $script .= '}
  4344. };
  4345. $.validationEngineLanguage.newLang();
  4346. })(jQuery);';
  4347. $script .= '$(document).ready(function(){
  4348. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  4349. });';
  4350. $script .= '</script>';
  4351. //print_r($script);die;
  4352. return $script;
  4353. }
  4354. /**
  4355. * save
  4356. *
  4357. * @return string
  4358. */
  4359. public function save()
  4360. {
  4361. $config = $this->config();
  4362. if (isset($config['manage']['save'])) {
  4363. return 'yes';
  4364. }
  4365. return 'no';
  4366. }
  4367. }