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 . '
';
} else { $msg .= JText::_('ERROR adding "Site Content" Section!') . '
'; }
}
// 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 . '
';
} else { $msg .= JText::_('ERROR adding "Articles" Category!') . '
'; }
}
// 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 . '
';
} else { $msg .= JText::_('ERROR adding "Latest Articles" Worksheet!') . ' SQL=' . $query . '
'; }
}
$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 . '
';
} else { $msg .= JText::_('ERROR adding "Latest Articles" Worksheet!') . '
'; }
}
$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 . '
';
} else { $msg .= JText::_('ERROR adding "Latest Articles - With WB Parameter" Worksheet!') . ' SQL=' . $query . '
'; }
}
// 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 . '
';
} else { $msg .= JText::_('ERROR adding "Articles" workbook!') . '
'; }
$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!
');
}
}
}
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 . '
';
} else { $msg .= JText::_('ERROR adding "Articles - WB Parameter" workbook!') . '
'; }
$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!
');
}
}
}
if ( $msg == '' ) {
$msg = JText::_( 'Sample data already installed - nothing added.' );
} else { $msg = '