project.php 34 KB

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