123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
-
- require_once 'config.php';
- require_once 'dbh.inc.php';
- require_once 'checkLogin.php';
-
-
-
- if(isset($_POST['updateExperience'])) {
-
-
- $id = mysqli_real_escape_string($connection, trim($_POST['id']));
- $newTitle = mysqli_real_escape_string($connection, trim($_POST['newTitle']));
- $newDescription = mysqli_real_escape_string($connection, trim($_POST['newDescription']));
- $newType = mysqli_real_escape_string($connection, trim($_POST['newType']));
- $newStart = mysqli_real_escape_string($connection, trim($_POST['newStart']));
- $newEnd = mysqli_real_escape_string($connection, trim($_POST['newEnd']));
-
-
-
-
-
-
- if($id === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify experience ID."));
- exit();
- } else if(mysqli_query($connection, "SELECT * FROM experience WHERE id = '$id';")->num_rows !== 1) {
- http_response_code(400);
- echo json_encode(array("error" => "Given experience ID ($id) not in database."));
- exit();
- }
-
-
-
-
-
-
- if($newTitle === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify title."));
- exit();
- } else if(mb_strlen($newTitle) > 60) {
- http_response_code(400);
- echo json_encode(array("error" => "Title too long (max. is 60 characters)."));
- exit();
- }
-
-
-
-
-
-
- if($newDescription === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify description."));
- exit();
- } else if(mb_strlen($newDescription) > 100) {
- http_response_code(400);
- echo json_encode(array("error" => "Description too long (max. is 100 characters)."));
- exit();
- }
-
-
-
-
-
-
-
-
- if($newType === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify type."));
- exit();
- } else if($newType !== 'Course-Based Research Experience' AND $newType !== 'Undergraduate Research Experience' AND $newType !== 'Test') {
- http_response_code(400);
- echo json_encode(array("error" => "Invalid type ($newType)."));
- exit();
- }
-
-
-
-
-
-
- function validDate($date) {
- $d = date_create_from_format("Y-m-d", $date);
- return $d && date_format($d, "Y-m-d") === $date;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if($newEnd === "") {
- http_response_code(400);
- echo json_encode(array("error" => "Please specify experience's end date."));
- exit();
- } else if(!validDate($newEnd)) {
- http_response_code(400);
- echo json_encode(array("error" => "Experience's end date ($newEnd) given in wrong format (use YYYY-MM-DD instead)."));
- exit();
- }
-
-
-
- $duration_seconds = strtotime($newEnd) - strtotime($newStart);
-
-
-
- if($duration_seconds <= 0) {
- http_response_code(400);
- echo json_encode(array("error" => "Experience's end date ($newEnd) must occur at least a day after the start date ($newStart)."));
- exit();
- }
-
-
-
- $duration_weeks = round($duration_seconds / 604800);
-
-
-
-
- $newDuration = mysqli_real_escape_string($connection, trim($duration_weeks));
- $query = "UPDATE `experience`
- SET `title` = '$newTitle',
- `description` = '$newDescription',
- `type` = '$newType',
- `end_date` = '$newEnd',
- `duration_weeks` = '$newDuration'
- WHERE `id` = '$id';";
- $result = mysqli_query($connection, $query) or die("Error: ".mysqli_error($connection));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
|