Database.php 129 KB

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