Exemple #1
0
 /**
  * @name acl_addLibrary
  * @package new  group
  * @param array $lib_array  array("lib name"=>array("lib name"=>array("read","create"), "lib name"=>array("read")), "5"=>array("dd"=>));
  * @param String $groupName
  * @param String $desc
  * @param int $position
  * @return false or group id
  */
 public function acl_addLibrary($lib_array, $groupName, $desc, $position)
 {
     if (!is_array($lib_array)) {
         return false;
     }
     $format = "INSERT INTO `" . DB_PRE_CORE . "group` (`name`, `desc`, `position`, `permissions`, `types`)";
     $format .= " VALUES ( '%s', '%s', '%d', '%s', " . DB_TYPE_DIFFERENCE . ")";
     $sql = sprintf($format, $groupName, $desc, $position, json_encode($lib_array));
     $res = $this->Insert($sql, GetPB("w", "1"));
     if (!is_array($res)) {
         return false;
     } else {
         return $res[0]['id'];
     }
 }
Exemple #2
0
 /**
  * @name acl_save_lib
  * @package save lib for admin ON DUPLICATE KEY UPDATE
  * @return false
  */
 private function acl_save_lib($lib_arr)
 {
     if (count($lib_arr) < 1) {
         return;
     }
     $add_menu = "INSERT INTO `" . DB_PRE_CORE . "roles` ( `pid`, `lib`, `name`, `desc`, `ismenu`, `types`)";
     $add_menu .= " VALUES ( '%d', '%s', '%s', '%s', '%d', '%d')";
     $update_menu = "UPDATE `" . DB_PRE_CORE . "roles` SET `name` = '%s', `desc`='%s' WHERE `id` = %d and types=%d;";
     $slist = "SELECT id FROM `" . DB_PRE_CORE . "roles` where lib='%s' and types =%d limit 1";
     $pid = 0;
     foreach ($lib_arr as $k => $v) {
         if (!isset($v[$k . '_index'])) {
             continue;
         }
         $sql_list = sprintf($slist, $k, DB_TYPE_DIFFERENCE);
         $res = $this->FetchOne($sql_list);
         if (empty($res['id'])) {
             $pid = 0;
             $sql = sprintf($add_menu, $pid, $k, $v[$k . '_index'], '', '', DB_TYPE_DIFFERENCE);
             $pid = $this->Insert($sql, GetPB("w", "1"));
             if (isset($pid[0]['id'])) {
                 $pid = $pid[0]['id'];
             } else {
                 throw new \Exception("save_lib '{$sql}' sql insert error, aclrole.php.");
             }
         } else {
             $pid = $res['id'];
             $sql = sprintf($update_menu, $v[$k . '_index'], '', $pid, DB_TYPE_DIFFERENCE);
             $this->Update($sql);
         }
         if (!is_array($v)) {
             continue;
         }
         foreach ($v as $sub_k => $sub_v) {
             if (!is_array($sub_v)) {
                 continue;
             }
             $sql = sprintf($slist, $sub_k, DB_TYPE_DIFFERENCE);
             $res = $this->FetchOne($sql);
             if (empty($res)) {
                 $sql = sprintf($add_menu, $pid, $sub_k, $sub_v['name'], $sub_v['desc'], $sub_v['ismenu'], DB_TYPE_DIFFERENCE);
                 $this->Insert($sql);
             } else {
                 $id = $res['id'];
                 $sql = sprintf($update_menu, $sub_v['name'], $sub_v['desc'], $id, DB_TYPE_DIFFERENCE);
                 $this->Update($sql);
             }
         }
     }
 }