git-svn-id: https://192.168.0.254/svn/Proyectos.FundacionLQDVI_WebCongresos/trunk@2 94ccb1af-fd9d-d947-8d90-7f70ea60afc8
417 lines
15 KiB
PHP
417 lines
15 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 Sql2excelControllerSqlexcelupgrade extends Sql2excelController
|
|
{
|
|
/**
|
|
* constructor (registers additional tasks to methods)
|
|
* @return void
|
|
*/
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
// Register Extra tasks
|
|
$this->registerTask( 'upgrade' , 'upgrade' );
|
|
}
|
|
|
|
|
|
/**
|
|
* Public
|
|
*
|
|
* Perform Database upgrade
|
|
* @return void
|
|
*/
|
|
function upgrade()
|
|
{
|
|
|
|
$err = '';
|
|
|
|
|
|
// Version 0.9.2
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'formulas', "VARCHAR(255) NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "formulas" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
|
|
|
|
// Pro 1.0.1
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'nr_parms', "int(11) unsigned NOT NULL default 0");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "nr_parms" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'parms', "TEXT NOT NULL default ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "parms" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'database', "INT(11) NOT NULL DEFAULT 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "database" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'ws_password', "VARCHAR(40) NOT NULL default ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "ws_password" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'pane_horiz', "INT(11) NOT NULL DEFAULT -1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "pane_horiz" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'pane_vert', "INT(11) NOT NULL DEFAULT -1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "pane_vert" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
}
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'parms', "TEXT NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'UPGRADE_WB_PARMS_ERR' );
|
|
} else {
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'parms_prompt', "INT(11) NOT NULL DEFAULT 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'UPGRADE_WB_PARMSPROMPT_ERR' );
|
|
} else {
|
|
$query = "CREATE TABLE `#__sql2excel_databases` (
|
|
`id` int(11) NOT NULL auto_increment,
|
|
`db_name` varchar(255) NOT NULL,
|
|
`db_type` int(11) unsigned NOT NULL default '0',
|
|
`db_host` varchar(255) NOT NULL default '',
|
|
`db_username` varchar(255) NOT NULL default '',
|
|
`db_password` varchar(255) NOT NULL default '',
|
|
`db_database` varchar(255) NOT NULL default '',
|
|
`db_prefix` varchar(40) NOT NULL default '',
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
|
|
|
$res = $this->_addTable('#__sql2excel_databases', $query);
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'UPGRADE_DBTABLE_ERR' );
|
|
} else {
|
|
$db =& JFactory::getDBO();
|
|
$query = "SELECT COUNT(*) AS CNT FROM `#__sql2excel_databases` WHERE ID=1";
|
|
$db->setQuery( $query );
|
|
$joomlaDB = $db->loadResult();
|
|
if ( !joomlaDB ) {
|
|
$query = "INSERT INTO `#__sql2excel_databases` (`id`, `db_name`, `db_type`)
|
|
VALUES (1,'Joomla!',1)";
|
|
$db->setQuery( $query );
|
|
if (!$result = $db->query()){
|
|
$err .= JText::_( 'UPGRADE_DBTABLE_JOOMLA_ERR' );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Pro 1.1.3
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'extracells', "TEXT NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "extracells" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
}
|
|
|
|
|
|
// Pro 1.2.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'description', "TEXT NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "description" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'keywords', "VARCHAR(255) NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "keywords" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
}
|
|
|
|
|
|
// Pro 1.2.2
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'cache', "ENUM('Global','Yes','No') NOT NULL default 'Global'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "cache" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'preview_rows', "int(11) unsigned default NULL");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "preview_rows" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'preview_extracells', "ENUM('Global','Show','Hide') NOT NULL default 'Global'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "preview_extracells" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'preview_formulas', "ENUM('Global','Show','Label','Hide') NOT NULL default 'Global'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "preview_formulas" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'preview_hidecols', "VARCHAR(255) NOT NULL default ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "preview_hidecols" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
}
|
|
|
|
|
|
// Pro 1.4.0
|
|
if ( $err == '' ) {
|
|
$query = "CREATE TABLE `#__sql2excel_settings` (
|
|
`param` VARCHAR(40) NOT NULL,
|
|
`value` TEXT NOT NULL default '',
|
|
PRIMARY KEY (`param`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
|
|
|
$res = $this->_addTable('#__sql2excel_settings', $query);
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to create "__sql2excel_settings" table.' );
|
|
}
|
|
}
|
|
|
|
// Pro 1.6.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'header_parms', "VARCHAR(255) NOT NULL DEFAULT 'Arial,10,normal,black,none'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "header_parms" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'data_parms', "VARCHAR(255) NOT NULL DEFAULT 'Arial,10,normal,black,None,silver,1,27,1'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "data_parms" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'footer_parms', "VARCHAR(255) NOT NULL DEFAULT 'Arial,10,normal,black,none'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "footer_parms" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'compress_wb', "ENUM('Global','Yes','No') NOT NULL default 'Global'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "compress_wb" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'compress_attachments', "tinyint(1) unsigned NOT NULL default 0");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "compress_attachments" column to #__sql2excel_schedules table.' );
|
|
}
|
|
}
|
|
|
|
// Pro 1.7.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'print_parms', "VARCHAR(255) NOT NULL default '0.75,0.75,1.0,1.0,0,0,0,0,0'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "print_parms" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'hide_grid', "tinyint(1) unsigned NOT NULL default 0");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "hide_grid" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
}
|
|
|
|
|
|
// 1.8.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'sql_db', "tinyint(1) unsigned NOT NULL default 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "sql_db" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'run_if_type', "tinyint(1) unsigned NOT NULL default 0");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "run_if_type" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'run_if_sql', "TEXT NOT NULL default ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "run_if_sql" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'run_if_db', "tinyint(1) unsigned NOT NULL default 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "run_if_db" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'run_if_op', "VARCHAR(3) NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "run_if_op" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'run_if_val_1', "VARCHAR(80) NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "run_if_val_1" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'run_if_val_2', "VARCHAR(80) NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "run_if_val_2" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'on_success_sql', "TEXT NOT NULL default ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "on_success_sql" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'on_success_db', "tinyint(1) unsigned NOT NULL default 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "on_success_db" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'on_success_email', "VARCHAR(255) NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "on_success_email" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'on_failure_sql', "TEXT NOT NULL default ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "on_failure_sql" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'on_failure_db', "tinyint(1) unsigned NOT NULL default 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "on_failure_db" column to #__sql2excel_schedules table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_schedules', 'on_failure_email', "VARCHAR(255) NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "on_failure_email" column to #__sql2excel_schedules table.' );
|
|
}
|
|
}
|
|
|
|
|
|
// 1.9.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'dlformat', "tinyint(1) unsigned NOT NULL default 0");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "dlformat" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
}
|
|
|
|
|
|
// 2.1.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'cellformat', "TEXT NOT NULL DEFAULT ''");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "cellformat" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
}
|
|
|
|
// 2.2.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'zoom', "int(11) unsigned NOT NULL default 100");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "zoom" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
}
|
|
|
|
// 2.3.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'parms_length', "int(11) unsigned NOT NULL default 5");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "parms_length" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
}
|
|
|
|
// 2.4.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'show_colheader', "tinyint(1) unsigned NOT NULL default 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "show_colheader" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_worksheets', 'escape_chars_html', "tinyint(1) unsigned NOT NULL default 1");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "escape_chars_html" column to #__sql2excel_worksheets table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'lightbox_x', "int(11) default NULL");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "lightbox_x" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'lightbox_y', "int(11) default NULL");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "lightbox_y" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
}
|
|
|
|
// 2.4.0
|
|
if ( $err == '' ) {
|
|
$res = $this->_addColumn('#__sql2excel_workbooks', 'preview_dl_btn', "ENUM('Global','Show','Hide') NOT NULL default 'Global'");
|
|
if ( ! $res ) {
|
|
$err .= JText::_( 'Failed to add "preview_dl_btn" column to #__sql2excel_workbooks table.' );
|
|
}
|
|
}
|
|
|
|
|
|
if ( $err != '' ) {
|
|
$msg = '<p>' . JText::_( 'Error' ) . '!</p>' . $err;
|
|
} else {
|
|
$msg = JText::_( 'Upgrade Successful!' );
|
|
}
|
|
$this->setRedirect( 'index.php?option=com_sql2excel', $msg );
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Private function
|
|
*
|
|
* Adds a column to a table, if not exists
|
|
* @return boolean
|
|
*/
|
|
function _addColumn($table, $colName, $colAttr = "INT( 11 ) NOT NULL DEFAULT '0'" ) {
|
|
|
|
global $mainframe;
|
|
$db =& JFactory::getDBO();
|
|
$colExists = false;
|
|
|
|
$query = 'SHOW COLUMNS FROM ' . $table;
|
|
$db->setQuery( $query );
|
|
if (!$result = $db->query()){return false;}
|
|
$columnData = $db->loadObjectList();
|
|
|
|
|
|
foreach ($columnData as $currCol) {
|
|
if ($currCol->Field == $colName) {
|
|
$colExists = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!$colExists) {
|
|
$query = "ALTER TABLE `".$table."` ADD `" . $colName . "` " . $colAttr;
|
|
$db->setQuery( $query );
|
|
if (!$result = $db->query()){
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* Private function
|
|
*
|
|
* Adds a table, if not exists
|
|
* @return boolean
|
|
*/
|
|
function _addTable($tableName, $sql) {
|
|
$db =& JFactory::getDBO();
|
|
if ( ! $this->_tableExists($tableName) ) {
|
|
$db->setQuery( $sql );
|
|
if (!$result = $db->query()){
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* Private function
|
|
*
|
|
* Checks if a table exists
|
|
* @return boolean
|
|
*/
|
|
function _tableExists($tableName) {
|
|
$db = & JFactory::getDBO();
|
|
$prefix = $db->getPrefix();
|
|
$tableName = str_replace('#__', $prefix, $tableName);
|
|
$tableList = $db->getTableList($db);
|
|
if ( in_array($tableName,$tableList) ) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|