LDAPAccountManager/lam/templates/profedit/profilepage.php

267 lines
8.2 KiB
PHP
Raw Normal View History

<?php
/*
$Id$
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2014 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-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
*/
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 */
include_once("../../lib/profiles.inc");
2004-06-10 22:13:39 +00:00
/** access to LDAP server */
include_once("../../lib/ldap.inc");
2004-06-10 22:13:39 +00:00
/** access to configuration options */
include_once("../../lib/config.inc");
2004-06-10 22:13:39 +00:00
/** access to account modules */
include_once("../../lib/modules.inc");
/** Used to display status messages */
include_once("../../lib/status.inc");
// start session
2006-03-26 17:51:25 +00:00
startSecureSession();
2007-12-30 13:15:39 +00:00
// die if no write access
if (!checkIfWriteAccessIsAllowed()) die();
2012-08-13 17:43:48 +00:00
checkIfToolIsActive('toolProfileEditor');
setlanguage();
// check if user is logged in, if not go to login
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
metaRefresh("../login.php");
exit;
}
// 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'];
if (isAccountTypeHidden($_GET['type']) || !checkIfWriteAccessIsAllowed($_GET['type'])) {
logNewMessage(LOG_ERR, 'User tried to access hidden account type profile: ' . $_GET['type']);
die();
}
// abort button was pressed
// back to profile editor
2006-01-25 18:31:19 +00:00
if (isset($_POST['abort'])) {
metaRefresh("profilemain.php");
exit;
}
2004-03-14 15:34:53 +00:00
$errors = array();
// save button was presed
2006-01-25 18:31:19 +00:00
if (isset($_POST['save'])) {
// 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');
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();
}
2012-08-26 14:09:22 +00:00
// textareas
if ($_SESSION['profile_types'][$element] == "textarea") {
$options[$element] = explode("\r\n", $_POST[$element]);
}
}
// 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]);
}
}
// check options
$errors = checkProfileOptions($_POST['accounttype'], $options);
if (sizeof($errors) == 0) { // input data is valid, save profile
// save profile
if (saveAccountProfile($options, $_POST['profname'], $_POST['accounttype'])) {
metaRefresh('profilemain.php?savedSuccessfully=' . $_POST['profname']);
exit();
}
else {
$errors[] = array("ERROR", _("Unable to save profile!"), $_POST['profname']);
}
}
}
// print header
include '../main_header.php';
// print error messages if any
if (sizeof($errors) > 0) {
echo "<br>\n";
for ($i = 0; $i < sizeof($errors); $i++) {
call_user_func_array('StatusMessage', $errors[$i]);
}
}
// empty list of attribute types
$_SESSION['profile_types'] = array();
// check if account type is valid
$type = $_GET['type'];
// get module options
$options = getProfileOptions($type);
// load old profile or POST values if needed
2004-03-15 16:34:16 +00:00
$old_options = array();
if (isset($_POST['save'])) {
$postKeys = array_keys($_POST);
for ($i = 0; $i < sizeof($postKeys); $i++) {
if (!is_array($_POST[$postKeys[$i]])) {
if (get_magic_quotes_gpc() == 1) {
$old_options[$postKeys[$i]] = array(stripslashes($_POST[$postKeys[$i]]));
}
else {
$old_options[$postKeys[$i]] = array($_POST[$postKeys[$i]]);
}
}
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);
}
// display formular
echo ("<form action=\"profilepage.php?type=$type\" method=\"post\">\n");
2010-09-25 16:39:07 +00:00
$profName = '';
if (isset($_GET['edit'])) {
$profName = $_GET['edit'];
}
$tabindex = 1;
2010-09-25 16:39:07 +00:00
$container = new htmlTable();
$container->addElement(new htmlTitle(_("Profile editor")), true);
2010-09-25 16:39:07 +00:00
// general options
$dnContent = new htmlTable();
$dnContent->addElement(new htmlTableExtendedInputField(_("Profile name") . '*', 'profname', $profName, '360'), true);
$dnContent->addElement(new htmlSpacer(null, '10px'), true);
// suffix box
// get root suffix
$rootsuffix = $_SESSION['config']->get_Suffix($type);
// get subsuffixes
2011-05-14 13:51:08 +00:00
$suffixes = array('-' => '-');
2011-04-25 18:01:11 +00:00
$typeObj = new $type();
$possibleSuffixes = $typeObj->getSuffixList();
foreach ($possibleSuffixes as $suffix) {
$suffixes[getAbstractDN($suffix)] = $suffix;
}
$selectedSuffix = array();
if (isset($old_options['ldap_suffix'][0])) {
$selectedSuffix[] = $old_options['ldap_suffix'][0];
}
$suffixSelect = new htmlTableExtendedSelect('ldap_suffix', $suffixes, $selectedSuffix, _("LDAP suffix"), '361');
$suffixSelect->setHasDescriptiveElements(true);
$suffixSelect->setSortElements(false);
$suffixSelect->setRightToLeftTextDirection(true);
$dnContent->addElement($suffixSelect, true);
// RDNs
2005-05-21 14:35:14 +00:00
$rdns = getRDNAttributes($type);
$selectedRDN = array();
if (isset($old_options['ldap_rdn'][0])) {
$selectedRDN[] = $old_options['ldap_rdn'][0];
}
$dnContent->addElement(new htmlTableExtendedSelect('ldap_rdn', $rdns, $selectedRDN, _("RDN identifier"), '301'), true);
2005-05-21 14:35:14 +00:00
$container->addElement(new htmlFieldset($dnContent, _("General settings"), '../../graphics/logo32.png'), true);
$container->addElement(new htmlSpacer(null, '15px'), true);
$_SESSION['profile_types'] = parseHtml(null, $container, $old_options, false, $tabindex, $type);
// 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;
2007-11-19 18:52:50 +00:00
$module = new $modules[$m]($type);
$icon = $module->getIcon();
if (($icon != null) && !(strpos($icon, 'http') === 0) && !(strpos($icon, '/') === 0)) {
$icon = '../../graphics/' . $icon;
2007-11-19 18:52:50 +00:00
}
$container = new htmlTable();
$container->addElement(new htmlFieldset($options[$modules[$m]], getModuleAlias($modules[$m], $type), $icon), true);
$container->addElement(new htmlSpacer(null, '15px'), true);
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml($modules[$m], $container, $old_options, false, $tabindex, $type));
}
// profile name and submit/abort buttons
$buttonTable = new htmlTable();
$saveButton = new htmlButton('save', _('Save'));
$saveButton->setIconClass('saveButton');
$buttonTable->addElement($saveButton);
$cancelButton = new htmlButton('abort', _('Cancel'));
$cancelButton->setIconClass('cancelButton');
$buttonTable->addElement($cancelButton);
$buttonTable->addElement(new htmlHiddenInput('accounttype', $type));
$_SESSION['profile_types'] = array_merge($_SESSION['profile_types'], parseHtml(null, $buttonTable, $old_options, false, $tabindex, $type));
?>
<script type="text/javascript">
jQuery(document).ready(function() {
var maxWidth = 0;
jQuery('fieldset').each(function() {
if (jQuery(this).width() > maxWidth) {
maxWidth = jQuery(this).width();
};
});
jQuery('fieldset').each(function() {
jQuery(this).css({'width': maxWidth});
});
});
</script>
<?php
2010-08-21 09:43:52 +00:00
echo ("</form>\n");
include '../main_footer.php';
?>