Location: PHPKode > projects > ZZ/OSS Installer > zic-1.1.0dev1/installer/packages_reset.php
<?php   
    /*
    Copyright (C) 2001-2004 ZZOSS GbR, http://www.zzoss.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    */
    
    /**
    @version $Id: packages_reset.php,v 1.9 2004/04/05 06:49:42 ordnas Exp $
    @copyright Copyright &copy; 2001-2004 ZZ/OSS GbR, http://www.zzoss.com
    @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
    */

	// execute init file
	require_once 'inc/init.php';
    
    $pkg_type = 'package';
    if(isset($_REQUEST['type'])){
        $pkg_type = $_REQUEST['type'];
    }
    
    $remove_installed_pkgs = true;
    $remove_plugins = true;
    $buffer_output = false;
    
    $application = $zi_registry->getApplication();
    
    require_once 'ZZOSS_Config/Config.php';
    $application = ZZOSS_Config::prepareNumeric($application, array($pkg_type));

    // if there are no plugins, we proceed
    if(
        (!isset($_REQUEST['widget_type']) || $_REQUEST['widget_type'] != 'popup') &&
        !isset($application['release'][$pkg_type.'s'][$pkg_type])
        ){
        
        if(isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'dev'){
            $url_next = 'packages.php'.zi_form_querystr();
        } else {
            $_REQUEST['type'] = 'package';
            $url_next = 'packages.php'.zi_form_querystr();
        }
        header('Location: '.$url_next);
        exit;
    }
    
    // check if this script is part of installation procedure
    if(/*isset($_REQUEST['mode']) && ($_REQUEST['mode'] == 'dev' || $_REQUEST['mode'] == 'instant') && */!$zi_registry->isProcedure($pkg_type.'s_register')){
        header('Location: packages.php'.zi_form_querystr());
        exit;
    } elseif($zi_registry->isProcedure($pkg_type.'s_register')){
        if($pkg_type == 'plugin'){
            // When resetting plugins, we need to install them to the plugin
            // runtime environment and register them as plugins,
            // otherwise the build won't work
            $zi_registry->setProcedure('plugins_fileroles');
        }
        if($zi_registry->getProcedure($pkg_type.'s_register') != 'rm_installed'){
            $remove_installed_pkgs = false;
        }
        if($zi_registry->getProcedure($pkg_type.'s_register') == 'hide'){
            $buffer_output = true;
        }
    }
     
    function zi_default()
    {
        global $zi_registry;
        
        $regfile = $zi_registry->getApplicationPath().'installer'.DIRECTORY_SEPARATOR.'bundle_downloads.reg';
        $_REQUEST['ZI_VALUES'] = ZZOSS_InstallerUtils::unserializeFromFile($regfile);
        
        return $_REQUEST;
    }

    /***************************************************************************   
    * PAGE CONTENT                                                             *   
    ***************************************************************************/
    
    $is_popup = false;
    $widget_type = '';
    
    if(isset($_REQUEST['widget_type']) && $_REQUEST['widget_type'] == 'popup'){
        $is_popup = true;
        $widget_type = '_popup';
    }
    
    if($buffer_output){
        ob_start();
    }
    
    include 'themes/'.$GLOBALS['ZI']['theme'].'/header'.$widget_type.'.php';
    ?>
    <h1>Packages Sources</h1>
    <h2><a href="info.php?mode=<?php echo $_REQUEST['mode']; ?>&type=application&distribution=<?php echo $_REQUEST['distribution']; ?>" onclick="javascript:window.open('info.php?mode=<?php echo $_REQUEST['mode']; ?>&type=application&distribution=<?php echo $_REQUEST['distribution']; ?>', 'ApplicationInformation', 'width=500,height=500,resizable=1,status=0,scrollbars=1,toolbar=0,location=0,directories=0,menubar=0,dependent=0');void(0);javascript:return(false);" target="_blank" title="<?php echo $application["summary"].' '.$application['release']['version']; ?>"><?php echo $application["summary"].' '.$application['release']['version']; ?></a></h2>
    <p>
    <?php
    $zi_registry->setPackageType($pkg_type);
    
    $packages = array();
    
    if(isset($application['release'][$pkg_type.'s'][$pkg_type])){
        $packages = $application['release'][$pkg_type.'s'][$pkg_type];
    }
    
    if(!count($packages)){
        ?>
        <div class="warning">No <?php echo ucfirst($pkg_type); ?>s defined in application.xml</div>
        <?php
    } else {
        if(!isset($_REQUEST['dev']) || $_REQUEST['dev'] != 'bundle'){
            $bundle_dir = $zi_registry->getApplicationPath().'downloads'.DIRECTORY_SEPARATOR;
        } else {
            $bundle_dir = $zi_registry->getApplicationPath().'bundle'.DIRECTORY_SEPARATOR;
            if(is_dir($bundle_dir)){
                System::rm(array('-rf', $bundle_dir));
            }
            System::mkdir(array('-p', $bundle_dir));
        }
        
        if($remove_installed_pkgs){
            // Remove previously installed packages and their registries
            $dir_installed = $zi_registry->getApplicationPath().$pkg_type.'s_installed';
            if(is_dir($dir_installed)){
                System::rm(array('-rf', $dir_installed));
                System::mkDir($dir_installed);
            }
        }
        $zi_registry->unsetPackages();

        if($pkg_type == 'plugin'){
            $dir_plugins_re = $zi_registry->getApplicationPath().'plugins_re';
            if(is_dir($dir_plugins_re)){
                System::rm(array('-rf', $dir_plugins_re));
                System::mkDir($dir_plugins_re);
            }
            
            $zi_registry->unsetPlugins();
        }
        
        ?>
        <h2>Installed <?php echo ucfirst($pkg_type); ?>s</h2>
        <div class="warning">Removed installed <?php echo ucfirst($pkg_type); ?>s.</div>
        <?php
        
        $app_settings = $zi_registry->getApplicationSettings();
        $log = array();
        
        require_once 'ZZOSS_Package/Package.php';
        $pkg_obj = new ZZOSS_Package;
        if(!$pkg_obj->packageSources($bundle_dir, $packages, $app_settings)){
            ?>
            <div class="warning">No package sources defined.</div>
            <?php
            // need to register packages here, otherwise full/minimum install would not work!
            $zi_registry->registerPackages();
        } else {
            $log = $pkg_obj->getLog();
            if(strlen($log)){
                ?>
                <h2>Local <?php echo ucfirst($pkg_type); ?>s</h2>
                
                <div class="warning">Rebuilt <?php echo ucfirst($pkg_type); ?>s from sources.</div>
                
                <textarea cols="60" rows="20" wrap="off"><?php
                echo $log;
                ?></textarea>
                <?php
                $zi_registry->registerPackages();
            }
            
            // If the package is not available locally, download it from the
            // location specified in the packages.xml.
            if($pkg_obj->hasUnprocessedPkgs()){
                $zi_buttons['next'] = 'packages_sources_downloads.php'.zi_form_querystr();
                // installer widget class
                require_once 'ZZOSS_Installer/Widget.php';
                $zi_widget = new ZZOSS_InstallerWidget;
                if(isset($zi_errors)){
                    $zi_widget->setErrors($zi_errors);
                }
                ?>
                <h2>Remote Packages</h2>
                <p>Please provide the URL to the download location of each package.</p>
                <table border="0" cellspacing="0" cellpadding="4">
                <?php
                //print_r($packages);
                //$zi_registry->registerPackages();
                //$pkgs_available = $zi_registry->getPackages();
                //print_r($pkgs_available);
                $pkgs_unprocessed = $pkg_obj->getUnprocessedPkgs();
                foreach($pkgs_unprocessed as $pos => $package){
                    $package_unique = $package['@']['name'].'-'.$package['@']['version'];
                    echo $zi_widget->add('text', $package_unique, $package_unique, array('validation' => 'not empty'));
                }
                ?>
                </table>
                <?php
            }
        }
    }
    ?>
    </p>
    <?php
    if($is_popup){
        $zi_buttons['reload_parent'] = true;
    } else {
        $zi_buttons['next'] = 'packages.php'.zi_form_querystr();
    }
	include 'themes/'.$GLOBALS['ZI']['theme'].'/footer'.$widget_type.'.php';
    
    if(!$is_popup && $buffer_output){
        ob_end_clean();
        header('Location: '.$zi_buttons['next']);
        exit;
    }
?>
Return current item: ZZ/OSS Installer