Ejemplo n.º 1
0
 /**
  * 
  * 添加菜单执行页面
  * @author 张骥
  */
 public function insertAction()
 {
     /**
      * 记录日志
      */
     $log = "添加菜单执行页面\n\nServerIp:\n" . $this->request->getServer('SERVER_ADDR') . "\n\nGET:\n" . var_export($_GET, true) . "\n\nPOST:\n" . var_export($_POST, true);
     $this->oLogManager->push('log', $log);
     $this->manager->checkMenuPermission($this->sign, Widget_Manager::MENU_PURVIEW_INSERT);
     $name = $this->request->name;
     $link = $this->request->link;
     $sign = $this->request->sign;
     $sort = $this->request->sort;
     foreach ($_REQUEST as $key => $val) {
         if (strstr($key, "parent") && $val != 0) {
             $k = explode("_", $key);
             $parents[$k[1]] = $val;
         }
     }
     if (count($parents)) {
         ksort($parents);
         $parent = $parents[count($parents)];
     } else {
         $parent = 0;
     }
     $Menu = new Widget_Menu();
     //检查菜单名
     if (empty($name)) {
         $response = array('errno' => 1);
         echo json_encode($response);
         return false;
     }
     //检查菜单名是否已经存在
     if ($Menu->getByName($name)) {
         $response = array('errno' => 2);
         echo json_encode($response);
         return false;
     }
     $bind['name'] = $name;
     $bind['link'] = $link;
     $bind['sign'] = $sign;
     $bind['parent'] = $parent;
     $bind['sort'] = $sort;
     $menu_id = $Menu->insert($bind);
     if (!$menu_id) {
         $response = array('errno' => 9);
         echo json_encode($response);
         return false;
     }
     //更新权限
     $MenuPermission = new Widget_Menu_Permission();
     $bind = array();
     $bind['menu_id'] = $menu_id;
     $bind['group_id'] = $this->manager->menu_group_id;
     $bind['purview'] = bindec(1111);
     $res = $MenuPermission->insert($bind);
     if (!$res) {
         $response = array('errno' => 4);
     }
     $response = array('errno' => 0);
     echo json_encode($response);
 }