File "admin.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/custom-dbx/modules/afiliere/admin.php
File size: 10.9 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

add_action('admin_menu', 'dbx_aff_page');
function dbx_aff_page()
{
    add_menu_page('DBX - Statistici Afiliere', 'Afiliere DBX', 'manage_options', 'dbx-afiliere', 'dbx_aff_callback', 'dashicons-tickets', 1);
}
function dbx_aff_callback()
{
    $url = "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
    $_url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
    $action = $_GET['action'];
    if (empty($action)) {
        ?>
    <div class="dbx_title">
        <h1>Statistici Afiliere</h1>
    </div>
    <div class="dbx_content">
        <div class="col_1">
        <h3>Site-uri active</h3>
        <p>Aici gasim toate site-urile care primesc click-uri.</p>
        <?php 
        $res = dbx_aff_get_data();
        $sites = [];
        foreach ($res as $r) {
            $site = $r['site'];
            if (in_array($site, $sites)) {
                continue;
            }
            array_push($sites, $site);
        }
        echo '<ul>';
        foreach ($sites as $s) {
            $nume_site = str_replace('https://', '', $s);
            $detalii = $_url . '&action=per_site&site=' . $nume_site;
            echo '<li><a href="' . $detalii . '" title="Vezi Detalii">' . $nume_site . '</a></li>';
        }
        echo '</ul>';
        ?>
        </div>
        <div class="col_1">
            <?php 
        $result = dbx_aff_get_today_data();
        $i = 0;
        foreach ($result as $row) {
            $data = unserialize($row['data']);
            foreach ($data as $_d) {
                $i++;
            }
        }
        $last_7 = dbx_aff_get_last_7_days();
        $j = 0;
        foreach ($last_7 as $row) {
            $data = unserialize($row['data']);
            foreach ($data as $_d) {
                $j++;
            }
        }
        $last_30 = dbx_aff_get_last_30_days();
        $k = 0;
        foreach ($last_30 as $row) {
            $data = unserialize($row['data']);
            foreach ($data as $_d) {
                $k++;
            }
        }
        ?>
            <div class="dbx_all">
            <div class="dbx_w">
                <h3>Azi</h3>
                <p class="dbx_c"><?php 
        echo $i;
        ?></p>
                <a class="dbx_btn" href="<?php 
        echo $_url . '&action=per_date&last=1';
        ?>">Vezi detalii</a>
            </div>
            <div class="dbx_w">
                <h3>Ultimile 7 zile</h3>
                <p class="dbx_c"><?php 
        echo $j;
        ?></p>
                <a class="dbx_btn" href="<?php 
        echo $_url . '&action=per_date&last=7';
        ?>">Vezi detalii</a>
            </div>
            <div class="dbx_w">
                <h3>Ultimile 30 zile</h3>
                <p class="dbx_c"><?php 
        echo $k;
        ?></p>
                <a class="dbx_btn" href="<?php 
        echo $_url . '&action=per_date&last=30';
        ?>">Vezi detalii</a>
            </div>
            </div>
        </div>
    </div>
    <?php 
    } else {
        echo '<div class="dbx_content tabel">';
        if ($action == 'per_site') {
            $_site = $_GET['site'];
            $nume_site = 'https://' . $_site;
            $result = dbx_aff_get_data_per_site($nume_site);
            echo '<h2>Click-uri detaliate pentru site-ul ' . $_site . '</h2>';
            echo '<table>';
            echo '<tr>';
            echo '<td>Data</td>';
            echo '<td>Site</td>';
            echo '<td>Magazin</td>';
            echo '<td>URL Produs(intern)</td>';
            echo '<td>Oras</td>';
            echo '<td>Tara</td>';
            echo '<td>IP</td>';
            echo '</tr>';
            foreach ($result as $r) {
                $site = $r['site'];
                $d = $r['date'];
                $_d = unserialize($r['data']);
                foreach ($_d as $data) {
                    if ($data['country'] != 'RO') {
                        continue;
                    }
                    if ($data['ip'] == '82.76.155.112') {
                        continue;
                    }
                    echo '<tr>';
                    echo '<td>' . $d . '</td>';
                    echo '<td>' . $site . '</td>';
                    echo '<td>' . $data['magazin'] . '</td>';
                    echo '<td>' . $data['url_produs'] . '</td>';
                    echo '<td>' . $data['city'] . '</td>';
                    echo '<td>' . $data['country'] . '</td>';
                    echo '<td>' . $data['ip'] . '</td>';
                    echo '</tr>';
                }
            }
            echo '</table>';
        }
        if ($action == 'per_date') {
            $_last = $_GET['last'];
            if ($_last == 1) {
                $result = dbx_aff_get_today_data();
            } else {
                if ($_last == 7) {
                    $result = dbx_aff_get_last_7_days();
                }
                if ($_last == 30) {
                    $result = dbx_aff_get_last_30_days();
                }
            }
            echo '<h2>Click-uri detaliate pentru ultimile ' . $_last . ' zile</h2>';
            echo '<table>';
            echo '<tr>';
            echo '<td>Data</td>';
            echo '<td>Site</td>';
            echo '<td>Magazin</td>';
            echo '<td>URL Produs(intern)</td>';
            echo '<td>Oras</td>';
            echo '<td>Tara</td>';
            echo '<td>IP</td>';
            echo '</tr>';
            foreach ($result as $r) {
                $site = $r['site'];
                $d = $r['date'];
                $_d = unserialize($r['data']);
                foreach ($_d as $data) {
                    if ($data['country'] != 'RO') {
                        continue;
                    }
                    if ($data['ip'] == '82.76.155.112') {
                        continue;
                    }
                    echo '<tr>';
                    echo '<td>' . $d . '</td>';
                    echo '<td>' . $site . '</td>';
                    echo '<td>' . $data['magazin'] . '</td>';
                    echo '<td>' . $data['url_produs'] . '</td>';
                    echo '<td>' . $data['city'] . '</td>';
                    echo '<td>' . $data['country'] . '</td>';
                    echo '<td>' . $data['ip'] . '</td>';
                    echo '</tr>';
                }
            }
            echo '</table>';
            ?>
            <?php 
        }
        echo '<div>';
    }
    ?>
    <style>
    table {
      font-family: arial, sans-serif;
      border-collapse: collapse;
      width: 100%;
    }
    td, th {
      border: 1px solid #dddddd;
      text-align: left;
      padding: 8px;
    }
    tr:nth-child(even) {
      background-color: #dddddd;
    }
    .dbx_content.tabel {
        display: block;
    }
    a.dbx_btn {
    background: #2271b1;
    color: #fff;
    padding: 3px 5px;
    text-decoration: none;
    border-radius: 0.375em;
    margin-top: 15px;
    }
    .dbx_all {
    display: inline-flex;
    width: 100%;
    gap: 15px;
    flex-flow: wrap;
    }
    .dbx_w {
    background: #f3f3f3;
    text-align: center;
    padding: 15px;
    border-radius: 0.375em;
    color: #000;
    min-width: 44%;
    } 
    .dbx_w h3 {
    color: #000!important;
    font-size: 22px!important;
    margin-bottom: 0!important;
    }
    p.dbx_c {
    margin: 0;
    font-size: 24px;
    color: red;
    font-weight: 550;
    margin-bottom: 10px;
    }
    .dbx_content {
    width: 96%;
    display: inline-flex;
    gap: 25px;
    }
    .col_1 {
    width: 50%;
    border: 1px solid #f3f3f3;
    padding: 25px;
    border-radius: 0.375em;
    }
    .col_1 ul {
    display: inline-flex;
    gap: 10px;
    width: 100%;
    flex-flow: wrap;
    }
    .col_1 ul li {
    min-width: 20%;
    background: #f3f3f3;
    text-align: center;
    border-radius: 0.375em;
    padding: 3px;
    }
    .dbx_title, .dbx_content {
    background: #fff;
    padding: 25px;
    margin: 10px 0;
    border-radius: 0.375em;
    }
    .dbx_title{
        text-align: center;
    }
    </style>
    <?php 
}
function dbx_aff_get_last_30_days()
{
    $hostname = 'localhost';
    $username = 'kosmetik_afiliere_user';
    $password = 'UXf#jtIX75ll';
    $database = 'kosmetik_afiliere';
    $table_name = 'clicuri_afiliere';
    $con = mysqli_connect($hostname, $username, $password, $database);
    $azi = date("Y-m-d");
    $old = date('Y-m-d', strtotime('-7 days'));
    if (!$con) {
        return;
    }
    $sql_check = "SELECT * FROM {$table_name} WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND NOW() ORDER BY date DESC";
    $result = mysqli_query($con, $sql_check);
    while ($row = $result->fetch_assoc()) {
        $results_array[] = $row;
    }
    return $results_array;
}
function dbx_aff_get_last_7_days()
{
    $hostname = 'localhost';
    $username = 'kosmetik_afiliere_user';
    $password = 'UXf#jtIX75ll';
    $database = 'kosmetik_afiliere';
    $table_name = 'clicuri_afiliere';
    $con = mysqli_connect($hostname, $username, $password, $database);
    $azi = date("Y-m-d");
    $old = date('Y-m-d', strtotime('-7 days'));
    if (!$con) {
        return;
    }
    $sql_check = "SELECT * FROM {$table_name} WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND NOW() ORDER BY date DESC";
    $result = mysqli_query($con, $sql_check);
    while ($row = $result->fetch_assoc()) {
        $results_array[] = $row;
    }
    return $results_array;
}
function dbx_aff_get_today_data()
{
    $hostname = 'localhost';
    $username = 'kosmetik_afiliere_user';
    $password = 'UXf#jtIX75ll';
    $database = 'kosmetik_afiliere';
    $table_name = 'clicuri_afiliere';
    $con = mysqli_connect($hostname, $username, $password, $database);
    $azi = date("Y-m-d");
    if (!$con) {
        return;
    }
    $sql_check = "SELECT * FROM {$table_name} WHERE date='{$azi}' ORDER BY date DESC";
    $result = mysqli_query($con, $sql_check);
    while ($row = $result->fetch_assoc()) {
        $results_array[] = $row;
    }
    return $results_array;
}
function dbx_aff_get_data_per_site($site = null)
{
    $hostname = 'localhost';
    $username = 'kosmetik_afiliere_user';
    $password = 'UXf#jtIX75ll';
    $database = 'kosmetik_afiliere';
    $table_name = 'clicuri_afiliere';
    $con = mysqli_connect($hostname, $username, $password, $database);
    if (!$con) {
        return;
    }
    $sql_check = "SELECT * FROM {$table_name} WHERE site='{$site}' ORDER BY date DESC";
    $result = mysqli_query($con, $sql_check);
    while ($row = $result->fetch_assoc()) {
        $results_array[] = $row;
    }
    return $results_array;
}
function dbx_aff_get_data()
{
    $hostname = 'localhost';
    $username = 'kosmetik_afiliere_user';
    $password = 'UXf#jtIX75ll';
    $database = 'kosmetik_afiliere';
    $table_name = 'clicuri_afiliere';
    $con = mysqli_connect($hostname, $username, $password, $database);
    if (!$con) {
        return;
    }
    $sql_check = "SELECT * FROM {$table_name} ORDER BY date DESC";
    $result = mysqli_query($con, $sql_check);
    while ($row = $result->fetch_assoc()) {
        $results_array[] = $row;
    }
    return $results_array;
}