| 1 |
<?php
|
| 2 |
// $Id: birthdays.page.inc,v 1.9 2008/10/01 22:19:56 maartenvg Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* All functions related to the birthdays listings page
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Show birthdays page
|
| 10 |
* @desc Callback for birthdays menu item to show a page which lists all users.
|
| 11 |
* @return string
|
| 12 |
* Themed birthday listing of all users
|
| 13 |
*/
|
| 14 |
function birthdays_view_page() {
|
| 15 |
global $_birthdays_field;
|
| 16 |
// Nothing to see when the birthdays profile field hasn't been set yet.
|
| 17 |
if (!isset($_birthdays_field)) {
|
| 18 |
return NULL;
|
| 19 |
}
|
| 20 |
drupal_add_css(drupal_get_path('module', 'birthdays') .'/birthdays.css');
|
| 21 |
if (isset($_REQUEST['birthdays_filter_month'])) {
|
| 22 |
$filter_month = (int) $_REQUEST['birthdays_filter_month'];
|
| 23 |
}
|
| 24 |
if (isset($_REQUEST['birthdays_filter_year'])) {
|
| 25 |
$filter_year = (int) $_REQUEST['birthdays_filter_year'];
|
| 26 |
}
|
| 27 |
$output = '';
|
| 28 |
$filter = '';
|
| 29 |
|
| 30 |
switch ($GLOBALS['db_type']) {
|
| 31 |
case 'mysql':
|
| 32 |
case 'mysqli':
|
| 33 |
// Right join = filtering out
|
| 34 |
$join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN';
|
| 35 |
$sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? 'MONTH({dob}.birthday), DAYOFMONTH({dob}.birthday), YEAR({dob}.birthday), ' : '';
|
| 36 |
$filter .= !empty($filter_month) ? " AND MONTH({dob}.birthday) = ". $filter_month : '';
|
| 37 |
$filter .= !empty($filter_year) ? " AND YEAR({dob}.birthday) = ". $filter_year : '';
|
| 38 |
break;
|
| 39 |
case 'pgsql':
|
| 40 |
// Right join = filtering out
|
| 41 |
$join = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) != BIRTHDAYS_PAGE_NOFILTER_SORT_USER || !empty($filter_month) || !empty($filter_year) ? 'RIGHT JOIN' : 'LEFT JOIN';
|
| 42 |
$sort = variable_get('birthdays_page_settings', BIRTHDAYS_PAGE_FILTER_SORT_DATE) == BIRTHDAYS_PAGE_FILTER_SORT_DATE || !empty($filter_month) || !empty($filter_year) ? "date_part('month', {dob}.birthday), date_part('day', {dob}.birthday), date_part('year', {dob}.birthday), " : '';
|
| 43 |
$filter .= !empty($filter_month) ? " AND date_part('month', {dob}.birthday) = ". $filter_month : '';
|
| 44 |
$filter .= !empty($filter_year) ? " AND date_part('year', {dob}.birthday) = ". $filter_year : '';
|
| 45 |
break;
|
| 46 |
}
|
| 47 |
|
| 48 |
// Select all users (but ignore blocked and never logged in ones)
|
| 49 |
$result = pager_query("SELECT {users}.uid FROM {users} ". $join ." {dob} ON {users}.uid = {dob}.uid WHERE {users}.status <> 0 AND {users}.access <> 0". $filter ." ORDER BY ". $sort ."{users}.name", variable_get('birthdays_page_list_number', 25));
|
| 50 |
|
| 51 |
while ($uid = db_fetch_object($result)) {
|
| 52 |
// load the user objects
|
| 53 |
$account = user_load(array('uid' => $uid->uid));
|
| 54 |
if (empty($filter_year) || !$account->birthdays_user_hide_year) {
|
| 55 |
$accounts[] = $account;
|
| 56 |
}
|
| 57 |
}
|
| 58 |
|
| 59 |
// Call theme_birthdays_page
|
| 60 |
$output .= theme('birthdays_page', $accounts, $filter_month, $filter_year);
|
| 61 |
// Get the filter form
|
| 62 |
|
| 63 |
return $output;
|
| 64 |
}
|
| 65 |
|
| 66 |
|
| 67 |
/**
|
| 68 |
* Return a form containing a select box to filter users by month of birth
|
| 69 |
*
|
| 70 |
* @param $filter_month
|
| 71 |
* @param int $filter_year
|
| 72 |
* @return array of the form
|
| 73 |
*/
|
| 74 |
function birthdays_page_filter($filter_month = NULL, $filter_year = NULL) {
|
| 75 |
$options_months[0] = '';
|
| 76 |
for ($i = 1; $i <= 12; $i++) {
|
| 77 |
$options_months[$i] = format_date(gmmktime(0, 0, 0, $i, 2, 1970), 'custom', 'F', 0);
|
| 78 |
}
|
| 79 |
|
| 80 |
$options_years[0] = '';
|
| 81 |
$options_years = $options_years + drupal_map_assoc(range(date('Y'), 1900));
|
| 82 |
|
| 83 |
$form['birthdays_filter_month'] = array(
|
| 84 |
'#type' => 'select',
|
| 85 |
'#options' => $options_months,
|
| 86 |
'#default_value' => $filter_month,
|
| 87 |
'#title' => t('Filter by month'),
|
| 88 |
'#attributes' => array('onchange' => 'submit()'),
|
| 89 |
);
|
| 90 |
|
| 91 |
if (variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) != BIRTHDAYS_HIDE_YEAR_YES) {
|
| 92 |
$form['birthdays_filter_year'] = array(
|
| 93 |
'#type' => 'select',
|
| 94 |
'#options' => $options_years,
|
| 95 |
'#default_value' => $filter_year,
|
| 96 |
'#title' => t('Year'),
|
| 97 |
'#attributes' => array('onchange' => 'submit()'),
|
| 98 |
);
|
| 99 |
}
|
| 100 |
|
| 101 |
$form['button'] = array(
|
| 102 |
'#type' => 'button',
|
| 103 |
'#prefix' => '<noscript>',
|
| 104 |
'#value' => t('Filter'),
|
| 105 |
'#suffix' => '</noscript>',
|
| 106 |
);
|
| 107 |
|
| 108 |
return $form;
|
| 109 |
}
|
| 110 |
|
| 111 |
/**
|
| 112 |
* Preprocess variables to format the birthdays page.
|
| 113 |
*
|
| 114 |
* $variables contains the following data:
|
| 115 |
* - $accounts
|
| 116 |
* - $filter_month
|
| 117 |
* - $filter_year
|
| 118 |
*/
|
| 119 |
function template_preprocess_birthdays_page(&$variables) {
|
| 120 |
global $_birthdays_field;
|
| 121 |
|
| 122 |
$row = 0;
|
| 123 |
$birthdays = array();
|
| 124 |
|
| 125 |
$variables['show_year'] = variable_get('birthdays_hide_year', BIRTHDAYS_HIDE_YEAR_NO) != BIRTHDAYS_HIDE_YEAR_YES;
|
| 126 |
$variables['show_starsign'] = (bool) variable_get('birthdays_show_starsign', BIRTHDAYS_STARSIGN_OFF);
|
| 127 |
$variables['show_user_picture'] = variable_get('user_pictures', FALSE);
|
| 128 |
$variables['show_filter'] = variable_get('birthdays_page_show_filters', 1);
|
| 129 |
|
| 130 |
foreach ($variables['accounts'] as $account) {
|
| 131 |
$birthdays[$row] = array(
|
| 132 |
'account' => $account,
|
| 133 |
'age' => _birthdays_show_age($account),
|
| 134 |
'username' => theme('username', $account),
|
| 135 |
'starsign' => birthdays_get_starsign_image($account->birthdays_starsign, variable_get('birthdays_show_starsign', BIRTHDAYS_STARSIGN_OFF)),
|
| 136 |
'picture' => theme('user_picture', $account),
|
| 137 |
'date' => _birthdays_show_date($account->{$_birthdays_field->name}, $account),
|
| 138 |
'zebra' => $row % 2 == 0 ? 'odd' : 'even',
|
| 139 |
);
|
| 140 |
|
| 141 |
$birthdays[$row]['show_age'] = isset($birthdays[$row]['age']);
|
| 142 |
|
| 143 |
$row++;
|
| 144 |
}
|
| 145 |
|
| 146 |
$variables['birthdays'] = $birthdays;
|
| 147 |
|
| 148 |
$variables['filter_form'] = drupal_get_form('birthdays_page_filter', $variables['filter_month'], $variables['filter_year']);
|
| 149 |
$variables['pager'] = theme('pager', NULL, variable_get('birthdays_page_list_number', 25), 0);
|
| 150 |
}
|