<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
class AbookControllerBook extends AbookController
{
function __construct()
{
//echo "controller: book; action: construct<br>";var_dump($_POST);var_dump(JRequest: :get('post'));exit();
parent::__construct();
// Register Extra tasks
$this->registerTask( 'add' , 'edit' );
$this->registerTask( 'apply', 'save' );
$this->registerTask( 'accesspublic', 'access' );
$this->registerTask( 'accessregistered','access' );
$this->registerTask( 'accessspecial', 'access' );
$this->registerTask( 'resethits', 'save' );
$this->registerTask( 'resetrates', 'resetrates' );
}
function display()
{
//echo "controller: book; action: display<br>";var_dump($_POST);var_dump(JRequest::g et('post'));exit();
global $mainframe, $option;
JRequest::setVar( 'view', 'books' );
parent::display();
}
function edit()
{
//echo "controller: book; action: edit<br>";var_dump($_POST);var_dump(JRequest::get( 'post'));exit();
JRequest::setVar( 'view', 'book' );
JRequest::setVar( 'layout', 'form' );
JRequest::setVar('hidemainmenu', 1);
// Checkout
$model = $this->getModel('book');
$model->checkout();
parent::display();
}
function save()
{
//echo "controllers: book; action: save<br>";var_dump($_POST);var_dump(JRequest::get( 'post'));exit();
JRequest::checkToken() or die( 'Invalid Token' );
global $mainframe;
$model = $this->getModel('book');
$post = JRequest::get('post');
$task = JRequest::getCmd( 'task' );
//aggiungo anche l'id che è uguale al cid, perchè come campo hidden del form devo mettere per forza cid sennò non funziona il checkin
$post['id'] = JRequest::getVar( 'cid', '', 'post', 'int' );
$post['html'] = JRequest::getVar('html', '', 'post', 'string', JREQUEST_ALLOWRAW);
$catid= JRequest::getVar('catid', array(), 'post', 'array');
if (is_array( $catid)) {
$post['catid'] = implode( ",", $catid);
}
$idbookbook= JRequest::getVar('bookbook', array(), 'post', 'array', JREQUEST_ALLOWRAW);
//var_dump($idbookbook);exit();
//var_dump($_POST);exit();
if ($task=='resethits'){
$post['hits'] = 0;
}
if ($returnid = $model->store($post)) {
$model->storeauthor($returnid, $post['idauth']);
$model->storebookbook($returnid, $post['idbookbook']);
switch ($task){
case 'resethits':
case 'apply':
$link = 'index.php?option=com_abook&controller=book&task=e dit&cid[]='. $returnid ;
$msg .= JText::_( 'SUCCESSFULLY APPLY CHANGES TO BOOK' );
break;
case 'save':
default:
$link = 'index.php?option=com_abook&controller=book';
$msg .= JText::_( 'SUCCESSFULLY SAVED CHANGES TO BOOK' );
break;
}
} else {
$msg = JText::_( 'AN ERROR HAS OCCURRED' );
}
$model->checkin();
//var_dump($_POST);exit();
$this->setRedirect($link, $msg);
}
function remove()
{
//echo "controller: book; action: remove<br>";var_dump($_POST);var_dump(JRequest::ge t('post'));exit();
$model = $this->getModel('book');
if(!$model->delete()) {
$msg = JText::_( 'ONE OR MORE ITEMS COULD NOT BE DELETED' );
} else {
$msg = JText::_( 'ITEM(S) DELETED' );
}
$this->setRedirect( 'index.php?option=com_abook&controller=book', $msg );
}
function cancel()
{
//echo "controller: book; action: cancel<br>";var_dump($_POST);var_dump(JRequest::ge t('post'));exit();
//sblocca il lucchetto
$model = $this->getModel('book');
$model->checkin();
$msg = JText::_( 'OPERATION CANCELLED' );
$this->setRedirect( 'index.php?option=com_abook&controller=book', $msg );
}
function access( )
{
//echo "controller: book; action: access<br>";var_dump($_POST);var_dump(JRequest::ge t('post'));exit();
global $option;
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$id = $cid[0];
$task = JRequest::getVar( 'task' );
if ($task == 'accesspublic') {
$access = 0;
} elseif ($task == 'accessregistered') {
$access = 1;
} else {
$access = 2;
}
$model = $this->getModel('book');
$model->access( $id, $access );
$this->setRedirect('index.php?option='. $option .'&controller=book' );
}
function publish()
{
//echo "controller: book; action: publish<br>";var_dump($_POST);var_dump(JRequest::g et('post'));exit();
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
if (!is_array( $cid ) || count( $cid ) < 1) {
JError::raiseError(500, JText::_( 'SELECT AN ITEM TO PUBLISHED' ) );
}
$model = $this->getModel('books');
if(!$model->publish($cid, 1)) {
//echo "********** alert('".$model->getError()."'); window.history.go(-1); </script>\n";
}
$total = count( $cid );
$msg = $total.' '.JText::_('BOOK PUBLISHED');
$this->setRedirect( 'index.php?option=com_abook&controller=book', $msg );
}
function unpublish()
{
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
if (!is_array( $cid ) || count( $cid ) < 1) {
JError::raiseError(500, JText::_( 'SELECT AN ITEM TO UNPUBLISHED' ) );
}
$model = $this->getModel('books');
if(!$model->publish($cid, 0)) {
//echo "********** alert('".$model->getError()."'); window.history.go(-1); </script>\n";
}
$total = count( $cid );
$msg = $total.' '.JText::_('BOOK UNPUBLISHED');
$this->setRedirect( 'index.php?option=com_abook&controller=book', $msg );
}
function resetrates()
{
$id = JRequest::getVar( 'cid', '', 'post', 'int' );
$model = $this->getModel('book');
if(!$model->reset_rates($id, 0)) {
//echo "********** alert('".$model->getError()."'); window.history.go(-1); </script>\n";
}
$msg = JText::_('SUCCESSFULLY RESET RATES');
$this->setRedirect( 'index.php?option=com_abook&controller=book&task=e dit&cid[]='.$id, $msg );
}
function orderup()
{
$model = $this->getModel('books');
$model->move(-1);
$this->setRedirect( 'index.php?option=com_abook&controller=book');
}
function orderdown()
{
$model = $this->getModel('books');
$model->move(1);
$this->setRedirect( 'index.php?option=com_abook&controller=book');
}
function saveorder()
{
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$order = JRequest::getVar( 'order', array(0), 'post', 'array' );
JArrayHelper::toInteger($order, array(0));
$model = $this->getModel('books');
$model->saveorder($cid, $order);
$msg = JText::_( 'NEW ORDERING SAVED');
$this->setRedirect( 'index.php?option=com_abook&controller=book', $msg );
}
}