<?php
    require("config.php");

    //------------------------------
    // VERSIUNEA SITE-ului
    $site_version = "1.0.0.0";
    //------------------------------

    if (!function_exists("getuserdata"))
    {
        function getuserdata($paramname, $defaultvalue=NULL)
        {
            if (isset($_REQUEST[$paramname]))
                if ($_REQUEST[$paramname] != "")
                    if (get_magic_quotes_gpc())
                        return $_REQUEST[$paramname];
                    else
                        return addslashes($_REQUEST[$paramname]);
                else return $defaultvalue;
            else return $defaultvalue;
        }
    }

    @session_start();

    $connected = false;
    $authenticated = false;

    if (isset($_SESSION['saved_session_id']))
        if ($_SESSION['saved_session_id'] != session_id())
        {
            $_SESSION['saved_session_id'] = session_id();
        }
        else ;
    else $_SESSION['saved_session_id'] = session_id();
    
    $connMain = mysqli_init();
    $connected = $connMain->real_connect($dbserver, $dbuser, $dbpass, $dbname);
    if ($connected)
    {
        $connMain->query("SET CHARACTER SET utf8");
    }
    
    $connection = mysql_connect($dbserver, $dbuser, $dbpass, true);
    $db = mysql_select_db($dbname);
    $error = "";
    if ($connection)
    {
        $connected = true;
        $q = mysql_query("SET CHARACTER SET utf8");
        $authenticated = false; // not needed here
    }
    else $error = 'Nu se poate realiza conexiunea cu serverul de date!<br><br>Eroare internă: '.mysql_error();

    if (!function_exists("check_auth"))
    {
        function check_auth()
        {
            global $authenticated, $scriptroot;
            if (!$authenticated)
            {
                header("Location: {$scriptroot}");
                echo "Please press <a href='{$scriptroot}'>here</a> to enter your credentials.";
                exit;
            }
        }
    }

    if (!function_exists("check_connected"))
    {
        function check_connected()
        {
            global $connected, $scriptroot;
            if (!$connected)
            {
                header("Location: {$scriptroot}");
                echo "Please press <a href='{$scriptroot}'>here</a> to connect.";
                exit;
            }
        }
    }
?>