Database.php 153 KB

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