Database.php 118 KB

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