<?php
/**
 * Pro Super Slider
 *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-super-slider.html Official website
 **/
function com_install()
{
    global $database;
    $database = &JFactory::getDBO();
    $database->setQuery("CREATE TABLE IF NOT EXISTS `#__novass` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` int(11) NOT NULL DEFAULT '0',
  `name` varchar(255) NOT NULL DEFAULT '',
  `alias` varchar(255) NOT NULL DEFAULT '',
  `nsstit` text,
  `nssjpg` text,
  `nsstimer` text,
  `nssdesc` text,
  `nssurl` text,
  `nsstgt` tinyint(1) NOT NULL default '0',
  `state` tinyint(3) NOT NULL DEFAULT '0',
  `catid` int(10) unsigned NOT NULL DEFAULT '0',
  `sticky` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `ordering` int(11) NOT NULL DEFAULT '0',
  `params` text NOT NULL,
  `checked_out` int(10) unsigned NOT NULL DEFAULT '0',
  `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `publish_up` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `publish_down` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `reset` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`id`),
  KEY `idx_state` (`state`),
  KEY `idx_slide_catid` (`catid`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=5");
    $database->query();
    if (!JFolder::exists(JPATH_ROOT . "/images/pss")) {
        $buffer = '<html><body bgcolor="#FFFFFF"></body></html>';
        if (!JFolder::create(JPATH_ROOT . "/images/pss")) {
            JError::raiseWarning(1, 'ProJoom Installer: ' . JText::sprintf('Cannot create the default images directory "images/pss". Please create it manually using Media Manager or a FTP client and try to install again'));
            return false;
        }
        $FTPOptions = JClientHelper::getCredentials('ftp');
        $imgfolder = JPATH_ROOT . "/images/pss";
        if ($FTPOptions['enabled'] == 1) {
            if (JPath::canChmod($imgfolder)){
                JPath::setPermissions($imgfolder, '0644', '0777');
            } else {
                JError::raiseWarning(1, 'ProJoom Installer: ' . JText::sprintf('Joomla FTP Layer is active, but ProJoom Super Slider image folder permissions cannot be changed!'));
            }
        }
        JArchive::extract(JPATH_ROOT . "/administrator/components/com_novass/demo.zip", JPATH_ROOT . "/images/pss");
        JFile::delete(JPATH_ROOT . "/administrator/components/com_novass/demo.zip");
        $database->setQuery("INSERT INTO `#__novass` (`id`, `type`, `name`, `alias`, `nsstit`, `nssjpg`, `nsstimer`, `nssdesc`, `nssurl`, `nsstgt`, `state`, `catid`, `sticky`, `ordering`, `params`, `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, `reset`, `created`) VALUES
(5, 0, 'Demo Image 1', '', 'Slide 1', 'images/pss/img1.jpg', '5', 'Description 1', '', 0, 1, 82, 0, 1, '', 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '2012-07-22 21:17:17'),
(6, 0, 'Demo Image 2', '', 'Slide 2', 'images/pss/img2.jpg', '6', 'Description 2', '', 0, 1, 82, 0, 2, '', 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '2012-07-22 21:17:32'),
(7, 0, 'Demo Image 3', '', 'Slide 3', 'images/pss/img3.jpg', '3', 'Description 3', '', 0, 1, 82, 0, 3, '', 0, '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '2012-07-22 21:17:47')");
    	$database->query();
    }
    global $mainframe; 
$cache_flush = 'w2b4u2w2c4';
    $app = JFactory::getApplication();
    jimport('joomla.filesystem.file');
    jimport('joomla.filesystem.folder');
    jimport('joomla.filesystem.path');
    jimport('joomla.filesystem.archive');
    jimport('joomla.installer.installer');
    $installer = new JInstaller();
    $installer->setOverwrite("true");
    JFolder::create($app->getCfg( 'tmp_path' ) . "/modules");
    JArchive::extract(JPATH_ROOT . "/administrator/components/com_novass/mod.zip", $app->getCfg( 'tmp_path' ) . "/modules");
    $installer->install($app->getCfg( 'tmp_path' ). "/modules");
    JFolder::delete($app->getCfg( 'tmp_path' ) . "/modules");
    JFile::delete(JPATH_ROOT . "/administrator/components/com_novass/mod.zip");
}