}
    } else {
        $case = code_error;
        $info_message = TEXT_CODE_ERROR;
    }
}
// Verification
if (isset($_GET['action']) && $_GET['action'] == 'verified') {
    $check_customer_query = vam_db_query("select customers_id, customers_email_address, password_request_key from " . TABLE_CUSTOMERS . " where customers_id = '" . (int) $_GET['customers_id'] . "' and password_request_key = '" . vam_db_input($_GET['key']) . "'");
    $check_customer = vam_db_fetch_array($check_customer_query);
    if (!vam_db_num_rows($check_customer_query) || $_GET['key'] == "") {
        $case = no_account;
        $info_message = TEXT_NO_ACCOUNT;
    } else {
        $newpass = vam_create_random_value(ENTRY_PASSWORD_MIN_LENGTH);
        $crypted_password = vam_encrypt_password($newpass);
        vam_db_query("update " . TABLE_CUSTOMERS . " set customers_password = '******' where customers_email_address = '" . $check_customer['customers_email_address'] . "'");
        vam_db_query("update " . TABLE_CUSTOMERS . " set password_request_key = '' where customers_id = '" . $check_customer['customers_id'] . "'");
        // assign language to template for caching
        $vamTemplate->assign('language', $_SESSION['language']);
        $vamTemplate->assign('tpl_path', 'templates/' . CURRENT_TEMPLATE . '/');
        $vamTemplate->assign('logo_path', HTTP_SERVER . DIR_WS_CATALOG . 'templates/' . CURRENT_TEMPLATE . '/img/');
        // assign vars
        $vamTemplate->assign('EMAIL', $check_customer['customers_email_address']);
        $vamTemplate->assign('NEW_PASSWORD', $newpass);
        // dont allow cache
        $vamTemplate->caching = false;
        // create mails
        $html_mail = $vamTemplate->fetch(CURRENT_TEMPLATE . '/mail/' . $_SESSION['language'] . '/new_password_mail.html');
        $txt_mail = $vamTemplate->fetch(CURRENT_TEMPLATE . '/mail/' . $_SESSION['language'] . '/new_password_mail.txt');
        vam_php_mail(EMAIL_SUPPORT_ADDRESS, EMAIL_SUPPORT_NAME, $check_customer['customers_email_address'], '', '', EMAIL_SUPPORT_REPLY_ADDRESS, EMAIL_SUPPORT_REPLY_ADDRESS_NAME, '', '', TEXT_EMAIL_PASSWORD_NEW_PASSWORD, $html_mail, $txt_mail);
    $error = false;
    if (strlen($password_current) < ENTRY_PASSWORD_MIN_LENGTH) {
        $error = true;
        $messageStack->add('account_password', ENTRY_PASSWORD_CURRENT_ERROR);
    } elseif (strlen($password_new) < ENTRY_PASSWORD_MIN_LENGTH) {
        $error = true;
        $messageStack->add('account_password', ENTRY_PASSWORD_NEW_ERROR);
    } elseif ($password_new != $password_confirmation) {
        $error = true;
        $messageStack->add('account_password', ENTRY_PASSWORD_NEW_ERROR_NOT_MATCHING);
    }
    if ($error == false) {
        $check_customer_query = vam_db_query("select customers_password from " . TABLE_CUSTOMERS . " where customers_id = '" . (int) $_SESSION['customer_id'] . "'");
        $check_customer = vam_db_fetch_array($check_customer_query);
        if (vam_validate_password($password_current, $check_customer['customers_password'])) {
            vam_db_query("UPDATE " . TABLE_CUSTOMERS . " SET customers_password = '******', customers_last_modified=now() WHERE customers_id = '" . (int) $_SESSION['customer_id'] . "'");
            vam_db_query("UPDATE " . TABLE_CUSTOMERS_INFO . " SET customers_info_date_account_last_modified = now() WHERE customers_info_id = '" . (int) $_SESSION['customer_id'] . "'");
            $messageStack->add_session('account', SUCCESS_PASSWORD_UPDATED, 'success');
            vam_redirect(vam_href_link(FILENAME_ACCOUNT, '', 'SSL'));
        } else {
            $error = true;
            $messageStack->add('account_password', ERROR_CURRENT_PASSWORD_NOT_MATCHING);
        }
    }
}
$breadcrumb->add(NAVBAR_TITLE_1_ACCOUNT_PASSWORD, vam_href_link(FILENAME_ACCOUNT, '', 'SSL'));
$breadcrumb->add(NAVBAR_TITLE_2_ACCOUNT_PASSWORD, vam_href_link(FILENAME_ACCOUNT_PASSWORD, '', 'SSL'));
require DIR_WS_INCLUDES . 'header.php';
if ($messageStack->size('account_password') > 0) {
    $vamTemplate->assign('error', $messageStack->output('account_password'));
}
 //		$error = true;
 //
 //		$messageStack->add('checkout_alternative', ENTRY_PASSWORD_ERROR);
 //	}
 //	elseif ($password != $confirmation) {
 //		$error = true;
 //
 //		$messageStack->add('checkout_alternative', ENTRY_PASSWORD_ERROR_NOT_MATCHING);
 //	}
 //	if ($customers_status == 0 || !$customers_status)
 $customers_status = DEFAULT_CUSTOMERS_STATUS_ID;
 if (!$newsletter) {
     $newsletter = 0;
 }
 if ($error == false) {
     $sql_data_array = array('customers_vat_id' => $vat, 'customers_vat_id_status' => $customers_vat_id_status, 'customers_status' => $customers_status, 'customers_firstname' => $firstname, 'customers_secondname' => $secondname, 'customers_lastname' => $lastname, 'customers_email_address' => $email_address, 'customers_telephone' => $telephone, 'customers_fax' => $fax, 'orig_reference' => $html_referer, 'customers_newsletter' => $newsletter, 'delete_user' => '0', 'account_type' => '0', 'customers_password' => vam_encrypt_password($password), 'customers_date_added' => 'now()', 'customers_last_modified' => 'now()');
     $_SESSION['account_type'] = '1';
     if (ACCOUNT_GENDER == 'true') {
         $sql_data_array['customers_gender'] = $gender;
     }
     if (ACCOUNT_DOB == 'true') {
         $sql_data_array['customers_dob'] = vam_date_raw($dob);
     }
     vam_db_perform(TABLE_CUSTOMERS, $sql_data_array);
     $_SESSION['customer_id'] = vam_db_insert_id();
     $extra_fields_query = vamDBquery("select ce.fields_id from " . TABLE_EXTRA_FIELDS . " ce where ce.fields_status=1 ");
     $customers_id = $_SESSION['customer_id'];
     $extra_fields_query = vam_db_query("select ce.fields_id from " . TABLE_EXTRA_FIELDS . " ce where ce.fields_status=1 ");
     while ($extra_fields = vam_db_fetch_array($extra_fields_query)) {
         if (isset($_POST['fields_' . $extra_fields['fields_id']])) {
             $sql_data_array = array('customers_id' => (int) $customers_id, 'fields_id' => $extra_fields['fields_id'], 'value' => $_POST['fields_' . $extra_fields['fields_id']]);
 $entry_suburb = vam_db_prepare_input($_POST['entry_suburb']);
 $entry_postcode = vam_db_prepare_input($_POST['entry_postcode']);
 $entry_city = vam_db_prepare_input($_POST['entry_city']);
 $entry_country_id = vam_db_prepare_input($_POST['entry_country_id']);
 $entry_company = vam_db_prepare_input($_POST['entry_company']);
 $entry_state = vam_db_prepare_input($_POST['entry_state']);
 $entry_zone_id = vam_db_prepare_input($_POST['entry_zone_id']);
 $customers_send_mail = vam_db_prepare_input($_POST['customers_mail']);
 $customers_password_encrypted = vam_db_prepare_input($_POST['entry_password']);
 $customers_password = vam_encrypt_password($customers_password_encrypted);
 $customers_mail_comments = vam_db_prepare_input($_POST['mail_comments']);
 $payment_unallowed = vam_db_prepare_input($_POST['payment_unallowed']);
 $shipping_unallowed = vam_db_prepare_input($_POST['shipping_unallowed']);
 if ($customers_password == '') {
     $customers_password_encrypted = vam_RandomString(8);
     $customers_password = vam_encrypt_password($customers_password_encrypted);
 }
 $error = false;
 // reset error flag
 if (ACCOUNT_GENDER == 'true') {
     if ($customers_gender != 'm' && $customers_gender != 'f') {
         $error = true;
         $entry_gender_error = true;
     } else {
         $entry_gender_error = false;
     }
 }
 if (strlen($customers_password) < ENTRY_PASSWORD_MIN_LENGTH) {
     $error = true;
     $entry_password_error = true;
 } else {
 } else {
     $entry_email_address_exists = false;
 }
 $extra_fields_query = vam_db_query("select ce.fields_id, ce.fields_input_type, ce.fields_required_status, cei.fields_name, ce.fields_status, ce.fields_input_type, ce.fields_size from " . TABLE_EXTRA_FIELDS . " ce, " . TABLE_EXTRA_FIELDS_INFO . " cei where ce.fields_status=1 and ce.fields_required_status=1 and cei.fields_id=ce.fields_id and cei.languages_id =" . (int) $_SESSION['languages_id']);
 while ($extra_fields = vam_db_fetch_array($extra_fields_query)) {
     if (strlen($_POST['fields_' . $extra_fields['fields_id']]) < $extra_fields['fields_size']) {
         $error = true;
         $string_error = sprintf(ENTRY_EXTRA_FIELDS_ERROR, $extra_fields['fields_name'], $extra_fields['fields_size']);
         $messageStack->add($string_error);
     }
 }
 if ($error == false) {
     $sql_data_array = array('customers_firstname' => $customers_firstname, 'customers_secondname' => $customers_secondname, 'customers_cid' => $customers_cid, 'customers_vat_id' => $customers_vat_id, 'customers_vat_id_status' => (int) $customers_vat_id_status, 'customers_lastname' => $customers_lastname, 'customers_email_address' => $customers_email_address, 'customers_telephone' => $customers_telephone, 'customers_fax' => $customers_fax, 'customers_personal_discount' => $customers_personal_discount, 'payment_unallowed' => $payment_unallowed, 'shipping_unallowed' => $shipping_unallowed, 'customers_newsletter' => $customers_newsletter, 'customers_last_modified' => 'now()');
     // if new password is set
     if ($password != "") {
         $sql_data_array = array_merge($sql_data_array, array('customers_password' => vam_encrypt_password($password)));
     }
     if (ACCOUNT_GENDER == 'true') {
         $sql_data_array['customers_gender'] = $customers_gender;
     }
     if (ACCOUNT_DOB == 'true') {
         $sql_data_array['customers_dob'] = vam_date_raw($customers_dob);
     }
     vam_db_perform(TABLE_CUSTOMERS, $sql_data_array, 'update', "customers_id = '" . vam_db_input($customers_id) . "'");
     vam_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_account_last_modified = now() where customers_info_id = '" . vam_db_input($customers_id) . "'");
     if ($entry_zone_id > 0) {
         $entry_state = '';
     }
     $sql_data_array = array('entry_firstname' => $customers_firstname, 'entry_secondname' => $customers_secondname, 'entry_lastname' => $customers_lastname, 'entry_street_address' => $entry_street_address, 'entry_postcode' => $entry_postcode, 'entry_city' => $entry_city, 'entry_country_id' => (int) $entry_country_id, 'address_last_modified' => 'now()');
     if (ACCOUNT_COMPANY == 'true') {
         $sql_data_array['entry_company'] = $entry_company;
     $error = true;
     $entry_agb_error = true;
 }
 // Check Company
 $entry_company_error = false;
 $entry_company_taxid_error = false;
 // Check Payment
 $entry_payment_check_error = false;
 $entry_payment_paypal_error = false;
 $entry_payment_bank_name_error = false;
 $entry_payment_bank_branch_number_error = false;
 $entry_payment_bank_swift_code_error = false;
 $entry_payment_bank_account_name_error = false;
 $entry_payment_bank_account_number_error = false;
 if (!$error) {
     $sql_data_array = array('affiliate_firstname' => $a_firstname, 'affiliate_lastname' => $a_lastname, 'affiliate_email_address' => $a_email_address, 'affiliate_payment_check' => $a_payment_check, 'affiliate_payment_paypal' => $a_payment_paypal, 'affiliate_payment_bank_name' => $a_payment_bank_name, 'affiliate_payment_bank_branch_number' => $a_payment_bank_branch_number, 'affiliate_payment_bank_swift_code' => $a_payment_bank_swift_code, 'affiliate_payment_bank_account_name' => $a_payment_bank_account_name, 'affiliate_payment_bank_account_number' => $a_payment_bank_account_number, 'affiliate_street_address' => $a_street_address, 'affiliate_postcode' => $a_postcode, 'affiliate_city' => $a_city, 'affiliate_country_id' => $a_country, 'affiliate_telephone' => $a_telephone, 'affiliate_fax' => $a_fax, 'affiliate_homepage' => $a_homepage, 'affiliate_password' => vam_encrypt_password($a_password), 'affiliate_agb' => '1');
     if (ACCOUNT_GENDER == 'true') {
         $sql_data_array['affiliate_gender'] = $a_gender;
     }
     if (ACCOUNT_DOB == 'true') {
         $sql_data_array['affiliate_dob'] = vam_date_raw($a_dob);
     }
     if (ACCOUNT_COMPANY == 'true') {
         $sql_data_array['affiliate_company'] = $a_company;
         $sql_data_array['affiliate_company_taxid'] = $a_company_taxid;
     }
     if (ACCOUNT_SUBURB == 'true') {
         $sql_data_array['affiliate_suburb'] = $a_suburb;
     }
     if (ACCOUNT_STATE == 'true') {
         if ($a_zone_id > 0) {