2004-03-09 14:29:47 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
$Id$
|
|
|
|
|
2009-10-27 18:47:12 +00:00
|
|
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
2010-01-01 17:21:46 +00:00
|
|
|
Copyright (C) 2003 - 2010 Roland Gruber
|
2004-03-09 14:29:47 +00:00
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2006-03-26 17:51:25 +00:00
|
|
|
/** security functions */
|
|
|
|
include_once("../../lib/security.inc");
|
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");
|
2005-07-12 15:52:15 +00:00
|
|
|
/** Used to display status messages */
|
|
|
|
include_once("../../lib/status.inc");
|
2004-03-09 14:29:47 +00:00
|
|
|
|
|
|
|
// start session
|
2006-03-26 17:51:25 +00:00
|
|
|
startSecureSession();
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2007-12-30 13:15:39 +00:00
|
|
|
// die if no write access
|
|
|
|
if (!checkIfWriteAccessIsAllowed()) die();
|
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
setlanguage();
|
|
|
|
|
|
|
|
// check if user is logged in, if not go to login
|
|
|
|
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
|
|
|
|
metaRefresh("../login.php");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// copy type and profile name from POST to GET
|
|
|
|
if (isset($_POST['profname'])) $_GET['edit'] = $_POST['profname'];
|
|
|
|
if (isset($_POST['accounttype'])) $_GET['type'] = $_POST['accounttype'];
|
|
|
|
|
|
|
|
// abort button was pressed
|
|
|
|
// back to profile editor
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST['abort'])) {
|
2005-07-12 15:52:15 +00:00
|
|
|
metaRefresh("profilemain.php");
|
|
|
|
exit;
|
|
|
|
}
|
2004-03-14 15:34:53 +00:00
|
|
|
|
2010-05-26 17:30:55 +00:00
|
|
|
$errors = array();
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// save button was presed
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST['save'])) {
|
2005-07-12 15:52:15 +00:00
|
|
|
// create option array to check and save
|
|
|
|
$options = array();
|
|
|
|
$opt_keys = array_keys($_SESSION['profile_types']);
|
|
|
|
foreach ($opt_keys as $element) {
|
|
|
|
// text fields
|
|
|
|
if ($_SESSION['profile_types'][$element] == "text") {
|
|
|
|
$options[$element] = array($_POST[$element]);
|
|
|
|
}
|
|
|
|
// checkboxes
|
|
|
|
elseif ($_SESSION['profile_types'][$element] == "checkbox") {
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST[$element]) && ($_POST[$element] == "on")) $options[$element] = array('true');
|
2005-07-12 15:52:15 +00:00
|
|
|
else $options[$element] = array('false');
|
|
|
|
}
|
|
|
|
// dropdownbox
|
|
|
|
elseif ($_SESSION['profile_types'][$element] == "select") {
|
|
|
|
$options[$element] = array($_POST[$element]);
|
|
|
|
}
|
|
|
|
// multiselect
|
|
|
|
elseif ($_SESSION['profile_types'][$element] == "multiselect") {
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($_POST[$element])) $options[$element] = $_POST[$element]; // value is already an array
|
|
|
|
else $options[$element] = array();
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove double slashes if magic quotes are on
|
|
|
|
if (get_magic_quotes_gpc() == 1) {
|
|
|
|
foreach ($opt_keys as $element) {
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($options[$element][0]) && is_string($options[$element][0])) $options[$element][0] = stripslashes($options[$element][0]);
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check options
|
|
|
|
$errors = checkProfileOptions($_POST['accounttype'], $options);
|
2010-05-26 17:30:55 +00:00
|
|
|
if (sizeof($errors) == 0) { // input data is valid, save profile
|
2005-07-12 15:52:15 +00:00
|
|
|
// save profile
|
|
|
|
if (saveAccountProfile($options, $_POST['profname'], $_POST['accounttype'])) {
|
2010-05-26 17:30:55 +00:00
|
|
|
metaRefresh('profilemain.php?savedSuccessfully=' . $_POST['profname']);
|
2005-07-12 15:52:15 +00:00
|
|
|
exit();
|
|
|
|
}
|
2010-05-26 17:30:55 +00:00
|
|
|
else {
|
|
|
|
$errors[] = array("ERROR", _("Unable to save profile!"), $_POST['profname']);
|
|
|
|
}
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-26 17:30:55 +00:00
|
|
|
// print header
|
|
|
|
include '../main_header.php';
|
2010-08-21 09:43:52 +00:00
|
|
|
echo "<br>\n";
|
2010-05-26 17:30:55 +00:00
|
|
|
|
|
|
|
// print error messages if any
|
|
|
|
if (sizeof($errors) > 0) {
|
|
|
|
for ($i = 0; $i < sizeof($errors); $i++) {
|
|
|
|
call_user_func_array('StatusMessage', $errors[$i]);
|
|
|
|
}
|
|
|
|
echo "<br>\n";
|
|
|
|
}
|
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// empty list of attribute types
|
|
|
|
$_SESSION['profile_types'] = array();
|
|
|
|
|
2004-03-09 14:29:47 +00:00
|
|
|
// check if account type is valid
|
|
|
|
$type = $_GET['type'];
|
|
|
|
|
|
|
|
// get module options
|
|
|
|
$options = getProfileOptions($type);
|
|
|
|
|
2005-07-12 15:52:15 +00:00
|
|
|
// load old profile or POST values if needed
|
2004-03-15 16:34:16 +00:00
|
|
|
$old_options = array();
|
2005-07-12 15:52:15 +00:00
|
|
|
if (isset($_POST['save'])) {
|
|
|
|
$postKeys = array_keys($_POST);
|
|
|
|
for ($i = 0; $i < sizeof($postKeys); $i++) {
|
|
|
|
if (!is_array($_POST[$postKeys[$i]])) {
|
2005-10-23 09:26:18 +00:00
|
|
|
if (get_magic_quotes_gpc() == 1) {
|
|
|
|
$old_options[$postKeys[$i]] = array(stripslashes($_POST[$postKeys[$i]]));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$old_options[$postKeys[$i]] = array($_POST[$postKeys[$i]]);
|
|
|
|
}
|
2005-07-12 15:52:15 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$old_options[$postKeys[$i]] = $_POST[$postKeys[$i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (isset($_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
|
2005-07-12 15:52:15 +00:00
|
|
|
echo ("<form action=\"profilepage.php?type=$type\" method=\"post\">\n");
|
2004-03-09 14:29:47 +00:00
|
|
|
|
2010-09-25 16:39:07 +00:00
|
|
|
$tabindex = 1;
|
|
|
|
|
|
|
|
// profile name and submit/abort buttons
|
|
|
|
echo "<table width=\"100%\"><tr><td align=\"left\">";
|
|
|
|
echo _("Profile name");
|
|
|
|
$profName = '';
|
|
|
|
if (isset($_GET['edit'])) {
|
|
|
|
$profName = $_GET['edit'];
|
|
|
|
}
|
|
|
|
echo (" <input tabindex=\"$tabindex\" type=\"text\" name=\"profname\" value=\"" . $profName . "\">\n");
|
|
|
|
$tabindex++;
|
|
|
|
printHelpLink(getHelp('', '360'), '360');
|
|
|
|
echo "</td><td align=\"right\">";
|
|
|
|
echo "<button tabindex=\"$tabindex\" id=\"saveButton\" name=\"save\" type=\"submit\">" . _('Save') . "</button>";
|
|
|
|
$tabindex++;
|
|
|
|
echo " ";
|
|
|
|
echo "<button tabindex=\"$tabindex\" id=\"cancelButton\" name=\"abort\" type=\"submit\">" . _('Cancel') . "</button>";
|
|
|
|
$tabindex++;
|
|
|
|
echo "<input type=\"hidden\" name=\"accounttype\" value=\"$type\">\n";
|
|
|
|
echo "</td></tr></table>";
|
|
|
|
echo "<br><br>\n";
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
jQuery(document).ready(function() {
|
|
|
|
jQuery('#saveButton').button({
|
|
|
|
icons: {
|
|
|
|
primary: 'saveButton'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
jQuery('#cancelButton').button({
|
|
|
|
icons: {
|
|
|
|
primary: 'cancelButton'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
2004-06-27 18:07:43 +00:00
|
|
|
// suffix box
|
|
|
|
// get root suffix
|
2005-03-10 20:20:00 +00:00
|
|
|
$rootsuffix = $_SESSION['config']->get_Suffix($type);
|
2004-06-27 18:07:43 +00:00
|
|
|
// get subsuffixes
|
|
|
|
$suffixes = array();
|
|
|
|
foreach ($_SESSION['ldap']->search_units($rootsuffix) as $suffix) {
|
|
|
|
$suffixes[] = $suffix;
|
|
|
|
}
|
2005-05-21 14:35:14 +00:00
|
|
|
// get RDNs
|
|
|
|
$rdns = getRDNAttributes($type);
|
|
|
|
|
2008-12-28 13:59:03 +00:00
|
|
|
echo "<fieldset class=\"" . $type . "edit\">\n";
|
|
|
|
echo "<legend><img align=\"middle\" src=\"../../graphics/logo32.png\" alt=\"logo32.png\"> <b>" . _("LDAP") . "</b></legend>\n";
|
2005-05-21 14:35:14 +00:00
|
|
|
echo "<table border=0>";
|
|
|
|
echo "<tr><td>";
|
|
|
|
// LDAP suffix
|
2010-09-25 16:39:07 +00:00
|
|
|
echo _("LDAP suffix");
|
2005-05-21 14:35:14 +00:00
|
|
|
echo "</td><td>";
|
2010-09-25 16:39:07 +00:00
|
|
|
echo "<select class=\"rightToLeftText\" name=\"ldap_suffix\" tabindex=\"$tabindex\">";
|
|
|
|
$tabindex++;
|
2005-05-21 14:35:14 +00:00
|
|
|
for ($i = 0; $i < sizeof($suffixes); $i++) {
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($old_options['ldap_suffix']) && ($old_options['ldap_suffix'][0] == $suffixes[$i])) {
|
2010-05-31 19:35:55 +00:00
|
|
|
echo "<option selected value=\"" .$suffixes[$i] . "\">" . getAbstractDN($suffixes[$i]) . "</option>\n";
|
2005-05-21 14:35:14 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-05-31 19:35:55 +00:00
|
|
|
echo "<option value=\"" .$suffixes[$i] . "\">" . getAbstractDN($suffixes[$i]) . "</option>\n";
|
2005-05-21 14:35:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-27 18:07:43 +00:00
|
|
|
echo "</select>\n";
|
2005-05-21 14:35:14 +00:00
|
|
|
echo "</td><td>";
|
2005-04-24 12:42:20 +00:00
|
|
|
// help link
|
2009-02-07 22:56:36 +00:00
|
|
|
echo " ";
|
|
|
|
printHelpLink(getHelp('', '361'), '361');
|
|
|
|
echo "<br>\n";
|
2005-05-21 14:35:14 +00:00
|
|
|
echo "</td></tr>";
|
|
|
|
// LDAP RDN
|
|
|
|
echo "<tr><td>";
|
2010-09-25 16:39:07 +00:00
|
|
|
echo _("RDN identifier");
|
2005-05-21 14:35:14 +00:00
|
|
|
echo "</td><td>";
|
2010-09-25 16:39:07 +00:00
|
|
|
echo "<select name=\"ldap_rdn\" tabindex=\"$tabindex\">";
|
|
|
|
$tabindex++;
|
2005-05-21 14:35:14 +00:00
|
|
|
for ($i = 0; $i < sizeof($rdns); $i++) {
|
2006-01-25 18:31:19 +00:00
|
|
|
if (isset($old_options['ldap_rdn']) && ($old_options['ldap_rdn'][0] == $rdns[$i])) {
|
2005-05-21 14:35:14 +00:00
|
|
|
echo "<option selected>" . $rdns[$i] . "</option>\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "<option>" . $rdns[$i] . "</option>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "</select>\n";
|
|
|
|
echo "</td><td>";
|
|
|
|
// help link
|
2009-02-07 22:56:36 +00:00
|
|
|
echo " ";
|
|
|
|
printHelpLink(getHelp('', '301'), '301');
|
|
|
|
echo "<br>\n";
|
2005-05-21 14:35:14 +00:00
|
|
|
echo "</td></tr>";
|
|
|
|
echo "</table>";
|
2004-06-27 18:07:43 +00:00
|
|
|
echo "</fieldset>\n<br>\n";
|
2005-05-21 14:35:14 +00:00
|
|
|
$_SESSION['profile_types']['ldap_suffix'] = 'select';
|
|
|
|
$_SESSION['profile_types']['ldap_rdn'] = 'select';
|
2004-06-27 18:07:43 +00:00
|
|
|
|
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;
|
2005-04-24 12:42:20 +00:00
|
|
|
echo "<fieldset class=\"" . $type . "edit\">\n";
|
2007-11-19 18:52:50 +00:00
|
|
|
$icon = '';
|
|
|
|
$module = new $modules[$m]($type);
|
|
|
|
$iconImage = $module->getIcon();
|
|
|
|
if ($iconImage != null) {
|
2007-12-01 12:34:52 +00:00
|
|
|
$icon = '<img align="middle" src="../../graphics/' . $iconImage . '" alt="' . $iconImage . '"> ';
|
2007-11-19 18:52:50 +00:00
|
|
|
}
|
|
|
|
echo "<legend>$icon<b>" . getModuleAlias($modules[$m], $type) . "</b></legend>\n";
|
2009-02-07 19:25:22 +00:00
|
|
|
$profileTypes = parseHtml($modules[$m], $options[$modules[$m]], $old_options, true, $tabindex, $type);
|
2005-03-29 16:13:44 +00:00
|
|
|
$_SESSION['profile_types'] = array_merge($profileTypes, $_SESSION['profile_types']);
|
2004-03-09 14:29:47 +00:00
|
|
|
echo "</fieldset>\n";
|
2004-06-23 19:14:07 +00:00
|
|
|
echo "<br>";
|
2004-03-09 14:29:47 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 09:43:52 +00:00
|
|
|
echo ("</form>\n");
|
|
|
|
include '../main_footer.php';
|
2004-03-09 14:29:47 +00:00
|
|
|
|
|
|
|
?>
|