-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathajaxIndex.php
188 lines (150 loc) · 5.02 KB
/
ajaxIndex.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
<?php
/*
* As a work of the United States government, this project is in the public domain within the United States.
*/
/*
Index for everything
Date: September 11, 2007
*/
use App\Leaf\XSSHelpers;
error_reporting(E_ERROR);
require_once getenv('APP_LIBS_PATH') . '/loaders/Leaf_autoloader.php';
//$settings = $oc_db->query_kv('SELECT * FROM settings', 'setting', 'data');
if (isset($settings['timeZone']))
{
date_default_timezone_set(XSSHelpers::xscrub($settings['timeZone']));
}
$oc_login->loginUser();
if ($oc_login)
{
}
$type = null;
switch ($_GET['categoryID']) {
case 1: // employee
$type = new Orgchart\Employee($oc_db, $oc_login);
break;
case 2: // position
$type = new Orgchart\Position($oc_db, $oc_login);
break;
case 3: // group
$type = new Orgchart\Group($oc_db, $oc_login);
break;
default:
return false;
}
$action = isset($_GET['a']) ? $_GET['a'] : '';
switch ($action) {
case 'doupload': // handle file upload
$uploadOk = true;
$uploadedFilename = '';
foreach ($_FILES as $file)
{
if ($file['error'] != UPLOAD_ERR_OK)
{
$uploadOk = false;
}
$uploadedFilename = $file['name'];
}
// wrap output in html for dojo
echo '<html><body><textarea>';
if ($uploadOk)
{
try
{
if ($type->modify($_GET['UID']))
{
echo "{$uploadedFilename} has been attached!";
}
else
{
echo 'File extension may not be supported.';
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
else
{
$errorCode = '';
switch ($file['error']) {
case UPLOAD_ERR_INI_SIZE:
$errorCode = 'The uploaded file exceeds the maximum server filesize limit.';
break;
case UPLOAD_ERR_FORM_SIZE:
$errorCode = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
break;
case UPLOAD_ERR_PARTIAL:
$errorCode = 'The uploaded file was only partially uploaded, please try again.';
break;
case UPLOAD_ERR_NO_FILE:
$errorCode = 'No file was selected to be attached.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$errorCode = 'Missing a temporary folder';
break;
case UPLOAD_ERR_CANT_WRITE:
$errorCode = 'Failed to write file to disk';
break;
case UPLOAD_ERR_EXTENSION:
$errorCode = 'File upload stopped by extension';
break;
default:
$errorCode = 'Unknown upload error';
break;
}
}
// wrap output in html for dojo
echo '</textarea></body></html>';
break;
case 'deleteattachment':
echo $type->deleteAttachment($_POST['categoryID'], $_POST['UID'], $_POST['indicatorID'], $_POST['file']);
break;
case 'gethistory':
$t_form = getSmarty();
$itemID = isset($_GET['itemID']) ? (int)$_GET['itemID'] : 0;
$tz = isset($_GET['tz']) ? $_GET['tz'] : null;
if($tz == null){
//$settings = $oc_db->query_kv('SELECT * FROM settings', 'setting', 'data');
if(isset($settings['timeZone']))
{
$tz = $settings['timeZone'];
}
else{
$tz = 'America/New_York';
}
}
if ($itemID != 0)
{
$resHistory = $type->getHistory($itemID);
$t_form->assign('dataType', $type->getDataTableDescription());
$t_form->assign('dataID', $itemID);
$t_form->assign('dataName', $type->getTitle($itemID));
$resHistory = $resHistory ?? array();
for($i = 0; $i<count($resHistory); $i++){
$dateInLocal = new DateTime($resHistory[$i]['timestamp'], new DateTimeZone('UTC'));
$resHistory[$i]["timestamp"] = $dateInLocal->setTimezone(new DateTimeZone($tz))->format('Y-m-d H:i:s T');;
}
$t_form->assign('history', $resHistory);
$t_form->display('view_history.tpl');
}
break;
default:
/*
echo "Action: $action<br /><br />Catchall...<br /><br />POST: <pre>";
print_r($_POST);
echo "</pre><br /><br />GET:<pre>";
print_r($_GET);
echo "</pre><br /><br />FILES:<pre>";
print_r($_FILES);
echo "</pre>";
*/
break;
}
function getSmarty(){
$t_form = new Smarty;
$t_form->left_delimiter = '<!--{';
$t_form->right_delimiter = '}-->';
return $t_form;
}