<?php
/*
OsShare v1 ,
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class PfavoritesController extends AppController {
var $name = 'Pfavorites';
var $helpers = array('Html', 'Form','Javascript','ajax','Pagination' ,'Time' );
var $uses = array('Pfavorite','Picture','User');
var $components = array ('Pagination');
function index() {
$this->Pfavorite->recursive = 0;
$this->set('favorites', $this->paginate());
}
function pview($id = null) {
$data = $this->dolayout();
if(!$id) {
$id = $data['id'];
}
$condition = "`Category`.id = " . $id;
// debug($this->Category->Video->findall("`Category`.id = " . $id));
$condition =" `Picture`.is_corrupted = 1 AND `Pfavorite`.user_id = " . $id;
list($order,$limit,$page) = $this->Pagination->init($condition,array(''=>$id),array('page'=>$this->page,'show'=>$this->show));
$this->set('favpictures',$this->Pfavorite->findall($condition,NULL,NULL,$limit,$page));
$this->set('id',$id);
$user = $this->User->findbyid($id);
$this->set('username',$user['User']['username']);
//rss
if(isset($this->params["named"]["output"]))
{
Configure::write('debug', '0');
if($this->params["named"]["output"]=="rss")
{
$setting = $this->Sitesetting->findbyid(1);
$this->set("ssetting",$setting["Sitesetting"]);
$this->render('rss','rss');
}
}
}
function add() {
if(!empty($this->data)) {
$this->cleanUpFields();
$Pfavorite = $this->Pfavorite->findcount("`Pfavorite`.user_id = " . $this->data["Pfavorite"]["user_id"] . " and `Pfavorite`.picture_id = " . $this->data["Pfavorite"]["picture_id"]) ;
if ((int)$Pfavorite > 0 )
{
$this->Session->setFlash('Try Harder to Favit again');
die();
}
$this->Pfavorite->create();
if($this->Pfavorite->save($this->data)) {
$this->Session->setFlash('The Favorite has been saved');
Configure::write('debug', '0');
$this->layout= false;
$this->render('thankyou');
} else {
$this->Session->setFlash('The Favorite could not be saved. Please, try again.');
}
}
$users = $this->Pfavorite->User->find('list');
$pictures = $this->Pfavorite->Picture->find('list');
$this->set(compact('users', 'pictures'));
}
function edit($id = null) {
if(!$id && empty($this->data)) {
$this->Session->setFlash('Invalid favorite');
$this->redirect(array('action'=>'index'), null, true);
}
if(!empty($this->data)) {
$this->cleanUpFields();
if($this->Pfavorite->save($this->data)) {
$this->Session->setFlash('The favorite saved');
$this->redirect(array('action'=>'index'), null, true);
} else {
$this->Session->setFlash('The favorite could not be saved. Please, try again.');
}
}
if(empty($this->data)) {
$this->data = $this->Pfavorite->read(null, $id);
}
$users = $this->Pfavorite->User->find('list');
$pictures = $this->Pfavorite->Picture->find('list');
$this->set(compact('users','pictures'));
}
function delete($id = null) {
if(!$id) {
$this->Session->setFlash('Invalid id for favorite');
$this->redirect(array('action'=>'index'), null, true);
}
$Pfavorite = $this->Pfavorite->findbyid($id);
$data = $this->Session->read('User');
$priv = $data["privilege"];
if($data['id'] != $Pfavorite["Pfavorite"]["user_id"])
die();
if($this->Pfavorite->del($id)) {
$this->Session->setFlash('Pfavorite #'.$id.' deleted');
Configure::write('debug', '0');
$this->layout= false;
$this->render('removed');
}
}
}
?>