I just got our drupal config working with a role-based home page.

This really isn't hard, but getting it all tuned and working correctly took a bit of time. I think you would take my ideas and easily adapt them to more sophisticated uses.


Role Based home page



What I'm doing here is just using a static page as a home page. You'll need to flag the static page as "Promoted to front page" and "static on front page". Also, it will look better if you change the default story publishing prefs to make all other content not be promoted to the front page by default. While someone could override this, as long as you have control over the content creators, it works well enough. You could certainly hack node.module to do a more clean implementation.

So, after implementing profile.module, create the static page and promote it to the front page. Edit it as a php page with contents like this:

global $user;

$enthome = "Welcome to the Acme Enterprise Sales Portal.";

if (!$user->uid){
   $enthome.="CONTENT FOR NOT-LOGGED IN USERS";
}

if ($user->profile_sales == "yes") {
   $enthome.="SALES CONTENT ON HOME PAGE you will see this content if you are in the Sales role";
 }

if ($user->profile_se == "yes") {
   $enthome.="SE CONTENT ON HOME PAGE you will see this content if you are in the SE role";
 }

if ($user->profile_role3 == "yes") {
   $enthome.="ROLE3 CONTENT ON HOME PAGE you will see this content if you are in the ROLE3 role";
}

if ($user->profile_manager == "yes") {
   $enthome.="MANAGER CONTENT ON HOME PAGE you will see this content if you are in the MANAGER role";
}

$enthome.="end of content";

print $enthome;

The intention here is that each user is only in one role, but if they were in multiple roles you could certainly clean up the HTML to handle that.

Comments

tdailey’s picture

here's the menu code. Just make a block and put it in the top left corner, or whereever you please. You could easily make this more complex with collapsible menus and such if you wanted.

global $user;

$entmenu = "<ul>";
$entmenu .= "<li><a href=\"/\">Home</a></li>";

if ($user->profile_sales == "yes") {
   $entmenu.="<li><A HREF=\"/?q=node/view/31\">Item 2</A></li>
   <li><A HREF=\"/?q=node/view/32\">Item 3</A></li>";
}

if ($user->profile_se == "yes") {
   $entmenu.="<li><A HREF=\"<li><A HREF=\"/?q=node/view/31\">Item 2</A></li>
   <li><A HREF=\"/?q=node/view/32\">Item 3</A></li>";
}

if ($user->profile_role3 == "yes") {
   $entmenu.="<li>ROLE3 MENU ITEMS PLACEHOLDER</li>";
}

if ($user->profile_manager == "yes") {
   $entmenu.="<li>MANAGER MENU ITEMS PLACEHOLDER/li>";
}

$entmenu.="</ul>";

return t($entmenu);
Donovan@drupal.org’s picture

Thanks! This could certainly help me accomplish what I am trying to do. I have a few questions though:

1) How would I modify your code to check for a "webmail" role?

I tried changing if ($user->profile_sales == "yes") to if ($user->profile_webmail == "yes") and if ($user->webmail == "yes")

But the link does not show up in the block in either case.

2) Is there a way to conditionally show this block? (e.g., show block only for users with role="weblink"?

Thx.

AXIN’s picture

if ($user->role == "sales") {
$enthome.="sales content";
}

tdailey’s picture

I tried changing if ($user->profile_sales == "yes") to
 if ($user->profile_webmail == "yes") and if ($user->webmail == "yes") 

But the link does not show up in the block in either case.

You did configure the webmail role in profile.module, right? If not, you need to do that first, then you should have a drop-down box for the role in the user configuration. Make sure that is turned on. also, don't forget to declare global $user.

2) Is there a way to conditionally show this block? (e.g., show block only for users with role="weblink"?

A completely empty block won't display. So if you wrap your whole block in a conditional statement, and the user doesn't meet the condition, the block won't display at all.

Donovan@drupal.org’s picture

Thanks tdailey and AXIN. As a result of tdailey's Role-based menu, and AXIN's suggestions, I now have a convenient, conditional (role-based) webmail link on my site. The link allows direct access to a webmail interface, and is only displayed for users with a specific role (in my case: "family"). The block code is very simple:


global $user;
<br>if ($user->role == "family") {
<br>   $entmenu = &ltul>
<br>   $entmenu.= &ltli&gt &ltA HREF=\"http://www.mydomain.com/webmail\">Check Email&lt/A&gt &lt/li>
<br>   $entmenu.= &lt/ul>
<br>}
<br>   return t($entmenu);

I also installed an excellent webmail script (UebiMiau) based on instructions posted my "mir" at the following URL:



http://s88567960.onlinehome.us/forums/index.php?showtopic=137



The combination does just about everything I'm looking for, so now I would like to tweak it by dictating how the linked (webmail) page is rendered. Does Drupal support this? That is, can I code a weblink in such a away that the referenced page is rendered to either:



(a) a new window/page instead of the current one, or


(b) to a frame within a pre-existing static page on the website?



TIA,

Donovan.

tdailey’s picture

a new window/page instead of the current one

That's easy. In HTML you can:

&lt;a href="http://www.yourlink.com" target="_blank"&gt;Your Link Text&lt;/a&gt;


In XHTML strict, you'll need to use an onclick window.open method. I tried to paste the sample code here but for some reason it gets labeled at suspicious data. Anyway, you probably don't care about XHTML strict so just use target=.

(b) to a frame within a pre-existing static page on the website?

For that, you just need to define a node as an iframe and reference the iframe:

$frame = "<iframe src=\"http://www.youriframedpage.com/page.html\" width=\"100%\" height=\"1600\">";
$frame .= "<!-- Alternate content for non-supporting browsers -->";
$frame .= "Your browser won't work here.";
$frame .= "</iframe>";

print $frame;

Just make this a PHP static page and reference the link to the page.

Donovan@drupal.org’s picture

Thanks tdailey. I implemented option (b) as you suggested and it worked perfectly. I now have a permission-based webmail access link, and webmail client interface integrated into my drupal installation. Thanks so much for your help. This is too cool -- and will probably be of interest to others. I'll post a link to some screen shots shortly.

Donovan@drupal.org’s picture

You can check out the screenshots in my "Drupal" image gallery at the following URL:

http://www.dillonsdomain.com/image/tid/30

tdailey’s picture

looks great! glad i could help out. That's a pretty nice webmail interface. I've used SquirrelMail, which is a bit more complex, probably, but it's nice too.

Donovan@drupal.org’s picture

I'll have to check out SquirrelMail. I would like to tighten the integration a bit further by auto-populating the Username and Password fields, and perhaps some skinning for cosmetics. Would SquirrelMail facilitate this? Also, I recall seeing somewhere that SquirrelMail requires an IMAP server, which my webhost (1and1) does not support. Can you confirm this?

Thanks again for all of your help tdailey.

mythos07’s picture

I tried changing if ($user->profile_sales == "yes") to
if ($user->profile_webmail == "yes") and if ($user->webmail == "yes")

--------------------------------
Busby SEO Challenge.