Location: PHPKode > projects > OSShare > osshare-project-v1.0.1/app/controllers/pcomments_controller.php
<?php
/*
OsShare v1 , 
Coded By Paimpozhil B. , SaravanaKumar M.S.
*/
class PcommentsController extends AppController {
	
	var $name = 'Pcomments';
	var $helpers = array('Html', 'Form' ,'javascript','ajax', 'time');
	var $uses= array('Pcomment','Picture','Sitesetting');

	function index() {
		$this->Pcomment->recursive = 0;
		$this->set('pcomments', $this->paginate());
	}

	function view($id = null) {
		if(!$id) {
			$this->Session->setFlash('Invalid Comment.');
			$this->redirect(array('action'=>'index'), null, true);
		}
		$this->set('pcomment', $this->Pcomment->read(null, $id));
	}

	function add() {
		if(!empty($this->data)) {
			$this->cleanUpFields();
			$this->Pcomment->create();
			if($this->Pcomment->save($this->data)) {
				$this->Session->setFlash('The comment has been saved');
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash('The comment could not be saved. Please, try again.');
			}
		}
		$pictures = $this->Pcomment->Picture->find('list');
		$this->set(compact('pictures'));
	}

	function edit($id = null) {
		if(!$id && empty($this->data)) {
			$this->Session->setFlash('Invalid comment');
			$this->redirect(array('action'=>'index'), null, true);
		}
		if(!empty($this->data)) {
			$this->cleanUpFields();
			if($this->Pcomment->save($this->data)) {
				$this->Session->setFlash('The comment saved');
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash('The comment could not be saved. Please, try again.');
			}
		}
		if(empty($this->data)) {
			$this->data = $this->Pcomment->read(null, $id);
		}
		$pictures = $this->Pcomment->Picture->find('list');
		$this->set(compact('pictures'));
	}

	function delete($id = null) {
		if(!$id) {
			$this->Session->setFlash('Invalid id for comment');
			$this->redirect(array('action'=>'index'), null, true);
		}
		
		if($this->Pcomment->del($id)) {
			$this->Session->setFlash('Pcomment #'.$id.' deleted');
			$this->redirect(array('action'=>'index'), null, true);
			
		}
	}
	
	function abuse($id = null) {
		if(!$id) {
			$this->Session->setFlash('Invalid id for comment');
			$this->redirect(array('action'=>'index'), null, true);
		}
		$data = $this->Session->read('User');
		$priv = $data["privilege"];
		if ($priv=='user')
			$abval = 1;	
		elseif ($priv =='admin')
			$abval = 5;
		elseif ($priv == 'mod')
			$abval = 3;
		$comment = $this->Pcomment->findbyid($id);
		$comment["Pcomment"]["abusepoints"] +=  $abval;
		$this->Pcomment->save($comment);
		$this->Session->setFlash('Abuse Reported ');
		$this->redirect(array('action'=>'index'), null, true);
		
	}
	
	function partview($id=null)
	{
		$data = $this->Session->read('User');
	$this->set('pcomments',$this->Pcomment->findallbypicture_id($id));
	$this->set('picture', $this->Picture->read(null, $id));
	$this->set('user',$data);
	$this->layout= false;
	 Configure::write('debug', '0');
	}
}
?>
Return current item: OSShare