%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/nailstv/public_html/es.nails.tv/
Upload File :
Create Path :
Current File : /home/nailstv/public_html/es.nails.tv/_szavazat.php

<?php

if(empty($_POST)) die;

require_once 'config/config.php';

Registry::set('debug', false);

$db = Db::getInstance();

settype($_POST['video'], 'integer');

if($_POST['irany'] == 'p'){
    $rec['ertek'] = 1;
} else {
    $rec['ertek'] = -1;
}

if(isset($_SESSION[Registry::get('site')]['user_id'])){
    $rec['felhasznalo_id'] = $_SESSION[Registry::get('site')]['user_id'];

    $rec['video_id'] = $_POST['video'];
    $rec['datum'] = date("Y-m-d H:i:s");

    $bind = array($rec['video_id'], $rec['felhasznalo_id']);
    $sql = "SELECT video_id FROM video_szavazas WHERE video_id = ? AND felhasznalo_id = ?";
    $row = $db->GetRow($sql, $bind);
}
if(empty($rec['felhasznalo_id'])) {
    echo '<div class="white-popup review-callback login"><p>Para acceder a este contenido debe estar registrado.
            <br/><br/><a href="iniciarsesion" class="btn btn-site-color">Iniciar sesiĆ³n</a> <a href="registracion" class="btn btn-default">RegistraciĆ³n</a></p></div>';
}
elseif(!empty($row)) {
    echo '<div class="white-popup review-callback re"><p>No has votado este video</p></div>';
}
else {
    $db->insert($rec, 'video_szavazas');
    $sql = "UPDATE `video` SET "
            . "osszes_szavazas = osszes_szavazas +(".$rec['ertek']."), "
            . "napi_szavazas = napi_szavazas +(".$rec['ertek']."), "
            . "heti_szavazas = heti_szavazas +(".$rec['ertek']."), "
            . "havi_szavazas = havi_szavazas +(".$rec['ertek'].") WHERE id = ?";
    $bind = array($rec['video_id']);
    $db->query($sql,$bind);
    ertekeles($rec['video_id'], $db);
    
    echo '<div class="white-popup review-callback ok"><p>Su voto se estar verificando, Gracias.</p></div>';
}

function ertekeles($videoId, $db){
    $where = array("osszes_"   => "", 
                    "napi_"    => "vsz.datum > (NOW() - interval 1 day) AND",
                    "heti_"    => "vsz.datum > (NOW() - interval 1 week) AND",
                    "havi_"    => "vsz.datum > (NOW() - interval 1 month) AND");
    
    $bind = array($videoId);
    foreach($where as $key => $w){
        $sql = "SELECT count(vsz.id) as szavazat, (sum(case `vsz`.`ertek` when 1 then 1 else 0 end) / count(`vsz`.`id`)) * 100 AS `szazalek`, vsz.video_id 
                            FROM video_szavazas vsz 
                            WHERE ".$w." AND
                                vsz.video_id = ?
                            GROUP BY vsz.video_id)  sz ON sz.video_id = v.id";
        $res = $db->GetRow($sql, $bind);
        $ertekeles = isset($res['szazalek'])? $res['szazalek']: 0;
        $szavazat = isset($res['szavazat'])? $res['szavazat'] : 0;
        $update = "UPDATE video SET " . $key . "ertekeles = ". $ertekeles .", ".$key."szavazas=".$szavazat." WHERE id = ".$videoId;
        $db->query($update);
    }
}

?>

Zerion Mini Shell 1.0