project.php 51 KB

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