255 lines
5.7 KiB
PHP
255 lines
5.7 KiB
PHP
|
|
<?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 Sql2excelControllerSqlexceldatabase 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( 'sqlexceldatabase' );
|
||
|
|
$thismodel->checkout();
|
||
|
|
|
||
|
|
JRequest::setVar( 'view', 'sqlexceldatabase' );
|
||
|
|
JRequest::setVar( 'layout', 'form' );
|
||
|
|
JRequest::setVar('hidemainmenu', 1);
|
||
|
|
|
||
|
|
parent::display();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Move Section Up
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function orderup()
|
||
|
|
{
|
||
|
|
$model = $this->getModel( 'sqlexceldatabase' );
|
||
|
|
$model->move(-1);
|
||
|
|
|
||
|
|
$link = 'index.php?option=com_sql2excel&view=sqlexceldatabases';
|
||
|
|
$this->setRedirect( $link );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Move Database Down
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function orderdown()
|
||
|
|
{
|
||
|
|
$model = $this->getModel( 'sqlexceldatabase' );
|
||
|
|
$model->move(1);
|
||
|
|
|
||
|
|
$link = 'index.php?option=com_sql2excel&view=sqlexceldatabases';
|
||
|
|
$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('sqlexceldatabase');
|
||
|
|
$task = JRequest::getCmd('task');
|
||
|
|
|
||
|
|
|
||
|
|
if ( $task == 'apply' ) {
|
||
|
|
$id = $model->store($post);
|
||
|
|
if ($id && $id > 0) {
|
||
|
|
if ( (int) $cid[0] > 0 ) {
|
||
|
|
$msg = JText::_( 'Database Changes Saved' );
|
||
|
|
} else {
|
||
|
|
$msg = JText::_( 'New Database Saved' );
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$msg = JText::_( 'Error Saving Database' );
|
||
|
|
}
|
||
|
|
// if ( (int) $cid[0] > 0 ) { $id = (int) $cid[0]; }
|
||
|
|
$this->setRedirect( 'index.php?option=com_sql2excel&controller=sqlexceldatabase&task=edit&cid[]=' . $id, $msg );
|
||
|
|
} else {
|
||
|
|
$id = $model->store($post);
|
||
|
|
if ( $id ) {
|
||
|
|
if ( (int) $cid[0] > 0 ) {
|
||
|
|
$msg = JText::_( 'Database Changes Saved' );
|
||
|
|
} else {
|
||
|
|
$msg = JText::_( 'New Database Saved!!' );
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if ( (int) $cid[0] > 0 ) {
|
||
|
|
$msg = JText::_( 'Error Saving Database Changes' );
|
||
|
|
} else {
|
||
|
|
$msg = JText::_( 'Error Saving New Database' );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexceldatabases', $msg );
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Save Ordering of Databases
|
||
|
|
* @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( 'sqlexceldatabase' );
|
||
|
|
$model->saveorder($cid, $order);
|
||
|
|
|
||
|
|
$msg = JText::_( 'New Database order saved' );
|
||
|
|
$link = 'index.php?option=com_sql2excel&view=sqlexceldatabases';
|
||
|
|
$this->setRedirect( $link, $msg );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* remove record(s)
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function remove()
|
||
|
|
{
|
||
|
|
$model = $this->getModel('sqlexceldatabase');
|
||
|
|
$msg = $model->delete();
|
||
|
|
if ( $msg == '' ) {
|
||
|
|
$msg = JText::_( 'Database(s) deleted');
|
||
|
|
}
|
||
|
|
$this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexceldatabases', $msg );
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Method to publish database(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 Database to publish' ) );
|
||
|
|
}
|
||
|
|
|
||
|
|
$model = $this->getModel('sqlexceldatabase');
|
||
|
|
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=sqlexceldatabases';
|
||
|
|
$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 Database to unpublish' ) );
|
||
|
|
}
|
||
|
|
|
||
|
|
$model = $this->getModel('sqlexceldatabase');
|
||
|
|
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=sqlexceldatabases';
|
||
|
|
$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( 'sqlexceldatabase' );
|
||
|
|
|
||
|
|
$model->accessmenu($cid[0],$access_id);
|
||
|
|
$model->checkin();
|
||
|
|
$link = 'index.php?option=com_sql2excel&view=sqlexceldatabases';
|
||
|
|
$this->setRedirect($link);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* cancel editing a record
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
function cancel()
|
||
|
|
{
|
||
|
|
$msg = JText::_( 'Operation Cancelled' );
|
||
|
|
$this->setRedirect( 'index.php?option=com_sql2excel&view=sqlexceldatabases', $msg );
|
||
|
|
}
|
||
|
|
}
|