Пример #1
0
/**
 * Database connection (connection opened here)
 *
 * @global DB $DB
 */
$DB = new DB($db_config);
/**
 * Load settings class
 */
load_class('settings/model/_generalsettings.class.php', 'GeneralSettings');
/**
 * Interface to general settings
 *
 * Keep this below the creation of the {@link $DB DB object}, because it checks for the
 * correct db_version and catches "table does not exist" errors, providing a link to the
 * install script.
 *
 * @global GeneralSettings $Settings
 */
$Settings = new GeneralSettings();
$time_difference = $Settings->get('time_difference');
/**
 * Corrected Unix timestamp to match server timezone
 * @global int $localtimenow
 */
$localtimenow = $servertimenow + $time_difference;
/**
 * @global AbstractSettings
 */
$global_Cache = new AbstractSettings('T_global__cache', array('cach_name'), 'cach_cache', 0);
$Timer->pause('_init_db');
// Get the datetime which corresponds to the minimum delay value.
// If the last unread message reminder for a specific user is after this datetime, then notification must not be send to that user now.
$reminder_threshold = date2mysql($servertimenow - $minimum_delay * 86400);
if (empty($UserSettings)) {
    // initialize UserSettings
    load_class('users/model/_usersettings.class.php', 'UserSettings');
    $UserSettings = new UserSettings();
}
if (empty($Settings)) {
    // initialize GeneralSettings
    load_class('settings/model/_generalsettings.class.php', 'GeneralSettings');
    $Settings = new GeneralSettings();
}
// set condition to check if user wants to recive unread messages reminders
$notify_condition = '( notif_setting.uset_value IS NOT NULL AND notif_setting.uset_value <> ' . $DB->quote('0') . ' )';
if ($Settings->get('def_notify_unread_messages')) {
    // by default everybody should be notified, so notify those users who didn't explicitly set to not receive notifications
    $notify_condition .= ' OR notif_setting.uset_value IS NULL';
}
// Find user who have unread messages created more than x ( = configured threshold value ) hours ago, and have not been reminded in the last y ( = configured reminder delay for this user ) hours
// We needs to send reminder for these users, but the message must include all unread threads even if the last unread messages was created less then x hours
$query = 'SELECT DISTINCT user_ID, last_sent.uset_value
		FROM T_users
			INNER JOIN T_messaging__threadstatus ON tsta_user_ID = user_ID
			INNER JOIN T_messaging__message ON tsta_first_unread_msg_ID = msg_ID
			LEFT JOIN T_users__usersettings last_sent ON last_sent.uset_user_ID = user_ID AND last_sent.uset_name = "last_unread_messages_reminder"
			LEFT JOIN T_users__usersettings notif_setting ON notif_setting.uset_user_ID = user_ID AND notif_setting.uset_name = "notify_unread_messages"
		WHERE ( msg_datetime < ' . $DB->quote($threshold_date) . ' )
			AND ( last_sent.uset_value IS NULL OR last_sent.uset_value < ' . $DB->quote($reminder_threshold) . ' )
			AND ( ' . $notify_condition . ' )
			AND ( LENGTH(TRIM(user_email)) > 0 )