<?php
	/**************************************************************************\
	* phpGroupWare - - eLDAPtir - LDAP Administration                          *
	* http://www.phpgroupware.org                                              *
	* Written by Kazuya Nouchi <kazuya@dokidoki.ne.jp>                         *
	* --------------------------------------------                             *
	*  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.                                              *
	\**************************************************************************/

	/* $Id: delete.php,v 1.1.12.1 2004/09/26 11:15:52 kazuyan Exp $ */

	foreach($_POST as $key => $val)
	{
		$$key = $_POST[$key];
	}
	foreach($_GET as $key => $val)
	{
		$$key = $$key ? $$key : $_GET[$key];
	}

	$thisdn = urldecode($dn);
	if (!$dn || !$server_id)
	{
		$GLOBALS['phpgw_info']['flags'] = array(
			'nonavbar' => True,
			'noheader' => True
		);
		include('../header.inc.php');
		Header('Location: ' . $GLOBALS['phpgw']->link('/eldaptir/index.php'));
	}
	elseif ($confirm)
	{		
		$GLOBALS['phpgw_info']['flags'] = array(
			'noheader' 		=> True, 
			'nonavbar' 		=> True
		);
	}
	else
	{
		$GLOBALS['phpgw_info']['flags'] = array(
			'enable_nextmatchs_class' => True,
			'currentapp'              => 'eldaptir',
			'parent_page'             => 'viewou.php'
		);
	}
	$GLOBALS['phpgw_info']['flags']['currentapp'] = 'eldaptir';
	include('../header.inc.php');
	$codecv = CreateObject('phpgwapi.codecv');
	
	unset($error_message);
	if ($confirm)
	{
		$servers = servers();
		$server_type = $servers[$server_id]['type'];
		$ldapobj = CreateObject('eldaptir.ldap',$servers[$server_id]);
		if ($ldapobj->delete(array('dn' => $thisdn)) != 99)

			Header('Location: ' . $GLOBALS['phpgw']->link('/eldaptir/viewou.php',"ou=$ou&server_id=$server_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter"));
		else
			$error_message = '<font color="red">'. ldap_error($ldapobj->ldap) . "</font>\n";
	}

	$hidden_vars =
		'<input type="hidden" name="sort" value="' . $sort . '">' . "\n"
		. '<input type="hidden" name="order" value="' . $order . '">' . "\n"
		. '<input type="hidden" name="query" value="' . $query . '">' . "\n"
		. '<input type="hidden" name="start" value="' . $start . '">' . "\n"
		. '<input type="hidden" name="filter" value="' . $filter . '">' . "\n"
		. '<input type="hidden" name="server_id" value="' . $server_id . '">' . "\n";

	$GLOBALS['phpgw']->template->set_unknowns('remove');
	$GLOBALS['phpgw']->template->set_file(array('dn_delete' => 'delete_common.tpl'));
	$GLOBALS['phpgw']->template->set_var('messages',nl2br("$error_message<b>".$codecv->utf8toeuc($thisdn)."</b>\n\n").lang('Are you sure you want to delete this entry ?'));
	$nolinkf = $GLOBALS['phpgw']->link('/eldaptir/viewou.php',"ou=$ou&server_id=$server_id&start=$start&query=$query&sort=$sort&order=$order&filter=$filter");
	$nolink = '<input type="button" onclick="javascript:location.href=' . "'$nolinkf'" . '" value="' . lang('No') . '">';
	$GLOBALS['phpgw']->template->set_var('no',$nolink);
	
	$yeslinkf = '<FORM method="POST" name="yesbutton" action="' . $GLOBALS['phpgw']->link('/eldaptir/delete.php') . '">'
		. $hidden_vars
		. '<input type="hidden" name="server_id" value="' . $server_id . '">'
		. '<input type="hidden" name="dn" value="' . $dn . '">'
		. '<input type="hidden" name="ou" value="' . $ou . '">'
		. '<input type="hidden" name="confirm" value="True">'
		. '<input type="submit" name="yesbutton" value="' . lang('Yes'). '">'
		. '</FORM><SCRIPT>document.yesbutton.yesbutton.focus()</SCRIPT>';

	$yeslink = "<a href=\"$yeslinkf\">" . lang('Yes') ."</a>";
	$yeslink = $yeslinkf;
	$GLOBALS['phpgw']->template->set_var('yes',$yeslink);
	
	$GLOBALS['phpgw']->template->pparse('out','dn_delete');

	$GLOBALS['phpgw']->common->phpgw_footer();
?>