Database.php 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339
  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. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="javascript:;" onclick="fastEdit($(this),\''.$this->url('add').'\',\''.$k.'\', \'\')">' . $k . '</a>';
  814. } elseif ($v[0] == 'fasts') {
  815. $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>';
  816. } else {
  817. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . $this->url($v[0], false, $v[1]) . '">' . $k . '</a>';
  818. }
  819. } elseif (strpos($v, 'modal|') !== false) {
  820. $t = explode('modal|', $v);
  821. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default layui-btn layuiadmin-btn-list" onclick="showAlert(\'' . $t[1] . '\')">' . $k . '</a>';
  822. } elseif (strpos($v, '|') !== false) {
  823. $t = explode('|', $v);
  824. $result .= $t[0] . '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $t[1] . '>' . $k . '</a>';
  825. } elseif (strpos($v, 'onclick') !== false) {
  826. $result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning layui-btn layuiadmin-btn-list layui-btn-warm" ' . $v . '>' . $k . '</a>';
  827. } elseif (strpos($v, 'http://') !== false) {
  828. //$result .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-default" onclick="jump(\''.Dever::url($v).'\')">'.$k.'</a>';
  829. $result .= '&nbsp;&nbsp;<a class="btn btn-default layui-btn layuiadmin-btn-list" href="' . Dever::url($v) . '">' . $k . '</a>';
  830. } else {
  831. $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>';
  832. }
  833. }
  834. return $result;
  835. }
  836. /**
  837. * 列表页搜索
  838. *
  839. * @return array
  840. */
  841. public function list_search()
  842. {
  843. # 新增权限
  844. if (Dever::load('manage/auth.oper', 2) == false) {
  845. Dever::alert('你没有权限');
  846. }
  847. $config = $this->config();
  848. $result = '';
  849. # 搜索
  850. if (isset($config['struct']) && isset($config['manage']['search'])) {
  851. $search = Dever::preInput('search_');
  852. $node = Html::node(array(' style="margin-top:0px;"', ''));
  853. $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>';
  854. //$result .= '<form id="f1" action="'.$this->url('list').'" method="post">';
  855. $prefix = 'search_';
  856. $result .= $node[0];
  857. if (isset($config['manage']['search']['linkage'])) {
  858. foreach ($config['manage']['search']['linkage'] as $k => $v) {
  859. $this->list_search_linkage($result, $search, $prefix . 'linkage_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  860. $result .= '<br />';
  861. }
  862. }
  863. if (isset($config['manage']['search']['time'])) {
  864. foreach ($config['manage']['search']['time'] as $k => $v) {
  865. $this->list_search_time($result, $search, $prefix, $k, $v);
  866. }
  867. }
  868. if (isset($config['manage']['search']['date'])) {
  869. foreach ($config['manage']['search']['date'] as $k => $v) {
  870. $this->list_search_time($result, $search, $prefix, $k, $v, 'date');
  871. }
  872. }
  873. if (isset($config['manage']['search']['select'])) {
  874. $this->list_search_br($result);
  875. foreach ($config['manage']['search']['select'] as $k => $v) {
  876. $bind = array();
  877. $parent = '';
  878. $option = $this->option($v['option']);
  879. if (isset($config['manage']['search_parent'][$k])) {
  880. $bind = array
  881. (
  882. 'onchange',
  883. 'setOption',
  884. 'search_option_' . $config['manage']['search_parent'][$k]
  885. );
  886. }
  887. elseif (isset($config['manage']['search_child'][$k])) {
  888. $parent = $config['manage']['search_child'][$k];
  889. }
  890. $this->list_search_select($result, $search, $prefix . 'option_' . $k, $v['lang'], $option, $v['default'], $bind, $parent);
  891. }
  892. }
  893. if (isset($config['manage']['search']['exist'])) {
  894. $this->list_search_br($result);
  895. foreach ($config['manage']['search']['exist'] as $k => $v) {
  896. $this->list_search_select($result, $search, $prefix . 'exist_' . $k, $v['lang'], $this->option($v['option']), '');
  897. }
  898. }
  899. if (isset($config['manage']['search']['group'])) {
  900. $this->list_search_br($result);
  901. foreach ($config['manage']['search']['group'] as $k => $v) {
  902. $this->list_search_group($result, $search, $prefix . 'option_' . $k, $v['lang'], $this->option($v['option']), $v['default']);
  903. }
  904. }
  905. if (isset($config['manage']['search']['api'])) {
  906. $this->list_search_br($result);
  907. foreach ($config['manage']['search']['api'] as $k => $v) {
  908. $value = array();
  909. $value['name'] = $prefix . 'api_' . $k;
  910. $value['class'] = 'form-control';
  911. if (isset($search[$value['name']])) {
  912. $value['value'] = $search[$value['name']];
  913. }
  914. if (strpos($v['lang'], '-') !== false) {
  915. $t = explode('-', $v['lang']);
  916. $v['lang'] = $t[0];
  917. }
  918. $value['placeholder'] = $v['lang'];
  919. $result .= Html::text($value, false);
  920. }
  921. }
  922. if (isset($config['manage']['search']['text'])) {
  923. $this->list_search_br($result);
  924. foreach ($config['manage']['search']['text'] as $k => $v) {
  925. $value = array();
  926. $value['name'] = $prefix . 'option_' . $k;
  927. $value['class'] = 'form-control';
  928. if (isset($search[$value['name']])) {
  929. $value['value'] = $search[$value['name']];
  930. }
  931. if (strpos($v, '-') !== false) {
  932. $t = explode('-', $v);
  933. $v = $t[0];
  934. }
  935. $value['placeholder'] = $v;
  936. $result .= Html::text($value, false);
  937. }
  938. }
  939. if (isset($config['manage']['search']['fulltext'])) {
  940. $this->list_search_br($result);
  941. foreach ($config['manage']['search']['fulltext'] as $k => $v) {
  942. $value = array();
  943. $value['name'] = $prefix . 'fulltext_' . $k;
  944. $value['class'] = 'form-control';
  945. if (isset($search[$value['name']])) {
  946. $value['value'] = $search[$value['name']];
  947. }
  948. if (strpos($v, '-') !== false) {
  949. $t = explode('-', $v);
  950. $v = $t[0];
  951. }
  952. $value['placeholder'] = $v;
  953. $result .= Html::text($value, false);
  954. }
  955. }
  956. if (isset($config['manage']['search']['exp'])) {
  957. $result .= '<br />';
  958. $this->list_search_select($result, $search, $prefix . 'exp_col', '选择检索项', $config['manage']['search']['exp']);
  959. $this->list_search_select($result, $search, $prefix . 'exp_type', '', array
  960. (
  961. 3 => '大于',
  962. 4 => '大于等于',
  963. 5 => '小于',
  964. 6 => '小于等于',
  965. ), 1);
  966. $value = array();
  967. $value['name'] = $prefix . 'exp_value';
  968. $value['class'] = 'form-control';
  969. if (isset($search[$value['name']])) {
  970. $value['value'] = $search[$value['name']];
  971. }
  972. $value['placeholder'] = '填写值';
  973. $result .= Html::text($value, false);
  974. }
  975. # 列表页按钮
  976. if (isset($config['manage']['search_button'])) {
  977. $btn .= $this->button_list($config['manage']['search_button']);
  978. }
  979. $result .= $btn . $node[1];
  980. //$result .= '</form>';
  981. # 增加每页显示条数
  982. $config['manage']['num'] = $this->getNumConfig($config);
  983. if ($config['manage']['num']) {
  984. $result = $this->num($result, $config['manage']['num']);
  985. }
  986. }
  987. //print_r($result);die;
  988. return $result;
  989. }
  990. private function list_search_br(&$result)
  991. {
  992. if (strpos($result, '&nbsp;&nbsp;') && !strpos($result, '<br />')) {
  993. $result .= '<br />';
  994. }
  995. }
  996. /**
  997. * 获取条数配置
  998. *
  999. * @return array
  1000. */
  1001. private function getNumConfig($config)
  1002. {
  1003. if (isset($config['manage']['list_type'])) {
  1004. return false;
  1005. }
  1006. if (isset($config['manage']['num']) && $config['manage']['num'] == false) {
  1007. return false;
  1008. }
  1009. if (!isset($config['manage']['num'])) {
  1010. $config['manage']['num'] = array(20,50,100);
  1011. }
  1012. return $config['manage']['num'];
  1013. }
  1014. /**
  1015. * 生成条数的html
  1016. *
  1017. * @return string
  1018. */
  1019. private function num($result, $config)
  1020. {
  1021. $limit = '';
  1022. $cur = Dever::input('search_limit', 0);
  1023. foreach($config as $k => $v) {
  1024. if ($cur == $k) {
  1025. $btn = 'success';
  1026. } else {
  1027. $btn = 'default';
  1028. }
  1029. $url = $this->url('list', 0, false, '&search_limit=' . $k);
  1030. $limit .= '<a href="'.$url.'" style="width:60px;font-weight:bold;" class="btn btn-'.$btn.'">'.$v.'</a> ';
  1031. }
  1032. $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>';
  1033. if (layadmin()) {
  1034. $num = '';
  1035. }
  1036. $result .= $num;
  1037. return $result;
  1038. }
  1039. /**
  1040. * 列表页表格头
  1041. *
  1042. * @return array
  1043. */
  1044. public function list_thead($type = false)
  1045. {
  1046. # 新增权限
  1047. if (Dever::load('manage/auth.oper', 1) == false) {
  1048. Dever::alert('你没有权限');
  1049. }
  1050. $config = $this->config();
  1051. $result = array();
  1052. if (isset($config['struct'])) {
  1053. if (isset($config['manage']['list']) && $config['manage']['list'] == 'update') {
  1054. # 验证头部权限 这里如果是多个选择权限的话,暂时无法实现。。。
  1055. if (isset($config['top']) && is_string($config['top'])) {
  1056. $top = Dever::load('manage/auth.getTop', array($config['top']));
  1057. if ($top) {
  1058. $url = $this->url('update', $top['value']);
  1059. }
  1060. } else {
  1061. $url = $this->url('update', 1);
  1062. }
  1063. return Dever::location($url);
  1064. } else {
  1065. if (isset($config['manage']['mul'])) {
  1066. if ($type == 'layui') {
  1067. $layui = array
  1068. (
  1069. 'field' => 'checkbox',
  1070. 'title' => '<input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list" lay-ignore/>',
  1071. 'fixed' => 'left',
  1072. );
  1073. $result[] = $layui;
  1074. } else {
  1075. $result[] = '<th><input type="checkbox" class="checkbox-checkall" name="checkall" id="checkall" value="list"/></th>';
  1076. }
  1077. }
  1078. $data = array();
  1079. $data = $this->getAdminInfo($data);
  1080. foreach ($config['struct'] as $k => $v) {
  1081. if (isset($v['list']) && $v['list']) {
  1082. # 处理权限
  1083. if (isset($v['auth'])) {
  1084. $auth = $this->value($v['auth'], $data);
  1085. if (!$auth) {
  1086. continue;
  1087. }
  1088. }
  1089. if (isset($v['list_name'])) {
  1090. $v['name'] = $v['list_name'];
  1091. } else {
  1092. $temp = Html::cue(array('name' => $v['name']));
  1093. $v['name'] = $temp['name'];
  1094. }
  1095. if (!isset($v['level'])) {
  1096. $v['level'] = $config['level'];
  1097. }
  1098. if (isset($v['search']) && is_string($v['search']) && strpos($v['search'], 'order') !== false) {
  1099. $link = Dever::url();
  1100. $order = 'search_order_' . $k . '';
  1101. if (strpos($link, $order) !== false) {
  1102. $link = preg_replace('/[?|&]' . $order . '=(desc|asc)/i', '{order}', $link);
  1103. } else {
  1104. $link .= '{order}';
  1105. }
  1106. $search = Dever::input($order);
  1107. $cancel = '';
  1108. if ($search) {
  1109. $asc = $search;
  1110. $cancel = '&nbsp;<a class="glyphicon glyphicon-remove-sign" style="color:black;" href="' . str_replace('{order}', '', $link) . '" title="取消排序"></a>';
  1111. } else {
  1112. $asc = 'desc';
  1113. if (!isset($v['order']) && $k != 'id') {
  1114. $cancel = '&nbsp;<a class="glyphicon glyphicon-circle-arrow-down" style="color:black;" href="' . str_replace('{order}', '&' . $order . '=desc', $link) . '" title="降序"></a>';
  1115. }
  1116. }
  1117. if ($asc == 'asc') {
  1118. $asc = 'desc';
  1119. $icon = 'down';
  1120. $text = '降序';
  1121. } else {
  1122. $asc = 'asc';
  1123. $icon = 'up';
  1124. $text = '升序';
  1125. }
  1126. $link = str_replace('{order}', '&' . $order . '=' . $asc, $link);
  1127. if ($type == 'layui') {
  1128. $layui = array
  1129. (
  1130. 'field' => $k,
  1131. 'title' => '<a href="' . $link . '" title="' . $text . '" style="color:black;">' . $v['name'] . '&nbsp;<span class="layui-icon layui-icon-' . $icon . '"></span></a>',
  1132. );
  1133. $result[] = $layui;
  1134. } else {
  1135. $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>';
  1136. }
  1137. } else {
  1138. if ($type == 'layui') {
  1139. if ($k == 'id' || isset($v['fixed'])) {
  1140. $layui = array
  1141. (
  1142. 'field' => $k,
  1143. 'title' => $v['name'],
  1144. 'fixed' => 'left',
  1145. );
  1146. } else {
  1147. $layui = array
  1148. (
  1149. 'field' => $k,
  1150. 'title' => $v['name'],
  1151. );
  1152. }
  1153. $result[] = $layui;
  1154. } else {
  1155. $result[] = '<th data-priority="'.$v['level'].'">' . $v['name'] . '</th>';
  1156. }
  1157. }
  1158. }
  1159. }
  1160. if ((Dever::load('manage/auth.oper', 3) != false || Dever::load('manage/auth.oper', 5) != false) && isset($config['manage']['_list']['value'])) {
  1161. if ($type == 'layui') {
  1162. $layui = array
  1163. (
  1164. 'field' => $config['manage']['_list']['col'],
  1165. 'title' => $config['manage']['_list']['name'],
  1166. 'fixed' => 'right',
  1167. );
  1168. $result[] = $layui;
  1169. } else {
  1170. $result[] = '<th data-priority="1">' . $config['manage']['_list']['name'] . '</th>';
  1171. }
  1172. }
  1173. }
  1174. }
  1175. return $result;
  1176. }
  1177. # layui表头
  1178. public function list_thead_layui()
  1179. {
  1180. $html = 'config.table = {};config.table.cols = [];';
  1181. $data = array($this->list_thead('layui'));
  1182. $data = Dever::json_encode($data);
  1183. $html .= 'config.table.cols = ' . $data;
  1184. return $html;
  1185. }
  1186. # layui表的数据 没有使用其异步方式
  1187. public function list_tbody_layui()
  1188. {
  1189. $html = 'config.table.data = [];';
  1190. $data = $this->list_tbody(false, 'layui');
  1191. $data = Dever::json_encode($data);
  1192. $html .= 'config.table.data = ' . $data;
  1193. return $html;
  1194. }
  1195. /**
  1196. * 导出列表
  1197. *
  1198. * @return array
  1199. */
  1200. public function list_excel_api()
  1201. {
  1202. Dever::$global['base']['excel'] = 1;
  1203. $data = $this->list_tbody(true);
  1204. if ($data) {
  1205. $config = $this->config();
  1206. if (isset($config['manage']['excel']) && $config['manage']['excel']) {
  1207. $method = 'excel';
  1208. $info = $this->info();
  1209. $data = $this->getAdminInfo($data);
  1210. $this->excel($info, $data, $config);
  1211. }
  1212. }
  1213. //print_r($data);die;
  1214. }
  1215. private function excel($info, $data, $config)
  1216. {
  1217. $file = $info['list_header'] . '的' . $info['list_desc'] . '-' . $info['project_name'];
  1218. $header = $body = array();
  1219. $i = 0;
  1220. foreach ($config['struct'] as $k => $v) {
  1221. if (isset($v['list']) && $v['list']) {
  1222. # 处理权限
  1223. if (isset($v['auth'])) {
  1224. $auth = $this->value($v['auth'], $data);
  1225. if (!$auth) {
  1226. continue;
  1227. }
  1228. }
  1229. //$v['name'] = mb_convert_encoding($v['name'],'gb2312','utf-8');
  1230. $header[$i] = $v['name'];
  1231. $i++;
  1232. $j = 0;
  1233. foreach ($data as $ki => $vi) {
  1234. $body[$j][$i] = '';
  1235. if (isset($vi[$k])) {
  1236. $value = $vi[$k];
  1237. if (is_string($v['list'])) {
  1238. $value = $this->value($v['list'], $data[$ki], $config['struct']);
  1239. }
  1240. if (isset($v['option'])) {
  1241. $value = $this->getOptionValue($value, $v);
  1242. }
  1243. //$value = mb_convert_encoding($value,'gb2312','utf-8');
  1244. $body[$j][$i] = $value;
  1245. $j++;
  1246. }
  1247. }
  1248. }
  1249. }
  1250. Dever::excelExport($body, $header, $file);
  1251. }
  1252. private function getOptionValue($value, $v)
  1253. {
  1254. # 验证option是否是匿名函数
  1255. $v['option'] = $this->option($v['option']);
  1256. # 位运算
  1257. if (isset($v['bit'])) {
  1258. $ts = array();
  1259. foreach ($v['option'] as $tm => $tv) {
  1260. if (isset($v['bit'][$tm]) && ($value & $tm) > 0) {
  1261. $ts[] = $tv;
  1262. }
  1263. }
  1264. $value = implode(',', $ts);
  1265. }
  1266. if ((isset($v['child_name']) || (isset($v['show']) && is_string($v['show'])))) {
  1267. if (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1268. $value = $v['option'][$value]['name'];
  1269. } else {
  1270. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1271. }
  1272. } else {
  1273. if (strstr($value, ',')) {
  1274. $temp = explode(',', $value);
  1275. $t = array();
  1276. foreach ($temp as $vv) {
  1277. if (isset($v['option'][$vv]) && is_array($v['option'][$vv])) {
  1278. $t[] = $v['option'][$vv]['name'];
  1279. } elseif(isset($v['option'][$vv])) {
  1280. $t[] = $v['option'][$vv];
  1281. } else {
  1282. $t[] = $vv;
  1283. }
  1284. }
  1285. $value = implode("\r\n", $t);
  1286. } elseif (isset($v['option'][$value]) && is_array($v['option'][$value])) {
  1287. $value = $v['option'][$value]['name'];
  1288. } else {
  1289. $value = isset($v['option'][$value]) ? $v['option'][$value] : $value;
  1290. }
  1291. }
  1292. return $value;
  1293. }
  1294. private function _getChr($start, $num)
  1295. {
  1296. $num = $start + $num;
  1297. $max = floor($num / 91);
  1298. if ($max > 0) {
  1299. $num = $num - (91 * $max) + $start;
  1300. $num = chr($start) . chr($num);
  1301. } else {
  1302. $num = chr($num);
  1303. }
  1304. return $num;
  1305. }
  1306. /**
  1307. * 列表页数据列表 检索
  1308. *
  1309. * @return array
  1310. */
  1311. private function list_tbody_search($config, $param, $high, $search)
  1312. {
  1313. # 根据api的数据检索到id
  1314. $api = Dever::preInput('search_api_');
  1315. if ($api) {
  1316. foreach ($api as $k => $v) {
  1317. if ($v) {
  1318. unset($search[$k]);
  1319. $k = str_replace('search_api_', '', $k);
  1320. # 设定检索高亮
  1321. $high[$k] = $v;
  1322. if (isset($config['manage']['search']['api'][$k]['api'])) {
  1323. $col = $config['manage']['search']['api'][$k]['col'];
  1324. $option = array($col => $v);
  1325. $v = Dever::load($config['manage']['search']['api'][$k]['api'], $option);
  1326. $result = $config['manage']['search']['api'][$k]['result'];
  1327. if ($v && is_array($v)) {
  1328. if (isset($v[$result])) {
  1329. $v = $v[$result];
  1330. } else {
  1331. if ($result == 'id') {
  1332. $v = array_keys($v);
  1333. } else {
  1334. $t = array();
  1335. foreach ($v as $k1 => $v1) {
  1336. $t[] = $v1[$result];
  1337. }
  1338. $v = $t;
  1339. }
  1340. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1341. $param['option'][$config['manage']['search']['api'][$k]['search']] = array('yes', 'in');
  1342. } else {
  1343. $param['option'][$k] = array('yes', 'in');
  1344. }
  1345. }
  1346. } else {
  1347. $v = '-100';
  1348. }
  1349. }
  1350. if (isset($config['manage']['search']['api'][$k]['search'])) {
  1351. $param['option_' . $config['manage']['search']['api'][$k]['search']] = $v;
  1352. } else {
  1353. $param['option_' . $k] = $v;
  1354. }
  1355. }
  1356. }
  1357. }
  1358. # 检索有无值
  1359. $exist = Dever::preInput('search_exist_');
  1360. if ($exist) {
  1361. foreach ($exist as $k => $v) {
  1362. if ($v) {
  1363. unset($search[$k]);
  1364. $k = str_replace('search_exist_', '', $k);
  1365. if ($v == 'yes') {
  1366. # 有值
  1367. $param['option'][$k] = array('yes', '!=');
  1368. $param['option_' . $k] = 'null';
  1369. } elseif ($v == 'no') {
  1370. # 无值
  1371. $param['option'][$k] = array('yes', '=');
  1372. $param['option_' . $k] = 'null';
  1373. } elseif (strpos($v, '|')) {
  1374. # 有无值或者自定义的值
  1375. $temp = explode('|', $v);
  1376. $param['option_' . $k] = $temp[1];
  1377. if ($temp[0] == 'yes') {
  1378. $param['option'][$k] = array('yes', '!=');
  1379. $param['option'][$k . '_t1'] = array('yes-' . $k, '!=');
  1380. } else {
  1381. $param['option'][$k] = array('yes', '=', 'and(');
  1382. $param['option'][$k . '_t1'] = array('yes-' . $k, '=', 'or)');
  1383. }
  1384. $param['option_' . $k . '_t1'] = 'null';
  1385. } else {
  1386. # 自定义的值
  1387. $param['option_' . $k] = $v;
  1388. }
  1389. }
  1390. }
  1391. }
  1392. $fulltext = Dever::preInput('search_fulltext_');
  1393. if ($fulltext) {
  1394. $fulltext_state = false;
  1395. foreach ($fulltext as $k => $v) {
  1396. if ($v) {
  1397. unset($search[$k]);
  1398. $k = str_replace('search_fulltext_', '', $k);
  1399. $param['option_' . $k] = $v;
  1400. # 设定检索高亮
  1401. $high[$k] = $v;
  1402. $fulltext_state = true;
  1403. }
  1404. }
  1405. $this->search = true;
  1406. }
  1407. $linkage = Dever::preInput('search_linkage_');
  1408. if ($linkage) {
  1409. foreach ($linkage as $k => $v) {
  1410. if ($v) {
  1411. unset($search[$k]);
  1412. $k = str_replace('search_linkage_', '', $k);
  1413. if (is_array($v)) {
  1414. $v = implode(',', $v);
  1415. }
  1416. if ($v != -1) {
  1417. $v = Dever::defaultValue($v);
  1418. $param['option_' . $k] = $v;
  1419. # 设定检索高亮
  1420. $high[$k] = $v;
  1421. }
  1422. }
  1423. }
  1424. $this->search = true;
  1425. }
  1426. $exp = Dever::preInput('search_exp_');
  1427. if ($exp) {
  1428. $k = $search['search_exp_col'];
  1429. $v = $search['search_exp_value'];
  1430. $param['option_' . $k] = $v;
  1431. $param['search_type'] = $search['search_exp_type'];
  1432. $this->search = true;
  1433. }
  1434. $order = Dever::preInput('search_order_');
  1435. if ($order) {
  1436. foreach ($order as $k => $v) {
  1437. $k = str_replace('search_order_', '', $k);
  1438. $param['order'][0][$k] = $v;
  1439. unset($search[$k]);
  1440. }
  1441. }
  1442. foreach ($search as $k => $v) {
  1443. if ($v) {
  1444. if (strpos($k, 'option_') !== false) {
  1445. //Dever::setInput(str_replace('search_', '', $k), $v);
  1446. if (is_array($v)) {
  1447. if ($v[0] == 0) {
  1448. continue;
  1449. }
  1450. $v = str_replace(',0', '', implode(',', $v));
  1451. $t = explode(',', $v);
  1452. $parent = end($t);
  1453. $v .= '%';
  1454. }
  1455. $param[str_replace('search_', '', $k)] = $v;
  1456. $this->search = true;
  1457. } elseif ($k == 'search_limit') {
  1458. $num = $this->getNumConfig($config);
  1459. if ($num) {
  1460. $param['page'][0] = $num[$v];
  1461. }
  1462. }
  1463. }
  1464. }
  1465. return array($param, $high);
  1466. }
  1467. private function list_tbody_mul($param)
  1468. {
  1469. $mul = Dever::load('manage/auth.oper', 3) ? Dever::preInput('mul_') : false;
  1470. if (Dever::input('method') == 'mul' && $mul && $mul['mul_type'] > 0) {
  1471. if ($mul['mul_type'] == 1 && empty($mul['mul_where_id'])) {
  1472. Dever::alert('您还未选择任何数据条目');
  1473. }
  1474. Dever::$global['base']['mul_type'] = $mul['mul_type'];
  1475. unset($mul['mul_type']);
  1476. foreach ($mul as $k => $v) {
  1477. if ($v) {
  1478. if (is_array($v)) {
  1479. $v = implode(',', $v);
  1480. }
  1481. $param[str_replace('mul_', '', $k)] = $v;
  1482. }
  1483. }
  1484. if (isset($param)) {
  1485. $method = $this->project . '/' . $this->table . '-updatemul';
  1486. $state = Dever::load($method, $param);
  1487. }
  1488. Dever::alert('reload');
  1489. }
  1490. }
  1491. /**
  1492. * 列表页数据列表:图片形式
  1493. *
  1494. * @return array
  1495. */
  1496. public function list_photo()
  1497. {
  1498. $config = $this->config();
  1499. $result = array();
  1500. if (isset($config['manage']['photo'])) {
  1501. $high = array();
  1502. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  1503. $param = array();
  1504. $parent = 0;
  1505. if ($search) {
  1506. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  1507. }
  1508. if (empty($param['page'])) {
  1509. $num = $this->getNumConfig($config);
  1510. if ($num) {
  1511. $param['page'][0] = $num[0];
  1512. }
  1513. }
  1514. $method = $this->project . '/' . $this->table . '-list';
  1515. $result = Dever::load($method, $param);
  1516. if ($result) {
  1517. foreach ($result as $k => $v) {
  1518. $result[$k] = Dever::load($config['manage']['photo'], $v);
  1519. $result[$k]['button'] = $this->list_tbody_button($config, $v, 'div');
  1520. }
  1521. }
  1522. }
  1523. return $result;
  1524. }
  1525. /**
  1526. * 列表页数据列表:表格形式
  1527. *
  1528. * @return array
  1529. */
  1530. public function list_tbody($excel = false, $type = false)
  1531. {
  1532. # 新增权限
  1533. if (Dever::load('manage/auth.oper', 1) == false) {
  1534. Dever::alert('你没有权限');
  1535. }
  1536. if (Dever::input('page_content') == 1) {
  1537. return;
  1538. }
  1539. $config = $this->config();
  1540. $high = array();
  1541. $search = Dever::load('manage/auth.oper', 2) ? Dever::preInput('search_') : false;
  1542. $param = array();
  1543. $parent = 0;
  1544. if ($search) {
  1545. list($param, $high) = $this->list_tbody_search($config, $param, $high, $search);
  1546. }
  1547. if (empty($param['page'])) {
  1548. $num = $this->getNumConfig($config);
  1549. if ($num) {
  1550. $param['page'][0] = $num[0];
  1551. }
  1552. }
  1553. # 批量更新
  1554. $this->list_tbody_mul($param);
  1555. $result = $return = array();
  1556. if ($excel == true) {
  1557. $method = $this->project . '/' . $this->table . '-all';
  1558. } else {
  1559. $method = $this->project . '/' . $this->table . '-list';
  1560. }
  1561. //print_r($param);die;
  1562. $data = Dever::load($method, $param);
  1563. if (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'parent') {
  1564. $parent = array();
  1565. $child = array();
  1566. foreach ($data as $k => $v) {
  1567. if ($v[$config['name'] . '_id'] <= 0) {
  1568. $parent[$k] = $v;
  1569. } else {
  1570. $v['name'] = '|-----' . $v['name'];
  1571. $child[$v[$config['name'] . '_id']][$k] = $v;
  1572. }
  1573. }
  1574. if ($parent) {
  1575. $data = array();
  1576. foreach ($parent as $k => $v) {
  1577. $data[$v['id']] = $v;
  1578. if (isset($child[$v['id']])) {
  1579. foreach ($child[$v['id']] as $i => $j) {
  1580. $data[$j['id']] = $j;
  1581. }
  1582. }
  1583. }
  1584. }
  1585. } elseif (isset($config['manage']['list_type']) && $config['manage']['list_type'] == 'tree') {
  1586. $data = $this->tree($data, $config, -1);
  1587. }
  1588. if ($excel == true) {
  1589. return $data;
  1590. }
  1591. if (Dever::input('page_type') == 1) {
  1592. Dever::$global['manage']['list_data'] = $data;
  1593. return;
  1594. }
  1595. //print_r($data);die;
  1596. //print_r(Helper::page("current"));die;
  1597. if ($data && isset($config['struct'])) {
  1598. $i = 0;
  1599. $pg = Dever::input('pg', 1);
  1600. $cur = Dever::input('search_limit', 0);
  1601. $num = $this->getNumConfig($config);
  1602. foreach ($data as $k => $v) {
  1603. $data[$k] = $this->getAdminInfo($data[$k]);
  1604. $data[$k]['i'] = $i;
  1605. $ii = intval($num[$cur])*($pg-1);
  1606. $data[$k]['r'] = $i+1+$ii;
  1607. $result[$k] = '<tr>';
  1608. $return[$i] = array();
  1609. if (isset($config['manage']['mul'])) {
  1610. $checkbox = '<input type="checkbox" name="mul_where_id[]" class="checkbox-checkall-list" lay-ignore value="' . $v['id'] . '"/>';
  1611. $result[$k] .= '<td>'.$checkbox.'</td>';
  1612. $return[$i]['checkbox'] = $checkbox;
  1613. }
  1614. foreach ($config['struct'] as $ki => $vi) {
  1615. # 处理同步
  1616. if (isset($vi['sync']) && strpos($ki, '-')) {
  1617. $temp = explode('-', $ki);
  1618. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $vi['sync'][1] => $v[$vi['sync'][0]]));
  1619. $v[$ki] = isset($load[$temp[2]]) ? $load[$temp[2]] : $vi['default'];
  1620. }
  1621. if (isset($vi['list']) && $vi['list']) {
  1622. if (empty($v[$ki])) {
  1623. $v[$ki] = $vi['default'];
  1624. }
  1625. # 处理权限
  1626. if (isset($vi['auth'])) {
  1627. $auth = $this->value($vi['auth'], $data[$k]);
  1628. if (!$auth) {
  1629. continue;
  1630. }
  1631. }
  1632. $show = $v[$ki];
  1633. if (is_string($vi['list'])) {
  1634. $show = $this->value($vi['list'], $data[$k], $config['struct']);
  1635. }
  1636. if (isset($vi['key']) && $vi['update'] != 'editor') {
  1637. $show = Dever::upload($show);
  1638. }
  1639. if (isset($vi['modal'])) {
  1640. $show = Html::modal($this->value($vi['modal'], $data[$k], $config['struct']), $show);
  1641. } elseif (isset($vi['option'])) {
  1642. # 验证option是否是匿名函数
  1643. $vi['option'] = $this->option($vi['option']);
  1644. # 位运算
  1645. if (isset($vi['bit'])) {
  1646. $ts = array();
  1647. foreach ($vi['option'] as $tm => $tv) {
  1648. if (isset($vi['bit'][$tm]) && ($show & $tm) > 0) {
  1649. $ts[] = $tv;
  1650. }
  1651. }
  1652. $show = implode(',', $ts);
  1653. }
  1654. if ((isset($vi['child_name']) || (isset($vi['show']) && is_string($vi['show'])))) {
  1655. if (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  1656. $show = $vi['option'][$show]['name'];
  1657. } else {
  1658. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  1659. }
  1660. }
  1661. //elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']) || $ki == 'status')
  1662. elseif ($config['state'] == 1 && (isset($vi['edit']) && $vi['edit']))
  1663. {
  1664. $vi['name'] = 'up_col_' . $ki;
  1665. $vi['value'] = $v[$ki];
  1666. $m = 'select';
  1667. if (isset($vi['update']) && $vi['update'] == 'group') {
  1668. $m = 'group';
  1669. }
  1670. $show = Html::$m($vi, 'form-list', '', 'style="min-width: 100px;" data-old="'.$show.'" onchange="update($(this), \'' . $v['id'] . '\', \'' . $this->project . '\', \'' . $this->table . '\')"');
  1671. } else {
  1672. if (strstr($show, ',')) {
  1673. $temp = explode(',', $show);
  1674. $t = array();
  1675. foreach ($temp as $vv) {
  1676. if (isset($vi['option'][$vv]) && is_array($vi['option'][$vv])) {
  1677. $t[] = $vi['option'][$vv]['name'];
  1678. } elseif(isset($vi['option'][$vv])) {
  1679. $t[] = $vi['option'][$vv];
  1680. } else {
  1681. $t[] = $vv;
  1682. }
  1683. }
  1684. $show = implode('<br />', $t);
  1685. } elseif (isset($vi['option'][$show]) && is_array($vi['option'][$show])) {
  1686. $show = $vi['option'][$show]['name'];
  1687. } else {
  1688. $show = isset($vi['option'][$show]) ? $vi['option'][$show] : $show;
  1689. }
  1690. }
  1691. }
  1692. $text = $show;
  1693. if ($high && isset($high[$ki])) {
  1694. if (isset($v['s_' . $ki])) {
  1695. $text = $v['s_' . $ki];
  1696. $text = str_replace('<em class="dever_highlight">', '<font color="red" class="dever_highlight">', $text);
  1697. $text = str_replace('</em>', '</font>', $text);
  1698. } else {
  1699. $text = preg_replace('/('.$high[$ki].')/i', '<font color="red" class="dever_highlight">${1}</font>', $text);
  1700. }
  1701. }
  1702. if (!isset($vi['option']) && isset($vi['edit']) && $vi['edit']) {
  1703. //$url = Dever::url($vi['edit'] . '?where_id=' . $v['id'] . '&col=' . $vi['col']. '&key=' . $this->project . '&table=' . $this->table);
  1704. $url = $this->url('updateAction');
  1705. $vi['edit'] = $vi['edit'] == 'textarea' ? $vi['edit'] : 'text';
  1706. $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>';
  1707. $result[$k] .= '<td >' . $text . '</td>';
  1708. if (isset($return[$i][$ki])) {
  1709. $text = $return[$i][$ki] . $text;
  1710. }
  1711. $return[$i][$ki] = $text;
  1712. } else {
  1713. $result[$k] .= '<td>' . $text . '</td>';
  1714. if (isset($return[$i][$ki])) {
  1715. $text = $return[$i][$ki] . $text;
  1716. }
  1717. $return[$i][$ki] = $text;
  1718. }
  1719. }
  1720. }
  1721. $button = $this->list_tbody_button($config, $data[$k]);
  1722. $result[$k] .= $button;
  1723. $return[$i]['manage'] = str_replace(array('<td>', '</td>'), '', $button);
  1724. $result[$k] .= '</tr>';
  1725. $i++;
  1726. }
  1727. }
  1728. /*
  1729. if ($result) {
  1730. $thead = $this->list_thead();
  1731. if ($thead) {
  1732. $k = $k + 1;
  1733. $result[$k] = '<tr>';
  1734. foreach ($thead as $k => $v) {
  1735. $result[$k] .= $v;
  1736. }
  1737. $result[$k] .= '</tr>';
  1738. }
  1739. }
  1740. */
  1741. if ($type) {
  1742. return $return;
  1743. }
  1744. return $result;
  1745. }
  1746. private function list_tbody_button($config, $data, $type = 'td')
  1747. {
  1748. $result = '';
  1749. if (isset($config['manage']['_list']['value'])) {
  1750. $result = '<'.$type.'>';
  1751. if ($config['state'] == 2) {
  1752. if (isset($config['manage']['_list']['value']['update'])) {
  1753. unset($config['manage']['_list']['value']['update']);
  1754. }
  1755. if (isset($config['manage']['_list']['value']['delete'])) {
  1756. $config['manage']['_list']['value']['delete'] = '恢复';
  1757. }
  1758. }
  1759. foreach ($config['manage']['_list']['value'] as $kj => $vj) {
  1760. $pj = false;
  1761. $h = '<span class="am-icon-pencil-square-o"></span>';
  1762. $oper = true;
  1763. if ($kj == 'update') {
  1764. $oper = Dever::load('manage/auth.oper', 3);
  1765. } elseif ($kj == 'delete') {
  1766. $oper = Dever::load('manage/auth.oper', 5);
  1767. $h = '<span class="am-icon-trash-o"></span>';
  1768. }
  1769. if (is_array($vj) && isset($vj[1])) {
  1770. if (isset($vj[2])) {
  1771. $oper = $this->value($vj[2], $data);
  1772. }
  1773. if ($oper && strpos($vj[1], 'modal|') === false) {
  1774. $pj = $this->value($vj[1], $data);
  1775. $vjn = $vj[0];
  1776. }
  1777. } else {
  1778. $vjn = $vj;
  1779. }
  1780. if ($oper == true) {
  1781. if ($kj == 'delete') {
  1782. $class = 'layui-btn layui-btn-danger';
  1783. } else {
  1784. $class = 'layui-btn';
  1785. }
  1786. if (layadmin()) {
  1787. $class .= ' layui-btn-xs';
  1788. }
  1789. if (strpos($kj, 'edits') !== false) {
  1790. if (!isset($vj[1])) {
  1791. $vj[1] = '';
  1792. }
  1793. $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;';
  1794. } elseif (strpos($kj, 'edit') !== false) {
  1795. if (!isset($vj[1])) {
  1796. $vj[1] = '';
  1797. }
  1798. $result .= '<a href="javascript:;" onclick="fastEdit($(this), \'' . $this->url($kj, $data['id']) . '\', \''.$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;';
  1799. } elseif (strpos($kj, 'oper') !== false) {
  1800. $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;';
  1801. } elseif (isset($vj[1]) && strpos($vj[1], 'modal|') !== false) {
  1802. $t = explode('|', $vj[1]);
  1803. $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;';
  1804. } elseif (isset($vj[1])) {
  1805. $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;';
  1806. } else {
  1807. $result .= '<span style="margin-left:5px;margin-right:10px;">' . $vj[0] . '</span>';
  1808. }
  1809. }
  1810. }
  1811. $result .= '</'.$type.'>';
  1812. }
  1813. return $result;
  1814. }
  1815. /**
  1816. * 多级分类
  1817. *
  1818. * @return array
  1819. */
  1820. private function tree($data, $config, $parent = 0)
  1821. {
  1822. $key = $config['name'] . '_id';
  1823. $result = array();
  1824. $this->treeData($data, $result, $key, $parent);
  1825. return $result;
  1826. }
  1827. private function treeData($array, &$result, $key, $parent_id = 0, $level = 0)
  1828. {
  1829. if (empty($array)) {
  1830. return;
  1831. }
  1832. $level++;
  1833. foreach ($array as $k => $v) {
  1834. if (isset($v[$key]) && $v[$key] == $parent_id) {
  1835. $v['level'] = $level;
  1836. $v['name'] = $this->treeName($v['name'], $level);
  1837. $result[] = $v;
  1838. unset($array[$k]);
  1839. $this->treeData($array, $result, $key, $v['id'], $level);
  1840. }
  1841. }
  1842. }
  1843. private function treeName($name, $level = 1)
  1844. {
  1845. $string = '';
  1846. if ($level > 1) {
  1847. /*
  1848. $num = 4;
  1849. $string = '-';
  1850. //STR_PAD_LEFT
  1851. $string = str_pad('|', $level * $num, $string);
  1852. */
  1853. $string = str_repeat(' ',$level-1);
  1854. $string .= '|—';
  1855. }
  1856. return $string . $name;
  1857. }
  1858. /**
  1859. * 列表页批量管理
  1860. *
  1861. * @return array
  1862. */
  1863. public function list_mul()
  1864. {
  1865. # 新增权限:更新权限
  1866. if (Dever::load('manage/auth.oper', 3) == false) {
  1867. Dever::alert('你没有权限');
  1868. }
  1869. $config = $this->config();
  1870. $result = '';
  1871. if (isset($config['struct']) && isset($config['manage']['mul'])) {
  1872. $mul = Dever::preInput('mul_');
  1873. $node = Html::node(array('class="am-u-sm-12" style="margin-top:10px;"', 'class="am-form-group am-input-group-sm"'));
  1874. $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>';
  1875. $prefix = 'mul_';
  1876. $result .= $node[0];
  1877. $default = 0;
  1878. $option = array
  1879. (
  1880. 1 => '本页选中的数据',
  1881. );
  1882. # 只有当有搜索条件时才会出现
  1883. if (Dever::load('manage/auth.oper', 2) && $this->search == true) {
  1884. $option[2] = '所有页面的数据';
  1885. $default = 2;
  1886. }
  1887. $this->list_search_select($result, $mul, $prefix . 'type' . '" id="' . $prefix . 'type', '请选择要更新的数据', $option, $default);
  1888. foreach ($config['struct'] as $k => $v) {
  1889. if ($k == 'state' && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  1890. $v['option'] = Dever::config('base')->state;
  1891. if ($this->getState() == 2) {
  1892. unset($v['option'][2]);
  1893. } else {
  1894. unset($v['option'][1]);
  1895. }
  1896. $v['edit'] = true;
  1897. }
  1898. if (isset($v['edit']) && isset($v['option']) && (is_array($v['option']) || is_object($v['option']))) {
  1899. $result .= '&nbsp;&nbsp;';
  1900. $this->list_search_select($result, $mul, $prefix . 'set_' . $k, $v['name'], $this->option($v['option']), $v['default']);
  1901. }
  1902. }
  1903. $result .= $btn . $node[1];
  1904. }
  1905. //print_r($result);die;
  1906. return $result;
  1907. }
  1908. private function value($value, $data, $struct = array())
  1909. {
  1910. if (!$data) {
  1911. return $value;
  1912. }
  1913. if (is_string($data)) {
  1914. $eval = '$value = ' . $value . ';';
  1915. eval($eval);
  1916. return $value;
  1917. }
  1918. if ($value == 'table' && $struct) {
  1919. $result = $this->struct_data($struct, $data);
  1920. $value = Dever::table($result);
  1921. } elseif (strpos($value, '{') !== false) {
  1922. # 这里用到了/e,注意这里无论如何不能传入$_GET之类的用户参数 2015/7/21更新为callback方式
  1923. //$eval = '$value = ' . preg_replace('/{(.*?)}/e', "\$data['$1']", $value) . ';';
  1924. $func = function ($r) use ($data) {
  1925. if (isset($data[$r[1]])) {
  1926. return $data[$r[1]];
  1927. }
  1928. return false;
  1929. };
  1930. $eval = '$value = ' . preg_replace_callback('/{(.*?)}/', $func, $value) . ';';
  1931. eval($eval);
  1932. }
  1933. return $value;
  1934. }
  1935. /**
  1936. * update
  1937. *
  1938. * @return array
  1939. */
  1940. public function update()
  1941. {
  1942. $config = $this->config();
  1943. $result = array();
  1944. $prefix = 'update';
  1945. $data = array();
  1946. if ($this->id) {
  1947. # 新增权限
  1948. if (Dever::load('manage/auth.oper', 3) == false) {
  1949. Dever::alert('你没有权限');
  1950. }
  1951. $data = $this->load('one', $this->id);
  1952. if ($data) {
  1953. //$prefix = 'set';
  1954. }
  1955. } else {
  1956. # 新增权限
  1957. if (Dever::load('manage/auth.oper', 4) == false) {
  1958. Dever::alert('你没有权限');
  1959. }
  1960. }
  1961. //print_r($config['manage']['update']);die;
  1962. $data = $this->getAdminInfo($data);
  1963. $col = Dever::input('col');
  1964. foreach ($config['struct'] as $k => $v) {
  1965. if (isset($v['update'])) {
  1966. if ($col && !strstr(',' . $col . ',', ',' . $k . ',')) {
  1967. continue;
  1968. }
  1969. //处理权限
  1970. if (isset($v['auth'])) {
  1971. $auth = $this->value($v['auth'], $data);
  1972. if (!$auth) {
  1973. continue;
  1974. }
  1975. }
  1976. # 处理show模式下的class
  1977. $class = $this->update_class($k, $v, '', $data);
  1978. $result[$k] = '<div class="form-group ' . $class . '"><div class="margin-top">';
  1979. if (layadmin()) {
  1980. $result[$k] = '<div class="layui-form-item ' . $class . '"><div class="layui-col-lg6">';
  1981. }
  1982. $result[$k] .= $this->create_update_html($k, $v, $data);
  1983. $result[$k] .= '</div></div>';
  1984. } elseif (!$col && isset($v['class'])) {
  1985. # 分割线
  1986. $v['name'] = $this->value($v['name'], array('test' => 1));
  1987. if (isset($v['right'])) {
  1988. $this->card_right = true;
  1989. }
  1990. $this->card = true;
  1991. $result[$k] = Html::hr($v);
  1992. }
  1993. }
  1994. if (Dever::input('ajax') == 1) {
  1995. return implode('', $result);
  1996. }
  1997. //print_r($result);die;
  1998. return $result;
  1999. }
  2000. public function card()
  2001. {
  2002. if (isset($this->card_right)) {
  2003. return 'layui-col-md6';
  2004. }
  2005. return 'layui-col-md12';
  2006. }
  2007. public function layui_card()
  2008. {
  2009. if (isset($this->card)) {
  2010. return false;
  2011. }
  2012. return true;
  2013. }
  2014. /**
  2015. * update_class
  2016. *
  2017. * @return string
  2018. */
  2019. public function update_class($name, $param, $prefix = '', $data = array())
  2020. {
  2021. $class = '';
  2022. $key = 'show';
  2023. if (isset($param[$key]) && $param[$key]) {
  2024. $parent = array();
  2025. $child = array();
  2026. if (is_string($param[$key])) {
  2027. parse_str($param[$key], $param[$key]);
  2028. }
  2029. if (is_array($param[$key])) {
  2030. foreach ($param[$key] as $k => $v) {
  2031. if ($k == 'no') {
  2032. $child[$k . '_' . $v] = $key . '_no';
  2033. } elseif (strpos($v, '/')) {
  2034. $parent[$k] = $key . '_' . $k;
  2035. $k = $k . '_ajax';
  2036. $value = '';
  2037. if (isset($data[$name])) {
  2038. $value = $data[$name];
  2039. }
  2040. $v = str_replace('?', '?key='.$name.'&value='.$value.'&source='.$this->name.'&', $v);
  2041. $child[$k] = $key . '_' . $k .'" dever-ajax="'.Dever::url($v).'"';
  2042. } else {
  2043. if (strpos($v, ',')) {
  2044. $temp = explode(',', $v);
  2045. foreach ($temp as $v1) {
  2046. $show = $k . '_' . $v1;
  2047. if ($prefix) {
  2048. $k = str_replace($name, $k, $prefix);
  2049. $show = str_replace($name, $show, $prefix);
  2050. }
  2051. $parent[$k] = $key . '_' . $k;
  2052. $child[$show] = $key . '_' . $show;
  2053. }
  2054. } else {
  2055. $show = $k . '_' . $v;
  2056. if ($prefix) {
  2057. $k = str_replace($name, $k, $prefix);
  2058. $show = str_replace($name, $show, $prefix);
  2059. }
  2060. $parent[$k] = $key . '_' . $k;
  2061. $child[$show] = $key . '_' . $show;
  2062. }
  2063. }
  2064. }
  2065. }
  2066. $class = implode(' ', $parent) . ' ' . implode(' ', $child);
  2067. }
  2068. if (isset($param['control'])) {
  2069. $class .= ' ' . $key . '_input';
  2070. }
  2071. return $class;
  2072. }
  2073. /**
  2074. * update_html
  2075. *
  2076. * @return string
  2077. */
  2078. public function create_update_html($key, $value, $data = array())
  2079. {
  2080. $result = '';
  2081. $value['ext'] = $value['col'] = $key;
  2082. $value['update'] = $value['update'] ? $value['update'] : 'text';
  2083. if (isset($value['match']) && $value['match'] != 'option') {
  2084. if (is_string($value['match']) && strpos($value['match'], '/') !== false) {
  2085. if (strstr($value['match'], 'option||')) {
  2086. $value['valid'] = 'validate[custom[' . $key . ']]';
  2087. } else {
  2088. $value['valid'] = 'validate[required,custom[' . $key . ']]';
  2089. }
  2090. } else {
  2091. $value['valid'] = 'validate[required]';
  2092. }
  2093. }
  2094. if (is_string($value['update']) && strpos($value['update'], 'copy.') !== false) {
  2095. $value['value'] = $value['update'];
  2096. $value['update'] = 'hidden';
  2097. }
  2098. $this->update_html($value, $key, $key, $data, $result);
  2099. return $result;
  2100. }
  2101. /**
  2102. * update_html
  2103. *
  2104. * @return string
  2105. */
  2106. public function update_html($param, $key, $index, $data, &$result)
  2107. {
  2108. if (isset($param['name']) && $param['update'] != 'hidden' && isset($param['update'])) {
  2109. $result .= Html::pageLeft($param);
  2110. }
  2111. if ($param['update']) {
  2112. # 名称带前缀
  2113. $param['name'] = 'update_' . $param['ext'];
  2114. $param['index'] = $index;
  2115. //$param['value'] = '';
  2116. # 得到当前的值
  2117. if (isset($data[$index]) && !isset($param['value'])) {
  2118. $param['value'] = $data[$index];
  2119. }
  2120. # 得到下级的值
  2121. if (isset($param['child_value']) && isset($data['id'])) {
  2122. $param['child_value'] = $this->value($param['child_value'], $data);
  2123. }
  2124. # 验证option是否是匿名函数
  2125. if (isset($param['option'])) {
  2126. $param['option'] = $this->option($param['option']);
  2127. }
  2128. if (isset($data[$index]) && isset($param['key']) && $param['update'] != 'editor') {
  2129. $param['value'] = Dever::upload($data[$index]);
  2130. }
  2131. # 处理下级字段
  2132. if (isset($param['child'])) {
  2133. $param['child'] = $this->option($param['child']);
  2134. if (isset($data[$key . '_parent'])) {
  2135. $param['parent_value'] = $data[$key . '_parent'];
  2136. }
  2137. }
  2138. # 设置默认值
  2139. if (isset($param['default'])) {
  2140. $param['default'] = $this->option($param['default']);
  2141. }
  2142. # 处理同步
  2143. if (isset($param['sync']) && isset($data[$param['sync'][0]]) && strpos($key, '-')) {
  2144. $temp = explode('-', $key);
  2145. $load = Dever::load($temp[0] . '/' . $temp[1] . '-one', array('option_' . $param['sync'][1] => $data[$param['sync'][0]]));
  2146. $param['value'] = isset($load[$temp[2]]) ? $load[$temp[2]] : $param['default'];
  2147. }
  2148. $method = $param['update'];
  2149. if (is_array($method)) {
  2150. $c = '';
  2151. if (layadmin()) {
  2152. $c = 'layui-tab-title';
  2153. }
  2154. $result .= '<ul class="nav nav-tabs '.$c.'">{tab}<li><a href="javascript:;" class="dever_form_add" toggle_key="' . $key . '">增加一条</a></li></ul>';
  2155. $tab = '';
  2156. $order = array
  2157. (
  2158. 'col' => 'order',
  2159. 'name' => '排序-按照数字正序排列',
  2160. 'default' => '1',
  2161. 'desc' => '排序',
  2162. 'match' => 'is_string',
  2163. 'update' => 'text',
  2164. );
  2165. array_unshift($method, $order);
  2166. $this->update_child(array(), $method, $key, $result, -1);
  2167. if (isset($param['value']) && $param['value']) {
  2168. $param['value'] = json_decode(base64_decode($param['value']), true);
  2169. if (is_array($param['value'])) {
  2170. foreach ($param['value'] as $k => $v) {
  2171. $this->update_child($v, $method, $key, $result, $k);
  2172. $active = '';
  2173. if ($k == 0) {
  2174. $active = 'active';
  2175. }
  2176. if (layadmin() && $active) {
  2177. $active .= ' layui-this';
  2178. }
  2179. $k = $k + 1;
  2180. $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>';
  2181. }
  2182. }
  2183. } else {
  2184. $this->update_child(array(), $method, $key, $result, 0);
  2185. $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>';
  2186. }
  2187. $result = str_replace('{tab}', $tab, $result);
  2188. } else {
  2189. if (isset($param['update_input']) && isset($data[$index . '_input'])) {
  2190. $param['update_input_data'] = explode(',', $data[$index . '_input']);
  2191. }
  2192. $result .= Html::$method($param);
  2193. }
  2194. if (isset($param['desc']) && ($param['update'] == 'text' || $param['update'] == 'password')) {
  2195. $result .= Html::desc($param['desc']);
  2196. }
  2197. }
  2198. }
  2199. /**
  2200. * update_action
  2201. *
  2202. * @return array
  2203. */
  2204. private function update_child($data, $param, $key, &$result, $index)
  2205. {
  2206. $style = '';
  2207. if ($index != 0) {
  2208. $style = 'style="display:none;"';
  2209. }
  2210. $result .= '<div id="' . $key . '-child-' . ($index + 1) . '" class="dever_' . $key . '_child dever_form_add_child" ' . $style . '><div class="dever_form_delete">[删除]</div>';
  2211. foreach ($param as $k => $v) {
  2212. $v['type'] = $v['update'];
  2213. $prefix = '';
  2214. if ($index < 0) {
  2215. $v['ext'] = $key . '_c_' . $v['col'];
  2216. $prefix = $v['ext'];
  2217. } else {
  2218. $v['ext'] = $key . '_c_' . $index . '_i_' . $v['col'];
  2219. $prefix = $v['ext'];
  2220. }
  2221. if ($v['col'] == 'order') {
  2222. $v['default'] = $index+1;
  2223. }
  2224. $class = $this->update_class($v['col'], $v, $prefix);
  2225. $result .= '<div class="form-group ' . $class . '">';
  2226. $this->update_html($v, $key, $v['col'], $data, $result);
  2227. $result .= '</div>';
  2228. }
  2229. $result .= '</div>';
  2230. }
  2231. /**
  2232. * update_action
  2233. *
  2234. * @return array
  2235. */
  2236. public function update_action_api()
  2237. {
  2238. $method = false;
  2239. $config = $this->config();
  2240. $input = Dever::preInput('update_');
  2241. if ($this->id) {
  2242. # 新增权限
  2243. if (Dever::load('manage/auth.oper', 3) == false) {
  2244. Dever::alert('你没有权限');
  2245. }
  2246. Dever::setInput('where_id', $this->id);
  2247. //Dever::setInput('update_where_id', $this->id);
  2248. $info = $this->load('one', $this->id);
  2249. if ($info) {
  2250. $method = 'update';
  2251. $col = Dever::input('col');
  2252. $value = Dever::input('value');
  2253. if ($col && $value) {
  2254. $method = 'update_' . $col;
  2255. //Dever::setInput('set_' . $col, $value);
  2256. //Dever::setInput('update_' . $col, $value);
  2257. $param['where_id'] = $this->id;
  2258. $param['set_' . $col] = $value;
  2259. $this->load($method, $param);
  2260. $struct = $this->struct_data($config['struct'], array($col => $value));
  2261. Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct, 'struct' => $config['struct']), $this->id);
  2262. Dever::out('yes');
  2263. return;
  2264. }
  2265. $prefix = 'set';
  2266. } else {
  2267. $method = 'insert';
  2268. $prefix = 'add';
  2269. }
  2270. }
  2271. if (!$method) {
  2272. # 新增权限
  2273. if (Dever::load('manage/auth.oper', 4) == false) {
  2274. Dever::alert('你没有权限');
  2275. }
  2276. $method = 'insert';
  2277. $prefix = 'add';
  2278. }
  2279. if ($method && $input) {
  2280. $update = $order = array();
  2281. $i = 0;
  2282. $c = array();
  2283. foreach ($input as $k => $v) {
  2284. if ($v === '') {
  2285. $v = 'null';
  2286. }
  2287. if ($v && is_string($v) && strpos($v, 'copy.') !== false) {
  2288. $temp = str_replace('copy.', '', $v);
  2289. if (isset($input['update_' . $temp])) {
  2290. $v = $input['update_' . $temp];
  2291. }
  2292. }
  2293. if (strpos($k, '_c_') !== false) {
  2294. if ($v == 'null') {
  2295. $v = '';
  2296. }
  2297. $temp = explode('_c_', $k);
  2298. $k = str_replace('update_', $prefix . '_', $temp[0]);
  2299. if (!isset($c[$k])) {
  2300. $c[$k] = array();
  2301. }
  2302. if (strpos($temp[1], '_i_') !== false) {
  2303. $temp = explode('_i_', $temp[1]);
  2304. if (!isset($c[$k][$temp[1]])) {
  2305. $c[$k][$temp[1]] = 0;
  2306. } else {
  2307. $c[$k][$temp[1]]++;
  2308. }
  2309. $num = $c[$k][$temp[1]];
  2310. $update[$i][$k][$num][$temp[1]] = $v;
  2311. if ($temp[1] == 'order') {
  2312. $order[$i][$k][$num] = $v;
  2313. }
  2314. } else {
  2315. //$update[$i][$k][$c][$temp[1]] = $v;
  2316. }
  2317. } elseif (strpos($k, '__') !== false) {
  2318. $temp1 = explode('__', $k);
  2319. $temp2 = explode('_', $temp1[0]);
  2320. $i = $temp2[1] - 1;
  2321. if (strpos($k, 'where_id') !== false) {
  2322. //$update[$i]['where_id'] = $v;
  2323. } else {
  2324. $update[$i]['add_' . $temp1[1]] = $v;
  2325. }
  2326. } else {
  2327. $ki = str_replace('update_', $prefix . '_', $k);
  2328. if (strpos($ki, 'where_id') !== false) {
  2329. if ($method != 'insert') {
  2330. $update[$i]['where_id'] = $v;
  2331. }
  2332. } else {
  2333. if (strpos($k, '-')) {
  2334. $k = str_replace('update_', '', $k);
  2335. if (isset($config['struct'][$k]) && isset($config['struct'][$k]['sync'])) {
  2336. $s_col = $config['struct'][$k]['sync'][0];
  2337. $m_col = $config['struct'][$k]['sync'][1];
  2338. if ($s_col == 'id') {
  2339. $s_value = $this->id;
  2340. } else {
  2341. $s_one = $this->load('one', $this->id);
  2342. $s_value = $s_one[$s_col];
  2343. }
  2344. $temp = explode('-', $k);
  2345. $index = $temp[0] . '/' . $temp[1];
  2346. $update_other_set[$index]['set_' . $temp[2]] = $v;
  2347. //$update_other_set[$index]['set_' . $m_col] = $s_value;
  2348. $update_other_add[$index]['add_' . $temp[2]] = $v;
  2349. $update_other_add[$index]['add_' . $m_col] = $s_value;
  2350. $update_other_id[$index]['option_' . $m_col] = $s_value;
  2351. }
  2352. } else {
  2353. if (is_array($v)) {
  2354. $k = str_replace('update_', '', $k);
  2355. $kd = $k . '_id';
  2356. if (isset($config['struct'][$kd])) {
  2357. foreach ($v as $vk => $vt) {
  2358. if ($vt == -1) {
  2359. unset($v[$vk]);
  2360. }
  2361. }
  2362. if ($v) {
  2363. $vd = end($v);
  2364. $kdi = $prefix . '_' . $kd;
  2365. $update[$i][$kdi] = $vd;
  2366. }
  2367. }
  2368. if (isset($config['struct'][$k]) && strpos($config['struct'][$k]['type'], 'int') !== false) {
  2369. $v = end($v);
  2370. }
  2371. }
  2372. $update[$i][$ki] = $v;
  2373. }
  2374. }
  2375. }
  2376. }
  2377. //print_r($update_other_set);die;
  2378. //print_r($input);
  2379. //print_r($update_other);die;
  2380. //print_r($config['struct']);die;
  2381. # 增加复制的数量
  2382. $copy_num = Dever::input('copy_num');
  2383. if ($copy_num > 0) {
  2384. $update[0]['where_id'] = 0;
  2385. for ($i = 1; $i < $copy_num; $i++) {
  2386. $update[$i] = $update[0];
  2387. # 缓存处理
  2388. $update[$i]['rank'] = $i;
  2389. }
  2390. }
  2391. if ($this->id && !$info) {
  2392. $update[0]['add_id'] = $this->id;
  2393. }
  2394. //print_r($update);die;
  2395. foreach ($update as $k => $v) {
  2396. $method = 'insert';
  2397. $old = array();
  2398. if (isset($v['where_id']) && $v['where_id']) {
  2399. $method = 'update';
  2400. $old = $this->load('one', $v['where_id']);
  2401. }
  2402. if (isset($order[$k])) {
  2403. foreach ($order[$k] as $i => $j) {
  2404. array_multisort($j, SORT_ASC, $v[$i]);
  2405. }
  2406. }
  2407. $id = $this->load($method, $v);
  2408. if ($id) {
  2409. $struct = $this->struct_data($config['struct'], $v, $old);
  2410. Log::add($this->project, $this->table, array('method' => $method, 'input' => $struct), $this->id ? $this->id : $id);
  2411. }
  2412. if (isset($update_other_id) && $update_other_id) {
  2413. foreach ($update_other_set as $k => $v) {
  2414. $check = Dever::load($k . '-one', $update_other_id[$k]);
  2415. //print_r($check);die;
  2416. if ($check) {
  2417. $v['where_id'] = $check['id'];
  2418. Dever::load($k . '-update', $v);
  2419. } else {
  2420. Dever::load($k . '-insert', $update_other_add[$k]);
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. Dever::out('yes');
  2427. }
  2428. private function struct_data($struct, $data, $old = array())
  2429. {
  2430. $log = $tlog = array();
  2431. foreach ($struct as $i => $j) {
  2432. if (isset($j['list_name'])) {
  2433. $j['name'] = $j['list_name'];
  2434. } elseif (strpos($j['name'], '-')) {
  2435. $temp = explode('-', $j['name']);
  2436. $j['name'] = $temp[0];
  2437. }
  2438. if (isset($j['list_table'])) {
  2439. $j['list'] = $j['list_table'];
  2440. if ($j['list'] == false) {
  2441. $data[$i] = false;
  2442. }
  2443. }
  2444. $list = (isset($j['list']) && is_string($j['list']) && $j['list'] != 'table');
  2445. if (isset($data['where_' . $i]) && $data['where_' . $i]) {
  2446. $log[$j['name']] = $data['where_' . $i];
  2447. } elseif (isset($data['set_' . $i]) && $data['set_' . $i]) {
  2448. $log[$j['name']] = $data['set_' . $i];
  2449. } elseif (isset($data['add_' . $i]) && $data['add_' . $i]) {
  2450. $log[$j['name']] = $data['add_' . $i];
  2451. } elseif (isset($data[$i]) && $data[$i]) {
  2452. $log[$j['name']] = $list ? $this->value($j['list'], $data) : $data[$i];
  2453. }
  2454. if (isset($log[$j['name']])) {
  2455. $tlog[$j['name']] = $log[$j['name']];
  2456. if (is_array($tlog[$j['name']])) {
  2457. if (isset($tlog[$j['name']][0]) && is_array($tlog[$j['name']][0])) {
  2458. $tlog[$j['name']] = json_encode($tlog[$j['name']]);
  2459. if (isset($old[$i]) && is_array($old[$i])) {
  2460. $old[$i] = json_encode($old[$i]);
  2461. }
  2462. } elseif (isset($tlog[$j['name']][0])) {
  2463. $tlog[$j['name']] = implode(',', $tlog[$j['name']]);
  2464. if (isset($old[$i]) && is_array($old[$i])) {
  2465. $old[$i] = implode(',', $old[$i]);
  2466. }
  2467. }
  2468. } 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) {
  2469. $log[$j['name']] = '<img layer-src="' . $log[$j['name']] . '" src="' . $log[$j['name']] . '" width="150">';
  2470. if (isset($old[$i]) && $old[$i]) {
  2471. $old[$i] = '<img layer-src="' . $old[$i] . '" src="' . $old[$i] . '" width="150">';
  2472. }
  2473. } elseif (is_numeric($log[$j['name']]) && (strpos($i, 'time') !== false || strpos($i, 'date') !== false)) {
  2474. $log[$j['name']] = date("Y-m-d H:i:s", $log[$j['name']]);
  2475. if (isset($old[$i]) && $old[$i]) {
  2476. $old[$i] = date("Y-m-d H:i:s", $old[$i]);
  2477. }
  2478. } elseif (isset($j['decode'])) {
  2479. $log[$j['name']] = json_decode(base64_decode($log[$j['name']]), true);
  2480. if (isset($old[$i]) && $old[$i]) {
  2481. $old[$i] = json_decode(base64_decode($old[$i]), true);
  2482. }
  2483. }
  2484. if (isset($j['option']) && !$list) {
  2485. $name = array();
  2486. $option = $this->option($j['option']);
  2487. if (is_array($option)) {
  2488. foreach ($option as $a => $b) {
  2489. if (!is_array($log[$j['name']])) {
  2490. if ($a == $log[$j['name']]) {
  2491. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  2492. }
  2493. } elseif (in_array($a, $log[$j['name']])) {
  2494. $name[] = (is_array($b) && isset($b['name'])) ? $b['name'] : $b;
  2495. }
  2496. }
  2497. }
  2498. $log[$j['name']] = implode(',', $name);
  2499. }
  2500. if (isset($old[$i]) && $old[$i] != $tlog[$j['name']]) {
  2501. $log[$j['name']] = array('old' => $old[$i], 'new' => $log[$j['name']]);
  2502. }
  2503. }
  2504. }
  2505. return $log;
  2506. }
  2507. /**
  2508. * delete_action
  2509. *
  2510. * @return array
  2511. */
  2512. public function delete_action_api()
  2513. {
  2514. if (Dever::load('manage/auth.oper', 5) == false) {
  2515. Dever::alert('您没有权限');
  2516. }
  2517. $config = $this->config();
  2518. if (isset($config['manage']['delete']) && $config['manage']['delete'] === 2) {
  2519. $this->load('delete', array('where_id' => $this->id));
  2520. } elseif (isset($config['struct']['state']) && (!isset($config['manage']['delete']) || (isset($config['manage']['delete']) && $config['manage']['delete']))) {
  2521. $this->load('update', array('where_id' => $this->id, 'state' => 2));
  2522. }
  2523. return 'reloaderror';
  2524. }
  2525. /**
  2526. * recovery_action
  2527. *
  2528. * @return array
  2529. */
  2530. public function recovery_action_api()
  2531. {
  2532. if (Dever::load('manage/auth.oper', 5) == false) {
  2533. Dever::alert('您没有权限');
  2534. }
  2535. $this->load('update', array('where_id' => $this->id, 'state' => 1));
  2536. return 'reload';
  2537. }
  2538. /**
  2539. * stat 为主动统计提供相关数据
  2540. *
  2541. * @return array
  2542. */
  2543. public function stat()
  2544. {
  2545. //bundle 包依赖工具
  2546. $config = $this->config();
  2547. if (empty($config['manage']['stat'])) {
  2548. Dever::alert('该项目主动统计功能未开放');
  2549. }
  2550. $data = $config['manage'];
  2551. $data['table'] = '';
  2552. $method = $this->project . '/' . $this->table . '-all';
  2553. $gp = Dever::input('gp', 'month,day');
  2554. $col = is_string($gp) ? explode(',', $gp) : $gp;
  2555. $data['search'] = $this->stat_search($config['struct'], $gp, $config['manage']['stat'], $config['manage']['search']);
  2556. foreach ($col as $k => $v) {
  2557. $this->stat_data($data, $config['struct'], $v, $method);
  2558. }
  2559. return $data;
  2560. }
  2561. /**
  2562. * stat 为主动统计提供导出数据 后续优化
  2563. *
  2564. * @return array
  2565. */
  2566. public function stat_excel()
  2567. {
  2568. Dever::$global['base']['excel'] = 1;
  2569. //print_r($data['thead']);die;
  2570. $data = $this->stat();
  2571. if ($data && isset($data['list'])) {
  2572. $xls = new \PHPExcel();
  2573. $xls->getProperties()->setCreator("Maze Stat Excel")
  2574. ->setLastModifiedBy("Maze Stat Excel")
  2575. ->setTitle("Office 2007 XLSX Maze Document")
  2576. ->setSubject("Office 2007 XLSX Maze Document")
  2577. ->setDescription("Mazephp Stat Excel")
  2578. ->setKeywords("Mazephp Stat Excel")
  2579. ->setCategory("Mazephp Stat Excel");
  2580. $info = $this->info();
  2581. $name = $info['list_header'] . '的' . $info['stat_desc'] . '-' . $info['project_name'];
  2582. $start = 65;
  2583. $s = 0;
  2584. foreach ($data['thead'] as $k => $v) {
  2585. if ($s > 0) {
  2586. $xls->createSheet();
  2587. }
  2588. $act = $xls->setActiveSheetIndex($s);
  2589. $act->setTitle($v[0]);
  2590. $s++;
  2591. $i = 0;
  2592. foreach ($v as $kj => $vj) {
  2593. $num = 1;
  2594. $cell = $this->_getChr($start, $i);
  2595. $act->setCellValue($cell . '' . $num, $vj);
  2596. $act->getColumnDimension($cell)->setWidth(20);
  2597. $i++;
  2598. if (isset($data['list'][$k])) {
  2599. foreach ($data['list'][$k] as $ki => $vi) {
  2600. if (isset($vi[$kj])) {
  2601. $num += 1;
  2602. $act->setCellValue($cell . $num, $vi[$kj]);
  2603. }
  2604. }
  2605. }
  2606. }
  2607. }
  2608. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); // 垂直居中
  2609. //$act->getStyle('A1:'.$k.'20')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);// 水平居中
  2610. $xls->setActiveSheetIndex(0);
  2611. $filename = $name . '.xlsx';
  2612. header('Pragma: public');
  2613. header('Expires: 0');
  2614. header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
  2615. header('Content-Type:application/force-download');
  2616. header('Content-Type:application/vnd.ms-execl');
  2617. header('Content-Type:application/octet-stream');
  2618. header('Content-Type:application/download');
  2619. header("Content-Disposition:attachment;filename='" . $filename . "'");
  2620. header('Content-Transfer-Encoding:binary');
  2621. $write = \PHPExcel_IOFactory::createWriter($xls, 'Excel2007');
  2622. $write->save('php://output');
  2623. }
  2624. }
  2625. /**
  2626. * stat_search
  2627. *
  2628. * @return mixed
  2629. */
  2630. private function stat_search($struct, $col, $stat, $search)
  2631. {
  2632. unset($struct['id']);
  2633. unset($struct['cdate']);
  2634. if ($stat) {
  2635. $stat = explode(',', $stat);
  2636. foreach ($stat as $k => $v) {
  2637. if (isset($struct[$v])) {
  2638. unset($struct[$v]);
  2639. }
  2640. }
  2641. }
  2642. $struct['day']['name'] = '天';
  2643. $struct['month']['name'] = '月';
  2644. $struct['year']['name'] = '年';
  2645. $param['update'] = 'checkbox';
  2646. $param['name'] = 'gp';
  2647. $param['value'] = $col;
  2648. $param['option'] = $struct;
  2649. $html = '<form action="' . $this->url('stat') . '" method="post" id="f1">';
  2650. $html .= '<div class="form-group">';
  2651. $html .= Html::pageLeft(array('name' => '统计项', 'col' => 'col'));
  2652. $html .= Html::radio($param);
  2653. $html .= '</div>';
  2654. $input = Dever::preInput('search_');
  2655. if (isset($search['date'])) {
  2656. foreach ($search['date'] as $k => $v) {
  2657. $html .= '<div class="form-group">';
  2658. $this->list_search_time($html, $input, 'search_', $k, $v, 'date');
  2659. $html .= '</div>';
  2660. }
  2661. $input = Dever::preInput('search_');
  2662. if ($input) {
  2663. foreach ($input as $k => $v) {
  2664. if ($v && strpos($k, 'option_') !== false) {
  2665. Dever::setInput(str_replace('search_', '', $k), $v);
  2666. }
  2667. }
  2668. }
  2669. }
  2670. if (isset($search['fulltext'])) {
  2671. $html .= '<div class="form-group">';
  2672. $this->list_search_select($html, $input, 'search_fulltext', '选择检索项', $search['fulltext']);
  2673. $this->list_search_select($html, $input, 'search_fulltext_type', '', array
  2674. (
  2675. 1 => '精确匹配',
  2676. 2 => '模糊匹配',
  2677. 3 => '大于',
  2678. 4 => '大于等于',
  2679. 5 => '小于',
  2680. 6 => '小于等于',
  2681. ), 1);
  2682. $value = array();
  2683. $value['name'] = 'search_fulltext_value';
  2684. $value['class'] = 'form-control';
  2685. if (isset($input[$value['name']])) {
  2686. $value['value'] = $input[$value['name']];
  2687. $fix = '';
  2688. if ($input['search_fulltext_type'] == 2) {
  2689. $fix = '%';
  2690. }
  2691. Dever::setInput('option_' . $input['search_fulltext'], $fix . $value['value'] . $fix);
  2692. //print_r(Dever::input('option_name'));die;
  2693. }
  2694. $html .= Html::text($value, false);
  2695. $html .= '</div>';
  2696. }
  2697. $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>';
  2698. $html .= '&nbsp;&nbsp;<a href="javascript:;" class="btn btn-warning" onclick="$(\'#f1\').attr(\'action\', \'' . $this->url('stat_excel') . '\').submit();">下载报表</a>';
  2699. $html .= '</form>';
  2700. return $html;
  2701. }
  2702. /**
  2703. * stat_data
  2704. *
  2705. * @return mixed
  2706. */
  2707. private function stat_data(&$data, $struct, $col, $method)
  2708. {
  2709. Dever::setInput('group', $col);
  2710. switch ($col) {
  2711. case 'year':
  2712. $name = '按年统计';
  2713. break;
  2714. case 'month':
  2715. $name = '按月统计';
  2716. break;
  2717. case 'day':
  2718. $name = '按天统计';
  2719. break;
  2720. default:
  2721. $name = $struct[$col]['name'];
  2722. break;
  2723. }
  2724. $list = Dever::load($method, array('group' => $col, 'col' => 'count(1) as total,id'));
  2725. $data['table'] .= '<div style="overflow-y:auto;width:100%;max-height:600px;"><table class="table table-bordered table-striped">';
  2726. $data['table'] .= '<thead><tr><th>' . $name . '</th><th>统计数字</th></tr></thead>';
  2727. $data['thead'][$col] = array($name, '统计数字');
  2728. if ($list) {
  2729. $data['table'] .= '<tbody>';
  2730. $total = 0;
  2731. foreach ($list as $k => $v) {
  2732. if (isset($v[$col])) {
  2733. if (isset($struct[$col]['option'])) {
  2734. $option = $this->option($struct[$col]['option']);
  2735. if (isset($option[$v[$col]])) {
  2736. $v[$col] = $option[$v[$col]];
  2737. if (is_array($v[$col])) {
  2738. $v[$col] = $v[$col]['name'];
  2739. }
  2740. }
  2741. }
  2742. $data['table'] .= '<tr><td width="60%" style="word-break:break-all;word-wrap:break-word;">' . $v[$col] . '</td><td>' . $v['total'] . '</td></tr>';
  2743. $total += $v['total'];
  2744. $data['list'][$col][] = array($v[$col], $v['total']);
  2745. }
  2746. }
  2747. $data['table'] .= '</tbody>';
  2748. if ($total > 0 && $k > 0) {
  2749. $data['table'] .= '<tr><td style="font-weight:bold">汇总</td><td style="font-weight:bold">' . $total . '</td></tr>';
  2750. $data['list'][$col][] = array('汇总', $total);
  2751. }
  2752. }
  2753. $data['table'] .= '</table></div>';
  2754. }
  2755. /**
  2756. * load
  2757. *
  2758. * @return mixed
  2759. */
  2760. private function load($method = 'one', $param = array())
  2761. {
  2762. return Dever::load($this->project . '/' . $this->table . '-' . $method, $param);
  2763. }
  2764. /**
  2765. * __call
  2766. *
  2767. * @return object
  2768. */
  2769. public function __call($method, $param)
  2770. {
  2771. if (strpos($method, 'html_') !== false) {
  2772. return Html::text($param);
  2773. }
  2774. return $this;
  2775. }
  2776. /**
  2777. * option
  2778. *
  2779. * @return string
  2780. */
  2781. private function option($option)
  2782. {
  2783. if (is_object($option)) {
  2784. $function = $option;
  2785. $option = $function();
  2786. }
  2787. return $option;
  2788. }
  2789. /**
  2790. * option
  2791. *
  2792. * @return string
  2793. */
  2794. public function manage()
  2795. {
  2796. $config = $this->config();
  2797. return $config;
  2798. }
  2799. /**
  2800. * valid
  2801. *
  2802. * @return string
  2803. */
  2804. public function valid()
  2805. {
  2806. //http://placehold.it/350x150
  2807. $config = $this->config();
  2808. if (isset($config['struct'])) {
  2809. $rule = array();
  2810. $rule['required']['regex'] = 'none';
  2811. $rule['required']['alertText'] = '此项不能为空';
  2812. $rule['required']['alertTextCheckboxMultiple'] = '请选择一个选项';
  2813. $rule['required']['alertTextCheckboxe'] = '请选择一个选项';
  2814. $rule['required']['alertTextDateRange'] = '日期范围不可空白';
  2815. foreach ($config['struct'] as $k => $v) {
  2816. if (isset($v['match']) && $v['match'] != 'option' && is_string($v['match']) && strpos($v['match'], '/') !== false) {
  2817. if (strstr($v['match'], 'option||')) {
  2818. $v['match'] = str_replace('option||', '', $v['match']);
  2819. }
  2820. $rule[$k]['regex'] = $v['match'];
  2821. $rule[$k]['alertText'] = $v['desc'];
  2822. }
  2823. }
  2824. }
  2825. $script = '<script>';
  2826. //参考https://blog.csdn.net/wangzl1163/article/details/51071826
  2827. //http://code.ciaoca.com/jquery/validation-engine/demo/demoOnForm
  2828. $script .= '(function($){
  2829. $.fn.validationEngineLanguage = function(){
  2830. };
  2831. $.validationEngineLanguage = {
  2832. newLang: function(){
  2833. $.validationEngineLanguage.allRules = ';
  2834. //此处进行了转义过滤,其实也可以使用json_encode的第二个参数,不过只支持5.4以上版本,考虑到虚拟主机就放弃了
  2835. $script .= str_replace(array('\\\\', '\\/', '"/', '/"'), array('\\', '/', '/', '/'), json_encode($rule)) . ';';
  2836. $script .= '}
  2837. };
  2838. $.validationEngineLanguage.newLang();
  2839. })(jQuery);';
  2840. $script .= '$(document).ready(function(){
  2841. $(".form1").validationEngine("attach",{onSuccess:function(){submit();},onFailure:function(){submit();}});
  2842. });';
  2843. $script .= '</script>';
  2844. //print_r($script);die;
  2845. return $script;
  2846. }
  2847. /**
  2848. * save
  2849. *
  2850. * @return string
  2851. */
  2852. public function save()
  2853. {
  2854. $config = $this->config();
  2855. if (isset($config['manage']['save'])) {
  2856. return 'yes';
  2857. }
  2858. return 'no';
  2859. }
  2860. }