container = $container; $this->params = $params; } function showRender($p){ $album = $this->container->models['user_albums']->get($p['id']); if (!$album) redirect('/'); $template = array( "subpage" => "show", "album" => $album, "photos" => $album->photos, "user" => $this->container->user, "myself" => ($album->user->id==$this->container->user->id) ); $this->container->template->set($template); } function editRender($p){ $album = $this->container->models['user_albums']->get($p['id']); if (!$album) redirect('/'); $template = array( "subpage" => "edit", "album" => $album, "user" => $this->container->user, "countries" => $this->container->models['countries']->select(array(),'*','ORDER BY name'), "myself" => ($album->user->id==$this->container->user->id) ); $this->container->template->set($template); } function updateRender($p){ $album = $this->container->models['user_albums']->get($p['id']); if (!$album) redirect('/'); $a=array("controller" => "albums", "action" => "update_album", "user_id" => $this->container->user->id, "id" => $album->id, "name" => $_POST["album_name"], "description" => $_POST["description"], "country_id" => isset($_POST["country_id"])?$_POST["country_id"]:'' ); $resp = $this->container->api->call($a); redirect(route('album', 'show', $album->id)); } function uploadRender($p){ //Validate if (!$_FILES["img"]) redirect('/'); $album = $this->container->models['user_albums']->get($p['id']); if (!$album) redirect('/'); if ($album->user->id!=$this->container->user->id) redirect('/'); $cnt=0; foreach ($_FILES["img"]["tmp_name"] as $imgi => $imgtmpname){ $cnt++; if (!file_exists($imgtmpname)){ $this->container->log("AlbumController file ".$imgtmpname." not found by user #".nalogovan(), 'ERROR'); $this->container->flash->error(d('file_not_found')); $this->container->flash->keep(); redirect('/'); } } if ($cnt==0) return false; $user = $album->user; $last_photo = false; foreach ($_FILES["img"]["name"] as $imgi => $imgname){ $url = $_FILES["img"]["tmp_name"][$imgi]; $h = array("name" => '', "type_id" => PHOTO_TYPE_USER_ALBUM ); //Create photo $photo = $this->container->models['photos']->download($url, $h); if (!$photo) continue; $photo->setOwner($user); $album->addPhoto($photo); $last_photo=$photo; $this->container->log("Photo ".$imgname." uploaded by user #".$user->id); } if ($last_photo){ $album->recountPhotos(); $user->recountAlbumPhotos(); //$user->update(array('photos_cnt' => ($user->photos_cnt | 0) + $cnt)); $album->setMainPhoto($last_photo); if ($post = $last_photo->post) $post->setMainPhoto($last_photo); } //Post to the wall //TODO: # $o=array_merge($h, array("user_id" => $album->user->id, "market_id" => $album->user->market_id, "type" => WALL_TYPE_PHOTO)); # $this->container->models['wall']->post($o); redirect(route('album','show',$album->id)); } function deleteRender($p){ $album = $this->container->models['user_albums']->get($p['id']); if (!$album){ $this->container->log("Album->deleteRender: Album #".$p['id']." doesn't exist",'WARN'); redirect('/'); } if ($album->user->id!=nalogovan()){ $this->container->log("Album->deleteRender: Album is #".$album->user->id."'s but not #".nalogovan()."'s",'WARN'); redirect('/'); } $a = array("controller" => "albums", "action" => "delete", "user_id" => nalogovan(), "id" => $album->id ); $resp = $this->container->api->call($a); redirect(route('user','photos',nalogovan())); } } ?>