<?php
/*
OsShare v1 ,
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class AlbitemsController extends AppController {
var $layout = 'user';
var $name = 'Albitems';
var $helpers = array('Html', 'Form','Javascript','ajax','Pagination' ,'Time');
var $uses= array('Albitem','Alb','User','Picture','Sitesetting');
var $components = array ('Pagination');
function index() {
$this->Albitem->recursive = 0;
$this->set('albitems', $this->paginate());
}
function addtolist($id = null)
{
$data = $this->dolayout();
$usid = $data["id"];
$this->set('picid',$id);
if(!$id) {
$this->Session->setFlash('Invalid Album.');
$this->redirect(array('action'=>'index'), null, true);
}
$album_list = $this->Alb->findallbyuser_id($usid);
$this->set('alb',$album_list);
}
function add($id = null , $vdid = null)
{
$data = $this->dolayout();
$usid = $data["id"];
if(!empty($this->data)) {
$this->cleanUpFields();
$this->Albitem->create();
if($this->Albitem->save($this->data))
{
if($this->data["Albitem"]["ajax_id"] ==1 )
{
$this->layout = false;
$this->render('ajaxadd');
Configure::write('debug', '0');
return 0;
}
$this->redirect(array('action'=>'itemview',$this->data["Albitem"]["pl_id"]));
$this->Session->setFlash('Successfully Added');
}
}
// $items = $this->Albitem->findbysql('SELECT sum(precedence) from `Albitem`');
$album_items = $this->Picture->findbyid($vdid);
$album_name = $this->Alb->findbyid($id);
//debug($play_items);
$this->set('picname',$album_items);
$this->set('albname',$album_name);
/*if(($items == null) or (count($items) == 1))
//debug($items);
$this->set('preced',$items);
else
{
$items = $this->Albitem->findbypl_id($id,"sum(precedence) as sp");
//echo array_sum($items);
//$num = array_sum($items);
debug($items);
$this->set('preced',0);
$this->set('spreced',$items);
}*/
$this->set('plid',$id);
$this->set('vdid',$vdid);
}
function itemview($id = null)
{
$data = $this->dolayout();
$usid = $data["id"];
$items = $this->Albitem->findallbyalb_id($id);
$album_name = $this->Alb->findbyid($id);
$this->set('albitems',$items);
$this->set('albname',$album_name);
// debug($items);
// debug($playlist_name);
if($items == null)
{
$this->Session->SetFlash("Your Album is Empty");
}
else
{
$i=1;
foreach($items as $it)
{
//echo $it["Albitem"]["precedence"];
$it["Albitem"]["precedence"] = $i++;
$this->Albitem->save($it);
}
}
}
function playall($id = null)
{
$data = $this->dolayout();
$usid = $data["id"];
$items = $this->Albitem->findallbyalb_id($id);
if($items == null)
{
$this->Session->SetFlash("Please add the items to play");
$this->redirect(array('action'=>'index','controller'=>'albs'));
}
$album_name = $this->Alb->findbyid($id);
$rel_album = $this->Alb->findallbyuser_id($usid,"*",null,10);
// debug($rel_playlist);
$settings = $this->Sitesetting->findbyid(1);
//Social
$social = $settings['Sitesetting']['SocialTools'];
$this->set('social',$social);
//debug($social);
$this->set('albitems',$items);
$this->set('albname',$album_name);
$this->set('id',$id);
$this->set('rel_album',$rel_album);
$this->set('settings',$settings);
}
function userplayall($id = null,$usid = null)
{
$data = $this->dolayout();
$items = $this->Albitem->findallbyalb_id($id);
$album_name = $this->Alb->findbyid($id);
$rel_album = $this->Alb->findallbyuser_id($usid,"*",null,10);
// debug($rel_playlist);
$settings = $this->Sitesetting->findbyid(1);
//Social
$social = $settings['Sitesetting']['SocialTools'];
$this->set('social',$social);
//debug($social);
$this->set('albitems',$items);
$this->set('albname',$album_name);
$this->set('id',$id);
$this->set('rel_album',$rel_album);
$this->set('settings',$settings);
}
function pl_rss($id = null)
{
$items = $this->Albitem->findallbyalb_id($id);
$album_name = $this->Alb->findbyid($id);
$settings = $this->Sitesetting->findbyid(1);
$no_items = count($items);
$i=1;
foreach($items as $it)
{
//echo $it["Picture"]["user_id"];
$user_name = $this->User->findbyid($it["Picture"]["user_id"]);
$usname = 'usname'.$i;
$this->set($usname,$user_name);
//echo 'usname'.$i.'Z';
// debug($user_name);
}
$this->set('albitems',$items);
$this->set('album_name',$album_name);
$this->set('settings',$settings);
Configure::write('debug', '0');
$this->render('pl_rss','rss');
}
function image_gallery($id = null)
{
$data = $this->dolayout();
$items = $this->Albitem->findallbyalb_id($id);
$album_name = $this->Alb->findbyid($id);
$settings = $this->Sitesetting->findbyid(1);
$no_items = count($items);
$this->set('albitems',$items);
$this->set('album_name',$album_name);
$this->set('settings',$settings);
}
function operate($id = null,$albid = null,$swid = null,$opid = null)
{
$operate_item = $this->Albitem->findbyid($id);
$items = $this->Albitem->findallbyalb_id($albid);
$album_name = $this->Alb->findbyid($albid);
$this->set('albitems',$items);
$this->set('albname',$album_name);
$this->set('operate_item',$operate_item);
if(isset($swid))
{
$swap_item = $this->Albitem->findbyid($swid);
$op_item = $this->Albitem->findbyid($opid);
//debug($swap_item);
//debug($op_item);
$temp_item = $swap_item["Albitem"]["picture_id"];
$swap_item["Albitem"]["picture_id"] = $op_item["Albitem"]["picture_id"];
$this->Albitem->save($swap_item);
$op_item["Albitem"]["picture_id"] = $temp_item;
if($this->Albitem->save($op_item))
{
$this->Session->setFlash('Successfully Altred');
$this->redirect(array('action'=>'itemview',$albid));
}
else
{
$this->Session->SetFlash('Could not Move');
}
}
/*$this->set('plitems',$items);
//debug($items);
$i=1;
foreach($items as $it)
{
//echo $it["Albitem"]["precedence"];
$it["Albitem"]["precedence"] = $i++;
$this->Albitem->save($it);
}*/
}
function operate_up($id = null,$albid = null,$preced_id = null)
{
$operate_item = $this->Albitem->findbyid($id);
$items = $this->Albitem->findallbyalb_id($albid);
// $tpre = $operate_item["Albitem"]["precedence"];
if($preced_id == 1)
{
$preced_id = count($items);
$condition = "`Albitem`.precedence=".$preced_id . " AND `Albitem`.alb_id=".$albid;
}
else
{
$preced_id = $preced_id - 1;
$condition = "`Albitem`.precedence=".$preced_id . " AND `Albitem`.alb_id=".$albid;
}
// $tpre = tpre - 1;
// debug($tpre);
// die();
$swap_item = $this->Albitem->find($condition);
$temp_item = $swap_item["Albitem"]["picture_id"];
$swap_item["Albitem"]["picture_id"] = $operate_item["Albitem"]["picture_id"];
$this->Albitem->save($swap_item);
$operate_item["Albitem"]["picture_id"] = $temp_item;
if($this->Albitem->save($operate_item))
{
$this->Session->setFlash('Successfully Altred');
$this->redirect(array('action'=>'itemview',$albid));
}
else
{
$this->Session->SetFlash('Could not Move');
}
}
function operate_down($id = null,$albid = null,$preced_id = null)
{
$operate_item = $this->Albitem->findbyid($id);
$items = $this->Albitem->findallbyalb_id($albid);
// $tpre = $operate_item["Albitem"]["precedence"];
if($preced_id == count($items))
{
$condition = "`Albitem`.precedence=1 AND `Albitem`.alb_id=".$albid;
}
else
{
$preced_id = $preced_id + 1;
$condition = "`Albitem`.precedence=".$preced_id . " AND `Albitem`.alb_id=".$albid;
}
// $tpre = tpre - 1;
// debug($tpre);
// die();
$swap_item = $this->Albitem->find($condition);
$temp_item = $swap_item["Albitem"]["picture_id"];
$swap_item["Albitem"]["picture_id"] = $operate_item["Albitem"]["picture_id"];
$this->Albitem->save($swap_item);
$operate_item["Albitem"]["picture_id"] = $temp_item;
if($this->Albitem->save($operate_item))
{
$this->Session->setFlash('Successfully Altred');
$this->redirect(array('action'=>'itemview',$albid));
}
else
{
$this->Session->SetFlash('Could not Move');
}
}
function removeitem($id = null,$albid = null)
{
if(!$id) {
$this->Session->setFlash('Could not Be Deleted');
$this->redirect(array('action'=>'itemview',$albid));
}
if($this->Albitem->del($id)) {
$this->Session->setFlash('Item deleted');
$this->redirect(array('action'=>'itemview',$albid));
}
}
/*function add($id = null , $vdid = null)
{
if(!empty($this->data)) {
$this->cleanUpFields();
$this->Albitem->create();
if($this->Albitem->save($this->data))
{
$this->Session->setFlash('Successfully Added');
$this->redirect(array('action'=>'index'), null, true);
}
}
$items = $this->Albitem->findallbypl_id($id);
//debug($items);
if($items == null)
$this->set('preced',1);
else
{
$num = count($items) + 1;
$this->set('preced',$num);
}
$this->set('plid',$id);
$this->set('vdid',$vdid);
}*/
}
?>