<?php
/* $Id: save_ldap.inc.php,v 1.10 2003/11/18 20:36:34 k-fish Exp $ */
if(!defined("SETUP_RUNNING")) die('Use index.php for running setup!');

include("../include/crypt.inc.php");

/* array to store the errors that occured */
$errors = array();

if($_SESSION["SETUP"]["auth_method"]=="ldap") {
    if($_POST["auth_ldaptype"]=="") {
    	$ldaperrorarray[] = Lang::getLanguageString("err_ldap_type");
        $errors["auth_ldaptype"] = 1;
    } else {
    	$_SESSION["SETUP"]["auth_ldaptype"] = $_POST["auth_ldaptype"];
    }
    if($_POST["auth_ldaphost"]=="") {
    	$ldaperrorarray[] = Lang::getLanguageString("err_ldap_host");
        $errors["auth_ldaphost"] = 1;
    } else {
    	$_SESSION["SETUP"]["auth_ldaphost"] = $_POST["auth_ldaphost"];
    }
    if($_POST["auth_ldapbase"]=="") {
    	$ldaperrorarray[] = Lang::getLanguageString("err_ldap_base");
        $errors["auth_ldapbase"] = 1;
    } else {
    	$_SESSION["SETUP"]["auth_ldapbase"] = $_POST["auth_ldapbase"];
    }
    if($_POST["auth_ldapuid"]=="") {
    	$ldaperrorarray[] = Lang::getLanguageString("err_ldap_uid");
        $errors["auth_ldapuid"] = 1;
    } else {
    	$_SESSION["SETUP"]["auth_ldapuid"] = $_POST["auth_ldapuid"];
    }
    if($_POST["auth_ldappasswd"]=="") {
    	$ldaperrorarray[] = Lang::getLanguageString("err_ldap_passwd");
        $errors["auth_ldappasswd"] = 1;
    } else {
	$myC = new Crypto();
	$_SESSION["SETUP"]["auth_ldappasswd"] = $myC->encrypt("moregroupware", $_POST["auth_ldappasswd"]);
    }
    if($_POST["auth_ldapsuffixe"]=="") {
    	$ldaperrorarray[] = Lang::getLanguageString("err_ldap_suffixe");
        $errors["auth_ldapsuffixe"] = 1;
    }   else {
    	$_SESSION["SETUP"]["auth_ldapsuffixe"] = $_POST["auth_ldapsuffixe"];
    }                      
    $_SESSION["SETUP"]["create_accounts_on_login"] = $_POST["create_accounts_on_login"];
    $_SESSION["SETUP"]["encrypt_pwd"] = 0;
}

/* if no error occured unset the array */
if (count($errors)==0) unset($errors);
if (count($ldaperrorarray)==0) unset($ldaperrorarray);

/* all settings ok? */
if (!isset($errors) and !isset($ldaperrorarray)) $_SESSION["SETUP"]["ldap_ok"] = true;

?>