Skip to content

Commit

Permalink
Add FCM link to user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
drlippman committed Sep 23, 2017
1 parent 52ad81a commit 1e18f4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
22 changes: 12 additions & 10 deletions admin/FCMsetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
echo "OK";
exit;
}
if (isset($_GET['remove'])) {
if (isset($_POST['remove'])) {
$stm = $DBH->prepare("UPDATE imas_users SET FCMtoken='' WHERE id=:id");
$stm->execute(array(":id"=>$userid));
echo "OK";
Expand All @@ -19,8 +19,8 @@
<script>
// Initialize Firebase
var FCMconfig = {
apiKey: "'.$CFG['FCM']['webApiKey'].'",
messagingSenderId: "'.$CFG['FCM']['SenderId'].'"
apiKey: "'.Sanitize::encodeStringForJavascript($CFG['FCM']['webApiKey']).'",
messagingSenderId: "'.Sanitize::encodeStringForJavascript($CFG['FCM']['SenderId']).'"
};
firebase.initializeApp(FCMconfig);
Expand All @@ -30,10 +30,10 @@
// Registration was successful
console.log("ServiceWorker registration successful with scope: ", registration.scope);
messaging.useServiceWorker(registration);
if ("'.$FCMtoken.'" != "") {
if ("'.Sanitize::encodeStringForJavascript($FCMtoken).'" != "") {
messaging.getToken()
.then(function(token) {
if (token=="'.$FCMtoken.'") {
if (token=="'.Sanitize::encodeStringForJavascript($FCMtoken).'") {
$("#havetoken").show(); $("#dosetup").hide();
}
})
Expand All @@ -49,7 +49,9 @@
function removeNotifications() {
$.ajax({
url: "FCMsetup.php?remove=true"
url: "FCMsetup.php",
type: "POST",
data: {"remove": true}
}).done(function() {
$("#havetoken").hide(); $("#otherdevice").hide(); $("#dosetup").show(); $("#stopnotifications").hide();
});
Expand Down Expand Up @@ -100,7 +102,7 @@ function askPermission() {
<div class="breadcrumb"><a href="../index.php">Home</a> &gt; <a href="../forms.php?action=chguserinfo">User Profile</a> &gt; Notification Settings</div>

<div id="dosetup">
<p>If you would like to receive new message notifications on this system, even when not visiting this site,
<p>If you would like to receive new message notifications from this system, even when not visiting this site,
click the button below. When your browser asks for permissions, click Allow. Note this system only works in some browsers
(Chrome and Firefox).</p>
<?php
Expand All @@ -113,9 +115,9 @@ function askPermission() {
</div>
<div id="havetoken" style="display:none">Notifications are set up on this device.</div>

<p id="stopnotifications" <?php if ($FCMtoken=='') { echo 'style="display:none"';} ?>>
<button type="button" onclick="removeNotifications()">Stop Notifications</button></p>

<?php
if ($FCMtoken != '') {
echo '<p id="stopnotifications"><button type="button" onclick="removeNotifications()">Stop Notifications</button></p>';
}
require("../footer.php");
?>
4 changes: 4 additions & 0 deletions forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
echo "<span class=form><label for=\"msgnot\">Notify me by email when I receive a new message:</label></span><span class=formright><input type=checkbox id=msgnot name=msgnot ";
if ($line['msgnotify']==1) {echo "checked=1";}
echo " /></span><BR class=form>\n";
if (isset($CFG['FCM']) && isset($CFG['FCM']['webApiKey']) && strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== false) {
echo '<span class=form>'._('Push notifications:').'</span><span class=formright>';
echo '<a href="'.$imasroot.'/admin/FCMsetup.php">'.('Setup push notifications on this device').'</a></span><br class=form>';
}

echo "<span class=form><label for=\"stupic\">Picture:</label></span>";
echo "<span class=\"formright\">";
Expand Down

0 comments on commit 1e18f4a

Please sign in to comment.