|
|
@@ -51,52 +51,54 @@ if($submit) {
|
|
|
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());
|
|
|
+ if(Core::$user->isAdmin()) {
|
|
|
+ $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);
|
|
|
+ // 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();
|
|
|
}
|
|
|
- $file->delete();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if($form_exception->hasErrors()) throw $form_exception;
|
|
|
$success = $location->commit();
|
|
|
if(!$success) throw new Exception("Failed to edit location at this time. Please try again later.");
|
|
|
@@ -132,5 +134,3 @@ Core::addBreadcrumb("/account/locations/$id/edit", $page_title);
|
|
|
View::includeOnce("header", compact("page_title"));
|
|
|
View::include("location_form", compact("location", "photos"));
|
|
|
View::includeOnce("footer");
|
|
|
-
|
|
|
-?>
|