function get_shop_cates() { $all_cate = lazy_get_data("select * from `u2_shop_cate` ", 'id'); $cates = array(); if ($all_cate) { foreach ($all_cate as $v) { $parent[$v['pid']][$v['id']] = $v['orders']; } $ids = format_cate_order(0, $parent); foreach ($ids as $v) { $cates[$v['id']] = $all_cate[$v['id']]; $cates[$v['id']]['root'] = $v['root']; } } return $cates; }
function shop_cate_list($id = NULL) { $this->is_admin(); $id = intval($id); $all_cate = lazy_get_data("select * from `u2_shop_cate` ", 'id'); if (!$all_cate) { die('<div class="notice">暂无分类</div>'); } foreach ($all_cate as $v) { $parent[$v['pid']][$v['id']] = $v['orders']; } if (!isset($parent[$id])) { $id = 0; } $ids = format_cate_order(0, $parent); foreach ($ids as $v) { $cates[$v['id']] = $all_cate[$v['id']]; $cates[$v['id']]['root'] = $v['root']; } $html = NULL; $ul_start = false; if ($id == 0) { $html = '<ul id="cate_' . $id . '" class="shop">'; $ul_start = true; } $li_start = false; foreach ($cates as $v) { $blank = NULL; $style = NULL; $extra = NULL; if ($v['id'] != $id && isset($parent[$v['id']]) && $parent[$v['id']]) { $extra = '<a href="JavaScript:void(0)" onclick="shop_cate_list(' . $v['id'] . ');" title="调整分类顺序"><img src="/static/images/plus.gif"></a>'; } if ($v['root']) { $blank = '└'; $style = ' style="padding-left:' . ($v['root'] * 10 - 1) . 'px" '; } if (isset($parent[$id][$v['id']])) { unset($parent[$id][$v['id']]); if ($li_start) { $li_start = true; $html .= '</li>'; } $html .= '<li id="cate_id_' . $v['id'] . '"><div ' . $style . '><span class="r"><a href="JavaScript:void(0)" onclick="admin_shop_del(\'cate\',' . $v['id'] . ')"><img src="/static/images/cross.gif"></a></span><img src="/static/images/movearrow.gif" class="m" /><a href="/admin/shop/modify/cate/' . $v['id'] . '">' . $v['cate_desc'] . '</a>' . $extra . '<br clear="all"/></div>'; } else { $html .= '<div ' . $style . '><span class="r"><a href="JavaScript:void(0)" onclick="admin_shop_del(\'cate\',' . $v['id'] . ')"><img src="/static/images/cross.gif"></a></span>' . $blank . '<a href="/admin/shop/modify/cate/' . $v['id'] . '">' . $v['cate_desc'] . '</a>' . $extra . '<br clear="all"/></div>'; } if ($id == $v['id']) { $html .= '<ul id="cate_' . $id . '" class="shop">'; $ul_start = true; $li_start = false; } if ($ul_start == true && !$parent[$id] && $id != 0) { $ul_start = false; $html .= '</li></ul>'; } } if ($id == 0) { $start = false; $html .= '</ul>'; } $html .= '<script>new Sortables($(\'cate_' . $id . '\') , {handles:$(\'cate_' . $id . '\').getElementsByClassName(\'m\') , onComplete:function() { var order =( this.serialize( function(el) { return el.id.replace("cate_id_" , "" ); } )); var url = \'/ajax/save_shop_order/cate/\'+order ; var myajax = new Ajax(url, { data:foodata, method:\'post\' , evalScripts:true, onComplete:function() { } }).request(); }} ); </script>'; echo $html; }