Database.php 125 KB

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