Database.php 126 KB

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