Просмотр исходного кода

Merge pull request #393 from visuddhinanda/master

wbw 支持权限判断
visuddhinanda 4 лет назад
Родитель
Сommit
c98d5061ac

+ 1 - 1
app/channal/function.php

@@ -47,7 +47,7 @@ class Channal extends Table
 
 
 	}
 	}
 	public function getPower($id){
 	public function getPower($id){
-		#查询用户对此channel是否有权限		
+		#查询用户对此channel是否有权限
 		if(isset($_COOKIE["userid"])){
 		if(isset($_COOKIE["userid"])){
 			$userId = $_COOKIE["userid"];
 			$userId = $_COOKIE["userid"];
 		}
 		}

+ 1 - 2
app/channal/get.php

@@ -27,7 +27,7 @@ foreach ($my_group as $key => $value) {
 $channelList = array();
 $channelList = array();
 
 
 //找自己的
 //找自己的
-PDO_Connect(""._FILE_DB_CHANNAL_);
+PDO_Connect(_FILE_DB_CHANNAL_);
 $query = "SELECT id,owner,name,status,lang FROM channal WHERE owner = ?  LIMIT 0,100";
 $query = "SELECT id,owner,name,status,lang FROM channal WHERE owner = ?  LIMIT 0,100";
 $Fetch_my = PDO_FetchAll($query,array($_COOKIE["userid"]));
 $Fetch_my = PDO_FetchAll($query,array($_COOKIE["userid"]));
 
 
@@ -38,7 +38,6 @@ foreach ($Fetch_my as $key => $value) {
 
 
 # 找协作的
 # 找协作的
 $coop_channal =  share_res_list_get($_COOKIE["userid"],2);
 $coop_channal =  share_res_list_get($_COOKIE["userid"],2);
-$Fetch_coop = array();
 foreach ($coop_channal as $key => $value) {
 foreach ($coop_channal as $key => $value) {
 	# return res_id,res_type,power res_title  res_owner_id
 	# return res_id,res_type,power res_title  res_owner_id
 	if(isset($channelList[$value["res_id"]])){
 	if(isset($channelList[$value["res_id"]])){

+ 11 - 12
app/channal/my_channal_post.php

@@ -46,7 +46,7 @@ else{
 		}
 		}
 	}
 	}
     // 设置 句子库和逐词译库可见性
     // 设置 句子库和逐词译库可见性
-    PDO_Connect(""._FILE_DB_SENTENCE_);
+    PDO_Connect(_FILE_DB_SENTENCE_);
     $query="UPDATE sentence SET language = ?  , status = ? where  channal = ?  ";
     $query="UPDATE sentence SET language = ?  , status = ? where  channal = ?  ";
     $sth = PDO_Execute($query,array($_POST["lang"],$_POST["status"],$_POST["id"]));
     $sth = PDO_Execute($query,array($_POST["lang"],$_POST["status"],$_POST["id"]));
     if (!$sth || ($sth && $sth->errorCode() != 0)) {
     if (!$sth || ($sth && $sth->errorCode() != 0)) {
@@ -54,17 +54,16 @@ else{
         $respond['status']=1;
         $respond['status']=1;
         $respond['message']=$error[2];
         $respond['message']=$error[2];
     }
     }
-    else{
-        // 设置 逐词译库可见性
-        PDO_Connect(""._FILE_DB_USER_WBW_);
-        $query="UPDATE wbw_block SET lang = ?  , status = ? where  channal = ?  ";
-        $sth = PDO_Execute($query,array($_POST["lang"],$_POST["status"],$_POST["id"]));
-        if (!$sth || ($sth && $sth->errorCode() != 0)) {
-            $error = PDO_ErrorInfo();
-            $respond['status']=1;
-            $respond['message']=$error[2];
-        }
-    }
+
+	// 设置 逐词译库可见性
+	PDO_Connect(_FILE_DB_USER_WBW_);
+	$query="UPDATE wbw_block SET lang = ?  , status = ? where  channal = ?  ";
+	$sth = PDO_Execute($query,array($_POST["lang"],$_POST["status"],$_POST["id"]));
+	if (!$sth || ($sth && $sth->errorCode() != 0)) {
+		$error = PDO_ErrorInfo();
+		$respond['status']=1;
+		$respond['message']=$error[2];
+	}	
 }
 }
 
 
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 17 - 0
app/db/table.php

@@ -23,6 +23,23 @@ class Table
 	public function setField($setting){
 	public function setField($setting){
 		$this->field_setting = $setting;
 		$this->field_setting = $setting;
 	}
 	}
+	protected function fetch($query,$params){
+		if (isset($params)) {
+			$stmt = $this->dbh->prepare($query);
+			if($stmt){
+				$stmt->execute($params);
+			}
+			
+		} else {
+			$stmt = $PDO->query($query);
+		}
+		if($stmt){
+			return $stmt->fetch(PDO::FETCH_ASSOC);
+		}
+		else{
+			return false;
+		}
+	}
 	public function syncList($time){
 	public function syncList($time){
 
 
 	}
 	}

+ 29 - 0
app/db/wbw_block.php

@@ -0,0 +1,29 @@
+<?php
+require_once "../path.php";
+require_once "../db/table.php";
+require_once "../channal/function.php";
+
+class WbwBlock extends Table
+{
+    function __construct($redis=false) {
+		parent::__construct(_FILE_DB_USER_WBW_, "wbw_block", "", "",$redis);
+    }
+
+	public function getPower($blockId){
+		$channelInfo = new Channal($this->redis);
+		$power = 0;
+		$query = "SELECT channal,owner from wbw_block   where id= ?  ";
+		$row = $this->fetch($query,array($blockId));
+		if($row ){
+			if(empty($row["channal"])){
+				if($row["owner"]==$_COOKIE["userid"]){
+					$power = 30;
+				}
+			}
+			else{
+				$power = $channelInfo->getPower($row["channal"]);
+			}
+		}
+		return $power;
+	}
+}

+ 281 - 0
app/doc/fork_channel.php

@@ -0,0 +1,281 @@
+<?php
+
+/*拷贝其他人的文件
+ *
+ *
+ */
+require_once '../studio/index_head.php';
+?>
+<body id="file_list_body" >
+<?php
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+require_once "../channal/function.php";
+require_once "../redis/function.php";
+
+$redis = redis_connect();
+
+require_once '../studio/index_tool_bar.php';
+
+echo '<div class="index_inner" style="    margin-left: 18em;margin-top: 5em;">';
+
+if ($_COOKIE["uid"]) {
+    $uid = $_COOKIE["uid"];
+} else {
+    echo "尚未登录";
+    echo "<h3><a href='../ucenter/index.php?op=login'>登录</a>后才可以打开文档 </h3>";
+    exit;
+}
+
+if(isset($_GET["para"])){
+    $_para = json_decode($_GET["para"]);
+}
+else{
+    echo "没有 para 编号";
+    exit;
+}
+
+if (isset($_GET["src_channel"]) == false) {
+    echo "没有 channel 编号";
+    exit;
+}
+    //文档信息
+    $mbook = $_GET["book"];
+    $paragraph = implode(",",$_para);
+
+if (isset($_GET["dest_channel"]) == false) {
+    echo '<div class="file_list_block">';
+    echo "<h2>选择一个空白的版风存储新的文档</h2>";
+    echo "<div>原有版本中相同段落的数据将被覆盖</div>";
+    echo "<form action='fork_channel.php' method='get'>";
+    echo "<input type='hidden' name='book' value='{$_GET["book"]}' />";
+    echo "<input type='hidden' name='para' value='{$_GET["para"]}' />";
+    echo "<input type='hidden' name='src_channel' value='{$_GET["src_channel"]}' />";
+    PDO_Connect(_FILE_DB_CHANNAL_);
+    $query = "select * from channal where owner = '{$_COOKIE["userid"]}'   limit 0,100";
+    $Fetch = PDO_FetchAll($query);
+    $i = 0;
+    PDO_Connect( _FILE_DB_USER_WBW_);	
+    foreach ($Fetch as $row) {
+        echo '<div class="file_list_row" style="padding:5px;display:flex;">';
+
+        echo '<div class="pd-10"  style="max-width:2em;flex:1;">';
+        echo '<input name="dest_channel" value="' . $row["id"] . '" ';
+        if ($i == 0) {
+            echo "checked";
+        }
+        echo ' type="radio" />';
+        echo '</div>';
+        echo '<div class="title" style="flex:3;padding-bottom:5px;">' . $row["name"] . '</div>';
+        echo '<div class="title" style="flex:3;padding-bottom:5px;">' . $row["lang"] . '</div>';
+        echo '<div class="title" style="flex:2;padding-bottom:5px;">';
+        $query = "select count(*) from wbw_block where channal = '{$row["id"]}' and book='{$mbook}' and paragraph in ({$paragraph})  limit 0,100";
+        $FetchWBW = PDO_FetchOne($query);
+        echo '</div>';
+        echo '<div class="title" style="flex:2;padding-bottom:5px;">';
+        if ($FetchWBW == 0) {
+            echo $_local->gui->blank;
+        } else {
+            echo $FetchWBW . $_local->gui->para;
+            echo "<a href='../studio/editor.php?op=openchannal&book=$book&para={$paraList}&channal={$row["id"]}'>open</a>";
+        }
+        echo '</div>';
+
+        echo '<div class="summary"  style="flex:1;padding-bottom:5px;">' . $row["status"] . '</div>';
+        echo '<div class="author"  style="flex:1;padding-bottom:5px;">' . $row["create_time"] . '</div>';
+
+        echo '</div>';
+        $i++;
+    }
+    echo "<input type='submit' />";
+    echo "</form>";
+    echo "</div>";
+    exit;
+}
+
+PDO_Connect( _FILE_DB_USER_WBW_);	
+
+$channelInfo= new Channal($redis);
+
+$srcPower = (int)$channelInfo->getPower($_GET["src_channel"]);
+
+{
+
+	{
+
+        if ($srcPower == 30) {
+            //自己的文档
+            echo "这是自己的文档,不能复刻。";
+        } else {
+            //别人的文档
+            //查询以前自己是否曾经复刻
+            $query = "select * from wbw_block where parent_channel=? and owner=? ";
+            $FetchSelf = PDO_FetchAll($query,array($_GET["src_channel"],$_COOKIE["userid"]));
+            $iFetchSelf = count($FetchSelf);
+            if ($iFetchSelf > 0) {
+                //以前打开过
+                echo "文档已经复刻";
+                echo "正在<a href='../studio/editor.php?op=openchannal&book={$_GET["book"]}&para={$_para[0]}&channal={$FetchSelf[0]["channal"]}'>打开</a>文档";
+                echo "<script>";
+                echo "window.location.assign(\"../studio/editor.php?op=openchannal&book={$_GET["book"]}&para={$_para[0]}&channal={$FetchSelf[0]["channal"]}\");";
+                echo "</script>";
+            } else {
+                //以前没打开过
+                echo "<h3>共享的文档,正在fork...</h3>";
+                echo "<div style='display:none;'>";
+
+				{
+                    //复制数据
+                    //打开逐词解析数据库
+                    $dns = _FILE_DB_USER_WBW_;
+                    $dbhWBW = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+                    $dbhWBW->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+                    //逐词解析新数据数组
+                    $arrNewBlock = array();
+                    $arrNewBlockData = array();
+                    $arrBlockTransform = array();
+
+                    $blocks = $_para;
+                    for ($i = 0; $i < count($blocks); $i++) {
+						$query = "select id from wbw_block where book= ? and paragraph = ? and channal = ? ";
+						$stmt = $dbhWBW->prepare($query);
+						$stmt->execute(array($_GET["book"],$iPara,$_GET["dest_channel"]));
+						$fDest = $stmt->fetch(PDO::FETCH_ASSOC);
+						if($fDest){
+							#旧的逐词解析数据块wbw_block id 
+							$destId = $fDest["id"];
+						}
+						#逐词解析
+						$iPara = $blocks[$i];
+						$query = "select * from wbw_block where book= ? and paragraph = ? and channal = ? ";
+						$stmt = $dbhWBW->prepare($query);
+						$stmt->execute(array($_GET["book"],$iPara,$_GET["src_channel"]));
+						$fBlock = $stmt->fetchAll(PDO::FETCH_ASSOC);
+						if(isset($destId)){
+							$newBlockId = $destId;
+						}
+						else{
+							$newBlockId = UUID::V4();
+						}
+						$arrBlockTransform[$fBlock[0]["id"]] = $newBlockId;
+						if (count($fBlock) > 0) {
+							array_push($arrNewBlock,
+								array($newBlockId,
+									"",
+									$_GET["dest_channel"],
+									$_GET["src_channel"],
+									$_COOKIE["userid"],
+									$fBlock[0]["book"],
+									$fBlock[0]["paragraph"],
+									$fBlock[0]["style"],
+									$fBlock[0]["lang"],
+									$fBlock[0]["status"],
+									mTime(),
+									mTime(),
+									mTime()
+								));
+						}
+
+						$query = "select * from wbw where block_id= ? ";
+						$stmtWBW = $dbhWBW->prepare($query);
+						$stmtWBW->execute(array($fBlock[0]["id"]));
+						$fBlockData = $stmtWBW->fetchAll(PDO::FETCH_ASSOC);
+						foreach ($fBlockData as $value) {
+							array_push($arrNewBlockData,
+								array(UUID::V4(),
+									$arrBlockTransform[$value["block_id"]],
+									$value["book"],
+									$value["paragraph"],
+									$value["wid"],
+									$value["word"],
+									$value["data"],
+									mTime(),
+									mTime(),
+									$value["status"],
+									$_COOKIE["userid"],
+								));
+
+						}
+
+                    }
+
+					# 查找目标block是否存在
+
+					//删除旧的逐词解析block数据块
+					$query = "DELETE from wbw_block where  paragraph = ? AND book = ? AND channal = ? ";
+					$stmt = $dbhWBW->prepare($query);
+					$stmt->execute(array($iPara,$_GET["book"],$_GET["dest_channel"]));
+					
+                    //新增逐词解析block数据块
+                    if (count($arrNewBlock) > 0) {
+                        $dbhWBW->beginTransaction();
+                        $query = "INSERT INTO wbw_block ('id','parent_id','channal','parent_channel','owner','book','paragraph','style','lang','status','modify_time','receive_time','create_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
+                        $stmtNewBlock = $dbhWBW->prepare($query);
+                        foreach ($arrNewBlock as $oneParam) {
+                            $stmtNewBlock->execute($oneParam);
+                        }
+                        // 提交更改
+                        $dbhWBW->commit();
+                        if (!$stmtNewBlock || ($stmtNewBlock && $stmtNewBlock->errorCode() != 0)) {
+                            $error = $dbhWBW->errorInfo();
+                            echo "error - $error[2] <br>";
+							exit;
+                        } else {
+                            //逐词解析block块复刻成功
+                            $count = count($arrNewBlock);
+                            echo "wbw block $count recorders.<br/>";
+                        }
+                    }
+
+					//删除逐词解析数据块
+					if(isset($destId)){
+						$query = "DELETE from wbw where  block_id = ? ";
+						$stmt = $dbhWBW->prepare($query);
+						$stmt->execute($destId);
+					}
+					
+                    if (count($arrNewBlockData) > 0) {
+                        // 开始一个事务,逐词解析数据 关闭自动提交
+                        $dbhWBW->beginTransaction();
+                        $query = "INSERT INTO wbw ('id','block_id','book','paragraph','wid','word','data','modify_time','receive_time','status','owner') VALUES (?,?,?,?,?,?,?,?,?,?,?)";
+                        $stmtWbwData = $dbhWBW->prepare($query);
+                        foreach ($arrNewBlockData as $oneParam) {
+                            $stmtWbwData->execute($oneParam);
+                        }
+                        // 提交更改
+                        $dbhWBW->commit();
+                        if (!$stmtWbwData || ($stmtWbwData && $stmtWbwData->errorCode() != 0)) {
+                            $error = $dbhWBW->errorInfo();
+                            echo "error - $error[2] <br>";
+							exit;
+                        } else {
+                            //逐词解析 数据 复刻成功
+                            $count = count($arrNewBlockData);
+                            echo "new wbw $count recorders.";
+                        }
+                    }
+
+                   {
+                        //成功
+                        echo "doc list updata 1 recorders.";
+                        echo "</div>";
+                        echo "<h3>复刻成功</h3>";
+                        echo "正在<a href='../studio/editor.php?op=openchannal&book={$_GET["book"]}&para={$_para[0]}&channal={$_GET["dest_channel"]}'>打开</a>文档";
+                        echo "<script>";
+                        echo "window.location.assign(\"../studio/editor.php?op=openchannal&book={$_GET["book"]}&para={$_para[0]}&channal={$_GET["dest_channel"]}\");";
+                        echo "</script>";
+                    }
+                }
+
+            }
+        }
+    }
+}
+
+echo "</div>";
+?>
+
+</body>
+</html>

+ 1 - 1
app/studio/dict_find_one.php

@@ -83,7 +83,7 @@ if ($dict_name == "") {
 } else {
 } else {
     $dict_list = str_getcsv($dict_name, ',');
     $dict_list = str_getcsv($dict_name, ',');
     foreach ($dict_list as $dict) {
     foreach ($dict_list as $dict) {
-        $db_file_list[] = array( $dict,"");
+        $db_file_list[] = array( $dict,"",false);
     }
     }
 }
 }
 
 

+ 17 - 3
app/term/term.css

@@ -294,12 +294,22 @@ note > .tran .tran_text_tool_bar::after,
 
 
 note > .palitext,
 note > .palitext,
 .palitext {
 .palitext {
-	font-family: Noto serif;
 	line-height: 1.5em;
 	line-height: 1.5em;
 	color: #9f3a01;
 	color: #9f3a01;
 	font-weight: 500;
 	font-weight: 500;
 	margin: 4px;
 	margin: 4px;
 }
 }
+h1 .palitext {
+	font-family: "Noto Serif", "Noto Sans TC", "Noto Sans SC";
+	font-weight: 700;
+	font-size: 130%;
+}
+h2 .palitext {
+	font-family: "Noto Serif", "Noto Sans TC", "Noto Sans SC";
+	font-weight: 700;
+	font-size: 120%;
+}
+
 note n {
 note n {
 	display: inline;
 	display: inline;
 	color: blue;
 	color: blue;
@@ -880,9 +890,13 @@ span.keybutton {
 	word-break: break-word;
 	word-break: break-word;
 }
 }
 span.tran_sent {
 span.tran_sent {
-	display: block;
+	line-height: 1.7em;
+}
+.tran_sent ul,
+.tran_sent li {
+	list-style-type: unset;
+	margin-left: 1em;
 }
 }
-
 .icon_sent_status {
 .icon_sent_status {
 	display: none;
 	display: none;
 	width: 22px;
 	width: 22px;

+ 0 - 39
app/uwbw/sync_block.php

@@ -1,39 +0,0 @@
-<?php
-//header('Content-type: application/json; charset=utf8');
-
-require_once "../path.php";
-require_once "../sync/function.php";
-
-$input = (object) [
-    "database" =>  _FILE_DB_USER_WBW_,
-    "table" =>  "wbw_block",
-    "uuid" =>  "id",
-    "modify_time" =>  "modify_time",
-    "receive_time" =>  "receive_time",
-    "insert" => [
-        "id",
-        "parent_id",
-        "book",
-        "paragraph",
-        "owner",
-        "lang",
-        "author",
-        "editor",
-        "tag",
-        "status",
-        "modify_time",
-        "receive_time"
-    ],
-    "update" =>  [
-        "lang",
-        "author",
-        "editor",
-        "tag",
-        "status",
-        "receive_time"
-    ]    
-];
-
-do_sync($input);
-
-?>

+ 0 - 39
app/uwbw/sync_wbw.php

@@ -1,39 +0,0 @@
-<?php
-//header('Content-type: application/json; charset=utf8');
-
-require_once "../path.php";
-require_once "../sync/function.php";
-
-$input = (object) [
-    "database" =>  _FILE_DB_USER_WBW_,
-    "table" =>  "wbw",
-    "uuid" =>  "id",
-    "modify_time" =>  "modify_time",
-    "receive_time" =>  "receive_time",
-    "insert" => [
-        "id",
-        "parent_id",
-        "book",
-        "paragraph",
-        "owner",
-        "lang",
-        "author",
-        "editor",
-        "tag",
-        "status",
-        "modify_time",
-        "receive_time"
-    ],
-    "update" =>  [
-        "lang",
-        "author",
-        "editor",
-        "tag",
-        "status",
-        "receive_time"
-    ]    
-];
-
-do_sync($input);
-
-?>

+ 29 - 2
app/uwbw/update.php

@@ -7,9 +7,15 @@ require_once "../public/_pdo.php";
 require_once "../public/function.php";
 require_once "../public/function.php";
 require_once "../ucenter/active.php";
 require_once "../ucenter/active.php";
 require_once "../redis/function.php";
 require_once "../redis/function.php";
+require_once "../channal/function.php";
+require_once "../db/wbw_block.php";
+
 
 
 $respond['status'] = 0;
 $respond['status'] = 0;
 $respond['message'] = "";
 $respond['message'] = "";
+$redis = redis_connect();
+$channelInfo = new Channal($redis);
+$_WbwBlock = new WbwBlock($redis);
 
 
 if (isset($_POST["data"])) {
 if (isset($_POST["data"])) {
     $aData = json_decode($_POST["data"]);
     $aData = json_decode($_POST["data"]);
@@ -25,13 +31,29 @@ if (count($aData) > 0) {
 
 
     PDO_Connect(_FILE_DB_USER_WBW_);
     PDO_Connect(_FILE_DB_USER_WBW_);
 
 
+	#确定block id 的写入权限
+	$listBlockId=array();
+	foreach ($aData as $data) {
+        $listBlockId[$data->block_id]=0;
+    }
+	#查询channel 的 权限
+	$maxPower=0;
+	foreach ($listBlockId as $key => $value) {
+		$listBlockId[$key] = $_WbwBlock->getPower($key);
+		if($listBlockId[$key]>$maxPower){
+			$maxPower = $listBlockId[$key];
+		}
+	}
+
     /* 开始一个事务,关闭自动提交 */
     /* 开始一个事务,关闭自动提交 */
     $PDO->beginTransaction();
     $PDO->beginTransaction();
     $query = "UPDATE wbw SET data= ?  , receive_time= ?  , modify_time= ?   where block_id= ?  and wid= ?  ";
     $query = "UPDATE wbw SET data= ?  , receive_time= ?  , modify_time= ?   where block_id= ?  and wid= ?  ";
     $sth = $PDO->prepare($query);
     $sth = $PDO->prepare($query);
 
 
     foreach ($aData as $data) {
     foreach ($aData as $data) {
-        $sth->execute(array($data->data, mTime(), $data->time, $data->block_id, $data->word_id));
+		if($listBlockId[$data->block_id]>=20){
+			$sth->execute(array($data->data, mTime(), $data->time, $data->block_id, $data->word_id));
+		}
     }
     }
     $PDO->commit();
     $PDO->commit();
 
 
@@ -48,9 +70,14 @@ if (count($aData) > 0) {
         $respond['status'] = 0;
         $respond['status'] = 0;
         $respond['message'] = "成功";
         $respond['message'] = "成功";
     }
     }
+	
+	if($maxPower<20){
+		$respond['status'] = 1;
+        $respond['message'] = "没有修改权限";
+	}
 	if (count($aData) ==1){
 	if (count($aData) ==1){
-		$redis = redis_connect();
 		try {
 		try {
+			#将数据插入redis 作为自动匹配最新数据
 			if($redis){
 			if($redis){
 				$xmlString = "<root>" . $data->data . "</root>";
 				$xmlString = "<root>" . $data->data . "</root>";
 				$xmlWord = simplexml_load_string($xmlString);
 				$xmlWord = simplexml_load_string($xmlString);

+ 45 - 7
app/uwbw/wbw_channal_list.js

@@ -33,19 +33,45 @@ function wbw_channal_list_open(book, paralist) {
 				let html = "";
 				let html = "";
 				for (let index = 0; index < _wbw_channel.data.length; index++) {
 				for (let index = 0; index < _wbw_channel.data.length; index++) {
 					const element = _wbw_channel.data[index];
 					const element = _wbw_channel.data[index];
-					html += "<div style='display:flex;line-height: 2.5em;'>";
-					html += "<span style='flex:2'>";
-					html += "<button onclick=\"wbw_create('" + index + "')\">";
+					html += "<div style='display:flex;line-height: 2.5em;border-bottom: 1px solid gray;'>";
+					html += "<span style='flex:4'>";
+					let style = "";
+					let text = "";
 					if (parseInt(element.wbw_para) > 0) {
 					if (parseInt(element.wbw_para) > 0) {
-						html += gLocal.gui.open;
+						if (parseInt(element.power) < 20) {
+							text = "查看";
+							style = "background-color: yellow;";
+						} else {
+							text = gLocal.gui.edit;
+							style = "background-color: greenyellow;";
+						}
 					} else {
 					} else {
-						html += gLocal.gui.new;
+						text = gLocal.gui.new;
+					}
+					html +=
+						"<button style='" + style + "' onclick=\"wbw_create('" + index + "')\">" + text + "</button>";
+
+					if (parseInt(element.power) < 30) {
+						html += "<button onclick=\"wbw_fork('" + index + "')\">";
+						html += "复制到";
+						html += "</button>";
 					}
 					}
 
 
-					html += "</button>";
 					html += "</span>";
 					html += "</span>";
 					html += "<span  style='flex:1'>" + (index + 1) + "</span>";
 					html += "<span  style='flex:1'>" + (index + 1) + "</span>";
-					html += "<span style='flex:3'>" + element.name + "</span>";
+					html += "<span style='flex:5'>" + element.name + "</span>";
+					html += "<span style='flex:1'>";
+					let power = [
+						{ id: 10, note: "查看者" },
+						{ id: 20, note: "编辑者" },
+						{ id: 30, note: "拥有者" },
+					];
+					for (const iterator of power) {
+						if (parseInt(element.power) == iterator.id) {
+							html += iterator.note;
+						}
+					}
+					html += "</span>";
 					html += "<span style='flex:2'>" + element.lang + "</span>";
 					html += "<span style='flex:2'>" + element.lang + "</span>";
 					html += "<span style='flex:2;display:none;'>" + element.wbw_para + "/" + element.count + "</span>";
 					html += "<span style='flex:2;display:none;'>" + element.wbw_para + "/" + element.count + "</span>";
 					html += "</div>";
 					html += "</div>";
@@ -87,3 +113,15 @@ function wbw_create(index) {
 		}
 		}
 	);
 	);
 }
 }
+
+function wbw_fork(index) {
+	$("#wbw_channal_list_dlg").dialog("close");
+	let url =
+		"../doc/fork_channel.php?book=" +
+		_wbw_channel.book +
+		"&para=" +
+		_wbw_channel.para +
+		"&src_channel=" +
+		_wbw_channel.data[index].id;
+	window.open(url, "_blank");
+}

+ 58 - 8
app/uwbw/wbw_channel_list.php

@@ -2,6 +2,11 @@
 require_once '../path.php';
 require_once '../path.php';
 require_once "../public/_pdo.php";
 require_once "../public/_pdo.php";
 require_once "../public/function.php";
 require_once "../public/function.php";
+require_once '../share/function.php';
+require_once '../channal/function.php';
+require_once '../redis/function.php';
+
+$redis = redis_connect();
 
 
 $output["status"] = 0;
 $output["status"] = 0;
 $output["error"] = "";
 $output["error"] = "";
@@ -23,19 +28,64 @@ $place_holders = implode(',', array_fill(0, count($_para), '?'));
 $params = $_para;
 $params = $_para;
 $params[] = $_book;
 $params[] = $_book;
 
 
-PDO_Connect("" . _FILE_DB_CHANNAL_);
-$query = "SELECT * FROM channal WHERE owner = ?  LIMIT 0,100";
+#查重复
+$channelList = array();
+
+PDO_Connect(_FILE_DB_CHANNAL_);
+$query = "SELECT id FROM channal WHERE owner = ?  LIMIT 0,100";
 $FetchChannal = PDO_FetchAll($query, array($_COOKIE["userid"]));
 $FetchChannal = PDO_FetchAll($query, array($_COOKIE["userid"]));
+
+foreach ($FetchChannal as $key => $value) {
+	# code...
+	$channelList[$value["id"]]=array("power"=>30);
+}
+
+# 找协作的
+$coop_channal =  share_res_list_get($_COOKIE["userid"],2);
+foreach ($coop_channal as $key => $value) {
+	# return res_id,res_type,power res_title  res_owner_id
+	if(isset($channelList[$value["res_id"]])){
+		if($channelList[$value["res_id"]]<(int)$value["power"]){
+			$channelList[$value["res_id"]]=array("power"=>(int)$value["power"]);
+		}
+	}
+	else{
+		$channelList[$value["res_id"]]=array("power"=>(int)$value["power"]);
+	}
+}
+
+# 查询全网公开 的
+PDO_Connect( _FILE_DB_USER_WBW_);
+$query = "SELECT  channal FROM wbw_block WHERE  paragraph IN ($place_holders)  AND book = ? AND channal IS NOT NULL AND status = 30 group by channal ";
+$publicChannel = PDO_FetchAll($query, $params);
+foreach ($publicChannel as $key => $channel) {
+	# code...
+	if(!isset($channelList[$channel["channal"]])){
+		$channelList[$channel["channal"]]=array("power"=>10);
+	}
+}
+
+$channelInfo = new Channal($redis);
 $i = 0;
 $i = 0;
-foreach ($FetchChannal as $key => $row) {
-    PDO_Connect("" . _FILE_DB_USER_WBW_);
+$outputData = array();
 
 
+
+foreach ($channelList as $key => $row) {
     $queryParam = $params;
     $queryParam = $params;
-    $queryParam[] = $row["id"];
+    $queryParam[] = $key;
     $query = "SELECT count(*) FROM wbw_block WHERE  paragraph IN ($place_holders)  AND book = ? AND channal = ? ";
     $query = "SELECT count(*) FROM wbw_block WHERE  paragraph IN ($place_holders)  AND book = ? AND channal = ? ";
     $wbwCount = PDO_FetchOne($query, $queryParam);
     $wbwCount = PDO_FetchOne($query, $queryParam);
-    $FetchChannal[$key]["wbw_para"] = $wbwCount;
-    $FetchChannal[$key]["count"] = count($_para);
+    $channelList[$key]["wbw_para"] = $wbwCount;
+    $channelList[$key]["count"] = count($_para);
+	$info = $channelInfo->getChannal($key);
+    $channelList[$key]["id"] = $info["id"];
+    $channelList[$key]["name"] = $info["name"];
+    $channelList[$key]["lang"] = $info["lang"];
+	$outputData[]=$channelList[$key];
 }
 }
-$output["data"] = $FetchChannal;
+
+
+
+
+$output["data"] = $outputData;
 echo json_encode($output, JSON_UNESCAPED_UNICODE);
 echo json_encode($output, JSON_UNESCAPED_UNICODE);