2
0
Эх сурвалжийг харах

Merge branch 'laravel' of https://github.com/iapt-platform/mint into laravel

bhikkhu-kosalla-china 4 жил өмнө
parent
commit
791e8f0b1e
100 өөрчлөгдсөн 2805 нэмэгдсэн , 732 устгасан
  1. 8 3
      app/Http/Controllers/Controller.php
  2. 199 0
      app/Http/Controllers/DhammaTermController.php
  3. 11 0
      app/Models/DhammaTerm.php
  4. 11 0
      app/Models/FileIndex.php
  5. 11 0
      app/Models/GroupInfo.php
  6. 11 0
      app/Models/GroupMember.php
  7. 11 0
      app/Models/Share.php
  8. 1 1
      app/Providers/AppServiceProvider.php
  9. 50 0
      database/migrations/2022_02_02_103531_create_dhamma_terms_table.php
  10. 47 0
      database/migrations/2022_02_04_012828_create_shares_table.php
  11. 41 0
      database/migrations/2022_02_05_020339_create_group_infos_table.php
  12. 43 0
      database/migrations/2022_02_05_024244_create_group_members_table.php
  13. 57 0
      database/migrations/2022_02_06_075148_create_file_indices_table.php
  14. 1 1
      deploy/roles/ubuntu/tasks/main.yml
  15. 3 3
      public/app/admin/setting.php
  16. 1 1
      public/app/article/article.js
  17. 180 0
      public/app/article/print.php
  18. 0 0
      public/app/article/templiates/footnote.tpl
  19. 15 18
      public/app/article/templiates/main.tpl
  20. 0 0
      public/app/article/templiates/reference.tpl
  21. 0 0
      public/app/article/templiates/term.tpl
  22. 29 31
      public/app/config.table.php
  23. 1 1
      public/app/doc/card.php
  24. 1 1
      public/app/doc/coop.php
  25. 2 2
      public/app/doc/coopfilelist.php
  26. 2 2
      public/app/doc/docinfo.php
  27. 15 13
      public/app/doc/fork.php
  28. 2 2
      public/app/doc/function.php
  29. 7 26
      public/app/doc/pcs2db.php
  30. 11 7
      public/app/group/function.php
  31. 3 32
      public/app/group/get.php
  32. 1 1
      public/app/group/get_name.php
  33. 5 21
      public/app/group/group_del.php
  34. 4 4
      public/app/group/list.php
  35. 1 1
      public/app/group/list_member.php
  36. 19 41
      public/app/group/member_del.php
  37. 39 36
      public/app/group/member_put.php
  38. 39 31
      public/app/group/my_group_put.php
  39. 19 7
      public/app/palicanon/palicanon.js
  40. 3 3
      public/app/pcdl/get_res_index.php
  41. 6 0
      public/app/pcdl/head_bar.php
  42. 1 1
      public/app/public/_pdo.php
  43. 2 2
      public/app/share/coop_del.php
  44. 2 2
      public/app/share/coop_get.php
  45. 2 2
      public/app/share/coop_post.php
  46. 86 61
      public/app/share/coop_put.php
  47. 9 9
      public/app/share/function.php
  48. 1 1
      public/app/share/share.js
  49. 10 10
      public/app/studio/file_index.php
  50. 2 2
      public/app/studio/get_res_json.php
  51. 3 3
      public/app/studio/getfilelist.php
  52. 9 9
      public/app/studio/js/index_mydoc.js
  53. 98 69
      public/app/studio/project.php
  54. 2 2
      public/app/studio/project_load.php
  55. 2 2
      public/app/studio/project_load_db.php
  56. 20 18
      public/app/term/channal_list.php
  57. 3 3
      public/app/term/get_term_index.php
  58. 80 0
      public/app/term/my_dict_list-beta.php
  59. 129 0
      public/app/term/my_dict_list.js
  60. 21 100
      public/app/term/my_dict_list.php
  61. 1 1
      public/app/term/new.php
  62. 22 7
      public/app/term/note.js
  63. 12 2
      public/app/term/term.css
  64. 12 5
      public/app/term/term.js
  65. 40 18
      public/app/term/term.php
  66. 4 4
      public/app/term/term_channel_get.php
  67. 141 35
      public/app/term/term_edit_dlg.js
  68. 10 5
      public/app/term/term_get.php
  69. 3 3
      public/app/term/term_get_id.php
  70. 2 2
      public/app/term/term_popup.js
  71. 69 39
      public/app/term/term_post.php
  72. 3 3
      public/app/term/update_analytics.php
  73. 19 0
      public/app/ucenter/jquery_jwt_example.html
  74. 1 1
      public/app/uwbw/create_wbw.php
  75. 4 3
      public/app/uwbw/update.js
  76. 7 2
      public/app/uwbw/update.php
  77. 17 0
      public/db/sqlite/dhammaterm/term.sql
  78. 43 0
      public/db/sqlite/fileindex/up.sql
  79. 35 0
      public/db/sqlite/group/up.sql
  80. 0 0
      public/db/sqlite/share/share.sql
  81. 9 1
      public/documents/testing.md
  82. 2 0
      routes/api.php
  83. 8 0
      v1/scripts/install3.sh
  84. 9 0
      v1/scripts/install4.sh
  85. 1 1
      v1/scripts/migrations/20211204120600_wbw_blocks_copy.php
  86. 1 1
      v1/scripts/migrations/20211207052901_sent_copy.php
  87. 1 1
      v1/scripts/migrations/20211207164600_sent_pr_copy.php
  88. 1 1
      v1/scripts/migrations/20211207171500_sent_historay_copy.php
  89. 2 2
      v1/scripts/migrations/20211214181900_user_operation_log_copy.php
  90. 2 2
      v1/scripts/migrations/20211214190200_user_operation_frames_copy.php
  91. 2 2
      v1/scripts/migrations/20211214191900_user_operation_dailys_copy.php
  92. 1 1
      v1/scripts/migrations/20211215214400_channel_copy.php
  93. 1 1
      v1/scripts/migrations/20211218093500_articles_copy.php
  94. 1 1
      v1/scripts/migrations/20211218132000_collections_copy.php
  95. 3 3
      v1/scripts/migrations/20211218133000_article_collection_copy.php
  96. 190 0
      v1/scripts/migrations/20220202172100_dhamma_terms_copy.php
  97. 195 0
      v1/scripts/migrations/20220204081300_share_copy.php
  98. 181 0
      v1/scripts/migrations/20220205084100_group_info_copy.php
  99. 170 0
      v1/scripts/migrations/20220205092400_group_member_copy.php
  100. 188 0
      v1/scripts/migrations/20220206143600_fileindex_copy.php

+ 8 - 3
app/Http/Controllers/Controller.php

@@ -11,7 +11,7 @@ class Controller extends BaseController
 {
     use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
 
-	public function sendResponse($result,$message){
+	public function sendResponse($result,$message=""){
 		$response = [
 			'ok' => true,
 			'data'=>$result,
@@ -19,7 +19,9 @@ class Controller extends BaseController
 		];
 		return response()->json($response,200);
 	}
-
+    public function ok($result,$message=""){
+        return $this->sendResponse($result,$message);
+    }
 	public function sendError($error, $errorMessages = [], $code = 404){
 		$response = [
 			'ok' => false,
@@ -27,6 +29,9 @@ class Controller extends BaseController
 			'message'=> $error,
 		];
 		return response()->json($response,code);
-
 	}
+
+    public function error($error, $errorMessages, $code){
+        return $this->sendError($error, $errorMessages, $code);
+    }
 }

+ 199 - 0
app/Http/Controllers/DhammaTermController.php

@@ -0,0 +1,199 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\DhammaTerm;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\DB;
+
+class DhammaTermController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index(Request $request)
+    {
+        $result=false;
+		$indexCol = ['id','guid','word','word_en','meaning','other_meaning','note','language','channal','updated_at'];
+
+		switch ($request->get('view')) {
+			case 'user':
+				# code...
+                $userUid = $_COOKIE['user_uid'];
+                $search = $request->get('search');
+				$table = DhammaTerm::select($indexCol)
+									->where('owner', $userUid);
+				if(!empty($search)){
+					$table->where('word', 'like', $search."%")
+                          ->orWhere('word_en', 'like', $search."%")
+                          ->orWhere('meaning', 'like', "%".$search."%");
+				}
+				if(!empty($request->get('order')) && !empty($request->get('dir'))){
+					$table->orderBy($request->get('order'),$request->get('dir'));
+				}else{
+					$table->orderBy('updated_at','desc');
+				}
+				$count = $table->count();
+				if(!empty($request->get('limit'))){
+					$offset = 0;
+					if(!empty($request->get("offset"))){
+						$offset = $request->get("offset");
+					}
+					$table->skip($offset)->take($request->get('limit'));
+				}
+				$result = $table->get();
+				break;
+			case 'word':
+				$result = DhammaTerm::select($indexCol)
+									->where('word', $request->get("word"))
+									->orderBy('created_at','desc')
+									->get();
+				break;
+            case 'hot-meaning':
+                $key='term/hot_meaning';
+                $value = Cache::get($key, function()use($request) {
+                    $hotMeaning=[];
+                    $words = DhammaTerm::select('word')
+                                ->where('language',$request->get("language"))
+                                ->groupby('word')
+                                ->get();
+                    
+                    foreach ($words as $key => $word) {
+                        # code...
+                        $result = DhammaTerm::select(DB::raw('count(*) as word_count, meaning'))
+                                ->where('language',$request->get("language"))
+                                ->where('word',$word['word'])
+                                ->groupby('meaning')
+                                ->orderby('word_count','desc')
+                                ->first();
+                        if($result){
+                            $hotMeaning[]=[
+                                'word'=>$word['word'],
+                                'meaning'=>$result['meaning'],
+                                'language'=>$request->get("language"),
+                                'owner'=>'',
+                            ];
+                        }
+                    }
+                    Cache::put($key, $hotMeaning, 3600);
+                    return $hotMeaning;
+                });
+                return $this->ok(["rows"=>$value,"count"=>count($value)]);
+                break;
+			default:
+				# code...
+				break;
+		}
+		if($result){
+			return $this->ok(["rows"=>$result,"count"=>$count]);
+		}else{
+			return $this->error("没有查询到数据");
+		}
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+                // validate
+        // read more on validation at http://laravel.com/docs/validation
+        $rules = array(
+            'word' => 'required',
+            'meaning' => 'required',
+            'language' => 'required'
+        );
+        $validator = Validator::make($request->all(), $rules);
+
+        // process the login
+        if ($validator->fails()) {
+            return $this->error($validator);
+        } else {
+            #查询重复的
+            $table = DhammaTerm::where('owner', $_COOKIE["user_uid"])
+                    ->where('word',$request->get("word"))
+                    ->where('tag',$request->get("tag"));
+            if($request->get("channel")){
+                $isDoesntExist = $table->where('channel',$request->get("channel"))
+                      ->doesntExist();
+            }else{
+                $isDoesntExist = $table->where('language',$request->get("language"))
+                    ->doesntExist();
+            }
+	
+            if($isDoesntExist){
+                #不存在插入数据
+                $term = new DhammaTerm;
+                $term->id=$snowflake->id();
+                $term->guid=Str::uuid();
+                $term->word=$request->get("word");
+                $term->meaning=$request->get("meaning");
+                $term->save();
+                return $this->ok($data);
+
+            }else{
+                return $this->error("word existed");
+            }
+            // store
+            /*
+            $data = $request->all();
+            $data['id'] = $snowflake->id();
+            $data['guid'] = Str::uuid();
+            DhammaTerm::create($data);
+            */
+            
+        }
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function show(DhammaTerm $dhammaTerm)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, DhammaTerm $dhammaTerm)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\DhammaTerm  $dhammaTerm
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(DhammaTerm $dhammaTerm,Request $request)
+    {
+        //
+        $arrId = json_decode($request->get("id"),true) ;
+		$count = 0;
+		foreach ($arrId as $key => $id) {
+			# code...
+			$result = DhammaTerm::where('id', $id)
+							->where('owner', $_COOKIE["user_uid"])
+							->delete();
+            if($result){
+                $count++;
+            }
+		}
+		return $this->ok($count);
+    }
+}

+ 11 - 0
app/Models/DhammaTerm.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class DhammaTerm extends Model
+{
+    use HasFactory;
+}

+ 11 - 0
app/Models/FileIndex.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class FileIndex extends Model
+{
+    use HasFactory;
+}

+ 11 - 0
app/Models/GroupInfo.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class GroupInfo extends Model
+{
+    use HasFactory;
+}

+ 11 - 0
app/Models/GroupMember.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class GroupMember extends Model
+{
+    use HasFactory;
+}

+ 11 - 0
app/Models/Share.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Share extends Model
+{
+    use HasFactory;
+}

+ 1 - 1
app/Providers/AppServiceProvider.php

@@ -19,7 +19,7 @@ class AppServiceProvider extends ServiceProvider
         //雪花算法
 		
 		$this->app->singleton('snowflake', function () {
-            return (new Snowflake())
+            return (new Snowflake(env('SNOWFLAKE_DATA_CENTER_ID'),env('SNOWFLAKE_WORKER_ID')))
                 ->setStartTimeStamp(strtotime(config('database.snowflake.start'))*1000)
                 ->setSequenceResolver(
                     new LaravelSequenceResolver($this->app->get('cache')->store()

+ 50 - 0
database/migrations/2022_02_02_103531_create_dhamma_terms_table.php

@@ -0,0 +1,50 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateDhammaTermsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('dhamma_terms', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+            $table->string('guid',36)->uniqid();
+
+            $table->string('word',1024)->index();
+            $table->string('word_en',1024)->index();
+            $table->string('meaning',1024)->index();
+            $table->string('other_meaning',1024)->nullable();
+            $table->text('note',1024)->nullable();
+            $table->string('tag',1024)->nullable();
+            $table->string('channal',36)->index()->nullable();
+            $table->string('language',16)->default('zh-hans');
+            $table->string('owner',36)->index();
+            $table->bigInteger('editor_id')->index();
+
+            $table->bigInteger('create_time');
+            $table->bigInteger('modify_time');
+
+			$table->timestamp('created_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+			$table->timestamp('deleted_at')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('dhamma_terms');
+    }
+}

+ 47 - 0
database/migrations/2022_02_04_012828_create_shares_table.php

@@ -0,0 +1,47 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateSharesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('shares', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+
+            $table->string('res_id',36);
+            $table->integer('res_type');
+            $table->string('cooperator_id',36);
+            $table->integer('cooperator_type');
+            $table->integer('power');
+            $table->bigInteger('create_time');
+            $table->bigInteger('modify_time');
+
+			$table->timestamp('accepted_at')->nullable()->index();
+            $table->bigInteger('acceptor')->nullable();
+
+			$table->timestamp('created_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+
+            $table->unique(['res_id','res_type','cooperator_id','cooperator_type']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('shares');
+    }
+}

+ 41 - 0
database/migrations/2022_02_05_020339_create_group_infos_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateGroupInfosTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('group_infos', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+
+            $table->string('uid',36)->uniqid()->index();
+            $table->string('name',64)->uniqid()->index();
+            $table->string('description',1024)->nullable();
+            $table->integer('status')->default(30);
+            $table->string('owner',36)->index();
+            $table->bigInteger('create_time');
+            $table->bigInteger('modify_time');
+            $table->timestamp('created_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('group_infos');
+    }
+}

+ 43 - 0
database/migrations/2022_02_05_024244_create_group_members_table.php

@@ -0,0 +1,43 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateGroupMembersTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('group_members', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+
+            $table->string('user_id',36)->index();
+            $table->string('group_id',36)->index();
+            $table->string('group_name',64)->nullable();
+
+            $table->integer('power')->default(1);
+            $table->integer('level')->default(0);
+            $table->integer('status')->default(1)->index();
+            $table->timestamp('created_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+
+            $table->unique(['user_id','group_id']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('group_members');
+    }
+}

+ 57 - 0
database/migrations/2022_02_06_075148_create_file_indices_table.php

@@ -0,0 +1,57 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateFileIndicesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('file_indices', function (Blueprint $table) {
+			#使用雪花id
+            $table->bigInteger('id')->primary();
+
+            $table->string('uid',36)->uniqid();
+            $table->string('parent_id',36)->nullable()->index();
+            $table->bigInteger('user_id')->index();
+            $table->integer('book');
+            $table->integer('paragraph');
+            $table->string('channal',36)->nullable()->index();
+            $table->string('file_name',128)->nullable()->index();
+            $table->string('title',128)->index();
+            $table->string('tag',512)->nullable()->index();
+            $table->integer('status')->default(1);
+            $table->integer('file_size')->nullable();
+            $table->integer('share')->default(0);
+            $table->text('doc_info');
+            $table->text('doc_block');
+
+            $table->bigInteger('create_time');
+            $table->bigInteger('modify_time');
+            $table->bigInteger('accese_time');
+
+            $table->timestamp('created_at')->useCurrent()->index();
+            $table->timestamp('accesed_at')->useCurrent()->index();
+			$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate()->index();
+            $table->timestamp('deleted_at')->nullable();
+
+            $table->index(['book','paragraph']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('file_indices');
+    }
+}

+ 1 - 1
deploy/roles/ubuntu/tasks/main.yml

@@ -130,7 +130,7 @@
 
 - name: Set timezone
   become: true
-  shell: timedatectl set-timezone Asia/Shanghai
+  shell: timedatectl set-timezone UTC
 
 - name: Set git rebase mode
   become: true

+ 3 - 3
public/app/admin/setting.php

@@ -124,11 +124,11 @@ foreach ($Fetch as $album) {
         echo "</table>";
         break;
     case "share":
-        PDO_Connect("" . _FILE_DB_FILEINDEX_);
-        $query = "SELECT count(*) from 'fileindex' where share=1";
+        PDO_Connect(_FILE_DB_FILEINDEX_);
+        $query = "SELECT count(*) from "._TABLE_FILEINDEX_." where share=1";
         $file_count = PDO_FetchOne($query);
         echo "共计:{$file_count} 个共享文件";
-        $query = "SELECT * from 'fileindex' where share=1 limit 0,100";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where share=1 limit 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>";

+ 1 - 1
public/app/article/article.js

@@ -46,7 +46,7 @@ function articel_load(id, collection_id) {
 						$("#article_author").html( article_author );
 
 						//将绝对链接转换为 用户连接的主机链接
-						result.content = result.content.replace(/[A-z]*.wikipali.org/g,location.host);
+						//result.content = result.content.replace(/www-[A-z]*.wikipali.org/g,location.host);
 
 						$("#contents").html(note_init(result.content,"",result.owner,result.lang));
 						//处理<code>标签作为气泡注释

+ 180 - 0
public/app/article/print.php

@@ -0,0 +1,180 @@
+<?php
+require_once __DIR__."/../config.php";
+require_once "../pcdl/html_head.php";
+?>
+<body style="margin: 0;padding: 0;" class="reader_body" >
+	<script>
+		var gCaseTable=<?php echo file_get_contents("../public/js/case.json"); ?>
+	</script>
+
+	<script  src="./article.js"></script>
+
+	<script>
+	<?php
+	$_id = "";
+	$_display = "";
+	$_channal  = "";
+	$_collect = "";
+
+	if(isset($_GET["view"])){
+		echo "_view='".$_GET["view"]."';";
+	}
+	else{
+		echo "_view='article';";
+	}
+
+	if(isset($_GET["collection"])){
+		echo "_collection_id='".$_GET["collection"]."';";
+	}
+
+	if(isset($_GET["channel"])){
+		echo "_channal='".$_GET["channel"]."';";
+	}
+
+
+	
+	if(isset($_GET["mode"]) && $_GET["mode"]=="edit" && isset($_COOKIE["userid"])){
+		#登录状态下 编辑模式
+		$_mode = "edit";
+		echo "_mode='edit';";
+		$classMode="edit_mode";
+	}
+	else{
+		$_mode = "read";
+		echo "_mode='read';";
+		$classMode="read_mode";
+	}
+	if(isset($_GET["display"])){
+		if($_mode == "edit"){
+			$_display = "sent";
+			echo "_display='sent';";	
+		}
+		else{
+			$_display = $_GET["display"];
+			echo "_display='".$_GET["display"]."';";	
+		}
+	}
+	else{
+		if($_mode=="read"){
+			$_display = "para";
+			echo "_display='para';";
+		}
+		else{
+			$_display = "sent";
+			echo "_display='sent';";			
+		}
+
+	}	
+	if(isset($_GET["direction"])){
+		$_direction = $_GET["direction"];
+		echo "_direction='".$_GET["direction"]."';";
+	}
+	else{
+		if($_mode=="read"){
+			$_direction = "row";
+			echo "_direction='row';";
+		}
+		else{
+			$_direction = "col";
+			echo "_direction='col';";
+		}
+	}
+	$contentClass= "";
+	if($_direction=="row"){
+		$contentClass .= ' horizontal ';
+	}
+	else{
+		$contentClass .= ' vertical ';
+	}
+	if($_display=="para"){
+		$contentClass .= ' para_mode ';
+	}
+	else{
+		$contentClass .= ' sent_mode ';
+	}
+	$contentClass .= " $_mode ";
+	
+	?>
+	</script>
+
+
+<link type="text/css" rel="stylesheet" href="style.css"  />
+
+<script src="../article/my_collect.js" type="text/javascript"></script>
+
+<script src="../../node_modules/mustache/mustache.js"></script>
+
+<style>
+ul.fancytree-container{
+	border:unset;
+	width: max-content;
+}
+.fancytree-container .active {
+    font-weight: 700;
+    color: var(--main-color);
+	background: linear-gradient(to right, var(--link-color), var(--nocolor));
+    border-radius: 5px;
+}
+span.fancytree-title{
+	color: var(--main-color1);
+}
+span.fancytree-node{
+	display: flex;
+}
+
+
+#content_toc>ul>li>span.fancytree-node{
+	font-size: 120%;
+    font-weight: 900;
+}
+#article_path chapter{
+	display:unset;
+}
+
+#contents ul, li {
+    margin-block-start: 0.5em;
+    margin-block-end: 0.5em;
+    margin-left: 7px;
+}
+.click_dropdown_div{
+	align-self: center;
+}
+.channel_select_button{
+	color: var(--link-color);
+	
+}
+.channel_select_button:hover{
+	text-decoration-line: underline;
+	
+}
+.sent_tran_div a{
+	white-space: normal;
+	overflow-wrap: anywhere;
+}
+.para_tran_div a{
+	white-space: normal;
+	overflow-wrap: anywhere;
+}
+
+</style>
+
+
+
+<div id="main_view" class="main_view <?php echo $classMode;?>">
+
+</div>
+
+
+
+<script>
+
+$(document).ready(function(){
+	note_create();
+	historay_init();
+    collection_load(_collection_id);
+});
+
+</script>
+
+</body>
+</html>

+ 0 - 0
public/app/article/templiates/footnote.tpl


+ 15 - 18
public/app/article/templiates/main.tpl

@@ -1,22 +1,19 @@
-<div>
-{{title}}
-</div>
-<div>
-{{subtitle}}
-</div>
-<div>
-{{editor.name}} at {{updated_at}}
-</div>
-<div class="content">
-{{content}}
+<div class="article">
+    {{#article}}
+        <div class="title heading{{article.level}}">{{article.title}}</div>
+        <div class="subtitle">{{article.subtitle}}</div>
+        <div class="editor">
+        {{article.editor.name}} at {{article.updated_at}}
+        </div>
+        <content>{{article.content}}</content>
+    {{/article}}
 </div>
 
 <h2>Glossary</h2>
-{{#glossary}}
-<b>{{pali}}</b>:{{meaning}}
-{{/glossary}}
+<glossary></glossary>
+
+<h2>reference</h2>
+<reference></reference>
 
-<h2>ref</h2>
-{{#ref}}
-{{path}}
-{{/ref}}
+<h2>footnote</h2>
+<footnote></footnote>

+ 0 - 0
public/app/article/templiates/reference.tpl


+ 0 - 0
public/app/article/templiates/term.tpl


+ 29 - 31
public/app/config.table.php

@@ -292,14 +292,14 @@ define("_SQLITE_DB_TERM_", "sqlite:" . __DIR__ . "/../tmp/user/dhammaterm.db");
 define("_SQLITE_TABLE_TERM_", "term");
 
 define("_PG_DB_TERM_", _PDO_DB_DSN_);
-define("_PG_TABLE_TERM_", "term");
+define("_PG_TABLE_TERM_", "dhamma_terms");
 
 # 协作
 define("_SQLITE_DB_USER_SHARE_", "sqlite:" . __DIR__ . "/../tmp/user/share.db3");
 define("_SQLITE_TABLE_USER_SHARE_", "share_cooperator");
 
 define("_PG_DB_USER_SHARE_", _PDO_DB_DSN_);
-define("_PG_TABLE_USER_SHARE_", "share_cooperator");
+define("_PG_TABLE_USER_SHARE_", "shares");
 
 # 工作组
 define("_SQLITE_DB_GROUP_", "sqlite:" . __DIR__ . "/../tmp/user/group.db3");
@@ -307,8 +307,8 @@ define("_SQLITE_TABLE_GROUP_INFO_", "group_info");
 define("_SQLITE_TABLE_GROUP_MEMBER_", "group_member");
 
 define("_PG_DB_GROUP_", _PDO_DB_DSN_);
-define("_PG_TABLE_GROUP_INFO_", "group_info");
-define("_PG_TABLE_GROUP_MEMBER_", "group_member");
+define("_PG_TABLE_GROUP_INFO_", "group_infos");
+define("_PG_TABLE_GROUP_MEMBER_", "group_members");
 
 # 逐词解析文件索引
 define("_SQLITE_DB_FILEINDEX_", "sqlite:" . __DIR__ . "/../tmp/user/fileindex.db");
@@ -316,8 +316,7 @@ define("_SQLITE_TABLE_FILEINDEX_", "fileindex");
 define("_SQLITE_TABLE_FILEINDEX_POWER_", "power");
 
 define("_PG_DB_FILEINDEX_", _PDO_DB_DSN_);
-define("_PG_TABLE_FILEINDEX_", "fileindex");
-define("_PG_TABLE_FILEINDEX_POWER_", "power");
+define("_PG_TABLE_FILEINDEX_", "file_indices");
 
 # 课程
 define("_SQLITE_DB_COURSE_", "sqlite:" . __DIR__ . "/../tmp/user/course.db3");
@@ -627,10 +626,7 @@ define("_TABLE_USER_OPERATION_LOG_", _PG_TABLE_USER_OPERATION_LOG_);
 
 
 //读取频繁 写入不频繁 
-# 用户账号
-#sqlite
-define("_FILE_DB_USERINFO_", _SQLITE_DB_USERINFO_);
-define("_TABLE_USER_INFO_", _SQLITE_TABLE_USER_INFO_);
+
 
 
 # 版本风格 
@@ -638,7 +634,6 @@ define("_TABLE_USER_INFO_", _SQLITE_TABLE_USER_INFO_);
 define("_FILE_DB_CHANNAL_", _PG_DB_CHANNAL_);
 define("_TABLE_CHANNEL_", _PG_TABLE_CHANNEL_);
 
-
 # 文章 文集
 
 define("_FILE_DB_USER_ARTICLE_", _PG_DB_USER_ARTICLE_);
@@ -646,44 +641,47 @@ define("_TABLE_ARTICLE_", _PG_TABLE_ARTICLE_);
 define("_TABLE_COLLECTION_", _PG_TABLE_COLLECTION_);
 define("_TABLE_ARTICLE_COLLECTION_", _PG_TABLE_ARTICLE_COLLECTION_);
 
-
-
 # 术语
-define("_FILE_DB_TERM_", _SQLITE_DB_TERM_);
-define("_TABLE_TERM_", _SQLITE_TABLE_TERM_);
+define("_FILE_DB_TERM_", _PG_DB_TERM_);
+define("_TABLE_TERM_", _PG_TABLE_TERM_);
 
 # 协作
-define("_FILE_DB_USER_SHARE_", _SQLITE_DB_USER_SHARE_);
-define("_TABLE_USER_SHARE_", _SQLITE_TABLE_USER_SHARE_);
+define("_FILE_DB_USER_SHARE_", _PG_DB_USER_SHARE_);
+define("_TABLE_USER_SHARE_", _PG_TABLE_USER_SHARE_);
 
 # 工作组
-define("_FILE_DB_GROUP_", _SQLITE_DB_GROUP_);
-define("_TABLE_GROUP_INFO_", _SQLITE_TABLE_GROUP_INFO_);
-define("_TABLE_GROUP_MEMBER_", _SQLITE_TABLE_GROUP_MEMBER_);
+define("_FILE_DB_GROUP_", _PG_DB_GROUP_);
+define("_TABLE_GROUP_INFO_", _PG_TABLE_GROUP_INFO_);
+define("_TABLE_GROUP_MEMBER_", _PG_TABLE_GROUP_MEMBER_);
 
 # 逐词解析文件索引
-define("_FILE_DB_FILEINDEX_", _SQLITE_DB_FILEINDEX_);
-define("_TABLE_FILEINDEX_", _SQLITE_TABLE_FILEINDEX_);
-define("_TABLE_FILEINDEX_POWER_", _SQLITE_TABLE_FILEINDEX_POWER_);
+define("_FILE_DB_FILEINDEX_", _PG_DB_FILEINDEX_);
+define("_TABLE_FILEINDEX_", _PG_TABLE_FILEINDEX_);
 
-# 课程
-define("_FILE_DB_COURSE_", _SQLITE_DB_COURSE_);
-define("_TABLE_COURSE_",_SQLITE_TABLE_COURSE_);
-define("_TABLE_LESSON_",_SQLITE_TABLE_LESSON_);
 
 # 用户自定义书
 define("_FILE_DB_USER_CUSTOM_BOOK_", _SQLITE_DB_USER_CUSTOM_BOOK_);
 define("_TABLE_CUSTOM_BOOK_", _SQLITE_TABLE_CUSTOM_BOOK_);
 define("_TABLE_CUSTOM_BOOK_SENT_", _SQLITE_TABLE_CUSTOM_BOOK_SENT_);
 
-# 逐词译和译文编辑消息 无需迁移数据
-define("_FILE_DB_MESSAGE_", _SQLITE_DB_MESSAGE_);
-define("_TABLE_MESSAGE_", _SQLITE_TABLE_MESSAGE_);
-
 #点赞
 define("_FILE_DB_LIKE_", _SQLITE_DB_LIKE_);
 define("_TABLE_LIKE_", _SQLITE_TABLE_LIKE_);
 
+# 课程
+define("_FILE_DB_COURSE_", _SQLITE_DB_COURSE_);
+define("_TABLE_COURSE_",_SQLITE_TABLE_COURSE_);
+define("_TABLE_LESSON_",_SQLITE_TABLE_LESSON_);
+
+
+# 用户账号
+define("_FILE_DB_USERINFO_", _SQLITE_DB_USERINFO_);
+define("_TABLE_USER_INFO_", _SQLITE_TABLE_USER_INFO_);
+
+# 逐词译和译文编辑消息 无需迁移数据
+define("_FILE_DB_MESSAGE_", _SQLITE_DB_MESSAGE_);
+define("_TABLE_MESSAGE_", _SQLITE_TABLE_MESSAGE_);
+
 
 # 用户字典统计数据 刷库 - 无需迁移数据
 define("_FILE_DB_USER_DICT_", _SQLITE_DB_USER_DICT_);

+ 1 - 1
public/app/doc/card.php

@@ -9,7 +9,7 @@ require_once '../ucenter/function.php';
 if (isset($_GET["id"])) {
 	$output["id"]=$_GET["id"];
 	PDO_Connect( _FILE_DB_FILEINDEX_);
-	$query = "SELECT title,create_time,user_id as owner FROM fileindex  WHERE id = ? ";
+	$query = "SELECT title,create_time,user_id as owner FROM "._TABLE_FILEINDEX_."  WHERE uid = ? ";
 	$result = PDO_FetchRow($query, array($_GET["id"]));
 	$strData="";
 	if ($result) {

+ 1 - 1
public/app/doc/coop.php

@@ -52,7 +52,7 @@ $powerlist["30"] = "可修改";
 PDO_Connect(_FILE_DB_FILEINDEX_);
 
 echo "<input id='doc_coop_docid' type='hidden' value='{$_doc_id}' />";
-$query = "SELECT * from fileindex where id = ? ";
+$query = "SELECT * from "._TABLE_FILEINDEX_." where uid = ? ";
 $Fetch = PDO_FetchAll($query, array($_doc_id));
 $iFetch = count($Fetch);
 if ($iFetch > 0) {

+ 2 - 2
public/app/doc/coopfilelist.php

@@ -20,7 +20,7 @@ else{
     $Fetch = PDO_FetchAll($query,array($_COOKIE["userid"]));
     $result=array();
     foreach($Fetch as $row){
-        $query = "SELECT * from fileindex where id = ?  ";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where uid = ?  ";
         $FetchFile = PDO_FetchAll($query,array($row['doc_id']));
         if(count($FetchFile)>0){
             $FetchFile[0]["power"]=$row["power"];
@@ -28,7 +28,7 @@ else{
             $FetchFile[0]["power_create_time"]=$row["create_time"];
             $FetchFile[0]["power_modify_time"]=$row["modify_time"];
             $FetchFile[0]["user_name"]=ucenter_get($FetchFile[0]["user_id"],"");
-            $query = "SELECT id from fileindex where parent_id = ? and user_id = ? ";
+            $query = "SELECT uid from "._TABLE_FILEINDEX_." where parent_id = ? and user_id = ? ";
             $FetchFile[0]["my_doc_id"] = PDO_FetchOne($query,array($row['doc_id'],$uid));
             $FetchFile[0]["path"] = _get_para_path($FetchFile[0]["book"],$FetchFile[0]["paragraph"]);
             $result[] = $FetchFile[0];

+ 2 - 2
public/app/doc/docinfo.php

@@ -15,11 +15,11 @@ if ($_COOKIE["userid"]) {
     $isLogin = true;
 }
 
-PDO_Connect("" . _FILE_DB_FILEINDEX_);
+PDO_Connect(_FILE_DB_FILEINDEX_);
 if (isset($_GET["id"])) {
 
     $doc_id = $_GET["id"];
-    $query = "SELECT * from fileindex where id = ? ";
+    $query = "SELECT * from "._TABLE_FILEINDEX_." where uid = ? ";
     $Fetch = PDO_FetchAll($query, array($doc_id));
     $iFetch = count($Fetch);
     if ($iFetch > 0) {

+ 15 - 13
public/app/doc/fork.php

@@ -29,9 +29,9 @@ if (isset($_GET["doc_id"]) == false) {
     echo "没有 文档编号";
     exit;
 }
-PDO_Connect("" . _FILE_DB_FILEINDEX_);
+PDO_Connect( _FILE_DB_FILEINDEX_);
 $doc_id = $_GET["doc_id"];
-$query = "select * from fileindex where id= ? ";
+$query = "SELECT * from "._TABLE_FILEINDEX_." where uid= ? ";
 $Fetch = PDO_FetchAll($query, array($doc_id));
 $iFetch = count($Fetch);
 if ($iFetch > 0) {
@@ -104,7 +104,7 @@ if (isset($_GET["channel"]) == false) {
 {
     PDO_Connect( _FILE_DB_FILEINDEX_,_DB_USERNAME_,_DB_PASSWORD_);
     $doc_id = $_GET["doc_id"];
-    $query = "SELECT * from fileindex where id= ? ";
+    $query = "SELECT * from "._TABLE_FILEINDEX_." where uid= ? ";
     $Fetch = PDO_FetchAll($query, array($doc_id));
     $iFetch = count($Fetch);
     if ($iFetch > 0) {
@@ -123,7 +123,7 @@ if (isset($_GET["channel"]) == false) {
         } else {
             //别人的文档
             //查询自己是否以前打开过
-            $query = "SELECT * from fileindex where parent_id='{$doc_id}' and user_id='{$uid}' ";
+            $query = "SELECT * from "._TABLE_FILEINDEX_." where parent_id='{$doc_id}' and user_id='{$uid}' ";
             $FetchSelf = PDO_FetchAll($query);
             $iFetchSelf = count($FetchSelf);
             if ($iFetchSelf > 0) {
@@ -139,8 +139,8 @@ if (isset($_GET["channel"]) == false) {
                 echo "<div style='display:none;'>";
                 //获取文件路径
 
-                PDO_Connect("" . _FILE_DB_USERINFO_);
-                $query = "select userid from user where id='{$owner}'";
+                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;
@@ -309,8 +309,10 @@ if (isset($_GET["channel"]) == false) {
                     //插入记录到文件索引
                     $filesize = 0;
                     //服务器端文件列表
-                    PDO_Connect("" . _FILE_DB_FILEINDEX_);
-                    $query = "INSERT INTO fileindex ('id',
+                    PDO_Connect(_FILE_DB_FILEINDEX_);
+                    $query = "INSERT INTO "._TABLE_FILEINDEX_." (
+                                                        'id',
+                                                        'uid',
                                                        'parent_id',
                                                        'user_id',
                                                        'book',
@@ -325,8 +327,7 @@ if (isset($_GET["channel"]) == false) {
                                                        'file_size',
                                                        'share',
                                                        'doc_info',
-                                                       'doc_block',
-                                                       'receive_time'
+                                                       'doc_block'
                                                        )
                                         VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                     $stmt = $PDO->prepare($query);
@@ -336,7 +337,9 @@ if (isset($_GET["channel"]) == false) {
                     $newDocInfo["parent_id"] = $orgFileInfo["id"];
                     $newDocInfo["user_id"] = $_COOKIE["uid"];
                     $newDocInfo["doc_block"] = json_encode($newDocBlockList, JSON_UNESCAPED_UNICODE);
-                    $newData = array($newDocInfo["id"],
+                    $newData = array(
+                        $snowflake->id(),
+                        $newDocInfo["id"],
                         $newDocInfo["parent_id"],
                         $newDocInfo["user_id"],
                         $newDocInfo["book"],
@@ -351,8 +354,7 @@ if (isset($_GET["channel"]) == false) {
                         $newDocInfo["file_size"],
                         $newDocInfo["share"],
                         $newDocInfo["doc_info"],
-                        $newDocInfo["doc_block"],
-                        mTime(),
+                        $newDocInfo["doc_block"]
                     );
                     $stmt->execute($newData);
                     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {

+ 2 - 2
public/app/doc/function.php

@@ -6,8 +6,8 @@ require_once "../public/_pdo.php";
 function pcs_get_title($id)
 {
     if (isset($id)) {
-		PDO_Connect("" . _FILE_DB_FILEINDEX_);
-		$query = "SELECT title FROM fileindex  WHERE id = ? ";
+		PDO_Connect(_FILE_DB_FILEINDEX_);
+		$query = "SELECT title FROM "._TABLE_FILEINDEX_."  WHERE uid = ? ";
 		$file = PDO_FetchRow($query, array($id));
 		if ($file) {
 			return $file["title"];

+ 7 - 26
public/app/doc/pcs2db.php

@@ -24,9 +24,9 @@ if (isset($_GET["doc_id"]) == false) {
     echo "没有 文档编号";
     exit;
 }
-PDO_Connect("" . _FILE_DB_FILEINDEX_);
+PDO_Connect(_FILE_DB_FILEINDEX_);
 $doc_id = $_GET["doc_id"];
-$query = "SELECT * from fileindex where id= ? ";
+$query = "SELECT book,paragraph from "._TABLE_FILEINDEX_." where uid= ? ";
 $Fetch = PDO_FetchAll($query, array($doc_id));
 $iFetch = count($Fetch);
 if ($iFetch > 0) {
@@ -96,8 +96,8 @@ if (isset($_GET["channel"]) == false) {
 }
 
 $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=? ";
+PDO_Connect(_FILE_DB_FILEINDEX_);
+$query = "SELECT file_name, doc_info, modify_time from "._TABLE_FILEINDEX_." where uid=? ";
 $Fetch = PDO_FetchRow($query, array($_GET["doc_id"]));
 
 if ($Fetch === false) {
@@ -434,28 +434,9 @@ $dataBlock = $xml->xpath('//block');
     //插入记录到文件索引
     $filesize = 0;
     //服务器端文件列表
-    PDO_Connect("" . _FILE_DB_FILEINDEX_);
-    $query = "INSERT INTO fileindex ('id',
-                                   'parent_id',
-                                   'user_id',
-                                   'book',
-                                   'paragraph',
-                                   'file_name',
-                                   'title',
-                                   'tag',
-                                   'status',
-                                   'create_time',
-                                   'modify_time',
-                                   'accese_time',
-                                   'file_size',
-                                   'share',
-                                   'doc_info',
-                                   'doc_block',
-                                   'receive_time'
-                                   )
-                    VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-    $stmt = $PDO->prepare($query);
-    $query = "UPDATE 'fileindex' SET 'doc_info' = ? , 'doc_block' = ?  WHERE id = ? ";
+    PDO_Connect( _FILE_DB_FILEINDEX_);
+
+    $query = "UPDATE "._TABLE_FILEINDEX_." SET 'doc_info' = ? , 'doc_block' = ?  WHERE id = ? ";
     $stmt = $PDO->prepare($query);
     $newData = array(
         $strHead,

+ 11 - 7
public/app/group/function.php

@@ -8,8 +8,8 @@ require_once '../ucenter/function.php';
 function group_get_name($id)
 {
     if (isset($id)) {
-        PDO_Connect("" . _FILE_DB_GROUP_);
-        $query = "SELECT name FROM group_info  WHERE id=?";
+        PDO_Connect(_FILE_DB_GROUP_);
+        $query = "SELECT name FROM "._TABLE_GROUP_INFO_."  WHERE uid=?";
         $Fetch = PDO_FetchRow($query, array($id));
         if ($Fetch) {
             return $Fetch["name"];
@@ -27,9 +27,9 @@ class GroupInfo
     private $buffer;
     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);
+        $dns = _FILE_DB_GROUP_;
+        $this->dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
+        $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $buffer = array();
         $parentId = array();
     }
@@ -43,7 +43,7 @@ class GroupInfo
             return $buffer[$id];
         }
         if ($this->dbh) {
-            $query = "SELECT name FROM group_info WHERE id= ? ";
+            $query = "SELECT name FROM "._TABLE_GROUP_INFO_." WHERE uid= ? ";
             $stmt = $this->dbh->prepare($query);
             $stmt->execute(array($id));
             $user = $stmt->fetch(PDO::FETCH_ASSOC);
@@ -62,6 +62,10 @@ class GroupInfo
 	
 	public function getParentId($id)
     {
+        /*
+        */
+        return 0;
+
         if (empty($id)) {
             return "";
         }
@@ -69,7 +73,7 @@ class GroupInfo
             return $parentId[$id];
         }
         if ($this->dbh) {
-            $query = "SELECT parent FROM group_info WHERE id= ? ";
+            $query = "SELECT parent FROM "._TABLE_GROUP_INFO_." WHERE uid= ? ";
             $stmt = $this->dbh->prepare($query);
             $stmt->execute(array($id));
             $user = $stmt->fetch(PDO::FETCH_ASSOC);

+ 3 - 32
public/app/group/get.php

@@ -11,42 +11,13 @@ $output = array();
 if (isset($_GET["id"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
     $id = $_GET["id"];
-    $query = "SELECT * FROM group_info  WHERE id = ? ";
+    $query = "SELECT * FROM "._TABLE_GROUP_INFO_."  WHERE uid = ? ";
     $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;
-			*/
-			$output["file"] =share_res_list_get($id);
-        }
+		$output["file"] =share_res_list_get($id);
+
     }
 }
 echo json_encode($output, JSON_UNESCAPED_UNICODE);

+ 1 - 1
public/app/group/get_name.php

@@ -9,7 +9,7 @@ require_once '../ucenter/function.php';
 $output = array();
 if (isset($_GET["name"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
-    $query = "SELECT * FROM group_info  WHERE name like ? and parent=0 limit 0,5";
+    $query = "SELECT * FROM "._TABLE_GROUP_INFO_."  WHERE name like ?  limit 50";
     $Fetch = PDO_FetchAll($query, array("%" . $_GET["name"] . "%"));
 
     $user_info = new UserInfo();

+ 5 - 21
public/app/group/group_del.php

@@ -7,35 +7,19 @@ $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 owner=? ";
+    $query = "SELECT id from "._TABLE_GROUP_INFO_." where uid=? and owner=? ";
     $gInfo = PDO_FetchRow($query, array($_POST["groupid"], $_COOKIE["userid"]));
     if ($gInfo) {
         #删除group info
-        $query = "DELETE from group_info where id=? and owner=? ";
+        $query = "DELETE from "._TABLE_GROUP_INFO_." where uid=? and owner=? ";
         PDO_Execute($query, array($_POST["groupid"], $_COOKIE["userid"]));
         #删除 组员
-        $query = "DELETE from group_member where group_id=? ";
+        $query = "DELETE from "._TABLE_GROUP_MEMBER_." where group_id=? ";
         PDO_Execute($query, array($_POST["groupid"]));
         #删除到此组的分享
+        $query = "DELETE from "._TABLE_USER_SHARE_." where cooperator_id=? and cooperator_type=1 ";
+        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 ";

+ 4 - 4
public/app/group/list.php

@@ -7,12 +7,12 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 
 //列出 我j参与的群组
-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"]));
+PDO_Connect(_FILE_DB_GROUP_);
+$query = "SELECT group_name,group_id,power FROM "._TABLE_GROUP_MEMBER_."  WHERE level = 0 and user_id=?";
+$Fetch = PDO_FetchAll($query, array($_COOKIE["user_uid"]));
 foreach ($Fetch as $key => $value) {
 	# code...
-	$query = "SELECT name FROM group_info  WHERE id=?";
+	$query = "SELECT name FROM "._TABLE_GROUP_INFO_."  WHERE uid=?";
 	$groupInfo = PDO_FetchRow($query, array($value["group_id"]));
 	if($groupInfo){
 		$Fetch[$key]["group_name"]=$groupInfo["name"];

+ 1 - 1
public/app/group/list_member.php

@@ -10,7 +10,7 @@ $output = array();
 if (isset($_GET["id"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
     $id = $_GET["id"];
-    $query = "SELECT user_id FROM group_member  WHERE group_id = ? ";
+    $query = "SELECT user_id FROM "._TABLE_GROUP_MEMBER_."  WHERE group_id = ? ";
     $output = PDO_FetchAll($query, array($id));
     $userinfo = new UserInfo();
     foreach ($output as $key => $value) {

+ 19 - 41
public/app/group/member_del.php

@@ -4,6 +4,13 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 
 $respond = array("status" => 0, "message" => "");
+set_exception_handler(function($e){
+    $respond['status'] = 1;
+    $respond['message'] = $e->getFile().$e->getLine().$e->getMessage();
+    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+	exit;
+});
+
 if (!isset($_COOKIE["userid"])) {
     $respond['status'] = 1;
     $respond['message'] = "尚未登录";
@@ -14,28 +21,22 @@ if (isset($_POST["groupid"])) {
     PDO_Connect("" . _FILE_DB_GROUP_);
     $mypower = 100;
     # 先查是否有删人权限
-    $query = "SELECT * from group_info where id=?";
+    #是否是拥有者
+    $query = "SELECT * from "._TABLE_GROUP_INFO_." where uid=?";
     $fc = PDO_FetchRow($query, array($_POST["groupid"]));
     if ($fc) {
-        if ($fc["parent"] == 0) {
-            if ($fc["owner"] == $_COOKIE["userid"]) {
-                $mypower = 0;
-            }
-        } else {
-            $query = "SELECT owner  from group_info where id=?";
-            $g_parent = PDO_FetchRow($query, array($fc["parent"]));
-            if ($g_parent && $g_parent["owner"] == $_COOKIE["userid"]) {
-                $mypower = 0;
-            }
+        if ($fc["owner"] == $_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"]));
+        $query = "SELECT power from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=? ";
+        $power = PDO_FetchRow($query, array($_COOKIE["user_uid"], $_POST["groupid"]));
         if ($power) {
             $mypower = (int) $power["power"];
         }
+        #普通成员无权移除他人
         if ($mypower > 1) {
             $respond['status'] = 1;
             $respond['message'] = "no power to remove memeber";
@@ -45,7 +46,7 @@ if (isset($_POST["groupid"])) {
     }
 
     # 查询被删除人的权限
-    $query = "SELECT power from group_member where user_id=? and group_id=? ";
+    $query = "SELECT power from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=? ";
     $power = PDO_FetchRow($query, array($_POST["userid"], $_POST["groupid"]));
     $userpower = 0;
     if ($power) {
@@ -54,39 +55,16 @@ if (isset($_POST["groupid"])) {
     #操作人的权限不足
     if ($mypower >= $userpower) {
         $respond['status'] = 1;
-        $respond['message'] = "can not removed";
+        $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];
-    }
+    $query = "DELETE from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id =? ";
+    PDO_Execute($query, array($_POST["userid"], $_POST["groupid"]));
+
 } else {
     $respond['status'] = 1;
     $respond['message'] = "参数不足";

+ 39 - 36
public/app/group/member_put.php

@@ -2,56 +2,59 @@
 require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
+
 
 $respond = array("status" => 0, "message" => "");
+
+set_exception_handler(function($e){
+    $respond['status'] = 1;
+    $respond['message'] = $e->getFile().$e->getLine().$e->getMessage();
+    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+	exit;
+});
 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=? ";
+    #先查是否有加人权限 0:拥有者,1.管理员
+    $query = "SELECT power from "._TABLE_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;
-        }
+    if (!$power || $power["power"] > 1) {
+        $respond['status'] = 1;
+        $respond['message'] = "no power to add memeber";
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
     }
 
-    $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=?";
+    #查询组信息
+    $query = "SELECT * from "._TABLE_GROUP_INFO_." where uid=?";
     $g_curr = PDO_FetchRow($query, array($_POST["groupid"]));
+    if (!$g_curr) {
+        $respond['status'] = 1;
+        $respond['message'] = '组不存在';
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
+    }
+#查询是否有重复记录
+    $query = "SELECT * from "._TABLE_GROUP_MEMBER_." where user_id=? and group_id=?";
+    $isExist = PDO_FetchRow($query, array($_POST["userid"], $_POST["groupid"]));
+    if ($isExist) {
+        $respond['status'] = 1;
+        $respond['message'] = '组员已经存在';
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
+    }
 
-    $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )
-		VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
+    $query = "INSERT INTO "._TABLE_GROUP_MEMBER_." (id,  user_id  , group_id  , power , group_name , level ,  status )
+		VALUES  (  ? , ? , ? , ? , ?  ,? ,?) ";
     $sth = $PDO->prepare($query);
-    $sth->execute(array($_POST["userid"], $_POST["groupid"], 2, $g_curr["name"], $level, 1));
-    $respond = array("status" => 0, "message" => "");
+    $sth->execute(array($snowflake->id(),$_POST["userid"], $_POST["groupid"], 2, $g_curr["name"], 0, 1));
     if (!$sth || ($sth && $sth->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
         $respond['status'] = 1;
         $respond['message'] = $error[2];
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        exit;
     }
 }
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 39 - 31
public/app/group/my_group_put.php

@@ -3,41 +3,49 @@
 require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../public/function.php';
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
+
+$respond = array("status" => 0, "message" => "ok");
+set_exception_handler(function($e){
+    $respond['status'] = 1;
+    $respond['message'] = $e->getFile().$e->getLine().$e->getMessage();
+	exit;
+});
+
 
-$respond = array("status" => 0, "message" => "");
 if (isset($_COOKIE["userid"])) {
     PDO_Connect(_FILE_DB_GROUP_);
-	#先查询是否有重复的组名
-	$query = "SELECT id FROM group_info  WHERE name = ? ";
-    $Fetch = PDO_FetchRow($query, array($_POST["name"]));
-	if ($Fetch) {
-		$respond['status'] = 1;
-        $respond['message'] = "错误:有相同的组名称,请选择另一个名称。";
-		echo json_encode($respond, JSON_UNESCAPED_UNICODE);
-		exit;
-	}
-    $query = "INSERT INTO group_info ( id,  parent  , name  , description ,  status , owner ,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];
-    }
+    try{
+        $PDO->beginTransaction();
+        #先查询是否有重复的组名
+        $query = "SELECT id FROM "._TABLE_GROUP_INFO_."  WHERE name = ? ";
+        $Fetch = PDO_FetchRow($query, array($_POST["name"]));
+        if ($Fetch) {
+            $respond['status'] = 1;
+            $respond['message'] = "错误:有相同的组名称,请选择另一个名称。";
+            echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+            exit;
+        }
+        $query = "INSERT INTO "._TABLE_GROUP_INFO_." ( id, uid  , name  , description  , owner ,create_time,modify_time )
+                            VALUES  ( ?, ? , ? , ? , ? , ?  ,? ) ";
+        $sth = $PDO->prepare($query);
+        $newid = UUID::v4();
+        $sth->execute(array($snowflake->id(),$newid,  $_POST["name"], "",  $_COOKIE["user_uid"], mTime(), mTime()));
 
-	#将创建者添加到成员中
-    $query = "INSERT INTO group_member (  user_id  , group_id  , power , group_name , level ,  status )
-		VALUES  (  ? , ? , ? , ? , ?  ,? ) ";
-    $sth = $PDO->prepare($query);
-    $sth->execute(array($_COOKIE["userid"], $newid, 0, $_POST["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 = "INSERT INTO "._TABLE_GROUP_MEMBER_." (id,  user_id  , group_id  , power , group_name , level ,  status )
+            VALUES  ( ? , ? , ? , ? , ? , ?  ,? ) ";
+        $sth = $PDO->prepare($query);
+        $sth->execute(array($snowflake->id(),$_COOKIE["user_uid"], $newid, 0, $_POST["name"], 0, 1));
+        $PDO->commit();    
+    }catch (Exception $e) {
+        $PDO->rollBack();
+    	$respond['status']=1;
+        $respond['message']="Failed: " . $e->getMessage();
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
     }
+
 }
 echo json_encode($respond, JSON_UNESCAPED_UNICODE);

+ 19 - 7
public/app/palicanon/palicanon.js

@@ -22,18 +22,30 @@ function palicanon_onload() {
 }
 
 function palicanon_load_term() {
-	$.post(
-		"../term/get_term_index.php",
+    let lang =getCookie("language");
+    switch (lang) {
+        case 'zh-cn':
+            lang = 'zh-hans';
+            break;
+        case 'zh-tw':
+            lang = 'zh-hant';
+            break;    
+        case '':
+            lang = 'en';
+            break;  
+    }
+	$.get(
+		"/api/v2/terms",
 		{
-			lang: getCookie("language"),
+            view:'hot-meaning',
+			language: lang,
 		},
 		function (data) {
-			let result = JSON.parse(data);
-			if (result.status == 0) {
-				arrMyTerm = result.data;
+			if (data.ok) {
+				arrMyTerm = data.data.rows;
 				render_main_tag();
 			} else {
-				alert(result.error);
+				alert(data.message);
 			}
 		}
 	);

+ 3 - 3
public/app/pcdl/get_res_index.php

@@ -171,9 +171,9 @@ if ($album == -1) {
 
         }
         //查共享文档
-        PDO_Connect("" . _FILE_DB_FILEINDEX_);
-        $query = "select * from fileindex where book='$book' and paragraph=$paragraph  and status>0 and share>0 order by create_time";
-        $Fetch = PDO_FetchAll($query);
+        PDO_Connect(_FILE_DB_FILEINDEX_);
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where book=? and paragraph=?  and status>0 and share>0 order by create_time";
+        $Fetch = PDO_FetchAll($query,array($book,$paragraph));
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
             echo "<ul class='search_list'>";

+ 6 - 0
public/app/pcdl/head_bar.php

@@ -472,6 +472,12 @@ switch($_COOKIE['language']){
 				<span class="goto-platform"> ▸ <?php echo $_local->gui->studio; ?></span></a>
 		</div>
 	</div>
+    <?php 
+        $host = $_SERVER ['HTTP_HOST']; 
+        if(stripos('staging',$host)>0){
+            echo "<span style='backgroud-color:red;color:white;padding:0.5em;font-size:120%;' title='本服务器仅仅作为功能测试之用,所有用户数据均不保留。'>测试服务器</span>";
+        }
+    ?>
 	<input type="checkbox" id="nav-toggle" class="nav-toggle">
 	<nav>
 		<ul>

+ 1 - 1
public/app/public/_pdo.php

@@ -3,7 +3,7 @@ function PDO_Connect($dsn, $user="", $password="")
 {
     global $PDO;
     $PDO = new PDO($dsn,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
-    $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+    $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
 function PDO_FetchOne($query, $params=null)
 {

+ 2 - 2
public/app/share/coop_del.php

@@ -14,8 +14,8 @@ $respond['message']="成功";
 if(isset($_POST["res_id"])){
 	$redis = redis_connect();
 
-	PDO_Connect(_FILE_DB_USER_SHARE_);
-    $query = "DELETE FROM share_cooperator WHERE res_id=? and cooperator_id = ? ";
+	PDO_Connect(_FILE_DB_USER_SHARE_,_DB_USERNAME_, _DB_PASSWORD_);
+    $query = "DELETE FROM "._TABLE_USER_SHARE_." WHERE res_id=? and cooperator_id = ? ";
 	$sth = $PDO->prepare($query);
 	if($sth)
 	{

+ 2 - 2
public/app/share/coop_get.php

@@ -8,10 +8,10 @@ require_once '../ucenter/function.php';
 require_once '../group/function.php';
 
 if(isset($_GET["res_id"])){
-    PDO_Connect(_FILE_DB_USER_SHARE_);
+    PDO_Connect(_FILE_DB_USER_SHARE_,_DB_USERNAME_, _DB_PASSWORD_);
     $id=$_GET["res_id"];
     $type=$_GET["res_type"];
-    $query = "SELECT * FROM share_cooperator  WHERE res_id = ? and res_type=? ";
+    $query = "SELECT * FROM "._TABLE_USER_SHARE_."  WHERE res_id = ? and res_type=? ";
 	$Fetch = PDO_FetchAll($query,array($id,$type));
 
 	#获取协作者名字

+ 2 - 2
public/app/share/coop_post.php

@@ -13,8 +13,8 @@ $respond['status']=0;
 $respond['message']="成功";
 if(isset($_POST["res_id"])){
 	$redis = redis_connect();
-	PDO_Connect(_FILE_DB_USER_SHARE_);
-    $query = "UPDATE share_cooperator set power = ? WHERE res_id=? and cooperator_id = ? ";
+	PDO_Connect(_FILE_DB_USER_SHARE_,_DB_USERNAME_, _DB_PASSWORD_);
+    $query = "UPDATE "._TABLE_USER_SHARE_." set power = ? WHERE res_id=? and cooperator_id = ? ";
 	$sth = $PDO->prepare($query);
 	if($sth)
 	{

+ 86 - 61
public/app/share/coop_put.php

@@ -8,74 +8,99 @@ require_once '../ucenter/function.php';
 require_once '../group/function.php';
 require_once "../redis/function.php";
 require_once "../collect/function.php";
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 $respond['status']=0;
 $respond['message']="成功";
 if(isset($_POST["res_id"])){
 	$redis = redis_connect();
-	PDO_Connect(_FILE_DB_USER_SHARE_);
-	$PDO->beginTransaction();
-    $query = "INSERT  INTO share_cooperator ('id','res_id','res_type','cooperator_id','cooperator_type','power','create_time','modify_time','is_deleted') VALUES (null,?,?,?,?,?,?,?,?) ";
-	$sth = $PDO->prepare($query);
+    #打开目标数据库
+    $dest_db = _PG_DB_USER_SHARE_;#目标数据库
+    $dest_table = _PG_TABLE_USER_SHARE_;#目标表名
+    $PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+    $PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+    $queryInsert = "INSERT INTO ".$dest_table." 
+								(
+                                    id,
+									res_id,
+									res_type,
+									cooperator_id,
+									cooperator_type,
+									power,
+									create_time,
+									modify_time,
+									created_at,
+									updated_at) 
+									VALUES (? , ? , ? , ?, ? , ? ,? , ? , ? , ? )";
+    $stmtDEST = $PDO_DEST->prepare($queryInsert);
+
 	$data = json_decode($_POST["user_info"]);
-	foreach ($data as $key => $user) {
-		# code...
-		$sth->execute(array($_POST["res_id"],
-							$_POST["res_type"],
-							$user->id,
-							$user->type,
-							$_POST["power"],
-							mTime(),
-							mTime(),
-							0
-						));
-	}
-	$PDO->commit();
+    try {
+        $PDO_DEST->beginTransaction();
+        foreach ($data as $key => $user) {
+            # code...
+            #插入目标表
+            $create_time = mTime();
+            $created_at = date("Y-m-d H:i:s.",$create_time/1000).($create_time%1000)." UTC";
+            $updated_at = date("Y-m-d H:i:s.",$create_time/1000).($create_time%1000)." UTC";
+            $commitData = array(
+                $snowflake->id(),
+                $_POST["res_id"],
+                $_POST["res_type"],
+                $user->id,
+                $user->type,
+                $_POST["power"],
+                $create_time,
+                $create_time,
+                $created_at,
+                $updated_at
+            );
+            $stmtDEST->execute($commitData);
+        }
+        $PDO_DEST->commit();
+
+        $respond['status']=0;
+        $respond['message']="成功";
+        if($redis){
+            switch ((int)$_POST["res_type"]) {
+                case 1:
+                    # pcs
+                    $redis->del("power://pcs/".$_POST["res_id"]);
+                    break;
+                case 2:
+                    # channel
+                    $redis->del("power://channel/".$_POST["res_id"]);
+                    break;
+                case 3:
+                    # code...
+                    $redis->del("power://article/".$_POST["res_id"]);
+                    break;
+                case 4:
+                    # 文集
+                    $redis->del("power://collection/".$_POST["res_id"]);
+                    # 删除文章列表权限缓存
+                    $collection = new CollectInfo($redis);
+                    $articleList = $collection->getArticleList($_POST["res_id"]);
+                    foreach ($articleList as $key => $value) {
+                        # code...
+                        $redis->del("power://article/".$value);
+                    }
+                    break;
+                default:
+                    # code...
+                    break;
+            }
+        }
         
-	if (!$sth || ($sth && $sth->errorCode() != 0)) {
-		/*  识别错误且回滚更改  */
-		$PDO->rollBack();
-		$error = PDO_ErrorInfo();
-		$respond['status']=1;
-		$respond['message']=$error[2];
-		echo json_encode($respond, JSON_UNESCAPED_UNICODE);
-		exit;
-	}
-	else{
-		$respond['status']=0;
-		$respond['message']="成功";
-		if($redis){
-			switch ((int)$_POST["res_type"]) {
-				case 1:
-					# pcs
-					$redis->del("power://pcs/".$_POST["res_id"]);
-					break;
-				case 2:
-					# channel
-					$redis->del("power://channel/".$_POST["res_id"]);
-					break;
-				case 3:
-					# code...
-					$redis->del("power://article/".$_POST["res_id"]);
-					break;
-				case 4:
-					# 文集
-					$redis->del("power://collection/".$_POST["res_id"]);
-					# 删除文章列表权限缓存
-					$collection = new CollectInfo($redis);
-					$articleList = $collection->getArticleList($_POST["res_id"]);
-					foreach ($articleList as $key => $value) {
-						# code...
-						$redis->del("power://article/".$value);
-					}					
-					break;											
-				default:
-					# code...
-					break;
-			}
-		}
-	}	
-    echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+    }catch (Exception $e) {
+    $PDO_DEST->rollBack();
+    	$respond['status']=1;
+        $respond['message']="Failed: " . $e->getMessage();
+        echo json_encode($respond, JSON_UNESCAPED_UNICODE);
+    }
 }
 else{
 	$respond['status']=1;

+ 9 - 9
public/app/share/function.php

@@ -15,9 +15,9 @@ $res_type 见readme.md#资源类型 -1全部类型资源
 function share_res_list_get($userid,$res_type=-1){
 	$redis = redis_connect();
 	# 找我加入的群
-	$dbhGroup = new PDO(_FILE_DB_GROUP_, "", "");
+	$dbhGroup = new PDO(_FILE_DB_GROUP_, _DB_USERNAME_, _DB_PASSWORD_);
     $dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
-	$query = "SELECT group_id from group_member where user_id = ?  limit 0,200";
+	$query = "SELECT group_id from "._TABLE_GROUP_MEMBER_." where user_id = ?  limit 500";
 	$stmtGroup = $dbhGroup->prepare($query);
 	$stmtGroup->execute(array($userid));
 	$my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);
@@ -30,11 +30,11 @@ function share_res_list_get($userid,$res_type=-1){
 	
 	$place_holders = implode(',', array_fill(0, count($userList), '?'));
 	$Fetch=array();
-	$PDO = new PDO(_FILE_DB_USER_SHARE_, "", "");
+	$PDO = new PDO(_FILE_DB_USER_SHARE_, _DB_USERNAME_, _DB_PASSWORD_);
     $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 	if($res_type==-1){
 		#所有类型资源
-		$query = "SELECT res_id,res_type,power FROM share_cooperator  WHERE is_deleted=0 AND cooperator_id IN ($place_holders) ";
+		$query = "SELECT res_id,res_type,power FROM "._TABLE_USER_SHARE_."  WHERE  cooperator_id IN ($place_holders) ";
 		$stmt = $PDO->prepare($query);
 		$stmt->execute($userList);
 		$Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -42,7 +42,7 @@ function share_res_list_get($userid,$res_type=-1){
 	else{
 		#指定类型资源
 		$userList[]=$res_type;
-		$query = "SELECT res_id,res_type,power FROM share_cooperator  WHERE is_deleted=0 AND  cooperator_id IN ($place_holders) AND res_type = ?";
+		$query = "SELECT res_id,res_type,power FROM "._TABLE_USER_SHARE_."  WHERE   cooperator_id IN ($place_holders) AND res_type = ?";
 		$stmt = $PDO->prepare($query);
 		$stmt->execute($userList);
 		$Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -144,9 +144,9 @@ function share_get_res_power($userid,$res_id){
 			return 0;
 		}
 		# 找我加入的群
-		$dbhGroup = new PDO(_FILE_DB_GROUP_, "", "");
+		$dbhGroup = new PDO(_FILE_DB_GROUP_, _DB_USERNAME_, _DB_PASSWORD_);
 		$dbhGroup->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
-		$query = "SELECT group_id from group_member where user_id = ?  limit 0,100";
+		$query = "SELECT group_id from "._TABLE_GROUP_MEMBER_." where user_id = ?  limit 500";
 		$stmtGroup = $dbhGroup->prepare($query);
 		$stmtGroup->execute(array($userid));
 		$my_group = $stmtGroup->fetchAll(PDO::FETCH_ASSOC);
@@ -159,11 +159,11 @@ function share_get_res_power($userid,$res_id){
 		
 		$place_holders = implode(',', array_fill(0, count($userList), '?'));
 		$Fetch=array();
-		$PDO = new PDO(_FILE_DB_USER_SHARE_, "", "");
+		$PDO = new PDO(_FILE_DB_USER_SHARE_, _DB_USERNAME_, _DB_PASSWORD_);
 		$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 
 			$userList[]=$res_id;
-			$query = "SELECT power FROM share_cooperator  WHERE is_deleted=0 AND  cooperator_id IN ($place_holders) AND res_id = ? ";
+			$query = "SELECT power FROM "._TABLE_USER_SHARE_."  WHERE  cooperator_id IN ($place_holders) AND res_id = ? ";
 			$stmt = $PDO->prepare($query);
 			$stmt->execute($userList);
 			$Fetch =$stmt->fetchAll(PDO::FETCH_ASSOC);

+ 1 - 1
public/app/share/share.js

@@ -209,7 +209,7 @@ function username_search(keyword, type) {
 					for (const iterator of result) {
 						html +=
 							"<li onclick=\"user_selected('" +
-							iterator.id +
+							iterator.uid +
 							"','" +
 							iterator.name +
 							"',1)\">" +

+ 10 - 10
public/app/studio/file_index.php

@@ -35,14 +35,14 @@ switch ($op) {
     case "list":
         break;
     case "get";
-        $query = "select * from fileindex where user_id='$uid' AND  id='{$doc_id}'";
-        $Fetch = PDO_FetchAll($query);
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id=? AND  id=?";
+        $Fetch = PDO_FetchAll($query,[$uid,$doc_id]);
         echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
         break;
     case "getall";
         //
-        $query = "select * from fileindex where user_id='$uid' AND  id='{$_POST["doc_id"]}'";
-        $Fetch = PDO_FetchAll($query);
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id=? AND  id=?";
+        $Fetch = PDO_FetchAll($query,[$uid,$_POST["doc_id"]]);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {
             echo json_encode($Fetch[0], JSON_UNESCAPED_UNICODE);
@@ -54,8 +54,8 @@ switch ($op) {
             $value = mTime();
         }
         $doc_id = $_POST["doc_id"];
-        $query = "UPDATE fileindex SET $field='$value' where user_id='$uid' AND  id='{$doc_id}'";
-        $stmt = @PDO_Execute($query);
+        $query = "UPDATE "._TABLE_FILEINDEX_." SET $field='$value' where user_id=? AND  uid=?";
+        $stmt = @PDO_Execute($query,array($uid,$doc_id));
         if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
             $error = PDO_ErrorInfo();
             echo json_encode(array("error" => $error[2], "message" => $query), JSON_UNESCAPED_UNICODE);
@@ -80,7 +80,7 @@ switch ($op) {
                 }
                 $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                 $strFileList .= ")";
-                $query = "UPDATE fileindex SET share='$share' where user_id='$uid' AND   id in $strFileList";
+                $query = "UPDATE "._TABLE_FILEINDEX_." SET share='$share' where user_id='$uid' AND   uid in $strFileList";
                 $stmt = @PDO_Execute($query);
                 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                     $error = PDO_ErrorInfo();
@@ -105,7 +105,7 @@ switch ($op) {
                     $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                     $strFileList .= ")";
 
-                    $query = "UPDATE fileindex SET status='0',share='0' where user_id='$uid' AND  id in $strFileList";
+                    $query = "UPDATE "._TABLE_FILEINDEX_." SET status='0',share='0' where user_id='$uid' AND  uid in $strFileList";
                     $stmt = @PDO_Execute($query);
                     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                         $error = PDO_ErrorInfo();
@@ -129,7 +129,7 @@ switch ($op) {
                 $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                 $strFileList .= ")";
 
-                $query = "UPDATE fileindex SET status='1' where user_id='$uid' AND  id in $strFileList";
+                $query = "UPDATE "._TABLE_FILEINDEX_." SET status='1' where user_id='$uid' AND  uid in $strFileList";
                 $stmt = @PDO_Execute($query);
                 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                     $error = PDO_ErrorInfo();
@@ -157,7 +157,7 @@ switch ($op) {
                 $strFileList = mb_substr($strFileList, 0, mb_strlen($strFileList, "UTF-8") - 1, "UTF-8");
                 $strFileList .= ")";
                 //删除记录
-                $query = "DELETE FROM fileindex WHERE user_id='$uid' AND   id in $strFileList";
+                $query = "DELETE FROM "._TABLE_FILEINDEX_." WHERE user_id='$uid' AND   uid in $strFileList";
                 $stmt = @PDO_Execute($query);
                 if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
                     $error = PDO_ErrorInfo();

+ 2 - 2
public/app/studio/get_res_json.php

@@ -81,7 +81,7 @@ if ($paragraph > 0) {
     }
     //查共享文档
     PDO_Connect(_FILE_DB_FILEINDEX_);
-    $query = "select * from fileindex where book='$book' and paragraph=$paragraph  and status>0 and share>0 order by create_time";
+    $query = "SELECT * from "._TABLE_FILEINDEX_." where book='$book' and paragraph=$paragraph  and status>0 and share>0 order by create_time";
     $Fetch = PDO_FetchAll($query);
     $iFetch = count($Fetch);
     if ($iFetch > 0) {
@@ -95,7 +95,7 @@ if ($paragraph > 0) {
     }
     //查我的文档
     if ($UID != "") {
-        $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status!=0 and user_id='{$UID}' order by create_time DESC";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where book='$book' and paragraph=$paragraph and status!=0 and user_id='{$UID}' order by create_time DESC";
         $Fetch = PDO_FetchAll($query);
         $iFetch = count($Fetch);
         if ($iFetch > 0) {

+ 3 - 3
public/app/studio/getfilelist.php

@@ -53,13 +53,13 @@ switch ($order_by) {
 
 switch ($status) {
     case "all":
-        $query = "select * from fileindex where user_id='$uid' AND title like '%$keyword%' and status>0 order by $order_by $order";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id='$uid' AND title like '%$keyword%' and status>0 order by $order_by $order";
         break;
     case "share":
-        $query = "select * from fileindex where user_id='$uid' AND  title like '%$keyword%' and status>0 and share=1 order by $order_by $order";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id='$uid' AND  title like '%$keyword%' and status>0 and share=1 order by $order_by $order";
         break;
     case "recycle":
-        $query = "select * from fileindex where user_id='$uid' AND  title like '%$keyword%' and status=0 order by $order_by $order";
+        $query = "SELECT * from "._TABLE_FILEINDEX_." where user_id='$uid' AND  title like '%$keyword%' and status=0 order by $order_by $order";
         break;
 }
 $Fetch = PDO_FetchAll($query);

+ 9 - 9
public/app/studio/js/index_mydoc.js

@@ -59,7 +59,7 @@ function file_list_refresh() {
 
 					html += '<div class="file_list_col_1">';
 					html += "<input id='file_check_" + x + '\' type="checkbox" />';
-					html += "<input id='file_id_" + x + "' value='" + file_list[x].id + '\' type="hidden" />';
+					html += "<input id='file_id_" + x + "' value='" + file_list[x].uid + '\' type="hidden" />';
 					html += "</div>";
 
 					html += '<div class="file_list_col_2">';
@@ -68,7 +68,7 @@ function file_list_refresh() {
 						parseInt(file_list[x].share) == 1
 					) {
 						//shared
-						html += "<span onclick=\"file_show_coop_win('" + file_list[x].id + "')\">";
+						html += "<span onclick=\"file_show_coop_win('" + file_list[x].uid + "')\">";
 					} else {
 						html += "<span>";
 					}
@@ -89,16 +89,16 @@ function file_list_refresh() {
 					html += "</svg>";
 					html += "</span>";
 
-					html += "<div id='coop_show_" + file_list[x].id + "' style='display:inline;'></div>";
+					html += "<div id='coop_show_" + file_list[x].uid + "' style='display:inline;'></div>";
 
 					let $link;
 					if (file_list[x].doc_info && file_list[x].doc_info.length > 1) {
-						$link = "<a href='./editor.php?op=opendb&fileid=" + file_list[x].id + "' target='_blank'>";
+						$link = "<a href='./editor.php?op=opendb&fileid=" + file_list[x].uid + "' target='_blank'>";
 					} else {
-						$link = "<a href='./editor.php?op=open&fileid=" + file_list[x].id + "' target='_blank'>";
+						$link = "<a href='./editor.php?op=open&fileid=" + file_list[x].uid + "' target='_blank'>";
 					}
 
-					html += $link + "<span id='title_" + file_list[x].id + "'>" + file_list[x].title;
+					html += $link + "<span id='title_" + file_list[x].uid + "'>" + file_list[x].title;
 					html += "</span></a>";
 
 					//html +="<input type='input' style='diaplay:none;' id='input_title_"+file_list[x].id+"' value='"+file_list[x].title+"' />"
@@ -109,7 +109,7 @@ function file_list_refresh() {
 						"</span>";
 					html +=
 						"<button id='edit_title' type='button' class='icon_btn' onclick=\"title_change('" +
-						file_list[x].id +
+						file_list[x].uid +
 						"','" +
 						file_list[x].title +
 						"')\" >";
@@ -174,7 +174,7 @@ function file_list_refresh() {
 					if (!(file_list[x].doc_info && file_list[x].doc_info.length > 1)) {
 						html +=
 							"<a href='../doc/pcs2db.php?doc_id=" +
-							file_list[x].id +
+							file_list[x].uid +
 							"' target='_blank'>转数据库格式</a>";
 					}
 
@@ -185,7 +185,7 @@ function file_list_refresh() {
 					html += '<span class="icon_btn_tip">' + gLocal.gui.copy_share_link + "</span>";
 					html +=
 						"<button id='edit_title' type='button' class='icon_btn' onclick=\"share_link_copy_to_clipboard('" +
-						file_list[x].id +
+						file_list[x].uid +
 						"')\" >";
 					//html +='	<svg class="icon">';
 					//html +='		<use xlink:href="./svg/icon.svg#ic_rename"></use>';

+ 98 - 69
public/app/studio/project.php

@@ -27,6 +27,13 @@ require_once __DIR__."/../public/snowflakeid.php";
 # 雪花id
 $snowflake = new SnowFlakeId();
 
+set_exception_handler(function($e){
+	echo("error-msg:".$e->getMessage().PHP_EOL);
+	echo("error-file:".$e->getFile().PHP_EOL);
+	echo("error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+
 $user_setting = get_setting();
 
 $sLang["1"] = "pali";
@@ -53,9 +60,11 @@ if ($_COOKIE["uid"]) {
     echo '<a href="../ucenter/index.php" target="_blank">' . $_local->gui->not_login . '</a>';
     exit;
 }
+if(isset($_POST["channal"])){
+    $channelClass = new Channal(redis_connect());
+    $channelInfo = $channelClass->getChannal($_POST["channal"]); 
+}
 
-$channelClass = new Channal(redis_connect());
-$channelInfo = $channelClass->getChannal($_POST['channal']);
 
 switch ($op) {
     case "create":
@@ -159,9 +168,10 @@ switch ($op) {
                                     }
                                     $block_id = UUID::v4();
                                     $trans_block_id = UUID::v4();
+                                    $snowId = $snowflake->id();
                                     $block_data[] = array
 									(
-										$snowflake->id(),
+										$snowId,
 										$block_id, 
 										"", 
 										$_POST["channal"], 
@@ -222,7 +232,7 @@ switch ($op) {
 											$strXml, 
 											mTime(), 
 											mTime(), 
-											$channelInfo["status"], 
+											0, 
 											$_COOKIE['userid'],
 											$_COOKIE['uid']
 										);
@@ -302,59 +312,75 @@ switch ($op) {
                             }
 
                             //服务器端文件列表
-                            PDO_Connect(_FILE_DB_FILEINDEX_);
-                            $query = "INSERT INTO fileindex ('id',
-												'parent_id',
-												'channal',
-												'user_id',
-												'book',
-												'paragraph',
-												'file_name',
-												'title',
-												'tag',
-												'status',
-												'create_time',
-												'modify_time',
-												'accese_time',
-												'file_size',
-												'share',
-												'doc_info',
-												'doc_block',
-												'receive_time'
-												)
-									VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-                            $stmt = $PDO->prepare($query);
+                            $PDO_File = new PDO(_FILE_DB_FILEINDEX_,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+                            $PDO_File->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+                            $queryInsert = "INSERT INTO \""._TABLE_FILEINDEX_."\"  
+ (
+                                    id,
+									uid,
+									parent_id,
+									user_id,
+									book,
+									paragraph,
+									channal,
+									file_name,
+									title,
+									tag,
+									status,
+									file_size,
+									share,
+									doc_info,
+									doc_block,
+									create_time,
+									modify_time,
+									accese_time,
+									accesed_at,
+									updated_at,
+									created_at) 
+									VALUES (? , ? , ? , ? , ?, ? ,? , ? , ? , ?, ? ,? , ? , ? , ?, ? ,? , ? , ? , ?, ? )";
+                            $stmtDEST = $PDO_File->prepare($queryInsert);
                             $doc_id = UUID::v4();
-                            $file_name = $book . '_' . $create_para . '_' . time();
-                            $newData = array(
-                                $doc_id,
-                                "",
-                                $_POST["channal"],
-                                $uid,
-                                $book,
-                                $create_para,
-                                $file_name,
-                                $user_title,
-                                $tag,
-                                1,
-                                mTime(),
-                                mTime(),
-                                mTime(),
-                                0,
-                                0,
-                                $doc_head,
-                                json_encode($block_list, JSON_UNESCAPED_UNICODE),
-                                mTime(),
-                            );
-                            $stmt->execute($newData);
-                            if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
-                                $error = PDO_ErrorInfo();
-                                echo "error - $error[2] <br>";
-                            } else {
+                            $file_name = $book . '_' . $create_para;
+
+                            $created_at = date("Y-m-d H:i:s.",mTime()/1000).(mTime()%1000)." UTC";
+
+                            $commitData = array(
+                                    $snowflake->id(),
+                                    $doc_id,
+                                    null,
+                                    $uid,
+                                    $book,
+                                    $create_para,
+                                    $_POST["channal"],
+                                    $file_name,
+                                    $user_title,
+                                    $tag,
+                                    1,
+                                    0,
+                                    0,
+                                    $doc_head,
+                                    json_encode($block_list, JSON_UNESCAPED_UNICODE),
+                                    mTime(),
+                                    mTime(),
+                                    mTime(),
+                                    $created_at,
+                                    $created_at,
+                                    $created_at
+                                );
+                            try{
+                                $stmtDEST->execute($commitData); 
                                 echo "成功新建一个文件.";
+                                echo "<a href=\"editor.php?op=opendb&doc_id={$doc_id}\">{$_local->gui->open}</a>";
+                            }catch(PDOException $e){
+                                echo($e->getMessage().PHP_EOL);
+                                echo "<pre>";
+                                print_r($commitData);
+                                echo "</pre>";                                
+                                exit;
                             }
+                            
 
-                            echo "<a href=\"editor.php?op=opendb&doc_id={$doc_id}\">{$_local->gui->open}</a>";
                         }
                         break;
                 }
@@ -837,7 +863,9 @@ switch ($op) {
             //服务器端文件列表
             PDO_Connect(_FILE_DB_FILEINDEX_);
 
-            $query = "INSERT INTO fileindex ('id',
+            $query = "INSERT INTO "._TABLE_FILEINDEX_." (
+                                            'id',
+                                            'uid',
 												'parent_id',
 												'user_id',
 												'book',
@@ -852,13 +880,14 @@ switch ($op) {
 												'file_size',
 												'share',
 												'doc_info',
-												'doc_block',
-												'receive_time'
+												'doc_block'
 												)
 									VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
             $stmt = $PDO->prepare($query);
             $doc_id = UUID::v4();
-            $newData = array($doc_id,
+            $newData = array(
+                $snowflake->id(),
+                $doc_id,
                 "",
                 $uid,
                 $book,
@@ -874,7 +903,6 @@ switch ($op) {
                 0,
                 "",
                 "",
-                mTime(),
             );
             $stmt->execute($newData);
             if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
@@ -906,8 +934,8 @@ switch ($op) {
             PDO_Connect(_FILE_DB_FILEINDEX_);
             if (isset($_GET["doc_id"])) {
                 $doc_id = $_GET["doc_id"];
-                $query = "select * from fileindex where id='$doc_id' ";
-                $Fetch = PDO_FetchAll($query);
+                $query = "SELECT * from "._TABLE_FILEINDEX_." where uid=? ";
+                $Fetch = PDO_FetchAll($query,array($doc_id));
                 $iFetch = count($Fetch);
                 if ($iFetch > 0) {
                     //文档信息
@@ -930,16 +958,16 @@ switch ($op) {
                     } else {
                         //别人的文档
                         //查询自己是否以前打开过
-                        $query = "select * from fileindex where parent_id='$doc_id' and user_id='$uid' ";
-                        $FetchSelf = PDO_FetchAll($query);
+                        $query = "SELECT * from "._TABLE_FILEINDEX_." where parent_id=? and user_id=? ";
+                        $FetchSelf = PDO_FetchAll($query,array($doc_id,$uid));
                         $iFetchSelf = count($FetchSelf);
                         if ($iFetchSelf > 0) {
                             //以前打开过
                             echo "已经复制的文档 Already Copy";
-                            $my_doc_id = $FetchSelf[0]["id"];
-                            echo "<a href='../studio/editor.php?op=opendb&fileid={$doc_id}'>{$_local->gui->edit_now}</a>";
+                            $my_doc_id = $FetchSelf[0]["uid"];
+                            echo "<a href='../studio/editor.php?op=opendb&fileid={$my_doc_id}'>{$_local->gui->edit_now}</a>";
                             echo "<script>";
-                            echo "window.location.assign(\"editor.php?op=opendb&fileid={$doc_id}\");";
+                            echo "window.location.assign(\"editor.php?op=opendb&fileid={$my_doc_id}\");";
                             echo "</script>";
                         } else {
                             //以前没打开过
@@ -1002,7 +1030,9 @@ exit;
                                     //$stmt = $PDO->prepare($query);
                                     //$newData=array($uid,$doc_id,UUID::v4(),$mbook,$paragraph,$filename,$title,$tag,time(),time(),time(),$filesize);
 
-                                    $query = "INSERT INTO fileindex ('id',
+                                    $query = "INSERT INTO "._TABLE_FILEINDEX_." (
+                                                'id',
+                                                'uid',
 												'parent_id',
 												'user_id',
 												'book',
@@ -1017,13 +1047,13 @@ exit;
 												'file_size',
 												'share',
 												'doc_info',
-												'doc_block',
-												'receive_time'
+												'doc_block'
 												)
 									VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                                     $stmt = $PDO->prepare($query);
                                     $newdoc_id = UUID::v4();
                                     $newData = array(
+                                        $snowflake->id(),
                                         $newdoc_id,
                                         $doc_id,
                                         $uid,
@@ -1040,7 +1070,6 @@ exit;
                                         0,
                                         "",
                                         "",
-                                        mTime(),
                                     );
 
                                     $stmt->execute($newData);

+ 2 - 2
public/app/studio/project_load.php

@@ -4,8 +4,8 @@ require_once "../config.php";
 require_once "../public/_pdo.php";
 
 PDO_Connect(_FILE_DB_FILEINDEX_);
-$query = "select file_name from fileindex where user_id='{$_COOKIE["uid"]}' AND  id='{$_GET["id"]}'";
-$Fetch = PDO_FetchOne($query);
+$query = "SELECT file_name from "._TABLE_FILEINDEX_." where user_id=? AND  uid=?";
+$Fetch = PDO_FetchOne($query,array($_COOKIE["uid"],$_GET["id"]));
 $FileName = _DIR_USER_DOC_ . "/" . $userid . _DIR_MYDOCUMENT_ . "/" . $Fetch;
 if (file_exists($FileName)) {
     echo file_get_contents($FileName);

+ 2 - 2
public/app/studio/project_load_db.php

@@ -9,8 +9,8 @@ require_once "../public/function.php";
 $id = $_GET["id"];
 
 PDO_Connect( _FILE_DB_FILEINDEX_);
-$query = "select * from fileindex where id=" . $PDO->quote($id);
-$Fetch = PDO_FetchAll($query);
+$query = "SELECT * from "._TABLE_FILEINDEX_." where uid=?";
+$Fetch = PDO_FetchAll($query,array($id));
 if (count($Fetch) > 0) {
     echo "<set>\n";
     echo $Fetch[0]["doc_info"];

+ 20 - 18
public/app/term/channal_list.php

@@ -166,24 +166,26 @@ foreach ($channal as $key => $value) {
         $arr_sent_final[] = $sent_final;
     }
     $channalInfo = $_channal->getChannal($key);
-	
-    $name = $_userinfo->getName($channalInfo["owner_uid"]);
-    $channalInfo["username"] = $name["username"];
-    $channalInfo["nickname"] = $name["nickname"];
-    $channalInfo["count"] = $value;
-    $channalInfo["all"] = count($_data);
-    $channalInfo["final"] = $arr_sent_final;
-	$channalInfo["article_len"] = $article_len;
-	$channalInfo["id"] = $key;
-	$channalInfo["owner"] = $channalInfo["owner_uid"];
-
-	if(isset($channel_power[$key])){
-		$channalInfo["power"] =$channel_power[$key];
-	}
-	else{
-		$channalInfo["power"] =10;
-	}
-    $output[] = $channalInfo;
+	if($channalInfo){
+        $name = $_userinfo->getName($channalInfo["owner_uid"]);
+        $channalInfo["username"] = $name["username"];
+        $channalInfo["nickname"] = $name["nickname"];
+        $channalInfo["count"] = $value;
+        $channalInfo["all"] = count($_data);
+        $channalInfo["final"] = $arr_sent_final;
+        $channalInfo["article_len"] = $article_len;
+        $channalInfo["id"] = $key;
+        $channalInfo["owner"] = $channalInfo["owner_uid"];
+
+        if(isset($channel_power[$key])){
+            $channalInfo["power"] =$channel_power[$key];
+        }
+        else{
+            $channalInfo["power"] =10;
+        }
+        $output[] = $channalInfo;        
+    }
+
 }
 
 $time = microtime(true);

+ 3 - 3
public/app/term/get_term_index.php

@@ -23,15 +23,15 @@ if (isset($_POST["lang"])) {
 
 if (isset($_POST["word"])) {
     $word = $_POST["word"];
-    $query = "select word,meaning,language,owner,count(*) as co from term where word=? and language=? group by word,meaning order by co DESC";
+    $query = "SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where word=? and language=? group by word,meaning order by co DESC";
     $output["data"] = PDO_FetchAll($query, array($word, $lang));
 } else {
-    $query = "select * from (select word,meaning,language,owner,count(*) as co from term where language=? group by word,meaning order by co DESC) where 1 group by word";
+    $query = "SELECT * from (SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where language=? group by word,meaning order by co DESC)  group by word";
     $output["data"] = PDO_FetchAll($query, array($lang));
     $pos = mb_strpos($lang, "-", 0, "UTF-8");
     if ($pos) {
         $lang_family = mb_substr($lang, 0, $pos, "UTF-8");
-        $query = "select * from (select word,meaning,language,owner,count(*) as co from term where language like ? group by word,meaning order by co DESC) where 1 group by word";
+        $query = "SELECT * from (SELECT word,meaning,language,owner,count(*) as co from "._TABLE_TERM_." where language like ? group by word,meaning order by co DESC)  group by word";
         $otherlang = PDO_FetchAll($query, array($lang_family . "%"));
         foreach ($otherlang as $key => $value) {
             $output["data"][] = $value;

+ 80 - 0
public/app/term/my_dict_list-beta.php

@@ -0,0 +1,80 @@
+<?php
+require_once '../studio/index_head.php';
+?>
+<body id="file_list_body"  onLoad="my_term_onload()">
+	<script src="../channal/channal.js"></script>
+
+    <script src="../term/my_term.js"></script>
+    <script src="../term/term_edit_dlg.js"></script>
+	<link type="text/css" rel="stylesheet" href="../term/term_edit_dlg.css"/>
+	<script >
+	var gCurrPage="term";
+	</script>
+
+	<style>
+	#term {
+		background-color: var(--btn-border-color);
+
+	}
+	#term:hover{
+		background-color: var(--btn-border-color);
+		color: var(--btn-color);
+		cursor:auto;
+    }
+    #word_list{
+        width:unset;
+    }
+	#setting_user_dict_nav{
+		width:95%;
+		display:inline-flex;
+		justify-content: space-between;
+}
+	}
+	</style>
+
+<?php
+require_once '../studio/index_tool_bar.php';
+?>
+
+	<div class="index_inner" style="    margin-left: 18em;margin-top: 5em;">
+		<div id="word_list"  class="file_list_block">
+
+		<div class="tool_bar">
+	<div>
+	<?php echo $_local->gui->userdict; ?>
+	</div>
+
+	<div>
+		<span class="icon_btn_div">
+			<span class="icon_btn_tip"><?php echo $_local->gui->add; ?></span>
+			<button id="file_add" type="button" class="icon_btn" title=" ">
+				<a href="../course/my_channal_new.php">
+				<svg class="icon">
+					<use xlink:href="../studio/svg/icon.svg#ic_add_circle"></use>
+				</svg>
+				</a>
+			</button>
+		</span>
+
+		<span class="icon_btn_div">
+			<span class="icon_btn_tip"><?php echo $_local->gui->recycle_bin; ?></span>
+			<button id="to_recycle" type="button" class="icon_btn" title="delete">
+				<svg class="icon">
+					<use xlink:href="../studio/svg/icon.svg#ic_delete"></use>
+				</svg>
+			</button>
+		</span>
+	</div>
+
+</div>
+<script src="../../node_modules/gridjs/dist/gridjs.umd.js"></script>
+<link
+      href="../../node_modules/gridjs/dist/theme/mermaid.min.css"
+      rel="stylesheet"
+    />
+
+<div id="userfilelist"></div>
+<script  type="module" src="my_dict_list.js"></script>
+<?php
+require_once '../studio/index_foot.php';
+?>

+ 129 - 0
public/app/term/my_dict_list.js

@@ -0,0 +1,129 @@
+import { Grid, h } from "../../node_modules/gridjs/dist/gridjs.module.js";
+export var _rowSelected =   new Array();
+const grid = new gridjs.Grid({
+	sort: {
+		multiColumn: false,
+		server: {
+		  url: (prev, columns) => {
+		   if (!columns.length) return prev;
+		   
+		   const col = columns[0];
+		   const dir = col.direction === 1 ? 'asc' : 'desc';
+		   let colName = ['Sel','id','guid', 'word','word_en','meaning','other_meaning','updated_at'][col.index];
+		   
+		   return `${prev}&order=${colName}&dir=${dir}`;
+		 }
+		}
+	  },
+	columns: [
+		{ 
+			name: 'Sel',
+			hidden: false,
+			sort: false,
+			formatter: (cell, row) => {
+			return h('input', {
+				type:'checkbox',
+				className: 'py-2 mb-4 px-4 border',
+				id:"cb-"+row.cells[1].data,
+				onClick: () =>{
+					let id = row.cells[1].data;
+					if(document.querySelector("#cb-"+id).checked){
+						_rowSelected.push(id);
+						console.log("checked",_rowSelected);
+					}else{
+						_rowSelected.splice(_rowSelected.findIndex(item => item ===id),1);
+						console.log("remove",_rowSelected);
+					}
+				} 
+			}, '');
+			}
+      	},
+        {
+			name: 'id',
+			hidden: true
+		},
+		{
+			name: 'guid',
+			hidden: true
+		},
+		'word',
+		{
+			name:'word_en',
+			sort: false,
+            hidden: true
+		},
+		{
+			name:'meaning',
+			sort: false,
+		},
+		{
+			name:'other_meaning',
+			sort: false,
+		},
+        'updated_at',
+		{ 
+			name: 'Actions',
+			sort: false,
+			hidden:false,
+			formatter: (cell, row) => {
+			return h('button', {
+				className: 'py-2 mb-4 px-4 border rounded-md text-white bg-blue-600',
+				onClick: () =>{
+                    let id = row.cells[2].data;
+					term_edit_dlg_open(id);
+				} 
+			}, 'Edit');
+			}
+      	}
+	],
+	server: {
+		url: '/api/v2/terms?view=user',
+		then: data => data.data.rows.map(card => [null,card.id,card.guid,card.word, card.word_en, card.meaning, card.other_meaning, card.updated_at,null]),
+		total: data => data.data.count
+	  },
+	pagination: {
+		enabled: true,
+		limit:30,
+		server: {
+			url: (prev, page, limit) => `${prev}&limit=${limit}&offset=${page * limit}`
+		  }
+	},
+	search: {
+		server: {
+		  url: (prev, keyword) => `${prev}&search=${keyword}`
+		}
+	  },
+	resizable: true,
+  }).render(document.getElementById("userfilelist"));
+
+//grid.on('rowClick', (...args) => console.log('row: ' + JSON.stringify(args), args));
+//grid.on('cellClick', (...args) => console.log(cell,args));
+
+document.querySelector("#to_recycle").onclick = function(){
+	if(_rowSelected.length>0){
+		if(confirm(`删除${_rowSelected.length}个单词,此操作不能恢复。`)){
+        $.ajax(
+        {
+            url: "/api/v2/terms/0",
+            type: 'DELETE',
+            data: {
+                id:JSON.stringify(_rowSelected),
+                "_token": 'token',
+            },
+            success: function (response){
+                if(response.ok){
+                    grid.forceRender();
+                    alert('delete ' + response.data + 'word ok');
+                }else{
+                    alert(`delete error `+response.message);
+                }
+            },
+            error: function (error) {
+                console.log(error);
+            }
+        });
+
+		}
+
+	}
+}

+ 21 - 100
public/app/term/my_dict_list.php

@@ -1,7 +1,7 @@
 <?php
 require_once '../studio/index_head.php';
 ?>
-<body id="file_list_body" onLoad="my_term_onload()">
+<body id="file_list_body"  onLoad="my_term_onload()">
 	<script src="../channal/channal.js"></script>
 
     <script src="../term/my_term.js"></script>
@@ -24,9 +24,15 @@ require_once '../studio/index_head.php';
     #word_list{
         width:unset;
     }
+	#setting_user_dict_nav{
+		width:95%;
+		display:inline-flex;
+		justify-content: space-between;
+}
+	}
 	</style>
 
-	<?php
+<?php
 require_once '../studio/index_tool_bar.php';
 ?>
 
@@ -35,22 +41,24 @@ require_once '../studio/index_tool_bar.php';
 
 		<div class="tool_bar">
 	<div>
-        <?php echo $_local->gui->terms_system; ?>
+	<?php echo $_local->gui->userdict; ?>
 	</div>
 
 	<div>
 		<span class="icon_btn_div">
 			<span class="icon_btn_tip"><?php echo $_local->gui->add; ?></span>
-			<button id="file_add" type="button" class="icon_btn" title=" " onclick="term_edit_dlg_open()">
+			<button id="file_add" type="button" class="icon_btn" title=" ">
+				<a href="../course/my_channal_new.php">
 				<svg class="icon">
 					<use xlink:href="../studio/svg/icon.svg#ic_add_circle"></use>
 				</svg>
+				</a>
 			</button>
 		</span>
 
 		<span class="icon_btn_div">
 			<span class="icon_btn_tip"><?php echo $_local->gui->recycle_bin; ?></span>
-			<button id="to_recycle" type="button" class="icon_btn" onclick="file_del()" title=" ">
+			<button id="to_recycle" type="button" class="icon_btn" title="delete">
 				<svg class="icon">
 					<use xlink:href="../studio/svg/icon.svg#ic_delete"></use>
 				</svg>
@@ -59,101 +67,14 @@ require_once '../studio/index_tool_bar.php';
 	</div>
 
 </div>
-
-<div id="userfilelist">
-<?php
-//
-
-require_once "../config.php";
-require_once "../public/_pdo.php";
-require_once '../public/load_lang.php';
-require_once '../ucenter/function.php';
-
-if (isset($_GET["page"])) {
-    $iCurrPage = $_GET["page"];
-} else {
-    $iCurrPage = 0;
-}
-$iOnePage = 300;
-
-PDO_Connect(_FILE_DB_TERM_);
-
-$query = "select count(*) as co  from term where owner= ? ";
-
-$allWord = PDO_FetchOne($query, array($_COOKIE["userid"]));
-$iCountWords = $allWord;
-
-if ($iCountWords == 0) {
-    echo "<div id='setting_user_dict_count'>您的术语字典中没有单词。</div>";
-} else {
-    echo "<div id='setting_user_dict_count'>" . $_local->gui->my_term . "&nbsp;" . $_local->gui->include . "{$iCountWords}" . $_local->gui->words . "</div>";
-    $iPages = ceil($iCountWords / $iOnePage);
-    if ($iCurrPage > $iPages) {
-        $iCurrPage = $iPages;
-    }
-    $begin = $iCurrPage * $iOnePage;
-
-    $query = "select *  from term where owner= ? ";
-    $allWords = PDO_FetchAll($query, array($_COOKIE["userid"]));
-
-    echo '<div id="setting_user_dict_nav">';
-
-    if ($iCurrPage == 0) {
-        echo "第一页 | ";
-        echo "上一页";
-    } else {
-        echo "<a href=\"setting.php?item=term&page=0\">第一页</a>";
-        $prevPage = $iCurrPage - 1;
-        echo "<a href=\"setting.php?item=term&page={$prevPage}\">上一页</a>";
-    }
-
-    echo "第<span style='display:inline-block;width:4em;'><input type=\"input\" value=\"" . ($iCurrPage + 1) . "\" size=\"4\" /></span>页";
-    echo "共{$iPages}页";
-
-    if ($iCurrPage < $iPages - 1) {
-        echo "<a href=\"setting.php?item=term&page=" . ($iCurrPage + 1) . "\">下一页</a>";
-        echo "<a href=\"setting.php?item=term&page=" . ($iPages - 1) . "\">最后一页</a>";
-
-    } else {
-        echo "下一页 | 最后一页";
-    }
-    ?>
-    </div>
-    <div>
-        <div style="display:flex;">
-            <div style='max-width:2em;flex:1;'></div>
-            <div style='flex:1;'>Sn</div>
-            <div style='flex:2;'>Spell</div>
-            <div style='flex:2;'>Meaning</div>
-            <div style='flex:2;'>Meaning2</div>
-            <div style='flex:4;'>Note</div>
-            <div style='flex:1;'>Language</div>
-            <div style='flex:1;'>Channal</div>
-            <div style='flex:1;'></div>
-        </div>
-    <?php
-
-    foreach ($allWords as $key => $word) {
-        echo '<div class="file_list_row" style="padding:5px;">';
-        echo '<div style="max-width:2em;flex:1;"><input type="checkbox" /></div>';
-        echo "<div style='flex:1;'>" . ($key + 1) . "</div>";
-        echo "<div style='flex:2;'>{$word["word"]}</div>";
-        echo "<div style='flex:2;'>{$word["meaning"]}</div>";
-        echo "<div style='flex:2;'>{$word["other_meaning"]}</div>";
-        echo "<div style='flex:4;'><textarea style='width:100%;'>{$word["note"]}</textarea></div>";
-        echo "<div style='flex:1;'>{$word["language"]}</div>";
-        echo "<div style='flex:1;'>{$word["channal"]}</div>";
-        echo "<div style='flex:1;'><button onclick=\"term_edit_dlg_open('{$word["guid"]}')\">edit</button></div>";
-        echo "</div>";
-    }
-
-    echo '</div>';
-}
-?>
-
-    </div>
-
-
+<script src="../../node_modules/gridjs/dist/gridjs.umd.js"></script>
+<link
+      href="../../node_modules/gridjs/dist/theme/mermaid.min.css"
+      rel="stylesheet"
+    />
+
+<div id="userfilelist"></div>
+<script  type="module" src="my_dict_list.js"></script>
 <?php
 require_once '../studio/index_foot.php';
 ?>

+ 1 - 1
public/app/term/new.php

@@ -9,7 +9,7 @@ require_once '../ucenter/function.php';
 PDO_Connect(_FILE_DB_TERM_);
 $userInfo = new UserInfo();
 
-$query = "select word,meaning , owner from term where 1  order by create_time DESC limit 0,4";
+$query = "SELECT word,meaning , owner from "._TABLE_TERM_."  order by create_time DESC limit 4";
 $Fetch = PDO_FetchAll($query);
 
 foreach ($Fetch as $row) {

+ 22 - 7
public/app/term/note.js

@@ -6,6 +6,7 @@ var _channal = "";
 var _lang = "";
 var _author = "";
 
+
 var _arrData = new Array();
 var _channalData;
 
@@ -115,12 +116,17 @@ function note_update_background_style() {
 }
 //
 function note_refresh_new(callback = null) {
+    let Params={
+        maxSentenceOneRequest:0
+    };
 	note_update_background_style();
 	let objNotes = document.querySelectorAll("note");
 	let arrSentInfo = new Array();
+    let noteCounter = 0;
 	for (const iterator of objNotes) {
 		let id = iterator.id;
 		if (id == null || id == "") {
+            
 			//查看这个节点是第几层note嵌套。大于预定层数退出。
 			let layout = 1;
 			let parent = iterator.parentNode;
@@ -135,6 +141,7 @@ function note_refresh_new(callback = null) {
 				}
 				parent = parent.parentNode;
 			}
+            
 			id = com_guid();
 			iterator.id = id;
 			if (iterator.hasAttribute("info")) {
@@ -151,6 +158,10 @@ function note_refresh_new(callback = null) {
 					arrSentInfo.push({ id: id, data: info });
 				}
 			}
+            noteCounter++;
+            if(Params.maxSentenceOneRequest>0 && noteCounter>=Params.maxSentenceOneRequest){
+                break;
+            }
 		}
 	}
 	if (arrSentInfo.length > 0) {
@@ -167,6 +178,7 @@ function note_refresh_new(callback = null) {
 				if (status == "success") {
 					try {
 						let sentData = JSON.parse(data);
+                        //开始渲染句子
 						for (const iterator of sentData) {
 							let id = iterator.id;
 							let strHtml = "<a name='" + id + "'></a>";
@@ -180,6 +192,7 @@ function note_refresh_new(callback = null) {
 								$("#" + id).html(strHtml);
 							}
 						}
+                        //句子渲染完毕
 						//处理<code>标签作为气泡注释
 						popup_init();
 
@@ -190,7 +203,7 @@ function note_refresh_new(callback = null) {
 						_arrData = _arrData.concat(sentData);
 						note_ref_init();
 						//获取术语字典
-						term_get_dict();
+						term_get_dict(callback);
 						//刷新channel列表
 						note_channal_list();
 						//显示不同的巴利语脚本
@@ -199,9 +212,7 @@ function note_refresh_new(callback = null) {
 						splite_pali_word();
 						//处理编辑框消息
 						tran_sent_textarea_event_init();
-						if (callback) {
-							callback();
-						}
+
 						//初始化mermaid
 						mermaid.initialize({startOnLoad:true});
 
@@ -209,11 +220,14 @@ function note_refresh_new(callback = null) {
 						console.error(e);
 					}
 				}
+                
 			}
 		);
 	} else {
-		term_get_dict();
+		term_get_dict(callback);
 	}
+
+    return arrSentInfo.length;
 }
 
 //渲染巴利原文句子
@@ -297,7 +311,7 @@ function render_read_mode_sent(iterator) {
 		let html = "<span class='tran_sent' lang='" + oneTran.lang + "' channal='" + oneTran.channal + "'>";
 
 		//将绝对链接转换为 用户连接的主机链接
-		oneTran.text = oneTran.text.replace(/[A-z]*.wikipali.org/g,location.host);
+		//oneTran.text = oneTran.text.replace(/www-[A-z]*.wikipali.org/g,location.host);
 
 		html += marked(term_std_str_to_tran(oneTran.text, oneTran.channal, oneTran.editor, oneTran.lang));
 		html += "</span>";
@@ -906,7 +920,8 @@ function render_one_sent_tran_a(iterator, diff = false) {
 	let sid = iterator.book + "-" + iterator.para + "-" + iterator.begin + "-" + iterator.end;
 
 	//将绝对链接转换为 用户连接的主机链接
-	let showText = iterator.text.replace(/[A-z]*.wikipali.org/g,location.host);
+	//let showText = iterator.text.replace(/www-[A-z]*.wikipali.org/g,location.host);
+	let showText = iterator.text;
 
 	if (iterator.text == "") {
 		if (typeof iterator.channalinfo == "undefined") {

+ 12 - 2
public/app/term/term.css

@@ -337,8 +337,18 @@ note n {
 	padding: 5px 0;
 }
 .term_block {
-	border-bottom: 1px solid #cecece;
-	padding: 5px 0;
+
+}
+.term_block h2{
+    margin: 0;
+}
+.term_popup_foot{
+    display: flex;
+    justify-content: space-between;
+}
+.guide_contence .term_note{
+    border-bottom: 1px solid var(--border-line-color);
+    min-height: 9em;
 }
 .term_word_head_authors a {
 	color: blue;

+ 12 - 5
public/app/term/term.js

@@ -405,8 +405,12 @@ function term_array_updata() {
 		);
 	}
 }
-
-function term_updata_translation() {
+/*
+*-----------------------
+*更新术语显示
+*-----------------------
+*/
+function term_updata_translation(callback=null) {
 	termCounter = new Array();
 	noteCounter = 1;
 	//计算有效模版数量
@@ -551,6 +555,9 @@ function term_updata_translation() {
 		}
 	});
 	term_popup_init();
+    if(callback){
+        callback();
+    }
 }
 
 function term_show_win(guid, keyWord = "",channel="",lang="") {
@@ -674,9 +681,9 @@ function term_show_new() {
 	guide_init();
 }
 
-function term_get_dict() {
+function term_get_dict(callback=null) {
 	if (arrMyTerm.length > 0) {
-		term_updata_translation();
+		term_updata_translation(callback);
 		return;
 	}
 	let termwordlist = new Array();
@@ -707,7 +714,7 @@ function term_get_dict() {
 			if (data.length > 0) {
 				try {
 					arrMyTerm = JSON.parse(data);
-					term_updata_translation();
+					term_updata_translation(callback);
 				} catch (e) {
 					console.error(e.error + " data:" + data);
 				}

+ 40 - 18
public/app/term/term.php

@@ -5,6 +5,8 @@ require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../public/load_lang.php';
 require_once '../public/function.php';
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 //is login
 if (isset($_COOKIE["username"])) {
@@ -41,7 +43,7 @@ if (isset($_GET["username"])) {
 }
 
 global $PDO;
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect( _FILE_DB_TERM_);
 switch ($op) {
     case "pre": //预查询
         {
@@ -49,10 +51,10 @@ switch ($op) {
 				echo json_encode(array(), JSON_UNESCAPED_UNICODE);
             	break;
 			}
-            $query = "SELECT word,meaning from term where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
+            $query = "SELECT word,meaning from "._TABLE_TERM_." where \"word_en\" like " . $PDO->quote($word . '%') . " OR \"word\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
             $Fetch = PDO_FetchAll($query);
             if (count($Fetch) < 3) {
-                $query = "SELECT word,meaning from term where \"word_en\" like " . $PDO->quote('%' . $word . '%') . " OR \"word\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
+                $query = "SELECT word,meaning from "._TABLE_TERM_." where \"word_en\" like " . $PDO->quote('%' . $word . '%') . " OR \"word\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
                 $Fetch2 = PDO_FetchAll($query);
                 //去掉重复的
                 foreach ($Fetch2 as $onerow) {
@@ -68,12 +70,12 @@ switch ($op) {
                     }
                 }
                 if (count($Fetch) < 8) {
-                    $query = "SELECT word,meaning from term where \"meaning\" like " . $PDO->quote($word . '%') . " OR \"other_meaning\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
+                    $query = "SELECT word,meaning from "._TABLE_TERM_." where \"meaning\" like " . $PDO->quote($word . '%') . " OR \"other_meaning\" like " . $PDO->quote($word . '%') . " group by word limit 0,10";
                     $Fetch3 = PDO_FetchAll($query);
 
                     $Fetch = array_merge($Fetch, $Fetch3);
                     if (count($Fetch) < 8) {
-                        $query = "SELECT word,meaning from term where \"meaning\" like " . $PDO->quote('%' . $word . '%') . " OR \"other_meaning\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
+                        $query = "SELECT word,meaning from "._TABLE_TERM_." where \"meaning\" like " . $PDO->quote('%' . $word . '%') . " OR \"other_meaning\" like " . $PDO->quote('%' . $word . '%') . " group by word limit 0,10";
                         $Fetch4 = PDO_FetchAll($query);
                         //去掉重复的
                         foreach ($Fetch4 as $onerow) {
@@ -96,7 +98,7 @@ switch ($op) {
         }
     case "my":
         {
-            $query = "select guid,word,meaning,other_meaning,language from term  where owner= ? ";
+            $query = "select guid,word,meaning,other_meaning,language from "._TABLE_TERM_."  where owner= ? ";
             $Fetch = PDO_FetchAll($query, array($_COOKIE["userid"]));
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -108,7 +110,7 @@ switch ($op) {
         }
     case "allpali":
         {
-            $query = "select word from term  where 1 group by word";
+            $query = "select word from "._TABLE_TERM_." group by word";
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -118,7 +120,7 @@ switch ($op) {
         }
     case "allmean":
         {
-            $query = "select meaning from term  where \"word\" = " . $PDO->quote($word) . " group by meaning";
+            $query = "select meaning from "._TABLE_TERM_."  where \"word\" = " . $PDO->quote($word) . " group by meaning";
             $Fetch = PDO_FetchAll($query);
             foreach ($Fetch as $one) {
                 echo "<a>" . $one["meaning"] . "</a> ";
@@ -130,7 +132,7 @@ switch ($op) {
         {
             if (isset($_GET["id"])) {
                 $id = $_GET["id"];
-                $query = "select * from term  where \"guid\" = " . $PDO->quote($id);
+                $query = "select * from "._TABLE_TERM_."  where \"guid\" = " . $PDO->quote($id);
                 $Fetch = PDO_FetchAll($query);
                 echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
             } else {
@@ -149,7 +151,7 @@ switch ($op) {
             echo "<div class='pali'>{$word}</div>";
             //查本人数据
             echo "<div></div>"; //My Term
-            $query = "select * from term  where word = ? AND  owner = ? limit 0,30";
+            $query = "select * from "._TABLE_TERM_."  where word = ? AND  owner = ? limit 30";
             $Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
@@ -235,7 +237,7 @@ switch ($op) {
             echo "</div>";
 
             //查他人数据
-            $query = "SELECT * FROM term  WHERE word = ? AND owner <> ? LIMIT 0,30";
+            $query = "SELECT * FROM "._TABLE_TERM_."  WHERE word = ? AND owner <> ? LIMIT 30";
 
             $Fetch = PDO_FetchAll($query, array($word, $_COOKIE["userid"]));
             $iFetch = count($Fetch);
@@ -262,23 +264,43 @@ switch ($op) {
         }
     case "copy": //拷贝到我的字典
         {
-            $query = "select * from term  where \"guid\" = " . $PDO->quote($_GET["wordid"]);
+            $query = "select * from "._TABLE_TERM_."  where \"guid\" = " . $PDO->quote($_GET["wordid"]);
 
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             if ($iFetch > 0) {
                 /* 开始一个事务,关闭自动提交 */
                 $PDO->beginTransaction();
-                $query = "INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?," . time() . ",'$username',1)";
+                $query = "INSERT INTO "._TABLE_TERM_." 
+                (
+                    'id',
+                    'guid',
+                    'word',
+                    'word_en',
+                    'meaning',
+                    'other_meaning',
+                    'note',
+                    'tag',
+                    'owner',
+                    'editor_id',
+                    'create_time',
+                    'update_time',
+                    ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
                 $stmt = $PDO->prepare($query);
                 {
-                    $stmt->execute(array(UUID::v4,
+                    $stmt->execute(array(
+                        $snowflake->id(),
+                        UUID::v4,
                         $Fetch[0]["word"],
                         $Fetch[0]["word_en"],
                         $Fetch[0]["meaning"],
                         $Fetch[0]["other_meaning"],
                         $Fetch[0]["note"],
                         $Fetch[0]["tag"],
+                        $_COOKIE['user_uid'],
+                        $_COOKIE['user_id'],
+                        mTime(),
+                        mTime()
                     ));
                 }
                 /* 提交更改 */
@@ -301,7 +323,7 @@ switch ($op) {
                 $authors = str_getcsv($_POST["authors"]);
             }
             $queryLang = $currLanguage . "%";
-            $query = "SELECT * from term  where \"word\" in {$words} AND language like ?  limit 0,1000";
+            $query = "SELECT * from "._TABLE_TERM_."  where \"word\" in {$words} AND language like ?  limit 1000";
             $Fetch = PDO_FetchAll($query, array($queryLang));
             $iFetch = count($Fetch);
             echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
@@ -310,7 +332,7 @@ switch ($op) {
     case "sync":
         {
             $time = $_GET["time"];
-            $query = "SELECT guid,modify_time from term  where receive_time>'{$time}'   limit 0,1000";
+            $query = "SELECT guid,modify_time from "._TABLE_TERM_."  where receive_time>'{$time}'   limit 1000";
             $Fetch = PDO_FetchAll($query);
             $iFetch = count($Fetch);
             echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
@@ -320,9 +342,9 @@ switch ($op) {
         {
             $Fetch = array();
             if (isset($guid)) {
-                $query = "select * from term  where \"guid\" = '{$guid}'";
+                $query = "select * from "._TABLE_TERM_."  where \"guid\" = '{$guid}'";
             } else if (isset($word)) {
-                $query = "select * from term  where \"word\" = '{$word}'";
+                $query = "select * from "._TABLE_TERM_."  where \"word\" = '{$word}'";
             } else {
                 echo "[]";
                 return;

+ 4 - 4
public/app/term/term_channel_get.php

@@ -10,7 +10,7 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 require_once '../channal/function.php';
 
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect(_FILE_DB_TERM_);
 
 $output = array();
 if (isset($_POST["words"])) {
@@ -30,7 +30,7 @@ if (isset($_POST["words"])) {
         /*  创建一个填充了和params相同数量占位符的字符串 */
         $place_holders = implode(',', array_fill(0, count($channal), '?'));
         $owner_holders = implode(',', array_fill(0, count($channal_owner), '?'));
-        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM term WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
+        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM "._TABLE_TERM_." WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
         foreach ($channal_owner as $key => $value) {
             # code...
             $channal[] = $key;
@@ -82,9 +82,9 @@ if (isset($_POST["words"])) {
             }
 
             if ($otherCase == "") {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? ";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? ";
             } else {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? AND ( $otherCase )";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? AND ( $otherCase )";
             }
 
             $fetch = PDO_FetchAll($query, $parm);

+ 141 - 35
public/app/term/term_edit_dlg.js

@@ -7,7 +7,8 @@ function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
 		outerHeight: "80vh",
 		buttons: [
 			{
-				text: gLocal.gui.save,
+                id:"term_edit_dlg_save",
+				text: gLocal.gui.submit,
 				click: function () {
 					term_edit_dlg_save();
 					$(this).dialog("close");
@@ -22,7 +23,10 @@ function term_edit_dlg_init(title = gLocal.gui.dict_terms) {
 		],
 	});
 }
-function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
+/*
+obj:调用此函数的按钮的handle
+*/
+function term_edit_dlg_open(id = "", word = "",channel="",lang="",obj=null) {
 	if (id == "") {
 		let newWord = new Object();
 		newWord.guid = "";
@@ -33,7 +37,7 @@ function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
 		newWord.note = "";
 		newWord.language = lang;
 		newWord.channel = channel;
-		let html = term_edit_dlg_render(newWord);
+		let html = term_edit_dlg_render(newWord,obj);
 		$("#term_edit_dlg_content").html(html);
 		$("#term_edit_dlg").dialog("open");
 	} else {
@@ -44,7 +48,7 @@ function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
 			},
 			function (data) {
 				let word = JSON.parse(data);
-				let html = term_edit_dlg_render(word);
+				let html = term_edit_dlg_render(word,obj);
 				$("#term_edit_dlg_content").html(html);
 				$("#term_edit_dlg").dialog("open");
 			}
@@ -52,11 +56,11 @@ function term_edit_dlg_open(id = "", word = "",channel="",lang="") {
 	}
 }
 
-function term_edit_dlg_render(word = "") {
-	if (word == "") {
+function term_edit_dlg_render(word = null,obj=null) {
+	if (word == null) {
 		word = new Object();
 		word.guid = "";
-		word.word = pali;
+		word.word = "";
 		word.meaning = "";
 		word.other_meaning = "";
 		word.tag = "";
@@ -67,12 +71,21 @@ function term_edit_dlg_render(word = "") {
 	output += "<input type='hidden' id='term_edit_form_id' name='id' value='" + word.guid + "'>";
 	output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.spell + "</legend>";
-	output +=
-		"<input type='input' id='term_edit_form_word' name='word' value='" +
-		word.word +
-		"'placeholder=" +
-		gLocal.gui.required +
-		">";
+    if(word.guid === "" && word.word === ""){
+        //新建术语 而且词头为空 允许修改word 拼写
+            "<input type='input' id='term_edit_form_word' name='word' value='" +
+            word.word +
+            ">";  
+    }else{
+        output += "<div style='font-size:200%;font-weight:700;'>"+word.word+"</div>";
+        output +=
+            "<input type='hidden' id='term_edit_form_word' name='word' value='" +
+            word.word +
+            "'placeholder=" +
+            gLocal.gui.required +
+            ">";        
+    }
+
 	output += "</fieldset>";
 
 	output += "<fieldset>";
@@ -115,50 +128,135 @@ function term_edit_dlg_render(word = "") {
 		" >";
 	output += "</fieldset>";
 
+
+
 	output += "<fieldset>";
+	output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
+	output += "<textarea id='term_edit_form_note' name='note' placeholder=" + gLocal.gui.optional +	" style='height:5em;'>";
+	output += word.note ;
+	output += "</textarea>";
+	output += "</fieldset>";
+
+
+
+    output += "<fieldset>";
 	output += "<legend>" + gLocal.gui.channel + "</legend>";
 
-	let currChannel=null;
+	let currChannel=null;//当前单词的channel
 	if(typeof word.channel == "undefined" && typeof word.channal != "undefined"){
 		word.channel = word.channal;
 	}
 	for (const iterator of _my_channal) {
-		if(iterator.id==word.channel){
+		if(iterator.uid==word.channel){
 			currChannel = iterator;
 		}
 	}
+    //查询术语所在句子的channel
+    let sentChannel=null;
+    let sentChannelId=null;
+    if(obj){
+        let sentObj = find_sent_tran_div(obj);
+        if(sentObj){
+            sentChannelId = sentObj.attr('channel');
+            for (const iterator of _my_channal) {
+                if(iterator.uid==sentChannelId){
+                    sentChannel = iterator;
+                }
+	        }
+        }
+    }
+    let style='display:none;';
+    if(word.guid === ''){
+        //新建术语 可以修改channel
+        style = 'display:block;';
+    }else{
+        //修改术语 不能修改channel
+        output +="<div>当前:" ;
+        if(word.channel === ''){
+            output += "通用于<b>所有版本</b>";
+            //判断是否只读
+            if(sentChannel.power !== 30){
+                output += "(只读)";
+            }
+        }else{
+            output += "仅使用于版本<b>";
+            if(currChannel !== null){
+                //我有写权限
+                output += currChannel.name;
+            }else{
+                //我没有写权限 设置按钮为disable
+                output += word.channel;
+                output += "(只读)";
+            }
+            output += "</b>";
+        }
 
+        output += "</div>";
+        output +="<div><input type='checkbox' name='save_as' onchange='term_save_as(this)' />另存为</div>";
+    }
+
+    output += "<div id='term_save_as_channel' style='"+style+"' >";
 	output += "<select id='term_edit_form_channal' name='channal'>";
-	if(currChannel !== null){
-		if(currChannel.owner == getCookie("user_uid")){
-			//是自己的
-			output += "<option value=''>通用于所有版本</option>";
-			
-		}
-		output += "<option value='"+currChannel.id+"'>仅用于"+currChannel.name+"</option>";
-	}else{
-		output += "<option value=''>通用于所有版本</option>";
-	}
-	/*
+    //TODO 句子channel 是我自己的才显示通用于所有版本
+    if(sentChannelId){
+        if(sentChannel && sentChannel.power==30){
+            output += "<option value=''>通用于我的所有版本</option>";
+        }
+    }else{
+        //术语不在句子里,也显示
+        output += "<option value=''>通用于我的所有版本</option>";
+    }
+    
+    
+    /*
+    按照当前的默认匹配逻辑,先匹配句子所在channel 里面的术语,没有才匹配通用的
+    所以如果此术语匹配到了channel 说明这个channel一定是这个句子的channel 
+    在这种情况下,如果没有在我的有写权限的channel列表中找到,这个句子channel一定是我没有写权限的。
+    */
+
+    //句子channel 我有写权限才显示仅用于此channel
+    let ignoreChannelId=null;
+    if(word.channel === ''){
+        if(sentChannel !== null){
+            output += "<option value='"+sentChannel.uid+"'>[本句版本]"+sentChannel.name+"</option>";
+            ignoreChannelId = sentChannel.uid;
+        }
+    }
+    if(word.guid==''){
+        //新建术语
+        for (const iterator of _my_channal) {
+            if(iterator.uid==word.channel){
+                //这句我有写权限
+                output += "<option value='"+word.channel+"'>[本句版本]"+iterator.name+"</option>";
+                ignoreChannelId = word.channel;
+            }
+        }
+    }
+
 	for (const iterator of _my_channal) {
-		if(word.channel=="" || (word.channel!="" && iterator.id==word.channel)){
-			output += "<option value='"+iterator.id+"'>仅用于"+iterator.name+"</option>";
+        if(currChannel && currChannel.uid==iterator.uid){
+            continue;
+        }
+        if(ignoreChannelId === iterator.uid){
+            continue;
+        }
+		if(word.channel=="" || (word.channel!="" && iterator.uid !== word.channel)){
+			output += "<option value='"+iterator.uid+"' onclick=\"set_term_dlg_channel_msg('此术语将仅仅用于这个版本')\">仅用于"+iterator.name+"</option>";
 		}
 	}
-	*/
+	
 	output += "</select>";
+    output += "<div class='msg' id='term_dlg_channel_msg'>只有选择<b>通用版本</b>或者<b>本句版本</b>才会应用到这个句子</div>";
+    output += "</div>";
 	output += "</fieldset>";
 
-	output += "<fieldset>";
-	output += "<legend>" + gLocal.gui.encyclopedia + "</legend>";
-	output += "<textarea id='term_edit_form_note' name='note' placeholder=" + gLocal.gui.optional +	">";
-	output += word.note ;
-	output += "</textarea>";
-	output += "</fieldset>";
 	output += "</form>";
 
 	return output;
 }
+function set_term_dlg_channel_msg(msg){
+    $("#term_dlg_channel_msg").text(msg);
+}
 function term_edit_dlg_save() {
 	$.ajax({
 		type: "POST", //方法类型
@@ -202,3 +300,11 @@ function term_edit_dlg_save() {
 		},
 	});
 }
+
+function term_save_as(obj){
+    if(obj.checked){
+        $("#term_save_as_channel").show();
+    }else{
+        $("#term_save_as_channel").hide();
+    }
+}

+ 10 - 5
public/app/term/term_get.php

@@ -10,12 +10,17 @@ require_once '../public/function.php';
 require_once '../ucenter/function.php';
 require_once '../channal/function.php';
 
-PDO_Connect("" . _FILE_DB_TERM_);
+if(isset($_POST["readonly"])){
+    $readonly = $_POST["readonly"];
+}else{
+    $readonly = true;
+}
+PDO_Connect(_FILE_DB_TERM_);
 
 $output = array();
 if (isset($_POST["words"])) {
     $wordlist = json_decode($_POST["words"]);
-    if ($_POST["readonly"] == "false" && !empty($_POST["channal"])) {
+    if ($readonly == "false" && !empty($_POST["channal"])) {
         $channal = explode(",", $_POST["channal"]);
         $channal_info = new Channal();
         $channal_owner = array();
@@ -29,7 +34,7 @@ if (isset($_POST["words"])) {
         /*  创建一个填充了和params相同数量占位符的字符串 */
         $place_holders = implode(',', array_fill(0, count($channal), '?'));
         $owner_holders = implode(',', array_fill(0, count($channal_owner), '?'));
-        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM term WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
+        $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note  FROM "._TABLE_TERM_." WHERE channal IN ($place_holders) OR owner IN ($owner_holders)";
         foreach ($channal_owner as $key => $value) {
             # code...
             $channal[] = $key;
@@ -80,9 +85,9 @@ if (isset($_POST["words"])) {
             }
 
             if ($otherCase == "") {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? ";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? ";
             } else {
-                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM term WHERE word = ? AND ( $otherCase )";
+                $query = "SELECT guid,word,meaning,other_meaning,owner,channal,language,tag ,note FROM "._TABLE_TERM_." WHERE word = ? AND ( $otherCase )";
             }
 
             $fetch = PDO_FetchAll($query, $parm);

+ 3 - 3
public/app/term/term_get_id.php

@@ -8,16 +8,16 @@ require_once "../config.php";
 require_once "../public/_pdo.php";
 require_once '../ucenter/function.php';
 
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect( _FILE_DB_TERM_);
 
 $fetch = array();
 if (isset($_POST["id"])) {
-    $query = "SELECT * FROM term WHERE guid = ? ";
+    $query = "SELECT * FROM "._TABLE_TERM_." WHERE guid = ? ";
 
     $fetch = PDO_FetchRow($query, array($_POST["id"]));
-    $userinfo = new UserInfo();
     if ($fetch) {
         # code...
+        $userinfo = new UserInfo();
         $fetch["user"] = $userinfo->getName($fetch["owner"]);
     }
 }

+ 2 - 2
public/app/term/term_popup.js

@@ -57,7 +57,7 @@ function note_lookup_guid_json(guid) {
             "<div class='term_note' status='1'>" +
             note_init(result.note) +
             "</div>";
-          html += "<div >";
+          html += "<div class='term_popup_foot'>";
           html +=
             "<a href='../wiki/wiki.php?word=" +
             result.word +
@@ -65,7 +65,7 @@ function note_lookup_guid_json(guid) {
           html +=
             "<button onclick=\"term_edit_dlg_open('" +
             result.guid +
-            "')\">修改</button>";
+            "','','','',this)\">修改</button>";
           html += "</div>";
           html += "</div>";
           $("[term-popup='" + guid + "']").html(html);

+ 69 - 39
public/app/term/term_post.php

@@ -7,6 +7,8 @@ require_once "../public/_pdo.php";
 require_once '../public/function.php';
 require_once "../redis/function.php";
 require_once "../channal/function.php";
+require_once __DIR__."/../public/snowflakeid.php";
+$snowflake = new SnowFlakeId();
 
 $redis = redis_connect();
 
@@ -20,15 +22,15 @@ if (isset($_COOKIE["userid"]) == false) {
 
 
 $respond = array("status" => 0, "message" => "");
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect( _FILE_DB_TERM_);
 
+$channelInfo = new Channal($redis);
 
-
-if ($_POST["id"] != "") {
+if ($_POST["id"] != "" && !isset($_POST['save_as'])) {
 	#更新
 	#先查询是否有权限
 	#是否这个术语的作者
-	$query = "SELECT id,channal,owner from term where guid= ? ";
+	$query = "SELECT id,channal,owner from "._TABLE_TERM_." where guid= ? ";
 	$stmt = $PDO->prepare($query);
 	$stmt->execute(array($_POST["id"]));
 	if ($stmt) {
@@ -36,7 +38,7 @@ if ($_POST["id"] != "") {
 		if($Fetch){
 			if($Fetch['owner']!=$_COOKIE["userid"]){
 				#不是这个术语的作者,查是否是channel的有编辑权限者	
-				$channelInfo = new Channal($redis);
+				
 				$channelPower = $channelInfo->getPower($Fetch['channal']);
 				if($channelPower<20){
 					$respond['status'] = 1;
@@ -54,16 +56,14 @@ if ($_POST["id"] != "") {
 			exit;				
 		}
 	}
-    $query = "UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? ,  language = ? , note = ? , receive_time= ?, modify_time= ?   where guid= ? ";
+    $query = "UPDATE "._TABLE_TERM_." SET meaning= ? ,other_meaning = ? , tag= ? ,  language = ? , note = ? ,  modify_time= ? , updated_at = now()  where guid= ? ";
 	$stmt = @PDO_Execute($query, 
 						array($_POST["mean"],
         					  $_POST["mean2"],
         					  $_POST["tag"],
-        					  $_POST["channal"],
         					  $_POST["language"],
         					  $_POST["note"],
         					  mTime(),
-        					  mTime(),
         					  $_POST["id"],
     ));
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
@@ -107,15 +107,25 @@ if ($_POST["id"] != "") {
 	}
 	#先查询是否有重复数据
 	if($_POST["channal"]==""){
-		$query = "SELECT id from term where word= ? and  language=? and tag=? and owner = ? ";
+		$query = "SELECT id from "._TABLE_TERM_." where word= ? and  language=? and tag=? and owner = ? ";
 		$stmt = $PDO->prepare($query);
 		$stmt->execute(array($_POST["word"],$_POST["language"],$_POST["tag"],$_COOKIE["userid"]));
 	}else{
-		$query = "SELECT id from term where word= ? and channal=?  and tag=? and owner = ? ";
+        #TODO 
+		$query = "SELECT id from "._TABLE_TERM_." where word= ? and channal=?  and tag=? and owner = ? ";
 		$stmt = $PDO->prepare($query);
 		$stmt->execute(array($_POST["word"],$_POST["channal"],$_POST["tag"],$_COOKIE["userid"]));
 	}
-	
+	if($_POST["channal"]==""){
+        $owner_uid = $_COOKIE["user_uid"];
+    }else{
+        $channel = $channelInfo->getChannal($_POST["channal"]);
+        if($channelInfo){
+            $owner_uid = $channel["owner_uid"];
+        }else{
+            $owner_uid = $_COOKIE["user_uid"];
+        }
+    }
 	if ($stmt) {
 		$Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
 		if($Fetch){
@@ -125,22 +135,40 @@ if ($_POST["id"] != "") {
 			exit;
 		}
 	}
-    $parm[] = UUID::v4();
-    $parm[] = $_POST["word"];
-    $parm[] = pali2english($_POST["word"]);
-    $parm[] = $_POST["mean"];
-    $parm[] = $_POST["mean2"];
-    $parm[] = $_POST["tag"];
-    $parm[] = $_POST["channal"];
-    $parm[] = $_POST["language"];
-    $parm[] = $_POST["note"];
-    $parm[] = $_COOKIE["userid"];
-    $parm[] = 0;
-    $parm[] = mTime();
-    $parm[] = mTime();
-    $parm[] = mTime();
-    $query = "INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time )
-	VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
+    $parm = [
+        $snowflake->id(),
+        UUID::v4(),
+        $_POST["word"],
+        pali2english($_POST["word"]),
+        $_POST["mean"],
+        $_POST["mean2"],
+        $_POST["tag"],
+        $_POST["channal"],
+        $_POST["language"],
+        $_POST["note"],
+        $owner_uid,
+        $_COOKIE["user_id"],
+        mTime(),
+        mTime()
+        ];
+    $query = "INSERT INTO "._TABLE_TERM_." 
+    (
+        id, 
+        guid, 
+        word, 
+        word_en, 
+        meaning, 
+        other_meaning, 
+        tag, 
+        channal, 
+        language,
+        note,
+        owner,
+        editor_id,
+        create_time,
+        modify_time
+    )
+	VALUES (?, ? , ?, ?, ?, ?, ?, ?, ?, ? , ?, ?, ?, ?) ";
     $stmt = @PDO_Execute($query, $parm);
     if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
         $error = PDO_ErrorInfo();
@@ -149,17 +177,19 @@ if ($_POST["id"] != "") {
     } else {
         $respond['status'] = 0;
         $respond['message'] = $_POST["word"];
-        $respond['data'] = ["guid"=>$parm[0],
-							"word"=>$parm[1],
-							"word_en"=>$parm[2],
-							"meaning"=>$parm[3],
-							"other_meaning"=>$parm[4],
-							"tag"=>$parm[5],
-							"channal"=>$parm[6],
-							"language"=>$parm[7],
-							"note"=>$parm[8],
-							"owner"=>$parm[9]
-						];
+        $respond['data'] = [
+            "id"=>$parm[0],
+            "guid"=>$parm[1],
+			"word"=>$parm[2],
+			"word_en"=>$parm[3],
+			"meaning"=>$parm[4],
+			"other_meaning"=>$parm[5],
+			"tag"=>$parm[6],
+			"channal"=>$parm[7],
+			"language"=>$parm[8],
+			"note"=>$parm[9],
+			"owner"=>$parm[10]
+			];
 
     }
 }
@@ -168,7 +198,7 @@ if ($_POST["id"] != "") {
 	if ($redis != false) {
 		{
 			# code...
-			$query = "SELECT id,word,meaning,other_meaning,note,owner,language from term where word = ? ";
+			$query = "SELECT id,word,meaning,other_meaning,note,owner,language from "._TABLE_TERM_." where word = ? ";
 			$stmt = $PDO->prepare($query);
 			$stmt->execute(array($_POST["word"]));
 			if ($stmt) {

+ 3 - 3
public/app/term/update_analytics.php

@@ -5,15 +5,15 @@ require_once '../public/load_lang.php';
 require_once '../public/function.php';
 
 global $PDO;
-PDO_Connect("" . _FILE_DB_TERM_);
+PDO_Connect(_FILE_DB_TERM_);
 
 echo "Day Index,创建,更新\n";
 $end = strtotime("now");
 $begin = strtotime("-1 day");
 for ($i = 0; $i < 100; $i++) {
-    $query = "select count(*) from term where \"create_time\" > " . $PDO->quote($begin) . " AND \"create_time\" < " . $PDO->quote($end);
+    $query = "SELECT count(*) from "._TABLE_TERM_." where \"create_time\" > " . $PDO->quote($begin) . " AND \"create_time\" < " . $PDO->quote($end);
     $create = PDO_FetchOne($query);
-    $query = "select count(*) from term where modify_time <> create_time AND \"modify_time\" > " . $PDO->quote($begin) . " AND \"modify_time\" < " . $PDO->quote($end);
+    $query = "SELECT count(*) from "._TABLE_TERM_." where modify_time <> create_time AND \"modify_time\" > " . $PDO->quote($begin) . " AND \"modify_time\" < " . $PDO->quote($end);
     $modify = PDO_FetchOne($query);
     echo date("m/d/Y", $begin) . ',' . $create . "," . $modify . "\n";
     $end = $begin;

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 19 - 0
public/app/ucenter/jquery_jwt_example.html


+ 1 - 1
public/app/uwbw/create_wbw.php

@@ -201,7 +201,7 @@ foreach ($_para as $key => $para) {
 				$strXml,
 				mTime(),
 				mTime(),
-				$channelInfo["status"],
+				0,
 				$_COOKIE["userid"],
 				$_COOKIE["uid"]
 			);

+ 4 - 3
public/app/uwbw/update.js

@@ -7,7 +7,7 @@ function user_wbw_push_word_element(xWord) {
 	let wId = wordid.split("-")[2];
 	let mWord = doc_word("#" + wordid);
 	let blockid = mWord.block.info("id");
-	user_wbw_push(blockid, wId, com_xmlToString(xWord));
+	user_wbw_push(blockid, wId, com_xmlToString(xWord),getNodeText(xWord,'status'));
 }
 
 function user_wbw_push_word(wordid) {
@@ -34,11 +34,11 @@ function user_wbw_push_word(wordid) {
 			}
 			wordData += com_xmlToString(xAllWord[i]);
 		}
-		user_wbw_push(blockid, wId, wordData);
+		user_wbw_push(blockid, wId, wordData,getNodeText(xAllWord[i],'status'));
 	}
 }
 
-function user_wbw_push(block_id, wid, data) {
+function user_wbw_push(block_id, wid, data,status=7) {
 	let d = new Date();
 	let objData = new Object();
 	objData.block_id = block_id;
@@ -47,6 +47,7 @@ function user_wbw_push(block_id, wid, data) {
 	objData.time = d.getTime();
 	objData.book = doc_block("#" + block_id).info("book");
 	objData.para = doc_block("#" + block_id).info("paragraph");
+	objData.status = status;
 	user_wbw_data_buffer.push(objData);
 }
 var commitTimes = 0;

+ 7 - 2
public/app/uwbw/update.php

@@ -48,12 +48,17 @@ if (count($aData) > 0) {
 
     /* 开始一个事务,关闭自动提交 */
     $PDO->beginTransaction();
-    $query = "UPDATE "._TABLE_USER_WBW_." SET data= ?  , editor_id = ? , modify_time= ? , updated_at = now()  where block_uid= ?  and wid= ?  ";
+    $query = "UPDATE "._TABLE_USER_WBW_." SET data= ?  , editor_id = ? , status = ?, modify_time= ? , updated_at = now()  where block_uid= ?  and wid= ?  ";
     $sth = $PDO->prepare($query);
 
     foreach ($aData as $data) {
 		if($listBlockId[$data->block_id]>=20){
-			$sth->execute(array($data->data, $_COOKIE['uid'], mTime(), $data->block_id, $data->word_id));
+            if(!isset($data->status) || empty($data->status)){
+                $status = 7;
+            }else{
+                $status = (int)$data->status;
+            }
+			$sth->execute(array($data->data, $_COOKIE['uid'], $status , mTime(), $data->block_id, $data->word_id));
 		}
     }
     $PDO->commit();

+ 17 - 0
public/db/sqlite/dhammaterm/term.sql

@@ -0,0 +1,17 @@
+CREATE TABLE dhammaterm (
+    id            INTEGER   PRIMARY KEY AUTOINCREMENT,
+    guid          TEXT (36),
+    word          TEXT,
+    word_en       TEXT,
+    meaning       TEXT,
+    other_meaning TEXT,
+    note          TEXT,
+    tag           TEXT,
+    create_time   INTEGER,
+    owner         TEXT,
+    hit           INTEGER   DEFAULT (0),
+    language      CHAR (8),
+    receive_time  INTEGER,
+    modify_time   INTEGER,
+    channal       TEXT
+);

+ 43 - 0
public/db/sqlite/fileindex/up.sql

@@ -0,0 +1,43 @@
+--
+-- 由SQLiteStudio v3.1.1 产生的文件 周日 2月 6 14:17:51 2022
+--
+-- 文本编码:UTF-8
+--
+PRAGMA foreign_keys = off;
+BEGIN TRANSACTION;
+
+-- 表:fileindex
+CREATE TABLE fileindex (
+    id           CHAR (36),
+    parent_id    CHAR (36),
+    user_id      INTEGER,
+    book         INTEGER   DEFAULT (0),
+    paragraph    INTEGER   DEFAULT (0),
+    file_name    TEXT      NOT NULL,
+    title        TEXT,
+    tag          TEXT,
+    status       INTEGER   DEFAULT (1),
+    create_time  INTEGER,
+    modify_time  INTEGER,
+    accese_time  INTEGER,
+    file_size    INTEGER,
+    share        INTEGER   DEFAULT (0),
+    doc_info     TEXT,
+    doc_block    TEXT,
+    receive_time INTEGER
+, 'channal' TEXT);
+
+-- 表:power
+CREATE TABLE power (
+    id           CHAR (36) PRIMARY KEY,
+    doc_id       CHAR (36),
+    user         CHAR (36),
+    power        INTEGER,
+    status       INTEGER,
+    create_time  INTEGER,
+    modify_time  INTEGER,
+    receive_time INTEGER
+, 'type' INTEGER DEFAULT 0);
+
+COMMIT TRANSACTION;
+PRAGMA foreign_keys = on;

+ 35 - 0
public/db/sqlite/group/up.sql

@@ -0,0 +1,35 @@
+--
+-- 由SQLiteStudio v3.1.1 产生的文件 周六 2月 5 08:30:59 2022
+--
+-- 文本编码:UTF-8
+--
+PRAGMA foreign_keys = off;
+BEGIN TRANSACTION;
+
+-- 表:group_info
+CREATE TABLE group_info 
+(
+    id CHAR (36) PRIMARY KEY, 
+    parent CHAR (36), 
+    name CHAR (32) NOT NULL, 
+    description TEXT, 
+    create_time INTEGER NOT NULL, 
+    status INTEGER, 
+    owner CHAR (36), 
+    'modify_time' INTEGER
+);
+
+-- 表:group_member
+CREATE TABLE group_member 
+(
+    id INTEGER PRIMARY KEY AUTOINCREMENT, 
+    user_id CHAR (36) NOT NULL, 
+    group_id INTEGER NOT NULL, 
+    power INTEGER NOT NULL DEFAULT (1), 
+    group_name CHAR (32), 
+    level INTEGER DEFAULT (0), 
+    status INTEGER DEFAULT (1)
+);
+
+COMMIT TRANSACTION;
+PRAGMA foreign_keys = on;

+ 0 - 0
public/db/sqlite/share/share.sql


+ 9 - 1
public/documents/testing.md

@@ -64,4 +64,12 @@
    1. 创建[v]
    2. 删除(无)
    3. 修改[v]
-   4. 协作[v]
+   4. 协作[v]
+9. 群组
+   1. 创建[v] (不允许建立同名群组)
+   2. 删除[v] (同时删除共享资源链接)
+   3. 修改(无)
+   4. 加成员[v]
+   5. 删除成员[v] (只有群主可以删除其他成员)
+   6. 分享资源到这个群组
+10. 

+ 2 - 0
routes/api.php

@@ -3,6 +3,7 @@
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Route;
 use App\Http\Controllers\WbwTemplateController;
+use App\Http\Controllers\DhammaTermController;
 /*
 |--------------------------------------------------------------------------
 | API Routes
@@ -20,4 +21,5 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
 
 Route::group(['prefix' => 'v2'],function(){
 	Route::apiResource('wbw_templates',WbwTemplateController::class);
+	Route::apiResource('terms',DhammaTermController::class);
 });

+ 8 - 0
v1/scripts/install3.sh

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+date
+
+php ./migrations/20220202172100_dhamma_terms_copy.php
+php ./migrations/20220204081300_share_copy.php
+
+date

+ 9 - 0
v1/scripts/install4.sh

@@ -0,0 +1,9 @@
+#!/bin/sh
+
+date
+
+php ./migrations/20220205084100_group_info_copy.php
+php ./migrations/20220205092400_group_member_copy.php
+
+php ./migrations/20220206143600_fileindex_copy.php
+date

+ 1 - 1
v1/scripts/migrations/20211204120600_wbw_blocks_copy.php

@@ -83,7 +83,7 @@ $allSrcCount = 0;
 $count = 0;
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 

+ 1 - 1
v1/scripts/migrations/20211207052901_sent_copy.php

@@ -69,7 +69,7 @@ $allInsertCount = 0;
 $allSrcCount = 0;
 $count = 0;
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 

+ 1 - 1
v1/scripts/migrations/20211207164600_sent_pr_copy.php

@@ -66,7 +66,7 @@ $allSrcCount = 0;
 $count = 0;
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 1 - 1
v1/scripts/migrations/20211207171500_sent_historay_copy.php

@@ -56,7 +56,7 @@ $allSrcCount = 0;
 $count = 0;
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 2 - 2
v1/scripts/migrations/20211214181900_user_operation_log_copy.php

@@ -66,7 +66,7 @@ fwrite(STDOUT,"open dest table".PHP_EOL);
 #删除源数据表中全部数据
 fwrite(STDOUT,"delete dest".PHP_EOL);
 
-$query = "delete from $dest_table where true;";
+$query = "delete from $dest_table";
 $stmtDest = $PDO_DEST->prepare($query);
 $stmtDest->execute();
 
@@ -93,7 +93,7 @@ $query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
 $stmtUser = $PDO_USER->prepare($query);
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 2 - 2
v1/scripts/migrations/20211214190200_user_operation_frames_copy.php

@@ -49,7 +49,7 @@ fwrite(STDOUT,"open dest table".PHP_EOL);
 #删除目标数据表中全部数据
 fwrite(STDOUT,"delete dest".PHP_EOL);
 
-$query = "delete from $dest_table where true;";
+$query = "delete from $dest_table";
 $stmtDest = $PDO_DEST->prepare($query);
 $stmtDest->execute();
 
@@ -77,7 +77,7 @@ $query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
 $stmtUser = $PDO_USER->prepare($query);
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 2 - 2
v1/scripts/migrations/20211214191900_user_operation_dailys_copy.php

@@ -49,7 +49,7 @@ fwrite(STDOUT,"open dest table".PHP_EOL);
 #删除目标数据表中全部数据
 fwrite(STDOUT,"delete dest".PHP_EOL);
 
-$query = "delete from $dest_table where true;";
+$query = "delete from $dest_table";
 $stmtDest = $PDO_DEST->prepare($query);
 $stmtDest->execute();
 
@@ -75,7 +75,7 @@ $query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
 $stmtUser = $PDO_USER->prepare($query);
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 1 - 1
v1/scripts/migrations/20211215214400_channel_copy.php

@@ -75,7 +75,7 @@ $query = "SELECT id ,userid FROM ".$user_table." WHERE userid = ? or username =
 $stmtUser = $PDO_USER->prepare($query);
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 1 - 1
v1/scripts/migrations/20211218093500_articles_copy.php

@@ -78,7 +78,7 @@ $query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
 $stmtUser = $PDO_USER->prepare($query);
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 1 - 1
v1/scripts/migrations/20211218132000_collections_copy.php

@@ -77,7 +77,7 @@ $query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
 $stmtUser = $PDO_USER->prepare($query);
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true ";
+$query = "SELECT *  FROM ".$src_table;
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 3 - 3
v1/scripts/migrations/20211218133000_article_collection_copy.php

@@ -34,12 +34,12 @@ fwrite(STDOUT,"migarate _TABLE_ARTICLE_COLLECTION_".PHP_EOL);
 
 #打开源数据库
 $PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
-$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 fwrite(STDOUT,"open src table".PHP_EOL);
 
 #打开目标数据库
 $PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
-$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 fwrite(STDOUT,"open dest table".PHP_EOL);
 
 #删除目标数据表中全部数据
@@ -70,7 +70,7 @@ $count = 0;
 
 
 #从源数据表中读取
-$query = "SELECT *  FROM ".$src_table." WHERE true order by id ASC";
+$query = "SELECT *  FROM ".$src_table." order by id ASC";
 $stmtSrc = $PDO_SRC->prepare($query);
 $stmtSrc->execute();
 while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){

+ 190 - 0
v1/scripts/migrations/20220202172100_dhamma_terms_copy.php

@@ -0,0 +1,190 @@
+<?php
+/*
+迁移  article 库
+从旧数据表中提取数据插入到新的表
+插入时用uuid判断是否曾经插入
+曾经插入就不插入了
+*/
+require_once __DIR__."/../../../public/app/config.php";
+require_once __DIR__."/../../../public/app/public/snowflakeid.php";
+
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+$start = time();
+# 雪花id
+$snowflake = new SnowFlakeId();
+
+$fpError = fopen(__DIR__.'/log/'.basename($_SERVER['PHP_SELF'],'.php').".err.data.csv",'w');
+
+#user info
+$user_db=_FILE_DB_USERINFO_;#user数据库
+$user_table=_TABLE_USER_INFO_;#user表名
+
+# 
+$src_db = _SQLITE_DB_TERM_;#源数据库
+$src_table = _SQLITE_TABLE_TERM_;#源表名
+
+$dest_db = _PG_DB_TERM_;#目标数据库
+$dest_table = _PG_TABLE_TERM_;#目标表名
+
+fwrite(STDOUT,"migarate dhammaterm".PHP_EOL);
+#打开user数据库
+$PDO_USER = new PDO($user_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_USER->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open user table".PHP_EOL);
+
+#打开源数据库
+$PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open src table".PHP_EOL);
+
+#打开目标数据库
+$PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open dest table".PHP_EOL);
+
+$queryInsert = "INSERT INTO ".$dest_table." 
+								(
+                                    id,
+									guid,
+									word,
+									word_en,
+									meaning,
+									other_meaning,
+									note,
+									tag,
+									channal,
+									language,
+									owner,
+									editor_id,
+									create_time,
+									modify_time,
+									updated_at,
+									created_at) 
+									VALUES (? , ? , ? , ?, ? , ? ,? , ? , ? , ? , ? , ? , ?,? ,?,?)";
+$stmtDEST = $PDO_DEST->prepare($queryInsert);
+
+$commitData = [];
+$allInsertCount = 0;
+$allSrcCount = 0;
+$count = 0;
+
+#从user数据表中读取
+$query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
+$stmtUser = $PDO_USER->prepare($query);
+
+#从源数据表中读取
+$query = "SELECT *  FROM ".$src_table;
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    if($srcData["owner"]=='visuddhinanda'){
+		$srcData["owner"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+    if($srcData["owner"]=='test7'){
+		$srcData["owner"] = '6bd2f4d7-d970-419c-8ee5-f4bac42f4bc1';
+	}
+    if($srcData["owner"]=='Dhammadassi'){
+		$srcData["owner"] = 'd8538ebd-d369-4777-b99a-3ccb1aff8bfc';
+	}
+    if($srcData["owner"]=='pannava'){
+		$srcData["owner"] = '4db550c4-bc1b-43f2-a518-2740cb478f37';
+	}
+    if($srcData["owner"]=='NST'){
+		$srcData["owner"] = '5c23e629-56a3-48e9-97c7-2af73b59c3b9';
+	}
+    if($srcData["owner"]=='viranyani'){
+		$srcData["owner"] = 'C1AB2ABF-EAA8-4EEF-B4D9-3854321852B4';
+	}
+    if($srcData["owner"]=='test6'){
+		$srcData["owner"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["owner"]=='test28'){
+		$srcData["owner"] = 'df0ad9bc-c0cd-4cd9-af05-e43d23ed57f0';
+	}
+	if($srcData["owner"]=='290fd808-2f46-4b8c-b300-0367badd67ed'){
+		$srcData["owner"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["owner"]=='BA837178-9ABD-4DD4-96A0-D2C21B756DC4'){
+		$srcData["owner"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+	$stmtUser->execute(array($srcData["owner"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["owner"]}".PHP_EOL);
+		continue;
+	}
+	if(strlen($srcData["owner"])>36){
+		fwrite(STDERR,time().",error,user id too long {$srcData["owner"]}".PHP_EOL);
+		continue;	
+	}
+    if(empty($srcData["word"])){
+		fwrite(STDERR,time().",error,word is empty {$srcData["id"]}".PHP_EOL);
+		continue;	
+	}
+    if(empty($srcData["language"]) ){
+        $srcData["language"]='zh-hans';
+    }
+
+    if($srcData["create_time"] < 15987088320){
+        $srcData["create_time"] *= 1000;
+    }
+    if($srcData["modify_time"] < 15987088320){
+        $srcData["modify_time"] *= 1000;
+    }
+	//查询是否已经插入
+	$queryExsit = "SELECT id  FROM ".$dest_table." WHERE guid = ? ";
+	$getExist = $PDO_DEST->prepare($queryExsit);
+	$getExist->execute(array($srcData["guid"]));
+	$exist = $getExist->fetch(PDO::FETCH_ASSOC);
+	if($exist){
+		continue;
+	}
+	#插入目标表
+	$created_at = date("Y-m-d H:i:s.",$srcData["create_time"]/1000).($srcData["create_time"]%1000)." UTC";
+	$updated_at = date("Y-m-d H:i:s.",$srcData["modify_time"]/1000).($srcData["modify_time"]%1000)." UTC";
+	$commitData = array(
+            $snowflake->id(),
+			$srcData["guid"],
+			$srcData["word"],
+			$srcData["word_en"],
+			$srcData["meaning"],
+			$srcData["other_meaning"],
+			$srcData["note"],
+			$srcData["tag"],
+			$srcData["channal"],
+			$srcData["language"],
+			$srcData["owner"],
+            $userId["id"],
+			$srcData["create_time"],
+			$srcData["modify_time"],
+			$created_at,
+			$updated_at
+		);
+	$stmtDEST->execute($commitData);
+
+	$count++;	
+	$allInsertCount++;
+
+
+	if($count ==10000){
+		#10000行输出log 一次
+		echo "finished $count".PHP_EOL;
+		$count=0;
+	}	
+}
+
+fwrite(STDOUT,"insert done $allInsertCount in $allSrcCount ".PHP_EOL) ;
+fwrite(STDOUT, "all done in ".(time()-$start)."s".PHP_EOL);
+
+fclose($fpError);
+
+
+
+

+ 195 - 0
v1/scripts/migrations/20220204081300_share_copy.php

@@ -0,0 +1,195 @@
+<?php
+/*
+迁移  article 库
+从旧数据表中提取数据插入到新的表
+插入时用uuid判断是否曾经插入
+曾经插入就不插入了
+*/
+require_once __DIR__."/../../../public/app/config.php";
+require_once __DIR__."/../../../public/app/public/snowflakeid.php";
+
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+$start = time();
+# 雪花id
+$snowflake = new SnowFlakeId();
+
+$fpError = fopen(__DIR__.'/log/'.basename($_SERVER['PHP_SELF'],'.php').".err.data.csv",'w');
+
+#user info
+$user_db=_FILE_DB_USERINFO_;#user数据库
+$user_table=_TABLE_USER_INFO_;#user表名
+
+# 
+$src_db = _SQLITE_DB_USER_SHARE_;#源数据库
+$src_table = _SQLITE_TABLE_USER_SHARE_;#源表名
+
+$dest_db = _PG_DB_USER_SHARE_;#目标数据库
+$dest_table = _PG_TABLE_USER_SHARE_;#目标表名
+
+fwrite(STDOUT,"migarate share ".PHP_EOL);
+#打开user数据库
+$PDO_USER = new PDO($user_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_USER->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open user table".PHP_EOL);
+
+#打开源数据库
+$PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open src table".PHP_EOL);
+
+#打开目标数据库
+$PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open dest table".PHP_EOL);
+
+$queryInsert = "INSERT INTO ".$dest_table." 
+								(
+                                    id,
+									res_id,
+									res_type,
+									cooperator_id,
+									cooperator_type,
+									power,
+									create_time,
+									modify_time,
+									created_at,
+									updated_at) 
+									VALUES (? , ? , ? , ?, ? , ? ,? , ? , ? , ? )";
+$stmtDEST = $PDO_DEST->prepare($queryInsert);
+
+$commitData = [];
+$allInsertCount = 0;
+$allSrcCount = 0;
+$count = 0;
+
+#从user数据表中读取
+$query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
+$stmtUser = $PDO_USER->prepare($query);
+
+    
+#从源数据表中读取
+$query = "SELECT *  FROM ".$src_table;
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    $queryExist = "SELECT *  FROM ".$dest_table." where res_id=? and res_type=? and cooperator_id=? and cooperator_type=?";
+    $stmtExist = $PDO_DEST->prepare($queryExist);
+    $stmtExist->execute([$srcData["res_id"],$srcData["res_type"],$srcData["cooperator_id"],$srcData["cooperator_type"]]);
+    $isExist = $stmtExist->fetch(PDO::FETCH_ASSOC);
+	if($isExist){
+        echo "record is existed id=".$srcData['id'].PHP_EOL;
+            if($srcData["modify_time"]>$isExist['modify_time']){
+                #源数据新,删除旧数据
+                $query = "delete from $dest_table where id=?";
+                $stmtDest = $PDO_DEST->prepare($query);
+                $stmtDest->execute([$isExist['id']]);
+                echo "desc record is old delete id=".$isExist['id'].PHP_EOL;
+                $allInsertCount--;
+            }else{
+                echo "desc record is new id=".$isExist['id'].PHP_EOL;
+                continue;
+            }
+    }
+
+if($srcData["cooperator_type"]==0){
+    if($srcData["cooperator_id"]=='visuddhinanda'){
+		$srcData["cooperator_id"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+    if($srcData["cooperator_id"]=='test7'){
+		$srcData["cooperator_id"] = '6bd2f4d7-d970-419c-8ee5-f4bac42f4bc1';
+	}
+    if($srcData["cooperator_id"]=='Dhammadassi'){
+		$srcData["cooperator_id"] = 'd8538ebd-d369-4777-b99a-3ccb1aff8bfc';
+	}
+    if($srcData["cooperator_id"]=='pannava'){
+		$srcData["cooperator_id"] = '4db550c4-bc1b-43f2-a518-2740cb478f37';
+	}
+    if($srcData["cooperator_id"]=='NST'){
+		$srcData["cooperator_id"] = '5c23e629-56a3-48e9-97c7-2af73b59c3b9';
+	}
+    if($srcData["cooperator_id"]=='viranyani'){
+		$srcData["cooperator_id"] = 'C1AB2ABF-EAA8-4EEF-B4D9-3854321852B4';
+	}
+    if($srcData["cooperator_id"]=='test6'){
+		$srcData["cooperator_id"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["cooperator_id"]=='test28'){
+		$srcData["cooperator_id"] = 'df0ad9bc-c0cd-4cd9-af05-e43d23ed57f0';
+	}
+	if($srcData["cooperator_id"]=='290fd808-2f46-4b8c-b300-0367badd67ed'){
+		$srcData["cooperator_id"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["cooperator_id"]=='BA837178-9ABD-4DD4-96A0-D2C21B756DC4'){
+		$srcData["cooperator_id"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+	$stmtUser->execute(array($srcData["cooperator_id"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["cooperator_id"]}".PHP_EOL);
+		continue;
+	}
+}
+
+
+	if(strlen($srcData["cooperator_id"])>36){
+		fwrite(STDERR,time().",error,user id too long {$srcData["cooperator_id"]}".PHP_EOL);
+		continue;	
+	}
+
+
+    if($srcData["create_time"] < 15987088320){
+        $srcData["create_time"] *= 1000;
+    }
+    if($srcData["modify_time"] < 15987088320){
+        $srcData["modify_time"] *= 1000;
+    }
+
+
+	#插入目标表
+	$created_at = date("Y-m-d H:i:s.",$srcData["create_time"]/1000).($srcData["create_time"]%1000)." UTC";
+	$updated_at = date("Y-m-d H:i:s.",$srcData["modify_time"]/1000).($srcData["modify_time"]%1000)." UTC";
+	$commitData = array(
+            $snowflake->id(),
+			$srcData["res_id"],
+			$srcData["res_type"],
+			$srcData["cooperator_id"],
+			$srcData["cooperator_type"],
+			$srcData["power"],
+			$srcData["create_time"],
+			$srcData["modify_time"],
+			$created_at,
+			$updated_at
+		);
+    try{
+        $stmtDEST->execute($commitData);
+    }catch (Exception $e) {
+        echo "Failed: " . $e->getMessage();
+    }
+	
+
+	$count++;	
+	$allInsertCount++;
+
+
+	if($count ==10000){
+		#10000行输出log 一次
+		echo "finished $count".PHP_EOL;
+		$count=0;
+	}	
+}
+
+fwrite(STDOUT,"insert done $allInsertCount in $allSrcCount ".PHP_EOL) ;
+fwrite(STDOUT, "all done in ".(time()-$start)."s".PHP_EOL);
+
+fclose($fpError);
+
+
+
+

+ 181 - 0
v1/scripts/migrations/20220205084100_group_info_copy.php

@@ -0,0 +1,181 @@
+<?php
+/*
+迁移  article 库
+从旧数据表中提取数据插入到新的表
+插入时用uuid判断是否曾经插入
+曾经插入就不插入了
+*/
+require_once __DIR__."/../../../public/app/config.php";
+require_once __DIR__."/../../../public/app/public/snowflakeid.php";
+
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+$start = time();
+# 雪花id
+$snowflake = new SnowFlakeId();
+
+$fpError = fopen(__DIR__.'/log/'.basename($_SERVER['PHP_SELF'],'.php').".err.data.csv",'w');
+
+#user info
+$user_db=_FILE_DB_USERINFO_;#user数据库
+$user_table=_TABLE_USER_INFO_;#user表名
+
+# 
+$src_db = _SQLITE_DB_GROUP_;#源数据库
+$src_table = _SQLITE_TABLE_GROUP_INFO_;#源表名
+
+$dest_db = _PG_DB_GROUP_;#目标数据库
+$dest_table = _PG_TABLE_GROUP_INFO_;#目标表名
+
+fwrite(STDOUT,"migarate group info".PHP_EOL);
+#打开user数据库
+$PDO_USER = new PDO($user_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_USER->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open user table".PHP_EOL);
+
+#打开源数据库
+$PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open src table".PHP_EOL);
+
+#打开目标数据库
+$PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open dest table".PHP_EOL);
+
+$queryInsert = "INSERT INTO ".$dest_table." 
+								(
+                                    id,
+									uid,
+									name,
+									description,
+									status,
+									owner,
+									create_time,
+									modify_time,
+									updated_at,
+									created_at) 
+									VALUES (? , ? , ? , ?, ? , ? , ? , ? , ? , ? )";
+$stmtDEST = $PDO_DEST->prepare($queryInsert);
+
+$commitData = [];
+$allInsertCount = 0;
+$allSrcCount = 0;
+$count = 0;
+
+#从user数据表中读取
+$query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
+$stmtUser = $PDO_USER->prepare($query);
+
+#从源数据表中读取
+$query = "SELECT *  FROM ".$src_table;
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    if($srcData["owner"]=='visuddhinanda'){
+		$srcData["owner"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+    if($srcData["owner"]=='test7'){
+		$srcData["owner"] = '6bd2f4d7-d970-419c-8ee5-f4bac42f4bc1';
+	}
+    if($srcData["owner"]=='Dhammadassi'){
+		$srcData["owner"] = 'd8538ebd-d369-4777-b99a-3ccb1aff8bfc';
+	}
+    if($srcData["owner"]=='pannava'){
+		$srcData["owner"] = '4db550c4-bc1b-43f2-a518-2740cb478f37';
+	}
+    if($srcData["owner"]=='NST'){
+		$srcData["owner"] = '5c23e629-56a3-48e9-97c7-2af73b59c3b9';
+	}
+    if($srcData["owner"]=='viranyani'){
+		$srcData["owner"] = 'C1AB2ABF-EAA8-4EEF-B4D9-3854321852B4';
+	}
+    if($srcData["owner"]=='test6'){
+		$srcData["owner"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["owner"]=='test28'){
+		$srcData["owner"] = 'df0ad9bc-c0cd-4cd9-af05-e43d23ed57f0';
+	}
+	if($srcData["owner"]=='290fd808-2f46-4b8c-b300-0367badd67ed'){
+		$srcData["owner"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["owner"]=='BA837178-9ABD-4DD4-96A0-D2C21B756DC4'){
+		$srcData["owner"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+	$stmtUser->execute(array($srcData["owner"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["owner"]}".PHP_EOL);
+		continue;
+	}
+	if(strlen($srcData["owner"])>36){
+		fwrite(STDERR,time().",error,user id too long {$srcData["owner"]}".PHP_EOL);
+		continue;	
+	}
+    if(empty($srcData["name"])){
+		fwrite(STDERR,time().",error,name is empty {$srcData["id"]}".PHP_EOL);
+		continue;
+	}
+
+    $srcData["status"] = 30;
+
+    if(empty($srcData["modify_time"])){
+        $srcData["modify_time"] = $srcData["create_time"];
+    }
+
+    if($srcData["create_time"] < 15987088320){
+        $srcData["create_time"] *= 1000;
+    }
+    if($srcData["modify_time"] < 15987088320){
+        $srcData["modify_time"] *= 1000;
+    }
+	//查询是否已经插入
+	$queryExsit = "SELECT id  FROM ".$dest_table." WHERE uid = ? ";
+	$getExist = $PDO_DEST->prepare($queryExsit);
+	$getExist->execute(array($srcData["id"]));
+	$exist = $getExist->fetch(PDO::FETCH_ASSOC);
+	if($exist){
+		continue;
+	}
+	#插入目标表
+	$created_at = date("Y-m-d H:i:s.",$srcData["create_time"]/1000).($srcData["create_time"]%1000)." UTC";
+	$updated_at = date("Y-m-d H:i:s.",$srcData["modify_time"]/1000).($srcData["modify_time"]%1000)." UTC";
+	$commitData = array(
+            $snowflake->id(),
+			$srcData["id"],
+			$srcData["name"],
+			$srcData["description"],
+			$srcData["status"],
+			$srcData["owner"],
+			$srcData["create_time"],
+			$srcData["modify_time"],
+			$created_at,
+			$updated_at
+		);
+	$stmtDEST->execute($commitData);
+
+	$count++;	
+	$allInsertCount++;
+
+
+	if($count ==10000){
+		#10000行输出log 一次
+		echo "finished $count".PHP_EOL;
+		$count=0;
+	}	
+}
+
+fwrite(STDOUT,"insert done $allInsertCount in $allSrcCount ".PHP_EOL) ;
+fwrite(STDOUT, "all done in ".(time()-$start)."s".PHP_EOL);
+
+fclose($fpError);
+
+
+
+

+ 170 - 0
v1/scripts/migrations/20220205092400_group_member_copy.php

@@ -0,0 +1,170 @@
+<?php
+/*
+迁移  article 库
+从旧数据表中提取数据插入到新的表
+插入时用uuid判断是否曾经插入
+曾经插入就不插入了
+*/
+require_once __DIR__."/../../../public/app/config.php";
+require_once __DIR__."/../../../public/app/public/snowflakeid.php";
+
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+$start = time();
+# 雪花id
+$snowflake = new SnowFlakeId();
+
+$fpError = fopen(__DIR__.'/log/'.basename($_SERVER['PHP_SELF'],'.php').".err.data.csv",'w');
+
+#user info
+$user_db=_FILE_DB_USERINFO_;#user数据库
+$user_table=_TABLE_USER_INFO_;#user表名
+
+# 
+$src_db = _SQLITE_DB_GROUP_;#源数据库
+$src_table = _SQLITE_TABLE_GROUP_MEMBER_;#源表名
+
+$dest_db = _PG_DB_GROUP_;#目标数据库
+$dest_table = _PG_TABLE_GROUP_MEMBER_;#目标表名
+
+fwrite(STDOUT,"migarate group member ".PHP_EOL);
+#打开user数据库
+$PDO_USER = new PDO($user_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_USER->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open user table".PHP_EOL);
+
+#打开源数据库
+$PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open src table".PHP_EOL);
+
+#打开目标数据库
+$PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open dest table".PHP_EOL);
+
+$queryInsert = "INSERT INTO ".$dest_table." 
+								(
+                                    id,
+									user_id,
+									group_id,
+									group_name,
+									power,
+									level,
+									status,
+									created_at,
+									updated_at) 
+									VALUES (? , ? , ? , ?, ? , ? ,?  , now() , now() )";
+$stmtDEST = $PDO_DEST->prepare($queryInsert);
+
+$commitData = [];
+$allInsertCount = 0;
+$allSrcCount = 0;
+$count = 0;
+
+#从user数据表中读取
+$query = "SELECT id  FROM ".$user_table." WHERE userid = ? ";
+$stmtUser = $PDO_USER->prepare($query);
+
+    
+#从源数据表中读取
+$query = "SELECT *  FROM ".$src_table;
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    $queryExist = "SELECT *  FROM ".$dest_table." where user_id=? and group_id=? ";
+    $stmtExist = $PDO_DEST->prepare($queryExist);
+    $stmtExist->execute([$srcData["user_id"],$srcData["group_id"]]);
+    $isExist = $stmtExist->fetch(PDO::FETCH_ASSOC);
+	if($isExist){
+        echo "record is existed id=".$srcData['id'].PHP_EOL;
+        continue;
+    }
+
+{
+    if($srcData["user_id"]=='visuddhinanda'){
+		$srcData["user_id"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+    if($srcData["user_id"]=='test7'){
+		$srcData["user_id"] = '6bd2f4d7-d970-419c-8ee5-f4bac42f4bc1';
+	}
+    if($srcData["user_id"]=='Dhammadassi'){
+		$srcData["user_id"] = 'd8538ebd-d369-4777-b99a-3ccb1aff8bfc';
+	}
+    if($srcData["user_id"]=='pannava'){
+		$srcData["user_id"] = '4db550c4-bc1b-43f2-a518-2740cb478f37';
+	}
+    if($srcData["user_id"]=='NST'){
+		$srcData["user_id"] = '5c23e629-56a3-48e9-97c7-2af73b59c3b9';
+	}
+    if($srcData["user_id"]=='viranyani'){
+		$srcData["user_id"] = 'C1AB2ABF-EAA8-4EEF-B4D9-3854321852B4';
+	}
+    if($srcData["user_id"]=='test6'){
+		$srcData["user_id"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["user_id"]=='test28'){
+		$srcData["user_id"] = 'df0ad9bc-c0cd-4cd9-af05-e43d23ed57f0';
+	}
+	if($srcData["user_id"]=='290fd808-2f46-4b8c-b300-0367badd67ed'){
+		$srcData["user_id"] = 'f81c7140-64b4-4025-b58c-45a3b386324a';
+	}
+	if($srcData["user_id"]=='BA837178-9ABD-4DD4-96A0-D2C21B756DC4'){
+		$srcData["user_id"] = 'ba5463f3-72d1-4410-858e-eadd10884713';
+	}
+	$stmtUser->execute(array($srcData["user_id"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["user_id"]}".PHP_EOL);
+		continue;
+	}
+}
+
+
+	if(strlen($srcData["user_id"])>36){
+		fwrite(STDERR,time().",error,user id too long {$srcData["user_id"]}".PHP_EOL);
+		continue;	
+	}
+
+	#插入目标表
+	$commitData = array(
+            $snowflake->id(),
+			$srcData["user_id"],
+			$srcData["group_id"],
+			$srcData["group_name"],
+			$srcData["power"],
+			$srcData["level"],
+			$srcData["status"]
+		);
+    try{
+        $stmtDEST->execute($commitData);
+    }catch (Exception $e) {
+        echo "Failed: " . $e->getMessage();
+    }
+	
+
+	$count++;	
+	$allInsertCount++;
+
+
+	if($count ==10000){
+		#10000行输出log 一次
+		echo "finished $count".PHP_EOL;
+		$count=0;
+	}	
+}
+
+fwrite(STDOUT,"insert done $allInsertCount in $allSrcCount ".PHP_EOL) ;
+fwrite(STDOUT, "all done in ".(time()-$start)."s".PHP_EOL);
+
+fclose($fpError);
+
+
+
+

+ 188 - 0
v1/scripts/migrations/20220206143600_fileindex_copy.php

@@ -0,0 +1,188 @@
+<?php
+/*
+迁移  article 库
+从旧数据表中提取数据插入到新的表
+插入时用uuid判断是否曾经插入
+曾经插入就不插入了
+*/
+require_once __DIR__."/../../../public/app/config.php";
+require_once __DIR__."/../../../public/app/public/snowflakeid.php";
+
+set_exception_handler(function($e){
+	fwrite(STDERR,"error-msg:".$e->getMessage().PHP_EOL);
+	fwrite(STDERR,"error-file:".$e->getFile().PHP_EOL);
+	fwrite(STDERR,"error-line:".$e->getLine().PHP_EOL);
+	exit;
+});
+
+
+$start = time();
+# 雪花id
+$snowflake = new SnowFlakeId();
+
+$fpError = fopen(__DIR__.'/log/'.basename($_SERVER['PHP_SELF'],'.php').".err.data.csv",'w');
+
+#user info
+$user_db=_FILE_DB_USERINFO_;#user数据库
+$user_table=_TABLE_USER_INFO_;#user表名
+
+# 
+$src_db = _SQLITE_DB_FILEINDEX_;#源数据库
+$src_table = _SQLITE_TABLE_FILEINDEX_;#源表名
+
+$dest_db = _PG_DB_FILEINDEX_;#目标数据库
+$dest_table = _PG_TABLE_FILEINDEX_;#目标表名
+
+fwrite(STDOUT,"migarate file index".PHP_EOL);
+#打开user数据库
+$PDO_USER = new PDO($user_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_USER->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open user table".PHP_EOL);
+
+#打开源数据库
+$PDO_SRC = new PDO($src_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_SRC->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open src table".PHP_EOL);
+
+#打开目标数据库
+$PDO_DEST = new PDO($dest_db,_DB_USERNAME_,_DB_PASSWORD_,array(PDO::ATTR_PERSISTENT=>true));
+$PDO_DEST->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+fwrite(STDOUT,"open dest table".PHP_EOL);
+
+$queryInsert = "INSERT INTO ".$dest_table." 
+								(
+                                    id,
+									uid,
+									parent_id,
+									user_id,
+									book,
+									paragraph,
+									channal,
+									file_name,
+									title,
+									tag,
+									status,
+									file_size,
+									share,
+									doc_info,
+									doc_block,
+									create_time,
+									modify_time,
+									accese_time,
+									accesed_at,
+									updated_at,
+									created_at) 
+									VALUES (? , ? , ? , ? , ?, ? ,? , ? , ? , ?, ? ,? , ? , ? , ?, ? ,? , ? , ? , ?, ? )";
+$stmtDEST = $PDO_DEST->prepare($queryInsert);
+
+$commitData = [];
+$allInsertCount = 0;
+$allSrcCount = 0;
+$count = 0;
+
+#从user数据表中读取
+$query = "SELECT id  FROM ".$user_table." WHERE id = ? ";
+$stmtUser = $PDO_USER->prepare($query);
+
+#从源数据表中读取
+$query = "SELECT *  FROM ".$src_table;
+$stmtSrc = $PDO_SRC->prepare($query);
+$stmtSrc->execute();
+while($srcData = $stmtSrc->fetch(PDO::FETCH_ASSOC)){
+	$allSrcCount++;
+
+    $queryExist = "SELECT *  FROM ".$dest_table." where uid=? ";
+    $stmtExist = $PDO_DEST->prepare($queryExist);
+    $stmtExist->execute([$srcData["id"]]);
+    $isExist = $stmtExist->fetch(PDO::FETCH_ASSOC);
+	if($isExist){
+        continue;
+    }
+
+	$stmtUser->execute(array($srcData["user_id"]));
+	$userId = $stmtUser->fetch(PDO::FETCH_ASSOC);
+	if(!$userId){
+		fwrite(STDERR,time()."error,no user id {$srcData["user_id"]}".PHP_EOL);
+		continue;
+	}
+
+    if(empty($srcData["doc_block"]) ){
+		fwrite(STDERR,time().",error, doc_block is empty {$srcData["id"]}".PHP_EOL);
+        fputcsv($fpError,$srcData);
+		continue;
+	}
+    if(empty($srcData["book"]) ){
+        $srcData["book"] = 0;
+		fwrite(STDERR,time().",error, book is empty {$srcData["id"]}".PHP_EOL);
+        fputcsv($fpError,array('book is empty',$srcData["id"]));
+	}
+    if(empty($srcData["paragraph"]) ){
+        $srcData["paragraph"] = 0;
+		fwrite(STDERR,time().",error, paragraph is empty {$srcData["id"]}".PHP_EOL);
+        fputcsv($fpError,array('paragraph is empty',$srcData["id"]));
+	}
+    if(empty($srcData["modify_time"])){
+        $srcData["modify_time"] = $srcData["create_time"];
+    }
+
+    if($srcData["create_time"] < 15987088320){
+        $srcData["create_time"] *= 1000;
+    }
+    if($srcData["modify_time"] < 15987088320){
+        $srcData["modify_time"] *= 1000;
+    }
+	//查询是否已经插入
+	$queryExsit = "SELECT id  FROM ".$dest_table." WHERE uid = ? ";
+	$getExist = $PDO_DEST->prepare($queryExsit);
+	$getExist->execute(array($srcData["id"]));
+	$exist = $getExist->fetch(PDO::FETCH_ASSOC);
+	if($exist){
+		continue;
+	}
+	#插入目标表
+	$created_at = date("Y-m-d H:i:s.",$srcData["create_time"]/1000).($srcData["create_time"]%1000)." UTC";
+	$updated_at = date("Y-m-d H:i:s.",$srcData["modify_time"]/1000).($srcData["modify_time"]%1000)." UTC";
+	$commitData = array(
+            $snowflake->id(),
+			$srcData["id"],
+			$srcData["parent_id"],
+			$srcData["user_id"],
+			$srcData["book"],
+			$srcData["paragraph"],
+			$srcData["channal"],
+			$srcData["file_name"],
+			$srcData["title"],
+			$srcData["tag"],
+			$srcData["status"],
+			$srcData["file_size"],
+			$srcData["share"],
+			$srcData["doc_info"],
+			$srcData["doc_block"],
+			$srcData["create_time"],
+			$srcData["modify_time"],
+			$srcData["accese_time"],
+			$created_at,
+			$updated_at,
+            $updated_at
+		);
+	$stmtDEST->execute($commitData);
+
+	$count++;	
+	$allInsertCount++;
+
+
+	if($count ==10000){
+		#10000行输出log 一次
+		echo "finished $count".PHP_EOL;
+		$count=0;
+	}	
+}
+
+fwrite(STDOUT,"insert done $allInsertCount in $allSrcCount ".PHP_EOL) ;
+fwrite(STDOUT, "all done in ".(time()-$start)."s".PHP_EOL);
+
+fclose($fpError);
+
+
+
+

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно