1<?php
2	/**************************************************************************\
3	* phpGroupWare - - eLDAPtir - LDAP Administration                          *
4	* http://www.phpgroupware.org                                              *
5	* Written by Miles Lott <milosch@phpgroupware.org>                         *
6	* --------------------------------------------                             *
7	*  This program is free software; you can redistribute it and/or modify it *
8	*  under the terms of the GNU General Public License as published by the   *
9	*  Free Software Foundation; either version 2 of the License, or (at your  *
10	*  option) any later version.                                              *
11	\**************************************************************************/
12
13	/* $Id: add.php 13600 2003-10-09 23:28:08Z skwashd $ */
14
15	$dn	= $_GET['dn'];
16	$ou	= $_GET['ou'];
17	$submit	= $_POST['submit'];
18
19	$GLOBALS['phpgw_info']['flags'] = array(
20		'enable_nextmatchs_class' => True,
21		'currentapp'              => 'eldaptir',
22		'parent_page'             => 'viewou.php'
23	);
24	include('../header.inc.php');
25
26	$servers = servers();
27	$server_type = $servers[$server_id]['type'];
28	$ldapobj = CreateObject('eldaptir.ldap',$servers[$server_id]);
29	$ldapobj->DEBUG = 1;
30
31	if ($submit && $dn)
32	{
33		// This doesn't touch LDAP yet, just displays what might occur
34		echo "<br>Form values:";
35		$thisdn = urldecode($dn);
36		$entry  = $ldapobj->read($thisdn);
37		while (list($key,$objectclass) = each($entry[0]['objectclass']))
38		{
39			$object = strtolower($objectclass);
40			if($ldapobj->$object)
41			{
42				echo "<br><br>Checking: ".$object;
43				while(list($attrib,$req) = @each($ldapobj->$object))
44				{
45					$lattrib = strtolower($attrib);
46					if($ldapobj->DEBUG)
47					{
48						echo "<br>". $object."[".$lattrib."] = "
49							. ${$object}[$lattrib];
50					}
51
52					if (${$object}[$lattrib] && !$ldapobj->entry[$lattrib])
53					{
54						$ldapobj->entry[$lattrib] = ${$object}[$lattrib];
55					}
56				}
57			}
58		}
59		if($ldapobj->DEBUG) { echo "<br><br>Entry values:"; }
60		while (list($key,$val) = each($entry[0]))
61		{
62			if($ldapobj->clean($val))
63			{
64				if (is_array($val))
65				{
66					while(list($v) = each($val))
67					{
68						if($ldapobj->clean($v))
69						{
70							if($ldapobj->DEBUG) { echo '<br>arr '.$v.': '.$entry[0][$v][0]."\n"; }
71						}
72					}
73				}
74				else
75				{
76					if($ldapobj->DEBUG) { echo '<br>str '.$val.': '.$entry[0][$val][0]."\n"; }
77				}
78			}
79		}
80		//$GLOBALS['phpgw']->common->phpgw_footer();
81		//exit;
82		//...
83		$ldapobj->add($thisdn);
84		$GLOBALS['phpgw']->common->phpgw_footer();
85		$GLOBALS['phpgw']->common->exit();
86	}
87
88	$GLOBALS['phpgw']->template->set_unknowns('remove');
89	$GLOBALS['phpgw']->template->set_file(array('add' => 'add.tpl'));
90	$GLOBALS['phpgw']->template->set_block('add','header','header');
91	$GLOBALS['phpgw']->template->set_block('add','row','row');
92	$GLOBALS['phpgw']->template->set_block('add','footer','footer');
93
94	$GLOBALS['phpgw']->template->set_var('title','<a href="'.$GLOBALS['phpgw']->link('/eldaptir','server_id='.$server_id).'">'.lang('eldaptir')."</a>\n");
95	$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
96	$GLOBALS['phpgw']->template->set_var('tr_color1',$GLOBALS['phpgw_info']['theme']['row_on']);
97	$GLOBALS['phpgw']->template->set_var('tr_color2',$GLOBALS['phpgw_info']['theme']['row_off']);
98	$GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel'));
99	$GLOBALS['phpgw']->template->set_var('lang_addobj',lang('Add').' '.lang('Objectclass'));
100	$GLOBALS['phpgw']->template->set_var('lang_submit',lang('Submit'));
101	$GLOBALS['phpgw']->template->set_var('lang_dn',lang('dn'));
102	$GLOBALS['phpgw']->template->set_var('lang_obj',lang('Objectclass'));
103	$GLOBALS['phpgw']->template->set_var('lang_attr',lang('Attribute'));
104	$GLOBALS['phpgw']->template->set_var('lang_value',lang('Value'));
105	$GLOBALS['phpgw']->template->set_var('lang_rule',lang('Rule'));
106	$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/eldaptir/add.php','server_id='.$server_id.'&ou='.$ou));
107	//$GLOBALS['phpgw']->template->set_var('addobj_url',$GLOBALS['phpgw']->link('/eldaptir/add.php','ou='.$ou.'&dn='.$dn.'&server_id='.$server_id));
108	// following needs to work properly first
109	$GLOBALS['phpgw']->template->set_var('addobj_url',$GLOBALS['phpgw']->link('/eldaptir/addobj.php','dn='.$dn));
110	$GLOBALS['phpgw']->template->set_var('hidden_vars','<input type="hidden" name ="dn" value="'.$dn.'">');
111	$GLOBALS['phpgw']->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/eldaptir/viewou.php','ou='.$ou.'&nisMapName='.$nisMapName.'&server_id='.$server_id));
112
113	if ($addobj)
114	{
115		while(list($key,$oc) = each($ldapobj->objectclasses))
116		{
117			eval("if \(\$\$oc=='on'\) { \$newoc \.= \$oc\.';'; }");
118		}
119		$addto = explode(';',$newoc);
120		$ldapobj->form_addobj($dn,$addto);
121	}
122
123	$userData = $ldapobj->create($ou,$nisMapName);
124	$thisdn   = '<input size="30" name="dn" value="'.$ldapobj->objkey.'=,ou='.$ou.','.$ldapobj->base.'">';
125	$GLOBALS['phpgw']->template->set_var('dn',$thisdn);
126	$GLOBALS['phpgw']->template->pparse('out','header');
127
128	while (list($key,$objectclass) = each($userData[0]['objectclass']))
129	{
130		if (gettype($objectclass) == 'string')
131		{
132			$object = strtolower($objectclass);
133			$tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
134			$GLOBALS['phpgw']->template->set_var(tr_color,$tr_color);
135			$GLOBALS['phpgw']->template->set_var('objectclass',$object);
136			$GLOBALS['phpgw']->template->set_var('row_name','&nbsp;');
137			$GLOBALS['phpgw']->template->set_var('row_value','&nbsp;');
138			$GLOBALS['phpgw']->template->set_var('row_rule','&nbsp;');
139			$GLOBALS['phpgw']->template->parse('rows','row',True);
140			$GLOBALS['phpgw']->template->pparse('out','row');
141			if (is_array($ldapobj->$object))
142			{
143				@reset($ldapobj->$object);
144				while(list($attrib,$req) = each($ldapobj->$object))
145				{
146					$lattrib = strtolower($attrib);
147					if ($req) { $required = lang('required'); }
148					else { $required = lang('optional'); }
149					if ($userData[0][$lattrib][0] || $userData[0][$attrib][0])
150					{
151						if ($userData[0][$attrib])
152						{
153							$tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
154							$GLOBALS['phpgw']->template->set_var(tr_color,$tr_color);
155							$GLOBALS['phpgw']->template->set_var('objectclass','&nbsp;');
156							$GLOBALS['phpgw']->template->set_var('row_name',$attrib);
157							$GLOBALS['phpgw']->template->set_var('row_value','<input size="30" name="'.$object.'['.$attrib.']" value="'.$userData[0][$attrib][0].'">');
158							$GLOBALS['phpgw']->template->set_var('row_rule',$required);
159							$GLOBALS['phpgw']->template->parse('rows','row',True);
160						}
161						else
162						{
163							$tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
164							$GLOBALS['phpgw']->template->set_var(tr_color,$tr_color);
165							$GLOBALS['phpgw']->template->set_var('objectclass','&nbsp;');
166							$GLOBALS['phpgw']->template->set_var('row_name',$attrib);
167							$GLOBALS['phpgw']->template->set_var('row_value','<input size="30" name="'.$object.'['.$lattrib.']" value="'.$userData[0][$lattrib][0].'">');
168							$GLOBALS['phpgw']->template->set_var('row_rule',$required);
169							$GLOBALS['phpgw']->template->parse('rows','row',True);
170						}
171					}
172					else
173					{
174						$tr_color = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($tr_color);
175						$GLOBALS['phpgw']->template->set_var(tr_color,$tr_color);
176						$GLOBALS['phpgw']->template->set_var('objectclass','&nbsp;');
177						$GLOBALS['phpgw']->template->set_var('row_name',$attrib);
178						$GLOBALS['phpgw']->template->set_var('row_value','<input size="30" name="'.$object.'['.$attrib.']" value="">');
179						$GLOBALS['phpgw']->template->set_var('row_rule',$required);
180						$GLOBALS['phpgw']->template->parse('rows','row',True);
181					}
182					$GLOBALS['phpgw']->template->pparse('out','row');
183				}
184			}
185		}
186	}
187
188	$GLOBALS['phpgw']->template->pparse('out','footer');
189	$GLOBALS['phpgw']->common->phpgw_footer();
190?>
191