Esempio n. 1
0
function NBMS_Save_Profile()
{
    global $conf, $user;
    include_once PHPWG_ROOT_PATH . 'admin/include/functions_notification_by_mail.inc.php';
    $query = '
SELECT *
FROM ' . USER_MAIL_NOTIFICATION_TABLE . '
WHERE user_id = \'' . $user['id'] . '\'
';
    $count = pwg_db_num_rows(pwg_query($query));
    if ($count == 0) {
        $inserts = array();
        $check_key_list = array();
        // Calculate key
        $nbm_user['check_key'] = find_available_check_key();
        // Save key
        array_push($check_key_list, $nbm_user['check_key']);
        // Insert new nbm_users
        array_push($inserts, array('user_id' => $user['id'], 'check_key' => $nbm_user['check_key'], 'enabled' => $_POST['NBM_Subscription']));
        mass_inserts(USER_MAIL_NOTIFICATION_TABLE, array('user_id', 'check_key', 'enabled'), $inserts);
    } elseif ($count != 0 and !empty($_POST['NBM_Subscription']) && in_array($_POST['NBM_Subscription'], array('true', 'false'))) {
        $query = '
UPDATE ' . USER_MAIL_NOTIFICATION_TABLE . '
  SET enabled = \'' . $_POST['NBM_Subscription'] . '\'
  WHERE user_id = \'' . $user['id'] . '\';';
        pwg_query($query);
    }
}
Esempio 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...'));
            }
        }
    }
}