Templatize admin/settings.php
[bugdar.git] / admin / global.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 chdir('./../');
23
24 require_once('./includes/init.php');
25 require_once('./includes/functions.php');
26
27 // ###################################################################
28 // setup admin templates
29
30 require_once ISSO . '/DecoratorHelpers.php';
31
32 require_once ISSO . '/Template.php';
33 BSTemplate::$dbCacheTable = TABLE_PREFIX . 'template';
34 BSTemplate::$templatePath = 'admin/templates/%s.html';
35
36 $globaltemplates = array(
37 'doctype',
38 'nav',
39 'headinclude',
40 'footer',
41 );
42
43 $start = microtime();
44 BSTemplate::cache(array_merge($globaltemplates, (array)$fetchtemplates));
45 BSApp::debug('time for tpl cache: ' . BSFunctions::fetch_microtime_diff($start));
46
47 BSTemplate::$globalVars = array(
48 'templates' => array(
49 'doctype' => BSTemplate::fetch('doctype')->evaluate()->getTemplate(),
50 'nav' => BSTemplate::fetch('nav')->evaluate()->getTemplate(),
51 'headinclude' => BSTemplate::fetch('headinclude')->evaluate()->getTemplate(),
52 'title' => T('Bugdar Administration')
53 )
54 );
55
56 // ###################################################################
57
58 function admin_footer()
59 {
60 return BSTemplate::fetch('footer')->evaluate()->getTemplate();
61 }
62
63 function admin_login()
64 {
65 BSTemplate::fetch('login')->evaluate()->flush();
66 exit;
67 }
68
69 // ###################################################################
70
71 if (can_perform('canadminpanel'))
72 {
73 $session = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "adminsession WHERE sessionid = '" . $input->inputEscape(COOKIE_PREFIX . 'adminsession') . "'");
74 if ($session AND $session['userid'] == bugdar::$userinfo['userid'] AND $session['dateline'] >= (TIMENOW - 3600))
75 {
76 // renew the cookie
77 BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', $session['sessionid'], false);
78 }
79 else
80 {
81 BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', false);
82 admin_login();
83 }
84 }
85 else
86 {
87 BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', false);
88 admin_login();
89 }
90
91 // ###################################################################
92
93 // ###################################################################
94 /**
95 * Callback function for the Pagination->BitProcessor()
96 *
97 * @param string Base link
98 * @param bool Do not show this as a link
99 * @param integer Page number
100 * @param object Page navigator framework
101 *
102 * @return string Processed HTML
103 */
104 function AdminPageNavigatorBitCallback($baselink, $nolink, $number, $paginator)
105 {
106 if ($nolink)
107 {
108 return '<strong>' . $number . '</strong>' . "\n";
109 }
110 else
111 {
112 return '<a href="' . $baselink . 'p=' . $number . '&amp;pp=' . $paginator->getPerPage() . '">' . $number . '</a>' . "\n";
113 }
114 }
115
116 // ###################################################################
117 /**
118 * Callback function for the Pagination->NavigatorProcessor()
119 *
120 * @param string Base URL
121 * @param integer Next page number
122 * @param integer Previous page number
123 * @param array Show information
124 * @param string Individual page bits
125 * @param object Page navigator framework
126 *
127 * @return string Processed HTML
128 */
129 function AdminPageNavigatorCallback($baselink, $nextpage, $prevpage, $show, $pagebits, $paginator)
130 {
131 global $stylevar;
132
133 $return = '';
134
135 if ($show['first'])
136 {
137 $return .= '<a href="' . $baselink . 'p=1&amp;pp=' . $paginator->getPerPage() . '">' . T('First') . '</a> ...';
138 }
139 if ($show['prev'])
140 {
141 $return .= '<a href="' . $baselink . 'p=' . $prevpage . '&amp;pp=' . $paginator->getPerPage() . '">' . T('Prev') . '</a> ...';
142 }
143
144 $return .= $pagebits;
145
146 if ($show['next'])
147 {
148 $return .= '... <a href="' . $baselink . 'p=' . $nextpage . '&amp;pp=' . $paginator->getPerPage() . '">' . T('Next') . '</a>';
149 }
150 if ($show['last'])
151 {
152 $return .= '... <a href="' . $baselink . 'p=' . $paginator->getPageCount() . '&amp;pp=' . $paginator->getPerPage() . '">' . T('Last') . '</a>';
153 }
154 return '<div style="margin-top: 15px; float: ' . $stylevar['right'] . '">' . $return . '</div>';
155 }
156
157 ?>