Changeset 230

Show
Ignore:
Timestamp:
25.11.2005 00:52:02 (3 years ago)
Author:
bobe
Message:

Ajout refonte du système d’inscription pour passage par code only sur confirmation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk

    • Property svn:ignore set to
      .htaccess
  • trunk/includes

    • Property svn:ignore set to
      config.inc.php
  • trunk/includes/class.form.php

    r216 r230  
    4040    var $hasAccount    = false; 
    4141    var $isRegistered  = false; 
    42     var $update_stats  = false; 
    4342    var $message       = ''; 
    4443     
    45     function Wanewsletter($listdata) 
    46     { 
    47         $this->listdata    = $listdata; 
    48         $this->liste_email = ( !empty($listdata['liste_alias']) ) ? $listdata['liste_alias'] : $listdata['sender_email']; 
    49     } 
    50      
    51     function account_info($email, $pseudo, $code, $action) 
    52     { 
    53         $email = trim($email); 
    54         $this->code = trim($code); 
    55          
    56         switch( $this->listdata['liste_format'] ) 
    57         { 
    58             case FORMAT_MULTIPLE: 
    59                 if( $this->format != FORMAT_TEXTE && $this->format != FORMAT_HTML ) 
     44    var $mailer; 
     45     
     46    function Wanewsletter($listdata = null) 
     47    { 
     48        global $nl_config, $lang; 
     49         
     50        require WAMAILER_DIR . '/class.mailer.php'; 
     51         
     52        $mailer =& new Mailer(WA_ROOTDIR . '/language/email_' . $nl_config['language'] . '/'); 
     53         
     54        if( $nl_config['use_smtp'] ) 
     55        { 
     56            $mailer->smtp_path = WAMAILER_DIR . '/'; 
     57            $mailer->use_smtp( 
     58                $nl_config['smtp_host'], 
     59                $nl_config['smtp_port'], 
     60                $nl_config['smtp_user'], 
     61                $nl_config['smtp_pass'] 
     62            ); 
     63        } 
     64         
     65        $mailer->correctRpath = !is_disabled_func('ini_set'); 
     66        $mailer->set_charset($lang['CHARSET']); 
     67        $mailer->set_format(FORMAT_TEXTE); 
     68        $this->mailer =& $mailer; 
     69         
     70        if( isset($listdata) ) 
     71        { 
     72            switch( $listdata['liste_format'] ) 
     73            { 
     74                case FORMAT_MULTIPLE: 
     75                    if( $this->format != FORMAT_TEXTE && $this->format != FORMAT_HTML ) 
     76                    { 
     77                        $this->format = FORMAT_TEXTE; 
     78                    } 
     79                    break; 
     80                 
     81                case FORMAT_HTML: 
     82                case FORMAT_TEXTE: 
     83                    $this->format = $listdata['liste_format']; 
     84                    break;                   
     85                 
     86                default: 
     87                    $this->format = FORMAT_TEXTE; 
     88                    break; 
     89            } 
     90             
     91            $this->listdata    = $listdata; 
     92            $this->liste_email = ( !empty($listdata['liste_alias']) ) ? $listdata['liste_alias'] : $listdata['sender_email']; 
     93        } 
     94    } 
     95     
     96    function check($action, $email) 
     97    { 
     98        global $db, $nl_config, $lang; 
     99         
     100        // 
     101        // Vérification syntaxique de l'email 
     102        // 
     103        if( Mailer::validate_email($email) == false ) 
     104        { 
     105            return array('error' => true, 'message' => $lang['Message']['Invalid_email']); 
     106        } 
     107         
     108        // 
     109        // Vérification de la liste des masques de bannissements 
     110        // 
     111        if( $action == 'inscription' ) 
     112        { 
     113            $sql = "SELECT ban_email 
     114                FROM " . BANLIST_TABLE . " 
     115                WHERE liste_id = " . $this->listdata['liste_id']; 
     116            if( $result = $db->query($sql) ) 
     117            { 
     118                while( $row = $db->fetch_array($result) ) 
    60119                { 
    61                     $this->format = FORMAT_TEXTE; 
     120                    if( preg_match('/\b' . str_replace('*', '.*?', $row['ban_email']) . '\b/i', $email) ) 
     121                    { 
     122                        return array('error' => true, 'message' => $lang['Message']['Email_banned']); 
     123                    } 
    62124                } 
    63                 break; 
    64              
    65             case FORMAT_HTML: 
    66             case FORMAT_TEXTE: 
    67                 $this->format = $this->listdata['liste_format']; 
    68                 break;                   
    69              
    70             default: 
    71                 $this->format = FORMAT_TEXTE; 
    72                 break; 
    73         } 
    74          
    75         $result = check_email($email, $this->listdata['liste_id'], $action); 
    76          
    77         if( !$result['error'] ) 
    78         { 
    79             if( is_array($result['abodata']) ) 
    80             { 
    81                 $this->hasAccount   = true; 
    82                 $this->isRegistered = isset($result['abodata']['confirmed']); 
    83                  
    84                 $this->account['abo_id']    = $result['abodata']['abo_id']; 
    85                 $this->account['email']     = $result['abodata']['abo_email']; 
    86                 $this->account['pseudo']    = $result['abodata']['abo_pseudo']; 
    87                 $this->account['code']      = $result['abodata']['abo_register_key']; 
    88                 $this->account['date']      = $result['abodata']['register_date']; 
    89                 $this->account['format']    = $result['abodata']['format']; 
    90                 $this->account['status']    = $result['abodata']['abo_status']; 
     125            } 
     126        } 
     127         
     128        $sql = "SELECT a.abo_id, a.abo_pseudo, a.abo_pwd, a.abo_email, a.abo_lang, a.abo_register_key, 
     129                a.abo_register_date, a.abo_status, al.format, al.register_key, al.register_date, al.confirmed 
     130            FROM " . ABONNES_TABLE . " AS a 
     131                LEFT JOIN " . ABO_LISTE_TABLE . " AS al ON al.abo_id = a.abo_id 
     132                    AND al.liste_id = {$this->listdata['liste_id']} 
     133            WHERE LOWER(a.abo_email) = '" . $db->escape(strtolower($email)) . "'"; 
     134        if( !($result = $db->query($sql)) ) 
     135        { 
     136            return array('error' => true, 'message' => 'Impossible de tester les tables d\'inscriptions'); 
     137        } 
     138         
     139        if( $abodata = $db->fetch_array($result) ) 
     140        { 
     141            if( isset($abodata['confirmed']) ) 
     142            { 
     143                if( $action == 'inscription' && $abodata['confirmed'] == SUBSCRIBE_CONFIRMED ) 
     144                { 
     145                    return array('error' => true, 'message' => $lang['Message']['Allready_reg']); 
     146                } 
     147                else if( $action == 'desinscription' && $abodata['confirmed'] == SUBSCRIBE_NOT_CONFIRMED ) 
     148                { 
     149                    return array('error' => true, 'message' => $lang['Message']['Unknown_email']); 
     150                } 
     151            } 
     152            else if( $action != 'inscription' ) 
     153            { 
     154                return array('error' => true, 'message' => $lang['Message']['Unknown_email']); 
     155            } 
     156        } 
     157        else if( $action != 'inscription' ) 
     158        { 
     159            return array('error' => true, 'message' => $lang['Message']['Unknown_email']); 
     160        } 
     161         
     162        if( $nl_config['check_email_mx'] && $abodata === false ) 
     163        { 
     164            // 
     165            // Vérification de l'existence d'un Mail eXchanger sur le domaine de l'email,  
     166            // et vérification de l'existence du compte associé (La vérification de l'existence du  
     167            // compte n'est toutefois pas infaillible, les serveurs smtp refusant parfois le relaying,  
     168            // c'est à dire de traiter les demandes émanant d'un entité extérieure à leur réseau, et  
     169            // pour une adresse email extérieure à ce réseau) 
     170            // 
     171            if( $this->mailer->validate_email_mx($email) == false ) 
     172            { 
     173                return array('error' => true, 'message' => $lang['Message']['Unrecognized_email']); 
     174            } 
     175        } 
     176         
     177        if( is_array($abodata) ) 
     178        { 
     179            $this->hasAccount   = true; 
     180            $this->isRegistered = isset($abodata['confirmed']); 
     181             
     182            $this->account['abo_id'] = $abodata['abo_id']; 
     183            $this->account['email']  = $abodata['abo_email']; 
     184            $this->account['pseudo'] = $abodata['abo_pseudo']; 
     185            $this->account['code']   = $abodata['register_key']; 
     186            $this->account['date']   = $abodata['register_date']; 
     187            $this->account['format'] = $abodata['format']; 
     188            $this->account['status'] = $abodata['abo_status']; 
     189        } 
     190        else 
     191        { 
     192            $this->hasAccount = false; 
     193             
     194            $this->account['abo_id'] = 0; 
     195            $this->account['email']  = $email; 
     196            $this->account['pseudo'] = ''; 
     197            $this->account['code']   = generate_key(20); 
     198            $this->account['date']   = time(); 
     199            $this->account['format'] = $this->format; 
     200            $this->account['status'] = ( $this->listdata['confirm_subscribe'] == CONFIRM_NONE ) ? ABO_ACTIF : ABO_INACTIF; 
     201        } 
     202         
     203        return array('error' => false, 'abodata' => $abodata); 
     204    } 
     205     
     206    function do_action($action, $email) 
     207    { 
     208        $email  = trim($email); 
     209        $result = $this->check($action, $email); 
     210         
     211        if( $result['error'] == false ) 
     212        { 
     213            switch( $action ) 
     214            { 
     215                case 'inscription': 
     216                    $this->subscribe(); 
     217                    break; 
     218                case 'desinscription': 
     219                    $this->unsubscribe(); 
     220                    break; 
     221                case 'setformat': 
     222                    $this->setformat(); 
     223                    break; 
     224            } 
     225        } 
     226        else if( empty($this->message) ) 
     227        { 
     228            $this->message = $result['message']; 
     229        } 
     230    } 
     231     
     232    function check_code($code) 
     233    { 
     234        global $db, $lang; 
     235         
     236        $sql = "SELECT a.abo_id, a.abo_email, a.abo_status, al.confirmed, al.register_date, l.liste_id, 
     237                l.liste_format, l.sender_email, l.liste_alias, l.limitevalidate, l.liste_name, 
     238                l.return_email, l.form_url, l.liste_sig, l.use_cron, l.confirm_subscribe 
     239            FROM " . ABONNES_TABLE . " AS a 
     240                INNER JOIN " . ABO_LISTE_TABLE . " AS al ON al.abo_id = a.abo_id 
     241                    AND al.register_key = '" . $db->escape($code) . "' 
     242                INNER JOIN " . LISTE_TABLE . " AS l ON l.liste_id = al.liste_id"; 
     243        if( !($result = $db->query($sql)) ) 
     244        { 
     245            trigger_error('Impossible de tester les tables d\'inscriptions', ERROR); 
     246        } 
     247         
     248        if( $abodata = $db->fetch_array($result) ) 
     249        { 
     250            $this->account['abo_id'] = $abodata['abo_id']; 
     251            $this->account['email']  = $abodata['abo_email']; 
     252            $this->account['date']   = $abodata['register_date']; 
     253            $this->account['code']   = $code; 
     254            $this->listdata = $abodata; 
     255             
     256            if( $abodata['confirmed'] == SUBSCRIBE_NOT_CONFIRMED ) 
     257            { 
     258                $this->confirm($code); 
    91259            } 
    92260            else 
    93261            { 
    94                 $this->hasAccount = false; 
    95                  
    96                 $this->account['abo_id'] = 0; 
    97                 $this->account['email']  = $email; 
    98                 $this->account['pseudo'] = trim($pseudo); 
    99                 $this->account['code']   = generate_key(); 
    100                 $this->account['date']   = time(); 
    101                 $this->account['format'] = $this->format; 
    102                 $this->account['status'] = ( $this->listdata['confirm_subscribe'] == CONFIRM_NONE ) ? ABO_ACTIF : ABO_INACTIF; 
    103             } 
    104              
    105             return true; 
    106         } 
    107         else 
    108         { 
    109             $this->message = $result['message']; 
    110              
    111             return false; 
     262                $this->unsubscribe($code); 
     263            } 
     264        } 
     265        else 
     266        { 
     267            $this->message = $lang['Message']['Invalid_code']; 
    112268        } 
    113269    } 
     
    115271    function subscribe() 
    116272    { 
    117         global $db, $nl_config, $lang, $mailer
     273        global $db, $nl_config, $lang
    118274         
    119275        $db->transaction(START_TRC); 
     
    124280                'abo_email'         => $this->account['email'], 
    125281                'abo_pseudo'        => $this->account['pseudo'], 
    126                 'abo_register_key'  => $this->account['code']
     282                'abo_register_key'  => generate_key()
    127283                'abo_register_date' => $this->account['date'], 
    128284                'abo_status'        => $this->account['status'] 
     
    152308            } 
    153309             
    154             $sql = "INSERT INTO " . ABO_LISTE_TABLE . " (abo_id, liste_id, format, confirmed, register_date)  
    155                 VALUES({$this->account[abo_id]}, {$this->listdata[liste_id]}, $this->format, $confirmed, " . time() . ")"; 
     310            $sql = "INSERT INTO " . ABO_LISTE_TABLE . " (abo_id, liste_id, format, register_key, register_date, confirmed)  
     311                VALUES({$this->account['abo_id']}, {$this->listdata['liste_id']}, $this->format, '{$this->account['code']}', " . time() . ", $confirmed)"; 
    156312            if( !$db->query($sql) ) 
    157313            { 
     
    166322        { 
    167323            $email_tpl = ( $this->listdata['use_cron'] ) ? 'welcome_cron2' : 'welcome_form2'; 
    168             $link_action = 'confirmation'; 
    169324        } 
    170325        else 
    171326        { 
    172327            $email_tpl = ( $this->listdata['use_cron'] ) ? 'welcome_cron1' : 'welcome_form1'; 
    173             $link_action = 'desinscription'; 
    174              
    175328            $this->alert_admin(true); 
    176329        } 
    177330         
    178         $mailer->clear_all(); 
    179         $mailer->set_from($this->listdata['sender_email'], unhtmlspecialchars($this->listdata['liste_name'])); 
    180         $mailer->set_address($this->account['email']); 
    181         $mailer->set_subject(sprintf($lang['Subject_email']['Subscribe'], $nl_config['sitename'])); 
    182         $mailer->set_priority(1); 
    183         $mailer->set_return_path($this->listdata['return_email']); 
    184          
    185         $mailer->use_template($email_tpl, array( 
     331        $this->mailer->clear_all(); 
     332        $this->mailer->set_from($this->listdata['sender_email'], unhtmlspecialchars($this->listdata['liste_name'])); 
     333        $this->mailer->set_address($this->account['email']); 
     334        $this->mailer->set_subject(sprintf($lang['Subject_email']['Subscribe'], $nl_config['sitename'])); 
     335        $this->mailer->set_priority(1); 
     336        $this->mailer->set_return_path($this->listdata['return_email']); 
     337         
     338        $this->mailer->use_template($email_tpl, array( 
    186339            'LISTE'    => unhtmlspecialchars($this->listdata['liste_name']), 
    187340            'SITENAME' => $nl_config['sitename'], 
     
    193346        if( $this->listdata['use_cron'] ) 
    194347        { 
    195             $mailer->assign_tags(array( 
     348            $this->mailer->assign_tags(array( 
    196349                'EMAIL_NEWSLETTER' => $this->liste_email 
    197350            )); 
     
    199352        else 
    200353        { 
    201             $mailer->assign_tags(array( 
    202                 'LINK' => $this->make_link($link_action
     354            $this->mailer->assign_tags(array( 
     355                'LINK' => $this->make_link(
    203356            )); 
    204357        } 
     
    206359        if( $nl_config['enable_profil_cp'] ) 
    207360        { 
    208             $mailer->assign_block_tags('enable_profil_cp', array( 
     361            $this->mailer->assign_block_tags('enable_profil_cp', array( 
    209362                'LINK_PROFIL_CP' => make_script_url('profil_cp.php') 
    210363            )); 
    211364        } 
    212365         
    213         if( !$mailer->send() ) 
     366        if( !$this->mailer->send() ) 
    214367        { 
    215368            $this->message = $lang['Message']['Failed_sending']; 
     
    221374            if( $this->listdata['confirm_subscribe'] == CONFIRM_NONE ) 
    222375            { 
    223                 $this->update_stats = true
     376                $this->update_stats()
    224377                $message = $lang['Message']['Subscribe_2']; 
    225378            } 
     
    237390            else if( $this->listdata['confirm_subscribe'] != CONFIRM_ALWAYS ) 
    238391            { 
    239                 $this->update_stats = true
     392                $this->update_stats()
    240393                $message = $lang['Message']['Subscribe_2']; 
    241394            } 
     
    249402    } 
    250403     
    251     function confirm($time = 0) 
    252     { 
    253         global $db, $nl_config, $lang, $mailer
    254          
    255         if( $this->code == $this->account['code']
     404    function confirm($code, $time = 0) 
     405    { 
     406        global $db, $nl_config, $lang
     407         
     408        if( strcmp($code, $this->account['code']) == 0
    256409        { 
    257410            $time = ( empty($time) ) ? time() : $time; 
     
    261414            { 
    262415                $low_priority = ( strncmp(DATABASE, 'mysql', 5) == 0 ) ? 'LOW_PRIORITY' : ''; 
     416                $this->account['code'] = generate_key(20); 
    263417                 
    264418                $db->transaction(START_TRC); 
     
    274428                 
    275429                $sql = "UPDATE $low_priority " . ABO_LISTE_TABLE . " 
    276                     SET confirmed = " . SUBSCRIBE_CONFIRMED . " 
     430                    SET confirmed = " . SUBSCRIBE_CONFIRMED . ", 
     431                        register_key = '" . $this->account['code'] . "' 
    277432                    WHERE liste_id = " . $this->listdata['liste_id'] . " 
    278433                        AND abo_id = " . $this->account['abo_id']; 
     
    285440                $db->transaction(END_TRC); 
    286441                 
    287                 $this->update_stats = true
     442                $this->update_stats()
    288443                $this->alert_admin(true); 
    289444                 
     
    305460    } 
    306461     
    307     function unsubscribe() 
    308     { 
    309         global $db, $nl_config, $lang, $mailer; 
    310          
    311         if( $this->code != '' ) 
    312         { 
    313             if( $this->code == $this->account['code'] ) 
    314             { 
    315                 $sql = "SELECT COUNT(abo_id) AS num_subscribe 
    316                     FROM " . ABO_LISTE_TABLE . " 
    317                     WHERE abo_id = " . $this->account['abo_id']; 
    318                 if( !($result = $db->query($sql)) ) 
     462    function unsubscribe($code = '') 
     463    { 
     464        global $db, $nl_config, $lang; 
     465         
     466        if( !empty($code) ) 
     467        { 
     468            $sql = "SELECT COUNT(abo_id) AS num_subscribe 
     469                FROM " . ABO_LISTE_TABLE . " 
     470                WHERE abo_id = " . $this->account['abo_id']; 
     471            if( !($result = $db->query($sql)) ) 
     472            { 
     473                trigger_error('Impossible de vérifier la table de jointure', ERROR); 
     474                return false; 
     475            } 
     476             
     477            $num_subscribe = $db->result($result, 0, 'num_subscribe'); 
     478             
     479            $db->transaction(START_TRC); 
     480             
     481            $sql = "DELETE FROM " . ABO_LISTE_TABLE . " 
     482                WHERE liste_id = " . $this->listdata['liste_id'] . " 
     483                    AND abo_id = " . $this->account['abo_id']; 
     484            if( !$db->query($sql) ) 
     485            { 
     486                trigger_error('Impossible d\'effacer l\'entrée de la table abo_liste', ERROR); 
     487                return false; 
     488            } 
     489             
     490            if( $num_subscribe == 1 ) 
     491            { 
     492                $sql = 'DELETE FROM ' . ABONNES_TABLE . '  
     493                    WHERE abo_id = ' . $this->account['abo_id']; 
     494                if( !$db->query($sql) ) 
    319495                { 
    320                     trigger_error('Impossible de vérifier la table de jointure', ERROR); 
     496                    trigger_error('Impossible d\'effacer l\'entrée de la table des abonnés', ERROR); 
    321497                    return false; 
    322498                } 
    323499                 
    324                 $num_subscribe = $db->result($result, 0, 'num_subscribe'); 
    325                  
    326                 $db->transaction(START_TRC); 
    327                  
    328                 $sql = "DELETE FROM " . ABO_LISTE_TABLE . " 
    329                     WHERE liste_id = " . $this->listdata['liste_id'] . " 
    330                         AND abo_id = " . $this->account['abo_id']; 
    331                 if( !$db->query($sql) ) 
    332                 { 
    333                     trigger_error('Impossible d\'effacer l\'entrée de la table abo_liste', ERROR); 
    334                     return false; 
    335                 } 
    336                  
    337                 if( $num_subscribe == 1 ) 
    338                 { 
    339                     $sql = 'DELETE FROM ' . ABONNES_TABLE . '  
    340                         WHERE abo_id = ' . $this->account['abo_id']; 
    341                     if( !$db->query($sql) ) 
    342                     { 
    343                         trigger_error('Impossible d\'effacer l\'entrée de la table des abonnés', ERROR); 
    344                         return false; 
    345                     } 
    346                      
    347                     $this->message = $lang['Message']['Unsubscribe_3']; 
    348                 } 
    349                 else 
    350                 { 
    351                     $this->message = $lang['Message']['Unsubscribe_2']; 
    352                 } 
    353                  
    354                 $db->transaction(END_TRC); 
    355                 $this->alert_admin(false); 
    356                  
    357                 return true; 
     500                $this->message = $lang['Message']['Unsubscribe_3']; 
    358501            } 
    359502            else 
    360503            { 
    361                 $this->message = $lang['Message']['Invalid_code']; 
    362                  
    363                 return false; 
    364             } 
    365         } 
    366         else 
    367         { 
    368             $mailer->set_from($this->listdata['sender_email'], unhtmlspecialchars($this->listdata['liste_name'])); 
    369             $mailer->set_address($this->account['email']); 
    370             $mailer->set_subject($lang['Subject_email']['Unsubscribe']); 
    371             $mailer->set_priority(3); 
    372             $mailer->set_return_path($this->listdata['return_email']); 
     504                $this->message = $lang['Message']['Unsubscribe_2']; 
     505            } 
     506             
     507            $db->transaction(END_TRC); 
     508            $this->alert_admin(false); 
     509             
     510            return true; 
     511        } 
     512        else 
     513        { 
     514            $this->mailer->set_from($this->listdata['sender_email'], unhtmlspecialchars($this->listdata['liste_name'])); 
     515            $this->mailer->set_address($this->account['email']); 
     516            $this->mailer->set_subject($lang['Subject_email']['Unsubscribe']); 
     517            $this->mailer->set_priority(3); 
     518            $this->mailer->set_return_path($this->listdata['return_email']); 
    373519             
    374520            $email_tpl = ( $this->listdata['use_cron'] ) ? 'unsubscribe_cron' : 'unsubscribe_form'; 
    375521             
    376             $mailer->use_template($email_tpl, array( 
     522            $this->mailer->use_template($email_tpl, array( 
    377523                'LISTE'    => unhtmlspecialchars($this->listdata['liste_name']), 
    378524                'SITENAME' => $nl_config['sitename'], 
     
    383529            if( $this->listdata['use_cron'] ) 
    384530            { 
    385                 $mailer->assign_tags(array( 
     531                $this->mailer->assign_tags(array( 
    386532                    'EMAIL_NEWSLETTER' => $this->liste_email, 
    387533                    'CODE'             => $this->account['code'] 
     
    390536            else 
    391537            { 
    392                 $mailer->assign_tags(array( 
    393                     'LINK' => $this->make_link('desinscription'
     538                $this->mailer->assign_tags(array( 
     539                    'LINK' => $this->make_link(
    394540                )); 
    395541            } 
    396542             
    397             if( !($mailer->send()) ) 
     543            if( !$this->mailer->send() ) 
    398544            { 
    399545                $this->message = $lang['Message']['Failed_sending']; 
     
    447593    } 
    448594     
    449     function make_link($action
    450     { 
    451         $prefix = $this->listdata['form_url'] . ( ( strstr($this->listdata['form_url'], '?') ) ? '&' : '?' ); 
    452          
    453         return $prefix . 'action=' . $action . '&email=' . rawurlencode($this->account['email']) . '&code=' . $this->account['code'] . '&liste=' . $this->listdata['liste_id']; 
     595    function make_link(
     596    { 
     597        return $this->listdata['form_url'] 
     598           . (( strstr($this->listdata['form_url'], '?') ) ? '&' : '?') 
     599           . $this->account['code']; 
    454600    } 
    455601     
    456602    function alert_admin($new_subscribe) 
    457603    { 
    458         global $nl_config, $db, $mailer
     604        global $db, $nl_config, $lang
    459605         
    460606        if( $new_subscribe == true ) 
     
    483629            if( $row = $db->fetch_array($result) ) 
    484630            { 
    485                 $mailer->clear_all(); 
    486                  
    487                 $mailer->set_from($this->listdata['sender_email'], unhtmlspecialchars($this->listdata['liste_name'])); 
    488                 $mailer->set_subject($subject); 
    489                  
    490                 $mailer->use_template($template, array( 
     631                $this->mailer->clear_all(); 
     632                $this->mailer->set_from($this->listdata['sender_email'], unhtmlspecialchars($this->listdata['liste_name'])); 
     633                $this->mailer->set_subject($subject); 
     634                 
     635                $this->mailer->use_template($template, array( 
    491636                    'EMAIL'   => $this->account['email'], 
    492637                    'LISTE'   => unhtmlspecialchars($this->listdata['liste_name']), 
     
    497642                do 
    498643                { 
    499                     $mailer->clear_address(); 
    500                     $mailer->set_address($row['admin_email'], $row['admin_login']); 
     644                    $this->mailer->clear_address(); 
     645                    $this->mailer->set_address($row['admin_email'], $row['admin_login']); 
    501646                     
    502                     $mailer->assign_tags(array( 
     647                    $this->mailer->assign_tags(array( 
    503648                        'USER' => $row['admin_login'] 
    504649                    )); 
    505650                     
    506                     $mailer->send(); // envoi 
     651                    $this->mailer->send(); // envoi 
    507652                } 
    508653                while( $row = $db->fetch_array($result) ); 
    509654            } 
     655        } 
     656    } 
     657     
     658    function update_stats() 
     659    { 
     660        @include WA_ROOTDIR . '/includes/functions.stats.php'; 
     661         
     662        if( function_exists('update_stats') ) 
     663        { 
     664            update_stats($this->listdata); 
    510665        } 
    511666    } 
  • trunk/includes/engine_send.php

    r221 r230  
    165165    // On récupère les infos sur les abonnés destinataires 
    166166    // 
    167     $sql = "SELECT a.abo_id, a.abo_pseudo, $fields_str a.abo_email, a.abo_register_key, al.format 
     167    $sql = "SELECT a.abo_id, a.abo_pseudo, $fields_str a.abo_email, al.register_key, al.format 
    168168        FROM " . ABONNES_TABLE . " AS a 
    169             INNER JOIN " . ABO_LISTE_TABLE . " AS al 
    170             ON al.abo_id = a.abo_id 
     169            INNER JOIN " . ABO_LISTE_TABLE . " AS al ON al.abo_id = a.abo_id 
    171170                AND al.liste_id  = $listdata[liste_id] 
    172171                AND al.confirmed = " . SUBSCRIBE_CONFIRMED . " 
     
    294293                        'abo_pseudo' => '', 
    295294                        'abo_email'  => $address, 
    296                         'abo_register_key' => '', 
     295                        'register_key' => '', 
    297296                        'abo_id'     => -1 
    298297                    )); 
     
    305304                        'abo_pseudo' => '', 
    306305                        'abo_email'  => $address, 
    307                         'abo_register_key' => '', 
     306                        'register_key' => '', 
    308307                        'abo_id'     => -1 
    309308                    )); 
     
    387386                { 
    388387                    $tags_replace = array_merge($tags_replace, array( 
    389                         'WA_CODE'  => $row['abo_register_key'], 
     388                        'WA_CODE'  => $row['register_key'], 
    390389                        'WA_EMAIL' => rawurlencode($row['abo_email']) 
    391390                    )); 
     
    460459        $sql = "SELECT COUNT(*) AS num_dest, al.send 
    461460            FROM " . ABO_LISTE_TABLE . " AS al 
    462                 INNER JOIN " . ABONNES_TABLE . " AS a 
    463                 ON a.abo_id = al.abo_id 
     461                INNER JOIN " . ABONNES_TABLE . " AS a ON a.abo_id = al.abo_id 
    464462                    AND a.abo_status = " . ABO_ACTIF . " 
    465463            WHERE al.liste_id    = $listdata[liste_id] 
     
    583581        else 
    584582        { 
    585             $tmp_link  = $listdata['form_url'] . ( ( strstr($listdata['form_url'], '?') ) ? '&' : '?' ); 
    586             $tmp_link .= 'action=desinscription&email={WA_EMAIL}&code={WA_CODE}&liste=' . $listdata['liste_id']; 
     583            $tmp_link = $listdata['form_url'] . ( ( strstr($listdata['form_url'], '?') ) ? '&' : '?' ) . '{WA_CODE}'; 
    587584             
    588585            $link = array( 
  • trunk/includes/functions.validate.php

    r184 r230  
    2929 
    3030define('FUNCTIONS_VALIDATE_INC', true); 
    31  
    32 /** 
    33  * check_email() 
    34  *  
    35  * Vérification de l'email 
    36  *  
    37  * @param string  $email   Email à vérifier 
    38  * @param integer $liste   Id de la liste concernée 
    39  * @param string  $action  Action en cours 
    40  *  
    41  * @return array 
    42  */ 
    43 function check_email($email, $liste = 0, $action = '', $disable_check_mx = false) 
    44 { 
    45     global $db, $nl_config, $lang; 
    46      
    47     if( !class_exists('Mailer') ) 
    48     { 
    49         require WAMAILER_DIR . '/class.mailer.php'; 
    50     } 
    51      
    52     // 
    53     // Vérification syntaxique de l'email 
    54     // 
    55     if( Mailer::validate_email($email) == false ) 
    56     { 
    57         return array('error' => true, 'message' => $lang['Message']['Invalid_email']); 
    58     } 
    59      
    60     $sql = 'SELECT ban_email FROM ' . BANLIST_TABLE . '  
    61         WHERE liste_id = ' . $liste; 
    62     if( $result = $db->query($sql) ) 
    63     { 
    64         while( $row = $db->fetch_array($result) ) 
    65         { 
    66             if( preg_match('/\b' . str_replace('*', '.*?', $row['ban_email']) . '\b/i', $email) ) 
    67             { 
    68                 return array('error' => true, 'message' => $lang['Message']['Email_banned']); 
    69             } 
    70         } 
    71     } 
    72      
    73     $abodata   = array(); 
    74     $sql_email = $db->escape(strtolower($email)); 
    75      
    76     $sql = "SELECT a.abo_id, a.abo_pseudo, a.abo_pwd, a.abo_email, a.abo_lang, a.abo_register_key, a.abo_register_date, 
    77             a.abo_status, al.format, al.confirmed, al.register_date 
    78         FROM " . ABONNES_TABLE . " AS a 
    79             LEFT JOIN " . ABO_LISTE_TABLE . " AS al ON al.abo_id = a.abo_id 
    80                 AND al.liste_id = $liste 
    81         WHERE LOWER(a.abo_email) = '$sql_email'"; 
    82     if( !($result = $db->query($sql)) ) 
    83     { 
    84         trigger_error('Impossible de tester les tables d\'inscriptions', ERROR); 
    85     } 
    86      
    87     if( $abodata = $db->fetch_array($result) ) 
    88     { 
    89         if( isset($abodata['confirmed']) ) 
    90         { 
    91             if( $action == 'inscription' && $abodata['confirmed'] == SUBSCRIBE_CONFIRMED ) 
    92             { 
    93                 return array('error' => true, 'message' => $lang['Message']['Allready_reg']); 
    94             } 
    95             else if( $action == 'confirmation' && $abodata['confirmed'] == SUBSCRIBE_CONFIRMED ) 
    96             { 
    97                 return array('error' => true, 'message' => $lang['Message']['Allready_confirm']); 
    98             } 
    99         } 
    100         else if( $action != 'inscription' ) 
    101         { 
    102             return array('error' => true, 'message' => $lang['Message']['Unknown_email']); 
    103         } 
    104     } 
    105     else if( $action != 'inscription' ) 
    106     { 
    107         return array('error' => true, 'message' => $lang['Message']['Unknown_email']); 
    108     } 
    109      
    110     if( !$disable_check_mx && $nl_config['check_email_mx'] && $abodata === false ) 
    111     { 
    112         // 
    113         // Vérification de l'existence d'un Mail eXchanger sur le domaine de l'email,  
    114         // et vérification de l'existence du compte associé (La vérification de l'existence du  
    115         // compte n'est toutefois pas infaillible, les serveurs smtp refusant parfois le relaying,  
    116         // c'est à dire de traiter les demandes émanant d'un entité extérieure à leur réseau, et  
    117         // pour une adresse email extérieure à ce réseau) 
    118         // 
    119         $mailer = new Mailer(); 
    120         $mailer->smtp_path = WAMAILER_DIR . '/'; 
    121          
    122         if( $mailer->validate_email_mx($email) == false ) 
    123         { 
    124             return array('error' => true, 'message' => $lang['Message']['Unrecognized_email']); 
    125         } 
    126     } 
    127      
    128     return array('error' => false, 'abodata' => $abodata); 
    129 } 
    13031 
    13132/** 
  • trunk/language/lang_francais.php

    r223 r230  
    249249$lang['Message']['Upload_error_7']          = "Échec de l'écriture du fichier sur le disque"; 
    250250$lang['Message']['Invalid_filename']        = "Nom de fichier non valide"; 
     251$lang['Message']['Invalid_action']          = "Action non valide"; 
    251252$lang['Message']['Invalid_ext']             = "Cette extension de fichier a été interdite"; 
    252253$lang['Message']['weight_too_big']          = "Le poids total des fichiers joints excède le maximum autorisé, il ne vous reste que %.2f octets de libre"; 
  • trunk/newsletter.php

    r208 r230  
    6262} 
    6363 
     64$action  = ( !empty($_REQUEST['action']) ) ? trim($_REQUEST['action']) : ''; 
     65$email   = ( !empty($_REQUEST['email']) ) ? trim($_REQUEST['email']) : ''; 
    6466$message = ''; 
     67$code    = ''; 
     68$liste   = ( isset($_REQUEST['liste']) ) ? intval($_REQUEST['liste']) : 0; 
    6569 
    66 $vararray = array('action', 'email', 'code', 'liste'); 
    67 foreach( $vararray AS $varname ) 
     70if( empty($action) && preg_match('/([a-z0-9]{20})(?:&|$)/i', $_SERVER['QUERY_STRING'], $match) ) 
    6871{ 
    69     ${$varname} = ( !empty($_REQUEST[$varname]) ) ? $_REQUEST[$varname] : ''
     72    $code = $match[1]
    7073} 
    7174 
     
    7376// Compatibilité avec les version < 2.3.x 
    7477// 
    75 if( strlen($code) == 32 ) 
     78else if( !empty($action) && !empty($email) && strlen($code) == 32 ) 
    7679{ 
    7780    $code = substr($code, 0, 20); 
    7881} 
    7982 
    80 if( $action != ''
     83if( !empty($action) || !empty($code)
    8184{ 
    82     $sql = 'SELECT * FROM ' . LISTE_TABLE . '  
    83         WHERE liste_id = ' . intval($liste); 
    84     if( !($result = $db->query($sql)) ) 
     85    // 
     86    // Purge des éventuelles inscriptions dépassées 
     87    // pour parer au cas d'une réinscription 
     88    // 
     89    purge_liste(); 
     90     
     91    require WA_ROOTDIR . '/includes/class.form.php'; 
     92     
     93    if( !empty($action) ) 
    8594    { 
    86         trigger_error('Impossible d\'obtenir les données sur la liste', ERROR); 
    87     } 
    88     else if( $listdata = $db->fetch_array($result) ) 
    89     { 
    90         // 
    91         // Purge des éventuelles inscriptions dépassées 
    92         // pour parer au cas d'une réinscription 
    93         // 
    94         purge_liste(); 
    95          
    96         require WAMAILER_DIR . '/class.mailer.php'; 
    97         require WA_ROOTDIR . '/includes/class.form.php'; 
    98         include WA_ROOTDIR . '/includes/functions.stats.php'; 
    99          
    100         $mailer = new Mailer(WA_ROOTDIR . '/language/email_' . $nl_config['language'] . '/'); 
    101          
    102         if( $nl_config['use_smtp'] ) 
     95        if( in_array($action, array('inscription', 'setformat', 'desinscription')) ) 
    10396        { 
    104             $mailer->smtp_path = WAMAILER_DIR . '/'; 
    105             $mailer->use_smtp( 
    106                 $nl_config['smtp_host'], 
    107                 $nl_config['smtp_port'], 
    108                 $nl_config['smtp_user'], 
    109                 $nl_config['smtp_pass'] 
    110             ); 
    111