Adding jquery tooltip css globally
[PHPCredLocker.git] / lib / output.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<?php
/** Main HTML Output generation
*
* Copyright (C) 2012 B Tasker
* Released under GNU GPL V2
* See LICENSE
*
*/
 
defined('_CREDLOCK') or die;
 
 
 
class genOutput{
 
/** Will be overhauled at some point, will most likely move the actual page content into the template
*
*/
function genDefaultPage(){
global $notifications;
$notifications->setPageTitle("Home");
 
$str = "<span class='basic-content default-page'>";
if (BTMain::getUser()->name){
 
$str .= 'Welcome to the cred handling system. Please use the menus to proceed';
 
}else{
 
$str .= 'Please log-in to continue';
 
 
}
 
return $str . "</span>\n";
 
}
 
 
 
 
 
/** Call the relevant template
*
*/
function callTemplate(){
// Load the config so we know which template to call
 
$template = BTMain::getConf()->template;
require "templates/$template/index.php";
 
}
 
 
/** Load a view and return the output
*
* @arg view string
*/
function loadView($view){
 
ob_start;
$template = BTMain::getConf()->template;
$view = str_replace(".","/",$view);
        // Check for template level override
    if (file_exists("templates/". $template . "html/views/" . $view . ".php")){
        require "templates/". $template . "html/views/" . $view . ".php";
    }else{
        require "views/" . $view . ".php";
 
    }
return ob_get_clean();
}
 
 
/** Output the Breadcrumbs
*
*/
function BreadCrumbs(){
?>
<ul class="breadcrumb">
 <li>
    <a href="index.php">Home</a>
 </li>
<?php foreach ($GLOBALS['BREADCRUMB'] as $crumb){?>
 <li>
  <span class="divider">/</span>
    <a href="<?php echo $crumb['url']; ?>"><?php echo $crumb['name']; ?></a> 
</li>
  
 
<?php }?>
 
</ul>
<?php
 
}
 
 
 
/** Generate the HTML for any relevant Notifications
*
*/
function Notifications(){
 
global $notifications;
$nots = $notifications->getNotifications();
 
  if ($notifications){
  
      foreach ($nots as $not){
      $id='';
 
          if (!empty($not->id)){
          $id = " id='{$not->id}'";
          }
 
      $str[] = "<div class='{$not->className}'$id>{$not->text}</div>";
 
      }
 
 
  }
 
return implode("\n",$str);
 
}
 
 
 
/** Push the required headers
*
*/
function headContents(){
 
global $notifications;
$page = $notifications->getPageInfo();
$conf = BTMain::getConf();
?>
      <title><?php echo $conf->ProgName;?> - <?php echo htmlentities($page->title);?></title>
      <link rel="stylesheet" type="text/css" href="Resources/jquery.tooltip<?php echo $conf->JSMinName;?>.css" />
      <link rel="stylesheet" type="text/css" href="Resources/bootstrap/css/bootstrap<?php echo $conf->JSMinName;?>.css" />
      <link rel="stylesheet" type="text/css" href="Resources/bootstrap/css/bootstrap-responsive<?php echo $conf->JSMinName;?>.css" />
 
 
    <?php foreach ($page->css as $css):?>
            <link rel="stylesheet" type="text/css" href='Resources/<?php echo $css;?>.css'/>
    <?php endforeach;?>
 
      <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
      <script type="text/javascript" src="Resources/bootstrap/js/bootstrap<?php echo $conf->JSMinName;?>.js"></script>
      <script type="text/javascript" src="Resources/jquery.tooltip.min.js"></script>
      <script id='kFile' src="Resources/info.php?<?php echo md5(session_id().$_SERVER['REMOTE_ADDR']); ?>" type="text/javascript"></script>
      <script src="Resources/main<?php echo $conf->JSMinName;?>.js" type="text/javascript"></script>
      <script src="Resources/base64<?php echo $conf->JSMinName;?>.js" type="text/javascript"></script>
 
    <?php foreach ($page->reqscripts as $script):?>
      <script src="Resources/<?php echo $script;?><?php echo $conf->JSMinName;?>.js" type="text/javascript"></script>
    <?php endforeach;  if (!empty($page->custJS[0])):?>
 
      <script type="text/javascript">
      <?php echo implode("\n",$page->custJS);?>
      </script>
 
    <?php endif; ?>
 
<!-- Fire the default scripts when the browser reports document ready -->
    <script type="text/javascript">
    var sesscheck; jQuery(document).ready(function() {  checkKeyAvailable(); 
    <?php if (BTMain::getUser()->name):?>sesscheck = setInterval("checkSession()",120000);<?php endif;?>});
    </script>
 
<?php
}
 
 
 
 
/** Load a module by name
*
* @arg module - string
*
*/
function loadModule($module){
 
$template = BTMain::getConf()->template;
 
 
        // Check for template override
            if (file_exists("templates/$template/html/modules/$module/$module.php")){
                require "templates/$template/html/modules/$module/$module.php";
            }else{
                require "modules/$module/$module.php";
            }
 
 
 
}
 
 
 
 
}/** Gen Output Class Ends **/
 
 
 
 
 
 
 
 
/**                     Notifications class                                    **/
class notifications{
 
 
 
 
/** Return an object containing any notification items that have been set (or at least those suited for embedding in the head)
*
* @return object
*
*/
function getPageInfo(){
 
$page->title = '';
$page->css = array();
$page->reqscripts = array();
$page->custJS = array();
 
  if (isset($this->pagetitle)){
  $page->title = $this->pagetitle;
  }
 
  if (is_array($this->css)){
  $page->css = $this->css;
  }
 
  if (is_array($this->requiredscripts)){
  $page->reqscripts = $this->requiredscripts;
  }
 
  if (is_array($this->customJS)){
  $page->custJS = $this->customJS;
  }
 
return $page;
}
 
 
/** Set the page title
*
* @arg title
*
*/
function setPageTitle($title){
$this->pagetitle = $title;
}
 
 
 
/** Get any notifications that have been triggered
*
* @return object (or false if no notifications)
*
*/
function getNotifications(){
 
$notif = BTMain::getVar('notif');
$triggernotifs = is_array($this->notifications);
 
 
// Check whether there are any notifications to push
if (!$notif && !$triggernotifs){
return false;
}
 
 
$nots = new stdClass();
include 'conf/notifications.php';
 
// Check for notifications triggered by views
if ($triggernotifs){
 
    foreach ($this->notifications as $msg){
        $nots->$msg = $notifs->$msg;
      }
 
  }
 
 
// Check for notifications triggered by the request
if ($notif){
  $nots->$notif = $notifs->$notif;
  }
 
 
return $nots;
}
 
 
/** Set a notification to display when getNotifications is called
*
* @arg notification - string containing notification name
*
*/
function setNotification($notification){
$this->notifications[] = $notification;
}
 
 
/** Trigger the inclusion of a CSS file in the document head
*
* @arg file - filename (Will be automatically prefixed with Resources/ and appended with .css)
*
*/
function RequireCSS($file){
$this->css[] = $file;
}
 
 
/** Trigger the inclusion of a JS file in the document head
*
* @arg file - filename (Will be automatically prefixed with Resources/ and appended with .js)
*
*/
function RequireScript($script){
$this->requiredscripts[] = $script;
}
 
 
/** Set the breadcrumb path
*
* @arg path - array
*
* Exact schema of the array is dictated by class genOutput but at time of writing, 
* each breadcrumb item should be an array containing elements name and url
*
*/
function setBreadcrumb($path){
 
$GLOBALS['BREADCRUMB'] = $path;
 
}
 
 
/** Embed a JS string into the document head, will automatically be placed between script tags
*
* @arg js - string
*
*/
function setCustomJS($js){
$this->customJS[] = "$js";
}
 
 
}
 
 
 
 
 
?>