YaWK  24.1
Yet another WebKit
alert.php
Go to the documentation of this file.
1 <?php
2 namespace YAWK {
3  /**
4  *
5  * @author Daniel Retzl <[email protected]>
6  * @copyright 2009-2015 Daniel Retzl www.yawk.io
7  * @license https://opensource.org/licenses/MIT
8  * @brief Throws a fancy Bootstrap Alert (success, info, warning or danger)
9  * @details Throw default bootstrap-powered alerts. (warning, succes etc...)
10  * This lets you throw an alert message box at any time, anywhere in your script.
11  * Alert uses 5 Arguments, as shown below. Example: any place of your script where
12  * an error, info, success or danger Message needs to be thrown.
13  * <p><i>Class covers both, backend & frontend functionality.
14  * See Methods Summary for Details!</i></p>
15  *
16  */
17 
18  class alert
19  {
20  /**
21  * @brief draw a fancy alert notification
22  * @param string $type Bootstrap class: success, warning, danger, info or default
23  * @param string $title Title of the notification box, drawn in h4
24  * @param string $text The Message Text of your notification. You can use HTML tags to format it.
25  * @param string $redirect URL to redirect the user via setTimeOut delay(ms). Leave empty if you just want to put on a message, but dont want to redirect the user.
26  * @param int $delay How long should the notification stay on top before it hides respectively redirect. Leave empty if it should stay on top forevermore.
27  * @example <?php YAWK\alert::draw("success", "Yey!", "Test Alert thrown! It worked!", "index.html", 5000); ?>
28  *
29  */
30  static function draw($type, $title, $text, $redirect, $delay)
31  {
32 
33  // default animation when alert pops in
34  $animatedEnter = "animated fadeInDown";
35  // default animation when alert pops out
36  $animatedExit = "animated fadeOutUp";
37  // default placementFrom (top, bottom)
38  $placementFrom = "top";
39  // default placementFrom (left, center, right)
40  $placementAlign = "center";
41  // any URL to link to
42  $url = "";
43  // URL target
44  $urlTarget = "_blank";
45  // should it be allowed to dismiss this alert?
46  $allowDismiss = "true";
47  // display newest on top if there are more simultaneous alerts?
48  $newestOnTop = "false";
49  // display a progressbar to show how long the alert will stay
50  $progressBar = "false";
51  // offest X axis
52  $offsetX = "10";
53  // offest Y axis
54  $offsetY = "62";
55  // spacing
56  $spacing = "10";
57  // z-index
58  $zIndex = "9999";
59  // icon
60  $icon = "fa fa-info-circle";
61 
62  if (!isset($type) || (empty($type)))
63  {
64  $type = "info";
65  }
66  if (!isset($title) || (empty($title)))
67  {
68  $title = "";
69  }
70  if (!isset($text) || (empty($text)))
71  {
72  $text = "";
73  }
74  if (!isset($redirect) || (empty($redirect)))
75  {
76  $redirect = "";
77  }
78  if (!isset($delay) || (empty($delay)))
79  {
80  $delay = 0;
81  }
82 
83  if (empty($type)) { $type="danger"; }
84  if (empty($title)) { $title="ERROR!"; }
85  if (empty($text)) { $text="Something strange has happened. Text is empty. Sorry that there is no more Information available. (Code 0)"; }
86  if (empty($redirect)) { $redirect="null"; }
87  if (empty($delay)) { $delay="null"; }
88 
89  if ($redirect === "null" && ($delay !== "null"))
90  {
91  $n_delay = $delay;
92  }
93  else {
94  // calculate delay time for notify before redirect
95  $n_delay = $delay;
96  if (is_int($n_delay)){
97  $n_delay = $n_delay / 3;
98  $n_delay = round($n_delay);
99  }
100  }
101 
102  if ($delay === "null")
103  {
104  $n_delay = "null";
105  }
106 
107  // switch icon
108  switch ($type)
109  {
110  case "danger":
111  $icon = "fa fa-exclamation-triangle";
112  break;
113  case "warning":
114  $icon = "fa fa-flash";
115  break;
116  case "success":
117  $icon = "fa fa-check-circle-o";
118  break;
119  case "tipofday":
120  $icon = "fa fa-lightbulb-o";
121  $type = "success";
122  $animatedEnter = "animated fadeInRight";
123  $animatedExit = "animated fadeOutRight";
124  $placementFrom = "top";
125  $placementAlign = "right";
126  break;
127  default:
128  $icon = "fa fa-info-circle";
129  break;
130  }
131 
132  // run notify javascript
133  echo "
134  <script type=\"text/javascript\">
135  $.notify({
136  // options
137  title: '<h4><i class=\"$icon\"></i>&nbsp; $title</h4>',
138  message: '$text',
139  url: '$url',
140  target: '$urlTarget'
141  }, {
142  // settings
143  type: '$type',
144  element: 'body',
145  position: null,
146  allow_dismiss: '$allowDismiss',
147  newest_on_top: '$newestOnTop',
148  showProgressbar: $progressBar,
149  placement: {
150  from: '$placementFrom',
151  align: '$placementAlign'
152  },
153  offset: {
154  x: $offsetX,
155  y: $offsetY
156  },
157  spacing: $spacing,
158  z_index: $zIndex,
159  delay: '$n_delay',
160  timer: 420,
161  url_target: '$urlTarget',
162  mouse_over: 'pause',
163  animate: {
164  enter: '$animatedEnter',
165  exit: '$animatedExit'
166  }
167  });
168  </script>";
169 
170  if ($redirect !== "null" && ($delay !== "null"))
171  {
172  // redirect after notify with given delay param
173  return \YAWK\sys::setTimeout("index.php?$redirect", $delay);
174  }
175  else
176  {
177  return null;
178  }
179  } // ./draw
180  } // ./class alert
181 } // ./namespace
$offsetY
Definition: actions.php:19
$offsetX
Definition: actions.php:18
Throws a fancy Bootstrap Alert (success, info, warning or danger)
Definition: alert.php:19
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
$type
This class serves methods to create backup from files.
Definition: AdminLTE.php:2
$redirect
$url
Definition: user-new.php:101