public function post() { $car = new CarModel($_POST['guid']); $car->setMake($_POST['make']); $car->setModel($_POST['model']); $car->setYear($_POST['year']); $car->setImage($_POST['image']); // Save picture of the car if picture submitted if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { // Replace the existing image with a new image of a car if (isset($_POST['image']) && !empty($_POST['image'])) { parent::deleteFile($_POST['image']); } parent::saveFile(); $path = 'uploads/' . $_FILES['file']['name']; $car->setImage($path); $car->save(); } else { if (isset($_POST['delete'])) { // Delete the car and its image $car->delete(); parent::deleteFile($_POST['image']); } else { $car->save(); } } if (headers_sent()) { die('Redirect failed. Please go back to home page'); } else { exit(header('Location: index.php')); } }
public function post() { // Save the CSV file if submitted if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { parent::saveFile(); } if (headers_sent()) { die('Redirect failed. Please go back to home page'); } else { exit(header('Location: index.php?page=importcsv')); } }
public function post() { if ($_POST['form']) { $clean = array(); $clean['vin'] = parent::sanitizeString($_POST['vin']); $clean['price'] = parent::sanitizeString($_POST['price']); $clean['condition'] = parent::sanitizeString($_POST['condition']); $clean['img_url'] = parent::sanitizeString($_POST['img_url']); $carCollection = new CarCollection(); $car = $carCollection->create(); $car->setVin($clean['vin']); // Delete the car if delete button was clicked/submitted if (isset($_POST['delete'])) { $message = ''; $type = 'danger'; if ($car->delete()) { $message = 'Congratulations! You\'ve successfully deleted the car.'; $type = 'success'; } else { $message = 'Something went wrong. Please go back and try again'; } $notification = new NotificationsView($message, $type); exit; } $car->setPrice($clean['price']); $car->setCondition($clean['condition']); // Save a new file image if submitted if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { parent::saveFile(); $path = 'uploads/' . $_FILES['file']['name']; $car->setImageUrl($path); } else { $car->setImageUrl($clean['img_url']); } $message = ''; $type = 'danger'; if ($car->update()) { $message = 'You\'ve successfully updated the information about the car.'; $type = 'success'; } else { $message = 'Something went wrong. Please go back and try again.'; } $notification = new NotificationsView($message, $type); } else { $message = 'Something went wrong. Please go back and try again.'; $type = 'danger'; $notification = new NotificationsView($message, $type); } }
public function post() { $car = new CarModel(); $car->setMake($_POST['make']); $car->setModel($_POST['model']); $car->setYear($_POST['year']); // Save picture of the car if picture submitted if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { $src = parent::saveFile(); $path = 'uploads/' . $_FILES['file']['name']; $car->setImage($path); $car->save(); } else { $car->save(); } // Redirect if (headers_sent()) { die('Redirect failed. Please go back to home page'); } else { exit(header('Location: index.php')); } }
public function post() { $success = true; if ($_POST['form']) { $allowed = array(); $allowed[] = 'form'; $allowed[] = 'vin'; $allowed[] = 'price'; $allowed[] = 'condition'; $sent = array_keys($_POST); if ($allowed == $sent) { if (isset($_POST['form']) && isset($_POST['vin']) && isset($_POST['price']) && isset($_POST['condition']) && isset($_FILES['file']) && $_FILES['file']['size'] > 0) { // Check if the toekn from form matches the one saved in the session if (isset($_SESSION['token']) && $_POST['form'] != $_SESSION['token']) { $message = 'Something went wrong. Please try again.'; $success = false; } // Grab details from the API $clean_vin = parent::sanitizeString($_POST['vin']); $carDetails = parent::getCarsDetails($clean_vin); // If the reponse from the API is an error if (isset($carDetails->errorType) && $carDetails->errorType == 'INCORRECT_PARAMS' || isset($carDetails->status) && $carDetails->status == 'NOT_FOUND') { $message = 'Oops! Something went wrong! Please try again with a different VIN.'; $success = false; } // If the checks fail if (!$success) { $notification = new NotificationsView($message, 'danger'); unset($_SESSION['token']); unset($_SESSION['digit']); exit; } // Variables $clean_price = parent::sanitizeString($_POST['price']); $clean_cond = parent::sanitizeString($_POST['condition']); // Save the picture parent::saveFile(); $path = 'uploads/' . $_FILES['file']['name']; $carCollection = new CarCollection(); $car = $carCollection->create(); $car->setVin($clean_vin); $car->setMake($carDetails->make->name); $car->setModel($carDetails->model->name); $car->setYear($carDetails->years[0]->year); $car->setPrice($clean_price); $car->setCondition($clean_cond); $car->setImageUrl($path); $car->setCreatedBy($_SESSION['user_session']); if ($car->save()) { $message = 'Congratulations! You\'ve successfully added a new car.'; $success = true; } else { $message = 'Could not save the car right now. Please try again later.'; $success = false; } } else { $message = 'Something is missing. Please make sure you\'ve specified all input fields'; $success = false; } } else { $message = 'Something went wrong. Please try again.'; $success = false; } } else { $message = 'Something went wrong. Please try again.'; $success = false; } unset($_SESSION['token']); unset($_SESSION['digit']); if ($success) { $type = 'success'; } else { $type = 'danger'; } $notification = new NotificationsView($message, $type); }