FundacionLQDVI_WebCongresos/www/administrator/components/com_sql2excel/controllers/sqlexcelsection.php

252 lines
5.6 KiB
PHP
Raw Normal View History

<?php
/*
* @component SQL 2 Excel Component
* @copyright Copyright (C) Joomla-R-Us, joomla-r-us.com
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPLv3
*/
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
class Sql2excelControllerSqlexcelsection extends Sql2excelController
{
/**
* constructor (registers additional tasks to methods)
* @return void
*/
function __construct()
{
parent::__construct();
// Register Extra tasks
$this->registerTask( 'add' , 'edit' );
$this->registerTask( 'accesspublic', 'accessMenu');
$this->registerTask( 'accessregistered', 'accessMenu');
$this->registerTask( 'accessspecial', 'accessMenu');
}
/**
* display the edit form
* @return void
*/
function edit()
{
$thismodel = $this->getModel( 'sqlexcelsection' );
$thismodel->checkout();
JRequest::setVar( 'view', 'sqlexcelsection' );
JRequest::setVar( 'layout', 'form' );
JRequest::setVar('hidemainmenu', 1);
parent::display();
}
/**
* Move Section Up
* @return void
*/
function orderup()
{
$model = $this->getModel( 'sqlexcelsection' );
$model->move(-1);
$link = 'index.php?option=com_sql2excel&view=sqlexcelsections';
$this->setRedirect( $link );
}
/**
* Move Section Down
* @return void
*/
function orderdown()
{
$model = $this->getModel( 'sqlexcelsection' );
$model->move(1);
$link = 'index.php?option=com_sql2excel&view=sqlexcelsections';
$this->setRedirect( $link );
}
/**
* Apply changes to the record
* @return void
*/
function apply()
{
$this->save();
}
/**
* Save a record
* @return void
*/
function save()
{
$post = JRequest::get('post');
$post['description'] = JRequest::getVar( 'description', '', 'post', 'string', JREQUEST_ALLOWRAW );
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$post['id'] = (int) $cid[0]; // 0 for new, or actual ID when editing
$model = $this->getModel('sqlexcelsection');
$task = JRequest::getCmd('task');
if ( $task == 'apply' ) {
$id = $model->store($post);
if ($id && $id > 0) {
if ( (int) $cid[0] > 0 ) {
$msg = JText::_( 'Section Changes Saved' );
} else {
$msg = JText::_( 'New Section Saved' );
}
} else {
$msg = JText::_( 'Error Saving Section' );
}
// if ( (int) $cid[0] > 0 ) { $id = (int) $cid[0]; }
$this->setRedirect( 'index.php?option=com_sql2excel&controller=sqlexcelsection&task=edit&cid[]=' . $id, $msg );
} else {
$id = $model->store($post);
if ( $id ) {
if ( (int) $cid[0] > 0 ) {
$msg = JText::_( 'Section Changes Saved' );
} else {
$msg = JText::_( 'New Section Saved!!' );
}
} else {
if ( (int) $cid[0] > 0 ) {
$msg = JText::_( 'Error Saving Section Changes' );
} else {
$msg = JText::_( 'Error Saving New Section' );
}
}
$this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexcelsections', $msg );
}
}
/**
* Save Ordering of Sections
* @return void
*/
function saveorder()
{
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
$order = JRequest::getVar( 'order', array(), 'post', 'array' );
JArrayHelper::toInteger($cid);
JArrayHelper::toInteger($order);
$model = $this->getModel( 'sqlexcelsection' );
$model->saveorder($cid, $order);
$msg = JText::_( 'New Section order saved' );
$link = 'index.php?option=com_sql2excel&view=sqlexcelsections';
$this->setRedirect( $link, $msg );
}
/**
* remove record(s)
* @return void
*/
function remove()
{
$model = $this->getModel('sqlexcelsection');
$msg = $model->delete();
$this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexcelsections', $msg );
}
/**
* Method to publish section(s)
*
* @access public
* @return boolean True on success
*/
function publish()
{
global $mainframe;
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
JArrayHelper::toInteger($cid);
if (count( $cid ) < 1) {
JError::raiseError(500, JText::_( 'Please select a Section to publish' ) );
}
$model = $this->getModel('sqlexcelsection');
if(!$model->publish($cid, 1)) {
echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
} else {
$model->checkin();
}
$link = 'index.php?option=com_sql2excel&view=sqlexcelsections';
$this->setRedirect($link);
}
function unpublish()
{
global $mainframe;
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
JArrayHelper::toInteger($cid);
if (count( $cid ) < 1) {
JError::raiseError(500, JText::_( 'Select a Section to unpublish' ) );
}
$model = $this->getModel('sqlexcelsection');
if(!$model->publish($cid, 0)) {
echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
} else {
$model->checkin();
}
$link = 'index.php?option=com_sql2excel&view=sqlexcelsections';
$this->setRedirect($link);
}
function accessMenu()
{
$post = JRequest::get('post');
$cid = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$access = $post['task'];
switch ($access)
{
case 'accessregistered':
$access_id= 1;
break;
case 'accessspecial':
$access_id= 2;
break;
case 'accesspublic':
default:
$access_id= 0;
break;
}
$model = $this->getModel( 'sqlexcelsection' );
$model->accessmenu($cid[0],$access_id);
$model->checkin();
$link = 'index.php?option=com_sql2excel&view=sqlexcelsections';
$this->setRedirect($link);
}
/**
* cancel editing a record
* @return void
*/
function cancel()
{
$msg = JText::_( 'Operation Cancelled' );
$this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexcelsections', $msg );
}
}