Close #658: Can change a xnet non-X account into a X account.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 13 Sep 2007 21:38:44 +0000 (23:38 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 13 Sep 2007 21:38:44 +0000 (23:38 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
ChangeLog
modules/xnetgrp.php
templates/xnetgrp/membres-edit.tpl

index bcf7991..831bfaf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -47,6 +47,7 @@ Bug/Wish:
         - #694: Color of 'Promotion' groups                                -ALK
 
     * XnetGrp:
+        - #658: Admins can convert 'non-X' into X                          -FRU
         - #696: Don't forget non-X when counting members                   -FRU
         - #698: Fix the unregister user lister when adding a new member    -FRU
 
index 0c29632..85dcdf0 100644 (file)
@@ -838,6 +838,72 @@ class XnetGrpModule extends PLModule
         }
     }
 
+    private function changeLogin(PlatalPage &$page, array &$user, MMList &$mmlist, $login)
+    {
+        require_once 'user.func.inc.php';
+        // Search the uid of the user...
+        $res = XDB::query("SELECT  f.id, f.alias
+                             FROM  aliases AS a
+                       INNER JOIN  aliases AS f ON (f.id = a.id AND f.type = 'a_vie')
+                            WHERE  a.alias = {?}",
+                          $login);
+        if ($res->numRows() == 0) {
+            $x = get_not_registered_user($login);
+            if (!$x) {
+                $page->trig("Le login $login ne correspond à aucun X");
+                return false;
+            } else if (count($x) > 1) {
+                $page->trig("Le login $login correspond a plusieurs camarades");
+                return false;
+            }
+            $uid = $x[0]['user_id'];
+            $sub = false;
+        } else {
+            list($uid, $login) = $res->fetchOneRow();
+            $sub = true;
+        }
+
+        // Check if the user is already in the group
+        global $globals;
+        $res = XDB::query("SELECT  uid, email
+                             FROM  groupex.membres
+                            WHERE  uid = {?} AND asso_id = {?}",
+                          $uid, $globals->asso('id'));
+        if ($res->numRows()) {
+            list($uid, $email) = $res->fetchOneRow();
+            XDB::execute("DELETE FROM groupex.membres
+                                WHERE uid = {?}",
+                         $user['uid']);
+        } else {
+            $email = $user['email'];
+            XDB::execute("UPDATE  groupex.membres
+                             SET  uid = {?}, origine = 'X'
+                           WHERE  uid = {?} AND asso_id = {?}",
+                         $uid, $user['uid'], $globals->asso('id'));
+        }
+        if ($sub) {
+            $email = $login . '@' . $globals->mail->domain;
+        }
+
+        // Update subscription to aliases
+        if ($email != $user['email']) {
+            XDB::execute("UPDATE IGNORE  virtual_redirect AS vr
+                             INNER JOIN  virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?})
+                                    SET  vr.redirect = {?}
+                                  WHERE  vr.redirect = {?}",
+                         $globals->asso('mail_domain'), $email, $user['email']);
+            XDB::execute("DELETE  vr.*
+                            FROM  virtual_redirect AS vr
+                      INNER JOIN  virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', 2) = {?})
+                           WHERE  vr.redirect = {?}",
+                         $globals->asso('mail_domain'), $user['email']);
+            foreach (Env::v('ml1', array()) as $ml => $state) {
+                $mmlist->replace_email($ml, $user['email'], $email);
+            }
+        }
+        return $login;
+    }
+
     function handler_admin_member(&$page, $user)
     {
         global $globals;
@@ -853,6 +919,15 @@ class XnetGrpModule extends PLModule
                              $globals->asso('mail_domain'));
 
         if (Post::has('change')) {
+            // Convert user status to X
+            if ($user['origine'] == 'ext' && trim(Post::v('login_X'))) {
+                $forlife = $this->changeLogin($page, $user, $mmlist, trim(Post::v('login_X')));
+                if ($forlife) {
+                    pl_redirect('member/' . $forlife);
+                }
+            }
+
+            // Update user info
             $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email')));
             $from_email = $user['email'];
             if ($user['origine'] != 'X') {
@@ -880,6 +955,7 @@ class XnetGrpModule extends PLModule
                 $page->trig('permissions modifiées');
             }
 
+            // Update ML subscriptions
             foreach (Env::v('ml1', array()) as $ml => $state) {
                 $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2;
                 if ($ask == $state) {
@@ -906,6 +982,7 @@ class XnetGrpModule extends PLModule
                 }
             }
 
+            // Change subscriptioin to aliases
             foreach (Env::v('ml3', array()) as $ml => $state) {
                 $ask = !empty($_REQUEST['ml4'][$ml]);
                 if($state == $ask) continue;
index 844c445..7b3bb5f 100644 (file)
 {**************************************************************************}
 
 <script type="text/javascript">
-  {literal}
-    function showInformations(box)
-    {
-        var state = (box.value == 'ext') ? '' : 'none';
-        document.getElementById('prenom').style.display = state;
-        document.getElementById('sexe').style.display = state;
-    }
-  {/literal}
+{literal}
+  function showInformations(box)
+  {
+      var state = (box.value == 'ext') ? '' : 'none';
+      document.getElementById('prenom').style.display = state;
+      document.getElementById('sexe').style.display = state;
+      document.getElementById('make_X').style.display = state;
+  }
+
+  function showXInput(box)
+  {
+     if (box.checked) {
+       document.getElementById('make_X_cb').style.display = 'none';
+       document.getElementById('make_X_login').style.display = '';
+     }
+  }
+{/literal}
 </script>
 
 <h1>{$asso.nom} : gestion des membres</h1>
         <input type="text" value="{$user.email}" name="email" size="40" />
       </td>
     </tr>
+    <tr id="make_X" {if $user.origine eq "groupe"}style="display: none"{/if}>
+      <td colspan="2">
+        <span id="make_X_cb">
+          <input type="checkbox" name="is_x" id="is_x" onchange="showXInput(this);" />
+          <label for="is_x">coche cette case si il s'agit d'un X</label>
+        </span>
+        <span id="make_X_login" style="display: none">
+          <span class="titre">Identifiant (prenom.nom.promo)&nbsp;:</span>
+          <input type="text" name="login_X" value="" />
+        </span>
+      </td>
+    </tr>
     {/if}
   </table>