Settings: Add interface for User Settings, add ability for Admin to manage (own) Domain and User Settings.

This commit is contained in:
reliberate
2016-02-29 11:39:46 -07:00
parent c23f53ea34
commit b54b832145
14 changed files with 2584 additions and 1396 deletions
+7 -1
View File
@@ -30,6 +30,7 @@
$y++;
$apps[$x]['permissions'][$y]['name'] = "domain_edit";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "domain_delete";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
@@ -38,18 +39,23 @@
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "domain_setting_view";
$apps[$x]['permissions'][$y]['menu']['uuid'] = "4fa7e90b-6d6c-12d4-712f-62857402b801";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "domain_setting_add";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "domain_setting_edit";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "domain_setting_delete";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
$apps[$x]['permissions'][$y]['groups'][] = "admin";
$y++;
$apps[$x]['permissions'][$y]['name'] = "domain_setting_category_edit";
$apps[$x]['permissions'][$y]['groups'][] = "superadmin";
//schema details
$y = 0; //table array index
+15
View File
@@ -15,4 +15,19 @@ $apps[$x]['menu'][0]['category'] = "internal";
$apps[$x]['menu'][0]['path'] = "/core/domain_settings/domains.php";
$apps[$x]['menu'][0]['groups'][] = "superadmin";
$apps[$x]['menu'][1]['title']['en-us'] = "Domain Settings";
$apps[$x]['menu'][1]['title']['es-cl'] = "Configuraciones de Dominio";
$apps[$x]['menu'][1]['title']['fr-fr'] = "Paramètres du Domaine";
$apps[$x]['menu'][1]['title']['pt-pt'] = "Definições do Domínio";
$apps[$x]['menu'][1]['title']['pt-br'] = "Configurações do Dominio";
$apps[$x]['menu'][1]['title']['pl'] = "Ustawienia Domen";
$apps[$x]['menu'][1]['title']['sv-se'] = "Domän Inställning";
$apps[$x]['menu'][1]['title']['uk'] = "Налаштування доменів";
$apps[$x]['menu'][1]['title']['de-at'] = "Domain Einstellungen";
$apps[$x]['menu'][1]['uuid'] = "0869ac79-4af3-498f-af65-69662280d74e";
$apps[$x]['menu'][1]['parent_uuid'] = "594d99c5-6128-9c88-ca35-4b33392cec0f";
$apps[$x]['menu'][1]['category'] = "internal";
$apps[$x]['menu'][1]['path'] = "/core/domain_settings/domain_edit.php";
$apps[$x]['menu'][1]['groups'][] = "admin";
?>
+22 -7
View File
@@ -40,12 +40,19 @@ else {
$text = $language->get();
//action add or update
if (isset($_REQUEST["id"])) {
if (!permission_exists('domain_add') || (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/") && !permission_exists('domain_parent') && permission_exists('domain_descendants'))) {
//admin editing own domain/settings
$domain_uuid = $_SESSION['domain_uuid'];
$action = "update";
$domain_uuid = check_str($_REQUEST["id"]);
}
else {
$action = "add";
if (isset($_REQUEST["id"])) {
$action = "update";
$domain_uuid = check_str($_REQUEST["id"]);
}
else {
$action = "add";
}
}
//get http post variables and set them to php variables
@@ -573,17 +580,23 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
//redirect the browser
if ($action == "update") {
$_SESSION["message"] = $text['message-update'];
if (!permission_exists('domain_add')) { //admin, updating own domain
header("Location: domain_edit.php");
}
else {
header("Location: domains.php"); //superadmin
}
}
if ($action == "add") {
$_SESSION["message"] = $text['message-add'];
header("Location: domains.php");
}
header("Location: domains.php");
return;
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
//pre-populate the form
if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
//pre-populate the form (admin won't have domain_add permissions, but domain_uuid will already be set above)
if ((count($_GET) > 0 || (!permission_exists('domain_add') && $domain_uuid != '')) && $_POST["persistformvar"] != "true") {
$sql = "select * from v_domains ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
@@ -619,7 +632,9 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
}
echo "</b></td>\n";
echo "<td width='70%' align='right' valign='top'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='domains.php'\" value='".$text['button-back']."'>\n";
if (permission_exists('domain_add')) { //only for superadmin, not admin editing their own domain
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='domains.php'\" value='".$text['button-back']."'>\n";
}
if (permission_exists('domain_export')) {
echo " <input type='button' class='btn' name='' alt='".$text['button-export']."' onclick=\"window.location='".PROJECT_PATH."/app/domain_export/index.php?id=".$domain_uuid."'\" value='".$text['button-export']."'>\n";
}
+93 -46
View File
@@ -38,6 +38,25 @@ else {
$language = new text;
$text = $language->get();
//retrieve allowed setting categories
if (!permission_exists('domain_setting_category_edit')) {
if (is_array($_SESSION['settings']) && sizeof($_SESSION['settings']) > 0) {
foreach ($_SESSION['groups'] as $index => $group) {
$group_name = $group['group_name'];
if (is_array($_SESSION['settings'][$group_name]) && sizeof($_SESSION['settings'][$group_name]) > 0) {
foreach ($_SESSION['settings'][$group_name] as $category) {
$categories[] = strtolower($category);
}
}
}
}
if (is_array($categories) && sizeof($categories) > 0) {
$allowed_categories = array_unique($categories);
sort($allowed_categories, SORT_NATURAL);
}
unset($group, $group_name, $index, $category, $categories);
}
//action add or update
if (isset($_REQUEST["id"])) {
$action = "update";
@@ -71,12 +90,12 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
}
//check for all required data
//if (strlen($domain_setting_category) == 0) { $msg .= $text['message-required'].$text['label-category']."<br>\n"; }
//if (strlen($domain_setting_subcategory) == 0) { $msg .= $text['message-required'].$text['label-subcategory']."<br>\n"; }
//if (strlen($domain_setting_name) == 0) { $msg .= $text['message-required'].$text['label-type']."<br>\n"; }
if (strlen($domain_setting_category) == 0) { $msg .= $text['message-required'].$text['label-category']."<br>\n"; }
if (strlen($domain_setting_subcategory) == 0) { $msg .= $text['message-required'].$text['label-subcategory']."<br>\n"; }
if (strlen($domain_setting_name) == 0) { $msg .= $text['message-required'].$text['label-type']."<br>\n"; }
//if (strlen($domain_setting_value) == 0) { $msg .= $text['message-required'].$text['label-value']."<br>\n"; }
//if (strlen($domain_setting_order) == 0) { $msg .= $text['message-required'].$text['label-order']."<br>\n"; }
//if (strlen($domain_setting_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."<br>\n"; }
if (strlen($domain_setting_order) == 0) { $msg .= $text['message-required'].$text['label-order']."<br>\n"; }
if (strlen($domain_setting_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."<br>\n"; }
//if (strlen($domain_setting_description) == 0) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
require_once "resources/header.php";
@@ -358,7 +377,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo $text['description-domain_setting-edit'];
}
if ($action == "add") {
echo $text['header-domain_setting-add'];
echo $text['description-domain_setting-add'];
}
echo "<br /><br />\n";
echo "</td>\n";
@@ -369,18 +388,31 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo " ".$text['label-category']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='domain_setting_category' maxlength='255' value=\"$domain_setting_category\">\n";
if (permission_exists('domain_setting_category_edit')) {
echo " <input type='text' class='formfld' name='domain_setting_category' id='domain_setting_category' maxlength='255' value=\"".$domain_setting_category."\">\n";
}
else {
echo " <select class='formfld' name='domain_setting_category' id='domain_setting_category' onchange=\"$('#domain_setting_subcategory').focus();\">\n";
echo " <option value=''></option>\n";
if (is_array($allowed_categories) && sizeof($allowed_categories) > 0) {
foreach ($allowed_categories as $category) {
$selected = ($domain_setting_category == $category) ? 'selected' : null;
echo " <option value='".$category."' ".$selected.">".ucwords(str_replace('_',' ',$category))."</option>\n";
}
}
echo " </select>";
}
echo "<br />\n";
echo $text['description-category']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-subcategory']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='domain_setting_subcategory' maxlength='255' value=\"$domain_setting_subcategory\">\n";
echo " <input class='formfld lowercase' type='text' name='domain_setting_subcategory' id='domain_setting_subcategory' maxlength='255' value=\"$domain_setting_subcategory\">\n";
echo "<br />\n";
echo $text['description-subcategory']."\n";
echo "</td>\n";
@@ -391,7 +423,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo " ".$text['label-type']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='domain_setting_name' maxlength='255' value=\"$domain_setting_name\">\n";
echo " <input class='formfld lowercase' type='text' name='domain_setting_name' id='domain_setting_name' maxlength='255' value=\"$domain_setting_name\">\n";
echo "<br />\n";
echo $text['description-type']."\n";
echo "</td>\n";
@@ -424,7 +456,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
}
unset ($sub_prep_statement);
echo " </select>\n";
} elseif ($category == "domain" && $subcategory == "template" && $name == "name" ) {
}
elseif ($category == "domain" && $subcategory == "template" && $name == "name" ) {
echo " <select id='domain_setting_value' name='domain_setting_value' class='formfld' style=''>\n";
echo " <option value=''></option>\n";
//add all the themes to the list
@@ -445,7 +478,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
closedir($handle);
}
echo " </select>\n";
} elseif ($category == "domain" && $subcategory == "language" && $name == "code" ) {
}
elseif ($category == "domain" && $subcategory == "language" && $name == "code" ) {
echo " <select id='domain_setting_value' name='domain_setting_value' class='formfld' style=''>\n";
echo " <option value=''></option>\n";
foreach ($_SESSION['app']['languages'] as $key => $value) {
@@ -457,7 +491,8 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
}
}
echo " </select>\n";
} elseif ($category == "domain" && $subcategory == "time_zone" && $name == "name" ) {
}
elseif ($category == "domain" && $subcategory == "time_zone" && $name == "name" ) {
echo " <select id='domain_setting_value' name='domain_setting_value' class='formfld' style=''>\n";
echo " <option value=''></option>\n";
//$list = DateTimeZone::listAbbreviations();
@@ -541,12 +576,14 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo " <option value='fine' ".(($row['default_setting_value'] == 'fine') ? 'selected' : null).">".$text['label-fine']."</option>";
echo " <option value='superfine' ".(($row['default_setting_value'] == 'superfine') ? 'selected' : null).">".$text['label-superfine']."</option>";
echo " </select>";
} elseif ($category == "theme" && $subcategory == "domain_visible" && $name == "text" ) {
}
elseif ($category == "theme" && $subcategory == "domain_visible" && $name == "text" ) {
echo " <select class='formfld' name='default_setting_value'>\n";
echo " <option value='false' ".(($row['default_setting_value'] == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
echo " <option value='true' ".(($row['default_setting_value'] == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
echo " </select>\n";
} elseif ($category == "theme" && $subcategory == "cache" && $name == "boolean" ) {
}
elseif ($category == "theme" && $subcategory == "cache" && $name == "boolean" ) {
echo " <select class='formfld' name='default_setting_value'>\n";
echo " <option value='true' ".(($row['default_setting_value'] == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
echo " <option value='false' ".(($row['default_setting_value'] == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
@@ -559,40 +596,44 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo $text['description-value']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
if ($name == "array" || $name == '') {
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap' width='30%'>\n";
echo " ".$text['label-order']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select name='domain_setting_order' class='formfld'>\n";
$i=0;
while($i<=999) {
$selected = ($i == $domain_setting_order) ? "selected" : null;
if (strlen($i) == 1) {
echo " <option value='00$i' ".$selected.">00$i</option>\n";
}
if (strlen($i) == 2) {
echo " <option value='0$i' ".$selected.">0$i</option>\n";
}
if (strlen($i) == 3) {
echo " <option value='$i' ".$selected.">$i</option>\n";
}
$i++;
}
echo " </select>\n";
echo " <br />\n";
echo $text['description-order']."\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<div id='tr_order' ".(($domain_setting_name != 'array') ? "style='display: none;'" : null).">\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-order']."\n";
echo "</td>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <select name='domain_setting_order' class='formfld'>\n";
$i=0;
while($i<=999) {
$selected = ($i == $domain_setting_order) ? "selected" : null;
if (strlen($i) == 1) {
echo " <option value='00$i' ".$selected.">00$i</option>\n";
}
if (strlen($i) == 2) {
echo " <option value='0$i' ".$selected.">0$i</option>\n";
}
if (strlen($i) == 3) {
echo " <option value='$i' ".$selected.">$i</option>\n";
}
$i++;
}
echo " </select>\n";
echo " <br />\n";
echo $text['description-order']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap>\n";
echo " ".$text['label-enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <select class='formfld' name='domain_setting_enabled'>\n";
if ($domain_setting_enabled == "true") {
echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
@@ -642,12 +683,18 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo " $(window).keypress(function(event){\n";
echo " if (event.which == 13) { submit_form(); }\n";
echo " });\n";
// convert password fields to
//hide/convert password fields then submit form
echo " function submit_form() {\n";
echo " $('input:password').css('visibility','hidden');\n";
echo " $('input:password').attr({type:'text'});\n";
echo " $('form#frm').submit();\n";
echo " }\n";
//define lowercase class
echo " $('.lowercase').blur(function(){ this.value = this.value.toLowerCase(); });";
//show order if array
echo " $('#domain_setting_name').keyup(function(){ \n";
echo " (this.value.toLowerCase() == 'array') ? $('#tr_order').slideDown('fast') : $('#tr_order').slideUp('fast');\n";
echo " });\n";
echo "</script>\n";
//include the footer
+2 -11
View File
@@ -255,16 +255,7 @@ if (sizeof($_REQUEST) > 1) {
} //end if results
echo "<tr>\n";
if (
(permission_exists("domain_select") && permission_exists("domain_setting_add") && count($_SESSION['domains']) > 1) ||
permission_exists("domain_delete")
) {
$colspan = 7;
}
else {
$colspan = 6;
}
echo "<td colspan='".$colspan."' align='left'>\n";
echo "<td colspan='20' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
@@ -274,7 +265,7 @@ if (sizeof($_REQUEST) > 1) {
echo "<a href='domain_setting_edit.php?domain_uuid=".check_str($_GET['id'])."' alt='".$text['button-add']."'>$v_link_label_add</a>";
}
if (permission_exists('domain_setting_delete') && $result_count > 0) {
echo "<a href='javascript:void(0);' onclick=\"if (confirm('".$text['confirm-delete']."')) { document.getElementById('action').value = 'delete'; document.getElementById('domain_frm').submit(); }\" alt='".$text['button-delete']."'>".$v_link_label_delete."</a>";
echo "<a href='javascript:void(0);' onclick=\"if (confirm('".$text['confirm-delete']."')) { document.getElementById('action').value = 'delete'; document.getElementById('domain_frm').submit(); }\" alt='".$text['button-delete']."'>".$v_link_label_delete."</a>";
}
echo " </td>\n";
echo " </tr>\n";
+14 -7
View File
@@ -26,13 +26,20 @@
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
if (permission_exists('domain_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//redirect admin to app instead
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/domains/") && !permission_exists('domain_parent') && permission_exists('domain_descendants')) {
header("Location: ".PROJECT_PATH."/app/domains/domains.php");
}
//check permission
if (permission_exists('domain_view')) {
//access granted
}
else {
echo "access denied";
exit;
}
//add multi-lingual support
$language = new text;