| 1 |
<?php |
<?php |
| 2 |
// $Id: pcp.module,v 1.0 2008/07/01 14:16:28 nrussell Exp $ |
// $Id$ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 20 |
/** |
/** |
| 21 |
* Implementation of hook_menu() |
* Implementation of hook_menu() |
| 22 |
*/ |
*/ |
| 23 |
function pcp_menu($may_cache) { |
function pcp_menu() { |
| 24 |
$items = array(); |
$items = array(); |
| 25 |
if ($may_cache) { |
|
| 26 |
$items[] = array( |
$items['admin/user/pcp'] = array( |
| 27 |
'path' => 'admin/user/pcp', |
'title' => 'Profile Complete Percentages', |
| 28 |
'title' => t('Profile Complete Percentages'), |
'description' => 'Tag profile fields as required for percent complete handling.', |
| 29 |
'callback' => 'pcp_admin_settings', |
'page callback' => 'pcp_admin_settings', |
| 30 |
'access' => user_access('administer pcp'), |
'access arguments' => array('administer pcp'), |
| 31 |
'description' => t('Tag profile fields as required for percent complete handling.'), |
); |
| 32 |
); |
|
|
} |
|
| 33 |
return $items; |
return $items; |
| 34 |
} |
} |
| 35 |
|
|
| 47 |
case 0: |
case 0: |
| 48 |
global $user; |
global $user; |
| 49 |
$complete_data = pcp_get_complete_percentage_data($user); |
$complete_data = pcp_get_complete_percentage_data($user); |
| 50 |
$block['subject'] = t('Profile Complete'); |
$block = array( |
| 51 |
$block['content'] = theme('pcp_profile_percent_complete', $complete_data); |
'subject' => t('Profile Complete'), |
| 52 |
|
'content' => theme('pcp_profile_percent_complete', $complete_data), |
| 53 |
|
); |
| 54 |
break; |
break; |
| 55 |
} |
} |
| 56 |
return $block; |
return $block; |
| 61 |
/** |
/** |
| 62 |
* Implementation of hook_form_alter() |
* Implementation of hook_form_alter() |
| 63 |
*/ |
*/ |
| 64 |
function pcp_form_alter($form_id, &$form) { |
function pcp_form_alter(&$form, $form_state, $form_id) { |
| 65 |
if ($form_id == 'profile_field_form' && user_access('administer pcp')) { |
if ($form_id == 'profile_field_form' && user_access('administer pcp')) { |
| 66 |
$fid = $form['fid']['#value']; |
$fid = $form['fid']['#value']; |
| 67 |
$tag = TRUE; |
$tag = TRUE; |
| 82 |
'#description' => t('Checking this box will tag this field as a required field for completion of the users profile.'), |
'#description' => t('Checking this box will tag this field as a required field for completion of the users profile.'), |
| 83 |
'#default_value' => $tag, |
'#default_value' => $tag, |
| 84 |
); |
); |
| 85 |
$form['#submit'] = $form['#submit'] + array('pcp_profile_field_form_submit' => array()); |
$form['#submit'][] = 'pcp_profile_field_form_submit'; |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
if ($form_id == 'user_edit' && arg(3) != '' && $_GET['fieldname'] != '') { |
if ($form_id == 'user_profile_form' && arg(3) != '' && $_GET['fieldname'] != '') { |
| 89 |
$fieldname = 'edit-'. preg_replace("/_/", "-", $_GET['fieldname']); |
$fieldname = 'edit-'. preg_replace("/_/", "-", $_GET['fieldname']); |
| 90 |
drupal_add_js(" |
drupal_add_js(" |
| 91 |
$('#". $fieldname ."').css({ |
$('#". $fieldname ."').css({ |
| 99 |
* Called when a user submits a profile field form from the |
* Called when a user submits a profile field form from the |
| 100 |
* profile module (when adding or editing a profile field). |
* profile module (when adding or editing a profile field). |
| 101 |
*/ |
*/ |
| 102 |
function pcp_profile_field_form_submit($form_id, $form) { |
function pcp_profile_field_form_submit($form, &$form_state) { |
| 103 |
$fid = $form['fid'] ? $form['fid'] : db_result(db_query("SELECT MAX(fid) FROM {profile_fields}")); |
$fid = $form_state['values']['fid'] ? $form_state['values']['fid'] : db_result(db_query("SELECT MAX(fid) FROM {profile_fields}")); |
| 104 |
db_query("DELETE FROM {profile_pcp} WHERE fid = %d", $form['fid']); |
db_query("DELETE FROM {profile_pcp} WHERE fid = %d", $form_state['values']['fid']); |
| 105 |
if ($form['tag']) { |
if ($form_state['values']['tag']) { |
| 106 |
db_query("INSERT INTO {profile_pcp} VALUES (%d)", $fid); |
db_query("INSERT INTO {profile_pcp} (`fid`) VALUES (%d)", $fid); |
| 107 |
} |
} |
| 108 |
} |
} |
| 109 |
|
|
| 141 |
/** |
/** |
| 142 |
* Admin settings form submit |
* Admin settings form submit |
| 143 |
*/ |
*/ |
| 144 |
function pcp_admin_settings_form_submit($form_id, $form_values) { |
function pcp_admin_settings_form_submit($form, &$form_state) { |
| 145 |
if (is_array($form_values['profile_fields']) && !empty($form_values['profile_fields'])) { |
if (is_array($form_state['values']['profile_fields']) && !empty($form_state['values']['profile_fields'])) { |
| 146 |
db_query("DELETE FROM {profile_pcp}"); |
db_query("DELETE FROM {profile_pcp}"); |
| 147 |
foreach ($form_values['profile_fields'] as $fid) { |
foreach ($form_state['values']['profile_fields'] as $fid) { |
| 148 |
if ($fid) { |
if ($fid) { |
| 149 |
db_query("INSERT INTO {profile_pcp} VALUES (%d)", $fid); |
db_query("INSERT INTO {profile_pcp} VALUES (%d)", $fid); |
| 150 |
} |
} |
| 286 |
return $fields; |
return $fields; |
| 287 |
} |
} |
| 288 |
|
|
| 289 |
|
|
| 290 |
|
function pcp_theme() { |
| 291 |
|
return array( |
| 292 |
|
'pcp_profile_percent_complete' => array( |
| 293 |
|
'arguments' => array('complete_data' => NULL), |
| 294 |
|
), |
| 295 |
|
); |
| 296 |
|
} |
| 297 |
|
|
| 298 |
/** |
/** |
| 299 |
* Block Theme function that displays the default output of a users |
* Block Theme function that displays the default output of a users |
| 300 |
* profile complete percent. Use this theme function to override |
* profile complete percent. Use this theme function to override |
| 325 |
$output .= '</div>'; |
$output .= '</div>'; |
| 326 |
|
|
| 327 |
if ($complete_data['nextfield'] && $complete_data['nextpercent']) { |
if ($complete_data['nextfield'] && $complete_data['nextpercent']) { |
| 328 |
$output .= 'Filling out <i>'. l($complete_data['nextfield'], 'user/'. $complete_data['uid'] .'/edit/'. $complete_data['nextcategory'], array(), 'fieldname='. $complete_data['nextname']) .'</i> will bring your profile to '. t('!complete% Complete', array('!complete' => $complete_data['nextpercent'])); |
$output .= 'Filling out <i>'. l($complete_data['nextfield'], 'user/'. $complete_data['uid'] .'/edit/'. $complete_data['nextcategory'], array('query' => 'fieldname='. $complete_data['nextname'])) .'</i> will bring your profile to '. t('!complete% Complete', array('!complete' => $complete_data['nextpercent'])); |
| 329 |
} |
} |
| 330 |
|
|
| 331 |
return $output; |
return $output; |