Database.php 190 KB

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