admin/emails/broken: Sort lines of the produced CSV
[platal.git] / htdocs / webredirect.php
index 9bae428..8ba42f9 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2004 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 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);
-$page->assign('xorg_title','Polytechnique.org - Redirection de page WEB');
+require_once 'xorg.inc.php';
 
-$log =& Session::getMixed('log');
-$url = Env::get('url');
+$platal = new Xorg('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');
-    } else {
-        $page->trig('Erreur de suppression');
+global $globals;
+$path = ltrim($platal->pl_self(), '/');
+@list($username, $path) = explode('/', $path, 2);
+
+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");
+        }
     }
 }
 
-
-$res = $globals->xdb->query('SELECT redirecturl FROM auth_user_quick WHERE user_id = {?}', Session::getInt('uid'));
-$page->assign('carva', $res->fetchOneCell());
-
-$page->run();
+header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
+?>
+<!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 fenc=utf-8:
 ?>