Happy 2009! Updating copyright years.
[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 . '/Template.php';
31 BSTemplate::$dbCacheTable = TABLE_PREFIX . 'template';
32 BSTemplate::$templatePath = 'admin/templates/%s.html';
33
34 $globaltemplates = array(
35 'doctype',
36 'nav',
37 'headinclude',
38 'footer',
39 );
40
41 $start = microtime();
42 BSTemplate::cache(array_merge($globaltemplates, (array)$fetchtemplates));
43 BSApp::debug('time for tpl cache: ' . BSFunctions::fetch_microtime_diff($start));
44
45 BSTemplate::$globalVars = array(
46 'templates' => array(
47 'doctype' => BSTemplate::fetch('doctype')->evaluate()->getTemplate(),
48 'nav' => BSTemplate::fetch('nav')->evaluate()->getTemplate(),
49 'headinclude' => BSTemplate::fetch('headinclude')->evaluate()->getTemplate(),
50 'title' => T('Bugdar Administration')
51 )
52 );
53
54 // ###################################################################
55
56 function admin_footer()
57 {
58 return BSTemplate::fetch('footer')->evaluate()->getTemplate();
59 }
60
61 function admin_login()
62 {
63 BSTemplate::fetch('login')->evaluate()->flush();
64 exit;
65 }
66
67 // ###################################################################
68
69 if (can_perform('canadminpanel'))
70 {
71 $session = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "adminsession WHERE sessionid = '" . $input->inputEscape(COOKIE_PREFIX . 'adminsession') . "'");
72 if ($session AND $session['userid'] == bugdar::$userinfo['userid'] AND $session['dateline'] >= (TIMENOW - 3600))
73 {
74 // renew the cookie
75 BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', $session['sessionid'], false);
76 }
77 else
78 {
79 BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', false);
80 admin_login();
81 }
82 }
83 else
84 {
85 BSFunctions::cookie(COOKIE_PREFIX . 'adminsession', false);
86 admin_login();
87 }
88
89 // ###################################################################
90
91 // ###################################################################
92 /**
93 * Callback function for the Pagination->BitProcessor()
94 *
95 * @param string Base link
96 * @param bool Do not show this as a link
97 * @param integer Page number
98 * @param object Page navigator framework
99 *
100 * @return string Processed HTML
101 */
102 function AdminPageNavigatorBitCallback($baselink, $nolink, $number, $paginator)
103 {
104 if ($nolink)
105 {
106 return '<strong>' . $number . '</strong>' . "\n";
107 }
108 else
109 {
110 return '<a href="' . $baselink . 'p=' . $number . '&amp;pp=' . $paginator->getPerPage() . '">' . $number . '</a>' . "\n";
111 }
112 }
113
114 // ###################################################################
115 /**
116 * Callback function for the Pagination->NavigatorProcessor()
117 *
118 * @param string Base URL
119 * @param integer Next page number
120 * @param integer Previous page number
121 * @param array Show information
122 * @param string Individual page bits
123 * @param object Page navigator framework
124 *
125 * @return string Processed HTML
126 */
127 function AdminPageNavigatorCallback($baselink, $nextpage, $prevpage, $show, $pagebits, $paginator)
128 {
129 global $stylevar;
130
131 $return = '';
132
133 if ($show['first'])
134 {
135 $return .= '<a href="' . $baselink . 'p=1&amp;pp=' . $paginator->getPerPage() . '">' . T('First') . '</a> ...';
136 }
137 if ($show['prev'])
138 {
139 $return .= '<a href="' . $baselink . 'p=' . $prevpage . '&amp;pp=' . $paginator->getPerPage() . '">' . T('Prev') . '</a> ...';
140 }
141
142 $return .= $pagebits;
143
144 if ($show['next'])
145 {
146 $return .= '... <a href="' . $baselink . 'p=' . $nextpage . '&amp;pp=' . $paginator->getPerPage() . '">' . T('Next') . '</a>';
147 }
148 if ($show['last'])
149 {
150 $return .= '... <a href="' . $baselink . 'p=' . $paginator->getPageCount() . '&amp;pp=' . $paginator->getPerPage() . '">' . T('Last') . '</a>';
151 }
152 return '<div style="margin-top: 15px; float: ' . $stylevar['right'] . '">' . $return . '</div>';
153 }
154
155 ?>