Database.php 149 KB

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