git-svn-id: https://192.168.0.254/svn/Proyectos.FundacionLQDVI_WebCongresos/trunk@2 94ccb1af-fd9d-d947-8d90-7f70ea60afc8
225 lines
8.2 KiB
PHP
225 lines
8.2 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 Sql2excelControllerSqlexcelsampledata extends Sql2excelController
|
|
{
|
|
/**
|
|
* constructor (registers additional tasks to methods)
|
|
* @return void
|
|
*/
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
// Register Extra tasks
|
|
$this->registerTask( 'add' , 'addSampleData' );
|
|
}
|
|
|
|
function addSampleData()
|
|
{
|
|
$msg = '';
|
|
$db = & JFactory::getDBO();
|
|
|
|
// Sample Section
|
|
$query = ' SELECT ID '
|
|
. ' FROM #__sql2excel_sections'
|
|
. " WHERE title = 'Site Content' ";
|
|
|
|
$db->setQuery($query);
|
|
$sectID = $db->loadResult();
|
|
|
|
if ( !$sectID ) {
|
|
$query = 'INSERT INTO #__sql2excel_sections '
|
|
.'(`title`,`alias`,`published`) '
|
|
.'VALUES (\'Site Content\',\'site-content\',1)';
|
|
$db->setQuery($query);
|
|
if ($db->query()) {
|
|
$sectID = $db->insertid();
|
|
$msg .= JText::_('"Site Content" Section added. ID=') . $sectID . '<br>';
|
|
} else { $msg .= JText::_('ERROR adding "Site Content" Section!') . '<br>'; }
|
|
}
|
|
|
|
// Sample Category
|
|
$query = ' SELECT ID '
|
|
. ' FROM #__sql2excel_categories'
|
|
. " WHERE title = 'Articles' AND section=" . $sectID;
|
|
|
|
|
|
$db->setQuery($query);
|
|
$catID = $db->loadResult();
|
|
|
|
|
|
if ( !$catID ) {
|
|
$query = 'INSERT INTO #__sql2excel_categories '
|
|
.'(`title`,`alias`,`published`,`section`) '
|
|
.'VALUES (\'Articles\',\'articles\',1,' . $sectID . ')';
|
|
$db->setQuery($query);
|
|
if ($db->query()) {
|
|
$catID = $db->insertid();
|
|
$msg .= JText::_('"Articles" Category added. ID=') . $catID . '<br>';
|
|
} else { $msg .= JText::_('ERROR adding "Articles" Category!') . '<br>'; }
|
|
|
|
}
|
|
|
|
|
|
// Sample Worksheets
|
|
$query = ' SELECT ID '
|
|
. ' FROM #__sql2excel_worksheets'
|
|
. " WHERE title = 'Latest Articles' ";
|
|
|
|
|
|
$db->setQuery($query);
|
|
$ws1ID = $db->loadResult();
|
|
|
|
|
|
if ( !$ws1ID ) {
|
|
$header = "'Latest articles\n" . JURI::root() . "\n\n'";
|
|
$footer = "'\n\nJoomla-R-Us : Sample Worksheet'";
|
|
$error_norecords = "'Sorry, no articles found!'";
|
|
$sql = "'SELECT a.id, a.title, a.created, CONCAT(\'" . JURI::root() . "index.php?option=com_content&view=article&id=\',a.id) AS URL\nFROM #__content AS a\nORDER BY a.id DESC LIMIT 0,100'";
|
|
$query = 'INSERT INTO #__sql2excel_worksheets '
|
|
.'(`title`,`sheetname`,`published`, `created`, `header`, `heading_bg_col`, `heading_text_col`, `heading_text_size`, `colwidths`, `footer`, `error_norecords`, `query`) '
|
|
."VALUES ('Latest Articles','Latest Articles',1,'" . date('Y-m-d H:i:s') . "'," . $header . ", 'cyan', 'black',10,'10,60,20,60'," . $footer . "," . $error_norecords . "," . $sql . ") ";
|
|
|
|
$db->setQuery($query);
|
|
if ($db->query()) {
|
|
$ws1ID = $db->insertid();
|
|
$msg .= JText::_('"Latest Articles" Worksheet added. ID=') . $ws1ID . '<br>';
|
|
} else { $msg .= JText::_('ERROR adding "Latest Articles" Worksheet!') . ' SQL=' . $query . '<br>'; }
|
|
}
|
|
|
|
|
|
$query = ' SELECT ID '
|
|
. ' FROM #__sql2excel_worksheets'
|
|
. " WHERE title = 'Popular Articles' ";
|
|
|
|
$db->setQuery($query);
|
|
$ws2ID = $db->loadResult();
|
|
|
|
if ( !$ws2ID ) {
|
|
$header = "'Popular Articles\n" . JURI::root() . "\n\n'";
|
|
$footer = "'\n\nJoomla-R-Us : Sample Worksheet'";
|
|
$error_norecords = "'Sorry, no articles found!'";
|
|
$sql = "'SELECT a.id, a.title, a.hits, CONCAT(\'" . JURI::root() . "index.php?option=com_content&view=article&id=\',a.id) AS URL\nFROM #__content AS a\nORDER BY a.hits DESC LIMIT 0,100'";
|
|
$query = 'INSERT INTO #__sql2excel_worksheets '
|
|
.'(`title`,`sheetname`,`published`,`created`,`header`, `heading_bg_col`, `heading_text_col`, `heading_text_size`, `colwidths`, `footer`, `error_norecords`, `query`) '
|
|
."VALUES ('Popular Articles','Popular Articles',1,'" . date('Y-m-d H:i:s') . "'," . $header . ", 'cyan', 'black',10,'10,60,10,60'," . $footer . "," . $error_norecords . "," . $sql . ") ";
|
|
|
|
$db->setQuery($query);
|
|
if ($db->query()) {
|
|
$ws2ID = $db->insertid();
|
|
$msg .= JText::_('"Popular Articles" Worksheet added. ID=') . $ws2ID . '<br>';
|
|
} else { $msg .= JText::_('ERROR adding "Latest Articles" Worksheet!') . '<br>'; }
|
|
}
|
|
|
|
|
|
$query = ' SELECT ID '
|
|
. ' FROM #__sql2excel_worksheets'
|
|
. " WHERE title = 'Latest Articles - With WB Parameter' ";
|
|
|
|
$db->setQuery($query);
|
|
$ws3ID = $db->loadResult();
|
|
|
|
if ( !$ws3ID ) {
|
|
$header = "'Latest Articles - With WB Parameter\n" . JURI::root() . "\n\n'";
|
|
$footer = "'\n\nJoomla-R-Us : Sample Worksheet'";
|
|
$error_norecords = "'Sorry, no articles found!'";
|
|
$sql = "'SELECT a.id, a.title, a.created, CONCAT(\'" . JURI::root() . "index.php?option=com_content&view=article&id=\',a.id) AS URL\nFROM #__content AS a\nORDER BY a.id DESC LIMIT 0,{USERROWS}'";
|
|
$query = 'INSERT INTO #__sql2excel_worksheets '
|
|
.'(`title`,`sheetname`,`published`, `created`, `header`, `heading_bg_col`, `heading_text_col`, `heading_text_size`, `colwidths`, `footer`, `error_norecords`, `query`, `pane_horiz`) '
|
|
."VALUES ('Latest Articles - With WB Parameter','Latest Articles',1,'" . date('Y-m-d H:i:s') . "'," . $header . ", 'cyan', 'black',10,'10,60,20,60'," . $footer . "," . $error_norecords . "," . $sql . ",0) ";
|
|
|
|
$db->setQuery($query);
|
|
if ($db->query()) {
|
|
$ws3ID = $db->insertid();
|
|
$msg .= JText::_('"Latest Articles - With WB Parameter" Worksheet added. ID=') . $ws3ID . '<br>';
|
|
} else { $msg .= JText::_('ERROR adding "Latest Articles - With WB Parameter" Worksheet!') . ' SQL=' . $query . '<br>'; }
|
|
}
|
|
|
|
|
|
// Sample Workbook
|
|
if ( $ws1ID > 0 && $ws2ID > 0 ) {
|
|
|
|
$query = ' SELECT ID '
|
|
. ' FROM #__sql2excel_workbooks'
|
|
. " WHERE title = 'Articles' AND section=" . $sectID . " AND category=" . $catID;
|
|
|
|
|
|
$db->setQuery($query);
|
|
$wbID = $db->loadResult();
|
|
|
|
|
|
if ( !$wbID ) {
|
|
$query = 'INSERT INTO #__sql2excel_workbooks '
|
|
.'(`title`,`link_title`,`filename`, `section`, `category`, `published`, `created`) '
|
|
.'VALUES (\'Articles\',\'Articles\',\'articles.xls\',' . $sectID . ',' . $catID . ',1, \'' . date('Y-m-d H:i:s') . '\')';
|
|
$db->setQuery($query);
|
|
if ($db->query()) {
|
|
$wbID = $db->insertid();
|
|
$msg .= JText::_('"Articles" Workbook added. ID=') . $wbID . '<br>';
|
|
} else { $msg .= JText::_('ERROR adding "Articles" workbook!') . '<br>'; }
|
|
|
|
$query = 'INSERT INTO #__sql2excel_worksheet2book '
|
|
.'(`wb_id`,`ws_id`,`ordering`) '
|
|
.'VALUES (' . $wbID . ',' . $ws1ID . ',1)';
|
|
$db->setQuery($query);
|
|
$res = $db->query();
|
|
$query = 'INSERT INTO #__sql2excel_worksheet2book '
|
|
.'(`wb_id`,`ws_id`,`ordering`) '
|
|
.'VALUES (' . $wbID . ',' . $ws2ID . ',2)';
|
|
$db->setQuery($query);
|
|
if (!$db->query()) {
|
|
$msg .= JText::_('ERROR mapping Worksheets to "Articles" workbook!<br>');
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( $ws3ID > 0 ) {
|
|
$query = ' SELECT ID '
|
|
. ' FROM #__sql2excel_workbooks'
|
|
. " WHERE title = 'Articles - WB Parameter' AND section=" . $sectID . " AND category=" . $catID;
|
|
|
|
$db->setQuery($query);
|
|
$wbID = $db->loadResult();
|
|
|
|
if ( !$wbID ) {
|
|
$query = 'INSERT INTO #__sql2excel_workbooks '
|
|
.'(`title`,`link_title`,`filename`, `section`, `category`, `published`, `created`,`parms`,`parms_prompt`) '
|
|
.'VALUES (\'Articles - WB Parameter\',\'Articles - Param\',\'articles_param.xls\',' . $sectID . ',' . $catID . ',1, \'' . date('Y-m-d H:i:s') . '\',\'Number of rows,USERROWS,Integer,10\',1)';
|
|
$db->setQuery($query);
|
|
if ($db->query()) {
|
|
$wbID = $db->insertid();
|
|
$msg .= JText::_('"Articles" Workbook added. ID=') . $wbID . '<br>';
|
|
} else { $msg .= JText::_('ERROR adding "Articles - WB Parameter" workbook!') . '<br>'; }
|
|
|
|
$query = 'INSERT INTO #__sql2excel_worksheet2book '
|
|
.'(`wb_id`,`ws_id`,`ordering`) '
|
|
.'VALUES (' . $wbID . ',' . $ws3ID . ',1)';
|
|
$db->setQuery($query);
|
|
if (!$db->query()) {
|
|
$msg .= JText::_('ERROR mapping Worksheets to "Articles - WB Parameter" workbook!<br>');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if ( $msg == '' ) {
|
|
$msg = JText::_( 'Sample data already installed - nothing added.' );
|
|
} else { $msg = '<div style="margin-left: 40px;">' . $msg . '</div>'; }
|
|
|
|
$link = 'index.php?option=com_sql2excel';
|
|
$this->setRedirect( $link, $msg );
|
|
|
|
|
|
}
|
|
} |