Make widgets disappear if the user doesn't have permission to use them

V2_Rewrite
Skylar Ittner 7 years ago
parent 14f401f355
commit be892b007d

@ -12,4 +12,9 @@ $APPS["inventory_link"]["icon"] = "cubes";
$APPS["inventory_link"]["type"] = "teal";
$content = "<p class='mobile-app-hide'>" . lang("open inventory system", false) . '</p><a href="' . INVENTORY_HOME . '" class="btn btn-primary btn-block mobile-app-hide">' . lang("open app", false) . ' &nbsp;<i class="fa fa-external-link-square"></i></a>';
$APPS["inventory_link"]["content"] = $content;
require_once __DIR__ . "/../lib/login.php";
if (account_has_permission($_SESSION['username'], "INV_VIEW") !== true) {
unset($APPS['inventory_link']);
}
?>

@ -1,10 +1,12 @@
<?php
dieifnotloggedin();
require_once __DIR__ . "/../lib/login.php";
addMultiLangStrings(["en_us" => [
"qwikclock" => "QwikClock",
"punch in" => "Punch in",
"punch out" => "Punch out"
"punch out" => "Punch out",
"permission denied" => "You do not have permission to do that."
]
]);
$APPS["qwikclock_inout"]["i18n"] = TRUE;
@ -12,6 +14,9 @@ $APPS["qwikclock_inout"]["title"] = "qwikclock";
$APPS["qwikclock_inout"]["icon"] = "clock-o";
$APPS["qwikclock_inout"]["type"] = "blue";
$content = "";
use GuzzleHttp\Exception\ClientException;
if (!is_empty($_GET['qwikclock']) && ($_GET['qwikclock'] === "punchin" || $_GET['qwikclock'] === "punchout")) {
try {
$client = new GuzzleHttp\Client();
@ -28,6 +33,10 @@ if (!is_empty($_GET['qwikclock']) && ($_GET['qwikclock'] === "punchin" || $_GET[
} else {
$content = "<div class=\"alert alert-danger alert-dismissable\"><button type=\"button\" class=\"close\">&times;</button>" . $resp['msg'] . "</div>";
}
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() == 403) {
$content = "<div class=\"alert alert-danger alert-dismissable\"><button type=\"button\" class=\"close\">&times;</button>" . lang("permission denied", false) . "</div>";
}
} catch (Exception $e) {
$content = "<div class=\"alert alert-danger alert-dismissable\"><button type=\"button\" class=\"close\">&times;</button>" . lang("error loading widget", false) . " " . $e->getMessage() . "</div>";
}
@ -40,4 +49,9 @@ $content .= <<<END
END;
$content .= '<br /><a href="' . QWIKCLOCK_HOME . '" class="btn btn-primary btn-block mobile-app-hide">' . lang("open app", false) . ' &nbsp;<i class="fa fa-external-link-square"></i></a>';
$APPS["qwikclock_inout"]["content"] = $content;
if (account_has_permission($_SESSION['username'], "QWIKCLOCK") !== true) {
unset($APPS['qwikclock_inout']);
}
?>

@ -4,6 +4,7 @@ dieifnotloggedin();
use Endroid\QrCode\QrCode;
if (MOBILE_ENABLED) {
addMultiLangStrings(["en_us" => [
"sync mobile" => "Sync Mobile App",
"scan sync qrcode" => "Scan this code with the mobile app or enter the code manually.",
@ -72,3 +73,4 @@ END;
END;
$APPS["sync_mobile"]["content"] = $content;
}
}

@ -10,6 +10,9 @@ $APPS["taskfloor_messages"]["i18n"] = TRUE;
$APPS["taskfloor_messages"]["title"] = "messages";
$APPS["taskfloor_messages"]["icon"] = "comments";
$APPS["taskfloor_messages"]["type"] = "deep-purple";
use GuzzleHttp\Exception\ClientException;
try {
$client = new GuzzleHttp\Client();
@ -46,9 +49,15 @@ END;
$content = "<div class=\"alert alert-info\">" . lang("no messages", false) . "</div>";
}
}
$content .= '<a href="' . TASKFLOOR_HOME . '" class="btn btn-primary btn-block mobile-app-hide">' . lang("open app", false) . ' &nbsp;<i class="fa fa-external-link-square"></i></a>';
$APPS["taskfloor_messages"]["content"] = $content;
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() == 403) {
unset($APPS['taskfloor_messages']);
}
} catch (Exception $e) {
$content = "<div class=\"alert alert-danger\">" . lang("error loading widget", false) . " " . $e->getMessage() . "</div>";
}
$content .= '<a href="' . TASKFLOOR_HOME . '" class="btn btn-primary btn-block mobile-app-hide">' . lang("open app", false) . ' &nbsp;<i class="fa fa-external-link-square"></i></a>';
$APPS["taskfloor_messages"]["content"] = $content;
}
?>

@ -10,6 +10,9 @@ $APPS["taskfloor_tasks"]["i18n"] = TRUE;
$APPS["taskfloor_tasks"]["title"] = "tasks";
$APPS["taskfloor_tasks"]["icon"] = "tasks";
$APPS["taskfloor_tasks"]["type"] = "blue-grey";
use GuzzleHttp\Exception\ClientException;
try {
$client = new GuzzleHttp\Client();
@ -34,9 +37,15 @@ try {
$content = "<div class=\"alert alert-success\">" . lang("no tasks found", false) . "</div>";
}
}
$content .= '<a href="' . TASKFLOOR_HOME . '" class="btn btn-primary btn-block mobile-app-hide">' . lang("open app", false) . ' &nbsp;<i class="fa fa-external-link-square"></i></a>';
$APPS["taskfloor_tasks"]["content"] = $content;
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() == 403) {
unset($APPS['taskfloor_tasks']);
}
} catch (Exception $e) {
$content = "<div class=\"alert alert-danger\">" . lang("error loading widget", false) . " " . $e->getMessage() . "</div>";
}
$content .= '<a href="' . TASKFLOOR_HOME . '" class="btn btn-primary btn-block mobile-app-hide">' . lang("open app", false) . ' &nbsp;<i class="fa fa-external-link-square"></i></a>';
$APPS["taskfloor_tasks"]["content"] = $content;
}
?>

@ -156,7 +156,15 @@ END;
<div class="row widget-box">
<?php
// Center the widgets horizontally on the screen
$appcount = count(APPS[$pageid]);
$appcount = 0;
foreach (APPS[$pageid] as $app) {
if (file_exists(__DIR__ . "/apps/" . $app . ".php")) {
include_once __DIR__ . "/apps/" . $app . ".php";
if (isset($APPS[$app])) {
$appcount++;
}
}
}
if ($appcount == 1) {
?>
<div class="hidden-xs col-sm-3 col-md-4 col-lg-4">
@ -175,6 +183,9 @@ END;
foreach (APPS[$pageid] as $app) {
if (file_exists(__DIR__ . "/apps/" . $app . ".php")) {
include_once __DIR__ . "/apps/" . $app . ".php";
if (!isset($APPS[$app])) {
continue;
}
$apptitle = ($APPS[$app]['i18n'] === TRUE ? lang($APPS[$app]['title'], false) : $APPS[$app]['title']);
$appicon = (is_empty($APPS[$app]['icon']) ? "" : "fa fa-fw fa-" . $APPS[$app]['icon']);
$apptype = (is_empty($APPS[$app]['type']) ? "default" : $APPS[$app]['type']);

Loading…
Cancel
Save