function processEvents()
{
    global $CONFIG;
    $count = 0;
    while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_va_" . $count])) {
        $event = new Event($_POST[POST_INTERN_PROCESS_EVENTS . "_va_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vb_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vc_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vd_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_ve_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vf_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vg_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vh_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vk_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vl_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vm_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vn_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vo_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vp_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vq_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vt_" . $count]);
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id`='" . DBManager::RealEscape($event->Id) . "' LIMIT 1;");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "`.`eid`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_OVERLAYS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_OVERLAYS . "`.`action_id`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_RECEIVERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_RECEIVERS . "`.`action_id`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_WEBSITE_PUSHS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_WEBSITE_PUSHS . "`.`action_id`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_URLS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "`.`uid`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "`.`eid`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_SENDERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_OVERLAYS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_SENDERS . "`.`pid`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_WEBSITE_PUSHS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_SENDERS . "`.`pid`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_GOALS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_GOALS . "`.`goal_id`)");
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_URLS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_URLS . "`.`eid`)");
        if (!isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vx_" . $count])) {
            queryDB(true, $event->GetSQL());
            $counturl = 0;
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_a_" . $counturl])) {
                $eventURL = new EventURL($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_f_" . $counturl], $event->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_a_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_b_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_c_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_d_" . $counturl]);
                queryDB(true, $eventURL->GetSQL());
                if (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_e_" . $counturl])) {
                    queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "` (`eid`,`uid`,`ind`) VALUES ('" . DBManager::RealEscape($event->Id) . "','" . DBManager::RealEscape($eventURL->Id) . "','" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_e_" . $counturl]) . "');");
                }
                $counturl++;
            }
            $countgoals = 0;
            queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` WHERE `event_id` = '" . DBManager::RealEscape($event->Id) . "';");
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count . "_a_" . $countgoals])) {
                queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` (`event_id`,`goal_id`) VALUES ('" . DBManager::RealEscape($event->Id) . "','" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count . "_a_" . $countgoals]) . "');");
                $countgoals++;
            }
            $countaction = 0;
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_a_" . $countaction])) {
                $eventAction = new EventAction($event->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_b_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_c_" . $countaction]);
                queryDB(true, $eventAction->GetSQL());
                if ($eventAction->Type == 2 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_a_" . $countaction])) {
                    $invitationSettings = @unserialize(base64_decode($CONFIG["gl_invi"]));
                    array_walk($invitationSettings, "b64dcode");
                    //$invitationHTML = applyReplacements($BROWSER->ChatRequest->CreateInvitationTemplate($invitationSettings[13],$CONFIG["gl_site_name"],$CONFIG["wcl_window_width"],$CONFIG["wcl_window_height"],LIVEZILLA_URL,$INTERNAL[$BROWSER->ChatRequest->SenderSystemId],$invitationSettings[0]));
                    //$BROWSER->ChatRequest->Invitation = new Invitation($invitationHTML,$BROWSER->ChatRequest->Text,$invitationSettings);
                    $eventActionInvitation = new Invitation($eventAction->Id, $invitationSettings);
                    queryDB(true, $eventActionInvitation->GetSQL());
                    $countsender = 0;
                    while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_a_" . $countaction . "_" . $countsender])) {
                        $eventActionInvitationSender = new EventActionSender($eventActionInvitation->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_a_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_b_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_c_" . $countaction . "_" . $countsender]);
                        $eventActionInvitationSender->SaveSender();
                        $countsender++;
                    }
                } else {
                    if ($eventAction->Type == 5 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_a_" . $countaction])) {
                        $eventActionOverlayBox = new OverlayElement($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_b_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_c_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_d_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_e_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_f_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_g_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_h_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_i_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_j_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_k_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_l_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_m_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_n_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_o_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_p_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_q_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_r_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_s_" . $countaction]);
                        queryDB(true, $eventActionOverlayBox->GetSQL());
                    } else {
                        if ($eventAction->Type == 4 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_a_" . $countaction])) {
                            $eventActionWebsitePush = new WebsitePush($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_b_" . $countaction]);
                            $eventActionWebsitePush->SaveEventConfiguration();
                            $countsender = 0;
                            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_a_" . $countaction . "_" . $countsender])) {
                                $eventActionWebsitePushSender = new EventActionSender($eventActionWebsitePush->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_a_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_b_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_c_" . $countaction . "_" . $countsender]);
                                $eventActionWebsitePushSender->SaveSender();
                                $countsender++;
                            }
                        } else {
                            if ($eventAction->Type < 2) {
                                $countreceiver = 0;
                                while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_d_" . $countaction . "_" . $countreceiver])) {
                                    $eventActionReceiver = new EventActionReceiver($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_d_" . $countaction . "_" . $countreceiver], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_e_" . $countaction . "_" . $countreceiver]);
                                    queryDB(true, $eventActionReceiver->GetSQL());
                                    $countreceiver++;
                                }
                            }
                        }
                    }
                }
                $countaction++;
            }
        }
        $count++;
    }
    if ($count > 0) {
        CacheManager::SetDataUpdateTime(DATA_UPDATE_KEY_EVENTS);
    }
}
function appendEvents()
{
    global $VISITOR;
    $count = 0;
    while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_va_" . $count])) {
        $event = new Event($_POST[POST_INTERN_PROCESS_EVENTS . "_va_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vb_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vc_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vd_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_ve_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vf_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vg_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vh_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vk_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vl_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vm_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vn_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vo_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vp_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vq_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count]);
        queryDB(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id`='" . @mysql_real_escape_string($event->Id) . "' LIMIT 1;");
        if (!isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vx_" . $count])) {
            queryDB(true, $event->GetSQL());
            $counturl = 0;
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_a_" . $counturl])) {
                $eventURL = new EventURL($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_f_" . $counturl], $event->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_a_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_b_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_c_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_d_" . $counturl]);
                queryDB(true, $eventURL->GetSQL());
                if (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_e_" . $counturl])) {
                    queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "` (`eid`,`uid`,`ind`) VALUES ('" . @mysql_real_escape_string($event->Id) . "','" . @mysql_real_escape_string($eventURL->Id) . "','" . @mysql_real_escape_string($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_e_" . $counturl]) . "');");
                }
                $counturl++;
            }
            $countgoals = 0;
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count . "_a_" . $countgoals])) {
                queryDB(true, "INSERT INTO `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` (`event_id`,`goal_id`) VALUES ('" . @mysql_real_escape_string($event->Id) . "','" . @mysql_real_escape_string($_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count . "_a_" . $countgoals]) . "');");
                $countgoals++;
            }
            $countaction = 0;
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_a_" . $countaction])) {
                $eventAction = new EventAction($event->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_b_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_c_" . $countaction]);
                queryDB(true, $eventAction->GetSQL());
                if ($eventAction->Type == 2 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_a_" . $countaction])) {
                    $eventActionInvitation = new Invitation($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_b_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_c_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_d_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_e_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_f_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_g_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_h_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_" . $countaction]);
                    queryDB(true, $eventActionInvitation->GetSQL());
                    $countsender = 0;
                    while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_a_" . $countaction . "_" . $countsender])) {
                        $eventActionInvitationSender = new EventActionSender($eventActionInvitation->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_a_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_b_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_c_" . $countaction . "_" . $countsender]);
                        $eventActionInvitationSender->SaveSender();
                        $countsender++;
                    }
                } else {
                    if ($eventAction->Type == 4 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_a_" . $countaction])) {
                        $eventActionWebsitePush = new WebsitePush($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_b_" . $countaction]);
                        $eventActionWebsitePush->SaveEventConfiguration();
                        $countsender = 0;
                        while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_a_" . $countaction . "_" . $countsender])) {
                            $eventActionWebsitePushSender = new EventActionSender($eventActionWebsitePush->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_a_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_b_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_c_" . $countaction . "_" . $countsender]);
                            $eventActionWebsitePushSender->SaveSender();
                            $countsender++;
                        }
                    } else {
                        if ($eventAction->Type < 2) {
                            $countreceiver = 0;
                            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_d_" . $countaction . "_" . $countreceiver])) {
                                $eventActionReceiver = new EventActionReceiver($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_d_" . $countaction . "_" . $countreceiver], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_e_" . $countaction . "_" . $countreceiver]);
                                queryDB(true, $eventActionReceiver->GetSQL());
                                $countreceiver++;
                            }
                        }
                    }
                }
                $countaction++;
            }
        }
        $count++;
    }
}
function processEvents()
{
    $count = 0;
    while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_va_" . $count])) {
        $event = new Event($_POST[POST_INTERN_PROCESS_EVENTS . "_va_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vb_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vc_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vd_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_ve_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vf_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vg_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vh_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vk_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vl_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vm_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vn_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vo_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vp_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vq_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vt_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vu_" . $count], $_POST[POST_INTERN_PROCESS_EVENTS . "_vv_" . $count]);
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id`='" . DBManager::RealEscape($event->Id) . "' LIMIT 1;");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "`.`eid`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_OVERLAYS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_OVERLAYS . "`.`action_id`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_RECEIVERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_RECEIVERS . "`.`action_id`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_WEBSITE_PUSHS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTIONS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_WEBSITE_PUSHS . "`.`action_id`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_URLS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "`.`uid`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "`.`eid`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_SENDERS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_OVERLAYS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_SENDERS . "`.`pid`) AND NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENT_ACTION_WEBSITE_PUSHS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_ACTION_SENDERS . "`.`pid`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_GOALS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_GOALS . "`.`goal_id`)");
        DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_URLS . "` WHERE NOT EXISTS (SELECT * FROM `" . DB_PREFIX . DATABASE_EVENTS . "` WHERE `id` = `" . DB_PREFIX . DATABASE_EVENT_URLS . "`.`eid`)");
        if (!isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vx_" . $count])) {
            DBManager::Execute(true, $event->GetSQL());
            $counturl = 0;
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_a_" . $counturl])) {
                $eventURL = new EventURL($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_f_" . $counturl], $event->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_a_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_b_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_c_" . $counturl], $_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_d_" . $counturl]);
                DBManager::Execute(true, $eventURL->GetSQL());
                if (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_e_" . $counturl])) {
                    DBManager::Execute(true, "INSERT INTO `" . DB_PREFIX . DATABASE_EVENT_FUNNELS . "` (`eid`,`uid`,`ind`) VALUES ('" . DBManager::RealEscape($event->Id) . "','" . DBManager::RealEscape($eventURL->Id) . "','" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_EVENTS . "_vi_" . $count . "_e_" . $counturl]) . "');");
                }
                $counturl++;
            }
            $countgoals = 0;
            DBManager::Execute(true, "DELETE FROM `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` WHERE `event_id` = '" . DBManager::RealEscape($event->Id) . "';");
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count . "_a_" . $countgoals])) {
                DBManager::Execute(true, "INSERT INTO `" . DB_PREFIX . DATABASE_EVENT_GOALS . "` (`event_id`,`goal_id`) VALUES ('" . DBManager::RealEscape($event->Id) . "','" . DBManager::RealEscape($_POST[POST_INTERN_PROCESS_EVENTS . "_vs_" . $count . "_a_" . $countgoals]) . "');");
                $countgoals++;
            }
            $countaction = 0;
            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_a_" . $countaction])) {
                $eventAction = new EventAction($event->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_b_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_c_" . $countaction]);
                DBManager::Execute(true, $eventAction->GetSQL());
                if ($eventAction->Type == 2 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_a_" . $countaction])) {
                    $invitationSettings = @unserialize(base64_decode(Server::$Configuration->File["gl_invi"]));
                    array_walk($invitationSettings, "b64dcode");
                    $eventActionInvitation = new Invitation($eventAction->Id, $invitationSettings);
                    DBManager::Execute(true, $eventActionInvitation->GetSQL());
                    $countsender = 0;
                    while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_a_" . $countaction . "_" . $countsender])) {
                        $eventActionInvitationSender = new EventActionSender($eventActionInvitation->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_a_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_b_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_inv_i_c_" . $countaction . "_" . $countsender]);
                        $eventActionInvitationSender->SaveSender();
                        $countsender++;
                    }
                } else {
                    if ($eventAction->Type == 5 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_a_" . $countaction])) {
                        $eventActionOverlayBox = new OverlayElement($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_b_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_c_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_d_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_e_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_f_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_g_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_h_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_i_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_j_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_k_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_l_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_m_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_n_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_o_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_p_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_q_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_r_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_ovb_s_" . $countaction]);
                        DBManager::Execute(true, $eventActionOverlayBox->GetSQL());
                    } else {
                        if ($eventAction->Type == 4 && isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_a_" . $countaction])) {
                            $eventActionWebsitePush = new WebsitePush($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_a_" . $countaction], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_b_" . $countaction]);
                            $eventActionWebsitePush->SaveEventConfiguration();
                            $countsender = 0;
                            while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_a_" . $countaction . "_" . $countsender])) {
                                $eventActionWebsitePushSender = new EventActionSender($eventActionWebsitePush->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_a_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_b_" . $countaction . "_" . $countsender], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_wp_c_c_" . $countaction . "_" . $countsender]);
                                $eventActionWebsitePushSender->SaveSender();
                                $countsender++;
                            }
                        } else {
                            if ($eventAction->Type < 2) {
                                $countreceiver = 0;
                                while (isset($_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_d_" . $countaction . "_" . $countreceiver])) {
                                    $eventActionReceiver = new EventActionReceiver($eventAction->Id, $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_d_" . $countaction . "_" . $countreceiver], $_POST[POST_INTERN_PROCESS_EVENTS . "_vj_" . $count . "_e_" . $countaction . "_" . $countreceiver]);
                                    DBManager::Execute(true, $eventActionReceiver->GetSQL());
                                    $countreceiver++;
                                }
                            }
                        }
                    }
                }
                $countaction++;
            }
        }
        $count++;
    }
    if ($count > 0) {
        CacheManager::SetDataUpdateTime(DATA_UPDATE_KEY_EVENTS);
        CacheManager::FlushKey(DATA_CACHE_KEY_EVENTS);
    }
}