case 0: echo "This email has no associated registration inquiry. Link is invalid. Please, review whether you fully copied the activation link. If you don't know what's happened, just try signup again.<br>"; http_response_code(422); break; case 1: $arr = $conn->fetch_array(); //var_dump($arr['reg_token']); //var_dump($_POST['reg_token']); if ($arr["reg_token"] == $input_reg_token) { $adduser_query = "UPDATE users SET is_activated = TRUE, password='******' WHERE login='******'"; if ($arr["is_activated"] === 't') { echo "Your email has been activated. You may log in to your account"; http_response_code(422); exit; } if ($conn->run_insert($adduser_query) != 0) { $_SESSION['g_username'] = $input_email; $_SESSION['g_hostel_id'] = NULL; echo "Congratulation, registration completed!"; http_response_code(200); exit; } else { echo "Error: Can't add user to users table."; http_response_code(422); } } else { echo "Wrong registration token. Please, be sure, that you have copied activation link correctly or contact support or try to make new registration inquiry for another email.<br>"; http_response_code(422); } break; default:
} $path_to_cdbconn = $_SERVER["DOCUMENT_ROOT"] . "/php/CDBConn.php"; include_once $path_to_cdbconn; $hostel_info = json_decode($_POST["hostel_info"]); $rooms = json_decode($_POST["rooms"]); $conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123", TRUE); $conn->connect(); // Creating new hostel $insert_query = "INSERT INTO hostels (name, room_count, is_configured) VALUES('{$hostel_info->hostel_name}', {$hostel_info->room_count}, TRUE) RETURNING id"; $conn->run_query($insert_query); echo $conn->affected_rows() . " rows inserted."; $new_hostel_id = 0; while ($line = $conn->fetch_array()) { echo "id = " . $line[0]; $new_hostel_id = $line[0]; } // Associating email with hostel $login_from_session = $_SESSION['g_username']; $update_query = "UPDATE users SET hostel_id = {$new_hostel_id} WHERE login = '******'"; $conn->run_query($update_query); $_SESSION['g_hostel_id'] = $new_hostel_id; // Associating rooms with hostel for ($i = 0; $i < count($rooms); $i++) { $cur_room_name = $rooms[$i]->name; $cur_room_capacity = $rooms[$i]->capacity; $cur_room_type = $rooms[$i]->type; $cur_room_rate = $rooms[$i]->rate; $sql_room_add = "INSERT INTO rooms (name, bed_count, type_id, rate, hostel_id) VALUES('{$cur_room_name}', {$cur_room_capacity}, {$cur_room_type}, {$cur_room_rate}, {$new_hostel_id})"; $conn->run_insert($sql_room_add); } $conn->close();
<?php $arr = $_POST; $rcount = $_POST["roomscount"]; $path_to_hostconfig = $_SERVER['DOCUMENT_ROOT'] . "/php/hostconfig.php"; include_once $path_to_hostconfig; $path_to_cdbconn = $_SERVER["DOCUMENT_ROOT"] . "/php/CDBConn.php"; include_once $path_to_cdbconn; $my_conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123", FALSE); $my_conn->connect(); for ($i = 1; $i <= $rcount; $i++) { $nazv = "nazv" . $i; $type_id = "type" . $i; $capacity = "capacity" . $i; $price = "price" . $i; $q_insert = "INSERT INTO room (room_name, room_type_id, bed_count, room_rate) VALUES('" . $arr[$nazv] . "'," . $arr[$type_id] . "," . $arr[$capacity] . "," . $arr[$price] . ")"; $my_conn->run_insert($q_insert); } $my_conn->close(); header('Refresh: 1; url=thx.php'); ?> <?php } ?> </div> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="../js/bootstrap.js"></script> </body>
$conn->run_query($get_guest); $guest_id = 0; if ($conn->affected_rows() == 0) { $insert_guest = "INSERT INTO guests(first_name, last_name, telephone) VALUES('{$first_name}','{$last_name}','{$telephone}') RETURNING id"; $conn->run_query($insert_guest); $arr = $conn->fetch_array(); $guest_id = $arr['id']; echo "New guest id = " . $guest_id . "<br>"; } else { if ($conn->affected_rows() == 1) { $arr = $conn->fetch_array(); $guest_id = $arr['id']; echo 'Old guest id = ' . $guest_id . "<br>"; } else { echo "Please, contact support"; http_response_code(409); exit; } } $state_id = 1; $insert_order = "INSERT INTO orders(guest_id, date_in, date_out, state_id, room_id, bed_index)\nVALUES({$guest_id}, '{$date_in}', '{$date_out}', {$state_id}, {$room_id}, {$bed_index})"; $conn->run_insert($insert_order); if ($conn->affected_rows() != 1) { http_response_code(409); exit; } else { if ($conn->affected_rows() == 1) { http_response_code(200); } } $conn->close();
} $conn = new CDBConn($jet_ip, $db_name, $db_user, "qwerty123", FALSE); $conn->connect(); $conn->run_select("SELECT * FROM users WHERE login='******'"); if ($conn->affected_rows() > 0) { echo "Following email '{$send_to}' is already used or activation requested. Please, select another email, if appropriate.<br>"; http_response_code(422); exit(1); } else { $subject = "JetPMS.com Registration Request"; $message = "Dear customer, <br><br><br>We are glad to inform that you have almost done with the registration at JetPMS.<br/> Please, follow further simple instruction and be ready for evaluating our product.<br>"; /*$message .= "So far, you have requested JetPMS for:<br>"; $message .= "Beds <b>".$_POST["bedscount"] . "</b><br/>"; $message .= "Country <b>".$_POST["country"]."</b><br/>"; $message .= "Total price: <b>".$_POST["b_price"]."$/month</b><br>"; */ $message .= "Please, click to this activation link: "; $reg_token = bin2hex(openssl_random_pseudo_bytes(16)); $activation_link = "http://" . $_SERVER["HTTP_HOST"] . "/signup/activateAccount.php?email=" . $send_to . "®_token=" . $reg_token; $href_tag = "<a href=" . $activation_link . ">{$activation_link}</a>"; $conn->run_insert("INSERT INTO users (login, reg_token, is_activated) VALUES('{$send_to}', '{$reg_token}', FALSE)"); $message .= $href_tag . "<br>"; $message .= "<br><br>Best Wishes,<br/>JetPMS.com Team<br/>+380980238180<br>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers = "Content-type:text/html;charset=UTF-8" . "\r\n"; // setsebool -P httpd_can_sendmail on mail($send_to, $subject, $message, $headers); echo "Registration info is sent to {$send_to}. Please check email (also, check spam if you will have not found the email)<br/>"; http_response_code(200); }