'Dynamic Recent Period',
'URL' => get_root_url() . 'admin.php?page=plugin-' . DYNARECEPERIO_ID,
);
return $menu;
}
}
// REMOVE INPUT ON PROFILE AND USERS LIST
if (script_basename() == 'profile' || defined('IN_ADMIN'))
{
if ($conf['dynareceperio']['force'])
{
add_event_handler('loc_end_page_tail', 'dynareceperio_hide_recent_period');
function dynareceperio_hide_recent_period()
{
global $template, $page;
if (@$page['page'] == 'user_list')
{
$template->set_prefilter('user_list', 'dynareceperio_user_list');
}
else if (@$page['body_id']=='theProfilePage' || (@$page['page'] == 'configuration' && @$_GET['section'] == 'default'))
{
$template->block_footer_script(array('require'=>'jquery'), 'jQuery("#recent_period").parent().hide();');
}
}
function dynareceperio_user_list($content)
{
$search = '
{\'Recent period\'|translate}';
$replace = '{\'Recent period\'|translate}';
return str_replace($search, $replace, $content);
}
}
}
// APPLY DYNAMIC PERIOD
else
{
add_event_handler('init', 'dynareceperio_user_init');
function dynareceperio_user_init()
{
global $conf, $user;
$default_period = get_default_user_value('recent_period', $user['recent_period']);
if ($conf['dynareceperio']['force'] or $default_period == $user['recent_period'])
{
$query = '
SELECT MAX(D)
FROM (
SELECT D
FROM (
SELECT DATEDIFF(CURRENT_DATE, date_available) AS D
FROM '.IMAGES_TABLE.' AS i
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id
'.get_sql_condition_FandF(
array(
'forbidden_categories' => 'ic.category_id',
'visible_categories' => 'ic.category_id',
'visible_images' => 'id'
),
'WHERE',
true
).'
) AS ListDate
WHERE D >= 0
GROUP BY D
ORDER BY D ASC
LIMIT '.$conf['dynareceperio']['day_number'].'
) AS MaxD
;';
$result = pwg_query($query);
if (list($period) = pwg_db_fetch_row($result))
{
$user['recent_period'] = max($period, $default_period);
}
}
}
}