if(!file_exists("../include/config.php"))
{
header("Location:../install.php");
exit;
}
include("../include/config.php");
include("../include/lib/libconfig.php");
include("../include/db/db_".$db_type.".inc.php");
include("../include/interface.php");
include("../include/lib/libnewsletter.php");
//admin specific functions
include("include/function.php");
$conf = new config();
$op = (empty($_GET['op']) ? "" : $_GET['op']);
$op = (empty($_POST['op']) ? $op : $_POST['op']);
$list_id = (empty($_GET['list_id']) ? "" : $_GET['list_id']);
$list_id = (empty($_POST['list_id']) ? $list_id : $_POST['list_id']);
$action = (empty($_GET['action']) ? "" : $_GET['action']);
$action = (empty($_POST['action']) ? $action : $_POST['action']);
$page = (empty($_GET['page']) ? "subscribers" : $_GET['page']);
$page = (empty($_POST['page']) ? $page : $_POST['page']);
$error_list=false;
if($op=="saveGlobalconfig") {
$smtp_host = (isset($_POST['smtp_host']) ? $_POST['smtp_host'] : '');
$smtp_auth = (isset($_POST['smtp_auth']) ? $_POST['smtp_auth'] : 0);
$smtp_login = (isset($_POST['smtp_login']) ? $_POST['smtp_login'] : '');
$smtp_pass = (isset($_POST['smtp_pass']) ? $_POST['smtp_pass'] : '');
$mod_sub = (isset($_POST['mod_sub']) ? $_POST['mod_sub'] : 0);
if($conf->saveConfig($_POST['db_host'], $_POST['db_login'] ,$_POST['db_pass'],
$_POST['db_name'], $_POST['table_config'],
$_POST['admin_pass'], 50 , $_POST['base_url'],
$_POST['path'], $_POST['language'], $_POST['table_email'],
$_POST['table_temp'], $_POST['table_listsconfig'],
$_POST['table_archives'], $_POST['sending_method'],
$smtp_host, $smtp_auth, $smtp_login,
$smtp_pass,$_POST['sending_limit'], $_POST['validation_period'],
$_POST['sub_validation'], $_POST['unsub_validation'],
$_POST['admin_email'], $_POST['admin_name'], $_POST['mod_sub'],
$_POST['table_sub'], $_POST['charset']
))
$configSaved=true;
else $configSaved=false;
if($_POST['file']==1){
$configFile = saveConfigFile($_POST['db_host'], $_POST['db_login'], $_POST['db_pass'], $_POST['db_name'], $_POST['table_config']);
$forceUpdate = 1;
include("../include/config.php");
unset($forceUpdate);
}
}
$r = $conf->getConfig($hostname,$login,$pass,$database, $table_global_config);
if ( $r != 'SUCCESS'){
include("../include/lang/english.php");
echo "
".translate($r)."
";
echo "
";
exit;
}
if(empty($conf->language)) $conf->language="english";
include("../include/lang/".$conf->language.".php");
/*** LOGIN CHECK ***/
$form_pass = (empty($_POST['form_pass']) ? "" : $_POST['form_pass']);
if(!isset($form_pass) || $form_pass== "") $form_pass = (empty($_GET['form_pass']) ? "" : $_GET['form_pass']);
if(!checkAdminAccess($conf->admin_pass, $form_pass)){
if(!empty($_POST['form']) && $_POST['form']) header("Location:login.php?error=1");
else header("Location:login.php");
exit;
}
/* deleting a newsletter*/
if($action =="delete" && $page =="newsletterconf"){
$deleted = deleteNewsletter($conf->db_host, $conf->db_login, $conf->db_pass,$conf->db_name,
$conf->table_listsconfig, $conf->table_archives,
$conf->table_email, $conf->table_temp, $list_id);
}
$newsletter = new Newsletter();
/* saving the configuration */
if($op=="SaveConfig"){
$save = $newsletter->saveConfig($conf->db_host, $conf->db_login, $conf->db_pass,
$conf->db_name, $_POST['list_id'], $conf->table_listsconfig,
$_POST['newsletter_name'], $_POST['from'],
$_POST['from_name'], $_POST['subject'],
$_POST['header'], $_POST['footer'],
$_POST['subscription_subject'],
$_POST['subscription_body'],$_POST['welcome_subject'],
$_POST['welcome_body'],
$_POST['quit_subject'], $_POST['quit_body']);
}
/* adding a new newsletter */
if($op=="createConfig"){
$new_id=createNewsletter($conf->db_host, $conf->db_login, $conf->db_pass,
$conf->db_name, $conf->table_listsconfig, $_POST['newsletter_name'],
$_POST['from'], $_POST['from_name'],
$_POST['subject'], $_POST['header'], $_POST['footer'],
$_POST['subscription_subject'], $_POST['subscription_body'],
$_POST['welcome_subject'], $_POST['welcome_body'],
$_POST['quit_subject'], $_POST['quit_body']);
if($new_id>0) $list_id=$new_id;
}
$list_name=-1;
if(!empty($list_id)){
$list_name=get_newsletter_name($conf->db_host, $conf->db_login, $conf->db_pass, $conf->db_name, $conf->table_listsconfig,$list_id);
if($list_name==-1) unset($list_id);
}
$list = list_newsletter($conf->db_host, $conf->db_login, $conf->db_pass,
$conf->db_name, $conf->table_listsconfig);
if(empty($list_id)) $list_id=get_first_newsletter_id($conf->db_host, $conf->db_login,
$conf->db_pass,
$conf->db_name, $conf->table_listsconfig);
//no newsletter available, so let's configure the first one !
if(sizeof($list) == 0 && $page != "config") {
$page = "newsletterconf";
$action = "create";
}
$list_total_subscribers = get_newsletter_total_subscribers($conf->db_host, $conf->db_login, $conf->db_pass, $conf->db_name, $conf->table_email,$list_id);
include("include/pageheader.inc.php");
if(!flushTempTable($conf->db_host, $conf->db_login,
$conf->db_pass, $conf->db_name,
$conf->table_temp, $conf->validation_period)){
echo error_msg(translate("ERROR_FLUSHING_TEMP_TABLE",$conf->table_temp));
}
else echo "
";
switch($page){
/* archives section */
case "archives":
require 'include/archives.php';
break;
/* phpmynewsletter global configuration section */
case "config":
require 'include/globalconf.php';
break;
/* write a new message and send it*/
case "compose":
require('include/compose.php');
break;
/* managing newsletter */
/* TODO: this section really need refactoring */
case "newsletterconf":
if(!sizeof($list)) {
$action = "create";
}
if(sizeof($list)){
echo " ";
echo " ";
if($action!="create"){
echo "";
echo "
".translate("NEWSLETTER_ACTION")."
";
echo "
";
echo "\t\n";
echo "
";
echo "
";
}
}
if($action=="create"){
echo "";
echo "
".translate("NEWSLETTER_CREATE")."
";
echo "
";
echo "
";
echo "
";
}
if(isset($list_id) && !empty($list_id)){
if($action=="delete"){
if($deleted) {
echo "".translate("NEWSLETTER_DELETED").".
";
} else {
echo "".translate("ERROR_DELETING_NEWSLETTER").".
";
}
}
if(empty($action)){
if($op=="SaveConfig"){
if($save) echo "".translate("NEWSLETTER_SETTINGS_SAVED")."
";
else echo "".translate("ERROR_SAVING_SETTINGS", "
".DbError())."
";
}
if($op=="createConfig") {
if($new_id){
echo "".translate("NEWSLETTER_SETTINGS_CREATED").".
";
} else {
echo "".translate("ERROR_SAVING_SETTINGS"," :
".DbError())."
";
}
}
echo "";
echo "
".translate("NEWSLETTER_SETTINGS")."
";
echo "
";
echo "
";
echo "
";
}
}
break;
/* Add/delete subscribers section*/
case "subscribers":
default:
require("include/subscribers.php");
break;
}
include("include/pagefooter.inc.php");
?>