Database.php 100 KB

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