project.php 33 KB

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