Browse Source

Merge pull request #323 from visuddhinanda:master

channel指南
Bhikkhu-Kosalla 5 years ago
parent
commit
41e2284544
100 changed files with 5486 additions and 4911 deletions
  1. 1 0
      .gitignore
  2. 57 64
      app/admin/db_update_cs6_para.php
  3. 77 80
      app/admin/setting.php
  4. 31 35
      app/admin/update_user_active_time.php
  5. 116 123
      app/admin/word_index_weight_refresh.php
  6. 1 1
      app/article/add_article_to_collect.php
  7. 2 2
      app/article/collect_get.php
  8. 1 1
      app/article/collect_list.php
  9. 1 1
      app/article/get.php
  10. 1 1
      app/article/list.php
  11. 1 1
      app/article/list_article_in_collect.php
  12. 1 1
      app/article/list_new.php
  13. 3 3
      app/article/my_article_post.php
  14. 1 1
      app/article/my_article_put.php
  15. 1 1
      app/article/my_collect_post.php
  16. 1 1
      app/article/my_collect_put.php
  17. 63 66
      app/calendar/index.html
  18. 32 3
      app/channal/channal.js
  19. 3 0
      app/channal/channal_add_dlg.js
  20. 21 0
      app/channal/coop_new_user.php
  21. 1 1
      app/channal/function.php
  22. 2 2
      app/channal/get.php
  23. 2 0
      app/channal/my_channal_edit.php
  24. 2 2
      app/channal/my_channal_get.php
  25. 4 0
      app/channal/my_channal_index.php
  26. 3 3
      app/channal/my_channal_post.php
  27. 1 1
      app/channal/my_channal_put.php
  28. 1 1
      app/collect/function.php
  29. 1 1
      app/collect/list.php
  30. 1 1
      app/course/course_get.php
  31. 1 1
      app/course/course_list.php
  32. 1 1
      app/course/lesson_get.php
  33. 1 1
      app/course/lesson_list.php
  34. 1 1
      app/course/list_new.php
  35. 1 1
      app/course/my_course_edit.php
  36. 1 1
      app/course/my_course_insert.php
  37. 1 1
      app/course/my_course_list.php
  38. 1 1
      app/course/my_course_update.php
  39. 1 1
      app/course/my_lesson_edit.php
  40. 1 1
      app/course/my_lesson_insert.php
  41. 1 1
      app/course/my_lesson_list.php
  42. 1 1
      app/course/my_lesson_new.php
  43. 1 1
      app/course/my_lesson_update.php
  44. 2 2
      app/course/teacher_list.php
  45. 0 1
      app/dict/README.md
  46. 104 0
      app/dict/comp_csv.php
  47. 41 16
      app/dict/dict.js
  48. 309 382
      app/dict/dict_lookup.php
  49. 58 0
      app/dict/dict_lookup_pre.php
  50. 95 63
      app/dict/index.php
  51. 39 0
      app/dict/multi-core.bat
  52. 19 0
      app/dict/p_ending.php
  53. 46 0
      app/dict/pali_word_list_to_redis.php
  54. 146 470
      app/dict/split.php
  55. 493 0
      app/dict/turbo_split.php
  56. 1 1
      app/dict_builder/dict_find3.php
  57. 2 2
      app/dict_builder/get_one_word.php
  58. 1 1
      app/dict_builder/index - 副本.php
  59. 88 94
      app/dict_builder/index.php
  60. 61 72
      app/dict_builder/save.php
  61. 137 145
      app/doc/coop.php
  62. 1 1
      app/doc/coopfilelist.php
  63. 40 45
      app/doc/docinfo.php
  64. 4 4
      app/doc/edit_wbw.php
  65. 398 407
      app/doc/fork.php
  66. 69 75
      app/doc/load_channal_para.php
  67. 252 269
      app/doc/pcs2db.php
  68. 7 0
      app/es/test.php
  69. 5 0
      app/es/uuid.php
  70. 29 31
      app/fullcalendar/examples/php/get-date.php
  71. 0 0
      app/group/doc_del.php
  72. 30 34
      app/group/function.php
  73. 35 38
      app/group/get.php
  74. 9 10
      app/group/get_name.php
  75. 131 157
      app/group/group.js
  76. 229 238
      app/group/group.php
  77. 47 0
      app/group/group_del.php
  78. 5 9
      app/group/list.php
  79. 8 9
      app/group/list_member.php
  80. 94 0
      app/group/member_del.php
  81. 48 40
      app/group/member_put.php
  82. 30 29
      app/group/my_group_put.php
  83. 0 40
      app/group/user_select_dlg.js
  84. 15 16
      app/hostsetting/function.php
  85. 62 65
      app/install/db_create.php
  86. 117 121
      app/install/db_insert_bold.php
  87. 58 62
      app/install/db_insert_bookword_from_csv.php
  88. 258 279
      app/install/db_insert_index.php
  89. 193 207
      app/install/db_insert_index_once.php
  90. 116 123
      app/install/db_insert_page_index.php
  91. 88 95
      app/install/db_insert_palitext.php
  92. 298 317
      app/install/db_insert_sentence.php
  93. 25 29
      app/install/db_insert_sim.php
  94. 111 113
      app/install/db_insert_templet.php
  95. 49 51
      app/install/db_insert_word_from_csv.php
  96. 36 43
      app/install/db_insert_wordindex_from_csv.php
  97. 28 27
      app/install/db_pali_text_export.php
  98. 155 162
      app/install/db_update_palitext.php
  99. 99 106
      app/install/db_update_toc.php
  100. 219 0
      app/install/filelist.php

+ 1 - 0
.gitignore

@@ -3,3 +3,4 @@
 .DS_Store
 /.debug
 .favorites.json
+/vendor

+ 57 - 64
app/admin/db_update_cs6_para.php

@@ -2,75 +2,68 @@
 require_once "../public/_pdo.php";
 require_once "../path.php";
 
-	$db_file = _FILE_DB_PALITEXT_;
-	PDO_Connect("sqlite:$db_file");
+$db_file = _FILE_DB_PALITEXT_;
+PDO_Connect("$db_file");
 
-	$query = "SELECT * from books where 1";
-	$books = PDO_FetchAll($query);
+$query = "SELECT * from books where 1";
+$books = PDO_FetchAll($query);
 
+$db_file = _FILE_DB_PAGE_INDEX_;
+PDO_Connect("$db_file");
 
-	$db_file = _FILE_DB_PAGE_INDEX_;
-	PDO_Connect("sqlite:$db_file");
+// 打开文件并读取数据
+$irow = 0;
+if (($fp = fopen("./cs6_para.csv", "r")) !== false) {
+    // 开始一个事务,关闭自动提交
+    $PDO->beginTransaction();
+    $query = "INSERT INTO cs6_para ('book','para','bookid','cspara','book_name') VALUES (  ? , ? , ? , ? , ? )";
+    $stmt = $PDO->prepare($query);
 
-	// 打开文件并读取数据
-	$irow=0;
-	if(($fp=fopen("./cs6_para.csv", "r"))!==FALSE){
-		// 开始一个事务,关闭自动提交
-		$PDO->beginTransaction();
-		$query="INSERT INTO cs6_para ('book','para','bookid','cspara','book_name') VALUES (  ? , ? , ? , ? , ? )";
-		$stmt = $PDO->prepare($query);
+    // 提交更改
+    try {
+        while (($data = fgetcsv($fp, 0, ',')) !== false) {
+            $irow++;
+            if ($irow > 1) {
+                $book_id = 0;
+                foreach ($books as $key => $value) {
+                    # code...
+                    if ($value["book"] == $data[0] && $data[1] >= $value["paragraph"]) {
+                        $book_id = $value["id"];
+                        break;
+                    }
+                }
+                if ($data[3] == $data[4]) {
+                    $stmt->execute(array($data[0], $data[1], $book_id, $data[3], $data[2]));
+                } else {
+                    $begin = (int) $data[3];
+                    $end = (int) $data[4];
+                    $arr1 = array();
+                    for ($i = $begin; $i <= $end; $i++) {
+                        $arr1[] = $i;
+                    }
+                    foreach ($arr1 as $key => $value) {
+                        $stmt->execute(array($data[0], $data[1], $book_id, $value, $data[2]));
+                    }
+                }
 
-		// 提交更改 
-		try{
-			while(($data=fgetcsv($fp,0,','))!==FALSE){
-				$irow++;
-				if($irow>1){
-					$book_id=0;
-					foreach ($books as $key => $value) {
-						# code...
-						if($value["book"]==$data[0] && $data[1]>=$value["paragraph"]){
-							$book_id = $value["id"];
-							break;
-						}
-					}
-					if($data[3]==$data[4]){
-						$stmt->execute(array($data[0],$data[1],$book_id,$data[3],$data[2]));
-					}
-					else{
-						$begin = (int)$data[3];
-						$end = (int)$data[4];
-						$arr1=array();
-						for($i=$begin; $i<=$end; $i++){
-							$arr1[] = $i;
-						}
-						foreach ($arr1 as $key => $value) {
-							$stmt->execute(array($data[0],$data[1],$book_id,$value,$data[2]));
-						}						
-					}
+            }
+        }
+        $PDO->commit();
+    } catch (Exception $e) {
+        var_dump($e);
+        $PDO->rollback();
+    }
 
-				}
-			}
-			$PDO->commit();
-		}catch (Exception $e){
-			var_dump($e);
-			$PDO->rollback();
-		}
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        echo "error - $error[2] \n";
+    } else {
+        echo "updata  recorders.\n";
+    }
 
-		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-			$error = PDO_ErrorInfo();
-			echo "error - $error[2] \n";
-		}
-		else{
-			echo "updata  recorders.\n";
-		}			
+    fclose($fp);
+} else {
+    echo "can not open csv file. cs6_para.csv";
+}
 
-		fclose($fp);
-	}
-	else{
-		echo "can not open csv file. cs6_para.csv";
-	}
-	
-
-
-	echo "齐活!功德无量!all done!";	
-?>
+echo "齐活!功德无量!all done!";

+ 77 - 80
app/admin/setting.php

@@ -3,18 +3,15 @@
 require_once '../path.php';
 require_once "../public/_pdo.php";
 
-if(isset($_GET["language"])){$currLanguage=$_GET["language"];}
-else{$currLanguage="en";}
+if (isset($_GET["language"])) {$currLanguage = $_GET["language"];} else { $currLanguage = "en";}
 
-if(isset($_GET["device"])){$currDevice=$_GET["device"];}
-else{$currDevice="computer";}
+if (isset($_GET["device"])) {$currDevice = $_GET["device"];} else { $currDevice = "computer";}
 
-if(isset($_GET["item"])){$currSettingItem=$_GET["item"];}
-else{$currSettingItem="local_gramma";}
+if (isset($_GET["item"])) {$currSettingItem = $_GET["item"];} else { $currSettingItem = "local_gramma";}
 
-$album_power["15"]="超级管理员";
-$album_power["1"]="管理员";
-$album_power["2"]="编辑";
+$album_power["15"] = "超级管理员";
+$album_power["1"] = "管理员";
+$album_power["2"] = "编辑";
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
@@ -30,7 +27,7 @@ $album_power["2"]="编辑";
 </head>
 <body class="mainbody" id="mbody">
 	<div class="main">
-		<!-- content begin--> 
+		<!-- content begin-->
 		<div id="leftmenuinner">
 			<div class="toolgroup1">
 
@@ -39,8 +36,8 @@ $album_power["2"]="编辑";
 			<div >
 				<h1>Setting</h1>
 			</div>
-			
-			<div class='toc' id='leftmenuinnerinner'>	
+
+			<div class='toc' id='leftmenuinnerinner'>
 				<ul class="setting_item">
 					<li><a href="setting.php?item=general">General</a></li>
 					<li><a href="setting.php?item=studio">Studio</a></li>
@@ -60,17 +57,17 @@ $album_power["2"]="编辑";
 		<div class="tool_bar">
 			<div >
 			<?php
-			switch($currSettingItem){
-				case "account":
-				break;
-				case "album":
-				if(isset($_GET["id"])){
-					echo "<a href='setting.php?item=album'>返回</a>";
-				}
-				break;
-			}
-			?>
-				
+switch ($currSettingItem) {
+    case "account":
+        break;
+    case "album":
+        if (isset($_GET["id"])) {
+            echo "<a href='setting.php?item=album'>返回</a>";
+        }
+        break;
+}
+?>
+
 			</div>
 			<div>
 				<span>Language</span>
@@ -83,39 +80,39 @@ $album_power["2"]="编辑";
 			</div>
 		</div>
 <?php
-	switch($currSettingItem){
-		case "account":
-			PDO_Connect("sqlite:"._FILE_DB_USERINFO_);
-			$query = "SELECT * from 'user' where 1 limit 0,1000";
-			$user_info = PDO_FetchAll($query);
-			echo "<table>";
-			echo "<tr><th>id</th><th>user name</th><th>nick name</th></tr>";
-			
-			foreach($user_info as $user){
-				echo "<tr>";	
-				echo "<td>{$user["id"]}</td>";
-				echo "<td>{$user["username"]}</td>";
-				echo "<td>{$user["nickname"]}</td>";
-				echo "</tr>";
-			}
-			
-			echo "</table>";
-			break;
-		case "album":
-			$db_file = _FILE_DB_RES_INDEX_;
-			PDO_Connect("sqlite:$db_file");		
-			echo "<h2>Album</h2>";
-
-			$query = "SELECT * from 'album' where 1 limit 0,1000";
-			$Fetch = PDO_FetchAll($query);
-			?>
+switch ($currSettingItem) {
+    case "account":
+        PDO_Connect("" . _FILE_DB_USERINFO_);
+        $query = "SELECT * from 'user' where 1 limit 0,1000";
+        $user_info = PDO_FetchAll($query);
+        echo "<table>";
+        echo "<tr><th>id</th><th>user name</th><th>nick name</th></tr>";
+
+        foreach ($user_info as $user) {
+            echo "<tr>";
+            echo "<td>{$user["id"]}</td>";
+            echo "<td>{$user["username"]}</td>";
+            echo "<td>{$user["nickname"]}</td>";
+            echo "</tr>";
+        }
+
+        echo "</table>";
+        break;
+    case "album":
+        $db_file = _FILE_DB_RES_INDEX_;
+        PDO_Connect("$db_file");
+        echo "<h2>Album</h2>";
+
+        $query = "SELECT * from 'album' where 1 limit 0,1000";
+        $Fetch = PDO_FetchAll($query);
+        ?>
 			<table>
 				<tr>
 					<th>Book</th><th>Title</th><th>Author</th><th>语言</th><th>媒体</th><th></th><th></th>
 				</tr>
 			<?php
-			foreach($Fetch as $album){
-				echo "<tr><td>{$album["book"]}</td>
+foreach ($Fetch as $album) {
+            echo "<tr><td>{$album["book"]}</td>
 						  <td>{$album["title"]}</td>
 						  <td>{$album["author"]}</td>
 						  <td>{$album["language"]}</td>
@@ -123,37 +120,37 @@ $album_power["2"]="编辑";
 						  <td><a href=\"../app/album.php?op=show_info&album_id={$album["id"]}\" target='_blank'>详情</a></td>
 						  <td><a href=\"../app/album.php?op=export&album_id={$album["id"]}\" target='_blank'>导出</a></td>
 						</tr>";
-			}
-			echo "</table>";
-			break;		
-		case "share":
-			PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-			$query = "SELECT count(*) from 'fileindex' where share=1";
-			$file_count = PDO_FetchOne($query);
-			echo "共计:{$file_count} 个共享文件";
-			$query = "SELECT * from 'fileindex' where share=1 limit 0,100";
-			$file_share = PDO_FetchAll($query);			
-			echo "<table>";
-			echo "<tr><th>id</th><th>user id</th><th>Title</th><th>Size</th><th></th></tr>";
-			
-			foreach($file_share as $file){
-				echo "<tr>";	
-				echo "<td>{$file["id"]}</td>";
-				echo "<td>{$file["user_id"]}</td>";
-				echo "<td>{$file["title"]}</td>";
-				echo "<td>{$file["file_size"]}</td>";
-				echo "<td>详情</td>";
-				echo "</tr>";
-			}
-			
-			echo "</table>";		
-			break;
-	}
-			
+        }
+        echo "</table>";
+        break;
+    case "share":
+        PDO_Connect("" . _FILE_DB_FILEINDEX_);
+        $query = "SELECT count(*) from 'fileindex' where share=1";
+        $file_count = PDO_FetchOne($query);
+        echo "共计:{$file_count} 个共享文件";
+        $query = "SELECT * from 'fileindex' where share=1 limit 0,100";
+        $file_share = PDO_FetchAll($query);
+        echo "<table>";
+        echo "<tr><th>id</th><th>user id</th><th>Title</th><th>Size</th><th></th></tr>";
+
+        foreach ($file_share as $file) {
+            echo "<tr>";
+            echo "<td>{$file["id"]}</td>";
+            echo "<td>{$file["user_id"]}</td>";
+            echo "<td>{$file["title"]}</td>";
+            echo "<td>{$file["file_size"]}</td>";
+            echo "<td>详情</td>";
+            echo "</tr>";
+        }
+
+        echo "</table>";
+        break;
+}
+
 ?>
-			
+
 		</div>
 	</div>
-			
+
 </body>
 </html>

+ 31 - 35
app/admin/update_user_active_time.php

@@ -4,52 +4,48 @@ require_once '../path.php';
 date_default_timezone_set("UTC");
 $logfile = "update_user_active_time_last.txt";
 $last = file_get_contents($logfile);
-$start = strtotime($last." +1 day");
-$end = strtotime($last." +2 day");
+$start = strtotime($last . " +1 day");
+$end = strtotime($last . " +2 day");
 $today = strtotime("today");
 
-$dns = "sqlite:"._FILE_DB_USER_ACTIVE_;
-$dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+$dns = "" . _FILE_DB_USER_ACTIVE_;
+$dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
-
-$dns = "sqlite:"._FILE_DB_USER_ACTIVE_INDEX_;
-$dbh_index = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-$dbh_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+$dns = "" . _FILE_DB_USER_ACTIVE_INDEX_;
+$dbh_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dbh_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 /* 开始一个事务,关闭自动提交 */
 $dbh_index->beginTransaction();
 $query = "INSERT INTO active_index (user_id, date , duration , hit) VALUES (?, ?, ? , ?)";
 $sth_index = $dbh_index->prepare($query);
 
-$runing=$last;
+$runing = $last;
 while ($end <= $today) {
-	$runing=gmdate("Y-m-d",$start);
-	echo "runing:".$runing."\n";
-
-	# do one day
-	$query = "SELECT user_id, sum(duration) as time , sum(hit) as hit  FROM edit WHERE end between ? and ?  group by user_id ";
-	$stmt = $dbh->prepare($query);
-	$stmt->execute(array($start*1000,$end*1000));
-	while($result = $stmt->fetch(PDO::FETCH_ASSOC))
-	{
-		$user_id = $result["user_id"];
-		$time = $result["time"];
-		$hit = $result["hit"];
-		$sth_index->execute(array($user_id,$start*1000,$time,$hit));
-		echo "$user_id - $time - $hit \n";
-	}
-	$start = $end;
-	$end = strtotime( gmdate("Y-m-d",$end)." +1 day");
+    $runing = gmdate("Y-m-d", $start);
+    echo "runing:" . $runing . "\n";
+
+    # do one day
+    $query = "SELECT user_id, sum(duration) as time , sum(hit) as hit  FROM edit WHERE end between ? and ?  group by user_id ";
+    $stmt = $dbh->prepare($query);
+    $stmt->execute(array($start * 1000, $end * 1000));
+    while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) {
+        $user_id = $result["user_id"];
+        $time = $result["time"];
+        $hit = $result["hit"];
+        $sth_index->execute(array($user_id, $start * 1000, $time, $hit));
+        echo "$user_id - $time - $hit \n";
+    }
+    $start = $end;
+    $end = strtotime(gmdate("Y-m-d", $end) . " +1 day");
 }
 $dbh_index->commit();
 if (!$sth_index || ($sth_index && $sth_index->errorCode() != 0)) {
-	/*  识别错误且回滚更改  */
-	$sth_index->rollBack();
-	$error = $dbh_index->errorInfo();
-	echo "error:".$error[2]."\n";
+    /*  识别错误且回滚更改  */
+    $sth_index->rollBack();
+    $error = $dbh_index->errorInfo();
+    echo "error:" . $error[2] . "\n";
 }
 
-echo "run until:".$runing."\n";
-echo file_put_contents($logfile,$runing);
-
-?>
+echo "run until:" . $runing . "\n";
+echo file_put_contents($logfile, $runing);

+ 116 - 123
app/admin/word_index_weight_refresh.php

@@ -1,142 +1,135 @@
 <?php
 /*
 计算单词权重
-*/
+ */
 require_once '../path.php';
 require_once './word_index_weight_table.php';
 
-if(isset($_GET["from"])){
-	$from = $_GET["from"];
-	$to = $_GET["to"];
+if (isset($_GET["from"])) {
+    $from = $_GET["from"];
+    $to = $_GET["to"];
+} else {
+    if ($argc != 3) {
+        echo "无效的参数 ";
+        exit;
+    }
+    $from = (int) $argv[1];
+    $to = (int) $argv[2];
+    if ($to > 217) {
+        $to = 217;
+    }
 }
-else{
-	if ($argc != 3){
-	echo "无效的参数 ";
-	exit;
-	}
-	$from = (int)$argv[1];
-	$to =(int)$argv[2];
-	if($to>217){
-		$to = 217;
-	}
-}
-
 
-$dh_word = new PDO("sqlite:"._FILE_DB_WORD_INDEX_, "", "");
+$dh_word = new PDO("" . _FILE_DB_WORD_INDEX_, "", "");
 $dh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
-$dh_pali = new PDO("sqlite:"._FILE_DB_PALI_INDEX_, "", "");
+$dh_pali = new PDO("" . _FILE_DB_PALI_INDEX_, "", "");
 $dh_pali->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 echo "from=$from to = $to \n";
-for ($i=$from; $i <=$to ; $i++) {
-	$time_start = microtime(true);
-	echo "正在处理 book= $i ";
-	$query = "SELECT max(paragraph) from word where book={$i}";
-	$stmt = $dh_pali->query($query);
-	$row = $stmt->fetch(PDO::FETCH_NUM);
+for ($i = $from; $i <= $to; $i++) {
+    $time_start = microtime(true);
+    echo "正在处理 book= $i ";
+    $query = "SELECT max(paragraph) from word where book={$i}";
+    $stmt = $dh_pali->query($query);
+    $row = $stmt->fetch(PDO::FETCH_NUM);
     if ($row) {
-		$max_para =  $row[0];
-		echo "段落数量:$max_para \n";
-		for ($j=0; $j <=$max_para ; $j++) {
-			# code...
-			$query = "SELECT id,book,wordindex,bold from word where book={$i} and paragraph={$j} order by id ASC";
-			$stmt = $dh_pali->query($query);
-			$fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
+        $max_para = $row[0];
+        echo "段落数量:$max_para \n";
+        for ($j = 0; $j <= $max_para; $j++) {
+            # code...
+            $query = "SELECT id,book,wordindex,bold from word where book={$i} and paragraph={$j} order by id ASC";
+            $stmt = $dh_pali->query($query);
+            $fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+            $query = "SELECT wordindex,count(*) as co from word where book={$i} and paragraph={$j} group by wordindex";
+            $stmt = $dh_pali->query($query);
+            $fetch_voc = $stmt->fetchAll(PDO::FETCH_ASSOC);
+            $vocabulary = array();
+            foreach ($fetch_voc as $key => $value) {
+                $vocabulary[$value["wordindex"]] = $value["co"];
+            }
+            for ($iWord = 0; $iWord < count($fetch); $iWord++) {
+                # 非黑体字
+                if ($fetch[$iWord]["bold"] == 0) {
+                    $count = $vocabulary[$fetch[$iWord]["wordindex"]];
+                    $paraWeight = pow(1.01, $count); //总分
+                    if ($paraWeight > 1.9) {
+                        $paraWeight = 1.9;
+                    }
+                    $weight = $paraWeight / $count;
+                } else {
+                    #黑体字
+                    #查找前后相连的黑体字
+                    $begin = $iWord;
+                    while ($fetch[$begin]["bold"] == 1) {
+                        $begin--;
+                        if ($begin < 0) {
+                            break;
+                        }
+                    }
+                    $begin = $begin + 1;
 
-			$query = "SELECT wordindex,count(*) as co from word where book={$i} and paragraph={$j} group by wordindex";
-			$stmt = $dh_pali->query($query);
-			$fetch_voc = $stmt->fetchAll(PDO::FETCH_ASSOC);			
-			$vocabulary = array();
-			foreach ($fetch_voc as $key => $value) {
-				$vocabulary[$value["wordindex"]] = $value["co"];
-			}
-			for ($iWord=0; $iWord <count($fetch) ; $iWord++) { 
-				# 非黑体字
-				if($fetch[$iWord]["bold"]==0){
-					$count = $vocabulary[$fetch[$iWord]["wordindex"]];
-					$paraWeight = pow(1.01,$count);//总分
-					if($paraWeight>1.9){
-						$paraWeight = 1.9;
-					}			
-					$weight = $paraWeight/$count;						
-				}
-				else{
-					#黑体字
-					#查找前后相连的黑体字
-					$begin = $iWord;
-					while ($fetch[$begin]["bold"] ==1) {
-						$begin--;
-						if($begin<0){
-							break;
-						}
-					}
-					$begin = $begin+1;
+                    $end = $iWord;
+                    while ($fetch[$end]["bold"] == 1) {
+                        $end++;
+                        if ($end > count($fetch) - 1) {
+                            break;
+                        }
+                    }
+                    $end = $end - 1;
+                    $bold_count = $end - $begin + 1;
+                    if ($bold_count == 1) {
 
-					$end = $iWord;
-					while ($fetch[$end]["bold"] ==1) {
-						$end++;
-						if($end>count($fetch)-1){
-							break;
-						}
-					}
-					$end = $end-1;
-					$bold_count = $end-$begin+1;
-					if($bold_count==1){
-						
-						$query = "SELECT * from wordindex where id=".$fetch[$iWord]["wordindex"];
-						$stmt_word = $dh_word->query($query);
-						$wordinfo = $stmt_word->fetch(PDO::FETCH_ASSOC);
-						$bookId = (int)$fetch[$iWord]["book"];
-						if(mb_substr($wordinfo["word"],-2)=="ti"){
-							$weight = 100+$book_weight[$bookId];
-						}
-						else{
-							$weight = 100+$book_weight[$bookId];
-						}
-						//echo "单独黑体 $weight \n";
-					}
-					else{
-						#连续黑体字
-						//echo "连续黑体字";
-						$len_sum = 0;
-						$len_curr = 0;
-						for ($iBold=$begin; $iBold <=$end ; $iBold++) { 
-							# code...
-							$boldid = $fetch[$iBold]["wordindex"];
-							$query = "SELECT len from wordindex where id=".$boldid;
-							$stmt_bold = $dh_word->query($query);
-							$wordbold = $stmt_bold->fetch(PDO::FETCH_ASSOC);
-							$len_sum += $wordbold["len"];
-							if($iBold==$i){
-								$len_curr = $wordbold["len"];
-							}
-						}
-						$weight = 10+$len_curr/$len_sum;
-					}
-				}
-				//echo $weight."\n";
-				$fetch[$iWord]["weight"] = (int)($weight*100);
-			}
-			# 将整段权重写入据库
-			$dh_pali->beginTransaction();
-			$query = "UPDATE word set weight = ? where id=? ";
-			$stmt_weight = $dh_pali->prepare($query);
-			foreach ($fetch as $key => $value) {
-        		$stmt_weight->execute(array($value["weight"],$value["id"]));
-			}
-			$dh_pali->commit();
-			if (!$stmt_weight || ($stmt_weight && $stmt_weight->errorCode() != 0)) {
-				$error = $dh_pali->errorInfo();
-				echo "error - $error[2]";
-			}
-			else{
-				//echo "修改数据库成功 book={$i} paragraph={$j} \n";
-			}
-		}
+                        $query = "SELECT * from wordindex where id=" . $fetch[$iWord]["wordindex"];
+                        $stmt_word = $dh_word->query($query);
+                        $wordinfo = $stmt_word->fetch(PDO::FETCH_ASSOC);
+                        $bookId = (int) $fetch[$iWord]["book"];
+                        if (mb_substr($wordinfo["word"], -2) == "ti") {
+                            $weight = 100 + $book_weight[$bookId];
+                        } else {
+                            $weight = 100 + $book_weight[$bookId];
+                        }
+                        //echo "单独黑体 $weight \n";
+                    } else {
+                        #连续黑体字
+                        //echo "连续黑体字";
+                        $len_sum = 0;
+                        $len_curr = 0;
+                        for ($iBold = $begin; $iBold <= $end; $iBold++) {
+                            # code...
+                            $boldid = $fetch[$iBold]["wordindex"];
+                            $query = "SELECT len from wordindex where id=" . $boldid;
+                            $stmt_bold = $dh_word->query($query);
+                            $wordbold = $stmt_bold->fetch(PDO::FETCH_ASSOC);
+                            $len_sum += $wordbold["len"];
+                            if ($iBold == $i) {
+                                $len_curr = $wordbold["len"];
+                            }
+                        }
+                        $weight = 10 + $len_curr / $len_sum;
+                    }
+                }
+                //echo $weight."\n";
+                $fetch[$iWord]["weight"] = (int) ($weight * 100);
+            }
+            # 将整段权重写入据库
+            $dh_pali->beginTransaction();
+            $query = "UPDATE word set weight = ? where id=? ";
+            $stmt_weight = $dh_pali->prepare($query);
+            foreach ($fetch as $key => $value) {
+                $stmt_weight->execute(array($value["weight"], $value["id"]));
+            }
+            $dh_pali->commit();
+            if (!$stmt_weight || ($stmt_weight && $stmt_weight->errorCode() != 0)) {
+                $error = $dh_pali->errorInfo();
+                echo "error - $error[2]";
+            } else {
+                //echo "修改数据库成功 book={$i} paragraph={$j} \n";
+            }
+        }
     } else {
         echo "无法获取段落最大值";
-	}
-	echo "处理时间 :".( microtime(true)-$time_start);
+    }
+    echo "处理时间 :" . (microtime(true) - $time_start);
 }
-?>

+ 1 - 1
app/article/add_article_to_collect.php

@@ -16,7 +16,7 @@ if(isset($_POST["id"])){
     $dirty_collect = array();
     $data = json_decode($_POST["data"]);
     $title = $_POST["title"];
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $article_id=$_POST["id"];
     //找出脏的collect
     $query = "SELECT collect_id FROM article_list  WHERE article_id = ? ";

+ 2 - 2
app/article/collect_get.php

@@ -8,7 +8,7 @@ require_once '../ucenter/function.php';
 
 
 if(isset($_GET["id"])){
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $id=$_GET["id"];
     $query = "select * from collect  where id = ? ";
     $Fetch = PDO_FetchRow($query,array($id));
@@ -26,7 +26,7 @@ if(isset($_GET["id"])){
 }
 else if(isset($_GET["article"])){
     # 给文章编号,查文集信息
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $article=$_GET["article"];
     $query = "SELECT collect_id FROM article_list  WHERE article_id = ? ";
     $Fetch = PDO_FetchAll($query,array($article));

+ 1 - 1
app/article/collect_list.php

@@ -8,7 +8,7 @@ require_once '../ucenter/function.php';
 
 
 if(isset($_GET["userid"])){
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $userid=$_GET["userid"];
     $query = "SELECT * from collect  where owner = ".$PDO->quote($userid)." and status <> 0 order by modify_time DESC";
     $Fetch = PDO_FetchAll($query);

+ 1 - 1
app/article/get.php

@@ -8,7 +8,7 @@ require_once '../ucenter/function.php';
 
 
 if(isset($_GET["id"])){
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $id=$_GET["id"];
     $query = "SELECT * FROM article  WHERE id = ? ";
     $Fetch = PDO_FetchRow($query,array($id));

+ 1 - 1
app/article/list.php

@@ -5,7 +5,7 @@ require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../ucenter/function.php';
-PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+PDO_Connect(""._FILE_DB_USER_ARTICLE_);
 if(isset($_GET["userid"])){
     $userid=$_GET["userid"];
     $query = "SELECT * from article  where owner = ? and status <> 0 order by modify_time DESC";

+ 1 - 1
app/article/list_article_in_collect.php

@@ -8,7 +8,7 @@ require_once '../ucenter/function.php';
 
 $output  = array();
 if(isset($_GET["id"])){
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $article_id=$_GET["id"];
     $query = "SELECT collect_id as id from article_list  where article_id = ?  ";
     $exist = PDO_FetchAll($query,array($article_id));

+ 1 - 1
app/article/list_new.php

@@ -24,7 +24,7 @@ require_once '../collect/function.php';
     else{
         $begin = 0;
     }
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $query = "SELECT id,title,subtitle,summary,owner,modify_time from article  where status <> 0 ";
     
     if(isset($_GET["orderby"])){

+ 3 - 3
app/article/my_article_post.php

@@ -10,7 +10,7 @@ add_edit_event(_ARTICLE_EDIT_,$_POST["id"]);
 $respond=array("status"=>0,"message"=>"");
 
 # 检查是否由修改权限
-PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+PDO_Connect(""._FILE_DB_USER_ARTICLE_);
 $query = "SELECT owner FROM  article WHERE id= ?";
 $owner = PDO_FetchOne($query,array($_POST["id"]));
 if($owner!=$_COOKIE["userid"]){
@@ -43,7 +43,7 @@ if($_POST["import"]=='on'){
             echo json_encode($respond, JSON_UNESCAPED_UNICODE);
             exit;
         }
-        PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
+        PDO_Connect(""._FILE_DB_SENTENCE_);
 
         /* 开始一个事务,关闭自动提交 */
         $PDO->beginTransaction();
@@ -112,7 +112,7 @@ if($_POST["import"]=='on'){
     }
 }
 
-PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+PDO_Connect(""._FILE_DB_USER_ARTICLE_);
 
 $query="UPDATE article SET title = ? , subtitle = ? , summary = ?, content = ?  , tag = ? , setting = ? , status = ? , receive_time= ?  , modify_time= ?   where  id = ?  ";
 $sth = $PDO->prepare($query);

+ 1 - 1
app/article/my_article_put.php

@@ -6,7 +6,7 @@ require_once '../hostsetting/function.php';
 require_once "../ucenter/active.php";
 
 $respond=array("status"=>0,"message"=>"");
-PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+PDO_Connect(""._FILE_DB_USER_ARTICLE_);
 
 $query="INSERT INTO article ( id,  title  , subtitle  , summary , content   , tag  , owner, setting  , status  , create_time , modify_time , receive_time   )  VALUES  ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ";
 $sth = $PDO->prepare($query);

+ 1 - 1
app/article/my_collect_post.php

@@ -9,7 +9,7 @@ add_edit_event(_COLLECTION_EDIT_,$_POST["id"]);
 
 $respond=array("status"=>0,"message"=>"");
 
-PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+PDO_Connect(""._FILE_DB_USER_ARTICLE_);
 
 $query="UPDATE collect SET title = ? , subtitle = ? , summary = ?, article_list = ?  ,  status = ? , lang = ? , receive_time= ?  , modify_time= ?   where  id = ?  ";
 $sth = $PDO->prepare($query);

+ 1 - 1
app/article/my_collect_put.php

@@ -6,7 +6,7 @@ require_once '../hostsetting/function.php';
 require_once "../ucenter/active.php";
 
 $respond=array("status"=>0,"message"=>"");
-PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+PDO_Connect(""._FILE_DB_USER_ARTICLE_);
 
 $query="INSERT INTO collect ( id,  title  , subtitle  , summary , article_list   , owner, lang  , status  , create_time , modify_time , receive_time   )  VALUES  ( ? , ? , ? , ?  , ? , ? , ? , ? , ? , ? , ? ) ";
 $sth = $PDO->prepare($query);

+ 63 - 66
app/calendar/index.html

@@ -636,77 +636,74 @@ function show_time() {
 				result.lunar = pali_nakkhatta_name[lunar_num]; //27星宿月站名称
 				return result;
 			}
-			function show_position(){
+function show_position(){
 	curr_position = localStorage.getItem("local_position");
-			if (curr_position) {
-				g_coordinate_this.AT = curr_position.split("#")[0];
-				g_coordinate_this.LT = curr_position.split("#")[1];
-				g_coordinate_this.height = curr_position.split("#")[2];
-				if (g_coordinate_this.AT >= 0) {
-					var AT_string = angle_trans(g_coordinate_this.AT)[0]+"°" +angle_trans(g_coordinate_this.AT)[1] +
-					"’" +
-					angle_trans(g_coordinate_this.AT)[2] +
-					"” N";
-
-				} else {
-					var AT_string = angle_trans(0-g_coordinate_this.AT)[0]+"°" +angle_trans(0-g_coordinate_this.AT)[1] +
-					"’" +
-					angle_trans(0-g_coordinate_this.AT)[2] +
-					"” S";
-				}
-
-				if (g_coordinate_this.LT >= 0) {
-					var LT_string = angle_trans(g_coordinate_this.LT)[0]+"°" +angle_trans(g_coordinate_this.LT)[1] +
-					"’" +
-					angle_trans(g_coordinate_this.LT)[2] +
-					"” E";
-
-				} else {
-					var LT_string = angle_trans(0-g_coordinate_this.LT)[0]+"°" +angle_trans(0-g_coordinate_this.LT)[1] +
-					"’" +
-					angle_trans(0-g_coordinate_this.LT)[2] +
-					"” W";
-				}
+		if (curr_position) {
+			g_coordinate_this.AT = curr_position.split("#")[0];
+			g_coordinate_this.LT = curr_position.split("#")[1];
+			g_coordinate_this.height = curr_position.split("#")[2];
+			if (g_coordinate_this.AT >= 0) {
+				var AT_string = angle_trans(g_coordinate_this.AT)[0]+"°" +angle_trans(g_coordinate_this.AT)[1] +
+				"’" +
+				angle_trans(g_coordinate_this.AT)[2] +
+				"” N";
+			} else {
+				var AT_string = angle_trans(0-g_coordinate_this.AT)[0]+"°" +angle_trans(0-g_coordinate_this.AT)[1] +
+				"’" +
+				angle_trans(0-g_coordinate_this.AT)[2] +
+				"” S";
+			}
+			if (g_coordinate_this.LT >= 0) {
+				var LT_string = angle_trans(g_coordinate_this.LT)[0]+"°" +angle_trans(g_coordinate_this.LT)[1] +
+				"’" +
+				angle_trans(g_coordinate_this.LT)[2] +
+				"” E";
 
-				if (g_coordinate_this.height != "null") {
-					var height_string = g_coordinate_this.height + "M";
-				} else {
-					var height_string = localString[g_language].unknown;
-				}
 			} else {
-				getLocation();
+				var LT_string = angle_trans(0-g_coordinate_this.LT)[0]+"°" +angle_trans(0-g_coordinate_this.LT)[1] +
+				"’" +
+				angle_trans(0-g_coordinate_this.LT)[2] +
+				"” W";
 			}
-			$("#AT_str").html(AT_string);
-			$("#LT_str").html(LT_string);
-			$("#altitude_string").html(height_string);
-		if(g_coordinate_this.AT<0){
-			$("#AT_°")[0].value = angle_trans(0-g_coordinate_this.AT)[0];
-			$("#AT_’")[0].value = angle_trans(0-g_coordinate_this.AT)[1];
-			$("#AT_”")[0].value = angle_trans(0-g_coordinate_this.AT)[2];
-			$("#NS")[0].value="-";
+			if (g_coordinate_this.height != "null") {
+				var height_string = g_coordinate_this.height + "M";
+			} else {
+				var height_string = localString[g_language].unknown;
+			}
+		} else {
+			getLocation();
 		}
-		else{
-			$("#AT_°")[0].value = angle_trans(g_coordinate_this.AT)[0];
-			$("#AT_’")[0].value = angle_trans(g_coordinate_this.AT)[1];
-			$("#AT_”")[0].value = angle_trans(g_coordinate_this.AT)[2];
-			$("#NS")[0].value="+";
+	$("#AT_str").html(AT_string);
+	$("#LT_str").html(LT_string);
+	$("#altitude_string").html(height_string);
 
-		}
-		if(g_coordinate_this.LT<0){
-			$("#LT_°")[0].value = angle_trans(0-g_coordinate_this.LT)[0];
-			$("#LT_’")[0].value = angle_trans(0-g_coordinate_this.LT)[1];
-			$("#LT_”")[0].value = angle_trans(0-g_coordinate_this.LT)[2];
-			$("#WE")[0].value="-";
+	if(g_coordinate_this.AT<0){
+		$("#AT_°")[0].value = angle_trans(0-g_coordinate_this.AT)[0];
+		$("#AT_’")[0].value = angle_trans(0-g_coordinate_this.AT)[1];
+		$("#AT_”")[0].value = angle_trans(0-g_coordinate_this.AT)[2];
+		$("#NS")[0].value="-";
+	}
+	else{
+		$("#AT_°")[0].value = angle_trans(g_coordinate_this.AT)[0];
+		$("#AT_’")[0].value = angle_trans(g_coordinate_this.AT)[1];
+		$("#AT_”")[0].value = angle_trans(g_coordinate_this.AT)[2];
+		$("#NS")[0].value="+";
 
-		}
-		else{
-			$("#LT_°")[0].value = angle_trans(g_coordinate_this.LT)[0];
-			$("#LT_’")[0].value = angle_trans(g_coordinate_this.LT)[1];
-			$("#LT_”")[0].value = angle_trans(g_coordinate_this.LT)[2];
-			$("#WE")[0].value="+";
-		}
-		$("#HT_M")[0].value = g_coordinate_this.height;
-		$("#city_str").html(find_city(g_coordinate_this.AT,g_coordinate_this.LT).name);
+	}
+	if(g_coordinate_this.LT<0){
+		$("#LT_°")[0].value = angle_trans(0-g_coordinate_this.LT)[0];
+		$("#LT_’")[0].value = angle_trans(0-g_coordinate_this.LT)[1];
+		$("#LT_”")[0].value = angle_trans(0-g_coordinate_this.LT)[2];
+		$("#WE")[0].value="-";
+	}
+	else{
+		$("#LT_°")[0].value = angle_trans(g_coordinate_this.LT)[0];
+		$("#LT_’")[0].value = angle_trans(g_coordinate_this.LT)[1];
+		$("#LT_”")[0].value = angle_trans(g_coordinate_this.LT)[2];
+		$("#WE")[0].value="+";
+	}
+	$("#HT_M")[0].value = g_coordinate_this.height;
+	$("#city_str").html(find_city(g_coordinate_this.AT,g_coordinate_this.LT).name);
 }
 show_position();
 function getLocation() {
@@ -777,8 +774,8 @@ function angle_trans(angle,type) {
 	}
 	angle=Math.abs(angle);
 	angle_str.d = Math.floor(angle);
-	angle_str.m = Math.floor((angle - num_d) * 60);
-	angle_str.s = Math.round((angle - num_d) * 60 - num_m);
+	angle_str.m = Math.floor((angle - angle_str.d) * 60);
+	angle_str.s = Math.round((angle - angle_str.d) * 60 - angle_str.m);
 
 	angle_str.str=angle_str.d+"°"+angle_str.m+"’"+angle_str.s+"”"+angle_str.suf;
 

+ 32 - 3
app/channal/channal.js

@@ -1,4 +1,5 @@
 var _my_channal = null;
+var gChannelId;
 var get_channel_list_callback = null;
 channal_list();
 
@@ -90,6 +91,7 @@ function my_channal_list() {
 编辑channel信息
 */
 function my_channal_edit(id) {
+	gChannelId = id;
 	$.get(
 		"../channal/my_channal_get.php",
 		{
@@ -174,12 +176,14 @@ function my_channal_edit(id) {
 					html += "</div>";
 					html += "</div>";
 
-					html += "<div id='coop_div' style='padding:5px;'>";
+					html += "<div id='coop_div' style='padding:5px;position: relative;'>";
 					html += "<h2>协作者</h2>";
-					html += "<div id='add_coop_user_dlg' class='float_dlg'></div>";
+
 					html += "<button onclick='add_coop_user()'>添加协作者</button>";
-					html += "<div id='add_coop_group_dlg' class='float_dlg'></div>";
+					html += "<div id='add_coop_user_dlg' class='float_dlg' style='left: 0;'></div>";
+
 					html += "<button onclick='add_coop_group()' >添加协作群</button>";
+					html += "<div id='add_coop_group_dlg' class='float_dlg' style='left: 0;'></div>";
 					html += "<div id='coop_inner' >";
 					if (typeof result.coop == "undefined" || result.coop.length == 0) {
 						html += "这里很安静";
@@ -205,6 +209,7 @@ function my_channal_edit(id) {
 					html += "</div>";
 
 					$("#channal_info").html(html);
+					user_select_dlg_init("add_coop_user_dlg");
 					tran_lang_select_init("channal_lang_select");
 					//$("#aritcle_status").html(render_status(result.status));
 					$("#channal_title").html(result.name);
@@ -219,6 +224,30 @@ function my_channal_edit(id) {
 	);
 }
 
+function add_coop_user() {
+	user_select_dlg_show();
+}
+
+function user_selected(id) {
+	$.post(
+		"../channal/coop_new_user.php",
+		{
+			userid: id,
+			channel_id: gChannelId,
+		},
+		function (data) {
+			let error = JSON.parse(data);
+			if (error.status == 0) {
+				user_select_cancel();
+				alert("ok");
+				location.reload();
+			} else {
+				alert(error.message);
+			}
+		}
+	);
+}
+
 function status_change(obj) {
 	let arrStatus = [
 		{ id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },

+ 3 - 0
app/channal/channal_add_dlg.js

@@ -5,6 +5,7 @@ function channal_add_dlg_init(div) {
 	html += "<div id='channal_add_dlg'>";
 	html += "<div >";
 	html += "<div >" + gLocal.gui.name + "</div>";
+	html += "<guide gid='channel_guide'></guide>"
 	html += "<input type='input' id='channal_add_title' maxlength='32' placeholder='" + gLocal.gui.name + "'/>";
 	html += "</div>";
 	html += "<div>";
@@ -31,6 +32,7 @@ function channal_add_dlg_init(div) {
 	html += "</div>";
 
 	$("#" + div).append(html);
+	guide_init();
 }
 
 function channal_add_dlg_show() {
@@ -67,4 +69,5 @@ function channal_add_new() {
 			}
 		}
 	);
+
 }

+ 21 - 0
app/channal/coop_new_user.php

@@ -0,0 +1,21 @@
+<?php
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once '../public/function.php';
+
+$respond=array("status"=>0,"message"=>"");
+if(isset($_COOKIE["userid"]) && isset($_POST["channel_id"])){
+	PDO_Connect(""._FILE_DB_CHANNAL_);
+	$query="INSERT INTO cooperation ( channal_id , user_id  ,type  , power  )  
+	VALUES  (  ? , ? , ? , ? ) ";
+	$sth = $PDO->prepare($query);
+	$sth->execute(array($_POST["channel_id"],$_POST["userid"] , 0 , 1 ));
+	$respond=array("status"=>0,"message"=>"");
+	if (!$sth || ($sth && $sth->errorCode() != 0)) {
+		$error = PDO_ErrorInfo();
+		$respond['status']=1;
+		$respond['message']=$error[2];
+	}	
+}
+echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+?>

+ 1 - 1
app/channal/function.php

@@ -4,7 +4,7 @@ class Channal
 {
     public $dbh;
     public function __construct() {
-        $dns = "sqlite:"._FILE_DB_CHANNAL_;
+        $dns = ""._FILE_DB_CHANNAL_;
         $this->dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
         $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
     }

+ 2 - 2
app/channal/get.php

@@ -6,7 +6,7 @@ require_once "../public/_pdo.php";
 require_once '../ucenter/function.php';
 
 # 找我加入的群
-PDO_Connect("sqlite:"._FILE_DB_GROUP_);
+PDO_Connect(""._FILE_DB_GROUP_);
 $query = "SELECT group_id from group_member where user_id = ?  limit 0,100";
 $my_group = PDO_FetchAll($query,array($_COOKIE["userid"]));
 $userList = array();
@@ -17,7 +17,7 @@ foreach ($my_group as $key => $value) {
 }
 
 //找自己的
-PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+PDO_Connect(""._FILE_DB_CHANNAL_);
 $query = "SELECT * from channal where owner = ?  limit 0,100";
 $Fetch_my = PDO_FetchAll($query,array($_COOKIE["userid"]));
 

+ 2 - 0
app/channal/my_channal_edit.php

@@ -8,6 +8,7 @@ require_once '../studio/index_head.php';
 	<script src="../public/js/jquery-ui-1.12.1/jquery-ui.js"></script>
 	<link type="text/css" rel="stylesheet" href="../public/js/jquery-ui-1.12.1/jquery-ui.css"/>
 	<script language="javascript" src="../lang/tran_lang_select.js"></script>
+	<script language="javascript" src="../group/user_select_dlg.js"></script>
 
 	<script >
 	var gCurrPage="channal";
@@ -89,6 +90,7 @@ require_once '../studio/index_head.php';
 	</div>
 	
 <script>
+
 my_channal_edit("<?php echo $_GET["id"] ?>");
 </script>
 <?php

+ 2 - 2
app/channal/my_channal_get.php

@@ -9,7 +9,7 @@ require_once '../group/function.php';
 
 
 if(isset($_GET["id"])){
-    PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+    PDO_Connect(""._FILE_DB_CHANNAL_);
     $id=$_GET["id"];
     $query = "SELECT * FROM channal  WHERE id = ? ";
 	$Fetch = PDO_FetchRow($query,array($id));
@@ -34,7 +34,7 @@ if(isset($_GET["id"])){
     echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
 }
 else{
-    PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+    PDO_Connect(""._FILE_DB_CHANNAL_);
     $query = "SELECT * FROM channal  WHERE owner = ? ";
     $Fetch = PDO_FetchAll($query,array($_COOKIE["userid"]));
     echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);

+ 4 - 0
app/channal/my_channal_index.php

@@ -6,9 +6,12 @@ require_once '../studio/index_head.php';
 	<script language="javascript" src="../ucenter/name_selector.js"></script>
 	<script language="javascript" src="../channal/channal_add_dlg.js"></script>
 	<script language="javascript" src="../channal/channal.js"></script>
+	<script src="../guide/guide.js"></script>
+	<link type="text/css" rel="stylesheet" href="../guide/guide.css"/>
 	<script >
 	var gCurrPage="channal";
 	</script>
+	<script src="../public/js/marked.js"></script>
 
 	<style>
 	#channal {
@@ -63,6 +66,7 @@ require_once '../studio/index_head.php';
 		
 	</div>
 	
+
 <?php
 require_once '../studio/index_foot.php';
 ?>

+ 3 - 3
app/channal/my_channal_post.php

@@ -6,7 +6,7 @@ require_once '../hostsetting/function.php';
 $respond=array("status"=>0,"message"=>"");
 
 #先查询对此channal是否有权限修改
-   PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+   PDO_Connect(""._FILE_DB_CHANNAL_);
 $cooperation = 0;
 if(isset($_POST["id"])){
     $query = "SELECT owner FROM channal WHERE id=?";
@@ -53,7 +53,7 @@ if (!$sth || ($sth && $sth->errorCode() != 0)) {
 }
 else{
     // 设置 句子库和逐词译库可见性
-    PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
+    PDO_Connect(""._FILE_DB_SENTENCE_);
     $query="UPDATE sentence SET language = ?  , status = ? where  channal = ?  ";
     $sth = PDO_Execute($query,array($_POST["lang"],$_POST["status"],$_POST["id"]));
     if (!$sth || ($sth && $sth->errorCode() != 0)) {
@@ -63,7 +63,7 @@ else{
     }
     else{
         // 设置 逐词译库可见性
-        PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
+        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)) {

+ 1 - 1
app/channal/my_channal_put.php

@@ -5,7 +5,7 @@ require_once '../public/function.php';
 require_once '../hostsetting/function.php';
 $respond=array("status"=>0,"message"=>"");
 if(isset($_COOKIE["userid"])){
-	PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+	PDO_Connect(""._FILE_DB_CHANNAL_);
 	$query="INSERT INTO channal ( id,  owner  , name  , summary ,  status  , lang, create_time , modify_time , receive_time   )  VALUES  ( ? , ? , ? , ? , ? , ? , ? , ? , ?  ) ";
 	$sth = $PDO->prepare($query);
 	$sth->execute(array(UUID::v4() , $_COOKIE["userid"] , $_POST["name"] , "" , $_POST["status"] ,$_POST["lang"]  ,  mTime() ,  mTime() , mTime() ));

+ 1 - 1
app/collect/function.php

@@ -6,7 +6,7 @@ class CollectInfo
     private $dbh;
     private $buffer;
     public function __construct() {
-        $dns = "sqlite:"._FILE_DB_USER_ARTICLE_;
+        $dns = ""._FILE_DB_USER_ARTICLE_;
         $this->dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
         $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
         $buffer = array();

+ 1 - 1
app/collect/list.php

@@ -23,7 +23,7 @@ require_once '../ucenter/function.php';
     else{
         $begin = 0;
     }
-    PDO_Connect("sqlite:"._FILE_DB_USER_ARTICLE_);
+    PDO_Connect(""._FILE_DB_USER_ARTICLE_);
     $query = "SELECT * FROM collect  where  1 ";
     if(isset($_GET["orderby"])){
         switch ($_GET["orderby"]) {

+ 1 - 1
app/course/course_get.php

@@ -6,7 +6,7 @@ require_once "../public/_pdo.php";
 require_once "../ucenter/function.php";
 
 $userinfo = new UserInfo();
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 $query = "SELECT * from course where id = ?   limit 0,1";
 $fCourse = PDO_FetchRow($query,array($_GET["id"]));
 

+ 1 - 1
app/course/course_list.php

@@ -18,7 +18,7 @@ require_once '../ucenter/function.php';
 40 已完结
 */
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 
 if(isset($_GET["teacher"])){
     $query = "SELECT * from course where teacher = ?  order by create_time DESC limit 0,100";

+ 1 - 1
app/course/lesson_get.php

@@ -7,7 +7,7 @@ require_once "../ucenter/function.php";
 
 $userinfo = new UserInfo();
 
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 $query = "SELECT * from lesson where id = ?   limit 0,1";
 $fLesson = PDO_FetchRow($query,array($_GET["id"]));
 

+ 1 - 1
app/course/lesson_list.php

@@ -5,7 +5,7 @@ require_once "../path.php";
 require_once "../public/_pdo.php";
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 $query = "SELECT * from lesson where course_id = ? order by date DESC    limit 0,200";
 $fAllLesson = PDO_FetchAll($query,array($_GET["id"]));
 echo json_encode($fAllLesson, JSON_UNESCAPED_UNICODE);

+ 1 - 1
app/course/list_new.php

@@ -7,7 +7,7 @@ require_once '../public/load_lang.php';
 require_once '../ucenter/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:" . _FILE_DB_COURSE_);
+PDO_Connect("" . _FILE_DB_COURSE_);
 $query = "SELECT * from course where 1  order by modify_time DESC limit 0,4";
 $Fetch = PDO_FetchAll($query);
 

+ 1 - 1
app/course/my_course_edit.php

@@ -41,7 +41,7 @@ require_once "../public/_pdo.php";
 require_once '../media/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 
 
 $query = "SELECT * from course where id = ?   limit 0,1";

+ 1 - 1
app/course/my_course_insert.php

@@ -4,7 +4,7 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 
 $query = "INSERT INTO course (id,  title,  subtitle, creator, tag, summary, status, cover, teacher,  lang , speech_lang ,attachment, lesson_num , create_time , modify_time , receive_time ) 
                       VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?  )";

+ 1 - 1
app/course/my_course_list.php

@@ -37,7 +37,7 @@ require_once '../public/load_lang.php';
 require_once '../ucenter/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 $query = "SELECT * from course where creator = ?  order by modify_time DESC limit 0,100";
 $Fetch = PDO_FetchAll($query,array($_COOKIE["userid"]));
 

+ 1 - 1
app/course/my_course_update.php

@@ -34,7 +34,7 @@ if(isset($_FILES["cover"])){
 
 //处理文件上传结束
 
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 
 $query="UPDATE course SET  title = ? , subtitle = ? ,  summary = ? , teacher = ?  , tag = ?  , lang = ?  , attachment = ? , status = ? , receive_time = ?  , modify_time = ?   where  id = ?  ";
 $sth = $PDO->prepare($query);

+ 1 - 1
app/course/my_lesson_edit.php

@@ -43,7 +43,7 @@ require_once "../public/_pdo.php";
 require_once '../media/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 
 $query = "SELECT * from lesson where id = ?  limit 0,1";
 $Fetch = PDO_FetchAll($query,array($_GET["lesson"]));

+ 1 - 1
app/course/my_lesson_insert.php

@@ -4,7 +4,7 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 
 $query="UPDATE course SET  receive_time= ?  , modify_time= ?   where  id = ?  ";
 PDO_Execute($query,array(mTime(),mTime(),$_POST["course_id"]));

+ 1 - 1
app/course/my_lesson_list.php

@@ -42,7 +42,7 @@ require_once "../public/_pdo.php";
 require_once '../ucenter/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 $query = "SELECT * from course where id = ?   limit 0,1";
 $Fetch = PDO_FetchAll($query,array($_GET["course"]));
 if(count($Fetch)==0)

+ 1 - 1
app/course/my_lesson_new.php

@@ -35,7 +35,7 @@ require_once "../public/_pdo.php";
 require_once '../ucenter/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 $query = "SELECT * from course where id = ?   limit 0,1";
 $Fetch = PDO_FetchAll($query,array($_GET["course"]));
 if(count($Fetch)==0)

+ 1 - 1
app/course/my_lesson_update.php

@@ -4,7 +4,7 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:"._FILE_DB_COURSE_);
+PDO_Connect(""._FILE_DB_COURSE_);
 $query="SELECT course_id from lesson  where  id = ?  ";
 $course_id = PDO_FetchOne($query,array($_POST["lesson"]));
 

+ 2 - 2
app/course/teacher_list.php

@@ -7,7 +7,7 @@ require_once '../public/load_lang.php';
 require_once '../ucenter/function.php';
 
 global $PDO;
-PDO_Connect("sqlite:" . _FILE_DB_COURSE_);
+PDO_Connect("" . _FILE_DB_COURSE_);
 $query = "SELECT teacher,count(*) as co from course where 1 group by teacher order by co DESC limit 0,4";
 $Fetch = PDO_FetchAll($query);
 
@@ -17,7 +17,7 @@ foreach ($Fetch as $value) {
     echo '<div class="teacher_text">';
     echo '<div class="title"><a href="../uhome/course.php?userid=' . $value['teacher'] . '">' . ucenter_getA($value['teacher']) . '</a></div>';
     echo '<div class="teacher_intro">';
-    PDO_Connect("sqlite:" . _FILE_DB_USERINFO_);
+    PDO_Connect("" . _FILE_DB_USERINFO_);
     $query = "SELECT bio from profile where user_id = ? limit 0,10";
     $Fetch = PDO_FetchAll($query,array($value['teacher']));
     if($Fetch){

File diff suppressed because it is too large
+ 0 - 1
app/dict/README.md


+ 104 - 0
app/dict/comp_csv.php

@@ -0,0 +1,104 @@
+<?php
+require_once "../path.php";
+
+require_once "../dict/turbo_split.php";
+require_once "../redis/function.php";
+
+if (isset($argv[1])) {
+	$start = (int)$argv[1];
+}
+else{
+	$start=0;
+}
+
+if (isset($argv[2])) {
+	$end = (int)$argv[2];
+}
+else{
+	$end=1000000;
+}
+
+global $result;
+$myfile = fopen(_DIR_TEMP_ . "/comp.csv", "a");
+$filefail = fopen(_DIR_TEMP_ . "/comp_fail.txt", "a");
+$iMax = 2;//输出前三个结果
+/*
+$dns = "" . _FILE_DB_WORD_INDEX_;
+$dbh_word = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dbh_word->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+$query = "SELECT * from wordindex where 1";
+$stmt = $dbh_word->query($query);
+
+while ($word = $stmt->fetch(PDO::FETCH_ASSOC))
+ */
+$redis = redis_connect();
+if ($redis == false) {
+    echo "no redis connect\n";
+    exit;
+}
+$i = null;
+$counter = 0;
+while ($words = $redis->sscan("pali_word", $i)) {
+	# code...
+	
+	if($counter<$start){
+		$counter+=10;
+		continue;
+	}
+	if($counter>$end){
+		echo "all done";
+		exit;
+	}
+    foreach ($words as $key => $word) {
+        # code...
+        $arrword = split_diphthong($word);
+        if (count($arrword) > 1) {
+            fputcsv($myfile, array($word, implode("+", $arrword), 0.99));
+        }
+
+        foreach ($arrword as $oneword) {
+            $counter++;
+			$result = array(); //全局变量,递归程序的输出容器
+			mySplit2($oneword, 0, true, 0.5, 0.9, 0, true, false);
+			if(count($result)<2){
+				mySplit2($oneword, 0, $_express, 0.2, 0.9, 0, true, true);
+				if (isset($_POST["debug"])) {
+					echo "正切:" . count($result) . "\n";
+				}
+				if(count($result)<2){
+					mySplit2($oneword, 0, $_express, 0.2, 0.8, 0, false, true);
+					if (isset($_POST["debug"])) {
+						echo "反切:" . count($result) . "\n";
+					}					
+				}
+				
+			}
+
+            /*
+            #正向切分
+            mySplit2($oneword, 0, false);
+            if (count($result) == 0) {
+            #如果没有 逆向切分
+            mySplit2($oneword, 0, false, 0, 0.8, 0.8, true);
+            }
+             */
+            echo "{$counter}-{$oneword}:" . count($result) . "\n";
+            if (count($result) > 0) {
+                arsort($result); //按信心指数排序
+                $iCount = 0;
+                foreach ($result as $row => $value) {
+					fputcsv($myfile, array($oneword, $row, $value));
+					$iCount++;
+                    if ($iCount > $iMax) {
+                        break;
+                    }
+                }
+            } else {
+                fwrite($filefail, $oneword . "\n");
+            }
+
+        }
+
+    }
+}

+ 41 - 16
app/dict/dict.js

@@ -23,14 +23,17 @@ function dict_search(word) {
 	$.get(
 		"dict_lookup.php",
 		{
-			op: "search",
 			word: word,
 		},
 		function (data, status) {
 			$("#dict_search_result").html(data);
-			$("#dict_list").html($("#dictlist").html());
-			$("#dictlist").html("");
+			$("#dict_list").append($("#dictlist"));
+			$("#search_result_shell").append($("#search_summary"));
 			guide_init();
+			let word_count = parseInt($("#word_count").val());
+			if (word_count < 3) {
+				trubo_split();
+			}
 		}
 	);
 }
@@ -51,16 +54,29 @@ function dict_pre_search(word) {
 	dict_pre_search_curr_word = word;
 
 	$.get(
-		"dict_lookup.php",
+		"dict_lookup_pre.php",
 		{
-			op: "pre",
 			word: word,
 		},
 		function (data, status) {
 			dict_pre_searching = false;
 			dict_pre_search_curr_word = "";
-			$("#pre_search_word_content").html(data);
-			$("#pre_search_result").css("display", "block");
+			try {
+				let result = JSON.parse(data);
+				let html = "<div>";
+				for (const iterator of result) {
+					html += "<div class='dict_word_list' onclick=\"dict_pre_word_click('" + iterator.word + "')\">";
+					html += "<span class='spell' >" + iterator.word + "(" + iterator.count + ")</span>";
+					html += "<div class='mean'>" + iterator.mean + "</div>";
+					html += "</div>";
+				}
+				html += "</div>";
+				$("#pre_search_word_content").html(html);
+				$("#pre_search_result").css("display", "block");
+				$(document).one("click", function () {
+					$("#pre_search_result").hide();
+				});
+			} catch (error) {}
 		}
 	);
 }
@@ -71,6 +87,11 @@ function dict_pre_word_click(word) {
 	dict_search(word);
 }
 
+function search_on_load(word) {
+	$("#dict_ref_search_input").val(word);
+	dict_search(word);
+}
+
 function dict_input_change(obj) {
 	dict_pre_search(obj.value);
 }
@@ -113,15 +134,16 @@ function dict_input_keyup(e, obj) {
 
 function dict_input_split(word) {
 	if (word.indexOf("+") >= 0) {
-		var wordParts = word.split("+");
-		var strParts = "";
-		for (var i in wordParts) {
-			//strParts += "<div class='part_list'><a onclick='dict_search(\"" + wordParts[i] + "\")'>" + wordParts[i] + "</a></div>";
-			strParts += "<part><a onclick='dict_search(\"" + wordParts[i] + "\")'>" + wordParts[i] + "</a></part>";
+		let wordParts = word.split("+");
+		let strParts = "";
+		for (const iterator of wordParts) {
+			strParts += "<part><a onclick='dict_search(\"" + iterator + "\")'>" + iterator + "</a></part>";
 		}
-		strParts =
-			"<div class='dropdown_ctl'><div class='content'><div class='main_view' >" + strParts + "</div></div></div>";
-		$("#input_parts").html(strParts);
+		let html =
+			"点击查词<div class='dropdown_ctl'><div class='content'><div class='main_view' >" +
+			strParts +
+			"</div></div></div>";
+		$("#input_parts").html(html);
 	} else {
 		$("#input_parts").html("");
 	}
@@ -152,6 +174,7 @@ function cls_word_search_history() {
 
 function trubo_split() {
 	$("#pre_search_result").hide();
+	$("#input_parts").html("正在自动切分复合词……");
 	$.post(
 		"split.php",
 		{
@@ -163,7 +186,7 @@ function trubo_split() {
 				let html = "<div>";
 				if (result.length > 0) {
 					for (const part of result[0]["data"]) {
-						html += '<div class="dropdown_ctl">';
+						html += '自动拆分结果<div class="dropdown_ctl">';
 						html += '<div class="content">';
 						html +=
 							'<div class="main_view">' +
@@ -180,6 +203,8 @@ function trubo_split() {
 						html += "</div>";
 						html += "</div>";
 					}
+				} else {
+					html += "无法拆分";
 				}
 				html += "</div>";
 				$("#input_parts").html(html);

+ 309 - 382
app/dict/dict_lookup.php

@@ -4,424 +4,351 @@ require_once '../path.php';
 require_once '../public/casesuf.inc';
 require_once '../public/union.inc';
 require_once "../public/_pdo.php";
-require_once "../public/load_lang.php";//语言文件
+require_once "../public/load_lang.php"; //语言文件
 require_once "../public/function.php";
 require_once "../search/word_function.php";
 require_once "../ucenter/active.php";
+require_once "../dict/p_ending.php";
 
 _load_book_index();
 
+$word = mb_strtolower($_GET["word"], 'UTF-8');
+$org_word = $word;
 
-$op=$_GET["op"];
-$word=mb_strtolower($_GET["word"],'UTF-8');
-$org_word=$word;
+$count_return = 0;
+$dict_list = array();
 
-$count_return=0;
-$dict_list=array();
+$right_word_list = "";
 
-$right_word_list="";
+        add_edit_event(_DICT_LOOKUP_, $word);
+		echo "<div id='dict_list_shell' onclick='setNaviVisibility()'>";
+		echo "<div id='dict_list' class='dict_list_off'></div>";
+		echo "</div>";
+		echo "<div id='dict_ref'>";
+		echo "<div id='search_result_shell'></div>";
+		echo "<div class='pali_spell'><a name='{word_$word}'></a>" . $word . "</div>";
+        $dict_list_a = [];
+        //社区字典开始
+        PDO_Connect("" . _FILE_DB_WBW_);
+        $query = "SELECT *  from " . _TABLE_DICT_REF_ . " where pali = ? limit 0,100";
+        $Fetch = PDO_FetchAll($query, array($word));
+        $iFetch = count($Fetch);
+        $count_return += $iFetch;
+        if ($iFetch > 0) {
+            $userlist = array();
+            foreach ($Fetch as $value) {
+                if (isset($userlist[$value["creator"]])) {
+                    $userlist[$value["creator"]] += 1;
+                } else {
+                    $userlist[$value["creator"]] = 1;
+                }
+                $userwordcase = $value["type"] . "#" . $value["gramma"];
+                if (isset($userdict["{$userwordcase}"])) {
+                    $userdict["{$userwordcase}"]["mean"] .= $value["mean"] . ";";
+                    $userdict["{$userwordcase}"]["factors"] .= $value["factors"];
+                } else {
+                    $userdict["{$userwordcase}"]["mean"] = $value["mean"];
+                    $userdict["{$userwordcase}"]["factors"] = $value["factors"];
+                }
 
-global $PDO;
-function isExsit($word){
-global $PDO;
-		$query = "SELECT count(*) as co from dict where word = ? ";
-		$row=PDO_FetchOne($query,array($word));
-		if($row[0]==0){
-			return false;
-		}
-		else{
-			return true;
-		}
-}
+            }
+            echo "<div class='dict_word'>";
+            echo "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
+            $dict_list_a[] = array("net", $_local->gui->com_dict);
 
-function myfunction($v1,$v2)
-{
-return $v1 . "+" . $v2;
-}
+            foreach ($userdict as $key => $value) {
+                echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
+            }
+            echo "<div><span>{$_local->gui->contributor}:</span>";
+            foreach ($userlist as $key => $value) {
+                echo $key . "[" . $value . "]";
+            }
+            echo "</div>";
+            echo "</div>";
+        }
+        //社区字典结束
 
-function mySplit($strWord){
-	//echo("<br>".$strWord."<br>");
-	$doubleword="kkggccjjṭṭḍḍttddppbb";
-	$len=mb_strlen($strWord,"UTF-8");
-	if($len>5){
-		for($i=$len-1;$i>3;$i--){
-			$str1=mb_substr($strWord,0,$i,"UTF-8");
-			$str2=mb_substr($strWord,$i,NULL,"UTF-8");
-			//echo "$str1 + $str2 = ";
-			if(isExsit($str1)){
-				//echo "match";
-				$left2=mb_substr($str2,0,2,"UTF-8");
-				if(mb_strpos($doubleword,$left2,0,"UTF-8")!==FALSE){
-					$str2=mb_substr($str2,1,NULL,"UTF-8");
-				}
-				return array($str1,$str2);
-			}
-			else{
-				$str1=$str1."a";
-				if(isExsit($str1)){
-					//echo "match";
-					$left2=mb_substr($str2,0,2,"UTF-8");
-					if(mb_strpos($doubleword,$left2,0,"UTF-8")!==FALSE){
-						$str2=mb_substr($str2,1,NULL,"UTF-8");
-					}
-					return array($str1,$str2);
-				}
-			}
-		}
-		//not found
-		if(mb_substr($strWord,0,1,"UTF-8")=="ā"){
-			$strWord='a'.mb_substr($strWord,1,NULL,"UTF-8");
-			for($i=$len-1;$i>3;$i--){
-				$str1=mb_substr($strWord,0,$i,"UTF-8");
-				$str2=mb_substr($strWord,$i,NULL,"UTF-8");
-				//echo "$str1 + $str2 = ";
-				if(isExsit($str1)){
-					//echo "match";
-					$left2=mb_substr($str2,0,2,"UTF-8");
-					if(mb_strpos($doubleword,$left2,0,"UTF-8")!==FALSE){
-						$str2=mb_substr($str2,1,NULL,"UTF-8");
-					}
-					return array($str1,$str2);
-				}
-				else{
-					$str1=$str1."a";
-					if(isExsit($str1)){
-						//echo "match";
-						$left2=mb_substr($str2,0,2,"UTF-8");
-						if(mb_strpos($doubleword,$left2,0,"UTF-8")!==FALSE){
-							$str2=mb_substr($str2,1,NULL,"UTF-8");
-						}
-						return array($str1,$str2);
-					}
-				}
-			}			
+        PDO_Connect("" . _FILE_DB_REF_);
+        //直接查询
+        $query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,100";
+
+        $Fetch = PDO_FetchAll($query, array($word));
+        $iFetch = count($Fetch);
+        $count_return += $iFetch;
+        if ($iFetch > 0) {
+            for ($i = 0; $i < $iFetch; $i++) {
+                $mean = $Fetch[$i]["mean"];
+                $dictid = $Fetch[$i]["dict_id"];
+                $dict_list[$dictid] = $Fetch[$i]["shortname"];
+                $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
+                $outXml = "<div class='dict_word'>";
+                $outXml = $outXml . "<a name='ref_dict_$dictid'></a>";
+                $outXml = $outXml . "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
+                $outXml = $outXml . "<div class='mean'>" . $mean . "</div>";
+                $outXml = $outXml . "</div>";
+                echo $outXml;
+            }
 		}
-		//not found
-		if(mb_substr($strWord,0,1,"UTF-8")=="e"){
-			$strWord='i'.mb_substr($strWord,1,NULL,"UTF-8");
-			for($i=$len-1;$i>3;$i--){
-				$str1=mb_substr($strWord,0,$i,"UTF-8");
-				$str2=mb_substr($strWord,$i,NULL,"UTF-8");
-				//echo "$str1 + $str2 = ";
-				if(isExsit($str1)){
-					//echo "match";
-					$left2=mb_substr($str2,0,2,"UTF-8");
-					if(mb_strpos($doubleword,$left2,0,"UTF-8")!==FALSE){
-						$str2=mb_substr($str2,1,NULL,"UTF-8");
-					}
-					return array($str1,$str2);
-				}
-				else{
-					$str1=$str1."a";
-					if(isExsit($str1)){
-						//echo "match";
-						$left2=mb_substr($str2,0,2,"UTF-8");
-						if(mb_strpos($doubleword,$left2,0,"UTF-8")!==FALSE){
-							$str2=mb_substr($str2,1,NULL,"UTF-8");
-						}
-						return array($str1,$str2);
-					}
-				}
-			}			
-		}		
-	}
-	return(FALSE);
-}
+		
 
+        //去格位除尾查
+        $newWord = array();
+        for ($row = 0; $row < count($case); $row++) {
+            $len = mb_strlen($case[$row][1], "UTF-8");
+            $end = mb_substr($word, 0 - $len, null, "UTF-8");
+            if ($end == $case[$row][1]) {
+                $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][0];
+                if ($base != $word) {
+                    $thiscase = "";
+                    $arrCase = explode('$', $case[$row][2]);
+                    foreach ($arrCase as $value) {
+                        $caseid = "grammar_" . str_replace('.', '', $value);
+                        $thiscase .= "<guide gid='$caseid'>$value</guide>";
+                    }
 
-switch($op){
-	case "pre"://预查询
-		PDO_Connect("sqlite:"._FILE_DB_REF_INDEX_);
-		echo "<div>";
-		$query = "SELECT word,count from dict where eword like ?  OR word like ?  limit 0,20";
+                    if (isset($newWord[$base])) {
+                        $newWord[$base] .= "<br />" . $thiscase;
+                    } else {
+                        $newWord[$base] = $thiscase;
+                    }
+                }
+            }
+        }
 
-		$Fetch = PDO_FetchAll($query,array($word.'%',$word.'%'));
-		$iFetch=count($Fetch);
-		if($iFetch>0){
-			for($i=0;$i<$iFetch;$i++){
-				$word=$Fetch[$i]["word"];
-				$count=$Fetch[$i]["count"];
-				echo  "<div class='dict_word_list'>";
-				echo  "<a onclick='dict_pre_word_click(\"$word\")'>$word-$count</a>";
-				echo  "</div>";
-			}
-		}
-		echo "</div>";
-		break;
-	case "search":
-		add_edit_event(_DICT_LOOKUP_,$word);
-		echo "<div id='dict_list_shell' onclick='setNaviVisibility()'><div id='dict_list' class='dict_list_off'></div></div>";
-		echo "<div id='dict_ref'>";	
-		$dict_list_a = [];
-		//社区字典开始
-		PDO_Connect("sqlite:"._FILE_DB_WBW_);
-		$query = "SELECT *  from dict where pali = ? limit 0,100";
-		$Fetch = PDO_FetchAll($query,array($word));
-		$iFetch=count($Fetch);
-		$count_return+=$iFetch;
-		if($iFetch>0){
-			$userlist = array();
-			foreach($Fetch as $value){
-				if(isset($userlist[$value["creator"]])){
-					$userlist[$value["creator"]] += 1;
-				}
-				else{
-					$userlist[$value["creator"]] = 1;
-				}
-				$userwordcase = $value["type"]."#".$value["gramma"];
-				if(isset($userdict["{$userwordcase}"])){
-					$userdict["{$userwordcase}"]["mean"] .= $value["mean"].";";
-					$userdict["{$userwordcase}"]["factors"] .= $value["factors"];
-				}
-				else{
-					$userdict["{$userwordcase}"]["mean"] = $value["mean"];
-					$userdict["{$userwordcase}"]["factors"] = $value["factors"];
-				}
-				
+		$base_list = array();
+        if (count($newWord) > 0) {
+            foreach ($newWord as $x => $x_value) {
+                $query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,30";
+                $Fetch = PDO_FetchAll($query, array($x));
+                $iFetch = count($Fetch);
+                $count_return += $iFetch;
+                if ($iFetch > 0) {
+					$base_list[] = $x;
+                    $dict_list_a[] = array("word_$x", $x);
+                    echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
+                    //语法信息
+                    foreach ($_local->grammastr as $gr) {
+                        $x_value = str_replace($gr->id, $gr->value, $x_value);
+                    }
+                    echo "<div class='dict_find_gramma'>" . $x_value . "</div>";
+                    for ($i = 0; $i < $iFetch; $i++) {
+                        $mean = $Fetch[$i]["mean"];
+                        $dictid = $Fetch[$i]["dict_id"];
+                        $dict_list[$dictid] = $Fetch[$i]["shortname"];
+                        $dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
+                        echo "<div class='dict_word'>";
+                        echo "<a name='ref_dict_$dictid'></a>";
+                        echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
+                        echo "<div class='mean'>" . $mean . "</div>";
+                        echo "</div>";
+                    }
+                }
+            }
+        }
+		//去除尾查结束
 
-			}
-			echo "<div class='dict_word'>";
-			echo "<div class='dict'>{$_local->gui->com_dict}</div><a name='net'></a>";
-			$dict_list_a[] = array("net",$_local->gui->com_dict);
+		//去分词除尾查
+        $arrBase = array();		
+		if (count($newWord) > 0) {
+			foreach ($newWord as $base => $grammar){
+				for ($row = 0; $row < count($p_ending); $row++) {
+					$len = mb_strlen($case[$row][1], "UTF-8");
+					$end = mb_substr($base, 0 - $len, null, "UTF-8");
+					if ($end == $p_ending[$row][1]) {
+						$newbase = mb_substr($base, 0, mb_strlen($base, "UTF-8") - $len, "UTF-8") . $p_ending[$row][0];
+						if ($newbase != $base) {
+							$thiscase = "";
+							$arrCase = explode('$', $p_ending[$row][2]);
+							foreach ($arrCase as $value) {
+								$caseid = "grammar_" . str_replace('.', '', $value);
+								$thiscase .= "<guide gid='$caseid'>$value</guide>";
+							}
 
-			foreach($userdict as $key => $value){
-				echo "<div class='mean'>{$key}:{$value["mean"]}</div>";
-			}
-			echo "<div><span>{$_local->gui->contributor}:</span>";
-			foreach ($userlist as $key => $value) {
-				echo $key."[".$value."]";
-			}
-			echo "</div>";
-			echo "</div>";
-		}
-		//社区字典结束
+							if (isset($arrBase[$newbase])) {
+								$arrBase[$newbase]['grammar'] .= "<br />" . $thiscase;
+							} else {
+								$arrBase[$newbase]['grammar'] = $thiscase;
+								$arrBase[$newbase]['parent'] = $base;
 
-		PDO_Connect("sqlite:"._FILE_DB_REF_);
-		//直接查询
-		$query = "SELECT dict.dict_id,dict.mean,info.shortname from dict LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,100";
-		
-		$Fetch = PDO_FetchAll($query,array($word));
-		$iFetch=count($Fetch);
-		$count_return+=$iFetch;
-		if($iFetch>0){
-			for($i=0;$i<$iFetch;$i++){
-				$mean=$Fetch[$i]["mean"];
-				$dictid=$Fetch[$i]["dict_id"];
-				$dict_list[$dictid]=$Fetch[$i]["shortname"];
-				$dict_list_a[] = array("ref_dict_$dictid",$Fetch[$i]["shortname"]);
-				$outXml = "<div class='dict_word'>";
-				$outXml = $outXml."<a name='ref_dict_$dictid'></a>";
-				$outXml = $outXml."<div class='dict'>".$Fetch[$i]["shortname"]."</div>";
-				$outXml = $outXml."<div class='mean'>".$mean."</div>";
-				$outXml = $outXml."</div>";
-				echo $outXml;
-			}
-		}
-		//去除尾查
-		$newWord=array();
-		for ($row = 0; $row < count($case); $row++) {
-			$len=mb_strlen($case[$row][1],"UTF-8");
-			$end=mb_substr($word, 0-$len,NULL,"UTF-8");
-			if($end==$case[$row][1]){
-				$base=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$case[$row][0];
-				if($base!=$word){
-					$thiscase = "";
-					$arrCase = explode('$',$case[$row][2]);
-					foreach($arrCase as $value){
-						$caseid = "grammar_".str_replace('.','',$value);
-						$thiscase .= "<guide gid='$caseid'>$value</guide>";
-					}
-					
-					
-					if(isset($newWord[$base])){
-						$newWord[$base] .= "<br />".$thiscase;
-					}
-					else{
-						$newWord[$base] = $thiscase;
+							}
+						}
 					}
 				}
 			}
-		}
 
-		if(count($newWord)>0){
-			foreach($newWord as $x=>$x_value) {
-				$query = "SELECT dict.dict_id,dict.mean,info.shortname from dict LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,30";
-				$Fetch = PDO_FetchAll($query,array($x));
-				$iFetch=count($Fetch);
-				$count_return+=$iFetch;
-				if($iFetch>0){
-					$dict_list_a[] = array("word_$x",$x);
-					echo "<div style='font-size:120%;font-weight:700;'><a name='word_$x'></a>".$x."</div>" ;
-					//语法信息
-					foreach($_local->grammastr as $gr){
-						$x_value = str_replace($gr->id,$gr->value,$x_value);
-					}
-					echo "<div class='dict_find_gramma'>" . $x_value . "</div>";
-					for($i=0;$i<$iFetch;$i++){
-						$mean=$Fetch[$i]["mean"];
-						$dictid=$Fetch[$i]["dict_id"];
-						$dict_list[$dictid]=$Fetch[$i]["shortname"];
-						$dict_list_a[] = array("ref_dict_$dictid",$Fetch[$i]["shortname"]);
-						echo "<div class='dict_word'>";
-						echo "<a name='ref_dict_$dictid'></a>";
-						echo "<div class='dict'>".$Fetch[$i]["shortname"]."</div>";
-						echo "<div class='mean'>".$mean."</div>";
-						echo "</div>";
-					}
-				}			  
-			}
-		}
-		//去除尾查结束
-		
-		//查连读词
-		if($count_return<2){
-			echo "<div>Junction</div>";
-			$newWord=array();
-			for ($row = 0; $row < count($un); $row++) {
-				$len=mb_strlen($un[$row][1],"UTF-8");
-				$end=mb_substr($word, 0-$len,NULL,"UTF-8");
-				if($end==$un[$row][1]){
-					$base=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$un[$row][0];
-						$arr_un=explode("+",$base);
-						foreach ($arr_un as $oneword)
-						{
-						  echo "<a onclick='dict_pre_word_click(\"$oneword\")'>$oneword</a> + ";
+			$base_list = array();
+			if (count($arrBase) > 0) {
+				foreach ($arrBase as $x => $x_value) {
+					$query = "SELECT dict.dict_id,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where word = ? limit 0,30";
+					$Fetch = PDO_FetchAll($query, array($x));
+					$iFetch = count($Fetch);
+					$count_return += $iFetch;
+					if ($iFetch > 0) {
+						$base_list[] = $x;
+						$dict_list_a[] = array("word_$x", $x);
+						echo "<div class='pali_spell'><a name='word_$x'></a>" . $x . "</div>";
+						echo "<div style='color:gray;'>{$x}->{$x_value["parent"]}->{$word}</div>";
+						//语法信息
+						foreach ($_local->grammastr as $gr) {
+							$x_value['grammar'] = str_replace($gr->id, $gr->value, $x_value['grammar']);
 						}
-						echo "<br />";
-				}
-			}		
-		}
-		
-		//查内容
-		if($count_return<2){
-			$word1=$org_word;
-			$wordInMean="%$org_word%";
-			echo "include $org_word:<br />";
-			$query = "SELECT dict.dict_id,dict.word,dict.mean,info.shortname from dict LEFT JOIN info ON dict.dict_id = info.id where mean like ? limit 0,30";
-			$Fetch = PDO_FetchAll($query,array($wordInMean));
-			$iFetch=count($Fetch);
-			$count_return+=$iFetch;
-			if($iFetch>0){
-				for($i=0;$i<$iFetch;$i++){
-					$mean=$Fetch[$i]["mean"];
-					$pos=mb_stripos($mean,$word,0,"UTF-8");
-					if($pos){
-						if($pos>20){
-							$start=$pos-20;
+						echo "<div class='dict_find_gramma'>" . $x_value['grammar'] . "</div>";
+						for ($i = 0; $i < $iFetch; $i++) {
+							$mean = $Fetch[$i]["mean"];
+							$dictid = $Fetch[$i]["dict_id"];
+							$dict_list[$dictid] = $Fetch[$i]["shortname"];
+							$dict_list_a[] = array("ref_dict_$dictid", $Fetch[$i]["shortname"]);
+							echo "<div class='dict_word'>";
+							echo "<a name='ref_dict_$dictid'></a>";
+							echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
+							echo "<div class='mean'>" . $mean . "</div>";
+							echo "</div>";
 						}
-						else{
-							$start=0;
-						}
-						$newmean=mb_substr($mean,$start,100,"UTF-8");
-					}
-					else{
-						$newmean=$mean;
 					}
-					$pos=mb_stripos($newmean,$word1,0,"UTF-8");
-					$head=mb_substr($newmean,0,$pos,"UTF-8");
-					$mid=mb_substr($newmean,$pos,mb_strlen($word1,"UTF-8"),"UTF-8");
-					$end=mb_substr($newmean,$pos+mb_strlen($word1,"UTF-8"),NULL,"UTF-8");
-					$heigh_light_mean="$head<hl>$mid</hl>$end";
-					echo "<div class='dict_word'>";
-					echo "<div class='pali'>".$Fetch[$i]["word"]."</div>";
-					echo "<div class='dict'>".$Fetch[$i]["shortname"]."</div>";
-					echo "<div class='mean'>".$heigh_light_mean."</div>";
-					echo "</div>";
 				}
-			}		
-		}
-		
-		//拆复合词
-		
-		$splitWord=$word;
-		$part=array();
-		if($count_return<2){
-			echo "Try to split comp:<br>";
-			while(($split=mySplit($splitWord))!==FALSE){
-				array_push($part,$split[0]);
-				$splitWord=$split[1];
-			}
-			if(count($part)>0){
-				array_push($part,$splitWord);
-				$newPart=ltrim(array_reduce($part,"myfunction"),"+");
-				echo $newPart;
 			}
 		}
+		//去除尾查结束
 
 
-		echo "<div id='dictlist'>";
-		foreach($dict_list_a as $x_value) {
-			if(substr($x_value[0],0,4)=="word"){
-				echo "<div style='font-size:120%;font-weight:700;margin-top:15px;'>";
-				echo "<a href='#{$x_value[0]}'>$x_value[1]</a></div>";
-			}
-			else{
-				echo "<div><a href='#{$x_value[0]}'>$x_value[1]</a></div>";
+		echo "<div id='search_summary'>";
+		echo "查询{$word} 共{$count_return}条 ";
+		if(count($base_list)>0){
+			echo "找到可能的拼写: ";
+			foreach ($base_list as $key => $value) {
+				# code...
+				echo "<a>{$value}</a> ";
 			}
-		  }		
-		echo "<div>";
-
-		$arrWords = countWordInPali($word,true);
-		$weight = 0;
-		foreach($arrWords as $oneword){
-			$weight += $oneword["count"] * $oneword["len"];
 		}
-		//echo "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
-		//echo "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
-		$right_word_list .= "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
-		$right_word_list .= "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
-		foreach($arrWords as $oneword){
-			if($oneword["bold"]>0){
-				//echo "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
-				$right_word_list .= "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
-			}
-			else{
-				//echo "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
-				$right_word_list .= "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
-			}
-		}		
-		echo "</div>";
 		echo "</div>";
-		echo "</div>";
-		//参考字典查询结束
-
-		//用户词典编辑窗口
-		echo "<div id='dict_user' >";	
-		echo "<div><a href='word_statistics.php?word={$word}'>";
-		echo "<svg t='1596783175334' class='icon' style='font-size: xxx-large; fill: var(--link-hover-color); margin: 5px;' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='7755' width='200' height='200'><path d='M1019.904 450.56L536.576 557.056l417.792 208.896C999.424 692.224 1024 606.208 1024 512c0-20.48 0-40.96-4.096-61.44z m-12.288-61.44C958.464 184.32 786.432 28.672 573.44 4.096L446.464 512l561.152-122.88zM737.28 970.752c73.728-36.864 139.264-90.112 188.416-159.744L507.904 602.112l229.376 368.64zM512 0C229.376 0 0 229.376 0 512s229.376 512 512 512c61.44 0 118.784-12.288 172.032-28.672L385.024 512 512 0z' p-id='7756'></path></svg>";
-		echo "<br>{$_local->gui->click_to_chart}</a></div>";
-		echo $right_word_list;
-		echo "<div class='dict_word' ><b>{$_local->gui->undone_function}</b>";
-		echo "<div class='' onclick=\"dict_show_edit()\">{$_local->gui->edit}</div>";		
-		echo "<div class='pali'>{$word}</div>";
+		echo "<input type='hidden' id='word_count' value='{$count_return}' />";
 
-		if($iFetch>0){
-			echo "<div id='user_word_edit' style='display:none'>";
+        //查连读词
+        if ($count_return < 2) {
+            echo "<div>Junction</div>";
+            $newWord = array();
+            for ($row = 0; $row < count($un); $row++) {
+                $len = mb_strlen($un[$row][1], "UTF-8");
+                $end = mb_substr($word, 0 - $len, null, "UTF-8");
+                if ($end == $un[$row][1]) {
+                    $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $un[$row][0];
+                    $arr_un = explode("+", $base);
+                    foreach ($arr_un as $oneword) {
+                        echo "<a onclick='dict_pre_word_click(\"$oneword\")'>$oneword</a> + ";
+                    }
+                    echo "<br />";
+                }
+            }
 		}
-		else{
-			echo "<div id='user_word_edit'>";
-		}
-		echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->wordtype}</legend>";
-		echo "<select id=\"id_type\" name=\"type\" >";
-		foreach($_local->type_str as $type){
-			echo "<option value=\"{$type->id}\" >{$type->value}</option>";
-		}
-		echo "</select>";
-		echo "</fieldset>";
-		echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->gramma}</legend><input type='input' value=''/></fieldset>";
-		echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->parent}</legend><input type='input' value=''/></fieldset>";
-		echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->g_mean}</legend><input type='input' value=''/></fieldset>";
-		echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->note}</legend><textarea></textarea></fieldset>";
-		echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->factor}</legend><input type='input' value=''/></fieldset>";
-		echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->f_mean}</legend><input type='input' value=''/></fieldset>";
-		echo "<div class=''><button>{$_local->gui->add_to} {$_local->gui->my_dictionary}</button></div>";
-		echo "</div>";
-		echo "</div>";	
-		echo "</div>";			
-		//查用户词典结束	
+		
+		//拆复合词
+		echo "<div id='auto_split'></div>";
+
+/*
+        //查内容
+        if ($count_return < 2) {
+            $word1 = $org_word;
+            $wordInMean = "%$org_word%";
+            echo "包含 $org_word 的:<br />";
+            $query = "SELECT dict.dict_id,dict.word,dict.mean,info.shortname from " . _TABLE_DICT_REF_ . " LEFT JOIN info ON dict.dict_id = info.id where mean like ? limit 0,30";
+            $Fetch = PDO_FetchAll($query, array($wordInMean));
+            $iFetch = count($Fetch);
+            $count_return += $iFetch;
+            if ($iFetch > 0) {
+                for ($i = 0; $i < $iFetch; $i++) {
+                    $mean = $Fetch[$i]["mean"];
+                    $pos = mb_stripos($mean, $word, 0, "UTF-8");
+                    if ($pos) {
+                        if ($pos > 20) {
+                            $start = $pos - 20;
+                        } else {
+                            $start = 0;
+                        }
+                        $newmean = mb_substr($mean, $start, 100, "UTF-8");
+                    } else {
+                        $newmean = $mean;
+                    }
+                    $pos = mb_stripos($newmean, $word1, 0, "UTF-8");
+                    $head = mb_substr($newmean, 0, $pos, "UTF-8");
+                    $mid = mb_substr($newmean, $pos, mb_strlen($word1, "UTF-8"), "UTF-8");
+                    $end = mb_substr($newmean, $pos + mb_strlen($word1, "UTF-8"), null, "UTF-8");
+                    $heigh_light_mean = "$head<hl>$mid</hl>$end";
+                    echo "<div class='dict_word'>";
+                    echo "<div class='pali'>" . $Fetch[$i]["word"] . "</div>";
+                    echo "<div class='dict'>" . $Fetch[$i]["shortname"] . "</div>";
+                    echo "<div class='mean'>" . $heigh_light_mean . "</div>";
+                    echo "</div>";
+                }
+            }
+        }
+*/
+        echo "<div id='dictlist'>";
+        foreach ($dict_list_a as $x_value) {
+            if (substr($x_value[0], 0, 4) == "word") {
+                echo "<div class='pali_spell'>";
+                echo "<a href='#{$x_value[0]}'>$x_value[1]</a></div>";
+            } else {
+                echo "<div><a href='#{$x_value[0]}'>$x_value[1]</a></div>";
+            }
+        }
+        echo "<div>";
+
+        $arrWords = countWordInPali($word, true);
+        $weight = 0;
+        foreach ($arrWords as $oneword) {
+            $weight += $oneword["count"] * $oneword["len"];
+        }
+        //echo "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
+        //echo "<div>{$_local->gui->real_declension}:".count($arrWords)." {$_local->gui->forms}</div>";
+        $right_word_list .= "<div>{$_local->gui->word_weight}:$weight {$_local->gui->characters}</div>";
+        $right_word_list .= "<div>{$_local->gui->real_declension}:" . count($arrWords) . " {$_local->gui->forms}</div>";
+        foreach ($arrWords as $oneword) {
+            if ($oneword["bold"] > 0) {
+                //echo "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
+                $right_word_list .= "<div><b>{$oneword["word"]}</b> {$oneword["count"]} {$_local->gui->times}</div>";
+            } else {
+                //echo "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
+                $right_word_list .= "<div>{$oneword["word"]} {$oneword["count"]}{$_local->gui->times}</div>";
+            }
+        }
+        echo "</div>";
+        echo "</div>";
+        echo "</div>";
+        //参考字典查询结束
+
+        //用户词典编辑窗口
+        echo "<div id='dict_user' >";
+        echo "<div><a href='word_statistics.php?word={$word}'>";
+        echo "<svg t='1596783175334' class='icon' style='font-size: xxx-large; fill: var(--link-hover-color); margin: 5px;' viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' p-id='7755' width='200' height='200'><path d='M1019.904 450.56L536.576 557.056l417.792 208.896C999.424 692.224 1024 606.208 1024 512c0-20.48 0-40.96-4.096-61.44z m-12.288-61.44C958.464 184.32 786.432 28.672 573.44 4.096L446.464 512l561.152-122.88zM737.28 970.752c73.728-36.864 139.264-90.112 188.416-159.744L507.904 602.112l229.376 368.64zM512 0C229.376 0 0 229.376 0 512s229.376 512 512 512c61.44 0 118.784-12.288 172.032-28.672L385.024 512 512 0z' p-id='7756'></path></svg>";
+        echo "<span>{$_local->gui->click_to_chart}</span></a></div>";
+        echo $right_word_list;
+        echo "<div class='dict_word' ><b>{$_local->gui->undone_function}</b>";
+        echo "<div class='' onclick=\"dict_show_edit()\">{$_local->gui->edit}</div>";
+        echo "<div class='pali'>{$word}</div>";
+
+        if ($iFetch > 0) {
+            echo "<div id='user_word_edit' style='display:none'>";
+        } else {
+            echo "<div id='user_word_edit'>";
+        }
+        echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->wordtype}</legend>";
+        echo "<select id=\"id_type\" name=\"type\" >";
+        foreach ($_local->type_str as $type) {
+            echo "<option value=\"{$type->id}\" >{$type->value}</option>";
+        }
+        echo "</select>";
+        echo "</fieldset>";
+        echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->gramma}</legend><input type='input' value=''/></fieldset>";
+        echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->parent}</legend><input type='input' value=''/></fieldset>";
+        echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->g_mean}</legend><input type='input' value=''/></fieldset>";
+        echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->note}</legend><textarea></textarea></fieldset>";
+        echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->factor}</legend><input type='input' value=''/></fieldset>";
+        echo "<fieldset class='broder-1 broder-r'><legend>{$_local->gui->f_mean}</legend><input type='input' value=''/></fieldset>";
+        echo "<div class=''><button>{$_local->gui->add_to} {$_local->gui->my_dictionary}</button></div>";
+        echo "</div>";
+        echo "</div>";
+        echo "</div>";
+        //查用户词典结束
 
-		break;	
-}
 
 
-?>

+ 58 - 0
app/dict/dict_lookup_pre.php

@@ -0,0 +1,58 @@
+<?php
+//查询参考字典
+require_once '../path.php';
+require_once '../public/_pdo.php';
+require_once '../redis/function.php';
+
+if (isset($_GET["language"])) {
+    $currLanguage = $_GET["language"];
+} else {
+    if (isset($_COOKIE["language"])) {
+        $currLanguage = $_COOKIE["language"];
+    } else {
+        $currLanguage = "en";
+    }
+}
+$currLanguage = explode("-", $currLanguage)[0];
+
+if (isset($_GET["word"])) {
+    $word = $_GET["word"];
+} else {
+    echo json_encode(array(), JSON_UNESCAPED_UNICODE);
+    exit;
+}
+/*
+$redis = redis_connect();
+if($redis!==false){
+	$redis->hexist()
+}
+else
+*/
+{
+	PDO_Connect(_FILE_DB_REF_INDEX_);
+	$query = "SELECT word,count from " . _TABLE_REF_INDEX_ . " where eword like ?  OR word like ?  limit 0,15";
+	$Fetch = PDO_FetchAll($query, array($word . '%', $word . '%'));
+
+	PDO_Connect(_FILE_DB_REF_, _DB_USERNAME_, _DB_PASSWORD_);
+	$query = "SELECT mean from " . _TABLE_DICT_REF_ . " where word = ? and language = ?  limit 0,1";
+	foreach ($Fetch as $key => $value) {
+		# code...
+		$mean = PDO_FetchRow($query, array($value["word"], $currLanguage));
+		if ($mean) {
+			$Fetch[$key]["mean"] = $mean["mean"];
+		} else {
+			if ($currLanguage != "en") {
+				$mean = PDO_FetchRow($query, array($value["word"], "en"));
+				if ($mean) {
+					$Fetch[$key]["mean"] = $mean["mean"];
+				} else {
+					$Fetch[$key]["mean"] = "";
+				}
+			} else {
+				$Fetch[$key]["mean"] = "";
+			}
+		}
+	}
+}
+
+echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);

+ 95 - 63
app/dict/index.php

@@ -4,13 +4,12 @@ require_once "../pcdl/html_head.php";
 
 <body>
 	<a name="toc_root"></a>
-	<?php
-	if(!(isset($_GET["inline"]) && $_GET["inline"]=='1')){
-		require_once("../pcdl/head_bar.php");
-	}
-	
-	?>
-
+<?php
+if (!(isset($_GET["builtin"]) && $_GET["builtin"] == 'true')) {
+    require_once "../pcdl/head_bar.php";
+}
+?>
+	<script language="javascript" src="./dict.js"></script>
 	<style>
 		body {
 			margin: unset;
@@ -96,13 +95,14 @@ require_once "../pcdl/html_head.php";
 		/*for word split part */
 		.dropdown_ctl {
 			display: inline-block;
-			margin-right: 0.7em;
+			margin: 0 0.7em;
 		}
 
 		.dropdown_ctl>.content {
 			display: flex;
 			border: 1px solid var(--border-line-color);
 			border-radius: 99px;
+			line-height: 2em;
 		}
 
 		.dropdown_ctl>.menu {
@@ -218,6 +218,44 @@ require_once "../pcdl/html_head.php";
 		.dict_find_gramma guide{
 			color:unset;
 		}
+
+		#pre_search_result{
+			background-color: var(--btn-color);
+			z-index: 50;
+			display:none;
+		}
+
+		#dt_title {
+			border-bottom: 2px solid var(--link-hover-color);
+		}
+
+		.dict_word_list .mean {
+			overflow: hidden;
+			text-overflow: ellipsis;
+			display: -webkit-box;
+			-webkit-box-orient: vertical;
+			-webkit-line-clamp: 1;
+			padding-left: 1em;
+		}
+
+		.section_inner{
+			max-width:1024px;
+			margin: 0 auto;
+		}
+		.spell{
+			font-size: 110%;
+    		font-weight: 700;
+		}
+		.dict_word_list:hover{
+			color: var(--link-hover-color);
+		}
+
+		.pali_spell{
+			font-size:200%;
+			font-weight:700;
+			margin-top:15px;
+			padding-bottom:0
+		}
 	</style>
 	<link type="text/css" rel="stylesheet" href="./css/style.css" >
 	<link type="text/css" rel="stylesheet" href="./css/style_mobile.css" media="screen and (max-width:800px)">
@@ -225,7 +263,7 @@ require_once "../pcdl/html_head.php";
 
 	<!-- tool bar begin-->
 	<div id='search_toolbar' class="search_toolbar">
-		<div style="display:flex;justify-content: space-between;">
+		<div class='section_inner' style="display:flex;justify-content: space-between;">
 			<div id="left_menu_button">
 				<button id="left_toc" type="button" class="icon_btn" onclick="setNaviVisibility('table_of_content')" title="Dict List">
 				<svg class="icon">
@@ -241,14 +279,15 @@ require_once "../pcdl/html_head.php";
 			<div style="flex:6;">
 				<div>
 					<div>
-						<input id="dict_ref_search_input" type="input" placeholder="<?php echo $_local->gui->search; ?>" onkeyup="dict_input_keyup(event,this)" style="" onfocus="dict_input_onfocus()" />
+						<input id="dict_ref_search_input" type="text" autocomplete="off" placeholder="<?php echo $_local->gui->search; ?> 单词里面添加+ 预览拆词结果" onkeyup="dict_input_keyup(event,this)" style="" onfocus="dict_input_onfocus()" />
 					</div>
+					<div id="result_msg"></div>
 					<div id="word_parts">
 						<div id="input_parts" style="font-size: 1.1em;padding: 2px 1em;"></div>
 					</div>
 				</div>
 
-				<div id="pre_search_result" style="background-color: var(--btn-color);z-index: 50;">
+				<div id="pre_search_result" >
 					<div id="pre_search_word" class="pre_serach_block">
 						<div id="pre_search_word_title" class="pre_serach_block_title">
 							<div id="pre_search_word_title_left"><?php echo $_local->gui->vocabulary_list; ?></div>
@@ -261,8 +300,7 @@ require_once "../pcdl/html_head.php";
 			</div>
 			<span style="display:flex;">
 				<button id="trubo_split" onclick="trubo_split()" >
-					<?php echo $_local->gui->turbo_split; //强力拆分
-					?>
+					<?php echo $_local->gui->turbo_split; /*强力拆分*/ ?>
 				</button>
 				<guide gid="comp_split"></guide>
 			</span>
@@ -312,60 +350,54 @@ require_once "../pcdl/html_head.php";
 			</a>
 		</button>
 	</div>
-	<script>
-		window.addEventListener('scroll', winScroll);
-
-		function winScroll(e) {
-			if (GetPageScroll().y > 150) {
-				$("#search_toolbar_1").css("top", 0);
-			} else {
-				$("#search_toolbar_1").css("top", GetPageScroll().y - 150);
-			}
-			if (GetPageScroll().y > $(window).height() * 0.9) {
-				$("#tool_btn").show();
-			} else {
-				$("#tool_btn").hide();
-			}
-
-		}
-		//滚动条位置
-		function GetPageScroll() {
-			var pos = new Object();
-			var x, y;
-			if (window.pageYOffset) { // all except IE	
-				y = window.pageYOffset;
-				x = window.pageXOffset;
-			} else if (document.documentElement && document.documentElement.scrollTop) { // IE 6 Strict	
-				y = document.documentElement.scrollTop;
-				x = document.documentElement.scrollLeft;
-			} else if (document.body) { // all other IE	
-				y = document.body.scrollTop;
-				x = document.body.scrollLeft;
-			}
-			pos.x = x;
-			pos.y = y;
-			return (pos);
-		}
-	</script>
-	<style>
-		#dt_title {
-			border-bottom: 2px solid var(--link-hover-color);
-		}
-	</style>
-	<script language="javascript" src="./dict.js"></script>
 
-	<div id="dict_search_result" style="background-color:white;color:black;">
+<div>
+	<div class='section_inner' id="dict_search_result" style="background-color:white;color:black;">
 	</div>
+</div>
+	<script>
+<?php
+if (isset($_GET["key"]) && !empty($_GET["key"])) {
+    echo "var _key='{$_GET["key"]}';\n";
+    echo "search_on_load(\"{$_GET["key"]}\")";
+}
+?>
 
-	<?php
-	if (!empty($_GET["key"])) {
-		echo "<script>";
-		echo "dict_pre_word_click(\"{$_GET["key"]}\")";
-		echo "</script>";
+window.addEventListener('scroll', winScroll);
+
+function winScroll(e) {
+	if (GetPageScroll().y > 150) {
+		$("#search_toolbar_1").css("top", 0);
+	} else {
+		$("#search_toolbar_1").css("top", GetPageScroll().y - 150);
+	}
+	if (GetPageScroll().y > $(window).height() * 0.9) {
+		$("#tool_btn").show();
+	} else {
+		$("#tool_btn").hide();
 	}
-	?>
 
+}
+//滚动条位置
+function GetPageScroll() {
+	var pos = new Object();
+	var x, y;
+	if (window.pageYOffset) { // all except IE
+		y = window.pageYOffset;
+		x = window.pageXOffset;
+	} else if (document.documentElement && document.documentElement.scrollTop) { // IE 6 Strict
+		y = document.documentElement.scrollTop;
+		x = document.documentElement.scrollLeft;
+	} else if (document.body) { // all other IE
+		y = document.body.scrollTop;
+		x = document.body.scrollLeft;
+	}
+	pos.x = x;
+	pos.y = y;
+	return (pos);
+}
+</script>
 
 	<?php
-	include "../pcdl/html_foot.php";
-	?>
+include "../pcdl/html_foot.php";
+?>

+ 39 - 0
app/dict/multi-core.bat

@@ -0,0 +1,39 @@
+
+rem RunP.bat
+rem 同时并行运行多个程序
+
+set cmd1=php comp_csv.php 0 50000
+set cmd2=php comp_csv.php 49990 100000
+set cmd3=php comp_csv.php 99990 150000
+set cmd4=php comp_csv.php 149990 200000
+set cmd5=php comp_csv.php 199990 250000
+set cmd6=php comp_csv.php 249990 300000
+set cmd7=php comp_csv.php 299990 350000
+set cmd8=php comp_csv.php 349990 400000
+set cmd9=php comp_csv.php 399990 450000
+set cmd10=php comp_csv.php 449990 500000
+set cmd11=php comp_csv.php 499990 550000
+set cmd12=php comp_csv.php 549990 600000
+set cmd13=php comp_csv.php 599990 650000
+set cmd14=php comp_csv.php 649990 700000
+set cmd15=php comp_csv.php 699990 750000
+set cmd16=php comp_csv.php 749990 800000
+set cmd17=php comp_csv.php 799990 855000
+
+start %cmd1%
+start %cmd2%
+start %cmd3%
+start %cmd4%
+start %cmd5%
+start %cmd6%
+start %cmd7%
+start %cmd8%
+start %cmd9%
+start %cmd10%
+start %cmd11%
+start %cmd12%
+start %cmd13%
+start %cmd14%
+start %cmd15%
+start %cmd16%
+start %cmd17%

+ 19 - 0
app/dict/p_ending.php

@@ -0,0 +1,19 @@
+<?php
+global $p_ending;
+$p_ending = array(
+array("ti","māna",".ti.$.prp."),
+array("ti","anta",".ti.$.prp."),
+array("ti","ta",".ti.pp."),
+array("ti","na",".ti.$.pp."),
+array("ati","eyya",".ti.$.fpp."),
+array("eti","eyya",".ti.$.fpp."),
+array("oti","eyya",".ti.$.fpp."),
+array("ti","tabba",".ti.$.fpp."),
+array("ati","itabba",".ti.$.fpp."),
+array("eti","itabba",".ti.$.fpp."),
+array("oti","itabba",".ti.$.fpp."),
+array("ati","aniya",".ti.$.fpp."),
+array("eti","aniya",".ti.$.fpp."),
+array("oti","aniya",".ti.$.fpp.")
+)
+?>

+ 46 - 0
app/dict/pali_word_list_to_redis.php

@@ -0,0 +1,46 @@
+<?php
+require_once "../path.php";
+require_once "../install/filelist.php";
+require_once "../redis/function.php";
+
+if (PHP_SAPI == "cli") {
+    if ($argc >= 2) {
+        $command = $argv[1];
+    } else {
+        $redis = redis_connect();
+        if ($redis == false) {
+            echo "no redis connect\n";
+            exit;
+        }
+        $dirXmlBase = _DIR_PALI_CSV_ . "/";
+
+        $book = array(1, 2, 3, 4, 5, 6, 7, 8, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 153, 152, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217);
+        $redis->delete('pali_word');
+        foreach ($book as $key => $value) {
+            # code...
+            echo "runing:{$value}\n";
+            $outputFileNameHead = $_filelist[$value];
+            $dirXml = $outputFileNameHead . "/";
+            // 打开文件并读取数据
+            $irow = 0;
+            if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+                while (($str = fgets($fp)) !== false) {
+                    $data = explode(",", $str);
+                    $irow++;
+                    if ($irow > 1) {
+                        if ($data[6] != ".ctl." && $data[5] != "") {
+                            $redis->sadd('pali_word', $data[5]);
+                        }
+                    }
+                }
+                fclose($fp);
+            } else {
+                echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
+            }
+        }
+    }
+} else {
+    echo "cli";
+}
+
+echo "<h2>齐活!功德无量!all done!</h2>";

+ 146 - 470
app/dict/split.php

@@ -4,501 +4,177 @@
 function: split compound word
 step 1 : split at diphthong . ~aa~ -> ~a-a~
 第一步:先切开双元音
-step 2 : every part use sandhi rule 
+step 2 : every part use sandhi rule
 第二步:用$sandhi的方法切分(套用连音规则)
-algorithm: 
+algorithm:
 算法:
 f(word){
-	1. cut one letter from the end of word by sandhi rule in array($sandhi)
-	1. 从单词尾部切去一个字母
-	2. lookup first part . 
-	2. 查询剩余部分
-	if confidence value>0.8 
-	如果有结果
-		- get the confidence value 
-		获取该部分的信心指数
-		- process the remaining part at same way
-		用同样的方法处理剩余部分
-		- f(stack.first element)
-	else
-		apply other sandhi rule
-		back to 1
+1. cut one letter from the end of word by sandhi rule in array($sandhi)
+1. 从单词尾部切去一个字母
+2. lookup first part .
+2. 查询剩余部分
+if confidence value>0.8
+如果有结果
+- get the confidence value
+获取该部分的信心指数
+- process the remaining part at same way
+用同样的方法处理剩余部分
+- f(stack.first element)
+else
+apply other sandhi rule
+back to 1
 }
 this is a recursion, depth=16
 此为递归算法,深度=16
-*/
-require_once '../public/casesuf.inc';
-require_once '../studio/dict_find_un.inc';
-require_once '../studio/sandhi.php';
-require_once "../path.php";
-require_once "../public/_pdo.php";
+ */
+require_once "../dict/turbo_split.php";
 
 //check input
-if(isset($_POST["word"])){
-	$input_word=mb_strtolower(trim($_POST["word"]),'UTF-8');
-	if(trim($input_word)==""){
-		echo "Empty";
-		exit;
-	}
-	$arrWords = str_getcsv($input_word,"\n");//支持批量拆分 
-}
-else{
-?>
+if (isset($_POST["word"])) {
+    $input_word = mb_strtolower(trim($_POST["word"]), 'UTF-8');
+    if (trim($input_word) == "") {
+        echo "Empty";
+        exit;
+    }
+    $arrWords = str_getcsv($input_word, "\n"); //支持批量拆分
+} else {
+    ?>
 <!--debug only-->
 <form action="split.php" method="post">
-Words: <textarea type="text" name="word"></textarea>
+Words: <br>
+<textarea type="text" name="word" style="width:50em;height:20em;"></textarea><br>
 <input name="debug" type="hidden" />批量查询,单词之间用换行分隔。 input word. between two words insert 'enter'
 <div>
-<input type="checkbox" name = "express" checked /> 快速搜索(遇到第一个连音规则成功就返回) return when get first result 
+<input type="checkbox" name = "express" checked /> 快速搜索(遇到第一个连音规则成功就返回) return when get first result
 </div>
 <input type="submit">
 </form>
 
 <?php
-	return;
-}
-
-if(isset($_POST["express"])){
-	if($_POST["express"]==="on"){
-		$_express = true;
-	}
-	else{
-		$_express = false;
-	}
-}
-else{
-	$_express = false;
-}
-
-// open word part db
-global $dbh;
-$dns = "sqlite:"._FILE_DB_PART_;
-$dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
-
-global $path;
-global $confidence;
-global $result;
-global $part ;
-$part= array();
-
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-$path[]=array("",0);
-
-	global $sandhi ;
-	//sandhi rules table 语尾表
-	$sandhi[]=array("a"=>"","b"=>"","c"=>"","len"=>0,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"a","c"=>"ā","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"ā","b"=>"ā","c"=>"ā","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"ā","c"=>"ā","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"ā","b"=>"a","c"=>"ā","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"e","c"=>"e","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"i","c"=>"i","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"o","c"=>"o","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"u","c"=>"o","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"u","b"=>"a","c"=>"o","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"u","b"=>"u","c"=>"ū","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"u","c"=>"u","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"ī","c"=>"ī","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"ū","c"=>"ū","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"i","c"=>"e","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"i","b"=>"i","c"=>"ī","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"i","b"=>"e","c"=>"e","len"=>1,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"i","b"=>"a","c"=>"ya","len"=>2,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"atth","c"=>"atth","len"=>4,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"taṃ","b"=>"n","c"=>"tann","len"=>4,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"api","c"=>"mpi","len"=>3,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"eva","c"=>"meva","len"=>4,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[o]","b"=>"iva","c"=>"ova","len"=>3,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"ādi","c"=>"ādi","len"=>3,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a[ānaṃ]","b"=>"a","c"=>"ānama","len"=>5,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"a","b"=>"iti","c"=>"āti","len"=>3,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"ca","c"=>"ñca","len"=>3,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"iti","c"=>"nti","len"=>3,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"a","c"=>"ma","len"=>2,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"ā","c"=>"mā","len"=>2,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"u","c"=>"mu","len"=>2,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"[ṃ]","b"=>"h","c"=>"ñh","len"=>2,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"ā","b"=>"[ṃ]","c"=>"am","len"=>2,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"ī","b"=>"[ṃ]","c"=>"im","len"=>2,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"ati","b"=>"tabba","c"=>"atabba","len"=>6,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"ati","b"=>"tabba","c"=>"itabba","len"=>6,"adj_len"=>0,"advance"=>false);
-	$sandhi[]=array("a"=>"iti","b"=>"a","c"=>"icca","len"=>4,"adj_len"=>0,"advance"=>false);
-
-/*
-other sandhi rule. can be use but program will be slow down
-其他连音规则,如果使用则会让程序运行变慢
-
-$sandhi[]=array("a"=>"u[ūnaṃ]","b"=>"a","c"=>"ūnama","len"=>5,"adj_len"=>0,"advance"=>false);
-$sandhi[]=array("a"=>"ī[īnaṃ]","b"=>"a","c"=>"īnama","len"=>5,"adj_len"=>0,"advance"=>false);
-
-$sandhi[]=array("a"=>"ā","b"=>"iti","c"=>"āti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"a","b"=>"iti","c"=>"āti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"e","b"=>"iti","c"=>"eti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"ī","b"=>"iti","c"=>"īti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"i","b"=>"iti","c"=>"īti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"o","b"=>"iti","c"=>"oti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"ū","b"=>"iti","c"=>"ūti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"u","b"=>"iti","c"=>"ūti","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"ṃ","b"=>"iti","c"=>"nti","len"=>3,"adj_len"=>0);
-
-$sandhi[]=array("a"=>"ṃ","b"=>"ca","c"=>"ñca","len"=>3,"adj_len"=>0);
-
-$sandhi[]=array("a"=>"a","b"=>"eva","c"=>"eva","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"ā","b"=>"eva","c"=>"āyeva","len"=>5,"adj_len"=>0);
-$sandhi[]=array("a"=>"e","b"=>"eva","c"=>"eva","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"i","b"=>"eva","c"=>"yeva","len"=>4,"adj_len"=>0);
-$sandhi[]=array("a"=>"ī","b"=>"eva","c"=>"iyeva","len"=>5,"adj_len"=>0);
-$sandhi[]=array("a"=>"ī","b"=>"eva","c"=>"īyeva","len"=>5,"adj_len"=>0);
-$sandhi[]=array("a"=>"o","b"=>"eva","c"=>"ova","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"u","b"=>"eva","c"=>"veva","len"=>3,"adj_len"=>0);
-
-$sandhi[]=array("a"=>"a","b"=>"eva","c"=>"evā","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"e","b"=>"eva","c"=>"evā","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"i","b"=>"eva","c"=>"yevā","len"=>4,"adj_len"=>0);
-$sandhi[]=array("a"=>"ī","b"=>"eva","c"=>"yevā","len"=>4,"adj_len"=>0);
-$sandhi[]=array("a"=>"ī","b"=>"eva","c"=>"iyevā","len"=>4,"adj_len"=>0);
-$sandhi[]=array("a"=>"ī","b"=>"eva","c"=>"īyevā","len"=>4,"adj_len"=>0);
-$sandhi[]=array("a"=>"o","b"=>"eva","c"=>"ovā","len"=>4,"adj_len"=>0);
-
-$sandhi[]=array("a"=>"ā","b"=>"api","c"=>"āpi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"a","b"=>"api","c"=>"āpi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"e","b"=>"api","c"=>"epi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"ī","b"=>"api","c"=>"īpi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"i","b"=>"api","c"=>"īpi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"o","b"=>"api","c"=>"opi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"ū","b"=>"api","c"=>"ūpi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"u","b"=>"api","c"=>"ūpi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"u","b"=>"api","c"=>"upi","len"=>3,"adj_len"=>0);
-$sandhi[]=array("a"=>"ṃ","b"=>"api","c"=>"mpi","len"=>3,"adj_len"=>0);
-*/
-	//$sandhi[]=array("a"=>"a","b"=>"a","c"=>"a","len"=>1,"adj_len"=>-1,"advance"=>true);
-	//$sandhi[]=array("a"=>"ī","b"=>"","c"=>"i","len"=>1,"adj_len"=>0,"advance"=>true);
-
-
-//diphthong table双元音表
-$search  = array('aa', 'ae', 'ai', 'ao', 'au', 'aā', 'aī', 'aū', 'ea', 'ee', 'ei', 'eo', 'eu', 'eā', 'eī', 'eū', 'ia', 'ie', 'ii', 'io', 'iu', 'iā', 'iī', 'iū', 'oa', 'oe', 'oi', 'oo', 'ou', 'oā', 'oī', 'oū', 'ua', 'ue', 'ui', 'uo', 'uu', 'uā', 'uī', 'uū', 'āa', 'āe', 'āi', 'āo', 'āu', 'āā', 'āī', 'āū', 'īa', 'īe', 'īi', 'īo', 'īu', 'īā', 'īī', 'īū', 'ūa', 'ūe', 'ūi', 'ūo', 'ūu', 'ūā', 'ūī', 'ūū');
-$replace = array('a-a', 'a-e', 'a-i', 'a-o', 'a-u', 'a-ā', 'a-ī', 'a-ū', 'e-a', 'e-e', 'e-i', 'e-o', 'e-u', 'e-ā', 'e-ī', 'e-ū', 'i-a', 'i-e', 'i-i', 'i-o', 'i-u', 'i-ā', 'i-ī', 'i-ū', 'o-a', 'o-e', 'o-i', 'o-o', 'o-u', 'o-ā', 'o-ī', 'o-ū', 'u-a', 'u-e', 'u-i', 'u-o', 'u-u', 'u-ā', 'u-ī', 'u-ū', 'ā-a', 'ā-e', 'ā-i', 'ā-o', 'ā-u', 'ā-ā', 'ā-ī', 'ā-ū', 'ī-a', 'ī-e', 'ī-i', 'ī-o', 'ī-u', 'ī-ā', 'ī-ī', 'ī-ū', 'ū-a', 'ū-e', 'ū-i', 'ū-o', 'ū-u', 'ū-ā', 'ū-ī', 'ū-ū');
-
-//main 
-
-$allword = array();
-foreach($arrWords as $oneword){
-	//预处理
-	//将双元音拆开
-	//step 1 : split at diphthong . ~aa~ -> ~a-a~
-	$word = str_replace($search, $replace, $oneword);
-
-	if(isset($_POST["debug"])){
-		echo "Look up:{$word}<br>";
-	}
-	
-	//按连字符拆开处理
-	$arrword = str_getcsv($word,"-");
-
-	$t1=microtime_float();
-	$output = array();
-	foreach($arrword as $oneword){
-		$result = array();//全局变量,递归程序的输出容器
-
-		if(mb_strlen($oneword,"UTF-8")<30){
-			mySplit2($oneword,0,$_express);
-		}
-		else{
-			mySplit2($oneword,0,$_express);
-		}
-		
-		arsort($result);//按信心指数排序
-		$wordlist = array();
-		$iMax = 5;
-		$iCount = 0;
-		foreach($result as $row=>$value){
-			$iCount++;
-			$word_part  = array();
-			$word_part["word"] = $row;
-			$word_part["confidence"] = $value;
-			$wordlist[] = $word_part;
-			if($iCount>=$iMax){
-			break;
-			}
-
-		}
-		$output[] = $wordlist;
-
-		if(isset($_POST["debug"])){
-			echo "<h2>{$oneword}</h2>";
-			echo "<h4>".count($result)."</h4>";
-		}
-		$iCount=0;
-		foreach($result as $row=>$value){
-			if($iCount>10){
-				break;
-			}
-			$iCount++;
-			$level=$value*90;
-			if(isset($_POST["debug"])){
-				echo $row."-[".$value."]<br>";
-			}
-		}
-		
-		/*
-		后处理
-		-ssāpi=-[ssa]-api
-		*/
-	}
-	$t2 = microtime_float();
-	$one_split["data"]=$output;
-	$one_split["time"]= $auto_split_times;
-	$one_split["second"]= $t2-$t1;	
-	$allword[] = $one_split;
-
-	if(isset($_POST["debug"])){
-		echo "<div>";
-		echo "<br>查询【{$auto_split_times}】次";	
-		echo "time:".($t2-$t1);
-		echo "</div>";
-	}
+return;
 }
 
-if(isset($_POST["debug"])){
-	echo "<pre style='margin:2em;padding:1em;background-color:#e9e9e9;'>";
-	print_r($allword);
-	echo "</pre>";
-}
-echo json_encode($allword,JSON_UNESCAPED_UNICODE);
-
-/*
-用于数组连接字符串
-*/
-function myfunction($v1,$v2)
-{
-	return $v1 . "+" . $v2;
-}
-function microtime_float()
-{
-    list($usec, $sec) = explode(" ", microtime());
-    return ((float)$usec + (float)$sec);
-}
-
-function dict_lookup($word){
-	global $dbh;
-	$query = "SELECT weight from part where word = ? ";
-	$stmt = $dbh->prepare($query);
-	$stmt->execute(array($word));
-    $row = $stmt->fetch(PDO::FETCH_NUM);
-    if ($row) {
-        return $row[0];
+if (isset($_POST["express"])) {
+    if ($_POST["express"] === "on") {
+        $_express = true;
     } else {
-        return 0;
-    }	
+        $_express = false;
+    }
+} else {
+    $_express = false;
 }
 
-/*
-查找某个单词是否在现有词典出现
-返回信心指数
-look up single word in dictionary vocabulary
-return the confidence value
-*/
-function isExsit($word,$adj_len=0){
+//main
 
-	global $auto_split_times;
-	global $result;
-	global $part;
-	global $confidence;
-	$auto_split_times++;
-	
-	if(isset($_POST["debug"])){
-		echo "<div>正在查询:{$word}</div>";
-	}
-	$isFound=false;
-	if(isset($part["{$word}"]))
-	{
-		if($part["{$word}"]>0){
-			$isFound=true;
-			$count=$part["{$word}"]+1;			
-		}
-	}
-	else{
-		$db=dict_lookup($word);
-		//加入查询缓存
-		$part["{$word}"] = $db;
-		if($db>0){
-			$isFound=true;
-			$count=$db+1;
-		}
-		else{
-			
-		}
-	} 
-//fomular of confidence value 信心值计算公式
-	if($isFound)
-	{
-		if(isset($confidence["{$word}"])){
-			$cf=$confidence["{$word}"];
-		}
-		else{
-			$len=mb_strlen($word,"UTF-8")+$adj_len;
-			$len_correct=1.2;
-			$count2=1.1+pow($count,1.18);
-			$conf_num=pow(1/$count2,pow(($len-1),$len_correct));
-			$cf=round(1/(1+640*$conf_num),9);
-
-			$confidence["{$word}"]=$cf;
-		}
-		return($cf);
-		
-	}
-	else{
-		return(-1);
-	}
+$allword = array();
+foreach ($arrWords as $currword) {
+    $t1 = microtime_float();
+    $output = array();
+    if (isset($_POST["debug"])) {
+        echo "Look up:{$currword}<br>";
+    }
+
+    //预处理
+    //将双元音拆开
+    //step 1 : split at diphthong . ~aa~ -> ~a-a~
+    //按连字符拆开处理
+    $arrword = split_diphthong($currword);
+    foreach ($arrword as $oneword) {
+        $result = array(); //全局变量,递归程序的输出容器
+
+        mySplit2($oneword, 0, false, 0, 0.5, 0.8, true, false);
+		if(count($result) < 3){
+			mySplit2($oneword, 0, $_express, 0, 0.2, 0.8, true, true);
+		}
+        if (isset($_POST["debug"])) {
+            echo "正切:" . count($result) . "\n";
+		}
+		if(count($result) < 3){
+			mySplit2($oneword, 0, $_express, 0, 0.2, 0.8, false, true);
+		}
+        if (isset($_POST["debug"])) {
+            echo "反切:" . count($result) . "\n";
+        }
+        /*
+        if (count($result) < 5) {
+        #sandhi advance
+        mySplit2($oneword, 0, $_express, 0, 0.8, 0.8, false, true);
+        if (isset($_POST["debug"])) {
+        echo "反切:" . count($result) . "\n";
+        }
+        }
+        if (count($result) < 5) {
+        #反向
+        mySplit2($oneword, 0, $_express, 0, 0.8, 0.8, false);
+        }
+        if (count($result) < 5) {
+        #正向
+        mySplit2($oneword, 0, $_express, 0, 0.8, 0, true);
+        }
+        if (count($result) < 5) {
+        #反向
+        mySplit2($oneword, 0, $_express, 0, 0.8, 0, false);
+        }
+         */
+        arsort($result); //按信心指数排序
+
+        #输出结果 ouput to json
+        $wordlist = array();
+        $iMax = 5;
+        $iCount = 0;
+        foreach ($result as $row => $value) {
+            $iCount++;
+            $word_part = array();
+            $word_part["word"] = $row;
+            $word_part["confidence"] = $value;
+            $wordlist[] = $word_part;
+            if ($iCount >= $iMax) {
+                break;
+            }
+
+        }
+        $output[] = $wordlist;
+
+        if (isset($_POST["debug"])) {
+            echo "<h2>{$oneword}</h2>";
+            echo "<h4>" . count($result) . "</h4>";
+        }
+        $iCount = 0;
+        foreach ($result as $row => $value) {
+            if ($iCount > 10) {
+                break;
+            }
+            $iCount++;
+            $level = $value * 90;
+            if (isset($_POST["debug"])) {
+                echo $row . "-[" . $value . "]<br>";
+            }
+        }
+
+        /*
+    后处理
+    -ssāpi=-[ssa]-api
+     */
+    }
+    $t2 = microtime_float();
+    $one_split["data"] = $output;
+    $one_split["time"] = $auto_split_times;
+    $one_split["second"] = $t2 - $t1;
+    $allword[] = $one_split;
+
+    if (isset($_POST["debug"])) {
+        echo "<div>";
+        echo "<br>查询【{$auto_split_times}】次";
+        echo "time:" . ($t2 - $t1);
+        echo "</div>";
+    }
 }
 
-/*
-核心拆分函数
-
-$strWord, word to be look up 要查询的词
-$deep, 当前递归深度
-$express=true, 快速查询
-$adj_len=0 长度校正系数
-$c_threshhold 信心指数阈值
-*/
-
-function mySplit2($strWord,$deep,$express=false,$adj_len=0,$c_threshhold=0.8){
-	global $path;
-	global $result;
-	global $sandhi ;
-	$output = array();
-	
-	//达到最大搜索深度,返回
-	if($deep>=16){
-		$word = "";
-		$cf=1.0;
-		for($i=0;$i<$deep;$i++){
-			$word .= $path[$i][0];
-			if(isset($_POST["debug"])){
-				$word .="(".$path[$i][1].")-";
-			}
-			else{
-				$word .= "-";
-			}
-			$cf=$cf*$path[$i][1];
-		}
-		$len=pow(mb_strlen($strWord,"UTF-8"),3);
-		$cf+=(0-$len)/($len+150);
-		$word .= "{$strWord}";
-		$result[$word]=$cf;
-		return;
-	}
-	//直接找到
-	$confidence=isExsit($strWord,$adj_len);
-	if($confidence>=0){
-		$output[] = array($strWord,"",$confidence);
-	}
-	else{
-		$confidence=isExsit("[".$strWord."]");
-		if($confidence>=0){
-			$output[] = array("[".$strWord."]","",$confidence);
-		}
-	}
-
-	//如果开头有双辅音,去掉第一个辅音。因为巴利语中没有以双辅音开头的单词。
-	$doubleword="kkggccjjṭṭḍḍttddppbb";
-	if(mb_strlen($strWord,"UTF-8")>2){
-		$left2=mb_substr($strWord,0,2,"UTF-8");
-		if(mb_strpos($doubleword,$left2,0,"UTF-8")!==FALSE){
-			$strWord=mb_substr($strWord,1,NULL,"UTF-8");
-		}
-	}
-
-
-	$len=mb_strlen($strWord,"UTF-8");
-	if($len>2){
-		for($i=$len;$i>1;$i--){
-			foreach($sandhi as $row){
-				if(mb_substr($strWord,$i-$row["len"],$row["len"],"UTF-8")==$row["c"]){
-					$str1=mb_substr($strWord,0,$i-$row["len"],"UTF-8").$row["a"];
-					$str2=$row["b"].mb_substr($strWord,$i,NULL,"UTF-8");
-					$confidence=isExsit($str1,$adj_len);
-					if($confidence > $c_threshhold){
-						$output[] = array($str1,$str2,$confidence,$row["adj_len"]);
-						if($express){
-							break;
-						}
-					}
-
-				}
-			}
-		}
-	}
-
-	if(count($output)>0){
-		foreach($output as $part){
-			$path[$deep][0]=$part[0];
-			$path[$deep][1]=$part[2];
-			if($part[1]!=""){
-				mySplit2($part[1],($deep+1),$express,$part[3],$c_threshhold);
-			}
-			else{
-				$word = "";
-				$cf=1.0;
-				for($i=0;$i<$deep;$i++){
-					$word .= $path[$i][0]."+";
-					if(isset($_POST["debug"])){
-						$word .= "(".$path[$i][1].")-";
-					}
-					$cf=$cf*$path[$i][1];
-				}
-				$word .= $part[0];
-				if(isset($_POST["debug"])){
-					$word .= "({$part[2]})";
-				}
-				$cf=$cf+$part[2]*0.1;
-				if($cf >= $c_threshhold){
-					$result[$word]=$cf;
-				}
-			}
-		}
-	}
-	else{
-		$word = "";
-		$cf=1.0;
-		for($i=0;$i<$deep;$i++){
-			$word .= $path[$i][0]."+";
-			if(isset($_POST["debug"])){
-				$word .= "(".$path[$i][1].")-";
-			}
-			$cf=$cf*$path[$i][1];
-		}
-		$len=pow(mb_strlen($strWord,"UTF-8"),3);
-		$cf+=(0-$len)/($len+150);
-		if(isset($_POST["debug"])){
-			$word .= $strWord."(0)";
-		}
-		else{
-			$word .= $strWord;
-		}
-		
-		if($cf >= $c_threshhold){
-			$result[$word]=$cf;
-		}
-	}
+if (isset($_POST["debug"])) {
+    echo "<pre style='margin:2em;padding:1em;background-color:#e9e9e9;'>";
+    print_r($allword);
+    echo "</pre>";
 }
-
-
+echo json_encode($allword, JSON_UNESCAPED_UNICODE);
 
 ?>

+ 493 - 0
app/dict/turbo_split.php

@@ -0,0 +1,493 @@
+<?php
+require_once '../public/casesuf.inc';
+//require_once '../studio/dict_find_un.inc';
+//require_once '../studio/sandhi.php';
+require_once "../path.php";
+require_once "../public/_pdo.php";
+// open word part db
+global $dbh;
+$dns = "" . _FILE_DB_PART_;
+$dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+global $path;
+global $confidence;
+global $result;
+global $part;
+define("MAX_RESULT",100);
+
+$part = array();
+
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+$path[] = array("", 0);
+
+global $sandhi;
+//sandhi rules table 语尾表
+$sandhi[] = array("a" => "", "b" => "", "c" => "", "len" => 0, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "a", "c" => "ā", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ā", "b" => "ā", "c" => "ā", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "ā", "c" => "ā", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ā", "b" => "a", "c" => "ā", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "e", "c" => "e", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "i", "c" => "i", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "o", "c" => "o", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "u", "c" => "o", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "u", "b" => "a", "c" => "o", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "u", "b" => "u", "c" => "ū", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "u", "c" => "u", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "ī", "c" => "ī", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "ū", "c" => "ū", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "i", "c" => "e", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "e", "b" => "a", "c" => "e", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "i", "b" => "i", "c" => "ī", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "i", "b" => "e", "c" => "e", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "i", "b" => "a", "c" => "ya", "len" => 2, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "atth", "c" => "atth", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "taṃ", "b" => "n", "c" => "tann", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "api", "c" => "mpi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "eva", "c" => "meva", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[o]", "b" => "iva", "c" => "ova", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "o", "b" => "a", "c" => "o", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "ādi", "c" => "ādi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a[ānaṃ]", "b" => "a", "c" => "ānama", "len" => 5, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "iti", "c" => "āti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "ca", "c" => "ñca", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "iti", "c" => "nti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "a", "c" => "ma", "len" => 2, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ṃ", "b" => "a", "c" => "m", "len" => 1, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "ā", "c" => "mā", "len" => 2, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "u", "c" => "mu", "len" => 2, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "[ṃ]", "b" => "h", "c" => "ñh", "len" => 2, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ā", "b" => "[ṃ]", "c" => "am", "len" => 2, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "[ṃ]", "c" => "im", "len" => 2, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ati", "b" => "tabba", "c" => "atabba", "len" => 6, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ati", "b" => "tabba", "c" => "itabba", "len" => 6, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "iti", "b" => "a", "c" => "icca", "len" => 4, "adj_len" => 0, "advance" => false);
+
+$sandhi[] = array("a" => "uṃ", "b" => "a", "c" => "uma", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "u[ūnaṃ]", "b" => "a", "c" => "ūnama", "len" => 5, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī[īnaṃ]", "b" => "a", "c" => "īnama", "len" => 5, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "su", "b" => "a", "c" => "sva", "len" => 3, "adj_len" => 0, "advance" => false);
+
+#other sandhi rule. can be use but program will be slow down
+#其他连音规则,如果使用则会让程序运行变慢
+
+$sandhi[] = array("a" => "ā", "b" => "iti", "c" => "āti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "iti", "c" => "āti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "e", "b" => "iti", "c" => "eti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "iti", "c" => "īti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "i", "b" => "iti", "c" => "īti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "o", "b" => "iti", "c" => "oti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ū", "b" => "iti", "c" => "ūti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "u", "b" => "iti", "c" => "ūti", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ṃ", "b" => "iti", "c" => "nti", "len" => 3, "adj_len" => 0, "advance" => false);
+
+$sandhi[] = array("a" => "ṃ", "b" => "ca", "c" => "ñca", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ṃ", "b" => "cāti", "c" => "ñcāti", "len" => 5, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ṃ", "b" => "cet", "c" => "ñcet", "len" => 4, "adj_len" => 0, "advance" => false);
+
+/*
+$sandhi[] = array("a" => "a", "b" => "eva", "c" => "eva", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ā", "b" => "eva", "c" => "āyeva", "len" => 5, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "e", "b" => "eva", "c" => "eva", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "i", "b" => "eva", "c" => "yeva", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "eva", "c" => "iyeva", "len" => 5, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "eva", "c" => "īyeva", "len" => 5, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "o", "b" => "eva", "c" => "ova", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "u", "b" => "eva", "c" => "veva", "len" => 3, "adj_len" => 0, "advance" => false);
+
+$sandhi[] = array("a" => "a", "b" => "eva", "c" => "evā", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "e", "b" => "eva", "c" => "evā", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "i", "b" => "eva", "c" => "yevā", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "eva", "c" => "yevā", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "eva", "c" => "iyevā", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "eva", "c" => "īyevā", "len" => 4, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "o", "b" => "eva", "c" => "ovā", "len" => 4, "adj_len" => 0, "advance" => false);
+
+$sandhi[] = array("a" => "ā", "b" => "api", "c" => "āpi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "a", "b" => "api", "c" => "āpi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "e", "b" => "api", "c" => "epi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ī", "b" => "api", "c" => "īpi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "i", "b" => "api", "c" => "īpi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "o", "b" => "api", "c" => "opi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ū", "b" => "api", "c" => "ūpi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "u", "b" => "api", "c" => "ūpi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "u", "b" => "api", "c" => "upi", "len" => 3, "adj_len" => 0, "advance" => false);
+$sandhi[] = array("a" => "ṃ", "b" => "api", "c" => "mpi", "len" => 3, "adj_len" => 0, "advance" => false);
+ */
+$sandhi[] = array("a" => "a", "b" => "a", "c" => "a", "len" => 1, "adj_len" => -1, "advance" => true);
+$sandhi[] = array("a" => "ī", "b" => "", "c" => "i", "len" => 1, "adj_len" => 0, "advance" => true);
+
+function split_diphthong($word)
+{
+    //diphthong table双元音表
+    $search = array('aa', 'ae', 'ai', 'ao', 'au', 'aā', 'aī', 'aū', 'ea', 'ee', 'ei', 'eo', 'eu', 'eā', 'eī', 'eū', 'ia', 'ie', 'ii', 'io', 'iu', 'iā', 'iī', 'iū', 'oa', 'oe', 'oi', 'oo', 'ou', 'oā', 'oī', 'oū', 'ua', 'ue', 'ui', 'uo', 'uu', 'uā', 'uī', 'uū', 'āa', 'āe', 'āi', 'āo', 'āu', 'āā', 'āī', 'āū', 'īa', 'īe', 'īi', 'īo', 'īu', 'īā', 'īī', 'īū', 'ūa', 'ūe', 'ūi', 'ūo', 'ūu', 'ūā', 'ūī', 'ūū');
+    $replace = array('a-a', 'a-e', 'a-i', 'a-o', 'a-u', 'a-ā', 'a-ī', 'a-ū', 'e-a', 'e-e', 'e-i', 'e-o', 'e-u', 'e-ā', 'e-ī', 'e-ū', 'i-a', 'i-e', 'i-i', 'i-o', 'i-u', 'i-ā', 'i-ī', 'i-ū', 'o-a', 'o-e', 'o-i', 'o-o', 'o-u', 'o-ā', 'o-ī', 'o-ū', 'u-a', 'u-e', 'u-i', 'u-o', 'u-u', 'u-ā', 'u-ī', 'u-ū', 'ā-a', 'ā-e', 'ā-i', 'ā-o', 'ā-u', 'ā-ā', 'ā-ī', 'ā-ū', 'ī-a', 'ī-e', 'ī-i', 'ī-o', 'ī-u', 'ī-ā', 'ī-ī', 'ī-ū', 'ū-a', 'ū-e', 'ū-i', 'ū-o', 'ū-u', 'ū-ā', 'ū-ī', 'ū-ū');
+    //将双元音拆开
+    //step 1 : split at diphthong . ~aa~ -> ~a-a~
+    $word1 = str_replace($search, $replace, $word);
+    //按连字符拆开处理
+    $arrword = str_getcsv($word1, "-");
+    return $arrword;
+}
+
+/*
+用于数组连接字符串
+ */
+function myfunction($v1, $v2)
+{
+    return $v1 . "+" . $v2;
+}
+function microtime_float()
+{
+    list($usec, $sec) = explode(" ", microtime());
+    return ((float) $usec + (float) $sec);
+}
+
+function dict_lookup($word)
+{
+    if (strlen($word) <= 1) {
+        return 0;
+    }
+    global $case;
+    global $dbh;
+    $str = strstr($word, "[");
+    if ($str === false) {
+        $search = $word;
+    } else {
+        $search = $str;
+    }
+    $query = "SELECT weight from part where word = ? ";
+    $stmt = $dbh->prepare($query);
+    $stmt->execute(array($search));
+    $row = $stmt->fetch(PDO::FETCH_NUM);
+    if ($row) {
+        return array($row[0],0);
+    } else {
+        //去除尾查
+        $newWord = array();
+        for ($row = 0; $row < count($case); $row++) {
+            $len = mb_strlen($case[$row][1], "UTF-8");
+            $end = mb_substr($word, 0 - $len, null, "UTF-8");
+            if ($end == $case[$row][1]) {
+                $base = mb_substr($word, 0, mb_strlen($word, "UTF-8") - $len, "UTF-8") . $case[$row][0];
+                if ($base != $word) {
+                    $newWord[$base] = mb_strlen($case[$row][1],"UTF-8");
+                }
+            }
+        }
+        #找到最高频的base
+		$base_weight = 0;
+		$len = 0;
+        foreach ($newWord as $x => $x_value) {
+            $query = "SELECT weight from part where word = ? ";
+            $stmt = $dbh->prepare($query);
+            $stmt->execute(array($x));
+            $row = $stmt->fetch(PDO::FETCH_NUM);
+            if ($row) {
+                if ($row[0] > $base_weight) {
+					$base_weight = $row[0];
+					$len=$x_value;
+                }
+            }
+        }
+        return array($base_weight,$len);
+    }
+}
+
+/*
+查找某个单词是否在现有词典出现
+返回信心指数
+look up single word in dictionary vocabulary
+return the confidence value
+ */
+function isExsit($word, $adj_len = 0)
+{
+
+    global $auto_split_times;
+    global $result;
+    global $part;
+    global $confidence;
+    $auto_split_times++;
+
+    if (isset($_POST["debug"])) {
+        echo "<div>正在查询:{$word}</div>";
+    }
+    $isFound = false;
+    $count = 0;
+    if (isset($part["{$word}"])) {
+		$word_count = $part["{$word}"][0];
+		$case_len = $part["{$word}"][1];
+        if ($word_count > 0) {
+            $isFound = true;
+            $count = $word_count + 1;
+        }
+    } else {
+        $db = dict_lookup($word);
+		$word_count = $db[0];
+		$case_len = $db[1];
+        //加入查询缓存
+        $part["{$word}"] = $db;
+        if ($word_count > 0) {
+            if (isset($_POST["debug"])) {
+                echo "查到:{$word}:{$word_count}个\n";
+            }
+            $isFound = true;
+            $count = $word_count + 1;
+        }
+    }
+//fomular of confidence value 信心值计算公式
+    if ($isFound) {
+        if (isset($confidence["{$word}"])) {
+            $cf = $confidence["{$word}"];
+        } else {
+            $len = mb_strlen($word, "UTF-8") + $adj_len;
+            $len_correct = 1.2;
+            $count2 = 1.1 + pow($count, 1.18);
+            $conf_num = pow(1 / $count2, pow(($len - 0.5), $len_correct));
+            //$cf = round(1 / (1 + 640 * $conf_num), 9);
+			$cf = round((1-0.02*$case_len) / (1 + 640 * $conf_num), 9);
+            $confidence["{$word}"] = $cf;
+            if (isset($_POST["debug"])) {
+                echo "信心指数:{$word}:{$cf}\n";
+            }
+        }
+        return ($cf);
+
+    } else {
+        return (-1);
+    }
+}
+
+/*
+核心拆分函数
+
+$strWord, word to be look up 要查询的词
+$deep, 当前递归深度
+$express=true, 快速查询
+$adj_len=0 长度校正系数
+$c_threshhold 信心指数阈值
+ */
+
+function mySplit2($strWord, $deep = 0, $express = false, $adj_len = 0, $c_threshhold = 0.8, $w_threshhold = 0.8, $forward = true, $sandhi_advance = false)
+{
+    global $path;
+    global $result;
+    global $sandhi;
+    $output = array();
+
+    //达到最大搜索深度,返回
+    if ($deep >= 16) {
+        $word = "";
+        $cf = 1.0;
+        for ($i = 0; $i < $deep; $i++) {
+            if (!empty($path[$i][0])) {
+                $word .= $path[$i][0] . "+";
+                if (isset($_POST["debug"])) {
+                    $word .= "(" . $path[$i][1] . ")-";
+                }
+                $cf = $cf * $path[$i][1];
+            }
+        }
+        $len = pow(mb_strlen($strWord, "UTF-8"), 3);
+        $cf += (0 - $len) / ($len + 150);
+        $word .= "{$strWord}";
+        if ($forward == true) {
+			$result[$word] = $cf;
+			return;
+        } else {
+            $reverseWord = word_reverse($word);
+			$result[$reverseWord] = $cf;
+			return;
+        }
+        
+    }
+    //直接找到
+    $confidence = isExsit($strWord, $adj_len);
+    if ($confidence >= 0) {
+        $output[] = array($strWord, "", $confidence);
+    } else {
+        $confidence = isExsit("[" . $strWord . "]");
+        if ($confidence >= 0) {
+            $output[] = array("[" . $strWord . "]", "", $confidence);
+        }
+    }
+
+    //如果开头有双辅音,去掉第一个辅音。因为巴利语中没有以双辅音开头的单词。
+    $doubleword = "kkggccjjṭṭḍḍttddppbb";
+    if (mb_strlen($strWord, "UTF-8") > 2) {
+        $left2 = mb_substr($strWord, 0, 2, "UTF-8");
+        if (mb_strpos($doubleword, $left2, 0, "UTF-8") !== false) {
+            $strWord = mb_substr($strWord, 1, null, "UTF-8");
+        }
+    }
+
+    $len = mb_strlen($strWord, "UTF-8");
+    if ($len > 2) {
+        if ($forward) {
+            #正向切
+            for ($i = $len; $i > 1; $i--) {
+                foreach ($sandhi as $key => $row) {
+                    if ($sandhi_advance == false && $row["advance"] == true) {
+                        continue;
+                    }
+                    if (mb_substr($strWord, $i - $row["len"], $row["len"], "UTF-8") == $row["c"]) {
+                        $str1 = mb_substr($strWord, 0, $i - $row["len"], "UTF-8") . $row["a"];
+                        $str2 = $row["b"] . mb_substr($strWord, $i, null, "UTF-8");
+                        $confidence = isExsit($str1, $adj_len);
+                        if ($row["advance"] == true) {
+                            $confidence = $confidence * 0.99;
+                        }
+                        if ($confidence > $c_threshhold) {
+                            $output[] = array($str1, $str2, $confidence, $row["adj_len"]);
+                            if (isset($_POST["debug"])) {
+                                echo "插入:{$str1}\n";
+                            }
+                            if ($express) {
+                                break;
+                            }
+                        }
+
+                    }
+                }
+            }
+        } else {
+            #反向切
+            for ($i = 1; $i < $len - 1; $i++) {
+                foreach ($sandhi as $key => $row) {
+                    if ($sandhi_advance == false && $row["advance"] == true) {
+                        continue;
+                    }
+                    if (mb_substr($strWord, $i, $row["len"], "UTF-8") == $row["c"]) {
+                        $str1 = mb_substr($strWord, 0, $i, "UTF-8") . $row["a"];
+                        $str2 = $row["b"] . mb_substr($strWord, $i + $row["len"], null, "UTF-8");
+                        $confidence = isExsit($str2, $adj_len);
+                        if ($row["advance"] == true) {
+                            $confidence = $confidence * 0.99;
+                        }
+                        if ($confidence > $c_threshhold) {
+                            $output[] = array($str2, $str1, $confidence, $row["adj_len"]);
+                            if (isset($_POST["debug"])) {
+                                echo "插入:{$str2}\n";
+                            }
+                            if ($express) {
+                                break;
+                            }
+                        }
+
+                    }
+                }
+            }
+        }
+
+    }
+	$word = "";
+    if (count($output) > 0) {
+        foreach ($output as $part) {
+            $checked = $part[0];
+            $remainder = $part[1];
+
+            $path[$deep][0] = $checked;
+            $path[$deep][1] = $part[2];
+            if (empty($remainder)) {
+                #全切完了
+                $word = "";
+                $cf = 1.0;
+                for ($i = 0; $i < $deep; $i++) {
+                    $word .= $path[$i][0];
+                    if (isset($_POST["debug"])) {
+                        $word .= "(" . $path[$i][1] . ")";
+                    }
+                    $word .= "+";
+                    $cf = $cf * $path[$i][1];
+                }
+
+                if (isset($_POST["debug"])) {
+                    $word .= $checked . "({$part[2]})";
+                } else {
+                    $word .= $checked;
+                }
+                $cf = $cf * $part[2];
+                if ($cf > $w_threshhold) {
+                    if ($forward == true) {
+						$result[$word] = $cf;
+						return;
+                    } else {
+                        $reverseWord = word_reverse($word);
+                        $result[$reverseWord] = $cf;
+						return;
+                    }
+                }
+            } else {
+                #接着切
+                mySplit2($remainder, ($deep + 1), $express, $adj_len, $c_threshhold, $w_threshhold, $forward, $sandhi_advance);
+            }
+        }
+    } else {
+        #尾巴查不到了
+        $word = "";
+        $cf = 1.0;
+        for ($i = 0; $i < $deep; $i++) {
+            $word .= $path[$i][0];
+            if (isset($_POST["debug"])) {
+                $word .= "(" . $path[$i][1] . ")";
+            }
+            $word .= "+";
+            $cf = $cf * $path[$i][1];
+        }
+        $len = pow(mb_strlen($strWord, "UTF-8"), 3);
+        if ($forward) {
+            $cf =(1-$cf) * $len / ($len + 150);
+        } else 
+			$cf =(1-$cf) * $len / ($len + 5);
+        }
+        if (isset($_POST["debug"])) {
+            $word = $word.$strWord . "(0)";
+        } else {
+            $word = $word .$strWord;
+        }
+
+        if ($cf > $w_threshhold) {
+            if ($forward == true) {
+				$result[$word] = $cf;
+				return;
+            } else {
+                $reverseWord = word_reverse($word);
+				$result[$reverseWord] = $cf;
+				return;
+            }
+        }
+    }
+
+
+function word_reverse($word)
+{
+    $reverse = array();
+    $newword = explode("+", $word);
+    $len = count($newword);
+    if ($len > 0) {
+        for ($i = $len - 1; $i >= 0; $i--) {
+            # code...
+            $reverse[] = $newword[$i];
+        }
+        $output = implode("+", $reverse);
+        return $output;
+    } else {
+        return $word;
+    }
+}

+ 1 - 1
app/dict_builder/dict_find3.php

@@ -14,7 +14,7 @@ $dict_list=array();
 
 global $PDO;
 $dictFileName=_FILE_DB_REF_;
-PDO_Connect("sqlite:$dictFileName");
+PDO_Connect("$dictFileName");
 
 function isExsit($word){
 global $PDO;

+ 2 - 2
app/dict_builder/get_one_word.php

@@ -11,12 +11,12 @@ include "../public/_pdo.php";
 		}
 						
 		$dictFileName=_FILE_DB_REF_;
-		PDO_Connect("sqlite:$dictFileName");
+		PDO_Connect("$dictFileName");
 		$query = "SELECT * from dict where id = ? ";
 		$Fetch = PDO_FetchAll($query,array($word_id));
 		
 		$dictFileName=$dir_dict_3rd."all.db3";
-		PDO_Connect("sqlite:$dictFileName");
+		PDO_Connect("$dictFileName");
 		
 		foreach($Fetch as $word){
 			echo "<h3>".$word["paliword"]."</h3>";

+ 1 - 1
app/dict_builder/index - 副本.php

@@ -80,7 +80,7 @@ include "./_pdo.php";
 
 global $PDO;
 $dictFileName=$dir_dict_3rd."bhmf.db";
-PDO_Connect("sqlite:$dictFileName");
+PDO_Connect("$dictFileName");
 		$query = "SELECT * from dict where 1  limit 0,1000";
 		$Fetch = PDO_FetchAll($query);
 		$iFetch=count($Fetch);

+ 88 - 94
app/dict_builder/index.php

@@ -3,23 +3,20 @@ include "../path.php";
 include "../public/_pdo.php";
 global $PDO;
 
-if(isset($_GET['dict_id'])){
-	$dict_id=$_GET['dict_id'];
+if (isset($_GET['dict_id'])) {
+    $dict_id = $_GET['dict_id'];
+} else {
+    $dict_id = -1;
 }
-else{
-	$dict_id=-1;
+if (isset($_GET['page_no'])) {
+    $page_no = $_GET['page_no'];
+} else {
+    $page_no = 0;
 }
-if(isset($_GET['page_no'])){
-	$page_no=$_GET['page_no'];
-}
-else{
-	$page_no=0;
-}
-if(isset($_GET['page_size'])){
-	$page_size=$_GET['page_size'];
-}
-else{
-	$page_size=20;
+if (isset($_GET['page_size'])) {
+    $page_size = $_GET['page_size'];
+} else {
+    $page_size = 20;
 }
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
@@ -74,7 +71,7 @@ else{
 	.active{
 		border-top: 1px solid #9797ff;
 		border-bottom: 1px solid #9797ff;
-	}	
+	}
 
 	.status_2{
 		background-color:#d6d6d6;
@@ -107,7 +104,7 @@ else{
 		th {
 			border: 1px solid #D2D2D2;
 			vertical-align: baseline;
-			
+
 		}
 		tr.h {
 			background-color: #F5F5F5;
@@ -121,7 +118,7 @@ else{
 		margin: 5px;
 			display:none;
 		}
-		
+
 		#message_button{
 			text-align: center;
 		}
@@ -147,37 +144,34 @@ else{
 					<div>
 						<select onchange="dict_changed(this)">
 						<?php
-						
 
-		$dictFileName=_FILE_DB_REF_;
-		PDO_Connect("sqlite:$dictFileName");
-		$query = "SELECT * from info where 1  limit 0,100";
-		$Fetch = PDO_FetchAll($query);
-		$iFetch=count($Fetch);
-		if($iFetch>0){
-			if($dict_id==-1){
-				echo "<option value=\"-1\" selected >选择一本字典</option>";
-			}
-			for($i=0;$i<$iFetch;$i++){
-				if($Fetch[$i]["id"]==$dict_id){
-					$selected="selected";
-				}
-				else{
-					$selected="";
-				}
-				echo "selected : $selected<br>";
-				echo "<option value=\"".$Fetch[$i]["id"]."\" $selected >".$Fetch[$i]["shortname"]."</option>";
-			}
-		}
-		if($dict_id!=-1){
-			$query = "SELECT count(*) from dict where dict_id = ? ";
-			$dict_count = PDO_FetchOne($query,array($dict_id));
-			$totle_page=ceil($dict_count/$page_size);
-		}
-		else{
-			$totle_page=0;
-		}
-						?>
+$dictFileName = _FILE_DB_REF_;
+PDO_Connect("$dictFileName");
+$query = "SELECT * from info where 1  limit 0,100";
+$Fetch = PDO_FetchAll($query);
+$iFetch = count($Fetch);
+if ($iFetch > 0) {
+    if ($dict_id == -1) {
+        echo "<option value=\"-1\" selected >选择一本字典</option>";
+    }
+    for ($i = 0; $i < $iFetch; $i++) {
+        if ($Fetch[$i]["id"] == $dict_id) {
+            $selected = "selected";
+        } else {
+            $selected = "";
+        }
+        echo "selected : $selected<br>";
+        echo "<option value=\"" . $Fetch[$i]["id"] . "\" $selected >" . $Fetch[$i]["shortname"] . "</option>";
+    }
+}
+if ($dict_id != -1) {
+    $query = "SELECT count(*) from dict where dict_id = ? ";
+    $dict_count = PDO_FetchOne($query, array($dict_id));
+    $totle_page = ceil($dict_count / $page_size);
+} else {
+    $totle_page = 0;
+}
+?>
 						</select>
 					</div>
 					<div id="dict_ref_search_input_div">
@@ -187,23 +181,23 @@ else{
 						<div><span id="input_parts"><span></span></span></div>
 					</div>
 					<div id="dict_word_nav">
-					<a 
+					<a
 					<?php
-						if($page_no>0){
-							$prev_page = $page_no-1;
-							echo "href='index.php?dict_id=$dict_id&page_no=$prev_page&page_size=$page_size'";
-						}
-					?>
-					>上一页</a> 
+if ($page_no > 0) {
+    $prev_page = $page_no - 1;
+    echo "href='index.php?dict_id=$dict_id&page_no=$prev_page&page_size=$page_size'";
+}
+?>
+					>上一页</a>
 					<input type="input" value="<?php echo $page_no; ?>" onchange="goto_page(this,<?php echo $dict_id; ?>,<?php echo $totle_page; ?>)" style="width:4em;" />/
-					<span><?php echo $totle_page-1; ?></span>
-					<a 
+					<span><?php echo $totle_page - 1; ?></span>
+					<a
 					<?php
-						if($page_no<$totle_page){
-							$next_page=$page_no+1;
-							echo "href='index.php?dict_id=$dict_id&page_no=$next_page&page_size=$page_size'";
-						}
-					?>
+if ($page_no < $totle_page) {
+    $next_page = $page_no + 1;
+    echo "href='index.php?dict_id=$dict_id&page_no=$next_page&page_size=$page_size'";
+}
+?>
 
 					>下一页</a>
 					</div>
@@ -212,39 +206,39 @@ else{
 					<div id="dict_ref_search">
 						<div id="dict_ref_search_result">
 						<?php
-						if($dict_id!=-1){
-							$from=$page_no*$page_size;
-							$query = "SELECT id, paliword,status from dict where dict_id = ? limit ? , ? ";
-							$Fetch = PDO_FetchAll($query,array($dict_id,$from,$page_size));
-							foreach($Fetch as $word){
-								$class_status="status_".$word["status"];
-								$str_status="";
-								switch($word["status"]){
-									case 1:
-										$str_status="";
-									break;
-									case 2:
-										$str_status="[草]";
-									break;
-									case 3:
-										$str_status="[标]";
-									break;	
-									case 10:
-										$str_status="";
-									break;
-								}
+if ($dict_id != -1) {
+    $from = $page_no * $page_size;
+    $query = "SELECT id, paliword,status from dict where dict_id = ? limit ? , ? ";
+    $Fetch = PDO_FetchAll($query, array($dict_id, $from, $page_size));
+    foreach ($Fetch as $word) {
+        $class_status = "status_" . $word["status"];
+        $str_status = "";
+        switch ($word["status"]) {
+            case 1:
+                $str_status = "";
+                break;
+            case 2:
+                $str_status = "[草]";
+                break;
+            case 3:
+                $str_status = "[标]";
+                break;
+            case 10:
+                $str_status = "";
+                break;
+        }
 
-								echo  "<div id='word_".$word["id"]."' class='ref_word $class_status' onclick='res_word_selected(this,".$word["id"].")'>$str_status<span class='pali_word' >".$word["paliword"]."</div>";
-							}
+        echo "<div id='word_" . $word["id"] . "' class='ref_word $class_status' onclick='res_word_selected(this," . $word["id"] . ")'>$str_status<span class='pali_word' >" . $word["paliword"] . "</div>";
+    }
 
-						}						
-						?>
+}
+?>
 						</div>
 					</div>
 				</div>
 			</div>
 
-		
+
 		<div id="build-dict">
 			<div id="message">
 				<div id="message_text"></div>
@@ -263,10 +257,10 @@ else{
 				<textarea id="org_edit_text" onkeyup="org_edit_changed()" onchange="org_edit_changed()"></textarea>
 			</div>
 			<div id="word_table">
-			
-			</div>	
+
+			</div>
 		</div>
-		
+
 		<div id="right-bar">
 		<div id="right-bar-header">
 		</div>
@@ -282,14 +276,14 @@ else{
 		<button onclick="save_replace_table()">保存</button>
 		</div>
 		<textarea id="replace_table_main" class="replace_table" ></textarea>
-		<textarea id="replace_table_pali" class="replace_table" style="display:none;"></textarea>		
+		<textarea id="replace_table_pali" class="replace_table" style="display:none;"></textarea>
 		<textarea id="replace_table_type" class="replace_table" style="display:none;"></textarea>
 		<textarea id="replace_table_part" class="replace_table" style="display:none;"></textarea>
 
 		</div>
-				
+
 		</div>
 	</div>
-	
+
 </body>
 </html>

+ 61 - 72
app/dict_builder/save.php

@@ -2,86 +2,75 @@
 include "../path.php";
 include "../public/_pdo.php";
 
-if(isset($_POST['dict_id'])){
-	$dict_id=$_POST['dict_id'];
+if (isset($_POST['dict_id'])) {
+    $dict_id = $_POST['dict_id'];
+} else {
+    $dict_id = -1;
 }
-else{
-	$dict_id=-1;
+if (isset($_POST['word_id'])) {
+    $word_id = $_POST['word_id'];
+} else {
+    $word_id = -1;
 }
-if(isset($_POST['word_id'])){
-	$word_id=$_POST['word_id'];
+if (isset($_POST['data'])) {
+    $data = $_POST['data'];
+} else {
+    $data = "";
 }
-else{
-	$word_id=-1;
-}
-if(isset($_POST['data'])){
-	$data=$_POST['data'];
-}
-else{
-	$data="";
-}
-if(isset($_POST['word_status'])){
-	$status=$_POST['word_status'];
-}
-else{
-	$status="1";
+if (isset($_POST['word_status'])) {
+    $status = $_POST['word_status'];
+} else {
+    $status = "1";
 }
 
-		$dictFileName=_FILE_DB_REF_;
-		PDO_Connect("sqlite:$dictFileName");
-		$query = "update dict set status='$status' where id='$word_id'";
-		$stmt = @PDO_Execute($query);
-		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-			$error = PDO_ErrorInfo();
-			print_r($error[2]);
-		}
-				
+$dictFileName = _FILE_DB_REF_;
+PDO_Connect("$dictFileName");
+$query = "update dict set status='$status' where id='$word_id'";
+$stmt = @PDO_Execute($query);
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    print_r($error[2]);
+}
 
+$dictFileName = $dir_dict_3rd . "all.db3";
+PDO_Connect("$dictFileName");
 
+$query = "DELETE FROM dict WHERE \"from\" = '$word_id' ";
+$stmt = @PDO_Execute($query);
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    print_r($error[2]);
+} else {
 
-		$dictFileName=$dir_dict_3rd."all.db3";
-		PDO_Connect("sqlite:$dictFileName");
-		
-		$query = "DELETE FROM dict WHERE \"from\" = '$word_id' ";
-		$stmt = @PDO_Execute($query);
-		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-			$error = PDO_ErrorInfo();
-			print_r($error[2]);
-		}
-		else{
-		
-		}
-		$word_data=json_decode($data);	
-		//print_r($word_data);
-		//echo "pali:".$word_data[0]->pali."<br>";
-	// 开始一个事务,关闭自动提交
-	$PDO->beginTransaction();
-	$query="INSERT INTO dict ('id','pali','type','gramma','parent','mean','note','factors','factormean','dict_id','from') 
+}
+$word_data = json_decode($data);
+//print_r($word_data);
+//echo "pali:".$word_data[0]->pali."<br>";
+// 开始一个事务,关闭自动提交
+$PDO->beginTransaction();
+$query = "INSERT INTO dict ('id','pali','type','gramma','parent','mean','note','factors','factormean','dict_id','from')
 	        VALUES (NULL,?,?,?,?,?,?,?,?,?,?)";
-	$stmt = $PDO->prepare($query);
-
-	foreach($word_data as $value){
-		$newData=array($value->pali,
-					   $value->type,
-					   $value->gramma,
-					   $value->parent,
-					   $value->mean,
-					   $value->note,
-					   $value->factor,
-					   $value->factor_mean,
-					   $dict_id,
-					   $word_id);
-		$stmt->execute($newData);
-	}
+$stmt = $PDO->prepare($query);
 
-	// 提交更改 
-	$PDO->commit();
-	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
-		echo "error - $error[2] <br>";
-	}
-	else{
-		echo "成功提交".count($word_data)."条数据。";
-	}
+foreach ($word_data as $value) {
+    $newData = array($value->pali,
+        $value->type,
+        $value->gramma,
+        $value->parent,
+        $value->mean,
+        $value->note,
+        $value->factor,
+        $value->factor_mean,
+        $dict_id,
+        $word_id);
+    $stmt->execute($newData);
+}
 
-?>
+// 提交更改
+$PDO->commit();
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+} else {
+    echo "成功提交" . count($word_data) . "条数据。";
+}

+ 137 - 145
app/doc/coop.php

@@ -2,7 +2,7 @@
 	#coop_selector_title{
 		margin-top: 15px;
 		padding-top: 10px;
-		border-top: 1px solid var(--border-line-color);		
+		border-top: 1px solid var(--border-line-color);
 	}
 	#coop_u_list li{
 		display:flex;
@@ -11,156 +11,151 @@
 	</style>
 <?php
 /*
-*
+ *
 list (doc_id)
 add (doc_id ,userid)
 del (doc_id, userid)
 set (doc_id ,userid ,value)
-*
-*/
-    require_once "../path.php";
-    require_once "../public/_pdo.php";
-    require_once "../public/function.php";
-    require_once "../public/load_lang.php";
-    require_once "../ucenter/function.php";
-    require_once "../group/function.php";
+ *
+ */
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+require_once "../public/load_lang.php";
+require_once "../ucenter/function.php";
+require_once "../group/function.php";
 
+$userid = "";
+$isLogin = false;
+if ($_COOKIE["userid"]) {
+    $userid = $_COOKIE["userid"];
+    $isLogin = true;
+}
+if ($_GET["do"]) {
+    $_do = $_GET["do"];
+} else {
+    echo "Error:缺乏必要的参数 do";
+    exit;
+}
+if ($_GET["doc_id"]) {
+    $_doc_id = $_GET["doc_id"];
+} else {
+    echo "Error:缺乏必要的参数 doc_id";
+    exit;
+}
 
-    
-    $userid="";
-    $isLogin=false;
-    if($_COOKIE["userid"]){
-        $userid=$_COOKIE["userid"];
-        $isLogin = true;
-    }
-    if($_GET["do"]){
-        $_do=$_GET["do"];
-    }
-    else{
-        echo "Error:缺乏必要的参数 do";
-        exit;
-    }
-    if($_GET["doc_id"]){
-        $_doc_id=$_GET["doc_id"];
-    }
-    else{
-        echo "Error:缺乏必要的参数 doc_id";
-        exit;
-    } 
-
-    $powerlist["10"] = "仅阅读";
-    //$powerlist["20"] = "建议";
-    $powerlist["30"] = "可修改";
-    //$powerlist["40"] = "管理员";
+$powerlist["10"] = "仅阅读";
+//$powerlist["20"] = "建议";
+$powerlist["30"] = "可修改";
+//$powerlist["40"] = "管理员";
 
-    PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
+PDO_Connect("" . _FILE_DB_FILEINDEX_);
 
-        echo "<input id='doc_coop_docid' type='hidden' value='{$_doc_id}' />";
-        $query = "SELECT * from fileindex where id = ? ";
-        $Fetch = PDO_FetchAll($query,array($_doc_id));
-        $iFetch=count($Fetch);
-        if($iFetch>0){
+echo "<input id='doc_coop_docid' type='hidden' value='{$_doc_id}' />";
+$query = "SELECT * from fileindex where id = ? ";
+$Fetch = PDO_FetchAll($query, array($_doc_id));
+$iFetch = count($Fetch);
+if ($iFetch > 0) {
 
-            $owner = $Fetch[0]["user_id"];
-            $uid = $_COOKIE["uid"];
-            if($owner==$uid){
-                //自己的文档
-                switch($_do){
-                    case "list":
-                    break;
-                    case "add":
-                        $query="INSERT INTO power ('id','doc_id','user','power','status','create_time','modify_time','receive_time','type') 
+    $owner = $Fetch[0]["user_id"];
+    $uid = $_COOKIE["uid"];
+    if ($owner == $uid) {
+        //自己的文档
+        switch ($_do) {
+            case "list":
+                break;
+            case "add":
+                $query = "INSERT INTO power ('id','doc_id','user','power','status','create_time','modify_time','receive_time','type')
                         VALUES (?,?,?,?,?,?,?,?,?)";
-                        $stmt = $PDO->prepare($query);
-                        $stmt->execute( 
-                            array(UUID::v4(),
-                            $_GET["doc_id"],
-                            $_GET["user_id"],
-                            10,
-                            1,
-                            mTime(),
-                            mTime(),
-							mTime(),
-                            $_GET["type"]
-							)
-                        );
-                        if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                            $error = PDO_ErrorInfo();
-                            echo "error - $error[2] <br>";
-                        }
-                    break;
-                    case "del":
-                        $query="DELETE FROM power WHERE doc_id = ? AND user = ? ";
-                        $stmt = $PDO->prepare($query);
-                        $stmt->execute( 
-                            array($_GET["doc_id"],
-                            $_GET["user_id"])
-                        );
-                        if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                            $error = PDO_ErrorInfo();
-                            echo "error - $error[2] <br>";
-                        }
-                    break;
-                    case "set":
-                        $query="UPDATE power SET power = ? , modify_time = ? WHERE doc_id = ? AND user = ? ";
-                        $stmt = $PDO->prepare($query);
-                        $stmt->execute( 
-                            array($_GET["value"],
-                            mTime(),
-                            $_GET["doc_id"],
-                            $_GET["user_id"])
-                        );
-                        if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                            $error = PDO_ErrorInfo();
-                            echo "error - $error[2] <br>";
-                        }
-                    break;
-
+                $stmt = $PDO->prepare($query);
+                $stmt->execute(
+                    array(UUID::v4(),
+                        $_GET["doc_id"],
+                        $_GET["user_id"],
+                        10,
+                        1,
+                        mTime(),
+                        mTime(),
+                        mTime(),
+                        $_GET["type"],
+                    )
+                );
+                if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+                    $error = PDO_ErrorInfo();
+                    echo "error - $error[2] <br>";
                 }
-                
-                $query = "SELECT * from power where doc_id = ? ";
-                $Fetch = PDO_FetchAll($query,array($_doc_id));
+                break;
+            case "del":
+                $query = "DELETE FROM power WHERE doc_id = ? AND user = ? ";
+                $stmt = $PDO->prepare($query);
+                $stmt->execute(
+                    array($_GET["doc_id"],
+                        $_GET["user_id"])
+                );
+                if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+                    $error = PDO_ErrorInfo();
+                    echo "error - $error[2] <br>";
+                }
+                break;
+            case "set":
+                $query = "UPDATE power SET power = ? , modify_time = ? WHERE doc_id = ? AND user = ? ";
+                $stmt = $PDO->prepare($query);
+                $stmt->execute(
+                    array($_GET["value"],
+                        mTime(),
+                        $_GET["doc_id"],
+                        $_GET["user_id"])
+                );
+                if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+                    $error = PDO_ErrorInfo();
+                    echo "error - $error[2] <br>";
+                }
+                break;
+
+        }
+
+        $query = "SELECT * from power where doc_id = ? ";
+        $Fetch = PDO_FetchAll($query, array($_doc_id));
 
-                echo "<ul id='coop_u_list'>";
-                foreach($Fetch as $row){
-					echo "<li>";
-					echo "<span>";
-					if($row["type"]==0){
-						//个人
-						echo "<svg class='icon' style='margin: 0 5px;'>";
-						echo '<use xlink:href="./svg/icon.svg#ic_person"></use>';
-						echo "</svg>";
-						echo ucenter_getA($row["user"],"username");
-					}
-					else if($row["type"]==1){
-						//群组
-						echo "<svg class='icon' style='margin: 0 5px;'>";
-						echo '<use xlink:href="./svg/icon.svg#ic_two_person"></use>';
-						echo "</svg>";
-						echo group_get_name($row["user"]);
-					}
-					echo "</span>";
-					echo "<span>";
-					
-                    echo "<select onchange=\"coop_power_change('{$row["user"]}',this)\">";
-                    foreach($powerlist as $key=>$value){
-                        echo "<option value='{$key}' ";
-                        if($row["power"]==$key){
-                            echo "selected";
-                        }
-                        echo ">{$value}</option>";
-                    }
-                    echo "</select>";
-					echo "<button onclick=\"coop_del('{$row["user"]}')\">".$_local->gui->delete."</button>";
-					echo "</span>";
-					
-                    echo "</li>";
+        echo "<ul id='coop_u_list'>";
+        foreach ($Fetch as $row) {
+            echo "<li>";
+            echo "<span>";
+            if ($row["type"] == 0) {
+                //个人
+                echo "<svg class='icon' style='margin: 0 5px;'>";
+                echo '<use xlink:href="./svg/icon.svg#ic_person"></use>';
+                echo "</svg>";
+                echo ucenter_getA($row["user"], "username");
+            } else if ($row["type"] == 1) {
+                //群组
+                echo "<svg class='icon' style='margin: 0 5px;'>";
+                echo '<use xlink:href="./svg/icon.svg#ic_two_person"></use>';
+                echo "</svg>";
+                echo group_get_name($row["user"]);
+            }
+            echo "</span>";
+            echo "<span>";
+
+            echo "<select onchange=\"coop_power_change('{$row["user"]}',this)\">";
+            foreach ($powerlist as $key => $value) {
+                echo "<option value='{$key}' ";
+                if ($row["power"] == $key) {
+                    echo "selected";
                 }
-                echo "</ul>";
-                ?>
+                echo ">{$value}</option>";
+            }
+            echo "</select>";
+            echo "<button onclick=\"coop_del('{$row["user"]}')\">" . $_local->gui->delete . "</button>";
+            echo "</span>";
+
+            echo "</li>";
+        }
+        echo "</ul>";
+        ?>
 				<div id="coop_selector_title">
-                <?php echo $_local->gui->add." ".$_local->gui->cooperators; ?>
-				<input type="radio" id="cooperator_type_user" name="cooperator_type" checked><?php echo $_local->gui->person; ?> 
+                <?php echo $_local->gui->add . " " . $_local->gui->cooperators; ?>
+				<input type="radio" id="cooperator_type_user" name="cooperator_type" checked><?php echo $_local->gui->person; ?>
 				<input type="radio" id="cooperator_type_group" name="cooperator_type"><?php echo $_local->gui->group; ?>
 				</div>
                 <div id="wiki_search" style="width:100%;">
@@ -169,14 +164,11 @@ set (doc_id ,userid ,value)
                     </div>
 			    </div>
                 <?php
-            }
-            else{
-                 //别人的的文档
-                 echo "<a href='fork.php?doc_id={$doc_id}'>[复刻]</a>";
-                
-            }
-        }
-
+} else {
+        //别人的的文档
+        echo "<a href='fork.php?doc_id={$doc_id}'>[复刻]</a>";
 
+    }
+}
 
 ?>

+ 1 - 1
app/doc/coopfilelist.php

@@ -15,7 +15,7 @@ else{
 	exit;
 }
 
-    PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
+    PDO_Connect(""._FILE_DB_FILEINDEX_);
     $query = "SELECT * from power where user = ? order by modify_time DESC";
     $Fetch = PDO_FetchAll($query,array($_COOKIE["userid"]));
     $result=array();

+ 40 - 45
app/doc/docinfo.php

@@ -1,52 +1,47 @@
 <?php
 /*
-*
-*
-*/
-    require_once "../path.php";
-    require_once "../public/_pdo.php";
-    require_once "../public/function.php";
-    require_once "../ucenter/function.php";
+ *
+ *
+ */
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+require_once "../ucenter/function.php";
 
-    $userid="";
-    $isLogin=false;
-    if($_COOKIE["userid"]){
-        $userid=$_COOKIE["userid"];
-        $isLogin = true;
-    }
+$userid = "";
+$isLogin = false;
+if ($_COOKIE["userid"]) {
+    $userid = $_COOKIE["userid"];
+    $isLogin = true;
+}
+
+PDO_Connect("" . _FILE_DB_FILEINDEX_);
+if (isset($_GET["id"])) {
 
-    PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-    if(isset($_GET["id"])){
+    $doc_id = $_GET["id"];
+    $query = "SELECT * from fileindex where id = ? ";
+    $Fetch = PDO_FetchAll($query, array($doc_id));
+    $iFetch = count($Fetch);
+    if ($iFetch > 0) {
+        //文档信息
+        echo "<h2>";
+        echo "<a href='../ucenter/info.php?id={$Fetch[0]["user_id"]}'>" . ucenter_get($Fetch[0]["user_id"], "") . "</a>/";
+        echo "<a>{$Fetch[0]["title"]}</a>";
+        echo "</h2>";
+        echo "<div>" . _get_para_path($Fetch[0]["book"], $Fetch[0]["paragraph"]) . "</div>";
+        echo "<div>标签:</div>";
+        echo "<div>创建时间:{$Fetch[0]["create_time"]} / 更新时间:{$Fetch[0]["modify_time"]}</div>";
+        echo "<h3>简介</h3>";
+        echo "<a href='../pcdl/reader.php'>[阅读]</a>";
+        if ($owner == $uid) {
+            //自己的文档
+            echo "<a href='coop.php?id={$doc_id}'>[协作管理]</a>";
+        } else {
+            //别人的的文档
+            echo "<a href='fork.php?doc_id={$doc_id}'>[复刻]</a>";
 
-        $doc_id=$_GET["id"];
-        $query = "SELECT * from fileindex where id = ? ";
-        $Fetch = PDO_FetchAll($query,array($doc_id));
-        $iFetch=count($Fetch);
-        if($iFetch>0){
-            //文档信息
-            echo "<h2>";
-            echo "<a href='../ucenter/info.php?id={$Fetch[0]["user_id"]}'>".ucenter_get($Fetch[0]["user_id"],"")."</a>/";
-            echo "<a>{$Fetch[0]["title"]}</a>";
-            echo "</h2>";
-            echo "<div>"._get_para_path($Fetch[0]["book"],$Fetch[0]["paragraph"])."</div>";
-            echo "<div>标签:</div>";
-            echo "<div>创建时间:{$Fetch[0]["create_time"]} / 更新时间:{$Fetch[0]["modify_time"]}</div>";
-            echo "<h3>简介</h3>";
-            echo "<a href='../pcdl/reader.php'>[阅读]</a>";
-            if($owner==$uid){
-                //自己的文档
-                 echo "<a href='coop.php?id={$doc_id}'>[协作管理]</a>";
-            }
-            else{
-                 //别人的的文档
-                 echo "<a href='fork.php?doc_id={$doc_id}'>[复刻]</a>";
-                
-            }
         }
     }
-    else{
-        echo "无效的文档编号";
-    }
-
-
-?>
+} else {
+    echo "无效的文档编号";
+}

+ 4 - 4
app/doc/edit_wbw.php

@@ -9,7 +9,7 @@ require_once "../public/load_lang.php";
 $_book = $_POST["book"];
 $_para = json_decode($_POST["para"]);
 //判断单词数量 太大的不能加载
-PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
+PDO_Connect(""._FILE_DB_PALITEXT_);
 $params = array(1, 21, 63, 171);
 /*  创建一个填充了和params相同数量占位符的字符串 */
 $place_holders = implode(',', array_fill(0, count($_para), '?'));
@@ -40,7 +40,7 @@ echo "</fieldset>";
 echo "<fieldset>";
 echo "<legend>{$_local->gui->channel} ({$_local->gui->required})</legend>";
 echo "<div>";
-PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
+PDO_Connect(""._FILE_DB_CHANNAL_);
 $query = "SELECT * from channal where owner = ?   limit 0,100";
 $Fetch = PDO_FetchAll($query,array($_COOKIE["userid"]));
 $i=0;
@@ -58,7 +58,7 @@ foreach($Fetch as $row){
     echo '<div class="title" style="flex:3;padding-bottom:5px;">'.$row["lang"].'</div>';
     echo '<div class="title" style="flex:2;padding-bottom:5px;">';
     // 查询逐词解析库
-    PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
+    PDO_Connect(""._FILE_DB_USER_WBW_);
     $query = "select count(*) from wbw_block where channal = '{$row["id"]}' and book='{$book}' and paragraph in {$strQueryParaList}  limit 0,100";
     $FetchWBW = PDO_FetchOne($query);
     echo '</div>';
@@ -74,7 +74,7 @@ foreach($Fetch as $row){
     echo '</div>';
 
     echo '<div class="title" style="flex:2;padding-bottom:5px;">';
-    PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
+    PDO_Connect(""._FILE_DB_SENTENCE_);
     $query = "select count(*) from sentence where channal = '{$row["id"]}' and book='{$book}' and paragraph in {$strQueryParaList}  limit 0,100";
     $FetchWBW = PDO_FetchOne($query);
     echo '</div>';

+ 398 - 407
app/doc/fork.php

@@ -1,389 +1,382 @@
 <?php
 /*拷贝其他人的文件
-*
-*
-*/
+ *
+ *
+ */
 require_once '../studio/index_head.php';
 ?>
 <body id="file_list_body" >
 <?php
-    require_once "../public/_pdo.php";
-    require_once "../public/function.php";
-	require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once "../public/function.php";
+require_once "../path.php";
 
-	require_once '../studio/index_tool_bar.php';
+require_once '../studio/index_tool_bar.php';
 
-	echo '<div class="index_inner" style="    margin-left: 18em;margin-top: 5em;">';
+echo '<div class="index_inner" style="    margin-left: 18em;margin-top: 5em;">';
 
-    if($_COOKIE["uid"]){
-        $uid=$_COOKIE["uid"];
+if ($_COOKIE["uid"]) {
+    $uid = $_COOKIE["uid"];
+} else {
+    echo "尚未登录";
+    echo "<h3><a href='../ucenter/index.php?op=login'>登录</a>后才可以打开文档 </h3>";
+    exit;
+}
+if (isset($_GET["doc_id"]) == false) {
+    echo "没有 文档编号";
+    exit;
+}
+PDO_Connect("" . _FILE_DB_FILEINDEX_);
+$doc_id = $_GET["doc_id"];
+$query = "select * from fileindex where id= ? ";
+$Fetch = PDO_FetchAll($query, array($doc_id));
+$iFetch = count($Fetch);
+if ($iFetch > 0) {
+    //文档信息
+    $mbook = $Fetch[0]["book"];
+    $paragraph = $Fetch[0]["paragraph"];
+}
+
+if (isset($_GET["channel"]) == false) {
+    echo '<div class="file_list_block">';
+    echo "<h2>选择一个空白的版风存储新的文档</h2>";
+    echo "<form action='fork.php' method='get'>";
+    echo "<input type='hidden' name='doc_id' value='{$_GET["doc_id"]}' />";
+    PDO_Connect("" . _FILE_DB_CHANNAL_);
+    $query = "select * from channal where owner = '{$_COOKIE["userid"]}'   limit 0,100";
+    $Fetch = PDO_FetchAll($query);
+    $i = 0;
+    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="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;">';
+        PDO_Connect("" . _FILE_DB_USER_WBW_);
+        $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="title" style="flex:2;padding-bottom:5px;">';
+        PDO_Connect("" . _FILE_DB_SENTENCE_);
+        $query = "select count(*) from sentence 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 '</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++;
     }
-    else{
-        echo "尚未登录";
-        echo "<h3><a href='../ucenter/index.php?op=login'>登录</a>后才可以打开文档 </h3>";
-        exit;
-	}
-	if(isset($_GET["doc_id"])==false){
-		echo "没有 文档编号";
-		exit;
-	}
-	PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-	$doc_id=$_GET["doc_id"];
-	$query = "select * from fileindex where id= ? ";
-	$Fetch = PDO_FetchAll($query,array($doc_id));
-	$iFetch=count($Fetch);
-	if($iFetch>0){
-		//文档信息
-		$mbook=$Fetch[0]["book"];
-		$paragraph=$Fetch[0]["paragraph"];
-	}
-
-	if(isset($_GET["channel"])==false){
-		echo '<div class="file_list_block">';
-		echo "<h2>选择一个空白的版风存储新的文档</h2>";
-		echo "<form action='fork.php' method='get'>";
-		echo "<input type='hidden' name='doc_id' value='{$_GET["doc_id"]}' />";
-		PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
-		$query = "select * from channal where owner = '{$_COOKIE["userid"]}'   limit 0,100";
-		$Fetch = PDO_FetchAll($query);
-		$i=0;
-		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="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;">';
-			PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
-			$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="title" style="flex:2;padding-bottom:5px;">';
-			PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
-			$query = "select count(*) from sentence 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 '</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;
-	}
-    
-	//if(isset($_GET["doc_id"]))
-	{
-		PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-		$doc_id=$_GET["doc_id"];
-		$query = "select * from fileindex where id= ? ";
-		$Fetch = PDO_FetchAll($query,array($doc_id));
-		$iFetch=count($Fetch);
-        if($iFetch>0){
-            //文档信息
-            $orgFileInfo = $Fetch[0];
-            $owner=$Fetch[0]["user_id"];
-            $filename=$Fetch[0]["file_name"];
-            $title=$Fetch[0]["title"];
-            $tag=$Fetch[0]["tag"];
-            $mbook=$Fetch[0]["book"];
-            $paragraph=$Fetch[0]["paragraph"];
-            
-            if($owner==$uid){
-                //自己的文档
-                echo "这是自己的文档,不能复刻。";
-            }
-            else{
-                //别人的文档
-                //查询自己是否以前打开过
-                $query = "select * from fileindex where parent_id='{$doc_id}' and user_id='{$uid}' ";
-                $FetchSelf = PDO_FetchAll($query);
-                $iFetchSelf=count($FetchSelf);
-                if($iFetchSelf>0){
-                    //以前打开过
-                    echo "文档已经复刻";
-                    echo "正在<a href='../studio/editor.php?op=opendb&doc_id={$doc_id}'>打开</a>文档";
-                    echo "<script>";
-                    echo "window.location.assign(\"../studio/editor.php?op=opendb&doc_id={$doc_id}\");";
-                    echo "</script>";
-                }
-                else{
-                    //以前没打开过
-                    echo "<h3>共享的文档,正在fork...</h3>";
-                    echo "<div style='display:none;'>";
-                    //获取文件路径
-                    
-                    PDO_Connect("sqlite:"._FILE_DB_USERINFO_);
-                    $query = "select userid from user where id='{$owner}'";
-                    $FetchUid = PDO_FetchOne($query);
-                    if($FetchUid){
-                        //$source=$dir_user_base.$FetchUid.$dir_mydocument.$filename;
-                        //$dest=$dir_user_base.$userid.$dir_mydocument.$filename;
-                        //复制数据
-                        //打开逐词解析数据库
-                        $dns = "sqlite:"._FILE_DB_USER_WBW_;
-                        $dbhWBW = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-                        $dbhWBW->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
-
-                        //打开译文数据库
-                        $dns = "sqlite:"._FILE_DB_SENTENCE_;
-                        $dbhSent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-                        $dbhSent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 
-
-                        //逐词解析新数据数组
-                        $arrNewBlock = array();
-                        $arrNewBlockData = array();
-                        $arrBlockTransform = array();
-                        
-                        //译文新数据数组
-                        $arrSentNewBlock = array();
-                        $arrSentNewBlockData = array();
-                        $arrSentBlockTransform = array(); 
-
-                        $newDocBlockList=array();
-
-                        $blocks = json_decode($Fetch[0]["doc_block"]);
-                        for ($i=0;$i<count($blocks);$i++) {
-                            switch($blocks[$i]->type){
-                                case 1:
+    echo "<input type='submit' />";
+    echo "</form>";
+    echo "</div>";
+    exit;
+}
+
+//if(isset($_GET["doc_id"]))
+{
+    PDO_Connect("" . _FILE_DB_FILEINDEX_);
+    $doc_id = $_GET["doc_id"];
+    $query = "select * from fileindex where id= ? ";
+    $Fetch = PDO_FetchAll($query, array($doc_id));
+    $iFetch = count($Fetch);
+    if ($iFetch > 0) {
+        //文档信息
+        $orgFileInfo = $Fetch[0];
+        $owner = $Fetch[0]["user_id"];
+        $filename = $Fetch[0]["file_name"];
+        $title = $Fetch[0]["title"];
+        $tag = $Fetch[0]["tag"];
+        $mbook = $Fetch[0]["book"];
+        $paragraph = $Fetch[0]["paragraph"];
+
+        if ($owner == $uid) {
+            //自己的文档
+            echo "这是自己的文档,不能复刻。";
+        } else {
+            //别人的文档
+            //查询自己是否以前打开过
+            $query = "select * from fileindex where parent_id='{$doc_id}' and user_id='{$uid}' ";
+            $FetchSelf = PDO_FetchAll($query);
+            $iFetchSelf = count($FetchSelf);
+            if ($iFetchSelf > 0) {
+                //以前打开过
+                echo "文档已经复刻";
+                echo "正在<a href='../studio/editor.php?op=opendb&doc_id={$doc_id}'>打开</a>文档";
+                echo "<script>";
+                echo "window.location.assign(\"../studio/editor.php?op=opendb&doc_id={$doc_id}\");";
+                echo "</script>";
+            } else {
+                //以前没打开过
+                echo "<h3>共享的文档,正在fork...</h3>";
+                echo "<div style='display:none;'>";
+                //获取文件路径
+
+                PDO_Connect("" . _FILE_DB_USERINFO_);
+                $query = "select userid from user where id='{$owner}'";
+                $FetchUid = PDO_FetchOne($query);
+                if ($FetchUid) {
+                    //$source=$dir_user_base.$FetchUid.$dir_mydocument.$filename;
+                    //$dest=$dir_user_base.$userid.$dir_mydocument.$filename;
+                    //复制数据
+                    //打开逐词解析数据库
+                    $dns = "" . _FILE_DB_USER_WBW_;
+                    $dbhWBW = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+                    $dbhWBW->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+                    //打开译文数据库
+                    $dns = "" . _FILE_DB_SENTENCE_;
+                    $dbhSent = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+                    $dbhSent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+                    //逐词解析新数据数组
+                    $arrNewBlock = array();
+                    $arrNewBlockData = array();
+                    $arrBlockTransform = array();
+
+                    //译文新数据数组
+                    $arrSentNewBlock = array();
+                    $arrSentNewBlockData = array();
+                    $arrSentBlockTransform = array();
+
+                    $newDocBlockList = array();
+
+                    $blocks = json_decode($Fetch[0]["doc_block"]);
+                    for ($i = 0; $i < count($blocks); $i++) {
+                        switch ($blocks[$i]->type) {
+                            case 1:
                                 break;
-                                case 2:
-                                    //译文
-                                    $blockid = $blocks[$i]->block_id;
-                                    $query = "select * from sent_block where id= ? ";
-                                    $stmt = $dbhSent->prepare($query);
-                                    $stmt->execute(array($blockid));
-                                    $fBlock = $stmt->fetchAll(PDO::FETCH_ASSOC);
-									$newBlockId = UUID::V4();
-									//不复刻译文
-                                    //$newDocBlockList[]=array('type' => 2,'block_id' => $newBlockId);
-                                    $arrSentBlockTransform[$fBlock[0]["id"]] = $newBlockId;
-                                    if(count($fBlock)>0){
-										array_push( $arrSentNewBlock,
-													array($newBlockId,
-                                                          $fBlock[0]["id"],
-                                                          $fBlock[0]["book"],
-                                                          $fBlock[0]["paragraph"],
-                                                          $_COOKIE["userid"],
-                                                          $fBlock[0]["lang"],
-                                                          $fBlock[0]["author"],
-                                                          $fBlock[0]["editor"],
-                                                          $fBlock[0]["tag"],
-                                                          $fBlock[0]["status"],
-                                                          mTime(),
-                                                          mTime()
-                                                        ));
-                                    }
-
-                                    $query = "select * from sentence where block_id= ? ";
-                                    $stmtSent = $dbhSent->prepare($query);
-                                    $stmtSent->execute(array($fBlock[0]["id"]));
-                                    $fBlockData = $stmtSent->fetchAll(PDO::FETCH_ASSOC);
-                                    foreach($fBlockData as $value){
-										array_push( $arrSentNewBlockData,
-													array(UUID::V4(),
-														$arrSentBlockTransform[$value["block_id"]],
-														$value["book"],
-														$value["paragraph"],
-														$value["begin"],
-														$value["end"],
-														$value["channal"],
-														$value["tag"],
-														$value["author"],
-														$_COOKIE["userid"],
-														$value["text"],
-														$value["language"],
-														$value["ver"],
-														$value["status"],
-														mTime(),
-														mTime()
-													));
-
-                                    }
-                                    
+                            case 2:
+                                //译文
+                                $blockid = $blocks[$i]->block_id;
+                                $query = "select * from sent_block where id= ? ";
+                                $stmt = $dbhSent->prepare($query);
+                                $stmt->execute(array($blockid));
+                                $fBlock = $stmt->fetchAll(PDO::FETCH_ASSOC);
+                                $newBlockId = UUID::V4();
+                                //不复刻译文
+                                //$newDocBlockList[]=array('type' => 2,'block_id' => $newBlockId);
+                                $arrSentBlockTransform[$fBlock[0]["id"]] = $newBlockId;
+                                if (count($fBlock) > 0) {
+                                    array_push($arrSentNewBlock,
+                                        array($newBlockId,
+                                            $fBlock[0]["id"],
+                                            $fBlock[0]["book"],
+                                            $fBlock[0]["paragraph"],
+                                            $_COOKIE["userid"],
+                                            $fBlock[0]["lang"],
+                                            $fBlock[0]["author"],
+                                            $fBlock[0]["editor"],
+                                            $fBlock[0]["tag"],
+                                            $fBlock[0]["status"],
+                                            mTime(),
+                                            mTime(),
+                                        ));
+                                }
+
+                                $query = "select * from sentence where block_id= ? ";
+                                $stmtSent = $dbhSent->prepare($query);
+                                $stmtSent->execute(array($fBlock[0]["id"]));
+                                $fBlockData = $stmtSent->fetchAll(PDO::FETCH_ASSOC);
+                                foreach ($fBlockData as $value) {
+                                    array_push($arrSentNewBlockData,
+                                        array(UUID::V4(),
+                                            $arrSentBlockTransform[$value["block_id"]],
+                                            $value["book"],
+                                            $value["paragraph"],
+                                            $value["begin"],
+                                            $value["end"],
+                                            $value["channal"],
+                                            $value["tag"],
+                                            $value["author"],
+                                            $_COOKIE["userid"],
+                                            $value["text"],
+                                            $value["language"],
+                                            $value["ver"],
+                                            $value["status"],
+                                            mTime(),
+                                            mTime(),
+                                        ));
+
+                                }
+
                                 break;
-                                case 3:
+                            case 3:
                                 break;
-                                case 4:
+                            case 4:
                                 break;
-                                case 5:
+                            case 5:
                                 break;
-								case 6: 
-									#逐词解析
-                                    $blockid = $blocks[$i]->block_id;
-                                    $query = "select * from wbw_block where id= ? ";
-                                    $stmt = $dbhWBW->prepare($query);
-                                    $stmt->execute(array($blockid));
-                                    $fBlock = $stmt->fetchAll(PDO::FETCH_ASSOC);
-                                    $newBlockId = UUID::V4();
-                                    $newDocBlockList[]=array('type' => 6,'block_id' => $newBlockId);
-                                    $arrBlockTransform[$fBlock[0]["id"]] = $newBlockId;
-                                    if(count($fBlock)>0){
-										array_push( $arrNewBlock,
-													array($newBlockId,
-														$fBlock[0]["id"],
-														$_GET["channel"],
-														$_COOKIE["userid"],
-														$fBlock[0]["book"],
-														$fBlock[0]["paragraph"],
-														$fBlock[0]["style"],
-														$fBlock[0]["lang"],
-														$fBlock[0]["status"],
-														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"]
-													));
-
-                                    }
+                            case 6:
+                                #逐词解析
+                                $blockid = $blocks[$i]->block_id;
+                                $query = "select * from wbw_block where id= ? ";
+                                $stmt = $dbhWBW->prepare($query);
+                                $stmt->execute(array($blockid));
+                                $fBlock = $stmt->fetchAll(PDO::FETCH_ASSOC);
+                                $newBlockId = UUID::V4();
+                                $newDocBlockList[] = array('type' => 6, 'block_id' => $newBlockId);
+                                $arrBlockTransform[$fBlock[0]["id"]] = $newBlockId;
+                                if (count($fBlock) > 0) {
+                                    array_push($arrNewBlock,
+                                        array($newBlockId,
+                                            $fBlock[0]["id"],
+                                            $_GET["channel"],
+                                            $_COOKIE["userid"],
+                                            $fBlock[0]["book"],
+                                            $fBlock[0]["paragraph"],
+                                            $fBlock[0]["style"],
+                                            $fBlock[0]["lang"],
+                                            $fBlock[0]["status"],
+                                            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"],
+                                        ));
+
+                                }
                                 break;
-                                case 2:
+                            case 2:
 
                                 break;
-                            }
+                        }
 
+                    }
+                    //逐词解析block数据块
+
+                    if (count($arrNewBlock) > 0) {
+                        $dbhWBW->beginTransaction();
+                        $query = "INSERT INTO wbw_block ('id','parent_id','channal','owner','book','paragraph','style','lang','status','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?)";
+                        $stmtNewBlock = $dbhWBW->prepare($query);
+                        foreach ($arrNewBlock as $oneParam) {
+                            $stmtNewBlock->execute($oneParam);
                         }
-                        //逐词解析block数据块
-                        
-                        if(count($arrNewBlock)>0){
-                            $dbhWBW->beginTransaction();
-                            $query="INSERT INTO wbw_block ('id','parent_id','channal','owner','book','paragraph','style','lang','status','modify_time','receive_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>";
-                            }
-                            else{
-                                //逐词解析block块复刻成功
-                                $count=count($arrNewBlock);
-                                echo "wbw block $count recorders.<br/>";                  
-                            }
+                        // 提交更改
+                        $dbhWBW->commit();
+                        if (!$stmtNewBlock || ($stmtNewBlock && $stmtNewBlock->errorCode() != 0)) {
+                            $error = $dbhWBW->errorInfo();
+                            echo "error - $error[2] <br>";
+                        } else {
+                            //逐词解析block块复刻成功
+                            $count = count($arrNewBlock);
+                            echo "wbw block $count recorders.<br/>";
                         }
+                    }
 
-                        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>";
-                            }
-                            else{
-                                //逐词解析 数据 复刻成功
-                                $count=count($arrNewBlockData);
-                                echo "new wbw $count recorders.";
-                            }   
+                    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);
                         }
-						
-						//不复刻译文
-                        
-                        //译文 block数据块
-                        /*
-                        if(count($arrSentNewBlock)>0){
-                            $dbhSent->beginTransaction();
-                            $query="INSERT INTO sent_block ('id','parent_id','book','paragraph','owner','lang','author','editor','tag','status','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
-                            $stmtSentNewBlock = $dbhSent->prepare($query);
-                            foreach($arrSentNewBlock as $oneParam){
-                                //print_r($oneParam);
-                                $stmtSentNewBlock->execute($oneParam);
-                            }
-                            // 提交更改 
-                            $dbhSent->commit();
-                            if (!$stmtSentNewBlock || ($stmtSentNewBlock && $stmtSentNewBlock->errorCode() != 0)) {
-                                $error = $dbhSent->errorInfo();
-                                echo "error - $error[2] <br>";
-                            }
-                            else{
-                                //译文 block块复刻成功
-                                $count=count($arrNewBlock);
-                                echo "wbw block $count recorders.<br/>";                  
-                            }
+                        // 提交更改
+                        $dbhWBW->commit();
+                        if (!$stmtWbwData || ($stmtWbwData && $stmtWbwData->errorCode() != 0)) {
+                            $error = $dbhWBW->errorInfo();
+                            echo "error - $error[2] <br>";
+                        } else {
+                            //逐词解析 数据 复刻成功
+                            $count = count($arrNewBlockData);
+                            echo "new wbw $count recorders.";
                         }
+                    }
 
-                        if(count($arrSentNewBlockData)>0){
-                            // 开始一个事务,逐词解析数据 关闭自动提交
-                            $dbhSent->beginTransaction();
-                            $query="INSERT INTO sentence ('id','block_id','book','paragraph','begin','end','channal','tag','author','editor','text','language','ver','status','modify_time','receive_time') VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?, ?)";
-                            $stmtSentData = $dbhSent->prepare($query);
-                            foreach($arrSentNewBlockData as $oneParam){
-                                $stmtSentData->execute($oneParam);
-                            }
-                            // 提交更改 
-                            $dbhSent->commit();
-                            if (!$stmtSentData || ($stmtSentData && $stmtSentData->errorCode() != 0)) {
-                                $error = $dbhSent->errorInfo();
-                                echo "error - $error[2] <br>";
-                            }
-                            else{
-                                //译文 数据 复刻成功
-                                $count=count($arrSentNewBlockData);
-                                echo "new translation $count recorders.";
-                            }   
-                        }
-                        */
+                    //不复刻译文
+
+                    //译文 block数据块
+                    /*
+                    if(count($arrSentNewBlock)>0){
+                    $dbhSent->beginTransaction();
+                    $query="INSERT INTO sent_block ('id','parent_id','book','paragraph','owner','lang','author','editor','tag','status','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
+                    $stmtSentNewBlock = $dbhSent->prepare($query);
+                    foreach($arrSentNewBlock as $oneParam){
+                    //print_r($oneParam);
+                    $stmtSentNewBlock->execute($oneParam);
+                    }
+                    // 提交更改
+                    $dbhSent->commit();
+                    if (!$stmtSentNewBlock || ($stmtSentNewBlock && $stmtSentNewBlock->errorCode() != 0)) {
+                    $error = $dbhSent->errorInfo();
+                    echo "error - $error[2] <br>";
+                    }
+                    else{
+                    //译文 block块复刻成功
+                    $count=count($arrNewBlock);
+                    echo "wbw block $count recorders.<br/>";
+                    }
+                    }
 
-                        //插入记录到文件索引
-                        $filesize=0;
-                        //服务器端文件列表
-                        PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-                        $query="INSERT INTO fileindex ('id',
+                    if(count($arrSentNewBlockData)>0){
+                    // 开始一个事务,逐词解析数据 关闭自动提交
+                    $dbhSent->beginTransaction();
+                    $query="INSERT INTO sentence ('id','block_id','book','paragraph','begin','end','channal','tag','author','editor','text','language','ver','status','modify_time','receive_time') VALUES (? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?, ?)";
+                    $stmtSentData = $dbhSent->prepare($query);
+                    foreach($arrSentNewBlockData as $oneParam){
+                    $stmtSentData->execute($oneParam);
+                    }
+                    // 提交更改
+                    $dbhSent->commit();
+                    if (!$stmtSentData || ($stmtSentData && $stmtSentData->errorCode() != 0)) {
+                    $error = $dbhSent->errorInfo();
+                    echo "error - $error[2] <br>";
+                    }
+                    else{
+                    //译文 数据 复刻成功
+                    $count=count($arrSentNewBlockData);
+                    echo "new translation $count recorders.";
+                    }
+                    }
+                     */
+
+                    //插入记录到文件索引
+                    $filesize = 0;
+                    //服务器端文件列表
+                    PDO_Connect("" . _FILE_DB_FILEINDEX_);
+                    $query = "INSERT INTO fileindex ('id',
                                                        'parent_id',
                                                        'user_id',
                                                        'book',
@@ -400,60 +393,58 @@ require_once '../studio/index_head.php';
                                                        'doc_info',
                                                        'doc_block',
                                                        'receive_time'
-                                                       ) 
+                                                       )
                                         VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-                        $stmt = $PDO->prepare($query);
-                        $newDocId = UUID::v4();
-                        $newDocInfo = $orgFileInfo;
-                        $newDocInfo["id"] = $newDocId;
-                        $newDocInfo["parent_id"] = $orgFileInfo["id"];
-                        $newDocInfo["user_id"] = $_COOKIE["uid"];
-                        $newDocInfo["doc_block"] = json_encode($newDocBlockList, JSON_UNESCAPED_UNICODE); 
-                        $newData=array($newDocInfo["id"],
-                                       $newDocInfo["parent_id"],
-                                       $newDocInfo["user_id"],
-                                       $newDocInfo["book"],
-                                       $newDocInfo["paragraph"],
-                                       $newDocInfo["file_name"],
-                                       $newDocInfo["title"],
-                                       $newDocInfo["tag"],
-                                       $newDocInfo["status"],
-                                       mTime(),
-                                       mTime(),
-                                       mTime(),
-                                       $newDocInfo["file_size"], 
-                                       $newDocInfo["share"], 
-                                       $newDocInfo["doc_info"], 
-                                       $newDocInfo["doc_block"], 
-                                       mTime()
-                                    );
-                        $stmt->execute($newData);
-                        if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                            $error = PDO_ErrorInfo();
-                            echo "error - $error[2] <br>";
-                        }
-                        else{
-                            //文档列表插入成功
-                            
-                            echo "doc list updata 1 recorders.";
-                            echo "</div>";
-                            echo "<h3>复刻成功</h3>";
-                            echo "正在<a href='../studio/editor.php?op=opendb&doc_id={$newDocId}'>打开</a>文档";
-                            echo "<script>";
-                            echo "window.location.assign(\"../studio/editor.php?op=opendb&fileid={$newDocId}\");";
-                            echo "</script>";
-                        } 
-                    }
-                    else{
-                        echo "无效的文档id";
+                    $stmt = $PDO->prepare($query);
+                    $newDocId = UUID::v4();
+                    $newDocInfo = $orgFileInfo;
+                    $newDocInfo["id"] = $newDocId;
+                    $newDocInfo["parent_id"] = $orgFileInfo["id"];
+                    $newDocInfo["user_id"] = $_COOKIE["uid"];
+                    $newDocInfo["doc_block"] = json_encode($newDocBlockList, JSON_UNESCAPED_UNICODE);
+                    $newData = array($newDocInfo["id"],
+                        $newDocInfo["parent_id"],
+                        $newDocInfo["user_id"],
+                        $newDocInfo["book"],
+                        $newDocInfo["paragraph"],
+                        $newDocInfo["file_name"],
+                        $newDocInfo["title"],
+                        $newDocInfo["tag"],
+                        $newDocInfo["status"],
+                        mTime(),
+                        mTime(),
+                        mTime(),
+                        $newDocInfo["file_size"],
+                        $newDocInfo["share"],
+                        $newDocInfo["doc_info"],
+                        $newDocInfo["doc_block"],
+                        mTime(),
+                    );
+                    $stmt->execute($newData);
+                    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+                        $error = PDO_ErrorInfo();
+                        echo "error - $error[2] <br>";
+                    } else {
+                        //文档列表插入成功
+
+                        echo "doc list updata 1 recorders.";
+                        echo "</div>";
+                        echo "<h3>复刻成功</h3>";
+                        echo "正在<a href='../studio/editor.php?op=opendb&doc_id={$newDocId}'>打开</a>文档";
+                        echo "<script>";
+                        echo "window.location.assign(\"../studio/editor.php?op=opendb&fileid={$newDocId}\");";
+                        echo "</script>";
                     }
-                    
+                } else {
+                    echo "无效的文档id";
                 }
+
             }
         }
     }
+}
 
-	echo "</div>";
+echo "</div>";
 ?>
 
 </body>

+ 69 - 75
app/doc/load_channal_para.php

@@ -1,93 +1,87 @@
 <?php
 /*
 get xml doc from db
-*/
+ */
 require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once "../public/function.php";
 
-if(isset($_POST["book"])){
-	$book=$_POST["book"];
-}
-else{
-	echo "error: no book id";
-	exit;
+if (isset($_POST["book"])) {
+    $book = $_POST["book"];
+} else {
+    echo "error: no book id";
+    exit;
 }
 
-if(isset($_POST["para"])){
-	$paralist=explode(",",$_POST["para"]);
-}
-else{
-	exit;
+if (isset($_POST["para"])) {
+    $paralist = explode(",", $_POST["para"]);
+} else {
+    exit;
 }
 
-if(isset($_POST["channal"])){
-	$channal=$_POST["channal"];
-}
-else{
-	exit;
+if (isset($_POST["channal"])) {
+    $channal = $_POST["channal"];
+} else {
+    exit;
 }
 
-	echo '<?xml version="1.0" encoding="UTF-8"?>';
-	echo "<set>\n";
-	echo "    <head>\n";
-	echo "        <type>pcdsset</type>\n";
-	echo "        <mode>package</mode>\n";
-	echo "        <ver>1</ver>\n";
-	echo "        <toc></toc>\n";
-	echo "        <style></style>\n";
-	echo "        <title>{$book}-{$paralist[0]}</title>\n";
-	echo "    </head>\n";
-	echo "\n<dict></dict>\n";
-	echo "<message></message>\n";
-	echo "<body>\n";
-	
-	$dh_wbw = new PDO("sqlite:"._FILE_DB_USER_WBW_, "", "",array(PDO::ATTR_PERSISTENT=>true));
-    $dh_wbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
-	
-	foreach($paralist as $para){
+echo '<?xml version="1.0" encoding="UTF-8"?>';
+echo "<set>\n";
+echo "    <head>\n";
+echo "        <type>pcdsset</type>\n";
+echo "        <mode>package</mode>\n";
+echo "        <ver>1</ver>\n";
+echo "        <toc></toc>\n";
+echo "        <style></style>\n";
+echo "        <title>{$book}-{$paralist[0]}</title>\n";
+echo "    </head>\n";
+echo "\n<dict></dict>\n";
+echo "<message></message>\n";
+echo "<body>\n";
 
-				$albumId = UUID::v4();
-				$query="SELECT * FROM wbw_block WHERE channal=? AND book = ? AND paragraph = ?  ";
-				$stmt = $dh_wbw->prepare($query);
-				$stmt->execute(array($channal,$book,$para));
-				$FetchBlock = $stmt->fetch(PDO::FETCH_ASSOC);
-				if($FetchBlock){
-					echo "\n<block>";
-					echo "<info>\n";
-					
-					echo "<type>wbw</type>";
-					echo "<book>{$book}</book>";
-					echo "<paragraph>{$para}</paragraph>";
-					echo "<level>100</level>";
-					echo "<title></title>";
-					echo "<album_id></album_id>";
-					echo "<album_guid></album_guid>";
-					echo "<author>{$FetchBlock["owner"]}</author>";
-					echo "<language>{$FetchBlock["lang"]}</language>";
-					echo "<version>1</version>";
-					echo "<edition>1</edition>";
-					echo "<id>{$FetchBlock["id"]}</id>";
-					echo "</info>\n";		
+$dh_wbw = new PDO("" . _FILE_DB_USER_WBW_, "", "", array(PDO::ATTR_PERSISTENT => true));
+$dh_wbw->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
-					echo "<data>\n";
-					$block_id = $FetchBlock["id"];
-					$query="select * from wbw where block_id= ? ";
-					$stmt = $dh_wbw->prepare($query);
-					$stmt->execute(array($block_id));
-					$wbw_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
-					foreach($wbw_data as $word){
-						echo $word["data"];	
-						echo "\r\n";	
-					}
-					echo "</data>";
-					echo "</block>\n";
-				}
+foreach ($paralist as $para) {
 
-	}
-				
-	echo "</body>\n";
-	echo "</set>";
+    $albumId = UUID::v4();
+    $query = "SELECT * FROM wbw_block WHERE channal=? AND book = ? AND paragraph = ?  ";
+    $stmt = $dh_wbw->prepare($query);
+    $stmt->execute(array($channal, $book, $para));
+    $FetchBlock = $stmt->fetch(PDO::FETCH_ASSOC);
+    if ($FetchBlock) {
+        echo "\n<block>";
+        echo "<info>\n";
 
+        echo "<type>wbw</type>";
+        echo "<book>{$book}</book>";
+        echo "<paragraph>{$para}</paragraph>";
+        echo "<level>100</level>";
+        echo "<title></title>";
+        echo "<album_id></album_id>";
+        echo "<album_guid></album_guid>";
+        echo "<author>{$FetchBlock["owner"]}</author>";
+        echo "<language>{$FetchBlock["lang"]}</language>";
+        echo "<version>1</version>";
+        echo "<edition>1</edition>";
+        echo "<id>{$FetchBlock["id"]}</id>";
+        echo "</info>\n";
+
+        echo "<data>\n";
+        $block_id = $FetchBlock["id"];
+        $query = "select * from wbw where block_id= ? ";
+        $stmt = $dh_wbw->prepare($query);
+        $stmt->execute(array($block_id));
+        $wbw_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
+        foreach ($wbw_data as $word) {
+            echo $word["data"];
+            echo "\r\n";
+        }
+        echo "</data>";
+        echo "</block>\n";
+    }
+
+}
 
-?>
+echo "</body>\n";
+echo "</set>";

+ 252 - 269
app/doc/pcs2db.php

@@ -2,7 +2,7 @@
 /*
 转换pcs 到数据库格式
 
-*/
+ */
 require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once "../public/function.php";
@@ -13,118 +13,113 @@ echo '<div class="index_inner" style="    margin-left: 18em;margin-top: 5em;">';
 
 echo "<h2>转换PCS 到数据库格式</h2>";
 
-if($_COOKIE["uid"]){
-	$uid=$_COOKIE["uid"];
+if ($_COOKIE["uid"]) {
+    $uid = $_COOKIE["uid"];
+} else {
+    echo "尚未登录";
+    echo "<h3><a href='../ucenter/index.php?op=login'>登录</a>后才可以打开文档 </h3>";
+    exit;
 }
-else{
-	echo "尚未登录";
-	echo "<h3><a href='../ucenter/index.php?op=login'>登录</a>后才可以打开文档 </h3>";
-	exit;
+if (isset($_GET["doc_id"]) == false) {
+    echo "没有 文档编号";
+    exit;
 }
-if(isset($_GET["doc_id"])==false){
-	echo "没有 文档编号";
-	exit;
-}
-PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-$doc_id=$_GET["doc_id"];
+PDO_Connect("" . _FILE_DB_FILEINDEX_);
+$doc_id = $_GET["doc_id"];
 $query = "SELECT * from fileindex where id= ? ";
-$Fetch = PDO_FetchAll($query,array($doc_id));
-$iFetch=count($Fetch);
-if($iFetch>0){
-	//文档信息
-	$mbook=$Fetch[0]["book"];
-	$paragraph=$Fetch[0]["paragraph"];
+$Fetch = PDO_FetchAll($query, array($doc_id));
+$iFetch = count($Fetch);
+if ($iFetch > 0) {
+    //文档信息
+    $mbook = $Fetch[0]["book"];
+    $paragraph = $Fetch[0]["paragraph"];
 }
 
-if(isset($_GET["channel"])==false){
-	echo '<div class="file_list_block">';
-	echo "<h2>选择一个空白的版风存储新的文档</h2>";
-	echo "<form action='pcs2db.php' method='get'>";
-	echo "<input type='hidden' name='doc_id' value='{$_GET["doc_id"]}' />";
-	PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
-	$query = "SELECT * from channal where owner = '{$_COOKIE["userid"]}'   limit 0,100";
-	$Fetch = PDO_FetchAll($query);
-	$i=0;
-	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="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;">';
-		PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
-		$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="title" style="flex:2;padding-bottom:5px;">';
-		PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
-		$query = "select count(*) from sentence 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 '</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;
+if (isset($_GET["channel"]) == false) {
+    echo '<div class="file_list_block">';
+    echo "<h2>选择一个空白的版风存储新的文档</h2>";
+    echo "<form action='pcs2db.php' method='get'>";
+    echo "<input type='hidden' name='doc_id' value='{$_GET["doc_id"]}' />";
+    PDO_Connect("" . _FILE_DB_CHANNAL_);
+    $query = "SELECT * from channal where owner = '{$_COOKIE["userid"]}'   limit 0,100";
+    $Fetch = PDO_FetchAll($query);
+    $i = 0;
+    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="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;">';
+        PDO_Connect("" . _FILE_DB_USER_WBW_);
+        $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="title" style="flex:2;padding-bottom:5px;">';
+        PDO_Connect("" . _FILE_DB_SENTENCE_);
+        $query = "select count(*) from sentence 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 '</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;
 }
 
-$dir = _DIR_USER_DOC_.'/'.$_COOKIE["userid"]._DIR_MYDOCUMENT_;
-PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
+$dir = _DIR_USER_DOC_ . '/' . $_COOKIE["userid"] . _DIR_MYDOCUMENT_;
+PDO_Connect("" . _FILE_DB_FILEINDEX_);
 $query = "SELECT file_name, doc_info, modify_time from fileindex where id=? ";
-$Fetch = PDO_FetchRow($query,array($_GET["doc_id"]));
+$Fetch = PDO_FetchRow($query, array($_GET["doc_id"]));
 
-if($Fetch===false){
-	echo "文件不存在";
-    exit;    
-}
-else{
+if ($Fetch === false) {
+    echo "文件不存在";
+    exit;
+} else {
     $file_modify_time = $Fetch["modify_time"];
-    if(empty($Fetch["doc_info"])){
-        $file = $dir.'/'.$Fetch["file_name"];    
-    }
-    else{
-		echo "已经是数据库格式了。无需转换";
-		exit;
+    if (empty($Fetch["doc_info"])) {
+        $file = $dir . '/' . $Fetch["file_name"];
+    } else {
+        echo "已经是数据库格式了。无需转换";
+        exit;
     }
 }
-if(!file_exists($file)){
-	echo "文件不存在";
-	exit;
+if (!file_exists($file)) {
+    echo "文件不存在";
+    exit;
 }
 $xml = simplexml_load_file($file);
-if($xml==false){
-	echo "载入pcs文件错误";
-	exit;
+if ($xml == false) {
+    echo "载入pcs文件错误";
+    exit;
 }
 $xml_head = $xml->xpath('//head')[0];
 $strHead = "<head>";
@@ -141,127 +136,124 @@ $strHead .= "</head>";
 
 $dataBlock = $xml->xpath('//block');
 
-
 {
 
     //复制数据
     //打开逐词解析数据库
-    $dns = "sqlite:"._FILE_DB_USER_WBW_;
-    $dbhWBW = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-    $dbhWBW->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+    $dns = "" . _FILE_DB_USER_WBW_;
+    $dbhWBW = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+    $dbhWBW->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
     //打开译文数据库
-    $dns = "sqlite:"._FILE_DB_SENTENCE_;
-    $dbhSent = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-    $dbhSent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); 
+    $dns = "" . _FILE_DB_SENTENCE_;
+    $dbhSent = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+    $dbhSent->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
     //逐词解析新数据数组
     $arrNewBlock = array();
     $arrNewBlockData = array();
     $arrBlockTransform = array();
-    
+
     //译文新数据数组
     $arrSentNewBlock = array();
     $arrSentNewBlockData = array();
-    $arrSentBlockTransform = array(); 
+    $arrSentBlockTransform = array();
 
-    $newDocBlockList=array();
-    foreach($dataBlock as $block){
-        switch($block->info->type){
+    $newDocBlockList = array();
+    foreach ($dataBlock as $block) {
+        switch ($block->info->type) {
             case "translate":
-                echo "wbw:".$block->info->book."<br>";
-            break;
+                echo "wbw:" . $block->info->book . "<br>";
+                break;
             case "wbw":
-                echo "translate:".$block->info->book."<br>";
-            break;
+                echo "translate:" . $block->info->book . "<br>";
+                break;
         }
     }
 
-    foreach($dataBlock as $block) {
-        switch($block->info->type){
+    foreach ($dataBlock as $block) {
+        switch ($block->info->type) {
             case 1:
-            break;
+                break;
             case "translate":
                 //译文
-				$blockid = UUID::V4();
-				//译文不加入块列表 因为译文用channel解决 不需要渲染译文块
+                $blockid = UUID::V4();
+                //译文不加入块列表 因为译文用channel解决 不需要渲染译文块
                 //$newDocBlockList[]=array('type' => 2,'block_id' => $blockid);
                 $arrSentBlockTransform["{$blockid}"] = $blockid;
                 //if(count($fBlock)>0)
                 {
-                    array_push( $arrSentNewBlock,array($blockid,
-                                                    "",
-                                                    $block->info->book,
-                                                    $block->info->paragraph,
-                                                    $_COOKIE["userid"],
-                                                    $block->info->language,
-                                                    $block->info->author,
-                                                    "",
-                                                    "",
-                                                    "1",
-                                                    $file_modify_time,
-                                                    mTime()
-                                                ));
+                    array_push($arrSentNewBlock, array($blockid,
+                        "",
+                        $block->info->book,
+                        $block->info->paragraph,
+                        $_COOKIE["userid"],
+                        $block->info->language,
+                        $block->info->author,
+                        "",
+                        "",
+                        "1",
+                        $file_modify_time,
+                        mTime(),
+                    ));
                 }
-                foreach($block->data->children() as $sen){
-                    if(isset($sen->begin)){
-                        $sent_begin=$sen->begin;
+                foreach ($block->data->children() as $sen) {
+                    if (isset($sen->begin)) {
+                        $sent_begin = $sen->begin;
+                    } else {
+                        $sent_begin = "";
                     }
-                    else{
-                        $sent_begin="";
+                    if (isset($sen->end)) {
+                        $sent_end = $sen->end;
+                    } else {
+                        $sent_end = "";
                     }
-                    if(isset($sen->end)){
-                        $sent_end=$sen->end;
-                    }
-                    else{
-                        $sent_end="";
-                    }
-                    if(isset($sen->text) && strlen(trim($sen->text))>0){
-                        $paraText=$sen->text;
-                        if( $block->info->level>0 &&  $block->info->level<8){
-                            $toc.=$sen->text;
-						}
-						array_push( $arrSentNewBlockData,
-									array(UUID::V4(),
-										$blockid,
-										$block->info->book,
-										$block->info->paragraph,
-										$sent_begin,
-										$sent_end,
-										"",
-										$block->info->author,
-										$_COOKIE["userid"],
-										$paraText,
-										mb_strlen($paraText,"UTF-8"),
-										$block->info->language,
-										"1",
-										"7",
-										$file_modify_time,
-										mTime(),
-										mTime(),
-										$_GET["channel"]
-									));						
+                    if (isset($sen->text) && strlen(trim($sen->text)) > 0) {
+                        $paraText = $sen->text;
+                        if ($block->info->level > 0 && $block->info->level < 8) {
+                            $toc .= $sen->text;
+                        }
+                        array_push($arrSentNewBlockData,
+                            array(UUID::V4(),
+                                $blockid,
+                                $block->info->book,
+                                $block->info->paragraph,
+                                $sent_begin,
+                                $sent_end,
+                                "",
+                                $block->info->author,
+                                $_COOKIE["userid"],
+                                $paraText,
+                                mb_strlen($paraText, "UTF-8"),
+                                $block->info->language,
+                                "1",
+                                "7",
+                                $file_modify_time,
+                                mTime(),
+                                mTime(),
+                                $_GET["channel"],
+                            ));
                     }
                 }
-            break;
+                break;
             case "wbw":
                 $blockid = UUID::V4();
-                $newDocBlockList[]=array('type' => 6,'block_id' => $blockid);
+                $newDocBlockList[] = array('type' => 6, 'block_id' => $blockid);
                 $arrBlockTransform["{$blockid}"] = $blockid;
                 {
-					array_push( $arrNewBlock,
-								array($blockid,
-								"",
-								$_GET["channel"],
-								$_COOKIE["userid"],
-								$block->info->book,
-								$block->info->paragraph,
-								"",
-								$block->info->language,
-								"",
-								$file_modify_time,
-								mTime()
-							));
+                    array_push($arrNewBlock,
+                        array($blockid,
+                            "",
+                            $_GET["channel"],
+                            $_COOKIE["userid"],
+                            $block->info->book,
+                            $block->info->paragraph,
+                            "",
+                            $block->info->language,
+                            "",
+                            $file_modify_time,
+                            mTime(),
+                        ));
                 }
 
                 $currWordId = "";
@@ -269,13 +261,13 @@ $dataBlock = $xml->xpath('//block');
                 $currWordStatus = "";
                 $sWordData = "";
                 $iWordCount = 0;
-                foreach($block->data->children() as $word){
-                    $word_id = explode("-",$word->id)[2];
-                    $arrWordId = explode("_",$word_id);
+                foreach ($block->data->children() as $word) {
+                    $word_id = explode("-", $word->id)[2];
+                    $arrWordId = explode("_", $word_id);
                     $realWordId = $arrWordId[0];
-                    if($realWordId != $currWordId){
-                        if($iWordCount>0){
-                            array_push( $arrNewBlockData,array(UUID::V4(),
+                    if ($realWordId != $currWordId) {
+                        if ($iWordCount > 0) {
+                            array_push($arrNewBlockData, array(UUID::V4(),
                                 $blockid,
                                 $block->info->book,
                                 $block->info->paragraph,
@@ -285,7 +277,7 @@ $dataBlock = $xml->xpath('//block');
                                 $file_modify_time,
                                 mTime(),
                                 $currWordStatus,
-                                $_COOKIE["userid"]
+                                $_COOKIE["userid"],
                             ));
                             $sWordData = "";
                         }
@@ -293,7 +285,7 @@ $dataBlock = $xml->xpath('//block');
                         $currWordReal = $word->real;
                         $currWordStatus = $word->status;
                     }
-                    
+
                     $sWordData .= "<word>";
                     $sWordData .= "<pali>{$word->pali}</pali>";
                     $sWordData .= "<real>{$word->real}</real>";
@@ -308,51 +300,49 @@ $dataBlock = $xml->xpath('//block');
                     $sWordData .= "<style>{$word->style}</style>";
                     $sWordData .= "<status>{$word->status}</status>";
                     $sWordData .= "<parent>{$word->parent}</parent>";
-                    if(isset($word->bmc)){
+                    if (isset($word->bmc)) {
                         $sWordData .= "<bmc>{$word->bmc}</bmc>";
                     }
-                    if(isset($word->bmt)){
+                    if (isset($word->bmt)) {
                         $sWordData .= "<bmt>{$word->bmt}</bmt>";
                     }
-                    if(isset($word->un)){
+                    if (isset($word->un)) {
                         $sWordData .= "<un>{$word->un}</un>";
                     }
-                    if(isset($word->lock)){
+                    if (isset($word->lock)) {
                         $sWordData .= "<lock>{$word->lock}</lock>";
                     }
                     $sWordData .= "</word>";
 
-
-                     $iWordCount++;
+                    $iWordCount++;
                 }
-				array_push( $arrNewBlockData,
-							array(UUID::V4(),
-							$blockid,
-							$block->info->book,
-							$block->info->paragraph,
-							$word_id,
-							$word->real,
-							$sWordData,
-							$file_modify_time,
-							mTime(),
-							$word->status,
-							$_COOKIE["userid"]
-            			));
-            break;
+                array_push($arrNewBlockData,
+                    array(UUID::V4(),
+                        $blockid,
+                        $block->info->book,
+                        $block->info->paragraph,
+                        $word_id,
+                        $word->real,
+                        $sWordData,
+                        $file_modify_time,
+                        mTime(),
+                        $word->status,
+                        $_COOKIE["userid"],
+                    ));
+                break;
             case 2:
 
-            break;
+                break;
         }
 
     }
-    
-    //逐词解析block数据块结束
 
+    //逐词解析block数据块结束
 
-	#插入逐词解析块数据
-    if(count($arrNewBlock)>0){
+    #插入逐词解析块数据
+    if (count($arrNewBlock) > 0) {
         $dbhWBW->beginTransaction();
-        $query="INSERT INTO wbw_block (
+        $query = "INSERT INTO wbw_block (
 										'id',
 										'parent_id',
 										'channal',
@@ -364,97 +354,91 @@ $dataBlock = $xml->xpath('//block');
 										'status',
 										'modify_time',
 										'receive_time'
-										) 
+										)
 										VALUES (?,?,?,?,?,?,?,?,?,?,?)";
         $stmtNewBlock = $dbhWBW->prepare($query);
-        foreach($arrNewBlock as $oneParam){
+        foreach ($arrNewBlock as $oneParam) {
             $stmtNewBlock->execute($oneParam);
         }
-        // 提交更改 
+        // 提交更改
         $dbhWBW->commit();
         if (!$stmtNewBlock || ($stmtNewBlock && $stmtNewBlock->errorCode() != 0)) {
             $error = $dbhWBW->errorInfo();
             echo "error - $error[2] <br>";
-        }
-        else{
+        } else {
             //逐词解析block块复刻成功
-            $count=count($arrNewBlock);
-            echo "wbw block $count recorders.<br/>";                  
+            $count = count($arrNewBlock);
+            echo "wbw block $count recorders.<br/>";
         }
     }
 
-    if(count($arrNewBlockData)>0){
+    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 (?,?,?,?,?,?,?,?,?,?,?)";
+        $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){
+        foreach ($arrNewBlockData as $oneParam) {
             $stmtWbwData->execute($oneParam);
         }
-        // 提交更改 
+        // 提交更改
         $dbhWBW->commit();
         if (!$stmtWbwData || ($stmtWbwData && $stmtWbwData->errorCode() != 0)) {
             $error = $dbhWBW->errorInfo();
             echo "error - $error[2] <br>";
-        }
-        else{
+        } else {
             //逐词解析 数据 复刻成功
-            $count=count($arrNewBlockData);
+            $count = count($arrNewBlockData);
             echo "new wbw $count recorders.";
-        }   
+        }
     }
-    
-    
+
     //译文 block数据块
-    
-    if(count($arrSentNewBlock)>0){
+
+    if (count($arrSentNewBlock) > 0) {
         $dbhSent->beginTransaction();
-        $query="INSERT INTO sent_block ('id','parent_id','book','paragraph','owner','lang','author','editor','tag','status','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
+        $query = "INSERT INTO sent_block ('id','parent_id','book','paragraph','owner','lang','author','editor','tag','status','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
         $stmtSentNewBlock = $dbhSent->prepare($query);
-        foreach($arrSentNewBlock as $oneParam){
+        foreach ($arrSentNewBlock as $oneParam) {
             //print_r($oneParam);
             $stmtSentNewBlock->execute($oneParam);
         }
         // 提交更改
         $dbhSent->commit();
-        if (!$stmtSentNewBlock || ($stmtSentNewBlock && $stmtSentNewBlock->errorCode() != 0)){
+        if (!$stmtSentNewBlock || ($stmtSentNewBlock && $stmtSentNewBlock->errorCode() != 0)) {
             $error = $dbhSent->errorInfo();
             echo "error - $error[2] <br>";
-        }
-        else{
+        } else {
             //译文 block块复刻成功
-            $count=count($arrNewBlock);
-            echo "wbw block $count recorders.<br/>";                  
+            $count = count($arrNewBlock);
+            echo "wbw block $count recorders.<br/>";
         }
     }
 
-    if(count($arrSentNewBlockData)>0){
+    if (count($arrSentNewBlockData) > 0) {
         // 开始一个事务,逐词解析数据 关闭自动提交
         $dbhSent->beginTransaction();
-        $query="INSERT INTO sentence ('id','block_id','book','paragraph','begin','end','tag','author','editor','text','strlen','language','ver','status','modify_time','receive_time','create_time','channal') VALUES (? , ? , ? , ? , ? ,?, ? , ? , ? , ? , ? , ? , ? , ? , ?, ? , ? ,?)";
+        $query = "INSERT INTO sentence ('id','block_id','book','paragraph','begin','end','tag','author','editor','text','strlen','language','ver','status','modify_time','receive_time','create_time','channal') VALUES (? , ? , ? , ? , ? ,?, ? , ? , ? , ? , ? , ? , ? , ? , ?, ? , ? ,?)";
         $stmtSentData = $dbhSent->prepare($query);
-        foreach($arrSentNewBlockData as $oneParam){
+        foreach ($arrSentNewBlockData as $oneParam) {
             $stmtSentData->execute($oneParam);
         }
-        // 提交更改 
+        // 提交更改
         $dbhSent->commit();
         if (!$stmtSentData || ($stmtSentData && $stmtSentData->errorCode() != 0)) {
             $error = $dbhSent->errorInfo();
             echo "error - $error[2] <br>";
-        }
-        else{
+        } else {
             //译文 数据 复刻成功
-            $count=count($arrSentNewBlockData);
+            $count = count($arrSentNewBlockData);
             echo "new translation $count recorders.";
-        }   
+        }
     }
-    
 
     //插入记录到文件索引
-    $filesize=0;
+    $filesize = 0;
     //服务器端文件列表
-    PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-    $query="INSERT INTO fileindex ('id',
+    PDO_Connect("" . _FILE_DB_FILEINDEX_);
+    $query = "INSERT INTO fileindex ('id',
                                    'parent_id',
                                    'user_id',
                                    'book',
@@ -471,30 +455,29 @@ $dataBlock = $xml->xpath('//block');
                                    'doc_info',
                                    'doc_block',
                                    'receive_time'
-                                   ) 
+                                   )
                     VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
     $stmt = $PDO->prepare($query);
-    $query="UPDATE 'fileindex' SET 'doc_info' = ? , 'doc_block' = ?  WHERE id = ? ";
-	$stmt = $PDO->prepare($query);
-    $newData=array(
-                   $strHead,
-                   json_encode($newDocBlockList, JSON_UNESCAPED_UNICODE), 
-                   $_GET["doc_id"]
-                );
+    $query = "UPDATE 'fileindex' SET 'doc_info' = ? , 'doc_block' = ?  WHERE id = ? ";
+    $stmt = $PDO->prepare($query);
+    $newData = array(
+        $strHead,
+        json_encode($newDocBlockList, JSON_UNESCAPED_UNICODE),
+        $_GET["doc_id"],
+    );
     $stmt->execute($newData);
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
         echo "error - $error[2] <br>";
-    }
-    else{
+    } else {
         //文档列表插入成功
         echo "doc list updata 1 recorders.";
         echo "<a href='../studio/editor.php?op=opendb&doc_id={$_GET["doc_id"]}'>在编辑器中打开</a>";
-    }          
-                
+    }
+
 }
 ?>
 
 </div>
 </body>
-</html>
+</html>

+ 7 - 0
app/es/test.php

@@ -0,0 +1,7 @@
+<?php
+use Elasticsearch\ClientBuilder;
+require '../../vendor/autoload.php';
+$client = Elasticsearch\ClientBuilder::create()->build();
+
+
+?>

+ 5 - 0
app/es/uuid.php

@@ -0,0 +1,5 @@
+<?php
+require_once '../public/function.php';
+$uuid = str_replace("-", "", UUID::v4());
+$str = gmp_strval(gmp_init($uuid, 16), 62);
+echo $str;

+ 29 - 31
app/fullcalendar/examples/php/get-date.php

@@ -4,36 +4,34 @@
 require_once "../../../path.php";
 require_once "../../../public/_pdo.php";
 
-function get_teacher_course($teacher_id){
-
-		$teacher = "  ";
-
-	global $PDO;
-	PDO_Connect("sqlite:"._FILE_DB_COURSE_);
-	
-	$query = "select * from course where teacher = ?  order by create_time DESC limit 0,100";
-
-	$Fetch = PDO_FetchAll($query,array($teacher_id));
-	
-	$output = array();
-	foreach ($Fetch as $key => $couse) {
-		# code...
-		$query = "select * from lesson where course_id = '{$couse["id"]}'   limit 0,300";
-		$fAllLesson = PDO_FetchAll($query);
-		foreach ($fAllLesson as  $lesson) {
-			$start = date("Y-m-d\TH:i:s+00:00",$lesson["date"]/1000);
-			$end = date("Y-m-d\TH:i:s+00:00",$lesson["date"]/1000+$lesson["duration"]);
-			$output[]=array("id"=>$lesson["id"],
-										"title"=>$couse["title"],
-										"url"=>"../../course/lesson.php?id=".$lesson["id"],
-										"start"=> $start,
-										"end"=>$end
-									);
-		}
-	}
-	return($output);
-	
-}
+function get_teacher_course($teacher_id)
+{
+
+    $teacher = "  ";
+
+    global $PDO;
+    PDO_Connect("" . _FILE_DB_COURSE_);
 
+    $query = "select * from course where teacher = ?  order by create_time DESC limit 0,100";
 
-?>
+    $Fetch = PDO_FetchAll($query, array($teacher_id));
+
+    $output = array();
+    foreach ($Fetch as $key => $couse) {
+        # code...
+        $query = "select * from lesson where course_id = '{$couse["id"]}'   limit 0,300";
+        $fAllLesson = PDO_FetchAll($query);
+        foreach ($fAllLesson as $lesson) {
+            $start = date("Y-m-d\TH:i:s+00:00", $lesson["date"] / 1000);
+            $end = date("Y-m-d\TH:i:s+00:00", $lesson["date"] / 1000 + $lesson["duration"]);
+            $output[] = array("id" => $lesson["id"],
+                "title" => $couse["title"],
+                "url" => "../../course/lesson.php?id=" . $lesson["id"],
+                "start" => $start,
+                "end" => $end,
+            );
+        }
+    }
+    return ($output);
+
+}

+ 0 - 0
app/group/doc_del.php


+ 30 - 34
app/group/function.php

@@ -1,65 +1,61 @@
 <?php
 
-
 require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../ucenter/function.php';
 
-function group_get_name($id){
-	if(isset($id)){
-		PDO_Connect("sqlite:"._FILE_DB_GROUP_);
-		$query = "SELECT name FROM group_info  WHERE id=?";
-		$Fetch = PDO_FetchRow($query,array($id));
-		if($Fetch){
-			return $Fetch["name"];
-		}
-		else{
-			return "";
-		}
-	}
-	else{
-		return "";
-	}
+function group_get_name($id)
+{
+    if (isset($id)) {
+        PDO_Connect("" . _FILE_DB_GROUP_);
+        $query = "SELECT name FROM group_info  WHERE id=?";
+        $Fetch = PDO_FetchRow($query, array($id));
+        if ($Fetch) {
+            return $Fetch["name"];
+        } else {
+            return "";
+        }
+    } else {
+        return "";
+    }
 }
 
 class GroupInfo
 {
     private $dbh;
     private $buffer;
-    public function __construct() {
-        $dns = "sqlite:"._FILE_DB_GROUP_;
-        $this->dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+    public function __construct()
+    {
+        $dns = "" . _FILE_DB_GROUP_;
+        $this->dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
         $buffer = array();
     }
 
-    public function getName($id){
-        if(empty($id)){
+    public function getName($id)
+    {
+        if (empty($id)) {
             return "";
         }
-        if(isset($buffer[$id])){
+        if (isset($buffer[$id])) {
             return $buffer[$id];
         }
-        if($this->dbh){
+        if ($this->dbh) {
             $query = "SELECT name FROM group_info WHERE id= ? ";
             $stmt = $this->dbh->prepare($query);
             $stmt->execute(array($id));
             $user = $stmt->fetch(PDO::FETCH_ASSOC);
-            if($user){
+            if ($user) {
                 $buffer[$id] = $user["name"];
                 return $buffer[$id];
-            }
-            else{
-                $buffer[$id] ="";
+            } else {
+                $buffer[$id] = "";
                 return $buffer[$id];
-            }            
-        }
-        else{
-            $buffer[$id] ="";
+            }
+        } else {
+            $buffer[$id] = "";
             return $buffer[$id];
         }
     }
 }
-
-?>

+ 35 - 38
app/group/get.php

@@ -7,44 +7,41 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 
 $output = array();
-if(isset($_GET["id"])){
-    PDO_Connect("sqlite:"._FILE_DB_GROUP_);
-    $id=$_GET["id"];
+if (isset($_GET["id"])) {
+    PDO_Connect("" . _FILE_DB_GROUP_);
+    $id = $_GET["id"];
     $query = "SELECT * FROM group_info  WHERE id = ? ";
-	$Fetch = PDO_FetchRow($query,array($id));
-	if($Fetch){
-		$output["info"] = $Fetch;
-		if($Fetch["parent"]==0 ){
-			#顶级组 列出小组
-			$query = "SELECT * FROM group_info  WHERE parent = ? ";
-			$FetchList = PDO_FetchAll($query,array($id));
-			$output["children"] = $FetchList;
-		}
-		else{
-			$output["children"] = array();
-			$query = "SELECT * FROM group_info  WHERE id = ? ";
-			$parent_group = PDO_FetchRow($query,array($Fetch["parent"]));
-			$output["parent"] = $parent_group;
-		}
-		#列出组文件
-		{
-			PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
-			$query = "SELECT * FROM power  WHERE user = ? ";
-			$fileList = PDO_FetchAll($query,array($id));
-			foreach ($fileList as $key => $value) {
-				# code...
-				$query = "SELECT title FROM fileindex  WHERE id = ? ";
-				$file = PDO_FetchRow($query,array($value["doc_id"]));
-				if($file){
-					$fileList[$key]["title"]=$file["title"];
-				}
-				else{
-					$fileList[$key]["title"]="";
-				}
-			}
-			$output["file"] = $fileList;
-		}
-	}
+    $Fetch = PDO_FetchRow($query, array($id));
+    if ($Fetch) {
+        $output["info"] = $Fetch;
+        if ($Fetch["parent"] == 0) {
+            #顶级组 列出小组
+            $query = "SELECT * FROM group_info  WHERE parent = ? ";
+            $FetchList = PDO_FetchAll($query, array($id));
+            $output["children"] = $FetchList;
+        } else {
+            $output["children"] = array();
+            $query = "SELECT * FROM group_info  WHERE id = ? ";
+            $parent_group = PDO_FetchRow($query, array($Fetch["parent"]));
+            $output["parent"] = $parent_group;
+        }
+        #列出组文件
+        {
+            PDO_Connect("" . _FILE_DB_FILEINDEX_);
+            $query = "SELECT * FROM power  WHERE user = ? ";
+            $fileList = PDO_FetchAll($query, array($id));
+            foreach ($fileList as $key => $value) {
+                # code...
+                $query = "SELECT title FROM fileindex  WHERE id = ? ";
+                $file = PDO_FetchRow($query, array($value["doc_id"]));
+                if ($file) {
+                    $fileList[$key]["title"] = $file["title"];
+                } else {
+                    $fileList[$key]["title"] = "";
+                }
+            }
+            $output["file"] = $fileList;
+        }
+    }
 }
 echo json_encode($output, JSON_UNESCAPED_UNICODE);
-?>

+ 9 - 10
app/group/get_name.php

@@ -7,16 +7,15 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 
 $output = array();
-if(isset($_GET["name"])){
-    PDO_Connect("sqlite:"._FILE_DB_GROUP_);
+if (isset($_GET["name"])) {
+    PDO_Connect("" . _FILE_DB_GROUP_);
     $query = "SELECT * FROM group_info  WHERE name like ? and parent=0 limit 0,5";
-	$Fetch = PDO_FetchAll($query,array("%".$_GET["name"]."%"));
+    $Fetch = PDO_FetchAll($query, array("%" . $_GET["name"] . "%"));
 
-	$user_info  = new UserInfo();
-	foreach ($Fetch as $key => $value) {
-		# code...
-		$Fetch[$key]["username"] = $user_info->getName($value["owner"]);
-	}
-	echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
+    $user_info = new UserInfo();
+    foreach ($Fetch as $key => $value) {
+        # code...
+        $Fetch[$key]["username"] = $user_info->getName($value["owner"]);
+    }
+    echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
 }
-?>

+ 131 - 157
app/group/group.js

@@ -8,7 +8,6 @@ function group_list_init() {
 		group_add_dlg_init("group_add_div");
 		$("#button_new_group").show();
 	} else {
-		$("#button_new_sub_group").show();
 		group_list(gGroupId, gList);
 		team_add_dlg_init("sub_group_add_div");
 		$("#member_list_shell").css("visibility", "visible");
@@ -52,14 +51,38 @@ function my_group_list() {
 						html += "<div style='flex:1;'>" + key++ + "</div>";
 						html += "<div style='flex:2;'>" + iterator.group_name + "</div>";
 						html += "<div style='flex:2;'>";
-						if (iterator.power == 1) {
-							html += "拥有者";
+						switch (parseInt(iterator.power)) {
+							case 0:
+								html += gLocal.gui.owner;
+								break;
+							case 1:
+								html += gLocal.gui.manager;
+								break;
+							case 2:
+								html += gLocal.gui.member;
+								break;
+							default:
+								break;
 						}
 						html += "</div>";
 						html +=
 							"<div style='flex:1;'><a href='../group/index.php?id=" +
 							iterator.group_id +
-							"'>进入</a></div>";
+							"'>" +
+							gLocal.gui.enter +
+							"</a></div>";
+						html += "<div style='flex:1;'><div class='hover_button'>";
+						if (parseInt(iterator.power) == 0) {
+							//管理员可以删除group
+							html +=
+								"<button onclick=\"group_del('" +
+								iterator.group_id +
+								"')\">" +
+								gLocal.gui.delete +
+								"</button>";
+						}
+
+						html += "</div></div>";
 						html += "</div>";
 					}
 				} else {
@@ -92,8 +115,10 @@ function group_list(id, list) {
 					html += "<h2>" + gLocal.gui.introduction + "</h2>";
 					html += result.info.description;
 					html += "</div>";
-					$("#curr_group").html("/ <a>" + result.info.name + "</a>");
+					$("#curr_group").html("/" + result.info.name);
+
 					if (result.parent) {
+						//如果是project 显示 group名词
 						$("#parent_group").html(
 							" / <a href='../group/index.php?id=" +
 								result.parent.id +
@@ -102,6 +127,9 @@ function group_list(id, list) {
 								"</a> "
 						);
 					} else {
+						if (result.info.creator == getCookie("userid")) {
+							$("#button_new_sub_group").show();
+						}
 						//子小组列表
 						html += "<div class='info_block'>";
 						html += "<h2>" + gLocal.gui.sub_group + "</h2>";
@@ -111,14 +139,26 @@ function group_list(id, list) {
 								html += "<div style='flex:1;'>" + key++ + "</div>";
 								html += "<div style='flex:2;'>" + iterator.name + "</div>";
 								html += "<div style='flex:2;'>";
-								if (iterator.power == 1) {
-									html += "拥有者";
+								if (iterator.creator == getCookie("userid")) {
+									html += gLocal.gui.owner;
 								}
 								html += "</div>";
 								html +=
 									"<div style='flex:1;'><a href='../group/index.php?id=" +
 									iterator.id +
-									"&list=file'>进入</a></div>";
+									"&list=file'>" +
+									gLocal.gui.enter +
+									"</a></div>";
+								html += "<div style='flex:1;'><div class='hover_button'>";
+								if (iterator.creator == getCookie("userid")) {
+									html +=
+										"<button onclick=\"group_del('" +
+										iterator.id +
+										"')\">" +
+										gLocal.gui.delete +
+										"</button>";
+								}
+								html += "</div></div>";
 								html += "</div>";
 							}
 						} else {
@@ -185,7 +225,7 @@ function member_list(id) {
 					let html = "";
 					let result = JSON.parse(data);
 					$("#member_number").html("(" + result.length + ")");
-					//子小组列表
+					//人员
 					html += "<div class='info_block'>";
 					if (result && result.length > 0) {
 						for (const iterator of result) {
@@ -196,8 +236,19 @@ function member_list(id) {
 								html += "拥有者";
 							}
 							html += "</div>";
-							html += "<div style='flex:1;'>";
-							html += "</div>";
+							html += "<div style='flex:1;'><div class='hover_button'>";
+							//if (iterator.creator == getCookie("userid"))
+							{
+								html +=
+									"<button onclick=\"member_del('" +
+									id +
+									"','" +
+									iterator.user_id +
+									"')\">" +
+									gLocal.gui.delete +
+									"</button>";
+							}
+							html += "</div></div>";
 							html += "</div>";
 						}
 					} else {
@@ -216,165 +267,88 @@ function member_list(id) {
 	);
 }
 
-/*
-编辑channel信息
-*/
-function my_channal_edit(id) {
-	$.get(
-		"../channal/my_channal_get.php",
+function user_selected(id) {
+	$.post(
+		"../group/member_put.php",
 		{
-			id: id,
-			setting: "",
+			userid: id,
+			groupid: gGroupId,
 		},
-		function (data, status) {
-			if (status == "success") {
-				try {
-					let html = "";
-					let result = JSON.parse(data);
-					$("#article_collect").attr("a_id", result.id);
-					html += '<div class="" style="padding:5px;">';
-					html += '<div style="max-width:2em;flex:1;"></div>';
-					html += "</div>";
-
-					html += "<div style='width: 60%;padding: 1em;min-width: 25em;'>";
-					html += '<div style="display:flex;line-height:32px;">';
-					html += "<input type='hidden' name='id' value='" + result.id + "'/>";
-					html += "</div>";
-
-					html += '<div style="display:flex;line-height:32px;">';
-					html += "<div style='flex:2;'>" + gLocal.gui.title + "</div>";
-					html += "<div style='flex:8;'>";
-					html +=
-						"<input type='input' name='name' value='" +
-						result.name +
-						"' maxlength='32' placeholder='channel title'/>";
-					html += "</div>";
-					html += "</div>";
-
-					html += "<div style='display:flex;'>";
-					html += "<div style='flex:2;'>" + gLocal.gui.introduction + "</div>";
-					html += "<div style='flex:8;'>";
-					html += "<textarea name='summary'>" + result.summary + "</textarea>";
-					html += "</div>";
-					html += "</div>";
-
-					html += '<div style="display:flex;line-height:32px;">';
-					html += '<div style="flex:2;">' + gLocal.gui.language_select + "</div>";
-					html += '<div style="flex:8;">';
-					html +=
-						'<input id="channal_lang_select" type="input"  onchange="channal_lang_change()"' +
-						' placeholder = "try type chinese or en " ' +
-						'  title="type language name/code" code="' +
-						result.lang +
-						'" value="' +
-						result.lang +
-						'" > <input id="channal_lang" type="hidden" name="lang" value="' +
-						result.lang +
-						'">';
-					html += "</div>";
-					html += "</div>";
-
-					html += '<div style="display:flex;line-height:32px;">';
-					html += '<div style="flex:2;">' + gLocal.gui.privacy + "</div>";
-					html += '<div style="flex:8;">';
-					let arrStatus = [
-						{ id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
-						{ id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
-						{ id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
-					];
-					html += "<select id = 'status'  name = 'status' onchange='status_change(this)'>";
-					let status_note = "";
-					for (const iterator of arrStatus) {
-						html += "<option ";
-						if (parseInt(result.status) == iterator.id) {
-							html += " selected ";
-							status_note = iterator.note;
-						}
-						html += " value='" + iterator.id + "'>" + iterator.string + "</option>";
-					}
-
-					html += "</select>";
-					html +=
-						"<span id = 'status_help' style='margin: 0 1em;'>" +
-						status_note +
-						"</span><a href='#' target='_blank'>[" +
-						gLocal.gui.infomation +
-						"]</li>";
-					html += "</div>";
-					html += "</div>";
-					html += "</div>";
-
-					html += "<div id='preview_div'>";
-					html += "<div id='preview_inner' ></div>";
-					html += "</div>";
-
-					$("#channal_info").html(html);
-					tran_lang_select_init("channal_lang_select");
-					//$("#aritcle_status").html(render_status(result.status));
-					$("#channal_title").html(result.name);
-					$("#preview_inner").html();
-				} catch (e) {
-					console.error(e);
-				}
+		function (data) {
+			let error = JSON.parse(data);
+			if (error.status == 0) {
+				user_select_cancel();
+				alert("ok");
+				location.reload();
 			} else {
-				console.error("ajex error");
+				user_select_cancel();
+				alert(error.message);
 			}
 		}
 	);
 }
 
-function status_change(obj) {
-	let arrStatus = [
-		{ id: 0, string: gLocal.gui.disable, note: gLocal.gui.disable_note },
-		{ id: 10, string: gLocal.gui.private, note: gLocal.gui.private_note },
-		{ id: 30, string: gLocal.gui.public, note: gLocal.gui.public_note },
-	];
-	let newStatus = $(obj).val();
-	for (const iterator of arrStatus) {
-		if (parseInt(newStatus) == iterator.id) {
-			$("#status_help").html(iterator.note);
+function user_select_new() {
+	$.post(
+		"../group/my_group_put.php",
+		{
+			name: $("#user_select_title").val(),
+			parent: parentid,
+		},
+		function (data) {
+			let error = JSON.parse(data);
+			if (error.status == 0) {
+				alert("ok");
+				user_select_cancel();
+				location.reload();
+			} else {
+				alert(error.message);
+			}
 		}
-	}
+	);
 }
 
-function channal_lang_change() {
-	let lang = $("#channal_lang_select").val();
-	if (lang.split("_").length == 3) {
-		$("#channal_lang").val(lang.split("_")[2]);
-	} else {
-		$("#channal_lang").val(lang);
+function group_del(group_id) {
+	if (
+		confirm(
+			"此操作将删除组/项目。\n以及切断分享到此组/项目文件的链接。\n但是不会删除该文件。\n此操作不能恢复。仍然要删除吗!"
+		)
+	) {
+		$.post(
+			"../group/group_del.php",
+			{
+				groupid: group_id,
+			},
+			function (data) {
+				let error = JSON.parse(data);
+				if (error.status == 0) {
+					alert("ok");
+					location.reload();
+				} else {
+					alert(error.message);
+				}
+			}
+		);
 	}
 }
 
-function my_channal_save() {
-	$.ajax({
-		type: "POST", //方法类型
-		dataType: "json", //预期服务器返回的数据类型
-		url: "../channal/my_channal_post.php", //url
-		data: $("#channal_edit").serialize(),
-		success: function (result) {
-			console.log(result); //打印服务端返回的数据(调试用)
-
-			if (result.status == 0) {
-				alert("保存成功");
-			} else {
-				alert("error:" + result.message);
-			}
-		},
-		error: function (data, status) {
-			alert("异常!" + status + data.responseText);
-			switch (status) {
-				case "timeout":
-					break;
-				case "error":
-					break;
-				case "notmodified":
-					break;
-				case "parsererror":
-					break;
-				default:
-					break;
+function member_del(group_id, user_id) {
+	if (confirm("此操作将移除成员。\n此操作不能恢复。仍然要移除吗!")) {
+		$.post(
+			"../group/member_del.php",
+			{
+				groupid: group_id,
+				userid: user_id,
+			},
+			function (data) {
+				let error = JSON.parse(data);
+				if (error.status == 0) {
+					alert("ok");
+					location.reload();
+				} else {
+					alert(error.message);
+				}
 			}
-		},
-	});
+		);
+	}
 }

+ 229 - 238
app/group/group.php

@@ -11,7 +11,7 @@ require_once '../public/_pdo.php';
 <style>
 	#group_index {
 		background-color: var(--btn-border-color);
-		
+
 	}
 	#group_index:hover{
 		background-color: var(--btn-border-color);
@@ -21,294 +21,285 @@ require_once '../public/_pdo.php';
 	</style>
 		<!-- tool bar begin-->
 		<?php
-		require_once '../studio/index_tool_bar.php';
-		?>
+require_once '../studio/index_tool_bar.php';
+?>
 		<!--tool bar end -->
 		<script>
-			document.getElementById("id_language").value="<?php echo($currLanguage); ?>";
+			document.getElementById("id_language").value="<?php echo ($currLanguage); ?>";
 		</script>
 	<div class="index_inner">
-			
+
 		<div class="fun_block">
 			<div id="userfilelist">
 			<?php
-			if(isset($_GET["list"])){
-				$list=$_GET["list"];
-			}
-			else{
-				$list="group";
-			}
+if (isset($_GET["list"])) {
+    $list = $_GET["list"];
+} else {
+    $list = "group";
+}
+
+PDO_Connect("" . _FILE_DB_GROUP_);
+switch ($list) {
+    case "group":
+        echo "<div class='group_path'>Group</div>";
+        $query = "select * from \"group_member\" where user_id='{$UID}' ";
+        $Fetch = PDO_FetchAll($query);
+        $iFetch = count($Fetch);
+        $sGroupId = "('";
+        if ($iFetch > 0) {
+            foreach ($Fetch as $group_id) {
+                $sGroupId .= "{$group_id["group_id"]}','";
+            }
+            $sGroupId = substr($sGroupId, 0, -2);
+            $sGroupId .= ")";
+            $query = "select * from \"group_info\" where id in {$sGroupId} ";
+            $Fetch = PDO_FetchAll($query);
+            foreach ($Fetch as $group) {
+                echo "<div><a href=\"group.php?list=project&group={$group["id"]}\">{$group["name"]}</a>";
+                echo "<a href=\"group.php?list=group_info&group={$group["id"]}\"> [详情]</a></div>";
+            }
+        }
+        break;
+    case "group_info":
+        echo "<div><a href=\"group.php?list=group\">返回Back</a></div>";
+        if (isset($_GET["group"])) {
+            $group = $_GET["group"];
+        } else {
+            $group = "0";
+        }
+        $query = "select * from \"group_info\" where id = '{$group}' ";
+        $Fetch = PDO_FetchAll($query);
+        $group_name = $Fetch[0]["name"];
+        if (count($Fetch) > 0) {
+
+            echo "<H2>{$group_name}</H2>";
+            echo "<table>";
+            echo "<tr><td>建立Create Time</td><td>{$Fetch[0]["create_time"]}</td></tr>";
+            echo "<tr><td>文件Files</td><td>{$Fetch[0]["file_number"]}</td></tr>";
+            echo "<tr><td>成员Member</td><td>{$Fetch[0]["member_number"]}</td></tr>";
+            $query = "select user_id from \"group_member\" where group_id = '{$group}' ";
+            $Fetch = PDO_FetchAll($query);
+            $sUserId = "('";
+            foreach ($Fetch as $user) {
+                $sUserId .= "{$user["user_id"]}','";
+            }
+            $sUserId = substr($sUserId, 0, -2);
+            $sUserId .= ")";
+
+            $query = "select nickname from \"user\" where id in {$sUserId} ";
+
+            $userlist = PDO_FetchAll($query);
+
+            echo "<tr><td></td><td>";
+            foreach ($userlist as $user) {
+                echo "{$user["nickname"]}<br>";
+            }
+            echo "</td></tr>";
+            echo "</table>";
+        }
 
-			PDO_Connect("sqlite:"._FILE_DB_GROUP_);
-			switch($list){
-				case "group":
-					echo "<div class='group_path'>Group</div>";
-					$query="select * from \"group_member\" where user_id='{$UID}' ";
-					$Fetch = PDO_FetchAll($query);
-					$iFetch=count($Fetch);
-					$sGroupId="('";
-					if($iFetch>0){
-						foreach($Fetch as $group_id){
-							$sGroupId .= "{$group_id["group_id"]}','";
-						}
-						$sGroupId = substr($sGroupId,0,-2);
-						$sGroupId .= ")";
-						$query="select * from \"group_info\" where id in {$sGroupId} ";
-						$Fetch = PDO_FetchAll($query);
-						foreach($Fetch as $group){
-							echo "<div><a href=\"group.php?list=project&group={$group["id"]}\">{$group["name"]}</a>";
-							echo "<a href=\"group.php?list=group_info&group={$group["id"]}\"> [详情]</a></div>";
-						}
-					}
-					break;
-				case "group_info":
-					echo "<div><a href=\"group.php?list=group\">返回Back</a></div>";
-					if(isset($_GET["group"])){
-						$group=$_GET["group"];
-					}
-					else{
-						$group="0";
-					}
-					$query="select * from \"group_info\" where id = '{$group}' ";
-					$Fetch = PDO_FetchAll($query);
-					$group_name=$Fetch[0]["name"];
-					if(count($Fetch)>0){
-						
-						
-						echo "<H2>{$group_name}</H2>";
-						echo "<table>";
-						echo "<tr><td>建立Create Time</td><td>{$Fetch[0]["create_time"]}</td></tr>";
-						echo "<tr><td>文件Files</td><td>{$Fetch[0]["file_number"]}</td></tr>";
-						echo "<tr><td>成员Member</td><td>{$Fetch[0]["member_number"]}</td></tr>";
-						$query="select user_id from \"group_member\" where group_id = '{$group}' ";
-						$Fetch = PDO_FetchAll($query);
-						$sUserId="('";
-						foreach($Fetch as $user){
-							$sUserId .= "{$user["user_id"]}','";
-						}
-						$sUserId = substr($sUserId,0,-2);
-						$sUserId .= ")";
-						
-						$query="select nickname from \"user\" where id in {$sUserId} ";
+        break;
+    case "project";
 
-						$userlist = PDO_FetchAll($query);	
-						
-						echo "<tr><td></td><td>";
-						foreach($userlist as $user){
-							echo "{$user["nickname"]}<br>";
-						}
-						echo "</td></tr>";
-						echo "</table>";
-					}
+        if (isset($_GET["group"])) {
+            $group = $_GET["group"];
+        } else {
+            $group = "0";
+        }
+        $query = "select group_name from \"group_member\" where group_id = \"{$group}\" AND user_id=\"{$UID}\"";
+        $group_name = PDO_FetchOne($query);
+        if ($group_name == "") {
+            $query = "select name from \"group_info\" where group_id = \"{$group}\" ";
+            $group_name = PDO_FetchOne($query);
+        }
 
-					break;
-				case "project";
+        echo "<div class='group_path'>";
+        echo "<a href='group.php?list=group'>群组Group</a> >> {$group_name}";
+        echo "</div>";
+        $query = "select file_id from \"group_file_power\" where group_id = \"{$group}\" AND user_id='{$UID}' group by file_id";
+        $Fetch = PDO_FetchAll($query);
+        $sFileId = "('";
+        foreach ($Fetch as $file) {
+            $sFileId .= "{$file["file_id"]}','";
+        }
+        $sFileId = substr($sFileId, 0, -2);
+        $sFileId .= ")";
+        $query = "select project , count(*) as co from \"group_file\" where id in {$sFileId} group by project";
+        $Fetch = PDO_FetchAll($query);
+        echo "<table>";
+        echo "<tr><td>Project</td><td>File Number</td></tr>";
+        foreach ($Fetch as $project) {
+            echo "<tr class='group_file_list'>";
+            echo "<td ><a href=\"group.php?list=file&group={$group}&project={$project["project"]}\">{$project["project"]}</a></td>";
+            echo "<td>{$project["co"]}</td> ";
+            echo "</tr>";
+        }
+        echo "</table>";
+        break;
+    case "file":
 
-					if(isset($_GET["group"])){
-						$group=$_GET["group"];
-					}
-					else{
-						$group="0";
-					}
-					$query="select group_name from \"group_member\" where group_id = \"{$group}\" AND user_id=\"{$UID}\"";
-					$group_name = PDO_FetchOne($query);
-					if($group_name == ""){
-						$query="select name from \"group_info\" where group_id = \"{$group}\" ";
-						$group_name = PDO_FetchOne($query);
-					}
-					
-					echo "<div class='group_path'>";
-					echo "<a href='group.php?list=group'>群组Group</a> >> {$group_name}";
-					echo "</div>";				
-					$query="select file_id from \"group_file_power\" where group_id = \"{$group}\" AND user_id='{$UID}' group by file_id";
-					$Fetch = PDO_FetchAll($query);
-					$sFileId="('";
-					foreach($Fetch as $file){
-						$sFileId .= "{$file["file_id"]}','";
-					}
-					$sFileId = substr($sFileId,0,-2);
-					$sFileId .= ")";
-					$query="select project , count(*) as co from \"group_file\" where id in {$sFileId} group by project";
-					$Fetch = PDO_FetchAll($query);
-					echo "<table>";
-					echo "<tr><td>Project</td><td>File Number</td></tr>";
-					foreach($Fetch as $project){
-						echo "<tr class='group_file_list'>";
-						echo "<td ><a href=\"group.php?list=file&group={$group}&project={$project["project"]}\">{$project["project"]}</a></td>";
-						echo "<td>{$project["co"]}</td> ";
-						echo "</tr>";
-					}	
-					echo "</table>";
-				break;
-				case "file":
+        if (isset($_GET["group"])) {
+            $group = $_GET["group"];
+        } else {
+            $group = "0";
+        }
+        if (isset($_GET["project"])) {
+            $project = $_GET["project"];
+        } else {
+            $project = "0";
+        }
+        $query = "select group_name from \"group_member\" where group_id = \"{$group}\" AND user_id=\"{$UID}\"";
+        $group_name = PDO_FetchOne($query);
+        if ($group_name == "") {
+            $query = "select name from \"group_info\" where group_id = \"{$group}\" ";
+            $group_name = PDO_FetchOne($query);
+        }
 
-					if(isset($_GET["group"])){
-						$group=$_GET["group"];
-					}
-					else{
-						$group="0";
-					}
-					if(isset($_GET["project"])){
-						$project=$_GET["project"];
-					}
-					else{
-						$project="0";
-					}
-					$query="select group_name from \"group_member\" where group_id = \"{$group}\" AND user_id=\"{$UID}\"";
-					$group_name = PDO_FetchOne($query);
-					if($group_name == ""){
-						$query="select name from \"group_info\" where group_id = \"{$group}\" ";
-						$group_name = PDO_FetchOne($query);
-					}
-					
-					echo "<div class='group_path'>";
-					echo "<a href='group.php?list=group'>群组Group</a> >> ";
-					echo "<a href=\"group.php?list=project&group={$group}\">{$group_name}</a> >> ";
-					echo "{$project}";
-					echo "</div>";
-					
-				?>
+        echo "<div class='group_path'>";
+        echo "<a href='group.php?list=group'>群组Group</a> >> ";
+        echo "<a href=\"group.php?list=project&group={$group}\">{$group_name}</a> >> ";
+        echo "{$project}";
+        echo "</div>";
+
+        ?>
 							<div  id="file_filter">
 				<div style="display:flex;justify-content: space-between;">
 					<div>
 						<select id="id_index_status"  onchange="showUserFilaList()">
 							<option value="all" >
-								<?php echo $_local->gui->all;//全部?>
+								<?php echo $_local->gui->all; //全部 ?>
 							</option>
 							<option value="share" >
-								<?php echo $_local->gui->shared;//已共享?>
+								<?php echo $_local->gui->shared; //已共享 ?>
 							</option>
 							<option value="recycle" >
-								<?php echo $_local->gui->recycle_bin;//回收站?>
+								<?php echo $_local->gui->recycle_bin; //回收站 ?>
 							</option>
-						</select>					
+						</select>
 					</div>
-					<div><?php echo $_local->gui->order_by;//排序方式?>
+					<div><?php echo $_local->gui->order_by; //排序方式 ?>
 						<select id="id_index_orderby"  onchange="showUserFilaList()">
-							<option value="accese_time" ><?php echo $_local->gui->accessed;//訪問?></option>
-							<option value="modify_time" ><?php echo $_local->gui->modified;//修改?></option>
-							<option value="create_time" ><?php echo $_local->gui->created;//創建?></option>
-							<option value="title" ><?php echo $_local->gui->title;//標題?></option>
-						</select>					
+							<option value="accese_time" ><?php echo $_local->gui->accessed; //訪問 ?></option>
+							<option value="modify_time" ><?php echo $_local->gui->modified; //修改 ?></option>
+							<option value="create_time" ><?php echo $_local->gui->created; //創建 ?></option>
+							<option value="title" ><?php echo $_local->gui->title; //標題 ?></option>
+						</select>
 						<select id="id_index_order"  onchange="showUserFilaList()">
-							<option value="DESC" ><?php echo $_local->gui->desc;//降序?></option>
-							<option value="ASC" ><?php echo $_local->gui->asc;;//升序?></option>
-						</select>	
+							<option value="DESC" ><?php echo $_local->gui->desc; //降序 ?></option>
+							<option value="ASC" ><?php echo $_local->gui->asc; //升序 ?></option>
+						</select>
 						<button id="file_select" onclick="mydoc_file_select(true)">
 							选择
 						</button>
 					</div>
 				</div>
 				<div>
-				<input id="keyword" type="input"  placeholder=<?php echo $_local->gui->title.$_local->gui->search;?>  onkeyup="file_search_keyup()"/>
+				<input id="keyword" type="input"  placeholder=<?php echo $_local->gui->title . $_local->gui->search; ?>  onkeyup="file_search_keyup()"/>
 				</div>
 
 			</div>
-			
+
 			<div id="file_tools" style="display:none;">
 				<div  style="display:flex;justify-content: space-between;">
 					<div>
 						<span id="button_group_nomal" >
-						<button onclick="file_del()"><?php echo $_local->gui->delete;//刪除?></button>
-						<button onclick="file_share(true)"><?php echo $_local->gui->share;//共享?></button>
-						<button onclick="file_share(false)"><?php echo $_local->gui->undo_shared;//取消共享?></button>
+						<button onclick="file_del()"><?php echo $_local->gui->delete; //刪除 ?></button>
+						<button onclick="file_share(true)"><?php echo $_local->gui->share; //共享 ?></button>
+						<button onclick="file_share(false)"><?php echo $_local->gui->undo_shared; //取消共享 ?></button>
 						</span>
 						<span id="button_group_recycle" style="dispaly:none">
-						<button onclick="file_remove()" style="background-color:red;"><?php echo $_local->gui->completely_delete;//彻底删除?></button>
-						<button onclick="file_remove_all()"><?php echo $_local->gui->empty_the_recycle_bin;//清空回收站?></button>
+						<button onclick="file_remove()" style="background-color:red;"><?php echo $_local->gui->completely_delete; //彻底删除 ?></button>
+						<button onclick="file_remove_all()"><?php echo $_local->gui->empty_the_recycle_bin; //清空回收站 ?></button>
 						</span>
 					</div>
 					<div>
-						<button onclick="mydoc_file_select(false)"><?php echo $_local->gui->cancel;//取消?></button>
+						<button onclick="mydoc_file_select(false)"><?php echo $_local->gui->cancel; //取消 ?></button>
 					</div>
 				</div>
 			</div>
-			
+
 				<?php
-					$query="select * from \"group_process\" where group_id = \"{$group}\" ";
-					$stage = PDO_FetchAll($query);
-					$aStage = array();
-					echo "<button>全部All</button>";
-					foreach($stage as $one){
-						$aStage[$one["stage"]]=$one["name"];
-						echo "<button>{$one["name"]}</button>";
-					}
-					
-					$query="select file_id from \"group_file_power\" where group_id = \"{$group}\" AND user_id='{$UID}' group by file_id";
-					$Fetch = PDO_FetchAll($query);
-					$sFileId="('";
-					foreach($Fetch as $file){
-						$sFileId .= "{$file["file_id"]}','";
-					}
-					$sFileId = substr($sFileId,0,-2);
-					$sFileId .= ")";
-					$query="select * from \"group_file\" where id in {$sFileId} AND project = \"{$project}\"";
-					$Fetch = PDO_FetchAll($query);
-					echo "<table>";
-					echo "<tr><td>Title</td><td>File Size</td><td>Date</td><td>Stage</td><td></td></tr>";
-					foreach($Fetch as $file){
-						echo "<tr class='group_file_list'>";
-						echo "<td class='group_file_title'><a href=\"group.php?list=stage&file={$file["id"]}\">{$file["file_title"]}</a></td>";
-						echo "<td>{$file["file_size"]}</td> ";
-						echo "<td>{$file["modify_time"]}</td> ";
-						$stage_name=$aStage["{$file["stage"]}"];
-						echo "<td><span class='tag'>{$stage_name}</span></td>";
-						echo "<td><a href=\"group.php?list=stage&file={$file["id"]}\">详情Details</a></td>";
-						echo "</tr>";
-					}	
-					echo "</table>";
-				break;
-				case "stage":
-					if(isset($_GET["file"])){
-						$file_id=$_GET["file"];
-					}
-					else{
-						$file_id="0";
-					}
-					$query="select * from \"group_file\" where id = {$file_id} ";
-					$Fetch = PDO_FetchAll($query);
-					$group_id=$Fetch[0]["group_id"];
-					$file_title=$Fetch[0]["file_title"];
-					$project = $Fetch[0]["project"];
-					$curr_stage=$Fetch[0]["stage"];
-					$query="select name from \"group_info\" where id = \"{$group_id}\" ";
-					$group_name = PDO_FetchOne($query);
-					$query="select group_name from \"group_member\" where group_id = \"{$group_id}\" AND user_id='{$UID}'  ";
-					$my_group_name = PDO_FetchOne($query);
-					if(empty($my_group_name)){
-						$my_group_name = $group_name;
-					}
-					$query="select * from \"group_process\" where group_id = \"{$group_id}\" ";
-					$stage = PDO_FetchAll($query);
-					echo "<div class='group_path'>";
-					echo "<a href=\"group.php?list=group\">群组Group</a> / ";
-					echo "<a href=\"group.php?list=project&group={$group_id}\">{$my_group_name}</a> / ";
-					echo "<a href=\"group.php?list=file&group={$group_id}&project={$project}\">{$project}</a>";
-					echo "</div>";
-					echo "<h2>{$file_title}</h2>";
-					foreach($stage as $one){
-						echo "<button>{$one["stage"]}</button>{$one["name"]}-";
-						if($one["stage"]<$curr_stage){
-							echo "<span style='color:green'>{$_local->gui->already_over}</span>";
-						}
-						else if($one["stage"]==$curr_stage){
-							echo "{$_local->gui->in_progress}<button>完成Done</button>";
-						}
-						else{
-							echo "尚未开始 Not Ready";
-						}
-						echo"<br>";
-					}	
-				break;
-			}
-			?>
+$query = "select * from \"group_process\" where group_id = \"{$group}\" ";
+        $stage = PDO_FetchAll($query);
+        $aStage = array();
+        echo "<button>全部All</button>";
+        foreach ($stage as $one) {
+            $aStage[$one["stage"]] = $one["name"];
+            echo "<button>{$one["name"]}</button>";
+        }
+
+        $query = "select file_id from \"group_file_power\" where group_id = \"{$group}\" AND user_id='{$UID}' group by file_id";
+        $Fetch = PDO_FetchAll($query);
+        $sFileId = "('";
+        foreach ($Fetch as $file) {
+            $sFileId .= "{$file["file_id"]}','";
+        }
+        $sFileId = substr($sFileId, 0, -2);
+        $sFileId .= ")";
+        $query = "select * from \"group_file\" where id in {$sFileId} AND project = \"{$project}\"";
+        $Fetch = PDO_FetchAll($query);
+        echo "<table>";
+        echo "<tr><td>Title</td><td>File Size</td><td>Date</td><td>Stage</td><td></td></tr>";
+        foreach ($Fetch as $file) {
+            echo "<tr class='group_file_list'>";
+            echo "<td class='group_file_title'><a href=\"group.php?list=stage&file={$file["id"]}\">{$file["file_title"]}</a></td>";
+            echo "<td>{$file["file_size"]}</td> ";
+            echo "<td>{$file["modify_time"]}</td> ";
+            $stage_name = $aStage["{$file["stage"]}"];
+            echo "<td><span class='tag'>{$stage_name}</span></td>";
+            echo "<td><a href=\"group.php?list=stage&file={$file["id"]}\">详情Details</a></td>";
+            echo "</tr>";
+        }
+        echo "</table>";
+        break;
+    case "stage":
+        if (isset($_GET["file"])) {
+            $file_id = $_GET["file"];
+        } else {
+            $file_id = "0";
+        }
+        $query = "select * from \"group_file\" where id = {$file_id} ";
+        $Fetch = PDO_FetchAll($query);
+        $group_id = $Fetch[0]["group_id"];
+        $file_title = $Fetch[0]["file_title"];
+        $project = $Fetch[0]["project"];
+        $curr_stage = $Fetch[0]["stage"];
+        $query = "select name from \"group_info\" where id = \"{$group_id}\" ";
+        $group_name = PDO_FetchOne($query);
+        $query = "select group_name from \"group_member\" where group_id = \"{$group_id}\" AND user_id='{$UID}'  ";
+        $my_group_name = PDO_FetchOne($query);
+        if (empty($my_group_name)) {
+            $my_group_name = $group_name;
+        }
+        $query = "select * from \"group_process\" where group_id = \"{$group_id}\" ";
+        $stage = PDO_FetchAll($query);
+        echo "<div class='group_path'>";
+        echo "<a href=\"group.php?list=group\">群组Group</a> / ";
+        echo "<a href=\"group.php?list=project&group={$group_id}\">{$my_group_name}</a> / ";
+        echo "<a href=\"group.php?list=file&group={$group_id}&project={$project}\">{$project}</a>";
+        echo "</div>";
+        echo "<h2>{$file_title}</h2>";
+        foreach ($stage as $one) {
+            echo "<button>{$one["stage"]}</button>{$one["name"]}-";
+            if ($one["stage"] < $curr_stage) {
+                echo "<span style='color:green'>{$_local->gui->already_over}</span>";
+            } else if ($one["stage"] == $curr_stage) {
+                echo "{$_local->gui->in_progress}<button>完成Done</button>";
+            } else {
+                echo "尚未开始 Not Ready";
+            }
+            echo "<br>";
+        }
+        break;
+}
+?>
 			</div>
-			
+
 		</div>
-		
+
 	</div>
 <div class="foot_div">
-<?php echo $_local->gui->poweredby;?>
+<?php echo $_local->gui->poweredby; ?>
 </div>
 </body>
 </html>

+ 47 - 0
app/group/group_del.php

@@ -0,0 +1,47 @@
+<?php
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once '../public/function.php';
+
+$respond = array("status" => 0, "message" => "");
+if (isset($_COOKIE["userid"]) && isset($_POST["groupid"])) {
+    PDO_Connect("" . _FILE_DB_GROUP_);
+    #TODO 先查是否有删除权限
+    $query = "SELECT parent from group_info where id=? and creator=? ";
+    $gInfo = PDO_FetchRow($query, array($_POST["groupid"], $_COOKIE["userid"]));
+    if ($gInfo) {
+        #删除group info
+        $query = "DELETE from group_info where id=? and creator=? ";
+        PDO_Execute($query, array($_POST["groupid"], $_COOKIE["userid"]));
+        #删除 组员
+        $query = "DELETE from group_member where group_id=? ";
+        PDO_Execute($query, array($_POST["groupid"]));
+        #删除到此组的分享
+
+        #查询是否有子项目
+        $query = "SELECT id from group_info where parent=? ";
+        $project = PDO_FetchAll($query, array($_POST["groupid"]));
+        if (count($project)) {
+            $arrProject = array();
+            foreach ($project as $key => $value) {
+                # code...
+                $arrProject[] = $value["id"];
+            }
+            $place_holders = implode(',', array_fill(0, count($arrProject), '?'));
+            #删除 parent info
+            $query = "DELETE from group_info where id IN ($place_holders) ";
+            PDO_Execute($query, $arrProject);
+            #删除 parent 组员
+            $query = "DELETE from group_member where group_id IN ($place_holders) ";
+            PDO_Execute($query, $arrProject);
+            #删除到此组的分享
+        }
+    } else {
+        $respond['status'] = 1;
+        $respond['message'] = "no power to delete ";
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
+    }
+}
+
+echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 5 - 9
app/group/list.php

@@ -6,13 +6,9 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once '../ucenter/function.php';
 
+//没有id 列出 我的群组
+PDO_Connect("" . _FILE_DB_GROUP_);
+$query = "SELECT group_name,group_id,power FROM group_member  WHERE level = 0 and user_id=?";
+$Fetch = PDO_FetchAll($query, array($_COOKIE["userid"]));
 
-	//没有id 列出 我的群组
-    PDO_Connect("sqlite:"._FILE_DB_GROUP_);
-    $query = "SELECT group_name,group_id,power FROM group_member  WHERE level = 0 and user_id=?";
-	$Fetch = PDO_FetchAll($query,array($_COOKIE["userid"]));
-	
-    echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
-
-
-?>
+echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);

+ 8 - 9
app/group/list_member.php

@@ -7,17 +7,16 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 
 $output = array();
-if(isset($_GET["id"])){
-    PDO_Connect("sqlite:"._FILE_DB_GROUP_);
-    $id=$_GET["id"];
+if (isset($_GET["id"])) {
+    PDO_Connect("" . _FILE_DB_GROUP_);
+    $id = $_GET["id"];
     $query = "SELECT user_id FROM group_member  WHERE group_id = ? ";
-	$output = PDO_FetchAll($query,array($id));
-	$userinfo = new UserInfo();
-	foreach ($output as $key => $value) {
-		# code...
+    $output = PDO_FetchAll($query, array($id));
+    $userinfo = new UserInfo();
+    foreach ($output as $key => $value) {
+        # code...
         $user = $userinfo->getName($value["user_id"]);
         $output[$key]["user_info"] = $user;
-	}
+    }
 }
 echo json_encode($output, JSON_UNESCAPED_UNICODE);
-?>

+ 94 - 0
app/group/member_del.php

@@ -0,0 +1,94 @@
+<?php
+require_once "../path.php";
+require_once "../public/_pdo.php";
+require_once '../public/function.php';
+
+$respond = array("status" => 0, "message" => "");
+if (!isset($_COOKIE["userid"])) {
+    $respond['status'] = 1;
+    $respond['message'] = "尚未登录";
+    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+    exit;
+}
+if (isset($_POST["groupid"])) {
+    PDO_Connect("" . _FILE_DB_GROUP_);
+    $mypower = 100;
+    # 先查是否有删人权限
+    $query = "SELECT * from group_info where id=?";
+    $fc = PDO_FetchRow($query, array($_POST["groupid"]));
+    if ($fc) {
+        if ($fc["parent"] == 0) {
+            if ($fc["creator"] == $_COOKIE["userid"]) {
+                $mypower = 0;
+            }
+        } else {
+            $query = "SELECT creator  from group_info where id=?";
+            $g_parent = PDO_FetchRow($query, array($fc["parent"]));
+            if ($g_parent && $g_parent["creator"] == $_COOKIE["userid"]) {
+                $mypower = 0;
+            }
+        }
+    }
+    if ($mypower != 0) {
+        #非拥有者,看看是不是管理员
+        $query = "SELECT power from group_member where user_id=? and group_id=? ";
+        $power = PDO_FetchRow($query, array($_COOKIE["userid"], $_POST["groupid"]));
+        if ($power) {
+            $mypower = (int) $power["power"];
+        }
+        if ($mypower > 1) {
+            $respond['status'] = 1;
+            $respond['message'] = "no power to remove memeber";
+            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+            exit;
+        }
+    }
+
+    # 查询被删除人的权限
+    $query = "SELECT power from group_member where user_id=? and group_id=? ";
+    $power = PDO_FetchRow($query, array($_POST["userid"], $_POST["groupid"]));
+    $userpower = 0;
+    if ($power) {
+        $userpower = (int) $power["power"];
+    }
+    #操作人的权限不足
+    if ($mypower >= $userpower) {
+        $respond['status'] = 1;
+        $respond['message'] = "can not removed";
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
+    }
+
+    $query = "SELECT * from group_info where id=?";
+    $fc = PDO_FetchRow($query, array($_POST["groupid"]));
+    if ($fc) {
+        $idList = array();
+        $idList[] = $_POST["userid"];
+        $idList[] = $_POST["groupid"];
+        if ($fc["parent"] == 0) {
+            //group
+            $level = 0;
+            #查询project
+            $query = "SELECT id from group_info where parent=?";
+            $g_project = PDO_FetchAll($query, array($_POST["groupid"]));
+            foreach ($g_project as $key => $parentid) {
+                # code...
+                $idList[] = $parentid["id"];
+            }
+        }
+    }
+    #删除
+    $place_holders = implode(',', array_fill(0, count($idList), '?'));
+    $query = "DELETE from group_member where user_id=? and group_id IN ($place_holders)";
+    PDO_Execute($query, $idList);
+
+    if (!$sth || ($sth && $sth->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        $respond['status'] = 1;
+        $respond['message'] = $error[2];
+    }
+} else {
+    $respond['status'] = 1;
+    $respond['message'] = "参数不足";
+}
+echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 48 - 40
app/group/member_put.php

@@ -3,47 +3,55 @@ require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
-$respond=array("status"=>0,"message"=>"");
-if(isset($_COOKIE["userid"]) && isset($_POST["groupid"])){
-	PDO_Connect("sqlite:"._FILE_DB_GROUP_);
-	#先查是否有加人权限
-	$query="SELECT * from group_info where id=?";
-	$fc = PDO_FetchRow($query,array($_POST["groupid"]));
-	if($fc){
-		if($fc["parent"]==0){
-			$level = 0;
-		}
-		else{
-			$level = 1;
-			#子小组要插入两条记录 第一条插入父层级
-			$query="SELECT * from group_info where id=?";
-			$g_parent = PDO_FetchRow($query,array($fc["id"]));
-			$query="INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )  
-			VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
-			$sth = $PDO->prepare($query);
-			$sth->execute(array($_POST["userid"] ,$fc["parent"], 1 , $$g_parent["name"], 0 ,1 ));
-			$respond=array("status"=>0,"message"=>"");
-			if (!$sth || ($sth && $sth->errorCode() != 0)) {
-				$error = PDO_ErrorInfo();
-				$respond['status']=1;
-				$respond['message']=$error[2];
-			}	
-		}
-	}
-	#查询这个
-	$query="SELECT * from group_info where id=?";
-	$g_curr = PDO_FetchRow($query,array($_POST["groupid"]));
+$respond = array("status" => 0, "message" => "");
+if (isset($_COOKIE["userid"]) && isset($_POST["groupid"])) {
+    PDO_Connect("" . _FILE_DB_GROUP_);
+    #TODO 先查是否有加人权限
+    $query = "SELECT power from group_member where user_id=? and group_id=? ";
+    $power = PDO_FetchRow($query, array($_COOKIE["userid"], $_POST["groupid"]));
+    if ($power) {
+        if ($power["power"] > 1) {
+            $respond['status'] = 1;
+            $respond['message'] = "no power to add memeber";
+            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+            exit;
+        }
+    }
 
-	$query="INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )  
+    $query = "SELECT * from group_info where id=?";
+    $fc = PDO_FetchRow($query, array($_POST["groupid"]));
+    if ($fc) {
+        if ($fc["parent"] == 0) {
+            $level = 0;
+        } else {
+            $level = 1;
+            #子小组要插入两条记录 第一条插入父层级
+            $query = "SELECT * from group_info where id=?";
+            $g_parent = PDO_FetchRow($query, array($fc["id"]));
+            $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )  VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
+            $sth = $PDO->prepare($query);
+            $sth->execute(array($_POST["userid"], $fc["parent"], 2, $$g_parent["name"], 0, 1));
+            $respond = array("status" => 0, "message" => "");
+            if (!$sth || ($sth && $sth->errorCode() != 0)) {
+                $error = PDO_ErrorInfo();
+                $respond['status'] = 1;
+                $respond['message'] = $error[2];
+            }
+        }
+    }
+    #查询这个
+    $query = "SELECT * from group_info where id=?";
+    $g_curr = PDO_FetchRow($query, array($_POST["groupid"]));
+
+    $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )
 		VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
-	$sth = $PDO->prepare($query);
-	$sth->execute(array($_POST["userid"] ,$_POST["groupid"], 1 , $g_curr["name"], $level ,1 ));
-	$respond=array("status"=>0,"message"=>"");
-	if (!$sth || ($sth && $sth->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
-		$respond['status']=1;
-		$respond['message']=$error[2];
-	}	
+    $sth = $PDO->prepare($query);
+    $sth->execute(array($_POST["userid"], $_POST["groupid"], 2, $g_curr["name"], $level, 1));
+    $respond = array("status" => 0, "message" => "");
+    if (!$sth || ($sth && $sth->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        $respond['status'] = 1;
+        $respond['message'] = $error[2];
+    }
 }
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);
-?>

+ 30 - 29
app/group/my_group_put.php

@@ -1,39 +1,40 @@
 <?php
+#新增群组或项目
 require_once "../path.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
-$respond=array("status"=>0,"message"=>"");
-if(isset($_COOKIE["userid"])){
-	PDO_Connect("sqlite:"._FILE_DB_GROUP_);
-	$query="INSERT INTO group_info ( id,  parent  , name  , description ,  status , owner ,create_time )  
+$respond = array("status" => 0, "message" => "");
+if (isset($_COOKIE["userid"])) {
+    PDO_Connect("" . _FILE_DB_GROUP_);
+    $query = "INSERT INTO group_info ( id,  parent  , name  , description ,  status , creator ,create_time )
 	                       VALUES  ( ?, ? , ? , ? , ? , ?  ,? ) ";
-	$sth = $PDO->prepare($query);
-	$newid = UUID::v4();
-	$sth->execute(array( $newid,$_POST["parent"], $_POST["name"], "" ,1 ,$_COOKIE["userid"] , mTime() ));
-	$respond=array("status"=>0,"message"=>"");
-	if (!$sth || ($sth && $sth->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
-		$respond['status']=1;
-		$respond['message']=$error[2];
-	}	
+    $sth = $PDO->prepare($query);
+    $newid = UUID::v4();
+    $sth->execute(array($newid, $_POST["parent"], $_POST["name"], "", 1, $_COOKIE["userid"], mTime()));
+    $respond = array("status" => 0, "message" => "");
+    if (!$sth || ($sth && $sth->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        $respond['status'] = 1;
+        $respond['message'] = $error[2];
+    }
 
-	$query="INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )  
+    $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )
 		VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
-	$sth = $PDO->prepare($query);
-	if($_POST["parent"]==0){
-		$level = 0;
-	}
-	else{
-		$level = 1;
-	}
-	$sth->execute(array($_COOKIE["userid"] ,$newid, 1 , $_POST["name"], $level ,1 ));
-	$respond=array("status"=>0,"message"=>"");
-	if (!$sth || ($sth && $sth->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	$respond['status']=1;
-	$respond['message']=$error[2];
-	}
+    $sth = $PDO->prepare($query);
+    if ($_POST["parent"] == 0) {
+        $level = 0;
+        $power = 0;
+    } else {
+        $level = 1;
+        $power = 1;
+    }
+    $sth->execute(array($_COOKIE["userid"], $newid, $power, $_POST["name"], $level, 1));
+    $respond = array("status" => 0, "message" => "");
+    if (!$sth || ($sth && $sth->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        $respond['status'] = 1;
+        $respond['message'] = $error[2];
+    }
 }
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);
-?>

+ 0 - 40
app/group/user_select_dlg.js

@@ -115,43 +115,3 @@ function username_search(keyword, type) {
 		);
 	}
 }
-
-function user_selected(id) {
-	$.post(
-		"../group/member_put.php",
-		{
-			userid: id,
-			groupid: gGroupId,
-		},
-		function (data) {
-			let error = JSON.parse(data);
-			if (error.status == 0) {
-				alert("ok");
-				user_select_cancel();
-				location.reload();
-			} else {
-				alert(error.message);
-			}
-		}
-	);
-}
-
-function user_select_new() {
-	$.post(
-		"../group/my_group_put.php",
-		{
-			name: $("#user_select_title").val(),
-			parent: parentid,
-		},
-		function (data) {
-			let error = JSON.parse(data);
-			if (error.status == 0) {
-				alert("ok");
-				user_select_cancel();
-				location.reload();
-			} else {
-				alert(error.message);
-			}
-		}
-	);
-}

+ 15 - 16
app/hostsetting/function.php

@@ -4,14 +4,16 @@ require_once '../path.php';
 class Hostsetting
 {
     public $dbh;
-    public function __construct() {
-        $dns = "sqlite:"._FILE_DB_HOSTSETTING_;
-        $this->dbh = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
-        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);  
+    public function __construct()
+    {
+        $dns = "" . _FILE_DB_HOSTSETTING_;
+        $this->dbh = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
+        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
     }
 
-    public function get($key){
-        if($this->dbh){
+    public function get($key)
+    {
+        if ($this->dbh) {
             $query = "SELECT value FROM setting WHERE key= ? ";
             $stmt = $this->dbh->prepare($query);
             $stmt->execute(array($key));
@@ -21,28 +23,25 @@ class Hostsetting
             } else {
                 return false;
             }
-        }
-        else{
+        } else {
             return false;
         }
     }
 
-    public function set($key,$value){
-        if($this->dbh){
+    public function set($key, $value)
+    {
+        if ($this->dbh) {
             $query = "UPDATE setting SET value = ?  WHERE key= ? ";
             $stmt = $this->dbh->prepare($query);
-            $stmt->execute(array($value,$key));
+            $stmt->execute(array($value, $key));
             if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                 $error = PDO_ErrorInfo();
                 return false;
-            }
-            else{
+            } else {
                 return true;
             }
-        }
-        else{
+        } else {
             return false;
         }
     }
 }
-?>

+ 62 - 65
app/install/db_create.php

@@ -10,8 +10,8 @@ require_once "install_head.php";
 <p><a href="index.php">Home</a></p>
 <?php
 include "./_pdo.php";
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_create.php" method="get">
 From: <input type="text" name="from"><br>
 To: <input type="text" name="to"><br>
@@ -22,85 +22,82 @@ Res: <input type="text" name="res"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
-$res=$_GET["res"];
-$filelist=array();
-$fileNums=0;
-$log="";
+$from = $_GET["from"];
+$to = $_GET["to"];
+$res = $_GET["res"];
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from - $to @ $res</h2>";
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
-
-$FileName=$filelist[$from][1].".htm";
-$fileId=$filelist[$from][0];
-$fileId=$filelist[$from][0];
-
-$dirLog=_DIR_LOG_."/";
 
-$dirDb="db/$res/";
-$inputFileName=$FileName;
-$outputFileNameHead=$filelist[$from][1];
-$bookId=$filelist[$from][2];
+$FileName = $filelist[$from][1] . ".htm";
+$fileId = $filelist[$from][0];
+$fileId = $filelist[$from][0];
 
-$dirXmlBase="xml/";
-$dirXml=$outputFileNameHead."/";
+$dirLog = _DIR_LOG_ . "/";
 
+$dirDb = "db/$res/";
+$inputFileName = $FileName;
+$outputFileNameHead = $filelist[$from][1];
+$bookId = $filelist[$from][2];
 
+$dirXmlBase = "xml/";
+$dirXml = $outputFileNameHead . "/";
 
 $xmlfile = $inputFileName;
-echo "doing:".$xmlfile."<br>";
-$log=$log."$from,$FileName,open\r\n";
+echo "doing:" . $xmlfile . "<br>";
+$log = $log . "$from,$FileName,open\r\n";
 
-$arrInserString=array();
-$db_file = $dirDb.$bookId."_".$res.".db3";
-PDO_Connect("sqlite:$db_file");
-switch($res){
-	case "translate":
-		$query="CREATE TABLE 'data' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'paragraph' INTEGER, 'language'  TEXT, 'anchor' TEXT, 'text' TEXT, 'author' TEXT, 'editor' TEXT, 'revision' TEXT, 'edition' INTEGER, 'subver' INTEGER,'time' DATETIME DEFAULT CURRENT_TIMESTAMP)";
-		break;
-	case "note":
-		$query="CREATE TABLE 'data' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'paragraph' INTEGER, 'language'  TEXT, 'anchor' TEXT, 'text' TEXT, 'author' TEXT, 'editor' TEXT, 'revision' TEXT, 'edition' INTEGER, 'subver' INTEGER,'time' DATETIME DEFAULT CURRENT_TIMESTAMP)";
-		break;
-	}
-	
-	$stmt = @PDO_Execute($query);
-    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
-        print_r($error[2]);
-        exit;
-    }
+$arrInserString = array();
+$db_file = $dirDb . $bookId . "_" . $res . ".db3";
+PDO_Connect("$db_file");
+switch ($res) {
+    case "translate":
+        $query = "CREATE TABLE 'data' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'paragraph' INTEGER, 'language'  TEXT, 'anchor' TEXT, 'text' TEXT, 'author' TEXT, 'editor' TEXT, 'revision' TEXT, 'edition' INTEGER, 'subver' INTEGER,'time' DATETIME DEFAULT CURRENT_TIMESTAMP)";
+        break;
+    case "note":
+        $query = "CREATE TABLE 'data' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , 'paragraph' INTEGER, 'language'  TEXT, 'anchor' TEXT, 'text' TEXT, 'author' TEXT, 'editor' TEXT, 'revision' TEXT, 'edition' INTEGER, 'subver' INTEGER,'time' DATETIME DEFAULT CURRENT_TIMESTAMP)";
+        break;
+}
 
-$query="CREATE INDEX 'search' ON \"data\" (\"paragraph\",\"language\",\"author\", \"editor\", \"revision\", \"edition\", \"subver\" , \"time\" )";
-    $stmt = @PDO_Execute($query);
-    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
-        print_r($error[2]);
-        $log=$log."$from, $FileName, error, $error[2] \r\n";
-    }
+$stmt = @PDO_Execute($query);
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    print_r($error[2]);
+    exit;
+}
 
+$query = "CREATE INDEX 'search' ON \"data\" (\"paragraph\",\"language\",\"author\", \"editor\", \"revision\", \"edition\", \"subver\" , \"time\" )";
+$stmt = @PDO_Execute($query);
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    print_r($error[2]);
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+}
 
-	
-	$myLogFile = fopen($dirLog."create_db.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
+$myLogFile = fopen($dirLog . "create_db.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 ?>
 
 
-<?php 
-if($from==$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_create.php?res=".$res."&from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+<?php
+if ($from == $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_create.php?res=" . $res . "&from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 117 - 121
app/install/db_insert_bold.php

@@ -15,8 +15,8 @@ require_once "install_head.php";
 include "./_pdo.php";
 include "../path.php";
 
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_insert_bold.php" method="get">
 From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
@@ -26,157 +26,153 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
-$filelist=array();
-$fileNums=0;
-$log="";
+$from = $_GET["from"];
+$to = $_GET["to"];
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from</h2>";
-function getWordEn($strIn){
-	$search  = array('ā', 'ī', 'ū', 'ṅ', 'ñ' , 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
-	$replace = array('a', 'i', 'u', 'n', 'n' , 't', 'd', 'n', 'l', 'm');
-	return(str_replace($search,$replace,$strIn));
+function getWordEn($strIn)
+{
+    $search = array('ā', 'ī', 'ū', 'ṅ', 'ñ', 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
+    $replace = array('a', 'i', 'u', 'n', 'n', 't', 'd', 'n', 'l', 'm');
+    return (str_replace($search, $replace, $strIn));
 }
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
 
-$FileName=$filelist[$from][1].".htm";
-$fileId=$filelist[$from][0];
-$fileId=$filelist[$from][0];
+$FileName = $filelist[$from][1] . ".htm";
+$fileId = $filelist[$from][0];
+$fileId = $filelist[$from][0];
 
-$dirLog=_DIR_LOG_;
+$dirLog = _DIR_LOG_;
 
 //输出文件夹
-$dirDb=_DIR_PALICANON_."/";
-$inputFileName=$FileName;
-$outputFileNameHead=$filelist[$from][1];
-$bookId=$filelist[$from][2];
-$vriParNum=0;
-$wordOrder=1;
-
-$dirXmlBase=_DIR_PALI_CSV_."/";
-$dirXml=$outputFileNameHead."/";
+$dirDb = _DIR_PALICANON_ . "/";
+$inputFileName = $FileName;
+$outputFileNameHead = $filelist[$from][1];
+$bookId = $filelist[$from][2];
+$vriParNum = 0;
+$wordOrder = 1;
 
-$currChapter="";
-$currParNum="";
-$arrAllWords[0]=array("id","wid","book","paragraph","word","real","type","gramma","mean","note","part","partmean","bmc","bmt","un","style","vri","sya","si","ka","pi","pa","kam");
-$g_wordCounter=0;
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
+$dirXml = $outputFileNameHead . "/";
 
+$currChapter = "";
+$currParNum = "";
+$arrAllWords[0] = array("id", "wid", "book", "paragraph", "word", "real", "type", "gramma", "mean", "note", "part", "partmean", "bmc", "bmt", "un", "style", "vri", "sya", "si", "ka", "pi", "pa", "kam");
+$g_wordCounter = 0;
 
-$arrUnPart[0]="word";
-$g_unPartCounter=-1;
+$arrUnPart[0] = "word";
+$g_unPartCounter = -1;
 
 /*去掉标点符号的统计*/
-$arrAllPaliWordsCount=array();
-$g_paliWordCounter=0;
-$g_wordCounterInSutta=0;
-$g_paliWordCountCounter=0;
-
+$arrAllPaliWordsCount = array();
+$g_paliWordCounter = 0;
+$g_wordCounterInSutta = 0;
+$g_paliWordCountCounter = 0;
 
 $xmlfile = $inputFileName;
-echo "doing:".$xmlfile."<br>";
-$log=$log."$from,$FileName,open\r\n";
+echo "doing:" . $xmlfile . "<br>";
+$log = $log . "$from,$FileName,open\r\n";
 
-$arrInserString=array();
+$arrInserString = array();
 $db_file = _FILE_DB_BOLD_;
-PDO_Connect("sqlite:$db_file");
+PDO_Connect("$db_file");
 
 // 打开文件并读取数据
-if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
-	while(($data=fgetcsv($fp,0,','))!==FALSE){
-		$params=$data;
-		$arrInserString[count($arrInserString)]=$params;
-	}
-	fclose($fp);
-	echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
-}
-else{
-	echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
+if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+    while (($data = fgetcsv($fp, 0, ',')) !== false) {
+        $params = $data;
+        $arrInserString[count($arrInserString)] = $params;
+    }
+    fclose($fp);
+    echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+} else {
+    echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
 }
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query="INSERT INTO bold ('id','book','paragraph','word','word2','word_en') VALUES (NULL,?,?,?,?,?)";
+$query = "INSERT INTO bold ('id','book','paragraph','word','word2','word_en') VALUES (NULL,?,?,?,?,?)";
 $stmt = $PDO->prepare($query);
-$allcount=1;
-$count=0;
-$count1=0;
-$sen="";
-$sen1="";
-$sen_en="";
-$sen_count=0;
-$book="";
-$paragraph="";
-foreach($arrInserString as $oneParam){
-	if($oneParam[15]=="bld" ){
-		if($oneParam[5]!=""){
-			$sen_count++;
-		}
-		$sen.=$oneParam[4]." ";
-		$sen1.=$oneParam[5]." ";
-		$book=substr($oneParam[2],1);
-		$paragraph=$oneParam[3];
-		if($oneParam[5]!=""){
-			$newWord=array($book,$paragraph,$oneParam[4],$oneParam[5],getWordEn($oneParam[5]));
-			$stmt->execute($newWord);
-			$count++;
-			$allcount++;
-		}
-	}
-	else{
-		if($sen_count>1){
-			$sen=rtrim($sen);
-			$sen1=rtrim($sen1);
-			$sen_en=getWordEn($sen1);			
-			$newWord=array($book,$paragraph,$sen,$sen1,$sen_en);
-			$stmt->execute($newWord);
-			$count1++;		
-			$allcount++;
-			$sen="";
-			$sen1="";
-			$sen_en="";			
-			$sen_count=0;
-		}
-		else{	
-			$sen="";
-			$sen1="";
-			$sen_en="";			
-			$sen_count=0;
-		}
-	}
+$allcount = 1;
+$count = 0;
+$count1 = 0;
+$sen = "";
+$sen1 = "";
+$sen_en = "";
+$sen_count = 0;
+$book = "";
+$paragraph = "";
+foreach ($arrInserString as $oneParam) {
+    if ($oneParam[15] == "bld") {
+        if ($oneParam[5] != "") {
+            $sen_count++;
+        }
+        $sen .= $oneParam[4] . " ";
+        $sen1 .= $oneParam[5] . " ";
+        $book = substr($oneParam[2], 1);
+        $paragraph = $oneParam[3];
+        if ($oneParam[5] != "") {
+            $newWord = array($book, $paragraph, $oneParam[4], $oneParam[5], getWordEn($oneParam[5]));
+            $stmt->execute($newWord);
+            $count++;
+            $allcount++;
+        }
+    } else {
+        if ($sen_count > 1) {
+            $sen = rtrim($sen);
+            $sen1 = rtrim($sen1);
+            $sen_en = getWordEn($sen1);
+            $newWord = array($book, $paragraph, $sen, $sen1, $sen_en);
+            $stmt->execute($newWord);
+            $count1++;
+            $allcount++;
+            $sen = "";
+            $sen1 = "";
+            $sen_en = "";
+            $sen_count = 0;
+        } else {
+            $sen = "";
+            $sen1 = "";
+            $sen_en = "";
+            $sen_count = 0;
+        }
+    }
 }
-// 提交更改 
+// 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	echo "error - $error[2] <br>";
-	
-	$log=$log."$from, $FileName, error, $error[2] \r\n";
-}
-else{
-	echo "updata $count-$count1 recorders.";
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+} else {
+    echo "updata $count-$count1 recorders.";
 }
 
-	$myLogFile = fopen($dirLog."insert_bold.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
+$myLogFile = fopen($dirLog . "insert_bold.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 ?>
 
 
-<?php 
-if($from==$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_bold.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+<?php
+if ($from == $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_insert_bold.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 58 - 62
app/install/db_insert_bookword_from_csv.php

@@ -10,8 +10,8 @@ require_once "install_head.php";
 <?php
 include "./_pdo.php";
 include "../path.php";
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_insert_bookword_from_csv.php" method="get">
 From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
@@ -21,81 +21,77 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
+$from = $_GET["from"];
+$to = $_GET["to"];
 
-$dirLog=_DIR_LOG_."/";
-$dirXmlBase=_DIR_PALI_CSV_."/";
+$dirLog = _DIR_LOG_ . "/";
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
 
-$filelist=array();
-$fileNums=0;
-$log="";
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>doing : No.{$from} book </h2>";
 
 global $dbh_word_index;
-$dns = "sqlite:"._FILE_DB_BOOK_WORD_;
-$dbh_word_index = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dns = "" . _FILE_DB_BOOK_WORD_;
+$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
 $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
-}
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
-
-    $bookword = array();
-    
-	if(($fpoutput=fopen(_DIR_CSV_PALI_CANON_WORD_."/{$from}_words.csv", "r"))!==FALSE){
-		$count=0;
-		while(($data=fgetcsv($fpoutput,0,','))!==FALSE){
-            $book = $data[1];
-            if(isset($bookword[$data[3]])){
-                $bookword[$data[3]]++;
-            }
-            else{
-                $bookword[$data[3]] = 1;
-            }
-			
-			$count++;
-		}        
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
     }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
+}
 
-		// 开始一个事务,关闭自动提交
-		$dbh_word_index->beginTransaction();
-		$query="INSERT INTO bookword ('book','wordindex','count') VALUES ( ? , ? , ?  )";
-		$stmt = $dbh_word_index->prepare($query);
+$bookword = array();
 
-        foreach ($bookword as $key => $value) {
-            $stmt->execute(array($book,$key,$value));
+if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_ . "/{$from}_words.csv", "r")) !== false) {
+    $count = 0;
+    while (($data = fgetcsv($fpoutput, 0, ',')) !== false) {
+        $book = $data[1];
+        if (isset($bookword[$data[3]])) {
+            $bookword[$data[3]]++;
+        } else {
+            $bookword[$data[3]] = 1;
         }
-		// 提交更改 
-		$dbh_word_index->commit();
-		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-			$error = $dbh_word_index->errorInfo();
-			echo "error - $error[2] <br>";
-			$log.="$from, $FileName, error, $error[2] \r\n";
-		}
-		else{
-			echo "updata $count recorders.<br />";
-			$log.="updata $count recorders.\r\n";
-		}		
-
 
+        $count++;
+    }
+}
 
-	$myLogFile = fopen($dirLog."insert_index.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
-	
+// 开始一个事务,关闭自动提交
+$dbh_word_index->beginTransaction();
+$query = "INSERT INTO bookword ('book','wordindex','count') VALUES ( ? , ? , ?  )";
+$stmt = $dbh_word_index->prepare($query);
 
-if($from>=$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
+foreach ($bookword as $key => $value) {
+    $stmt->execute(array($book, $key, $value));
+}
+// 提交更改
+$dbh_word_index->commit();
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = $dbh_word_index->errorInfo();
+    echo "error - $error[2] <br>";
+    $log .= "$from, $FileName, error, $error[2] \r\n";
+} else {
+    echo "updata $count recorders.<br />";
+    $log .= "updata $count recorders.\r\n";
 }
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_bookword_from_csv.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+
+$myLogFile = fopen($dirLog . "insert_index.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
+
+if ($from >= $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_insert_bookword_from_csv.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 258 - 279
app/install/db_insert_index.php

@@ -11,8 +11,8 @@ require_once "install_head.php";
 <?php
 include "./_pdo.php";
 include "../path.php";
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_insert_index.php" method="get">
 From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
@@ -22,318 +22,297 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
-
-
+$from = $_GET["from"];
+$to = $_GET["to"];
 
-$dirLog=_DIR_LOG_."/";
-$dirDb="db/";
-$dirXmlBase=_DIR_PALI_CSV_."/";
+$dirLog = _DIR_LOG_ . "/";
+$dirDb = "db/";
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
 
-$filelist=array();
-$fileNums=0;
-$log="";
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from</h2>";
 
 //已经存在的词
-$g_wordCounter=0;
-$g_wordIndexCounter=0;
-$iAllWordIndex=array();
-$sAllWord=array();
+$g_wordCounter = 0;
+$g_wordIndexCounter = 0;
+$iAllWordIndex = array();
+$sAllWord = array();
 //新加入的词
 $wordindex_max_index = 0;
 $aNewWordIndex = array(); //词内容
 $sNewWord = array(); //词头索引
 
 global $dbh_word_index;
-$dns = "sqlite:"._FILE_DB_WORD_INDEX_;
-$dbh_word_index = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dns = "" . _FILE_DB_WORD_INDEX_;
+$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
 $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 $query = "select id from wordindex where 1 order by id DESC ";
-	$stmt = $dbh_word_index->prepare($query);
-	$stmt->execute(array());
-	$id  = $stmt->fetch(PDO::FETCH_ASSOC);
-	if($id === FALSE){
-		$wordindex_max_index = 0;
-	}
-	else{
-		$wordindex_max_index =$id["id"];
-	}
-	$db_file = _FILE_DB_PALI_INDEX_;
-	PDO_Connect("sqlite:$db_file");
-	$query = "select id from word where 1 order by id DESC ";
-	$stmt = $PDO->prepare($query);
-	$stmt->execute(array());
-	$id  = $stmt->fetch(PDO::FETCH_ASSOC);	
-	if($id === FALSE){
-		$g_wordCounter = 0;
-	}
-	else{
-		$g_wordCounter = $id["id"];
-	}
-function dict_lookup($word){
-	global $dbh_word_index;
-	$query = "select * from wordindex where \"word\" = ? ";
-	$stmt = $dbh_word_index->prepare($query);
-	$stmt->execute(array($word));
-    return $stmt->fetch(PDO::FETCH_ASSOC);	
+$stmt = $dbh_word_index->prepare($query);
+$stmt->execute(array());
+$id = $stmt->fetch(PDO::FETCH_ASSOC);
+if ($id === false) {
+    $wordindex_max_index = 0;
+} else {
+    $wordindex_max_index = $id["id"];
 }
-
-function getWordEn($strIn){
-	$out=$strIn;
-	$out=str_replace("ā","a",$out);
-	$out=str_replace("ī","i",$out);
-	$out=str_replace("ū","u",$out);
-	$out=str_replace("ṅ","n",$out);
-	$out=str_replace("ñ","n",$out);
-	$out=str_replace("ṭ","t",$out);
-	$out=str_replace("ḍ","d",$out);
-	$out=str_replace("ṇ","n",$out);
-	$out=str_replace("ḷ","l",$out);
-	$out=str_replace("ṃ","m",$out);
-	return($out);
+$db_file = _FILE_DB_PALI_INDEX_;
+PDO_Connect("$db_file");
+$query = "select id from word where 1 order by id DESC ";
+$stmt = $PDO->prepare($query);
+$stmt->execute(array());
+$id = $stmt->fetch(PDO::FETCH_ASSOC);
+if ($id === false) {
+    $g_wordCounter = 0;
+} else {
+    $g_wordCounter = $id["id"];
+}
+function dict_lookup($word)
+{
+    global $dbh_word_index;
+    $query = "select * from wordindex where \"word\" = ? ";
+    $stmt = $dbh_word_index->prepare($query);
+    $stmt->execute(array($word));
+    return $stmt->fetch(PDO::FETCH_ASSOC);
 }
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+function getWordEn($strIn)
+{
+    $out = $strIn;
+    $out = str_replace("ā", "a", $out);
+    $out = str_replace("ī", "i", $out);
+    $out = str_replace("ū", "u", $out);
+    $out = str_replace("ṅ", "n", $out);
+    $out = str_replace("ñ", "n", $out);
+    $out = str_replace("ṭ", "t", $out);
+    $out = str_replace("ḍ", "d", $out);
+    $out = str_replace("ṇ", "n", $out);
+    $out = str_replace("ḷ", "l", $out);
+    $out = str_replace("ṃ", "m", $out);
+    return ($out);
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
 
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
+}
 
-	
 //for($iFile=$from;$iFile<=$to;$iFile++)
-$iFile=$from;
+$iFile = $from;
 {
 
-	$FileName=$filelist[$iFile][1].".htm";
-	$fileId=$filelist[$iFile][0];
-
-	$inputFileName=$FileName;
-	$outputFileNameHead=$filelist[$iFile][1];
-	$bookId=$filelist[$iFile][2];
-
-	$dirXml=$outputFileNameHead."/";
-
-	$xmlfile = $inputFileName;
-	echo "doing:".$xmlfile."<br>";
-	$log=$log."$iFile,$FileName,open\r\n";
-
-	$arrInserString=array();
-
-	// 打开文件并读取数据
-	$irow=0;
-	if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
-		while(($data=fgetcsv($fp,0,','))!==FALSE){
-			$irow++;
-			if($irow>1){
-				$params=$data;
-				$arrInserString[]=$params;
-			}
-		}
-		fclose($fp);
-		echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
-	}
-	else{
-		echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
-	}
-	
-
-	// 开始一个事务,关闭自动提交
-	$PDO->beginTransaction();
-	$query="INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
-	$stmt = $PDO->prepare($query);
-	$count=0;
-	$count1=0;
-	$sen="";
-	$sen1="";
-	$sen_en="";
-	$sen_count=0;
-	$book="";
-	$paragraph="";
-	foreach($arrInserString as $oneParam){
-		if($oneParam[5]!=""){
-			$g_wordCounter++;
-			$book=substr($oneParam[2],1);
-			$paragraph=$oneParam[3];
-			$word=$oneParam[5];
-			if($oneParam[15]=="bld" ){
-				$bold=1;
-			}
-			else{
-				$bold=0;
-			}			
-			
-			if(isset($sAllWord[$word])){
-				//已经存在的词
-				$wordindex=$sAllWord[$word];
-				
-				$iAllWordIndex[$wordindex][1]++;
-				if($bold==1){
-					$iAllWordIndex[$wordindex][3]++;
-				}
-				else{
-					$iAllWordIndex[$wordindex][2]++;
-				}
-				
-			}
-			else if(isset($sNewWord[$word])){
-				//是新家入的词
-				$wordindex=$sNewWord[$word];
-				
-				$aNewWordIndex[$wordindex][1]++;
-				if($bold==1){
-					$aNewWordIndex[$wordindex][3]++;
-				}
-				else{
-					$aNewWordIndex[$wordindex][2]++;
-				}
-			}
-			else if(($lookup=dict_lookup($word)) !== FALSE){
-				//在数据库中找到
-				$wordindex=$lookup["id"];
-				$sAllWord[$word]=$wordindex;
-				$iAllWordIndex[$wordindex][0]=$word;
-				
-				$iAllWordIndex[$wordindex][1]=$lookup["count"] + 1;//all word count
-				if($bold==1){
-					$iAllWordIndex[$wordindex][2] = $lookup["normal"] ;
-					$iAllWordIndex[$wordindex][3] = $lookup["bold"] + 1;
-				}
-				else{
-					$iAllWordIndex[$wordindex][2] = $lookup["normal"] + 1;
-					$iAllWordIndex[$wordindex][3] = $lookup["bold"] ;
-				}
-			}
-			else{
-				//数据库里也没找到 怎么办呢?我想呀想 想呀想
-				$wordindex=$wordindex_max_index + 1;
-				$sNewWord[$word]=$wordindex;
-				
-				$aNewWordIndex[$wordindex][0]=$word;
-				
-				$aNewWordIndex[$wordindex][1]=1;//all word count
-				if($bold==1){
-					$aNewWordIndex[$wordindex][2]=0;
-					$aNewWordIndex[$wordindex][3]=1;
-				}
-				else{
-					$aNewWordIndex[$wordindex][2]=1;
-					$aNewWordIndex[$wordindex][3]=0;
-				}
-				
-				$wordindex_max_index++;
-			}
-		
-	
-			$newWord=array($g_wordCounter,$book,$paragraph,$wordindex,$bold);
-			$stmt->execute($newWord);
-			$count++;
-		}
-
-	}
-	
-	// 提交更改 
-	$PDO->commit();
-	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
-		echo "error - $error[2] <br>";
-		$log.="$from, $FileName, error, $error[2] \r\n";
-	}
-	else{
-		echo "updata $count recorders.<br />";
-		$log.="updata $count recorders.\r\n";
-	}
+    $FileName = $filelist[$iFile][1] . ".htm";
+    $fileId = $filelist[$iFile][0];
+
+    $inputFileName = $FileName;
+    $outputFileNameHead = $filelist[$iFile][1];
+    $bookId = $filelist[$iFile][2];
+
+    $dirXml = $outputFileNameHead . "/";
+
+    $xmlfile = $inputFileName;
+    echo "doing:" . $xmlfile . "<br>";
+    $log = $log . "$iFile,$FileName,open\r\n";
+
+    $arrInserString = array();
+
+    // 打开文件并读取数据
+    $irow = 0;
+    if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+        while (($data = fgetcsv($fp, 0, ',')) !== false) {
+            $irow++;
+            if ($irow > 1) {
+                $params = $data;
+                $arrInserString[] = $params;
+            }
+        }
+        fclose($fp);
+        echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+    } else {
+        echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
+    }
+
+    // 开始一个事务,关闭自动提交
+    $PDO->beginTransaction();
+    $query = "INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
+    $stmt = $PDO->prepare($query);
+    $count = 0;
+    $count1 = 0;
+    $sen = "";
+    $sen1 = "";
+    $sen_en = "";
+    $sen_count = 0;
+    $book = "";
+    $paragraph = "";
+    foreach ($arrInserString as $oneParam) {
+        if ($oneParam[5] != "") {
+            $g_wordCounter++;
+            $book = substr($oneParam[2], 1);
+            $paragraph = $oneParam[3];
+            $word = $oneParam[5];
+            if ($oneParam[15] == "bld") {
+                $bold = 1;
+            } else {
+                $bold = 0;
+            }
+
+            if (isset($sAllWord[$word])) {
+                //已经存在的词
+                $wordindex = $sAllWord[$word];
+
+                $iAllWordIndex[$wordindex][1]++;
+                if ($bold == 1) {
+                    $iAllWordIndex[$wordindex][3]++;
+                } else {
+                    $iAllWordIndex[$wordindex][2]++;
+                }
+
+            } else if (isset($sNewWord[$word])) {
+                //是新家入的词
+                $wordindex = $sNewWord[$word];
+
+                $aNewWordIndex[$wordindex][1]++;
+                if ($bold == 1) {
+                    $aNewWordIndex[$wordindex][3]++;
+                } else {
+                    $aNewWordIndex[$wordindex][2]++;
+                }
+            } else if (($lookup = dict_lookup($word)) !== false) {
+                //在数据库中找到
+                $wordindex = $lookup["id"];
+                $sAllWord[$word] = $wordindex;
+                $iAllWordIndex[$wordindex][0] = $word;
+
+                $iAllWordIndex[$wordindex][1] = $lookup["count"] + 1; //all word count
+                if ($bold == 1) {
+                    $iAllWordIndex[$wordindex][2] = $lookup["normal"];
+                    $iAllWordIndex[$wordindex][3] = $lookup["bold"] + 1;
+                } else {
+                    $iAllWordIndex[$wordindex][2] = $lookup["normal"] + 1;
+                    $iAllWordIndex[$wordindex][3] = $lookup["bold"];
+                }
+            } else {
+                //数据库里也没找到 怎么办呢?我想呀想 想呀想
+                $wordindex = $wordindex_max_index + 1;
+                $sNewWord[$word] = $wordindex;
+
+                $aNewWordIndex[$wordindex][0] = $word;
+
+                $aNewWordIndex[$wordindex][1] = 1; //all word count
+                if ($bold == 1) {
+                    $aNewWordIndex[$wordindex][2] = 0;
+                    $aNewWordIndex[$wordindex][3] = 1;
+                } else {
+                    $aNewWordIndex[$wordindex][2] = 1;
+                    $aNewWordIndex[$wordindex][3] = 0;
+                }
+
+                $wordindex_max_index++;
+            }
+
+            $newWord = array($g_wordCounter, $book, $paragraph, $wordindex, $bold);
+            $stmt->execute($newWord);
+            $count++;
+        }
+
+    }
+
+    // 提交更改
+    $PDO->commit();
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        echo "error - $error[2] <br>";
+        $log .= "$from, $FileName, error, $error[2] \r\n";
+    } else {
+        echo "updata $count recorders.<br />";
+        $log .= "updata $count recorders.\r\n";
+    }
 
 }
 //更新单词索引表
 
 //首先插入新的词
-	// 开始一个事务,关闭自动提交
-	$dbh_word_index->beginTransaction();
-	$query="INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES ( ? , ? , ? , ? , ? , ? , ? , ? )";
-	$stmt = $dbh_word_index->prepare($query);
-	
-	echo "INSERT:".count($aNewWordIndex)."words<br>";
-	foreach($aNewWordIndex as $wIndex => $info){
-		$wordindex=$iword;
-		$newWord=array(
-								$wIndex,
-								$info[0],
-								getWordEn($info[0]),
-								$info[1],
-								$info[2],
-								$info[3],
-								0,
-								mb_strlen($info[0],"UTF-8")
-							);
-		$stmt->execute($newWord);
-	}
-	// 提交更改 
-	$dbh_word_index->commit();
-	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = $dbh_word_index->errorInfo();
-		echo "error - $error[2] <br>";
-		$log.="$from, $FileName, error, $error[2] \r\n";
-	}
-	else{
-		echo "updata iword recorders.<br />";
-		$log.="updata iword recorders.\r\n";
-	}
-	
+// 开始一个事务,关闭自动提交
+$dbh_word_index->beginTransaction();
+$query = "INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES ( ? , ? , ? , ? , ? , ? , ? , ? )";
+$stmt = $dbh_word_index->prepare($query);
+
+echo "INSERT:" . count($aNewWordIndex) . "words<br>";
+foreach ($aNewWordIndex as $wIndex => $info) {
+    $wordindex = $iword;
+    $newWord = array(
+        $wIndex,
+        $info[0],
+        getWordEn($info[0]),
+        $info[1],
+        $info[2],
+        $info[3],
+        0,
+        mb_strlen($info[0], "UTF-8"),
+    );
+    $stmt->execute($newWord);
+}
+// 提交更改
+$dbh_word_index->commit();
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = $dbh_word_index->errorInfo();
+    echo "error - $error[2] <br>";
+    $log .= "$from, $FileName, error, $error[2] \r\n";
+} else {
+    echo "updata iword recorders.<br />";
+    $log .= "updata iword recorders.\r\n";
+}
 
 //然后修改已经有的词
-	// 开始一个事务,关闭自动提交
-	$dbh_word_index->beginTransaction();
-	$query="UPDATE wordindex SET count = ? , normal = ? , bold = ?   where  id = ?  ";
-	$stmt = $dbh_word_index->prepare($query);
-	
-	echo "UPDATE:".count($iAllWordIndex)."words<br>";
-	foreach($iAllWordIndex as $wIndex => $info){
-		$wordindex=$iword;
-		$newWord=array(
-								$info[1],
-								$info[2],
-								$info[3],
-								$wIndex
-							);
-		$stmt->execute($newWord);
-	}
-	// 提交更改 
-	$dbh_word_index->commit();
-	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = $dbh_word_index->errorInfo();
-		echo "error - $error[2] <br>";
-		$log.="$from, $FileName, error, $error[2] \r\n";
-	}
-	else{
-		echo "updata iword recorders.<br />";
-		$log.="updata iword recorders.\r\n";
-	}
-
-
-
-	$myLogFile = fopen($dirLog."insert_index.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
-	
+// 开始一个事务,关闭自动提交
+$dbh_word_index->beginTransaction();
+$query = "UPDATE wordindex SET count = ? , normal = ? , bold = ?   where  id = ?  ";
+$stmt = $dbh_word_index->prepare($query);
+
+echo "UPDATE:" . count($iAllWordIndex) . "words<br>";
+foreach ($iAllWordIndex as $wIndex => $info) {
+    $wordindex = $iword;
+    $newWord = array(
+        $info[1],
+        $info[2],
+        $info[3],
+        $wIndex,
+    );
+    $stmt->execute($newWord);
+}
+// 提交更改
+$dbh_word_index->commit();
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = $dbh_word_index->errorInfo();
+    echo "error - $error[2] <br>";
+    $log .= "$from, $FileName, error, $error[2] \r\n";
+} else {
+    echo "updata iword recorders.<br />";
+    $log .= "updata iword recorders.\r\n";
+}
+
+$myLogFile = fopen($dirLog . "insert_index.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 
 ?>
 
 
-<?php 
+<?php
 
-if($from>=$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_index.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+if ($from >= $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_insert_index.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 193 - 207
app/install/db_insert_index_once.php

@@ -2,227 +2,213 @@
 require_once "install_head.php";
 include "./_pdo.php";
 
-if (PHP_SAPI  == "cli") {
-	echo $argc;
-	if($argc>=3){
-		$from=$argv[1];
-		$to=$argv[2];
-		echo "From: {$from} To:{$to}";
-	}
-	else if($argc>=1){
-		$from=0;
-		$to = 216;
-		echo "生成全部217本书";
-	}
-	else{
-		echo "参数错误";
-		exit;
-	}
-
-}
-else{
-	echo "<!DOCTYPE html><html><head></head>";
-	echo "<body><h2>Insert to Index</h2>";
-
-	if(isset($_GET["from"])==false){
-		echo '<form action="db_insert_index_once.php" method="get">';
-		echo 'From: <input type="text" name="from" value="0"><br>';
-		echo 'To: <input type="text" name="to" value="216"><br>';
-		echo '<input type="submit">';
-		echo '</form>';
-		exit;
-	}
-	else{
-		$from=$_GET["from"];
-		$to=$_GET["to"];
-	}
+if (PHP_SAPI == "cli") {
+    echo $argc;
+    if ($argc >= 3) {
+        $from = $argv[1];
+        $to = $argv[2];
+        echo "From: {$from} To:{$to}";
+    } else if ($argc >= 1) {
+        $from = 0;
+        $to = 216;
+        echo "生成全部217本书";
+    } else {
+        echo "参数错误";
+        exit;
+    }
+
+} else {
+    echo "<!DOCTYPE html><html><head></head>";
+    echo "<body><h2>Insert to Index</h2>";
+
+    if (isset($_GET["from"]) == false) {
+        echo '<form action="db_insert_index_once.php" method="get">';
+        echo 'From: <input type="text" name="from" value="0"><br>';
+        echo 'To: <input type="text" name="to" value="216"><br>';
+        echo '<input type="submit">';
+        echo '</form>';
+        exit;
+    } else {
+        $from = $_GET["from"];
+        $to = $_GET["to"];
+    }
 }
 
+$g_wordCounter = 0;
+$g_wordIndexCounter = 0;
+$iAllWordIndex = array();
+$sAllWord = array();
 
-$g_wordCounter=0;
-$g_wordIndexCounter=0;
-$iAllWordIndex=array();
-$sAllWord=array();
-
-$dirLog=_DIR_LOG_."/";
+$dirLog = _DIR_LOG_ . "/";
 
-$dirXmlBase=_DIR_PALI_CSV_."/";
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
 
-$filelist=array();
-$fileNums=0;
-$log="";
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from</h2>";
-function getWordEn($strIn){
-	$out=$strIn;
-	$out=str_replace("ā","a",$out);
-	$out=str_replace("ī","i",$out);
-	$out=str_replace("ū","u",$out);
-	$out=str_replace("ṅ","n",$out);
-	$out=str_replace("ñ","n",$out);
-	$out=str_replace("ṭ","t",$out);
-	$out=str_replace("ḍ","d",$out);
-	$out=str_replace("ṇ","n",$out);
-	$out=str_replace("ḷ","l",$out);
-	$out=str_replace("ṃ","m",$out);
-	return($out);
+function getWordEn($strIn)
+{
+    $out = $strIn;
+    $out = str_replace("ā", "a", $out);
+    $out = str_replace("ī", "i", $out);
+    $out = str_replace("ū", "u", $out);
+    $out = str_replace("ṅ", "n", $out);
+    $out = str_replace("ñ", "n", $out);
+    $out = str_replace("ṭ", "t", $out);
+    $out = str_replace("ḍ", "d", $out);
+    $out = str_replace("ṇ", "n", $out);
+    $out = str_replace("ḷ", "l", $out);
+    $out = str_replace("ṃ", "m", $out);
+    return ($out);
 }
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
+}
+
+$db_file = _FILE_DB_INDEX_;
+PDO_Connect("$db_file");
 
-	$db_file = _FILE_DB_INDEX_;
-	PDO_Connect("sqlite:$db_file");
-	
-for($iFile=$from;$iFile<=$to;$iFile++){
+for ($iFile = $from; $iFile <= $to; $iFile++) {
     echo "<h3>{$iFile}</h3>";
-	$FileName=$filelist[$iFile][1].".htm";
-	$fileId=$filelist[$iFile][0];
-
-	$inputFileName=$FileName;
-	$outputFileNameHead=$filelist[$iFile][1];
-	$bookId=$filelist[$iFile][2];
-
-	$dirXml=$outputFileNameHead."/";
-
-	$xmlfile = $inputFileName;
-	echo "doing:".$xmlfile."<br>";
-	$log=$log."$iFile,$FileName,open\r\n";
-
-	$arrInserString=array();
-
-
-	// 打开文件并读取数据
-	$irow=0;
-	if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
-		while(($data=fgetcsv($fp,0,','))!==FALSE){
-			$irow++;
-			if($irow>1){
-				$params=$data;
-				$arrInserString[count($arrInserString)]=$params;
-			}
-		}
-		fclose($fp);
-		echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
-	}
-	else{
-		echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
-	}
-	
-
-	// 开始一个事务,关闭自动提交
-	$PDO->beginTransaction();
-	$query="INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
-	$stmt = $PDO->prepare($query);
-	$count=0;
-	$count1=0;
-	$sen="";
-	$sen1="";
-	$sen_en="";
-	$sen_count=0;
-	$book="";
-	$paragraph="";
-	foreach($arrInserString as $oneParam){	
-		if($oneParam[5]!=""){
-			$g_wordCounter++;
-			$book=substr($oneParam[2],1);
-			$paragraph=$oneParam[3];
-			$word=$oneParam[5];
-			if($oneParam[15]=="bld" ){
-				$bold=1;
-			}
-			else{
-				$bold=0;
-			}			
-			
-			if(isset($sAllWord[$word])){
-				$wordindex=$sAllWord[$word];
-				
-				$iAllWordIndex[$wordindex][1]++;
-				if($bold==1){
-					$iAllWordIndex[$wordindex][3]++;
-				}
-				else{
-					$iAllWordIndex[$wordindex][2]++;
-				}
-				
-			}
-			else{
-				$wordindex=$g_wordIndexCounter;
-				$sAllWord[$word]=$g_wordIndexCounter;
-				
-				$iAllWordIndex[$g_wordIndexCounter][0]=$word;
-				
-				$iAllWordIndex[$g_wordIndexCounter][1]=1;//all word count
-				if($bold==1){
-					$iAllWordIndex[$g_wordIndexCounter][2]=0;
-					$iAllWordIndex[$g_wordIndexCounter][3]=1;
-				}
-				else{
-					$iAllWordIndex[$g_wordIndexCounter][2]=1;
-					$iAllWordIndex[$g_wordIndexCounter][3]=0;
-				}
-				
-				$g_wordIndexCounter++;
-			}
-		
-	
-			$newWord=array($g_wordCounter,$book,$paragraph,$wordindex,$bold);
-			$stmt->execute($newWord);
-			$count++;
-		}
-
-	}
-	
-	// 提交更改 
-	$PDO->commit();
-	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
-		echo "error - $error[2] <br>";
-		$log.="$from, $FileName, error, $error[2] \r\n";
-	}
-	else{
-		echo "updata $count recorders.<br />";
-		$log.="updata $count recorders.\r\n";
-	}
+    $FileName = $filelist[$iFile][1] . ".htm";
+    $fileId = $filelist[$iFile][0];
+
+    $inputFileName = $FileName;
+    $outputFileNameHead = $filelist[$iFile][1];
+    $bookId = $filelist[$iFile][2];
+
+    $dirXml = $outputFileNameHead . "/";
+
+    $xmlfile = $inputFileName;
+    echo "doing:" . $xmlfile . "<br>";
+    $log = $log . "$iFile,$FileName,open\r\n";
+
+    $arrInserString = array();
+
+    // 打开文件并读取数据
+    $irow = 0;
+    if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+        while (($data = fgetcsv($fp, 0, ',')) !== false) {
+            $irow++;
+            if ($irow > 1) {
+                $params = $data;
+                $arrInserString[count($arrInserString)] = $params;
+            }
+        }
+        fclose($fp);
+        echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+    } else {
+        echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
+    }
+
+    // 开始一个事务,关闭自动提交
+    $PDO->beginTransaction();
+    $query = "INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
+    $stmt = $PDO->prepare($query);
+    $count = 0;
+    $count1 = 0;
+    $sen = "";
+    $sen1 = "";
+    $sen_en = "";
+    $sen_count = 0;
+    $book = "";
+    $paragraph = "";
+    foreach ($arrInserString as $oneParam) {
+        if ($oneParam[5] != "") {
+            $g_wordCounter++;
+            $book = substr($oneParam[2], 1);
+            $paragraph = $oneParam[3];
+            $word = $oneParam[5];
+            if ($oneParam[15] == "bld") {
+                $bold = 1;
+            } else {
+                $bold = 0;
+            }
+
+            if (isset($sAllWord[$word])) {
+                $wordindex = $sAllWord[$word];
+
+                $iAllWordIndex[$wordindex][1]++;
+                if ($bold == 1) {
+                    $iAllWordIndex[$wordindex][3]++;
+                } else {
+                    $iAllWordIndex[$wordindex][2]++;
+                }
+
+            } else {
+                $wordindex = $g_wordIndexCounter;
+                $sAllWord[$word] = $g_wordIndexCounter;
+
+                $iAllWordIndex[$g_wordIndexCounter][0] = $word;
+
+                $iAllWordIndex[$g_wordIndexCounter][1] = 1; //all word count
+                if ($bold == 1) {
+                    $iAllWordIndex[$g_wordIndexCounter][2] = 0;
+                    $iAllWordIndex[$g_wordIndexCounter][3] = 1;
+                } else {
+                    $iAllWordIndex[$g_wordIndexCounter][2] = 1;
+                    $iAllWordIndex[$g_wordIndexCounter][3] = 0;
+                }
+
+                $g_wordIndexCounter++;
+            }
+
+            $newWord = array($g_wordCounter, $book, $paragraph, $wordindex, $bold);
+            $stmt->execute($newWord);
+            $count++;
+        }
+
+    }
+
+    // 提交更改
+    $PDO->commit();
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+        $error = PDO_ErrorInfo();
+        echo "error - $error[2] <br>";
+        $log .= "$from, $FileName, error, $error[2] \r\n";
+    } else {
+        echo "updata $count recorders.<br />";
+        $log .= "updata $count recorders.\r\n";
+    }
 
 }
 
-	// 开始一个事务,关闭自动提交
-	$PDO->beginTransaction();
-	$query="INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
-	$stmt = $PDO->prepare($query);
-	
-	echo count($iAllWordIndex)."words<br>";
-	for($iword=0;$iword<count($iAllWordIndex);$iword++){
-		$wordindex=$iword;
-		$newWord=array($wordindex,$iAllWordIndex[$iword][0],getWordEn($iAllWordIndex[$iword][0]),$iAllWordIndex[$iword][1],$iAllWordIndex[$iword][2],$iAllWordIndex[$iword][3],0,mb_strlen($iAllWordIndex[$iword][0],"UTF-8"));
-		//echo "<br>{$newWord[0]}-{$newWord[1]}-{$newWord[2]}-{$newWord[3]}-{$newWord[4]}-{$newWord[5]}-<br />";
-		$stmt->execute($newWord);
-	}
-
-	
-	// 提交更改 
-	$PDO->commit();
-	if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-		$error = PDO_ErrorInfo();
-		echo "error - $error[2] <br>";
-		$log.="$from, $FileName, error, $error[2] \r\n";
-	}
-	else{
-		echo "updata iword recorders.<br />";
-		$log.="updata iword recorders.\r\n";
-	}			
-	
-	$myLogFile = fopen($dirLog."insert_index.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
-	
-	
-	echo "<h2>齐活!功德无量!all done!</h2>";	
+// 开始一个事务,关闭自动提交
+$PDO->beginTransaction();
+$query = "INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
+$stmt = $PDO->prepare($query);
+
+echo count($iAllWordIndex) . "words<br>";
+for ($iword = 0; $iword < count($iAllWordIndex); $iword++) {
+    $wordindex = $iword;
+    $newWord = array($wordindex, $iAllWordIndex[$iword][0], getWordEn($iAllWordIndex[$iword][0]), $iAllWordIndex[$iword][1], $iAllWordIndex[$iword][2], $iAllWordIndex[$iword][3], 0, mb_strlen($iAllWordIndex[$iword][0], "UTF-8"));
+    //echo "<br>{$newWord[0]}-{$newWord[1]}-{$newWord[2]}-{$newWord[3]}-{$newWord[4]}-{$newWord[5]}-<br />";
+    $stmt->execute($newWord);
+}
+
+// 提交更改
+$PDO->commit();
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+    $log .= "$from, $FileName, error, $error[2] \r\n";
+} else {
+    echo "updata iword recorders.<br />";
+    $log .= "updata iword recorders.\r\n";
+}
+
+$myLogFile = fopen($dirLog . "insert_index.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
+
+echo "<h2>齐活!功德无量!all done!</h2>";
 ?>
 
 

+ 116 - 123
app/install/db_insert_page_index.php

@@ -3,139 +3,132 @@
 require_once "./_pdo.php";
 require_once "../path.php";
 
-if (PHP_SAPI  == "cli") {
-	echo $argc;
-	if($argc>=3){
-		$from=$argv[1];
-		$to=$argv[2];
-		echo "From: {$from} To:{$to}";
-	}
-	else if($argc>=1){
-		$from=0;
-		$to = 216;
-		echo "生成全部217本书";
-	}
-	else{
-		echo "参数错误";
-		exit;
-	}
-
-}
-else{
-	echo "<!DOCTYPE html><html><head></head>";
-	echo "<body><h2>Insert to Index</h2>";
-
-	if(isset($_GET["from"])==false){
-		echo '<form action="db_insert_index_once.php" method="get">';
-		echo 'From: <input type="text" name="from" value="0"><br>';
-		echo 'To: <input type="text" name="to" value="216"><br>';
-		echo '<input type="submit">';
-		echo '</form>';
-		exit;
-	}
-	else{
-		$from=$_GET["from"];
-		$to=$_GET["to"];
-	}
+if (PHP_SAPI == "cli") {
+    echo $argc;
+    if ($argc >= 3) {
+        $from = $argv[1];
+        $to = $argv[2];
+        echo "From: {$from} To:{$to}";
+    } else if ($argc >= 1) {
+        $from = 0;
+        $to = 216;
+        echo "生成全部217本书";
+    } else {
+        echo "参数错误";
+        exit;
+    }
+
+} else {
+    echo "<!DOCTYPE html><html><head></head>";
+    echo "<body><h2>Insert to Index</h2>";
+
+    if (isset($_GET["from"]) == false) {
+        echo '<form action="db_insert_index_once.php" method="get">';
+        echo 'From: <input type="text" name="from" value="0"><br>';
+        echo 'To: <input type="text" name="to" value="216"><br>';
+        echo '<input type="submit">';
+        echo '</form>';
+        exit;
+    } else {
+        $from = $_GET["from"];
+        $to = $_GET["to"];
+    }
 }
 
+$g_wordCounter = 0;
+$g_wordIndexCounter = 0;
+$iAllWordIndex = array();
+$sAllWord = array();
 
-$g_wordCounter=0;
-$g_wordIndexCounter=0;
-$iAllWordIndex=array();
-$sAllWord=array();
-
-$dirLog=_DIR_LOG_."/";
+$dirLog = _DIR_LOG_ . "/";
 
-$dirXmlBase=_DIR_PALI_CSV_."/";
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
 
-$filelist=array();
-$fileNums=0;
-$log="";
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "\n <h2>$from</h2>";
 
-
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
-	
-for($iFile=$from;$iFile<=$to;$iFile++){
+
+for ($iFile = $from; $iFile <= $to; $iFile++) {
     echo "<h3>{$iFile}</h3>";
-	$FileName=$filelist[$iFile][1].".htm";
-	$fileId=$filelist[$iFile][0];
-
-	$inputFileName=$FileName;
-	$outputFileNameHead=$filelist[$iFile][1];
-	$bookId=$filelist[$iFile][2];
-
-	$dirXml=$outputFileNameHead."/";
-
-	$xmlfile = $inputFileName;
-	echo "doing:".$xmlfile."<br>";
-	$log=$log."$iFile,$FileName,open\r\n";
-
-	$arrInserString=array();
-
-	$db_file = _FILE_DB_PAGE_INDEX_;
-	PDO_Connect("sqlite:$db_file");
-	// 打开文件并读取数据
-	$irow=0;
-	if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
-		// 开始一个事务,关闭自动提交
-		$PDO->beginTransaction();
-		$query="INSERT INTO m ('book','para','page1','page2') VALUES (?,?,?,?)";
-		$stmt = $PDO->prepare($query);
-
-		$currPage=array(0,0);
-		$currPara = 0;
-		while(($data=fgetcsv($fp,0,','))!==FALSE){
-			$irow++;
-			if($irow>1){
-				if($data[6]==".ctl." && mb_substr($data[5],0,1,"UTF-8")=="M"){
-					$sPage= mb_substr($data[5],1,6,"UTF-8");
-					$aPage = explode(".",$sPage);
-					if(count($aPage)==2){
-						$currPage = $aPage;
-					}
-					else{
-						echo "错误的页码: {$data[5]} \n ";
-					}
-				}
-				$para = $data[3];
-				if($currPara!=$data[3]){
-					$currPara=(int)$data[3];
-					$book = mb_substr($data[2],1, null ,"UTF-8");
-					$para = $currPara;
-					$page1 = $currPage[0];
-					$page2 = $currPage[1];
-					$stmt->execute(array($book,$para,$page1,$page2));
-				}
-			}
-				
-		}
-
-		// 提交更改 
-		$PDO->commit();
-		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-			$error = PDO_ErrorInfo();
-			echo "error - $error[2] <br>";
-			$log.="$from, $FileName, error, $error[2] \r\n";
-		}
-		else{
-			echo "updata  recorders.<br />";
-			$log.="updata  recorders.\r\n";
-		}
-		fclose($fp);
-		echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>\n";
-	}
-	else{
-		echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
-	}
+    $FileName = $filelist[$iFile][1] . ".htm";
+    $fileId = $filelist[$iFile][0];
+
+    $inputFileName = $FileName;
+    $outputFileNameHead = $filelist[$iFile][1];
+    $bookId = $filelist[$iFile][2];
+
+    $dirXml = $outputFileNameHead . "/";
+
+    $xmlfile = $inputFileName;
+    echo "doing:" . $xmlfile . "<br>";
+    $log = $log . "$iFile,$FileName,open\r\n";
+
+    $arrInserString = array();
+
+    $db_file = _FILE_DB_PAGE_INDEX_;
+    PDO_Connect("$db_file");
+    // 打开文件并读取数据
+    $irow = 0;
+    if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+        // 开始一个事务,关闭自动提交
+        $PDO->beginTransaction();
+        $query = "INSERT INTO m ('book','para','page1','page2') VALUES (?,?,?,?)";
+        $stmt = $PDO->prepare($query);
+
+        $currPage = array(0, 0);
+        $currPara = 0;
+        while (($data = fgetcsv($fp, 0, ',')) !== false) {
+            $irow++;
+            if ($irow > 1) {
+                if ($data[6] == ".ctl." && mb_substr($data[5], 0, 1, "UTF-8") == "M") {
+                    $sPage = mb_substr($data[5], 1, 6, "UTF-8");
+                    $aPage = explode(".", $sPage);
+                    if (count($aPage) == 2) {
+                        $currPage = $aPage;
+                    } else {
+                        echo "错误的页码: {$data[5]} \n ";
+                    }
+                }
+                $para = $data[3];
+                if ($currPara != $data[3]) {
+                    $currPara = (int) $data[3];
+                    $book = mb_substr($data[2], 1, null, "UTF-8");
+                    $para = $currPara;
+                    $page1 = $currPage[0];
+                    $page2 = $currPage[1];
+                    $stmt->execute(array($book, $para, $page1, $page2));
+                }
+            }
+
+        }
+
+        // 提交更改
+        $PDO->commit();
+        if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+            $error = PDO_ErrorInfo();
+            echo "error - $error[2] <br>";
+            $log .= "$from, $FileName, error, $error[2] \r\n";
+        } else {
+            echo "updata  recorders.<br />";
+            $log .= "updata  recorders.\r\n";
+        }
+        fclose($fp);
+        echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>\n";
+    } else {
+        echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
+    }
 }
-	echo "齐活!功德无量!all done!";	
+echo "齐活!功德无量!all done!";
 ?>
 
 

+ 88 - 95
app/install/db_insert_palitext.php

@@ -11,8 +11,8 @@ require_once "install_head.php";
 <?php
 require_once "./_pdo.php";
 require_once "../path.php";
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_insert_palitext.php" method="get">
 From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
@@ -22,129 +22,122 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
-$filelist=array();
-$fileNums=0;
-$log="";
+$from = $_GET["from"];
+$to = $_GET["to"];
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from</h2>";
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
-
-$FileName=$filelist[$from][1].".htm";
-$fileId=$filelist[$from][0];
-$fileId=$filelist[$from][0];
-
-$dirLog=_DIR_LOG_."/";
 
-$inputFileName=$FileName;
-$outputFileNameHead=$filelist[$from][1];
-$bookId=$filelist[$from][2];
-$vriParNum=0;
-$wordOrder=1;
+$FileName = $filelist[$from][1] . ".htm";
+$fileId = $filelist[$from][0];
+$fileId = $filelist[$from][0];
 
-$dirXmlBase=_DIR_PALI_CSV_."/";
-$dirPaliTextBase=_DIR_PALI_HTML_."/";
-$dirXml=$outputFileNameHead."/";
+$dirLog = _DIR_LOG_ . "/";
 
+$inputFileName = $FileName;
+$outputFileNameHead = $filelist[$from][1];
+$bookId = $filelist[$from][2];
+$vriParNum = 0;
+$wordOrder = 1;
 
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
+$dirPaliTextBase = _DIR_PALI_HTML_ . "/";
+$dirXml = $outputFileNameHead . "/";
 
 $xmlfile = $inputFileName;
-echo "doing:".$xmlfile."<br>";
-$log=$log."$from,$FileName,open\r\n";
+echo "doing:" . $xmlfile . "<br>";
+$log = $log . "$from,$FileName,open\r\n";
 
-$arrInserString=array();
-$db_file =_FILE_DB_PALITEXT_;
-PDO_Connect("sqlite:$db_file");
+$arrInserString = array();
+$db_file = _FILE_DB_PALITEXT_;
+PDO_Connect("$db_file");
 
 // 打开vri html文件并读取数据
-$pali_text_array=array();
-if(($fpPaliText=fopen($dirPaliTextBase.$xmlfile, "r"))!==FALSE){
-	while(($data=fgets($fpPaliText))!==FALSE){
-		if(  substr($data,0,2) === "<p" ){
-			array_push($pali_text_array,$data);
-		}
-		
-	}
-	fclose($fpPaliText);
-	echo "pali text load:".$dirPaliTextBase.$xmlfile."<br>";
-}
-else{
-	echo "can not pali text file. filename=".$dirPaliTextBase.$xmlfile;
+$pali_text_array = array();
+if (($fpPaliText = fopen($dirPaliTextBase . $xmlfile, "r")) !== false) {
+    while (($data = fgets($fpPaliText)) !== false) {
+        if (substr($data, 0, 2) === "<p") {
+            array_push($pali_text_array, $data);
+        }
+
+    }
+    fclose($fpPaliText);
+    echo "pali text load:" . $dirPaliTextBase . $xmlfile . "<br>";
+} else {
+    echo "can not pali text file. filename=" . $dirPaliTextBase . $xmlfile;
 }
 
-$inputRow=0;
-if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead."_pali.csv", "r"))!==FALSE){
-	while(($data=fgetcsv($fp , 0 , ',' )) !== FALSE ){
-		if($inputRow>0){
-			if(($inputRow-1)<count($pali_text_array)){
-				$data[5]=$pali_text_array[$inputRow-1];
-			}
-			$arrInserString[]=$data;
-		}
-		$inputRow++;
-	}
-	fclose($fp);
-	echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
-}
-else{
-	echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
+$inputRow = 0;
+if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . "_pali.csv", "r")) !== false) {
+    while (($data = fgetcsv($fp, 0, ',')) !== false) {
+        if ($inputRow > 0) {
+            if (($inputRow - 1) < count($pali_text_array)) {
+                $data[5] = $pali_text_array[$inputRow - 1];
+            }
+            $arrInserString[] = $data;
+        }
+        $inputRow++;
+    }
+    fclose($fp);
+    echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+} else {
+    echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
 }
 
-if(($inputRow-1)!=count($pali_text_array)){
-$log=$log."$from, $FileName,error,文件行数不匹配 inputRow=$inputRow pali_text_array=".count($pali_text_array)." \r\n";
+if (($inputRow - 1) != count($pali_text_array)) {
+    $log = $log . "$from, $FileName,error,文件行数不匹配 inputRow=$inputRow pali_text_array=" . count($pali_text_array) . " \r\n";
 }
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
 
-$query="INSERT INTO pali_text ('id', 'book','paragraph','level','class','toc','text','html','lenght') VALUES (NULL, ? , ? , ? , ? , ? , ? , ?,? )";
+$query = "INSERT INTO pali_text ('id', 'book','paragraph','level','class','toc','text','html','lenght') VALUES (NULL, ? , ? , ? , ? , ? , ? , ?,? )";
 $stmt = $PDO->prepare($query);
-foreach($arrInserString as $oneParam){
-	if($oneParam[3]<100){
-		$toc = $oneParam[6];
-	}
-	else{
-		$toc = "";
-	}
-	$newData=array($from+1, $oneParam[2], $oneParam[3], $oneParam[4], $toc , $oneParam[6], $oneParam[5], mb_strlen($oneParam[6],"UTF-8"));
-	$stmt->execute($newData);
+foreach ($arrInserString as $oneParam) {
+    if ($oneParam[3] < 100) {
+        $toc = $oneParam[6];
+    } else {
+        $toc = "";
+    }
+    $newData = array($from + 1, $oneParam[2], $oneParam[3], $oneParam[4], $toc, $oneParam[6], $oneParam[5], mb_strlen($oneParam[6], "UTF-8"));
+    $stmt->execute($newData);
 }
-// 提交更改 
+// 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	echo "error - $error[2] <br>";
-	
-	$log=$log."$from, $FileName, error, $error[2] \r\n";
-}
-else{
-	$count=count($arrInserString);
-	echo "updata $count recorders.";
-}
-
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
 
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+} else {
+    $count = count($arrInserString);
+    echo "updata $count recorders.";
+}
 
-	$myLogFile = fopen($dirLog."db_insert_palitext.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
+$myLogFile = fopen($dirLog . "db_insert_palitext.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 ?>
 
 
-<?php 
-if($from==$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_palitext.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+<?php
+if ($from == $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_insert_palitext.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 298 - 317
app/install/db_insert_sentence.php

@@ -13,10 +13,10 @@ require_once "install_head.php";
 include "./_pdo.php";
 require_once '../path.php';
 
-$db_file =_FILE_DB_PALI_SENTENCE_;
-$thisfile = '.'.mb_substr(__FILE__,mb_strlen(__DIR__));
-if(isset($_GET["from"])==false){
-?>
+$db_file = _FILE_DB_PALI_SENTENCE_;
+$thisfile = '.' . mb_substr(__FILE__, mb_strlen(__DIR__));
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="<?php echo $thisfile; ?>" method="get">
 From: <input type="text" value="0" name="from"><br>
 To: <input type="text" value="216" name="to"><br>
@@ -24,357 +24,338 @@ To: <input type="text" value="216" name="to"><br>
 </form>
 <?php
 
-return;
+    return;
 }
-function wordStyle($word,$style){
-	switch ($style) {
-		case 'bld':
-			# bold form
-			# 不包含字符{ }
-			if(mb_strpos($word,'{',0,"UTF-8")===FALSE){
-				return "<b>".$word."</b> ";
-			}
-			else{
-				$word = str_replace("{","<b>",$word);
-				$word = str_replace("}","</b>",$word);
-				return $word;
-			}
-			break;
-
-		case 'note':
-				# vir note...
-				return "<note>".$word."</note>";
-			break;
-		case 'paranum':
-				# vir note...
-				return "<paranum>".$word."</paranum>";
-			break;
-
-		default:
-			# code...
-			return $word;
-			break;
-	}
+function wordStyle($word, $style)
+{
+    switch ($style) {
+        case 'bld':
+            # bold form
+            # 不包含字符{ }
+            if (mb_strpos($word, '{', 0, "UTF-8") === false) {
+                return "<b>" . $word . "</b> ";
+            } else {
+                $word = str_replace("{", "<b>", $word);
+                $word = str_replace("}", "</b>", $word);
+                return $word;
+            }
+            break;
+
+        case 'note':
+            # vir note...
+            return "<note>" . $word . "</note>";
+            break;
+        case 'paranum':
+            # vir note...
+            return "<paranum>" . $word . "</paranum>";
+            break;
+
+        default:
+            # code...
+            return $word;
+            break;
+    }
 }
 
-
-$from=$_GET["from"];
-$to=$_GET["to"];
-$filelist=array();
-$fileNums=0;
-$log="";
+$from = $_GET["from"];
+$to = $_GET["to"];
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from-$to</h2>";
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to>=$fileNums) $to=$fileNums-1;
 
-$FileName=$filelist[$from][1].".htm";
-$fileId=$filelist[$from][0];
-$fileId=$filelist[$from][0];
+$FileName = $filelist[$from][1] . ".htm";
+$fileId = $filelist[$from][0];
+$fileId = $filelist[$from][0];
 
-$dirLog=_DIR_LOG_."/";
+$dirLog = _DIR_LOG_ . "/";
 
-$dirDb="db/";
-$inputFileName=$FileName;
-$outputFileNameHead=$filelist[$from][1];
-$bookId=$filelist[$from][2];
-$vriParNum=0;
-$wordOrder=1;
+$dirDb = "db/";
+$inputFileName = $FileName;
+$outputFileNameHead = $filelist[$from][1];
+$bookId = $filelist[$from][2];
+$vriParNum = 0;
+$wordOrder = 1;
 
-$dirXmlBase=_DIR_PALI_CSV_."/";
-$dirXml=$outputFileNameHead."/";
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
+$dirXml = $outputFileNameHead . "/";
 
-$currChapter="";
-$currParNum="";
-$arrAllWords[0]=array("id","wid","book","paragraph","word","real","type","gramma","mean","note","part","partmean","bmc","bmt","un","style","vri","sya","si","ka","pi","pa","kam");
-$g_wordCounter=0;
+$currChapter = "";
+$currParNum = "";
+$arrAllWords[0] = array("id", "wid", "book", "paragraph", "word", "real", "type", "gramma", "mean", "note", "part", "partmean", "bmc", "bmt", "un", "style", "vri", "sya", "si", "ka", "pi", "pa", "kam");
+$g_wordCounter = 0;
 
-$arrUnWords[0]=array("id","word","type","gramma","parent","mean","note","part","partmean","cf","state","delete","tag","len");
-$g_unWordCounter=0;
+$arrUnWords[0] = array("id", "word", "type", "gramma", "parent", "mean", "note", "part", "partmean", "cf", "state", "delete", "tag", "len");
+$g_unWordCounter = 0;
 
-$arrUnPart[0]="word";
-$g_unPartCounter=-1;
+$arrUnPart[0] = "word";
+$g_unPartCounter = -1;
 
 /*去掉标点符号的统计*/
-$arrAllPaliWordsCount=array();
-$g_paliWordCounter=0;
-$g_wordCounterInSutta=0;
-$g_paliWordCountCounter=0;
-
+$arrAllPaliWordsCount = array();
+$g_paliWordCounter = 0;
+$g_wordCounterInSutta = 0;
+$g_paliWordCountCounter = 0;
 
 $xmlfile = $inputFileName;
-echo "doing:".$xmlfile."<br>";
-$log=$log."$from,$FileName,open\r\n";
+echo "doing:" . $xmlfile . "<br>";
+$log = $log . "$from,$FileName,open\r\n";
 
-$arrInserString=array();
+$arrInserString = array();
 
-function getWordEn($strIn){
-	$search  = array('ā', 'ī', 'ū', 'ṅ', 'ñ' , 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
-	$replace = array('a', 'i', 'u', 'n', 'n' , 't', 'd', 'n', 'l', 'm');
-	return(str_replace($search,$replace,$strIn));
+function getWordEn($strIn)
+{
+    $search = array('ā', 'ī', 'ū', 'ṅ', 'ñ', 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
+    $replace = array('a', 'i', 'u', 'n', 'n', 't', 'd', 'n', 'l', 'm');
+    return (str_replace($search, $replace, $strIn));
 }
 
-
-
 // 打开文件并读取数据
-$iWord=0;
-$pre=null;
-$curr=null;
-$next=null;
-$wordlist=array();
-$arrSent=array();
-$book=0;
-$sent_html="";
-
-if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
-	while(($data=fgetcsv($fp))!==FALSE){
-		//id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
-		//$data = mb_split(",",$data);
-		
-		$wordlist[]=$data;
-		if($book==0){
-			$book=substr($data[2],1);
-		}
-
-	}
-	fclose($fp);
-	
-	$iWord=0;
-	$iCurrPara=0;
-	$Note_Mark=0;
-	if($wordlist[1][6] != ".ctl."){
-		$sent=$wordlist[1][4]." ";
-		$sent_html=wordStyle($wordlist[1][4],$wordlist[1][15])." ";
-		$sent_real=$wordlist[1][5];
-		$wordcount=1;
-	}
-	else{
-		$sent="";
-		$sent_html="";
-		$sent_real="";
-		$wordcount=0;
-	}
-	$begin=1;
-	$end=1;
-	$iSent=0;
-	$Note_Mark1=0;
-	$Note_Mark2=0;
-	$Note_Mark = 0;
-	$wordcount=0;
-	for($i=1;$i<count($wordlist);$i++){
-		if($wordlist[$i][3]>$iCurrPara){
-			//echo  "new paragraph<br>";
-			$iWord=0;
-			if($i>1){
-				//echo "上一段结束<br>";
-				if(strlen(trim($sent))>0){
-					$end = $wordlist[$i-1][16];
-					$arrSent[]=array($book,$iCurrPara,$begin,$end,mb_strlen(trim($sent_real),"UTF-8"),$wordcount,$sent,$sent_html,trim($sent_real),getWordEn($sent_real));
-					//echo "end={$end}<br>";
-					//echo "<div>[{$iCurrPara}-{$begin}-{$end}]({$wordcount})<br>{$sent}<br>{$sent_real}<br>".getWordEn($sent_real)."</div>";
-				}
-				$iCurrPara=$wordlist[$i][3];
-
-				$Note_Mark1=0;
-				$Note_Mark2=0;
-				$Note_Mark = 0;
-	
-				$pre=$wordlist[$i-1];
-				$curr=$wordlist[$i];
-				if($i<count($wordlist)-1){
-					$next=$wordlist[$i+1];
-				}
-				else{
-					$next="";
-				}
-	
-				if($next[4]=="(" || $curr[4]=="("){
-					$Note_Mark1=1;
-				}
-				else if($pre[4]==")" && $Note_Mark1==1){
-					$Note_Mark1=0;
-				}
-		
-				if($next[4]=="[" || $curr[4]=="["){
-					$Note_Mark2=1;
-				}
-				else if($pre[4]=="]" && $Note_Mark2==1){
-					$Note_Mark2=0;
-				}
-				$Note_Mark = $Note_Mark1+$Note_Mark2;
-				//下一段开始
-				if($wordlist[$i][6] != ".ctl."){
-					$sent=$wordlist[$i][4]." ";
-					$sent_html=wordStyle($wordlist[$i][4],$wordlist[$i][15])." ";
-					if($wordlist[$i][5]=='"'){
-						$sent_real="";
-					}
-					else{
-						$sent_real=$wordlist[$i][5];
-					}
-					$wordcount=1;
-				}
-				else{
-					$sent="";
-					$sent_html="";
-					$sent_real="";
-					$wordcount=0;
-				}
-				$begin = $wordlist[$i][16];
-				
-				$iSent++;
-				
-				
-				continue;
-			}
-			$iCurrPara=$wordlist[$i][3];
-		}
-		$isEndOfSen=false;
-		if($i<count($wordlist)-1){
-			$pre=$wordlist[$i-1];
-			$curr=$wordlist[$i];
-			if($i<count($wordlist)-1){
-				$next=$wordlist[$i+1];
-			}
-			else{
-				$next="";
-			}
-
-			if($next[4]=="("){
-				$Note_Mark1=1;
-			}
-			else if($pre[4]==")" && $Note_Mark1==1){
-				$Note_Mark1=0;
-			}
-	
-			if($next[4]=="["){
-				$Note_Mark2=1;
-			}
-			else if($pre[4]=="]" && $Note_Mark2==1){
-				$Note_Mark2=0;
-			}
-			$Note_Mark = $Note_Mark1+$Note_Mark2;
-
-			if($curr[15] != "note" || mb_substr($curr[1],0,5,"UTF-8") != "gatha"){
-				if($curr[4] == "."  && !is_numeric($pre[4]) && $next[3]==$iCurrPara && $Note_Mark===0){
-					//以.結尾且非註釋
-					if($next[4] != "("){
-						$isEndOfSen=true;
-					}
-				}
-				else if($curr[4]=="–"  && $next[4]=="‘"  && $Note_Mark===0){
-					$isEndOfSen=true;
-				}
-				else if($Note_Mark == 0){
-					//以!或?或;結尾
-					if($curr[4]=="!"){
-						if($next[4]!="!"){
-							if($next[4]!="("){
-								$isEndOfSen=true;
-							}
-						}
-					}
-					else if($curr[4]==";" || $curr[4]=="?"){
-						if($next[4] != "("){
-							$isEndOfSen=true;
-						}
-					}
-				}
-			}
-		}
-
-			if($curr[6] != ".ctl."){
-				if($next[5] != ""){
-					# 下一个是标点符号
-					$sent .= $curr[4]." ";
-					$sent_html .= wordStyle($curr[4],$curr[15])." ";
-				}
-				else{
-					$sent .= $curr[4];
-					$sent_html .= wordStyle($curr[4],$curr[15]);
-				}
-				if($wordlist[$i][5] != '' && ($Note_Mark==0 || ($Note_Mark==1 && ($next[4]=="[" || $next[4]=="(")))){
-
-					$wordcount++;
-					if($wordlist[$i][5]=="iti"){
-						$sent_real .=" ".$curr[4];
-					}
-					else{
-						$sent_real .=" ".$curr[5];
-					}
-				}
-				
-			}
-			if($isEndOfSen==true && strlen(trim($sent))>0){
-				$end = $wordlist[$i][16];
-				$arrSent[]=array($book,$iCurrPara,$begin,$end,mb_strlen(trim($sent_real),"UTF-8"),$wordcount,$sent,$sent_html,trim($sent_real),getWordEn($sent_real));			
-				//echo "end={$end}<br>";
-				//echo "<div>[{$iCurrPara}-{$begin}-{$end}]({$wordcount})<br>{$sent}<br>{$sent_real}<br>".getWordEn($sent_real)."</div>";
-				
-				$sent="";
-				$sent_html="";
-				$sent_real="";
-				$iSent++;
-				$begin = $wordlist[$i][16]+1;
-				$wordcount=0;
-			}
-			
-			$iWord++;
-	}
-				if(strlen(trim($sent))>0){
-					$end = $wordlist[count($wordlist)-1][16];
-					$arrSent[]=array($book,$iCurrPara,$begin,$end,mb_strlen(trim($sent_real),"UTF-8"),$wordcount,$sent,$sent_html,trim($sent_real),getWordEn($sent_real));
-					//echo "end={$end}<br>";
-					//echo "<div>[{$iCurrPara}-{$begin}-{$end}]({$wordcount})<br>{$sent}<br>{$sent_real}<br>".getWordEn($sent_real)."</div>";
-				}
-}
-else{
-	echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
+$iWord = 0;
+$pre = null;
+$curr = null;
+$next = null;
+$wordlist = array();
+$arrSent = array();
+$book = 0;
+$sent_html = "";
+
+if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+    while (($data = fgetcsv($fp)) !== false) {
+        //id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
+        //$data = mb_split(",",$data);
+
+        $wordlist[] = $data;
+        if ($book == 0) {
+            $book = substr($data[2], 1);
+        }
+
+    }
+    fclose($fp);
+
+    $iWord = 0;
+    $iCurrPara = 0;
+    $Note_Mark = 0;
+    if ($wordlist[1][6] != ".ctl.") {
+        $sent = $wordlist[1][4] . " ";
+        $sent_html = wordStyle($wordlist[1][4], $wordlist[1][15]) . " ";
+        $sent_real = $wordlist[1][5];
+        $wordcount = 1;
+    } else {
+        $sent = "";
+        $sent_html = "";
+        $sent_real = "";
+        $wordcount = 0;
+    }
+    $begin = 1;
+    $end = 1;
+    $iSent = 0;
+    $Note_Mark1 = 0;
+    $Note_Mark2 = 0;
+    $Note_Mark = 0;
+    $wordcount = 0;
+    for ($i = 1; $i < count($wordlist); $i++) {
+        if ($wordlist[$i][3] > $iCurrPara) {
+            //echo  "new paragraph<br>";
+            $iWord = 0;
+            if ($i > 1) {
+                //echo "上一段结束<br>";
+                if (strlen(trim($sent)) > 0) {
+                    $end = $wordlist[$i - 1][16];
+                    $arrSent[] = array($book, $iCurrPara, $begin, $end, mb_strlen(trim($sent_real), "UTF-8"), $wordcount, $sent, $sent_html, trim($sent_real), getWordEn($sent_real));
+                    //echo "end={$end}<br>";
+                    //echo "<div>[{$iCurrPara}-{$begin}-{$end}]({$wordcount})<br>{$sent}<br>{$sent_real}<br>".getWordEn($sent_real)."</div>";
+                }
+                $iCurrPara = $wordlist[$i][3];
+
+                $Note_Mark1 = 0;
+                $Note_Mark2 = 0;
+                $Note_Mark = 0;
+
+                $pre = $wordlist[$i - 1];
+                $curr = $wordlist[$i];
+                if ($i < count($wordlist) - 1) {
+                    $next = $wordlist[$i + 1];
+                } else {
+                    $next = "";
+                }
+
+                if ($next[4] == "(" || $curr[4] == "(") {
+                    $Note_Mark1 = 1;
+                } else if ($pre[4] == ")" && $Note_Mark1 == 1) {
+                    $Note_Mark1 = 0;
+                }
+
+                if ($next[4] == "[" || $curr[4] == "[") {
+                    $Note_Mark2 = 1;
+                } else if ($pre[4] == "]" && $Note_Mark2 == 1) {
+                    $Note_Mark2 = 0;
+                }
+                $Note_Mark = $Note_Mark1 + $Note_Mark2;
+                //下一段开始
+                if ($wordlist[$i][6] != ".ctl.") {
+                    $sent = $wordlist[$i][4] . " ";
+                    $sent_html = wordStyle($wordlist[$i][4], $wordlist[$i][15]) . " ";
+                    if ($wordlist[$i][5] == '"') {
+                        $sent_real = "";
+                    } else {
+                        $sent_real = $wordlist[$i][5];
+                    }
+                    $wordcount = 1;
+                } else {
+                    $sent = "";
+                    $sent_html = "";
+                    $sent_real = "";
+                    $wordcount = 0;
+                }
+                $begin = $wordlist[$i][16];
+
+                $iSent++;
+
+                continue;
+            }
+            $iCurrPara = $wordlist[$i][3];
+        }
+        $isEndOfSen = false;
+        if ($i < count($wordlist) - 1) {
+            $pre = $wordlist[$i - 1];
+            $curr = $wordlist[$i];
+            if ($i < count($wordlist) - 1) {
+                $next = $wordlist[$i + 1];
+            } else {
+                $next = "";
+            }
+
+            if ($next[4] == "(") {
+                $Note_Mark1 = 1;
+            } else if ($pre[4] == ")" && $Note_Mark1 == 1) {
+                $Note_Mark1 = 0;
+            }
+
+            if ($next[4] == "[") {
+                $Note_Mark2 = 1;
+            } else if ($pre[4] == "]" && $Note_Mark2 == 1) {
+                $Note_Mark2 = 0;
+            }
+            $Note_Mark = $Note_Mark1 + $Note_Mark2;
+
+            if ($curr[15] != "note" || mb_substr($curr[1], 0, 5, "UTF-8") != "gatha") {
+                if ($curr[4] == "." && !is_numeric($pre[4]) && $next[3] == $iCurrPara && $Note_Mark === 0) {
+                    //以.結尾且非註釋
+                    if ($next[4] != "(") {
+                        $isEndOfSen = true;
+                    }
+                } else if ($curr[4] == "–" && $next[4] == "‘" && $Note_Mark === 0) {
+                    $isEndOfSen = true;
+                } else if ($Note_Mark == 0) {
+                    //以!或?或;結尾
+                    if ($curr[4] == "!") {
+                        if ($next[4] != "!") {
+                            if ($next[4] != "(") {
+                                $isEndOfSen = true;
+                            }
+                        }
+                    } else if ($curr[4] == ";" || $curr[4] == "?") {
+                        if ($next[4] != "(") {
+                            $isEndOfSen = true;
+                        }
+                    }
+                }
+            }
+        }
+
+        if ($curr[6] != ".ctl.") {
+            if ($next[5] != "") {
+                # 下一个是标点符号
+                $sent .= $curr[4] . " ";
+                $sent_html .= wordStyle($curr[4], $curr[15]) . " ";
+            } else {
+                $sent .= $curr[4];
+                $sent_html .= wordStyle($curr[4], $curr[15]);
+            }
+            if ($wordlist[$i][5] != '' && ($Note_Mark == 0 || ($Note_Mark == 1 && ($next[4] == "[" || $next[4] == "(")))) {
+
+                $wordcount++;
+                if ($wordlist[$i][5] == "iti") {
+                    $sent_real .= " " . $curr[4];
+                } else {
+                    $sent_real .= " " . $curr[5];
+                }
+            }
+
+        }
+        if ($isEndOfSen == true && strlen(trim($sent)) > 0) {
+            $end = $wordlist[$i][16];
+            $arrSent[] = array($book, $iCurrPara, $begin, $end, mb_strlen(trim($sent_real), "UTF-8"), $wordcount, $sent, $sent_html, trim($sent_real), getWordEn($sent_real));
+            //echo "end={$end}<br>";
+            //echo "<div>[{$iCurrPara}-{$begin}-{$end}]({$wordcount})<br>{$sent}<br>{$sent_real}<br>".getWordEn($sent_real)."</div>";
+
+            $sent = "";
+            $sent_html = "";
+            $sent_real = "";
+            $iSent++;
+            $begin = $wordlist[$i][16] + 1;
+            $wordcount = 0;
+        }
+
+        $iWord++;
+    }
+    if (strlen(trim($sent)) > 0) {
+        $end = $wordlist[count($wordlist) - 1][16];
+        $arrSent[] = array($book, $iCurrPara, $begin, $end, mb_strlen(trim($sent_real), "UTF-8"), $wordcount, $sent, $sent_html, trim($sent_real), getWordEn($sent_real));
+        //echo "end={$end}<br>";
+        //echo "<div>[{$iCurrPara}-{$begin}-{$end}]({$wordcount})<br>{$sent}<br>{$sent_real}<br>".getWordEn($sent_real)."</div>";
+    }
+} else {
+    echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
 }
 
 // 开始一个事务,关闭自动提交
 
-PDO_Connect("sqlite:$db_file");
+PDO_Connect("$db_file");
 $PDO->beginTransaction();
-$query="INSERT INTO pali_sent ('id','book','paragraph','begin','end','length','count','text','html','real','real_en') VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
+$query = "INSERT INTO pali_sent ('id','book','paragraph','begin','end','length','count','text','html','real','real_en') VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
 $stmt = $PDO->prepare($query);
-foreach($arrSent as $oneParam){
-	$stmt->execute($oneParam);
+foreach ($arrSent as $oneParam) {
+    $stmt->execute($oneParam);
 }
-// 提交更改 
+// 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	echo "error - $error[2] <br>";
-	
-	$log=$log."$from, $FileName, error, $error[2] \r\n";
-}
-else{
-	$count=count($arrSent);
-	echo "updata $count recorders.";
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+} else {
+    $count = count($arrSent);
+    echo "updata $count recorders.";
 }
 
-	$myLogFile = fopen(_DIR_LOG_."insert_sent.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
+$myLogFile = fopen(_DIR_LOG_ . "insert_sent.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 
 ?>
 
 
-<?php 
+<?php
 
-if($from>=$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_sentence.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+if ($from >= $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_insert_sentence.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 25 - 29
app/install/db_insert_sim.php

@@ -1,51 +1,47 @@
-<?php 
+<?php
 /*
 用相似句导入数据库
-*/
+ */
 
 ?>
 <?php
 require_once '../public/_pdo.php';
 require_once '../path.php';
 
-$filelist=array();
-$fileNums=0;
-$log="";
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "start\n";
 
-$db_file = _DIR_PALICANON_."/pali_sim.db3";
-PDO_Connect("sqlite:$db_file");
+$db_file = _DIR_PALICANON_ . "/pali_sim.db3";
+PDO_Connect("$db_file");
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query="INSERT INTO sent_sim ('sent1','sent2','sim') VALUES (? , ? , ?)";
+$query = "INSERT INTO sent_sim ('sent1','sent2','sim') VALUES (? , ? , ?)";
 $stmt = $PDO->prepare($query);
 
 // 打开文件并读取数据
 $count = 0;
-if(($fp=fopen(_DIR_TMP_."/pali_simsent/sim.csv", "r"))!==FALSE){
-	while(($data=fgetcsv($fp,0,','))!==FALSE){
-		$stmt->execute($data);
-		$count++;
-		if($count%1000000==0){
-			echo $count."\n";
-		}
-	}
-	fclose($fp);
-}
-else{
-	echo "can not open csv file. ";
+if (($fp = fopen(_DIR_TMP_ . "/pali_simsent/sim.csv", "r")) !== false) {
+    while (($data = fgetcsv($fp, 0, ',')) !== false) {
+        $stmt->execute($data);
+        $count++;
+        if ($count % 1000000 == 0) {
+            echo $count . "\n";
+        }
+    }
+    fclose($fp);
+} else {
+    echo "can not open csv file. ";
 }
 
-// 提交更改 
+// 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	
-	echo " error, $error[2] \r\n";
-}
-else{
-	echo "updata $count recorders.";
-}
+    $error = PDO_ErrorInfo();
 
-?>
+    echo " error, $error[2] \r\n";
+} else {
+    echo "updata $count recorders.";
+}

+ 111 - 113
app/install/db_insert_templet.php

@@ -1,7 +1,7 @@
-<?php 
+<?php
 /*
 用拆分好的三藏数据 生成模板库
-*/
+ */
 require_once "install_head.php";
 ?>
 <!DOCTYPE html>
@@ -14,8 +14,8 @@ require_once "install_head.php";
 <?php
 require_once '../public/_pdo.php';
 require_once '../path.php';
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_insert_templet.php" method="get">
 From: <input type="text" value="0" name="from"><br>
 To: <input type="text" value="216" name="to"><br>
@@ -25,148 +25,146 @@ To: <input type="text" value="216" name="to"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
-$filelist=array();
-$fileNums=0;
-$log="";
+$from = $_GET["from"];
+$to = $_GET["to"];
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from</h2>";
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
 
-$FileName=$filelist[$from][1].".htm";
-$fileId=$filelist[$from][0];
-$fileId=$filelist[$from][0];
+$FileName = $filelist[$from][1] . ".htm";
+$fileId = $filelist[$from][0];
+$fileId = $filelist[$from][0];
 
-$dirLog=_DIR_LOG_;
+$dirLog = _DIR_LOG_;
 
-$dirDb=_DIR_PALICANON_TEMPLET_;
-$inputFileName=$FileName;
-$outputFileNameHead=$filelist[$from][1];
-$bookId=$filelist[$from][2];
-$vriParNum=0;
-$wordOrder=1;
+$inputFileName = $FileName;
+$outputFileNameHead = $filelist[$from][1];
+$bookId = $filelist[$from][2];
+$vriParNum = 0;
+$wordOrder = 1;
 
-$dirXmlBase=_DIR_PALI_CSV_."/";
-$dirXml=$outputFileNameHead."/";
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
+$dirXml = $outputFileNameHead . "/";
 
-$currChapter="";
-$currParNum="";
-$arrAllWords[0]=array("id","wid","book","paragraph","word","real","type","gramma","mean","note","part","partmean","bmc","bmt","un","style","vri","sya","si","ka","pi","pa","kam");
-$g_wordCounter=0;
+$currChapter = "";
+$currParNum = "";
+$arrAllWords[0] = array("id", "wid", "book", "paragraph", "word", "real", "type", "gramma", "mean", "note", "part", "partmean", "bmc", "bmt", "un", "style", "vri", "sya", "si", "ka", "pi", "pa", "kam");
+$g_wordCounter = 0;
 
-$arrUnWords[0]=array("id","word","type","gramma","parent","mean","note","part","partmean","cf","state","delete","tag","len");
-$g_unWordCounter=0;
+$arrUnWords[0] = array("id", "word", "type", "gramma", "parent", "mean", "note", "part", "partmean", "cf", "state", "delete", "tag", "len");
+$g_unWordCounter = 0;
 
-$arrUnPart[0]="word";
-$g_unPartCounter=-1;
+$arrUnPart[0] = "word";
+$g_unPartCounter = -1;
 
 /*去掉标点符号的统计*/
-$arrAllPaliWordsCount=array();
-$g_paliWordCounter=0;
-$g_wordCounterInSutta=0;
-$g_paliWordCountCounter=0;
-
+$arrAllPaliWordsCount = array();
+$g_paliWordCounter = 0;
+$g_wordCounterInSutta = 0;
+$g_paliWordCountCounter = 0;
 
 $xmlfile = $inputFileName;
-echo "doing:".$xmlfile."<br>";
-$log=$log."$from,$FileName,open\r\n";
+echo "doing:" . $xmlfile . "<br>";
+$log = $log . "$from,$FileName,open\r\n";
+
+$arrInserString = array();
 
-$arrInserString=array();
-$db_file = $dirDb."/".$bookId.'_tpl.db3';
-PDO_Connect("sqlite:$db_file");
+$db_file = _DIR_PALICANON_TEMPLET_ . "/" . $bookId . '_tpl.db3';
+PDO_Connect("$db_file");
 
 PDO_Execute("DROP TABLE IF EXISTS main;");
-$query="CREATE TABLE 'main' ( 'id' TEXT PRIMARY KEY NOT NULL, 
-							'book' INTEGER, 
-							'paragraph' INTEGER, 
-							'wid' INTEGER, 
-							'word' TEXT, 
-							'real' TEXT, 
-							'type' TEXT, 
-							'gramma' TEXT, 
-							'part' TEXT, 
+$query = "CREATE TABLE 'main' ( 'id' TEXT PRIMARY KEY NOT NULL,
+							'book' INTEGER,
+							'paragraph' INTEGER,
+							'wid' INTEGER,
+							'word' TEXT,
+							'real' TEXT,
+							'type' TEXT,
+							'gramma' TEXT,
+							'part' TEXT,
 							'style' TEXT)";
-    $stmt = @PDO_Execute($query);
-    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
-        print_r($error[2]);
-
-	}
-	PDO_Execute("DROP INDEX IF EXISTS search;");
-	
-$query="CREATE INDEX 'search' ON \"main\" (\"book\", \"paragraph\", \"wid\" ASC)";
-    $stmt = @PDO_Execute($query);
-    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-        $error = PDO_ErrorInfo();
-        print_r($error[2]);
-        $log=$log."$from, $FileName, error, $error[2] \r\n";
-    }
+$stmt = @PDO_Execute($query);
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    print_r($error[2]);
 
-// 打开文件并读取数据
-if(($fp=fopen($dirXmlBase.$dirXml.$outputFileNameHead.".csv", "r"))!==FALSE){
-	while(($data=fgetcsv($fp,0,','))!==FALSE){
-		//id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
-		
-		$params=array($data[0],
-					 mb_substr($data[2],1),
-					 $data[3],
-					 $data[16],
-					 $data[4],
-					 $data[5],
-					 $data[6],
-					 $data[7],
-					 $data[10],
-					 $data[15]);
-		$arrInserString[]=$params;
-	}
-	fclose($fp);
-	echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
 }
-else{
-	echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
+PDO_Execute("DROP INDEX IF EXISTS search;");
+
+$query = "CREATE INDEX 'search' ON \"main\" (\"book\", \"paragraph\", \"wid\" ASC)";
+$stmt = @PDO_Execute($query);
+if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+    $error = PDO_ErrorInfo();
+    print_r($error[2]);
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+}
+
+// 打开文件并读取数据
+if (($fp = fopen($dirXmlBase . $dirXml . $outputFileNameHead . ".csv", "r")) !== false) {
+    while (($data = fgetcsv($fp, 0, ',')) !== false) {
+        //id,wid,book,paragraph,word,real,type,gramma,mean,note,part,partmean,bmc,bmt,un,style,vri,sya,si,ka,pi,pa,kam
+
+        $params = array($data[0],
+            mb_substr($data[2], 1),
+            $data[3],
+            $data[16],
+            $data[4],
+            $data[5],
+            $data[6],
+            $data[7],
+            $data[10],
+            $data[15]);
+        $arrInserString[] = $params;
+    }
+    fclose($fp);
+    echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+} else {
+    echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
 }
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query="INSERT INTO main ('id','book','paragraph','wid','word','real','type','gramma','part','style') VALUES (?,?,?,?,?,?,?,?,?,?)";
+$query = "INSERT INTO main ('id','book','paragraph','wid','word','real','type','gramma','part','style') VALUES (?,?,?,?,?,?,?,?,?,?)";
 $stmt = $PDO->prepare($query);
-foreach($arrInserString as $oneParam){
-	$stmt->execute($oneParam);
+foreach ($arrInserString as $oneParam) {
+    $stmt->execute($oneParam);
 }
-// 提交更改 
+// 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	echo "error - $error[2] <br>";
-	
-	$log=$log."$from, $FileName, error, $error[2] \r\n";
-}
-else{
-	$count=count($arrInserString);
-	echo "updata $count recorders.";
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+} else {
+    $count = count($arrInserString);
+    echo "updata $count recorders.";
 }
 
-	$myLogFile = fopen($dirLog."insert_db.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
+$myLogFile = fopen($dirLog . "insert_db.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 ?>
 
 
-<?php 
-if($from==$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_templet.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+<?php
+if ($from == $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_insert_templet.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 49 - 51
app/install/db_insert_word_from_csv.php

@@ -11,8 +11,8 @@ require_once "install_head.php";
 <?php
 include "./_pdo.php";
 
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_insert_word_from_csv.php" method="get">
 From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
@@ -22,67 +22,65 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
+$from = $_GET["from"];
+$to = $_GET["to"];
 
-$dirLog=_DIR_LOG_."/";
-$dirXmlBase=_DIR_PALI_CSV_."/";
+$dirLog = _DIR_LOG_ . "/";
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
 
-$filelist=array();
-$fileNums=0;
-$log="";
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>doing : No.{$from} book </h2>";
 
 global $dbh_word_index;
-$dns = "sqlite:"._FILE_DB_PALI_INDEX_;
-$dbh_word_index = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dns = "" . _FILE_DB_PALI_INDEX_;
+$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
 $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
-
-	if(($fpoutput=fopen(_DIR_CSV_PALI_CANON_WORD_."/{$from}_words.csv", "r"))!==FALSE){
-		// 开始一个事务,关闭自动提交
-		$dbh_word_index->beginTransaction();
-		$query="INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
-		$stmt = $dbh_word_index->prepare($query);
 
-		$count=0;
-		while(($data=fgetcsv($fpoutput,0,','))!==FALSE){
-			$stmt->execute($data);
-			$count++;
-		}
-		// 提交更改 
-		$dbh_word_index->commit();
-		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-			$error = $dbh_word_index->errorInfo();
-			echo "error - $error[2] <br>";
-			$log.="$from, $FileName, error, $error[2] \r\n";
-		}
-		else{
-			echo "updata $count recorders.<br />";
-			$log.="updata $count recorders.\r\n";
-		}		
-	}
+if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_ . "/{$from}_words.csv", "r")) !== false) {
+    // 开始一个事务,关闭自动提交
+    $dbh_word_index->beginTransaction();
+    $query = "INSERT INTO word ('id','book','paragraph','wordindex','bold') VALUES (?,?,?,?,?)";
+    $stmt = $dbh_word_index->prepare($query);
 
+    $count = 0;
+    while (($data = fgetcsv($fpoutput, 0, ',')) !== false) {
+        $stmt->execute($data);
+        $count++;
+    }
+    // 提交更改
+    $dbh_word_index->commit();
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+        $error = $dbh_word_index->errorInfo();
+        echo "error - $error[2] <br>";
+        $log .= "$from, $FileName, error, $error[2] \r\n";
+    } else {
+        echo "updata $count recorders.<br />";
+        $log .= "updata $count recorders.\r\n";
+    }
+}
 
-	$myLogFile = fopen($dirLog."insert_index.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
-	
+$myLogFile = fopen($dirLog . "insert_index.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 
-if($from>=$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_word_from_csv.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+if ($from >= $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_insert_word_from_csv.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 36 - 43
app/install/db_insert_wordindex_from_csv.php

@@ -10,63 +10,56 @@ include "./_pdo.php";
 <h2>Insert to Index</h2>
 <?php
 
-if(isset($_GET["from"])==false){
-    $from=0;
+if (isset($_GET["from"]) == false) {
+    $from = 0;
+} else {
+    $from = $_GET["from"];
 }
-else{
-    $from=$_GET["from"];
-}
-
 
-$dirLog=_DIR_LOG_."/";
+$dirLog = _DIR_LOG_ . "/";
 
-$filelist=array();
-$fileNums=0;
-$log="";
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>doing : No.{$from}  </h2>";
 
 global $dbh_word_index;
-$dns = "sqlite:"._FILE_DB_WORD_INDEX_;
-$dbh_word_index = new PDO($dns, "", "",array(PDO::ATTR_PERSISTENT=>true));
+$dns = "" . _FILE_DB_WORD_INDEX_;
+$dbh_word_index = new PDO($dns, "", "", array(PDO::ATTR_PERSISTENT => true));
 $dbh_word_index->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
+if (($fpoutput = fopen(_DIR_CSV_PALI_CANON_WORD_INDEX_ . "/{$from}.csv", "r")) !== false) {
 
-	if(($fpoutput=fopen(_DIR_CSV_PALI_CANON_WORD_INDEX_."/{$from}.csv", "r"))!==FALSE){
-
-		// 开始一个事务,关闭自动提交
-		$dbh_word_index->beginTransaction();
-        $query="INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
+    // 开始一个事务,关闭自动提交
+    $dbh_word_index->beginTransaction();
+    $query = "INSERT INTO wordindex ('id','word','word_en','count','normal','bold','is_base','len') VALUES (?,?,?,?,?,?,?,?)";
 
-		$stmt = $dbh_word_index->prepare($query);
+    $stmt = $dbh_word_index->prepare($query);
 
-		$count=0;
-		while(($data=fgetcsv($fpoutput,0,','))!==FALSE){
-			$stmt->execute($data);
-			$count++;
-		}
-		// 提交更改 
-		$dbh_word_index->commit();
-		if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-			$error = $dbh_word_index->errorInfo();
-			echo "error - $error[2] <br>";
-			$log.="$from, $FileName, error, $error[2] \r\n";
-		}
-		else{
-			echo "updata $count recorders.<br />";
-			$log.="updata $count recorders.\r\n";
-		}		
+    $count = 0;
+    while (($data = fgetcsv($fpoutput, 0, ',')) !== false) {
+        $stmt->execute($data);
+        $count++;
     }
-    else{
-        echo "<h2>齐活!功德无量!all done!</h2>"; 
-        exit;
+    // 提交更改
+    $dbh_word_index->commit();
+    if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
+        $error = $dbh_word_index->errorInfo();
+        echo "error - $error[2] <br>";
+        $log .= "$from, $FileName, error, $error[2] \r\n";
+    } else {
+        echo "updata $count recorders.<br />";
+        $log .= "updata $count recorders.\r\n";
     }
-	
-
+} else {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+    exit;
+}
 
-	echo "<script>";
-	echo "window.location.assign(\"db_insert_wordindex_from_csv.php?from=".($from+1)."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+echo "<script>";
+echo "window.location.assign(\"db_insert_wordindex_from_csv.php?from=" . ($from + 1) . "\")";
+echo "</script>";
+echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 
 ?>
 </body>

+ 28 - 27
app/install/db_pali_text_export.php

@@ -10,10 +10,10 @@ require_once "../public/_pdo.php";
 <h2>Export Pali Text DB to CSV</h2>
 <?php
 
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_pali_text_export.php" method="get">
-From: <input type="text" name="from" value="0"><br> 
+From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
 <input type="submit">
 </form>
@@ -21,42 +21,43 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
+$from = $_GET["from"];
+$to = $_GET["to"];
 
-$log="";
+$log = "";
 echo "<h2>$from</h2>";
 
-if($to==0 || $to>=217) $to=216;
-    $book = $from +1;
-if(($fp=fopen(_DIR_PALI_TITLE_."/".$book."_title.csv", "w"))!==FALSE){
-    fputcsv($fp,array('id','book','par_num','level','class','title','text'));
-    PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
-    $query="select id, book, paragraph, level, class, toc, text from pali_text where book = '$book' ";
+if ($to == 0 || $to >= 217) {
+    $to = 216;
+}
+
+$book = $from + 1;
+if (($fp = fopen(_DIR_PALI_TITLE_ . "/" . $book . "_title.csv", "w")) !== false) {
+    fputcsv($fp, array('id', 'book', 'par_num', 'level', 'class', 'title', 'text'));
+    PDO_Connect("" . _FILE_DB_PALITEXT_);
+    $query = "select id, book, paragraph, level, class, toc, text from pali_text where book = '$book' ";
     $title_data = PDO_FetchAll($query);
-    foreach( $title_data as $value){
+    foreach ($title_data as $value) {
         $value["id"] = "NULL";
-        $value["book"] = "p".$value["book"];
-        if($value["level"]=="100"){
+        $value["book"] = "p" . $value["book"];
+        if ($value["level"] == "100") {
             $value["toc"] = "";
         }
-        fputcsv($fp,$value);
+        fputcsv($fp, $value);
     }
     fclose($fp);
     echo "ok";
-}
-else{
-    echo "error:can not open file "._DIR_PALI_TITLE_."/".$book."_title.csv";
+} else {
+    echo "error:can not open file " . _DIR_PALI_TITLE_ . "/" . $book . "_title.csv";
 }
 
-if($from==$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_pali_text_export.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+if ($from == $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_pali_text_export.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 

+ 155 - 162
app/install/db_update_palitext.php

@@ -11,10 +11,10 @@ require_once "../public/_pdo.php";
 <p><a href="index.php">Home</a></p>
 <?php
 
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_update_palitext.php" method="get">
-From: <input type="text" name="from" value="0"><br> 
+From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
 <input type="submit">
 </form>
@@ -22,209 +22,202 @@ To: <input type="text" name="to" value="216"><br>
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
-$filelist=array();
-$fileNums=0;
-$log="";
+$from = $_GET["from"];
+$to = $_GET["to"];
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from</h2>";
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
-
-$FileName=$filelist[$from][1].".htm";
-$fileId=$filelist[$from][0];
-$fileId=$filelist[$from][0];
-
-$dirLog=_DIR_LOG_."/";
 
-$dirDb="/";
-$inputFileName=$FileName;
-$outputFileNameHead=$filelist[$from][1];
-$bookId=$filelist[$from][2];
-$vriParNum=0;
-$wordOrder=1;
+$FileName = $filelist[$from][1] . ".htm";
+$fileId = $filelist[$from][0];
+$fileId = $filelist[$from][0];
 
-$dirXmlBase=_DIR_PALI_CSV_."/";
-$dirPaliTextBase=_DIR_PALI_HTML_."/";
-$dirXml=$outputFileNameHead."/";
+$dirLog = _DIR_LOG_ . "/";
 
+$dirDb = "/";
+$inputFileName = $FileName;
+$outputFileNameHead = $filelist[$from][1];
+$bookId = $filelist[$from][2];
+$vriParNum = 0;
+$wordOrder = 1;
 
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
+$dirPaliTextBase = _DIR_PALI_HTML_ . "/";
+$dirXml = $outputFileNameHead . "/";
 
 $xmlfile = $inputFileName;
-echo "doing:".$xmlfile."<br>";
-
-$log=$log.date("Y-m-d h:i:sa").",$from,$FileName,open\r\n";
-
-$arrInserString=array();
+echo "doing:" . $xmlfile . "<br>";
 
+$log = $log . date("Y-m-d h:i:sa") . ",$from,$FileName,open\r\n";
 
+$arrInserString = array();
 
 // 打开vri html文件并读取数据
-$pali_text_array=array();//vri text
-if(($fpPaliText=fopen($dirPaliTextBase.$xmlfile, "r"))!==FALSE){
-	while(($data=fgets($fpPaliText))!==FALSE){
-		array_push($pali_text_array,$data);
-	}
-	fclose($fpPaliText);
-	echo "pali text load:".$dirPaliTextBase.$xmlfile."<br>";
-}
-else{
-	echo "can not pali text file. filename=".$dirPaliTextBase.$xmlfile;
+$pali_text_array = array(); //vri text
+if (($fpPaliText = fopen($dirPaliTextBase . $xmlfile, "r")) !== false) {
+    while (($data = fgets($fpPaliText)) !== false) {
+        array_push($pali_text_array, $data);
+    }
+    fclose($fpPaliText);
+    echo "pali text load:" . $dirPaliTextBase . $xmlfile . "<br>";
+} else {
+    echo "can not pali text file. filename=" . $dirPaliTextBase . $xmlfile;
 }
 
 // 打开csv文件并读取数据
-$inputRow=0;
-if(($fp=fopen(_DIR_PALI_TITLE_."/".($from+1)."_title.csv", "r"))!==FALSE){
-	while(($data=fgetcsv($fp,0,','))!==FALSE){
-		if($inputRow>0){
-			$params=$data;
-			array_push($arrInserString,$params);
-		}
-		$inputRow++;
-	}
-	fclose($fp);
-	echo "单词表load:".$dirXmlBase.$dirXml.$outputFileNameHead.".csv<br>";
-}
-else{
-	echo "can not open csv file. filename=".$dirXmlBase.$dirXml.$outputFileNameHead.".csv";
+$inputRow = 0;
+if (($fp = fopen(_DIR_PALI_TITLE_ . "/" . ($from + 1) . "_title.csv", "r")) !== false) {
+    while (($data = fgetcsv($fp, 0, ',')) !== false) {
+        if ($inputRow > 0) {
+            $params = $data;
+            array_push($arrInserString, $params);
+        }
+        $inputRow++;
+    }
+    fclose($fp);
+    echo "单词表load:" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv<br>";
+} else {
+    echo "can not open csv file. filename=" . $dirXmlBase . $dirXml . $outputFileNameHead . ".csv";
 }
 
-if((count($arrInserString))  != count($pali_text_array)-2){
-	$log=$log."$from, $FileName,error,文件行数不匹配 csv = ".(count($arrInserString)-1) ." pali_text_array=".(count($pali_text_array)-2)." \r\n";
+if ((count($arrInserString)) != count($pali_text_array) - 2) {
+    $log = $log . "$from, $FileName,error,文件行数不匹配 csv = " . (count($arrInserString) - 1) . " pali_text_array=" . (count($pali_text_array) - 2) . " \r\n";
 }
 
-$book=$from+1;
+$book = $from + 1;
 
 //计算段落信息,如上一段
-PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
-$query="select * from pali_text where book = '$book' ";
+PDO_Connect("" . _FILE_DB_PALITEXT_);
+$query = "select * from pali_text where book = '$book' ";
 $title_data = PDO_FetchAll($query);
-echo  "Paragraph Count:".count($title_data)."<br>";
+echo "Paragraph Count:" . count($title_data) . "<br>";
 
 $paragraph_count = count($title_data);
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query ="UPDATE pali_text SET level = ? , toc = ? , chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ?  ,  chapter_strlen = ?  WHERE book=? and paragraph=?";
+$query = "UPDATE pali_text SET level = ? , toc = ? , chapter_len = ? , next_chapter = ?, prev_chapter=? , parent= ?  ,  chapter_strlen = ?  WHERE book=? and paragraph=?";
 $stmt = $PDO->prepare($query);
 
 $paragraph_info = array();
-array_push($paragraph_info,array($from,-1,$paragraph_count,-1,-1,-1));
-for($iPar=0;$iPar < count($title_data); $iPar++){
-	$title_data[$iPar]["level"] = $arrInserString[$iPar][3];
+array_push($paragraph_info, array($from, -1, $paragraph_count, -1, -1, -1));
+for ($iPar = 0; $iPar < count($title_data); $iPar++) {
+    $title_data[$iPar]["level"] = $arrInserString[$iPar][3];
 }
 
-for($iPar=0;$iPar < count($title_data); $iPar++){
-	$book=$from+1;
-	$paragraph=$title_data[$iPar]["paragraph"];
-	
-	if((int)$title_data[$iPar]["level"]==8){
-		$title_data[$iPar]["level"]=100;
-	}
-	
-	$curr_level=(int)$title_data[$iPar]["level"];
-	# j计算这个chapter的段落数量
-	$length=-1;
-	for($iPar1=$iPar+1;$iPar1<count($title_data); $iPar1++){
-		$thislevel = (int)$title_data[$iPar1]["level"];
-		if( $thislevel <= $curr_level){
-			$length=(int)$title_data[$iPar1]["paragraph"]-$paragraph;
-			break;
-		}
-	}
-	if($length==-1){
-		$length=$paragraph_count-$paragraph+1;
-	}
-	
-	$prev=-1;
-	if($iPar>0){
-		for($iPar1=$iPar-1;$iPar1>=0; $iPar1--){
-			if($title_data[$iPar1]["level"]==$curr_level){
-				$prev=$title_data[$iPar1]["paragraph"];
-				break;
-			}
-		}
-	}
-	
-	$next=-1;
-	if($iPar<count($title_data)-1){
-		for($iPar1=$iPar+1;$iPar1<count($title_data); $iPar1++){
-			if($title_data[$iPar1]["level"]==$curr_level){
-				$next=$title_data[$iPar1]["paragraph"];
-				break;
-			}
-		}
-	}		
-	
-	$parent=-1;
-	if($iPar>0){
-		for($iPar1=$iPar-1;$iPar1>=0; $iPar1--){
-			if($title_data[$iPar1]["level"]<$curr_level){
-				$parent=$title_data[$iPar1]["paragraph"];
-				break;
-			}
-		}
-	}				
-	//计算章节包含总字符数
-	$iChapter_strlen = 0;
-	for($i = $iPar ; $i < $iPar+$length; $i++ ){
-		$iChapter_strlen += $title_data[$i]["lenght"];
-	}
-	$newData=array(
-		$arrInserString[$iPar][3],
-		$arrInserString[$iPar][5],
-		$length,
-	   $next,
-	   $prev,
-	   $parent,
-	   $iChapter_strlen,
-	   $book,
-	   $paragraph
-	);
-	$stmt->execute($newData);
-	
-	if($curr_level>0 && $curr_level<8){
-		array_push($paragraph_info,array($book,$paragraph,$length,$prev,$next,$parent));
-	}
+for ($iPar = 0; $iPar < count($title_data); $iPar++) {
+    $book = $from + 1;
+    $paragraph = $title_data[$iPar]["paragraph"];
+
+    if ((int) $title_data[$iPar]["level"] == 8) {
+        $title_data[$iPar]["level"] = 100;
+    }
+
+    $curr_level = (int) $title_data[$iPar]["level"];
+    # j计算这个chapter的段落数量
+    $length = -1;
+    for ($iPar1 = $iPar + 1; $iPar1 < count($title_data); $iPar1++) {
+        $thislevel = (int) $title_data[$iPar1]["level"];
+        if ($thislevel <= $curr_level) {
+            $length = (int) $title_data[$iPar1]["paragraph"] - $paragraph;
+            break;
+        }
+    }
+    if ($length == -1) {
+        $length = $paragraph_count - $paragraph + 1;
+    }
+
+    $prev = -1;
+    if ($iPar > 0) {
+        for ($iPar1 = $iPar - 1; $iPar1 >= 0; $iPar1--) {
+            if ($title_data[$iPar1]["level"] == $curr_level) {
+                $prev = $title_data[$iPar1]["paragraph"];
+                break;
+            }
+        }
+    }
+
+    $next = -1;
+    if ($iPar < count($title_data) - 1) {
+        for ($iPar1 = $iPar + 1; $iPar1 < count($title_data); $iPar1++) {
+            if ($title_data[$iPar1]["level"] == $curr_level) {
+                $next = $title_data[$iPar1]["paragraph"];
+                break;
+            }
+        }
+    }
+
+    $parent = -1;
+    if ($iPar > 0) {
+        for ($iPar1 = $iPar - 1; $iPar1 >= 0; $iPar1--) {
+            if ($title_data[$iPar1]["level"] < $curr_level) {
+                $parent = $title_data[$iPar1]["paragraph"];
+                break;
+            }
+        }
+    }
+    //计算章节包含总字符数
+    $iChapter_strlen = 0;
+    for ($i = $iPar; $i < $iPar + $length; $i++) {
+        $iChapter_strlen += $title_data[$i]["lenght"];
+    }
+    $newData = array(
+        $arrInserString[$iPar][3],
+        $arrInserString[$iPar][5],
+        $length,
+        $next,
+        $prev,
+        $parent,
+        $iChapter_strlen,
+        $book,
+        $paragraph,
+    );
+    $stmt->execute($newData);
+
+    if ($curr_level > 0 && $curr_level < 8) {
+        array_push($paragraph_info, array($book, $paragraph, $length, $prev, $next, $parent));
+    }
 }
 
-// 提交更改 
+// 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	echo "error - $error[2] <br>";
-	
-	$log=$log."$from, $FileName, error, $error[2] \r\n";
-}
-else{
-	$count=count($title_data);
-	echo "updata $count paragraph info recorders.<br>";
-	echo count($paragraph_info)." Heading<br>";
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+
+    $log = $log . "$from, $FileName, error, $error[2] \r\n";
+} else {
+    $count = count($title_data);
+    echo "updata $count paragraph info recorders.<br>";
+    echo count($paragraph_info) . " Heading<br>";
 }
 //段落信息结束
 
+$myLogFile = fopen(_DIR_LOG_ . "/db_update_palitext.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
 
-	$myLogFile = fopen(_DIR_LOG_."/db_update_palitext.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
-	
 ?>
 
 
-<?php 
-if($from==$to){
-	echo "<h2>齐活!功德无量!all done!</h2>";
-}
-else{
-	echo "<script>";
-	echo "window.location.assign(\"db_update_palitext.php?from=".($from+1)."&to=".$to."\")";
-	echo "</script>";
-	echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
+<?php
+if ($from == $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    echo "window.location.assign(\"db_update_palitext.php?from=" . ($from + 1) . "&to=" . $to . "\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
 }
 ?>
 </body>

+ 99 - 106
app/install/db_update_toc.php

@@ -5,11 +5,12 @@ require_once '../path.php';
 require_once "../public/_pdo.php";
 require_once "../public/function.php";
 
-function getWordEn($strIn){
+function getWordEn($strIn)
+{
     $strIn = strtolower($strIn);
-	$search  = array('ā', 'ī', 'ū', 'ṅ', 'ñ' , 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
-	$replace = array('a', 'i', 'u', 'n', 'n' , 't', 'd', 'n', 'l', 'm');
-	return(str_replace($search,$replace,$strIn));
+    $search = array('ā', 'ī', 'ū', 'ṅ', 'ñ', 'ṭ', 'ḍ', 'ṇ', 'ḷ', 'ṃ');
+    $replace = array('a', 'i', 'u', 'n', 'n', 't', 'd', 'n', 'l', 'm');
+    return (str_replace($search, $replace, $strIn));
 }
 ?>
 <!DOCTYPE html>
@@ -20,10 +21,10 @@ function getWordEn($strIn){
 <h2>Update Table of Contence</h2>
 <?php
 
-if(isset($_GET["from"])==false){
-?>
+if (isset($_GET["from"]) == false) {
+    ?>
 <form action="db_update_toc.php" method="get">
-From: <input type="text" name="from" value="0"><br> 
+From: <input type="text" name="from" value="0"><br>
 To: <input type="text" name="to" value="216"><br>
 File: <input type="text" name="file" value="title"><br>
 Author: <input type="text" name="author" value=""><br>
@@ -41,151 +42,143 @@ Language:
 return;
 }
 
-$from=$_GET["from"];
-$to=$_GET["to"];
-$_file=$_GET["file"];
-$_author=$_GET["author"];
-$_lang=$_GET["lang"];
-$filelist=array();
-$fileNums=0;
-$log="";
+$from = $_GET["from"];
+$to = $_GET["to"];
+$_file = $_GET["file"];
+$_author = $_GET["author"];
+$_lang = $_GET["lang"];
+$filelist = array();
+$fileNums = 0;
+$log = "";
 echo "<h2>$from</h2>";
 
-if(($handle=fopen("filelist.csv",'r'))!==FALSE){
-	while(($filelist[$fileNums]=fgetcsv($handle,0,','))!==FALSE){
-		$fileNums++;
-	}
+if (($handle = fopen("filelist.csv", 'r')) !== false) {
+    while (($filelist[$fileNums] = fgetcsv($handle, 0, ',')) !== false) {
+        $fileNums++;
+    }
+}
+if ($to == 0 || $to >= $fileNums) {
+    $to = $fileNums - 1;
 }
-if($to==0 || $to>=$fileNums) $to=$fileNums-1;
-
-$FileName=$filelist[$from][1].".htm";
-$fileId=$filelist[$from][0];
-$fileId=$filelist[$from][0];
-
-$dirLog=_DIR_LOG_."/";
 
-$dirDb="/";
-$inputFileName=$FileName;
-$outputFileNameHead=$filelist[$from][1];
-$bookId=$filelist[$from][2];
-$vriParNum=0;
-$wordOrder=1;
+$FileName = $filelist[$from][1] . ".htm";
+$fileId = $filelist[$from][0];
+$fileId = $filelist[$from][0];
 
-$dirXmlBase=_DIR_PALI_CSV_."/";
-$dirPaliTextBase=_DIR_PALI_HTML_."/";
-$dirXml=$outputFileNameHead."/";
+$dirLog = _DIR_LOG_ . "/";
 
+$dirDb = "/";
+$inputFileName = $FileName;
+$outputFileNameHead = $filelist[$from][1];
+$bookId = $filelist[$from][2];
+$vriParNum = 0;
+$wordOrder = 1;
 
+$dirXmlBase = _DIR_PALI_CSV_ . "/";
+$dirPaliTextBase = _DIR_PALI_HTML_ . "/";
+$dirXml = $outputFileNameHead . "/";
 
 $xmlfile = $inputFileName;
 
-$log=$log.date("Y-m-d h:i:sa").",$from,$FileName,open\r\n";
-
-$arrInserString=array();
+$log = $log . date("Y-m-d h:i:sa") . ",$from,$FileName,open\r\n";
 
+$arrInserString = array();
 
 // 打开csv文件并读取数据
-$inputRow=0;
-if(($fp=fopen(_DIR_PALI_TITLE_."/".($from+1)."_{$_file}.csv", "r"))!==FALSE){
-	while(($data=fgetcsv($fp,0,','))!==FALSE){
-		if($inputRow>0 && $data[3] != 100  && !empty($data[6])){
-			array_push($arrInserString,$data);
-		}
-		$inputRow++;
-	}
-	fclose($fp);
-	echo "res load:"._DIR_PALI_TITLE_."/".($from+1)."_title.csv<br>";
-}
-else{
+$inputRow = 0;
+if (($fp = fopen(_DIR_PALI_TITLE_ . "/" . ($from + 1) . "_{$_file}.csv", "r")) !== false) {
+    while (($data = fgetcsv($fp, 0, ',')) !== false) {
+        if ($inputRow > 0 && $data[3] != 100 && !empty($data[6])) {
+            array_push($arrInserString, $data);
+        }
+        $inputRow++;
+    }
+    fclose($fp);
+    echo "res load:" . _DIR_PALI_TITLE_ . "/" . ($from + 1) . "_title.csv<br>";
+} else {
     echo "can not open csv ";
-    
-    if($from==$to){
+
+    if ($from == $to) {
         echo "<h2>齐活!功德无量!all done!</h2>";
-    }
-    else{
+    } else {
         echo "<script>";
-        $next = $from+1;
+        $next = $from + 1;
         echo "window.location.assign(\"db_update_toc.php?from={$next}&to={$to}&file={$_file}&author={$_author}&lang={$_lang}\")";
         echo "</script>";
-        echo "正在载入:".($from+1);
+        echo "正在载入:" . ($from + 1);
         echo "</body></html>";
         exit;
     }
 }
 
-$book=$from+1;
+$book = $from + 1;
 
 //删除已有标题
-PDO_Connect("sqlite:"._FILE_DB_RESRES_INDEX_);
-$query =" DELETE FROM 'index' WHERE book ='{$book}'  AND  language = '{$_lang}'  ";
+PDO_Connect("" . _FILE_DB_RESRES_INDEX_);
+$query = " DELETE FROM 'index' WHERE book ='{$book}'  AND  language = '{$_lang}'  ";
 
 $PDO->query($query);
 
 // 开始一个事务,关闭自动提交
 $PDO->beginTransaction();
-$query="INSERT INTO 'index' ('id','book','paragraph','title','title_en' ,'level','type','language','author','share','create_time','update_time' ) VALUES ( NULL , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
+$query = "INSERT INTO 'index' ('id','book','paragraph','title','title_en' ,'level','type','language','author','share','create_time','update_time' ) VALUES ( NULL , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
 $stmt = $PDO->prepare($query);
-if($_lang=="pali"){
-    $type=1;
-}
-else{
-    $type=2;
+if ($_lang == "pali") {
+    $type = 1;
+} else {
+    $type = 2;
 }
-foreach($arrInserString as $title){
-	if(isset($title[7])){
-		$author = $title[7];
-	}
-	else if(isset($_author)){
-		$author = $_author;
-	}
-	else{
-		$author = "";
-	}
-	$newData=array(
+foreach ($arrInserString as $title) {
+    if (isset($title[7])) {
+        $author = $title[7];
+    } else if (isset($_author)) {
+        $author = $_author;
+    } else {
+        $author = "";
+    }
+    $newData = array(
         $book,
         $title[2],
         $title[6],
         getWordEn($title[6]),
         $title[3],
-		$type,
-	    $_lang,
+        $type,
+        $_lang,
         $author,
-	   1,
-	   mTime(),
-       mTime()
-	);
-	$stmt->execute($newData);
+        1,
+        mTime(),
+        mTime(),
+    );
+    $stmt->execute($newData);
 }
-// 提交更改 
+// 提交更改
 $PDO->commit();
 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-	$error = PDO_ErrorInfo();
-	echo "error - $error[2] <br>";
-	$log=$log."$from, error, $error[2] \r\n";
-}
-else{
-	$count=count($arrInserString);
-	echo "updata $count title recorders.<br>";
+    $error = PDO_ErrorInfo();
+    echo "error - $error[2] <br>";
+    $log = $log . "$from, error, $error[2] \r\n";
+} else {
+    $count = count($arrInserString);
+    echo "updata $count title recorders.<br>";
 }
 //段落信息结束
-	$myLogFile = fopen(_DIR_LOG_."/db_update_toc.log", "a");
-	fwrite($myLogFile, $log);
-	fclose($myLogFile);
-	
+$myLogFile = fopen(_DIR_LOG_ . "/db_update_toc.log", "a");
+fwrite($myLogFile, $log);
+fclose($myLogFile);
+
 ?>
 
 
-<?php 
-    if($from==$to){
-        echo "<h2>齐活!功德无量!all done!</h2>";
-    }
-    else{
-        echo "<script>";
-        $next = $from+1;
-        echo "window.location.assign(\"db_update_toc.php?from={$next}&to={$to}&file={$_file}&author={$_author}&lang={$_lang}\")";
-        echo "</script>";
-        echo "正在载入:".($from+1)."——".$filelist[$from+1][0];
-    }
+<?php
+if ($from == $to) {
+    echo "<h2>齐活!功德无量!all done!</h2>";
+} else {
+    echo "<script>";
+    $next = $from + 1;
+    echo "window.location.assign(\"db_update_toc.php?from={$next}&to={$to}&file={$_file}&author={$_author}&lang={$_lang}\")";
+    echo "</script>";
+    echo "正在载入:" . ($from + 1) . "——" . $filelist[$from + 1][0];
+}
 ?>
 </body>
 </html>

+ 219 - 0
app/install/filelist.php

@@ -0,0 +1,219 @@
+<?php
+$_filelist = array();
+$_filelist[1]="e0601n.nrf";
+$_filelist[2]="e0602n.nrf";
+$_filelist[3]="e0603n.nrf";
+$_filelist[4]="e0604n.nrf";
+$_filelist[5]="e0605n.nrf";
+$_filelist[6]="e0606n.nrf";
+$_filelist[7]="e0607n.nrf";
+$_filelist[8]="e0608n.nrf";
+$_filelist[9]="e0810n.nrf";
+$_filelist[10]="e0811n.nrf";
+$_filelist[11]="e0812n.nrf";
+$_filelist[12]="e0813n.nrf";
+$_filelist[13]="e0801n.nrf";
+$_filelist[14]="e0802n.nrf";
+$_filelist[15]="e0803n.nrf";
+$_filelist[16]="e0804n.nrf";
+$_filelist[17]="e0805n.nrf";
+$_filelist[18]="e0806n.nrf";
+$_filelist[19]="e0807n.nrf";
+$_filelist[20]="e0808n.nrf";
+$_filelist[21]="e0809n.nrf";
+$_filelist[22]="e0201n.nrf";
+$_filelist[23]="e0301n.nrf";
+$_filelist[24]="e0401n.nrf";
+$_filelist[25]="e0501n.nrf";
+$_filelist[26]="e1010n.nrf";
+$_filelist[27]="e1001n.nrf";
+$_filelist[28]="e1002n.nrf";
+$_filelist[29]="e1003n.nrf";
+$_filelist[30]="e1004n.nrf";
+$_filelist[31]="e1005n.nrf";
+$_filelist[32]="e1006n.nrf";
+$_filelist[33]="e1007n.nrf";
+$_filelist[34]="e1008n.nrf";
+$_filelist[35]="e1009n.nrf";
+$_filelist[36]="e1101n.nrf";
+$_filelist[37]="e1102n.nrf";
+$_filelist[38]="e1103n.nrf";
+$_filelist[39]="e0901n.nrf";
+$_filelist[40]="e0902n.nrf";
+$_filelist[41]="e0903n.nrf";
+$_filelist[42]="e0904n.nrf";
+$_filelist[43]="e0905n.nrf";
+$_filelist[44]="e0906n.nrf";
+$_filelist[45]="e0907n.nrf";
+$_filelist[46]="e1210n.nrf";
+$_filelist[47]="e1211n.nrf";
+$_filelist[48]="e1212n.nrf";
+$_filelist[49]="e1213n.nrf";
+$_filelist[50]="e1214n.nrf";
+$_filelist[51]="e1215n.nrf";
+$_filelist[52]="e1201n.nrf";
+$_filelist[53]="e1202n.nrf";
+$_filelist[54]="e1203n.nrf";
+$_filelist[55]="e1204n.nrf";
+$_filelist[56]="e1205n.nrf";
+$_filelist[57]="e1206n.nrf";
+$_filelist[58]="e1207n.nrf";
+$_filelist[59]="e1208n.nrf";
+$_filelist[60]="e1209n.nrf";
+$_filelist[61]="e0701n.nrf";
+$_filelist[62]="e0702n.nrf";
+$_filelist[63]="e0703n.nrf";
+$_filelist[64]="e0101n.mul";
+$_filelist[65]="e0102n.mul";
+$_filelist[66]="e0103n.att";
+$_filelist[67]="e0104n.att";
+$_filelist[68]="e0105n.nrf";
+$_filelist[69]="abh03m8.mul";
+$_filelist[70]="abh03m9.mul";
+$_filelist[71]="abh03m10.mul";
+$_filelist[72]="abh03m11.mul";
+$_filelist[73]="abh01m.mul";
+$_filelist[74]="abh02m.mul";
+$_filelist[75]="abh03m1.mul";
+$_filelist[76]="abh03m2.mul";
+$_filelist[77]="abh03m3.mul";
+$_filelist[78]="abh03m4.mul";
+$_filelist[79]="abh03m5.mul";
+$_filelist[80]="abh03m6.mul";
+$_filelist[81]="abh03m7.mul";
+$_filelist[82]="s0404m3.mul";
+$_filelist[83]="s0404m4.mul";
+$_filelist[84]="s0401m.mul";
+$_filelist[85]="s0402m1.mul";
+$_filelist[86]="s0402m2.mul";
+$_filelist[87]="s0402m3.mul";
+$_filelist[88]="s0403m1.mul";
+$_filelist[89]="s0403m2.mul";
+$_filelist[90]="s0403m3.mul";
+$_filelist[91]="s0404m1.mul";
+$_filelist[92]="s0404m2.mul";
+$_filelist[93]="s0101m.mul";
+$_filelist[94]="s0102m.mul";
+$_filelist[95]="s0103m.mul";
+$_filelist[96]="abh01a.att";
+$_filelist[97]="abh02a.att";
+$_filelist[98]="abh03a.att";
+$_filelist[99]="s0401a.att";
+$_filelist[100]="s0402a.att";
+$_filelist[101]="s0403a.att";
+$_filelist[102]="s0404a.att";
+$_filelist[103]="s0101a.att";
+$_filelist[104]="s0102a.att";
+$_filelist[105]="s0103a.att";
+$_filelist[106]="s0509a.att";
+$_filelist[107]="s0510a.att";
+$_filelist[108]="s0511a.att";
+$_filelist[109]="s0512a.att";
+$_filelist[110]="s0513a1.att";
+$_filelist[111]="s0513a2.att";
+$_filelist[112]="s0513a3.att";
+$_filelist[113]="s0513a4.att";
+$_filelist[114]="s0514a1.att";
+$_filelist[115]="s0514a2.att";
+$_filelist[116]="s0501a.att";
+$_filelist[117]="s0514a3.att";
+$_filelist[118]="s0515a.att";
+$_filelist[119]="s0516a.att";
+$_filelist[120]="s0517a.att";
+$_filelist[121]="s0519a.att";
+$_filelist[122]="s0502a.att";
+$_filelist[123]="s0503a.att";
+$_filelist[124]="s0504a.att";
+$_filelist[125]="s0505a.att";
+$_filelist[126]="s0506a.att";
+$_filelist[127]="s0507a.att";
+$_filelist[128]="s0508a1.att";
+$_filelist[129]="s0508a2.att";
+$_filelist[130]="s0201a.att";
+$_filelist[131]="s0202a.att";
+$_filelist[132]="s0203a.att";
+$_filelist[133]="s0301a.att";
+$_filelist[134]="s0302a.att";
+$_filelist[135]="s0303a.att";
+$_filelist[136]="s0304a.att";
+$_filelist[137]="s0305a.att";
+$_filelist[138]="vin01a.att";
+$_filelist[139]="vin02a1.att";
+$_filelist[140]="vin02a2.att";
+$_filelist[141]="vin02a3.att";
+$_filelist[142]="vin02a4.att";
+$_filelist[143]="s0510m1.mul";
+$_filelist[144]="s0510m2.mul";
+$_filelist[145]="s0511m.mul";
+$_filelist[146]="s0512m.mul";
+$_filelist[147]="s0514m.mul";
+$_filelist[148]="s0513m.mul";
+$_filelist[149]="s0515m.mul";
+$_filelist[150]="s0516m.mul";
+$_filelist[151]="s0517m.mul";
+$_filelist[152]="s0518m.nrf";
+$_filelist[153]="s0519m.mul";
+$_filelist[154]="s0501m.mul";
+$_filelist[155]="s0520m.nrf";
+$_filelist[156]="s0502m.mul";
+$_filelist[157]="s0503m.mul";
+$_filelist[158]="s0504m.mul";
+$_filelist[159]="s0505m.mul";
+$_filelist[160]="s0506m.mul";
+$_filelist[161]="s0507m.mul";
+$_filelist[162]="s0508m.mul";
+$_filelist[163]="s0509m.mul";
+$_filelist[164]="s0201m.mul";
+$_filelist[165]="s0202m.mul";
+$_filelist[166]="s0203m.mul";
+$_filelist[167]="s0301m.mul";
+$_filelist[168]="s0302m.mul";
+$_filelist[169]="s0303m.mul";
+$_filelist[170]="s0304m.mul";
+$_filelist[171]="s0305m.mul";
+$_filelist[172]="abh01t.tik";
+$_filelist[173]="abh02t.tik";
+$_filelist[174]="abh03t.tik";
+$_filelist[175]="abh04t.nrf";
+$_filelist[176]="abh05t.nrf";
+$_filelist[177]="abh06t.nrf";
+$_filelist[178]="abh07t.nrf";
+$_filelist[179]="abh08t.nrf";
+$_filelist[180]="abh09t.nrf";
+$_filelist[181]="s0401t.tik";
+$_filelist[182]="s0402t.tik";
+$_filelist[183]="s0403t.tik";
+$_filelist[184]="s0404t.tik";
+$_filelist[185]="s0101t.tik";
+$_filelist[186]="s0102t.tik";
+$_filelist[187]="s0103t.tik";
+$_filelist[188]="s0104t.nrf";
+$_filelist[189]="s0105t.nrf";
+$_filelist[190]="s0519t.tik";
+$_filelist[191]="s0501t.nrf";
+$_filelist[192]="s0201t.tik";
+$_filelist[193]="s0202t.tik";
+$_filelist[194]="s0203t.tik";
+$_filelist[195]="s0301t.tik";
+$_filelist[196]="s0302t.tik";
+$_filelist[197]="s0303t.tik";
+$_filelist[198]="s0304t.tik";
+$_filelist[199]="s0305t.tik";
+$_filelist[200]="vin10t.nrf";
+$_filelist[201]="vin11t.nrf";
+$_filelist[202]="vin12t.nrf";
+$_filelist[203]="vin13t.nrf";
+$_filelist[204]="vin01t1.tik";
+$_filelist[205]="vin01t2.tik";
+$_filelist[206]="vin02t.tik";
+$_filelist[207]="vin04t.nrf";
+$_filelist[208]="vin05t.nrf";
+$_filelist[209]="vin06t.nrf";
+$_filelist[210]="vin07t.nrf";
+$_filelist[211]="vin08t.nrf";
+$_filelist[212]="vin09t.nrf";
+$_filelist[213]="vin01m.mul";
+$_filelist[214]="vin02m1.mul";
+$_filelist[215]="vin02m2.mul";
+$_filelist[216]="vin02m3.mul";
+$_filelist[217]="vin02m4.mul";

Some files were not shown because too many files changed in this diff