Commit 78db6ba1 authored by fettesvieh's avatar fettesvieh

introduced first part of finder grained access system

parent 280ddf86
......@@ -12,14 +12,24 @@
</p>
<dl>
{foreach from=$mod_list item=mod}
<dt><label for="module-{$mod.dir}">{$mod.name}</label></dt>
<dt><label for="access-read-{$mod.dir}">{$mod.name}</label></dt>
<dd>
<select name="form[modules][{$mod.dir}]" id="module-{$mod.dir}">
<option value="">{lang values="common|pls_select"}</option>
{foreach from=$mod.options item=row}
<option value="{$row.value}"{$row.selected}>{$row.lang}</option>
{/foreach}
</select>
<label for="access-read-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][read]" id="access-read-{$mod.dir}" value="1" class="checkbox"{$mod.read_checked} />
{lang values="access|can_read"}
</label>
<label for="access-write-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][write]" id="access-write-{$mod.dir}" value="2" class="checkbox"{$mod.write_checked} />
{lang values="access|can_write"}
</label>
<label for="access-edit-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][edit]" id="access-edit-{$mod.dir}" value="4" class="checkbox"{$mod.edit_checked} />
{lang values="access|can_edit"}
</label>
<label for="access-delete-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][delete]" id="access-delete-{$mod.dir}" value="8" class="checkbox"{$mod.delete_checked} />
{lang values="access|can_delete"}
</label>
</dd>
{/foreach}
</dl>
......
......@@ -12,14 +12,24 @@
</p>
<dl>
{foreach from=$mod_list item=mod}
<dt><label for="module-{$mod.dir}">{$mod.name}</label></dt>
<dt><label for="access-read-{$mod.dir}">{$mod.name}</label></dt>
<dd>
<select name="form[modules][{$mod.dir}]" id="module-{$mod.dir}">
<option value="">{lang values="common|pls_select"}</option>
{foreach from=$mod.options item=row}
<option value="{$row.value}"{$row.selected}>{$row.lang}</option>
{/foreach}
</select>
<label for="access-read-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][read]" id="access-read-{$mod.dir}" value="1" class="checkbox"{$mod.read_checked} />
{lang values="access|can_read"}
</label>
<label for="access-write-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][write]" id="access-write-{$mod.dir}" value="2" class="checkbox"{$mod.write_checked} />
{lang values="access|can_write"}
</label>
<label for="access-edit-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][edit]" id="access-edit-{$mod.dir}" value="4" class="checkbox"{$mod.edit_checked} />
{lang values="access|can_edit"}
</label>
<label for="access-delete-{$mod.dir}">
<input type="checkbox" name="form[modules][{$mod.dir}][delete]" id="access-delete-{$mod.dir}" value="8" class="checkbox"{$mod.delete_checked} />
{lang values="access|can_delete"}
</label>
</dd>
{/foreach}
</dl>
......
......@@ -186,7 +186,7 @@ CREATE TABLE `{pre}users` (
PRIMARY KEY (`id`)
) {engine};
INSERT INTO `{pre}access` VALUES ('1', 'Administrator', 'users:2,feeds:2,files:2,emoticons:2,errors:2,gallery:2,guestbook:2,categories:2,comments:2,contact:2,menu_items:2,news:2,newsletter:2,static_pages:2,search:2,system:2,polls:2,access:2,acp:2,captcha:2');
INSERT INTO `{pre}access` VALUES ('1', 'Administrator', 'users:15,feeds:15,files:15,emoticons:15,errors:15,gallery:15,guestbook:15,categories:15,comments:15,contact:15,menu_items:15,news:15,newsletter:15,static_pages:15,search:15,system:15,polls:15,access:15,acp:15,captcha:15');
INSERT INTO `{pre}access` VALUES ('2', 'Besucher', 'users:1,feeds:1,files:1,emoticons:1,errors:1,gallery:1,guestbook:1,categories:1,comments:1,contact:1,menu_items:1,news:1,newsletter:1,static_pages:1,search:1,system:0,polls:1,access:0,acp:0,captcha:1');
INSERT INTO `{pre}access` VALUES ('3', 'Benutzer', 'users:1,feeds:1,files:1,emoticons:1,errors:1,gallery:1,guestbook:1,categories:1,comments:1,contact:1,menu_items:1,news:1,newsletter:1,static_pages:1,search:1,system:0,polls:1,access:0,acp:0,captcha:1');
INSERT INTO `{pre}categories` VALUES ('', 'Erste Kategorie', '', 'Dies ist die erste Kategorie', 'news');
......
......@@ -32,6 +32,22 @@
<name>access_to_following_modules</name>
<message>Zugriff auf die Module</message>
</item>
<item>
<name>can_delete</name>
<message>Löschen</message>
</item>
<item>
<name>can_edit</name>
<message>Bearbeiten</message>
</item>
<item>
<name>can_read</name>
<message>Lesen</message>
</item>
<item>
<name>can_write</name>
<message>Schreiben</message>
</item>
<item>
<name>create</name>
<message>Neuen Zugriffslevel erstellen</message>
......
......@@ -32,6 +32,22 @@
<name>access_to_following_modules</name>
<message>Access to modules</message>
</item>
<item>
<name>can_delete</name>
<message>Delete</message>
</item>
<item>
<name>can_edit</name>
<message>Edit</message>
</item>
<item>
<name>can_read</name>
<message>Read</message>
</item>
<item>
<name>can_write</name>
<message>Write</message>
</item>
<item>
<name>create</name>
<message>Create a new access level</message>
......
......@@ -17,8 +17,6 @@ if (isset($_POST['submit'])) {
$errors[] = $lang->t('common', 'name_to_short');
if (!empty($form['name']) && $db->countRows('*', 'access', 'name = \'' . $db->escape($form['name']) . '\'') == '1')
$errors[] = $lang->t('access', 'access_level_already_exist');
if (emptyCheck($form['modules']))
$errors[] = $lang->t('access', 'select_modules');
if (isset($errors)) {
$tpl->assign('error_msg', comboBox($errors));
......@@ -43,13 +41,11 @@ if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
if ($info['dir'] == 'errors' || !$info['active']) {
unset($mod_list[$name]);
} else {
for ($i = 0; $i < 3; ++$i) {
$mod_list[$name]['options'][$i] = array(
'value' => $i,
'selected' => selectAccessLevel($info['dir'], (string) $i),
'lang' => $lang->t('access', 'access_level_' . $i),
);
}
$dir = $info['dir'];
$mod_list[$name]['read_checked'] = isset($form['modules'][$dir]['read']) ? ' checked="checked"' : '';
$mod_list[$name]['write_checked'] = isset($form['modules'][$dir]['write']) ? ' checked="checked"' : '';
$mod_list[$name]['edit_checked'] = isset($form['modules'][$dir]['edit']) ? ' checked="checked"' : '';
$mod_list[$name]['delete_checked'] = isset($form['modules'][$dir]['delete']) ? ' checked="checked"' : '';
}
}
$tpl->assign('mod_list', $mod_list);
......
......@@ -18,8 +18,6 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'access', 'id = \'' . $u
$errors[] = $lang->t('common', 'name_to_short');
if (!empty($form['name']) && $db->countRows('*', 'access', 'id != \'' . $uri->id . '\' AND name = \'' . $db->escape($form['name']) . '\'') == '1')
$errors[] = $lang->t('access', 'access_level_already_exist');
if (emptyCheck($form['modules']))
$errors[] = $lang->t('access', 'select_modules');
if (isset($errors)) {
$tpl->assign('error_msg', comboBox($errors));
......@@ -47,19 +45,43 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'access', 'id = \'' . $u
if ($info['dir'] == 'errors' || !$info['active']) {
unset($mod_list[$name]);
} else {
$db_value = '';
for ($i = 0; $i < $c_mods_arr; ++$i) {
if ($info['dir'] == substr($mods_arr[$i], 0, -2)) {
$db_value = substr($mods_arr[$i], -1, 1);
break;
$dir = $info['dir'];
if (isset($form['modules'])) {
$mod_list[$name]['read_checked'] = isset($form['modules'][$dir]['read']) ? ' checked="checked"' : '';
$mod_list[$name]['write_checked'] = isset($form['modules'][$dir]['write']) ? ' checked="checked"' : '';
$mod_list[$name]['edit_checked'] = isset($form['modules'][$dir]['edit']) ? ' checked="checked"' : '';
$mod_list[$name]['delete_checked'] = isset($form['modules'][$dir]['delete']) ? ' checked="checked"' : '';
} else {
$db_value = '';
for ($i = 0; $i < $c_mods_arr; ++$i) {
$pos = strrpos($mods_arr[$i], ':');
if ($info['dir'] == substr($mods_arr[$i], 0, $pos)) {
$db_value = substr($mods_arr[$i], $pos + 1);
break;
}
}
$mod_list[$name]['read_checked'] = '';
$mod_list[$name]['write_checked'] = '';
$mod_list[$name]['edit_checked'] = '';
$mod_list[$name]['delete_checked'] = '';
if ($db_value - 8 >= 0) {
$mod_list[$name]['delete_checked'] = ' checked="checked"';
$db_value-= 8;
}
if ($db_value - 4 >= 0) {
$mod_list[$name]['edit_checked'] = ' checked="checked"';
$db_value-= 4;
}
if ($db_value - 2 >= 0) {
$mod_list[$name]['write_checked'] = ' checked="checked"';
$db_value-= 2;
}
if ($db_value - 1 >= 0) {
$mod_list[$name]['read_checked'] = ' checked="checked"';
$db_value-= 1;
}
}
for ($i = 0; $i < 3; ++$i) {
$mod_list[$name]['options'][$i] = array(
'value' => $i,
'selected' => selectAccessLevel($info['dir'], (string) $i, $db_value),
'lang' => $lang->t('access', 'access_level_' . $i),
);
}
}
}
......
<?php
/**
* Access
*
* @author Goratsch Webdesign
* @package ACP3
* @subpackage Modules
/**
* Access
*
* @author Goratsch Webdesign
* @package ACP3
* @subpackage Modules
*/
if (!defined('IN_ADM'))
exit();
/**
* Baut den String den zu erstellenden / verändernden Zugriffslevel zusammen
*
* @param array $uri
* @return string
*/
function buildAccessLevel($uri)
{
if (!empty($uri) && is_array($uri)) {
$uri['errors'] = '2';
ksort($uri);
$access_level = '';
foreach ($uri as $module => $level) {
$access_level.= $module . ':' . $level . ',';
}
return substr($access_level, 0, -1);
}
return '';
}
/**
* Überprüft, ob zumindest ein Module ausgewählt wurde
*
* @param array $uri
* @return boolean
/**
* Baut den String den zu erstellenden / verändernden Zugriffslevel zusammen
*
* @param array $modules
* @return string
*/
function emptyCheck($uri) {
if (!empty($uri) && is_array($uri)) {
foreach ($uri as $key) {
if (!empty($key)) {
return false;
}
function buildAccessLevel($modules)
{
if (!empty($modules) && is_array($modules)) {
$modules['errors'] = array('read' => 1, 'write' => 2, 'edit' => 4, 'delete' => 8);
ksort($modules);
$access_level = '';
foreach ($modules as $mod => $levels) {
$level = 0;
$level+= isset($levels['read']) ? 1 : 0;
$level+= isset($levels['write']) ? 2 : 0;
$level+= isset($levels['edit']) ? 4 : 0;
$level+= isset($levels['delete']) ? 8 : 0;
$access_level.= $mod . ':' . $level . ',';
}
return substr($access_level, 0, -1);
}
return true;
}
/**
* Im Falle eines Fehlers im Formular, werden die ausgewählten Zugriffslevel selektiert
*
* @param string $dir
* @param integer $value
* @param integer $db_value
* @return string
*/
function selectAccessLevel($dir, $value, $db_value = '')
{
$selected = ' selected="selected"';
if (isset($_POST['form']['modules'][$dir]) && $_POST['form']['modules'][$dir] == $value) {
return $selected;
} elseif ($db_value != '' && $db_value == $value) {
return $selected;
}
return '';
return '';
}
?>
\ No newline at end of file
......@@ -12,7 +12,7 @@ require ACP3_ROOT . 'includes/classes/db.php';
$queries = array(
'ALTER TABLE `{pre}access` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT',
'UPDATE `{pre}access` SET modules = "users:2,feeds:2,files:2,emoticons:2,errors:2,gallery:2,guestbook:2,categories:2,comments:2,contact:2,menu_items:2,news:2,newsletter:2,static_pages:2,search:2,system:2,polls:2,access:2,acp:2,captcha:2" WHERE id = 1',
'UPDATE `{pre}access` SET modules = "users:15,feeds:15,files:15,emoticons:15,errors:15,gallery:15,guestbook:15,categories:15,comments:15,contact:15,menu_items:15,news:15,newsletter:15,static_pages:15,search:15,system:15,polls:15,access:15,acp:15,captcha:15" WHERE id = 1',
'UPDATE `{pre}access` SET modules = "users:1,feeds:1,files:1,emoticons:1,errors:1,gallery:1,guestbook:1,categories:1,comments:1,contact:1,menu_items:1,news:1,newsletter:1,static_pages:1,search:1,system:0,polls:1,access:0,acp:0,captcha:1" WHERE id = 2',
'UPDATE `{pre}access` SET modules = "users:1,feeds:1,files:1,emoticons:1,errors:1,gallery:1,guestbook:1,categories:1,comments:1,contact:1,menu_items:1,news:1,newsletter:1,static_pages:1,search:1,system:0,polls:1,access:0,acp:0,captcha:1" WHERE id = 3',
'ALTER TABLE `{pre}categories` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT',
......
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