Database.php.bak.php 159 KB

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