Database.php 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870
  1. <?php
  2. # 此类很大,以后优化,放到Database目录中,拆分为工厂模式
  3. namespace Manage\Src;
  4. use Dever;
  5. use Manage\Src\Lib\Input as Html;
  6. use Manage\Src\Lib\Log;
  7. class Database
  8. {
  9. /**
  10. * project
  11. *
  12. * @var string
  13. */
  14. private $project;
  15. /**
  16. * table
  17. *
  18. * @var string
  19. */
  20. private $table;
  21. /**
  22. * menu
  23. *
  24. * @var string
  25. */
  26. private $menu;
  27. /**
  28. * menu_id
  29. *
  30. * @var string
  31. */
  32. private $menu_id;
  33. /**
  34. * id
  35. *
  36. * @var string
  37. */
  38. private $id;
  39. /**
  40. * config
  41. *
  42. * @var array
  43. */
  44. private $config;
  45. /**
  46. * search
  47. *
  48. * @var bool
  49. */
  50. private $search = false;
  51. /**
  52. * __construct
  53. *
  54. * @return mixed
  55. */
  56. public function __construct()
  57. {
  58. $this->project = Dever::input('project');
  59. $this->table = Dever::input('table');
  60. $this->menu = Dever::input('menu');
  61. $this->menu_id = Dever::input('menu_id');
  62. $this->id = Dever::input('update_where_id', Dever::input('where_id'));
  63. }
  64. /**
  65. * url
  66. *
  67. * @return array
  68. */
  69. private function url($key = false, $id = 0, $table = false, $suffix = '')
  70. {
  71. $table = $table ? $table : $this->table;
  72. if (strpos($table, 'http://') !== false || strpos($table, 'javascript') !== false) {
  73. return $table;
  74. }
  75. $config = array
  76. (
  77. 'project' => 'project/database?project=' . $this->project,
  78. 'list' => 'project/database/list?{param}',
  79. 'search' => 'project/database/list?{param}',
  80. 'add' => 'project/database/update?{param}',
  81. 'update' => 'project/database/update?{param}&where_id=' . $id,
  82. 'updateAction' => 'database.update_action',
  83. 'url' => '',
  84. 'delete' => 'database.delete_action?{param}&where_id=' . $id,
  85. 'recovery' => 'database.recovery_action?{param}&where_id=' . $id,
  86. 'stat' => 'project/database/stat?{param}',
  87. 'excel' => 'database.list_excel?{param}',
  88. 'stat_excel' => 'database.stat_excel?{param}',
  89. 'diy' => 'list?{param}',
  90. );
  91. $state = $this->getState();
  92. if ($key == 'delete' && $state == 2) {
  93. $key = 'recovery';
  94. }
  95. if (strpos($key, 'list') !== false) {
  96. $config[$key] = $config['list'];
  97. } elseif (strpos($key, 'add') !== false) {
  98. $config[$key] = $config['add'];
  99. }
  100. if (isset($config[$key])) {
  101. if (strpos($config[$key], '{param}')) {
  102. $param = $this->getUrlParam($key, $table, $suffix, $state);
  103. $config[$key] = str_replace('{param}', $param, $config[$key]);
  104. }
  105. return Dever::url($config[$key]);
  106. }
  107. return $config;
  108. }
  109. /**
  110. * 获取url需要的参数
  111. *
  112. * @return string
  113. */
  114. private function getUrlParam($key, $table, $suffix, $state)
  115. {
  116. $param = '';
  117. $array = array('project', 'add', 'list', 'update');
  118. if (in_array($key, $array)) {
  119. $where = Dever::preInput('search_');
  120. if ($where) {
  121. if (isset($where['where_id'])) {
  122. //unset($where['where_id']);
  123. }
  124. unset($where['search_option_state']);
  125. $param .= '&' . http_build_query($where);
  126. }
  127. $oper = Dever::preInput('oper_');
  128. if ($oper) {
  129. $param .= '&' . http_build_query($oper);
  130. }
  131. }
  132. if ($key == 'search' && $search_limit = Dever::input('search_limit')) {
  133. $param .= '&search_limit=' . $search_limit;
  134. }
  135. if (strpos($suffix, 'search_option_state') !== false) {
  136. $state = '';
  137. } else {
  138. $state = '&search_option_state=' . $state;
  139. }
  140. $param = 'project=' . $this->project . $param . '&table=' . $table . '&menu=' . $this->menu . '&menu_id=' . $this->menu_id . $state . $suffix;
  141. return $param;
  142. }
  143. /**
  144. * 获得refer
  145. *
  146. * @return string
  147. */
  148. private function refer($type = 'project')
  149. {
  150. return '';
  151. switch ($type) {
  152. case 'project':
  153. $name = '数据库操作';
  154. break;
  155. case 'list':
  156. $name = '数据列表';
  157. break;
  158. case 'url':
  159. $name = '项目列表';
  160. break;
  161. }
  162. $name = '返回上一级';
  163. $url = $this->url($type);
  164. $refer = '-[<a href="' . $url . '">' . $name . '</a>]';
  165. return $refer;
  166. }
  167. /**
  168. * getAdminInfo
  169. *
  170. * @return array
  171. */
  172. private function getAdminInfo($data)
  173. {
  174. $admin = Dever::load('manage/auth.info');
  175. $data['my_admin_id'] = $admin['id'];
  176. $data['my_role_id'] = $admin['role'];
  177. return $data;
  178. }
  179. /**
  180. * cookie 处理cookie
  181. *
  182. * @return array
  183. */
  184. public function cookie()
  185. {
  186. $cookie = $_COOKIE;
  187. $array = array();
  188. # 判断手机版
  189. $mobile = Dever::mobile();
  190. if ((isset($cookie['left_menu']) && $cookie['left_menu'] == 'close') || $mobile) {
  191. $array['wrapper'] = 'enlarged forced';
  192. } else {
  193. $array['wrapper'] = 'forced';
  194. }
  195. return $array;
  196. }
  197. /**
  198. * listStyle
  199. *
  200. * @return array
  201. */
  202. public function listStyle()
  203. {
  204. $mobile = Dever::mobile();
  205. if ($mobile) {
  206. $style = '.container_list .panel-heading .form-control,#mul .form-control,#page .form-control
  207. {
  208. width:70%;
  209. }
  210. .row
  211. {
  212. margin-right: -15px;
  213. margin-left: -15px;
  214. }
  215. #dever_modal_body img
  216. {
  217. max-width:300px;
  218. }
  219. ';
  220. } else {
  221. $style = '#dever_modal_body img
  222. {
  223. max-width:300px;
  224. }';
  225. }
  226. return $style;
  227. }
  228. /**
  229. * info 处理一些基本的信息,供模板使用
  230. *
  231. * @return array
  232. */
  233. public function info()
  234. {
  235. $config = $this->config();
  236. $menu = isset($config['lang']) ? $config['lang'] : $this->project . '-' . $this->table;
  237. if ($config['state'] == 2) {
  238. $menu .= '[回收站]';
  239. }
  240. $top = Dever::load('manage/top.get');
  241. //print_r($top);die;
  242. $display = '';
  243. # 新增权限
  244. $insert_state = Dever::load('manage/auth.oper', 4);
  245. if ((isset($config['manage']['insert']) && $config['manage']['insert'] == false) || !isset($config['manage']['insert']) || $insert_state == false) {
  246. $display = 'display:none';
  247. }
  248. $info = array
  249. (
  250. 'action' => $this->url('updateAction'),
  251. 'list' => $this->url('list'),
  252. 'search' => $this->url('search'),
  253. 'mul' => $this->url('list'),
  254. //'add' => 'location.href=\'' . $this->url('add') . '\'',
  255. 'add' => $this->url('add'),
  256. 'add_state' => $display,
  257. 'project' => $this->project,
  258. 'table' => $this->table,
  259. 'id' => $this->id,
  260. 'main' => '数据管理' . $this->refer('url'),
  261. 'list_header' => $menu,
  262. 'list_desc' => '数据列表',
  263. 'project_name' => Dever::load('manage/project.name', $this->project),
  264. 'update_header' => $menu,
  265. 'update_desc' => '更新数据',
  266. 'updateMul' => (!$this->id && isset($config['manage']['updateMul']) && $config['manage']['updateMul']) ? '增加一条' : false,
  267. 'updateDesc' => isset($config['manage']['desc']) ? $config['manage']['desc'] : '',
  268. 'listDesc' => isset($config['desc']) ? $config['desc'] : '',
  269. 'struct' => isset($config['manage']['struct']) ? $config['manage']['struct'] : '',
  270. 'stat_desc' => '主动统计',
  271. );
  272. $info['parent'] = Dever::input('oper_parent');
  273. if ($info['parent']) {
  274. $oper = Dever::preInput('oper_');
  275. if ($oper) {
  276. $info['parent'] .= '&' . str_replace('oper_', '', http_build_query($oper));
  277. //$info['parent'] .= '&' . http_build_query($oper);
  278. }
  279. //$info['parent'] = 'location.href=\'' . $this->url(Dever::input('oper_index', 11), 0, $info['parent']) . '\'';
  280. $info['parent'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['parent']);
  281. $info['parent_state'] = '';
  282. } else {
  283. $info['parent_state'] = 'display:none';
  284. }
  285. $info['save'] = Dever::input('oper_save_jump');
  286. if ($info['save']) {
  287. $info['list'] = $this->url(Dever::input('oper_index', 'listData'), 0, $info['save']);
  288. }
  289. $search = Dever::preInput('search_');
  290. if ($search) {
  291. $info['mul'] .= '&' . http_build_query($search);
  292. }
  293. if ($this->id) {
  294. $info['update_header'] = $menu . '-更新数据' . $this->refer('list');
  295. }
  296. return $info;
  297. }
  298. /**
  299. * 获取表名
  300. *
  301. * @return array
  302. */
  303. public function getTableName($project, $table)
  304. {
  305. if ($project == 'other') {
  306. return '无数据表';
  307. }
  308. $path = Dever::load('manage/project.path', $project);
  309. $config = $this->config($project, $path, $table);
  310. $data = isset($config['lang']) ? $config['lang'] : $project;
  311. return $data;
  312. }
  313. private function getState()
  314. {
  315. return Dever::input('search_option_state');
  316. }
  317. /**
  318. * config
  319. *
  320. * @return array
  321. */
  322. public function config($project = false, $path = false, $table = false)
  323. {
  324. if (!$project) {
  325. $project = $this->project;
  326. $table = $this->table;
  327. }
  328. if (!$project) {
  329. return array();
  330. }
  331. Dever::$global['manage']['project'] = $project;
  332. $config = Dever::load('manage/project.config', $project);
  333. if (!is_array($config)) {
  334. Dever::alert($project . ' error');
  335. }
  336. $project = $config['name'];
  337. if (!$path) {
  338. if (isset($config['base']) && isset($config['rel'])) {
  339. $path = DEVER_INCLUDE_PATH . $config['rel'];
  340. } else {
  341. $path = $config['path'];
  342. }
  343. }
  344. if ($project && $path && empty($this->config[$path])) {
  345. $this->config[$path] = array();
  346. $dir = $path . 'database/';
  347. if (is_dir($dir)) {
  348. $database = scandir($dir);
  349. foreach ($database as $k => $v) {
  350. if (strpos($v, '.php') !== false) {
  351. $k = str_replace('.php', '', $v);
  352. $this->config[$path][$k] = $this->struct($dir . $v, $project);
  353. }
  354. }
  355. }
  356. }
  357. return ($table && isset($this->config[$path][$table])) ? $this->config[$path][$table] : $this->config[$path];
  358. }
  359. /**
  360. * 对database配置文件进行解析
  361. *
  362. * @return array
  363. */
  364. private function struct($file, $project = false)
  365. {
  366. $config = include $file;
  367. if (isset($config['struct']) && is_array($config['struct']['id'])) {
  368. $config['update'] = false;
  369. $config['manage']['struct'] = '<table border=1 width=100% height=100%>';
  370. $config['level'] = 1;
  371. foreach ($config['struct'] as $k => $v) {
  372. if (isset($v['level'])) {
  373. $config['level'] = 3;
  374. }
  375. if (isset($v['search_parent'])) {
  376. $config['manage']['search_parent'][$v['search_parent']] = $k;
  377. $config['manage']['search_child'][$k] = $v['search_parent'];
  378. }
  379. if (isset($v['search'])) {
  380. /*
  381. if(strpos($v['search'], 'order') !== false)
  382. {
  383. $config['manage']['search']['order'][$k] = $v['name'];
  384. }
  385. */
  386. if (strpos($v['search'], 'time') !== false) {
  387. $config['manage']['search']['time'][$k] = $v['name'];
  388. }
  389. if (strpos($v['search'], 'date') !== false) {
  390. $config['manage']['search']['date'][$k] = $v['name'];
  391. }
  392. if (strpos($v['search'], 'exp') !== false) {
  393. $config['manage']['search']['exp'][$k] = $v['name'];
  394. isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like');
  395. }
  396. if (strpos($v['search'], 'fulltext') !== false) {
  397. $config['manage']['search']['fulltext'][$k] = $v['name'];
  398. isset($v['match']) && $config['request']['list']['option'][$k] = array('option', 'like');
  399. }
  400. if (isset($v['option']) && strpos($v['search'], 'select') !== false) {
  401. $config['manage']['search']['select'][$k]['option'] = $v['option'];
  402. $config['manage']['search']['select'][$k]['lang'] = $v['name'];
  403. if (isset($v['default'])) {
  404. $config['manage']['search']['select'][$k]['default'] = $v['default'];
  405. }
  406. }
  407. if (isset($v['option']) && strpos($v['search'], 'group') !== false) {
  408. $config['manage']['search']['group'][$k]['option'] = $v['option'];
  409. $config['manage']['search']['group'][$k]['lang'] = $v['name'];
  410. if (isset($v['default'])) {
  411. $config['manage']['search']['group'][$k]['default'] = $v['default'];
  412. }
  413. }
  414. if (isset($v['option']) && strpos($v['search'], 'mul') !== false) {
  415. $config['manage']['search']['mul'][$k]['option'] = $v['option'];
  416. $config['manage']['search']['mul'][$k]['lang'] = $v['name'];
  417. if (isset($v['default'])) {
  418. $config['manage']['search']['mul'][$k]['default'] = $v['default'];
  419. }
  420. }
  421. }
  422. /*
  423. if (isset($v['table']) && !isset($config['end'])) {
  424. $config['end']['insert'] = $v['value'];
  425. }
  426. */
  427. if (isset($v['update'])) {
  428. if (!isset($config['manage']['insert'])) {
  429. $config['manage']['insert'] = true;
  430. }
  431. $config['update'] = true;
  432. }
  433. if (isset($v['type'])) {
  434. $config['manage']['struct'] .= Dever::tbody(array($k, $v['type'], $v['name']));
  435. }
  436. }
  437. $config['manage']['struct'] .= '</table>';
  438. $config['manage']['_list'] = array
  439. (
  440. 'col' => 'manage',
  441. 'name' => '管理',
  442. 'value' => array(),
  443. );
  444. if (!isset($config['manage']['edit']) && $config['update'] == true) {
  445. # 3
  446. $config['manage']['_list']['value']['update'] = '编辑';
  447. }
  448. if (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] == true)) {
  449. # 6
  450. $config['manage']['_list']['value']['delete'] = '删除';
  451. }
  452. if (isset($config['manage']['list'][0]) && is_array($config['manage']['list'][0])) {
  453. $config['manage']['_list']['value'] += $config['manage']['list'][0];
  454. unset($config['manage']['list'][0]);
  455. } elseif (isset($config['manage']['list_button'])) {
  456. $config['manage']['_list']['value'] += $config['manage']['list_button'];
  457. }
  458. if (!$config['manage']['_list']['value']) {
  459. unset($config['manage']['_list']);
  460. }
  461. }
  462. $config['state'] = $this->getState();
  463. $config['project'] = $project;
  464. return $config;
  465. }
  466. /**
  467. * 自定义列表页面
  468. *
  469. * @return array
  470. */
  471. public function page($key = 'list')
  472. {
  473. $key = Dever::input('page_value', $key);
  474. $type = Dever::input('page_type', 1);
  475. $config = $this->config();
  476. $result = array();
  477. $result['s1'] = 'display:none';
  478. $result['s2'] = 'display:';
  479. $result['content'] = '';
  480. $key = 'page_' . $key;
  481. if (isset($config['manage'][$key])) {
  482. $result['content'] = Dever::view($config['manage'][$key], 'manage', $this->project);
  483. //echo $result['content'];die;
  484. if ($result['content']) {
  485. $result['s1'] = 'display:';
  486. $result['s2'] = 'display:none';
  487. # 添加底部
  488. $result['content'] .= Dever::view('foot', 'inc', 'manage');
  489. }
  490. }
  491. return $result;
  492. }
  493. /**
  494. * 自定义列表页面
  495. *
  496. * @return array
  497. */
  498. public function page_list()
  499. {
  500. return $this->page('list');
  501. }
  502. /**
  503. * 自定义列表页面 只接管table部分,同时必须传值page_type=1
  504. *
  505. * @return array
  506. */
  507. public function page_list_table()
  508. {
  509. $type = Dever::input('page_type', 2);
  510. if ($type == 1) {
  511. return $this->page('list_table');
  512. } else {
  513. return $this->page('list_table_default');
  514. }
  515. }
  516. /**
  517. * 自定义列表页面
  518. *
  519. * @return array
  520. */
  521. public function page_update()
  522. {
  523. return $this->page('update');
  524. }
  525. /**
  526. * 载入自定义资源
  527. *
  528. * @return array
  529. */
  530. public function res()
  531. {
  532. $result = array
  533. (
  534. 'js' => '',
  535. 'css' => '',
  536. );
  537. if (!$this->project) {
  538. return $result;
  539. }
  540. $config = $this->config();
  541. if (isset($config['manage']['res'])) {
  542. foreach ($config['manage']['res'] as $k => $v) {
  543. $result[$k] = $this->getRes($k, $v);
  544. }
  545. }
  546. return $result;
  547. }
  548. /**
  549. * getRes
  550. *
  551. * @return string
  552. */
  553. protected function getRes($path, $value)
  554. {
  555. if (is_array($value)) {
  556. $res = '';
  557. foreach ($value as $k => $v) {
  558. $res .= $this->getRes($path, $v);
  559. }
  560. return $res;
  561. } else {
  562. if ($this->project != 'manage') {
  563. $base = str_replace('assets/', 'assets/manage/', Dever::config('host', $this->project)->$path);
  564. } else {
  565. $base = Dever::config('host', $this->project)->$path;
  566. }
  567. $file = $base . $value . '.' . $path;
  568. $res = '<script type="text/javascript" src="'.$file.'"></script>';
  569. return $res;
  570. }
  571. }
  572. /**
  573. * 头部banner
  574. *
  575. * @return array
  576. */
  577. public function banner()
  578. {
  579. if (!$this->project) {
  580. return '';
  581. }
  582. $config = $this->config();
  583. $result = '';
  584. if (isset($config['manage']['banner'])) {
  585. foreach ($config['manage']['banner'] as $k => $v) {
  586. $config['manage']['banner'][$k] = $this->value($v, 'yes');
  587. }
  588. if (empty($config['manage']['banner']['link'])) {
  589. $config['manage']['banner']['link'] = '#';
  590. $config['manage']['banner']['target'] = '_self';
  591. }
  592. if (empty($config['manage']['banner']['target'])) {
  593. $config['manage']['banner']['target'] = '_blank';
  594. }
  595. $result = '<a target="' . $config['manage']['banner']['target'] . '" href="' . $config['manage']['banner']['link'] . '"><img src="' . $config['manage']['banner']['img'] . '"></a>
  596. <span>' . $config['manage']['banner']['name'] . '</span>';
  597. }
  598. return $result;
  599. }
  600. /**
  601. * 列表页搜索
  602. *
  603. * @return array
  604. */
  605. public function list_search_select(&$result, $search, $name, $lang, $option, $default = false, $bind = array(), $parent = '')
  606. {
  607. $value = array();
  608. if (strpos($lang, '-')) {
  609. $temp = explode('-', $lang);
  610. $lang = $temp[0];
  611. }
  612. $value['name'] = $name;
  613. $value['lang'] = $lang;
  614. $value['option'] = $option;
  615. if (isset($search[$name])) {
  616. $value['value'] = $search[$name];
  617. }
  618. if ($default) {
  619. //$value['default'] = $default;
  620. }
  621. if ($bind) {
  622. $value['bind'] = $bind;
  623. }
  624. $value['parent'] = $parent;
  625. $result .= Html::select($value, false) . '&nbsp;&nbsp;&nbsp;';
  626. }
  627. /**
  628. * 列表页搜索
  629. *
  630. * @return array
  631. */
  632. public function list_search_group(&$result, $search, $name, $lang, $option, $default = false)
  633. {
  634. $value = array();
  635. $value['name'] = $name;
  636. $value['lang'] = $lang;
  637. $value['option'] = $option;
  638. if (isset($search[$name])) {
  639. $value['value'] = $search[$name];
  640. }
  641. if ($default) {
  642. //$value['default'] = $default;
  643. }
  644. $result .= Html::group($value, false) . '&nbsp;&nbsp;&nbsp;';
  645. }
  646. /**
  647. * 列表页搜索
  648. *
  649. * @return array
  650. */
  651. public function list_search_mul(&$result, $search, $name, $lang, $option, $default = false)
  652. {
  653. $value = array();
  654. $value['name'] = $name;
  655. $value['lang'] = $lang;
  656. $value['option'] = $option;
  657. if (isset($search[$name])) {
  658. $value['value'] = $search[$name];
  659. }
  660. if ($default) {
  661. //$value['default'] = $default;
  662. }
  663. $result .= Html::mul($value, 'span') . '&nbsp;&nbsp;&nbsp;';
  664. }
  665. /**
  666. * 列表页搜索
  667. *
  668. * @return array
  669. */
  670. public function list_search_time(&$result, $search, $prefix, $key, $lang, $type = 'time')
  671. {
  672. $value['name'] = $prefix . 'option_start_' . $key;
  673. $value['lang'] = '开始' . $lang;
  674. if (isset($search[$value['name']])) {
  675. $value['value'] = Dever::maketime($search[$value['name']]);
  676. Dever::setInput($value['name'], $value['value'], 'search_');
  677. }
  678. $result .= Html::$type($value) . '&nbsp;-&nbsp;';
  679. $value['name'] = $prefix . 'option_end_' . $key;
  680. $value['lang'] = '结束' . $lang;
  681. if (isset($search[$value['name']])) {
  682. $value['value'] = Dever::maketime($search[$value['name']]);
  683. Dever::setInput($value['name'], $value['value'], 'search_');
  684. }
  685. $result .= Html::$type($value) . '&nbsp;&nbsp;<br />';
  686. }
  687. /**
  688. * 列表页头部按钮
  689. *
  690. * @return array
  691. */
  692. public function list_button()
  693. {
  694. if (Dever::load('manage/auth.oper', 2) == false) {
  695. Dever::alert('你没有权限');
  696. }
  697. $config = $this->config();
  698. $result = '';
  699. # 增加主动统计按钮
  700. if (isset($config['manage']['stat'])) {
  701. $config['manage']['button']['数据统计'] = $this->url('stat');
  702. }
  703. # 增加下载报表按钮
  704. if (isset($config['manage']['excel'])) {
  705. $config['manage']['button']['导出数据'] = 'onclick="location.href=\''.$this->url('excel').'\'"';
  706. }
  707. # 增加回收站
  708. if (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete'] && isset($config['manage']['_list']['value']['delete'])))) {
  709. if ($config['state'] == 2) {
  710. $config['manage']['button']['返回数据列表'] = $this->url('list', 0, false, '&search_option_state=1');
  711. } else {
  712. $config['manage']['button']['回收站'] = $this->url('list', 0, false, '&search_option_state=2');
  713. }
  714. }
  715. # 列表页按钮
  716. if (isset($config['manage']['button'])) {
  717. $result .= $this->button_list($config['manage']['button']);
  718. }
  719. return $result;
  720. }
  721. /**
  722. * 更新页按钮
  723. *
  724. * @return array
  725. */
  726. public function update_button()
  727. {
  728. # 新增权限
  729. if (Dever::load('manage/auth.oper', 2) == false) {
  730. Dever::alert('你没有权限');
  731. }
  732. $info = $this->info();
  733. $result = '<button type="button" class="btn btn-primary save-data"><i class="fa fa-save"></i> 提交保存</button>
  734. <a href="' . $info['list'] . '" class="btn btn-danger" onclicks="msg({status:1,msg:\'yes\'})">放弃保存</a>';
  735. $config = $this->config();
  736. if (isset($config['manage']['update_button']) && $config['manage']['update_button']) {
  737. $result = '';
  738. foreach ($config['manage']['update_button'] as $k => $v) {
  739. if ($v == 'save-data') {
  740. $result .= '<button type="button" class="btn btn-primary save-data"><i class="fa fa-save"></i> ' . $k . '</button>';
  741. } elseif ($v == 'copy-data') {
  742. $result .= '<a href="javascript:;" class="btn btn-danger" onclick="set_update(\'#copy_num\', 1);set_update(\'#update_where_id\', 0);submit_action();">' . $k . '</a>';
  743. } elseif ($v == 'copy-datas') {
  744. $result .= '<a href="#dever_modal" data-toggle="modal" class="btn btn-danger" onclick="copy_data($(this))">' . $k . '</a>';
  745. } else {
  746. $result .= '<a href="javascript:;" class="btn btn-danger" onclick="' . $v . '">' . $k . '</a>';
  747. }
  748. }
  749. }
  750. return $result;
  751. }
  752. private function button_list($button)
  753. {
  754. $result = '';
  755. foreach ($button as $k => $v) {
  756. if (is_array($v)) {
  757. if ($v[0] == 'location') {
  758. $result .= '&nbsp;&nbsp;<a class="btn btn-default" onclick="location.href=\''.Dever::url($v[1]).'\'">' . $k . '</a>';
  759. } else {
  760. $result .= '&nbsp;&nbsp;<a class="btn btn-default" href="' . $this->url($v[0], false, $v[1]) . '">' . $k . '</a>';
  761. }
  762. } elseif (strpos($v, 'modal|') !== false) {
  763. $t = explode('modal|', $v);
  764. $result .= '&nbsp;&nbsp;<a href="#dever_modal" data-toggle="modal" class="btn btn-default" onclick="$(\'#dever_modal_body\').html(\'' . $t[1] . '\')">' . $k . '</a>';
  765. } elseif (strpos($v, '|') !== false) {
  766. $t = explode('|', $v);
  767. $result .= $t[0] . '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" ' . $t[1] . '>' . $k . '</a>';
  768. } elseif (strpos($v, 'onclick') !== false) {
  769. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" ' . $v . '>' . $k . '</a>';
  770. } elseif (strpos($v, 'http://') !== false) {
  771. //$result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default" onclick="jump(\''.Dever::url($v).'\')">'.$k.'</a>';
  772. $result .= '&nbsp;&nbsp;<a class="btn btn-default" href="' . Dever::url($v) . '">' . $k . '</a>';
  773. } else {
  774. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-danger" onclick="load(\'' . Dever::url($v) . '\')">' . $k . '</a>';
  775. }
  776. }
  777. return $result;
  778. }
  779. /**
  780. * 列表页搜索
  781. *
  782. * @return array
  783. */
  784. public function list_search()
  785. {
  786. # 新增权限
  787. if (Dever::load('manage/auth.oper', 2) == false) {
  788. Dever::alert('你没有权限');
  789. }
  790. $config = $this->config();
  791. $result = '';
  792. # 搜索
  793. if (isset($config['struct']) && isset($config['manage']['search'])) {
  794. $search = Dever::preInput('search_');
  795. $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
  796. $btn = '<input type="hidden" value="2" name="excel" id="excel"><button class="btn btn-primary" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('search') . '\');list_search($(this))" type="button" style="height: 38px;margin-left:10px;">搜索</button>';
  797. //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
  798. $prefix = 'search_';
  799. $result .= $node[0];
  800. if (isset($config['manage']['search']['time'])) {
  801. foreach ($config['manage']['search']['time'] as $k => $v) {
  802. $this->list_search_time($result, $search, $prefix, $k, $v);
  803. }
  804. }
  805. if (isset($config['manage']['search']['date'])) {
  806. foreach ($config['manage']['search']['date'] as $k => $v) {
  807. $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
  808. }
  809. }
  810. if (isset($config['manage']['search']['select'])) {
  811. foreach ($config['manage']['search']['select'] as $k => $v) {
  812. $bind = array();
  813. $parent = '';
  814. $option = $this->option($v['option']);
  815. if (isset($config['manage']['search_parent'][$k])) {
  816. $bind = array
  817. (
  818. 'onchange',
  819. 'setOption',
  820. 'search_option_' . $config['manage']['search_parent'][$k]
  821. );
  822. }
  823. elseif (isset($config['manage']['search_child'][$k])) {
  824. $parent = $config['manage']['search_child'][$k];
  825. }
  826. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
  827. }
  828. }
  829. if (isset($config['manage']['search']['group'])) {
  830. foreach ($config['manage']['search']['group'] as $k => $v) {
  831. $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  832. }
  833. }
  834. if (isset($config['manage']['search']['mul'])) {
  835. foreach ($config['manage']['search']['mul'] as $k => $v) {
  836. $this->list_search_mul($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  837. }
  838. }
  839. /*排序加到列表表头中
  840. if(isset($config['manage']['search']['order']))
  841. {
  842. $this->list_search_select($result, $search, $prefix . 'order', '选择排序', $config['manage']['search']['order']);
  843. $this->list_search_select($result, $search, $prefix . 'desc', false, array('asc' => '正序','desc' => '倒序'));
  844. }
  845. */
  846. if (isset($config['manage']['search']['fulltext'])) {
  847. //$result .= '<br />';
  848. /*
  849. $this->list_search_select($result, $search, $prefix . 'fulltext', '选择检索项', $config['manage']['search']['fulltext']);
  850. $this->list_search_select($result, $search, $prefix . 'fulltext_type', '', array
  851. (
  852. 1 => '精确匹配',
  853. 2 => '模糊匹配',
  854. 3 => '大于',
  855. 4 => '大于等于',
  856. 5 => '小于',
  857. 6 => '小于等于',
  858. ), 1);
  859. */
  860. foreach ($config['manage']['search']['fulltext'] as $k => $v) {
  861. $value = array();
  862. $value['name'] = $prefix . 'fulltext_' . $k;
  863. $value['class'] = 'form-control';
  864. if (isset($search[$value['name']])) {
  865. $value['value'] = $search[$value['name']];
  866. }
  867. if (strpos($v, '-') !== false) {
  868. $t = explode('-', $v);
  869. $v = $t[0];
  870. }
  871. $value['placeholder'] = $v;
  872. $result .= Html::text($value, false) . '&nbsp;';
  873. }
  874. }
  875. # 列表页按钮
  876. if (isset($config['manage']['search_button'])) {
  877. $btn .= $this->button_list($config['manage']['search_button']);
  878. }
  879. $result .= $btn . $node[1];
  880. //$result .= '</form>';
  881. # 增加每页显示条数
  882. $config['manage']['num'] = $this->getNumConfig($config);
  883. if ($config['manage']['num']) {
  884. $result = $this->num($result, $config['manage']['num']);
  885. }
  886. }
  887. //print_r($result);die;
  888. return $result;
  889. }
  890. /**
  891. * 获取条数配置
  892. *
  893. * @return array
  894. */
  895. private function getNumConfig($config)
  896. {
  897. if (isset($config['manage']['list_type'])) {
  898. return false;
  899. }
  900. if (empty($config['manage']['num'])) {
  901. $config['manage']['num'] = array(20,50,100);
  902. }
  903. return $config['manage']['num'];
  904. }
  905. /**
  906. * 生成条数的html
  907. *
  908. * @return string
  909. */
  910. private function num($result, $config)
  911. {
  912. $limit = '';
  913. $cur = Dever::input('search_limit', 0);
  914. foreach($config as $k => $v) {
  915. if ($cur == $k) {
  916. $btn = 'success';
  917. } else {
  918. $btn = 'default';
  919. }
  920. $url = $this->url('list', 0, false, '&search_limit=' . $k);
  921. $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.'">'.$v.'</a> ';
  922. }
  923. $num = '<div class="form-group "><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>';
  924. $result .= $num;
  925. return $result;
  926. }
  927. /**
  928. * 列表页表格头
  929. *
  930. * @return array
  931. */
  932. public function list_thead()
  933. {
  934. # 新增权限
  935. if (Dever::load('manage/auth.oper', 1) == false) {
  936. Dever::alert('你没有权限');
  937. }
  938. $config = $this->config();
  939. $result = array();
  940. if (isset($config['struct'])) {
  941. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  942. # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
  943. if (isset($config['top']) && is_string($config['top'])) {
  944. $top = Dever::load('manage/auth.getTop', array($config['top']));
  945. if ($top) {
  946. $url = $this->url('update', $top['value']);
  947. }
  948. } else {
  949. $url = $this->url('update', 1);
  950. }
  951. return Dever::location($url);
  952. } else {
  953. if (isset($config['manage']['mul'])) {
  954. $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
  955. }
  956. $data = array();
  957. $data = $this->getAdminInfo($data);
  958. foreach ($config['struct'] as $k => $v) {
  959. if (isset($v['list']) && $v['list']) {
  960. # 处理权限
  961. if (isset($v['auth'])) {
  962. $auth = $this->value($v['auth'], $data);
  963. if (!$auth) {
  964. continue;
  965. }
  966. }
  967. if (isset($v['list_name'])) {
  968. $v['name'] = $v['list_name'];
  969. } else {
  970. $temp = Html::cue(array('name' => $v['name']));
  971. $v['name'] = $temp['name'];
  972. }
  973. if (!isset($v['level'])) {
  974. $v['level'] = $config['level'];
  975. }
  976. if (isset($v['search']) && strpos($v['search'], 'order') !== false) {
  977. $link = Dever::url();
  978. $order = 'search_order_' . $k . '';
  979. if (strpos($link, $order) !== false) {
  980. $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
  981. } else {
  982. $link .= '{order}';
  983. }
  984. $search = Dever::input($order);
  985. $cancel = '';
  986. if ($search) {
  987. $asc = $search;
  988. $cancel = '&nbsp;<a class="glyphicon glyphicon-remove-sign" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
  989. } else {
  990. $asc = 'desc';
  991. if (!isset($v['order']) && $k != 'id') {
  992. $cancel = '&nbsp;<a class="glyphicon glyphicon-circle-arrow-down" style="color:black;" href="' . str_replace('{order}', '&' . $order . '=desc', $link) . '" title="降序"></a>';
  993. }
  994. }
  995. if ($asc == 'asc') {
  996. $asc = 'desc';
  997. $icon = 'down';
  998. $text = '降序';
  999. } else {
  1000. $asc = 'asc';
  1001. $icon = 'up';
  1002. $text = '升序';
  1003. }
  1004. $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
  1005. $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>';
  1006. } else {
  1007. $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
  1008. }
  1009. }
  1010. }
  1011. if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
  1012. $result[] = '<th data-priority="1">' . $config['manage']['_list']['name'] . '</th>';
  1013. }
  1014. }
  1015. }
  1016. return $result;
  1017. }
  1018. /**
  1019. * 导出列表
  1020. *
  1021. * @return array
  1022. */
  1023. public function list_excel_api()
  1024. {
  1025. Dever::$global['base']['excel'] = 1;
  1026. $data = $this->list_tbody(true);
  1027. if ($data) {
  1028. $config = $this->config();
  1029. if (isset($config['manage']['excel']) && $config['manage']['excel']) {
  1030. $method = 'excel_' . $config['manage']['excel'];
  1031. $info = $this->info();
  1032. $data = $this->getAdminInfo($data);
  1033. $this->$method($info, $data, $config);
  1034. }
  1035. }
  1036. //print_r($data);die;
  1037. }
  1038. private function excel_csv($info, $data, $config)
  1039. {
  1040. $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'] . '.csv';
  1041. $header = $body = array();
  1042. $i = 0;
  1043. foreach ($config['struct'] as $k => $v) {
  1044. if (isset($v['list']) && $v['list']) {
  1045. # 处理权限
  1046. if (isset($v['auth'])) {
  1047. $auth = $this->value($v['auth'], $data);
  1048. if (!$auth) {
  1049. continue;
  1050. }
  1051. }
  1052. $v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
  1053. $header[$i] = $v['name'];
  1054. $i++;
  1055. $j = 0;
  1056. foreach ($data as $ki => $vi) {
  1057. if (isset($vi[$k])) {
  1058. $value = $vi[$k];
  1059. if (is_string($v['list'])) {
  1060. $value = $this->value($v['list'], $data[$ki], $config['struct']);
  1061. }
  1062. if (isset($v['option'])) {
  1063. $v['option'] = $this->option($v['option']);
  1064. if (strstr($value, ',')) {
  1065. $temp = explode(',', $value);
  1066. $t = array();
  1067. foreach ($temp as $vv) {
  1068. if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
  1069. $t[] = $v['option'][$vv]['name'];
  1070. } else {
  1071. $t[] = $vv;
  1072. }
  1073. }
  1074. $value = implode("\r\n", $t);
  1075. } elseif (isset($v['option'][$value])) {
  1076. if (is_array($v['option'][$value])) {
  1077. $value = $v['option'][$value]['name'];
  1078. } else {
  1079. $value = $v['option'][$value];
  1080. }
  1081. }
  1082. }
  1083. $value = mb_convert_encoding($value,'gb2312','utf-8');
  1084. $body[$j][] = $value;
  1085. $j++;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. //print_r($header);
  1091. //print_r($body);die;
  1092. Dever::csv($body, $header, $file);
  1093. }
  1094. private function excel_phpexcel($info, $data, $config)
  1095. {
  1096. $xls = new \PHPExcel();
  1097. $xls->getProperties()->setCreator("Dever Excel")
  1098. ->setLastModifiedBy("Dever Excel")
  1099. ->setTitle("Office 2007 XLSX Analysis Document")
  1100. ->setSubject("Office 2007 XLSX Analysis Document")
  1101. ->setDescription("Dever Excel")
  1102. ->setKeywords("Dever Excel")
  1103. ->setCategory("Dever Excel");
  1104. $name = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
  1105. # 全局导出
  1106. $start = 65;
  1107. $act = $xls->setActiveSheetIndex(0);
  1108. $act->setTitle($name);
  1109. $i = 0;
  1110. foreach ($config['struct'] as $k => $v) {
  1111. if (isset($v['list']) && $v['list']) {
  1112. # 处理权限
  1113. if (isset($v['auth'])) {
  1114. $auth = $this->value($v['auth'], $data);
  1115. if (!$auth) {
  1116. continue;
  1117. }
  1118. }
  1119. $num = 1;
  1120. $cell = $this->_getChr($start, $i);
  1121. $act->setCellValue($cell . '' . $num, $v['name']);
  1122. $act->getColumnDimension($cell)->setWidth(20);
  1123. $i++;
  1124. foreach ($data as $ki => $vi) {
  1125. if (isset($vi[$k])) {
  1126. $num += 1;
  1127. $value = $vi[$k];
  1128. if (is_string($v['list'])) {
  1129. $value = $this->value($v['list'], $data[$ki], $config['struct']);
  1130. }
  1131. if (isset($v['option'])) {
  1132. $v['option'] = $this->option($v['option']);
  1133. if (strstr($value, ',')) {
  1134. $temp = explode(',', $value);
  1135. $t = array();
  1136. foreach ($temp as $vv) {
  1137. if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
  1138. $t[] = $v['option'][$vv]['name'];
  1139. } else {
  1140. $t[] = $vv;
  1141. }
  1142. }
  1143. $value = implode("\r\n", $t);
  1144. } elseif (isset($v['option'][$value])) {
  1145. if (is_array($v['option'][$value])) {
  1146. $value = $v['option'][$value]['name'];
  1147. } else {
  1148. $value = $v['option'][$value];
  1149. }
  1150. }
  1151. }
  1152. $act->setCellValue($cell . $num, $value);
  1153. }
  1154. }
  1155. }
  1156. }
  1157. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
  1158. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
  1159. $filename = $name . '.xlsx';
  1160. header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  1161. header('Content-Disposition: attachment;filename="' . $filename . '"');
  1162. header('Cache-Control: max-age=0');
  1163. $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
  1164. $write->save('php://output');
  1165. }
  1166. private function _getChr($start, $num)
  1167. {
  1168. $num = $start + $num;
  1169. $max = floor($num / 91);
  1170. if ($max > 0) {
  1171. $num = $num - (91 * $max) + $start;
  1172. $num = chr($start) . chr($num);
  1173. } else {
  1174. $num = chr($num);
  1175. }
  1176. return $num;
  1177. }
  1178. /**
  1179. * 列表页数据列表
  1180. *
  1181. * @return array
  1182. */
  1183. public function list_tbody($excel = false)
  1184. {
  1185. # 新增权限
  1186. if (Dever::load('manage/auth.oper', 1) == false) {
  1187. Dever::alert('你没有权限');
  1188. }
  1189. $config = $this->config();
  1190. $high = array();
  1191. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  1192. $param = array();
  1193. $parent = 0;
  1194. if ($search) {
  1195. $fulltext = Dever::preInput('search_fulltext_');
  1196. if ($fulltext) {
  1197. # like改为instr
  1198. $search['search_fulltext_type'] = 2;
  1199. $fix = '';
  1200. /*
  1201. if ($search['search_fulltext_type'] == 2) {
  1202. $fix = '%';
  1203. }
  1204. */
  1205. foreach ($fulltext as $k => $v) {
  1206. if ($v) {
  1207. $k = str_replace('search_fulltext_', '', $k);
  1208. $param['option_' . $k] = $fix . $v . $fix;
  1209. unset($search[$k]);
  1210. # 设定检索高亮
  1211. $high[$k] = $v;
  1212. }
  1213. }
  1214. if ($param) {
  1215. $param['search_type'] = $search['search_fulltext_type'];
  1216. }
  1217. $this->search = true;
  1218. }
  1219. $order = Dever::preInput('search_order_');
  1220. if ($order) {
  1221. foreach ($order as $k => $v) {
  1222. $k = str_replace('search_order_', '', $k);
  1223. $param['order'][0][$k] = $v;
  1224. unset($search[$k]);
  1225. }
  1226. }
  1227. foreach ($search as $k => $v) {
  1228. if ($v) {
  1229. if (strpos($k, 'option_') !== false) {
  1230. //Dever::setInput(str_replace('search_', '', $k), $v);
  1231. if (is_array($v)) {
  1232. if ($v[0] == 0) {
  1233. continue;
  1234. }
  1235. $v = str_replace(',0', '', implode(',', $v));
  1236. $t = explode(',', $v);
  1237. $parent = end($t);
  1238. $v .= '%';
  1239. }
  1240. $param[str_replace('search_', '', $k)] = $v;
  1241. $this->search = true;
  1242. } elseif ($k == 'search_limit') {
  1243. $num = $this->getNumConfig($config);
  1244. if ($num) {
  1245. $param['page'][0] = $num[$v];
  1246. }
  1247. }
  1248. }
  1249. }
  1250. //$search = Dever::preInput('option_');
  1251. //print_r($search);die;
  1252. }
  1253. if (empty($param['page'])) {
  1254. $num = $this->getNumConfig($config);
  1255. if ($num) {
  1256. $param['page'][0] = $num[0];
  1257. }
  1258. }
  1259. # 批量更新
  1260. $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
  1261. if (Dever::input('method') == 'mul' && $mul && $mul['mul_type'] > 0) {
  1262. if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
  1263. Dever::alert('您还未选择任何数据条目');
  1264. }
  1265. Dever::$global['base']['mul_type'] = $mul['mul_type'];
  1266. unset($mul['mul_type']);
  1267. foreach ($mul as $k => $v) {
  1268. if ($v) {
  1269. if (is_array($v)) {
  1270. $v = implode(',', $v);
  1271. }
  1272. $param[str_replace('mul_', '', $k)] = $v;
  1273. }
  1274. }
  1275. if (isset($param)) {
  1276. $method = $this->project . '/' . $this->table . '-updatemul';
  1277. $state = Dever::load($method, $param);
  1278. }
  1279. //print_r($param);die;
  1280. Dever::alert('reload');
  1281. }
  1282. $result = array();
  1283. if ($excel == true) {
  1284. $method = $this->project . '/' . $this->table . '-all';
  1285. } else {
  1286. $method = $this->project . '/' . $this->table . '-list';
  1287. }
  1288. //print_r($param);die;
  1289. $data = Dever::load($method, $param);
  1290. if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
  1291. $parent = array();
  1292. $child = array();
  1293. foreach ($data as $k => $v) {
  1294. if ($v[$config['name'] . '_id'] <= 0) {
  1295. $parent[$k] = $v;
  1296. } else {
  1297. $v['name'] = '|-----' . $v['name'];
  1298. $child[$v[$config['name'] . '_id']][$k] = $v;
  1299. }
  1300. }
  1301. if ($parent) {
  1302. $data = array();
  1303. foreach ($parent as $k => $v) {
  1304. $data[$v['id']] = $v;
  1305. if (isset($child[$v['id']])) {
  1306. foreach ($child[$v['id']] as $i => $j) {
  1307. $data[$j['id']] = $j;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
  1313. $data = $this->tree($data, $config, $parent);
  1314. }
  1315. if ($excel == true) {
  1316. return $data;
  1317. }
  1318. if (Dever::input('page_type') == 1) {
  1319. Dever::$global['manage']['list_data'] = $data;
  1320. return $data;
  1321. }
  1322. //print_r($data);die;
  1323. //print_r(Helper::page("current"));die;
  1324. if ($data && isset($config['struct'])) {
  1325. foreach ($data as $k => $v) {
  1326. $data[$k] = $this->getAdminInfo($data[$k]);
  1327. $result[$k] = '<tr>';
  1328. if (isset($config['manage']['mul'])) {
  1329. $result[$k] .= '<td><input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" value="' . $v['id'] . '"/></td>';
  1330. }
  1331. foreach ($config['struct'] as $ki => $vi) {
  1332. # 处理同步
  1333. if (isset($vi['sync']) && strpos($ki, '-')) {
  1334. $temp = explode('-', $ki);
  1335. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  1336. $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
  1337. }
  1338. if (isset($vi['list']) && $vi['list']) {
  1339. if (empty($v[$ki])) {
  1340. $v[$ki] = $vi['default'];
  1341. }
  1342. # 处理权限
  1343. if (isset($vi['auth'])) {
  1344. $auth = $this->value($vi['auth'], $data[$k]);
  1345. if (!$auth) {
  1346. continue;
  1347. }
  1348. }
  1349. $show = $v[$ki];
  1350. if (is_string($vi['list'])) {
  1351. $show = $this->value($vi['list'], $data[$k], $config['struct']);
  1352. }
  1353. if (isset($vi['key']) && $vi['update'] != 'editor') {
  1354. $show = Dever::upload($show);
  1355. }
  1356. if (isset($vi['modal'])) {
  1357. $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
  1358. } elseif (isset($vi['option'])) {
  1359. # 验证option是否是匿名函数
  1360. $vi['option'] = $this->option($vi['option']);
  1361. # 位运算
  1362. if (isset($vi['bit'])) {
  1363. $ts = array();
  1364. foreach ($vi['option'] as $tm => $tv) {
  1365. if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
  1366. $ts[] = $tv;
  1367. }
  1368. }
  1369. $show = implode(',', $ts);
  1370. }
  1371. if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
  1372. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  1373. $show = $vi['option'][$show]['name'];
  1374. } else {
  1375. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  1376. }
  1377. }
  1378. //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
  1379. elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
  1380. {
  1381. $vi['name'] = 'up_col_' . $ki;
  1382. $vi['value'] = $v[$ki];
  1383. $m = 'select';
  1384. if (isset($vi['update']) && $vi['update'] == 'group') {
  1385. $m = 'group';
  1386. }
  1387. $show = Html::$m($vi, 'form-list', '', 'onchange="update($(this), \'' . $v['id'] . '\', \'' . $this->project . '\', \'' . $this->table . '\')"');
  1388. } else {
  1389. if (strstr($show, ',')) {
  1390. $temp = explode(',', $show);
  1391. $t = array();
  1392. foreach ($temp as $vv) {
  1393. if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
  1394. $t[] = $vi['option'][$vv]['name'];
  1395. } else {
  1396. $t[] = $vv;
  1397. }
  1398. }
  1399. $show = implode('<br />', $t);
  1400. } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  1401. $show = $vi['option'][$show]['name'];
  1402. } else {
  1403. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  1404. }
  1405. }
  1406. }
  1407. $text = $show;
  1408. if ($high && isset($high[$ki])) {
  1409. if (isset($v['s_' . $ki])) {
  1410. $text = $v['s_' . $ki];
  1411. $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
  1412. $text = str_replace('</em>', '</font>', $text);
  1413. } else {
  1414. $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text);
  1415. }
  1416. }
  1417. if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
  1418. //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
  1419. $url = $this->url('updateAction');
  1420. $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
  1421. $result[$k] .= '<td 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 . '</td>';
  1422. } else {
  1423. $result[$k] .= '<td>' . $text . '</td>';
  1424. }
  1425. }
  1426. }
  1427. if (isset($config['manage']['_list']['value'])) {
  1428. $result[$k] .= '<td>';
  1429. if ($config['state'] == 2) {
  1430. if (isset($config['manage']['_list']['value']['update'])) {
  1431. unset($config['manage']['_list']['value']['update']);
  1432. }
  1433. if (isset($config['manage']['_list']['value']['delete'])) {
  1434. $config['manage']['_list']['value']['delete'] = '恢复';
  1435. }
  1436. }
  1437. foreach ($config['manage']['_list']['value'] as $kj => $vj) {
  1438. $pj = false;
  1439. $h = '<span class="am-icon-pencil-square-o"></span>';
  1440. $oper = true;
  1441. if ($kj == 'update') {
  1442. $oper = Dever::load('manage/auth.oper', 3);
  1443. } elseif ($kj == 'delete') {
  1444. $oper = Dever::load('manage/auth.oper', 5);
  1445. $h = '<span class="am-icon-trash-o"></span>';
  1446. }
  1447. if (is_array($vj) && isset($vj[1])) {
  1448. if (isset($vj[2])) {
  1449. $oper = $this->value($vj[2], $data[$k]);
  1450. }
  1451. if ($oper && strpos($vj[1], 'modal|') === false) {
  1452. $pj = $this->value($vj[1], $data[$k]);
  1453. $vjn = $vj[0];
  1454. }
  1455. } else {
  1456. $vjn = $vj;
  1457. }
  1458. if ($oper == true) {
  1459. if (strpos($kj, 'oper') !== false) {
  1460. $result[$k] .= '<a href="javascript:;" onclick="load(\'' . Dever::url($pj) . '\')"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5">' . $vj[0] . '</button></a>&nbsp;&nbsp;';
  1461. }
  1462. elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
  1463. $t = explode('|', $vj[1]);
  1464. $result[$k] .= '<a href="#dever_modal" data-toggle="modal" class="btn btn-info btn-rounded waves-effect waves-light m-b-5" onclick=' . $t[1] . ' msg-send="' . $this->value($t[2], $data[$k]) . '">' . $vj[0] . '</a>&nbsp;&nbsp;';
  1465. } elseif (isset($vj[1])) {
  1466. $result[$k] .= '<a href="' . $this->url($kj, $v['id'], $pj) . '" class="oper_' . $kj . '"><button type="button" class="btn btn-info btn-rounded waves-effect waves-light m-b-5">' . $h . $vjn . '</button></a>&nbsp;&nbsp;';
  1467. } else {
  1468. $result[$k] .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
  1469. }
  1470. }
  1471. }
  1472. $result[$k] .= '</td>';
  1473. }
  1474. $result[$k] .= '</tr>';
  1475. }
  1476. }
  1477. /*
  1478. if ($result) {
  1479. $thead = $this->list_thead();
  1480. if ($thead) {
  1481. $k = $k + 1;
  1482. $result[$k] = '<tr>';
  1483. foreach ($thead as $k => $v) {
  1484. $result[$k] .= $v;
  1485. }
  1486. $result[$k] .= '</tr>';
  1487. }
  1488. }
  1489. */
  1490. return $result;
  1491. }
  1492. /**
  1493. * 多级分类
  1494. *
  1495. * @return array
  1496. */
  1497. private function tree($data, $config, $parent = 0)
  1498. {
  1499. $key = $config['name'] . '_id';
  1500. $result = array();
  1501. $this->treeData($data, $result, $key, $parent);
  1502. return $result;
  1503. }
  1504. private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
  1505. {
  1506. if (empty($array)) {
  1507. return;
  1508. }
  1509. $level++;
  1510. foreach ($array as $k => $v) {
  1511. if (isset($v[$key . '_parent']) && $v[$key . '_parent'] == $parent_id) {
  1512. $v['level'] = $level;
  1513. $v['name'] = $this->treeName($v['name'], $level);
  1514. $result[] = $v;
  1515. unset($array[$k]);
  1516. $this->treeData($array, $result, $key, $v['id'], $level);
  1517. }
  1518. }
  1519. }
  1520. private function treeName($name, $level = 1)
  1521. {
  1522. $string = '';
  1523. if ($level > 1) {
  1524. $num = 4;
  1525. $string = '-';
  1526. //STR_PAD_LEFT
  1527. $string = str_pad('|', $level * $num, $string);
  1528. }
  1529. return $string . $name;
  1530. }
  1531. /**
  1532. * 列表页批量管理
  1533. *
  1534. * @return array
  1535. */
  1536. public function list_mul()
  1537. {
  1538. # 新增权限:更新权限
  1539. if (Dever::load('manage/auth.oper', 3) == false) {
  1540. Dever::alert('你没有权限');
  1541. }
  1542. $config = $this->config();
  1543. $result = '';
  1544. if (isset($config['struct']) && isset($config['manage']['mul'])) {
  1545. $mul = Dever::preInput('mul_');
  1546. $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
  1547. $btn = '<button class="btn btn-danger" onclick="$(\'#form1\').attr(\'action\', \'' . $this->url('list') . '\');list_mul($(this))" type="button" style="height: 38px;margin-left:10px;">更新</button>';
  1548. $prefix = 'mul_';
  1549. $result .= $node[0];
  1550. $default = 0;
  1551. $option = array
  1552. (
  1553. 1 => '选中的数据',
  1554. );
  1555. # 只有当有搜索条件时才会出现
  1556. if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
  1557. $option[2] = '所有数据';
  1558. $default = 2;
  1559. }
  1560. $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择更新方式', $option, $default);
  1561. foreach ($config['struct'] as $k => $v) {
  1562. if ($k == 'state') {
  1563. $v['option'] = Dever::config('base')->state;
  1564. if ($this->getState() == 2) {
  1565. unset($v['option'][2]);
  1566. } else {
  1567. unset($v['option'][1]);
  1568. }
  1569. $v['edit'] = true;
  1570. }
  1571. if (isset($v['edit']) && isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
  1572. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option']), $v['default']);
  1573. }
  1574. }
  1575. $result .= $btn . $node[1];
  1576. }
  1577. //print_r($result);die;
  1578. return $result;
  1579. }
  1580. private function value($value, $data, $struct = array())
  1581. {
  1582. if (!$data) {
  1583. return $value;
  1584. }
  1585. if (is_string($data)) {
  1586. $eval = '$value = ' . $value . ';';
  1587. eval($eval);
  1588. return $value;
  1589. }
  1590. if ($value == 'table' && $struct) {
  1591. $result = $this->struct_data($struct, $data);
  1592. $value = Dever::table($result);
  1593. } elseif (strpos($value, '{') !== false) {
  1594. # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
  1595. //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
  1596. $func = function ($r) use ($data) {
  1597. return $data[$r[1]];
  1598. };
  1599. $eval = '$value = ' . preg_replace_callback('/{(.*?)}/', $func, $value) . ';';
  1600. eval($eval);
  1601. }
  1602. return $value;
  1603. }
  1604. /**
  1605. * update
  1606. *
  1607. * @return array
  1608. */
  1609. public function update()
  1610. {
  1611. $config = $this->config();
  1612. $result = array();
  1613. $prefix = 'update';
  1614. $data = array();
  1615. if ($this->id) {
  1616. # 新增权限
  1617. if (Dever::load('manage/auth.oper', 3) == false) {
  1618. Dever::alert('你没有权限');
  1619. }
  1620. $data = $this->load('one', $this->id);
  1621. if ($data) {
  1622. //$prefix = 'set';
  1623. }
  1624. } else {
  1625. # 新增权限
  1626. if (Dever::load('manage/auth.oper', 4) == false) {
  1627. Dever::alert('你没有权限');
  1628. }
  1629. }
  1630. //print_r($config['manage']['update']);die;
  1631. $data = $this->getAdminInfo($data);
  1632. foreach ($config['struct'] as $k => $v) {
  1633. if (isset($v['update'])) {
  1634. //处理权限
  1635. if (isset($v['auth'])) {
  1636. $auth = $this->value($v['auth'], $data);
  1637. if (!$auth) {
  1638. continue;
  1639. }
  1640. }
  1641. # 处理show模式下的class
  1642. $class = $this->update_class($k, $v);
  1643. $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
  1644. $v['ext'] = $v['col'] = $k;
  1645. $v['update'] = $v['update'] ? $v['update'] : 'text';
  1646. if (isset($v['match']) && $v['match'] != 'option') {
  1647. if (is_string($v['match']) && strpos($v['match'], '/') !== false) {
  1648. $v['valid'] = 'validate[required,custom[' . $k . ']]';
  1649. } else {
  1650. $v['valid'] = 'validate[required]';
  1651. }
  1652. }
  1653. if (is_string($v['update']) && strpos($v['update'], 'copy.') !== false) {
  1654. $v['value'] = $v['update'];
  1655. $v['update'] = 'hidden';
  1656. }
  1657. $this->update_html($v, $k, $k, $data, $result);
  1658. $result[$k] .= '</div></div>';
  1659. } elseif (isset($v['class'])) {
  1660. # 分割线
  1661. $v['name'] = $this->value($v['name'], array('test' => 1));
  1662. $result[$k] = Html::hr($v);
  1663. }
  1664. }
  1665. if (Dever::input('ajax') == 1) {
  1666. return implode('', $result);
  1667. }
  1668. //print_r($result);die;
  1669. return $result;
  1670. }
  1671. /**
  1672. * update_class
  1673. *
  1674. * @return string
  1675. */
  1676. public function update_class($name, $param, $prefix = '')
  1677. {
  1678. $class = '';
  1679. $key = 'show';
  1680. if (isset($param[$key]) && $param[$key]) {
  1681. $parent = array();
  1682. $child = array();
  1683. if (is_array($param[$key])) {
  1684. foreach ($param[$key] as $k => $v) {
  1685. $this->controlShow($name, $parent, $child, $key, $v, $prefix);
  1686. }
  1687. } else {
  1688. $this->controlShow($name, $parent, $child, $key, $param[$key], $prefix);
  1689. }
  1690. $class = implode(' ', $parent) . ' ' . implode(' ', $child);
  1691. }
  1692. if (isset($param['control'])) {
  1693. $class .= ' ' . $key . '_input';
  1694. }
  1695. return $class;
  1696. }
  1697. /**
  1698. * controlShow
  1699. *
  1700. * @return mixed
  1701. */
  1702. private function controlShow($name, &$parent, &$child, $key, $show, $prefix = '')
  1703. {
  1704. if (strpos($show, '=') !== false) {
  1705. $temp = explode('=', $show);
  1706. $show = str_replace('=', '_', $show);
  1707. if ($prefix) {
  1708. $temp[0] = str_replace($name, $temp[0], $prefix);
  1709. $show = str_replace($name, $show, $prefix);
  1710. }
  1711. $parent[$temp[0]] = $key . '_' . $temp[0];
  1712. $child[$show] = $key . '_' . $show;
  1713. } elseif ($show == 'no') {
  1714. $child[$show] = $key . '_no';
  1715. }
  1716. }
  1717. /**
  1718. * update_html
  1719. *
  1720. * @return string
  1721. */
  1722. public function update_html($param, $key, $index, $data, &$result)
  1723. {
  1724. if (isset($param['name']) && $param['update'] != 'hidden' && isset($param['update'])) {
  1725. $result[$key] .= Html::pageLeft($param);
  1726. }
  1727. if ($param['update']) {
  1728. # 名称带前缀
  1729. $param['name'] = 'update_' . $param['ext'];
  1730. $param['index'] = $index;
  1731. //$param['value'] = '';
  1732. # 得到当前的值
  1733. if (isset($data[$index]) && !isset($param['value'])) {
  1734. $param['value'] = $data[$index];
  1735. }
  1736. # 得到下级的值
  1737. if (isset($param['child_value']) && isset($data['id'])) {
  1738. $param['child_value'] = $this->value($param['child_value'], $data);
  1739. }
  1740. # 验证option是否是匿名函数
  1741. if (isset($param['option'])) {
  1742. $param['option'] = $this->option($param['option']);
  1743. }
  1744. if (isset($data[$index]) && isset($param['key']) && $param['update'] != 'editor') {
  1745. $param['value'] = Dever::upload($data[$index]);
  1746. }
  1747. # 处理下级字段
  1748. if (isset($param['child'])) {
  1749. $param['child'] = $this->option($param['child']);
  1750. if (isset($data[$key . '_parent'])) {
  1751. $param['parent_value'] = $data[$key . '_parent'];
  1752. }
  1753. }
  1754. # 设置默认值
  1755. if (isset($param['default'])) {
  1756. $param['default'] = $this->option($param['default']);
  1757. }
  1758. # 处理同步
  1759. if (isset($param['sync']) && isset($data[$param['sync'][0]]) && strpos($key, '-')) {
  1760. $temp = explode('-', $key);
  1761. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $param['sync'][1] => $data[$param['sync'][0]]));
  1762. $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
  1763. }
  1764. $method = $param['update'];
  1765. if (is_array($method)) {
  1766. $result[$key] .= '<ul class="nav nav-tabs">{tab}<li><a href="javascript:;" class="dever_form_add" toggle_key="' . $key . '">增加一条</a></li></ul>';
  1767. $tab = '';
  1768. $order = array
  1769. (
  1770. 'col' => 'order',
  1771. 'name' => '排序-按照数字正序排列',
  1772. 'default' => '1',
  1773. 'desc' => '排序',
  1774. 'match' => 'is_string',
  1775. 'update' => 'text',
  1776. );
  1777. array_unshift($method, $order);
  1778. $this->update_child(array(), $method, $key, $result, -1);
  1779. if (isset($param['value']) && $param['value']) {
  1780. $param['value'] = json_decode(base64_decode($param['value']), true);
  1781. foreach ($param['value'] as $k => $v) {
  1782. $this->update_child($v, $method, $key, $result, $k);
  1783. $active = '';
  1784. if ($k == 0) {
  1785. $active = 'active';
  1786. }
  1787. $k = $k + 1;
  1788. $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))">第' . $k . '条</a></li>';
  1789. }
  1790. } else {
  1791. $this->update_child(array(), $method, $key, $result, 0);
  1792. $tab = '<li class="active"><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>';
  1793. }
  1794. $result[$key] = str_replace('{tab}', $tab, $result[$key]);
  1795. } else {
  1796. if (isset($param['update_input']) && isset($data[$index . '_input'])) {
  1797. $param['update_input_data'] = explode(',', $data[$index . '_input']);
  1798. }
  1799. $result[$key] .= Html::$method($param);
  1800. }
  1801. if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
  1802. $result[$key] .= Html::desc($param['desc']);
  1803. }
  1804. }
  1805. }
  1806. /**
  1807. * update_action
  1808. *
  1809. * @return array
  1810. */
  1811. private function update_child($data, $param, $key, &$result, $index)
  1812. {
  1813. $style = '';
  1814. if ($index != 0) {
  1815. $style = 'style="display:none;"';
  1816. }
  1817. $result[$key] .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" ' . $style . '><div class="dever_form_delete">[删除]</div>';
  1818. foreach ($param as $k => $v) {
  1819. $v['type'] = $v['update'];
  1820. $prefix = '';
  1821. if ($index < 0) {
  1822. $v['ext'] = $key . '_c_' . $v['col'];
  1823. } else {
  1824. $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
  1825. $prefix = $v['ext'];
  1826. }
  1827. if ($v['col'] == 'order') {
  1828. $v['default'] = $index+1;
  1829. }
  1830. $class = $this->update_class($v['col'], $v, $prefix);
  1831. $result[$key] .= '<div class="form-group ' . $class . '">';
  1832. $this->update_html($v, $key, $v['col'], $data, $result);
  1833. $result[$key] .= '</div>';
  1834. }
  1835. $result[$key] .= '</div>';
  1836. }
  1837. /**
  1838. * update_action
  1839. *
  1840. * @return array
  1841. */
  1842. public function update_action_api()
  1843. {
  1844. $method = false;
  1845. $config = $this->config();
  1846. $input = Dever::preInput('update_');
  1847. if ($this->id) {
  1848. # 新增权限
  1849. if (Dever::load('manage/auth.oper', 3) == false) {
  1850. Dever::alert('你没有权限');
  1851. }
  1852. Dever::setInput('where_id', $this->id);
  1853. //Dever::setInput('update_where_id', $this->id);
  1854. $info = $this->load('one', $this->id);
  1855. if ($info) {
  1856. $method = 'update';
  1857. $col = Dever::input('col');
  1858. $value = Dever::input('value');
  1859. if ($col && $value) {
  1860. $method = 'update_' . $col;
  1861. //Dever::setInput('set_' . $col, $value);
  1862. //Dever::setInput('update_' . $col, $value);
  1863. $param['where_id'] = $this->id;
  1864. $param['set_' . $col] = $value;
  1865. $this->load($method, $param);
  1866. $struct = $this->struct_data($config['struct'], array($col => $value));
  1867. Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct, 'struct' => $config['struct']), $this->id);
  1868. Dever::out('yes');
  1869. return;
  1870. }
  1871. $prefix = 'set';
  1872. } else {
  1873. $method = 'insert';
  1874. $prefix = 'add';
  1875. }
  1876. }
  1877. if (!$method) {
  1878. # 新增权限
  1879. if (Dever::load('manage/auth.oper', 4) == false) {
  1880. Dever::alert('你没有权限');
  1881. }
  1882. $method = 'insert';
  1883. $prefix = 'add';
  1884. }
  1885. if ($method && $input) {
  1886. $update = $order = array();
  1887. $i = 0;
  1888. $c = array();
  1889. foreach ($input as $k => $v) {
  1890. if ($v === '') {
  1891. $v = 'null';
  1892. }
  1893. if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
  1894. $temp = str_replace('copy.', '', $v);
  1895. if (isset($input['update_' . $temp])) {
  1896. $v = $input['update_' . $temp];
  1897. }
  1898. }
  1899. if (strpos($k, '_c_') !== false) {
  1900. if ($v == 'null') {
  1901. $v = '';
  1902. }
  1903. $temp = explode('_c_', $k);
  1904. $k = str_replace('update_', $prefix . '_', $temp[0]);
  1905. if (!isset($c[$k])) {
  1906. $c[$k] = array();
  1907. }
  1908. if (strpos($temp[1], '_i_') !== false) {
  1909. $temp = explode('_i_', $temp[1]);
  1910. if (!isset($c[$k][$temp[1]])) {
  1911. $c[$k][$temp[1]] = 0;
  1912. } else {
  1913. $c[$k][$temp[1]]++;
  1914. }
  1915. $num = $c[$k][$temp[1]];
  1916. $update[$i][$k][$num][$temp[1]] = $v;
  1917. if ($temp[1] == 'order') {
  1918. $order[$i][$k][$num] = $v;
  1919. }
  1920. } else {
  1921. //$update[$i][$k][$c][$temp[1]] = $v;
  1922. }
  1923. } elseif (strpos($k, '__') !== false) {
  1924. $temp1 = explode('__', $k);
  1925. $temp2 = explode('_', $temp1[0]);
  1926. $i = $temp2[1] - 1;
  1927. if (strpos($k, 'where_id') !== false) {
  1928. //$update[$i]['where_id'] = $v;
  1929. } else {
  1930. $update[$i]['add_' . $temp1[1]] = $v;
  1931. }
  1932. } else {
  1933. $ki = str_replace('update_', $prefix . '_', $k);
  1934. if (strpos($ki, 'where_id') !== false) {
  1935. if ($method != 'insert') {
  1936. $update[$i]['where_id'] = $v;
  1937. }
  1938. } else {
  1939. if (strpos($k, '-')) {
  1940. $k = str_replace('update_', '', $k);
  1941. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  1942. $s_col = $config['struct'][$k]['sync'][0];
  1943. $m_col = $config['struct'][$k]['sync'][1];
  1944. if ($s_col == 'id') {
  1945. $s_value = $this->id;
  1946. } else {
  1947. $s_one = $this->load('one', $this->id);
  1948. $s_value = $s_one[$s_col];
  1949. }
  1950. $temp = explode('-', $k);
  1951. $index = $temp[0] . '/' . $temp[1];
  1952. $update_other_set[$index]['set_' . $temp[2]] = $v;
  1953. //$update_other_set[$index]['set_' . $m_col] = $s_value;
  1954. $update_other_add[$index]['add_' . $temp[2]] = $v;
  1955. $update_other_add[$index]['add_' . $m_col] = $s_value;
  1956. $update_other_id[$index]['option_' . $m_col] = $s_value;
  1957. }
  1958. } else {
  1959. $update[$i][$ki] = $v;
  1960. }
  1961. }
  1962. }
  1963. }
  1964. //print_r($update_other_set);die;
  1965. //print_r($input);
  1966. //print_r($update_other);die;
  1967. //print_r($config['struct']);die;
  1968. # 增加复制的数量
  1969. $copy_num = Dever::input('copy_num');
  1970. if ($copy_num > 0) {
  1971. $update[0]['where_id'] = 0;
  1972. for ($i = 1; $i < $copy_num; $i++) {
  1973. $update[$i] = $update[0];
  1974. # 缓存处理
  1975. $update[$i]['rank'] = $i;
  1976. }
  1977. }
  1978. if ($this->id && !$info) {
  1979. $update[0]['add_id'] = $this->id;
  1980. }
  1981. //print_r($update);die;
  1982. foreach ($update as $k => $v) {
  1983. $method = 'insert';
  1984. $old = array();
  1985. if (isset($v['where_id']) && $v['where_id']) {
  1986. $method = 'update';
  1987. $old = $this->load('one', $v['where_id']);
  1988. }
  1989. if (isset($order[$k])) {
  1990. foreach ($order[$k] as $i => $j) {
  1991. array_multisort($j, SORT_ASC, $v[$i]);
  1992. }
  1993. }
  1994. $id = $this->load($method, $v);
  1995. if ($id) {
  1996. $struct = $this->struct_data($config['struct'], $v, $old);
  1997. Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct), $this->id ? $this->id : $id);
  1998. }
  1999. if (isset($update_other_id) && $update_other_id) {
  2000. foreach ($update_other_set as $k => $v) {
  2001. $check = Dever::load($k . '-one', $update_other_id[$k]);
  2002. //print_r($check);die;
  2003. if ($check) {
  2004. $v['where_id'] = $check['id'];
  2005. Dever::load($k . '-update', $v);
  2006. } else {
  2007. Dever::load($k . '-insert', $update_other_add[$k]);
  2008. }
  2009. }
  2010. }
  2011. }
  2012. }
  2013. Dever::out('yes');
  2014. }
  2015. private function struct_data($struct, $data, $old = array())
  2016. {
  2017. $log = $tlog = array();
  2018. foreach ($struct as $i => $j) {
  2019. if (isset($j['list_name'])) {
  2020. $j['name'] = $j['list_name'];
  2021. } elseif (strpos($j['name'], '-')) {
  2022. $temp = explode('-', $j['name']);
  2023. $j['name'] = $temp[0];
  2024. }
  2025. if (isset($j['list_table'])) {
  2026. $j['list'] = $j['list_table'];
  2027. if ($j['list'] == false) {
  2028. $data[$i] = false;
  2029. }
  2030. }
  2031. $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
  2032. if (isset($data['where_' . $i]) && $data['where_' . $i]) {
  2033. $log[$j['name']] = $data['where_' . $i];
  2034. } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
  2035. $log[$j['name']] = $data['set_' . $i];
  2036. } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
  2037. $log[$j['name']] = $data['add_' . $i];
  2038. } elseif (isset($data[$i]) && $data[$i]) {
  2039. $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
  2040. }
  2041. if (isset($log[$j['name']])) {
  2042. $tlog[$j['name']] = $log[$j['name']];
  2043. if (is_array($tlog[$j['name']])) {
  2044. if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
  2045. $tlog[$j['name']] = json_encode($tlog[$j['name']]);
  2046. } else {
  2047. $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
  2048. }
  2049. } 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) {
  2050. $log[$j['name']] = '<a href="' . $log[$j['name']] . '" target="_blank"><img src="' . $log[$j['name']] . '" width="150"></a>';
  2051. } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
  2052. $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
  2053. } elseif (isset($j['decode'])) {
  2054. $log[$j['name']] = json_decode(base64_decode($log[$j['name']]), true);
  2055. }
  2056. if (isset($j['option']) && !$list) {
  2057. $name = array();
  2058. $option = $this->option($j['option']);
  2059. foreach ($option as $a => $b) {
  2060. if (!is_array($log[$j['name']])) {
  2061. if ($a == $log[$j['name']]) {
  2062. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  2063. }
  2064. } elseif (in_array($a, $log[$j['name']])) {
  2065. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  2066. }
  2067. }
  2068. $log[$j['name']] = implode(',', $name);
  2069. }
  2070. if (isset($old[$i]) && $old[$i] != $tlog[$j['name']]) {
  2071. $log[$j['name']] = array('old' => $old[$i], 'new' => $log[$j['name']]);
  2072. }
  2073. }
  2074. }
  2075. return $log;
  2076. }
  2077. /**
  2078. * delete_action
  2079. *
  2080. * @return array
  2081. */
  2082. public function delete_action_api()
  2083. {
  2084. if (Dever::load('manage/auth.oper', 5) == false) {
  2085. Dever::alert('您没有权限');
  2086. }
  2087. $config = $this->config();
  2088. if (isset($config['manage']['delete']) && $config['manage']['delete'] === 2) {
  2089. $this->load('delete', array('where_id' => $this->id));
  2090. } elseif (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  2091. $this->load('update', array('where_id' => $this->id, 'state' => 2));
  2092. }
  2093. return 'reloaderror';
  2094. }
  2095. /**
  2096. * recovery_action
  2097. *
  2098. * @return array
  2099. */
  2100. public function recovery_action_api()
  2101. {
  2102. if (Dever::load('manage/auth.oper', 5) == false) {
  2103. Dever::alert('您没有权限');
  2104. }
  2105. $this->load('update', array('where_id' => $this->id, 'state' => 1));
  2106. return 'reload';
  2107. }
  2108. /**
  2109. * stat 为主动统计提供相关数据
  2110. *
  2111. * @return array
  2112. */
  2113. public function stat()
  2114. {
  2115. //bundle 包依赖工具
  2116. $config = $this->config();
  2117. if (empty($config['manage']['stat'])) {
  2118. Dever::alert('该项目主动统计功能未开放');
  2119. }
  2120. $data = $config['manage'];
  2121. $data['table'] = '';
  2122. $method = $this->project . '/' . $this->table . '-all';
  2123. $gp = Dever::input('gp', 'month,day');
  2124. $col = is_string($gp) ? explode(',', $gp) : $gp;
  2125. $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
  2126. foreach ($col as $k => $v) {
  2127. $this->stat_data($data, $config['struct'], $v, $method);
  2128. }
  2129. return $data;
  2130. }
  2131. /**
  2132. * stat 为主动统计提供导出数据 后续优化
  2133. *
  2134. * @return array
  2135. */
  2136. public function stat_excel()
  2137. {
  2138. Dever::$global['base']['excel'] = 1;
  2139. //print_r($data['thead']);die;
  2140. $data = $this->stat();
  2141. if ($data && isset($data['list'])) {
  2142. $xls = new \PHPExcel();
  2143. /*
  2144. if(class_exists('\\PHPExcel'))
  2145. {
  2146. $xls = new \PHPExcel();
  2147. }
  2148. else
  2149. {
  2150. Dever::debug('Class \'PHPExcel\' not found');
  2151. die;
  2152. }
  2153. */
  2154. $xls->getProperties()->setCreator("Maze Stat Excel")
  2155. ->setLastModifiedBy("Maze Stat Excel")
  2156. ->setTitle("Office 2007 XLSX Maze Document")
  2157. ->setSubject("Office 2007 XLSX Maze Document")
  2158. ->setDescription("Mazephp Stat Excel")
  2159. ->setKeywords("Mazephp Stat Excel")
  2160. ->setCategory("Mazephp Stat Excel");
  2161. $info = $this->info();
  2162. $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
  2163. $start = 65;
  2164. $s = 0;
  2165. foreach ($data['thead'] as $k => $v) {
  2166. if ($s > 0) {
  2167. $xls->createSheet();
  2168. }
  2169. $act = $xls->setActiveSheetIndex($s);
  2170. $act->setTitle($v[0]);
  2171. $s++;
  2172. $i = 0;
  2173. foreach ($v as $kj => $vj) {
  2174. $num = 1;
  2175. $cell = $this->_getChr($start, $i);
  2176. $act->setCellValue($cell . '' . $num, $vj);
  2177. $act->getColumnDimension($cell)->setWidth(20);
  2178. $i++;
  2179. if (isset($data['list'][$k])) {
  2180. foreach ($data['list'][$k] as $ki => $vi) {
  2181. if (isset($vi[$kj])) {
  2182. $num += 1;
  2183. $act->setCellValue($cell . $num, $vi[$kj]);
  2184. }
  2185. }
  2186. }
  2187. }
  2188. }
  2189. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
  2190. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
  2191. $xls->setActiveSheetIndex(0);
  2192. $filename = $name . '.xlsx';
  2193. header('Pragma: public');
  2194. header('Expires: 0');
  2195. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  2196. header('Content-Type:application/force-download');
  2197. header('Content-Type:application/vnd.ms-execl');
  2198. header('Content-Type:application/octet-stream');
  2199. header('Content-Type:application/download');
  2200. header("Content-Disposition:attachment;filename='" . $filename . "'");
  2201. header('Content-Transfer-Encoding:binary');
  2202. $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
  2203. $write->save('php://output');
  2204. }
  2205. }
  2206. /**
  2207. * stat_search
  2208. *
  2209. * @return mixed
  2210. */
  2211. private function stat_search($struct, $col, $stat, $search)
  2212. {
  2213. unset($struct['id']);
  2214. unset($struct['cdate']);
  2215. if ($stat) {
  2216. $stat = explode(',', $stat);
  2217. foreach ($stat as $k => $v) {
  2218. if (isset($struct[$v])) {
  2219. unset($struct[$v]);
  2220. }
  2221. }
  2222. }
  2223. $struct['day']['name'] = '天';
  2224. $struct['month']['name'] = '月';
  2225. $struct['year']['name'] = '年';
  2226. $param['update'] = 'checkbox';
  2227. $param['name'] = 'gp';
  2228. $param['value'] = $col;
  2229. $param['option'] = $struct;
  2230. $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
  2231. $html .= '<div class="form-group">';
  2232. $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
  2233. $html .= Html::radio($param);
  2234. $html .= '</div>';
  2235. $input = Dever::preInput('search_');
  2236. if (isset($search['date'])) {
  2237. foreach ($search['date'] as $k => $v) {
  2238. $html .= '<div class="form-group">';
  2239. $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
  2240. $html .= '</div>';
  2241. }
  2242. $input = Dever::preInput('search_');
  2243. if ($input) {
  2244. foreach ($input as $k => $v) {
  2245. if ($v && strpos($k, 'option_') !== false) {
  2246. Dever::setInput(str_replace('search_', '', $k), $v);
  2247. }
  2248. }
  2249. }
  2250. }
  2251. if (isset($search['fulltext'])) {
  2252. $html .= '<div class="form-group">';
  2253. $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
  2254. $this->list_search_select($html, $input, 'search_fulltext_type', '', array
  2255. (
  2256. 1 => '精确匹配',
  2257. 2 => '模糊匹配',
  2258. 3 => '大于',
  2259. 4 => '大于等于',
  2260. 5 => '小于',
  2261. 6 => '小于等于',
  2262. ), 1);
  2263. $value = array();
  2264. $value['name'] = 'search_fulltext_value';
  2265. $value['class'] = 'form-control';
  2266. if (isset($input[$value['name']])) {
  2267. $value['value'] = $input[$value['name']];
  2268. $fix = '';
  2269. if ($input['search_fulltext_type'] == 2) {
  2270. $fix = '%';
  2271. }
  2272. Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
  2273. //print_r(Dever::input('option_name'));die;
  2274. }
  2275. $html .= Html::text($value, false);
  2276. $html .= '</div>';
  2277. }
  2278. $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>';
  2279. $html .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
  2280. $html .= '</form>';
  2281. return $html;
  2282. }
  2283. /**
  2284. * stat_data
  2285. *
  2286. * @return mixed
  2287. */
  2288. private function stat_data(&$data, $struct, $col, $method)
  2289. {
  2290. Dever::setInput('group', $col);
  2291. switch ($col) {
  2292. case 'year':
  2293. $name = '按年统计';
  2294. break;
  2295. case 'month':
  2296. $name = '按月统计';
  2297. break;
  2298. case 'day':
  2299. $name = '按天统计';
  2300. break;
  2301. default:
  2302. $name = $struct[$col]['name'];
  2303. break;
  2304. }
  2305. $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
  2306. $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
  2307. $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
  2308. $data['thead'][$col] = array($name, '统计数字');
  2309. if ($list) {
  2310. $data['table'] .= '<tbody>';
  2311. $total = 0;
  2312. foreach ($list as $k => $v) {
  2313. if (isset($v[$col])) {
  2314. if (isset($struct[$col]['option'])) {
  2315. $option = $this->option($struct[$col]['option']);
  2316. if (isset($option[$v[$col]])) {
  2317. $v[$col] = $option[$v[$col]];
  2318. if (is_array($v[$col])) {
  2319. $v[$col] = $v[$col]['name'];
  2320. }
  2321. }
  2322. }
  2323. $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
  2324. $total += $v['total'];
  2325. $data['list'][$col][] = array($v[$col], $v['total']);
  2326. }
  2327. }
  2328. $data['table'] .= '</tbody>';
  2329. if ($total > 0 && $k > 0) {
  2330. $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
  2331. $data['list'][$col][] = array('汇总', $total);
  2332. }
  2333. }
  2334. $data['table'] .= '</table></div>';
  2335. }
  2336. /**
  2337. * load
  2338. *
  2339. * @return mixed
  2340. */
  2341. private function load($method = 'one', $param = array())
  2342. {
  2343. return Dever::load($this->project . '/' . $this->table . '-' . $method, $param);
  2344. }
  2345. /**
  2346. * __call
  2347. *
  2348. * @return object
  2349. */
  2350. public function __call($method, $param)
  2351. {
  2352. if (strpos($method, 'html_') !== false) {
  2353. return Html::text($param);
  2354. }
  2355. return $this;
  2356. }
  2357. /**
  2358. * option
  2359. *
  2360. * @return string
  2361. */
  2362. private function option($option)
  2363. {
  2364. if (is_object($option)) {
  2365. $function = $option;
  2366. $option = $function();
  2367. }
  2368. return $option;
  2369. }
  2370. /**
  2371. * option
  2372. *
  2373. * @return string
  2374. */
  2375. public function manage()
  2376. {
  2377. $config = $this->config();
  2378. return $config;
  2379. }
  2380. /**
  2381. * valid
  2382. *
  2383. * @return string
  2384. */
  2385. public function valid()
  2386. {
  2387. //http://placehold.it/350x150
  2388. $config = $this->config();
  2389. if (isset($config['struct'])) {
  2390. $rule = array();
  2391. $rule['required']['regex'] = 'none';
  2392. $rule['required']['alertText'] = '此项不能为空';
  2393. $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
  2394. $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
  2395. $rule['required']['alertTextDateRange'] = '日期范围不可空白';
  2396. foreach ($config['struct'] as $k => $v) {
  2397. if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
  2398. $rule[$k]['regex'] = $v['match'];
  2399. $rule[$k]['alertText'] = $v['desc'];
  2400. }
  2401. }
  2402. }
  2403. $script = '<script>';
  2404. //参考https://blog.csdn.net/wangzl1163/article/details/51071826
  2405. //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
  2406. $script .= '(function($){
  2407. $.fn.validationEngineLanguage = function(){
  2408. };
  2409. $.validationEngineLanguage = {
  2410. newLang: function(){
  2411. $.validationEngineLanguage.allRules = ';
  2412. //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
  2413. $script .= str_replace(array('\\\\', '\\/', '"/', '/"'), array('\\', '/', '/', '/'), json_encode($rule)) . ';';
  2414. $script .= '}
  2415. };
  2416. $.validationEngineLanguage.newLang();
  2417. })(jQuery);';
  2418. $script .= '$(document).ready(function(){
  2419. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  2420. });';
  2421. $script .= '</script>';
  2422. //print_r($script);die;
  2423. return $script;
  2424. }
  2425. /**
  2426. * save
  2427. *
  2428. * @return string
  2429. */
  2430. public function save()
  2431. {
  2432. $config = $this->config();
  2433. if (isset($config['manage']['save'])) {
  2434. return 'yes';
  2435. }
  2436. return 'no';
  2437. }
  2438. }