Html::displayMessageAfterRedirect PHP Method

displayMessageAfterRedirect() static public method

Display a div containing messages set in session in the previous page
static public displayMessageAfterRedirect ( )
    static function displayMessageAfterRedirect()
    {
        // Affichage du message apres redirection
        if (isset($_SESSION["MESSAGE_AFTER_REDIRECT"]) && count($_SESSION["MESSAGE_AFTER_REDIRECT"]) > 0) {
            foreach ($_SESSION['MESSAGE_AFTER_REDIRECT'] as $msgtype => $messages) {
                //get messages
                if (count($messages) > 0) {
                    $html_messages = implode('<br/>', $messages);
                } else {
                    continue;
                }
                //set title and css class
                switch ($msgtype) {
                    case ERROR:
                        $title = __('Error');
                        $class = 'err_msg';
                        break;
                    case WARNING:
                        $title = __('Warning');
                        $class = 'warn_msg';
                        break;
                    case INFO:
                        $title = __('Information');
                        $class = 'info_msg';
                        break;
                }
                echo "<div id=\"message_after_redirect_{$msgtype}\" title=\"{$title}\">";
                echo $html_messages;
                echo "</div>";
                $scriptblock = "\n               \$(document).ready(function() {\n                  var _of = window;\n                  var _at = 'right-20 bottom-20';\n                  //calculate relative dialog position\n                  \$('.message_after_redirect').each(function() {\n                     var _this = \$(this);\n                     if (_this.attr('aria-describedby') != 'message_after_redirect_{$msgtype}') {\n                        _of = _this;\n                        _at = 'right top-' + (10 + _this.outerHeight());\n                     }\n                  });\n\n                  \$('#message_after_redirect_{$msgtype}').dialog({\n                     dialogClass: 'message_after_redirect {$class}',\n                     minHeight: 40,\n                     minWidth: 200,\n                     position: {\n                        my: 'right bottom',\n                        at: _at,\n                        of: _of,\n                        collision: 'none'\n                     },\n                     autoOpen: false,\n                     show: {\n                       effect: 'slide',\n                       direction: 'down',\n                       'duration': 800\n                     }\n                  })\n                  .dialog('open');";
                //do not autoclose errors
                if ($msgtype != ERROR) {
                    $scriptblock .= "\n\n                  // close dialog on outside click\n                  \$(document.body).on('click', function(e){\n                     if (\$('#message_after_redirect_{$msgtype}').dialog('isOpen')\n                         && !\$(e.target).is('.ui-dialog, a')\n                         && !\$(e.target).closest('.ui-dialog').length) {\n                        \$('#message_after_redirect_{$msgtype}').dialog('close');\n                        // redo focus on initial element\n                        e.target.focus();\n                     }\n                  });";
                }
                $scriptblock .= "\n\n               });\n            ";
                echo Html::scriptBlock($scriptblock);
            }
        }
        // Clean message
        $_SESSION["MESSAGE_AFTER_REDIRECT"] = [];
    }

Usage Example

コード例 #1
0
ファイル: user.class.php プロジェクト: geldarr/hack-space
 /**
  * @param $input
  **/
 function updateForgottenPassword($input)
 {
     global $CFG_GLPI;
     echo "<div class='center'>";
     if ($this->getFromDBbyEmail($input['email'], "`glpi_users`.`is_active` AND NOT `glpi_users`.`is_deleted`")) {
         if ($this->fields["authtype"] == Auth::DB_GLPI || !Auth::useAuthExt()) {
             if ($input['password_forget_token'] == $this->fields['password_forget_token'] && abs(strtotime($_SESSION["glpi_currenttime"]) - strtotime($this->fields['password_forget_token_date'])) < DAY_TIMESTAMP) {
                 $input['id'] = $this->fields['id'];
                 if (Config::validatePassword($input["password"]) && $this->update($input)) {
                     _e('Reset password successful.');
                     //
                     $input2['password_forget_token'] = '';
                     $input2['password_forget_token_date'] = NULL;
                     $input2['id'] = $this->fields['id'];
                     $this->update($input2);
                 } else {
                     // Force display on error
                     Html::displayMessageAfterRedirect();
                 }
             } else {
                 _e('Your password reset request has expired or is invalid. Please renew it.');
             }
         } else {
             _e("The authentication method configuration doesn't allow you to change your password.");
         }
     } else {
         _e('Email address not found.');
     }
     echo "<br>";
     echo "<a href='" . $CFG_GLPI['root_doc'] . "'>" . __('Back') . "</a>";
     echo "</div>";
 }
All Usage Examples Of Html::displayMessageAfterRedirect
Html