Database.php 165 KB

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