|
@@ -44,7 +44,7 @@ class Gallery extends Controller {
|
|
}
|
|
}
|
|
|
|
|
|
public function CreateAlbum($title,$description) {
|
|
public function CreateAlbum($title,$description) {
|
|
- Breadcrumbs::Add("Manage", "");
|
|
|
|
|
|
+ Breadcrumbs::Add("Manage", "/gallery/manage/");
|
|
Breadcrumbs::Add("Create Album", "");
|
|
Breadcrumbs::Add("Create Album", "");
|
|
$album=new Album();
|
|
$album=new Album();
|
|
if (isset($title))
|
|
if (isset($title))
|
|
@@ -59,44 +59,48 @@ class Gallery extends Controller {
|
|
return new View("Gallery/create_album.view",array("album"=>$album));
|
|
return new View("Gallery/create_album.view",array("album"=>$album));
|
|
}
|
|
}
|
|
|
|
|
|
- public function Upload($imageTitle,$imageDesc) {
|
|
|
|
- if (!isset($_FILES['imageFile'])){
|
|
|
|
- header("location: /gallery/manage/");
|
|
|
|
|
|
+ public function Upload(){
|
|
|
|
+ Breadcrumbs::Add("Manage", "/gallery/manage/");
|
|
|
|
+ Breadcrumbs::Add("Upload", "");
|
|
|
|
+ return new View("Gallery/upload.view", array("maxUploadSize"=>Utils::GetMaxUploadSize()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function UploadImages($title, $description){
|
|
|
|
+ if (count($title)==0)
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
- $errors=array();
|
|
|
|
- $filename=$_FILES['imageFile']['name'];
|
|
|
|
- $tempFile=$_FILES['imageFile']['tmp_name'];
|
|
|
|
- if ($imageTitle=="")
|
|
|
|
- $errors[]="The image doesn't have a title";
|
|
|
|
- if ($_FILES['imageFile']['error'])
|
|
|
|
- $errors[]=Utils::FileUploadErrorToMessage($_FILES['imageFile']['error']);
|
|
|
|
- if (count($errors)==0) {
|
|
|
|
- if(!Image::IsValidType(pathinfo($filename,PATHINFO_EXTENSION)))
|
|
|
|
- $errors[]="File is of an invalid type";
|
|
|
|
- if (getimagesize($tempFile)===false)
|
|
|
|
- $errors[]="File is not an image";
|
|
|
|
- }
|
|
|
|
- $image=new Image($filename,$tempFile);
|
|
|
|
- $image->ImageTitle=$imageTitle;
|
|
|
|
- $image->ImageDescription=$imageDesc;
|
|
|
|
- if (count($errors)==0){
|
|
|
|
|
|
+
|
|
|
|
+ $allErrors=array();
|
|
|
|
+ $uploadedImages=array();
|
|
|
|
+ $files=$_FILES['files'];
|
|
|
|
+ foreach ($files['tmp_name'] as $index=>$tempFile) {
|
|
|
|
+ $filename=$files['name'][$index];
|
|
|
|
+ $imageTitle=$title[$index];
|
|
|
|
+ $errors=array();
|
|
|
|
+
|
|
|
|
+ if ($imageTitle=="")
|
|
|
|
+ $errors[]="The image $filename doesn't have a title";
|
|
|
|
+ if ($files['error'][$index])
|
|
|
|
+ $errors[]=Utils::FileUploadErrorToMessage($files['error'][$index]);
|
|
|
|
+
|
|
|
|
+ if (count($errors)==0) {
|
|
|
|
+ if(!Image::IsValidType(pathinfo($filename,PATHINFO_EXTENSION)))
|
|
|
|
+ $errors[]="File is of an invalid type";
|
|
|
|
+ if (getimagesize($tempFile)===false)
|
|
|
|
+ $errors[]="File is not an image";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (count($errors)>0){
|
|
|
|
+ $allErrors=array_merge($allErrors, $errors);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ $uploadedImages[]=$index;
|
|
|
|
+
|
|
|
|
+ $image=new Image($filename,$tempFile);
|
|
|
|
+ $image->ImageTitle=$imageTitle;
|
|
|
|
+ $image->ImageDescription=$description[$index];
|
|
$image->Save();
|
|
$image->Save();
|
|
- header("location: /gallery/manage/");
|
|
|
|
- return;
|
|
|
|
}
|
|
}
|
|
- return $this->Manage(array("errors"=>$errors,"image"=>$image));
|
|
|
|
- }
|
|
|
|
|
|
|
|
- public function JsonLoadAlbum($albumId) {
|
|
|
|
- $repo=new ImageRepository();
|
|
|
|
- $json='[';
|
|
|
|
- $images=$repo->GetImagesByAlbum($albumId);
|
|
|
|
- foreach ($images as $image)
|
|
|
|
- $json.='{"ImageId":"'.$image->ImageId.'","ImageTitle":"'.$image->ImageTitle.'","Path":"'.$image->Path.'","ThumbnailPath":"'.$image->ThumbnailPath.'"},';
|
|
|
|
- $json=trim($json,',');
|
|
|
|
- $json.=']';
|
|
|
|
- return $json;
|
|
|
|
- //return json_encode($images);
|
|
|
|
|
|
+ return json_encode(array("errors"=>$allErrors, "uploaded"=>$uploadedImages));
|
|
}
|
|
}
|
|
}
|
|
}
|