forked from tsugiproject/tsugi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.php
191 lines (166 loc) · 5.89 KB
/
profile.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
<?php
// In the top frame, we use cookies for session.
define('COOKIE_SESSION', true);
require_once("config.php");
require_once("pdo.php");
require_once("lib/lti_util.php");
header('Content-Type: text/html; charset=utf-8');
session_start();
if ( ! isset($_SESSION['profile_id']) ) {
header('Location: login.php');
return;
}
$stmt = pdoQueryDie($pdo,
"SELECT json FROM {$CFG->dbprefix}profile WHERE profile_id = :PID",
array('PID' => $_SESSION['profile_id'])
);
$profile_row = $stmt->fetch(PDO::FETCH_ASSOC);
if ( $profile_row === false ) {
$_SESSION['error'] = 'Unable to load profile';
header('Location: index.php');
return;
}
$profile = json_decode($profile_row['json']);
if ( ! is_object($profile) ) $profile = new stdClass();
// Handle the POST data
if ( isset($_POST['subscribe']) ) {
$profile->subscribe = $_POST['subscribe']+0 ;
if ( isset($_POST['map']) ) {
$profile->map = $_POST['map']+0 ;
$profile->lat = $_POST['lat']+0.0 ;
$profile->lng = $_POST['lng']+0.0 ;
}
$new_json = json_encode($profile);
$stmt = pdoQueryDie($pdo,
"UPDATE {$CFG->dbprefix}profile SET json= :JSON
WHERE profile_id = :PID",
array('JSON' => $new_json, 'PID' => $_SESSION['profile_id'])
);
$_SESSION['success'] = "Profile updated.";
header("Location: index.php");
return;
}
// Load data from the profile
$subscribe = isset($profile->subscribe) ? $profile->subscribe+0 : false;
$map = isset($profile->map) ? $profile->map+0 : false;
$lat = isset($profile->lat) ? $profile->lat+0.0 : 0.0;
$lng = isset($profile->lng) ? $profile->lng+0.0 : 0.0;
$defaultLat = $lat != 0.0 ? $lat : 42.279070216140425;
$defaultLng = $lng != 0.0 ? $lng : -83.73981015789798;
headerContent();
startBody();
if ( ! $CFG->OFFLINE ) {
?>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript">
var map;
function initialize() {
var myLatlng = new google.maps.LatLng(<?php echo($defaultLat.", ".$defaultLng); ?>);
var myOptions = {
zoom: 2,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
draggable: true,
position: myLatlng,
map: map,
title: "Your location"
});
google.maps.event.addListener(marker, 'dragend', function (event) {
document.getElementById("latbox").value = this.getPosition().lat();
document.getElementById("lngbox").value = this.getPosition().lng();
});
}
<?php } else { // OFFLINE ?>
<script type="text/javascript">
var map;
function initialize() { }
<?php } ?>
</script>
<div class="container">
<?php
function radio($var, $num, $val) {
$ret = '<input type="radio" name="'.$var.'" id="'.$var.$num.'" value="'.$num.'" ';
if ( $num == $val ) $ret .= ' checked ';
echo($ret);
}
function option($num, $val) {
echo(' value="'.$num.'" ');
if ( $num == $val ) echo(' selected ');
}
function checkbox($val) {
echo(' value="1" ');
if ( $val == 1 ) echo(' checked ');
}
echo('<h4>');echo($_SESSION['displayname']);
echo(' ('.$_SESSION['email'].")</h4>\n");
?>
<p>
<form method="POST">
<div class="control-group pull-right" style="margin-top: 20px">
<button type="submit" class="btn btn-primary visible-phone">Save</button>
<input class="btn btn-warning" type="button" onclick="location.href='index.php'; return false;" value="Cancel"/>
</div>
<div class="control-group">
<div class="controls">
How much mail would you like us to send?
<label class="radio">
<?php radio('subscribe',-1,$subscribe) ?> >
No mail will be sent.
</label>
<label class="radio">
<?php radio('subscribe',0,$subscribe) ?> >
Keep the mail level as low as possible.
</label>
<label class="radio">
<?php radio('subscribe',1,$subscribe) ?> >
Send only announcements.
</label>
<label class="radio">
<?php radio('subscribe',2,$subscribe) ?> >
Send me notification mail for important things like my assignment was graded.
</label>
</div>
</div>
<hr class="hidden-phone"/>
<?php if ( ! $CFG->OFFLINE ) { ?>
<hr class="hidden-phone"/>
How would you like to be shown in maps.<br/>
<select name="map">
<option value="0">--- Please Select ---</option>
<option <?php option(1,$map); ?>>Don't show me at all</option>
<option <?php option(2,$map); ?>>Show only my location with no identifying information</option>
<option <?php option(3,$map); ?>>Show my name (<?php echo($_SESSION['displayname']); ?>)</option>
</select>
<p>
Move the pointer on the map below until it is at the correct location.
If you are concerned about privacy, simply put the
location somewhere <i>near</i> where you live. Perhaps in the same country, state, or city
instead of your exact location.
</p>
<div class="control-group pull-right hidden-phone">
<button type="submit" style="margin-top: 40px" class="btn btn-primary">Save Profile Data</button>
</div>
<div id="map_canvas" style="margin: 10px; width:400px; max-width: 100%; height:400px"></div>
<div id="latlong" style="display:none" class="control-group">
<p>Latitude: <input size="30" type="text" id="latbox" name="lat" class="disabled"
<?php echo(' value="'.htmlent_utf8($lat).'" '); ?>
></p>
<p>Longitude: <input size="30" type="text" id="lngbox" name="lng" class="disabled"
<?php echo(' value="'.htmlent_utf8($lng).'" '); ?>
></p>
</div>
<p>
If you don't even want to reveal your country, put yourself
in Greenland in the middle of a glacier. One person put their location
in the middle of a bar. :)
</p>
<?php } ?>
</form>
<?php
// After jquery gets loaded at the *very* end...
footerContent('<script type="text/javascript">
$(document).ready(function() { initialize(); } );
</script>');