Using Drupal for karting club

I am using Drupal for my karting club, my-kart.org (http://www.my-kart.org/).

It meets most of my requirements as a community driven CMS (forums, blogs, image galleries, calendar etc).

Show/hide certain profile fields depending on user role or user permissions

Description
This collection of snippets allows site administrators to show or hide specific profile fields, depending on user permissions or on user roles.

Usage

  • For use in a user profile page override
  • Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the snippet into the user_profile.tpl.php file
  • Tested and works with Drupal 4.5 and 4.6
  • Change the div class name or the link text to suit.

Show content based on user permissions

User permissions are specified on the ADMINISTER --> ACCESS CONTROL page.

<?php if (user_access('administer users')): ?>
<div class="fields">CONTENT FOR ADMIN ONLY GOES HERE</div>
<?php endif; ?>

Show content based on user role.

In this example snippet, the content will only be displayed to users with the super admin role type. Change the role type, DIV etc. to change the output.

<?php if (in_array('super admin',$GLOBALS['user']->roles)): ?> 
<div class="fields">Super Administraator</div>
<?php endif; ?>

Show "Read User's Blog" on profile if user has permission to add blog entries.

Display users age based on a date-of-birth field

PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

Description

This php snippet displays the age of the user, based on a date of birth field.

Dependencies: profile.module must be installed & enabled and a custom profile date field called profile_dob must be setup. This is the DATE OF BIRTH field that is used to dynamically determine the users age.

Note: If you haven't setup your date-of-birth field yet, go to Administer › User management >Profiles and add a new DATE field. Give it the name profile_dob and fill out the rest of the options as suits.

Thanks to Pepe for improving the snippet.

Usage

  • For use in your user profile page override
  • Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the snippet into your user_profile.tpl.php file
  • Change the div class name or the message text to suit.

<?php
$year_diff = date("Y") - ($user->profile_dob{year});

Disabling a buggy module

A situation can arise where you've enabled a module through the user interface, but then because of a fatal error of some kind cannot get back to the modules administration screen to disable it (sometimes you cannot access any pages of your site at all): only the error is displayed and nothing else.

This can be resolved by executing the following query in the database (replace module_name with the name of the module you are trying to disable):

Using schema prefixes with PostgreSQL

This page discusses usage of PostgreSQL schemas for prefixes. "Normal" prefixes can be used in the same way as in MySQL, so they won't be discussed here.

PostgreSQL has something called 'schemas' (http://www.postgresql.org/docs/current/static/ddl-schemas.html). They can be very handy sometimes, but if you don't know what they are, you probably don't actually need them and can stop reading here.

Schemas can be used as prefixes within Drupal. That is, with a multisite setup, each site can reside in its own schema, and shared tables can reside in a "shared" schema (or even in the public schema).

There is one annoyance: the upgrade will fail. This is unfortunate, but nothing can be done as the "normal" (not schema) and schema prefixes are just incompatibile. If you are interested in the details, please see http://drupal.org/node/40034.

But, don't worry. This can be easily fixed by changing the update script (update.php and updates.inc) a bit. The problem lies in the CREATE [UNIQUE] INDEX and ALTER TABLE ... DROP/ADD CONSTRAINT statements. When schema prefixes are used, queries like this are executed:

CREATE INDEX prefix.search_total_word_idx ON prefix.search_total(word)
ALTER TABLE prefix.boxes DROP CONSTRAINT prefix.boxes_title_key
ALTER TABLE test.contact ADD CONSTRAINT test.contact_category_key UNIQUE (category)

Customizing the search forms

This info applies to Drupal 6 and 7.

Description

This guide describes how to override the default SEARCH THEME FORM* layout when using phptemplate based themes and the core Search module.

* The SEARCH THEME FORM is the search box that that appears in the page header, when enabled. Refer to the NOTES below for overriding the block search form and main page search form.

Pages

Subscribe with RSS Subscribe to RSS - Drupal 6.x