| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 | 
							- <?php
 
- namespace Manage\Src;
 
- use Dever;
 
- class Top
 
- {
 
-     /**
 
-      * 获取所有的头部菜单权限
 
-      *
 
-      * @return array
 
-      */
 
-     public function all()
 
-     {
 
-         $top = Dever::db('manage/top')->main();
 
-         $result = array();
 
-         if ($top) {
 
-             $child = Dever::db('manage/top')->child();
 
-             foreach ($top as $k => $v) {
 
-                 $k = str_replace('/', '-', $k);
 
-                 $result[$k] = $v;
 
-                 if (isset($child[$v['id']])) {
 
-                     $c = 0;
 
-                     foreach ($child[$v['id']] as $i => $j) {
 
-                         $i = str_replace('/', '-', $i);
 
-                         $result[$k]['child'][$i] = $j;
 
-                         $c++;
 
-                     }
 
-                     if (!isset($result[$k]['child'])) {
 
-                         unset($result[$k]);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         return $result;
 
-     }
 
-     /**
 
-      * menu 从数据库中得到所有权限
 
-      *
 
-      * @return array
 
-      */
 
-     public function get($auth = true)
 
-     {
 
-         # 得到当前的项目和表
 
-         $config = Dever::load('manage/database.config');
 
-         if (empty($config['top']) || is_array($config['top'])) {
 
-             return array();
 
-         }
 
-         $auth = true;
 
-         if ($auth) {
 
-             # 需要验证权限
 
-             $auth = Dever::load('manage/auth.top');
 
-         }
 
-         $top = Dever::db('manage/top')->main();
 
-         if ($top) {
 
-             $child = Dever::db('manage/top')->child();
 
-             foreach ($top as $k => $v) {
 
-                 /*
 
-                 if ($auth && strpos($auth, $k . '_') === false) {
 
-                     unset($top[$k]);
 
-                     continue;
 
-                 }
 
-                 */
 
-                 if (isset($child[$v['id']])) {
 
-                     # 如果已经保存了,就直接取出来吧
 
-                     //$info = Dever::load('manage/auth.getTop', $v['key']);
 
-                     $info = Dever::load('manage/auth.getTop', $config['top']);
 
-                     if ($info) {
 
-                         $top[$k]['name'] = $info['name'];
 
-                     }
 
-                     $c = 0;
 
-                     foreach ($child[$v['id']] as $i => $j) {
 
-                         if (strstr($i, $config['top'])) {
 
-                             $i = str_replace('/', '-', $i);
 
-                             if (($auth && strpos($auth . ',', $i . ',') === false) || ($info && $info['id'] == $j['id'])) {
 
-                             } elseif (!$info && $c == 0) {
 
-                                 $top[$k]['name'] = $j['name'];
 
-                                 Dever::load('manage/auth._setTop', $j);
 
-                                 $c++;
 
-                             } else {
 
-                                 $top[$k]['child'][$i] = $j;
 
-                                 $c++;
 
-                             }
 
-                         }
 
-                     }
 
-                     if (!isset($top[$k]['child'])) {
 
-                         //unset($top[$k]);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         if (isset($_GET['test']) && $_GET['test'] == 1) {
 
-             print_r($config);
 
-             print_r($child);
 
-             print_r($top);die;
 
-         }
 
-         //print_r($top);die;
 
-         return $top;
 
-     }
 
-     /**
 
-      * 更新数据到数据库
 
-      *
 
-      * @return array
 
-      */
 
-     public function update($param = array())
 
-     {
 
-         if (isset($param['key'])) {
 
-             $info = Dever::db('manage/top')->key(array('where_key' => $param['key']));
 
-             //print_r($info);die;
 
-             if (!$info) {
 
-                 $update['add_key'] = $param['key'];
 
-                 $update['add_name'] = $param['name'];
 
-                 $update['add_top_id'] = isset($param['top']) ? $param['top'] : -1;
 
-                 $update['add_value'] = $param['value'];
 
-                 $update['add_state'] = isset($param['state']) ? $param['state'] : 1;
 
-                 $info['id'] = Dever::db('manage/top')->insert($update);
 
-             } else {
 
-                 $update['set_name'] = $param['name'];
 
-                 $update['set_value'] = $param['value'];
 
-                 $update['set_state'] = isset($param['state']) ? $param['state'] : 1;
 
-                 $update['where_id'] = $info['id'];
 
-                 Dever::db('manage/top')->update($update);
 
-             }
 
-             return $info['id'];
 
-         }
 
-         return false;
 
-     }
 
-     /**
 
-      * 同步子权限更新到数据库
 
-      *
 
-      * @return array
 
-      */
 
-     public function sync($id, $name, $param = array(), $info_id = false)
 
-     {
 
-         if ($id && isset($param['top'])) {
 
-             $key = $param['top']['key'];
 
-             if (!$info_id) {
 
-                 $info = Dever::db('manage/top')->key(array('where_key' => $key));
 
-             } else {
 
-                 $info['id'] = $info_id;
 
-             }
 
-             
 
-             if ($info) {
 
-                 $update['value'] = Dever::input('where_id', $id);
 
-                 $update['name'] = Dever::param($param['top']['col'], $param);
 
-                 $update['top'] = $info['id'];
 
-                 if (isset($param['top']['type']) && $param['top']['type']) {
 
-                     $type = Dever::param($param['top']['type'], $param);
 
-                     $update['key'] = $key . '-' . $type . '_' . $update['value'];
 
-                 } else {
 
-                     $update['key'] = $key . '_' . $update['value'];
 
-                 }
 
-                 $update['state'] = Dever::param('state', $param);
 
-                 $this->update($update);
 
-             } else {
 
-                 $update['value'] = $param['top']['value'];
 
-                 $update['name'] = $param['top']['name'];
 
-                 $update['key'] = $key;
 
-                 $update['top'] = -1;
 
-                 $update['state'] = 1;
 
-                 $id = Dever::db('manage/top')->insert($update);
 
-                 $this->sync($id, $name, $param, $id);
 
-             }
 
-         }
 
-     }
 
-     /**
 
-      * 更新当前使用的top菜单
 
-      *
 
-      * @return array
 
-      */
 
-     public function update_action_api($id = false)
 
-     {
 
-         $id = $id ? $id : Dever::input('id');
 
-         $id = intval($id);
 
-         if ($id > 0) {
 
-             # 需要验证权限
 
-             $auth = Dever::load('manage/auth.top');
 
-             $info = Dever::db('manage/top')->one($id);
 
-             $info['key'] = str_replace('/', '-', $info['key']);
 
-             if ($info && $info['top_id'] > 0 && (!$auth || strpos($auth . ',', $info['key'] . ',') !== false)) {
 
-                 Dever::load('manage/auth._setTop', $info);
 
-             }
 
-             return $info['value'];
 
-         }
 
-     }
 
- }
 
 
  |