Exemplo n.º 1
0
function views_stat($file_id)
{
    global $db, $tpf, $file, $settings, $auth;
    $view_stat = gpc('view_stat', 'C', '');
    if (!$view_stat) {
        pd_setcookie('view_stat', 1, 3600 * 3);
        $db->query_unbuffered("update {$tpf}files set file_views=file_views+1 where file_id='{$file_id}'");
        if ($auth[view_credit] && $settings[how_view_credit_views] && $settings[how_view_credit_credit]) {
            $add_credit = @round((int) $settings[how_view_credit_credit] / (int) $settings[how_view_credit_views], 4);
            add_credit_log($file_id, $add_credit, 'view', $file[userid]);
            $db->query_unbuffered("update {$tpf}users set credit=credit+{$add_credit} where userid='{$file[userid]}'");
        }
    }
}
Exemplo n.º 2
0
function cal_downs($file_id)
{
    global $db, $tpf, $timestamp, $onlineip, $my_sid, $auth, $settings;
    $down_file = gpc('down_file_log', 'C', 0);
    $rs = $db->fetch_one_array("select userid,file_size from {$tpf}files where file_id='{$file_id}'");
    if ($rs) {
        $userid = $rs[userid];
        $file_size = $rs[file_size];
    }
    unset($rs);
    $ip_interval = get_plans(get_profile($userid, 'plan_id'), 'ip_interval');
    $ip_interval = $ip_interval ? (int) $ip_interval : 24;
    $db->query_unbuffered("update {$tpf}files set file_last_view='{$timestamp}' where file_id='{$file_id}'");
    if (!$down_file && check_download_ok($my_sid, $ip_interval * 60)) {
        //if(1){
        pd_setcookie('down_file_log', 1, $ip_interval * 60);
        $id = (int) @$db->result_first("select id from " . get_table_day_down() . " where file_id='{$file_id}' and d_day='" . date('Ymd') . "'");
        if (!$id) {
            $ins = array('d_year' => date('Y'), 'd_month' => date('Ym'), 'd_day' => date('Ymd'), 'd_week' => date('YW'), 'file_id' => $file_id, 'down_count' => 1, 'userid' => $userid);
            $db->query_unbuffered("insert into " . get_table_day_down() . " set " . $db->sql_array($ins) . "");
            if ($auth[open_plan_active] && $settings[open_plan_active]) {
                $dday = date('Ymd', strtotime('-1 day'));
                $dweek = date('YW', strtotime('-1 week'));
                if ($settings[down_active_interval] == 'week') {
                    $sql_do = " and d_week='{$dweek}'";
                } else {
                    $sql_do = " and d_day='{$dday}'";
                }
                $mydowns = (int) @$db->result_first("select sum(down_count) from " . get_table_day_down() . " where userid='{$userid}' {$sql_do}");
                //echo $mydowns.',';
                $mydowns = $mydowns ? get_discount($userid, $mydowns) : 1;
                $to_plan_id = @$db->result_first("select plan_id from {$tpf}plans where {$mydowns}>=down_active_num_min and {$mydowns}<down_active_num_max and is_hidden=0");
                //echo $to_plan_id;
                if ($to_plan_id && date('Ymd', get_profile($userid, 'plan_conv_time')) != date('Ymd')) {
                    conv_credit($userid);
                    $ins = array('open_plan' => 1, 'plan_id' => $to_plan_id, 'credit_rate' => get_plans($to_plan_id, 'income_rate'), 'plan_conv_time' => $timestamp);
                    $db->query_unbuffered("update {$tpf}users set " . $db->sql_array($ins) . " where userid='{$userid}'");
                }
            }
        } else {
            $db->query_unbuffered("update " . get_table_day_down() . " set down_count=down_count+1 where id='{$id}'");
        }
        $add_credit = 1;
        if ($settings[promo_time] != '') {
            $hour = date('G');
            $arr = explode(',', $settings[promo_time]);
            if (in_array($hour, $arr)) {
                $add_credit = 2;
            }
        }
        add_credit_log($file_id, $add_credit, 'download', $userid);
        $db->query_unbuffered("update {$tpf}users set credit=credit+{$add_credit} where userid='{$userid}'");
        $db->query_unbuffered("update {$tpf}files set file_downs=file_downs+1 where file_id='{$file_id}'");
        $db->query_unbuffered("update {$tpf}users set dl_credit=dl_credit+1 where userid=(select userid from {$tpf}buddys where touserid='{$userid}')");
        $upline_userid = (int) @$db->result_first("select userid from {$tpf}buddys where touserid='{$userid}'");
        $db->query_unbuffered("update {$tpf}users set dl_credit2=dl_credit2+1 where userid=(select userid from {$tpf}buddys where touserid='{$upline_userid}')");
    }
    echo 'true';
}