1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if (!defined('BASEPATH')) { |
4
|
|
|
exit('No direct script access allowed'); |
5
|
|
|
} |
6
|
|
|
/** |
7
|
|
|
* Java Script helper |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Show Roar message |
12
|
|
|
* |
13
|
|
|
* @param string $message |
14
|
|
|
* @param string|boolean $title |
15
|
|
|
* @param string $class |
16
|
|
|
* @param boolean $ret |
17
|
|
|
* @param bool $timeout |
18
|
|
|
* @return null|string |
19
|
|
|
*/ |
20
|
|
|
function showMessage($message, $title = FALSE, $class = '', $ret = false, $timeout = false) { |
21
|
|
|
$del = [ |
22
|
|
|
"'", |
23
|
|
|
'"', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
$message = str_replace($del, '', $message); |
27
|
|
|
$title = str_replace($del, '', $title); |
28
|
|
|
|
29
|
|
|
if ($title == FALSE) { |
30
|
|
|
$title = lang('Message') . ': '; |
31
|
|
|
if ($class == 'r') { |
32
|
|
|
$title = lang('Error') . ': '; |
33
|
|
|
} |
34
|
|
|
if ($class == 'g') { |
35
|
|
|
$title = lang('Success') . ': '; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
$CI = &get_instance(); |
39
|
|
|
$message .= '<br/><strong>' . lang('Requests to the database') . ': ' . $CI->db->total_queries() . '</strong>'; |
40
|
|
|
|
41
|
|
|
$message = str_replace(["\n", '<p>', '</p>'], ['<br/>', '', ''], $message); |
42
|
|
|
$title = str_replace(["\n", '<p>', '</p>'], ['<br/>', '', ''], $title); |
43
|
|
|
|
44
|
|
|
if (!$ret) { |
45
|
|
|
echo "<script type=\"text/javascript\"> showMessage('" . $title . "','" . $message . "','" . $class . "'); </script>"; |
46
|
|
|
} elseif (!$timeout) { |
47
|
|
|
return "<script type=\"text/javascript\"> showMessage('" . $title . "','" . $message . "','" . $class . "'); </script>"; |
48
|
|
|
} else { |
49
|
|
|
return "<script> setTimeout(function(){showMessage('" . $title . "','" . $message . "','" . $class . "');}, 300) </script>"; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
* @param string $url |
56
|
|
|
* @param string $selector |
57
|
|
|
*/ |
58
|
|
|
function pjax($url, $selector = '#mainContent') { |
59
|
|
|
echo '<script>$.pjax({url: "' . $url . '", container:"' . $selector . '"}); </script>'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Redirect function |
64
|
|
|
* @param string $location |
65
|
|
|
*/ |
66
|
|
|
function ajax_redirect($location) { |
67
|
|
|
echo lang('Redirecting') . ': <b>' . $location . '</b> ' . "<script type='text/javascript'> setTimeout(\"location.href = '" . $location . "';\",50); </script>"; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Load content to DIV |
72
|
|
|
* @param string $div_id |
73
|
|
|
* @param string $url |
74
|
|
|
*/ |
75
|
|
|
function updateDiv($div_id, $url) { |
76
|
|
|
echo "<script type=\"text/javascript\"> ajax_div('" . $div_id . "','" . $url . "'); </script>"; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Same function as above but with other name ;) |
81
|
|
|
* @param string $div_id |
82
|
|
|
* @param string $url |
83
|
|
|
*/ |
84
|
|
|
function ajax_div($div_id, $url) { |
85
|
|
|
updateDiv($div_id, $url); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Execute java script code |
90
|
|
|
* @param string $code |
91
|
|
|
*/ |
92
|
|
|
function jsCode($code) { |
93
|
|
|
|
94
|
|
|
echo '<script type="text/javascript"> ' . $code . ' </script>'; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if (!function_exists('checkAjaxRequest')) { |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return bool |
101
|
|
|
*/ |
102
|
|
|
function checkAjaxRequest() { |
103
|
|
|
$CI = &get_instance(); |
104
|
|
|
if ($CI->input->server('HTTP_X_REQUESTED_WITH') != 'XMLHttpRequest') { |
|
|
|
|
105
|
|
|
return false; |
106
|
|
|
} else { |
107
|
|
|
return true; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/* End of javascript helper */ |