Toolbox::manageRedirect PHP Méthode

manageRedirect() static public méthode

Manage login redirection
static public manageRedirect ( $where )
$where string: where to redirect ?
    static function manageRedirect($where)
    {
        global $CFG_GLPI, $PLUGIN_HOOKS;
        if (!empty($where)) {
            if (isset($_SESSION["glpiactiveprofile"]["interface"]) && !empty($_SESSION["glpiactiveprofile"]["interface"])) {
                $decoded_where = rawurldecode($where);
                // redirect to URL : URL must be rawurlencoded
                if ($link = preg_match('/(https?:\\/\\/[^\\/]+)\\/.+/', $decoded_where, $matches)) {
                    if ($matches[1] !== $CFG_GLPI['url_base']) {
                        Session::addMessageAfterRedirect('Redirection failed');
                        if ($_SESSION["glpiactiveprofile"]["interface"] === "helpdesk") {
                            Html::redirect($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php");
                        } else {
                            Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php");
                        }
                    } else {
                        Html::redirect($decoded_where);
                    }
                }
                // Redirect based on GLPI_ROOT : URL must be rawurlencoded
                if ($decoded_where[0] == '/') {
                    // echo $decoded_where;exit();
                    Html::redirect($CFG_GLPI["root_doc"] . $decoded_where);
                }
                $data = explode("_", $where);
                $forcetab = '';
                // forcetab for simple items
                if (isset($data[2])) {
                    $forcetab = 'forcetab=' . $data[2];
                }
                switch ($_SESSION["glpiactiveprofile"]["interface"]) {
                    case "helpdesk":
                        switch (strtolower($data[0])) {
                            // Use for compatibility with old name
                            case "tracking":
                            case "ticket":
                                $data[0] = 'Ticket';
                                // redirect to item
                                if (isset($data[1]) && is_numeric($data[1]) && $data[1] > 0) {
                                    // Check entity
                                    if (($item = getItemForItemtype($data[0])) && $item->isEntityAssign()) {
                                        if ($item->getFromDB($data[1])) {
                                            if (!Session::haveAccessToEntity($item->getEntityID())) {
                                                Session::changeActiveEntities($item->getEntityID(), 1);
                                            }
                                        }
                                    }
                                    Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $data[1] . "&{$forcetab}");
                                } else {
                                    if (!empty($data[0])) {
                                        // redirect to list
                                        if ($item = getItemForItemtype($data[0])) {
                                            Html::redirect($item->getSearchURL() . "?{$forcetab}");
                                        }
                                    }
                                }
                                Html::redirect($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php");
                                break;
                            case "preference":
                                Html::redirect($CFG_GLPI["root_doc"] . "/front/preference.php?{$forcetab}");
                                break;
                            case "reservation":
                                Html::redirect($CFG_GLPI["root_doc"] . "/front/reservation.form.php?id=" . $data[1] . "&{$forcetab}");
                                break;
                            default:
                                Html::redirect($CFG_GLPI["root_doc"] . "/front/helpdesk.public.php");
                                break;
                        }
                        break;
                    case "central":
                        switch (strtolower($data[0])) {
                            case "preference":
                                Html::redirect($CFG_GLPI["root_doc"] . "/front/preference.php?{$forcetab}");
                                break;
                                // Use for compatibility with old name
                                // no break
                            // Use for compatibility with old name
                            // no break
                            case "tracking":
                                $data[0] = "Ticket";
                            default:
                                // redirect to item
                                if (!empty($data[0]) && isset($data[1]) && is_numeric($data[1]) && $data[1] > 0) {
                                    // Check entity
                                    if ($item = getItemForItemtype($data[0])) {
                                        if ($item->isEntityAssign()) {
                                            if ($item->getFromDB($data[1])) {
                                                if (!Session::haveAccessToEntity($item->getEntityID())) {
                                                    Session::changeActiveEntities($item->getEntityID(), 1);
                                                }
                                            }
                                        }
                                        Html::redirect($item->getFormURL() . "?id=" . $data[1] . "&{$forcetab}");
                                    }
                                } else {
                                    if (!empty($data[0])) {
                                        // redirect to list
                                        if ($item = getItemForItemtype($data[0])) {
                                            Html::redirect($item->getSearchURL() . "?{$forcetab}");
                                        }
                                    }
                                }
                                Html::redirect($CFG_GLPI["root_doc"] . "/front/central.php");
                                break;
                        }
                        break;
                }
            }
        }
    }

Usage Example

		<div id="logo_big" style="border-right: 1px solid #ccc; width:220px;" >
			<img src="pics/logo_big.png" alt="GLPI" class="logo2" />
		</div>      
      
      <div id="auth" style="background:#fff;">
      
        <form class="form-horizontal" style="margin-bottom: 0px !important;" action='front/login.php' method='post'>
			<?php 
// Other CAS
if (isset($_GET["noAUTO"])) {
    echo "<input type='hidden' name='noAUTO' value='1'/>";
}
// redirect to ticket
if (isset($_GET["redirect"])) {
    Toolbox::manageRedirect($_GET["redirect"]);
    echo '<input type="hidden" name="redirect" value="' . $_GET['redirect'] . '">';
}
?>
        
                
          <div class="content">
            <h4 class="title"><?php 
echo __('Authentication');
?>
</h4>
            <div class="form-group">
              <div class="col-sm-12">
                <div class="input-group"> <span class="input-group-addon"><i class="fa fa-user"></i></span>
                  <input class="form-control" name="login_name" id="login_name" required="required" placeholder="<?php 
echo __('Login');