<?php
// Connect to SIMS LDAP server and return values

$need_horde_db = 0;
$db_lib_loaded = 0;

require( './config/defaults.php3' );     /* Defaults configuration file */

/* Html styles configuration */
require('./config/html.php3');


$ds=ldap_connect("$default->sims_server");  // must be a valid LDAP server!

if ($ds) {
$r=ldap_bind($ds);     // this is an "anonymous" bind

//Search for the values we need.

$sr=ldap_search($ds,"$default->sims_base",  "uid=$user" );
$info = ldap_get_entries($ds, $sr);
	for ($i=0; $i<$info["count"]; $i++) {
	$user_dn =  $info[$i]["dn"]  ;
    if(isset($info[$i]["maildeliveryoption"])){
    $delivery_list = $info[$i]["maildeliveryoption"];
    }
    if(isset($info[$i]["mailforwardingaddress"])){ 
	$forward_list = $info[$i]["mailforwardingaddress"] ;
    }
    if(isset($info[$i]["mailautoreplymode"])){
   	$auto_reply = $info[$i]["mailautoreplymode"] ;
    }
    if(isset($info[$i]["mailautoreplyexpirationdate"])){
    	$exp_date = $info[$i]["mailautoreplyexpirationdate"] ;
    }
    if(isset($info[$i]["mailautoreplysubject"])){
    	$vac_subject = $info[$i]["mailautoreplysubject"] ;
    }
    if(isset($info[$i]["mailautoreplytext"])){
    	$ext_text = $info[$i]["mailautoreplytext"] ;
    }
    if(isset($info[$i]["mailautoreplytextinternal"])){
    	$int_text = $info[$i]["mailautoreplytextinternal"] ;
    }

}
ldap_close($ds);

} else {
	echo "<h4>Unable to connect to LDAP server</h4>";
}


$delivery_count = count($delivery_list);

$forward_address = '<SELECT SIZE=2 NAME="delete_address" MULTIPLE>';

if (isset($forward_list)) {
	$forw_count = count($forward_list);
	$forw_count = ($forw_count - 1);

	for ($i = 0; $i < $forw_count; $i++) {
   		$val = $forward_list[$i];
   		$forward_address .= "<option>$val</option>\n";
	}
}

$forward_address .= '</SELECT>';

if (($delivery_list[0] == "mailbox" ) && (isset($delivery_list[1]) )){
        $deliv_select = $lang->cur_fwd_mbox ;
 	$fwd_mbox ='CHECKED';
} else ($fwd_mbox ='UNCHECKED');

if ($delivery_list[0] == "forward" ){
        $deliv_select = $lang->cur_fwd ;
 	$fwd ='CHECKED';
} else ($fwd ='UNCHECKED');

if (($delivery_list[0] == "mailbox") && (!isset($delivery_list[1]) )) {
        $deliv_select = $lang->cur_mbox ; 
 	$mbox ='CHECKED';
} else ($mbox ='UNCHECKED');

if (!isset($exp_date[0])){
	$exp_yy = '00';
	$exp_mm = '12';
	$exp_dd = '31';
} else {
	$exp_yy = substr($exp_date[0], 0, 2);
	$exp_mm = substr($exp_date[0], 2, 2);
	$exp_dd = substr($exp_date[0], 4, 2);
}

if (!isset($vac_subject)){
	$vac_subject = ' ';
}

if (!isset($ext_text)){
    	$ext_text = array('');
}

$full_date = "$exp_mm /";
$full_date .= "$exp_dd /";
$full_date .= "$exp_yy";

$num = count($delivery_list);
$num = ($num - 2);
if ($delivery_list[$num] == 'autoreply') {
        $vac_select = $lang->vacation_on ;
    	$vac_select .= $full_date ;
    	$vac = 'CHECKED';
} else{
 $vac_select = $lang->vacation_off ;
} 

$date_form = "<input type=\"text\" name=\"expdatemm\" value=$exp_mm size=2 maxlength=2>/";
$date_form .= "<input type=\"text\" name=\"expdatedd\" value=$exp_dd  size=2 maxlength=2>/";
$date_form .= "<input type=\"text\" name=\"expdateyy\" value=$exp_yy  size=2 maxlength=2>/";

if(isset($ext_text[0])) $new_ext_text = str_replace('\n', " \n", $ext_text[0]) ;

?>

