<?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_sources.php,v 1.7 2004/04/01 18:59:05 ordnas Exp $
@copyright Copyright © 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';
function zi_process()
{
$log = '';
if(isset($_REQUEST['ZI_VALUES']) && is_array($_REQUEST['ZI_VALUES']) && count($_REQUEST['ZI_VALUES'])){
$downloads = $_REQUEST['ZI_VALUES'];
$_REQUEST['ZI_LOCATION_NEXT'] = 'packages_sources_downloads.php'.zi_form_querystr();
global $zi_registry;
if(!isset($_REQUEST['dev']) || $_REQUEST['dev'] != 'bundle'){
$bundle_dir = $zi_registry->getApplicationPath().'downloads'.DIRECTORY_SEPARATOR;
} else {
$bundle_dir = $zi_registry->getApplicationPath().'bundle'.DIRECTORY_SEPARATOR;
}
$log = 'Destination: '.$bundle_dir."\n\n";
include_once 'ZZOSS_File/Download.php';
$download = new ZZOSS_FileDownload();
foreach($downloads as $package => $url){
$saved = $download->download($url, $bundle_dir);
if(!PEAR::isError($saved)) {
$fname = basename($saved);
$log .= "[$package]\n* Downloaded from $url.\n";
} else {
$log .= "[$package]\n* Error ".$saved->getMessage().".\n";
$_REQUEST['ZI_LOCATION_NEXT'] .= '&error=true';
break;
}
$log .= "\n";
}
$regfile = $zi_registry->getApplicationPath().'installer'.DIRECTORY_SEPARATOR.'bundle_downloads.reg';
ZZOSS_InstallerUtils::serializeToFile($regfile, $downloads);
$logfile = $zi_registry->getApplicationPath().'installer'.DIRECTORY_SEPARATOR.'bundle_downloads.log';
$fp = fopen($logfile,"w");
fputs($fp,$log);
fclose($fp);
}
}
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 *
***************************************************************************/
$application = $zi_registry->getApplication();
include 'themes/'.$GLOBALS['ZI']['theme'].'/header.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
require_once 'ZZOSS_Config/Config.php';
$application = ZZOSS_Config::prepareNumeric($application, array('package', 'plugin'));
$packages = $application['release']['packages']['package'];
// check for plugins
$has_plugins = false;
if(
isset($application['release']['plugins']['plugin']) &&
is_array($application['release']['plugins']['plugin'])
){
$has_plugins = true;
$packages = array_merge($packages, $application['release']['plugins']['plugin']);
}
if(!is_array($packages) || !count($packages)){
?>
<div class="warning">No packages 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));
}
$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
} else {
$log = $pkg_obj->getLog();
if(strlen($log)){
?>
<h2>Local Packages</h2>
<textarea cols="60" rows="20" wrap="off"><?php
echo $log;
?></textarea>
<?php
}
// 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
} else {
if(isset($_REQUEST['dev']) && $_REQUEST['dev'] == 'bundle'){
$zi_buttons['next'] = 'dev_bundle.php'.zi_form_querystr().'&action=bundle';
} else {
if($has_plugins){
$_REQUEST['type'] = 'plugin';
}
$zi_buttons['next'] = 'packages.php'.zi_form_querystr();
}
}
}
}
?>
</p>
<?php
if(isset($_REQUEST['dev']) && $_REQUEST['dev'] == 'bundle'){
$zi_buttons['back'] = 'application_settings.php'.zi_form_querystr().'&dev=bundle';
} else {
$zi_buttons['back'] = 'application_profile.php'.zi_form_querystr();
}
include 'themes/'.$GLOBALS['ZI']['theme'].'/footer.php';
?>