Database.php 141 KB

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