forked from AppStateESS/properties
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
120 lines (104 loc) · 3.69 KB
/
Module.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
<?php
/**
* @author Matthew McNaney <mcnaneym at appstate dot edu>
*/
namespace properties;
use properties\Factory\NavBar;
require_once PHPWS_SOURCE_DIR . 'src/Module.php';
require_once PHPWS_SOURCE_DIR . 'mod/properties/conf/system_defines.php';
require_once PHPWS_SOURCE_DIR . 'mod/properties/conf/defines.php';
class Module extends \Canopy\Module implements \Canopy\SettingDefaults
{
public function __construct()
{
parent::__construct();
$this->setTitle('properties');
$this->setProperName('Properties');
spl_autoload_register('\properties\Module::autoloader', true, true);
}
public function getSettingDefaults()
{
$settings['approval_email'] = '';
$settings['our_email'] = '';
$settings['our_phone'] = null;
$settings['our_name'] = null;
$settings['front_buttons'] = 1;
$settings['property_timeout'] = time() - 86400;
$settings['sublease_timeout'] = time() - 86400;
$settings['roommate_timeout'] = time() - 86400;
return $settings;
}
public function getController(\Canopy\Request $request)
{
try {
$controller = new Controller\Controller($this, $request);
return $controller;
} catch (\Exception $e) {
if (PROPERTIES_FRIENDLY_ERRORS && $request->isGet() && !$request->isAjax()) {
return $this->friendlyController();
}
throw $e;
}
}
private function friendlyController()
{
$error_controller = new Controller\FriendlyError($this);
return $error_controller;
}
public function afterRun(\Canopy\Request $request,
\Canopy\Response $response)
{
if ($request->isGet() && !$request->isAjax()) {
\properties\Factory\NavBar::view($request);
}
}
public function runTime(\Canopy\Request $request)
{
if ($request->isGet() && !$request->isAjax()) {
if (\phpws\PHPWS_Core::atHome() && \phpws2\Settings::get('properties', 'front_buttons')) {
\Layout::add($this->home());
}
if (!preg_match('/^properties/', \Canopy\Server::getCurrentUrl())) {
if (!\Current_User::isLogged()) {
$auth = \Current_User::getAuthorization();
if (!empty($auth->login_link)) {
$url = $auth->login_link;
} else {
$url = 'index.php?module=users&action=user&command=login_page';
}
NavBar::addItem("<a href='$url'>Student Sign in</a>");
NavBar::addDivider();
NavBar::addItem('<a href="properties/Manager/signin">Manager Sign in</a>');
}
\properties\Factory\NavBar::view($request);
}
}
}
public static function autoloader($class_name)
{
static $not_found = array();
if (strpos($class_name, 'properties') !== 0) {
return;
}
if (isset($not_found[$class_name])) {
return;
}
$class_array = explode('\\', $class_name);
array_shift($class_array);
$class_dir = implode('/', $class_array);
$class_path = PHPWS_SOURCE_DIR . 'mod/properties/class/' . $class_dir . '.php';
if (is_file($class_path)) {
require_once $class_path;
return true;
} else {
$not_found[] = $class_name;
return false;
}
}
public function home()
{
$template = new \phpws2\Template();
$template->setModuleTemplate('properties', 'home.html');
return $template->get();
}
}