<?php

/*******************************************************************************
 * eredeti url: http://www.archline.hu/events/newclick/bar_a_varos_tetejen/zsolt.fekete@cadline.hu
 * teszt: http://dev.cadline.hu/events/newclick/betaletoltes32/mcleod78@gmail.com
 ******************************************************************************/
error_reporting(E_ERROR | E_PARSE);
if (!class_exists('crm_users')) require_once("common_cadline_libraries/crm_users.class.php");

define('DOMAIN', 'www.archline.hu');
$alias  = $_GET['alias']; // segment(3);
$email  = str_replace("%40", "@", $_GET['email']); // segment(4);
$target = "";

switch ($alias) {
    case "create_3d": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=87";
            break;
        }
    case "polygon_reduction": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=84";
            break;
        }
    case "akcio-construma": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=790";
            break;
        }
    case "akcio-hv": {
            $target = "http://" . DOMAIN;
            break;
        }
    case "akcio-vn": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=790";
            break;
        }
    case "bar_a_varos_tetejen": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=266";
            break;
        }
    case "betaletoltes32": {
            $target = "http://" . DOMAIN . "/public/downloads/eng/ARCHLINE_XP2014_Beta_32bit_setup.exe";
            break;
        }
    case "betaletoltes64": {
            $target = "http://" . DOMAIN . "/public/downloads/eng/ARCHLINE_XP2014_Beta_64bit_setup.exe";
            break;
        }
        // case "construma" : { $target="http://".DOMAIN."/workshop/construma"; break;}
    case "interiorworkshopcsoport": {
            $target = "http://" . DOMAIN . "/workshopok/kezdo-szint/intenziv-kezdo-kurzusok";
            break;
        }
    case "download-int-hun": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=836";
            break;
        }
    case "megjelent_2014": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=264";
            break;
        }
    case "save_environment": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=86";
            break;
        }
    case "convert_object_to_door_window": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=926";
            break;
        }
    case "oled_stilus": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=791";
            break;
        }
    case "select_all": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=72";
            break;
        }
    case "project_backup": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=85";
            break;
        }
    case "reader": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=268";
            break;
        }
    case "szolgaltatasok-sk-arak": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=889";
            break;
        }
    case "szolgaltatasok-re-arak": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=893";
            break;
        }
    case "szolgaltatasok-vs-arak": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=894";
            break;
        }
    case "szolgaltatasok-kezirajz": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=889";
            break;
        }
    case "multi-pointer": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=82";
            break;
        }
    case "ujdonsagok-2014": {
            $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=74";
            break;
        }
    case "kereskedelmi_egyseg_2": {
            $target = "http://" . DOMAIN . "/workshopok/halado-szint/kereskedelmi-egyseg-i-2-es-szint";
            break;
        }
    default: {
            crm_database::getInstance()->query("SELECT * FROM `" . JMLADATBAZIS . "`.jml_content WHERE `alias`='" . $alias . "' ORDER BY id DESC LIMIT 1;");
            $res = crm_database::getInstance()->fetchAssoc();

            if (count($res)) {
                $res = $res[0];
                $target = "http://" . DOMAIN . "/index.php?option=com_content&view=article&id=" . $res['id'] . "&catid=" . $res['catid'];
            }
            break;
        }
}

crm_database::getInstance()->query("SELECT * FROM `" . JMLADATBAZIS . "`.`followed_links` WHERE `alias`='" . $alias . "' LIMIT 1");
$res = crm_database::getInstance()->fetchAssoc();

if (count($res)) {
    $adatok = (object)$res[0];
    if (trim($email) > '' && filter_var($email, FILTER_VALIDATE_EMAIL)) {
        crm_users::levelesemeny($email, "events", "newclick", $adatok->esem_id, $adatok->esem_cont, $adatok->esem_cont, $adatok->lang, $adatok->name);
    }
    if ($target != $adatok->redirect) $target = $adatok->redirect;
}

$loc = ($target > '' ? $target : ((isset($adatok->redirect) && trim($adatok->redirect) > "") ? $adatok->redirect : "http://" . DOMAIN));

parse_str($_SERVER['QUERY_STRING'], $query);
if (array_key_exists('alias', $query)) unset($query['alias']);
if (array_key_exists('email', $query)) unset($query['email']);
if (count($query)) $querystr =  http_build_query($query);

header("Location: " . $loc . (isset($querystr) && $querystr > '' ? '?' . $querystr : ''));
exit();
