Database.php 148 KB

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