Database.php 153 KB

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