2009-06-30 09:22:30 +00:00
< ? php
2009-06-30 11:52:55 +00:00
// $Header: /cvsroot/phpldapadmin/phpldapadmin/htdocs/add_value.php,v 1.21.2.2 2008/12/12 12:20:22 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
*
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 10:46:00 +00:00
if ( $ldapserver -> isReadOnly ())
2009-06-30 11:52:55 +00:00
error ( _ ( 'You cannot perform updates while server is in read-only mode' ), 'error' , 'index.php' );
2009-06-30 08:05:37 +00:00
2009-06-30 11:46:44 +00:00
if ( ! $_SESSION [ APPCONFIG ] -> isCommandAvailable ( 'attribute_add_value' ))
2009-06-30 11:52:55 +00:00
error ( sprintf ( '%s%s %s' , _ ( 'This operation is not permitted by the configuration' ), _ ( ':' ), _ ( 'add attribute value' )), 'error' , 'index.php' );
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
# The DN and ATTR we are working with.
2009-06-30 11:52:55 +00:00
$entry = array ();
2009-06-30 10:46:00 +00:00
$entry [ 'dn' ][ 'encode' ] = get_request ( 'dn' , 'POST' , true );
$entry [ 'dn' ][ 'string' ] = rawurldecode ( $entry [ 'dn' ][ 'encode' ]);
$entry [ 'attr' ][ 'encode' ] = get_request ( 'attr' , 'POST' , true );
$entry [ 'attr' ][ 'string' ] = rawurldecode ( $entry [ 'attr' ][ 'encode' ]);
$entry [ 'attr' ][ 'html' ] = htmlspecialchars ( $entry [ 'attr' ][ 'string' ]);
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
$entry [ 'value' ][ 'string' ] = get_request ( 'new_value' , 'POST' , true );
$entry [ 'value' ][ 'bin' ] = get_request ( 'binary' , 'POST' ) ? true : false ;
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if ( $ldapserver -> isAttrReadOnly ( $entry [ 'attr' ][ 'string' ]))
2009-06-30 11:52:55 +00:00
error ( sprintf ( _ ( 'The attribute "%s" is flagged as read-only in the phpLDAPadmin configuration.' ), $entry [ 'attr' ][ 'html' ]), 'error' , 'index.php' );
2009-06-30 08:07:14 +00:00
2009-06-30 10:46:00 +00:00
/*
* Special case for binary attributes :
* we must go read the data from the file .
*/
if ( $entry [ 'value' ][ 'bin' ]) {
$binaryfile [ 'name' ] = $_FILES [ 'new_value' ][ 'tmp_name' ];
$binaryfile [ 'handle' ] = fopen ( $binaryfile [ 'name' ], 'r' );
$binaryfile [ 'data' ] = fread ( $binaryfile [ 'handle' ], filesize ( $binaryfile [ 'name' ]));
fclose ( $binaryfile [ 'handle' ]);
2009-06-30 09:29:51 +00:00
2009-06-30 10:46:00 +00:00
$entry [ 'value' ][ 'string' ] = $binaryfile [ 'data' ];
2009-06-30 08:05:37 +00:00
}
2009-06-30 10:46:00 +00:00
$new_entry = array ( $entry [ 'attr' ][ 'string' ] => $entry [ 'value' ][ 'string' ]);
2009-06-30 09:22:30 +00:00
2009-06-30 10:46:00 +00:00
# Check to see if this is a unique Attribute
if ( $badattr = $ldapserver -> checkUniqueAttr ( $entry [ 'dn' ][ 'string' ], $entry [ 'attr' ][ 'string' ], $new_entry )) {
$href = htmlspecialchars ( sprintf ( 'cmd.php?cmd=search&search=true&form=advanced&server_id=%s&filter=%s=%s' ,
$ldapserver -> server_id , $entry [ 'attr' ][ 'string' ], $badattr ));
2009-06-30 11:52:55 +00:00
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.' ), $entry [ 'attr' ][ 'string' ], $badattr , $entry [ 'dn' ][ 'string' ], $href ), 'error' , 'index.php' );
2009-06-30 09:22:30 +00:00
}
2009-06-30 10:46:00 +00:00
# Call the custom callback for each attribute modification and verify that it should be modified.
if ( run_hook ( 'pre_attr_add' ,
array ( 'server_id' => $ldapserver -> server_id , 'dn' => $entry [ 'dn' ][ 'string' ], 'attr_name' => $entry [ 'attr' ][ 'string' ], 'new_value' => $new_entry ))) {
if ( run_hook ( 'pre_attr_modify' ,
array ( 'server_id' => $ldapserver -> server_id , 'dn' => $entry [ 'dn' ][ 'string' ], 'attr_name' => $entry [ 'attr' ][ 'string' ], 'new_value' => $new_entry ))) {
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
$add_result = $ldapserver -> attrModify ( $entry [ 'dn' ][ 'string' ], $new_entry );
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
if ( ! $add_result ) {
2009-06-30 11:52:55 +00:00
system_message ( array (
'title' => _ ( 'Could not perform ldap_mod_add operation.' ),
'body' => ldap_error_msg ( $ldapserver -> error (), $ldapserver -> errno ()),
'type' => 'error' ));
2009-06-30 10:46:00 +00:00
} else {
run_hook ( 'post_attr_modify' ,
array ( 'server_id' => $ldapserver -> server_id , 'dn' => $entry [ 'dn' ][ 'string' ], 'attr_name' => $entry [ 'attr' ][ 'string' ], 'new_value' => $new_entry ));
}
}
2009-06-30 09:22:30 +00:00
}
2009-06-30 08:05:37 +00:00
2009-06-30 10:46:00 +00:00
header ( sprintf ( 'Location: cmd.php?cmd=template_engine&server_id=%s&dn=%s&modified_attrs[]=%s' ,
$ldapserver -> server_id , $entry [ 'dn' ][ 'encode' ], $entry [ 'attr' ][ 'encode' ]));
die ();
2009-06-30 08:05:37 +00:00
?>