Carva.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Dec 2008 20:08:47 +0000 (21:08 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 28 Dec 2008 20:08:47 +0000 (21:08 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
htdocs/webredirect.php
modules/platal.php
templates/platal/webredirect.tpl
upgrade/account/03_carnet.sql
upgrade/account/04_carva.sql [new file with mode: 0644]
upgrade/account/99_insertion.sql

index dc7e761..311ae97 100644 (file)
 
 require_once 'xorg.inc.php';
 
-new Xorg('core');
+$platal = new Xorg('core');
 
 global $globals;
-list($username, $path) = preg_split('/\//', $_SERVER["REQUEST_URI"], 2, PREG_SPLIT_NO_EMPTY);
-$res = XDB::query(
-        "SELECT  redirecturl
-           FROM  auth_user_quick AS a
-     INNER JOIN  aliases         AS al ON (al.id = a.user_id AND (al.type='a_vie' OR al.type='alias'))
-          WHERE  al.alias = {?}
-       GROUP BY  redirecturl", $username);
+$path = ltrim($platal->pl_self(), '/');
+@list($username, $path) = explode('/', $path, 2);
 
-if ($url = $res->fetchOneCell()) {
-    $url = preg_replace('@/+$@', '', $url);
-    if ($path) {
-        http_redirect("http://$url/$path");
-    } else {
-        http_redirect("http://$url");
+if ($username && !is_null($user = User::getSilent($username))) {
+    $url = XDB::fetchOneCell('SELECT  url
+                                FROM  carvas
+                               WHERE  uid = {?}', $user->id());
+    if ($url) {
+        $url = preg_replace('@/+$@', '', $url);
+        if ($path) {
+            http_redirect("http://$url/$path");
+        } else {
+            http_redirect("http://$url");
+        }
     }
 }
 
-header("HTTP/1.0 404 Not Found");
-
+header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
 ?>
 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 <html>
index 23031f5..8146055 100644 (file)
@@ -162,33 +162,31 @@ class PlatalModule extends PLModule
     function handler_webredir(&$page)
     {
         $page->changeTpl('platal/webredirect.tpl');
-
         $page->setTitle('Redirection de page WEB');
 
-        $log =& S::v('log');
-        $url = Env::v('url');
-
-        if (Env::v('submit') == 'Valider' and Env::has('url')) {
-            XDB::execute('UPDATE  auth_user_quick
-                             SET  redirecturl = {?} WHERE user_id = {?}',
-                         $url, S::i('uid'));
-            S::logger()->log('carva_add', 'http://'.Env::v('url'));
-            $page->trigSuccess("Redirection activée vers <a href='http://$url'>$url</a>");
-        } elseif (Env::v('submit') == "Supprimer") {
-            XDB::execute("UPDATE  auth_user_quick
-                             SET  redirecturl = ''
-                           WHERE  user_id = {?}",
-                         S::i('uid'));
-            S::logger()->log("carva_del", $url);
+        if (Env::v('submit') == 'Valider' && !Env::blank('url')) {
+            if (Env::blank('url')) {
+                $page->trigError('URL invalide');
+            } else {
+                $url = Env::t('url');
+                XDB::execute('REPLACE INTO  carvas (uid, url)
+                                    VALUES  ({?}, {?})',
+                             S::i('uid'), $url);
+                S::logger()->log('carva_add', 'http://' . $url);
+                $page->trigSuccess("Redirection activée vers <a href='http://$url'>$url</a>");
+            }
+        } elseif (Env::v('submit') == 'Supprimer') {
+            XDB::execute('DELETE FROM carvas
+                                WHERE uid = {?}', S::i('uid'));
             Post::kill('url');
+            S::logger()->log('carva_del');
             $page->trigSuccess('Redirection supprimée');
         }
 
-        $res = XDB::query('SELECT  redirecturl
-                             FROM  auth_user_quick
-                            WHERE  user_id = {?}',
-                          S::i('uid'));
-        $page->assign('carva', $res->fetchOneCell());
+        $url = XDB::fetchOneCell('SELECT  url
+                                    FROM  carvas
+                                   WHERE  uid = {?}', S::i('uid'));
+        $page->assign('carva', $url);
 
         # FIXME: this code is not multi-domain compatible. We should decide how
         # carva will extend to users not in the main domain.
index fa9b58a..9a207bf 100644 (file)
 <h1>
   Mise en place de la redirection
 </h1>
-<p>
-{if $carva}
-  Actuellement, les adresses
-  <a href="http://www.carva.org/{$bestalias}">http://www.carva.org/{$bestalias}</a> et
-  <a href="http://www.carva.org/{$smarty.session.hruid}">http://www.carva.org/{$smarty.session.hruid}</a>
-  sont redirigées sur <a href="http://{$carva}">http://{$carva}</a>
-{else}
-  La redirection n'est pas utilisée ...
-{/if}
-</p>
 
 <p>
-  Pour modifier cette redirection remplis le champ suivant et clique sur <strong>Valider</strong>.
+  Pour modifier ta redirection remplis le champ suivant et clique sur <strong>Valider</strong>.
 {if $carva}
   Si tu veux annuler ta redirection, clique sur <strong>Supprimer</strong>.
 {/if}
index 3d3d4fd..707fe01 100644 (file)
@@ -1,5 +1,5 @@
 create table watch (
-  uid   int(6) not null auto_increment,
+  uid   int(6) not null,
   flags set('contacts', 'mail') not null default 'contacts',
   last  timestamp not null default '0000-00-00',
 
diff --git a/upgrade/account/04_carva.sql b/upgrade/account/04_carva.sql
new file mode 100644 (file)
index 0000000..b583fc0
--- /dev/null
@@ -0,0 +1,8 @@
+create table carvas (
+  uid int(6) not null,
+  url varchar(255) not null,
+
+  primary key uid (uid)
+);
+
+# vim:set syntax=mysql:
index 0c87792..1b1d464 100644 (file)
@@ -28,6 +28,12 @@ insert into watch
      select user_id as uid, watch_flags as flags, watch_last as last
        from auth_user_quick;
 
+# Insert carvas
+insert into carvas
+     select user_id, redirecturl
+       from auth_user_quick
+      where LENGTH(redirecturl) > 0;
+
 # Insert all existing profiles
 insert into profiles
      select user_id AS pid, hruid AS hrpid, matricule AS xorg_id,