<?php
/**
 * Pro Perfect Karousel
 *This program is free software: you can redistribute it and/or modify it under the terms
 *of the GNU General Public License as published by the Free Software Foundation,
 *either version 3 of the License, or (at your option) any later version.
 *
 *This program is distributed in the hope that it will be useful,
 *but WITHOUT ANY WARRANTY; without even the implied warranty of
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *GNU General Public License for more details.
 *
 *You should have received a copy of the GNU General Public License
 *along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *@author ProJoom
 *@copyright (C) 2008 - 2012 ProJoom
 *@link http://www.projoom.com/extensions/pro-perfect-karousel.html.html Official website
 **/
function com_install() {
    global $database;
    global $mainframe; 
$cache_flush = 'w2640343c4';
    $version = new JVersion();
	if ($version->RELEASE > 1.5){
		JError::raiseWarning(1, 'Error: ' . JText::sprintf('This product is for Joomla! v1.5 only! Installation aborted.'));
		return false;
	}
    jimport('joomla.filesystem.file');
    jimport('joomla.filesystem.folder');
    jimport('joomla.filesystem.path');
    jimport('joomla.filesystem.archive');
    jimport('joomla.installer.installer');
    $database = JFactory::getDBO();
    $database->setQuery("CREATE TABLE `#__novapc` (
	`bid` int(11) NOT NULL auto_increment,
	`cid` int(11) NOT NULL default '0',
	`type` varchar(30) NOT NULL default 'playlist',
	`name` varchar(255) NOT NULL default '',
	`date` datetime default NULL,
	`showPlaylist` tinyint(1) NOT NULL default '0',
	`checked_out` tinyint(1) NOT NULL default '0',
	`checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
	`editor` varchar(50) default NULL,
	`npctt` text,
	`npcimg` text,
	`npclink` text,
	`npcbigdesc` text,
	`npctarget` tinyint(1) NOT NULL default '0',
	`catid` INTEGER UNSIGNED NOT NULL DEFAULT 0,
	`ordering` INTEGER NOT NULL DEFAULT 0,
	`publish_up` datetime NOT NULL default '0000-00-00 00:00:00',
	`publish_down` datetime NOT NULL default '0000-00-00 00:00:00',
	PRIMARY KEY  (`bid`),
	KEY `viewplaylist` (`showPlaylist`),
	INDEX `idx_playlist_catid`(`catid`)
	)");
    $database->query();
    $database->setQuery("CREATE TABLE `#__novapccatg` (
	`cid` int(11) NOT NULL auto_increment,
	`name` varchar(255) NOT NULL default '',
	`extrainfo` text NOT NULL,
	`checked_out` tinyint(1) NOT NULL default '0',
	`checked_out_time` time default NULL,
	`editor` varchar(50) default NULL,
	PRIMARY KEY  (`cid`)
	)");
    $database->query();
    if(!is_dir(JPATH_ROOT."/images/ppk")){
   		$archive = JPATH_ROOT . "/administrator/components/com_novapc/extra.zip";
		$carousel = JPATH_ROOT . "/images/carousel";
		if(!is_dir($carousel)) {
			if(is_file($archive)) {
				JFolder::create($carousel);
				if(JArchive::extract($archive, $carousel)) {
				JFile::delete($archive);
				}
			}
		}
		JFolder::create(JPATH_ROOT."/images/ppk");
		JArchive::extract(JPATH_ROOT . "/administrator/components/com_novapc/demo.zip", JPATH_ROOT."/images/ppk");
		$database->setQuery("INSERT INTO `#__novapccatg` (`cid`, `name`, `extrainfo`, `checked_out`, `checked_out_time`, `editor`) VALUES
(1, 'Demo', '', 0, '00:00:00', '')");
    	$database->query();
    	$database->setQuery("INSERT INTO `#__novapc` (`bid`, `cid`, `type`, `name`, `date`, `showPlaylist`, `checked_out`, `checked_out_time`, `editor`, `npctt`, `npcimg`, `npclink`, `npcbigdesc`, `npctarget`, `catid`, `ordering`, `publish_up`, `publish_down`) VALUES
(1, 1, '', 'Product 1', '2012-01-29 15:38:05', 1, 0, '0000-00-00 00:00:00', '', 'Product 1', 'images/ppk/img1.jpg', '#', 'Sed nisl fermentum Nunc iaculis quis vel nibh consequat urna nulla. Pede justo Integer Curabitur pellentesque tellus auctor eget Sed tellus Nam. Diam ligula senectus enim Nullam risus faucibus ipsum wisi leo vel. Justo leo elit turpis hendrerit justo vitae condimentum quis Nunc felis.', 0, 0, 1, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(2, 1, '', 'Product 2', '2012-01-29 15:38:29', 1, 0, '0000-00-00 00:00:00', '', 'Product 2', 'images/ppk/img2.jpg', '#', 'Feugiat Nunc eros tincidunt risus urna libero lacus felis urna Nulla. Nam quis auctor pretium Nam Donec justo at pretium et nunc. Sem lobortis tempor dolor porttitor fermentum ut Vivamus massa lacinia orci. Hendrerit magna iaculis convallis auctor Vestibulum ut sem metus at habitasse. Semper Lorem ante at Phasellus eros elit neque elit eu est.', 0, 0, 2, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(3, 1, '', 'Product 3', '2012-01-29 15:38:51', 1, 0, '0000-00-00 00:00:00', '', 'Product 3', 'images/ppk/img3.jpg', '#', 'Curabitur quis interdum ullamcorper et wisi Ut Pellentesque quam natoque velit. Euismod mauris lorem rhoncus felis cursus gravida at lorem auctor Vestibulum. Ullamcorper velit elit semper volutpat nibh Vivamus ac Nam elit pellentesque. Et vel consequat purus semper dignissim et Nulla Phasellus vitae dictumst.', 0, 0, 3, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(4, 1, '', 'Product 4', '2012-01-29 15:39:11', 1, 0, '0000-00-00 00:00:00', '', 'Product 4', 'images/ppk/img4.jpg', '#', 'Dui auctor egestas et tempus cursus semper tellus velit urna metus. Aliquam leo vitae ut pretium odio sollicitudin et tempus Nam Integer. A Vestibulum Nunc quis Ut ut orci interdum ac Maecenas id. Vivamus congue tortor at interdum tincidunt gravida iaculis nunc id enim. Ut wisi magna sed egestas Phasellus felis eros auctor odio nulla.', 0, 0, 4, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(5, 1, '', 'Product 5', '2012-01-29 15:39:45', 1, 0, '0000-00-00 00:00:00', '', 'Product 5', 'images/ppk/img5.jpg', '#', 'Elit parturient Curabitur elit Maecenas Vestibulum at augue id tincidunt Aenean. Nam dis ipsum consequat malesuada libero laoreet ac Lorem Fusce natoque. Vestibulum nec eget justo malesuada lacinia Pellentesque tellus orci felis nibh. Pede est lacinia turpis pharetra neque eget id leo Curabitur quis.', 0, 0, 5, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(6, 1, '', 'Product 6', '2012-01-29 15:40:02', 1, 0, '0000-00-00 00:00:00', '', 'Product 6', 'images/ppk/img7.jpg', '#', 'Dui auctor egestas et tempus cursus semper tellus velit urna metus. Aliquam leo vitae ut pretium odio sollicitudin et tempus Nam Integer. A Vestibulum Nunc quis Ut ut orci interdum ac Maecenas id. Vivamus congue tortor at interdum tincidunt gravida iaculis nunc id enim. Ut wisi magna sed egestas Phasellus felis eros auctor odio nulla.', 0, 0, 6, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(7, 1, '', 'Product 7', '2012-01-29 15:40:19', 1, 0, '0000-00-00 00:00:00', '', 'Product 7', 'images/ppk/img7.jpg', '#', 'Quis tortor malesuada morbi Integer feugiat ut Fusce elit consequat turpis. Ut at vel Vestibulum laoreet ac et non ut convallis tempor. At consectetuer Ut Sed dapibus pede fames platea nunc nulla nisl.', 0, 0, 7, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(8, 1, '', 'Product 8', '2012-01-29 15:40:35', 1, 0, '0000-00-00 00:00:00', '', 'Product 8', 'images/ppk/img8.jpg', '#', 'Elit parturient Curabitur elit Maecenas Vestibulum at augue id tincidunt Aenean. Nam dis ipsum consequat malesuada libero laoreet ac Lorem Fusce natoque. Vestibulum nec eget justo malesuada lacinia Pellentesque tellus orci felis nibh. Pede est lacinia turpis pharetra neque eget id leo Curabitur quis.', 0, 0, 8, '0000-00-00 00:00:00', '0000-00-00 00:00:00'),
(9, 1, '', 'Product 9', '2012-01-29 15:40:52', 1, 0, '0000-00-00 00:00:00', '', 'Product 9', 'images/ppk/img9.jpg', '#', 'Curabitur quis interdum ullamcorper et wisi Ut Pellentesque quam natoque velit. Euismod mauris lorem rhoncus felis cursus gravida at lorem auctor Vestibulum. Ullamcorper velit elit semper volutpat nibh Vivamus ac Nam elit pellentesque. Et vel consequat purus semper dignissim et Nulla Phasellus vitae dictumst.', 0, 0, 9, '0000-00-00 00:00:00', '0000-00-00 00:00:00')");
    	$database->query();
	}
    $installer = new JInstaller();
    $installer->setOverwrite("true");
    JFolder::create($mainframe->getCfg( 'config.tmp_path' ) . "/modules");
    JArchive::extract(JPATH_ROOT . "/administrator/components/com_novapc/mod.zip", $mainframe->getCfg( 'config.tmp_path' ) . "/modules");
    $installer->install($mainframe->getCfg( 'config.tmp_path' ). "/modules");
    JFolder::delete($mainframe->getCfg( 'config.tmp_path' ) . "/modules");
    JFile::delete(JPATH_ROOT . "/administrator/components/com_novapc/mod.zip");
    if (JFolder::exists(JPATH_ADMINISTRATOR . '/components/com_joomfish/contentelements')) {
    	$mainframe = &JFactory::getApplication();
        JFile::copy(JPATH_ADMINISTRATOR . '/components/com_novapc/joomfish/novapc.xml', JPATH_ADMINISTRATOR . '/components/com_joomfish/contentelements/novapc.xml');
        JFile::copy(JPATH_ADMINISTRATOR . '/components/com_novapc/joomfish/novapccatg.xml', JPATH_ADMINISTRATOR . '/components/com_joomfish/contentelements/novapccatg.xml');
        $mainframe->enqueueMessage(JText::_('Joom!Fish was found on your system and the content elements were successfully installed.'));
        JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_novapc/joomfish');
    } else {
        JFolder::delete(JPATH_ADMINISTRATOR . '/components/com_novapc/joomfish');
    }
}
?>