Database.php 155 KB

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