Database.php 171 KB

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