Database.php 155 KB

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