Database.php 150 KB

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