1+ <?php
2+ /* (C)2005-2021 Lightning Framework Buliding.
3+ * 官网:http://www.FoundPHP.com
4+ * 邮箱:master@FoundPHP.com
5+ * This is not a freeware, use is subject to license terms.
6+ * 此软件为授权使用软件,请参考软件协议。
7+ * http://www.foundphp.com/?m=agreement
8+ */
9+ // 全局设置
10+ include_once "globals.php " ;
11+
12+
13+
14+ /**
15+ * 添加功能按钮
16+ * id 当前信息的id
17+ * more 附加信息,例如订单等都属于编辑状态
18+ more 数值为 1 表示关闭删除功能,其他内容表示附加信息
19+ */
20+ function add ($ die_power =array ()){
21+ global $ aus ;
22+ if (is_array ($ GLOBALS ['now_powers ' ])){
23+ if (@array_key_exists ('add ' ,$ GLOBALS ['now_powers ' ])){
24+ $ result = '<button type="button" class="btn btn-dark" onclick="location= \'' .$ GLOBALS ['page_url ' ].'&t=add \'"> ' .lang ('添加 ' ).'</button> ' ;
25+ }
26+ //导出数据
27+ if (@array_key_exists ('export_data ' ,$ GLOBALS ['now_powers ' ]) && !in_array ('export_data ' ,$ die_power )){
28+ $ result .= ' <button type="button" class="btn btn-primary" onclick="location= \'? ' .($ GLOBALS ['m ' ]!='' ?'m= ' .$ GLOBALS ['m ' ].'& ' :'' ).'a=export_data&n= ' .$ GLOBALS ['a ' ].($ GLOBALS ['o ' ] && in_array ($ GLOBALS ['g ' ],array ('a ' ,'d ' ))?"&o= " .$ GLOBALS ['o ' ]."&g= " .$ GLOBALS ['g ' ]:'' ).'\'"> ' .$ GLOBALS ['_sys_pn ' ]['export_data ' ].'</button> ' ;
29+ }
30+ //导入数据
31+ if (@array_key_exists ('import_data ' ,$ GLOBALS ['now_powers ' ]) && !in_array ('import_data ' ,$ die_power )){
32+ $ result .= ' <button type="button" class="btn btn-primary" onclick="location= \'? ' .($ GLOBALS ['m ' ]!='' ?'m= ' .$ GLOBALS ['m ' ].'& ' :'' ).'a= ' .$ GLOBALS ['a ' ].'&t=import_data \'"> ' .$ GLOBALS ['_sys_pn ' ]['import_data ' ].'</button> ' ;
33+ }
34+
35+ //批量删除
36+ if (@array_key_exists ('bdel ' ,$ GLOBALS ['now_powers ' ])){
37+ $ result .= ' <button type="submit" class="btn btn-danger" onclick="javascript:if(confirm( \'' .lang ('您确定要删除吗? ' ).'\'))return ture; else return false;">批量删除</button> ' ;
38+ }
39+
40+ return $ result ;
41+ }
42+ }
43+
44+
45+ /*
46+ * 搜索权限
47+ *
48+ */
49+ function search ($ search_file ='_search ' ){
50+ if (is_array ($ GLOBALS ['now_powers ' ])){
51+ if (array_key_exists ('search ' ,$ GLOBALS ['now_powers ' ])){
52+
53+ //session 搜索数据
54+ $ t = ($ GLOBALS ['t ' ] && $ GLOBALS ['id ' ]>0 ?'_ ' .$ GLOBALS ['t ' ].$ GLOBALS ['id ' ]:'' );
55+ $ k = $ GLOBALS ['m ' ].'_ ' .$ GLOBALS ['a ' ].$ t ;
56+ $ GLOBALS ['search_val ' ] = $ search_val = json (session ($ k ));
57+ $ input = array ();
58+ //获得关键词
59+ foreach ($ GLOBALS ['insert ' ] AS $ K =>$ V ){
60+ foreach ($ V AS $ sk =>$ sv ){
61+ if ((@$ sv ['search ' ]==1 || @$ sv ['search ' ]=='like ' ) && $ sv ['lang ' ]){
62+ preg_match_all ('@\[(.+)\]@i ' , $ sv ['lang ' ], $ matches );
63+ $ value = (@$ search_val [$ sk ]?@$ search_val [$ sk ]:@$ GLOBALS ['P ' ][$ sk ]);
64+ $ input [] = array ('title ' =>$ matches ['1 ' ]['0 ' ],'name ' =>$ sk ,'value ' =>$ value ,'type ' =>'text ' );
65+ }
66+ }
67+ }
68+
69+
70+ if (count ($ input )>0 ){
71+ //设置搜索值
72+ $ GLOBALS ['tpl ' ]->set_var ('_search_val ' ,$ search_val );
73+ $ GLOBALS ['tpl ' ]->set_var ('_search_input ' ,$ input );
74+ $ GLOBALS ['tpl ' ]->set_file ($ search_file ,@$ GLOBALS ['tpl_dir ' ]);
75+ return @$ id .$ GLOBALS ['tpl ' ]->r ();
76+ }
77+ }
78+ }
79+ }
80+
81+
82+ //搜索条件
83+ //搜索数据保留30分钟
84+ function search_where ($ set_where ='' ,$ times =30 ){
85+ $ t = ($ GLOBALS ['t ' ] && $ GLOBALS ['id ' ]>0 ?'_ ' .$ GLOBALS ['t ' ].$ GLOBALS ['id ' ]:'' );
86+ $ k = $ GLOBALS ['m ' ].'_ ' .$ GLOBALS ['a ' ].$ t ;
87+ //清空搜索记录
88+ if (@$ GLOBALS ['s ' ]=='clear ' ){
89+ session ($ k ,'[null] ' );
90+ session ('search_sql ' ,'[null] ' );
91+ session ('search_where ' ,'[null] ' );
92+ session ('search_order ' ,'[null] ' );
93+ session ('search_group ' ,'[null] ' );
94+ msg ('' ,str_replace ('&s=clear ' ,'' ,$ GLOBALS ['page_url ' ]));
95+ return '' ;
96+ }
97+ //存储
98+ if (@$ GLOBALS ['P ' ]['key ' ]){
99+ $ post = array ();
100+ foreach ($ GLOBALS ['P ' ]['key ' ] AS $ pk =>$ pv ) {
101+ if ($ pv || strlen ($ pv )>0 ){
102+ $ post [$ pk ] = $ pv ;
103+ }
104+ }
105+ //没有搜索内容则清空
106+ if (count ($ post )<=0 ){
107+ session ($ k ,'[null] ' );
108+ session ('search ' ,'[null] ' );
109+ }
110+ $ result ['data ' ] = $ s = $ post ;
111+ $ val = json ($ s );
112+ session ($ k ,$ val );
113+ session ('search ' ,'1 ' );
114+ msg ('' ,$ GLOBALS ['page_url ' ].'# ' .rand (1000 ,9999 ));
115+ exit ;
116+ }else {
117+ $ result ['data ' ] = $ s = json (session ($ k ));
118+ }
119+
120+
121+ $ table_index = array_flip (@$ GLOBALS ['table ' ]);
122+ $ ljoin_num = count (@(array )$ GLOBALS ['ljoin ' ]);
123+ $ where = array ();
124+ //获得关键词
125+ foreach ($ GLOBALS ['insert ' ] AS $ K =>$ V ){
126+ $ dot = $ table_index [$ K ];
127+ foreach ($ V AS $ sk =>$ sv ){
128+ if (!empty ($ sv ['search ' ])){
129+ if ($ s [$ sk ]){
130+
131+ switch ($ sv ['search ' ]){
132+ //等于
133+ case 1 :
134+ @$ where [] = ($ ljoin_num >=1 ?"$ dot. " :'' )."$ sk=' " .trim ($ s [$ sk ])."' " ;
135+ break ;
136+ //单独加入的下拉框
137+ case 'select ' :
138+ @$ where [] = ($ ljoin_num >=1 ?"$ dot. " :'' )."$ sk=' " .trim ($ s [$ sk ])."' " ;
139+ break ;
140+
141+ //模糊查询
142+ case 'like ' :
143+ @$ where [] = ($ ljoin_num >=1 ?"$ dot. " :'' )."$ sk LIKE '% " .trim ($ s [$ sk ])."%' " ;
144+ break ;
145+ //不会产生搜索框
146+ case 'likes ' :
147+ @$ where [] = ($ ljoin_num >=1 ?"$ dot. " :'' )."$ sk LIKE '% " .trim ($ s [$ sk ])."%' " ;
148+ break ;
149+ }
150+ }
151+ }
152+ }
153+ }
154+
155+ //导出数据筛选条件
156+ if ($ GLOBALS ['a ' ]=='export_data ' && session ('search_where ' )){
157+ $ result ['text ' ] = session ('search_where ' );
158+ return $ result ;
159+ }
160+
161+
162+ if (count ((array )$ where )){
163+ $ result ['text ' ] = ($ set_where ?$ set_where .' AND ' :'' ).implode (' AND ' ,$ where );
164+ return $ result ;
165+ }else {
166+ $ result ['text ' ] = $ set_where ;
167+ return $ result ;
168+ }
169+ }
170+
171+
172+ //排序
173+ function search_order ($ set ='' ){
174+ //导出数据筛选条件
175+ if ($ GLOBALS ['a ' ]=='export_data ' && (session ('search_order ' ) || session ('search_group ' ))){
176+ $ set = (session ('search_order ' )!='' ?session ('search_order ' ):'' );
177+ return $ set ;
178+ }
179+
180+ if (@$ GLOBALS ['o ' ] && in_array ($ GLOBALS ['g ' ],array ('a ' ,'d ' ))){
181+ $ set = $ GLOBALS ['o ' ].($ GLOBALS ['g ' ]=='d ' ?' DESC ' :' ASC ' );
182+ }
183+ return $ set ;
184+ }
185+
186+ //表格操作
187+ function torder ($ set ='' ){
188+ if ($ GLOBALS ['o ' ] && in_array ($ GLOBALS ['g ' ],array ('a ' ,'d ' ))){
189+ $ set = $ GLOBALS ['o ' ].($ GLOBALS ['g ' ]=='d ' ?' DESC ' :' ASC ' );
190+ }
191+ return $ set ;
192+ }
193+
194+ /**
195+ * 后台编辑管理
196+ * set_id 当前信息的id
197+ * die_power 禁用权限
198+ */
199+ function taction ($ set_id =0 ,$ die_power ='' ){
200+ global $ aus ,$ dls ;
201+ $ now_powers = $ GLOBALS ['now_powers ' ];
202+ if (!empty ($ now_powers ['add ' ])){
203+ unset($ now_powers ['add ' ]);
204+ }
205+ if (!empty ($ now_powers ['bdel ' ])){
206+ unset($ now_powers ['bdel ' ]);
207+ }
208+ //保护系统功能
209+ if (is_array ($ now_powers )){
210+ if (@array_key_exists ('del ' ,$ now_powers )){
211+ $ GLOBALS ['tpl ' ]->set_var ('del_url ' ,$ GLOBALS ['page_url ' ].'&id= ' .$ set_id .'&t=del ' .($ GLOBALS ['p ' ]?'&p= ' .$ GLOBALS ['p ' ]:'' ));
212+ unset($ now_powers ['del ' ]);
213+ }
214+ if (@array_key_exists ('edit ' ,$ now_powers )){
215+ $ GLOBALS ['tpl ' ]->set_var ('edit_url ' ,$ GLOBALS ['page_url ' ].'&id= ' .$ set_id .'&t=edit ' .($ GLOBALS ['p ' ]?'&p= ' .$ GLOBALS ['p ' ]:'' ));
216+ unset($ now_powers ['edit ' ]);
217+ }
218+ }
219+
220+ if (!empty ($ now_powers ['search ' ])){unset($ now_powers ['search ' ]);}
221+ if (!empty ($ now_powers ['export_data ' ])){unset($ now_powers ['export_data ' ]);}
222+ if (!empty ($ now_powers ['import_data ' ])){unset($ now_powers ['import_data ' ]);}
223+ if (!empty ($ now_powers ) && is_array ($ now_powers )){
224+ $ GLOBALS ['tpl ' ]->set_var ('more_link ' ,$ GLOBALS ['page_url ' ].'&id= ' .$ set_id .($ GLOBALS ['p ' ]?'&p= ' .$ GLOBALS ['p ' ]:'' ));
225+ $ GLOBALS ['tpl ' ]->set_var ('more ' ,$ now_powers );
226+ }
227+ $ GLOBALS ['tpl ' ]->set_var ('set_id ' ,@$ set_id );
228+ $ GLOBALS ['tpl ' ]->set_var ('die_power ' ,@$ die_power );
229+ $ GLOBALS ['tpl ' ]->set_file ('_taction ' ,@$ tpl_dir );
230+ return @$ id .$ GLOBALS ['tpl ' ]->r ();
231+ }
232+
233+ /**
234+ * 批量删除条件
235+ */
236+ function batch_del (){
237+ global $ aus ;
238+ if (@array_key_exists ('del ' ,$ GLOBALS ['now_powers ' ])){
239+ return true ;
240+ }
241+ return false ;
242+ }
243+
244+ /**
245+ * 搜索条件
246+ */
247+ function back_search (){
248+ global $ aus ;
249+ if (@array_key_exists ('search ' ,$ GLOBALS ['now_powers ' ])){
250+ return true ;
251+ }
252+ return false ;
253+ }
254+
255+
256+
257+
258+
259+
0 commit comments