phpldapadmin/htdocs/add_value.php

75 lines
2.5 KiB
PHP
Raw Normal View History

2009-06-30 09:22:30 +00:00
<?php
2009-06-30 10:40:03 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_value.php,v 1.20 2005/12/10 10:34:54 wurley Exp $
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
/**
2009-06-30 08:05:37 +00:00
* Adds a value to an attribute for a given dn.
2009-06-30 09:29:51 +00:00
*
* Variables that come in via common.php
* - server_id
2009-06-30 08:05:37 +00:00
* Variables that come in as POST vars:
* - dn (rawurlencoded)
2009-06-30 09:29:51 +00:00
* - attr (rawurlencoded) the attribute to which we are adding a value
2009-06-30 08:05:37 +00:00
* - new_value (form element)
2009-06-30 09:29:51 +00:00
* - binary
2009-06-30 08:05:37 +00:00
*
2009-06-30 09:29:51 +00:00
* On success, redirect to the edit_dn page. On failure, echo an error.
*
* @package phpLDAPadmin
*/
/**
2009-06-30 08:05:37 +00:00
*/
2009-06-30 09:22:30 +00:00
require './common.php';
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if( $ldapserver->isReadOnly() )
2009-06-30 10:26:08 +00:00
pla_error( _('You cannot perform updates while server is in read-only mode') );
2009-06-30 09:29:51 +00:00
if( ! $ldapserver->haveAuthInfo())
2009-06-30 10:26:08 +00:00
pla_error( _('Not enough information to login to server. Please check your configuration.') );
2009-06-30 09:29:51 +00:00
2009-06-30 08:07:14 +00:00
$attr = $_POST['attr'];
$new_value = $_POST['new_value'];
2009-06-30 09:29:51 +00:00
$dn = rawurldecode( $_POST['dn'] );
2009-06-30 08:07:14 +00:00
$is_binary_val = isset( $_POST['binary'] ) ? true : false;
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
$encoded_dn = rawurlencode( $dn );
$encoded_attr = rawurlencode( $attr );
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
if ($ldapserver->isAttrReadOnly($attr))
pla_error(sprintf(_('The attribute "%s" is flagged as read-only in the phpLDAPadmin configuration.'),htmlspecialchars( $attr )));
2009-06-30 08:07:14 +00:00
2009-06-30 09:29:51 +00:00
// special case for binary attributes:
2009-06-30 08:05:37 +00:00
// we must go read the data from the file.
2009-06-30 09:29:51 +00:00
if( $is_binary_val ) {
2009-06-30 08:07:14 +00:00
$file = $_FILES['new_value']['tmp_name'];
2009-06-30 09:29:51 +00:00
2009-06-30 08:05:37 +00:00
$f = fopen( $file, 'r' );
2009-06-30 08:07:14 +00:00
$binary_value = fread( $f, filesize( $file ) );
2009-06-30 08:05:37 +00:00
fclose( $f );
2009-06-30 09:29:51 +00:00
2009-06-30 08:07:14 +00:00
$new_value = $binary_value;
2009-06-30 08:05:37 +00:00
}
2009-06-30 09:29:51 +00:00
$new_entry = array( $attr => $new_value );
2009-06-30 09:22:30 +00:00
// Check to see if this is a unique Attribute
2009-06-30 10:26:08 +00:00
if ($badattr = $ldapserver->checkUniqueAttr($dn,$attr,$new_entry)) {
2009-06-30 09:29:51 +00:00
$search_href = sprintf('search.php?search=true&form=advanced&server_id=%s&filter=%s=%s',$ldapserver->server_id,$attr,$badattr);
2009-06-30 10:26:08 +00:00
pla_error(sprintf( _('Your attempt to add <b>%s</b> (<i>%s</i>) to <br><b>%s</b><br> is NOT allowed. That attribute/value belongs to another entry.<p>You might like to <a href=\'%s\'>search</a> for that entry.'),$attr,$badattr,$dn,$search_href ) );
2009-06-30 09:22:30 +00:00
}
// Call the custom callback for each attribute modification
// and verify that it should be modified.
2009-06-30 09:29:51 +00:00
if( run_hook ( 'pre_attr_add', array ( 'server_id' => $ldapserver->server_id, 'dn' => $dn, 'attr_name' => $attr,
'new_value' => $new_entry ) ) ) {
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
$add_result = $ldapserver->attrModify($dn,$new_entry);
2009-06-30 08:05:37 +00:00
2009-06-30 09:29:51 +00:00
if (! $add_result)
2009-06-30 10:26:08 +00:00
pla_error(_('Could not perform ldap_mod_add operation.'),
2009-06-30 09:40:37 +00:00
$ldapserver->error(),$ldapserver->errno());
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 10:26:08 +00:00
header(sprintf('Location: template_engine.php?server_id=%s&dn=%s&modified_attrs[]=%s',
2009-06-30 09:29:51 +00:00
$ldapserver->server_id,$encoded_dn,$encoded_attr));
2009-06-30 08:05:37 +00:00
?>