phpldapadmin/htdocs/modify_member_form.php

179 lines
5.9 KiB
PHP
Raw Permalink Normal View History

2009-06-30 10:41:18 +00:00
<?php
/**
* Displays a form to allow the user to modify group members.
*
* @package phpLDAPadmin
* @subpackage Page
2009-06-30 10:41:18 +00:00
*/
2009-06-30 10:41:18 +00:00
/**
*/
require './common.php';
# The DN we are working with
$request = array();
$request['dn'] = get_request('dn','GET');
$request['attr'] = get_request('attr','GET');
2009-06-30 10:41:18 +00:00
$request['page'] = new TemplateRender($app['server']->getIndex(),get_request('template','REQUEST',false,null));
$request['page']->setDN($request['dn']);
$request['page']->accept(true);
$request['template'] = $request['page']->getTemplate();
2009-06-30 10:41:18 +00:00
if (! is_null($request['dn']))
$rdn = get_rdn($request['dn']);
2009-06-30 10:41:18 +00:00
else
$rdn = null;
# Get all current group members
$current_members = $app['server']->getDNAttrValue($request['dn'],$request['attr']);
2009-06-30 11:52:55 +00:00
usort($current_members,'pla_compare_dns');
2009-06-30 10:41:18 +00:00
# Loop through all base dn's and search possible member entries
$query = array();
2009-06-30 10:41:18 +00:00
# Get all entries that can be added to the group
if (preg_match("/^".$request['attr']."$/i",$_SESSION[APPCONFIG]->getValue('modify_member','posixgroupattr'))) {
$query['filter'] = $_SESSION[APPCONFIG]->getValue('modify_member','posixfilter');
$attr = $_SESSION[APPCONFIG]->getValue('modify_member','posixattr');
2009-06-30 10:46:00 +00:00
} else {
$query['filter'] = $_SESSION[APPCONFIG]->getValue('modify_member','filter');
$attr = $_SESSION[APPCONFIG]->getValue('modify_member','attr');
2009-06-30 10:41:18 +00:00
}
$query['attrs'] = array($attr);
2009-06-30 10:41:18 +00:00
$possible_values = array();
foreach ($app['server']->getBaseDN() as $base) {
$query['base'] = $base;
2009-06-30 10:41:18 +00:00
$possible_values = array_merge($possible_values,$app['server']->query($query,null));
}
2009-06-30 10:41:18 +00:00
usort($possible_values,'pla_compare_dns');
2009-06-30 10:41:18 +00:00
$request['page']->drawTitle(sprintf('%s <b>%s</b>',_('Modify group'),get_rdn($request['dn'])));
$request['page']->drawSubTitle();
2009-06-30 10:41:18 +00:00
printf('%s <b>%s</b> %s <b>%s</b>:',
_('There are'),count($current_members),_('members in group'),htmlspecialchars(get_rdn($request['dn'])));
2009-06-30 10:41:18 +00:00
2009-06-30 11:52:55 +00:00
$possible_members = array();
for ($i=0;$i<count($possible_values);$i++) {
if (preg_match("/^".$request['attr']."$/i",$_SESSION[APPCONFIG]->getValue('modify_member','posixgroupattr')))
$possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member','posixattr')][0];
2009-06-30 10:41:18 +00:00
else
$possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member','attr')];
2009-06-30 10:41:18 +00:00
}
# Show only user that are not already in group.
$possible_members = array_diff($possible_members,$current_members);
2009-06-30 11:52:55 +00:00
usort($possible_members,'pla_compare_dns');
2009-06-30 10:41:18 +00:00
/* Draw form with select boxes, left for all possible members and
* right one for those that belong to group */
2009-06-30 10:41:18 +00:00
# Modifications will be sent to update_confirm which takes care of rest of the processing
echo '<br />';
echo '<br />';
2009-08-22 11:30:50 +00:00
2010-02-24 15:03:10 +00:00
echo '<form action="cmd.php" method="post" class="add_value" id="member">';
echo '<div>';
if ($_SESSION[APPCONFIG]->getValue('confirm','update'))
echo '<input type="hidden" name="cmd" value="update_confirm" />';
else
echo '<input type="hidden" name="cmd" value="update" />';
2010-02-24 15:03:10 +00:00
echo '</div>';
2009-06-30 10:41:18 +00:00
echo '<table class="modify_members">';
echo '<tr>';
printf('<td><img src="%s/ldap-user.png" alt="Users" /> %s</td>',IMGDIR,_('Available members'));
printf('<td><img src="%s/ldap-uniquegroup.png" alt="Members" /> %s</td>',IMGDIR,_('Group members'));
2009-06-30 10:41:18 +00:00
echo '</tr>';
# Generate select box from all possible members
echo '<tr>';
echo '<td>';
2010-02-24 15:03:10 +00:00
echo '<select name="notmembers" size="10" multiple="multiple">';
2009-06-30 10:41:18 +00:00
switch ($request['attr']) {
case 'nisnetgrouptriple':
foreach ($possible_members as $possible) {
// Added for output formating
$matches = preg_split('/[=,]/',$possible);
$possible = sprintf('(,%s,)',$matches[1]);
if (! in_array($possible,$current_members))
printf('<option>%s</option>',$possible);
}
break;
case ('memberuid' || 'member' || 'uniquemember'):
foreach ($possible_members as $possible) {
if (! in_array($possible,$current_members))
printf('<option>%s</option>',$possible);
}
break;
}
2009-06-30 10:41:18 +00:00
echo '</select>';
echo '</td>';
# Generate select box from all current members
echo '<td>';
2010-02-24 15:03:10 +00:00
echo '<select name="members" size="10" multiple="multiple">';
2009-06-30 10:41:18 +00:00
foreach ($current_members as $current)
2010-02-24 15:03:10 +00:00
printf('<option>%s</option>',htmlspecialchars($current));
2009-06-30 10:41:18 +00:00
echo '</select>';
echo '</td>';
echo '</tr>';
# Show buttons which move users from left to right and vice versa
echo '<tr>';
echo '<td>';
2010-02-24 15:03:10 +00:00
printf('<input type="button" onclick="one2two()" value="%s >>" />&nbsp;<input type="button" onclick="all2two()" value="%s >>" />',
2009-06-30 10:41:18 +00:00
_('Add selected'),_('Add all'));
echo '</td>';
echo '<td>';
2010-02-24 15:03:10 +00:00
printf('<input type="button" onclick="two2one()" value="<< %s" />&nbsp;<input type="button" onclick="all2one()" value="<< %s" />',
2009-06-30 10:41:18 +00:00
_('Remove selected'),('Remove all'));
echo '</td>';
echo '</tr>';
echo '<tr><td colspan="2">';
# Hidden attributes for update_confirm.php
printf('<input type="hidden" name="server_id" value="%s" />',$app['server']->getIndex());
printf('<input type="hidden" name="dn" value="%s" />',rawurlencode($request['dn']));
printf('<input type="hidden" name="attr" value="%s" />',$request['attr']);
2009-06-30 10:41:18 +00:00
/* Generate array of input text boxes from current members.
* update_confirm.php will see this as old_values[member-attribute][item] */
for ($i=0; $i<count($current_members); $i++)
2009-06-30 10:41:18 +00:00
printf('<input type="hidden" name="old_values[%s][%s]" value="%s" />',
htmlspecialchars($request['attr']),$i,htmlspecialchars($current_members[$i]));
/* Javascript generates array of input text boxes from new members.
2009-06-30 10:41:18 +00:00
* update_confirm.php will see this as new_values[member-attribute][item]
* Input text boxes will be generated to div=dnu */
2009-06-30 10:41:18 +00:00
echo '<div id="dnu">';
printf('<input type="hidden" name="new_values[%s][]" value="" />',htmlspecialchars($request['attr']));
2009-06-30 10:41:18 +00:00
echo '</div>';
# Submit values to update_confirm.php and when clicked, run addSelected
2010-02-24 15:03:10 +00:00
printf('<input type="submit" name="save" value="%s" onclick="update_new_values(\'%s\')" />',_('Save changes'),$request['attr']);
2009-06-30 10:41:18 +00:00
echo '</td></tr>';
echo '</table>';
echo '</form>';
2010-02-24 15:03:10 +00:00
printf('<script type="text/javascript" src="%smodify_member.js"></script>',JSDIR);
2009-06-30 10:41:18 +00:00
?>