Database.php 183 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827
  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. $config['state'] = $this->getState();
  655. $config['project'] = $project;
  656. # 新增排序
  657. $l = isset($_GET['l']) ? $_GET['l'] : '';
  658. if ($l == 'project/database/list' || $l == 'database.list_excel') {
  659. $list_order = array();
  660. $i = 0;
  661. foreach ($config['struct'] as $ki => $vi) {
  662. if (isset($vi['list_order'])) {
  663. $list_order[] = $vi['list_order'];
  664. } else {
  665. $config['struct'][$ki]['list_order'] = $i;
  666. $list_order[] = $i;
  667. }
  668. $i++;
  669. }
  670. if ($list_order) {
  671. array_multisort($list_order, SORT_ASC, SORT_NUMERIC, $config['struct']);
  672. }
  673. }
  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. # 搜索
  1202. if (isset($config['struct']) && isset($config['manage']['search']) && $config['manage']['search']) {
  1203. $search = Dever::preInput('search_');
  1204. $node = Html::node(array(' style="margin-top:0px;"', ''));
  1205. $btn = '<div class="layui-inline"><input type="hidden" value="2" name="excel" id="excel">';
  1206. if (isset($config['manage']['search']['button'])) {
  1207. foreach ($config['manage']['search']['button'] as $k => $v) {
  1208. $i = 0;
  1209. foreach ($v['option'] as $k1 => $v1) {
  1210. $value = $k . '~' . $v['sum'] . '~' . $k1;
  1211. if (isset($v['group'])) {
  1212. $value .= '~' . $v['group'];
  1213. }
  1214. if (!isset($search['search_button']) && $i == 0) {
  1215. $search['search_button'] = $value;
  1216. }
  1217. if (isset($search['search_button']) && $search['search_button'] == $value) {
  1218. $class = 'layui-btn-normal';
  1219. } else {
  1220. $class = 'layui-btn-primary';
  1221. }
  1222. $url = $this->url('list', 0, false, '&search_button=' . $value);
  1223. $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;';
  1224. }
  1225. }
  1226. }
  1227. $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>';
  1228. //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
  1229. $prefix = 'search_';
  1230. $result .= $node[0];
  1231. if (isset($config['manage']['search']['linkage'])) {
  1232. foreach ($config['manage']['search']['linkage'] as $k => $v) {
  1233. $this->list_search_linkage($result, $search, $prefix . 'linkage_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  1234. if (!layadmin()) {
  1235. $result .= '<br />';
  1236. }
  1237. }
  1238. }
  1239. if (isset($config['manage']['search']['selects'])) {
  1240. $this->list_search_br($result);
  1241. foreach ($config['manage']['search']['selects'] as $k => $v) {
  1242. $bind = array();
  1243. $parent = '';
  1244. $option = $this->option($v['option']);
  1245. if (isset($config['manage']['search_parent'][$k])) {
  1246. $bind = array
  1247. (
  1248. 'onchange',
  1249. 'setOption',
  1250. 'search_option_' . $config['manage']['search_parent'][$k]
  1251. );
  1252. }
  1253. elseif (isset($config['manage']['search_child'][$k])) {
  1254. $parent = $config['manage']['search_child'][$k];
  1255. }
  1256. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent, true);
  1257. }
  1258. }
  1259. if (isset($config['manage']['search']['select'])) {
  1260. $this->list_search_br($result);
  1261. foreach ($config['manage']['search']['select'] as $k => $v) {
  1262. $bind = array();
  1263. $parent = '';
  1264. $option = $this->option($v['option']);
  1265. if (isset($config['manage']['search_parent'][$k])) {
  1266. $bind = array
  1267. (
  1268. 'onchange',
  1269. 'setOption',
  1270. 'search_option_' . $config['manage']['search_parent'][$k]
  1271. );
  1272. }
  1273. elseif (isset($config['manage']['search_child'][$k])) {
  1274. $parent = $config['manage']['search_child'][$k];
  1275. }
  1276. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
  1277. }
  1278. }
  1279. if (isset($config['manage']['search']['exist'])) {
  1280. $this->list_search_br($result);
  1281. foreach ($config['manage']['search']['exist'] as $k => $v) {
  1282. $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
  1283. }
  1284. }
  1285. if (isset($config['manage']['search']['group'])) {
  1286. $this->list_search_br($result);
  1287. foreach ($config['manage']['search']['group'] as $k => $v) {
  1288. $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  1289. }
  1290. }
  1291. if (isset($config['manage']['search']['api'])) {
  1292. $this->list_search_br($result);
  1293. foreach ($config['manage']['search']['api'] as $k => $v) {
  1294. $value = array();
  1295. $value['name'] = $prefix . 'api_' . $k;
  1296. $value['class'] = 'form-control';
  1297. if (isset($search[$value['name']])) {
  1298. $value['value'] = $search[$value['name']];
  1299. }
  1300. if (strpos($v['lang'], '-') !== false) {
  1301. $t = explode('-', $v['lang']);
  1302. $v['lang'] = $t[0];
  1303. }
  1304. $value['placeholder'] = $v['lang'];
  1305. if (isset($v['option']) && $v['option']) {
  1306. $value['option'] = $this->option($v['option']);
  1307. $result .= Html::select($value, false);
  1308. } else {
  1309. $result .= Html::text($value, false);
  1310. }
  1311. }
  1312. }
  1313. if (isset($config['manage']['search']['text'])) {
  1314. $this->list_search_br($result);
  1315. foreach ($config['manage']['search']['text'] as $k => $v) {
  1316. $value = array();
  1317. $value['name'] = $prefix . 'option_' . $k;
  1318. $value['class'] = 'form-control';
  1319. if (isset($search[$value['name']])) {
  1320. $value['value'] = $search[$value['name']];
  1321. }
  1322. if (strpos($v, '-') !== false) {
  1323. $t = explode('-', $v);
  1324. $v = $t[0];
  1325. }
  1326. $value['placeholder'] = $v;
  1327. $result .= Html::text($value, false);
  1328. }
  1329. }
  1330. if (isset($config['manage']['search']['hidden'])) {
  1331. $this->list_search_br($result);
  1332. foreach ($config['manage']['search']['hidden'] as $k => $v) {
  1333. $value = array();
  1334. $value['name'] = $prefix . 'option_' . $k;
  1335. $value['class'] = 'form-control';
  1336. if (isset($search[$value['name']])) {
  1337. $value['value'] = $search[$value['name']];
  1338. }
  1339. if (strpos($v, '-') !== false) {
  1340. $t = explode('-', $v);
  1341. $v = $t[0];
  1342. }
  1343. $value['placeholder'] = $v;
  1344. $value['type'] = 'hidden';
  1345. $result .= Html::hidden($value, false);
  1346. }
  1347. }
  1348. if (isset($config['manage']['search']['ins'])) {
  1349. $this->list_search_br($result);
  1350. foreach ($config['manage']['search']['ins'] as $k => $v) {
  1351. $value = array();
  1352. $value['name'] = $prefix . 'option_' . $k;
  1353. $value['class'] = 'form-control';
  1354. if (isset($search[$value['name']])) {
  1355. $value['value'] = $search[$value['name']];
  1356. }
  1357. if (strpos($v, '-') !== false) {
  1358. $t = explode('-', $v);
  1359. $v = $t[0];
  1360. }
  1361. $value['placeholder'] = $v;
  1362. $result .= Html::text($value, false);
  1363. }
  1364. }
  1365. if (isset($config['manage']['search']['fulltext'])) {
  1366. $this->list_search_br($result);
  1367. foreach ($config['manage']['search']['fulltext'] as $k => $v) {
  1368. $value = array();
  1369. $value['name'] = $prefix . 'fulltext_' . $k;
  1370. $value['class'] = 'form-control';
  1371. if (isset($search[$value['name']])) {
  1372. $value['value'] = $search[$value['name']];
  1373. }
  1374. if (strpos($v, '-') !== false) {
  1375. $t = explode('-', $v);
  1376. $v = $t[0];
  1377. }
  1378. $value['placeholder'] = $v;
  1379. $result .= Html::text($value, false);
  1380. }
  1381. }
  1382. if (isset($config['manage']['search']['exp'])) {
  1383. $result .= '<br />';
  1384. $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
  1385. $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
  1386. (
  1387. 3 => '大于',
  1388. 4 => '大于等于',
  1389. 5 => '小于',
  1390. 6 => '小于等于',
  1391. ), 1);
  1392. $value = array();
  1393. $value['name'] = $prefix . 'exp_value';
  1394. $value['class'] = 'form-control';
  1395. if (isset($search[$value['name']])) {
  1396. $value['value'] = $search[$value['name']];
  1397. }
  1398. $value['placeholder'] = '填写值';
  1399. $result .= Html::text($value, false);
  1400. }
  1401. if (isset($config['manage']['search']['day'])) {
  1402. foreach ($config['manage']['search']['day'] as $k => $v) {
  1403. $this->list_search_time($result, $search, $prefix, $k, $v, 'day');
  1404. }
  1405. }
  1406. if (isset($config['manage']['search']['date'])) {
  1407. foreach ($config['manage']['search']['date'] as $k => $v) {
  1408. $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
  1409. }
  1410. }
  1411. if (isset($config['manage']['search']['year'])) {
  1412. foreach ($config['manage']['search']['year'] as $k => $v) {
  1413. $this->list_search_time($result, $search, $prefix, $k, $v, 'year');
  1414. }
  1415. }
  1416. if (isset($config['manage']['search']['month'])) {
  1417. foreach ($config['manage']['search']['month'] as $k => $v) {
  1418. $this->list_search_time($result, $search, $prefix, $k, $v, 'month');
  1419. }
  1420. }
  1421. if (isset($config['manage']['search']['sday'])) {
  1422. $result .= '<br />';
  1423. foreach ($config['manage']['search']['sday'] as $k => $v) {
  1424. $this->list_search_time($result, $search, $prefix, $k, $v, 'sday');
  1425. }
  1426. $sday = Dever::input('search_option_sday');
  1427. $s1 = $s2 = $s3 = '';
  1428. if ($sday == 7) {
  1429. $s2 = 'sday_button_border';
  1430. } elseif ($sday == 30) {
  1431. $s3 = 'sday_button_border';
  1432. } elseif ($sday) {
  1433. $s1 = 'sday_button_border';
  1434. }
  1435. $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>';
  1436. $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>';
  1437. $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>';
  1438. $result .= '<input type="hidden" name="search_option_sday" id="search_option_sday" value="0">';
  1439. } elseif (isset($config['manage']['search']['sdate'])) {
  1440. $result .= '<br />';
  1441. foreach ($config['manage']['search']['sdate'] as $k => $v) {
  1442. $this->list_search_time($result, $search, $prefix, $k, $v, 'sdate');
  1443. }
  1444. $sdate = Dever::input('search_option_sdate');
  1445. $s1 = $s2 = $s3 = '';
  1446. if ($sdate == 7) {
  1447. $s2 = 'sdate_button_border';
  1448. } elseif ($sdate == 30) {
  1449. $s3 = 'sdate_button_border';
  1450. } elseif ($sdate) {
  1451. $s1 = 'sdate_button_border';
  1452. }
  1453. $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>';
  1454. $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>';
  1455. $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>';
  1456. $result .= '<input type="hidden" name="search_option_sdate" id="search_option_sdate" value="0">';
  1457. }
  1458. # 列表页按钮
  1459. if (isset($config['manage']['search_button'])) {
  1460. $btn .= $this->list_button_show($config['manage']['search_button']);
  1461. }
  1462. $result .= $btn . $node[1];
  1463. //$result .= '</form>';
  1464. # 增加每页显示条数
  1465. $config['manage']['num'] = $this->getNumConfig($config);
  1466. /*
  1467. if ($config['manage']['num']) {
  1468. $result = $this->num($result, $config['manage']['num']);
  1469. }
  1470. */
  1471. }
  1472. $oper = Dever::preInput('oper_');
  1473. if ($oper) {
  1474. foreach ($oper as $k => $v) {
  1475. $result .= '<input type="hidden" value="'.$v.'" name="'.$k.'" id="'.$k.'" />';
  1476. }
  1477. }
  1478. $top = Dever::input('top_parent');
  1479. if ($top) {
  1480. $result .= '<input type="hidden" value="'.$top.'" name="top_parent" id="top_parent" />';
  1481. }
  1482. $page_type = Dever::input('page_type');
  1483. if ($page_type) {
  1484. $result .= '<input type="hidden" value="'.$page_type.'" name="page_type" id="page_type" />';
  1485. }
  1486. return $result;
  1487. }
  1488. private function list_search_br(&$result)
  1489. {
  1490. if (strpos($result, '&nbsp;&nbsp;') && !strpos($result, '<br />')) {
  1491. $result .= '<br />';
  1492. }
  1493. }
  1494. /**
  1495. * 获取条数配置
  1496. *
  1497. * @return array
  1498. */
  1499. private function getNumConfig($config)
  1500. {
  1501. if (isset($config['manage']['list_type'])) {
  1502. return false;
  1503. }
  1504. if (isset($config['manage']['num']) && $config['manage']['num'] == false) {
  1505. return false;
  1506. }
  1507. if (!isset($config['manage']['num'])) {
  1508. $config['manage']['num'] = array(20,30,40,50,60,70,80,90,100);
  1509. }
  1510. Dever::config('base')->page_num = $config['manage']['num'];
  1511. return $config['manage']['num'];
  1512. }
  1513. /**
  1514. * 生成条数的html
  1515. *
  1516. * @return string
  1517. */
  1518. private function num($result, $config)
  1519. {
  1520. return $result;
  1521. $limit = '';
  1522. $cur = Dever::input('search_limit', 0);
  1523. foreach($config as $k => $v) {
  1524. if ($cur == $k) {
  1525. $btn = 'success';
  1526. } else {
  1527. $btn = 'default';
  1528. }
  1529. $url = $this->url('list', 0, false, '&search_limit=' . $k);
  1530. $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.' layui-btn layui-btn-radius layui-btn-primary">'.$v.'</a> ';
  1531. }
  1532. $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>';
  1533. /*
  1534. if (layadmin()) {
  1535. $num = '';
  1536. }*/
  1537. $result .= $num;
  1538. return $result;
  1539. }
  1540. /**
  1541. * 列表页表格头
  1542. *
  1543. * @return array
  1544. */
  1545. public function list_thead($type = false)
  1546. {
  1547. if (Dever::load('manage/auth.oper', 1) == false) {
  1548. Dever::alert('你没有权限');
  1549. }
  1550. $config = $this->config();
  1551. if ($type == 'layui') {
  1552. if (!isset($config['manage']['list_table']) || (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'html')) {
  1553. return false;
  1554. }
  1555. } else {
  1556. if (isset($config['manage']['list_table']) && $config['manage']['list_table'] == 'js') {
  1557. return '';
  1558. }
  1559. }
  1560. $result = array();
  1561. /*
  1562. $tbody = Dever::load('manage/database.list_tbody');
  1563. if (!$tbody) {
  1564. return $result;
  1565. }
  1566. */
  1567. if (isset($config['struct'])) {
  1568. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  1569. # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
  1570. if (isset($config['top']) && is_string($config['top'])) {
  1571. $top = Dever::load('manage/auth.getTop', array($config['top']));
  1572. if ($top) {
  1573. $url = $this->url('update', $top['value']);
  1574. }
  1575. } else {
  1576. $url = $this->url('update', Dever::input('where_id', 1));
  1577. }
  1578. return Dever::location($url);
  1579. } else {
  1580. if (isset($config['manage']['mul']) && $config['manage']['mul']) {
  1581. if ($type == 'layui') {
  1582. $layui = array
  1583. (
  1584. 'field' => 'checkbox',
  1585. 'title' => '<input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list" lay-ignore/>',
  1586. //'fixed' => 'left',
  1587. );
  1588. $result[] = $layui;
  1589. } else {
  1590. $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
  1591. }
  1592. }
  1593. $data = array();
  1594. $data = $this->getAdminInfo($data);
  1595. foreach ($config['struct'] as $k => $v) {
  1596. if (isset($v['list']) && $v['list']) {
  1597. # 处理权限
  1598. if (isset($v['auth'])) {
  1599. $auth = $this->value($v['auth'], $data);
  1600. if (!$auth) {
  1601. continue;
  1602. }
  1603. }
  1604. if (isset($v['list_name'])) {
  1605. $v['name'] = $v['list_name'];
  1606. } else {
  1607. $temp = Html::cue(array('name' => $v['name']));
  1608. $v['name'] = $temp['name'];
  1609. }
  1610. if (!isset($v['level'])) {
  1611. $v['level'] = $config['level'];
  1612. }
  1613. if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
  1614. $link = Dever::url();
  1615. $order = 'search_order_' . $k . '';
  1616. if (strpos($link, $order) !== false) {
  1617. $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
  1618. } else {
  1619. $link .= '{order}';
  1620. }
  1621. $search = Dever::input($order);
  1622. $cancel = '';
  1623. if ($search) {
  1624. $asc = $search;
  1625. $cancel = '&nbsp;<a class="glyphicon glyphicon-remove-sign layui-icon layui-icon-close" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
  1626. } else {
  1627. $asc = 'desc';
  1628. if (!isset($v['order']) && $k != 'id') {
  1629. //$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>';
  1630. }
  1631. }
  1632. if ($asc == 'asc') {
  1633. $asc = 'desc';
  1634. $icon = 'down';
  1635. $text = '降序';
  1636. } else {
  1637. $asc = 'asc';
  1638. $icon = 'up';
  1639. $text = '升序';
  1640. }
  1641. $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
  1642. if ($type == 'layui') {
  1643. $layui = array
  1644. (
  1645. 'field' => $k,
  1646. '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>',
  1647. );
  1648. $result[] = $layui;
  1649. } else {
  1650. $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>';
  1651. }
  1652. } else {
  1653. if ($type == 'layui') {
  1654. if ($k == 'id' || isset($v['fixed'])) {
  1655. $layui = array
  1656. (
  1657. 'field' => $k,
  1658. 'title' => $v['name'],
  1659. //'fixed' => 'left',
  1660. );
  1661. } else {
  1662. $layui = array
  1663. (
  1664. 'field' => $k,
  1665. 'title' => $v['name'],
  1666. );
  1667. }
  1668. if (isset($v['list_header']) && $v['list_header']) {
  1669. $layui += $v['list_header'];
  1670. }
  1671. $result[] = $layui;
  1672. } else {
  1673. $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
  1674. }
  1675. }
  1676. }
  1677. }
  1678. //if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
  1679. if (isset($config['manage']['_list']['value']) && $this->manage_button) {
  1680. if ($type == 'layui') {
  1681. $layui = array
  1682. (
  1683. 'field' => $config['manage']['_list']['col'],
  1684. 'title' => $config['manage']['_list']['name'],
  1685. //'fixed' => 'right',
  1686. );
  1687. $result[] = $layui;
  1688. } else {
  1689. $result[] = '<th data-priority="1" class="dever-manage">' . $config['manage']['_list']['name'] . '</th>';
  1690. }
  1691. }
  1692. }
  1693. }
  1694. return $result;
  1695. }
  1696. # layui表头
  1697. /*
  1698. public function list_thead_layui()
  1699. {
  1700. $html = 'config.table = {};config.table.cols = [];';
  1701. $data = $this->list_thead('layui');
  1702. if ($data) {
  1703. $data = array($data);
  1704. $data = Dever::json_encode($data);
  1705. $html .= 'config.table.cols = ' . $data;
  1706. return $html;
  1707. } else {
  1708. $html .= 'config.table.cols = []';
  1709. return $html;
  1710. }
  1711. }
  1712. # layui表的数据 没有使用其异步方式
  1713. public function list_tbody_layui()
  1714. {
  1715. $html = 'config.table.data = [];';
  1716. $data = $this->list_tbody(false, 'layui');
  1717. $data = Dever::json_encode($data);
  1718. $html .= 'config.table.data = ' . $data;
  1719. return $html;
  1720. }
  1721. */
  1722. /**
  1723. * 导出列表
  1724. *
  1725. * @return array
  1726. */
  1727. public function list_excel_api()
  1728. {
  1729. Dever::$global['base']['excel'] = 1;
  1730. $this->list_search();
  1731. $data = $this->list_tbody(true);
  1732. if ($data) {
  1733. $config = $this->config();
  1734. if (isset($config['manage']['excel']) && $config['manage']['excel']) {
  1735. $method = 'excel';
  1736. $info = $this->info();
  1737. $load = Dever::input('excel_load');
  1738. if ($load) {
  1739. return Dever::load($load, $data);
  1740. } elseif (is_string($config['manage']['excel']) && strstr($config['manage']['excel'], '.')) {
  1741. return Dever::load($config['manage']['excel'], $data);
  1742. } else {
  1743. $data = $this->getAdminInfo($data);
  1744. return $this->excel($info, $data, $config);
  1745. }
  1746. }
  1747. } else {
  1748. Dever::alert('无导出数据');
  1749. }
  1750. //print_r($data);die;
  1751. }
  1752. private function excel($info, $data, $config)
  1753. {
  1754. $file = Dever::input('excel_name');
  1755. if (!$file) {
  1756. $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
  1757. }
  1758. $header = $body = array();
  1759. $i = 0;
  1760. foreach ($config['struct'] as $k => $v) {
  1761. if (isset($v['list']) && $v['list']) {
  1762. # 处理权限
  1763. if (isset($v['auth'])) {
  1764. $auth = $this->value($v['auth'], $data);
  1765. if (!$auth) {
  1766. continue;
  1767. }
  1768. }
  1769. //$v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
  1770. if (isset($v['list_name']) && $v['list_name']) {
  1771. $v['name'] = $v['list_name'];
  1772. }
  1773. $header[$i] = $v['name'];
  1774. $j = 0;
  1775. foreach ($data as $ki => $vi) {
  1776. if (is_array($vi)) {
  1777. $body[$j][$i] = '';
  1778. //if (isset($vi[$k])) {
  1779. # 处理同步
  1780. if (isset($v['sync']) && strpos($k, '-')) {
  1781. $temp = explode('-', $k);
  1782. if ($vi[$v['sync'][0]] > 0) {
  1783. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $v['sync'][1] => $vi[$v['sync'][0]]));
  1784. } else {
  1785. $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]]));
  1786. }
  1787. if (isset($temp[2])) {
  1788. $data[$ki][$k] = $vi[$k] = isset($load[$temp[2]]) ? $load[$temp[2]] : $v['default'];
  1789. }
  1790. }
  1791. if (true) {
  1792. $value = $vi[$k];
  1793. if (is_string($v['list'])) {
  1794. $value = $this->value($v['list'], $data[$ki], $config['struct']);
  1795. }
  1796. if (isset($v['option'])) {
  1797. $value = $this->getOptionValue($value, $v);
  1798. }
  1799. //$value = mb_convert_encoding($value,'gb2312','utf-8');
  1800. $body[$j][$i] = $value;
  1801. $j++;
  1802. }
  1803. }
  1804. }
  1805. $i++;
  1806. }
  1807. }
  1808. return Dever::excelExport($body, $header, $file);
  1809. }
  1810. private function getOptionValue($value, $v)
  1811. {
  1812. # 验证option是否是匿名函数
  1813. $v['option'] = $this->option($v['option']);
  1814. # 位运算
  1815. if (isset($v['bit'])) {
  1816. $ts = array();
  1817. foreach ($v['option'] as $tm => $tv) {
  1818. if (isset($v['bit'][$tm]) && ($value & $tm) > 0) {
  1819. $ts[] = $tv;
  1820. }
  1821. }
  1822. $value = implode(',', $ts);
  1823. }
  1824. if ((isset($v['child_name']) || (isset($v['show']) && is_string($v['show'])))) {
  1825. if (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1826. $value = $v['option'][$value]['name'];
  1827. } else {
  1828. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1829. }
  1830. } else {
  1831. if (strstr($value, ',')) {
  1832. $temp = explode(',', $value);
  1833. $t = array();
  1834. foreach ($temp as $vv) {
  1835. if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
  1836. $t[] = $v['option'][$vv]['name'];
  1837. } elseif(isset($v['option'][$vv])) {
  1838. $t[] = $v['option'][$vv];
  1839. } else {
  1840. $t[] = $vv;
  1841. }
  1842. }
  1843. $value = implode("\r\n", $t);
  1844. } elseif (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1845. $value = $v['option'][$value]['name'];
  1846. } else {
  1847. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1848. }
  1849. }
  1850. return $value;
  1851. }
  1852. private function _getChr($start, $num)
  1853. {
  1854. $num = $start + $num;
  1855. $max = floor($num / 91);
  1856. if ($max > 0) {
  1857. $num = $num - (91 * $max) + $start;
  1858. $num = chr($start) . chr($num);
  1859. } else {
  1860. $num = chr($num);
  1861. }
  1862. return $num;
  1863. }
  1864. /**
  1865. * 列表页数据列表 检索
  1866. *
  1867. * @return array
  1868. */
  1869. private function list_tbody_search($config, $param, $high, $search)
  1870. {
  1871. # 根据api的数据检索到id
  1872. $api = Dever::preInput('search_api_');
  1873. if ($api) {
  1874. foreach ($api as $k => $v) {
  1875. if ($v) {
  1876. unset($search[$k]);
  1877. $k = str_replace('search_api_', '', $k);
  1878. # 设定检索高亮
  1879. $high[$k] = $v;
  1880. if (isset($config['manage']['search']['api'][$k]['api'])) {
  1881. $col = $config['manage']['search']['api'][$k]['col'];
  1882. $v = ltrim($v);
  1883. $v = rtrim($v);
  1884. if ($v == 'no') {
  1885. $param['option_no'] = $config['manage']['search']['api'][$k]['no'];
  1886. } else {
  1887. $option = array($col => $v);
  1888. $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
  1889. $result = $config['manage']['search']['api'][$k]['result'];
  1890. if ($v && is_array($v)) {
  1891. if (isset($v[$result])) {
  1892. $v = $v[$result];
  1893. } else {
  1894. if ($result == 'id') {
  1895. $v = array_keys($v);
  1896. } else {
  1897. $t = array();
  1898. foreach ($v as $k1 => $v1) {
  1899. $t[] = $v1[$result];
  1900. }
  1901. $v = $t;
  1902. }
  1903. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1904. $param['option'][$config['manage']['search']['api'][$k]['search']] = array('yes', 'in');
  1905. } else {
  1906. $param['option'][$k] = array('yes', 'in');
  1907. }
  1908. }
  1909. } else {
  1910. $v = '-100';
  1911. }
  1912. }
  1913. }
  1914. if (!isset($param['option_no'])) {
  1915. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1916. $param['option_' . $config['manage']['search']['api'][$k]['search']] = $v;
  1917. } else {
  1918. $param['option_' . $k] = $v;
  1919. }
  1920. }
  1921. }
  1922. }
  1923. }
  1924. # 检索有无值
  1925. $exist = Dever::preInput('search_exist_');
  1926. if ($exist) {
  1927. foreach ($exist as $k => $v) {
  1928. if ($v) {
  1929. unset($search[$k]);
  1930. $k = str_replace('search_exist_', '', $k);
  1931. if ($v == 'yes') {
  1932. # 有值
  1933. $param['option'][$k] = array('yes', '!=');
  1934. $param['option_' . $k] = 'null';
  1935. } elseif ($v == 'no') {
  1936. # 无值
  1937. $param['option'][$k] = array('yes', '=');
  1938. $param['option_' . $k] = 'null';
  1939. } elseif (strpos($v, '|')) {
  1940. # 有无值或者自定义的值
  1941. $temp = explode('|', $v);
  1942. $param['option_' . $k] = $temp[1];
  1943. if ($temp[0] == 'yes') {
  1944. $param['option'][$k] = array('yes', '!=');
  1945. $param['option'][$k . '_t1'] = array('yes-' . $k, '!=');
  1946. } else {
  1947. $param['option'][$k] = array('yes', '=', 'and(');
  1948. $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
  1949. }
  1950. $param['option_' . $k . '_t1'] = 'null';
  1951. } else {
  1952. # 自定义的值
  1953. $param['option_' . $k] = $v;
  1954. }
  1955. }
  1956. }
  1957. }
  1958. # 检索in
  1959. $in = Dever::preInput('search_in_');
  1960. if ($in) {
  1961. $in_state = false;
  1962. foreach ($in as $k => $v) {
  1963. if ($v) {
  1964. unset($search[$k]);
  1965. $k = str_replace('search_in_', '', $k);
  1966. $param['option'][$k] = array('yes', 'in');
  1967. $param['option_' . $k] = $v;
  1968. # 设定检索高亮
  1969. //$high[$k] = $v;
  1970. $in_state = true;
  1971. }
  1972. }
  1973. $this->search = true;
  1974. }
  1975. $fulltext = Dever::preInput('search_fulltext_');
  1976. if ($fulltext) {
  1977. $fulltext_state = false;
  1978. foreach ($fulltext as $k => $v) {
  1979. if ($v) {
  1980. unset($search[$k]);
  1981. $k = str_replace('search_fulltext_', '', $k);
  1982. $param['option_' . $k] = $v;
  1983. # 设定检索高亮
  1984. $high[$k] = $v;
  1985. $fulltext_state = true;
  1986. }
  1987. }
  1988. $this->search = true;
  1989. }
  1990. $linkage = Dever::preInput('search_linkage_');
  1991. if ($linkage) {
  1992. foreach ($linkage as $k => $v) {
  1993. if ($v && $v != -1) {
  1994. unset($search[$k]);
  1995. $k = str_replace('search_linkage_', '', $k);
  1996. if (isset($config['struct'][$k]['search_col'])) {
  1997. $temp = explode(',', $config['struct'][$k]['search_col']);
  1998. if (!is_array($v)) {
  1999. $v = explode(',', $v);
  2000. }
  2001. foreach ($temp as $k1 => $v1) {
  2002. if (isset($v[$k1]) && $v[$k1] != -1) {
  2003. $param['option_' . $v1] = $v[$k1];
  2004. }
  2005. }
  2006. } else {
  2007. if (is_array($v)) {
  2008. $v = implode(',', $v);
  2009. }
  2010. if ($v != -1) {
  2011. $v = Dever::defaultValue($v);
  2012. $param['option_' . $k] = $v;
  2013. # 设定检索高亮
  2014. $high[$k] = $v;
  2015. }
  2016. }
  2017. }
  2018. }
  2019. $this->search = true;
  2020. }
  2021. $exp = Dever::preInput('search_exp_');
  2022. if ($exp) {
  2023. $k = $search['search_exp_col'];
  2024. $v = $search['search_exp_value'];
  2025. $param['option_' . $k] = $v;
  2026. $param['search_type'] = $search['search_exp_type'];
  2027. $this->search = true;
  2028. }
  2029. $order = Dever::preInput('search_order_');
  2030. if ($order) {
  2031. foreach ($order as $k => $v) {
  2032. $k = str_replace('search_order_', '', $k);
  2033. $param['order'][0][$k] = $v;
  2034. unset($search[$k]);
  2035. }
  2036. }
  2037. foreach ($search as $k => $v) {
  2038. if ($v) {
  2039. if (strpos($k, '-') !== false) {
  2040. $k = str_replace('search_option_', '', $k);
  2041. $temp = explode('-', $k);
  2042. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  2043. }
  2044. $sync = $config['struct'][$k];
  2045. if ($v[$vi['sync'][0]] > 0) {
  2046. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  2047. } else {
  2048. $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
  2049. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
  2050. }
  2051. if (isset($temp[2])) {
  2052. $data[$k][$ki] = $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
  2053. }
  2054. } elseif (strpos($k, 'dever_') !== false) {
  2055. continue;
  2056. } elseif (strpos($k, 'option_') !== false) {
  2057. //Dever::setInput(str_replace('search_', '', $k), $v);
  2058. if (is_array($v)) {
  2059. if ($v[0] == 0) {
  2060. continue;
  2061. }
  2062. $v = str_replace(',0', '', implode(',', $v));
  2063. $t = explode(',', $v);
  2064. $parent = end($t);
  2065. $v .= '%';
  2066. }
  2067. $param[str_replace('search_', '', $k)] = $v;
  2068. $this->search = true;
  2069. } elseif ($k == 'search_limit') {
  2070. $num = $this->getNumConfig($config);
  2071. if ($num) {
  2072. $param['page'][0] = $num[$v];
  2073. }
  2074. }
  2075. }
  2076. }
  2077. return array($param, $high);
  2078. }
  2079. private function list_tbody_mul($send)
  2080. {
  2081. $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
  2082. if (Dever::input('method') == 'mul' && $mul && $mul['mul_type'] > 0) {
  2083. if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
  2084. Dever::alert('您还未选择任何数据条目');
  2085. }
  2086. Dever::config('base')->mul_type = $mul['mul_type'];
  2087. /*
  2088. if (isset($param['page'])) {
  2089. unset($param['page']);
  2090. }
  2091. */
  2092. unset($mul['mul_type']);
  2093. $param = array();
  2094. foreach ($mul as $k => $v) {
  2095. if ($v) {
  2096. if (is_array($v)) {
  2097. $v = implode(',', $v);
  2098. }
  2099. $param[str_replace('mul_', '', $k)] = $v;
  2100. }
  2101. }
  2102. if (isset($param)) {
  2103. $method = $this->project . '/' . $this->table . '-updatemul';
  2104. $state = Dever::load($method, $param);
  2105. }
  2106. Dever::alert('reload');
  2107. }
  2108. }
  2109. /**
  2110. * 列表页数据列表:图片形式
  2111. *
  2112. * @return array
  2113. */
  2114. public function list_photo()
  2115. {
  2116. $config = $this->config();
  2117. $result = array();
  2118. if (isset($config['manage']['photo'])) {
  2119. $high = array();
  2120. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  2121. $param = array();
  2122. $parent = 0;
  2123. if ($search) {
  2124. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  2125. }
  2126. if (empty($param['page'])) {
  2127. $num = $this->getNumConfig($config);
  2128. if ($num) {
  2129. $param['page'][0] = $num[0];
  2130. }
  2131. }
  2132. $method = $this->project . '/' . $this->table . '-list';
  2133. $result = Dever::load($method, $param);
  2134. if ($result) {
  2135. foreach ($result as $k => $v) {
  2136. $result[$k] = Dever::load($config['manage']['photo'], $v);
  2137. $result[$k]['button'] = $this->list_tbody_button($config, $v, 'div');
  2138. }
  2139. }
  2140. }
  2141. return $result;
  2142. }
  2143. /**
  2144. * 列表页数据列表:表格形式
  2145. *
  2146. * @return array
  2147. */
  2148. public function list_tbody($excel = false, $type = false)
  2149. {
  2150. $this->state = false;
  2151. # 新增权限
  2152. if (Dever::load('manage/auth.oper', 1) == false) {
  2153. Dever::alert('你没有权限');
  2154. }
  2155. if (Dever::input('page_content') == 1) {
  2156. return '';
  2157. }
  2158. $config = $this->config();
  2159. $high = array();
  2160. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  2161. $param = array();
  2162. $parent = 0;
  2163. if ($search) {
  2164. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  2165. }
  2166. $num = $this->getNumConfig($config);
  2167. if (empty($param['page']) && $num) {
  2168. $param['page'][0] = $num[0];
  2169. }
  2170. # 批量更新
  2171. $this->list_tbody_mul($param);
  2172. $result = $return = array();
  2173. if (isset($config['top_option']) && $config['top_option']) {
  2174. if (isset($config['top_option'][0])) {
  2175. foreach ($config['top_option'] as $k => $v) {
  2176. $param['option'][$v['col']] = array($v['value'], 'in');
  2177. }
  2178. } else {
  2179. $param['option'][$config['top_option']['col']] = array($config['top_option']['value'], 'in');
  2180. }
  2181. }
  2182. if ($excel == true) {
  2183. $method = $this->project . '/' . $this->table . '-list';//all
  2184. } else {
  2185. $method = $this->project . '/' . $this->table . '-list';
  2186. }
  2187. //print_r($param);
  2188. $data = Dever::load($method, $param);
  2189. //print_r(Dever::sql());die;
  2190. if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
  2191. $parent = array();
  2192. $child = array();
  2193. foreach ($data as $k => $v) {
  2194. if ($v[$config['name'] . '_id'] <= 0) {
  2195. $parent[$k] = $v;
  2196. } else {
  2197. $v['name'] = '|-----' . $v['name'];
  2198. $child[$v[$config['name'] . '_id']][$k] = $v;
  2199. }
  2200. }
  2201. if ($parent) {
  2202. $data = array();
  2203. foreach ($parent as $k => $v) {
  2204. $data[$v['id']] = $v;
  2205. if (isset($child[$v['id']])) {
  2206. foreach ($child[$v['id']] as $i => $j) {
  2207. $data[$j['id']] = $j;
  2208. }
  2209. }
  2210. }
  2211. }
  2212. } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
  2213. $data = $this->tree($data, $config, -1);
  2214. }
  2215. if ($excel == true) {
  2216. return $data;
  2217. }
  2218. if (Dever::input('page_type') == 1) {
  2219. Dever::$global['manage']['list_data'] = $data;
  2220. return;
  2221. }
  2222. //print_r($data);die;
  2223. //print_r(Helper::page("current"));die;
  2224. $this->manage_button = false;
  2225. if ($data && isset($config['struct'])) {
  2226. $i = 0;
  2227. $pg = Dever::input('pg', 1);
  2228. $cur = Dever::input('search_limit', 0);
  2229. foreach ($data as $k => $v) {
  2230. $data[$k] = $this->getAdminInfo($data[$k]);
  2231. $data[$k]['i'] = $i;
  2232. $ii = isset($num[$cur]) ? intval($num[$cur])*($pg-1) : 0;
  2233. $data[$k]['r'] = $i+1+$ii;
  2234. $result[$k] = '<tr>';
  2235. $return[$i] = array();
  2236. if (isset($config['manage']['mul']) && $config['manage']['mul']) {
  2237. $mul_state = false;
  2238. if ($config['manage']['mul'] && is_string($config['manage']['mul'])) {
  2239. $mul_state = $this->value($config['manage']['mul'], $data[$k]);
  2240. } else {
  2241. $mul_state = true;
  2242. }
  2243. if ($mul_state) {
  2244. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="' . $v['id'] . '"/>';
  2245. } else {
  2246. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="-1" disabled/>';
  2247. }
  2248. $result[$k] .= '<td>'.$checkbox.'</td>';
  2249. $return[$i]['checkbox'] = $checkbox;
  2250. }
  2251. foreach ($config['struct'] as $ki => $vi) {
  2252. # 处理同步
  2253. if (isset($vi['sync']) && strpos($ki, '-')) {
  2254. $temp = explode('-', $ki);
  2255. if ($v[$vi['sync'][0]] > 0) {
  2256. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  2257. } else {
  2258. $lw = array('option_' . $vi['sync'][3] => $v[$vi['sync'][2]], 'option_' . $vi['sync'][4] => $v[$vi['sync'][0]]);
  2259. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', $lw);
  2260. }
  2261. if (isset($temp[2])) {
  2262. $data[$k][$ki] = $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
  2263. }
  2264. }
  2265. if (isset($vi['list']) && $vi['list']) {
  2266. if (empty($v[$ki])) {
  2267. $v[$ki] = isset($vi['default']) ? $vi['default'] : '';
  2268. }
  2269. # 处理权限
  2270. if (isset($vi['auth'])) {
  2271. $auth = $this->value($vi['auth'], $data[$k]);
  2272. if (!$auth) {
  2273. continue;
  2274. }
  2275. }
  2276. $show = $v[$ki];
  2277. if (is_string($vi['list'])) {
  2278. $show = $this->value($vi['list'], $data[$k], $config['struct']);
  2279. }
  2280. if (isset($vi['key']) && $vi['update'] != 'editor') {
  2281. $show = Dever::upload($show);
  2282. }
  2283. if (isset($vi['modal'])) {
  2284. $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
  2285. } elseif (isset($vi['option']) && !is_string($vi['list'])) {
  2286. # 验证option是否是匿名函数
  2287. if ((isset($vi['edit']) && $vi['edit'])) {
  2288. $vi['option'] = $this->option($vi['option'], $vi['edit']);
  2289. } else {
  2290. $vi['option'] = $this->option($vi['option']);
  2291. }
  2292. # 位运算
  2293. if (isset($vi['bit'])) {
  2294. $ts = array();
  2295. foreach ($vi['option'] as $tm => $tv) {
  2296. if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
  2297. $ts[] = $tv;
  2298. }
  2299. }
  2300. $show = implode(',', $ts);
  2301. }
  2302. if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
  2303. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2304. $show = $vi['option'][$show]['name'];
  2305. } else {
  2306. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2307. }
  2308. }
  2309. //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
  2310. elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
  2311. {
  2312. $vi['name'] = 'up_col_' . $ki;
  2313. $vi['value'] = $v[$ki];
  2314. $m = 'select';
  2315. if (isset($vi['update']) && $vi['update'] == 'group') {
  2316. $m = 'group';
  2317. }
  2318. $show_edit = $this->value($vi['edit'], $data[$k], $config['struct']);
  2319. if ($show_edit) {
  2320. $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 . '\')"');
  2321. } else {
  2322. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2323. $show = $vi['option'][$show]['name'];
  2324. } else {
  2325. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2326. }
  2327. $show = '';
  2328. }
  2329. } else {
  2330. if (strstr($show, ',')) {
  2331. $temp = explode(',', $show);
  2332. $t = array();
  2333. foreach ($temp as $vv) {
  2334. if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
  2335. $t[] = $vi['option'][$vv]['name'];
  2336. } elseif(isset($vi['option'][$vv])) {
  2337. $t[] = $vi['option'][$vv];
  2338. } else {
  2339. $t[] = $vv;
  2340. }
  2341. }
  2342. $show = implode('<br />', $t);
  2343. } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  2344. if (isset($vi['option'][$show]['style'])) {
  2345. $vi['option'][$show]['name'] = '<font style="'.$vi['option'][$show]['style'].'">' . $vi['option'][$show]['name'] . '</font>';
  2346. }
  2347. $show = $vi['option'][$show]['name'];
  2348. } else {
  2349. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  2350. }
  2351. }
  2352. }
  2353. $text = $show;
  2354. if ($high && isset($high[$ki])) {
  2355. if (isset($v['s_' . $ki])) {
  2356. $text = $v['s_' . $ki];
  2357. $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
  2358. $text = str_replace('</em>', '</font>', $text);
  2359. } elseif (strlen($high[$ki]) > 1) {
  2360. $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text, 1);
  2361. }
  2362. }
  2363. if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
  2364. //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
  2365. $url = $this->url('updateAction');
  2366. $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
  2367. $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>';
  2368. $result[$k] .= '<td >' . $text . '</td>';
  2369. if (isset($return[$i][$ki])) {
  2370. $text = $return[$i][$ki] . $text;
  2371. }
  2372. $return[$i][$ki] = $text;
  2373. } else {
  2374. $result[$k] .= '<td>' . $text . '</td>';
  2375. if (isset($return[$i][$ki])) {
  2376. $text = $return[$i][$ki] . $text;
  2377. }
  2378. $return[$i][$ki] = $text;
  2379. }
  2380. if (isset($config['manage']['chart'])) {
  2381. $this->chart($config['manage']['chart'], $ki, $return[$i][$ki], $vi);
  2382. }
  2383. }
  2384. }
  2385. $button = $this->list_tbody_button($config, $data[$k]);
  2386. if ($button == '<td></td>') {
  2387. $button = str_replace('<td></td>', '<td>&nbsp;</td>', $button);
  2388. }
  2389. $result[$k] .= $button;
  2390. $return[$i]['manage'] = str_replace(array('<td>', '</td>'), '', $button);
  2391. $result[$k] .= '</tr>';
  2392. $i++;
  2393. }
  2394. }
  2395. if ($result) {
  2396. $this->state = true;
  2397. $result = implode('', $result);
  2398. if (!$this->manage_button) {
  2399. $result = str_replace('<td>&nbsp;</td>', '', $result);
  2400. }
  2401. } else {
  2402. $result = '';
  2403. }
  2404. if ($type) {
  2405. return $return;
  2406. }
  2407. return $result;
  2408. }
  2409. private function list_tbody_button($config, $data, $type = 'td')
  2410. {
  2411. $result = '';
  2412. $auth = Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false;
  2413. if (isset($config['manage']['_list']['value']['list']) && isset($config['manage']['_list']['value']['list'][0]) && $config['manage']['_list']['value']['list'][0] == '查看详情') {
  2414. $auth = true;
  2415. }
  2416. if ($auth && isset($config['manage']['_list']['value'])) {
  2417. //if (isset($config['manage']['_list']['value'])) {
  2418. $result = '<'.$type.'>';
  2419. if ($config['state'] == 2) {
  2420. if (isset($config['manage']['_list']['value']['update'])) {
  2421. unset($config['manage']['_list']['value']['update']);
  2422. }
  2423. if (isset($config['manage']['_list']['value']['delete'])) {
  2424. $config['manage']['_list']['value']['delete'] = '恢复';
  2425. }
  2426. }
  2427. foreach ($config['manage']['_list']['value'] as $kj => $vj) {
  2428. $pj = false;
  2429. $h = '<span class="am-icon-pencil-square-o"></span>';
  2430. if (strstr($kj, 'new') || strstr($kj, 'location') || strstr($kj, 'list')) {
  2431. $oper = true;
  2432. } elseif ($kj == 'delete') {
  2433. $oper = Dever::load('manage/auth.oper', 5);
  2434. $h = '<span class="am-icon-trash-o"></span>';
  2435. } else {
  2436. $oper = Dever::load('manage/auth.oper', 3);
  2437. }
  2438. if (is_array($vj) && isset($vj[1])) {
  2439. if (isset($vj[2])) {
  2440. $oper = $this->value($vj[2], $data);
  2441. }
  2442. if ($oper && strpos($vj[1], 'modal|') === false) {
  2443. $pj = $this->value($vj[1], $data);
  2444. $vjn = $vj[0];
  2445. }
  2446. } else {
  2447. $vjn = $vj;
  2448. }
  2449. if ($oper == true) {
  2450. $this->manage_button = true;
  2451. if ($kj == 'delete') {
  2452. $class = 'layui-btn layui-btn-danger';
  2453. } else {
  2454. $class = 'layui-btn';
  2455. }
  2456. if (layadmin()) {
  2457. $class .= ' layui-btn-xs';
  2458. }
  2459. if (strpos($kj, 'fast_list') !== false) {
  2460. if (!isset($vj[3])) {
  2461. $vj[3] = '';
  2462. }
  2463. $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;';
  2464. } elseif (strpos($kj, 'fast_add') !== false) {
  2465. if (!isset($vj[3])) {
  2466. $vj[3] = '';
  2467. }
  2468. $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;';
  2469. } elseif (strpos($kj, 'fast') !== false) {
  2470. if (!isset($vj[3])) {
  2471. $vj[3] = '';
  2472. }
  2473. $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;';
  2474. } elseif (strpos($kj, 'edits') !== false) {
  2475. if (!isset($vj[1])) {
  2476. $vj[1] = '';
  2477. }
  2478. $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;';
  2479. } elseif (strpos($kj, 'copy') !== false) {
  2480. $vj[1] = $this->value($vj[1], $data);
  2481. $vj[1] = Dever::load($vj[1]);
  2482. $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;';
  2483. } elseif (strpos($kj, 'edit') !== false) {
  2484. if (!isset($vj[1])) {
  2485. $vj[1] = '';
  2486. }
  2487. if (strstr($vj[1], 'http')) {
  2488. $url = $vj[1] . '&id=' . $data['id'];
  2489. } else {
  2490. $url = $this->url($kj, $data['id']);
  2491. }
  2492. $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;';
  2493. } elseif (strpos($kj, 'location') !== false) {
  2494. if (!isset($vj[1])) {
  2495. $vj[1] = '';
  2496. }
  2497. if (strstr($vj[1], 'http')) {
  2498. $url = $vj[1] . '&id=' . $data['id'];
  2499. } else {
  2500. $url = $this->url($kj, $data['id']);
  2501. }
  2502. $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;';
  2503. } elseif (strpos($kj, 'oper') !== false) {
  2504. $content = '';
  2505. $title = '';
  2506. if (isset($vj[3])) {
  2507. $content = $this->value($vj[3], $data);
  2508. }
  2509. if (isset($vj[4])) {
  2510. $title = $vj[4];
  2511. }
  2512. $url = Dever::url($pj) . '&manage_log=update.' . $this->project . '.' . $this->table . '&manage_oper=' . $vj[0];
  2513. $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;';
  2514. } elseif (strpos($kj, 'new') !== false) {
  2515. if (!isset($vj[1])) {
  2516. $vj[1] = '';
  2517. }
  2518. if (!isset($vj[2])) {
  2519. $vj[2] = '';
  2520. }
  2521. if (strstr($vj[1], 'http')) {
  2522. $url = $vj[1] . '&id=' . $data['id'];
  2523. } elseif($vj[2]) {
  2524. $url = Dever::url($this->value($vj[1], $data), $vj[2]);
  2525. } else {
  2526. $url = $this->url($kj, $data['id']);
  2527. }
  2528. $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;';
  2529. } elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
  2530. $t = explode('|', $vj[1]);
  2531. $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;';
  2532. } elseif (isset($vj[1])) {
  2533. $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;';
  2534. } else {
  2535. $result .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
  2536. }
  2537. }
  2538. }
  2539. $result .= '</'.$type.'>';
  2540. }
  2541. return $result;
  2542. }
  2543. /**
  2544. * 多级分类
  2545. *
  2546. * @return array
  2547. */
  2548. private function tree($data, $config, $parent = 0)
  2549. {
  2550. $key = $config['name'] . '_id';
  2551. $result = array();
  2552. $this->treeData($data, $result, $key, $parent);
  2553. return $result;
  2554. }
  2555. private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
  2556. {
  2557. if (empty($array)) {
  2558. return;
  2559. }
  2560. $level++;
  2561. foreach ($array as $k => $v) {
  2562. if ((isset($v[$key]) && $v[$key] == $parent_id) || (isset($v['parent_id']) && $v['parent_id'] == $parent_id)) {
  2563. $v['level'] = $level;
  2564. $v['name'] = $this->treeName($v['name'], $level);
  2565. $result[] = $v;
  2566. unset($array[$k]);
  2567. $this->treeData($array, $result, $key, $v['id'], $level);
  2568. }
  2569. }
  2570. }
  2571. private function treeName($name, $level = 1)
  2572. {
  2573. $string = '';
  2574. if ($level > 1) {
  2575. /*
  2576. $num = 4;
  2577. $string = '-';
  2578. //STR_PAD_LEFT
  2579. $string = str_pad('|', $level * $num, $string);
  2580. */
  2581. $string = str_repeat(' ',$level-1);
  2582. $string .= '|—';
  2583. }
  2584. return $string . $name;
  2585. }
  2586. /**
  2587. * 列表页批量管理
  2588. *
  2589. * @return array
  2590. */
  2591. public function list_mul()
  2592. {
  2593. # 新增权限:更新权限
  2594. if (Dever::load('manage/auth.oper', 3) == false) {
  2595. return '';
  2596. }
  2597. $config = $this->config();
  2598. $result = '';
  2599. if ($this->state && isset($config['struct']) && isset($config['manage']['mul']) && $config['manage']['mul']) {
  2600. $mul = Dever::preInput('mul_');
  2601. $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
  2602. $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>';
  2603. $prefix = 'mul_';
  2604. $result .= $node[0];
  2605. $default = 0;
  2606. $option = array
  2607. (
  2608. 1 => '本页选中的数据',
  2609. );
  2610. # 只有当有搜索条件时才会出现
  2611. if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
  2612. //$option[2] = '所有页面的数据';
  2613. //$default = 2;
  2614. }
  2615. $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择要更新的数据', $option, $default);
  2616. foreach ($config['struct'] as $k => $v) {
  2617. if ($k == 'state' && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  2618. $v['option'] = Dever::config('base')->state;
  2619. if ($this->getState() == 2) {
  2620. unset($v['option'][2]);
  2621. } else {
  2622. unset($v['option'][1]);
  2623. }
  2624. $v['edit'] = true;
  2625. }
  2626. $select = false;
  2627. if (isset($v['mul'])) {
  2628. $select = $v['mul'];
  2629. } elseif (isset($v['edit'])) {
  2630. $select = $v['edit'];
  2631. }
  2632. if ($select) {
  2633. if (isset($v['mul_option']) && (is_array($v['mul_option']) || is_object($v['mul_option']))) {
  2634. $result .= '&nbsp;&nbsp;';
  2635. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['mul_option'], $select), $v['default']);
  2636. } elseif (isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
  2637. $result .= '&nbsp;&nbsp;';
  2638. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option'], $select), $v['default']);
  2639. }
  2640. }
  2641. }
  2642. $result .= $btn . $node[1];
  2643. }
  2644. //print_r($result);die;
  2645. return $result;
  2646. }
  2647. private function value($value, $data, $struct = array())
  2648. {
  2649. if (!$data) {
  2650. return $value;
  2651. }
  2652. if (strstr($value, '={') && !strstr($value, '"')) {
  2653. $value = '"' . $value . '"';
  2654. }
  2655. if (is_string($data)) {
  2656. $eval = '$value = ' . $value . ';';
  2657. eval($eval);
  2658. return $value;
  2659. }
  2660. if ($value == 'table' && $struct) {
  2661. $result = $this->struct_data($struct, $data);
  2662. $value = Dever::table($result);
  2663. } elseif (strpos($value, '{') !== false && strpos($value, '{"') === false) {
  2664. # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
  2665. //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
  2666. $func = function ($r) use ($data) {
  2667. if (isset($data[$r[1]])) {
  2668. return $data[$r[1]];
  2669. }
  2670. return false;
  2671. };
  2672. $value = preg_replace_callback('/{(.*?)}/', $func, $value);
  2673. if (strstr($value, '<script>')) {
  2674. $value = str_replace('<script>', '<script>$(document).ready(function(){', $value);
  2675. $value = str_replace('</script>', '});</script>', $value);
  2676. }
  2677. $eval = '$value = ' . $value . ';';
  2678. eval($eval);
  2679. }
  2680. return $value;
  2681. }
  2682. /**
  2683. * update
  2684. *
  2685. * @return array
  2686. */
  2687. public function update()
  2688. {
  2689. $config = $this->config();
  2690. $data = array();
  2691. if ($this->id) {
  2692. # 新增权限
  2693. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2694. $auth = 1;
  2695. } else {
  2696. $auth = 3;
  2697. }
  2698. if (Dever::load('manage/auth.oper', $auth) == false) {
  2699. Dever::alert('你没有权限');
  2700. }
  2701. $data = $this->load('one', $this->id);
  2702. } else {
  2703. # 新增权限
  2704. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2705. $auth = 1;
  2706. } else {
  2707. $auth = 4;
  2708. }
  2709. if (Dever::load('manage/auth.oper', $auth) == false) {
  2710. Dever::alert('你没有权限');
  2711. }
  2712. }
  2713. $data = $this->getAdminInfo($data);
  2714. $col = Dever::input('col');
  2715. $result = $this->update_struct($config, $col, $data);
  2716. //print_r($result);die;
  2717. return $result;
  2718. }
  2719. public function update_content()
  2720. {
  2721. $config = $this->config();
  2722. $data = array();
  2723. if ($this->id) {
  2724. # 新增权限
  2725. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2726. $auth = 1;
  2727. } else {
  2728. $auth = 3;
  2729. }
  2730. if (Dever::load('manage/auth.oper', $auth) == false) {
  2731. Dever::alert('你没有权限');
  2732. }
  2733. $data = $this->load('one', $this->id);
  2734. } else {
  2735. # 新增权限
  2736. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  2737. $auth = 1;
  2738. } else {
  2739. $auth = 4;
  2740. }
  2741. if (Dever::load('manage/auth.oper', $auth) == false) {
  2742. Dever::alert('你没有权限');
  2743. }
  2744. }
  2745. $data = $this->getAdminInfo($data);
  2746. $col = Dever::input('col');
  2747. Dever::setInput('ajax', 1);
  2748. $result = '<div class="layui-col-md12"><div class="layui-card" {style}><div class="layui-card-body">';
  2749. $desc = Dever::load('manage/database.info#updateDesc');
  2750. if ($desc) {
  2751. $result .= $desc;
  2752. }
  2753. if (isset($config['manage']['lang']) && Dever::config('base')->lang_set && count(Dever::config('base')->lang_set) > 1) {
  2754. $result .= '<div class="layui-tab layui-tab-card"><ul class="layui-tab-title">';
  2755. $tab = '<div class="layui-tab-content">';
  2756. $i = 0;
  2757. if ($col) {
  2758. $col = explode(',', $col);
  2759. $config['manage']['lang'] = explode(',', $config['manage']['lang']);
  2760. $config['manage']['lang'] = array_intersect($config['manage']['lang'], $col);
  2761. $config['manage']['lang'] = implode(',', $config['manage']['lang']);
  2762. $col = implode(',', $col);
  2763. }
  2764. foreach (Dever::config('base')->lang_set as $k => $v) {
  2765. if ($i == 0) {
  2766. $prefix = '';
  2767. } else {
  2768. $prefix = $k;
  2769. $col = $config['manage']['lang'];
  2770. //$prefix = 'l-l' . $k . 'l-l';
  2771. //$data = $this->load('one', $this->id, $this->table . '__' . $k);
  2772. }
  2773. if (isset($config['manage']['tab']) && $config['manage']['tab']) {
  2774. $content = '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
  2775. $tab_content = '<div class="layui-tab-content">';
  2776. $j = 0;
  2777. foreach ($config['manage']['tab'] as $k1 => $v1) {
  2778. $html = $this->update_struct($config, $col, $data, $k1, $prefix);
  2779. if ($html) {
  2780. $class_0 = $class_1 = '';
  2781. if ($j == 0) {
  2782. $class_0 = 'layui-this';
  2783. $class_1 = 'layui-show';
  2784. }
  2785. $content .= '<li class="'.$class_0.'">'.$v1.'</li>';
  2786. $tab_content .= '<div class="layui-tab-item '.$class_1.'">'.$html.'</div>';
  2787. $j++;
  2788. }
  2789. }
  2790. $tab_content .= '</div>';
  2791. $content .= '</ul>' . $tab_content . '</div>';
  2792. if ($content) {
  2793. $class_0 = $class_1 = '';
  2794. if ($i == 0) {
  2795. $class_0 = 'layui-this';
  2796. $class_1 = 'layui-show';
  2797. }
  2798. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2799. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2800. $i++;
  2801. }
  2802. } else {
  2803. $content = $this->update_struct($config, $col, $data, -1, $prefix);
  2804. if ($content) {
  2805. $class_0 = $class_1 = '';
  2806. if ($i == 0) {
  2807. $class_0 = 'layui-this';
  2808. $class_1 = 'layui-show';
  2809. }
  2810. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2811. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2812. $i++;
  2813. }
  2814. }
  2815. }
  2816. $tab .= '</div>';
  2817. $result .= '</ul>' . $tab . '</div>';
  2818. } elseif (isset($config['manage']['tab']) && $config['manage']['tab']) {
  2819. $result .= '<div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief"><ul class="layui-tab-title">';
  2820. $tab = '<div class="layui-tab-content">';
  2821. $i = 0;
  2822. foreach ($config['manage']['tab'] as $k => $v) {
  2823. $content = $this->update_struct($config, $col, $data, $k);
  2824. if ($content) {
  2825. $class_0 = $class_1 = '';
  2826. if ($i == 0) {
  2827. $class_0 = 'layui-this';
  2828. $class_1 = 'layui-show';
  2829. }
  2830. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  2831. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  2832. $i++;
  2833. }
  2834. }
  2835. $tab .= '</div>';
  2836. $result .= '</ul>' . $tab . '</div>';
  2837. } else {
  2838. $result .= $this->update_struct($config, $col, $data);
  2839. }
  2840. if (isset($this->card) && $this->card) {
  2841. $result = str_replace('{style}', 'style="display:none"', $result);
  2842. }
  2843. $button = '';
  2844. if (Dever::input('fast') != 1) {
  2845. $button = '<div class="layui-card-body" id="update_button"><div class="layui-form-item">' . $this->update_button() . '</div></div>';
  2846. }
  2847. $result .= '</div>'.$button.'</div></div>';
  2848. //print_r($result);die;
  2849. return $result;
  2850. }
  2851. public function update_struct($config, $col, $data, $tab = -1, $prefix = '', $layadmin = false)
  2852. {
  2853. if (!$layadmin) {
  2854. $layadmin = layadmin();
  2855. }
  2856. $result = array();
  2857. $upload_call = '';
  2858. if (isset($config['manage']['upload'])) {
  2859. $upload_call = $this->value($config['manage']['upload'], $data);
  2860. }
  2861. foreach ($config['struct'] as $k => $v) {
  2862. if (isset($config['manage']['lang']) && isset($v['sync']) && strpos($k, '-')) {
  2863. continue;
  2864. }
  2865. $state = false;
  2866. if ($tab == 0) {
  2867. if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
  2868. $state = true;
  2869. }
  2870. } elseif ($tab > 0) {
  2871. if (isset($v['tab']) && $v['tab'] == $tab) {
  2872. $state = true;
  2873. }
  2874. } else {
  2875. $state = true;
  2876. }
  2877. if (isset($v['update']) && $v['update'] && $state) {
  2878. if ($col && !strstr(',' . $col . ',', ',' . $k . ',')) {
  2879. continue;
  2880. }
  2881. //处理权限
  2882. if (isset($v['auth'])) {
  2883. $auth = $this->value($v['auth'], $data);
  2884. if (!$auth) {
  2885. continue;
  2886. }
  2887. }
  2888. $index = $k;
  2889. if ($prefix && !strstr($k, '-')) {
  2890. $k = $prefix . '_' . $k;
  2891. }
  2892. # 处理show模式下的class
  2893. $class = $this->update_class($k, $v, '', $data);
  2894. $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
  2895. $style = '';
  2896. if ($v['update'] == 'hidden') {
  2897. $style = 'style="display:none"';
  2898. }
  2899. if ($layadmin) {
  2900. $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div classs="layui-col-lg6">';
  2901. if (is_array($v['update'])) {
  2902. $result[$k] = '<div class="layui-form-item ' . $class . '" '.$style.'><div class="layui-tab layui-tab-card">';
  2903. }
  2904. }
  2905. if ($upload_call) {
  2906. $v['upload_call'] = $upload_call . '&key=' . $k;
  2907. }
  2908. $result[$k] .= $this->create_update_html($k, $v, $data, false, $prefix);
  2909. $result[$k] .= '</div></div>';
  2910. } elseif (!$col && isset($v['class'])) {
  2911. # 分割线
  2912. $v['name'] = $this->value($v['name'], array('test' => 1));
  2913. if (isset($v['right'])) {
  2914. $this->card_right = true;
  2915. }
  2916. $this->card = true;
  2917. $result[$k] = Html::hr($v);
  2918. }
  2919. }
  2920. if (Dever::input('ajax') == 1) {
  2921. return implode('', $result);
  2922. }
  2923. return $result;
  2924. }
  2925. public function card()
  2926. {
  2927. if (isset($this->card_right)) {
  2928. return 'layui-col-md6';
  2929. }
  2930. return 'layui-col-md12';
  2931. }
  2932. public function layui_card()
  2933. {
  2934. if (isset($this->card)) {
  2935. return false;
  2936. }
  2937. return true;
  2938. }
  2939. /**
  2940. * update_class
  2941. *
  2942. * @return string
  2943. */
  2944. public function update_class($name, $param, $prefix = '', $data = array())
  2945. {
  2946. $class = '';
  2947. $key = 'show';
  2948. if (isset($param[$key]) && $param[$key]) {
  2949. $parent = array();
  2950. $child = array();
  2951. if (is_string($param[$key])) {
  2952. parse_str($param[$key], $param[$key]);
  2953. }
  2954. if (is_array($param[$key])) {
  2955. foreach ($param[$key] as $k => $v) {
  2956. if ($k == 'no') {
  2957. $child[$k . '_' . $v] = $key . '_no';
  2958. } elseif (strpos($v, '/')) {
  2959. $parent[$k] = $key . '_' . $k;
  2960. $k = $k . '_ajax';
  2961. $value = '';
  2962. if (isset($data[$name])) {
  2963. $value = $data[$name];
  2964. }
  2965. $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
  2966. $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
  2967. } else {
  2968. if (strpos($v, ',')) {
  2969. $temp = explode(',', $v);
  2970. foreach ($temp as $v1) {
  2971. $show = $k . '_' . $v1;
  2972. if ($prefix) {
  2973. $k = str_replace($name, $k, $prefix);
  2974. $show = str_replace($name, $show, $prefix);
  2975. }
  2976. $parent[$k] = $key . '_' . $k;
  2977. $child[$show] = $key . '_' . $show;
  2978. }
  2979. } else {
  2980. $show = $k . '_' . $v;
  2981. if ($prefix) {
  2982. $k = str_replace($name, $k, $prefix);
  2983. $show = str_replace($name, $show, $prefix);
  2984. }
  2985. $parent[$k] = $key . '_' . $k;
  2986. $child[$show] = $key . '_' . $show;
  2987. }
  2988. }
  2989. }
  2990. }
  2991. $class = implode(' ', $parent) . ' ' . implode(' ', $child);
  2992. }
  2993. if (isset($param['control'])) {
  2994. $class .= ' ' . $key . '_input';
  2995. }
  2996. return $class;
  2997. }
  2998. /**
  2999. * update_html
  3000. *
  3001. * @return string
  3002. */
  3003. public function create_update_html($key, $value, $data = array(), $index = false, $prefix = '')
  3004. {
  3005. $result = '';
  3006. $value['ext'] = $value['col'] = $key;
  3007. $value['update'] = $value['update'] ? $value['update'] : 'text';
  3008. if (isset($value['match']) && $value['match'] != 'option') {
  3009. if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
  3010. if (strstr($value['match'], 'option||')) {
  3011. $value['valid'] = 'validate[custom[' . $key . ']]';
  3012. } else {
  3013. $value['valid'] = 'validate[required,custom[' . $key . ']]';
  3014. }
  3015. } else {
  3016. $value['valid'] = 'validate[required]';
  3017. }
  3018. }
  3019. if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
  3020. $value['value'] = $value['update'];
  3021. $value['update'] = 'hidden';
  3022. }
  3023. if (!$index) {
  3024. $index = $key;
  3025. }
  3026. $this->update_html($value, $key, $index, $data, $result, $prefix);
  3027. return $result;
  3028. }
  3029. /**
  3030. * update_html
  3031. *
  3032. * @return string
  3033. */
  3034. public function update_html($param, $key, $index, $data, &$result, $prefix = '')
  3035. {
  3036. if (isset($param['name']) && isset($param['update']) && $param['update'] != 'hidden' && $param['update'] != 'load') {
  3037. $result .= Html::pageLeft($param);
  3038. }
  3039. if ($param['update']) {
  3040. $order = true;
  3041. # 名称带前缀
  3042. $param['name'] = 'update_' . $param['ext'];
  3043. $param['index'] = $index;
  3044. //$param['value'] = '';
  3045. # 得到当前的值
  3046. //if (isset($data[$index]) && !isset($param['value'])) {
  3047. if (isset($data[$index]) && $data[$index]) {
  3048. $param['value'] = $data[$index];
  3049. }
  3050. # 得到下级的值
  3051. if (isset($param['child_value']) && isset($data['id'])) {
  3052. $param['child_value'] = $this->value($param['child_value'], $data);
  3053. }
  3054. # 验证option是否是匿名函数
  3055. if (isset($param['option'])) {
  3056. $param['option'] = $this->option($param['option']);
  3057. }
  3058. if (isset($data[$index]) && !isset($param['value']) && isset($param['key']) && $param['update'] != 'editor') {
  3059. $param['value'] = Dever::upload($data[$index]);
  3060. }
  3061. # 处理下级字段
  3062. if (isset($param['child'])) {
  3063. $param['child'] = $this->option($param['child']);
  3064. if (isset($data[$key . '_parent'])) {
  3065. $param['parent_value'] = $data[$key . '_parent'];
  3066. }
  3067. }
  3068. # 设置默认值
  3069. if (isset($param['default'])) {
  3070. $param['default'] = $this->option($param['default']);
  3071. }
  3072. # 处理同步
  3073. if (isset($param['sync']) && strpos($key, '-') && $param['update'] != 'load') {
  3074. $temp = explode('-', $key);
  3075. if (isset($data[$param['sync'][0]])) {
  3076. if (isset($temp[2])) {
  3077. $m = 'one';
  3078. } else {
  3079. $m = 'select';
  3080. }
  3081. if ($data[$param['sync'][0]] > 0) {
  3082. $load = Dever::load($temp[0] . '/' . $temp[1] . '-' . $m, array('option_' . $param['sync'][1] => $data[$param['sync'][0]], 'order' => array('id' => 'asc')));
  3083. } else {
  3084. $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')));
  3085. }
  3086. if ($m == 'one') {
  3087. $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
  3088. } else {
  3089. $param['value'] = $load;
  3090. }
  3091. }
  3092. if (!isset($temp[2]) && is_array($param['update'])) {
  3093. $order = false;
  3094. if (isset($param['update'][0]) && is_string($param['update'][0]) && strstr($param['update'][0], '.')) {
  3095. if (isset($param['update'][1]) && $param['update'][1]) {
  3096. $param['update_load'] = $param['update'][0];
  3097. $param['update'] = 'load';
  3098. } else {
  3099. $param['update'] = Dever::load($param['update'][0]);
  3100. }
  3101. } else {
  3102. $config = Dever::db($temp[0] . '/' . $temp[1])->config;
  3103. $param['update'] = $config['struct'];
  3104. }
  3105. if (isset($config['manage']['tab'])) {
  3106. $param['prefix'] = $prefix;
  3107. $param['tab'] = $config['manage']['tab'];
  3108. if (isset($config['manage']['tab'])) {
  3109. $param['lang'] = $config['manage']['lang'];
  3110. }
  3111. }
  3112. //$param['value'] = Dever::db($temp[0] . '/' . $temp[1]);
  3113. }
  3114. }
  3115. $method = $param['update'];
  3116. if (is_array($method)) {
  3117. $c = '';
  3118. if (layadmin()) {
  3119. $c = 'layui-tab-title';
  3120. }
  3121. $delete = true;
  3122. if (isset($param['option'])) {
  3123. $delete = false;
  3124. $result .= '<ul class="nav nav-tabs '.$c.'" style="height:100%;">{tab}</ul>';
  3125. $order = array
  3126. (
  3127. 'col' => $key,
  3128. 'name' => $param['desc'],
  3129. 'default' => '1',
  3130. 'desc' => $param['desc'],
  3131. 'match' => 'is_string',
  3132. 'update' => 'hidden',
  3133. 'option' => $param['option']
  3134. );
  3135. array_unshift($method, $order);
  3136. if (isset($param['value']) && $param['value']) {
  3137. $value = Dever::array_decode($param['value']);
  3138. $param['value'] = array();
  3139. foreach ($param['option'] as $k => $v) {
  3140. foreach ($value[$k-1] as $k1 => $v1) {
  3141. $param['value'][$v][$k1] = $v1;
  3142. }
  3143. }
  3144. } else {
  3145. $param['value'] = array();
  3146. foreach ($param['option'] as $k => $v) {
  3147. $param['value'][$v][$key] = $k;
  3148. }
  3149. }
  3150. } else {
  3151. $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>';
  3152. if ($order) {
  3153. $order = array
  3154. (
  3155. 'col' => 'order',
  3156. 'name' => '排序-按照数字正序排列',
  3157. 'default' => '1',
  3158. 'desc' => '排序',
  3159. 'match' => 'is_string',
  3160. 'update' => 'text',
  3161. );
  3162. array_unshift($method, $order);
  3163. }
  3164. }
  3165. $tab = '';
  3166. $this->update_child(array(), $method, $key, $result, -1, $param, $delete);
  3167. if (isset($param['value']) && $param['value']) {
  3168. if (!is_array($param['value'])) {
  3169. $param['value'] = Dever::array_decode($param['value']);
  3170. }
  3171. if (is_array($param['value'])) {
  3172. $i = 0;
  3173. foreach ($param['value'] as $k => $v) {
  3174. $n = $k;
  3175. if (is_string($k)) {
  3176. $k = $i;
  3177. }
  3178. $this->update_child($v, $method, $key, $result, $k, $param, $delete);
  3179. $active = '';
  3180. if ($k == 0) {
  3181. $active = 'active';
  3182. }
  3183. if (layadmin() && $active) {
  3184. $active .= ' layui-this';
  3185. }
  3186. $k = $k + 1;
  3187. if (!is_string($n)) {
  3188. $n = '第' . $k . '条';
  3189. }
  3190. $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>';
  3191. $i++;
  3192. }
  3193. }
  3194. } else {
  3195. $this->update_child(array(), $method, $key, $result, 0, $param, $delete);
  3196. $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>';
  3197. }
  3198. $result = str_replace('{tab}', $tab, $result);
  3199. } else {
  3200. if (isset($param['update_input']) && isset($data[$index . '_input'])) {
  3201. $param['update_input_data'] = explode(',', $data[$index . '_input']);
  3202. }
  3203. $param['project'] = $this->project;
  3204. $param['table'] = $this->table;
  3205. if (isset($param['upload_search'])) {
  3206. $param['upload_search'] = $this->value($param['upload_search'], $data + $param);
  3207. }
  3208. if (isset($param['upload_search_value'])) {
  3209. $param['upload_search_value'] = $this->value($param['upload_search_value'], $data + $param);
  3210. }
  3211. if ($param['update'] == 'load') {
  3212. $param['where_id'] = $this->id;
  3213. }
  3214. $result .= Html::$method($param);
  3215. }
  3216. if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
  3217. $result .= Html::desc($param['desc']);
  3218. }
  3219. }
  3220. }
  3221. /**
  3222. * update_action
  3223. *
  3224. * @return array
  3225. */
  3226. private function update_child($data, $param, $key, &$result, $index, $config, $delete = true)
  3227. {
  3228. if (isset($config['tab']) && $config['tab']) {
  3229. if ($index != 0) {
  3230. $style = 'display:none;';
  3231. } else {
  3232. $style = '';
  3233. }
  3234. $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">';
  3235. $tab = '<div class="layui-tab-content">';
  3236. $i = 0;
  3237. foreach ($config['tab'] as $k => $v) {
  3238. $content = $this->update_child_data($data, $param, $key, $index, $k, $config);
  3239. if ($content) {
  3240. $class_0 = $class_1 = '';
  3241. if ($i == 0) {
  3242. $class_0 = 'layui-this';
  3243. $class_1 = 'layui-show';
  3244. }
  3245. $result .= '<li class="'.$class_0.'">'.$v.'</li>';
  3246. $tab .= '<div class="layui-tab-item '.$class_1.'">'.$content.'</div>';
  3247. $i++;
  3248. }
  3249. }
  3250. $tab .= '</div>';
  3251. $result .= '</ul>' . $tab . '</div>';
  3252. } else {
  3253. $style = 'margin:10px;';
  3254. if ($index != 0) {
  3255. $style = 'display:none;margin:10px;';
  3256. }
  3257. $result .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" style="' . $style . '">';
  3258. if ($delete) {
  3259. $result .= '<div class="dever_form_delete" style="cursor:pointer">[删除]</div>';
  3260. }
  3261. $result .= $content = $this->update_child_data($data, $param, $key, $index, -1, $config);
  3262. $result .= '</div>';
  3263. }
  3264. }
  3265. private function update_child_data($data, $param, $key, $index, $tab = -1, $config = array())
  3266. {
  3267. $result = '';
  3268. foreach ($param as $k => $v) {
  3269. if (is_string($k)) {
  3270. $v['col'] = $k;
  3271. }
  3272. if ($this->id && $v['col'] == 'id') {
  3273. $v['update'] = 'hidden';
  3274. }
  3275. if (!isset($v['update'])) {
  3276. continue;
  3277. }
  3278. if (isset($config['prefix']) && $config['prefix']) {
  3279. if (isset($config['lang']) && $config['lang'] && !in_array($v['col'], $config['lang'])) {
  3280. continue;
  3281. }
  3282. $v['col'] = $config['prefix'] . '_' . $v['col'];
  3283. }
  3284. $state = false;
  3285. if ($tab == 0) {
  3286. if (!isset($v['tab']) || (isset($v['tab']) && $v['tab'] == $tab)) {
  3287. $state = true;
  3288. }
  3289. } elseif ($tab > 0) {
  3290. if (isset($v['tab']) && $v['tab'] == $tab) {
  3291. $state = true;
  3292. }
  3293. } else {
  3294. $state = true;
  3295. }
  3296. if (isset($v['update']) && $v['update'] && $state) {
  3297. $v['type'] = $v['update'];
  3298. $prefix = '';
  3299. if ($index < 0) {
  3300. $v['ext'] = $key . '_c_' . $v['col'];
  3301. $prefix = $v['ext'];
  3302. } else {
  3303. $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
  3304. $prefix = $v['ext'];
  3305. }
  3306. if ($v['col'] == 'order') {
  3307. $v['default'] = $index+1;
  3308. }
  3309. $class = $this->update_class($v['col'], $v, $prefix);
  3310. if ($v['update'] == 'hidden') {
  3311. $result .= '<div class="form-group ' . $class . '">';
  3312. $this->update_html($v, $key, $v['col'], $data, $result);
  3313. $result .= '</div>';
  3314. } else {
  3315. $result .= '<div class="form-group ' . $class . '" style="margin-top:10px">';
  3316. $this->update_html($v, $key, $v['col'], $data, $result);
  3317. $result .= '</div>';
  3318. }
  3319. }
  3320. }
  3321. return $result;
  3322. }
  3323. /**
  3324. * update_action
  3325. *
  3326. * @return array
  3327. */
  3328. public function update_action_api()
  3329. {
  3330. $method = false;
  3331. $config = $this->config();
  3332. $input = Dever::preInput('update_');
  3333. if ($this->id) {
  3334. # 新增权限
  3335. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  3336. $auth = 1;
  3337. } else {
  3338. $auth = 3;
  3339. }
  3340. if (Dever::load('manage/auth.oper', $auth) == false) {
  3341. Dever::alert('你没有权限');
  3342. }
  3343. Dever::setInput('where_id', $this->id);
  3344. //Dever::setInput('update_where_id', $this->id);
  3345. $info = $this->load('one', $this->id);
  3346. if ($info) {
  3347. $method = 'update';
  3348. $col = Dever::input('col');
  3349. $value = Dever::input('value');
  3350. if ($col && $value) {
  3351. $method = 'update_' . $col;
  3352. //Dever::setInput('set_' . $col, $value);
  3353. //Dever::setInput('update_' . $col, $value);
  3354. $param['where_id'] = $this->id;
  3355. $param['set_' . $col] = $value;
  3356. $this->load($method, $param);
  3357. $struct = $this->struct_data($config['struct'], array($col => $value));
  3358. Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $this->id);
  3359. Dever::out('yes');
  3360. return;
  3361. }
  3362. $prefix = 'set';
  3363. } else {
  3364. $method = 'insert';
  3365. $prefix = 'add';
  3366. }
  3367. }
  3368. if (!$method) {
  3369. # 新增权限
  3370. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  3371. $auth = 1;
  3372. } else {
  3373. $auth = 4;
  3374. }
  3375. if (Dever::load('manage/auth.oper', $auth) == false) {
  3376. Dever::alert('你没有权限');
  3377. }
  3378. $method = 'insert';
  3379. $prefix = 'add';
  3380. }
  3381. if ($method && $input) {
  3382. $update = $order = $update_other = array();
  3383. $i = 0;
  3384. $c = array();
  3385. foreach ($input as $k => $v) {
  3386. if ($v === '') {
  3387. $v = 'null';
  3388. }
  3389. if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
  3390. $temp = str_replace('copy.', '', $v);
  3391. if (isset($input['update_' . $temp])) {
  3392. $v = $input['update_' . $temp];
  3393. }
  3394. }
  3395. if (strpos($k, '_c_') !== false) {
  3396. if ($v == 'null') {
  3397. $v = '';
  3398. }
  3399. $temp = explode('_c_', $k);
  3400. $h = $temp[0];
  3401. $k = str_replace('update_', $prefix . '_', $h);
  3402. if (!isset($c[$k])) {
  3403. $c[$k] = array();
  3404. }
  3405. if (strpos($temp[1], '_i_') !== false) {
  3406. $temp = explode('_i_', $temp[1]);
  3407. if (!isset($c[$k][$temp[1]])) {
  3408. $c[$k][$temp[1]] = 0;
  3409. } else {
  3410. $c[$k][$temp[1]]++;
  3411. }
  3412. $num = $c[$k][$temp[1]];
  3413. if (strpos($h, '-')) {
  3414. $h = str_replace('update_', '', $h);
  3415. if (isset($config['struct'][$h]) && isset($config['struct'][$h]['sync'])) {
  3416. $s_col = $config['struct'][$h]['sync'][0];
  3417. $m_col = $config['struct'][$h]['sync'][1];
  3418. if ($s_col == 'id') {
  3419. $s_value = $this->id;
  3420. } else {
  3421. $s_one = $this->load('one', $this->id);
  3422. $s_value = $s_one[$s_col];
  3423. }
  3424. $t = explode('-', $h);
  3425. $index = $t[0] . '/' . $t[1];
  3426. $update_col[$i][$index] = $m_col;
  3427. $update_set[$i][$index][$num]['set_' . $temp[1]] = $v;
  3428. $update_add[$i][$index][$num]['add_' . $temp[1]] = $v;
  3429. $update_add[$i][$index][$num]['add_' . $m_col] = $s_value;
  3430. $update_id[$i][$index][$num][$m_col] = $s_value;
  3431. if ($this->id && $temp[1] == 'id') {
  3432. $update_id[$i][$index][$num]['id'] = $v;
  3433. }
  3434. }
  3435. } else {
  3436. $update[$i][$k][$num][$temp[1]] = $v;
  3437. if ($temp[1] == 'order') {
  3438. $order[$i][$k][$num] = $v;
  3439. }
  3440. }
  3441. } else {
  3442. //$update[$i][$k][$c][$temp[1]] = $v;
  3443. }
  3444. } elseif (strpos($k, '__') !== false) {
  3445. $temp1 = explode('__', $k);
  3446. $temp2 = explode('_', $temp1[0]);
  3447. $i = $temp2[1] - 1;
  3448. if (strpos($k, 'where_id') !== false) {
  3449. //$update[$i]['where_id'] = $v;
  3450. } else {
  3451. $update[$i]['add_' . $temp1[1]] = $v;
  3452. }
  3453. } else {
  3454. $ki = str_replace('update_', $prefix . '_', $k);
  3455. if (strpos($ki, 'where_id') !== false) {
  3456. if ($method != 'insert') {
  3457. $update[$i]['where_id'] = $v;
  3458. }
  3459. } else {
  3460. if (strpos($k, 'l-l')) {
  3461. $temp = explode('l-l', $k);
  3462. $k = str_replace('_', '', $temp[2]);
  3463. $update_other[$i][$temp[1]][$k] = $v;
  3464. } elseif (strpos($k, '-')) {
  3465. $k = str_replace('update_', '', $k);
  3466. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  3467. $s_col = $config['struct'][$k]['sync'][0];
  3468. $m_col = $config['struct'][$k]['sync'][1];
  3469. if ($s_col == 'id') {
  3470. $s_value = $this->id;
  3471. } else {
  3472. $s_one = $this->load('one', $this->id);
  3473. $s_value = $s_one[$s_col];
  3474. }
  3475. $temp = explode('-', $k);
  3476. $index = $temp[0] . '/' . $temp[1];
  3477. if (isset($temp[2])) {
  3478. $update_col[$i][$index] = $m_col;
  3479. $update_set[$i][$index][0]['set_' . $temp[2]] = $v;
  3480. //$update_set[$i][$index][0]['set_' . $m_col] = $s_value;
  3481. $update_add[$i][$index][0]['add_' . $temp[2]] = $v;
  3482. $update_add[$i][$index][0]['add_' . $m_col] = $s_value;
  3483. $update_id[$i][$index][0][$m_col] = $s_value;
  3484. }
  3485. } else {
  3486. $temp = explode('-', $k);
  3487. if (isset($temp[2])) {
  3488. $k = $temp[0] . '-' . $temp[1];
  3489. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  3490. $s_col = $config['struct'][$k]['sync'][0];
  3491. $m_col = $config['struct'][$k]['sync'][1];
  3492. if ($s_col == 'id') {
  3493. $s_value = $this->id;
  3494. } else {
  3495. $s_one = $this->load('one', $this->id);
  3496. $s_value = $s_one[$s_col];
  3497. }
  3498. $index = $temp[0] . '/' . $temp[1];
  3499. $temp[2] = ltrim($temp[2], '_');
  3500. $temp = explode('_', $temp[2]);
  3501. $update_col[$i][$index] = $m_col;
  3502. $up = array();
  3503. $up['add_' . $temp[0] . '_id'] = $temp[1];
  3504. $up['add_' . $temp[0] . '_value'] = $v;
  3505. $up['add_' . $m_col] = $s_value;
  3506. $update_add[$i][$index][] = $up;
  3507. $update_delete[$i][$index][][$m_col] = $s_value;
  3508. }
  3509. }
  3510. }
  3511. } else {
  3512. if (is_array($v)) {
  3513. $k = str_replace('update_', '', $k);
  3514. $kd = $k . '_id';
  3515. if (isset($config['struct'][$kd])) {
  3516. foreach ($v as $vk => $vt) {
  3517. if ($vt == -1) {
  3518. if ($vk != 0) {
  3519. unset($v[$vk]);
  3520. }
  3521. }
  3522. }
  3523. if ($v) {
  3524. $vd = end($v);
  3525. $kdi = $prefix . '_' . $kd;
  3526. $update[$i][$kdi] = $vd;
  3527. }
  3528. }
  3529. if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
  3530. $v = end($v);
  3531. }
  3532. }
  3533. $update[$i][$ki] = $v;
  3534. }
  3535. }
  3536. }
  3537. }
  3538. //print_r($update_set);
  3539. //print_r($update_id);
  3540. //print_r($update_add);die;
  3541. //print_r($input);
  3542. //print_r($update_other);
  3543. //print_r($config['struct']);die;
  3544. # 增加复制的数量
  3545. $copy_num = Dever::input('copy_num');
  3546. if ($copy_num > 0) {
  3547. $update[0]['where_id'] = 0;
  3548. for ($i = 1; $i < $copy_num; $i++) {
  3549. $update[$i] = $update[0];
  3550. # 缓存处理
  3551. $update[$i]['rank'] = $i;
  3552. }
  3553. }
  3554. if ($this->id && !$info) {
  3555. $update[0]['add_id'] = $this->id;
  3556. }
  3557. //print_r($update);die;
  3558. foreach ($update as $k => $v) {
  3559. $method = 'insert';
  3560. $old = array();
  3561. if (isset($v['where_id']) && $v['where_id']) {
  3562. $method = 'update';
  3563. $old = $this->load('one', $v['where_id']);
  3564. }
  3565. if (isset($order[$k])) {
  3566. foreach ($order[$k] as $i => $j) {
  3567. array_multisort($j, SORT_ASC, $v[$i]);
  3568. }
  3569. }
  3570. if (isset($v['set_password']) && (!$v['set_password'] || $v['set_password'] == 'null')) {
  3571. unset($v['set_password']);
  3572. }
  3573. $id = $this->load($method, $v);
  3574. if ($id) {
  3575. $struct = $this->struct_data($config['struct'], $v, $old);
  3576. Log::add($this->project, $this->table, $this->menu_id, '', $method, $struct, $id ? $id : $this->id);
  3577. if ($update_other && isset($update_other[$k])) {
  3578. foreach ($update_other[$k] as $k1 => $v1) {
  3579. $v1['id'] = $id;
  3580. $this->load($method, $v1, $this->table . '__' . $k1);
  3581. }
  3582. }
  3583. if (isset($update_add[$k]) && $update_add[$k]) {
  3584. foreach ($update_add[$k] as $k1 => $v1) {
  3585. $col = $update_col[$k][$k1];
  3586. foreach ($v1 as $k2 => $v2) {
  3587. if (isset($update_set[$k][$k1][$k2][$col])) {
  3588. $update_set[$k][$k1][$k2][$col] = $id;
  3589. }
  3590. if (isset($v2[$col])) {
  3591. $v2[$col] = $id;
  3592. }
  3593. $check = false;
  3594. if (isset($update_id[$k][$k1][$k2])) {
  3595. if (isset($update_id[$k][$k1][$k2][$col])) {
  3596. $update_id[$k][$k1][$k2][$col] = $id;
  3597. }
  3598. $check = Dever::load($k1 . '-one', $update_id[$k][$k1][$k2]);
  3599. } elseif (isset($update_delete[$k][$k1][$k2])) {
  3600. # 清理
  3601. Dever::load($k1 . '-delete', $update_delete[$k][$k1][$k2]);
  3602. }
  3603. if ($check) {
  3604. unset($update_set[$k][$k1][$k2]['set_id']);
  3605. $update_set[$k][$k1][$k2]['where_id'] = $check['id'];
  3606. Dever::load($k1 . '-update', $update_set[$k][$k1][$k2]);
  3607. } else {
  3608. Dever::load($k1 . '-insert', $v2);
  3609. }
  3610. }
  3611. }
  3612. }
  3613. }
  3614. }
  3615. }
  3616. Dever::out('yes');
  3617. }
  3618. public function struct_data($struct, $data, $old = array())
  3619. {
  3620. $log = $tlog = array();
  3621. foreach ($struct as $i => $j) {
  3622. /*
  3623. if ($i == 'reorder' || $i == 'id') {
  3624. continue;
  3625. }
  3626. */
  3627. if (isset($j['list_name'])) {
  3628. $j['name'] = $j['list_name'];
  3629. } elseif (strpos($j['name'], '-')) {
  3630. $temp = explode('-', $j['name']);
  3631. $j['name'] = $temp[0];
  3632. }
  3633. if (isset($j['list_table'])) {
  3634. $j['list'] = $j['list_table'];
  3635. if ($j['list'] == false) {
  3636. $data[$i] = false;
  3637. }
  3638. }
  3639. $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
  3640. $update = true;
  3641. if ($old && isset($j['update'])) {
  3642. $update = (is_string($j['update']) && $j['update'] != 'linkage');
  3643. }
  3644. if (isset($data['where_' . $i]) && $data['where_' . $i]) {
  3645. $log[$j['name']] = $data['where_' . $i];
  3646. } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
  3647. $log[$j['name']] = $data['set_' . $i];
  3648. } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
  3649. $log[$j['name']] = $data['add_' . $i];
  3650. } elseif (isset($data[$i]) && $data[$i]) {
  3651. if ($i == 'id') {
  3652. $log[$j['name']] = $data[$i];
  3653. } else {
  3654. $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
  3655. }
  3656. }
  3657. if (isset($log[$j['name']])) {
  3658. $tlog[$j['name']] = $log[$j['name']];
  3659. if (is_array($tlog[$j['name']])) {
  3660. if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
  3661. $tlog[$j['name']] = json_encode($tlog[$j['name']]);
  3662. if (isset($old[$i]) && is_array($old[$i])) {
  3663. $old[$i] = json_encode($old[$i]);
  3664. }
  3665. } elseif (isset($tlog[$j['name']][0])) {
  3666. $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
  3667. if (isset($old[$i]) && is_array($old[$i])) {
  3668. $old[$i] = implode(',', $old[$i]);
  3669. }
  3670. }
  3671. } 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) {
  3672. $log[$j['name']] = '<img layer-src="' . $log[$j['name']] . '" src="' . $log[$j['name']] . '" width="150">';
  3673. if (isset($old[$i]) && $old[$i]) {
  3674. $old[$i] = Dever::pic($old[$i]);
  3675. $old[$i] = '<img layer-src="' . $old[$i] . '" src="' . $old[$i] . '" width="150">';
  3676. }
  3677. } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
  3678. $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
  3679. if (isset($old[$i]) && $old[$i]) {
  3680. $old[$i] = date("Y-m-d H:i:s", $old[$i]);
  3681. }
  3682. } elseif (isset($j['decode'])) {
  3683. $log[$j['name']] = Dever::array_decode($log[$j['name']]);
  3684. if (isset($old[$i]) && $old[$i]) {
  3685. $old[$i] = Dever::array_decode($old[$i]);
  3686. }
  3687. }
  3688. if (isset($j['option']) && !$list && $update) {
  3689. $name = array();
  3690. $old_name = array();
  3691. $option = $this->option($j['option']);
  3692. if (is_array($option)) {
  3693. foreach ($option as $a => $b) {
  3694. if (!is_array($log[$j['name']])) {
  3695. if ($a == $log[$j['name']]) {
  3696. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3697. }
  3698. } elseif (in_array($a, $log[$j['name']])) {
  3699. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3700. }
  3701. if ($old && isset($old[$i])) {
  3702. if (!is_array($old[$i])) {
  3703. if ($a == $old[$i]) {
  3704. $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3705. }
  3706. } elseif (in_array($a, $old[$i])) {
  3707. $old_name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  3708. }
  3709. }
  3710. }
  3711. }
  3712. $log[$j['name']] = implode(',', $name);
  3713. if ($old_name) {
  3714. $old[$i] = implode(',', $old_name);
  3715. }
  3716. }
  3717. if ($log[$j['name']] == 'null') {
  3718. unset($log[$j['name']]);
  3719. }
  3720. if ($old && strstr($i, 'area')) {
  3721. $old[$i] = Dever::load('area/api')->string($old[$i]);
  3722. if (isset($log[$j['name']]) && $log[$j['name']]) {
  3723. $log[$j['name']] = Dever::load('area/api')->string($log[$j['name']]);
  3724. }
  3725. }
  3726. if (isset($log[$j['name']]) && isset($old[$i]) && $old[$i] != $tlog[$j['name']] && $old[$i] != $log[$j['name']]) {
  3727. $log[$j['name']] = array('更新前' => $old[$i], '更新后' => $log[$j['name']]);
  3728. } elseif ($old) {
  3729. //unset($log[$j['name']]);
  3730. }
  3731. }
  3732. }
  3733. return $log;
  3734. }
  3735. /**
  3736. * delete_action
  3737. *
  3738. * @return array
  3739. */
  3740. public function delete_action_api()
  3741. {
  3742. if (Dever::load('manage/auth.oper', 5) == false) {
  3743. Dever::alert('您没有权限');
  3744. }
  3745. $config = $this->config();
  3746. if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  3747. $name = '逻辑删除';
  3748. $this->load('update', array('where_id' => $this->id, 'state' => 2));
  3749. } else {
  3750. $name = '物理删除';
  3751. $this->load('delete', $this->id);
  3752. }
  3753. Log::add($this->project, $this->table, $this->menu_id, '', 3, array('ID' => $this->id, '方式' => $name), $this->id);
  3754. return 'reload';
  3755. return 'reloaderror';
  3756. }
  3757. /**
  3758. * recovery_action
  3759. *
  3760. * @return array
  3761. */
  3762. public function recovery_action_api()
  3763. {
  3764. if (Dever::load('manage/auth.oper', 5) == false) {
  3765. Dever::alert('您没有权限');
  3766. }
  3767. $this->load('update', array('where_id' => $this->id, 'state' => 1));
  3768. Log::add($this->project, $this->table, $this->menu_id, '', 4, array('ID' => $this->id, '方式' => '逻辑恢复'), $this->id);
  3769. return 'reload';
  3770. }
  3771. /**
  3772. * list_data
  3773. *
  3774. * @return array
  3775. */
  3776. public function list_data()
  3777. {
  3778. $config = $this->config();
  3779. $data = array();
  3780. if (isset($config['manage']['data'])) {
  3781. foreach ($config['manage']['data'] as $k => $v) {
  3782. if (is_object($v[1])) {
  3783. $function = $v[1];
  3784. $v[1] = $function();
  3785. }
  3786. $data[] = '<li class="layui-col-xs3">
  3787. <a class="layadmin-backlog-body"><h3>'.$v[0].'</h3>
  3788. <p><cite>'.$v[1].'</cite></p></a></li>';
  3789. }
  3790. }
  3791. return $data;
  3792. }
  3793. /**
  3794. * list_data
  3795. *
  3796. * @return array
  3797. */
  3798. public function list_data_show()
  3799. {
  3800. $config = $this->config();
  3801. if (isset($config['manage']['data'])) {
  3802. return 'display:block';
  3803. }
  3804. return 'display:none';
  3805. }
  3806. /**
  3807. * chart
  3808. *
  3809. * @return array
  3810. */
  3811. public function chart($config, $key, $data, $struct)
  3812. {
  3813. if (!$this->chart) {
  3814. $this->chart = array();
  3815. $this->chart['x'] = array();
  3816. $this->chart['data'] = array();
  3817. }
  3818. if ($config['x'] == $key) {
  3819. $this->chart['x'][] = $data;
  3820. } elseif (in_array($key, $config['data'])) {
  3821. if (!isset($this->chart['data'][$key])) {
  3822. $this->chart['data'][$key] = array
  3823. (
  3824. 'name' => $struct['name'],
  3825. 'type' => 'line',
  3826. 'stack' => 'Total',
  3827. 'data' => array(),
  3828. );
  3829. }
  3830. $this->chart['data'][$key]['data'][] = $data;
  3831. }
  3832. }
  3833. /**
  3834. * chart_data
  3835. *
  3836. * @return array
  3837. */
  3838. public function list_chart()
  3839. {
  3840. $config = $this->config();
  3841. $chart = '';
  3842. if (isset($config['manage']['chart']) && $this->chart) {
  3843. $this->chart['x'] = array_reverse($this->chart['x']);
  3844. $x = Dever::json_encode($this->chart['x']);
  3845. $this->chart['data'] = array_values($this->chart['data']);
  3846. foreach ($this->chart['data'] as $k => $v) {
  3847. $this->chart['data'][$k]['data'] = array_reverse($this->chart['data'][$k]['data']);
  3848. }
  3849. $data = Dever::json_encode($this->chart['data']);
  3850. $echarts = Dever::assets('lib/echarts/echarts.common.min.js', 'script');
  3851. $chart = '<script type="text/javascript" src="'.$echarts.'"></script><script>var chartDom = document.getElementById("chart");var myChart = echarts.init(chartDom);';
  3852. $chart .= "var option = {
  3853. tooltip: {
  3854. trigger: 'axis'
  3855. },
  3856. toolbox: {
  3857. feature: {
  3858. saveAsImage: {}
  3859. }
  3860. },
  3861. xAxis: {
  3862. type: 'category',
  3863. boundaryGap: false,
  3864. data: ".$x."
  3865. },
  3866. yAxis: {
  3867. type: 'value'
  3868. },
  3869. series: ".$data."
  3870. };option && myChart.setOption(option);</script>";
  3871. }
  3872. return $chart;
  3873. }
  3874. /**
  3875. * chart_data
  3876. *
  3877. * @return array
  3878. */
  3879. public function list_chart_show()
  3880. {
  3881. $config = $this->config();
  3882. if (isset($config['manage']['chart'])) {
  3883. return 'display:block';
  3884. }
  3885. return 'display:none';
  3886. }
  3887. /**
  3888. * stat 为主动统计提供相关数据
  3889. *
  3890. * @return array
  3891. */
  3892. public function stat()
  3893. {
  3894. //bundle 包依赖工具
  3895. $config = $this->config();
  3896. if (empty($config['manage']['stat'])) {
  3897. Dever::alert('该项目主动统计功能未开放');
  3898. }
  3899. $data = $config['manage'];
  3900. $data['table'] = '';
  3901. $method = $this->project . '/' . $this->table . '-all';
  3902. $gp = Dever::input('gp', 'month,day');
  3903. $col = is_string($gp) ? explode(',', $gp) : $gp;
  3904. $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
  3905. foreach ($col as $k => $v) {
  3906. $this->stat_data($data, $config['struct'], $v, $method);
  3907. }
  3908. return $data;
  3909. }
  3910. /**
  3911. * stat 为主动统计提供导出数据 后续优化
  3912. *
  3913. * @return array
  3914. */
  3915. public function stat_excel()
  3916. {
  3917. Dever::$global['base']['excel'] = 1;
  3918. //print_r($data['thead']);die;
  3919. $data = $this->stat();
  3920. if ($data && isset($data['list'])) {
  3921. $xls = new \PHPExcel();
  3922. $xls->getProperties()->setCreator("Maze Stat Excel")
  3923. ->setLastModifiedBy("Maze Stat Excel")
  3924. ->setTitle("Office 2007 XLSX Maze Document")
  3925. ->setSubject("Office 2007 XLSX Maze Document")
  3926. ->setDescription("Dever Stat Excel")
  3927. ->setKeywords("Dever Stat Excel")
  3928. ->setCategory("Dever Stat Excel");
  3929. $info = $this->info();
  3930. $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
  3931. $start = 65;
  3932. $s = 0;
  3933. foreach ($data['thead'] as $k => $v) {
  3934. if ($s > 0) {
  3935. $xls->createSheet();
  3936. }
  3937. $act = $xls->setActiveSheetIndex($s);
  3938. $act->setTitle($v[0]);
  3939. $s++;
  3940. $i = 0;
  3941. foreach ($v as $kj => $vj) {
  3942. $num = 1;
  3943. $cell = $this->_getChr($start, $i);
  3944. $act->setCellValue($cell . '' . $num, $vj);
  3945. $act->getColumnDimension($cell)->setWidth(20);
  3946. $i++;
  3947. if (isset($data['list'][$k])) {
  3948. foreach ($data['list'][$k] as $ki => $vi) {
  3949. if (isset($vi[$kj])) {
  3950. $num += 1;
  3951. $act->setCellValue($cell . $num, $vi[$kj]);
  3952. }
  3953. }
  3954. }
  3955. }
  3956. }
  3957. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
  3958. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
  3959. $xls->setActiveSheetIndex(0);
  3960. $filename = $name . '.xlsx';
  3961. header('Pragma: public');
  3962. header('Expires: 0');
  3963. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  3964. header('Content-Type:application/force-download');
  3965. header('Content-Type:application/vnd.ms-execl');
  3966. header('Content-Type:application/octet-stream');
  3967. header('Content-Type:application/download');
  3968. header("Content-Disposition:attachment;filename='" . $filename . "'");
  3969. header('Content-Transfer-Encoding:binary');
  3970. $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
  3971. $write->save('php://output');
  3972. }
  3973. }
  3974. /**
  3975. * stat_search
  3976. *
  3977. * @return mixed
  3978. */
  3979. private function stat_search($struct, $col, $stat, $search)
  3980. {
  3981. unset($struct['id']);
  3982. unset($struct['cdate']);
  3983. if ($stat) {
  3984. $stat = explode(',', $stat);
  3985. foreach ($stat as $k => $v) {
  3986. if (isset($struct[$v])) {
  3987. unset($struct[$v]);
  3988. }
  3989. }
  3990. }
  3991. $struct['day']['name'] = '天';
  3992. $struct['month']['name'] = '月';
  3993. $struct['year']['name'] = '年';
  3994. $param['update'] = 'checkbox';
  3995. $param['name'] = 'gp';
  3996. $param['value'] = $col;
  3997. $param['option'] = $struct;
  3998. $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
  3999. $html .= '<div class="form-group">';
  4000. $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
  4001. $html .= Html::radio($param);
  4002. $html .= '</div>';
  4003. $input = Dever::preInput('search_');
  4004. if (isset($search['date'])) {
  4005. foreach ($search['date'] as $k => $v) {
  4006. $html .= '<div class="form-group">';
  4007. $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
  4008. $html .= '</div>';
  4009. }
  4010. $input = Dever::preInput('search_');
  4011. if ($input) {
  4012. foreach ($input as $k => $v) {
  4013. if ($v && strpos($k, 'option_') !== false) {
  4014. Dever::setInput(str_replace('search_', '', $k), $v);
  4015. }
  4016. }
  4017. }
  4018. }
  4019. if (isset($search['fulltext'])) {
  4020. $html .= '<div class="form-group">';
  4021. $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
  4022. $this->list_search_select($html, $input, 'search_fulltext_type', '', array
  4023. (
  4024. 1 => '精确匹配',
  4025. 2 => '模糊匹配',
  4026. 3 => '大于',
  4027. 4 => '大于等于',
  4028. 5 => '小于',
  4029. 6 => '小于等于',
  4030. ), 1);
  4031. $value = array();
  4032. $value['name'] = 'search_fulltext_value';
  4033. $value['class'] = 'form-control';
  4034. if (isset($input[$value['name']])) {
  4035. $value['value'] = $input[$value['name']];
  4036. $fix = '';
  4037. if ($input['search_fulltext_type'] == 2) {
  4038. $fix = '%';
  4039. }
  4040. Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
  4041. //print_r(Dever::input('option_name'));die;
  4042. }
  4043. $html .= Html::text($value, false);
  4044. $html .= '</div>';
  4045. }
  4046. $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>';
  4047. $html .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
  4048. $html .= '</form>';
  4049. return $html;
  4050. }
  4051. /**
  4052. * stat_data
  4053. *
  4054. * @return mixed
  4055. */
  4056. private function stat_data(&$data, $struct, $col, $method)
  4057. {
  4058. Dever::setInput('group', $col);
  4059. switch ($col) {
  4060. case 'year':
  4061. $name = '按年统计';
  4062. break;
  4063. case 'month':
  4064. $name = '按月统计';
  4065. break;
  4066. case 'day':
  4067. $name = '按天统计';
  4068. break;
  4069. default:
  4070. $name = $struct[$col]['name'];
  4071. break;
  4072. }
  4073. $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
  4074. $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
  4075. $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
  4076. $data['thead'][$col] = array($name, '统计数字');
  4077. if ($list) {
  4078. $data['table'] .= '<tbody>';
  4079. $total = 0;
  4080. foreach ($list as $k => $v) {
  4081. if (isset($v[$col])) {
  4082. if (isset($struct[$col]['option'])) {
  4083. $option = $this->option($struct[$col]['option']);
  4084. if (isset($option[$v[$col]])) {
  4085. $v[$col] = $option[$v[$col]];
  4086. if (is_array($v[$col])) {
  4087. $v[$col] = $v[$col]['name'];
  4088. }
  4089. }
  4090. }
  4091. $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
  4092. $total += $v['total'];
  4093. $data['list'][$col][] = array($v[$col], $v['total']);
  4094. }
  4095. }
  4096. $data['table'] .= '</tbody>';
  4097. if ($total > 0 && $k > 0) {
  4098. $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
  4099. $data['list'][$col][] = array('汇总', $total);
  4100. }
  4101. }
  4102. $data['table'] .= '</table></div>';
  4103. }
  4104. /**
  4105. * load
  4106. *
  4107. * @return mixed
  4108. */
  4109. private function load($method = 'one', $param = array(), $table = false)
  4110. {
  4111. if (!$table) {
  4112. $table = $this->table;
  4113. }
  4114. return Dever::load($this->project . '/' . $table . '-' . $method, $param);
  4115. }
  4116. /**
  4117. * __call
  4118. *
  4119. * @return object
  4120. */
  4121. public function __call($method, $param)
  4122. {
  4123. if (strpos($method, 'html_') !== false) {
  4124. return Html::text($param);
  4125. }
  4126. return $this;
  4127. }
  4128. /**
  4129. * option
  4130. *
  4131. * @return string
  4132. */
  4133. private function option($option, $value = false)
  4134. {
  4135. if (is_object($option)) {
  4136. $function = $option;
  4137. $option = $function();
  4138. }
  4139. if ($value && is_array($value)) {
  4140. $state = false;
  4141. foreach ($value as $k => $v) {
  4142. if ($v === true) {
  4143. $state = true;
  4144. break;
  4145. }
  4146. }
  4147. if ($state) {
  4148. $option = array_intersect_key($option, $value);
  4149. } else {
  4150. $option = $value;
  4151. }
  4152. }
  4153. return $option;
  4154. }
  4155. /**
  4156. * option
  4157. *
  4158. * @return string
  4159. */
  4160. public function manage()
  4161. {
  4162. $config = $this->config();
  4163. return $config;
  4164. }
  4165. /**
  4166. * valid
  4167. *
  4168. * @return string
  4169. */
  4170. public function valid()
  4171. {
  4172. //http://placehold.it/350x150
  4173. $config = $this->config();
  4174. if (isset($config['struct'])) {
  4175. $rule = array();
  4176. $rule['required']['regex'] = 'none';
  4177. $rule['required']['alertText'] = '此项不能为空';
  4178. $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
  4179. $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
  4180. $rule['required']['alertTextDateRange'] = '日期范围不可空白';
  4181. foreach ($config['struct'] as $k => $v) {
  4182. if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
  4183. if (strstr($v['match'], 'option||')) {
  4184. $v['match'] = str_replace('option||', '', $v['match']);
  4185. }
  4186. $rule[$k]['regex'] = $v['match'];
  4187. $rule[$k]['alertText'] = $v['desc'];
  4188. }
  4189. }
  4190. }
  4191. $script = '<script>';
  4192. //参考https://blog.csdn.net/wangzl1163/article/details/51071826
  4193. //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
  4194. $script .= '(function($){
  4195. $.fn.validationEngineLanguage = function(){
  4196. };
  4197. $.validationEngineLanguage = {
  4198. newLang: function(){
  4199. $.validationEngineLanguage.allRules = ';
  4200. //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
  4201. $script .= str_replace(array('\\\\', '\\/', '"/', '/"', '/u"', '/g"', '/i"', '\x{4e00}-\x{9fa5}', '\x'), array('\\', '/', '/', '/', '/u', '/g', '/i', '\u4e00-\u9fa5', '\u'), json_encode($rule)) . ';';
  4202. $script .= '}
  4203. };
  4204. $.validationEngineLanguage.newLang();
  4205. })(jQuery);';
  4206. $script .= '$(document).ready(function(){
  4207. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  4208. });';
  4209. $script .= '</script>';
  4210. //print_r($script);die;
  4211. return $script;
  4212. }
  4213. /**
  4214. * save
  4215. *
  4216. * @return string
  4217. */
  4218. public function save()
  4219. {
  4220. $config = $this->config();
  4221. if (isset($config['manage']['save'])) {
  4222. return 'yes';
  4223. }
  4224. return 'no';
  4225. }
  4226. }