forked from AppStateESS/InternshipInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
121 lines (98 loc) · 3.43 KB
/
index.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
<?php
namespace Intern;
/**
* @author Micah Carter <mcarter at tux dot appstate dot edu>
*/
// Make sure the source directory is defined
if (!defined('PHPWS_SOURCE_DIR')) {
include '../../config/core/404.html';
exit();
}
require_once(PHPWS_SOURCE_DIR . 'mod/intern/inc/defines.php');
// Check some permissions
if (!\Current_User::isLogged()) {
// Fix by replacing the Users module
\PHPWS_Core::reroute('../secure');
}
// This is wrong, but it'll have to do for now.
// TODO: some sort of command pattern
$content = null;
if(DEBUG){
$inventory = new InternshipInventory();
$inventory->handleRequest();
$content = $inventory->getContent();
}else{
try{
$inventory = new InternshipInventory();
$inventory->handleRequest();
$content = $inventory->getContent();
}catch(\Exception $e){
try{
\NQ::simple('intern', \Intern\UI\NotifyUI::ERROR, 'The Intern Inventory has experienced an error. The software engineers have been notified about this problem. We apologize for the inconvenience.');
$message = formatException($e);
emailError($message);
\NQ::close();
\Intern\UI\NotifyUI::display();
\PHPWS_Core::goBack();
}catch(Exception $e){
$message2 = formatException($e);
echo "The Intern Inventory has experienced a major internal error. Attempting to email an admin and then exit.";
$message = "Something terrible has happened, and the exception catch-all threw an exception.\n\nThe first exception was:\n\n$message\n\nThe second exception was:\n\n$message2";
mail('[email protected]', 'A Major Intern Inventory Error Has Occurred', $message);
exit();
}
}
}
/**
* Plug content into TopUI. Show notifications. Add Style.
*/
if (isset($content)) {
if ($content === false) {
\NQ::close();
\PHPWS_Core::reroute('index.php?module=intern');
}
}
// Add top menu bar to theme
\PHPWS_Core::initModClass('intern', 'UI/TopUI.php');
UI\TopUI::plug();
// Get Notifications, add to layout
$nv = new UI\NotifyUI();
$notifications = $nv->display();
\Layout::add($notifications);
// Add content to Layout
\Layout::addStyle('intern', 'style.css');
\Layout::add($content);
function formatException(\Exception $e)
{
ob_start();
echo "Ohes Noes! Intern Inventory threw an exception that was not caught!\n\n";
echo "Host: {$_SERVER['SERVER_NAME']}({$_SERVER['SERVER_ADDR']})\n";
echo 'Request time: ' . date("D M j G:i:s T Y", $_SERVER['REQUEST_TIME']) . "\n";
if(isset($_SERVER['HTTP_REFERER'])){
echo "Referrer: {$_SERVER['HTTP_REFERER']}\n";
}else{
echo "Referrer: (none)\n";
}
echo "Remote addr: {$_SERVER['REMOTE_ADDR']}\n\n";
$user = \Current_User::getUserObj();
if(isset($user) && !is_null($user)){
echo "User name: {$user->getUsername()}\n\n";
}else{
echo "User name: (none)\n\n";
}
echo "Here is the exception:\n\n";
print_r($e);
echo "\n\nHere is $_REQUEST:\n\n";
print_r($_REQUEST);
echo "\n\nHere is CurrentUser:\n\n";
print_r(\Current_User::getUserObj());
$message = ob_get_contents();
ob_end_clean();
return $message;
}
function emailError($message)
{
$to = array('[email protected]');
$tags = array('MESSAGE' => $message);
Email::sendTemplateMessage($to, 'Uncaught Exception', 'email/UncaughtException.tpl', $tags);
}