Display a date related notice or countdown snippet

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 a special message, based on a date set in the user profile. It only displays for users with ADMINISTER USERS permissions or when a user is looking at his/her own user profile page.

The example below is a warning to Members that there are (x) days left before their membership expires. The same snippet maybe used for many applications.

Dependencies: profile.module must be enabled and a DATE field must be set in the user profile.

Usage

  • For use in your user profile page override
  • Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
  • Change the name of the profile date field you are using. (Tip: go to administer -->> settings -->> profile and in the second column it will give you the field name.)
  • Tested and works with Drupal 4.5 and 4.6
  • Change the div class names or the prefix text to suit.

<?php $date_key = 'profile_expiry_date'; /* change the name to the profile date field you are using */ ?>
<?php if ((user_access('administer users')) || ($GLOBALS['user']->uid == $user->uid)): ?>
<div class="warning">
<?php $keyMonth = $user->$date_key{month}; ?>
<?php $keyDay = $user->$date_key{day}; ?>
<?php $keyYear = $user->$date_key{year}; ?>
<?php $month = date(F); $mon = date(n); $day = date(j); $year = date(Y); ?>
<?php $hours_left = (mktime(0,0,0,$keyMonth,$keyDay,$keyYear) - time())/3600; ?>
<?php $daysLeft = ceil($hours_left/24); ?>
<?php $z = (string)$daysLeft; ?>
<?php if ($z > 1): ?>
<P>There are <?php print $z ;?> days left until your membership expires with this site</p>
</div>
<?php endif; ?>
<?php endif; ?>

 
 

Drupal is a registered trademark of Dries Buytaert.