project.php 52 KB

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