Database.php 166 KB

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