<?php 
/*
 * ----------------------------------------------
 * Lazarus Guestbook
 * by Stewart Souter
 * URL: www.carbonize.co.uk 
 * Based on Advanced Guestbook 2.3.x (PHP/MySQL)
 * Copyright (c)2001 Chi Kien Uong
 * URL: http://www.proxy2.de
 * Last Modified: Tue, 30 July 2013 20:35:33 GMT
 * ----------------------------------------------
 */

define('IS_INCLUDE', false);
define('LAZ_INCLUDE_PATH', dirname(__FILE__));

// Include necessary files
include_once LAZ_INCLUDE_PATH . '/admin/version.php';
include_once LAZ_INCLUDE_PATH . '/admin/config.inc.php';
include_once LAZ_INCLUDE_PATH . '/lib/' . $DB_CLASS;
include_once LAZ_INCLUDE_PATH . '/lib/image.class.php';
include_once LAZ_INCLUDE_PATH . '/lib/template.class.php';
include_once LAZ_INCLUDE_PATH . '/lib/vars.class.php';
include_once LAZ_INCLUDE_PATH . '/lib/add.class.php';

define('LAZ_TABLE_PREFIX', $table_prefix);

$gb_post = new addentry(LAZ_INCLUDE_PATH);

// Redirect based on configuration
if ($gb_post->db->VARS['included'] == 1) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: " . $gb_post->db->VARS['laz_url']);
    exit;
} elseif ($gb_post->db->VARS['included'] == 2) {
    header("HTTP/1.0 404 Not Found");
    exit;
}

$GB_PG = [
    'base_url' => $gb_post->db->VARS['base_url'],
    'index'    => $gb_post->db->VARS['base_url'] . '/index.php',
    'admin'    => $gb_post->db->VARS['base_url'] . '/admin.php',
    'comment'  => $gb_post->db->VARS['base_url'] . '/comment.php',
    'addentry' => $gb_post->db->VARS['base_url'] . '/addentry.php',
];

$antispam = $gb_post->db->VARS['antispam_word'];

// Check if a form was submitted
if (isset($_POST['agb_submit_' . $antispam]) || isset($_POST['agb_preview_' . $antispam])) {
    $gb_post->name = $_POST['gb_name'] ?? '';
    $gb_post->email = $_POST['gb_email'] ?? '';
    $gb_post->url = $_POST['gb_url'] ?? '';
    $gb_post->comment = $_POST['gb_comment'] ?? '';
    $gb_post->location = $_POST['gb_location'] ?? '';
    $gb_post->icq = $_POST['gb_icq'] ?? 0;
    $gb_post->aim = $_POST['gb_aim'] ?? '';
    $gb_post->msn = $_POST['gb_msn'] ?? '';
    $gb_post->yahoo = $_POST['gb_yahoo'] ?? '';
    $gb_post->skype = $_POST['gb_skype'] ?? '';
    $gb_post->gender = $_POST['gb_gender'] ?? '';

    if (($gb_post->db->VARS['solve_media'] == 1) && ($gb_post->db->VARS['antibottest'] == 2)) {
        $gb_post->bottest = trim($_POST['adcopy_response'] ?? '');
    } else {
        $gb_post->bottest = trim($_POST['gb_bottest'] ?? '');
    }

    $gb_post->timehash = $_POST['gb_timehash'] ?? '';
    $gb_post->keep_pic = isset($_POST['keep_pic']) ? 1 : 0;

    $gb_post->userfile = (!empty($_FILES['userfile']['tmp_name'])) ? $_FILES : '';
    $gb_post->user_img = ($_POST['gb_user_img'] ?? '') && $gb_post->keep_pic && empty($gb_post->userfile) 
        ? $_POST['gb_user_img'] 
        : '';

    $gb_post->preview = isset($_POST['gb_preview']) ? 1 : 0;
    $gb_post->private = isset($_POST['gb_private']) ? 1 : 0;
    $gb_post->honeypot = isset($_POST[$antispam]) ? 1 : 0;

    $gb_action = isset($_POST['agb_preview_' . $antispam]) ? 'preview' : 'submit';

    echo $gb_post->process($gb_action);
} else {
    // Display the form if nothing is submitted
    echo $gb_post->process();
}
?>