Exemple #1
0
function show_step1()
{
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    $usergroups = $usersgroupsList->search();
    if (!is_array($usergroups)) {
        $usergroups = array();
        popup_error(_("Failed to get User Group data"));
    }
    uasort($usergroups, "usergroup_cmp");
    $searchDiv = $usersgroupsList->getForm();
    $has_usergroups = count($usergroups) > 0;
    $usergroup_selected = false;
    if (!isset($_SESSION['wizard']['use_users'])) {
        $usergroup_selected = true;
    } elseif ($_SESSION['wizard']['use_users'] == 'usergroups') {
        $usergroup_selected = true;
    }
    $users = array();
    $sizelimit_exceeded = false;
    $res = $_SESSION['service']->users_list_partial('', array('login'));
    // todo manage wsdl to be able to send no/void argument to this request
    if ($res !== null) {
        foreach ($res['data'] as $item_id => $item) {
            $user = new User($item);
            if (!$user->is_valid()) {
                continue;
            }
            $users[] = $user;
        }
        uasort($users, "user_cmp");
        $sizelimit_exceeded = $res['partial'];
    }
    $applications = $_SESSION['service']->applications_list();
    if (!count($users)) {
        popup_error(_('No available users'));
    }
    if (!count($applications)) {
        popup_error(_('No available applications'));
    }
    if ($sizelimit_exceeded) {
        popup_error(_('Unable to display the list of users: too many users'));
        $users = array();
    }
    page_header();
    echo '<div>';
    echo '<h1><a href="wizard.php">' . _('Publication Wizard') . '</a> - ' . _('Select User Groups') . '</h1>';
    echo '<form action="" method="post">';
    echo '<input type="hidden" name="from" value="step1" />';
    echo '<table class="" id="wizard_list_table" border="0" cellspacing="1" cellpadding="5">';
    if ($has_usergroups) {
        echo '<tr class="title">';
        echo '<th>';
        if (userdb_is_writable() && count($users) > 0) {
            echo '<input class="input_radio" type="radio" name="use" value="users" onclick="$(\'wizard_usergroups_list_table\').hide(); $(\'wizard_users_list_table\').show()"';
            if (!$usergroup_selected) {
                echo ' checked="checked"';
            }
            echo '/>' . _('Create a new User Group');
        }
        echo '</th>';
        echo '<th><input class="input_radio" type="radio" name="use" value="usergroups" onclick="$(\'wizard_users_list_table\').hide(); $(\'wizard_usergroups_list_table\').show()"';
        if ($usergroup_selected) {
            echo ' checked="checked"';
        }
        echo '/> ' . _('Use existing User Groups') . '</th>';
        echo '</tr>';
    } else {
        echo '<input type="hidden" name="use" value="users" />';
    }
    echo '<tr>';
    echo '<td>';
    if (userdb_is_writable()) {
        $count = 0;
        echo '<table class="main_sub"';
        if ($has_usergroups) {
            if ($usergroup_selected) {
                echo ' style="display: none" ';
            }
        }
        echo 'id="wizard_users_list_table" border="0" cellspacing="1" cellpadding="5">';
        foreach ($users as $user) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<td colspan="2"><input class="input_checkbox" type="checkbox" name="users[]" value="' . $user->getAttribute('login') . '"';
            if (isset($_SESSION['wizard']['users']) && in_array($user->getAttribute('login'), $_SESSION['wizard']['users'])) {
                echo ' checked="checked"';
            }
            echo '/> <a href="users.php?action=manage&id=' . $user->getAttribute('login') . '">' . $user->getAttribute('displayname') . '</a></td>';
            echo '</tr>';
        }
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '"><td colspan="2"><a href="javascript:;" onclick="markAllRows(\'wizard_users_list_table\'); return false">' . _('Mark all') . '</a> / <a href="javascript:;" onclick="unMarkAllRows(\'wizard_users_list_table\'); return false">' . _('Unmark all') . '</a></td></tr>';
        echo '</table>';
        echo '</td>';
    }
    echo '<td>';
    if ($has_usergroups) {
        $count = 0;
        echo '<table class="main_sub"';
        if (!$usergroup_selected) {
            echo ' style="display: none;" ';
        }
        echo 'id="wizard_usergroups_list_table" border="0" cellspacing="1" cellpadding="5">';
        foreach ($usergroups as $usergroup) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<td><input class="input_checkbox" type="checkbox" name="usergroups[]" value="' . $usergroup->id . '" /> <a href="usersgroup.php?action=manage&id=' . $usergroup->id . '">' . $usergroup->name . '</a></td>';
            echo '</tr>';
        }
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '"><td><a href="javascript:;" onclick="markAllRows(\'wizard_usergroups_list_table\'); return false">' . _('Mark all') . '</a> / <a href="javascript:;" onclick="unMarkAllRows(\'wizard_usergroups_list_table\'); return false">' . _('Unmark all') . '</a></td></tr>';
        echo '</table>';
        echo $searchDiv;
    }
    echo '</td>';
    echo '</tr>';
    echo '<tr>';
    echo '<td style="text-align: right;" colspan="2">';
    echo '<input type="submit" name="submit_next" value="' . _('Next') . '" />';
    echo '</td>';
    echo '</tr>';
    echo '</table>';
    echo '</form>';
    echo '</div>';
    page_footer();
    die;
}
Exemple #2
0
function show_manage($sharedfolder_id_)
{
    $sharedfolder = $group = $_SESSION['service']->shared_folder_info($sharedfolder_id_);
    if (is_null($sharedfolder)) {
        popup_error(sprintf(_("Failed to import shared folder '%s'"), $sharedfolder_id_));
        redirect('sharedfolders.php');
    }
    $server_displayname = $sharedfolder->server;
    $server = $_SESSION['service']->server_info($sharedfolder->server);
    if (!is_null($server)) {
        $server_displayname = $server->getDisplayName();
    }
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    $all_groups = $usersgroupsList->search();
    if (!is_array($all_groups)) {
        $all_groups = array();
        popup_error(_("Failed to get User Group data"));
    }
    uasort($all_groups, "usergroup_cmp");
    $searchDiv = $usersgroupsList->getForm();
    $available_groups = array();
    $used_groups = array();
    if ($sharedfolder->hasAttribute('groups')) {
        $used_groups = array();
        $mods_by_group = array();
        $groups2 = $sharedfolder->getAttribute('groups');
        foreach ($groups2 as $mode => $groups3) {
            foreach ($groups3 as $group_id => $group_name) {
                $used_groups[$group_id] = $group_name;
                $mods_by_group[$group_id] = $mode;
            }
        }
    }
    foreach ($all_groups as $group) {
        if (array_key_exists($group->id, $used_groups) === false) {
            $available_groups[$group->id] = $group;
        }
    }
    $can_manage_sharedfolders = isAuthorized('manageSharedFolders');
    page_header();
    echo '<div id="sharedfolders_div">';
    echo '<h1>' . $sharedfolder->name . '</h1>';
    echo '<div>';
    echo '<h2>' . _('Server') . '</h2>';
    echo '<a href="servers.php?action=manage&id=' . $sharedfolder->server . '"> ' . $server_displayname . '</a>';
    echo '</div>';
    echo '<br />';
    echo '<div>';
    echo '<h2>' . _('Configuration') . '</h2>';
    echo '<table>';
    echo '<tr><td>';
    echo _('Name') . ': ';
    echo '</td><td>';
    if ($can_manage_sharedfolders) {
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="SharedFolder" />';
        echo '<input type="hidden" name="action" value="rename" />';
        echo '<input type="hidden" name="id" value="' . $sharedfolder->id . '" />';
    }
    echo '<input type="text" name="sharedfolder_name" value="' . $sharedfolder->name . '" />';
    if ($can_manage_sharedfolders) {
        echo ' <input type="submit" value="' . _('Rename') . '" />';
        echo '</form>';
    }
    echo '</td></tr>';
    echo '</table>';
    echo '</div>';
    echo '<br />';
    echo '<div>';
    echo '<h2>' . _('Publications') . '</h2>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($used_groups as $group_id => $group_name) {
        echo '<tr>';
        echo '<td><a href="usersgroup.php?action=manage&amp;id=' . $group_id . '">' . $group_name . '</a></td>';
        echo '<td>' . $mods_by_group[$group_id] . '</td>';
        if ($can_manage_sharedfolders) {
            echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this shared folder access?') . '\');">';
            echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder->id . '" />';
            echo '<input type="hidden" name="usergroup_id" value="' . $group_id . '" />';
            echo '<input type="submit" value="' . _('Delete access to this shared folder') . '" />';
            echo '</form></td>';
        }
        echo '</tr>';
    }
    if (count($available_groups) > 0 and $can_manage_sharedfolders) {
        echo '<tr><form action="actions.php" method="post"><td>';
        echo '<input type="hidden" name="name" value="SharedFolder_ACL" />';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="sharedfolder_id" value="' . $sharedfolder->id . '" />';
        echo '<select name="usergroup_id">';
        foreach ($available_groups as $group) {
            echo '<option value="' . $group->id . '" >' . $group->name . '</option>';
        }
        echo '</select>';
        echo '</td><td>';
        echo '<select name="mode">';
        echo '<option value="rw" >' . _('Read-write') . '</option>';
        echo '<option value="ro" >' . _('Read only') . '</option>';
        echo '</select>';
        echo '</td><td><input type="submit" value="' . _('Add access to this shared folder') . '" /></td>';
        echo '</form></tr>';
    }
    echo '</table>';
    echo $searchDiv;
    echo '</div>';
    echo '</div>';
    page_footer();
}
Exemple #3
0
function show_manage($script_id_)
{
    $script = $_SESSION['service']->script_info($script_id_);
    if (!is_object($script)) {
        redirect('script.php');
    }
    $can_manage_script = isAuthorized('manageNews');
    page_header();
    echo '<div id="script_div">';
    echo '<h1><a href="?">' . _('Login Script management') . '</a> - ' . $script->name . '</h1>';
    echo '<div>';
    echo '<h2>' . _('Modify') . '</h2>';
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    if ($can_manage_script) {
        $os_options = array("Windows", "Linux");
        $type_options = array("bash", "python", "VBS", "batch", "powershell");
        echo '<form action="script.php" method="post" enctype="multipart/form-data">';
        echo '<input type="hidden" name="action" value="rename" />';
        echo '<input type="hidden" name="id" value="' . $script->id . '" />';
        echo '<tr><td><strong>' . _('Name:') . '</strong></td><td><input type="text" name="script_name" value="' . $script->name . '" /></td></tr>';
        echo '<tr><td><strong>' . _('OS:') . '</strong></td><td><select name="script_os">';
        foreach ($os_options as $os_option) {
            echo '<option value="' . $os_option . '" ';
            if ($os_option == $script->os) {
                echo 'selected="selected"';
            }
            echo '/>' . $os_option . '</option>';
        }
        echo '</select></td></tr>';
        echo '<tr><td><strong>' . _('Type:') . '</strong></td><td><select name="script_type" onchange="changeScriptAreaSyntax(this, \'scriptArea\')">';
        foreach ($type_options as $type_option) {
            echo '<option value="' . $type_option . '" ';
            if ($type_option == $script->type) {
                echo 'selected="selected"';
            }
            echo '/>' . $type_option . '</option>';
        }
        echo '</select></td></tr>';
        echo '<tr><td></td><td><textarea name="script_data" id=\'scriptArea\' cols="100" rows="20">' . $script->data . '</textarea></td></tr>';
        echo '<script language="javascript" type="text/javascript"> initScriptArea(\'scriptArea\') </script>';
        echo '<tr><td colspan="2">';
        echo '<input type="file"  name="script_file" onchange="loadFileAsText(this,\'scriptArea\')"/><BR/>';
        echo '<input type="submit" value="' . _('Modify') . '" /></td></tr>';
        echo '</form>';
    }
    echo '</table>';
    echo '</div>';
    // User groups part
    $groups_mine = $script->getAttribute('groups');
    $groups_partial_list = $script->getAttribute('groups_partial_list');
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    if ($groups_partial_list) {
        if ($usersgroupsList->is_empty_filter()) {
            $usersgroupsList->set_external_result($groups_mine, true);
        } else {
            $groups_mine2 = $usersgroupsList->search($login);
            if (is_null($groups_mine)) {
                die_error(_('Error while requesting User Group data'), __FILE__, __LINE__);
            }
            $groups_mine = array();
            foreach ($groups_mine2 as $group) {
                $groups_mine[$group->id] = $group->name;
            }
        }
    }
    // do not request other groups if we do not display the 'add to' panel ...
    $groups_all = $usersgroupsList->search();
    usort($groups_all, "usergroup_cmp");
    $searchDiv = $usersgroupsList->getForm();
    $groups_available = array();
    foreach ($groups_all as $group) {
        if (!array_key_exists($group->id, $groups_mine)) {
            $groups_available[] = $group;
        }
    }
    echo '<div>';
    echo '<h2>' . _('User Groups with this user') . '</h2>';
    echo $searchDiv;
    echo '<table border="0" cellspacing="1" cellpadding="3">';
    foreach ($groups_mine as $group_id => $group_name) {
        echo '<tr><td>';
        if ($can_manage_script) {
            echo '<a href="usersgroup.php?action=manage&id=' . $group_id . '">' . $group_name . '</a>';
        } else {
            echo $group_name;
        }
        echo '</td>';
        if ($can_manage_script) {
            echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user from this group?') . '\');">';
            echo '<input type="hidden" name="name" value="Script_UserGroup" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="hidden" name="group" value="' . $group_id . '" />';
            echo '<input type="hidden" name="element" value="' . $script->id . '" />';
            echo '<input type="submit" value="' . _('Delete from this group') . '" />';
            echo '</form></td>';
        }
        echo '</tr>';
    }
    if (count($groups_available) > 0 and $can_manage_script) {
        echo '<tr><form action="actions.php" method="post"><td>';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="name" value="Script_UserGroup" />';
        echo '<input type="hidden" name="element" value="' . $script->id . '" />';
        echo '<select name="group">';
        foreach ($groups_available as $group) {
            echo '<option value="' . $group->id . '" >' . $group->name . '</option>';
        }
        echo '</select>';
        echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
    }
    echo '</form></tr>';
    echo '</table>';
    echo '</div>';
    echo '</div>';
    page_footer();
}
Exemple #4
0
function show_default()
{
    global $schedules;
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    $groups = $usersgroupsList->search();
    if (is_array($groups)) {
        uasort($groups, "usergroup_cmp");
    }
    $searchDiv = $usersgroupsList->getForm();
    $has_group = !(is_null($groups) or count($groups) == 0);
    $can_manage_usersgroups = isAuthorized('manageUsersGroups');
    page_header();
    echo '<div id="usersgroup_div" >';
    echo '<h1>' . _('User Groups') . '</h1>';
    echo $searchDiv;
    echo '<div id="usersgroup_list">';
    if (!$has_group) {
        echo _('No available User Groups') . '<br />';
    } else {
        $all_static = true;
        foreach ($groups as $group) {
            if ($group->type != 'static' || usergroupdb_is_writable()) {
                $all_static = false;
                break;
                // no need to continue;
            }
        }
        echo '<table class="main_sub sortable" id="usergroups_list" border="0" cellspacing="1" cellpadding="5">';
        echo '<thead>';
        echo '<tr class="title">';
        if (!$all_static || usergroupdb_is_writable() and $can_manage_usersgroups and count($groups) > 1) {
            echo '<th class="unsortable"></th>';
            // masse action
        }
        echo '<th>' . _('Name') . '</th>';
        echo '<th>' . _('Description') . '</th>';
        echo '<th>' . _('Status') . '</th>';
        echo '<th>' . _('Type') . '</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
        $count = 0;
        foreach ($groups as $group) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            if ($group->published) {
                $publish = '<span class="msg_ok">' . _('Enabled') . '</span>';
            } else {
                $publish = '<span class="msg_error">' . _('Blocked') . '</span>';
            }
            echo '<tr class="' . $content . '">';
            if ($can_manage_usersgroups) {
                if ($group->type != 'static' || usergroupdb_is_writable() and count($groups) > 1) {
                    echo '<td><input class="input_checkbox" type="checkbox" name="checked_groups[]" value="' . $group->id . '" /></td>';
                } else {
                    if (!$all_static and count($groups) > 1) {
                        echo '<td></td>';
                    }
                }
            }
            echo '<td><a href="?action=manage&id=' . $group->id . '">' . $group->name . '</a></td>';
            echo '<td>' . $group->description . '</td>';
            echo '<td class="centered">' . $publish . '</td>';
            echo '<td class="centered">' . $group->type . '</td>';
            if ($group->type != 'static' || usergroupdb_is_writable() and $can_manage_usersgroups) {
                echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this group?') . '\');">';
                echo '<input type="hidden" name="name" value="UserGroup" />';
                echo '<input type="submit" value="' . _('Delete') . '"/>';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="checked_groups[]" value="' . $group->id . '" />';
                echo '</form></td>';
            } else {
                if (!$all_static and $can_manage_usersgroups) {
                    echo '<td></td>';
                }
            }
            echo '</tr>';
        }
        echo '</tbody>';
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        if (!$all_static || usergroupdb_is_writable() and $can_manage_usersgroups and count($groups) > 1) {
            echo '<tfoot>';
            echo '<tr class="' . $content . '">';
            echo '<td colspan="5"><a href="javascript:;" onclick="markAllRows(\'usergroups_list\'); return false">' . _('Mark all') . '</a> / <a href="javascript:;" onclick="unMarkAllRows(\'usergroups_list\'); return false">' . _('Unmark all') . '</a></td>';
            echo '<td>';
            echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete these groups?') . '\') && updateMassActionsForm(this, \'usergroups_list\');">';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="del" />';
            echo '<input type="submit" value="' . _('Delete') . '"/>';
            echo '</form>';
            echo '</td>';
            echo '</tr>';
            echo '</tfoot>';
        }
        echo '</table>';
    }
    echo '</div>';
    $usergroup_types = array();
    if (usergroupdb_is_writable()) {
        $usergroup_types = array('static' => _('Static'));
    }
    if (is_module_enabled('UserGroupDBDynamic') || is_module_enabled('UserGroupDBDynamicCached')) {
        $usergroup_types['dynamic'] = _('Dynamic');
    }
    if ($can_manage_usersgroups && $usergroup_types != array()) {
        echo '<div>';
        echo '<h2>' . _('Create a new group') . '</h2>';
        $first_type = array_keys($usergroup_types);
        $first_type = $first_type[0];
        $usergroup_types2 = $usergroup_types;
        // bug in php 5.1.6 (redhat 5.2)
        foreach ($usergroup_types as $type => $name) {
            echo '<input class="input_radio" type="radio" name="type" value="' . $type . '" onclick="';
            foreach ($usergroup_types2 as $type2 => $name2) {
                // bug in php 5.1.6
                if ($type == $type2) {
                    echo '$(\'table_' . $type2 . '\').show(); ';
                } else {
                    echo '$(\'table_' . $type2 . '\').hide(); ';
                }
            }
            echo '"';
            if ($type == $first_type) {
                echo ' checked="checked"';
            }
            echo ' />';
            echo $name;
        }
        foreach ($usergroup_types as $type => $name) {
            $count = 2;
            echo '<form action="actions.php" method="post">';
            echo '<table id="table_' . $type . '"';
            if ($type != $first_type) {
                echo ' style="display: none" ';
            } else {
                echo ' style="display: visible" ';
            }
            echo ' border="0" class="main_sub" cellspacing="1" cellpadding="5" >';
            echo '<input type="hidden" name="name" value="UserGroup" />';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="type" value="' . $type . '" />';
            echo '<tr class="content' . ($count++ % 2 == 0 ? 1 : 2) . '">';
            echo '<th>' . _('Name') . '</th>';
            echo '<td><input type="text" name="name_group" value="" /></td>';
            echo '</tr>';
            echo '<tr class="content' . ($count++ % 2 == 0 ? 1 : 2) . '">';
            echo '<th>' . _('Description') . '</th>';
            echo '<td><input type="text" name="description_group" value="" /></td>';
            echo '</tr>';
            if (str_startswith($type, 'dynamic')) {
                echo '<tr class="content' . ($count++ % 2 == 0 ? 1 : 2) . '">';
                echo '<th>' . _('Cached') . '</th>';
                echo '<td>';
                echo '<input type="radio" name="cached" value="0" checked="checked" onclick="$(\'schedule_select\').hide();" /> ' . _('No');
                if (is_module_enabled('UserGroupDBDynamicCached')) {
                    echo '<input type="radio" name="cached" value="1" onclick="$(\'schedule_select\').show();" /> ' . _('Yes');
                    echo ' <span id="schedule_select" style="display: none;"><br />' . _('Time between two updates:') . ' <select name="schedule">';
                    foreach ($schedules as $interval => $text) {
                        echo '<option value="' . $interval . '">' . $text . '</option>';
                    }
                    echo '</select></span>';
                }
                echo '</td>';
                echo '</tr>';
                echo '<tr class="content' . ($count++ % 2 == 0 ? 1 : 2) . '">';
                echo '<th>' . _('Validation type') . '</th>';
                echo '<td><input type="radio" name="validation_type" value="and" checked="checked" /> ' . _('All') . ' <input type="radio" name="validation_type" value="or" /> ' . _('At least one') . '</td>';
                echo '</tr>';
                echo '<tr class="content' . ($count++ % 2 == 0 ? 1 : 2) . '">';
                echo '<th>' . _('Filters') . '</th>';
                echo '<td>';
                $i = 0;
                $filter_attributes = array('login', 'displayname');
                foreach ($filter_attributes as $key1 => $value1) {
                    if ($value1 == 'password') {
                        unset($filter_attributes[$key1]);
                    }
                }
                $filter_types = array('equal', 'not_equal', 'contains', 'not_contains', 'startswith', 'not_startswith', 'endswith', 'not_endswith');
                echo '<table border="0" cellspacing="1" cellpadding="3">';
                echo '<tr>';
                echo '<td><select name="rules[0][attribute]">';
                foreach ($filter_attributes as $filter_attribute) {
                    echo '<option value="' . $filter_attribute . '">' . $filter_attribute . '</option>';
                }
                echo '</select></td>';
                echo '<td><select name="rules[0][type]">';
                foreach ($filter_types as $filter_type) {
                    echo '<option value="' . $filter_type . '">' . $filter_type . '</option>';
                }
                echo '</select></td>';
                echo '<td><input type="text" name="rules[0][value]" value="" /></td>';
                echo '<td><input style="display: none;" type="button" onclick="del_field(this.parentNode.parentNode); return false;" value="-" /><input type="button" onclick="add_field(this.parentNode.parentNode); return false;" value="+" /></td>';
                echo '</tr>';
                echo '</table>';
                echo '</td>';
                echo '</tr>';
            }
            echo '<tr class="content1">';
            echo '<td class="centered" colspan="2"><input type="submit" value="' . _('Add') . '" /></td>';
            echo '</tr>';
            echo '</table>';
            echo '</form>';
        }
        echo '</div>';
    }
    //if ($can_manage_usersgroups)
    echo '</div>';
    page_footer();
    die;
}
Exemple #5
0
function show_manage($login)
{
    $u = $_SESSION['service']->user_info($login);
    if (!is_object($u)) {
        die_error('Unable to import user "' . $login . '"', __FILE__, __LINE__);
    }
    $userdb_rw = userdb_is_writable();
    $usergroupdb_rw = usergroupdb_is_writable();
    $keys = array();
    foreach ($u->getAttributesList() as $attr) {
        if (!in_array($attr, array('login', 'displayname'))) {
            $keys[] = $attr;
        }
    }
    // Users Group
    $groups_mine = $u->getAttribute('groups');
    $groups_partial_list = $u->getAttribute('groups_partial_list');
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    if ($groups_partial_list) {
        if ($usersgroupsList->is_empty_filter()) {
            $usersgroupsList->set_external_result($groups_mine, true);
        } else {
            $groups_mine2 = $usersgroupsList->search($login);
            if (is_null($groups_mine)) {
                die_error(_('Error while requesting User Group data'), __FILE__, __LINE__);
            }
            $groups_mine = array();
            foreach ($groups_mine2 as $group) {
                $groups_mine[$group->id] = $group->name;
            }
        }
    }
    uasort($groups_mine, 'usergroup_cmp');
    $groups_available = array();
    $default_group_id = null;
    if ($usergroupdb_rw) {
        // do not request other groups if we do not display the 'add to' panel ...
        $groups_all = $usersgroupsList->search();
        usort($groups_all, "usergroup_cmp");
        foreach ($groups_all as $group) {
            if (!array_key_exists($group->id, $groups_mine)) {
                $groups_available[] = $group;
            }
            if ($group->isDefault()) {
                $default_group_id = $group->id;
            }
        }
    }
    uasort($groups_available, 'usergroup_cmp');
    // need to be after all search call!
    $searchDiv = $usersgroupsList->getForm();
    $can_manage_users = isAuthorized('manageUsers');
    $can_manage_usersgroups = isAuthorized('manageUsersGroups');
    $can_manage_profiles = isAuthorized('manageSharedFolders');
    $prefs_of_a_user = array();
    $unuse_settings = array();
    $session_prefs = array();
    if ($u->hasAttribute('settings_default')) {
        $prefs = new Preferences_admin(null, false);
        $categs = $u->getAttribute('settings_default');
        $categs2 = array();
        if ($u->hasAttribute('settings')) {
            $categs2 = $u->getAttribute('settings');
        }
        foreach ($categs as $categ => $settings) {
            $session_prefs[$categ] = array();
            $prefs_of_a_user[$categ] = array();
            $unuse_settings[$categ] = array();
            foreach ($settings as $setting_id => $setting_attributes) {
                $p = $prefs->load_element($setting_attributes, 'general_' . $categ);
                $session_prefs[$categ][$setting_id] = $p;
                if (array_key_exists($categ, $categs2) && array_key_exists($setting_id, $categs2[$categ])) {
                    $p2 = clone $p;
                    $p2->content = $categs2[$categ][$setting_id];
                    $prefs_of_a_user[$categ][$setting_id] = $p2;
                } else {
                    $unuse_settings[$categ][$setting_id] = $p;
                }
            }
        }
    }
    $applications = array();
    if ($u->hasAttribute('applications')) {
        $applications = $u->getAttribute('applications');
        uasort($applications, 'application_cmp');
    }
    page_header();
    echo '<div id="users_div">';
    echo '<h1>' . $u->getAttribute('displayname') . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
    echo '<tr class="title">';
    echo '<th>' . _('Login') . '</th>';
    echo '<th>' . _('Locale') . '</th>';
    echo '</tr>';
    echo '<tr class="content1">';
    echo '<td>' . $u->getAttribute('login') . '</td>';
    echo '<td>' . $u->getAttribute('locale') . '</td>';
    echo '</tr>';
    echo '</table>';
    if ($userdb_rw and $can_manage_users) {
        echo '<div>';
        echo '<h2>' . _('Settings') . '</h2>';
        echo '<div>';
        echo '<form action="actions.php" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user?') . '\');">';
        echo '<input type="submit" value="' . _('Delete this user') . '"/>';
        echo '<input type="hidden" name="name" value="User" />';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="checked_users[]" value="' . htmlspecialchars($login) . '" />';
        echo '</form>';
        echo '</div>';
        echo '<br/><br/>';
        echo '<div>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="User" />';
        echo '<input type="hidden" name="action" value="modify" />';
        echo '<input type="hidden" name="id" value="' . htmlspecialchars($login) . '" />';
        echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="5">';
        $count = 0;
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '">';
        echo '<th>' . _('Display name') . '</th>';
        echo '<td><input type="text" name="displayname" value="' . htmlspecialchars($u->getAttribute('displayname')) . '" /></td>';
        echo '</tr>';
        if ($u->hasAttribute('password')) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            echo '<tr class="' . $content . '">';
            echo '<th>' . _('New password') . '</th>';
            echo '<td><input type="password" name="password" value="" /></td>';
            echo '</tr>';
        }
        $content = 'content' . ($count % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '">';
        echo '<td colspan="2">';
        echo '<input type="submit" name="modify" value="' . _('Save changes') . '" />';
        echo '</td>';
        echo '</tr>';
        echo '</table>';
        echo '</form>';
        echo '</div>';
    }
    // User groups part
    if (count($groups_mine) > 0 or !$usersgroupsList->is_empty_filter() or $usergroupdb_rw and count($groups_all) > 0) {
        echo '<div>';
        echo '<h2>' . _('User Groups with this user') . '</h2>';
        echo $searchDiv;
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($groups_mine as $group_id => $group_name) {
            echo '<tr><td>';
            if ($can_manage_usersgroups) {
                echo '<a href="usersgroup.php?action=manage&id=' . $group_id . '">' . $group_name . '</a>';
            } else {
                echo $group_name;
            }
            echo '</td>';
            if ($usergroupdb_rw and $can_manage_usersgroups and $group_id != $default_group_id) {
                echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this user from this group?') . '\');">';
                echo '<input type="hidden" name="name" value="User_UserGroup" />';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="group" value="' . $group_id . '" />';
                echo '<input type="hidden" name="element" value="' . htmlspecialchars($login) . '" />';
                echo '<input type="submit" value="' . _('Delete from this group') . '" />';
                echo '</form></td>';
            }
            echo '</tr>';
        }
        if (count($groups_available) > 0 && $usergroupdb_rw and $can_manage_usersgroups) {
            echo '<tr><form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="User_UserGroup" />';
            echo '<input type="hidden" name="element" value="' . htmlspecialchars($login) . '" />';
            echo '<select name="group">';
            foreach ($groups_available as $group) {
                echo '<option value="' . $group->id . '" >' . $group->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo "</div>\n";
    }
    $apps_s = array();
    if (count($applications) > 0) {
        echo '<br />';
        echo '<h2>' . _('Published Applications') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($applications as $application_id => $application_name) {
            echo '<tr>';
            echo '<td><img class="icon32" src="media/image/cache.php?id=' . $application_id . '" alt="" title="" /></td>';
            echo '<td><a href="applications.php?action=manage&id=' . $application_id . '">' . $application_name . '</a></td>';
            echo '</tr>';
        }
        echo '</table>';
    }
    echo '<h2>';
    echo _('Session Settings configuration');
    echo '</h2>';
    if ($prefs_of_a_user != array()) {
        foreach ($prefs_of_a_user as $container => $prefs_of_a_user_value) {
            echo '<fieldset class="prefssessionusergroup">';
            echo '<legend>' . $prefs->getPrettyName('general_' . $container) . '</legend>';
            echo '<form action="actions.php" method="post">';
            $key_name = 'general';
            echo '<input type="hidden" name="container" value="' . $container . '" />';
            // from admin/functions.inc.php
            $color = 0;
            if (count($prefs_of_a_user_value) != 0) {
                echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3" style="margin-bottom: 10px;">';
                // TODO
                echo '<tr  class="title">';
                echo '<th>' . _('Name') . '</th>';
                echo '<th>' . _('Default value') . '</th>';
                echo '<th>' . _('Value') . '</th>';
                echo '<th>' . _('Action') . '</th>';
                echo '<tr>';
                foreach ($prefs_of_a_user_value as $element_key => $config_element) {
                    echo '<tr class="content' . ($color % 2 + 1) . '">';
                    echo '<td style="width: 250px;">';
                    echo '<span onmouseover="showInfoBulle(\'' . str_replace("'", "&rsquo;", $config_element->description_detailed) . '\'); return false;" onmouseout="hideInfoBulle(); return false;">' . $config_element->label . '</span>';
                    echo '<td>';
                    $default_element = $session_prefs[$container][$config_element->id];
                    $default_element->setFormSeparator('NaN');
                    // it must be different of ___
                    $default_element->setPath(array('key_name' => $key_name, 'container' => $container, 'element_id' => $config_element->id));
                    echo $default_element->toHTML(true);
                    echo '</td>';
                    echo '</td>';
                    echo '<td style="padding: 3px;">';
                    print_element($key_name, $container, $element_key, $config_element);
                    echo '</td>';
                    echo '<td>';
                    echo '<input type="button" value="' . _('Remove this overridden setting') . '" onclick="user_settings_remove(\'' . $u->getAttribute('login') . '\',\'' . $container . '\',\'' . $config_element->id . '\'); return false;"/>';
                    echo '</td>';
                    echo '</tr>';
                    $color++;
                }
                // end from
                echo '<tr class="content' . ($color % 2 + 1) . '">';
                echo '<td colspan="3"></td>';
                echo '<td>';
                echo '<input type="hidden" name="name" value="User_settings" />';
                echo '<input type="hidden" name="container" value="' . $container . '" />';
                echo '<input type="hidden" name="unique_id" value="' . $u->getAttribute('login') . '" />';
                echo '<input type="hidden" name="action" value="modify" />';
                echo '<input type="submit" value="' . _('Save settings') . '" />';
                echo '</td>';
                echo '</tr>';
                echo '</table>';
                echo '</form>';
            }
            if ($unuse_settings[$container] != array()) {
                echo '<form action="actions.php" method="post">';
                echo '<input type="hidden" name="name" value="User_settings" />';
                echo '<input type="hidden" name="container" value="' . $container . '" />';
                echo '<input type="hidden" name="unique_id" value="' . $u->getAttribute('login') . '" />';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<select name="element_id">';
                foreach ($unuse_settings[$container] as $setting_name => $setting_content) {
                    echo '<option value="' . $setting_name . '" >' . $setting_content->label . '</option>';
                }
                echo '</select>';
                echo ' ';
                echo '<input type="submit" value="' . _('Add this setting') . '" />';
                echo '</form>';
            }
            echo '</fieldset>';
        }
    }
    echo '</div>';
    // Session settings configuration
    echo "\n\n\n";
    if ($u->hasAttribute('sessions') && count($u->getAttribute('sessions')) > 0) {
        echo '<div>';
        echo '<h2>' . _('Active sessions') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        foreach ($u->getAttribute('sessions') as $session_id => $session_start_time) {
            echo '<tr>';
            echo '<td>';
            if (!$session_start_time) {
                echo _('Not started yet');
            } else {
                echo @date('d/m/Y H:i:s', $session_start_time);
            }
            echo '</td>';
            echo '<td><a href="sessions.php?info=' . $session_id . '">' . $session_id . '</td>';
            echo '<td></td>';
            echo '<td>';
            echo '<form action="sessions.php">';
            echo '<input type="hidden" name="info" value="' . $session_id . '" />';
            echo '<input type="submit" value="' . _('Information about this session') . '" />';
            echo '</form>';
            echo '</td>';
            echo '</tr>';
        }
        echo '</table>';
        echo '</div>';
    }
    $use_profiles = false;
    $settings = $u->getAttribute('settings');
    $settings = $settings['session_settings_defaults'];
    if (array_key_exists('enable_profiles', $settings)) {
        if ($settings['enable_profiles']['value'] == 1) {
            $use_profiles = true;
        }
    } else {
        $settings = $u->getAttribute('settings_default');
        $settings = $settings['session_settings_defaults'];
        if (array_key_exists('enable_profiles', $settings)) {
            if ($settings['enable_profiles']['value'] == 1) {
                $use_profiles = true;
            }
        }
    }
    if ($use_profiles) {
        echo '<div>';
        echo '<h2>' . _('Profile') . '</h2>';
        if (!$u->hasAttribute('profiles')) {
            echo '<p>';
            echo _('This user doesn\'t have a user profile');
            echo '</p>';
            if ($can_manage_profiles) {
                echo '<div>';
                echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to create a profile for this user?') . '\');">';
                echo '<input type="hidden" name="name" value="Profile" />';
                echo '<input type="hidden" name="action" value="add" />';
                echo '<input type="hidden" name="users[]" value="' . $u->getAttribute('login') . '" />';
                echo '<input type="submit" value="' . _('Create a profile') . '" />';
                echo '</form>';
                echo '</div>';
            }
        } else {
            foreach ($u->getAttribute('profiles') as $profile_id => $profile_info) {
                echo '<p>';
                echo str_replace('%SERVER%', '<a href="servers.php?action=manage&id=' . $profile_info['server_id'] . '"> ' . $profile_info['server_name'] . '</a>', _('User has profile stored on server %SERVER%.'));
                echo '</p>';
                if ($can_manage_profiles) {
                    echo '<div>';
                    echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this profile?') . '\');">';
                    echo '<input type="hidden" name="name" value="Profile" />';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="ids[]" value="' . $profile_id . '" />';
                    echo '<input type="submit" value="' . _('Delete this profile') . '" />';
                    echo '</form>';
                    echo '</div>';
                }
            }
        }
        echo '</div>';
    }
    echo '</div>';
    page_footer();
    die;
}
Exemple #6
0
function show_manage($id)
{
    $group = $_SESSION['service']->applications_group_info($id);
    if (!is_object($group)) {
        popup_error(_('Unable to import group'));
        redirect();
    }
    if ($group->published) {
        $status = '<span class="msg_ok">' . _('Enabled') . '</span>';
        $status_change = _('Block');
        $status_change_value = 0;
    } else {
        $status = '<span class="msg_error">' . _('Blocked') . '</span>';
        $status_change = _('Enable');
        $status_change_value = 1;
    }
    $applications_all = $_SESSION['service']->applications_list();
    $applications_id = array();
    if ($group->hasAttribute('applications')) {
        $applications_id = $group->getAttribute('applications');
    }
    $applications = array();
    $applications_available = array();
    foreach ($applications_all as $application) {
        if (!in_array($application->getAttribute('id'), $applications_id)) {
            $applications_available[] = $application;
        } else {
            $applications[] = $application;
        }
    }
    uasort($applications, "application_cmp");
    uasort($applications_available, "application_cmp");
    // Publications
    $groups_users = array();
    if ($group->hasAttribute('usersgroups')) {
        $groups_users = $group->getAttribute('usersgroups');
        uasort($groups_users, "usergroup_cmp");
    }
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    $groups_users_all = $usersgroupsList->search();
    if (!is_array($groups_users_all)) {
        $groups_users_all = array();
        popup_error(_("Failed to get User Group data"));
    }
    uasort($groups_users_all, "usergroup_cmp");
    $searchDiv = $usersgroupsList->getForm();
    $groups_users_available = array();
    foreach ($groups_users_all as $group_users) {
        if (!array_key_exists($group_users->id, $groups_users)) {
            $groups_users_available[] = $group_users;
        }
    }
    $can_manage_applicationsgroups = isAuthorized('manageApplicationsGroups');
    $can_manage_publications = isAuthorized('managePublications');
    page_header();
    echo '<div>';
    echo '<h1><a href="?">' . _('Application Group management') . '</a> - ' . $group->name . '</h1>';
    echo '<table class="main_sub" border="0" cellspacing="1" cellpadding="3">';
    echo '<tr class="title">';
    echo '<th>' . _('Description') . '</th>';
    echo '<th>' . _('Status') . '</th>';
    echo '</tr>';
    echo '<tr class="content1">';
    echo '<td>' . $group->description . '</td>';
    echo '<td>' . $status . '</td>';
    echo '</tr>';
    echo '</table>';
    if ($can_manage_applicationsgroups) {
        echo '<div>';
        echo '<h2>' . _('Settings') . '</h2>';
        echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this group?') . '\');">';
        echo '<input type="submit" value="' . _('Delete this group') . '"/>';
        echo '<input type="hidden" name="name" value="ApplicationsGroup" />';
        echo '<input type="hidden" name="action" value="del" />';
        echo '<input type="hidden" name="checked_groups[]" value="' . $id . '" />';
        echo '<input type="hidden" name="id" value="' . $id . '" />';
        echo '</form>';
        echo '<br/>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="ApplicationsGroup" />';
        echo '<input type="hidden" name="action" value="modify" />';
        echo '<input type="hidden" name="id" value="' . $id . '" />';
        echo '<input type="hidden" name="published_appsgroup" value="' . $status_change_value . '" />';
        echo '<input type="submit" value="' . $status_change . '"/>';
        echo '</form>';
        echo '<br/>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="ApplicationsGroup" />';
        echo '<input type="hidden" name="action" value="modify" />';
        echo '<input type="hidden" name="id" value="' . $id . '" />';
        echo '<input type="text" name="name_appsgroup"  value="' . $group->name . '" size="50" /> ';
        echo '<input type="submit" value="' . _('Update the name') . '"/>';
        echo '</form>';
        echo '<br/>';
        echo '<form action="actions.php" method="post">';
        echo '<input type="hidden" name="name" value="ApplicationsGroup" />';
        echo '<input type="hidden" name="action" value="modify" />';
        echo '<input type="hidden" name="id" value="' . $id . '" />';
        echo '<input type="text" name="description_appsgroup"  value="' . $group->description . '" size="50" /> ';
        echo '<input type="submit" value="' . _('Update the description') . '"/>';
        echo '</form>';
        echo '<br/>';
    }
    // Application part
    if (count($applications_all) > 0 and $can_manage_applicationsgroups or count($applications) > 0) {
        echo '<div>';
        echo '<h2>' . _('List of applications in this group') . '</h2>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        if (count($applications) > 0) {
            foreach ($applications as $application) {
                echo '<tr>';
                echo '<td><img class="icon32" src="media/image/cache.php?id=' . $application->getAttribute('id') . '" alt="' . $application->getAttribute('name') . '" title="' . $application->getAttribute('name') . '" /> <a href="applications.php?action=manage&id=' . $application->getAttribute('id') . '">' . $application->getAttribute('name') . '</a>';
                echo '</td>';
                if ($can_manage_applicationsgroups) {
                    echo '<td>';
                    echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this application?') . '\');">';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
                    echo '<input type="hidden" name="group" value="' . $id . '" />';
                    echo '<input type="hidden" name="element" value="' . $application->getAttribute('id') . '" />';
                    echo '<input type="submit" value="' . _('Delete from this group') . '" />';
                    echo '</form>';
                    echo '</td>';
                }
                echo '</tr>';
            }
        }
        if (count($applications_available) > 0 and $can_manage_applicationsgroups) {
            echo '<tr><form action="actions.php" method="post"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
            echo '<input type="hidden" name="group" value="' . $id . '" />';
            echo '<select name="element">';
            foreach ($applications_available as $application) {
                echo '<option value="' . $application->getAttribute('id') . '" >' . $application->getAttribute('name') . ' (' . $application->getAttribute('type') . ')</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add to this group') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo '</div>';
    }
    /*
      // Servers
      echo '<div>';
      echo '<h2>'._('List of servers including this group').'</h2>';
      echo '<table border="0" cellspacing="1" cellpadding="3">';
      if (count($servers) == 0)
        echo '<tr><td colspan="2">'._('No server has this group').'</td></tr>';
      else {
        foreach($servers as $server) {
          echo '<tr>';
          echo '<td><a href="servers.php?action=manage&id='.$server->id.'">'.$server->getDisplayName().'</a>';
          echo '</td>';
          echo '<td>';
          echo '<form action="actions.php" method="post" onsubmit="return confirm(\''._('Are you sure you want to delete this group from this server?').'\');">';
          echo '<input type="hidden" name="action" value="del" />';
          echo '<input type="hidden" name="name" value="ApplicationGroup_Server" />';
          echo '<input type="hidden" name="group" value="'.$id.'" />';
          echo '<input type="hidden" name="server" value="'.$server->id.'" />';
          echo '<input type="submit" value="'._('Delete from this group').'" /> FIXME';
          echo '</form>';
          echo '</td>';
          echo '</tr>';
        }
      }
      if (count ($servers_available) ==0)
        echo '<tr><td colspan="2">'._('Not any available server to add').'</td></tr>';
      else {
        echo '<tr><form action="actions.php" method="post"><td>';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="name" value="Application_ApplicationGroup" />';
        echo '<input type="hidden" name="group" value="'.$id.'" />';
        echo '<select name="element">';
        foreach($servers_available as $servers)
          echo '<option value="'.$server->id.'" >'.$server->getDisplayName().'</option>';
        echo '</select>';
        echo '</td><td><input type="submit" value="'._('Add to this server').'" /></td>';
        echo '</form></tr>';
      }
      echo '</table>';
      echo '</div>';
    */
    // Publication part
    if (count($groups_users_all) > 0) {
        echo '<div>';
        echo '<h2>' . _('List of publications for this group') . '</h1>';
        echo '<table border="0" cellspacing="1" cellpadding="3">';
        if (count($groups_users) > 0) {
            foreach ($groups_users as $group_users_id => $group_users_name) {
                echo '<tr>';
                echo '<td><a href="usersgroup.php?action=manage&id=' . $group_users_id . '">' . $group_users_name . '</td>';
                if ($can_manage_publications) {
                    echo '<td>';
                    echo '<form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this publication?') . '\');">';
                    echo '<input type="hidden" name="action" value="del" />';
                    echo '<input type="hidden" name="name" value="Publication" />';
                    echo '<input type="hidden" name="group_a" value="' . $id . '" />';
                    echo '<input type="hidden" name="group_u" value="' . $group_users_id . '" />';
                    echo '<input type="submit" value="' . _('Delete this publication') . '" />';
                    echo '</form>';
                    echo '</td>';
                }
                echo '</tr>';
            }
        }
        if (count($groups_users_available) > 0 and $can_manage_publications) {
            echo '<tr><form action="actions.php" method="get"><td>';
            echo '<input type="hidden" name="action" value="add" />';
            echo '<input type="hidden" name="name" value="Publication" />';
            echo '<input type="hidden" name="group_a" value="' . $id . '" />';
            echo '<select name="group_u">';
            foreach ($groups_users_available as $group_users) {
                echo '<option value="' . $group_users->id . '" >' . $group_users->name . '</option>';
            }
            echo '</select>';
            echo '</td><td><input type="submit" value="' . _('Add this publication') . '" /></td>';
            echo '</form></tr>';
        }
        echo '</table>';
        echo $searchDiv;
        echo '</div>';
    }
    echo '</div>';
    echo '</div>';
    echo '</div>';
    page_footer();
    die;
}
Exemple #7
0
function show_default()
{
    $publications = array();
    $groups_apps = $_SESSION['service']->applications_groups_list();
    if (is_null($groups_apps)) {
        $groups_apps = array();
    }
    foreach ($groups_apps as $i => $group_apps) {
        if (!$group_apps->published) {
            unset($groups_apps[$i]);
        }
        $group_apps2 = $_SESSION['service']->applications_group_info($group_apps->id);
        if (is_null($group_apps2)) {
            unset($groups_apps[$i]);
        }
        $groups_apps[$i] = $group_apps2;
    }
    $usersgroupsList = new UsersGroupsList($_REQUEST);
    $groups_users = $usersgroupsList->search();
    if (!is_array($groups_users)) {
        $groups_users = array();
        popup_error(_("Failed to get User Groups list"));
    }
    uasort($groups_users, "usergroup_cmp");
    $searchDiv = $usersgroupsList->getForm();
    foreach ($groups_users as $i => $group_users) {
        if (!$group_users->published) {
            unset($groups_users[$i]);
        }
    }
    // Starts from the applications groups instead of users groups because
    // it's possible to not be able to have the complete users groups list (LDAP)
    foreach ($groups_apps as $group_apps) {
        if (!$group_apps->hasAttribute('usersgroups')) {
            continue;
        }
        foreach ($group_apps->getAttribute('usersgroups') as $group_users_id => $group_users_name) {
            $group_users = $_SESSION['service']->users_group_info($group_users_id);
            if (is_null($group_users)) {
                continue;
            }
            if (!$group_users->published) {
                continue;
            }
            $publications[] = array('user' => $group_users, 'app' => $group_apps);
        }
    }
    $has_publish = count($publications);
    $can_add_publish = true;
    if (count($groups_users) == 0) {
        $can_add_publish = false;
    } elseif (count($groups_apps) == 0) {
        $can_add_publish = false;
    } elseif (count($groups_users) * count($groups_apps) <= count($publications)) {
        $can_add_publish = false;
    }
    $servers_groups = $_SESSION['service']->servers_groups_list();
    $publication_servers = array();
    foreach ($servers_groups as $servers_group_id => $servers_group) {
        $servers_group = $_SESSION['service']->servers_group_info($servers_group_id);
        if (!is_object($servers_group)) {
            continue;
        }
        if (!$servers_group->published) {
            continue;
        }
        if (!$servers_group->hasAttribute('usersgroups')) {
            continue;
        }
        foreach ($servers_group->getAttribute('usersgroups') as $users_group_id => $users_group_name) {
            $users_group = $_SESSION['service']->users_group_info($users_group_id);
            if (is_null($users_group)) {
                continue;
            }
            if (!$users_group->published) {
                continue;
            }
            $publication_servers[] = array('user' => $users_group, 'server' => $servers_group);
        }
    }
    $count = 0;
    $can_manage_publications = isAuthorized('managePublications');
    page_header(array('js_files' => array('media/script/publication.js')));
    echo '<div>';
    echo '<h1>' . _('Publications') . '</h1>';
    echo '<table class="main_sub sortable" id="publications_list_table" border="0" cellspacing="1" cellpadding="5">';
    echo '<thead>';
    echo '<tr class="title">';
    echo '<th>' . _('User Group') . '</th>';
    echo '<th>' . _('Application Group') . '</th>';
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';
    if (!$has_publish) {
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '"><td colspan="3">' . _('No publications') . '</td></tr>';
    } else {
        foreach ($publications as $publication) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            $group_u = $publication['user'];
            $group_a = $publication['app'];
            echo '<tr class="' . $content . '">';
            echo '<td><a href="usersgroup.php?action=manage&amp;id=' . $group_u->id . '">' . $group_u->name . '</a></td>';
            echo '<td><a href="appsgroup.php?action=manage&amp;id=' . $group_a->id . '">' . $group_a->name . '</a></td>';
            if ($can_manage_publications) {
                echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this publication?') . '\');"><div>';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="name" value="Publication" />';
                echo '<input type="hidden" name="group_a" value="' . $group_a->id . '" />';
                echo '<input type="hidden" name="group_u" value="' . $group_u->id . '" />';
                echo '<input type="submit" value="' . _('Delete') . '"/>';
                echo '</div></form></td>';
            }
            echo '</tr>';
        }
    }
    echo '</tbody>';
    $nb_groups_apps = count($groups_apps);
    $nb_groups_users = count($groups_users);
    if ($can_add_publish and $can_manage_publications) {
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tfoot>';
        echo '<tr class="' . $content . '">';
        echo '<td>';
        echo '<select id="select_group_u" name="group_u" onchange="ovdsm_publication_hook_select(this)" style="width: 100%;">';
        echo '<option value="">*</option>';
        foreach ($groups_users as $group_users) {
            if (!$group_users->hasAttribute('applicationsgroups') || count($group_users->getAttribute('applicationsgroups')) < $nb_groups_apps) {
                echo '<option value="' . $group_users->id . '" >' . $group_users->name . '</option>';
            }
        }
        echo '</select>';
        echo '</td>';
        echo '<td>';
        echo '<select id="select_group_a" name="group_a" onchange="ovdsm_publication_hook_select(this)" style="width: 100%;">';
        echo '<option value="" >*</option>';
        foreach ($groups_apps as $group_apps) {
            if (!$group_apps->hasAttribute('usersgroups') || count($group_apps->getAttribute('usersgroups')) < $nb_groups_users) {
                echo '<option value="' . $group_apps->id . '" >' . $group_apps->name . '</option>';
            }
        }
        echo '</select>';
        echo '</td><td>';
        echo '<form action="actions.php" method="post" ><div>';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="name" value="Publication" />';
        echo '<input type="hidden" name="group_u" value="" id="input_group_u" />';
        echo '<input type="hidden" name="group_a" value="" id="input_group_a" />';
        echo '<input type="button" value="' . _('Add') . '" onclick="if($(\'input_group_u\').value == \'\') {alert(\'' . addslashes(_('Please select a User Group')) . '\'); return;} if($(\'input_group_a\').value == \'\') {alert(\'' . addslashes(_('Please select an Application Group')) . '\'); return;} this.form.submit();" />';
        echo '</div></form>';
        echo '</td>';
        echo '</tr>';
        echo '</tfoot>';
    }
    echo '</table>';
    echo '<br /><br /><br />';
    echo '</div>';
    // Servers groups publication
    $count = 0;
    echo '<div>';
    echo '<h2>' . _('Server Group publications') . '</h2>';
    echo '<table class="main_sub sortable" border="0" cellspacing="1" cellpadding="5">';
    echo '<thead>';
    echo '<tr class="title">';
    echo '<th>' . _('User Group') . '</th>';
    echo '<th>' . _('Server Group') . '</th>';
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';
    if (count($publication_servers) == 0) {
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tr class="' . $content . '"><td colspan="3">' . _('No publication') . '</td></tr>';
    } else {
        foreach ($publication_servers as $publication) {
            $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
            $group_u = $publication['user'];
            $group_s = $publication['server'];
            echo '<tr class="' . $content . '">';
            echo '<td><a href="usersgroup.php?action=manage&amp;id=' . $group_u->id . '">' . $group_u->name . '</a></td>';
            echo '<td><a href="serversgroup.php?action=manage&amp;id=' . $group_s->id . '">' . $group_s->name . '</a></td>';
            if ($can_manage_publications) {
                echo '<td><form action="actions.php" method="post" onsubmit="return confirm(\'' . _('Are you sure you want to delete this publication?') . '\');"><div>';
                echo '<input type="hidden" name="action" value="del" />';
                echo '<input type="hidden" name="name" value="UsersGroupServersGroup" />';
                echo '<input type="hidden" name="servers_group" value="' . $group_s->id . '" />';
                echo '<input type="hidden" name="users_group" value="' . $group_u->id . '" />';
                echo '<input type="submit" value="' . _('Delete') . '"/>';
                echo '</div></form></td>';
            }
            echo '</tr>';
        }
    }
    echo '</tbody>';
    if ($can_manage_publications) {
        $content = 'content' . ($count++ % 2 == 0 ? 1 : 2);
        echo '<tfoot>';
        echo '<form action="actions.php" method="post" >';
        echo '<input type="hidden" name="action" value="add" />';
        echo '<input type="hidden" name="name" value="UsersGroupServersGroup" />';
        echo '<tr class="' . $content . '">';
        echo '<td>';
        echo '<select name="users_group" style="width: 100%;">';
        echo '<option value="">*</option>';
        foreach ($groups_users as $group_users) {
            echo '<option value="' . $group_users->id . '" >' . $group_users->name . '</option>';
        }
        echo '</select>';
        echo '</td>';
        echo '<td>';
        echo '<select name="servers_group" style="width: 100%;">';
        echo '<option value="" >*</option>';
        foreach ($servers_groups as $servers_group) {
            echo '<option value="' . $servers_group->id . '" >' . $servers_group->name . '</option>';
        }
        echo '</select>';
        echo '</td><td>';
        echo '<input type="submit" value="' . _('Add') . '" />';
        echo '</td>';
        echo '</tr>';
        echo '</form>';
        echo '</tfoot>';
    }
    echo '</table>';
    echo '</div>';
    echo '<br /><br /><br />';
    echo $searchDiv;
    echo '</div>';
    page_footer();
}