<?php
$themoney_api = new themoneytizer_API();

$themoney_website = $themoney_api->getWebsite(get_option('themoneytizer_setting_siteid'));

if (isset($_POST['submit'])){
	if (isset($_POST['formatauto'])){
	    $post_format = $themoney_api->adminPanel($_POST['formatauto'],$_POST['submit']);
	}
	else{
	    $post_format = $themoney_api->adminPanel(array(),$_POST['submit']);
	}
}

$registered_format = explode("-",stripslashes(get_option('themoneytizer_autoformats')));

if( $themoney_website != null){
	if(!isset($themoney_website->infos_user->user_raison_ajout_id)){
		$themoney_website->infos_user->user_raison_ajout_id = null;
	}
	if(!isset($themoney_website->infos_user->user_raison_ajout_autre)){
		$themoney_website->infos_user->user_raison_ajout_autre = null;
	}
	update_option( 'prenom_money',stripslashes($themoney_website->infos_user->user_firstname));
	update_option( 'nom_money',stripslashes($themoney_website->infos_user->user_lastname));
	update_option( 'mail_money',stripslashes($themoney_website->infos_user->user_mail));
	update_option( 'tel_money',stripslashes($themoney_website->infos_user->user_phone));
	update_option( 'adresse_money',stripslashes($themoney_website->infos_user->user_adress));
	update_option( 'ville_money',stripslashes($themoney_website->infos_user->user_city));
	update_option( 'cp_money',stripslashes($themoney_website->infos_user->user_zip));
	update_option( 'country_money',stripslashes($themoney_website->infos_user->user_country));
	update_option( 'raison_ajout_money',stripslashes($themoney_website->infos_user->user_raison_ajout_id));
	update_option( 'raison_ajout_autre_money',stripslashes($themoney_website->infos_user->user_raison_ajout_autre));
	update_option( 'id_site_money',stripslashes($themoney_website->infos_user->site_id));
	update_option( 'user_bank_name_money',stripslashes($themoney_website->infos_user->user_bank_name));
	update_option( 'user_bank_iban_money',stripslashes($themoney_website->infos_user->user_bank_iban));
	update_option( 'user_bank_bic_money',stripslashes($themoney_website->infos_user->user_bank_bic));
	update_option( 'user_bank_namebank_money',stripslashes($themoney_website->infos_user->user_bank_namebank));
	update_option( 'user_bank_adressbank_money',stripslashes($themoney_website->infos_user->user_bank_adressbank));
	update_option( 'user_bank_countrybank_money',stripslashes($themoney_website->infos_user->user_bank_countrybank));
	update_option( 'user_bank_citybank_money',stripslashes($themoney_website->infos_user->user_bank_citybank));
	update_option( 'user_bank_zipbank_money',stripslashes($themoney_website->infos_user->user_bank_zipbank));
    update_option('themoney_type_structure', stripslashes($themoney_website->infos_user->user_type_structure));
	update_option( 'user_entreprise_money',stripslashes($themoney_website->infos_user->user_entreprise));
	update_option( 'user_siren_money',stripslashes($themoney_website->infos_user->user_siren));
	update_option( 'user_tva_money',stripslashes($themoney_website->infos_user->user_tva));
	update_option( 'user_id_money',stripslashes($themoney_website->infos_user->user_id));
	update_option( 'paypal_money',stripslashes($themoney_website->infos_user->user_paypal_mail));
	update_option('themoney_site_ads_txt', stripslashes($themoney_website->site_ads_txt));
	update_option('themoney_site_cmp', stripslashes($themoney_website->site_cmp));
	update_option('themoney_site_reset_plugin', stripslashes($themoney_website->site_reset_plugin));
	update_option( 'themoney_is_registered',"4");
	update_option( 'themoney_user_language', strtolower(substr(get_bloginfo("language"), 3, 2)));
	update_option('themoney_ads_version', stripslashes($themoney_website->ads_version));
    update_option('themoney_raison_refus', stripslashes($themoney_website->raison_refus));

    if (!empty(get_option('paypal_money'))) {
        update_option('bankChoice_money', 2);
    } elseif (!empty(get_option('user_bank_iban_money'))) {
        update_option('bankChoice_money', 1);
    }
}

$themoney_registered = get_option('themoney_is_registered');

if($themoney_registered == 1){
    include 'themoneytizer_panel_valid_inscription.php';
}
if($themoney_registered == 2){
    include 'themoneytizer_panel_signup_profile.php';
}
if($themoney_registered == 3){
    include 'themoneytizer_panel_signup_profile2.php';
}
if($themoney_registered == null || ($themoney_registered == 4 && $themoney_website == null)) {
    include 'themoneytizer_panel_signup_welcome.php';
}
if($themoney_registered == 4 && $themoney_website != null){
    include 'themoneytizer_home.php';
}
