|
@@ -36,12 +36,59 @@ if($submit) {
|
|
|
if(empty($location->latitude)) $form_exception->addError("Map location is required.");
|
|
if(empty($location->latitude)) $form_exception->addError("Map location is required.");
|
|
|
else if(empty($location->longitude)) $form_exception->addError("Map location is required.");
|
|
else if(empty($location->longitude)) $form_exception->addError("Map location is required.");
|
|
|
|
|
|
|
|
|
|
+ // Photo
|
|
|
|
|
+ $photo = (object) $_FILES["photo"];
|
|
|
|
|
+ if($photo->error != UPLOAD_ERR_NO_FILE) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if($photo->error != UPLOAD_ERR_OK) throw new Exception(HTTP::getUploadErrorString($photo->error));
|
|
|
|
|
+ if(!Image::isJPEG($photo->tmp_name)) throw new Exception("Photo is not a JPEG image.");
|
|
|
|
|
+
|
|
|
|
|
+ // Photo OK
|
|
|
|
|
+ $file = new LocationFile;
|
|
|
|
|
+ $file->location_id = $id;
|
|
|
|
|
+ $file->type = LocationFile::TYPE_PHOTO;
|
|
|
|
|
+ $file->dts_uploaded = Util::getDateTime();
|
|
|
|
|
+ $file->commit();
|
|
|
|
|
+
|
|
|
|
|
+ $id = $file->id;
|
|
|
|
|
+
|
|
|
|
|
+ $directory = $location->getDirectory();
|
|
|
|
|
+ $file_path = $directory . "/$id.jpg";
|
|
|
|
|
+
|
|
|
|
|
+ $output_image = Image::normalise($photo->tmp_name);
|
|
|
|
|
+ $success = imagejpeg($output_image, $file_path);
|
|
|
|
|
+ imagedestroy($output_image);
|
|
|
|
|
+ if(!$success) throw new Exception("Failed to save photo.");
|
|
|
|
|
+ }
|
|
|
|
|
+ catch(Exception $e) {
|
|
|
|
|
+ $form_exception->addError($e->getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Delete Photos
|
|
|
|
|
+ $delete_file_ids = http::value("delete_file_ids", "int");
|
|
|
|
|
+ $files = LocationFile::query([
|
|
|
|
|
+ "id" => $delete_file_ids,
|
|
|
|
|
+ "location_id" => $id,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ if($files) {
|
|
|
|
|
+ $directory = $location->getDirectory();
|
|
|
|
|
+ foreach($files as $file) {
|
|
|
|
|
+ $pattern = $directory . "/$file->id.*";
|
|
|
|
|
+ foreach(glob($pattern) as $path) {
|
|
|
|
|
+ unlink($path);
|
|
|
|
|
+ }
|
|
|
|
|
+ $file->delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
if($form_exception->hasErrors()) throw $form_exception;
|
|
if($form_exception->hasErrors()) throw $form_exception;
|
|
|
|
|
|
|
|
$success = $location->commit();
|
|
$success = $location->commit();
|
|
|
|
|
|
|
|
Core::addAlert("success", "Location updated successfully.");
|
|
Core::addAlert("success", "Location updated successfully.");
|
|
|
- HTTP::redirect("/account/locations/$location->id");
|
|
|
|
|
|
|
+ HTTP::redirect("/account/locations/$location->id/edit");
|
|
|
}
|
|
}
|
|
|
catch(FormException $e) {
|
|
catch(FormException $e) {
|
|
|
$e->generateAlerts();
|
|
$e->generateAlerts();
|
|
@@ -51,6 +98,11 @@ if($submit) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+$photos = LocationFile::query([
|
|
|
|
|
+ "location_id" => $id,
|
|
|
|
|
+ "type" => LocationFile::TYPE_PHOTO
|
|
|
|
|
+]);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
Core::addBreadcrumb("/account", "Account");
|
|
Core::addBreadcrumb("/account", "Account");
|
|
|
Core::addBreadcrumb("/account/locations", "Locations");
|
|
Core::addBreadcrumb("/account/locations", "Locations");
|
|
@@ -59,7 +111,7 @@ Core::addBreadcrumb("/account/locations/$id", $location->name);
|
|
|
Core::addBreadcrumb("/account/locations/$id/edit", $page_title);
|
|
Core::addBreadcrumb("/account/locations/$id/edit", $page_title);
|
|
|
|
|
|
|
|
View::includeOnce("header", compact("page_title"));
|
|
View::includeOnce("header", compact("page_title"));
|
|
|
-View::include("location_edit_form", compact("location"));
|
|
|
|
|
|
|
+View::include("location_edit_form", compact("location", "photos"));
|
|
|
View::includeOnce("footer");
|
|
View::includeOnce("footer");
|
|
|
|
|
|
|
|
?>
|
|
?>
|