PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/account.php

https://bitbucket.org/VasjaUa/pks_pl
PHP | 269 lines | 233 code | 22 blank | 14 comment | 68 complexity | e387ee4139786b2ac365bdd1ac3acb82 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. $connection = mysql_connect("localhost", "pkskrakow_4", "Dond33st4S!");
  3. $db = mysql_select_db("pkskrakow_4");
  4. mysql_query("SET NAMES 'utf8'");
  5. if (!$connection || !$db) {exit(mysql_error());}
  6. if (isset($_GET['reset'])) {
  7. if ($_COOKIE['resetPass'] == $_GET['resetPassword']) {
  8. $id = $_GET['id'];
  9. $_COOKIE['resetPass'] = '';
  10. ?>
  11. <link rel="stylesheet" href="libs/sweetalert/sweetalert.css">
  12. <script src="libs/jquery/jquery-1.9.1.min.js"></script>
  13. <script src="libs/sweetalert/sweetalert.min.js"></script>
  14. <script>
  15. $(document).ready(function () {
  16. swal({
  17. title: "Wprowadź nowe hasło",
  18. input: "password",
  19. closeOnConfirm: false,
  20. showLoaderOnConfirm: true,
  21. animation: "slide-from-top",
  22. inputPlaceholder: "Nowe hasło",
  23. preConfirm: function (inputValue) {
  24. return new Promise(function (resolve, reject) {
  25. if (inputValue.length < 6) {
  26. swal.showInputError("Minimum 6 symbols");
  27. reject();
  28. } else {
  29. setTimeout(function () {
  30. $.ajax({
  31. url: "/registration.php",
  32. type: "POST",
  33. data: {
  34. resetPassword: true,
  35. id: <?= $id ?>,
  36. password: inputValue
  37. },
  38. success: function (check) {
  39. swal('Success', 'Your password has been changed, now you can login with a new password', 'success')
  40. setTimeout(function () {
  41. location.href = '/'
  42. }, 2000)
  43. },
  44. error: function () {
  45. console.log('error')
  46. }
  47. });
  48. }, 1500)
  49. }
  50. })
  51. }
  52. });
  53. })
  54. </script>
  55. <?
  56. } else {
  57. header('location:/');
  58. }
  59. }
  60. if (isset($_POST['resetPassword'])) {
  61. $email = $_POST['email'];
  62. $query = mysql_query("SELECT * FROM `userdata` WHERE `email` LIKE '$email'");
  63. $result = mysql_fetch_assoc($query);
  64. if ($result['email'] == $email) {
  65. $token = md5(date('D:h:m:s'));
  66. $id = $result['idUser'];
  67. setcookie('resetPass', $token);
  68. echo 'true;' . $token . ";" . $id;
  69. } else {
  70. echo 'false';
  71. }
  72. }
  73. if (isset($_POST['data2db'])) {
  74. $id = $_COOKIE['logged'];
  75. $array = $_POST['data2db'];
  76. if ($id != '') {
  77. for ($i = 0; $i < count($array); $i++) {
  78. $ticket = $array[$i]['reserve_num'][$i];
  79. $arrival_time = $array[$i]['arrival'];
  80. $departure_time = $array[$i]['departure'];
  81. $total_time_road = $array[$i]['duration_minutes'];
  82. $station_from = $array[$i]['station_from'];
  83. $station_to = $array[$i]['station_to'];
  84. $price = $array[$i]['price'][$i];
  85. if (is_array($ticket)) {
  86. for ($n = 0; $n < count($ticket); $n++) {
  87. $num = $ticket[$n]['ticket_number'];
  88. $newPrice = $price / count($ticket);
  89. mysql_query("INSERT INTO `tickets` (`arrival_time`, `departure_time`, `number_ticket`, `price`, `status`, `total_time_road`, `id`, `station_from`, `station_to`)
  90. VALUES('$arrival_time','$departure_time', '$num','$newPrice', 'paid','$total_time_road','$id','$station_from','$station_to')");
  91. }
  92. } else {
  93. mysql_query("INSERT INTO `tickets` (`arrival_time`, `departure_time`, `number_ticket`, `price`, `status`, `total_time_road`, `id`, `station_from`, `station_to`)
  94. VALUES('$arrival_time','$departure_time','$ticket','$price', 'paid','$total_time_road','$id','$station_from','$station_to')");
  95. }
  96. }
  97. mysql_close();
  98. } else {
  99. echo "no access";
  100. }
  101. goto end;
  102. }
  103. if (isset($_POST['cancellation']) && $_POST['cancellation'] != '') {
  104. include_once("helpers/session/Helper.php");
  105. $helper = new Helper();
  106. $num = $_POST['cancellation'];
  107. $id = $_COOKIE['logged'];
  108. $query = mysql_query("SELECT * FROM `tickets` WHERE `Number` LIKE '$num'");
  109. $result = mysql_fetch_assoc($query);
  110. $reqData = array(
  111. "method" => "TicketsCancelation",
  112. "ticket_number" => "$result[number_ticket]"
  113. );
  114. $output = json_decode($helper::apiRequest($reqData), true);
  115. if($output['canceled'] == false){
  116. echo $output['Reclamation'];
  117. }else{
  118. echo 'ok';
  119. if($output['FakturaVAT'] == true){
  120. mysql_query('UPDATE `transactions` SET uuid = "'. $output['UUIDSalesInvoice'] .'", invoice_number = "'. $output['InvoiceNumber'] .'", SalesDate = "'. $output['SalesDate'] .'", firm = "'. $output['FirmSalesInvoice'] .'", Exhibitor = "'. $output['Exhibitor'] .'", DocumentTotal = "'. $output['DocumentTotal'] .'", response = "'. $output['PrintFile'] .'" WHERE id = "'. $result[transaction_id] .'"');
  121. }
  122. mysql_query("INSERT INTO `cancelledTickets` (`transaction_id`,`arrival_time`, `departure_time`, `number_ticket`, `price`, `status`, `total_time_road`, `id_user`, `station_from`, `station_to`, `Number`, `FiscalNumber`)
  123. VALUES('$result[transaction_id]', '$result[arrival_time]','$result[departure_time]','$result[number_ticket]','$result[price]', 'cancelled','$result[total_time_road]','$id','$result[station_from]','$result[station_to]', '$result[Number]', '$result[FiscalNumber]')");
  124. mysql_query("DELETE FROM `tickets` WHERE `Number` LIKE '$num'");
  125. }
  126. }
  127. // Код для входа ползователя в кабинет
  128. if (isset($_POST['login']) && isset($_POST['password'])) {
  129. $password_check = 'false';
  130. if ($_POST['login'] != '') {
  131. $login = $_POST['login'];
  132. $password = $_POST['password'];
  133. $query = mysql_query("SELECT * FROM `userdata` WHERE `login` LIKE '$login' OR `email` LIKE '$login'");
  134. $result = mysql_fetch_assoc($query);
  135. if ($result['login'] || $result['email'] == $login) {
  136. //проверка на подтверждения пользователя
  137. $query_status = mysql_query("SELECT activation FROM `userdata` WHERE `login` LIKE '$login' OR `email` LIKE '$login'");
  138. $result_status = mysql_fetch_assoc($query_status);
  139. if ($result_status['activation'] == 0) {
  140. $password_check = 'status';
  141. } else {
  142. if ($password == $result['password']) {
  143. $id = mysql_query("SELECT idUser FROM `userdata` WHERE `login` LIKE '$login' OR `email` LIKE '$login'");
  144. $result_id = mysql_fetch_assoc($id);
  145. setcookie("logged", $result_id['idUser']);
  146. $password_check = 'true';
  147. echo 'true';
  148. }
  149. }
  150. }
  151. }
  152. }
  153. // Edit password in user cabinet
  154. if (isset($_POST['password_old']) && isset($_POST['password_new'])) {
  155. $password_check = 'false';
  156. if ($_POST['password_old'] != '' && $_POST['password_new']) {
  157. $id = $_COOKIE['logged'];
  158. $password_old = $_POST['password_old'];
  159. $password_new = $_POST['password_new'];
  160. $query = mysql_query("SELECT password FROM `userdata` WHERE `password` LIKE '$password_old'");
  161. $result = mysql_fetch_assoc($query);
  162. if ($result['password'] == $password_old) {
  163. $result = mysql_query("UPDATE userdata SET password='$password_new' WHERE idUser='$id'");
  164. $password_check = 'true';
  165. }
  166. }
  167. print_r($password_check);
  168. }
  169. // Edit user data in user cabinet
  170. if (isset($_POST['array'])) {
  171. $array = $_POST['array'];
  172. $id = $_COOKIE['logged'];
  173. $email = $array[0];
  174. $phone = $array[1];
  175. $name = $array[2];
  176. $surname = $array[3];
  177. $birthday = $array[4];
  178. $country = $array[6];
  179. $city = $array[7];
  180. $profession = $array[8];
  181. if ($array[5] === 'male') {
  182. $gender = 'Mężczyzna';
  183. } elseif ($array[5] === 'female') {
  184. $gender = 'Kobieta';
  185. }
  186. $query = mysql_query("SELECT email FROM `userdata` WHERE idUser='$id'");
  187. $result = mysql_fetch_assoc($query);
  188. if ($result['email'] === $email) {
  189. $query = mysql_query("UPDATE userdata SET phone='$phone', name= '$name', gender='$gender', surname= '$surname', birthday= '$birthday', country= '$country', city= '$city', profession= '$profession' WHERE idUser='$id'");
  190. print_r('true');
  191. } else {
  192. $query = mysql_query("SELECT email FROM `userdata` WHERE `email` LIKE '$email'");
  193. $result = mysql_fetch_assoc($query);
  194. if (isset($result['email'])) {
  195. print_r('email');
  196. } else {
  197. $query = mysql_query("UPDATE userdata SET email='$email', phone='$phone', name= '$name',gender='$gender', surname= '$surname', birthday= '$birthday', country= '$country', city= '$city', profession= '$profession' WHERE idUser='$id'");
  198. print_r('true');
  199. }
  200. }
  201. }
  202. if (isset($_FILES["file"])) {
  203. $login = $_POST['login'];
  204. $file_name = date('y-m-d-H-i-s') . "_" . $_FILES["file"]["name"];
  205. $extension = end(explode(".", $_FILES["file"]["name"]));
  206. if ((strtolower($_FILES["file"]["type"]) == "image/jpg") || (strtolower($_FILES["file"]["type"]) == "image/jpeg") || (strtolower($_FILES["file"]["type"]) == "image/png") && ($_FILES["file"]["size"] < 200000000)) {
  207. if ($_FILES["file"]["error"] > 0) {
  208. echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
  209. } else {
  210. if (is_uploaded_file($_FILES["file"]["tmp_name"])) {
  211. move_uploaded_file($_FILES["file"]["tmp_name"], "user_img/" . str_replace(" ", "_", $file_name));
  212. $messageFile .= "/user_img/" . str_replace(" ", "_", $file_name);
  213. }
  214. mysql_query("UPDATE `userdata` SET `url`= '$messageFile' WHERE `login` LIKE '$login'");
  215. }
  216. } else {
  217. echo $_FILES["file"]["type"];
  218. }
  219. }
  220. // edit faktury
  221. if (isset($_POST['faktury'])) {
  222. $obj = $_POST['faktury'];
  223. $id = $_COOKIE['logged'];
  224. if($obj['firm_or_person'] == 'false'){
  225. $is_company = 0;
  226. }else{
  227. $is_company = 1;
  228. }
  229. mysql_query('UPDATE userdata SET firm = "'. $obj['firm'] .'", nip = "'. $obj['nip'] .'", f_post_code = "'. $obj['f_post_code'] .'", f_city = "'. $obj['f_city'] .'", f_country = "'. $obj['f_country'] .'", f_street = "'. $obj['f_street'] .'", is_company = "'. $is_company .'" WHERE idUser = '. $id );
  230. // mysql_query("UPDATE userdata SET
  231. // firm='$obj[firm]',
  232. // nip='$obj[nip]',
  233. // f_post_code='$obj[f_post_code]',
  234. // f_country='$obj[f_country]',
  235. // f_city='$obj[f_city]',
  236. // f_street='$obj[f_street]',
  237. // is_company='(int)$obj[firm_or_person]'
  238. // WHERE idUser='$id'");
  239. }
  240. if (isset($_POST['checkFacture'])) {
  241. $id = $_COOKIE['logged'];
  242. $checkFacture = $_POST['checkFacture'];
  243. mysql_query("UPDATE userdata SET checkFacture='$checkFacture' WHERE idUser='$id'");
  244. $result = mysql_fetch_assoc($query);
  245. echo $result;
  246. }
  247. end: