project.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link type="text/css" rel="stylesheet" href="css/style.css"/>
  7. <link type="text/css" rel="stylesheet" href="css/color_day.css" id="colorchange" />
  8. <link type="text/css" rel="stylesheet" href="css/style_mobile.css" media="screen and (max-width:767px)">
  9. </head>
  10. <body>
  11. <?php
  12. //工程文件操作
  13. //建立,
  14. require_once '../path.php';
  15. require_once "../public/_pdo.php";
  16. require_once "../public/function.php";
  17. require_once "../public/load_lang.php";
  18. require_once "./book_list_en.inc";
  19. require_once "../ucenter/function.php";
  20. require_once "../ucenter/setting_function.php";
  21. require_once "../lang/function.php";
  22. $user_setting = get_setting();
  23. $sLang["1"]="pali";
  24. $sLang["2"]="en";
  25. $sLang["3"]="sc";
  26. $sLang["4"]="tc";
  27. if(isset($_POST["op"])){
  28. $op=$_POST["op"];
  29. }
  30. if(isset($_GET["op"])){
  31. $op=$_GET["op"];
  32. }
  33. if(isset($_POST["data"])){
  34. $data=$_POST["data"];
  35. }
  36. else if(isset($_GET["data"])){
  37. $data=$_GET["data"];
  38. }
  39. if($_COOKIE["uid"]){
  40. $uid = $_COOKIE["uid"];
  41. $USER_ID = $_COOKIE["userid"];
  42. $USER_NAME = $_COOKIE["username"];
  43. }
  44. else{
  45. echo '<a href="../ucenter/index.php" target="_blank">'.$_local->gui->not_login.'</a>';
  46. exit;
  47. }
  48. switch($op){
  49. case "create":
  50. //判断单词数量 太大的不能加载
  51. $res=json_decode($data);
  52. $res_book = $res[0]->book;
  53. $paraList=$res[0]->parlist;
  54. $paraList=rtrim($paraList,",");
  55. $strQueryParaList=str_replace(",","','",$paraList);
  56. $strQueryParaList="('".$strQueryParaList."')";
  57. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  58. $query="SELECT sum(lenght) as sum_str FROM pali_text WHERE \"book\" = ".$PDO->quote($res_book)." AND (\"paragraph\" in {$strQueryParaList} ) ";
  59. $Fetch = PDO_FetchAll($query);
  60. if(count($Fetch)>0){
  61. if($Fetch[0]["sum_str"]>15000){
  62. echo $_local->gui->oversize_to_load;
  63. exit;
  64. }
  65. }
  66. //判断单词数量 结束
  67. if(isset($_POST["format"]) && $_POST["format"]=="db"){
  68. $res=json_decode($data);
  69. $title=$res[0]->title;
  70. $title_en=pali2english($title);
  71. $book=$res[0]->book;
  72. if(substr($book,0,1)=="p"){
  73. $book=substr($book,1);
  74. }
  75. $paragraph=$res[0]->parNum;
  76. $tag="[$title]";
  77. $paraList=$res[0]->parlist;
  78. $paraList=rtrim($paraList,",");
  79. $strQueryParaList=str_replace(",","','",$paraList);
  80. $strQueryParaList="('".$strQueryParaList."')";
  81. $aParaList=str_getcsv($paraList);
  82. $create_para=$aParaList[0];
  83. echo $strQueryParaList;
  84. echo "<textarea>";
  85. print_r($res);
  86. echo "</textarea>";
  87. $user_title=$_POST["title"];
  88. $doc_head =" <head>\n";
  89. $doc_head.=" <type>pcdsset</type>\n";
  90. $doc_head.=" <mode>package</mode>\n";
  91. $doc_head.=" <ver>1</ver>\n";
  92. $doc_head.=" <toc></toc>\n";
  93. $doc_head.=" <style></style>\n";
  94. $doc_head.=" <doc_title>$user_title</doc_title>\n";
  95. $doc_head.=" <tag>$tag</tag>\n";
  96. $doc_head.=" <lang>{$_POST["lang"]}</lang>\n";
  97. $doc_head.=" <book>$book</book>\n";
  98. $doc_head.=" <paragraph>$paragraph</paragraph>\n";
  99. $doc_head.=" </head>\n";
  100. for($iRes=0;$iRes<count($res);$iRes++){
  101. $get_res_type=$res[$iRes]->type;
  102. echo "iRes: $iRes,type:$get_res_type<br/>";
  103. $res_album_id=$res[$iRes]->album_id;
  104. $res_book=$res[$iRes]->book;
  105. $get_par_begin=$res[$iRes]->parNum;
  106. $language=$res[$iRes]->language;
  107. $author=$res[$iRes]->author;
  108. $db_file = _FILE_DB_RESRES_INDEX_;
  109. PDO_Connect("sqlite:$db_file");
  110. $query = "select guid,owner from 'album' where id='{$res_album_id}'";
  111. $Fetch = PDO_FetchAll($query);
  112. if(count($Fetch)>0){
  113. $res_album_guid=$Fetch[0]["guid"];
  114. $res_album_owner=$Fetch[0]["owner"];
  115. }
  116. else{
  117. $res_album_guid=UUID::v4();
  118. $res_album_owner=0;
  119. }
  120. switch($get_res_type){
  121. case "6"://逐词译模板
  122. {
  123. $album_guid = UUID::v4();
  124. $album_title = "title";
  125. $album_author = "VRI";
  126. $album_type=$get_res_type;
  127. //获取段落层级和标题
  128. $para_title=array();
  129. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  130. $query="SELECT * FROM pali_text WHERE \"book\" = ".$PDO->quote($res_book)." AND (\"paragraph\" in {$strQueryParaList} ) AND level>0 AND level<9";
  131. $sth = $PDO->prepare($query);
  132. $sth->execute();
  133. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  134. {
  135. $paragraph = $result["paragraph"];
  136. $para_title["{$paragraph}"][0]=$result["level"];
  137. $para_title["{$paragraph}"][1]=$result["text"];
  138. }
  139. $db_file = _DIR_PALICANON_TEMPLET_."/p".$res_book."_tpl.db3";
  140. PDO_Connect("sqlite:$db_file");
  141. foreach($aParaList as $iPar){
  142. $query="SELECT * FROM 'main' WHERE (\"paragraph\" = ".$PDO->quote($iPar)." ) ";
  143. $sth = $PDO->prepare($query);
  144. $sth->execute();
  145. {
  146. if(isset($para_title["{$iPar}"])){
  147. $level=$para_title["{$iPar}"][0];
  148. $title=$para_title["{$iPar}"][1];
  149. }
  150. else{
  151. $level=100;
  152. $title="";
  153. }
  154. $block_id=UUID::v4();
  155. $trans_block_id = UUID::v4();
  156. $block_data[] = array($block_id,"",$_POST["channal"],$USER_ID,$book,$iPar,"_none_",$_POST["lang"],1);
  157. $block_list[] = array("channal"=>$_POST["channal"],
  158. "type"=>6,//word by word
  159. "book"=>$res_book,
  160. "paragraph"=>$iPar,
  161. "block_id"=>$block_id,
  162. "readonly"=>false
  163. );
  164. /*
  165. $block_list[] = array("channal"=>$_POST["channal"],
  166. "type"=>2,//translation
  167. "book"=>$res_book,
  168. "paragraph"=>$iPar,
  169. "readonly"=>false
  170. );*/
  171. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  172. {
  173. if($result["gramma"]=="?"){
  174. $wGrammar="";
  175. }
  176. else{
  177. $wGrammar=$result["gramma"];
  178. }
  179. $strXml="<word>";
  180. $strXml.="<pali>{$result["word"]}</pali>";
  181. $strXml.="<real>{$result["real"]}</real>";
  182. $wordid = "p{$result["book"]}-{$result["paragraph"]}-{$result["wid"]}";
  183. $strXml.="<id>{$wordid}</id>";
  184. $strXml.="<type s=\"0\">{$result["type"]}</type>";
  185. $strXml.="<gramma s=\"0\">{$wGrammar}</gramma>";
  186. $strXml.="<mean s=\"0\"></mean>";
  187. $strXml.="<org s=\"0\">".mb_strtolower($result["part"], 'UTF-8')."</org>";
  188. $strXml.="<om s=\"0\"></om>";
  189. $strXml.="<case s=\"0\">{$result["type"]}#{$wGrammar}</case>";
  190. $strXml.="<style>{$result["style"]}</style>";
  191. $strXml.="<status>0</status>";
  192. $strXml.="</word>";
  193. $wbw_data[] = array(UUID::v4(),$block_id,$book,$iPar,$result["wid"],$result["real"],$strXml,mTime(),mTime(),1,$USER_NAME);
  194. }
  195. }
  196. }
  197. //写入数据库
  198. // 开始一个事务,关闭自动提交
  199. PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
  200. $PDO->beginTransaction();
  201. $query="INSERT INTO wbw_block ('id','parent_id','channal','owner','book','paragraph','style','lang','status','modify_time','receive_time') VALUES (?,?,?,?,?,?,?,?,?,?,?)";
  202. $stmt = $PDO->prepare($query);
  203. foreach($block_data as $oneParam){
  204. $stmt->execute($oneParam);
  205. }
  206. // 提交更改
  207. $PDO->commit();
  208. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  209. $error = PDO_ErrorInfo();
  210. echo "error - $error[2] <br>";
  211. }
  212. else{
  213. $count=count($block_data);
  214. echo "updata $count recorders.";
  215. }
  216. // 开始一个事务,关闭自动提交
  217. $PDO->beginTransaction();
  218. $query="INSERT INTO wbw ('id','block_id','book','paragraph','wid','word','data','modify_time','receive_time','status','owner') VALUES (?,?,?,?,?,?,?,?,?,?,?)";
  219. $stmt = $PDO->prepare($query);
  220. foreach($wbw_data as $oneParam){
  221. $stmt->execute($oneParam);
  222. }
  223. // 提交更改
  224. $PDO->commit();
  225. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  226. $error = PDO_ErrorInfo();
  227. echo "error - $error[2] <br>";
  228. }
  229. else{
  230. $count=count($block_data);
  231. echo "updata $count recorders.";
  232. }
  233. //服务器端文件列表
  234. $db_file = _FILE_DB_FILEINDEX_;
  235. PDO_Connect("sqlite:$db_file");
  236. $query="INSERT INTO fileindex ('id',
  237. 'parent_id',
  238. 'channal',
  239. 'user_id',
  240. 'book',
  241. 'paragraph',
  242. 'file_name',
  243. 'title',
  244. 'tag',
  245. 'status',
  246. 'create_time',
  247. 'modify_time',
  248. 'accese_time',
  249. 'file_size',
  250. 'share',
  251. 'doc_info',
  252. 'doc_block',
  253. 'receive_time'
  254. )
  255. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  256. $stmt = $PDO->prepare($query);
  257. $doc_id=UUID::v4();
  258. $file_name = $book . '_' . $create_para . '_' . time();
  259. $newData=array(
  260. $doc_id,
  261. "",
  262. $_POST["channal"],
  263. $uid,
  264. $book,
  265. $create_para,
  266. $file_name,
  267. $user_title,
  268. $tag,
  269. 1,
  270. mTime(),
  271. mTime(),
  272. mTime(),
  273. $filesize,
  274. 0,
  275. $doc_head,
  276. json_encode($block_list, JSON_UNESCAPED_UNICODE),
  277. mTime()
  278. );
  279. $stmt->execute($newData);
  280. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  281. $error = PDO_ErrorInfo();
  282. echo "error - $error[2] <br>";
  283. }
  284. else{
  285. echo "成功新建一个文件.";
  286. }
  287. echo "<a href=\"editor.php?op=opendb&doc_id={$doc_id}\">{$_local->gui->open}</a>";
  288. }
  289. break;
  290. }
  291. }
  292. }
  293. else
  294. {
  295. if(!isset($data)){
  296. $dl_file_name=$dir_user_base.$USER_ID."/dl.json";
  297. $data=file_get_contents($dl_file_name);
  298. }
  299. $res=json_decode($data);
  300. $title=$res[0]->title;
  301. $title_en=pali2english($title);
  302. $book=$res[0]->book;
  303. if(substr($book,0,1)=="p"){
  304. $book=substr($book,1);
  305. }
  306. $paragraph=$res[0]->parNum;
  307. $tag="[$title]";
  308. $paraList=$res[0]->parlist;
  309. $paraList=rtrim($paraList,",");
  310. $strQueryParaList=str_replace(",","','",$paraList);
  311. $strQueryParaList="('".$strQueryParaList."')";
  312. $aParaList=str_getcsv($paraList);
  313. echo "<div style='display:none;'>";
  314. echo $strQueryParaList;
  315. echo "<textarea>";
  316. print_r($res);
  317. echo "</textarea>";
  318. echo "</div>";
  319. if(!isset($_POST["title"])){
  320. $thisFileName=basename(__FILE__);
  321. echo "<div class='fun_block'>";
  322. echo "<h2>New Document 新建文档</h2>";
  323. echo "<form action=\"{$thisFileName}\" method=\"post\">";
  324. echo "<input type='hidden' name='op' value='{$op}'/>";
  325. echo "<input type='hidden' name='data' value='{$data}'/>";
  326. echo "<fieldset>";
  327. echo "<legend>Title 文档标题(必填)</legend>";
  328. echo "<div>";
  329. echo "<input type='input' name='title' value='{$title}'/>";
  330. echo "</div>";
  331. echo "</fieldset>";
  332. echo "<fieldset>";
  333. echo "<legend>Channal 频道(必填)</legend>";
  334. echo "<div>";
  335. PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
  336. $query = "select * from channal where owner = '{$_COOKIE["userid"]}' limit 0,100";
  337. $Fetch = PDO_FetchAll($query);
  338. $i=0;
  339. foreach($Fetch as $row){
  340. echo '<div class="file_list_row" style="padding:5px;">';
  341. echo '<div class="pd-10" style="max-width:2em;flex:1;">';
  342. echo '<input name="channal" value="'.$row["id"].'" ';
  343. if($i==0){
  344. echo "checked";
  345. }
  346. echo ' type="radio" />';
  347. echo '</div>';
  348. echo '<div class="title" style="flex:3;padding-bottom:5px;">'.$row["name"].'</div>';
  349. echo '<div class="title" style="flex:2;padding-bottom:5px;">';
  350. PDO_Connect("sqlite:"._FILE_DB_USER_WBW_);
  351. $query = "select count(*) from wbw_block where channal = '{$row["id"]}' and book='{$book}' and paragraph in {$strQueryParaList} limit 0,100";
  352. $FetchWBW = PDO_FetchOne($query);
  353. echo '</div>';
  354. echo '<div class="title" style="flex:2;padding-bottom:5px;">';
  355. if($FetchWBW==0){
  356. echo "空白";
  357. }
  358. else{
  359. echo $FetchWBW."个段落";
  360. }
  361. echo '</div>';
  362. echo '<div class="title" style="flex:2;padding-bottom:5px;">';
  363. PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
  364. $query = "select count(*) from sentence where channal = '{$row["id"]}' and book='{$book}' and paragraph in {$strQueryParaList} limit 0,100";
  365. $FetchWBW = PDO_FetchOne($query);
  366. echo '</div>';
  367. echo '<div class="title" style="flex:2;padding-bottom:5px;">';
  368. if($FetchWBW==0){
  369. echo "空白";
  370. }
  371. else{
  372. echo $FetchWBW."个段落";
  373. }
  374. echo '</div>';
  375. echo '<div class="summary" style="flex:1;padding-bottom:5px;">'.$row["status"].'</div>';
  376. echo '<div class="author" style="flex:1;padding-bottom:5px;">'.$row["create_time"].'</div>';
  377. echo '</div>';
  378. $i++;
  379. }
  380. echo '<div class="file_list_row" style="padding:5px;">';
  381. echo '<div class="pd-10" style="max-width:2em;flex:1;">New Channal 新建频道</div>';
  382. echo '<div class="title" style="flex:3;padding-bottom:5px;">';
  383. echo '<input type="input" placeholder="Channal Title"></div>';
  384. echo '<div class="author" style="flex:1;padding-bottom:5px;"><button>New 新建</button></div>';
  385. echo '</div>';
  386. echo "</div>";
  387. echo "</fieldset>";
  388. echo "<fieldset>";
  389. echo "<legend>Language 语言</legend>";
  390. echo "<select name='lang'>";
  391. $lang_list = new lang_enum;
  392. foreach ($user_setting['studio.translation.lang'] as $key => $value) {
  393. echo "<option value='{$value}'>".$lang_list->getName($value)["name"]."</option>";
  394. }
  395. echo "</select>";
  396. echo "</fieldset>";
  397. echo "<input type=\"submit\" value='Create 建立'>";
  398. echo "<input type='hidden' name='format' value='db'>";
  399. echo "</form>";
  400. echo "</div>";
  401. echo "</body>";
  402. exit;
  403. }
  404. $user_title=$_POST["title"];
  405. $create_para=$paragraph;
  406. $FileName = $book."_".$paragraph."_".time().".pcs";
  407. $sFullFileName=_DIR_USER_BASE_."/".$USER_ID._DIR_MYDOCUMENT_."/".$FileName;
  408. echo "filename:".$sFullFileName;
  409. $myfile = fopen($sFullFileName, "w") or die("Unable to open file!");
  410. $strXml="<set>\n";
  411. $doc_head =" <head>\n";
  412. $doc_head.=" <type>pcdsset</type>\n";
  413. $doc_head.=" <mode>package</mode>\n";
  414. $doc_head.=" <ver>1</ver>\n";
  415. $doc_head.=" <toc></toc>\n";
  416. $doc_head.=" <style></style>\n";
  417. $doc_head.=" <doc_title>$user_title</doc_title>\n";
  418. $doc_head.=" <tag>$tag</tag>\n";
  419. $doc_head.=" <book>$book</book>\n";
  420. $doc_head.=" <paragraph>$paragraph</paragraph>\n";
  421. $doc_head.=" </head>\n";
  422. $strXml.=$doc_head;
  423. $strXml.=" <dict></dict>\n";
  424. $strXml.=" <message></message>\n";
  425. $strXml.=" <body>\n";
  426. fwrite($myfile, $strXml);
  427. echo "count res:".count($res)."<br>";
  428. for($iRes=0;$iRes<count($res);$iRes++){
  429. $get_res_type=$res[$iRes]->type;
  430. echo "iRes: $iRes,type:$get_res_type<br/>";
  431. $res_album_id=$res[$iRes]->album_id;
  432. $res_book=$res[$iRes]->book;
  433. $get_par_begin=$res[$iRes]->parNum;
  434. $language=$res[$iRes]->language;
  435. $author=$res[$iRes]->author;
  436. $db_file = _FILE_DB_RESRES_INDEX_;
  437. PDO_Connect("sqlite:$db_file");
  438. $query = "select guid,owner from 'album' where id='{$res_album_id}'";
  439. $Fetch = PDO_FetchAll($query);
  440. if(count($Fetch)>0){
  441. $res_album_guid=$Fetch[0]["guid"];
  442. $res_album_owner=$Fetch[0]["owner"];
  443. }
  444. else{
  445. $res_album_guid=UUID::v4();
  446. $res_album_owner=0;
  447. }
  448. switch($get_res_type){
  449. case "1"://pali text
  450. {
  451. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  452. $query="SELECT * FROM pali_text WHERE \"book\" = ".$PDO->quote($res_book)." AND (\"paragraph\" in {$strQueryParaList} ) ";
  453. $sth = $PDO->prepare($query);
  454. $sth->execute();
  455. echo $query."<br/>";
  456. {
  457. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  458. {
  459. $text = $result["text"];
  460. $paragraph = $result["paragraph"];
  461. $strXml = "<block>";
  462. $strXml .= "<info>";
  463. $strXml .= "<type>palitext</type>";
  464. $strXml .= "<book>{$book}</book>";
  465. $strXml .= "<paragraph>{$result["paragraph"]}</paragraph>";
  466. $strXml .= "<album_id>{$result["album_index"]}</album_id>";
  467. $strXml .= "<album_guid>{$res_album_guid}</album_guid>";
  468. $strXml .= "<author>VRI</author>";
  469. $strXml .= "<language>pali</language>";
  470. $strXml .= "<version>4</version>";
  471. $strXml .= "<edition>CSCD4</edition>";
  472. $strXml .= "<level>{$result["level"]}</level>";
  473. $strXml .= "<id>".UUID::v4()."</id>";
  474. $strXml .= "</info>";
  475. $strXml .= "<data><text>{$result["text"]}</text></data>";
  476. $strXml .= "</block>";
  477. fwrite($myfile, $strXml);
  478. if($result["level"]>0 && $result["level"]<9){
  479. $strXml = "<block>";
  480. $strXml .= "<info>";
  481. $strXml .= "<type>heading</type>";
  482. $strXml .= "<book>{$book}</book>";
  483. $strXml .= "<paragraph>{$result["paragraph"]}</paragraph>";
  484. $strXml .= "<album_id>{$result["album_index"]}</album_id>";
  485. $strXml .= "<album_guid>{$res_album_guid}</album_guid>";
  486. $strXml .= "<author>VRI</author>";
  487. $strXml .= "<language>pali</language>";
  488. $strXml .= "<version>4</version>";
  489. $strXml .= "<edition>CSCD4</edition>";
  490. $strXml .= "<level>{$result["level"]}</level>";
  491. $strXml .= "<id>".UUID::v4()."</id>";
  492. $strXml .= "</info>";
  493. $strXml .= "<data><text>{$result["text"]}</text></data>";
  494. $strXml .= "</block>";
  495. fwrite($myfile, $strXml);
  496. }
  497. else{
  498. }
  499. }
  500. }
  501. break;
  502. }
  503. case "2"://wbw逐词解析
  504. {
  505. //$res_album_id;
  506. $album_title = "title";
  507. $album_author = $author;
  508. $album_type=$get_res_type;
  509. $db_file = _DIR_PALICANON_WBW_."/p{$res_book}_wbw.db3";
  510. $table_info="p{$res_book}_wbw_info";
  511. $table_data="p{$res_book}_wbw_data";
  512. PDO_Connect("sqlite:$db_file");
  513. foreach($aParaList as $iPar){
  514. $query="SELECT * FROM '{$table_info}' WHERE paragraph = ".$PDO->quote($iPar)." and album_id=".$PDO->quote($res_album_id);
  515. //$FetchInfo = PDO_FetchAll($query);
  516. echo $query."<br>";
  517. $sth = $PDO->prepare($query);
  518. $sth->execute();
  519. echo "para:{$iPar} row:".$sth->rowCount();
  520. if($result = $sth->fetch(PDO::FETCH_ASSOC))
  521. {
  522. $lang=$sLang["{$result["language"]}"];
  523. $info_id=$result["id"];
  524. $strXml = "<block>";
  525. $strXml .= "<info>";
  526. $strXml .= "<type>wbw</type>";
  527. $strXml .= "<book>{$res_book}</book>";
  528. $strXml .= "<paragraph>{$iPar}</paragraph>";
  529. $strXml .= "<level>{$result["level"]}</level>";
  530. $strXml .= "<title>{$result["title"]}</title>";
  531. $strXml .= "<album_id>{$res_album_id}</album_id>";
  532. $strXml .= "<album_guid>{$res_album_guid}</album_guid>";
  533. $strXml .= "<author>{$result["author"]}</author>";
  534. $strXml .= "<language>{$lang}</language>";
  535. $strXml .= "<version>{$result["version"]}</version>";
  536. $strXml .= "<edition>{$result["edition"]}</edition>";
  537. $strXml .= "<id>".UUID::v4()."</id>";
  538. $strXml .= "</info>\n";
  539. $strXml .= "<data>";
  540. fwrite($myfile, $strXml);
  541. $query="SELECT * FROM \"{$table_data}\" WHERE info_id=".$PDO->quote($info_id);
  542. $sth = $PDO->prepare($query);
  543. $sth->execute();
  544. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  545. {
  546. $wid="p{$res_book}-{$iPar}-{$result["sn"]}";
  547. $strXml="<word>";
  548. $strXml.="<pali>{$result["word"]}</pali>";
  549. $strXml.="<real>{$result["real"]}</real>";
  550. $strXml.="<id>{$wid}</id>";
  551. $strXml.="<type>{$result["type"]}</type>";
  552. $strXml.="<gramma>{$result["gramma"]}</gramma>";
  553. $strXml.="<mean>{$result["mean"]}</mean>";
  554. $strXml.="<note>{$result["note"]}</note>";
  555. $strXml.="<org>{$result["part"]}</org>";
  556. $strXml.="<om>{$result["partmean"]}</om>";
  557. $strXml.="<case>{$result["type"]}#{$result["gramma"]}</case>";
  558. $strXml.="<style>{$result["style"]}</style>";
  559. $strXml.="<enter>{$result["enter"]}</enter>";
  560. $strXml.="<status>0</status>";
  561. $strXml.="</word>\n";
  562. fwrite($myfile, $strXml);
  563. }
  564. $strXml="</data>\n</block>";
  565. fwrite($myfile, $strXml);
  566. }
  567. }
  568. break;
  569. }
  570. case "3"://translate
  571. {
  572. //打开翻译数据文件
  573. $db_file = _DIR_PALICANON_TRAN_."/p{$book}_translate.db3";
  574. PDO_Connect("sqlite:$db_file");
  575. $table="p{$book}_translate_info";
  576. //部分段落
  577. $query="SELECT * FROM {$table} WHERE paragraph in {$strQueryParaList} and album_id=$res_album_id";
  578. echo $query."<br/>";
  579. //查询翻译经文内容
  580. $FetchText = PDO_FetchAll($query);
  581. $iFetchText = count($FetchText);
  582. echo "iFetchText:{$iFetchText}<br/>";
  583. if($iFetchText>0){
  584. for($i=0;$i<$iFetchText;$i++){
  585. $currParNo = $FetchText[$i]["paragraph"];
  586. $language = $FetchText[$i]["language"];
  587. $language = $sLang["{$language}"];
  588. if($res_album_owner == $UID){
  589. $power = "write";
  590. }
  591. else{
  592. $power = "read";
  593. }
  594. //输出数据头
  595. $strXml="<block>";
  596. $strXml.="<info>";
  597. $strXml.="<type>translate</type>";
  598. $strXml.="<book>{$res_book}</book>";
  599. $strXml.="<paragraph>{$currParNo}</paragraph>";
  600. $strXml.="<album_id>{$res_album_id}</album_id>";
  601. $strXml.="<album_guid>{$res_album_guid}</album_guid>";
  602. $strXml.="<author>{$FetchText[$i]["author"]}</author>";
  603. $strXml.="<editor>{$FetchText[$i]["editor"]}</editor>";
  604. $strXml.="<language>{$language}</language>";
  605. $strXml.="<version>{$FetchText[$i]["version"]}</version>";
  606. $strXml.="<edition>{$FetchText[$i]["edition"]}</edition>";
  607. $strXml.="<level>{$FetchText[$i]["level"]}</level>";
  608. $strXml.="<readonly>0</readonly>";
  609. $strXml.="<power>{$power}</power>";
  610. $strXml.="<id>".UUID::v4()."</id>";
  611. $strXml.="</info>";
  612. $strXml.="<data>";
  613. fwrite($myfile, $strXml);
  614. //查另一个表,获取段落文本。一句一条记录。有些是一段一条记录
  615. $table_data = "p{$book}_translate_data";
  616. $query = "SELECT * FROM '{$table_data}' WHERE info_id={$FetchText[$i]["id"]}";
  617. $aParaText = PDO_FetchAll($query);
  618. //输出数据内容
  619. $par_text="";
  620. foreach($aParaText as $sent){
  621. $par_text .= "<sen><begin>{$sent["begin"]}</begin><end>{$sent["end"]}</end><text>{$sent["text"]}</text></sen>";
  622. }
  623. fwrite($myfile, $par_text);
  624. //段落块结束
  625. $strXml = "</data></block>";
  626. fwrite($myfile, $strXml);
  627. //获取段落文本结束。
  628. }
  629. }
  630. break;
  631. }
  632. case "4"://note
  633. break;
  634. case "5":
  635. break;
  636. case "6"://逐词译模板
  637. {
  638. $album_guid = UUID::v4();
  639. $album_title = "title";
  640. $album_author = "VRI";
  641. $album_type=$get_res_type;
  642. //获取段落层级和标题
  643. $para_title=array();
  644. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  645. $query="SELECT * FROM pali_text WHERE \"book\" = ".$PDO->quote($res_book)." AND (\"paragraph\" in {$strQueryParaList} ) AND level>0 AND level<9";
  646. $sth = $PDO->prepare($query);
  647. $sth->execute();
  648. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  649. {
  650. $paragraph = $result["paragraph"];
  651. $para_title["{$paragraph}"][0]=$result["level"];
  652. $para_title["{$paragraph}"][1]=$result["text"];
  653. }
  654. $db_file = _DIR_PALICANON_TEMPLET_."/p".$res_book."_tpl.db3";
  655. PDO_Connect("sqlite:$db_file");
  656. foreach($aParaList as $iPar){
  657. $query="SELECT * FROM 'main' WHERE (\"paragraph\" = ".$PDO->quote($iPar)." ) ";
  658. $sth = $PDO->prepare($query);
  659. $sth->execute();
  660. {
  661. if(isset($para_title["{$iPar}"])){
  662. $level=$para_title["{$iPar}"][0];
  663. $title=$para_title["{$iPar}"][1];
  664. }
  665. else{
  666. $level=100;
  667. $title="";
  668. }
  669. $strXml="<block>";
  670. $strXml.="<info>";
  671. $strXml.="<type>wbw</type>";
  672. $strXml.="<book>{$book}</book>";
  673. $strXml.="<paragraph>{$iPar}</paragraph>";
  674. $strXml.="<level>{$level}</level>";
  675. $strXml.="<title>{$title}</title>";
  676. $strXml.="<album_id>-1</album_id>";
  677. $strXml.="<album_guid>{$album_guid}</album_guid>";
  678. $strXml.="<author>{$USER_NAME}</author>";
  679. $strXml.="<editor>{$USER_NAME}</editor>";
  680. $strXml.="<language>en</language>";
  681. $strXml.="<version>1</version>";
  682. $strXml.="<edition></edition>";
  683. $strXml.="<splited>0</splited>";
  684. $strXml.="<id>".UUID::v4()."</id>";
  685. $strXml.="</info>\n";
  686. $strXml.="<data>";
  687. fwrite($myfile, $strXml);
  688. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  689. {
  690. if($result["gramma"]=="?"){
  691. $wGrammar="";
  692. }
  693. else{
  694. $wGrammar=$result["gramma"];
  695. }
  696. $strXml="<word>";
  697. $strXml.="<pali>{$result["word"]}</pali>";
  698. $strXml.="<real>{$result["real"]}</real>";
  699. $strXml.="<id>{$result["wid"]}</id>";
  700. $strXml.="<type status=\"0\">{$result["type"]}</type>";
  701. $strXml.="<gramma status=\"0\">{$wGrammar}</gramma>";
  702. $strXml.="<mean status=\"0\">?</mean>";
  703. $strXml.="<org status=\"0\">".mb_strtolower($result["part"], 'UTF-8')."</org>";
  704. $strXml.="<om status=\"0\">?</om>";
  705. $strXml.="<case status=\"0\">{$result["type"]}#{$wGrammar}</case>";
  706. $strXml.="<style>{$result["style"]}</style>";
  707. $strXml.="<status>0</status>";
  708. $strXml.="</word>";
  709. fwrite($myfile, $strXml);
  710. }
  711. $strXml="</data>\n</block>";
  712. fwrite($myfile, $strXml);
  713. }
  714. }
  715. break;
  716. }
  717. }
  718. /*查询结束*/
  719. }
  720. /*
  721. 自动新建译文
  722. */
  723. if(isset($_POST["new_tran"])){
  724. $new_tran=$_POST["new_tran"];
  725. if($new_tran=="on"){
  726. $album_guid = UUID::v4();
  727. foreach($aParaList as $iPar){
  728. $strXml="<block>";
  729. $strXml.="<info>";
  730. $strXml.="<album_id>-1</album_id>";
  731. $strXml.="<album_guid>{$album_guid}</album_guid>";
  732. $strXml.="<type>translate</type>";
  733. $strXml.="<paragraph>{$iPar}</paragraph>";
  734. $strXml.="<book>{$book}</book>";
  735. $strXml.="<author>{$author}</author>";
  736. $strXml.="<language>en</language>";
  737. $strXml.="<version>0</version>";
  738. $strXml.="<edition>0</edition>";
  739. $strXml.="<id>".UUID()::v4."</id>";
  740. $strXml.="</info>";
  741. $strXml.="<data>";
  742. $strXml.="<sen><begin></begin><end></end><text>new translate</text></sen>";
  743. $strXml.="</data>";
  744. $strXml.="</block>\n";
  745. fwrite($myfile, $strXml);
  746. }
  747. }
  748. }
  749. $strXml=" </body>\n";
  750. $strXml.="</set>\n";
  751. fwrite($myfile, $strXml);
  752. fclose($myfile);
  753. echo "<p>save ok</p>";
  754. $filesize=filesize($sFullFileName);
  755. //服务器端文件列表
  756. $db_file = _FILE_DB_FILEINDEX_;
  757. PDO_Connect("sqlite:$db_file");
  758. $query="INSERT INTO fileindex ('id',
  759. 'parent_id',
  760. 'user_id',
  761. 'book',
  762. 'paragraph',
  763. 'file_name',
  764. 'title',
  765. 'tag',
  766. 'status',
  767. 'create_time',
  768. 'modify_time',
  769. 'accese_time',
  770. 'file_size',
  771. 'share',
  772. 'doc_info',
  773. 'doc_block',
  774. 'receive_time'
  775. )
  776. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  777. $stmt = $PDO->prepare($query);
  778. $doc_id=UUID::v4();
  779. $newData=array($doc_id,
  780. "",
  781. $uid,
  782. $book,
  783. $create_para,
  784. $FileName,
  785. $user_title,
  786. $tag,
  787. 1,
  788. mTime(),
  789. mTime(),
  790. mTime(),
  791. $filesize,
  792. 0,
  793. "",
  794. "",
  795. mTime()
  796. );
  797. $stmt->execute($newData);
  798. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  799. $error = PDO_ErrorInfo();
  800. echo "error - $error[2] <br>";
  801. }
  802. else{
  803. echo "updata 1 recorders.";
  804. }
  805. echo "<a href=\"editor.php?op=open&fileid={$doc_id}\">正在跳转</a>";
  806. echo "<script>";
  807. echo "window.location.assign(\"editor.php?op=open&fileid={$doc_id}\");";
  808. echo "</script>";
  809. break;
  810. }
  811. case "open":
  812. {
  813. /*打开工程文件
  814. 三种情况
  815. 1.自己的文档
  816. 2.别人的共享文档,自己以前没有打开过。复制到自己的空间,再打开。
  817. 3.别人的共享文档,自己以前打开过。直接打开
  818. */
  819. if($_COOKIE["uid"]){
  820. $uid=$_COOKIE["uid"];
  821. }
  822. else{
  823. echo "<h3><a href='../ucenter/index.php?op=login'>{$_local->gui->login}</a>后才可以打开文档</h3>";
  824. exit;
  825. }
  826. $db_file = _FILE_DB_FILEINDEX_;
  827. PDO_Connect("sqlite:$db_file");
  828. if(isset($_GET["doc_id"])){
  829. $doc_id=$_GET["doc_id"];
  830. $query = "select * from fileindex where id='$doc_id' ";
  831. $Fetch = PDO_FetchAll($query);
  832. $iFetch=count($Fetch);
  833. if($iFetch>0){
  834. //文档信息
  835. $owner=$Fetch[0]["user_id"];
  836. $filename=$Fetch[0]["file_name"];
  837. $title=$Fetch[0]["title"];
  838. $tag=$Fetch[0]["tag"];
  839. $mbook=$Fetch[0]["book"];
  840. $paragraph=$Fetch[0]["paragraph"];
  841. $doc_head=$Fetch[0]["doc_info"];
  842. if($owner==$uid){
  843. //自己的文档
  844. echo "<h3>{$_local->gui->my_document}</h3>";
  845. $my_doc_id=$doc_id;
  846. echo "<a href=\"editor.php?op=opendb&fileid={$doc_id}\">{$_local->gui->open_doc}</a>";
  847. echo "<script>";
  848. echo "window.location.assign(\"editor.php?op=opendb&fileid={$doc_id}\");";
  849. echo "</script>";
  850. }
  851. else{
  852. //别人的文档
  853. //查询自己是否以前打开过
  854. $query = "select * from fileindex where parent_id='$doc_id' and user_id='$uid' ";
  855. $FetchSelf = PDO_FetchAll($query);
  856. $iFetchSelf=count($FetchSelf);
  857. if($iFetchSelf>0){
  858. //以前打开过
  859. echo "已经复制的文档 Already Copy";
  860. $my_doc_id=$FetchSelf[0]["id"];
  861. echo "<a href='../studio/editor.php?op=opendb&fileid={$doc_id}'>Open in Studio</a>";
  862. echo "<script>";
  863. echo "window.location.assign(\"editor.php?op=opendb&fileid={$doc_id}\");";
  864. echo "</script>";
  865. }
  866. else{
  867. //以前没打开过
  868. //询问是否打开
  869. if(isset($_GET["openin"])){
  870. $open_in=$_GET["openin"];
  871. }
  872. else{
  873. ?>
  874. <p><?php echo $_local->gui->co_doc?>,<?php echo $_local->gui->open?>?</p>
  875. <div>
  876. 文档信息:
  877. <ul>
  878. <?php
  879. $book_name=$book["p".$mbook];
  880. echo "<li>Owner:".ucenter_get($owner)."</li>";
  881. echo "<li>Title:{$title}</li>";
  882. echo "<li>Book:{$book_name}</li>";
  883. ?>
  884. </ul>
  885. </div>
  886. <p><?php echo $_local->gui->open_with?>:</p>
  887. <ul>
  888. <li style="display:none;"><a href="../pcdl/reader.php?file=<?php echo $doc_id;?>"><?php echo $_local->gui->reader;?>(<?php echo $_local->gui->read_only;?>)</a></li>
  889. <?php
  890. if(empty($doc_head)){
  891. echo '<li><a href="../studio/project.php?op=open&doc_id='.$doc_id.'&openin=editor">复制到我的空间用编辑器打开</a></li>';
  892. }
  893. else{
  894. echo '<li>'.$_local->gui->pcd_studio.'<a href="../doc/fork.php?doc_id='.$doc_id.'">'.$_local->gui->folk.$_local->gui->and.$_local->gui->edit.'</a></li>';
  895. }
  896. ?>
  897. </ul>
  898. <?php
  899. exit;
  900. }
  901. if($open_in=="editor"){
  902. //获取文件路径
  903. echo "共享的文档,复制并打开...";
  904. $db_file = _FILE_DB_USERINFO_;
  905. PDO_Connect("sqlite:$db_file");
  906. $query = "select userid from user where id='$owner'";
  907. $FetchUid = PDO_FetchOne($query);
  908. if($FetchUid){
  909. $source=_DIR_USER_BASE_."/".$FetchUid._DIR_MYDOCUMENT_."/".$filename;
  910. $dest=_DIR_USER_BASE_."/".$_COOKIE["userid"] ._DIR_MYDOCUMENT_."/".$filename;
  911. }
  912. echo "<div>源文件{$source}</div>";
  913. echo "<div>目标文件{$dest}</div>";
  914. if(copy($source,$dest)){
  915. echo "复制文件成功";
  916. $my_file_name=$filename;
  917. //插入记录到文件索引
  918. $filesize=filesize($dest);
  919. //服务器端文件列表
  920. $db_file = _FILE_DB_FILEINDEX_;
  921. PDO_Connect("sqlite:$db_file");
  922. //$query="INSERT INTO fileindex ('id','userid','parent_id','doc_id','book','paragraph','file_name','title','tag','create_time','modify_time','accese_time','file_size')
  923. // VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?)";
  924. //$stmt = $PDO->prepare($query);
  925. //$newData=array($uid,$doc_id,UUID::v4(),$mbook,$paragraph,$filename,$title,$tag,time(),time(),time(),$filesize);
  926. $query="INSERT INTO fileindex ('id',
  927. 'parent_id',
  928. 'user_id',
  929. 'book',
  930. 'paragraph',
  931. 'file_name',
  932. 'title',
  933. 'tag',
  934. 'status',
  935. 'create_time',
  936. 'modify_time',
  937. 'accese_time',
  938. 'file_size',
  939. 'share',
  940. 'doc_info',
  941. 'doc_block',
  942. 'receive_time'
  943. )
  944. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  945. $stmt = $PDO->prepare($query);
  946. $newdoc_id=UUID::v4();
  947. $newData=array(
  948. $newdoc_id,
  949. $doc_id,
  950. $uid,
  951. $mbook,
  952. $paragraph,
  953. $filename,
  954. $title,
  955. $tag,
  956. 1,
  957. mTime(),
  958. mTime(),
  959. mTime(),
  960. $filesize,
  961. 0,
  962. "",
  963. "",
  964. mTime()
  965. );
  966. $stmt->execute($newData);
  967. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  968. $error = PDO_ErrorInfo();
  969. echo "error - $error[2] <br>";
  970. $my_doc_id="";
  971. }
  972. else{
  973. $my_doc_id = newdoc_id;
  974. echo "updata 1 recorders.";
  975. }
  976. }
  977. else{
  978. echo "复制文件失败";
  979. $my_doc_id="";
  980. }
  981. }
  982. else{
  983. echo "错误-无法识别的操作:open in:{$open_in}";
  984. $my_doc_id="";
  985. }
  986. }
  987. }
  988. /*
  989. if($my_doc_id!=""){
  990. echo "<script>";
  991. echo "window.location.assign(\"editor.php?op=open&fileid={$my_doc_id}\");";
  992. echo "</script>";
  993. }
  994. */
  995. }
  996. else{
  997. echo "未知的文档。可能该文件已经被删除。";
  998. }
  999. }
  1000. }
  1001. break;
  1002. case "openfile":
  1003. break;
  1004. case "save":
  1005. break;
  1006. }
  1007. ?>
  1008. </body>