[imp] [IMP 2.2.5] How to export a variable on mailbox.php3 in order to see it also on compose.php3
Santiago Romero
sromero@servicom2000.com
Thu, 14 Jun 2001 18:52:28 +0200
El jue, 14 de jun de 2001, a las 12:49:18 +0200, Santiago Romero dijo:
> I need some users not to be able to add attachments to messages...
> As my qmail authenticates agains an Netscape LDAP directory server,
> I've added a LDAP field that indicates if that user can or can't
> attach files to the messages...
>
> I've modified mailbox.php3 to check the LDAP server using $imp->user
> as the UID to retrieve the LDAP field, and I assing it (true/false)
> to a variable called $user_can_use_attachs.
>
> My problem is that I need that variable to be seen on compose.inc.
> As it's defined on mailbox.php3, compose.inc can't see it...
> Where or how should I define it in order to be a global IMP variable?
In finally solved it using cookies. If someone has an LDAP directory
server and wants some user to have features that others don't have,
he can implement the following.
1.- Setup a new field on the LDAP server for the users (as I don't
want to add it for ALL users, I'm using the roomnumber field
that was not being used). I set this to 'y' or 'n' depending
on if I want or not that user to be able to send email with
attachments.
2.- Edit mailbox.php3 and add the following after the line 122
(just after the if (!isset($plural)) $plural = false; ):
// the isset is used to prevent the LDAP search on EACH mailbox
// refresh. This way it's only done once in the first refresh
// after login.
if( !isset( $canattach ) )
{
$ds=ldap_connect("my.ldap.server");
if ($ds)
{
$r=ldap_bind($ds);
$search="uid=" . $imp->user;
$sr=ldap_search($ds,"cn=Correo, ou=People, o=sistemas.servicom2000",
$search);
else
{
$info = ldap_get_entries($ds, $sr);
if( $info[0]["roomnumber"][0] == "y" )
SetCookie( "canattach", 'y', time()+3600 );
else
SetCookie( "canattach", 'n', time()+3600 );
}
ldap_close($ds);
}
}
3.- Edit login.php3 and add code to delete the cookie after
doing the logout on line 39 after the
if (!isset($reason)) { $reason = 'login'; } :
if( isset( $canattach ) )
{
unset( $canattach );
SetCookie("canattach");
}
4.- Finally, in my case I use this to allow/disallow the
display of the BROWSE+ATTACH options of the composition
page, so I edit horde/imp/template/compose/compose.inc
and put the code that displays the BOX and buttons
between the following if sentence:
<? if( $canattach == 'y' ) { ?>
// the standard code
<input type="hidden" name="attachmentAction" value="">
(etc...)
<?php endif; ?>
// end of standard code
<?php } ?>
This way only allowed users can attach files to messages.
You can also control any other webmail feature that way!!! This
would allow lots of new possibilites. In fact, you can use just
1 ldap field (testing bits, or just using it as a options string
where each letter reffers to a variable, as "ynnynny", where
[0] = can attach files, [1] = can use ldap ....) to control
different features. THat's important, as you can set IMP features
individually at user level on IMP 2.2.x.
PHP is quite awesome! I'm learning it while looking at IMP...
Hope this was useful for anybody.
Bye!
--
Santiago Romero
Departamento de Sistemas
sromero@servicom2000.com
Av. Primado Reig 189, entlo
46020 Valencia - Spain
Telf. (+34) 96 332 12 00
Fax. (+34) 96 332 12 01
http://www.servicom2000.com