0 );
}
function badcamp_init() {
if (function_exists('drupal_get_path')) {
drupal_add_js(drupal_get_path('theme', 'badcamp_theme') .'/craqbox.js');
if (strpos(drupal_get_js(), 'jquery.rating.js') === FALSE) {
drupal_add_js(drupal_get_path('module', 'fivestar') . '/jquery.rating.js');
drupal_add_js("jQuery(function(){jQuery('div.fivestar-widget').rating();});", 'inline');
}
drupal_add_css(drupal_get_path('theme', 'badcamp_theme') .'/craqbox.css');
drupal_add_css(drupal_get_path('module', 'fivestar') .'/fivestar.css');
drupal_add_css(drupal_get_path('theme', 'badcamp_theme') .'/badcamp.css');
}
if (function_exists('jquery_ui_backport_add')) {
jquery_ui_backport_add();
drupal_add_js(drupal_get_path('module', 'badcamp') . '/badcamp.js');
// drupal_add_css(drupal_get_path('module', 'jquib') . '/themes/flora/flora.all.css');
}
// this should be moved into badcamp.install
// db_query("UPDATE {system} SET weight = '20' WHERE name = 'badcamp'");
}
/**
* Test if node is signup enabled
*
* @param node_id $nid
* @return bool
*/
function _badcamp_is_signup( $nid ) {
return db_num_rows(db_query("SELECT nid FROM {signup} WHERE nid = %d", $nid));
}
function badcamp_menu( $may_cache ) {
if( !$may_cache ) {
if ( arg(0) == 'node' && is_numeric(arg(1)) && _badcamp_is_signup(arg(1)) ) {
$access = user_access('administer all signups');
$access_own = user_access('administer signups for own content') && ($user->uid == $node->uid);
$items[] = array(
'path' => 'node/'. arg(1) .'/signups-override',
'title' => t('Signup Override'),
'callback' => 'drupal_get_form',
'callback arguments' => array('badcamp_override_page', arg(1)),
'access' => $access || $access_own,
'type' => MENU_LOCAL_TASK,
'weight' => 22,
);
}
}
return $items;
}
function badcamp_override_page( $nid ) {
$node = node_load( $nid );
if( !$node->signup ) {
drupal_set_message( "Node $node->title is not signup enabled" );
return;
}
// dprint_r( $node );
$form = array();
$status = $node->signup_status ? 'Open' : 'Closed';
$form['status'] = array(
'#value' => "
Current signup status: $status
",
);
$form['count'] = array(
'#value' => "Current registration count: $node->signup_total (of $node->signup_close_signup_limit)
",
);
// // get non-registered users
// $result = db_query(
// 'SELECT u.uid, u.name '.
// 'FROM {users} u '.
// 'WHERE u.uid > 0 AND u.uid NOT IN (SELECT s.uid FROM {signup_log} s WHERE s.nid = %d) '.
// 'ORDER BY u.name ASC', $nid );
//
// $users = array();
// while ($user = db_fetch_object($result)) {
// $users[$user->uid] = $user->name;
// }
// get non-registered users with bios
$result = db_query(
'SELECT u.uid, u.name, u.mail, n.title '.
'FROM {users} u '.
' INNER JOIN {node} n ON u.uid = n.uid '.
'WHERE u.uid > 0 AND u.uid NOT IN (SELECT s.uid FROM {signup_log} s WHERE s.nid = %d) '.
' AND n.type = "%s" ',
$nid, variable_get('bio_nodetype', 'bio') );
while ($user = db_fetch_object($result)) {
$users[$user->uid] = "$user->title ($user->name) $user->mail" ;
}
$form['quick_child_add_nid'] = array(
'#type' => 'hidden',
'#value' => $nid,
);
$form['quick_child_add_user'] = array(
'#type' => 'select',
'#title' => t('Add User to '. $node->title ),
'#options' => $users,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Add User'),
);
return $form;
}
function badcamp_override_page_submit($form_id, $form_values) {
$uid = $form_values['quick_child_add_user'];
$nid = $form_values['quick_child_add_nid'];
$bid = bio_for_user( $uid );
if( $bid ) {
$bio = node_load( $bid );
$name = $bio->title;
_badcamp_add_signup_user( $uid, $nid, $name );
}
else {
$account = user_load(array('uid' => $uid));
$name = $account->name;
drupal_set_message( "Not Added. Please ask ". $name . ' to fill out a bio.', 'error' );
}
}
/**
* Admin access only, do it even if the event is closed.
* does not send out all the emails?
*/
function _badcamp_add_signup_user( $uid, $nid, $name ) {
$node = node_load( $nid );
// Allow other modules to inject data into the user's signup data.
$extra = module_invoke_all('signup_sign_up', $node);
$signup_form_data = serialize(array_merge(array( "Name" => $name ), $extra));
// Insert the user into the signup_log.
db_query(
"INSERT INTO {signup_log}
(uid, nid, anon_mail, signup_time, form_data)
VALUES (%d, %d, '%s', %d, '%s')",
$uid, $nid, '', time(), $signup_form_data
);
drupal_set_message(t('@name signed up to !title.', array('!title' => $node->title, '@name' => $name)) );
$node->signup_total++;
if ($node->signup_close_signup_limit) {
_signup_check_limit($node, 'total');
}
}
function badcamp_form_alter($form_id, &$form, $a=null){
if( $form_id == 'user_register' ) {
// $form['#validate']['badcamp_sneaky'] = array();
// $form['#submit']['badcamp_add_bio'] = array();
$form['#redirect'] = array( $_GET['q'], 'step1=done'); // go back to the page that called me.
}
elseif( $form_id == 'bio_node_form' ) {
$form['#redirect'] = array($_GET['q'], 'step2=done'); // go back to the page that called me.
}
}
/**
* Enter description here...
*
* @param unknown_type $node
* @param unknown_type $op
* @param unknown_type $a3
* @param unknown_type $is_page
*/
function badcamp_nodeapi(&$node, $op, $a3, $is_page) {
if( $node->type == 'session' ) {
if( $op == 'view' ) {
$bid = bio_for_user( $node->uid );
if( $bid ) {
$bio = node_load( $bid );
$node->content['presenter_name'] = array(
'#value' => $bio->title,
'#weight' => 10,
);
$node->content['presenter_bio'] = array(
'#value' => $bio->field_bio_blurb[0]['value'],
'#weight' => 11,
);
}
}
}
elseif( $node->type == 'bio' ) {
if( $op == 'view' ) {
$title = $node->field_first_name[0]['value'] .' '. $node->field_last_name[0]['value'];
$node->content['badcamp'] = array(
'#value' => ''. $title .'
',
'#weight' => -4,
);
if( $is_page ) {
drupal_set_title( $title ); // doesn't work, being set again somewhere else (prob bio)
}
// now that weight has changed, switch from node, to node->content
unset($node->content['field_first_name']);
unset($node->content['field_last_name']);
}
}
if( $node->type == 'event' && $node->signup && $op == 'view' ) {
// dprint_r( $node );
global $user;
if( $node->signup_status ) { // signup is open
if (!$user->uid) { // user is not logged in, present them with login form
if( $_GET['step1'] == 'start' ) {
$status = 'step1_start';
}
else {
$status = 'not_loggedin';
}
}
else { // user is logged in
$bid = bio_for_user( $user->uid );
if( !$bid ) { // user is logged in but has no bio, present with bio form
$status = 'no_bio';
}
else { // user is logged in and has bio form
if( _badcamp_is_user_signedup( $user->uid, $node->nid ) ) {
$status = 'signedup';
}
else { // user is logged in and has bio form, but has not registered
if( $_GET['step2'] == 'done' ) { // coming through reg, so auto sign them up
$status = 'auto_signup';
}
else { // they have all the prereqs, but are coming to the page cold
$status = 'not_signedup';
}
}
}
}
switch ($status) {
case 'not_loggedin':
$msg = l('Step #1: Click here to start registration for '. $node->title, 'node/'.$node->nid, array(), 'step1=start' );
break;
case 'step1_start': // nice to do this with ajax
$msg = 'Step #1: Fill Out Basic Account Information';
$form = drupal_get_form( 'user_register' );
break;
case 'no_bio':
if( $is_page ) {
$msg = 'Step #2: Fill Out Personal Information';
$form = drupal_get_form('bio_node_form', array( 'type' => 'bio' ) );
// need for badcamp module to have a bigger weight than signup for this to work
unset( $node->content['signup'] ); // don't allow signup until we have a bio
}
else { // teaser
$msg = l( 'Click here to regisister for '. $node->title, 'node/'.$node->nid, array(), 'step2=start' );
}
break;
case 'not_signedup':
if( $is_page ) {
$msg = 'Step #3: Click on "Sign up" button below to complete your registration.';
}
else { // teaser
$msg = l( 'Click here to regisister for '. $node->title, 'node/'.$node->nid, array(), 'step2=done' );
}
break;
case 'auto_signup':
$bio = node_load( $bid );
// _badcamp_signup_user( $user->uid, $node->nid, $bio->title );
$signup = array (
'nid'=> $node->nid,
'uid' => $user->uid,
'signup_form_data' => array (
'Name' => $bio->title,
),
);
signup_sign_up_user( $signup );
unset( $node->content['signup'] ); // questionable
case 'signedup':
$msg[] = 'You are registered for '. $node->title;
if( !$user->picture ) {
$msg[] = l( 'Click here to add a profile picture', "user/$user->uid/edit", array(), "destination=node/$node->nid" );
}
$msg[] = l( 'Would you like to offer a Session?', 'node/add/session' );
$msg = "- ". implode( $msg, '
- ' ) ."
";
break;
}
}
else {
$msg = "I am sorry, registration for $node->title is closed";
}
$node->content['badcamp'] = array(
'#value' => "$msg
$form",
'#weight' => -2,
'#theme' => 'badcamp_group',
);
// need for badcamp module to have a higher weight than signup for this to work
$node->content['signup']['#weight'] = -1;
}
}
function theme_badcamp_group( $element ) {
return theme( 'fieldset', array(
'#title' => 'Registration',
'#value' => $element['#value'],
'#collapsible' => false,
));
}
function badcamp_views_tables() {
$signups = array();
list($sql, $sql_count) = signup_admin_form_sql();
$results = db_query( $sql );
while( $row = db_fetch_array($results) ) {
$signups[$row['nid']] = $row['title'];
}
$tables['badcamp'] = array(
'name' => 'signup_log',
'join' => array (
'type' => 'inner',
'left' => array(
'table' => 'node',
'field' => 'uid'
),
'right' => array(
'field' => 'uid'
),
),
'filters' => array(
'badcamp' => array(
'name' => t("BC Signup: Nodes of User"),
'help' => t('Only show nodes that are owned by a user signed up for the selected event'),
'field' => 'nid',
'value' => array(
'#type' => 'select',
'#options' => $signups,
),
'operator' => array('=' => t('Signed Up For'), '<>' => t('Not Singed Up For') ),
'handler' => 'badcamp_views_handler_filter_signup_uid',
),
),
);
return $tables;
}
function badcamp_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$blocks[0]['info'] = t('BADCamp 07 Reg Status');
return $blocks;
}
else if ($op == 'view') {
switch ($delta) {
case 0:
global $user;
if( $user->uid && $user->uid != 1 ) { // don't bother for anonymous or admin
$registered = db_result(
db_query(
"SELECT uid FROM signup_log WHERE nid = %d and uid = %d",
1, $user->uid
)
);
if( $registered ) {
$output = "You are registed for BADCamp 07.";
}
else {
$output = "You are NOT registed for BADCamp 07.
";
$output .= ''. l( "Complete registration", "07/badcamp-07" ) .'
';
$block['subject'] = 'Registration Status';
$block['content'] = $output;
}
}
return $block;
break;
} // end switch
}
}
function badcamp_views_handler_filter_signup_uid($op, $filter, $filterinfo, &$query) {
//dprint_r( $filter['value'] );
$table = $filterinfo['table'];
$column = $filterinfo['field'];
$field = "$table.$column";
$event_nid = $filter['value'];
$query->ensure_table($table);
$query->add_where("%s = %s", $field, $event_nid);
}
// no longer announcing count.
//function theme_views_view_attendees($view, $type, $nodes, $level = NULL, $args = NULL) {
// $output = "There are " . count($nodes) ." Registered Attendees";
// $output .= theme_views_view($view, $type, $nodes, $level, $args);
// return $output;
//}