Commit 2e6960f5 authored by Malcolm Blaney's avatar Malcolm Blaney

more PSR changes.

parent afbbef89
......@@ -594,8 +594,8 @@ class Stock extends Base {
$organiser->GroupQuery().$buying_group_query.') ORDER BY name, user';
if ($result = $mysqli->query($query)) {
while ($stock = $result->fetch_assoc()) {
$available = $stock['order_available'] === '1' ||
$stock['purchase_available'] === '1';
$available = (int)$stock['order_available'] === 1 ||
(int)$stock['purchase_available'] === 1;
$product = array();
if ($stock['unit'] === 'adjusted') {
$product = $this->ChangeUnits($stock);
......@@ -736,7 +736,7 @@ class Stock extends Base {
'category' => $stock['category'],
'grower' => $stock['grower'],
'quantity' => $stock['quantity'],
'track' => $stock['track'] === 1);
'track' => (int)$stock['track'] === 1);
}
// The grid module requires this data as an indexed array, but it's
// also useful to have an associative array keyed on product names.
......@@ -767,7 +767,7 @@ class Stock extends Base {
'user = "'.$user.'"';
if ($result = $mysqli->query($query)) {
if ($stock = $result->fetch_assoc()) {
$composite = $stock['composite'] === '1';
$composite = (int)$stock['composite'] === 1;
}
$result->close();
}
......@@ -1109,7 +1109,7 @@ class Stock extends Base {
'category' => $stock['category'],
'grower' => $stock['grower'],
'quantity' => $stock['quantity'],
'track' => $stock['track'] === 1);
'track' => (int)$stock['track'] === 1);
}
private function EditProduct() {
......@@ -1675,7 +1675,7 @@ class Stock extends Base {
if ($result = $mysqli->query($query)) {
if ($stock = $result->fetch_assoc()) {
if (strtolower(trim($stock['category'])) !== 'hidden' &&
$stock['supplier_available'] === '0') {
(int)$stock['supplier_available'] === 0) {
if (!isset($new_available[$supplier])) {
$new_available[$supplier] = array();
}
......@@ -1711,7 +1711,7 @@ class Stock extends Base {
// don't update the existing value.
$track = 0;
$track_update = '';
if ($quantity !== 0) {
if ($quantity > 0) {
$track = 1;
$track_update = ', track = 1';
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -25,7 +25,7 @@
// for the JavaScript code in this page.
if(!this.dobrado.control){dobrado.control={};}
(function(){'use strict';var minimisedToolbar=false;var notificationsRequested=false;$(function(){var display=$('.dobrado-mobile').is(':hidden');$(".control .wrapper").addClass("ui-widget-header");$(".control-button.home").button({icons:{primary:"ui-icon-home"},text:display}).click(dobrado.home);$(".control-button.account-button").button({icons:{primary:"ui-icon-person"},text:display}).click(showAccount);$(".account-menu-wrapper .menu li").each(function(){$(this).click(dobrado.account.option);});$(".control-button.message-button").button({icons:{primary:"ui-icon-comment"},text:display}).click(message);$(".control-button.notification-button").button({icons:{primary:"ui-icon-star"},text:display}).click(notification);$("#control-tools").prop("checked",false);$("#control-tools").button({icons:{primary:"ui-icon-wrench"},text:display}).click(tools);$(".control-button.site").button({icons:{primary:"ui-icon-gear"},text:display}).click(site);$(".control-button.page").button({icons:{primary:"ui-icon-document"},text:display}).click(page);$("#page-input").keypress(pageSubmit).click(dobrado.clear);$(".control-button.add").button({icons:{primary:"ui-icon-plus"},text:display}).click(add);$(".add-menu-wrapper .menu li").each(function(){$(this).click(dobrado.addModule);});$("#control-edit").prop("checked",false);$("#control-edit").button({icons:{primary:"ui-icon-pencil"},text:display}).click(edit);$("#control-layout").prop("checked",false);$("#control-layout").button({icons:{primary:"ui-icon-arrow-4-diag"},text:display}).click(layout);$(".control-button.copy").button({icons:{primary:"ui-icon-copy"},text:display}).click(copy);$("#copy-input").keypress(copySubmit).click(dobrado.clear);$(".control-button.minimise").button({icons:{primary:"ui-icon-triangle-1-w"},text:false}).click(minimise);$(".control .menu").menu();$(".arrow-border").css("border-color","transparent transparent "+
(function(){'use strict';var minimisedToolbar=false;var notificationsRequested=false;$(function(){var display=$('.dobrado-mobile').is(':hidden');$(".control .wrapper").addClass("ui-widget-header");$(".control-button.home").button({icons:{primary:"ui-icon-home"},text:display}).click(dobrado.home);$(".control-button.account-button").button({icons:{primary:"ui-icon-person"},text:display}).click(showAccount);$(".account-menu-wrapper .menu li").each(function(){$(this).click(dobrado.account.option);});$(".control-button.message-button").button({icons:{primary:"ui-icon-comment"},text:display}).click(message);$(".control-button.notification-button").button({icons:{primary:"ui-icon-star"},text:display}).click(notification);$("#control-tools").prop("checked",false);$("#control-tools").button({icons:{primary:"ui-icon-wrench"},text:display}).click(tools);$(".control-button.site").button({icons:{primary:"ui-icon-gear"},text:display}).click(site);$(".control-button.page").button({icons:{primary:"ui-icon-document"},text:display}).click(page);$("#page-select").selectmenu({change:pageSelect});$("#page-input").keypress(pageSubmit).click(dobrado.clear);$(".control-button.add").button({icons:{primary:"ui-icon-plus"},text:display}).click(add);$(".add-menu-wrapper .menu li").each(function(){$(this).click(dobrado.addModule);});$("#control-edit").prop("checked",false);$("#control-edit").button({icons:{primary:"ui-icon-pencil"},text:display}).click(edit);$("#control-layout").prop("checked",false);$("#control-layout").button({icons:{primary:"ui-icon-arrow-4-diag"},text:display}).click(layout);$(".control-button.copy").button({icons:{primary:"ui-icon-copy"},text:display}).click(copy);$("#copy-input").keypress(copySubmit).click(dobrado.clear);$(".control-button.minimise").button({icons:{primary:"ui-icon-triangle-1-w"},text:false}).click(minimise);$(".control .menu").menu();$(".arrow-border").css("border-color","transparent transparent "+
dobrado.arrowBorderColor+" transparent");$(".arrow").css("border-color","transparent transparent "+
dobrado.arrowBackgroundColor+" transparent");$(".notification-dialog").dialog({autoOpen:false,position:{my:"top",at:"top+50",of:window},title:"Notifications",width:450,height:500,create:dobrado.fixedDialog});$(".control").show();$("#notification-tabs").tabs();showNotifications();dobrado.notify("system",dobrado.control.notifications);dobrado.notify("feed",dobrado.control.notifications);dobrado.notify("comment",dobrado.control.notifications);dobrado.notify("tag",dobrado.control.notifications);dobrado.notify("star",dobrado.control.notifications);dobrado.notify("share",dobrado.control.notifications);dobrado.notify("invite",dobrado.control.notifications);});function add(){dobrado.hideOtherMenu("add-menu-wrapper");dobrado.toggleMenu("add-menu-wrapper");$("body").one("click",hideMenu);return false;}
function message(){dobrado.hideOtherMenu("message-menu-wrapper");dobrado.toggleMenu("message-menu-wrapper");$("body").one("click",hideMenu);return false;}
......@@ -128,13 +128,13 @@ if($("#site-search-textarea").val()===""){$(".site-search-results").html("");ret
dobrado.log("Searching...","info");$.post("/php/request.php",{request:"extended",mode:"site",action:"search",search:$("#site-search-textarea").val(),group:$("#site-search-group-input").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"site search")){return;}
var extended=JSON.parse(response);searchData=extended.data;$(".site-search-update").hide();$(".site-search-results").after($(".site-search-update"));$(".site-search-results").html(extended.content);$(".search-match .edit-content").button().click(editContent);$(".search-match .edit-style").button().click(editStyle);});return false;}
dobrado.closeEditor();dobrado.current="";dobrado.log("Editor loading...","info");$.post("/php/request.php",{request:"extended",mode:"site",action:"display",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"site request")){return;}
var extended=JSON.parse(response);$("#extended-custom").html(extended.custom);$("button.rebuild-files").button().click(rebuild);$("#site-search-form .submit").button().click(search);$(".site-search-update .site-update-content .update").button().click(updateContent);$(".site-search-update .site-update-style .update").button().click(updateStyle);$("#site-config-form #user-input").change(updateConfig).keypress(updateConfigEnter);$("#site-config-form .submit").button().click(siteConfig);$("#extended-tabs li a").first().html("Site");$("#extended-tabs").show().tabs({activate:dobrado.extended.selectTab});if(extended.content===false){$("#extended-tabs").tabs("disable",1);}
var extended=JSON.parse(response);$("#extended-custom").html(extended.custom);if(extended.content===false){$("#extended-tabs").tabs("disable",1);}
else{$("#extended-content").html(extended.content);}
if(extended.style===false){$("#extended-tabs").tabs("disable",2);}
else{dobrado.extended.styleEditor(extended.style,extended.media);}
if(extended.history===false){$("#extended-tabs").tabs("disable",3);}
else{$("#extended-history").html(extended.history);}
$(".extended").dialog("open");$(".extended").data("mode","site");$("#site-template-form .submit").button().click(saveTemplate);$("#site-template-form .remove").button().click(removeTemplate);$("#site-template-form .help").button({icons:{primary:"ui-icon-help"},text:false}).tooltip({disabled:true}).click(templateHelp);loadTemplates();});}
$("button.rebuild-files").button().click(rebuild);$("#site-search-form .submit").button().click(search);$(".site-search-update .site-update-content .update").button().click(updateContent);$(".site-search-update .site-update-style .update").button().click(updateStyle);$("#site-config-form #user-input").change(updateConfig).keypress(updateConfigEnter);$("#site-config-form .submit").button().click(siteConfig);$("#extended-tabs li a").first().html("Site");$("#extended-tabs").show().tabs({activate:dobrado.extended.selectTab});$(".extended").dialog("open");$(".extended").data("mode","site");$("#site-template-form .submit").button().click(saveTemplate);$("#site-template-form .remove").button().click(removeTemplate);$("#site-template-form .help").button({icons:{primary:"ui-icon-help"},text:false}).tooltip({disabled:true}).click(templateHelp);loadTemplates();});}
function hideMenu(){$(".control .menu-wrapper").hide();}
function showAccount(){dobrado.hideOtherMenu("account-menu-wrapper");dobrado.toggleMenu("account-menu-wrapper");$("body").one("click",hideMenu);return false;}
function copySubmit(event){if(event.keyCode!==13){return;}
......@@ -144,8 +144,10 @@ dobrado.log("Copying page...","info");$.post("/php/copy.php",{url:location.href,
var page=JSON.parse(response);location.href=page.name;});}}
else{dobrado.log("Invalid page name.","error");}
return false;}});}
function pageSelect(){if($(this).val()===""){$("#page-select").selectmenu("destroy");$("#page-select").hide();$("#page-input").show();}
else{dobrado.changePage($(this).val());}}
function pageSubmit(event){if(event.keyCode!==13){return;}
event.preventDefault();$("#control-page-form > input").each(function(){if($(this).attr("name")==="page"){dobrado.changePage($(this).val());return false;}});}
event.preventDefault();dobrado.changePage($(this).val());return false;}
function minimise(){if(!minimisedToolbar){$(".control").css("width","auto");$(".control").css("min-width","20px");$(".toolbar").hide();$("#control-page-form").hide();$(".control .username").hide();$(".control-button.minimise").button("option","icons",{primary:"ui-icon-triangle-1-e"});minimisedToolbar=true;}
else{$(".control").css("width","100%");$(".control").css("min-width","300px");if($("#control-tools").is(":checked")){$(".toolbar").show();}
$("#control-page-form").show();$(".control .username").show();$(".control-button.minimise").button("option","icons",{primary:"ui-icon-triangle-1-w"});minimisedToolbar=false;}}
......
......@@ -34,19 +34,6 @@ if (!this.dobrado.control) {
var notificationsRequested = false;
$(function() {
//deal with any navigation events from navigation dropdown
$('#control-menu-select').on('change', function (e) {
var valueSelected = $(this).val();
if (valueSelected == 'control-page-more')
{
$("#control-menu-select").hide();
$("#page-input").show();
}
else if (valueSelected != "control-page-default")
{
dobrado.changePage(valueSelected);
}
});
// Display labels on control bar buttons when not mobile mode.
var display = $('.dobrado-mobile').is(':hidden');
// Help the control to fit in with the jquery-ui theme.
......@@ -70,6 +57,7 @@ if (!this.dobrado.control) {
text: display }).click(site);
$(".control-button.page").button({ icons: { primary: "ui-icon-document" },
text: display }).click(page);
$("#page-select").selectmenu({ change: pageSelect });
$("#page-input").keypress(pageSubmit).click(dobrado.clear);
$(".control-button.add").button({ icons: { primary: "ui-icon-plus" },
text: display }).click(add);
......@@ -1019,19 +1007,6 @@ if (!this.dobrado.control) {
}
var extended = JSON.parse(response);
$("#extended-custom").html(extended.custom);
$("button.rebuild-files").button().click(rebuild);
$("#site-search-form .submit").button().click(search);
$(".site-search-update .site-update-content .update").button().
click(updateContent);
$(".site-search-update .site-update-style .update").button().
click(updateStyle);
$("#site-config-form #user-input").change(updateConfig).
keypress(updateConfigEnter);
$("#site-config-form .submit").button().click(siteConfig);
// Rename the 'Custom' tab to signify that we're in 'site' mode.
$("#extended-tabs li a").first().html("Site");
// Initialise tabs here so that individual tabs can be disabled if false.
$("#extended-tabs").show().tabs({ activate: dobrado.extended.selectTab });
if (extended.content === false) {
$("#extended-tabs").tabs("disable", 1);
}
......@@ -1050,6 +1025,19 @@ if (!this.dobrado.control) {
else {
$("#extended-history").html(extended.history);
}
$("button.rebuild-files").button().click(rebuild);
$("#site-search-form .submit").button().click(search);
$(".site-search-update .site-update-content .update").button().
click(updateContent);
$(".site-search-update .site-update-style .update").button().
click(updateStyle);
$("#site-config-form #user-input").change(updateConfig).
keypress(updateConfigEnter);
$("#site-config-form .submit").button().click(siteConfig);
// Rename the 'Custom' tab to signify that we're in 'site' mode.
$("#extended-tabs li a").first().html("Site");
// Initialise tabs here so that individual tabs can be disabled if false.
$("#extended-tabs").show().tabs({ activate: dobrado.extended.selectTab });
$(".extended").dialog("open");
$(".extended").data("mode", "site");
$("#site-template-form .submit").button().click(saveTemplate);
......@@ -1115,17 +1103,24 @@ if (!this.dobrado.control) {
});
}
function pageSelect() {
if ($(this).val() === "") {
$("#page-select").selectmenu("destroy");
$("#page-select").hide();
$("#page-input").show();
}
else {
dobrado.changePage($(this).val());
}
}
function pageSubmit(event) {
if (event.keyCode !== 13) {
return;
}
event.preventDefault();
$("#control-page-form > input").each(function() {
if ($(this).attr("name") === "page") {
dobrado.changePage($(this).val());
return false;
}
});
dobrado.changePage($(this).val());
return false;
}
function minimise() {
......
<?php
// Dobrado Content Management System
// Copyright (C) 2013 Malcolm Blaney
// Copyright (C) 2016 Malcolm Blaney
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
......@@ -15,27 +15,27 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
function permission($action, $mode, $name = "") {
if ($action != "edit" && $action != "copy" && $action != "view") return false;
function permission($action, $mode, $name = '') {
if (!in_array($action, ['edit', 'copy', 'view', 'access'])) return false;
if (!isset($_SESSION['user'])) return false;
$user = $_SESSION['user'];
$page = "";
$owner = "";
$page = '';
$owner = '';
// An empty 'page' value is used to signify site permission below,
// and the owner is always 'admin' in this case.
if ($mode == "site") {
if ($user == "admin") return true;
$page = "";
$owner = "admin";
if ($mode === 'site') {
if ($user === 'admin') return true;
$page = '';
$owner = 'admin';
}
else {
preg_match("/^([a-z0-9_-]+)\/?([a-z0-9_-]*)$/i", $name, $matches);
if (count($matches) == 3) {
preg_match('/^([a-z0-9_-]+)\/?([a-z0-9_-]*)$/i', $name, $matches);
if (count($matches) === 3) {
// Note that count will always be 3 if there's a match because the second
// match is allowed to be empty.
if ($matches[2] === "") {
if ($matches[2] === '') {
$owner = $user;
$page = $matches[1];
}
......@@ -44,21 +44,27 @@ function permission($action, $mode, $name = "") {
$page = $matches[2];
}
}
if ($user === "" || $page === "" || $owner === "") return false;
if ($mode == "page" && $user == $owner) return true;
if ($user === '' || $page === '' || $owner === '') return false;
if ($mode === 'page' && $user === $owner) return true;
}
$permission = false;
$mysqli = connect_db();
$query = 'SELECT visitor FROM user_permission WHERE user = "'.$owner.'"'.
if ($action === 'access') {
$action = '(edit = 1 OR copy = 1 OR view = 1)';
}
else {
$action .= ' = 1';
}
$query = 'SELECT visitor FROM user_permission WHERE user = "'.$owner.'" '.
' AND page = "'.$page.'" AND (visitor = "'.$user.'" OR visitor = "") AND '.
$action.' = 1';
$action;
if ($result = $mysqli->query($query)) {
if ($result->num_rows > 0) $permission = true;
$result->close();
}
else {
error_log('permission 1: '.$mysqli->error);
log_db('permission 1: '.$mysqli->error);
}
if (!$permission) {
// Find all groups that have permission to edit/copy the page, for this
......@@ -67,13 +73,13 @@ function permission($action, $mode, $name = "") {
'groups.name = group_permission.name AND '.
'groups.user = group_permission.user WHERE '.
'group_permission.page = "'.$page.'" AND groups.visitor = "'.$user.'" '.
'AND groups.user = "'.$owner.'" AND '.$action.' = 1';
'AND groups.user = "'.$owner.'" AND '.$action;
if ($result = $mysqli->query($query)) {
if ($result->num_rows > 0) $permission = true;
$result->close();
}
else {
error_log('permission 2: '.$mysqli->error);
log_db('permission 2: '.$mysqli->error);
}
}
$mysqli->close();
......@@ -81,24 +87,21 @@ function permission($action, $mode, $name = "") {
}
function can_edit_site() {
return permission("edit", "site");
return permission('edit', 'site');
}
function can_edit_page($name) {
return permission("edit", "page", $name);
return permission('edit', 'page', $name);
}
function can_copy_page($name) {
return permission("copy", "page", $name);
return permission('copy', 'page', $name);
}
function can_view_page($name) {
return permission("view", "page", $name);
return permission('view', 'page', $name);
}
function can_access_page($name) {
if (can_view_page($name) || can_edit_page($name) || can_copy_page($name)) return true;
else return false;
return permission('access', 'page', $name);
}
?>
......@@ -400,7 +400,7 @@ class Account extends Base {
if (($result->num_rows === 1) && $users = $result->fetch_assoc()) {
$user_exists = true;
$current_group = $users['system_group'];
$already_confirmed = $users['confirmed'] === '1';
$already_confirmed = (int)$users['confirmed'] === 1;
}
$result->close();
}
......@@ -622,8 +622,8 @@ class Account extends Base {
if (($result->num_rows === 1) && $users = $result->fetch_assoc()) {
$email = $users['email'];
$group = $users['system_group'];
$confirmed = $users['confirmed'] === '1';
$active = $users['active'] === '1';
$confirmed = (int)$users['confirmed'] === 1;
$active = (int)$users['active'] === 1;
}
$result->close();
}
......@@ -794,16 +794,17 @@ class Account extends Base {
if ($page === '' && $owner === 'admin') {
$access .= '<i>members have site permission</i><br>';
}
if ($permission['edit'] === '1' && $permission['copy'] === '1') {
if ((int)$permission['edit'] === 1 &&
(int)$permission['copy'] === 1) {
$access .= $user.$page.' <i>(copy and edit)</i><br>';
}
else if ($permission['edit'] === '1') {
else if ((int)$permission['edit'] === 1) {
$access .= $user.$page.' <i>(edit)</i><br>';
}
else if ($permission['copy'] === '1') {
else if ((int)$permission['copy'] === 1) {
$access .= $user.$page.' <i>(copy)</i><br>';
}
else if ($permission['view'] === '1') {
else if ((int)$permission['view'] === 1) {
$access .= $user.$page.'<br>';
}
}
......@@ -821,7 +822,8 @@ class Account extends Base {
'name = "'.$group.'" AND groups.user = "'.$owner.'" ORDER BY visitor';
if ($result = $mysqli->query($query)) {
while ($groups = $result->fetch_assoc()) {
$can_edit = $groups['edit_group'] === '1' ? ' (can edit group)' : '';
$can_edit = (int)$groups['edit_group'] === 1 ?
' (can edit group)' : '';
$content .= '<div class="group-member">'.
'<button class="remove-group-member">remove</button> '.
'<span class="visitor">'.$groups['visitor'].'</span>'.$can_edit.
......@@ -873,7 +875,7 @@ class Account extends Base {
'AND name = "'.$group.'" AND visitor = "'.$this->user->name.'"';
if ($result = $mysqli->query($query)) {
if ($groups = $result->fetch_assoc()) {
$edit_group = $groups['edit_group'] === '1';
$edit_group = (int)$groups['edit_group'] === 1;
}
$result->close();
}
......@@ -932,7 +934,7 @@ class Account extends Base {
'AND name = "'.$group.'" AND visitor = "'.$this->user->name.'"';
if ($result = $mysqli->query($query)) {
if ($groups = $result->fetch_assoc()) {
$edit_group = $groups['edit_group'] === '1';
$edit_group = (int)$groups['edit_group'] === 1;
}
$result->close();
}
......@@ -982,19 +984,19 @@ class Account extends Base {
else {
$page = 'page <span class="page">'.$permission["page"].'</span>';
}
if ($permission['edit'] === 1 && $permission['copy'] === 1) {
if ((int)$permission['edit'] === 1 && (int)$permission['copy'] === 1) {
$content .= '<div class="group-permission">'.$remove.$group.
' can copy/edit '.$page.'</div>';
}
else if ($permission['edit'] === 1) {
else if ((int)$permission['edit'] === 1) {
$content .= '<div class="group-permission">'.$remove.$group.
' can edit '.$page.'</div>';
}
else if ($permission['copy'] === 1) {
else if ((int)$permission['copy'] === 1) {
$content .= '<div class="group-permission">'.$remove.$group.
' can copy '.$page.'</div>';
}
else if ($permission['view'] === 1) {
else if ((int)$permission['view'] === 1) {
$content .= '<div class="group-permission">'.$remove.$group.
' can view '.$page.'</div>';
}
......@@ -1031,19 +1033,19 @@ class Account extends Base {
$page = 'page <span class="page">'.$permission['page'].'</span>';
}
if ($permission['edit'] === 1 && $permission['copy'] === 1) {
if ((int)$permission['edit'] === 1 && (int)$permission['copy'] === 1) {
$content .= '<div class="user-permission">'.$remove.$user.
' can copy/edit '.$page.'</div>';
}
else if ($permission['edit'] === 1) {
else if ((int)$permission['edit'] === 1) {
$content .= '<div class="user-permission">'.$remove.$user.
' can edit '.$page.'</div>';
}
else if ($permission['copy'] === 1) {
else if ((int)$permission['copy'] === 1) {
$content .= '<div class="user-permission">'.$remove.$user.
' can copy '.$page.'</div>';
}
else if ($permission['view'] === 1) {
else if ((int)$permission['view'] === 1) {
$content .= '<div class="user-permission">'.$remove.$user.
' can view '.$page.'</div>';
}
......
......@@ -49,7 +49,7 @@ class Control extends Base {
'<div class="arrow-border"></div>'.
'<div class="arrow"></div>'.
'<ul class="menu">';
if ($user == 'guest') {
if ($user === 'guest') {
$account_menu .= '<li id="register">Register...</li>';
}
else {
......@@ -141,8 +141,7 @@ class Control extends Base {
'<span class="ui-icon ui-icon-alert"></span>'.
'<span class="message">error</span>'.
'</div>'.
$minimise_button.
$this->CreateControlPageForm().
$minimise_button.$this->PageForm().
'<div class="username">'.$user.'</div>'.
'</div>'. // This closes the opening div with class 'wrapper'.
$account_menu.$message_menu.$notification_menu.$add_menu.$copy_menu.
......@@ -197,7 +196,7 @@ class Control extends Base {
// The control is added for the 'admin' user here, for all other
// users it is added when their account is created.
$this->AddToAdmin('control');
$template = array('"control-admin-menu","","simple,more"','"control-menu-pages","","purchase,stock,manager,invoices,payments,report"');
$template = array('"control-admin-menu","","simple,more"');
$this->AddTemplate($template);
// This is a default media query for mobile devices.
$media = '@media screen and (max-device-width: 480px)';
......@@ -234,8 +233,16 @@ class Control extends Base {
'"",".arrow-border","margin-left","10px"',
'"","#control-page-form","float","right"',
'"","#control-page-form","margin","0 7px 2px 2px"',
'"","#page-input","width","200px"',
'"","#page-input","width","150px"',
'"'.$media.'","#page-input","width","100px"',
'"","#page-select","width","150px"',
'"'.$media.'","#page-select","width","100px"',
'"","#control-page-form .ui-selectmenu-button '.
'span.ui-selectmenu-text","font-size","18px"',
'"","#control-page-form .ui-selectmenu-button '.
'span.ui-selectmenu-text","padding-top","2px"',
'"","#control-page-form .ui-selectmenu-button '.
'span.ui-selectmenu-text","padding-bottom","2px"',
'"",".control-input","color","#828282"',
'"",".message-count","position","absolute"',
'"",".message-count","top","10px"',
......@@ -334,59 +341,6 @@ class Control extends Base {
// Public functions that aren't part of interface here /////////////////////
// Private functions below here ////////////////////////////////////////////
private function FilterPagesByPermission($thePages) {
$filteredPages = array();
foreach ($thePages as $thePage) {
if (can_access_page($this->GetNavigationMenuVal($thePage) )) {
array_push($filteredPages,$thePage);
}
}
return $filteredPages;
}
private function CreateControlPageForm() {
$p = explode(',', $this->Substitute("control-menu-pages"));
$pagesArray = $this->FilterPagesByPermission($p);
$currentPageIsInList = false;
$pageInputDisplayParam = "block;";
$selectDisplayParam = "none;";
if (count($pagesArray) > 0 && $this->Substitute("control-menu-pages") != "") {
$pageInputDisplayParam = "none;";
$selectDisplayParam = "block;";
$controlMenuSelect = '';
$optionsSelect = "";
foreach ($pagesArray as $page) {
$selected = "";
//check if the current page is in the predefined list,
if ($this->CurrentPageStr() == $this->GetNavigationMenuVal($page) ) {
$selected = "selected";
$currentPageIsInList = true;
}
//add item to the dropdown menu
if ($page != "") {
$optionsSelect .= '<option value="' . $this->GetNavigationMenuVal($page) .
'"' . $selected . '>' . $page . '</option>';
}
}
//put menu together
$controlMenuSelect .= '<select id="control-menu-select" style="position:relative; top:4px; min-width:170px; display:' . $selectDisplayParam .'">'
. '<option value="control-page-default" disabled="disabled" ' . ($currentPageIsInList == false ? "selected" : "")
. '>change page...</option>'
. $optionsSelect . '<option value="control-page-more">...more pages</option></select>';
}
//format form
$controlPageForm = '<form id="control-page-form">' . $controlMenuSelect . '<input style="position:relative; top:4px; display:'
. $pageInputDisplayParam . '" id="page-input" class="control-input" type="text" '
. 'name="page" value="change page..." size="20" maxlength="200"></form>';
return $controlPageForm;
}
private function CurrentPageStr() {
return $this->owner . "/" . $this->user->page;
}
private function GetNavigationMenuVal($menuItem) {
return "admin/" . $menuItem;
}
private function AddMenu($admin) {
$labels = array();
......@@ -453,6 +407,59 @@ class Control extends Base {
return false;
}
}
private function PageForm() {
$options = '';
$selected = false;
// Use a session array to avoid checking permissions on every page load.
if (isset($_SESSION['control-page-options'])) {
foreach($_SESSION['control-page-options'] as $page) {
if ($this->owner === 'admin' && $this->user->page === $page) {
$options .= '<option value="admin/'.$page.'" selected="selected">'.
$page.'</option>';
$selected = true;
}
else {
$options .= '<option value="admin/'.$page.'">'.$page.'</option>';
}
}
}
else {
$_SESSION['control-page-options'] = array();
$page_options = explode(',', $this->Substitute('control-page-options'));
foreach ($page_options as $page) {
$page = trim($page);
if ($page === '') continue;
if (can_access_page('admin/'.$page)) {
$_SESSION['control-page-options'][] = $page;
if ($this->owner === 'admin' && $this->user->page === $page) {
$options .= '<option value="admin/'.$page.'" selected="selected">'.
$page.'</option>';
$selected = true;
}
else {
$options .= '<option value="admin/'.$page.'">'.$page.'</option>';
}
}
}
}
$page_select = '';
$hide_input = '';
// Add an option so that page-input can be displayed instead of the select.
if ($options !== '') {
if (!$selected) {
// Show the current page at the top of the select for display purposes.
$options = '<option value="" selected="selected">'.$this->user->page.
'</option>'.$options;
}
$options .= '<option value="">other...</option>';
$page_select = '<select id="page-select">'.$options.'</select>';
$hide_input = ' hidden';
}
return '<form id="control-page-form">'.$page_select.
'<input id="page-input" class="control-input'.$hide_input.'" '.
'type="text" name="page" value="change page..." maxlength="200">'.
'</form>';
}
?>
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment