<?php
/*
OsShare v1 ,
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class CategoriesController extends AppController {
var $layout = 'admin';
var $name = 'Categories';
var $helpers = array('Html', 'Form','Javascript','ajax','Pagination' ,'Time','Cache');
var $uses = array('Category','Video','Picture');
var $components = array('Pagination');
function index() {
$this->recursive = 0;
$this->set('categories', $this->Category->findall());
// debug($this->paginate());
}
function view($id = null) {
$data = $this->Session->read('User');
$priv = $data["privilege"];
if ($priv=='user')
$this->layout = "user";
elseif ($priv =='admin')
$this->layout = "admin";
else
$this->layout = "default";
$categories = Cache::read('categories');
if($categories == false)
{
$categories = $this->Category->findall();
Cache::write('categories',$categories,'+1 hour');
}
$categories = $this->fix_width($categories,'Category','name',10);
$this->set('categories',$categories);
// $this->set('categories',$this->Category->findall());
$data = $this->Session->read('User');
$priv = $data["privilege"];
if ($priv=='user')
$this->layout = "user";
elseif ($priv =='admin')
$this->layout = "admin";
else
$this->layout = "default";
if(!$id) {
$this->Session->setFlash('Category Unavailable , Sorry');
$this->redirect(array('controller'=>'pages','action'=>'index'), null, true);
}
$condition = "`Video`.is_encoded = 1 AND `Category`.id = " . $id;
// debug($this->Category->Video->findall("`Category`.id = " . $id));
$this->Pagination->total = $this->Category->Video->findcount($condition);
list($order,$limit,$page) = $this->Pagination->init($condition,array(''=>$id),array('page'=>$this->page,'show'=>$this->show));
$cvideos = $this->Category->Video->findall($condition,NULL,NULL,$limit,$page);
$cvideos = $this->fix_width($cvideos,'Video','name',10);
$cvideos = $this->fix_width($cvideos,'User','username',5);
$this->set('cvideos',$cvideos);
// $this->set('cvideos',$this->Category->Video->findall($condition,NULL,NULL,$limit,$page));
$this->set('id',$id);
//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 pview($id = null) {
$categories = $this->Category->findall();
$categories = $this->fix_width($categories,'Category','name',10);
$this->set('categories',$categories);
$data = $this->Session->read('User');
$priv = $data["privilege"];
if ($priv=='user')
$this->layout = "user";
elseif ($priv =='admin')
$this->layout = "admin";
else
$this->layout = "default";
if(!$id) {
$this->Session->setFlash('Category Unavailable , Sorry');
$this->redirect(array('controller'=>'pages','action'=>'index'), null, true);
}
$condition = "`Picture`.is_corrupted = 1 AND `Category`.id = " . $id;
// debug($this->Category->Video->findall("`Category`.id = " . $id));
$this->Pagination->total = $this->Category->Picture->findcount($condition);
list($order,$limit,$page) = $this->Pagination->init($condition,array(''=>$id),array('page'=>$this->page,'show'=>$this->show));
$cpictures = $this->Category->Picture->findall($condition,NULL,NULL,$limit,$page);
$cpictures = $this->fix_width($cpictures,'Picture','name',10);
$cpictures = $this->fix_width($cpictures,'User','username',5);
$this->set('cpictures',$cpictures);
$this->set('id',$id);
//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 rview($id = null) {
$data = $this->Session->read('User');
$priv = $data["privilege"];
if ($priv=='user')
$this->layout = "user";
elseif ($priv =='admin')
$this->layout = "admin";
else
$this->layout = "default";
$categories = $this->Category->findall(NULL,NULL,NULL,NULL,NULL,0);
$videos[]=NULL;
foreach(array_keys($categories) as $key)
{
$category =& $categories[$key];
if ($this->Category->Video->findcount("`Video`.is_encoded = 1 AND `Category`.id = " . $category["Category"]["id"] , NULL, "`Video`.views Desc",NULL,NULL,0)>0){
$category["Video"] = $this->Category->Video->find("`Video`.is_encoded = 1 AND `Category`.id = " . $category["Category"]["id"] , NULL, "`Video`.views Desc",NULL,NULL,0);
$videos[$category['Category']['id']] = $category["Video"];
}
else
{
$category["Video"]["Category"]["name"]='';
$category["Video"]["Video"]["name"]="";
$category["Video"]["User"]["username"]="";
}
}
$categories = $this->fix_width($categories,'Category','name',10);
$categories = $this->fix_width_cate($categories,'Video','Video','name',10);
$categories = $this->fix_width_cate($categories,'Video','User','username',5);
// debug($categories);
$this->set('categories',$categories);
$data = $this->dolayout();
// debug($videos);
$this->set('cvideos',$videos );
//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"]);
Configure::write('debug', '0');
$this->render('rss','rss');
}
}
}
function prview($id = null) {
$categories = $this->Category->findall(NULL,NULL,NULL,NULL,NULL,0);
$pictures[]=NULL;
foreach(array_keys($categories) as $key)
{
$category =& $categories[$key];
if ($this->Category->Picture->findcount("`Picture`.is_corrupted = 1 AND `Category`.id = " . $category["Category"]["id"] , NULL, "`Picture`.views Desc",NULL,NULL,0)>0){
$category["Picture"] = $this->Category->Picture->find("`Picture`.is_corrupted = 1 AND `Category`.id = " . $category["Category"]["id"] , NULL, "`Picture`.views Desc",NULL,NULL,0);
$picures[$category['Category']['id']] = $category["Picture"];
}
else
{
$category["Picture"]["Category"]["name"]='';
$category["Picture"]["Picture"]["name"]="";
$category["Picture"]["User"]["username"]="";
}
}
// debug($videos);
$categories = $this->fix_width($categories,'Category','name',10);
$categories = $this->fix_width_cate($categories,'Picture','Picture','name',10);
$categories = $this->fix_width_cate($categories,'Picture','User','username',5);
$this->set('categories',$categories);
$data = $this->dolayout();
// debug($videos);
// $this->set('cpictures',$pictures);
//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"]);
Configure::write('debug', '0');
$this->render('rss','rss');
}
}
}
function add() {
if(!empty($this->data)) {
$this->cleanUpFields();
$this->Category->create();
if($this->Category->save($this->data)) {
$this->Session->setFlash('The Category has been saved');
clearCache('index.php');
$this->redirect(array('action'=>'index'), null, true);
} else {
$this->Session->setFlash('The Category could not be saved. Please, try again.');
}
}
}
function edit($id = null) {
if(!$id && empty($this->data)) {
$this->Session->setFlash('Invalid Category');
$this->redirect(array('action'=>'index'), null, true);
}
if(!empty($this->data)) {
$this->cleanUpFields();
if($this->Category->save($this->data)) {
$this->Session->setFlash('The Category saved');
clearCache('index.php');
$this->redirect(array('action'=>'index'), null, true);
} else {
$this->Session->setFlash('The Category could not be saved. Please, try again.');
}
}
if(empty($this->data)) {
$this->data = $this->Category->read(null, $id);
}
}
function delete($id = null) {
if(!$id) {
$this->Session->setFlash('Invalid id for Category');
$this->redirect(array('action'=>'index'), null, true);
}
if($this->Category->del($id)) {
$this->Session->setFlash('Category #'.$id.' deleted');
clearCache('index.php');
$this->redirect(array('action'=>'index'), null, true);
}
}
}
?>