if ($duration && in_array($duration_operand, array('<', '<=', '=', '>', '>='))) {
    $where['duration'] = $ds->prepare("{$duration_operand} ?", $duration);
}
$count = $log->countList($where);
$msg = '%d CLongRequestLog to be removed.';
if ($count == 1) {
    $msg = 'One CLongRequestLog to be removed.';
} elseif (!$count) {
    $msg = 'No CLongRequestLog to be removed.';
}
CAppUI::stepAjax("CLongRequestLog-msg-{$msg}", UI_MSG_OK, $count);
if ($just_count || !$count) {
    CAppUI::js("\$('clean_auto').checked = false");
    CApp::rip();
}
$logs = $log->loadList($where, null, $purge_limit);
if (!$logs) {
    CAppUI::js("\$('clean_auto').checked = false");
    CAppUI::stepAjax("CLongRequestLog-msg-No CLongRequestLog to be removed.", UI_MSG_OK);
    CApp::rip();
}
$deleted_logs = 0;
foreach ($logs as $_log) {
    if ($msg = $_log->delete()) {
        CAppUI::setMsg($msg, UI_MSG_WARNING);
    } else {
        CAppUI::setMsg('CLongRequestLog-msg-delete', UI_MSG_OK);
        $deleted_logs++;
    }
}
CAppUI::setMsg('CLongRequestLog-msg-%d CLongRequestLog to be removed.', UI_MSG_OK, $count - $deleted_logs);
$duration_operand = CValue::get("duration_operand");
$filter->duration = CValue::get("duration");
$ds = CSQLDataSource::get('std');
$where = array();
if ($filter->user_id) {
    $where["user_id"] = $ds->prepare("= ?", $filter->user_id);
}
if ($filter->_date_min) {
    $where[] = $ds->prepare("`datetime` >= ?", $filter->_date_min);
}
if ($filter->_date_max) {
    $where[] = $ds->prepare("`datetime` >= ?", $filter->_date_max);
}
if ($filter->duration && in_array($duration_operand, array('<', '<=', '=', '>', '>='))) {
    $where['duration'] = $ds->prepare("{$duration_operand} ?", $filter->duration);
}
$order = "datetime DESC";
/** @var CLongRequestLog[] $logs */
$logs = $filter->loadList($where, $order, "{$start}, 50");
$list_count = $filter->countList($where);
CStoredObject::massLoadFwdRef($logs, 'user_id');
foreach ($logs as $_log) {
    $_log->loadRefUser();
    $_log->_ref_user->loadRefFunction();
}
$smarty = new CSmartyDP();
$smarty->assign("start", $start);
$smarty->assign("list_count", $list_count);
$smarty->assign("filter", $filter);
$smarty->assign("logs", $logs);
$smarty->display("inc_list_long_request_logs.tpl");