<?php

/* ====================
[BEGIN_SED_EXTPLUGIN]
Code=hidefuturepages
Part=page
File=hidefuturepages.page.edit.update.done
Hooks=page.edit.update.done
Tags=
Order=10
[END_SED_EXTPLUGIN]
==================== */
defined('SED_CODE') or die('Wrong URL');
if ((int) $rpagebegin > (int) $sys['now_offset']) {
    $id = (int) $id;
    sed_sql_query("UPDATE {$db_pages} SET page_state='3' WHERE page_id='{$id}'");
    sed_log("Edited page #" . $id, 'adm');
    sed_redirect(sed_url('admin', 'm=page&s=queue', NULL, TRUE));
}
                    $expirepages_result['page_expire'] = (int) $newtempexpiredate;
                    $expirepages_result['page_state'] = 1;
                    $expirepages_result['page_comcount'] = 0;
                    sed_trash_put('page', $expirepages_result['page_title'], $expirepages_result['page_id'], $expirepages_result);
                }
                $sql_pagestatus = sed_sql_query("DELETE FROM {$db_pages} WHERE page_id='" . (int) $expirepages_result['page_id'] . "'");
                sed_log("Deleted page #" . (int) $expirepages_result['page_id'], 'adm');
                sed_sql_query("UPDATE {$db_structure} SET structure_pagecount=structure_pagecount-1 WHERE structure_code='" . sed_sql_prep($expirepages_result['page_cat']) . "'");
                if ($cfg['plugin']['hidefuturepages']['deletepagerelated'] == 'Yes') {
                    $pagecode = "p" . $pageid;
                    sed_sql_query("DELETE FROM {$db_ratings} WHERE rating_code='{$pagecode}'");
                    sed_sql_query("DELETE FROM {$db_rated} WHERE rated_code='{$pagecode}'");
                    sed_sql_query("DELETE FROM {$db_com} WHERE com_code='{$pagecode}'");
                }
                break;
            case 'hide':
                $sql_pagestatus = sed_sql_query("UPDATE {$db_pages} SET page_state='4' WHERE page_id='{$pageid}'");
                break;
        }
        if ($sql_pagestatus) {
            $expirepages_count++;
        }
    }
    if ($expirepages_count > 0 && $cfg['trash_page'] && $pageexpireaction == 'delete') {
        sed_log($expirepages_count . " page(s) had expired and were put in the trash", 'adm');
    } elseif ($expirepages_count > 0 && $pageexpireaction == 'delete') {
        sed_log($expirepages_count . " page(s) had expired and were deleted", 'adm');
    } elseif ($expirepages_count > 0 && $pageexpireaction == 'update') {
        sed_log($expirepages_count . " page(s) had expired and set to be hidden.", 'adm');
    }
}
        sed_log("User watchdog plugin sent " . $uwd_counter . " inactivity warning(s)", 'adm');
    }
    //delete user which reached the reprieve date
    $sql = sed_sql_query("SELECT user_id, user_name FROM {$db_users} WHERE " . $uwd_reprieveslot . ">'0' AND " . $uwd_reprieveslot . "<'{$uwd_reprieve}'");
    while ($row = sed_sql_fetcharray($sql)) {
        //if there is the trashcan enabled, we put it there
        if ($cfg['trash_user']) {
            $sqltrash = sed_sql_query("SELECT * FROM {$db_users} WHERE user_id='" . $row['user_id'] . "'");
            if ($rowtrash = sed_sql_fetchassoc($sqltrash)) {
                sed_trash_put('user', $L['User'] . " #" . $rowtrash['user_id'] . " " . $rowtrash['user_name'], $rowtrash['user_id'], $rowtrash);
            }
        }
        $sqldel = sed_sql_query("DELETE FROM {$db_users} WHERE user_id='" . $row['user_id'] . "'");
        $sqldel = sed_sql_query("DELETE FROM {$db_groups_users} WHERE gru_userid='" . $row['user_id'] . "'");
        if ($cfg['plugin']['userwatchdog']['uwd_delpfs']) {
            sed_pfs_deleteall($row['user_id']);
            //Avatar, Photo, Signature cleaning idea by Kilandor
            $uwd_avatar = $cfg['av_dir'] . $row['user_id'] . "-avatar.gif";
            $uwd_photo = $cfg['photos_dir'] . $row['user_id'] . "-photo.gif";
            $uwd_signature = $cfg['sig_dir'] . $row . "-signature.gif";
            @unlink($avatar);
            @unlink($photo);
            @unlink($signature);
        }
        if ($cfg['trash_user']) {
            sed_log("User Watchdog trashed #" . $row['user_id'] . " " . $row['user_name'], 'adm');
        } else {
            sed_log("User Watchdog deleted #" . $row['user_id'] . " " . $row['user_name'], 'adm');
        }
    }
}
Type=Plugin
Author=riptide
Description=Delete users which stayed off your website too long automaticaly
[END_SED]

[BEGIN_SED_EXTPLUGIN]
Code=userwatchdog
Part=users.auth.check.done
File=userwatchdog.auth
Hooks=users.auth.check.done
Tags=
Minlevel=0
Order=10
[END_SED_EXTPLUGIN]

==================== */
if (!defined('SED_CODE')) {
    die("Wrong URL.");
}
if ($cfg['plugin']['userwatchdog']['uwd_enableplugin'] == 'yes') {
    $uwd_reprieveslot = $cfg['plugin']['userwatchdog']['uwd_reprieveslot'];
    if ($rusername != '') {
        //check if it is a user with a reprieve and if yes, clear the reprieve date
        $uwd_sql = sed_sql_query("UPDATE {$db_users} SET " . $uwd_reprieveslot . "='' WHERE " . $uwd_reprieveslot . ">'0' AND user_name='" . sed_sql_prep($rusername) . "' LIMIT 1");
        $uwd_backagain = sed_sql_affectedrows($uwd_sql);
        if ($uwd_backagain > 0) {
            sed_log("User watchdog plugin welcomes back: " . sed_sql_prep($rusername) . "", 'adm');
        }
        unset($uwd_backagain);
    }
}