Example #1
0
/**
 *
 **/
function manage_droplet_perms()
{
    global $parser, $settings, $val, $backend;
    $info = NULL;
    $groups = array();
    $rows = array();
    $this_user_groups = CAT_Users::get_groups_id();
    if (!CAT_Helper_Droplet::is_allowed('manage_droplet_perms', $this_user_groups)) {
        $backend->print_error($backend->lang()->translate("You don't have the permission to do this"));
    }
    $groups = CAT_Users::getGroups();
    if ($val->get('_REQUEST', 'save') || $val->get('_REQUEST', 'save_and_back')) {
        foreach ($settings as $key => $value) {
            if ($val->get('_REQUEST', $key)) {
                CAT_Helper_Droplet::updateDropletSettings($key, implode('|', $val->get('_REQUEST', $key)));
            }
        }
        // reload settings
        $settings = get_settings();
        $info = $backend->lang()->translate('Permissions saved');
        if ($val->get('_REQUEST', 'save_and_back')) {
            return list_droplets($info);
        }
    }
    foreach ($settings as $key => $value) {
        $line = array();
        foreach ($groups as $id => $name) {
            $line[] = '<input type="checkbox" name="' . $key . '[]" id="' . $key . '_' . $id . '" value="' . $id . '"' . (is_in_array($value, $id) ? ' checked="checked"' : NULL) . '>' . '<label for="' . $key . '_' . $id . '">' . $name . '</label>' . "\n";
        }
        $rows[] = array('groups' => implode('', $line), 'name' => $backend->lang()->translate($key));
    }
    // sort rows by permission name (=text)
    $array = CAT_Helper_Array::getInstance();
    $rows = $array->ArraySort($rows, 'name', 'asc', true);
    $parser->output('permissions', array('rows' => $rows, 'info' => $info));
}