2004-03-09 14:29:47 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
|
|
|
Copyright (C) 2003 Roland Gruber
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2004-06-10 22:13:39 +00:00
|
|
|
*/
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2004-06-10 22:13:39 +00:00
|
|
|
/**
|
|
|
|
* Manages creating/changing of profiles.
|
|
|
|
*
|
2004-10-09 11:04:20 +00:00
|
|
|
* @package profiles
|
2004-06-10 22:13:39 +00:00
|
|
|
* @author Roland Gruber
|
2004-03-09 14:29:47 +00:00
|
|
|
*/
|
|
|
|
|
2004-06-10 22:13:39 +00:00
|
|
|
/** helper functions for profiles */
|
2004-03-09 14:29:47 +00:00
|
|
|
include_once("../../lib/profiles.inc");
|
2004-06-10 22:13:39 +00:00
|
|
|
/** access to LDAP server */
|
2004-03-09 14:29:47 +00:00
|
|
|
include_once("../../lib/ldap.inc");
|
2004-06-10 22:13:39 +00:00
|
|
|
/** access to configuration options */
|
2004-03-09 14:29:47 +00:00
|
|
|
include_once("../../lib/config.inc");
|
2004-06-10 22:13:39 +00:00
|
|
|
/** access to account modules */
|
2004-03-09 14:29:47 +00:00
|
|
|
include_once("../../lib/modules.inc");
|
|
|
|
|
|
|
|
// start session
|
|
|
|
session_save_path("../../sess");
|
|
|
|
@session_start();
|
|
|
|
|
|
|
|
setlanguage();
|
|
|
|
|
|
|
|
// check if user is logged in, if not go to login
|
|
|
|
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
|
|
|
|
metaRefresh("../login.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2004-03-14 15:34:53 +00:00
|
|
|
// empty list of attribute types
|
|
|
|
$_SESSION['profile_types'] = array();
|
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
// print header
|
|
|
|
echo $_SESSION['header'];
|
|
|
|
echo "<title></title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n";
|
|
|
|
echo "</head><body><br>\n";
|
|
|
|
|
|
|
|
// check if account type is valid
|
|
|
|
$type = $_GET['type'];
|
|
|
|
if (!(($type == 'user') || ($type == 'group') || ($type == 'host'))) meta_refresh('profilemain.php');
|
|
|
|
|
|
|
|
// get module options
|
|
|
|
$options = getProfileOptions($type);
|
|
|
|
|
|
|
|
// load old profile if needed
|
2004-03-15 16:34:16 +00:00
|
|
|
$old_options = array();
|
2004-03-09 14:29:47 +00:00
|
|
|
if ($_GET['edit']) {
|
2004-10-06 20:00:17 +00:00
|
|
|
$old_options = loadAccountProfile($_GET['edit'], $type);
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// display formular
|
|
|
|
echo ("<form action=\"profilecreate.php?type=$type\" method=\"post\">\n");
|
|
|
|
|
2004-06-27 18:07:43 +00:00
|
|
|
// suffix box
|
|
|
|
// get root suffix
|
|
|
|
$rootsuffix = call_user_func(array($_SESSION['config'], 'get_' . ucfirst($type) . 'Suffix'));
|
|
|
|
// get subsuffixes
|
|
|
|
$suffixes = array();
|
|
|
|
foreach ($_SESSION['ldap']->search_units($rootsuffix) as $suffix) {
|
|
|
|
$suffixes[] = $suffix;
|
|
|
|
}
|
|
|
|
if (sizeof($suffixes) > 0) {
|
|
|
|
echo "<fieldset>\n<legend><b>" . _("LDAP suffix") . "</b></legend>\n";
|
|
|
|
echo _("LDAP suffix") . ": ";
|
2004-07-02 15:27:14 +00:00
|
|
|
echo "<select tabindex=\"1\">";
|
2004-06-27 18:07:43 +00:00
|
|
|
for ($i = 0; $i < sizeof($suffixes); $i++) echo "<option>" . $suffixes[$i] . "</option>\n";
|
|
|
|
echo "</select>\n";
|
2004-10-02 17:23:53 +00:00
|
|
|
echo " <a href=../help.php?HelpNumber=\"361\">" . _('Help') . "</a>\n";
|
2004-06-27 18:07:43 +00:00
|
|
|
echo "</fieldset>\n<br>\n";
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:27:14 +00:00
|
|
|
// index for tab order (1 is LDAP suffix)
|
|
|
|
$tabindex = 2;
|
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
// display module options
|
|
|
|
$modules = array_keys($options);
|
|
|
|
for ($m = 0; $m < sizeof($modules); $m++) {
|
|
|
|
// ignore modules without options
|
|
|
|
if (sizeof($options[$modules[$m]]) < 1) continue;
|
|
|
|
echo "<fieldset>\n";
|
|
|
|
echo "<legend><b>" . getModuleAlias($modules[$m], $type) . "</b></legend>\n";
|
|
|
|
echo "<table>\n";
|
|
|
|
for ($l = 0; $l < sizeof($options[$modules[$m]]); $l++) { // option lines
|
|
|
|
echo "<tr>\n";
|
|
|
|
for ($o = 0; $o < sizeof($options[$modules[$m]][$l]); $o++) { // line parts
|
2004-06-23 19:14:07 +00:00
|
|
|
echo "<td";
|
|
|
|
if (isset($options[$modules[$m]][$l][$o]['align'])) echo " align=\"" . $options[$modules[$m]][$l][$o]['align'] . "\"";
|
|
|
|
if (isset($options[$modules[$m]][$l][$o]['colspan'])) echo " colspan=\"" . $options[$modules[$m]][$l][$o]['colspan'] . "\"";
|
|
|
|
if (isset($options[$modules[$m]][$l][$o]['rowspan'])) echo " rowspan=\"" . $options[$modules[$m]][$l][$o]['rowspan'] . "\"";
|
|
|
|
echo ">";
|
2004-07-23 14:12:29 +00:00
|
|
|
print_option($options[$modules[$m]][$l][$o], $modules[$m], $old_options, $tabindex);
|
2004-03-09 14:29:47 +00:00
|
|
|
echo "</td>\n";
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
echo "</fieldset>\n";
|
2004-06-23 19:14:07 +00:00
|
|
|
echo "<br>";
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// profile name and submit/abort buttons
|
|
|
|
echo ("<table border=0>\n");
|
|
|
|
echo ("<tr>\n");
|
|
|
|
echo ("<td><b>" . _("Profile name") . ":</b></td>\n");
|
2004-07-14 12:57:11 +00:00
|
|
|
$tabindex++;
|
|
|
|
echo ("<td><input tabindex=\"$tabindex\" type=\"text\" name=\"profname\" value=\"" . $_GET['edit'] . "\"></td>\n");
|
2004-03-09 14:29:47 +00:00
|
|
|
echo ("<td><a href=\"../help.php?HelpNumber=360\" target=\"lamhelp\">" . _("Help") . "</a></td>\n");
|
|
|
|
echo ("</tr>\n");
|
|
|
|
echo ("<tr>\n");
|
|
|
|
echo ("<td colspan=2> </td>");
|
|
|
|
echo ("</tr>\n");
|
|
|
|
echo ("<tr>\n");
|
2004-07-14 12:57:11 +00:00
|
|
|
$tabindex++;
|
|
|
|
echo ("<td><input tabindex=\"$tabindex\" type=\"submit\" name=\"submit\" value=\"" . _("Save") . "\"></td>\n");
|
|
|
|
$tabindex++;
|
|
|
|
echo ("<td><input tabindex=\"$tabindex\" type=\"reset\" name=\"reset\" value=\"" . _("Reset") . "\">\n");
|
|
|
|
$tabindex++;
|
|
|
|
echo ("<input tabindex=\"$tabindex\" type=\"submit\" name=\"abort\" value=\"" . _("Abort") . "\"></td>\n");
|
2004-03-09 14:29:47 +00:00
|
|
|
echo ("<td> </td>");
|
|
|
|
echo ("</tr>\n");
|
|
|
|
echo ("</table>\n");
|
2004-03-15 16:34:16 +00:00
|
|
|
echo "<input type=\"hidden\" name=\"accounttype\" value=\"$type\">\n";
|
2004-03-09 14:29:47 +00:00
|
|
|
|
|
|
|
echo ("</form></body></html>\n");
|
|
|
|
|
2004-06-10 22:13:39 +00:00
|
|
|
/**
|
|
|
|
* prints out the row of a section table including the option name, values and help
|
|
|
|
*
|
|
|
|
* @param array $values an array formated as module option
|
|
|
|
* @param string $module_name the name of the module the options belong to
|
|
|
|
* @param array $old_options a hash array with the values from the loaded profile
|
2004-07-23 14:12:29 +00:00
|
|
|
* @param integer $tabindex current value for tabulator order
|
2004-06-10 22:13:39 +00:00
|
|
|
*/
|
2004-07-23 14:12:29 +00:00
|
|
|
function print_option($values, $modulename, $old_options, &$tabindex) {
|
2004-03-15 16:34:16 +00:00
|
|
|
switch ($values['kind']) {
|
|
|
|
// text value
|
|
|
|
case 'text':
|
|
|
|
echo $values['text'] . "\n";
|
|
|
|
break;
|
|
|
|
// help link
|
|
|
|
case 'help':
|
2004-10-02 18:45:11 +00:00
|
|
|
echo "<a href=../help.php?module=$modulename&HelpNumber=" . $values['value'];
|
|
|
|
if (isset($values['scope'])) echo "&scope=" . $values['scope'];
|
|
|
|
echo ">" . _('Help') . "</a>\n";
|
2004-03-15 16:34:16 +00:00
|
|
|
break;
|
|
|
|
// input field
|
|
|
|
case 'input':
|
|
|
|
if (($values['type'] == 'text') || ($values['type'] == 'checkbox')) {
|
|
|
|
if ($values['type'] == 'text') {
|
2004-07-02 15:27:14 +00:00
|
|
|
$output = "<input tabindex=\"$tabindex\" type=\"text\" name=\"" . $values['name'] . "\"";
|
2004-03-15 16:34:16 +00:00
|
|
|
if ($values['size']) $output .= " size=\"" . $values['size'] . "\"";
|
|
|
|
if ($values['maxlength']) $output .= " maxlength=\"" . $values['maxlength'] . "\"";
|
|
|
|
if (isset($old_options[$values['name']])) $output .= " value=\"" . $old_options[$values['name']][0] . "\"";
|
|
|
|
elseif ($values['value']) $output .= " value=\"" . $values['value'] . "\"";
|
|
|
|
if ($values['disabled']) $output .= " disabled";
|
|
|
|
$output .= ">\n";
|
|
|
|
echo $output;
|
|
|
|
$_SESSION['profile_types'][$values['name']] = "text";
|
|
|
|
}
|
|
|
|
elseif ($values['type'] == 'checkbox') {
|
2004-07-02 15:27:14 +00:00
|
|
|
$output = "<input tabindex=\"$tabindex\" type=\"checkbox\" name=\"" . $values['name'] . "\"";
|
2004-03-15 16:34:16 +00:00
|
|
|
if ($values['size']) $output .= " size=\"" . $values['size'] . "\"";
|
|
|
|
if ($values['maxlength']) $output .= " maxlength=\"" . $values['maxlength'] . "\"";
|
|
|
|
if ($values['disabled']) $output .= " disabled";
|
2004-04-04 14:44:27 +00:00
|
|
|
if (isset($old_options[$values['name']]) && ($old_options[$values['name']][0] == 'true')) $output .= " checked";
|
2004-03-15 16:34:16 +00:00
|
|
|
elseif ($values['checked']) $output .= " checked";
|
|
|
|
$output .= ">\n";
|
|
|
|
echo $output;
|
|
|
|
$_SESSION['profile_types'][$values['name']] = "checkbox";
|
|
|
|
}
|
2004-07-02 15:27:14 +00:00
|
|
|
$tabindex++;
|
2004-03-15 16:34:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
// select box
|
|
|
|
case 'select':
|
2004-06-23 19:14:07 +00:00
|
|
|
if (! is_numeric($values['size'])) $values['size'] = 1;// correct size if needed
|
2004-03-15 16:34:16 +00:00
|
|
|
if ($values['multiple']) {
|
2004-07-02 15:27:14 +00:00
|
|
|
echo "<select tabindex=\"$tabindex\" name=\"" . $values['name'] . "[]\" size=\"" . $values['size'] . "\" multiple>\n";
|
2004-03-15 16:34:16 +00:00
|
|
|
$_SESSION['profile_types'][$values['name']] = "multiselect";
|
|
|
|
}
|
|
|
|
else {
|
2004-07-02 15:27:14 +00:00
|
|
|
echo "<select tabindex=\"$tabindex\" name=\"" . $values['name'] . "\" size=\"" . $values['size'] . "\">\n";
|
2004-03-15 16:34:16 +00:00
|
|
|
$_SESSION['profile_types'][$values['name']] = "select";
|
|
|
|
}
|
|
|
|
// option values
|
|
|
|
for ($i = 0; $i < sizeof($values['options']); $i++) {
|
|
|
|
// use values from old profile if given
|
|
|
|
if (isset($old_options[$values['name']])) {
|
|
|
|
if (in_array($values['options'][$i], $old_options[$values['name']])) {
|
|
|
|
echo "<option selected>" . $values['options'][$i] . "</option>\n";
|
2004-03-14 15:34:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2004-03-15 16:34:16 +00:00
|
|
|
echo "<option>" . $values['options'][$i] . "</option>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// use default values if not in profile
|
|
|
|
else {
|
2004-04-12 11:05:52 +00:00
|
|
|
if (is_array($values['options_selected']) && in_array($values['options'][$i], $values['options_selected'])) {
|
2004-03-15 16:34:16 +00:00
|
|
|
echo "<option selected>" . $values['options'][$i] . "</option>\n";
|
2004-03-14 15:34:53 +00:00
|
|
|
}
|
2004-03-15 16:34:16 +00:00
|
|
|
else {
|
|
|
|
echo "<option>" . $values['options'][$i] . "</option>\n";
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
2004-03-15 16:34:16 +00:00
|
|
|
}
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
2004-03-15 16:34:16 +00:00
|
|
|
echo "</select>\n";
|
2004-07-02 15:27:14 +00:00
|
|
|
$tabindex++;
|
2004-03-15 16:34:16 +00:00
|
|
|
break;
|
2004-04-04 14:44:27 +00:00
|
|
|
// subtable
|
|
|
|
case 'table':
|
|
|
|
echo "<table>\n";
|
|
|
|
for ($l = 0; $l < sizeof($values['value']); $l++) { // option lines
|
|
|
|
echo "<tr>\n";
|
|
|
|
for ($o = 0; $o < sizeof($values['value'][$l]); $o++) { // line parts
|
|
|
|
echo "<td>";
|
2004-07-23 14:12:29 +00:00
|
|
|
print_option($values['value'][$l][$o], $values['value'], $old_options, $tabindex);
|
2004-04-04 14:44:27 +00:00
|
|
|
echo "</td>\n";
|
|
|
|
}
|
|
|
|
echo "</tr>\n";
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
break;
|
2004-03-15 16:34:16 +00:00
|
|
|
// print error message for invalid types
|
|
|
|
default:
|
2004-11-06 13:05:34 +00:00
|
|
|
echo "Unrecognized type" . ": " . $values['kind'] . "\n";
|
2004-03-15 16:34:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|