project.php 34 KB

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