<?php
//Copyright (c) Florian Grannemann
//Last change in version: 2.0 RC 2
/*
******************************************************************************
ADbNewsSender 2
Copyright (C) 2009 Florian Grannemann (hide@address.com)
Website: http://adbnewssender.sf.net
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
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/
******************************************************************************
*/
//Do not edit anything unless you realy REALY know what you are doing!
$language=addslashes($_POST['language']);
$language=preg_replace("/\.\./", "",$language);
include "$path_to_protected/localisation/lang/$language/lang-setup.php.inc";
include "$path_to_protected/skeleton/public_apis.class.php.inc";
include "$path_to_protected/skeleton/private_apis.class.php.inc";
$MyDB=new ADBNS_DB("$path_to_protected/skeleton/includes/db_defs/","$path_to_protected/database/DBconf.php.inc");
if(!@$MyDB->connect())
{
die($MSG_NO_CONNECTION);
}
$MyCFG= new global_config_rw($MyDB);
$setupoption=$_POST["setupoption"];
//VariableMap with default configuration:
$variable_map=array();
$variable_map["URL"]="http://".$_SERVER['SERVER_NAME'];
$variable_map["Email"]="Webmaster@".preg_replace("/www\./i","",$_SERVER['SERVER_NAME']);
$req=preg_replace("/\/protected\/setup\/index.php/","",$_SERVER["REQUEST_URI"]);
$variable_map["SubscribeURL"]="http://".$_SERVER['SERVER_NAME']."$req/subscribe.php";
$variable_map["ConfirmationURL"]="http://".$_SERVER['SERVER_NAME']."$req/confirmation.php";
$variable_map["RenewalURL"]="http://".$_SERVER['SERVER_NAME']."$req/renewal.php";
$variable_map["ArchiveURL"]="http://".$_SERVER['SERVER_NAME']."$req/archive.php";
$variable_map["EnableTinyMCE"]="no";
$oldVersion=$MyCFG->get_config_value("Version");
if(!$setupoption)
{
$setupoption="install";
}
if($setupoption=="install")
{
print "<h1>ADbNewsSender $version $Step3_WelcomeMSG_install</h1>";
if($_POST["install"]=="yes")
{
//getting fields:
foreach($variable_map as $key=>$value)
{
$variable_map[$key]=$_POST[$key];
}
if($variable_map["EnableTinyMCE"] !="yes")
{
$variable_map["EnableTinyMCE"]="no";
}
//let's see if all fields are entered correctly:
$empty_settings=array();
$i=0;
foreach($variable_map as $key =>$value)
{
if(!$value)
{
$empty_settings[$i]=$key;
$i++;
}
}
if(count($empty_settings) >0)
{
//not all fields have been filled correctly:
print $ErrorMSG_1;
include "install.php.inc";
}
else
{
//ok installing...
//preparing Global config table:
$tablename="ADBNS2_global_config_table";
//columns
$columns=array();
$columns["name"]="varchar|100";
$columns["value"]="text";
$PK="name";
$defaults=array();
//create Global CF Table
if(@!$MyDB->create_table($tablename,$columns,$defaults,$PK))
{
print $MSG_COULD_NOT_CREATE_CT."<br>";
}
//preparing Newsletters table:
$tablename="ADBNS2_Newsletters";
//columns
$columns=array();
$columns["id"]="bigserial";
$columns["created"]="bigint";
$PK="id";
$defaults=array();
if(@!$MyDB->create_table($tablename,$columns,$defaults,$PK))
{
print $MSG_COULD_NOT_CREATE_Newsletters_table."<br>";
}
//writing config settings:
//updating settings:
$variable_map["Language"]=$language;
$variable_map["Version"]=$version;
$variable_map["NextMaintenance"]="0";
$variable_map["Update_unstables"]="NO";
$variable_map["Update_fastupdates"]="YES";
$variable_map["Update_onlyMV"]="NO";
foreach($variable_map as $key=>$val)
{
$MyCFG->replace_setting($key,$val);
}
//installation complete, printing success message:
$MSG=$MSG_SETUP_SUCCESS;
$MSG=preg_replace("/<-Version->/",$version,$MSG);
$MSG=preg_replace("/<-SubscribeURL->/",$variable_map["SubscribeURL"],$MSG);
$MSG=preg_replace("/<-ConfirmationURL->/",$variable_map["ConfirmationURL"],$MSG);
$MSG=preg_replace("/<-ConfirmationURL->/",$variable_map["ConfirmationURL"],$MSG);
$MSG=preg_replace("/<-RenewalURL->/",$variable_map["RenewalURL"],$MSG);
$MSG=preg_replace("/<-AdminAreaURL->/","../admin",$MSG);
print $MSG;
}
}
else
{
include "install.php.inc";
}
}
if($setupoption=="reinstall")
{
print "<h1>ADbNewsSender $version $Step3_WelcomeMSG_reinstall</h1>";
if($_POST["install"]=="yes")
{
//getting fields:
foreach($variable_map as $key=>$value)
{
$variable_map[$key]=$_POST[$key];
}
if($variable_map["EnableTinyMCE"] !="yes")
{
$variable_map["EnableTinyMCE"]="no";
}
//let's see if all fields are entered correctly:
$empty_settings=array();
$i=0;
foreach($variable_map as $key =>$value)
{
if(!$value)
{
$empty_settings[$i]=$key;
$i++;
}
}
if(count($empty_settings) >0)
{
//not all fields have been filled correctly:
print $ErrorMSG_1;
include "install.php.inc";
}
else
{
//ok installing...
//preparing Global config table:
$tablename="ADBNS2_global_config_table";
//columns
$columns=array();
$columns["name"]="varchar|100";
$columns["value"]="text";
$PK="name";
$defaults=array();
//trieng to drop the config table:
@$MyDB->drop_table("ADBNS2_global_config_table");
//(re)create Global CF Table
@$MyDB->create_table($tablename,$columns,$defaults,$PK);
//preparing Newsletters table:
$tablename="ADBNS2_Newsletters";
//columns
$columns=array();
$columns["id"]="bigserial";
$columns["created"]="bigint";
$PK="id";
$defaults=array();
@$MyDB->create_table($tablename,$columns,$defaults,$PK);
//writing config settings:
//updating settings:
$variable_map["Language"]=$language;
$variable_map["Version"]=$version;
$variable_map["NextMaintenance"]="0";
$variable_map["Update_unstables"]="NO";
$variable_map["Update_fastupdates"]="YES";
$variable_map["Update_onlyMV"]="NO";
foreach($variable_map as $key=>$val)
{
$MyCFG->replace_setting($key,$val);
}
//installation complete... printing success message.
$MSG=$MSG_SETUP_SUCCESS;
$MSG=preg_replace("/<-Version->/",$version,$MSG);
$MSG=preg_replace("/<-SubscribeURL->/",$variable_map["SubscribeURL"],$MSG);
$MSG=preg_replace("/<-ConfirmationURL->/",$variable_map["ConfirmationURL"],$MSG);
$MSG=preg_replace("/<-ConfirmationURL->/",$variable_map["ConfirmationURL"],$MSG);
$MSG=preg_replace("/<-RenewalURL->/",$variable_map["RenewalURL"],$MSG);
$MSG=preg_replace("/<-AdminAreaURL->/","../admin",$MSG);
print $MSG;
}
}
else
{
//At first check if settings are already in the config table and write them into the variable map:
foreach($variable_map as $key=>$val)
{
if($MyCFG->get_config_value($key))
{
$variable_map[$key]=$MyCFG->get_config_value($key);
}
}
include "install.php.inc";
}
}
if($setupoption=="update")
{
print "<h1>ADbNewsSender $version $Step3_WelcomeMSG_update</h1>";
$empty_settings=array();
$i=0;
foreach($variable_map as $key=>$val)
{
if($MyCFG->get_config_value($key))
{
$variable_map[$key]=$MyCFG->get_config_value($key);
}
else
{
//Setting is not yet in config table, let's see if it has been submited
if($_POST["Update_varmap".$key])
{
//yes using this setting:
$variable_map[$key]=$_POST["Update_varmap".$key];
}
else
{
//no: adding to empty settings
$empty_settings[$i]=$key;
$i++;
}
}
}
if(count($empty_settings) >0)
{
print $Step3_MSG1;
$i=0;
print "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"POST\">";
print "<input type=\"hidden\" name=\"step\" value=\"3\">";
print "<input type=\"hidden\" name=\"language\" value=\"$language\">";
print "<input type=\"hidden\" name=\"setupoption\" value=\"update\">";
$i=0;
while($i < count($empty_settings))
{
print $SettingMap[$empty_settings[$i]].": <input type=\"text\" name=\"Update_varmap".$empty_settings[$i]."\" size=\"30\" value=\"".$variable_map[$empty_settings[$i]]."\"><br>";
$i++;
}
print "<input type=\"submit\" value=\"$Step3_Submit\"></form>";
}
else
{
//updating settings:
$MyCFG->replace_setting("Version",$version);
$MyCFG->replace_setting("Language",$language);
foreach($variable_map as $key=>$val)
{
$MyCFG->replace_setting($key,$val);
}
$message=$Step3_Update_complete;
$message=preg_replace("/<-oldVersion->/",$oldVersion,$message);
$message=preg_replace("/<-newVersion->/",$version,$message);
print $message;
//update complete.
}
}
if($setupoption=="uninstall")
{
print "<h2>$Step3_Uninstall_MSG</h2>";
if($_POST["user_is_sure"]=="yes")
{
//deleting newsletters:
$newsletters=array();
$newsletters=$MyCFG->get_all_newsletters();
$i=0;
while($i < count($newsletters))
{
$MyCFG->delete_Newsletter($newsletters[$i]);
$i++;
}
//deleting global tables:
$MyDB->drop_table("ADBNS2_global_config_table");
$MyDB->drop_table("ADBNS2_Newsletters");
print $Step3_Uninstall_success;
}
else
{
print $Step3_Uninstall_msg1."<br><br>";
print "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"POST\">";
print "<input type=\"hidden\" name=\"step\" value=\"3\">";
print "<input type=\"hidden\" name=\"language\" value=\"$language\">";
print "<input type=\"hidden\" name=\"setupoption\" value=\"uninstall\">";
print "<input type=\"hidden\" name=\"user_is_sure\" value=\"yes\">";
print "<input type=\"submit\" value=\"$Step3_Uninstall_yes\"></form>";
print "<form action=\"".$_SERVER["PHP_SELF"]."\" method=\"POST\">";
print "<input type=\"hidden\" name=\"step\" value=\"2\">";
print "<input type=\"hidden\" name=\"language\" value=\"$language\">";
print "<input type=\"submit\" value=\"$Step3_Uninstall_no\"></form>";
}
}
?>