Pack html generated by the MiniWiki in <html><body> in mails.
[platal.git] / modules / register.php
index 4dea3ae..2f6a380 100644 (file)
@@ -28,6 +28,7 @@ class RegisterModule extends PLModule
             'register/end'     => $this->make_hook('end',      AUTH_PUBLIC),
             'register/end.php' => $this->make_hook('end_old',  AUTH_PUBLIC),
             'register/success' => $this->make_hook('success',  AUTH_MDP),
+            'register/save'    => $this->make_hook('save',     AUTH_MDP),
         );
     }
 
@@ -48,7 +49,7 @@ class RegisterModule extends PLModule
             $sub_state['backs'][] = $state;
             if (count($sub_state['backs']) == 3) {
                 $alert .= "Tentative d'inscription tres hesitante - ";
-            }   
+            }
         }
 
         // Compatibility with old sources, keep it atm
@@ -69,7 +70,7 @@ class RegisterModule extends PLModule
                 $sub_state['nom']    = $nom;
                 $sub_state['prenom'] = $prenom;
                 $sub_state['ourmat'] = $ourmat;
-                $sub_state['watch']  = $watch; 
+                $sub_state['watch']  = $watch;
                 $sub_state['naissance_ini'] = $naiss;
 
                 XDB::execute(
@@ -192,8 +193,8 @@ class RegisterModule extends PLModule
                         $sub_state['email']     = Post::v('email');
                         if (check_ip('unsafe')) {
                             $err = "Une erreur s'est produite lors de l'inscription."
-                                 . " Merci de contacter <a href='mailto:register@{$globals->mails->domain}>"
-                                 . " register@{$globals->mails->domain}</a>"
+                                 . " Merci de contacter <a href='mailto:register@{$globals->mail->domain}>"
+                                 . " register@{$globals->mail->domain}</a>"
                                  . " pour nous faire part de cette erreur";
                             $alert .= "Tentative d'inscription depuis une IP surveillee";
                         } else {
@@ -308,6 +309,12 @@ class RegisterModule extends PLModule
         $mymail->assign('prenom', $prenom);
         $mymail->send();
 
+        require_once('user.func.inc.php');
+        user_reindex($uid);
+
+        // update number of subscribers (perms has changed)
+        update_NbIns();
+
         if (!start_connexion($uid, false)) {
             return PL_FORBIDDEN;
         }
@@ -329,7 +336,7 @@ class RegisterModule extends PLModule
         while (list($salias, $snom, $sprenom, $sfemme) = $res->next()) {
             $mymail = new PlMailer();
             $mymail->setSubject("$prenom $nom s'est inscrit à Polytechnique.org !");
-            $mymail->setFrom('"Marketing Polytechnique.org" <register@' . $globals->mails->domain . '>');
+            $mymail->setFrom('"Marketing Polytechnique.org" <register@' . $globals->mail->domain . '>');
             $mymail->addTo("\"$sprenom $snom\" <$salias@{$globals->mail->domain}>");
             $msg = ($sfemme?'Chère':'Cher')." $sprenom,\n\n"
                  . "Nous t'écrivons pour t'informer que $prenom $nom (X$promo), "
@@ -346,7 +353,7 @@ class RegisterModule extends PLModule
         if ($globals->register->notif) {
             $mymail = new PlMailer();
             $mymail->setSubject("Inscription de $prenom $nom (X$promo)");
-            $mymail->setFrom('"Webmaster Polytechnique.org" <web@' . $globals->mails->domain . '>');
+            $mymail->setFrom('"Webmaster Polytechnique.org" <web@' . $globals->mail->domain . '>');
             $mymail->addTo($globals->register->notif);
             $msg = "$prenom $nom (X$promo) a terminé son inscription avec les données suivantes :\n"
                  . " - nom       : $nom\n"
@@ -359,7 +366,7 @@ class RegisterModule extends PLModule
                  . " - ip        : {$logger->ip} ({$logger->host})\n"
                  . ($logger->proxy_ip ? " - proxy     : {$logger->proxy_ip} ({$logger->proxy_host})\n" : "");
             $mymail->setTxtBody($msg);
-            $mymail->send(); 
+            $mymail->send();
         }
 
         Marketing::clear($uid);
@@ -410,6 +417,51 @@ class RegisterModule extends PLModule
 
         $page->addJsLink('motdepasse.js');
     }
+
+    function handler_save(&$page)
+    {
+        global $globals;
+
+        // Finish registration procedure
+        if (Post::v('register_from_ax_question')) {
+            XDB::execute('UPDATE auth_user_quick
+                                     SET profile_from_ax = 1
+                                   WHERE user_id = {?}',
+                                 S::v('uid'));
+        }
+        if (Post::v('add_to_nl')) {
+            require_once 'newsletter.inc.php';
+            NewsLetter::subscribe();
+        }
+        if (Post::v('add_to_ax')) {
+            require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
+            AXLetter::subscribe();
+        }
+        if (Post::v('add_to_promo')) {
+            $r = XDB::query('SELECT id FROM groupex.asso WHERE diminutif = {?}',
+                S::v('promo'));
+            $asso_id = $r->fetchOneCell();
+            XDB::execute('REPLACE INTO groupex.membres (uid,asso_id)
+                                     VALUES ({?}, {?})',
+                                 S::v('uid'), $asso_id);
+            $mmlist = new MMList(S::v('uid'), S::v('password'));
+            $mmlist->subscribe("promo".S::v('promo'));
+        }
+        if (Post::v('sub_ml')) {
+            $subs = array_keys(Post::v('sub_ml'));
+            $current_domain = null;
+            foreach ($subs as $list) {
+                list($sub, $domain) = explode('@', $list);
+                if ($domain != $current_domain) {
+                    $current_domain = $domain;
+                    $client = new MMList(S::v('uid'), S::v('password'), $domain);
+                }
+                $client->subscribe($sub);
+            }
+        }
+
+        pl_redirect('profile/edit');
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: