public function edit()
 {
     if (!IS_AJAX) {
         $this->error(L('_ERROR_ACTION_'));
     }
     $Type = M('Type');
     $lang = I('get.lang') ? I('get.lang') : $this->clang;
     $list = $Type->field('id,pid,name')->where('status=1 AND lang=\'' . $lang . '\'')->select();
     $tree = new \Common\Lib\Tree($list);
     if (IS_POST) {
         if ($Type->create()) {
             $Model = new \Think\Model();
             $query = $Model->query("SHOW TABLE STATUS LIKE '__TYPE__'");
             $nextid = $query[0]['auto_increment'];
             $top = I('post.pid') == 0 ? $nextid : $tree->get_top(I('post.pid'));
             $data = array('pid' => I('post.pid'), 'name' => I('post.name'), 'description' => I('post.description'), 'status' => I('post.status') ? 1 : 0, 'keyid' => $top['id'], 'lang' => I('post.lang'));
             $result = $Type->where('id=' . I('post.id'))->save($data);
             if ($result !== FALSE) {
                 $this->success(L('SAVE_OK'), U('Type/index', $this->vl . '&pid=' . $data['pid']));
             } else {
                 $this->error(L('SAVE_ERROR'));
             }
         } else {
             $this->error($Type->getError());
         }
     } else {
         $str = "<li data-val='\$id'>\$spacer\$name</li>";
         $vo = $Type->where('id=' . I('get.id'))->find();
         $this->assign('pids', $tree->get_tree(0, $str));
         $this->assign('vo', $vo);
         $this->display();
     }
 }
 public function edit()
 {
     if (!IS_AJAX) {
         $this->error(L('_ERROR_ACTION_'));
     }
     $Cat = D('Category');
     if (IS_POST) {
         print_r(I('post.'));
     } else {
         if (I('get.lang')) {
             $l = I('get.lang');
         } elseif ($this->clang) {
             $l = $this->clang;
         } else {
             $l = LANG_SET;
         }
         $cats = $Cat->where('status=1 AND lang=\'' . $l . '\'')->order('listorder')->select();
         $tree = new \Common\Lib\Tree($cats);
         $tree->icon = array('<span class="text-muted">&ensp;│</span>', '<span class="text-muted">&ensp;├─</span>', '<span class="text-muted">&ensp;└─</span>');
         $str = "<li data-val='\$id'>\$spacer\$name</li>";
         $Module = M('Module');
         $modules = $Module->where('status=1 AND type=1')->select();
         $vo = $Cat->where('id=' . I('get.id'))->find();
         $Urlrule = M('Urlrule');
         $rules = $Urlrule->where('ishtml=1')->order('listorder asc')->select();
         $this->assign('modules', $modules);
         $this->assign('cats', $tree->get_tree(0, $str));
         $this->assign('urlrules', $rules);
         $this->assign('vo', $vo);
         $this->display();
     }
 }
 public function edit()
 {
     if (!IS_AJAX) {
         $this->error(L('_ERROR_ACTION_'));
     }
     $Menu = D('Menu');
     if (IS_GET) {
         $vo = $Menu->where('id=' . I('get.id'))->find();
         $map = $Menu->where('status=1')->select();
         foreach ($map as $r) {
             $r['name'] = L($r['name']);
             $newmap[] = $r;
         }
         $tree = new \Common\Lib\Tree($newmap);
         $tree->icon = array('<span class="text-muted">&ensp;│</span>', '<span class="text-muted">&ensp;├─</span>', '<span class="text-muted">&ensp;└─</span>');
         $str = "<li data-val='\$id'>\$spacer\$name</li>";
         $this->assign('pid', $vo['pid']);
         $this->assign('map', $tree->get_tree(0, $str));
         $this->assign('vo', $vo);
         $this->display();
     } elseif (IS_POST) {
         if ($Menu->create()) {
             $mstr = strtoupper(I('post.model'));
             $astr = strtoupper(I('post.action') ? I('post.action') : 'index');
             $pstr = I('post.data') ? '_' . strtoupper(I('post.data')) : '';
             $name = 'M_' . $mstr . '_' . $astr . $pstr;
             $data = array('pid' => I('post.pid'), 'name' => $name, 'icon' => I('post.icon'), 'model' => ucfirst(I('post.model')), 'action' => I('post.action') ? strtolower(I('post.action')) : 'index', 'data' => I('post.data'), 'remark' => I('post.remark'), 'status' => I('post.status') ? 1 : 0, 'listorder' => I('post.listorder'));
             $result = $Menu->where('id=' . I('post.id'))->save($data);
             if ($result !== FALSE) {
                 $rname = I('post.realname');
                 write_lang(array($data['name'] => $rname[LANG_SET]), 'menu_common');
                 $this->success(L('SAVE_OK'), U('Menu/index', $this->vl));
             } else {
                 $this->error(L('SAVE_ERROR'));
             }
         } else {
             $this->error($Menu->getError());
         }
     }
 }