{site}.inc.php is the base for all jobs.
[platal.git] / htdocs / webredirect.php
index 9bff9b5..0de8baa 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require_once("xorg.inc.php");
-new_skinned_page('webredirect.tpl', AUTH_MDP);
+require_once 'xorg.inc.php';
 
-$log =& Session::getMixed('log');
-$url = Env::get('url');
+new Platal('core');
 
-if ((Env::get('submit') == 'Valider' or Env::get('submit') == 'Modifier') and Env::has('url')) {
-    if ($globals->xdb->execute('UPDATE auth_user_quick SET redirecturl = {?} WHERE user_id = {?}',
-                $url, Session::getInt('uid')))
-    {
-        $log->log('carva_add', 'http://'.Env::get('url'));
-        $page->trig("Redirection activée vers <a href='http://$url'>$url</a>");
-    } else {
-        $page->trig('Erreur de mise à jour');
-    }
-} elseif (Env::get('submit') == "Supprimer") {
-    if ($globals->xdb->execute("UPDATE auth_user_quick SET redirecturl = '' WHERE user_id = {?}", Session::getInt('uid')))
-    {
-        $log->log("carva_del", $url);
-        Post::kill('url');
-        $page->trig('Redirection supprimée');
+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);
+
+if ($url = $res->fetchOneCell()) {
+    $url = preg_replace('@/+$@', '', $url);
+    if ($path) {
+        http_redirect("http://$url/$path");
     } else {
-        $page->trig('Erreur de suppression');
+        http_redirect("http://$url");
     }
 }
 
+header("HTTP/1.0 404 Not Found");
 
-$res = $globals->xdb->query('SELECT redirecturl FROM auth_user_quick WHERE user_id = {?}', Session::getInt('uid'));
-$page->assign('carva', $res->fetchOneCell());
-
-$page->run();
+?>
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<html>
+  <head>
+    <title>404 Not Found</title>
+  </head>
+  <body>
+    <h1>Not Found</h1>
+    The requested URL <?php echo $_SERVER['REQUEST_URI'] ?> was not found on this server.<p>
+    <hr>
+    <address>Apache Server at www.carva.org Port 80</address>
+  </body>
+</html>
+<?php
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>