2017-02-08 04:29:03 +00:00
|
|
|
<?php
|
|
|
|
|
2022-02-16 04:08:28 +00:00
|
|
|
namespace Code\Module\Settings;
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 22:33:36 +00:00
|
|
|
use App;
|
2022-02-16 04:08:28 +00:00
|
|
|
use Code\Access\PermissionLimits;
|
|
|
|
use Code\Access\Permissions;
|
|
|
|
use Code\Lib\Libsync;
|
|
|
|
use Code\Lib\Permcat;
|
|
|
|
use Code\Render\Theme;
|
2022-02-12 20:43:29 +00:00
|
|
|
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
class Permcats
|
|
|
|
{
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
public function post()
|
|
|
|
{
|
2022-01-22 10:04:36 +00:00
|
|
|
//logger('$_REQUEST: ' . print_r($_REQUEST,true));
|
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if (!local_channel()) {
|
2021-12-02 23:02:31 +00:00
|
|
|
return;
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$channel = App::get_channel();
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
check_form_security_token_redirectOnErr('/settings/permcats', 'settings_permcats');
|
2017-02-08 04:29:03 +00:00
|
|
|
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$all_perms = Permissions::Perms();
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$name = escape_tags(trim($_POST['name']));
|
|
|
|
if (!$name) {
|
|
|
|
notice(t('Permission Name is required.') . EOL);
|
|
|
|
return;
|
|
|
|
}
|
2018-04-17 01:09:14 +00:00
|
|
|
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$pcarr = [];
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
if ($all_perms) {
|
|
|
|
foreach ($all_perms as $perm => $desc) {
|
|
|
|
if (array_key_exists('perms_' . $perm, $_POST)) {
|
|
|
|
$pcarr[] = $perm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
Permcat::update(local_channel(), $name, $pcarr);
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
Libsync::build_sync_packet();
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2022-01-22 10:04:36 +00:00
|
|
|
info(t('Permission role saved.') . EOL);
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-02-08 04:29:03 +00:00
|
|
|
|
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
public function get()
|
|
|
|
{
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if (!local_channel()) {
|
2022-09-04 06:28:17 +00:00
|
|
|
return '';
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$channel = App::get_channel();
|
2017-02-08 04:29:03 +00:00
|
|
|
|
|
|
|
|
2021-12-03 03:01:39 +00:00
|
|
|
if (argc() > 2) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$name = hex2bin(argv(2));
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
if (argc() > 3 && argv(3) === 'drop') {
|
|
|
|
Permcat::delete(local_channel(), $name);
|
|
|
|
Libsync::build_sync_packet();
|
|
|
|
json_return_and_die(['success' => true]);
|
|
|
|
}
|
2017-02-09 01:21:32 +00:00
|
|
|
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$desc = t('Use this form to create permission rules for various classes of people or connections.');
|
2017-02-09 01:21:32 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$existing = [];
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$pcat = new Permcat(local_channel());
|
|
|
|
$pcatlist = $pcat->listing();
|
|
|
|
$permcats = [];
|
|
|
|
if ($pcatlist) {
|
|
|
|
foreach ($pcatlist as $pc) {
|
2021-12-03 03:01:39 +00:00
|
|
|
if (($pc['name']) && ($name) && ($pc['name'] == $name)) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$existing = $pc['perms'];
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
|
|
|
if (!$pc['system']) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$permcats[bin2hex($pc['name'])] = $pc['localname'];
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2021-12-02 23:02:31 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2022-01-22 10:04:36 +00:00
|
|
|
$hidden_perms = [];
|
2021-12-02 23:02:31 +00:00
|
|
|
$global_perms = Permissions::Perms();
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
foreach ($global_perms as $k => $v) {
|
|
|
|
$thisperm = Permcat::find_permcat($existing, $k);
|
2022-01-22 10:04:36 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$checkinherited = PermissionLimits::Get(local_channel(), $k);
|
2017-02-08 04:29:03 +00:00
|
|
|
|
2022-01-22 10:04:36 +00:00
|
|
|
$inherited = (($checkinherited & PERMS_SPECIFIC) ? false : true);
|
|
|
|
|
|
|
|
$thisperm = 0;
|
|
|
|
if ($existing) {
|
|
|
|
foreach ($existing as $ex) {
|
|
|
|
if ($ex['name'] === $k) {
|
|
|
|
$thisperm = $ex['value'];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$perms[] = [ 'perms_' . $k, $v, $inherited ? 1 : intval($thisperm), '', [ t('No'), t('Yes') ], (($inherited) ? ' disabled="disabled" ' : '' )];
|
|
|
|
|
|
|
|
if ($inherited) {
|
|
|
|
$hidden_perms[] = ['perms_' . $k, 1 ];
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2021-12-02 23:02:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-01-22 10:04:36 +00:00
|
|
|
|
2022-02-12 20:43:29 +00:00
|
|
|
$tpl = Theme::get_template("settings_permcats.tpl");
|
2022-09-04 06:28:17 +00:00
|
|
|
return replace_macros($tpl, [
|
2021-12-02 23:02:31 +00:00
|
|
|
'$form_security_token' => get_form_security_token("settings_permcats"),
|
2022-01-22 10:04:36 +00:00
|
|
|
'$title' => t('Permission Roles'),
|
2021-12-02 23:02:31 +00:00
|
|
|
'$desc' => $desc,
|
2022-09-04 06:28:17 +00:00
|
|
|
'$desc2' => '',
|
|
|
|
'$tokens' => '',
|
2021-12-02 23:02:31 +00:00
|
|
|
'$permcats' => $permcats,
|
2022-09-04 06:28:17 +00:00
|
|
|
'$atoken' => '',
|
2021-12-02 23:02:31 +00:00
|
|
|
'$url1' => z_root() . '/channel/' . $channel['channel_address'],
|
|
|
|
'$url2' => z_root() . '/photos/' . $channel['channel_address'],
|
2022-09-04 06:28:17 +00:00
|
|
|
'$name' => ['name', t('Role name') . ' <span class="required">*</span>', (($name) ? $name : ''), ''],
|
2021-12-02 23:02:31 +00:00
|
|
|
'$me' => t('My Settings'),
|
|
|
|
'$perms' => $perms,
|
2022-01-22 10:04:36 +00:00
|
|
|
'$hidden_perms' => $hidden_perms,
|
2021-12-02 23:02:31 +00:00
|
|
|
'$inherited' => t('inherited'),
|
|
|
|
'$notself' => 0,
|
|
|
|
'$self' => 1,
|
|
|
|
'$permlbl' => t('Individual Permissions'),
|
2022-01-22 10:04:36 +00:00
|
|
|
'$permnote' => t('Some individual permissions may have been preset or locked based on your channel type and privacy settings.'),
|
2021-12-02 23:02:31 +00:00
|
|
|
'$submit' => t('Submit')
|
2022-09-04 06:28:17 +00:00
|
|
|
]);
|
2021-12-02 23:02:31 +00:00
|
|
|
}
|
2017-03-19 12:33:02 +00:00
|
|
|
}
|