project.php 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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>{$_local->gui->title} ({$_local->gui->required})</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>{$_local->gui->channel} ({$_local->gui->required})</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 $_local->gui->blank;
  357. }
  358. else{
  359. echo $FetchWBW.$_local->gui->para;
  360. echo "<a href='../studio/editor.php?op=openchannal&book=$book&para={$paraList}'>open</a>";
  361. }
  362. echo '</div>';
  363. echo '<div class="title" style="flex:2;padding-bottom:5px;">';
  364. PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
  365. $query = "select count(*) from sentence where channal = '{$row["id"]}' and book='{$book}' and paragraph in {$strQueryParaList} limit 0,100";
  366. $FetchWBW = PDO_FetchOne($query);
  367. echo '</div>';
  368. echo '<div class="title" style="flex:2;padding-bottom:5px;">';
  369. if($FetchWBW==0){
  370. echo $_local->gui->blank;
  371. }
  372. else{
  373. echo $FetchWBW.$_local->gui->para;
  374. }
  375. echo '</div>';
  376. echo '<div class="summary" style="flex:1;padding-bottom:5px;">'.$row["status"].'</div>';
  377. echo '<div class="author" style="flex:1;padding-bottom:5px;">'.$row["create_time"].'</div>';
  378. echo '</div>';
  379. $i++;
  380. }
  381. echo '<div class="file_list_row" style="padding:5px;">';
  382. echo '<div class="pd-10" style="max-width:2em;flex:1;">New Channal 新建频道</div>';
  383. echo '<div class="title" style="flex:3;padding-bottom:5px;">';
  384. echo '<input type="input" placeholder="Channal Title"></div>';
  385. echo '<div class="author" style="flex:1;padding-bottom:5px;"><button>New 新建</button></div>';
  386. echo '</div>';
  387. echo "</div>";
  388. echo "</fieldset>";
  389. echo "<fieldset>";
  390. echo "<legend>{$_local->gui->language}</legend>";
  391. echo "<select name='lang'>";
  392. $lang_list = new lang_enum;
  393. foreach ($user_setting['studio.translation.lang'] as $key => $value) {
  394. echo "<option value='{$value}'>".$lang_list->getName($value)["name"]."</option>";
  395. }
  396. echo "</select>";
  397. echo "</fieldset>";
  398. echo "<input type=\"submit\" value='Create 建立'>";
  399. echo "<input type='hidden' name='format' value='db'>";
  400. echo "</form>";
  401. echo "</div>";
  402. echo "</body>";
  403. exit;
  404. }
  405. $user_title=$_POST["title"];
  406. $create_para=$paragraph;
  407. $FileName = $book."_".$paragraph."_".time().".pcs";
  408. $sFullFileName=_DIR_USER_BASE_."/".$USER_ID._DIR_MYDOCUMENT_."/".$FileName;
  409. echo "filename:".$sFullFileName;
  410. $myfile = fopen($sFullFileName, "w") or die("Unable to open file!");
  411. $strXml="<set>\n";
  412. $doc_head =" <head>\n";
  413. $doc_head.=" <type>pcdsset</type>\n";
  414. $doc_head.=" <mode>package</mode>\n";
  415. $doc_head.=" <ver>1</ver>\n";
  416. $doc_head.=" <toc></toc>\n";
  417. $doc_head.=" <style></style>\n";
  418. $doc_head.=" <doc_title>$user_title</doc_title>\n";
  419. $doc_head.=" <tag>$tag</tag>\n";
  420. $doc_head.=" <book>$book</book>\n";
  421. $doc_head.=" <paragraph>$paragraph</paragraph>\n";
  422. $doc_head.=" </head>\n";
  423. $strXml.=$doc_head;
  424. $strXml.=" <dict></dict>\n";
  425. $strXml.=" <message></message>\n";
  426. $strXml.=" <body>\n";
  427. fwrite($myfile, $strXml);
  428. echo "count res:".count($res)."<br>";
  429. for($iRes=0;$iRes<count($res);$iRes++){
  430. $get_res_type=$res[$iRes]->type;
  431. echo "iRes: $iRes,type:$get_res_type<br/>";
  432. $res_album_id=$res[$iRes]->album_id;
  433. $res_book=$res[$iRes]->book;
  434. $get_par_begin=$res[$iRes]->parNum;
  435. $language=$res[$iRes]->language;
  436. $author=$res[$iRes]->author;
  437. $db_file = _FILE_DB_RESRES_INDEX_;
  438. PDO_Connect("sqlite:$db_file");
  439. $query = "select guid,owner from 'album' where id='{$res_album_id}'";
  440. $Fetch = PDO_FetchAll($query);
  441. if(count($Fetch)>0){
  442. $res_album_guid=$Fetch[0]["guid"];
  443. $res_album_owner=$Fetch[0]["owner"];
  444. }
  445. else{
  446. $res_album_guid=UUID::v4();
  447. $res_album_owner=0;
  448. }
  449. switch($get_res_type){
  450. case "1"://pali text
  451. {
  452. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  453. $query="SELECT * FROM pali_text WHERE \"book\" = ".$PDO->quote($res_book)." AND (\"paragraph\" in {$strQueryParaList} ) ";
  454. $sth = $PDO->prepare($query);
  455. $sth->execute();
  456. echo $query."<br/>";
  457. {
  458. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  459. {
  460. $text = $result["text"];
  461. $paragraph = $result["paragraph"];
  462. $strXml = "<block>";
  463. $strXml .= "<info>";
  464. $strXml .= "<type>palitext</type>";
  465. $strXml .= "<book>{$book}</book>";
  466. $strXml .= "<paragraph>{$result["paragraph"]}</paragraph>";
  467. $strXml .= "<album_id>{$result["album_index"]}</album_id>";
  468. $strXml .= "<album_guid>{$res_album_guid}</album_guid>";
  469. $strXml .= "<author>VRI</author>";
  470. $strXml .= "<language>pali</language>";
  471. $strXml .= "<version>4</version>";
  472. $strXml .= "<edition>CSCD4</edition>";
  473. $strXml .= "<level>{$result["level"]}</level>";
  474. $strXml .= "<id>".UUID::v4()."</id>";
  475. $strXml .= "</info>";
  476. $strXml .= "<data><text>{$result["text"]}</text></data>";
  477. $strXml .= "</block>";
  478. fwrite($myfile, $strXml);
  479. if($result["level"]>0 && $result["level"]<9){
  480. $strXml = "<block>";
  481. $strXml .= "<info>";
  482. $strXml .= "<type>heading</type>";
  483. $strXml .= "<book>{$book}</book>";
  484. $strXml .= "<paragraph>{$result["paragraph"]}</paragraph>";
  485. $strXml .= "<album_id>{$result["album_index"]}</album_id>";
  486. $strXml .= "<album_guid>{$res_album_guid}</album_guid>";
  487. $strXml .= "<author>VRI</author>";
  488. $strXml .= "<language>pali</language>";
  489. $strXml .= "<version>4</version>";
  490. $strXml .= "<edition>CSCD4</edition>";
  491. $strXml .= "<level>{$result["level"]}</level>";
  492. $strXml .= "<id>".UUID::v4()."</id>";
  493. $strXml .= "</info>";
  494. $strXml .= "<data><text>{$result["text"]}</text></data>";
  495. $strXml .= "</block>";
  496. fwrite($myfile, $strXml);
  497. }
  498. else{
  499. }
  500. }
  501. }
  502. break;
  503. }
  504. case "2"://wbw逐词解析
  505. {
  506. //$res_album_id;
  507. $album_title = "title";
  508. $album_author = $author;
  509. $album_type=$get_res_type;
  510. $db_file = _DIR_PALICANON_WBW_."/p{$res_book}_wbw.db3";
  511. $table_info="p{$res_book}_wbw_info";
  512. $table_data="p{$res_book}_wbw_data";
  513. PDO_Connect("sqlite:$db_file");
  514. foreach($aParaList as $iPar){
  515. $query="SELECT * FROM '{$table_info}' WHERE paragraph = ".$PDO->quote($iPar)." and album_id=".$PDO->quote($res_album_id);
  516. //$FetchInfo = PDO_FetchAll($query);
  517. echo $query."<br>";
  518. $sth = $PDO->prepare($query);
  519. $sth->execute();
  520. echo "para:{$iPar} row:".$sth->rowCount();
  521. if($result = $sth->fetch(PDO::FETCH_ASSOC))
  522. {
  523. $lang=$sLang["{$result["language"]}"];
  524. $info_id=$result["id"];
  525. $strXml = "<block>";
  526. $strXml .= "<info>";
  527. $strXml .= "<type>wbw</type>";
  528. $strXml .= "<book>{$res_book}</book>";
  529. $strXml .= "<paragraph>{$iPar}</paragraph>";
  530. $strXml .= "<level>{$result["level"]}</level>";
  531. $strXml .= "<title>{$result["title"]}</title>";
  532. $strXml .= "<album_id>{$res_album_id}</album_id>";
  533. $strXml .= "<album_guid>{$res_album_guid}</album_guid>";
  534. $strXml .= "<author>{$result["author"]}</author>";
  535. $strXml .= "<language>{$lang}</language>";
  536. $strXml .= "<version>{$result["version"]}</version>";
  537. $strXml .= "<edition>{$result["edition"]}</edition>";
  538. $strXml .= "<id>".UUID::v4()."</id>";
  539. $strXml .= "</info>\n";
  540. $strXml .= "<data>";
  541. fwrite($myfile, $strXml);
  542. $query="SELECT * FROM \"{$table_data}\" WHERE info_id=".$PDO->quote($info_id);
  543. $sth = $PDO->prepare($query);
  544. $sth->execute();
  545. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  546. {
  547. $wid="p{$res_book}-{$iPar}-{$result["sn"]}";
  548. $strXml="<word>";
  549. $strXml.="<pali>{$result["word"]}</pali>";
  550. $strXml.="<real>{$result["real"]}</real>";
  551. $strXml.="<id>{$wid}</id>";
  552. $strXml.="<type>{$result["type"]}</type>";
  553. $strXml.="<gramma>{$result["gramma"]}</gramma>";
  554. $strXml.="<mean>{$result["mean"]}</mean>";
  555. $strXml.="<note>{$result["note"]}</note>";
  556. $strXml.="<org>{$result["part"]}</org>";
  557. $strXml.="<om>{$result["partmean"]}</om>";
  558. $strXml.="<case>{$result["type"]}#{$result["gramma"]}</case>";
  559. $strXml.="<style>{$result["style"]}</style>";
  560. $strXml.="<enter>{$result["enter"]}</enter>";
  561. $strXml.="<status>0</status>";
  562. $strXml.="</word>\n";
  563. fwrite($myfile, $strXml);
  564. }
  565. $strXml="</data>\n</block>";
  566. fwrite($myfile, $strXml);
  567. }
  568. }
  569. break;
  570. }
  571. case "3"://translate
  572. {
  573. //打开翻译数据文件
  574. $db_file = _DIR_PALICANON_TRAN_."/p{$book}_translate.db3";
  575. PDO_Connect("sqlite:$db_file");
  576. $table="p{$book}_translate_info";
  577. //部分段落
  578. $query="SELECT * FROM {$table} WHERE paragraph in {$strQueryParaList} and album_id=$res_album_id";
  579. echo $query."<br/>";
  580. //查询翻译经文内容
  581. $FetchText = PDO_FetchAll($query);
  582. $iFetchText = count($FetchText);
  583. echo "iFetchText:{$iFetchText}<br/>";
  584. if($iFetchText>0){
  585. for($i=0;$i<$iFetchText;$i++){
  586. $currParNo = $FetchText[$i]["paragraph"];
  587. $language = $FetchText[$i]["language"];
  588. $language = $sLang["{$language}"];
  589. if($res_album_owner == $UID){
  590. $power = "write";
  591. }
  592. else{
  593. $power = "read";
  594. }
  595. //输出数据头
  596. $strXml="<block>";
  597. $strXml.="<info>";
  598. $strXml.="<type>translate</type>";
  599. $strXml.="<book>{$res_book}</book>";
  600. $strXml.="<paragraph>{$currParNo}</paragraph>";
  601. $strXml.="<album_id>{$res_album_id}</album_id>";
  602. $strXml.="<album_guid>{$res_album_guid}</album_guid>";
  603. $strXml.="<author>{$FetchText[$i]["author"]}</author>";
  604. $strXml.="<editor>{$FetchText[$i]["editor"]}</editor>";
  605. $strXml.="<language>{$language}</language>";
  606. $strXml.="<version>{$FetchText[$i]["version"]}</version>";
  607. $strXml.="<edition>{$FetchText[$i]["edition"]}</edition>";
  608. $strXml.="<level>{$FetchText[$i]["level"]}</level>";
  609. $strXml.="<readonly>0</readonly>";
  610. $strXml.="<power>{$power}</power>";
  611. $strXml.="<id>".UUID::v4()."</id>";
  612. $strXml.="</info>";
  613. $strXml.="<data>";
  614. fwrite($myfile, $strXml);
  615. //查另一个表,获取段落文本。一句一条记录。有些是一段一条记录
  616. $table_data = "p{$book}_translate_data";
  617. $query = "SELECT * FROM '{$table_data}' WHERE info_id={$FetchText[$i]["id"]}";
  618. $aParaText = PDO_FetchAll($query);
  619. //输出数据内容
  620. $par_text="";
  621. foreach($aParaText as $sent){
  622. $par_text .= "<sen><begin>{$sent["begin"]}</begin><end>{$sent["end"]}</end><text>{$sent["text"]}</text></sen>";
  623. }
  624. fwrite($myfile, $par_text);
  625. //段落块结束
  626. $strXml = "</data></block>";
  627. fwrite($myfile, $strXml);
  628. //获取段落文本结束。
  629. }
  630. }
  631. break;
  632. }
  633. case "4"://note
  634. break;
  635. case "5":
  636. break;
  637. case "6"://逐词译模板
  638. {
  639. $album_guid = UUID::v4();
  640. $album_title = "title";
  641. $album_author = "VRI";
  642. $album_type=$get_res_type;
  643. //获取段落层级和标题
  644. $para_title=array();
  645. PDO_Connect("sqlite:"._FILE_DB_PALITEXT_);
  646. $query="SELECT * FROM pali_text WHERE \"book\" = ".$PDO->quote($res_book)." AND (\"paragraph\" in {$strQueryParaList} ) AND level>0 AND level<9";
  647. $sth = $PDO->prepare($query);
  648. $sth->execute();
  649. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  650. {
  651. $paragraph = $result["paragraph"];
  652. $para_title["{$paragraph}"][0]=$result["level"];
  653. $para_title["{$paragraph}"][1]=$result["text"];
  654. }
  655. $db_file = _DIR_PALICANON_TEMPLET_."/p".$res_book."_tpl.db3";
  656. PDO_Connect("sqlite:$db_file");
  657. foreach($aParaList as $iPar){
  658. $query="SELECT * FROM 'main' WHERE (\"paragraph\" = ".$PDO->quote($iPar)." ) ";
  659. $sth = $PDO->prepare($query);
  660. $sth->execute();
  661. {
  662. if(isset($para_title["{$iPar}"])){
  663. $level=$para_title["{$iPar}"][0];
  664. $title=$para_title["{$iPar}"][1];
  665. }
  666. else{
  667. $level=100;
  668. $title="";
  669. }
  670. $strXml="<block>";
  671. $strXml.="<info>";
  672. $strXml.="<type>wbw</type>";
  673. $strXml.="<book>{$book}</book>";
  674. $strXml.="<paragraph>{$iPar}</paragraph>";
  675. $strXml.="<level>{$level}</level>";
  676. $strXml.="<title>{$title}</title>";
  677. $strXml.="<album_id>-1</album_id>";
  678. $strXml.="<album_guid>{$album_guid}</album_guid>";
  679. $strXml.="<author>{$USER_NAME}</author>";
  680. $strXml.="<editor>{$USER_NAME}</editor>";
  681. $strXml.="<language>en</language>";
  682. $strXml.="<version>1</version>";
  683. $strXml.="<edition></edition>";
  684. $strXml.="<splited>0</splited>";
  685. $strXml.="<id>".UUID::v4()."</id>";
  686. $strXml.="</info>\n";
  687. $strXml.="<data>";
  688. fwrite($myfile, $strXml);
  689. while($result = $sth->fetch(PDO::FETCH_ASSOC))
  690. {
  691. if($result["gramma"]=="?"){
  692. $wGrammar="";
  693. }
  694. else{
  695. $wGrammar=$result["gramma"];
  696. }
  697. $strXml="<word>";
  698. $strXml.="<pali>{$result["word"]}</pali>";
  699. $strXml.="<real>{$result["real"]}</real>";
  700. $strXml.="<id>{$result["wid"]}</id>";
  701. $strXml.="<type status=\"0\">{$result["type"]}</type>";
  702. $strXml.="<gramma status=\"0\">{$wGrammar}</gramma>";
  703. $strXml.="<mean status=\"0\">?</mean>";
  704. $strXml.="<org status=\"0\">".mb_strtolower($result["part"], 'UTF-8')."</org>";
  705. $strXml.="<om status=\"0\">?</om>";
  706. $strXml.="<case status=\"0\">{$result["type"]}#{$wGrammar}</case>";
  707. $strXml.="<style>{$result["style"]}</style>";
  708. $strXml.="<status>0</status>";
  709. $strXml.="</word>";
  710. fwrite($myfile, $strXml);
  711. }
  712. $strXml="</data>\n</block>";
  713. fwrite($myfile, $strXml);
  714. }
  715. }
  716. break;
  717. }
  718. }
  719. /*查询结束*/
  720. }
  721. /*
  722. 自动新建译文
  723. */
  724. if(isset($_POST["new_tran"])){
  725. $new_tran=$_POST["new_tran"];
  726. if($new_tran=="on"){
  727. $album_guid = UUID::v4();
  728. foreach($aParaList as $iPar){
  729. $strXml="<block>";
  730. $strXml.="<info>";
  731. $strXml.="<album_id>-1</album_id>";
  732. $strXml.="<album_guid>{$album_guid}</album_guid>";
  733. $strXml.="<type>translate</type>";
  734. $strXml.="<paragraph>{$iPar}</paragraph>";
  735. $strXml.="<book>{$book}</book>";
  736. $strXml.="<author>{$author}</author>";
  737. $strXml.="<language>en</language>";
  738. $strXml.="<version>0</version>";
  739. $strXml.="<edition>0</edition>";
  740. $strXml.="<id>".UUID()::v4."</id>";
  741. $strXml.="</info>";
  742. $strXml.="<data>";
  743. $strXml.="<sen><begin></begin><end></end><text>new translate</text></sen>";
  744. $strXml.="</data>";
  745. $strXml.="</block>\n";
  746. fwrite($myfile, $strXml);
  747. }
  748. }
  749. }
  750. $strXml=" </body>\n";
  751. $strXml.="</set>\n";
  752. fwrite($myfile, $strXml);
  753. fclose($myfile);
  754. echo "<p>save ok</p>";
  755. $filesize=filesize($sFullFileName);
  756. //服务器端文件列表
  757. $db_file = _FILE_DB_FILEINDEX_;
  758. PDO_Connect("sqlite:$db_file");
  759. $query="INSERT INTO fileindex ('id',
  760. 'parent_id',
  761. 'user_id',
  762. 'book',
  763. 'paragraph',
  764. 'file_name',
  765. 'title',
  766. 'tag',
  767. 'status',
  768. 'create_time',
  769. 'modify_time',
  770. 'accese_time',
  771. 'file_size',
  772. 'share',
  773. 'doc_info',
  774. 'doc_block',
  775. 'receive_time'
  776. )
  777. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  778. $stmt = $PDO->prepare($query);
  779. $doc_id=UUID::v4();
  780. $newData=array($doc_id,
  781. "",
  782. $uid,
  783. $book,
  784. $create_para,
  785. $FileName,
  786. $user_title,
  787. $tag,
  788. 1,
  789. mTime(),
  790. mTime(),
  791. mTime(),
  792. $filesize,
  793. 0,
  794. "",
  795. "",
  796. mTime()
  797. );
  798. $stmt->execute($newData);
  799. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  800. $error = PDO_ErrorInfo();
  801. echo "error - $error[2] <br>";
  802. }
  803. else{
  804. echo "updata 1 recorders.";
  805. }
  806. echo "<a href=\"editor.php?op=open&fileid={$doc_id}\">正在跳转</a>";
  807. echo "<script>";
  808. echo "window.location.assign(\"editor.php?op=open&fileid={$doc_id}\");";
  809. echo "</script>";
  810. break;
  811. }
  812. case "open":
  813. {
  814. /*打开工程文件
  815. 三种情况
  816. 1.自己的文档
  817. 2.别人的共享文档,自己以前没有打开过。复制到自己的空间,再打开。
  818. 3.别人的共享文档,自己以前打开过。直接打开
  819. */
  820. if($_COOKIE["uid"]){
  821. $uid=$_COOKIE["uid"];
  822. }
  823. else{
  824. echo "<h3><a href='../ucenter/index.php?op=login'>{$_local->gui->login}</a>后才可以打开文档</h3>";
  825. exit;
  826. }
  827. $db_file = _FILE_DB_FILEINDEX_;
  828. PDO_Connect("sqlite:$db_file");
  829. if(isset($_GET["doc_id"])){
  830. $doc_id=$_GET["doc_id"];
  831. $query = "select * from fileindex where id='$doc_id' ";
  832. $Fetch = PDO_FetchAll($query);
  833. $iFetch=count($Fetch);
  834. if($iFetch>0){
  835. //文档信息
  836. $owner=$Fetch[0]["user_id"];
  837. $filename=$Fetch[0]["file_name"];
  838. $title=$Fetch[0]["title"];
  839. $tag=$Fetch[0]["tag"];
  840. $mbook=$Fetch[0]["book"];
  841. $paragraph=$Fetch[0]["paragraph"];
  842. $doc_head=$Fetch[0]["doc_info"];
  843. if($owner==$uid){
  844. //自己的文档
  845. echo "<h3>{$_local->gui->my_document}</h3>";
  846. $my_doc_id=$doc_id;
  847. echo "<a href=\"editor.php?op=opendb&fileid={$doc_id}\">{$_local->gui->open_doc}</a>";
  848. echo "<script>";
  849. echo "window.location.assign(\"editor.php?op=opendb&fileid={$doc_id}\");";
  850. echo "</script>";
  851. }
  852. else{
  853. //别人的文档
  854. //查询自己是否以前打开过
  855. $query = "select * from fileindex where parent_id='$doc_id' and user_id='$uid' ";
  856. $FetchSelf = PDO_FetchAll($query);
  857. $iFetchSelf=count($FetchSelf);
  858. if($iFetchSelf>0){
  859. //以前打开过
  860. echo "已经复制的文档 Already Copy";
  861. $my_doc_id=$FetchSelf[0]["id"];
  862. echo "<a href='../studio/editor.php?op=opendb&fileid={$doc_id}'>{$_local->gui->edit_now}</a>";
  863. echo "<script>";
  864. echo "window.location.assign(\"editor.php?op=opendb&fileid={$doc_id}\");";
  865. echo "</script>";
  866. }
  867. else{
  868. //以前没打开过
  869. //询问是否打开
  870. if(isset($_GET["openin"])){
  871. $open_in=$_GET["openin"];
  872. }
  873. else{
  874. ?>
  875. <p><?php echo $_local->gui->co_doc?>,<?php echo $_local->gui->open?>?</p>
  876. <div>
  877. 文档信息:
  878. <ul>
  879. <?php
  880. $book_name=$book["p".$mbook];
  881. echo "<li>Owner:".ucenter_get($owner)."</li>";
  882. echo "<li>Title:{$title}</li>";
  883. echo "<li>Book:{$book_name}</li>";
  884. ?>
  885. </ul>
  886. </div>
  887. <p><?php echo $_local->gui->open_with?>:</p>
  888. <ul>
  889. <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>
  890. <?php
  891. if(empty($doc_head)){
  892. echo '<li><a href="../studio/project.php?op=open&doc_id='.$doc_id.'&openin=editor">复制到我的空间用编辑器打开</a></li>';
  893. }
  894. else{
  895. 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>';
  896. }
  897. ?>
  898. </ul>
  899. <?php
  900. exit;
  901. }
  902. if($open_in=="editor"){
  903. //获取文件路径
  904. echo "共享的文档,复制并打开...";
  905. $db_file = _FILE_DB_USERINFO_;
  906. PDO_Connect("sqlite:$db_file");
  907. $query = "select userid from user where id='$owner'";
  908. $FetchUid = PDO_FetchOne($query);
  909. if($FetchUid){
  910. $source=_DIR_USER_BASE_."/".$FetchUid._DIR_MYDOCUMENT_."/".$filename;
  911. $dest=_DIR_USER_BASE_."/".$_COOKIE["userid"] ._DIR_MYDOCUMENT_."/".$filename;
  912. }
  913. echo "<div>源文件{$source}</div>";
  914. echo "<div>目标文件{$dest}</div>";
  915. if(copy($source,$dest)){
  916. echo "复制文件成功";
  917. $my_file_name=$filename;
  918. //插入记录到文件索引
  919. $filesize=filesize($dest);
  920. //服务器端文件列表
  921. $db_file = _FILE_DB_FILEINDEX_;
  922. PDO_Connect("sqlite:$db_file");
  923. //$query="INSERT INTO fileindex ('id','userid','parent_id','doc_id','book','paragraph','file_name','title','tag','create_time','modify_time','accese_time','file_size')
  924. // VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?)";
  925. //$stmt = $PDO->prepare($query);
  926. //$newData=array($uid,$doc_id,UUID::v4(),$mbook,$paragraph,$filename,$title,$tag,time(),time(),time(),$filesize);
  927. $query="INSERT INTO fileindex ('id',
  928. 'parent_id',
  929. 'user_id',
  930. 'book',
  931. 'paragraph',
  932. 'file_name',
  933. 'title',
  934. 'tag',
  935. 'status',
  936. 'create_time',
  937. 'modify_time',
  938. 'accese_time',
  939. 'file_size',
  940. 'share',
  941. 'doc_info',
  942. 'doc_block',
  943. 'receive_time'
  944. )
  945. VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  946. $stmt = $PDO->prepare($query);
  947. $newdoc_id=UUID::v4();
  948. $newData=array(
  949. $newdoc_id,
  950. $doc_id,
  951. $uid,
  952. $mbook,
  953. $paragraph,
  954. $filename,
  955. $title,
  956. $tag,
  957. 1,
  958. mTime(),
  959. mTime(),
  960. mTime(),
  961. $filesize,
  962. 0,
  963. "",
  964. "",
  965. mTime()
  966. );
  967. $stmt->execute($newData);
  968. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  969. $error = PDO_ErrorInfo();
  970. echo "error - $error[2] <br>";
  971. $my_doc_id="";
  972. }
  973. else{
  974. $my_doc_id = newdoc_id;
  975. echo "updata 1 recorders.";
  976. }
  977. }
  978. else{
  979. echo "复制文件失败";
  980. $my_doc_id="";
  981. }
  982. }
  983. else{
  984. echo "错误-无法识别的操作:open in:{$open_in}";
  985. $my_doc_id="";
  986. }
  987. }
  988. }
  989. /*
  990. if($my_doc_id!=""){
  991. echo "<script>";
  992. echo "window.location.assign(\"editor.php?op=open&fileid={$my_doc_id}\");";
  993. echo "</script>";
  994. }
  995. */
  996. }
  997. else{
  998. echo "未知的文档。可能该文件已经被删除。";
  999. }
  1000. }
  1001. }
  1002. break;
  1003. case "openfile":
  1004. break;
  1005. case "save":
  1006. break;
  1007. }
  1008. ?>
  1009. </body>