Database.php 156 KB

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