<?php

defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller');
jimport('joomla.filesystem.file');

class wishlogueControllerwishlogueadspace extends JControllerLegacy {

    public function display($cachable = false, $urlparams = false) {
        $viewName = JRequest::getVar('view', 'wishlogueadspace');
        $viewLayout = JRequest::getVar('layout', 'wishlogueadspace');
        $view = $this->getView($viewName);
        if (($model = $this->getModel('wishlogueadspace'))) {
            $view->setModel($model, true);
        }
        $view->setLayout($viewLayout);
        $view->display();
    }

    function publish() { 
        $model = $this->getModel('wishlogueadspace');
        $model->publishstatus( JRequest::get('POST'), 1 );
        $this->setRedirect('index.php?layout=wishlogueadspace&option=' . JRequest::getVar('option'), 'Selected Ads published!');
    }

    function remove() { 
        $model = $this->getModel('wishlogueadspace');
        $model->deleteads( JRequest::get('POST') );
        $this->setRedirect('index.php?layout=wishlogueadspace&option=' . JRequest::getVar('option'), 'Selected Ads deleted!');
    }
    
    function unpublish() { 
        $model = $this->getModel('wishlogueadspace');
        $model->publishstatus( JRequest::get('POST'), 0 );
        $this->setRedirect('index.php?layout=wishlogueadspace&option=' . JRequest::getVar('option'), 'Selected Ads unpublished!');
    }
    
    function save() { 
        $adImage = JRequest::getVar( 'ad_image', '', 'files', 'array'); //Get File name, tmp_name
        $adURL = JRequest::getVar('ad_url', '');
        $description = JRequest::getVar('ad_description', '');
        $adStatus = JRequest::getVar('ad_status', '0');
        $adImageTmp = $adImage['tmp_name'];
        if ($adImageTmp != '' && $adURL != '') {
            $model =  $this->getModel('wishlogueadspace');
            $model->applynew($adImage, $adURL, $adStatus, $description);
            $this->setRedirect('index.php?layout=wishlogueadspace&option=' . JRequest::getVar('option'), 'Settings Saved!');
        } else {
            JError::raiseError(500, 'Error: You must give image and URL!');
        }
    }

    function add() { 
        $view = $this->getView('wishlogueadspace');
        if ($model = $this->getModel('wishlogueadspace')) {
            $view->setModel($model, true);
        }
        $view->setLayout('wishlogueadspacefrm');
        $view->display();
    }

    function cancel() {
        $this->setRedirect('index.php?layout=' . JRequest::getVar('layout', 'wishlogueadspace') . '&option=' . JRequest::getVar('option'));
    }
}

?>