コード例 #1
0
 public function editmenu()
 {
     $menu_id = $_GET['mid'];
     $menuinfo = mod_menu::get_one_menu($menu_id);
     if (!$menuinfo) {
         mod_login::message('对不起,该目录不存在');
     }
     if ($_POST['submit']) {
         try {
             $data = array();
             $data['parent_id'] = $_POST['parent_id'];
             $data['menu_name'] = $_POST['menu_name'];
             $data['act_url'] = $_POST['act_url'];
             $data['actioncode'] = $_POST['actioncode'];
             $data['is_show'] = $_POST['is_show'];
             $data['sort'] = $_POST['sort'];
             $data['level'] = $_POST['level'];
             if ($data['parent_id'] == 0 && $data['level'] != 1) {
                 mod_login::message('菜单级别和父级选择不正确');
             }
             if ($data['level'] < 2 && $data['act_url']) {
                 mod_login::message('一级,二级菜单不应该有对应URL');
             }
             $data['level'] = $data['level'] == 2 ? 3 : $data['level'];
             $ret = mod_menu::editmenu($data, $menu_id);
             if ($ret) {
                 mod_login::message("编辑菜单成功", '?c=menu&a=menulist');
             } else {
                 mod_login::message("编辑菜单失败");
             }
         } catch (Exception $e) {
             mod_login::message($e->getMessage());
         }
     } else {
         $menuinfo = mod_menu::get_one_menu($menu_id);
         //print_r($menuinfo);
         $parentmenu = mod_menu::get_parent_menu();
         $products = mod_menu::get_products();
         $topmenu = array(array('pid' => 8888888, 'pname' => '~客服管理~'), array('pid' => 9999999, 'pname' => '~产品汇总~'));
         $products = array_merge($products, $topmenu);
         $checked = mod_menu::get_proid($menu_id);
         if (is_array($checked)) {
             foreach ($products as &$value) {
                 foreach ($checked as $v) {
                     if ($value['pid'] == $v['product_id']) {
                         $value['checked'] = 1;
                     }
                 }
             }
         }
         $parentmenustr = '';
         $parentmenustr = '[';
         foreach ($parentmenu as $v) {
             $parentmenustr .= "[{$v['menu_id']},'{$v['menu_name']}'],";
         }
         $parentmenustr = substr($parentmenustr, 0, -1);
         $parentmenustr .= ']';
         pm_tpl::assign('parent_menu', $parentmenustr);
         pm_tpl::assign('menu', $menuinfo);
         $action_link = array('href' => '?c=menu&a=menulist', 'text' => '菜单管理');
         pm_tpl::assign('action_link', $action_link);
         pm_tpl::assign('ur_here', '编辑菜单');
         pm_tpl::assign('products', $products);
         pm_tpl::assign('prolist', $checked);
         pm_tpl::display('menu_editmenu');
     }
 }