function get_user_notifications($action, $check_key_list = array(), $enabled_filter_value = '')
{
    global $conf;
    $data_users = array();
    if (in_array($action, array('subscribe', 'send'))) {
        $quoted_check_key_list = quote_check_key_list($check_key_list);
        if (count($quoted_check_key_list) != 0) {
            $query_and_check_key = ' and
    check_key in (' . implode(",", $quoted_check_key_list) . ') ';
        } else {
            $query_and_check_key = '';
        }
        $query = '
select
  N.user_id,
  N.check_key,
  U.' . $conf['user_fields']['username'] . ' as username,
  U.' . $conf['user_fields']['email'] . ' as mail_address,
  N.enabled,
  N.last_send
from
  ' . USER_MAIL_NOTIFICATION_TABLE . ' as N,
  ' . USERS_TABLE . ' as U
where
  N.user_id =  U.' . $conf['user_fields']['id'];
        if ($action == 'send') {
            // No mail empty and all users enabled
            $query .= ' and
  N.enabled = \'true\' and
  U.' . $conf['user_fields']['email'] . ' is not null';
        }
        $query .= $query_and_check_key;
        if (isset($enabled_filter_value) and $enabled_filter_value != '') {
            $query .= ' and
        N.enabled = \'' . boolean_to_string($enabled_filter_value) . '\'';
        }
        $query .= '
order by';
        if ($action == 'send') {
            $query .= '
  last_send, username;';
        } else {
            $query .= '
  username;';
        }
        $query .= ';';
        $result = pwg_query($query);
        if (!empty($result)) {
            while ($nbm_user = pwg_db_fetch_assoc($result)) {
                $data_users[] = $nbm_user;
            }
        }
    }
    return $data_users;
}
Exemplo n.º 2
0
function insert_new_data_user_mail_notification()
{
    global $conf, $page, $env_nbm;
    // Set null mail_address empty
    $query = '
update
  ' . USERS_TABLE . '
set
  ' . $conf['user_fields']['email'] . ' = null
where
  trim(' . $conf['user_fields']['email'] . ') = \'\';';
    pwg_query($query);
    // null mail_address are not selected in the list
    $query = '
select
  u.' . $conf['user_fields']['id'] . ' as user_id,
  u.' . $conf['user_fields']['username'] . ' as username,
  u.' . $conf['user_fields']['email'] . ' as mail_address
from
  ' . USERS_TABLE . ' as u left join ' . USER_MAIL_NOTIFICATION_TABLE . ' as m on u.' . $conf['user_fields']['id'] . ' = m.user_id
where
  u.' . $conf['user_fields']['email'] . ' is not null and
  m.user_id is null
order by
  user_id;';
    $result = pwg_query($query);
    if (pwg_db_num_rows($result) > 0) {
        $inserts = array();
        $check_key_list = array();
        while ($nbm_user = pwg_db_fetch_assoc($result)) {
            // Calculate key
            $nbm_user['check_key'] = find_available_check_key();
            // Save key
            $check_key_list[] = $nbm_user['check_key'];
            // Insert new nbm_users
            $inserts[] = array('user_id' => $nbm_user['user_id'], 'check_key' => $nbm_user['check_key'], 'enabled' => 'false');
            $page['infos'][] = l10n('User %s [%s] added.', stripslashes($nbm_user['username']), $nbm_user['mail_address']);
        }
        // Insert new nbm_users
        mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
        // Update field enabled with specific function
        $check_key_treated = do_subscribe_unsubscribe_notification_by_mail(true, $conf['nbm_default_value_user_enabled'], $check_key_list);
        // On timeout simulate like tabsheet send
        if ($env_nbm['is_sendmail_timeout']) {
            $quoted_check_key_list = quote_check_key_list(array_diff($check_key_list, $check_key_treated));
            if (count($quoted_check_key_list) != 0) {
                $query = 'delete from ' . USER_MAIL_NOTIFICATION_TABLE . ' where check_key in (' . implode(",", $quoted_check_key_list) . ');';
                $result = pwg_query($query);
                redirect($base_url . get_query_string_diff(array(), false), l10n('Operation in progress') . "\n" . l10n('Please wait...'));
            }
        }
    }
}