2
0

project.php 51 KB

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