login.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. require_once '../public/config.php';
  3. require_once "../public/_pdo.php";
  4. require_once "./public.inc";
  5. if(isset($_GET["language"])){
  6. $currLanguage=$_GET["language"];
  7. }
  8. else{
  9. if(isset($_COOKIE["language"])){
  10. $currLanguage=$_COOKIE["language"];
  11. }
  12. else{
  13. $currLanguage="en";
  14. }
  15. }
  16. //load language file
  17. include $dir_language."default.php";
  18. if(file_exists($dir_language.$currLanguage.".php")){
  19. require $dir_language.$currLanguage.".php";
  20. }
  21. if(isset($_GET["device"])){
  22. $currDevice=$_GET["device"];
  23. }
  24. else{
  25. if(isset($_COOKIE["device"])){
  26. $currDevice=$_COOKIE["device"];
  27. }
  28. else{
  29. $currDevice="computer";
  30. }
  31. }
  32. ?>
  33. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  34. <html>
  35. <head>
  36. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  37. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  38. <link type="text/css" rel="stylesheet" href="css/style.css"/>
  39. <link type="text/css" rel="stylesheet" href="css/color_day.css" id="colorchange" />
  40. <title><?php echo $module_gui_str['editor']['1051'];?>PCD Studio</title>
  41. <script language="javascript" src="js/common.js"></script>
  42. <script src="js/jquery-3.3.1.min.js"></script>
  43. <script src="js/fixedsticky.js"></script>
  44. <script type="text/javascript">
  45. var g_device = "computer";
  46. var strSertch = location.search;
  47. if(strSertch.length>0){
  48. strSertch = strSertch.substr(1);
  49. var sertchList=strSertch.split('&');
  50. for ( i in sertchList){
  51. var item = sertchList[i].split('=');
  52. if(item[0]=="device"){
  53. g_device=item[1];
  54. }
  55. }
  56. }
  57. if(g_device=="mobile"){
  58. g_is_mobile=true;
  59. }
  60. else{
  61. g_is_mobile=false;
  62. }
  63. var g_langrage="en";
  64. function menuLangrage(obj){
  65. g_langrage=obj.value;
  66. setCookie('language',g_langrage,365);
  67. window.location.assign("login.php?language="+g_langrage);
  68. }
  69. </script>
  70. </head>
  71. <body class="indexbody" onLoad="">
  72. <!-- tool bar begin-->
  73. <div class='index_toolbar'>
  74. <div id="index_nav">
  75. </div>
  76. <div>
  77. </div>
  78. <div class="toolgroup1">
  79. <span><?php echo $module_gui_str['editor']['1050'];?></span>
  80. <select id="id_language" name="menu" onchange="menuLangrage(this)">
  81. <option value="en" >English</option>
  82. <option value="sinhala" >සිංහල</option>
  83. <option value="zh" >简体中文</option>
  84. <option value="tw" >繁體中文</option>
  85. </select>
  86. </div>
  87. </div>
  88. <!--tool bar end -->
  89. <script>
  90. document.getElementById("id_language").value="<?php echo($currLanguage); ?>";
  91. </script>
  92. <div class="index_inner" style="width: 100%;">
  93. <div id="id_app_name"><?php echo $module_gui_str['editor']['1051'];?>
  94. <span style="font-size: 70%;">1.6</span><br />
  95. <?php if($currLanguage=="en"){ ?>
  96. <span style="font-size: 70%;">Pali Cannon Database Studio</span>
  97. <?php
  98. }
  99. else{
  100. ?>
  101. <span style="font-size: 70%;">PCD Studio</span>
  102. <?php
  103. }
  104. ?>
  105. </div>
  106. <div class="fun_block">
  107. <h2>
  108. <?php
  109. if(isset($_GET["op"])){
  110. if($_GET["op"]=="new"){
  111. ?>
  112. <span style="width: 15em;">
  113. <a href="login.php">
  114. <?php echo $module_gui_str['editor']['1090'];?>
  115. </a>
  116. </span>
  117. <span style="width: 15em;">
  118. <?php echo $module_gui_str['editor']['1091'];?>
  119. </span>
  120. <?php }
  121. }
  122. else{
  123. ?>
  124. <span style="width: 15em;">
  125. <?php echo $module_gui_str['editor']['1090'];?>
  126. </span>
  127. <span style="width: 15em;">
  128. <a href="login.php?op=new">
  129. <?php echo $module_gui_str['editor']['1091'];?>
  130. </a>
  131. </span>
  132. <?php
  133. }
  134. ?>
  135. </h2>
  136. <?php
  137. if(isset($_GET["op"])){
  138. if($_GET["op"]=="new"){
  139. ?>
  140. <div>
  141. <form action="login.php" method="post">
  142. <div class="project_res_add_author" style="width: 80%;">
  143. <span style="width: 15em;"><?php echo $module_gui_str['editor']['1092'];?>: </span>
  144. <input type="text" name="username" />
  145. <span style="width: 17em;"><?php echo $module_gui_str['editor']['1096'];?> 64 <?php echo $module_gui_str['editor']['1097'];?></span>
  146. </div>
  147. <div class="project_res_add_author" style="width: 80%;">
  148. <span style="width: 15em;"><?php echo $module_gui_str['editor']['1093'];?>: </span>
  149. <input type="password" name="password" />
  150. <span style="width: 17em;"></span>
  151. </div>
  152. <div class="project_res_add_author" style="width: 80%;">
  153. <span style="width: 15em;"><?php echo $module_gui_str['editor']['1098'];?>: </span>
  154. <input type="password" name="password_again" />
  155. <span style="width: 17em;"></span>
  156. </div>
  157. <div class="project_res_add_author" style="width: 80%;">
  158. <span style="width: 15em;"><?php echo $module_gui_str['editor']['1094'];?>: </span>
  159. <input type="text" name="nickname" />
  160. <span style="width: 17em;"><?php echo $module_gui_str['editor']['1096'];?> 64 <?php echo $module_gui_str['editor']['1097'];?></span>
  161. </div>
  162. <div class="project_res_add_author" style="width: 80%;">
  163. <span style="width: 15em;"><?php echo $module_gui_str['editor']['1095'];?>: </span>
  164. <input type="text" name="email" />
  165. <span style="width: 17em;"><?php echo $module_gui_str['editor']['1096'];?> 128 <?php echo $module_gui_str['editor']['1097'];?></span>
  166. </div>
  167. <input type="hidden" name="op" value="new"/>
  168. <input type="submit" value=<?php echo $module_gui_str['editor']['1090'];?>>
  169. </form>
  170. <?php
  171. }
  172. if($_GET["op"]=="logout"){
  173. ?>
  174. <script type="text/javascript">
  175. setCookie('uid','',365);
  176. setCookie('username','',365);
  177. setCookie('userid','',365);
  178. setCookie('nickname','',365);
  179. setCookie('email','',365);
  180. </script>
  181. <?php
  182. echo "Logout<br>";
  183. echo "<a href=\"login.php\">Login</a>";
  184. ?>
  185. <script>
  186. window.location.assign("login.php");
  187. </script>
  188. <?php
  189. }
  190. }
  191. else{
  192. if(isset($_POST["op"])){
  193. switch($_POST["op"]){
  194. case "login":
  195. $username=$_POST["username"];
  196. $password=$_POST["password"];
  197. if(empty($username)){
  198. echo "Error:User Name Is Empty!<br>";
  199. }
  200. if(empty($password)){
  201. echo "Error:Password Is Empty!<br>";
  202. }
  203. if(!empty($username) && !empty($password)){
  204. $md5_password=md5($password);
  205. $db_file = $_file_db_userinfo;
  206. PDO_Connect("sqlite:$db_file");
  207. $query = "select * from user where \"username\"=".$PDO->quote($username)." and \"password\"=".$PDO->quote($md5_password);
  208. $Fetch = PDO_FetchAll($query);
  209. $iFetch=count($Fetch);
  210. if($iFetch>0){//username is exite
  211. $uid=$Fetch[0]["id"];
  212. $username=$Fetch[0]["username"];
  213. $userid=$Fetch[0]["userid"];
  214. $nickname=$Fetch[0]["nickname"];
  215. $email=$Fetch[0]["email"];
  216. ?>
  217. <script type="text/javascript">
  218. setCookie('uid','<?php echo $uid ?>',365);
  219. setCookie('username','<?php echo $username ?>',365);
  220. setCookie('userid','<?php echo $userid ?>',365);
  221. setCookie('nickname','<?php echo $nickname ?>',365);
  222. setCookie('email','<?php echo $email ?>',365);
  223. </script>
  224. <?php
  225. $newUserPath=$dir_user_base.$userid.'/';
  226. if(!file_exists($newUserPath)){
  227. echo "error:cannot find user dir:$newUserPath<br/>";
  228. }
  229. echo "Ok<br>";
  230. echo "<a href=\"index.php\">Enter</a>";
  231. ?>
  232. <script>
  233. window.location.assign("index.php");
  234. </script>
  235. <?php
  236. }
  237. else{
  238. echo "username or password error<br/>";
  239. echo "<a href=\"login.php\">Try Again</a>";
  240. }
  241. }
  242. else{
  243. echo "<a href=\"login.php?\">Try Again</a>";
  244. }
  245. break;
  246. case "new":
  247. $username=$_POST["username"];
  248. $password=$_POST["password"];
  249. $nickname=$_POST["nickname"];
  250. $email=$_POST["email"];
  251. if(empty($username)){
  252. echo "Error:User Name Is Empty!<br>";
  253. }
  254. if(empty($password)){
  255. echo "Error:Password Is Empty!<br>";
  256. }
  257. if(empty($nickname)){
  258. echo "Error:Nickname Is Empty!<br>";
  259. }
  260. if(!empty($username) && !empty($password) && !empty($nickname)){
  261. $md5_password=md5($password);
  262. $userid=GUIDv4();
  263. $db_file = $dir_db_userinfo.$file_db_userinfo;
  264. PDO_Connect("sqlite:$db_file");
  265. $query = "select * from user where \"username\"=".$PDO->quote($username);
  266. $Fetch = PDO_FetchAll($query);
  267. $iFetch=count($Fetch);
  268. if($iFetch>0){//username is exite
  269. echo "user name is exite<br>";
  270. echo "<a href=\"login.php?op=new\">Try Again</a>";
  271. }
  272. else{
  273. $query="INSERT INTO user ('id','userid','username','password','nickname','email') VALUES (NULL,".$PDO->quote($userid).",".$PDO->quote($username).",".$PDO->quote($md5_password).",".$PDO->quote($nickname).",".$PDO->quote($email).")";
  274. $stmt = @PDO_Execute($query);
  275. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  276. $error = PDO_ErrorInfo();
  277. print_r($error[2]);
  278. echo "<a href=\"login.php?op=new\">Try Again</a>";
  279. break;
  280. }
  281. $newUserPath=$dir_user_base.$userid;
  282. $userDirApp=$newUserPath.$dir_myApp;
  283. $userDirDict=$newUserPath.$dir_dict_user;
  284. $userDirMyDocument=$newUserPath.$dir_mydocument;
  285. $userDirMyPaliCanon=$newUserPath.$dir_myPaliCannon;
  286. if(!file_exists($newUserPath)){
  287. if(mkdir($newUserPath)){
  288. mkdir($userDirApp);
  289. mkdir($userDirDict);
  290. mkdir($userDirMyDocument);
  291. //copy($dir_user_templet.$dir_myApp."/config.js",$userDirApp."/config.js");
  292. //copy($dir_user_templet.$dir_myApp."/dictlist.json",$userDirApp."/dictlist.json");
  293. //copy($dir_user_templet.$dir_myApp."/style.css",$userDirApp."/style.css");
  294. //copy($dir_user_templet.$dir_myApp."/userinfo.js",$userDirApp."/userinfo.js");
  295. //copy($dir_user_templet.$dir_myApp."/userinfo.php",$userDirApp."/userinfo.php");
  296. //copy($dir_user_templet.$dir_dict_user."/wbw.db",$userDirDict."/wbw.db");
  297. //copy($dir_user_templet.$dir_dict_user."/default.db",$userDirDict."/default.db");
  298. }
  299. else{
  300. echo "create dir fail<br>";
  301. }
  302. }
  303. echo "Create Succecful<br/>";
  304. echo "User Name:$username<br/>";
  305. echo "Nickname:$nickname<br/>";
  306. echo "Email:$email<br/>";
  307. echo "<a href=\"login.php\">Login</a>";
  308. }
  309. }
  310. else{
  311. echo "<a href=\"login.php?op=new\">Try Again</a>";
  312. }
  313. break;
  314. }
  315. }
  316. else{
  317. ?>
  318. <div>
  319. <form action="login.php" method="post">
  320. <div class="project_res_add_author" style="width: 70%;">
  321. <span style="width: 12em;"><?php echo $module_gui_str['editor']['1092'];?>: </span>
  322. <input type="text" name="username" size="20" style="width:initial;" value="guest" />
  323. <span style="width: 20em;"><?php echo $module_gui_str['editor']['1096'];?> 64 <?php echo $module_gui_str['editor']['1097'];?></span>
  324. </div>
  325. <div class="project_res_add_author" style="width: 70%;">
  326. <span style="width: 12em;"><?php echo $module_gui_str['editor']['1093'];?>: </span>
  327. <input type="password" name="password" size="20" style="width:initial;" value="guest"/>
  328. <span style="width: 20em;"></span>
  329. </div>
  330. <input type="hidden" name="op" value="login"/>
  331. <input type="submit" value=<?php echo $module_gui_str['editor']['1090'];?>>
  332. </form>
  333. </div>
  334. <?php
  335. }
  336. }
  337. ?>
  338. </div>
  339. </div>
  340. </div>
  341. <div class="foot_div">
  342. <?php echo $module_gui_str['editor']['1066'];?>
  343. </div>
  344. </body>
  345. </html>