steffen: server/kolab-horde-fbview/kolab-horde-fbview/fbview/admin cmdshell.php, NONE, 1.1 groups.php, NONE, 1.1 index.php, NONE, 1.1 phpshell.php, NONE, 1.1 sqlshell.php, NONE, 1.1 templates.php, NONE, 1.1 user.php, NONE, 1.1

cvs at intevation.de cvs at intevation.de
Mon Oct 31 12:43:14 CET 2005


Author: steffen

Update of /kolabrepository/server/kolab-horde-fbview/kolab-horde-fbview/fbview/admin
In directory doto:/tmp/cvs-serv18388/kolab-horde-fbview/kolab-horde-fbview/fbview/admin

Added Files:
	cmdshell.php groups.php index.php phpshell.php sqlshell.php 
	templates.php user.php 
Log Message:
Fbview in separate package

--- NEW FILE: cmdshell.php ---
<?php
/**
 * $Horde: horde/admin/cmdshell.php,v 1.8 2004/04/07 14:43:01 chuck Exp $
 *
 * Copyright 1999-2004 Chuck Hagenbuch <chuck at horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Menu.php';
require_once 'Horde/Help.php';

if (!Auth::isAdmin()) {
    Horde::fatal('Forbidden.', __FILE__, __LINE__);
}

$title = _("Command Shell");
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';

if ($command = trim(Util::getFormData('cmd'))) {
    echo '<div class="header">' . _("Command") . ':</div><br />';
    echo '<table cellpadding="4" border="0"><tr><td class="text"><code>' . nl2br(htmlspecialchars($command)) . '</code></td></tr></table>';

    echo '<br /><div class="header">' . _("Results") . ':</div><br />';
    echo '<table cellpadding="4" border="0"><tr><td class="text"><pre>';

    $cmds = explode("\n", $command);
    foreach ($cmds as $cmd) {
        $cmd = trim($cmd);
        if (strlen($cmd)) {
            unset($results);
            flush();
            echo htmlspecialchars(shell_exec($cmd));
        }
    }

    echo '</pre></td></tr></table><br />';
}
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<?php Util::pformInput() ?>
<textarea class="fixed" name="cmd" rows="10" cols="60">
<?php if (!empty($command)) echo htmlspecialchars($command) ?></textarea>
<br />
<input type="submit" class="button" value="<?php echo _("Execute") ?>">
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <?php Help::javascript(); ?>
    <td class="header" align="right"><?php echo Help::link('admin', 'admin-cmdshell') ?></td>
<?php endif; ?>

</form>
<?php

require HORDE_TEMPLATES . '/common-footer.inc';

--- NEW FILE: groups.php ---
<?php
/**
 * $Horde: horde/admin/groups.php,v 1.41 2004/04/16 22:46:55 chuck Exp $
 *
 * Copyright 1999, 2000, 2001 Chuck Hagenbuch <chuck at horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Menu.php';
require_once 'Horde/Group.php';
require_once 'Horde/Tree.php';

if (!Auth::isAdmin()) {
    Horde::authenticationFailureRedirect();
}

$groups = &Group::singleton();
$auth = &Auth::singleton($conf['auth']['driver']);

$form = null;
$reload = false;
$actionID = Util::getFormData('actionID');
switch ($actionID) {

case 'addchild':
    if (Util::getFormData('cid') == '-1') {
        $form = 'addchild.inc';
        $gname = _("All Groups");
    } else {
        $group = &$groups->getGroupById(Util::getFormData('cid'));
        if (!is_a($group, 'PEAR_Error')) {
            $gname = $group->getShortName();
            $form = 'addchild.inc';
        }
    }
    break;

case 'addchildform':
    $parent = Util::getFormData('cid');
    if ($parent == '-1') {
        $child = &$groups->newGroup(Util::getFormData('child'));
        $result = $groups->addGroup($child);
    } else {
        $pOb = &$groups->getGroupById($parent);
        $name = $pOb->getName() . ':' . DataTree::encodeName(Util::getFormData('child'));
        $child = &$groups->newGroup($name);
        $result = $groups->addGroup($child);
    }
    if (is_a($result, 'PEAR_Error')) {
        $notification->push(sprintf(_("'%s' was not created: %s."), $child->getShortName(), $result->getMessage()), 'horde.error');
    } else {
        $notification->push(sprintf(_("'%s' was added to the groups system."), $child->getShortName()), 'horde.success');
        $group = &$child;
        $form = 'edit.inc';
        $reload = true;
    }
    break;

case 'delete':
    $group = &$groups->getGroupById(Util::getFormData('cid'));
    if (!is_a($group, 'PEAR_Error')) {
        $form = 'delete.inc';
    }
    break;

case 'deleteform':
    if (Util::getFormData('confirm') == _("Delete")) {
        $group = &$groups->getGroupById(Util::getFormData('cid'));
        if (is_a($group, 'PEAR_Error')) {
            $notification->push(_("Attempt to delete a non-existent group."), 'horde.error');
        } else {
            $result = $groups->removeGroup($group, true);
            if (is_a($result, 'PEAR_Error')) {
                $notification->push(sprintf(_("Unable to delete '%s': %s."), $group->getShortName(), $result->getMessage()), 'horde.error');
             } else {
                $notification->push(sprintf(_("Successfully deleted '%s'."), $group->getShortName()), 'horde.success');
                $reload = true;
            }
        }
    }
    break;

case 'edit':
    $group = &$groups->getGroupById(Util::getFormData('cid'));
    if (!is_a($group, 'PEAR_Error')) {
        $form = 'edit.inc';
    } elseif (($category = Util::getFormData('category')) !== null) {
        $group = &$groups->getGroup($category);
        if (!is_a($group, 'PEAR_Error')) {
            $form = 'edit.inc';
        } elseif (Util::getFormData('autocreate')) {
            $parent = Util::getFormData('parent');
            $group = &$groups->newGroup($category);
            $result = $groups->addGroup($group, $parent);
            if (!is_a($result, 'PEAR_Error')) {
                $form = 'edit.inc';
            }
        }
    }
    break;

case 'editform':
    $group = &$groups->getGroupById(Util::getFormData('cid'));

    // Add any new users.
    $newuser = Util::getFormData('new_user');
    if (!empty($newuser)) {
        if (is_array($newuser)) {
            foreach ($newuser as $new) {
                $group->addUser($new, false);
            }
        } else {
            $group->addUser($newuser, false);
        }
    }

    // Remove any users marked for purging.
    $removes = Util::getFormData('remove');
    if (!empty($removes) && is_array($removes)) {
        foreach ($removes as $user => $junk) {
            $group->removeUser($user, false);
        }
    }

    // Set the email address of the group.
    $group->set('email', Util::getFormData('email'));

    // Save the group to the backend.
    $group->save();

    $notification->push(sprintf(_("Updated '%s'."), $group->getShortName()), 'horde.success');
    $form = 'edit.inc';
    $reload = true;
    break;
}

switch ($form) {
 case 'addchild.inc':
     $notification->push('document.add_child.child.focus()', 'javascript');
     break;
}

$title = _("Group Administration");
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';
$notification->notify(array('listeners' => 'status'));
if (!empty($form)) {
    include HORDE_TEMPLATES . '/admin/groups/' . $form;
}

/* Get the perms tree. */
$nodes = $groups->_datatree->get(DATATREE_FORMAT_FLAT, -1, true);

/* Set up some node params. */
$spacer = '    ';
$current = Util::getFormData('cid');
$icondir = array('icondir' => $registry->getParam('graphics'));
$group_node = $icondir + array('icon' => 'group.gif');
$add = Horde::applicationUrl('admin/groups.php?actionID=addchild');
$edit = Horde::applicationUrl('admin/groups.php?actionID=edit');
$delete = Horde::applicationUrl('admin/groups.php?actionID=delete');
$edit_img = Horde::img('edit.gif', _("Edit Group"), 'hspace="2"');
$delete_img = Horde::img('delete.gif', _("Delete Group"), 'hspace="2"');

/* Set up the tree. */
$tree = &Horde_Tree::singleton('datatree', 'javascript');
$tree->setOption(array('border' => '0', 'class' => 'item', 'cellpadding' => '0', 'cellspacing' => '0', 'alternate' => true));

$current_parents = $groups->_datatree->getParentList($current);

foreach ($nodes as $cid => $node) {
    $node_class = ($current == $cid) ? array('class' => 'selected') : array();
    if ($cid == -1) {
        $add_img = Horde::img('group.gif', _("Add New Group"), 'hspace="2"');
        $add_link = Horde::link(Util::addParameter($add, 'cid', $cid), _("Add New Group")) . $add_img . '</a>';

        $base_node_params = $icondir + array('icon' => 'administration.gif');
        $tree->addNode($cid, null, _("All Groups"), 0, true, $base_node_params + $node_class, array($spacer, $add_link));
    } else {
        $add_img = Horde::img('group.gif', _("Add Child Group"), 'hspace="2"');
        $add_link = Horde::link(Util::addParameter($add, 'cid', $cid), _("Add Child Group")) . $add_img . '</a>';
        $edit_link = Horde::link(Util::addParameter($edit, 'cid', $cid), _("Edit Group")) . $edit_img . '</a>';
        $delete_link = Horde::link(Util::addParameter($delete, 'cid', $cid), _("Delete Group")) . $delete_img . '</a>';

        $parent_id = $groups->_datatree->getParent($node);
        $group_extra = array($spacer, $add_link, $edit_link, $delete_link);
        $tree->addNode($cid, $parent_id, DataTree::getShortName($node), substr_count($node, ':') + 1, (isset($current_parents[$cid])) ? true : false, $group_node + $node_class, $group_extra);
    }
}

$tree->renderTree();
require HORDE_TEMPLATES . '/common-footer.inc';

--- NEW FILE: index.php ---
<?php
/*
 * $Horde: horde/admin/index.php,v 1.14 2004/04/07 14:43:01 chuck Exp $
 *
 * Copyright 1999-2004 Charles J. Hagenbuch <chuck at horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Menu.php';

if (!Auth::isAdmin()) {
    Horde::fatal('Forbidden.', __FILE__, __LINE__);
}

$title = _("Administration");
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';
require HORDE_TEMPLATES . '/common-footer.inc';

--- NEW FILE: phpshell.php ---
<?php
/**
 * $Horde: horde/admin/phpshell.php,v 1.22 2004/04/29 19:14:08 jan Exp $
 *
 * Copyright 1999-2004 Chuck Hagenbuch <chuck at horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Menu.php';
require_once 'Horde/Help.php';

if (!Auth::isAdmin()) {
    Horde::authenticationFailureRedirect();
}

$title = _("PHP Shell");
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';

$apps = $registry->listApps();
$application = Util::getFormData('app', 'horde');
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<?php Util::pformInput() ?>

<table width="100%" border="0" cellpadding="2" cellspacing="0"><tr><td class="header"><?php echo _("Application") ?></td></tr></table>
<select name="app">
<?php foreach ($apps as $app): ?>
  <option value="<?php echo $app ?>"<?php if ($application == $app) echo ' selected="selected"' ?>><?php echo $registry->getParam('name', $app) ?></option>
<?php endforeach; ?>
</select><br /><br />
<?php

if ($command = trim(Util::getFormData('php'))) {
    if (@file_exists($registry->getParam('fileroot', $application) . '/lib/base.php')) {
        include $registry->getParam('fileroot', $application) . '/lib/base.php';
    } else {
        $registry->pushApp($application);
    }

    require_once 'Horde/MIME/Viewer.php';
    require_once 'Horde/MIME/Viewer/source.php';
    $pretty = highlight_string('<?php ' . $command . "\n", true);
    $pretty = str_replace(array('<?php',
                                "\r\n",
                                "\r",
                                "<code><font color=\"#000000\">\n",
                                "\n</code>",
                                "\n</font></code>"),
                          array('',
                                "\n",
                                "\n",
                                '<code><font color="#000000">',
                                '</code>',
                                '</font></code>'),
                          $pretty);
    $pretty = MIME_Viewer_Source::lineNumber(trim($pretty));

    echo '<table width="100%" border="0" cellpadding="2" cellspacing="0"><tr><td class="header">' . _("PHP Code") . '</td></tr></table><br />';
    echo $pretty;

    echo '<br /><table width="100%" border="0" cellpadding="2" cellspacing="0"><tr><td class="header">' . _("Results") . '</td></tr></table>';
    echo '<table cellpadding="4" border="0"><tr><td class="text"><pre>';
    eval($command);
    echo '</pre></td></tr></table><br />';
}
?>

<textarea class="fixed" name="php" rows="10" cols="60">
<?php if (!empty($command)) echo htmlspecialchars($command) ?></textarea>
<br />
<input type="submit" class="button" value="<?php echo _("Execute") ?>">
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <?php Help::javascript(); ?>
    <td class="header" align="right"><?php echo Help::link('admin', 'admin-phpshell') ?></td>
<?php endif; ?>

</form>
<?php

require HORDE_TEMPLATES . '/common-footer.inc';

--- NEW FILE: sqlshell.php ---
<?php
/**
 * $Horde: horde/admin/sqlshell.php,v 1.17 2004/05/12 15:14:37 chuck Exp $
 *
 * Copyright 1999-2004 Chuck Hagenbuch <chuck at horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

@define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Menu.php';
require_once 'Horde/Help.php';
require_once 'DB.php';

if (!Auth::isAdmin()) {
    Horde::fatal('Forbidden.', __FILE__, __LINE__);
}

$title = _("SQL Shell");
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';

?>
<form name="sqlshell" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<?php Util::pformInput() ?>

<?php
if (Util::getFormData('list-tables')) {
    $description = 'LIST TABLES';
    $dbh = &DB::connect($conf['sql']);
    if (is_a($dbh, 'PEAR_Error')) {
        $result = $dbh;
    } else {
        $result = $dbh->getListOf('tables');
    }
} elseif (Util::getFormData('list-dbs')) {
    $description = 'LIST DATABASES';
    $dbh = &DB::connect($conf['sql']);
    if (is_a($dbh, 'PEAR_Error')) {
        $result = $dbh;
    } else {
        $result = $dbh->getListOf('databases');
    }
} elseif ($command = trim(Util::getFormData('sql'))) {
    // Keep a cache of prior queries for convenience.
    if (!isset($_SESSION['_sql_query_cache'])) {
        $_SESSION['_sql_query_cache'] = array();
    }
    if (($key = array_search($command, $_SESSION['_sql_query_cache'])) !== false) {
        unset($_SESSION['_sql_query_cache'][$key]);
    }
    array_unshift($_SESSION['_sql_query_cache'], $command);
    while (count($_SESSION['_sql_query_cache']) > 20) {
        array_pop($_SESSION['_sql_query_cache']);
    }

    // Parse out the query results.
    $dbh = &DB::connect($conf['sql']);
    if (is_a($dbh, 'PEAR_Error')) {
        $result = $dbh;
    } else {
        $result = $dbh->query(String::convertCharset($command, NLS::getCharset(), $conf['sql']['charset']));
    }
}

if (isset($result)) {
    if (isset($command)) {
        echo '<table cellpadding="2" cellspacing="0" border="0" width="100%"><tr><td class="header">' . _("Query") . '</td></tr><tr><td class="text"><pre>' . htmlspecialchars($command) . '</pre></td></tr></table>';
    }

    echo '<table width="100%" cellpadding="2" cellspacing="0" border="0"><tr><td class="header">' . _("Results") . '</td></tr><tr><td>';

    if (is_a($result, 'PEAR_Error')) {
        echo '<pre>'; var_dump($result); echo '</pre>';
    } else {
        if (is_object($result)) {
            echo '<table border="0" cellpadding="1" cellspacing="1" class="item">';
            $first = true;
            $i = 0;
            while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
                if ($first) {
                    echo '<tr>';
                    foreach ($row as $key => $val) {
                        echo '<th align="left">' . (empty($key) ? ' ' : htmlspecialchars(String::convertCharset($key, $conf['sql']['charset']))) . '</th>';
                    }
                    echo '</tr>';
                    $first = false;
                }
                echo '<tr class="item' . ($i % 2) . '">';
                foreach ($row as $val) {
                    echo '<td class="fixed">' . (empty($val) ? ' ' : htmlspecialchars(String::convertCharset($val, $conf['sql']['charset']))) . '</td>';
                }
                echo '</tr>';
                $i++;
            }
            echo '</table>';
        } elseif (is_array($result)) {
            echo '<table border="0" cellpadding="1" cellspacing="1" class="item">';
            $first = true;
            foreach ($result as $i => $val) {
                if ($first) {
                    echo '<tr><th align="left">' . (isset($description) ? htmlspecialchars($description) : ' ') . '</th></tr>';
                    $first = false;
                }
                echo '<tr class="item' . ($i % 2) . '">';
                echo '<td class="fixed">' . (empty($val) ? ' ' : htmlspecialchars(String::convertCharset($val, $conf['sql']['charset']))) . '</td>';
                echo '</tr>';
            }
            echo '</table>';
        } else {
            echo '<b>' . _("Success") . '</b>';
        }
    }

    echo '</td></tr></table><br />';
}
?>

<?php if (isset($_SESSION['_sql_query_cache']) &&
          count($_SESSION['_sql_query_cache'])): ?>
  <select name="query_cache" onchange="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value;">
  <?php foreach ($_SESSION['_sql_query_cache'] as $query): ?>
    <option value="<?php echo htmlspecialchars($query) ?>"><?php echo htmlspecialchars($query) ?></option>
  <?php endforeach; ?>
  </select>
  <input type="button" value="<?php echo _("Paste") ?>" class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value;" />
  <input type="button" value="<?php echo _("Run") ?>" class="button" onclick="document.sqlshell.sql.value = document.sqlshell.query_cache[document.sqlshell.query_cache.selectedIndex].value; document.sqlshell.submit();" />
  <br />
<?php endif; ?>

<textarea class="fixed" name="sql" rows="10" cols="60" wrap="hard">
<?php if (!empty($command)) echo htmlspecialchars($command) ?></textarea>
<br />
<input type="submit" class="button" value="<?php echo _("Execute") ?>">
<input type="submit" class="button" name="list-tables" value="<?php echo _("List Tables") ?>">
<input type="submit" class="button" name="list-dbs" value="<?php echo _("List Databases") ?>">
<?php if ($conf['user']['online_help'] && $browser->hasFeature('javascript')): ?>
    <?php Help::javascript(); ?>
    <td class="header" align="right"><?php echo Help::link('admin', 'admin-sqlshell') ?></td>
<?php endif; ?>

</form>
<?php

require HORDE_TEMPLATES . '/common-footer.inc';

--- NEW FILE: templates.php ---
<?php
/**
 * Horde Template Admin
 *
 * $Horde: horde/admin/templates.php,v 1.14 2004/04/07 14:43:01 chuck Exp $
 *
 * First stab at a template loader for horde, to be used by the horde
 * admin to load alternate individual templates or entire themes for the
 * Horde_Template system.
 * - gives a list of active horde apps and their /templates directory
 *   contents to choose from
 * - user can drill down to a specific file and load as many alternate
 *   templates as required
 * - it allows saving of templates only on actual files (and not
 *   directories) and does not show hidden files.
 * - the alternate templates are stored in the VFS under the directory
 *   path:
 *      .horde_templates/$app/sometemplatedir/templatefile
 *   so that directory would contain all the alternatives for that
 *   template.
 * - TODO: don't show certain other files, like CVS directories; comments;
 *   theme selection and storing in the VFS under:
 *      .horde_templates/$app/_themes/$theme/sometemplatedir/templatefile
 *   to be able to call up an entire theme group of templates? better error
 *   checking; downloading of original templates; the application side of
 *   allowing a different template to be chosen/prefs/etc.
 *
 * Copyright 2003-2004 Marko Djukic <marko at oblo.com>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Menu.php';
require_once 'Horde/Variables.php';

if (!Auth::isAdmin()) {
    Horde::fatal('Forbidden.', __FILE__, __LINE__);
}
$auth = &Auth::singleton($conf['auth']['driver']);

function _setValuesToKeys($in) {
    $out = array();
    foreach ($in as $value) {
        $out[$value] = $value;
    }
    asort($out);
    return $out;
}

/* Set up VFS. */
require_once 'VFS.php';
$vfs_type = $conf['vfs']['type'];
$vfs_args = Horde::getDriverConfig('vfs', $vfs_type);
$vfs_args['user'] = Auth::getAuth();
$vfs = &VFS::singleton($vfs_type, $vfs_args);
                       
@define('TEMPLATES_VFS_PATH', '.horde_templates');

/* Require Horde_Form libs. */
require_once 'Horde/Form.php';
require_once 'Horde/Form/Renderer.php';
require_once 'Horde/Form/Action.php';

/* Set up Horde_Form. */
$vars = &Variables::getDefaultVariables();
$form = &Horde_Form::singleton('TemplatesForm', $vars);
$action = &Horde_Form_Action::factory('submit');

/* Set up form fields. */
$apps = _setValuesToKeys($registry->listApps());
$select_app = &$form->addVariable(_("Application"), 'app', 'enum', true, false, null, array($apps));
$select_app->setAction($action);
$form->addHidden('', 'old_app', 'text', false, false);

/* Set up some variables. */
$formname = $vars->get('formname');
$app = $vars->get('app');
$old_app = $vars->get('old_app');
$template_path = $vars->get('template_path');
$template_orig = $vars->get('template_orig');
$old_template_orig = $vars->get('old_template_orig');
$has_changed = false;

if ($app != $old_app) {
    $has_changed = true;
    $template_path = '';
    $template_orig = '';
    $old_template_orig = '';
}
$vars->set('old_app', $app);
if ($template_orig != $old_template_orig) {
    $has_changed = true;
}
$vars->set('old_template_orig', $template_orig);

if (!is_null($app)) {
    if ($template_orig == '..') {
        $path_parts = explode('/', $template_path);
        array_pop($path_parts);
        $template_path = implode('/', $path_parts);
        $template_orig = '';
    }

    /* Get the full template path on the file system. */
    $template_path_full = $GLOBALS['registry']->getParam('templates', $app) . '/' . $template_path;

    /* If selected template is directory add to template path. */
    if (!empty($template_orig) &&
        is_dir($template_path_full . '/' . $template_orig)) {
        $template_path .= '/' . $template_orig;
        $template_path_full .= '/' . $template_orig;
    }

    $form->addVariable(sprintf(_("Original templates in %s:"), $template_path), 'orig_templates_header', 'header', false, false);

    /* Add the path to the hidden var in the form. */
    $form->addHidden('', 'template_path', 'text', false, false);
    $vars->set('template_path', $template_path);

    /* Get directory list for chosen directory in templates. */
    if ($templates_dir = opendir($template_path_full)) {
        while (false !== ($file = readdir($templates_dir))) { 
            /* Don't show current dir, hidden files and only show
               '..' if not in root dir of an app's templates. */
            if ($file != "." && !($file == '..' && empty($template_path)) &&
                !($file != '..' && substr($file, 0, 1) == '.')) { 
            //if ($file != ".") { 
                $templates[] = $file;
            } 
        }
        closedir($templates_dir); 
        $templates = _setValuesToKeys($templates);
        $v = &$form->addVariable(_("Original application template"), 'template_orig', 'enum', true, false, null, array($templates));
        $v->setAction($action);
        $form->addHidden('', 'old_template_orig', 'text', false, false);
    }

    /* Only set up these vars if the chosen template is a file. */
    if (is_file($template_path_full . '/' . $template_orig)) {
        $form->addVariable(_("Alternate templates"), 'alt_templates_header', 'header', false, false);

        /* Get the already saved alternate templates. */
        $vfs_path = TEMPLATES_VFS_PATH . '/' . $app . $template_path . '/' . $template_orig;
        $templates_alt = array_keys($vfs->listFolder($vfs_path, null, false));
        $templates_alt = array('' => '') + _setValuesToKeys($templates_alt);
        $form->addVariable(_("Delete existing alternate template"), 'delete_template_alt', 'enum', false, false, null, array($templates_alt));

        $form->addVariable(_("Insert alternate template"), 'template_alt', 'file', false, false);
    }
}

if ($formname && !$has_changed) {
    /* Inserting a new alternate template. */
    $form->validate($vars);

    if ($form->isValid()) {
        $form->getInfo($vars, $info);
        if (!empty($info['delete_template_alt'])) {
            $vfs->deleteFile($vfs_path, $info['delete_template_alt']);
        }
        if (!empty($info['template_alt']['size'])) {
            $vfs->write($vfs_path, $info['template_alt']['name'], $info['template_alt']['tmp_name'], true);
        }
    }
}

$title = _("Template Administration");
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';
$notification->notify(array('listeners' => 'status'));

/* Render the form. */
$renderer = &new Horde_Form_Renderer();
$form->renderActive($renderer, $vars, 'templates.php', 'post');

require HORDE_TEMPLATES . '/common-footer.inc';

--- NEW FILE: user.php ---
<?php
/**
 * $Horde: horde/admin/user.php,v 1.46 2004/04/22 18:38:27 chuck Exp $
 *
 * Copyright 1999-2004 Chuck Hagenbuch <chuck at horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

define('HORDE_BASE', dirname(__FILE__) . '/..');
require_once HORDE_BASE . '/lib/base.php';
require_once 'Horde/Menu.php';
require_once 'Horde/Form.php';
require_once 'Horde/Variables.php';
require_once 'Horde/Form/Renderer.php';
require_once 'Horde/Variables.php';

if (!Auth::isAdmin()) {
    Horde::fatal('Forbidden.', __FILE__, __LINE__);
}
$auth = &Auth::singleton($conf['auth']['driver']);

if ($conf['signup']['approve']) {
    require_once 'Horde/Auth/Signup.php';
    $signup = &Auth_Signup::singleton();
}

$vars = &Variables::getDefaultVariables();
$addForm = &new Horde_Form($vars, _("Add a new user:"), 'adduser');
$addForm->setButtons(_("Add user"), _("Reset"));

$vars->set('form', 'add');
$addForm->addHidden('', 'form', 'text', true, true);
$addForm->addVariable(_("Username"), 'user_name', 'text', true);
$addForm->addVariable(_("Password"), 'password', 'passwordconfirm', false, false, _("type the password twice to confirm"));

/* Use hooks get any extra fields for new accounts. */
$extra = Horde::callHook('_horde_hook_signup_getextra');
if (!is_a($extra, 'PEAR_Error') && !empty($extra)) {
    foreach ($extra as $field_name => $field) {
        $readonly = isset($field['readonly']) ? $field['readonly'] : null;
        $desc = isset($field['desc']) ? $field['desc'] : null;
        $field_params = isset($field['params']) ? $field['params'] : array();

        $addForm->addVariable($field['label'], 'extra[' . $field_name . ']', $field['type'], $field['required'], $readonly, $desc, $field_params);
    }
}


// Process forms. Use Util::getPost() instead of Util::getFormData()
// for a lot of the data because we want to actively ignore GET data
// in some cases - adding/modifying users - as a security precaution.
switch (Util::getFormData('form')) {
case 'add':
    $addForm->validate($vars);

    if ($addForm->isValid() && $vars->get('formname') == 'adduser') {
        $addForm->getInfo($vars, $info);

        if (empty($info['user_name'])) {
            $notification->push(_("You must specify the username to add."), 'horde.error');

        } else {
            $credentials = array('password' => $info['password']);
            if (isset($info['extra'])) {
                foreach ($info['extra'] as $field => $value) {
                    $credentials[$field] = $value;
                }
            }

            if (is_a($ret = $auth->addUser($info['user_name'], $credentials), 'PEAR_Error')) {
                $notification->push(sprintf(_("There was a problem adding '%s' to the system: %s"), $info['user_name'], $ret->getMessage()), 'horde.error');
            } else {
                if (isset($info['extra'])) {
                    $result = Horde::callHook('_horde_hook_signup_addextra',
                                              array($info['user_name'], $info['extra']));
                    if (is_a($result, 'PEAR_Error')) {
                        $notification->push(sprintf(_("Added '%s' to the system, but could not add additional signup information: %s."), $info['user_name'], $result->getMessage()), 'horde.warning');
                    }
                }
                if (Util::getFormData('removeQueuedSignup')) {
                    $signup->removeQueuedSignup($info['user_name']);
                }
                $notification->push(sprintf(_("Successfully added '%s' to the system."), $info['user_name']), 'horde.success');
                $addForm->unsetVars($vars);
            }
        }
    }
    break;

case 'remove_f':
    $f_user_name = Util::getFormData('user_name');
    $remove_form = true;
    break;

case 'remove':
    $f_user_name = Util::getFormData('user_name');
    if (empty($f_user_name)) {
        $notification->push(_("You must specify a username to remove."), 'horde.message');
    } elseif (Util::getFormData('submit') !== _("Cancel")) {
        if (is_a($result = $auth->removeUser($f_user_name), 'PEAR_Error')) {
            $notification->push(sprintf(_("There was a problem removing '%s' from the system: ") . $result->getMessage(), $f_user_name), 'horde.error');
        } else {
            $notification->push(sprintf(_("Successfully removed '%s' from the system."), $f_user_name), 'horde.success');
        }
    }
    break;

case 'update_f':
    $f_user_name = Util::getFormData('user_name');
    $update_form = true;
    break;

case 'update':
    $user_name_1 = Util::getPost('user_name');
    $user_name_2 = Util::getPost('user_name2', $user_name_1);
    $fullname = Util::getPost('user_fullname');
    $email = Util::getPost('user_email');

    if ($auth->hasCapability('update')) {
        $user_pass_1 = Util::getPost('user_pass_1');
        $user_pass_2 = Util::getPost('user_pass_2');

        if (empty($user_name_1)) {
            $notification->push(_("You must specify the username to update."), 'horde.error');
        } elseif (empty($user_pass_1) || empty($user_pass_2)) {
            // Don't update, but don't complain.
        } elseif ($user_pass_1 != $user_pass_2) {
            $notification->push(_("Passwords must match."), 'horde.error');
        } else {
            $result = $auth->updateUser($user_name_1,
                                        $user_name_2,
                                        array('password' => $user_pass_1));
        }
    }

    if (isset($result) && is_a($result, 'PEAR_Error')) {
        $notification->push(sprintf(_("There was a problem updating '%s': %s"),
                                    $user_name_1, $result->getMessage()), 'horde.error');
    } else {
        require_once 'Horde/Identity.php';
        $identity = &Identity::singleton('none', $user_name_1);
        $identity->setValue('fullname', $fullname);
        $identity->setValue('from_addr', $email);
        $identity->save();

        $notification->push(sprintf(_("Successfully updated '%s'"),
                                    $user_name_2), 'horde.success');
    }
    break;

case 'approve_f':
    $thisSignup = $signup->getQueuedSignup(Util::getFormData('user_name'));
    $info = $thisSignup->getData();

    $vars->set('password',
                  array('original' => $info['password'],
                        'confirm' => $info['password']));
    unset($info['password']);
    $vars->set('extra', $info);

    $vars->set('removeQueuedSignup', true);
    $addForm->addHidden('', 'removeQueuedSignup', 'boolean', true);

    break;

case 'removequeued_f':
    $f_user_name = Util::getFormData('user_name'); 
    $removequeued_form = true;
    break;

case 'removequeued':
    $result = $signup->removeQueuedSignup(Util::getFormData('user_name'));
    if (is_a($result, 'PEAR_Error')) {
        $notification->push($result);
    } else {
        $notification->push(sprintf(_("The signup request for %s has been removed."), Util::getFormData('user_name')));
    }
    break;
}


$title = _("User Administration");
require HORDE_TEMPLATES . '/common-header.inc';
require HORDE_TEMPLATES . '/admin/common-header.inc';
$notification->notify(array('listeners' => 'status'));

if (isset($update_form) && $auth->hasCapability('list')) {
    require_once 'Horde/Identity.php';
    $identity = &Identity::singleton('none', $f_user_name);
    require HORDE_TEMPLATES . '/admin/user/update.inc';
} elseif (isset($remove_form) && $auth->hasCapability('list') && $auth->hasCapability('remove')) {
    require HORDE_TEMPLATES . '/admin/user/remove.inc';
} elseif (isset($removequeued_form)) {
    require HORDE_TEMPLATES . '/admin/user/removequeued.inc';
} elseif ($auth->hasCapability('add')) {
    require HORDE_TEMPLATES . '/admin/user/add.inc';
    if ($conf['signup']['approve']) {
        require HORDE_TEMPLATES . '/admin/user/approve.inc';
    }
} else {
    require HORDE_TEMPLATES . '/admin/user/noadd.inc';
}

if ($auth->hasCapability('list')) {

    /* If we aren't supplied with a page number, default to page 0. */
    $page = Util::getFormData('page', 0);
    $search_pattern = Util::getFormData('search_pattern', '');
    
    $users = $auth->listUsers();
    if (is_a($users, 'PEAR_Error')) {
        Horde::fatal($users, __FILE__, __LINE__);
    }

    /* Returns only users that match the specified pattern. */
    require_once 'Horde/Array.php';
    $users = preg_grep('/' . $search_pattern . '/', $users);
    sort($users);

    require_once 'Horde/UI/Pager.php';
    $viewurl = Util::addParameter('admin/user.php', 'search_pattern', $search_pattern);

    $numitem = count($users);
    $perpage = 20;
    
    $min = $page * $perpage;
    while ($min > $numitem) {
        $page--;
        $min = $page * $perpage;
    }
    $max = $min + $perpage;
    
    $start = ($page * $perpage) + 1;
    $end = min($numitem, $start + $perpage - 1);    

    require HORDE_TEMPLATES . '/admin/user/list.inc';
} else {
    require HORDE_TEMPLATES . '/admin/user/nolist.inc';
}

require HORDE_TEMPLATES . '/common-footer.inc';





More information about the commits mailing list