-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattribute.php
More file actions
361 lines (287 loc) · 11.9 KB
/
Copy pathattribute.php
File metadata and controls
361 lines (287 loc) · 11.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
/**
* ECSHOP 属性规格管理
* ============================================================================
* * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liubo $
* $Id: attribute.php 17217 2011-01-19 06:29:08Z liubo $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/* act操作项的初始化 */
$_REQUEST['act'] = trim($_REQUEST['act']);
if (empty($_REQUEST['act']))
{
$_REQUEST['act'] = 'list';
}
$exc = new exchange($ecs->table("attribute"), $db, 'attr_id', 'attr_name');
/*------------------------------------------------------ */
//-- 属性列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'list')
{
$goods_type = isset($_GET['goods_type']) ? intval($_GET['goods_type']) : 0;
$smarty->assign('ur_here', $_LANG['09_attribute_list']);
$smarty->assign('action_link', array('href' => 'attribute.php?act=add&goods_type='.$goods_type , 'text' => $_LANG['10_attribute_add']));
$smarty->assign('goods_type_list', goods_type_list($goods_type)); // 取得商品类型
$smarty->assign('full_page', 1);
$list = get_attrlist();
$smarty->assign('attr_list', $list['item']);
$smarty->assign('filter', $list['filter']);
$smarty->assign('record_count', $list['record_count']);
$smarty->assign('page_count', $list['page_count']);
$sort_flag = sort_flag($list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
/* 显示模板 */
assign_query_info();
$smarty->display('attribute_list.htm');
}
/*------------------------------------------------------ */
//-- 排序、翻页
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'query')
{
$list = get_attrlist();
$smarty->assign('attr_list', $list['item']);
$smarty->assign('filter', $list['filter']);
$smarty->assign('record_count', $list['record_count']);
$smarty->assign('page_count', $list['page_count']);
$sort_flag = sort_flag($list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
make_json_result($smarty->fetch('attribute_list.htm'), '',
array('filter' => $list['filter'], 'page_count' => $list['page_count']));
}
/*------------------------------------------------------ */
//-- 添加/编辑属性
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'add' || $_REQUEST['act'] == 'edit')
{
/* 检查权限 */
admin_priv('attr_manage');
/* 添加还是编辑的标识 */
$is_add = $_REQUEST['act'] == 'add';
$smarty->assign('form_act', $is_add ? 'insert' : 'update');
/* 取得属性信息 */
if ($is_add)
{
$goods_type = isset($_GET['goods_type']) ? intval($_GET['goods_type']) : 0;
$attr = array(
'attr_id' => 0,
'cat_id' => $goods_type,
'attr_name' => '',
'attr_input_type' => 0,
'attr_index' => 0,
'attr_values' => '',
'attr_type' => 0,
'is_linked' => 0,
);
}
else
{
$sql = "SELECT * FROM " . $ecs->table('attribute') . " WHERE attr_id = '$_REQUEST[attr_id]'";
$attr = $db->getRow($sql);
}
$smarty->assign('attr', $attr);
$smarty->assign('attr_groups', get_attr_groups($attr['cat_id']));
/* 取得商品分类列表 */
$smarty->assign('goods_type_list', goods_type_list($attr['cat_id']));
/* 模板赋值 */
$smarty->assign('ur_here', $is_add ?$_LANG['10_attribute_add']:$_LANG['52_attribute_add']);
$smarty->assign('action_link', array('href' => 'attribute.php?act=list', 'text' => $_LANG['09_attribute_list']));
/* 显示模板 */
assign_query_info();
$smarty->display('attribute_info.htm');
}
/*------------------------------------------------------ */
//-- 插入/更新属性
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'insert' || $_REQUEST['act'] == 'update')
{
/* 检查权限 */
admin_priv('attr_manage');
/* 插入还是更新的标识 */
$is_insert = $_REQUEST['act'] == 'insert';
/* 检查名称是否重复 */
$exclude = empty($_POST['attr_id']) ? 0 : intval($_POST['attr_id']);
if (!$exc->is_only('attr_name', $_POST['attr_name'], $exclude, " cat_id = '$_POST[cat_id]'"))
{
sys_msg($_LANG['name_exist'], 1);
}
$cat_id = $_REQUEST['cat_id'];
/* 取得属性信息 */
$attr = array(
'cat_id' => $_POST['cat_id'],
'attr_name' => $_POST['attr_name'],
'attr_index' => $_POST['attr_index'],
'attr_input_type' => $_POST['attr_input_type'],
'is_linked' => $_POST['is_linked'],
'attr_values' => isset($_POST['attr_values']) ? $_POST['attr_values'] : '',
'attr_type' => empty($_POST['attr_type']) ? '0' : intval($_POST['attr_type']),
'attr_group' => isset($_POST['attr_group']) ? intval($_POST['attr_group']) : 0
);
/* 入库、记录日志、提示信息 */
if ($is_insert)
{
$db->autoExecute($ecs->table('attribute'), $attr, 'INSERT');
admin_log($_POST['attr_name'], 'add', 'attribute');
$links = array(
array('text' => $_LANG['add_next'], 'href' => '?act=add&goods_type=' . $_POST['cat_id']),
array('text' => $_LANG['back_list'], 'href' => '?act=list'),
);
sys_msg(sprintf($_LANG['add_ok'], $attr['attr_name']), 0, $links);
}
else
{
$db->autoExecute($ecs->table('attribute'), $attr, 'UPDATE', "attr_id = '$_POST[attr_id]'");
admin_log($_POST['attr_name'], 'edit', 'attribute');
$links = array(
array('text' => $_LANG['back_list'], 'href' => '?act=list&goods_type='.$_POST['cat_id'].''),
);
sys_msg(sprintf($_LANG['edit_ok'], $attr['attr_name']), 0, $links);
}
}
/*------------------------------------------------------ */
//-- 删除属性(一个或多个)
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'batch')
{
/* 检查权限 */
admin_priv('attr_manage');
/* 取得要操作的编号 */
if (isset($_POST['checkboxes']))
{
$count = count($_POST['checkboxes']);
$ids = isset($_POST['checkboxes']) ? join(',', $_POST['checkboxes']) : 0;
$sql = "DELETE FROM " . $ecs->table('attribute') . " WHERE attr_id " . db_create_in($ids);
$db->query($sql);
$sql = "DELETE FROM " . $ecs->table('goods_attr') . " WHERE attr_id " . db_create_in($ids);
$db->query($sql);
/* 记录日志 */
admin_log('', 'batch_remove', 'attribute');
clear_cache_files();
$link[] = array('text' => $_LANG['back_list'], 'href' => 'attribute.php?act=list');
sys_msg(sprintf($_LANG['drop_ok'], $count), 0, $link);
}
else
{
$link[] = array('text' => $_LANG['back_list'], 'href' => 'attribute.php?act=list');
sys_msg($_LANG['no_select_arrt'], 0, $link);
}
}
/*------------------------------------------------------ */
//-- 编辑属性名称
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_attr_name')
{
check_authz_json('attr_manage');
$id = intval($_POST['id']);
$val = json_str_iconv(trim($_POST['val']));
/* 取得该属性所属商品类型id */
$cat_id = $exc->get_name($id, 'cat_id');
/* 检查属性名称是否重复 */
if (!$exc->is_only('attr_name', $val, $id, " cat_id = '$cat_id'"))
{
make_json_error($_LANG['name_exist']);
}
$exc->edit("attr_name='$val'", $id);
admin_log($val, 'edit', 'attribute');
make_json_result(stripslashes($val));
}
/*------------------------------------------------------ */
//-- 编辑排序序号
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'edit_sort_order')
{
check_authz_json('attr_manage');
$id = intval($_POST['id']);
$val = intval($_POST['val']);
$exc->edit("sort_order='$val'", $id);
admin_log(addslashes($exc->get_name($id)), 'edit', 'attribute');
make_json_result(stripslashes($val));
}
/*------------------------------------------------------ */
//-- 删除商品属性
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'remove')
{
check_authz_json('attr_manage');
$id = intval($_GET['id']);
$db->query("DELETE FROM " .$ecs->table('attribute'). " WHERE attr_id='$id'");
$db->query("DELETE FROM " .$ecs->table('goods_attr'). " WHERE attr_id='$id'");
$url = 'attribute.php?act=query&' . str_replace('act=remove', '', $_SERVER['QUERY_STRING']);
ecs_header("Location: $url\n");
exit;
}
/*------------------------------------------------------ */
//-- 获取某属性商品数量
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'get_attr_num')
{
check_authz_json('attr_manage');
$id = intval($_GET['attr_id']);
$sql = "SELECT COUNT(*) ".
" FROM " . $ecs->table('goods_attr') . " AS a, ".
$ecs->table('goods') . " AS g ".
" WHERE g.goods_id = a.goods_id AND g.is_delete = 0 AND attr_id = '$id' ";
$goods_num = $db->getOne($sql);
if ($goods_num > 0)
{
$drop_confirm = sprintf($_LANG['notice_drop_confirm'], $goods_num);
}
else
{
$drop_confirm = $_LANG['drop_confirm'];
}
make_json_result(array('attr_id'=>$id, 'drop_confirm'=>$drop_confirm));
}
/*------------------------------------------------------ */
//-- 获得指定商品类型下的所有属性分组
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'get_attr_groups')
{
check_authz_json('attr_manage');
$cat_id = intval($_GET['cat_id']);
$groups = get_attr_groups($cat_id);
make_json_result($groups);
}
/*------------------------------------------------------ */
//-- PRIVATE FUNCTIONS
/*------------------------------------------------------ */
/**
* 获取属性列表
*
* @return array
*/
function get_attrlist()
{
/* 查询条件 */
$filter = array();
$filter['goods_type'] = empty($_REQUEST['goods_type']) ? 0 : intval($_REQUEST['goods_type']);
$filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'sort_order' : trim($_REQUEST['sort_by']);
$filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']);
$where = (!empty($filter['goods_type'])) ? " WHERE a.cat_id = '$filter[goods_type]' " : '';
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('attribute') . " AS a $where";
$filter['record_count'] = $GLOBALS['db']->getOne($sql);
/* 分页大小 */
$filter = page_and_size($filter);
/* 查询 */
$sql = "SELECT a.*, t.cat_name " .
" FROM " . $GLOBALS['ecs']->table('attribute') . " AS a ".
" LEFT JOIN " . $GLOBALS['ecs']->table('goods_type') . " AS t ON a.cat_id = t.cat_id " . $where .
" ORDER BY $filter[sort_by] $filter[sort_order] ".
" LIMIT " . $filter['start'] .", $filter[page_size]";
$row = $GLOBALS['db']->getAll($sql);
foreach ($row AS $key => $val)
{
$row[$key]['attr_input_type_desc'] = $GLOBALS['_LANG']['value_attr_input_type'][$val['attr_input_type']];
$row[$key]['attr_values'] = str_replace("\n", ", ", $val['attr_values']);
}
$arr = array('item' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
return $arr;
}
?>