Database.php 124 KB

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