-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
executable file
·204 lines (161 loc) · 7.86 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
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
<?php
error_reporting(E_ALL);
set_time_limit(0);
date_default_timezone_set('Europe/London');
include_once('functions.php');
getHead("index.php", $user_name, $user_organisation);
?>
<div class="hero-unit">
<div class="row">
<div class="span4">
<h1>HXLator</h1>
</div>
<div class="span6">
<p style="margin-bottom: 1.5em">A simple online tool to convert a spreadsheet into the Humanitarian eXchange Language (HXL). Take a look at our <a href="guide.php">quick start guide</a> or start by uploading your spreadsheet here:</p>
</div>
</div>
<?php if(isset($_SESSION['loggedin'])) { // show the upload options only if the user is logged in: ?>
<form class="alert" id="metadata-form" enctype="multipart/form-data" action="hxlate.php#" method="POST">
<div class="control-group">
<label for="emergencies"><i class="icon-fire"></i> Emergency: </label>
<div class="controls">
<span class="add-on"></span>
<input type="text" id="emergencies" name="selectemergency" class="span3" /> <span style="margin-left: 20px;"><em>Start typing and select from the emergencies list.</em></span><br />
<input type="hidden" name="emergency" id="emergency">
</div>
</div>
<div class="control-group">
<label class="control-label" for="report_category" ><i class="icon-tags"></i> Report category:</label>
<div class="controls">
<select id="report_category" name="report_category" class="span3">
<option value="http://hxl.humanitarianresponse.info/data/reportcategories/cluster1">Cluster 1</option>
<option value="http://hxl.humanitarianresponse.info/data/reportcategories/cluster2">Cluster 2</option>
<option value="http://hxl.humanitarianresponse.info/data/reportcategories/humanitarian_profile" selected>Humanitarian profile</option>
<option value="http://hxl.humanitarianresponse.info/data/reportcategories/security">Security</option>
</select> <span style="margin-left: 20px;"><em>This determines who will verify and approve your submission.</em></span><br />
</div>
</div>
<div class="control-group">
<label class="control-label" for="report_category" ><i class="icon-calendar"></i> Data valid on:</label>
<div class="controls">
<input id="date" name="date" class="span3" data-date="<?php echo date('Y-m-d'); ?>" data-date-format="yyyy-mm-dd" size="16" type="text" value="<?php echo date('Y-m-d'); ?>" /><span style="margin-left: 20px;"><em>If there are data for different dates in the spreadsheet, this can be changed later.</em></span><br />
</div>
</div>
<div class="control-group">
<label class="control-label" for="translator"><i class="icon-briefcase"></i> HXL translator:</label>
<div class="controls">
<select id="translator" name="translator" class="span3">
<option value="new">Create new HXL translator</option>
<?php // list user's stored translators
$path = getcwd().'/mappings/'.$_SESSION['user_shortname'];
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<option value=\"".$file."\">Reuse translator created for ".substr($file, 0 ,-5)."</option>\n";
}
}
closedir($handle);
}
?>
</select><span style="margin-left: 20px;"><em>If your spreadsheet has the same structure as a spreadsheet you have HXLated before, you can reuse the mapping.</em></span><br />
</div>
</div>
<div class="fileupload fileupload-new control-group" data-provides="fileupload">
<label class="control-label" for="file"><i class="icon-file"></i> Select file to HXLate:</label>
<div class="fileupload-preview span3 uneditable-input" id="upload-preview" style="border: 1px solid #ccc"></div>
<span class="btn btn-file" id="file-button"><span class="fileupload-new">Select file</span><span class="fileupload-exists">Change</span><input name="userfile" type="file" /></span>
</div>
<br />
<button type="submit" class="btn btn-inverse btn-large">HXLate File</button>
</form>
<?php
} else {
show_login_form();
}
?>
</div>
</div> <!-- /container -->
<?php if(isset($_SESSION['loggedin'])) { ?>
<script>document.getElementById('emergencies').focus()</script>
<?php
/*
* Generates the autocomplete field for the emergency selection:
*/
function emergencyQuery(){
$emergencies = sparqlQuery('SELECT DISTINCT ?uri ?label WHERE {
?uri a hxl:Emergency;
hxl:commonTitle ?label .
} ORDER BY ?label');
$label = "label";
$uri = "uri";
// we'll return the whole JS code here - if we only return the array of emergencies, PHP renders the array as a table instead of simply passing on the string :/
$elist = '
/*
* Provides the autocomplete function with an array of emergency names itself
* provided by the emergency query php function.
*/
var emergencies = [';
foreach($emergencies as $emergency){
$elist .= ' { value: "'.$emergency->$label.'", uri: "'.$emergency->$uri.'"}, ' ;
}
// we're customizing the jQuery UI autocomplete a bit
// see http://jqueryui.com/demos/autocomplete/ for the documentation
$elist .= ' {} ]
$("#emergencies").autocomplete({
source: function(request, response) {
var results = $.ui.autocomplete.filter(emergencies, request.term);
if(!results.length){
$("#emergency").parents(".control-group").addClass("error");
response([]);
}else{
$("#emergency").parents(".control-group").removeClass("error");
response(results);
}
},
select: function(event, ui) {
$("#emergency").val(ui.item.uri);
}
}).data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "<br /></a>")
.appendTo(ul);
};
';
return $elist;
}
$customJS = emergencyQuery().'
$(".fileupload").fileupload();
$("#date").datepicker();
$("#metadata-form").submit(function(){
var isFormValid = true;
// check if an emergency has been selected
if ($.trim($("#emergency").val()).length == 0){
$("#emergency").parents(".control-group").addClass("error");
isFormValid = false;
} else {
$("#emergency").parents(".control-group").removeClass("error");
}
//check if a file is selected for upload
if($.trim($("#upload-preview").html()).length == 0){
$("#upload-preview").parents(".control-group").addClass("error");
$("#upload-preview").css("border", "1px solid #B94A48");
$("#file-button").addClass("btn-danger");
isFormValid = false;
}else{
$("#upload-preview").parents(".control-group").removeClass("error");
$("#upload-preview").css("border", "1px solid #CCC");
$("#file-button").removeClass("btn-danger");
}
if (!isFormValid) {
if($("#fillme").length == 0){
$("#metadata-form").before(\'<div class="alert alert-error" id="fillme">Please fill in all fields.</div>\');}
}
return isFormValid;
});
';
getFoot(array('jquery-ui-1.8.21.custom.min.js', 'bootstrap-fileupload.js', 'bootstrap-datepicker.js' ), $customJS );
} else {
getFoot(array('jquery-ui-1.8.21.custom.min.js'), null );
}
?>