load('aps_guicontroller');
// Check the module permissions
$app->auth->check_module_permissions('sites');
// Load needed classes
$app->uses('tpl');
$app->tpl->newTemplate("form.tpl.htm");
$app->tpl->setInclude('content_tpl', 'templates/aps_install_package.htm');
// Load the language file
$lngfile = 'lib/lang/'.$_SESSION['s']['language'].'_aps.lng';
require_once($lngfile);
$app->tpl->setVar($wb);
$app->load_language_file('web/sites/'.$lngfile);
$adminflag = ($_SESSION['s']['user']['typ'] == 'admin') ? true : false;
$gui = new ApsGUIController($app);
$pkg_id = (isset($_GET['id'])) ? $app->db->quote($_GET['id']) : '';
// Check if a newer version is available for the current package
// Note: It's intended that here is no strict ID check (see below)
if(isset($pkg_id))
{
$newest_pkg_id = $gui->getNewestPackageID($pkg_id);
if($newest_pkg_id != 0) $pkg_id = $newest_pkg_id;
}
// Make sure an integer ID is given
if(!isset($pkg_id) || !$gui->isValidPackageID($pkg_id, $adminflag))
$app->error($app->lng('Invalid ID'));
// Get package details
$details = $gui->getPackageDetails($pkg_id);
if(isset($details['error'])) $app->error($details['error']);
$settings = $gui->getPackageSettings($pkg_id);
if(isset($settings['error'])) $app->error($settings['error']);
// Get domain list
$domains = array();
$domain_for_user = '';
if(!$adminflag) $domain_for_user = "AND (sys_userid = '".$app->db->quote($_SESSION['s']['user']['userid'])."'
OR sys_groupid = '".$app->db->quote($_SESSION['s']['user']['userid'])."' )";
$domains_assoc = $app->db->queryAllRecords("SELECT domain FROM web_domain WHERE document_root != '' ".$domain_for_user." ORDER BY domain;");
if(!empty($domains_assoc)) foreach($domains_assoc as $domain) $domains[] = $domain['domain'];
// If data has been submitted, validate it
$result['input'] = array();
if(count($_POST) > 1)
{
$result = $gui->validateInstallerInput($_POST, $details, $domains, $settings);
if(empty($result['error']))
{
$gui->createPackageInstance($result['input'], $pkg_id);
@header('Location:aps_installedpackages_list.php');
}
else
{
$app->tpl->setVar('error', implode('
', $result['error']));
// Set memorized values (license, db password, install location)
if(!empty($result['input']))
foreach($result['input'] as $key => $value) $app->tpl->setVar('inp_'.$key, $value);
}
}
else $app->tpl->setVar('inp_main_database_password', ucfirst(substr(md5(crypt(rand(0, 10))), 0, 16)));
// Pass the package details to the template
foreach($details as $key => $value)
{
if(!is_array($value)) $app->tpl->setVar('pkg_'.str_replace(' ', '_', strtolower($key)), $value);
else if($key == 'Requirements PHP settings') $app->tpl->setLoop('pkg_requirements_php_settings', $details['Requirements PHP settings']);
}
// Parse the template as far as possible, then do the rest manually
$app->tpl_defaults();
$parsed_tpl = $app->tpl->grab();
// ISPConfig has a very old and functionally limited template engine. We have to style parts on our own...
// Print the domain list
$domains_tpl = '';
if(!empty($domains))
{
$set = array();
$set[] = '';
$domains_tpl = implode("\n", $set);
}
$parsed_tpl = str_replace('DOMAIN_LIST_SPACE', $domains_tpl, $parsed_tpl);
// Print the packgae settings
$settings_tpl = '';
if(!empty($settings))
{
$set = array();
$set[] = '';
foreach($settings as $setting)
{
$set[] = '
'.$setting['SettingDescription'].'
'; } else if($setting['SettingInputType'] == 'checkbox') { $checked = ''; if((count($_POST) > 1) && (isset($result['input'][$setting['SettingID']]) && ($result['input'][$setting['SettingID']] == 'true'))) $checked = 'checked '; else if($setting['SettingDefaultValue'] == '1') $checked = 'checked '; $set[] = ''.$setting['SettingDescription'].'
'; } else if($setting['SettingInputType'] == 'select') { $set[] = ''.$setting['SettingDescription'].'
'; } $set[] = '