<?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: online_update_process.php,v 1.2 2004/03/05 14:25:25 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';
// installer utils
require_once 'ZZOSS_Installer/Utils.php';
// config xml parser
require_once 'ZZOSS_Config/Config.php';
/***************************************************************************
* INSTALLER FRAMEWORK FUNCTIONS *
***************************************************************************/
/***************************************************************************
* SCRIPT FUNCTIONS *
***************************************************************************/
function downloadPackage($package) {
$file = $GLOBALS["application_dir"].'downloads/'.$package["name"].'-'.$package["release"]["version"].'.tgz';
if(is_array($package["filelist"]["file"])) {
if(isset($package["filelist"]["file"][0])) {
foreach($package["filelist"]["file"] as $url) {
if($url["@"]["role"] == 'package') {
$download_url = $url;
}
}
} else {
$download_url = $package["filelist"]["file"];
}
$result = ZZOSS_InstallerUtils::downloadFile(
$download_url["#"],
$file
);
}
if($result) {
return 'done';
} else {
return 'failed';
}
}
/***************************************************************************
* STARTUP *
***************************************************************************/
$file = 'data/installer/remote_application.xml';
$remote_application_xml = new ZZOSS_Config(array('numeric' => array('package', 'plugin')));
$remote_application_xml->setFile($file);
$remote_application = $remote_application_xml->query('/application');
$file = 'data/installer/remote_applications.xml';
$remote_applications_xml = new ZZOSS_Config();
$remote_applications_xml->setFile($file);
$remote_applications = $remote_applications_xml->query('/applications/application');
$remote_application_metadata = $remote_applications[$_REQUEST['application']];
$file = 'data/installer/remote_packages.xml';
if(file_exists($file)) {
unlink($file);
}
if(is_array($remote_application_metadata["filelist"]["descriptor"])) {
foreach($remote_application_metadata["filelist"]["descriptor"] as $descriptor) {
if($descriptor["@"]["role"] == 'packages') {
ZZOSS_InstallerUtils::downloadFile(
$descriptor["#"],
$file
);
}
}
}
if(!file_exists($file)) {
// error, since file does not exist
$error = 'unable to download package information';
} else {
$remote_packages_xml = new ZZOSS_Config( array( 'numeric' => array('file', 'package')
) );
$remote_packages_xml->setFile($file);
$remote_packages = $remote_packages_xml->query('/packages/package');
}
// compose array
if(is_array($remote_application["release"]["packages"]["package"])) {
foreach($remote_application["release"]["packages"]["package"] as $package) {
$remote_packages_install[$package["@"]["name"]] = $package["@"]["version"];
}
}
if(!isset($error)) {
// create directory for new application
$application_dir = 'data/applications/'.$remote_application["name"].'/';
mkdir($application_dir);
copy('data/installer/remote_application.xml', $application_dir.'application.xml');
copy('data/installer/remote_packages.xml', $application_dir.'installer/remote_packages.xml');
mkdir($application_dir.'installer');
mkdir($application_dir.'downloads');
mkdir($application_dir.'packages');
mkdir($application_dir.'packages_installed');
mkdir($application_dir.'cache');
mkdir($application_dir.'plugins');
// set rebuild applications flag
$fp = fopen("data/installer/applications.lock","w");
fputs($fp,'dummy');
fclose($fp);
}
/***************************************************************************
* PAGE CONTENT *
***************************************************************************/
if(isset($error)) {
include 'themes/'.$GLOBALS['ZI']['theme'].'/header.php';
?>
<h1>Download Application: Error</h1>
<?php echo $error;?>
<br clear="all"/>
<?php
$zi_buttons['next'] = "applications.php";
include 'themes/'.$GLOBALS['ZI']['theme'].'/footer.php';
} else {
header("Location: applications.php");
}
?>