Ejemplo n.º 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;
}
Ejemplo n.º 2
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;
}